diff options
Diffstat (limited to 'src/scan.l')
-rw-r--r-- | src/scan.l | 91 |
1 files changed, 36 insertions, 55 deletions
@@ -59,7 +59,7 @@ extern const char *escaped_qstart, *escaped_qend; #define MARK_END_OF_PROLOG mark_prolog(); #define YY_DECL \ - int flexscan() + int flexscan(void) #define RETURNCHAR \ yylval = (unsigned char) yytext[0]; \ @@ -135,7 +135,7 @@ M4QEND "]]" int doing_codeblock = false; int i, brace_depth=0, brace_start_line=0; - Char nmdef[MAXLINE]; + char nmdef[MAXLINE]; <INITIAL>{ @@ -146,7 +146,7 @@ M4QEND "]]" ^"%x"{NAME}? return XSCDECL; ^"%{".*{NL} { ++linenum; - line_directive_out( (FILE *) 0, 1 ); + line_directive_out(NULL, 1); indented_code = false; BEGIN(CODEBLOCK); } @@ -166,7 +166,7 @@ M4QEND "]]" sectnum = 2; bracelevel = 0; mark_defs1(); - line_directive_out( (FILE *) 0, 1 ); + line_directive_out(NULL, 1); BEGIN(SECT2PROLOG); return SECTEND; } @@ -174,7 +174,7 @@ M4QEND "]]" ^"%pointer".*{NL} yytext_is_array = false; ++linenum; ^"%array".*{NL} yytext_is_array = true; ++linenum; - ^"%option" BEGIN(OPTION); return OPTION_OP; + ^"%option" BEGIN(OPTION); return TOK_OPTION; ^"%"{LEXOPT}{OPTWS}[[:digit:]]*{OPTWS}{NL} ++linenum; /* ignore */ ^"%"{LEXOPT}{WS}.*{NL} ++linenum; /* ignore */ @@ -231,8 +231,8 @@ M4QEND "]]" [[:digit:]]+ linenum = myctoi( yytext ); \"[^"\n]*\" { - flex_free( (void *) infilename ); - infilename = copy_string( yytext + 1 ); + free(infilename); + infilename = xstrdup(yytext + 1); infilename[strlen( infilename ) - 1] = '\0'; } . /* ignore spurious characters */ @@ -272,8 +272,8 @@ M4QEND "]]" buf_strnappend(&top_buf, yytext, yyleng); } - {M4QSTART} buf_strnappend(&top_buf, escaped_qstart, strlen(escaped_qstart)); - {M4QEND} buf_strnappend(&top_buf, escaped_qend, strlen(escaped_qend)); + {M4QSTART} buf_strnappend(&top_buf, escaped_qstart, (int) strlen(escaped_qstart)); + {M4QEND} buf_strnappend(&top_buf, escaped_qend, (int) strlen(escaped_qend)); [^{}\r\n] { buf_strnappend(&top_buf, yytext, yyleng); @@ -293,7 +293,7 @@ M4QEND "]]" {NOT_WS}[^\r\n]* { if(yyleng < MAXLINE) { - strcpy( (char *) nmdef, yytext ); + strcpy( nmdef, yytext ); } else { @@ -301,7 +301,7 @@ M4QEND "]]" FLEX_EXIT(EXIT_FAILURE); } /* Skip trailing whitespace. */ - for ( i = strlen( (char *) nmdef ) - 1; + for ( i = strlen( nmdef ) - 1; i >= 0 && (nmdef[i] == ' ' || nmdef[i] == '\t'); --i ) ; @@ -421,12 +421,12 @@ M4QEND "]]" yyget_lloc ACTION_M4_IFDEF("M4""_YY_NO_GET_LLOC", ! option_sense); yyset_lloc ACTION_M4_IFDEF("M4""_YY_NO_SET_LLOC", ! option_sense); - extra-type return OPT_EXTRA_TYPE; - outfile return OPT_OUTFILE; - prefix return OPT_PREFIX; - yyclass return OPT_YYCLASS; - header(-file)? return OPT_HEADER; - tables-file return OPT_TABLES; + extra-type return TOK_EXTRA_TYPE; + outfile return TOK_OUTFILE; + prefix return TOK_PREFIX; + yyclass return TOK_YYCLASS; + header(-file)? return TOK_HEADER_FILE; + tables-file return TOK_TABLES_FILE; tables-verify { tablesverify = option_sense; if(!tablesext && option_sense) @@ -528,8 +528,7 @@ M4QEND "]]" if (sf_skip_ws()){ /* We're in the middle of a (?x: ) pattern. */ /* Push back everything starting at the "|" */ - size_t amt; - amt = strchr (yytext, '|') - yytext; + int amt = (int) (strchr (yytext, '|') - yytext); yyless(amt); } else { @@ -628,7 +627,7 @@ M4QEND "]]" * The reason it was disabled is so yacc/bison can parse * ccl operations, such as ccl difference and union. */ - && (cclval = ccllookup( (Char *) nmstr )) != 0 ) + && (cclval = ccllookup( nmstr )) != 0 ) { if ( input() != ']' ) synerr( _( "bad character class" ) ); @@ -642,7 +641,7 @@ M4QEND "]]" /* We fudge a bit. We know that this ccl will * soon be numbered as lastccl + 1 by cclinit. */ - cclinstal( (Char *) nmstr, lastccl + 1 ); + cclinstal( nmstr, lastccl + 1 ); /* Push back everything but the leading bracket * so the ccl can be rescanned. @@ -662,7 +661,7 @@ M4QEND "]]" * context. */ "{"{NAME}"}"[[:space:]]? { - Char *nmdefptr; + char *nmdefptr; int end_is_ws, end_ch; end_ch = yytext[yyleng-1]; @@ -686,7 +685,7 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ else { /* push back name surrounded by ()'s */ - int len = strlen( (char *) nmdefptr ); + int len = strlen( nmdefptr ); if (end_is_ws) unput(end_ch); @@ -694,7 +693,7 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ (len > 0 && nmdefptr[len - 1] == '$') || (end_is_ws && trlcontxt && !sf_skip_ws())) { /* don't use ()'s after all */ - PUT_BACK_STRING((char *) nmdefptr, 0); + PUT_BACK_STRING(nmdefptr, 0); if ( nmdefptr[0] == '^' ) BEGIN(CARETISBOL); @@ -703,7 +702,7 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ else { unput(')'); - PUT_BACK_STRING((char *) nmdefptr, 0); + PUT_BACK_STRING(nmdefptr, 0); unput('('); } } @@ -739,7 +738,13 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ return '('; } "(" sf_push(); return '('; - ")" sf_pop(); return ')'; + ")" { + if (_sf_top_ix > 0) { + sf_pop(); + return ')'; + } else + synerr(_("unbalanced parenthesis")); + } [/|*+?.(){}] return (unsigned char) yytext[0]; . RETURNCHAR; @@ -948,7 +953,7 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ } <SECT2,QUOTE,FIRSTCCL,CCL>{ESCSEQ} { - yylval = myesc( (Char *) yytext ); + yylval = myesc( (unsigned char *) yytext ); if ( YY_START == FIRSTCCL ) BEGIN(CCL); @@ -970,7 +975,7 @@ nmstr[yyleng - 2 - end_is_ws] = '\0'; /* chop trailing brace */ %% -int yywrap() +int yywrap(void) { if ( --num_input_files > 0 ) { @@ -985,12 +990,11 @@ int yywrap() /* set_input_file - open the given file (if NULL, stdin) for scanning */ -void set_input_file( file ) -char *file; +void set_input_file( char *file ) { if ( file && strcmp( file, "-" ) ) { - infilename = copy_string( file ); + infilename = xstrdup(file); yyin = fopen( infilename, "r" ); if ( yyin == NULL ) @@ -1000,31 +1004,8 @@ char *file; else { yyin = stdin; - infilename = copy_string( "<stdin>" ); + infilename = xstrdup("<stdin>"); } linenum = 1; } - - -/* Wrapper routines for accessing the scanner's malloc routines. */ - -void *flex_alloc( size ) -size_t size; - { - return (void *) malloc( size ); - } - -void *flex_realloc( ptr, size ) -void *ptr; -size_t size; - { - return (void *) realloc( ptr, size ); - } - -void flex_free( ptr ) -void *ptr; - { - if ( ptr ) - free( ptr ); - } |