From 006a2cce833664f3c0d6a7a9e3f9f3c499ddfdaf Mon Sep 17 00:00:00 2001 From: steve Date: Sun, 5 Sep 1999 22:33:18 +0000 Subject: [PATCH] Take multiple source files on the command line. --- ivlpp/globals.h | 7 ++++-- ivlpp/lexor.lex | 67 +++++++++++++++++++++++++++++++++++++++++++------ ivlpp/main.c | 14 ++++++++--- 3 files changed, 76 insertions(+), 12 deletions(-) diff --git a/ivlpp/globals.h b/ivlpp/globals.h index bb4b644e9..59a5ae5f6 100644 --- a/ivlpp/globals.h +++ b/ivlpp/globals.h @@ -19,12 +19,12 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #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 # include -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); /* These variables contain the include directories to be searched when @@ -40,6 +40,9 @@ extern int yyparse(); /* * $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 * Add include path and line directives. * diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index d694216b1..3256ede39 100644 --- a/ivlpp/lexor.lex +++ b/ivlpp/lexor.lex @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #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 # include @@ -60,6 +60,7 @@ struct include_stack_t { 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*standby = 0; @@ -469,12 +470,18 @@ static void do_include() 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() { int line_mask_flag = 0; struct include_stack_t*isp = istack; istack = isp->next; + /* Delete the current input buffers, and free the cell. */ yy_delete_buffer(YY_CURRENT_BUFFER); if (isp->file) { fclose(isp->file); @@ -492,13 +499,41 @@ static int yywrap() } free(isp); - if (istack == 0) - return 1; + /* If I am out if include stack, the main input is + 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); if (line_direct_flag && istack->path && !line_mask_flag) fprintf(yyout, "#line \"%s\" %u\n", istack->path, istack->lineno); + return 0; } @@ -507,14 +542,16 @@ static int yywrap() * opened, and the lexor is initialized. The include stack is cleared * 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)); - isp->path = strdup(path); - isp->file = fopen(path, "r"); + isp->path = strdup(paths[0]); + isp->file = fopen(paths[0], "r"); isp->str = 0; if (isp->file == 0) { - perror(path); + perror(paths[0]); exit(1); } @@ -525,4 +562,20 @@ void reset_lexor(FILE*out, const char*path) assert(istack == 0); istack = isp; 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; + } } diff --git a/ivlpp/main.c b/ivlpp/main.c index 83941856e..42b8f7881 100644 --- a/ivlpp/main.c +++ b/ivlpp/main.c @@ -17,7 +17,7 @@ const char COPYRIGHT[] = * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #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 const char NOTICE[] = @@ -109,7 +109,7 @@ int main(int argc, char*argv[]) flag_errors += 1; if (flag_errors) { - fprintf(stderr, "\nUsage: %s [-v][-L][-I][-D] \n" + fprintf(stderr, "\nUsage: %s [-v][-L][-I][-D] ...\n" " -D - Predefine a value.\n" " -I - Add an include file search directory\n" " -L - Emit line number directives\n" @@ -129,12 +129,20 @@ int main(int argc, char*argv[]) 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(); } /* * $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 * Add include path and line directives. *