Take multiple source files on the command line.
This commit is contained in:
parent
8f68a07476
commit
006a2cce83
|
|
@ -19,12 +19,12 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
#if !defined(WINNT)
|
#if !defined(WINNT)
|
||||||
#ident "$Id: globals.h,v 1.1 1999/07/03 20:03:47 steve Exp $"
|
#ident "$Id: globals.h,v 1.2 1999/09/05 22:33:18 steve Exp $"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
|
|
||||||
extern void reset_lexor(FILE*out, const char*ipath);
|
extern void reset_lexor(FILE*out, char*paths[]);
|
||||||
extern void define_macro(const char*name, const char*value);
|
extern void define_macro(const char*name, const char*value);
|
||||||
|
|
||||||
/* These variables contain the include directories to be searched when
|
/* These variables contain the include directories to be searched when
|
||||||
|
|
@ -40,6 +40,9 @@ extern int yyparse();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: globals.h,v $
|
* $Log: globals.h,v $
|
||||||
|
* Revision 1.2 1999/09/05 22:33:18 steve
|
||||||
|
* Take multiple source files on the command line.
|
||||||
|
*
|
||||||
* Revision 1.1 1999/07/03 20:03:47 steve
|
* Revision 1.1 1999/07/03 20:03:47 steve
|
||||||
* Add include path and line directives.
|
* Add include path and line directives.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
#if !defined(WINNT)
|
#if !defined(WINNT)
|
||||||
#ident "$Id: lexor.lex,v 1.11 1999/07/25 00:03:13 steve Exp $"
|
#ident "$Id: lexor.lex,v 1.12 1999/09/05 22:33:18 steve Exp $"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
|
|
@ -60,6 +60,7 @@ struct include_stack_t {
|
||||||
struct include_stack_t*next;
|
struct include_stack_t*next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static struct include_stack_t*file_queue = 0;
|
||||||
static struct include_stack_t*istack = 0;
|
static struct include_stack_t*istack = 0;
|
||||||
static struct include_stack_t*standby = 0;
|
static struct include_stack_t*standby = 0;
|
||||||
|
|
||||||
|
|
@ -469,12 +470,18 @@ static void do_include()
|
||||||
fprintf(yyout, "#line \"%s\" %u\n", istack->path, istack->lineno);
|
fprintf(yyout, "#line \"%s\" %u\n", istack->path, istack->lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The lexical analyzer calls this function when the current file
|
||||||
|
* ends. Here I pop the include stack and resume the previous file. If
|
||||||
|
* there is no previous file, then the main input is ended.
|
||||||
|
*/
|
||||||
static int yywrap()
|
static int yywrap()
|
||||||
{
|
{
|
||||||
int line_mask_flag = 0;
|
int line_mask_flag = 0;
|
||||||
struct include_stack_t*isp = istack;
|
struct include_stack_t*isp = istack;
|
||||||
istack = isp->next;
|
istack = isp->next;
|
||||||
|
|
||||||
|
/* Delete the current input buffers, and free the cell. */
|
||||||
yy_delete_buffer(YY_CURRENT_BUFFER);
|
yy_delete_buffer(YY_CURRENT_BUFFER);
|
||||||
if (isp->file) {
|
if (isp->file) {
|
||||||
fclose(isp->file);
|
fclose(isp->file);
|
||||||
|
|
@ -492,13 +499,41 @@ static int yywrap()
|
||||||
}
|
}
|
||||||
free(isp);
|
free(isp);
|
||||||
|
|
||||||
if (istack == 0)
|
/* If I am out if include stack, the main input is
|
||||||
return 1;
|
done. Look for another file to process in the input
|
||||||
|
queue. If none are there, give up. Otherwise, open the file
|
||||||
|
and continue parsing. */
|
||||||
|
if (istack == 0) {
|
||||||
|
if (file_queue == 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
istack = file_queue;
|
||||||
|
file_queue = file_queue->next;
|
||||||
|
istack->next = 0;
|
||||||
|
istack->lineno = 0;
|
||||||
|
|
||||||
|
istack->file = fopen(istack->path, "r");
|
||||||
|
if (istack->file == 0) {
|
||||||
|
perror(istack->path);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line_direct_flag)
|
||||||
|
fprintf(yyout, "#line \"%s\" 0\n", istack->path);
|
||||||
|
|
||||||
|
yyrestart(isp->file);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Otherwise, resume the input buffer that is the new stack
|
||||||
|
top. If I need to print a line directive, do so. */
|
||||||
|
|
||||||
yy_switch_to_buffer(istack->yybs);
|
yy_switch_to_buffer(istack->yybs);
|
||||||
|
|
||||||
if (line_direct_flag && istack->path && !line_mask_flag)
|
if (line_direct_flag && istack->path && !line_mask_flag)
|
||||||
fprintf(yyout, "#line \"%s\" %u\n", istack->path, istack->lineno);
|
fprintf(yyout, "#line \"%s\" %u\n", istack->path, istack->lineno);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -507,14 +542,16 @@ static int yywrap()
|
||||||
* opened, and the lexor is initialized. The include stack is cleared
|
* opened, and the lexor is initialized. The include stack is cleared
|
||||||
* and ready to go.
|
* and ready to go.
|
||||||
*/
|
*/
|
||||||
void reset_lexor(FILE*out, const char*path)
|
void reset_lexor(FILE*out, char*paths[])
|
||||||
{
|
{
|
||||||
|
unsigned idx;
|
||||||
|
struct include_stack_t*tail = 0;
|
||||||
struct include_stack_t*isp = malloc(sizeof(struct include_stack_t));
|
struct include_stack_t*isp = malloc(sizeof(struct include_stack_t));
|
||||||
isp->path = strdup(path);
|
isp->path = strdup(paths[0]);
|
||||||
isp->file = fopen(path, "r");
|
isp->file = fopen(paths[0], "r");
|
||||||
isp->str = 0;
|
isp->str = 0;
|
||||||
if (isp->file == 0) {
|
if (isp->file == 0) {
|
||||||
perror(path);
|
perror(paths[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -525,4 +562,20 @@ void reset_lexor(FILE*out, const char*path)
|
||||||
assert(istack == 0);
|
assert(istack == 0);
|
||||||
istack = isp;
|
istack = isp;
|
||||||
isp->next = 0;
|
isp->next = 0;
|
||||||
|
|
||||||
|
/* Now build up a queue of all the remaining file names, so
|
||||||
|
that yywrap can pull them when needed. */
|
||||||
|
file_queue = 0;
|
||||||
|
for (idx = 1 ; paths[idx] ; idx += 1) {
|
||||||
|
isp = malloc(sizeof(struct include_stack_t));
|
||||||
|
isp->path = strdup(paths[idx]);
|
||||||
|
isp->str = 0;
|
||||||
|
isp->next = 0;
|
||||||
|
if (tail)
|
||||||
|
tail->next = isp;
|
||||||
|
else
|
||||||
|
file_queue = isp;
|
||||||
|
|
||||||
|
tail = isp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
ivlpp/main.c
14
ivlpp/main.c
|
|
@ -17,7 +17,7 @@ const char COPYRIGHT[] =
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
*/
|
*/
|
||||||
#if !defined(WINNT)
|
#if !defined(WINNT)
|
||||||
#ident "$Id: main.c,v 1.2 1999/07/03 20:03:47 steve Exp $"
|
#ident "$Id: main.c,v 1.3 1999/09/05 22:33:18 steve Exp $"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char NOTICE[] =
|
const char NOTICE[] =
|
||||||
|
|
@ -109,7 +109,7 @@ int main(int argc, char*argv[])
|
||||||
flag_errors += 1;
|
flag_errors += 1;
|
||||||
|
|
||||||
if (flag_errors) {
|
if (flag_errors) {
|
||||||
fprintf(stderr, "\nUsage: %s [-v][-L][-I<dir>][-D<def>] <file>\n"
|
fprintf(stderr, "\nUsage: %s [-v][-L][-I<dir>][-D<def>] <file>...\n"
|
||||||
" -D<def> - Predefine a value.\n"
|
" -D<def> - Predefine a value.\n"
|
||||||
" -I<dir> - Add an include file search directory\n"
|
" -I<dir> - Add an include file search directory\n"
|
||||||
" -L - Emit line number directives\n"
|
" -L - Emit line number directives\n"
|
||||||
|
|
@ -129,12 +129,20 @@ int main(int argc, char*argv[])
|
||||||
out = stdout;
|
out = stdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_lexor(out, argv[optind]);
|
if (argv[optind] == 0) {
|
||||||
|
fprintf(stderr, "%s: No input files given.\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
reset_lexor(out, argv+optind);
|
||||||
return yyparse();
|
return yyparse();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log: main.c,v $
|
* $Log: main.c,v $
|
||||||
|
* Revision 1.3 1999/09/05 22:33:18 steve
|
||||||
|
* Take multiple source files on the command line.
|
||||||
|
*
|
||||||
* Revision 1.2 1999/07/03 20:03:47 steve
|
* Revision 1.2 1999/07/03 20:03:47 steve
|
||||||
* Add include path and line directives.
|
* Add include path and line directives.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue