From 2b11f78d6345fe7334de8b03617ad712db9694b6 Mon Sep 17 00:00:00 2001 From: steve Date: Sat, 20 Jan 2001 03:10:35 +0000 Subject: [PATCH] Catch malformed include directives (PR#100) --- ivlpp/lexor.lex | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index b66962386..be09cf011 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) && !defined(macintosh) -#ident "$Id: lexor.lex,v 1.21 2000/09/13 22:33:13 steve Exp $" +#ident "$Id: lexor.lex,v 1.22 2001/01/20 03:10:35 steve Exp $" #endif # include @@ -85,6 +85,7 @@ static int comment_enter = 0; %x PPDEFINE %x CCOMMENT %x CSTRING +%x ERROR_LINE %x IFDEF_FALSE %s IFDEF_TRUE @@ -136,6 +137,14 @@ W [ \t\b\f]+ \n\r { istack->lineno += 1; yy_pop_state(); do_include(); } <> { istack->lineno += 1; yy_pop_state(); do_include(); } + /* Anything that is not matched by the above is an error of some + sort. Print and error message and absorb the rest of the line. */ +. { + fprintf(stderr, "%s:%u: error: malformed `include directive." + " Did you quote the file name?\n", istack->path, + istack->lineno+1); + error_count += 1; + BEGIN(ERROR_LINE); } /* Detect the define directive, and match the name. Match any white space that might be found, as well. After I get the @@ -208,6 +217,9 @@ W [ \t\b\f]+ . { ECHO; } \n { istack->lineno += 1; ECHO; } + /* Absorb the rest of the line when a broken directive is detected. */ +.* { yy_pop_state(); } + %% /* Defined macros are kept in this table for convenient lookup. As `define directives are matched (and the do_define() function