diff --git a/src/scan.l b/src/scan.l index 225a2f9b7..db6ce7231 100644 --- a/src/scan.l +++ b/src/scan.l @@ -43,13 +43,24 @@ extern bool tablesverify, tablesext; extern int trlcontxt; /* Set in parse.y for each rule. */ extern const char *escaped_qstart, *escaped_qend; + +static bool write_to_buf; #define M4QSTART "[""[" #define M4QEND "]""]" #define ESCAPED_QSTART "[" M4QEND M4QSTART "[" M4QEND M4QSTART #define ESCAPED_QEND M4QEND "]" M4QSTART M4QEND "]" M4QSTART -#define ACTION_ECHO do add_action(yytext); while(0) +#define ACTION_ECHO \ + do \ + if (strlen(yytext) != yyleng) \ + synerr(_( "NUL character in input file")); \ + else if (write_to_buf) \ + buf_strnappend(&top_buf, yytext, yyleng); \ + else \ + add_action(yytext); \ + while(0) + #define ACTION_IFDEF(def, should_define) \ do if (should_define) action_define(def, 1); while (0) @@ -175,6 +186,7 @@ M4QEND "]""]" ++linenum; buf_linedir( &top_buf, infilename?infilename:"", linenum); brace_depth = 1; + write_to_buf = true; yy_push_state(CODEBLOCK_MATCH_BRACE); } @@ -226,19 +238,13 @@ M4QEND "]""]" { /* */ [^\[\]\*\n]* ACTION_ECHO; . ACTION_ECHO; - - {NL} ++linenum; ACTION_ECHO; -} -{ - "*/" add_action("*/]""]"); yy_pop_state(); -} -{ "*"{INVALID_ESCAPED_NEWLINE}+"/" { synerr(_("Escaped newline in comment end sequence\n")); } - - "*/" ACTION_ECHO; yy_pop_state(); + {NL} ++linenum; ACTION_ECHO; } +"*/" add_action("*/]""]"); yy_pop_state(); +"*/" ACTION_ECHO; yy_pop_state(); { /* This is the same as COMMENT, but is discarded rather than output. */ @@ -291,6 +297,7 @@ M4QEND "]""]" { "}" { if( --brace_depth == 0){ + write_to_buf = false; /* TODO: Matched. */ yy_pop_state(); }else @@ -309,9 +316,6 @@ M4QEND "]""]" {M4QSTART} buf_strnappend(&top_buf, escaped_qstart, (int) strlen(escaped_qstart)); {M4QEND} buf_strnappend(&top_buf, escaped_qend, (int) strlen(escaped_qend)); - ([^{}\r\n\[\]]+)|[^{}\r\n] { - buf_strnappend(&top_buf, yytext, yyleng); - } <> { linenum = brace_start_line; @@ -909,13 +913,6 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ } } { - "/"{INVALID_ESCAPED_NEWLINE}+"*" { - synerr(_("Invalid escaped newline in comment-open-sequence")); - ACTION_ECHO; - yy_push_state(CODE_COMMENT); - } - "/*" ACTION_ECHO; yy_push_state(CODE_COMMENT); - "reject" { ACTION_ECHO; CHECK_REJECT(yytext); @@ -924,6 +921,16 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ ACTION_ECHO; CHECK_YYMORE(yytext); } +} + +{ + "/"{INVALID_ESCAPED_NEWLINE}+"*" { + synerr(_("Invalid escaped newline in comment-open-sequence")); + ACTION_ECHO; + yy_push_state(CODE_COMMENT); + } + "/*" ACTION_ECHO; yy_push_state(CODE_COMMENT); + [^[:alpha:]_{}""''/\n\[\]]+ ACTION_ECHO; {NAME} ACTION_ECHO; "'"([^''\\\n]|\\.)"'" ACTION_ECHO; /* character constant */