diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 521 |
1 files changed, 279 insertions, 242 deletions
@@ -39,6 +39,7 @@ char copyright[] = #include "flexdef.h" #include "version.h" +#include "options.h" static char flex_version[] = FLEX_VERSION; @@ -244,10 +245,10 @@ void check_options() yytext_is_array = false; } - if ( C_plus_plus && (reentrant || reentrant_bison_pure) ) + if ( C_plus_plus && (reentrant || reentrant_bison_pure) ) flexerror( _( "Options -+ and -R are mutually exclusive." ) ); - - + + if ( useecs ) { /* Set up doubly-linked equivalence classes. */ @@ -362,7 +363,7 @@ void check_options() if ( do_yylineno ) GEN_PREFIX( "lineno" ); - + if ( do_yylineno && reentrant) outn ( "#define YY_USE_LINENO 1"); } @@ -461,12 +462,12 @@ int exit_status; putc( 'p', stderr ); if ( performance_report > 1 ) putc( 'p', stderr ); - if ( spprdflt ) + if ( spprdflt ) putc( 's', stderr ); - if ( reentrant ) + if ( reentrant ) { putc( 'R', stderr ); - + if( reentrant_bison_pure ) putc( 'b', stderr ); } @@ -629,8 +630,9 @@ void flexinit( argc, argv ) int argc; char **argv; { - int i, sawcmpflag; + int i, sawcmpflag, rv, optind; char *arg; + scanopt_t sopt; printstats = syntaxerror = trace = spprdflt = caseins = false; lex_compat = C_plus_plus = backing_up_report = ddebug = fulltbl = false; @@ -662,240 +664,275 @@ char **argv; C_plus_plus = true; /* read flags */ - for ( --argc, ++argv; argc ; --argc, ++argv ) - { - arg = argv[0]; - - /* Stop at first non-option. */ - if ( arg[0] != '-' || arg[1] == '\0' ) - break; - - if ( arg[1] == '-' ) - { /* --option */ - if ( ! strcmp( arg, "--help" ) ) - arg = "-h"; - - else if ( ! strcmp( arg, "--version" ) ) - arg = "-V"; - - else if ( ! strcmp( arg, "--" ) ) - { /* end of options */ - --argc; - ++argv; - break; - } - } + sopt = scanopt_init(flexopts, argc, argv, 0); + if (!sopt) { + /* This will only happen when flexopts array is altered. */ + fprintf(stderr, + _("Internal error. flexopts are malformed.\n")); + exit(1); + } + + while((rv=scanopt(sopt, &arg, &optind)) != 0){ + + if (rv < 0) { + /* Scanopt has already printed an option-specific error message. */ + fprintf( stderr, _( "For usage, try\n\t%s --help\n" ), + program_name ); + exit( 1 ); + break; + } - for ( i = 1; arg[i] != '\0'; ++i ) - switch ( arg[i] ) - { - case '+': - C_plus_plus = true; - break; - - case 'B': - interactive = false; - break; - - case 'b': - backing_up_report = true; - break; - - case 'c': - break; - - case 'C': - if ( i != 1 ) - flexerror( - _( "-C flag must be given separately" ) ); - - if ( ! sawcmpflag ) - { - useecs = false; - usemecs = false; - fulltbl = false; - sawcmpflag = true; - } - - for ( ++i; arg[i] != '\0'; ++i ) - switch ( arg[i] ) - { - case 'a': - long_align = - true; - break; - - case 'e': - useecs = true; - break; - - case 'F': - fullspd = true; - break; - - case 'f': - fulltbl = true; - break; - - case 'm': - usemecs = true; - break; - - case 'r': - use_read = true; - break; - - default: - lerrif( - _( "unknown -C option '%c'" ), - (int) arg[i] ); - break; - } - - goto get_next_arg; - - case 'd': - ddebug = true; - break; - - case 'f': - useecs = usemecs = false; - use_read = fulltbl = true; - break; - - case 'F': - useecs = usemecs = false; - use_read = fullspd = true; - break; - - case '?': - case 'h': - usage(); - exit( 0 ); - - case 'I': - interactive = true; - break; - - case 'i': - caseins = true; - break; - - case 'l': - lex_compat = true; - break; - - case 'L': - gen_line_dirs = false; - break; - - case 'n': - /* Stupid do-nothing deprecated - * option. - */ - break; - - case 'o': - if ( i != 1 ) - flexerror( - _( "-o flag must be given separately" ) ); - - outfilename = arg + i + 1; - did_outfilename = 1; - goto get_next_arg; - - case 'P': - if ( i != 1 ) - flexerror( - _( "-P flag must be given separately" ) ); - - prefix = arg + i + 1; - goto get_next_arg; - - case 'p': - ++performance_report; - break; - - case 'R': - if ( i != 1 ) - flexerror( - _( "-R flag must be given separately" ) ); + switch ((enum flexopt_flag_t)rv){ + case OPT_CPLUSPLUS: + C_plus_plus = true; + break; + + case OPT_BATCH: + interactive = false; + break; + + case OPT_BACKUP: + backing_up_report = true; + break; + + case OPT_DEPRECATED: + flexerror(_("Options -c and -n are deprecated. Do not use.")); + break; + + case OPT_COMPRESSION: + if ( ! sawcmpflag ) + { + useecs = false; + usemecs = false; + fulltbl = false; + sawcmpflag = true; + } + + for( i=0 ; arg && arg[i] != '\0'; i++) + switch ( arg[i] ) + { + case 'a': + long_align = true; + break; + + case 'e': + useecs = true; + break; + + case 'F': + fullspd = true; + break; + + case 'f': + fulltbl = true; + break; + + case 'm': + usemecs = true; + break; + + case 'r': + use_read = true; + break; + + default: + lerrif( + _( "unknown -C option '%c'" ), + (int) arg[i] ); + break; + } + break; + + case OPT_DEBUG: + ddebug = true; + break; + + case OPT_FULL: + useecs = usemecs = false; + use_read = fulltbl = true; + break; + + case OPT_FAST: + useecs = usemecs = false; + use_read = fullspd = true; + break; + + case OPT_HELP: + usage(); + exit( 0 ); + + case OPT_INTERACTIVE: + interactive = true; + break; + + case OPT_CASE_INSENSITIVE: + caseins = true; + break; + + case OPT_LEX_COMPAT: + lex_compat = true; + break; + + case OPT_MAIN: + action_define( "YY_MAIN", 1); + break; + + case OPT_NOLINE: + gen_line_dirs = false; + break; + + case OPT_OUTFILE: + outfilename = arg; + did_outfilename = 1; + break; + + case OPT_PREFIX: + prefix = arg; + break; + + case OPT_PERF_REPORT: + ++performance_report; + break; + + case OPT_REENTRANT_BISON: + reentrant = true; + reentrant_bison_pure = true; + break; + + case OPT_REENTRANT: reentrant = true; - - /* Optional arguments follow -R */ - - for ( ++i; arg[i] != '\0'; ++i ) - switch ( arg[i] ) - { - case 'b': - reentrant_bison_pure = true; - break; - - default: - lerrif( - _( "unknown -R option '%c'" ), - (int) arg[i] ); - break; - } - goto get_next_arg; - - case 'S': - if ( i != 1 ) - flexerror( - _( "-S flag must be given separately" ) ); - - skelname = arg + i + 1; - goto get_next_arg; - - case 's': - spprdflt = true; - break; - - case 't': - use_stdout = true; - break; - - case 'T': - trace = true; - break; - - case 'v': - printstats = true; - break; - - case 'V': - printf( _( "%s version %s\n" ), - program_name, flex_version ); - exit( 0 ); - - case 'w': - nowarn = true; - break; - - case '7': - csize = 128; - break; - - case '8': - csize = CSIZE; - break; - - default: - fprintf( stderr, - _( "%s: unknown flag '%c'. For usage, try\n\t%s --help\n" ), - program_name, (int) arg[i], - program_name ); - exit( 1 ); - } - - /* Used by -C, -S, -o, and -P flags in lieu of a "continue 2" - * control. - */ - get_next_arg: ; - } - num_input_files = argc; - input_files = argv; + /* Optional 'b' follows -R */ + if (arg) { + if (strcmp(arg,"b")==0) + reentrant_bison_pure = true; + else + lerrif(_( "unknown -R option '%c'" ),(int)arg[i]); + } + break; + + case OPT_SKEL: + skelname = arg; + break; + + case OPT_DEFAULT: + spprdflt = false; + break; + + case OPT_NODEFAULT: + spprdflt = true; + break; + + case OPT_STDOUT: + use_stdout = true; + break; + + case OPT_TRACE: + trace = true; + break; + + case OPT_VERBOSE: + printstats = true; + break; + + case OPT_VERSION: + printf( _( "%s version %s\n" ), + program_name, flex_version ); + exit( 0 ); + + case OPT_NOWARN: + nowarn = true; + break; + + case OPT_7BIT: + csize = 128; + break; + + case OPT_8BIT: + csize = CSIZE; + break; + + case OPT_ALIGN: + long_align = true; + break; + + case OPT_ALWAYS_INTERACTIVE: + action_define("YY_ALWAYS_INTERACTIVE", 1); + break; + + case OPT_NEVER_INTERACTIVE: + action_define( "YY_NEVER_INTERACTIVE", 1 ); + break; + + case OPT_ARRAY: + yytext_is_array = true; + break; + + case OPT_POINTER: + yytext_is_array = false; + break; + + case OPT_ECS: + useecs = true; + break; + + case OPT_HEADER: /*TODO*/ + break; + + case OPT_META_ECS: + usemecs = true; + + + case OPT_PREPROCDEFINE: + { + /* arg is "symbol" or "symbol=definition". + Replace the first '=' with ' '. + I'm not sure that argv[] is writable. So use a copy. */ + char *sym, *p; + sym = (char*)malloc(strlen("#define ")+strlen(arg)+1); + sprintf(sym,"#define %s\n",arg); + for(p=sym; *p != '\0'; ++p) + if (*p == '='){ + *p = ' '; + break; + } + + add_action(sym); + free(sym); + } + break; + + case OPT_READ: + use_read = true; + break; + + case OPT_STACK: + action_define( "YY_STACK_USED", 1 ); + break; + + case OPT_STDINIT: + do_stdinit = true; + break; + + case OPT_YYCLASS: + yyclass = arg; + break; + + case OPT_YYLINENO: + do_yylineno = true; + break; + + case OPT_YYWRAP: + do_yywrap = true; + break; + + } /* switch */ + } /* while scanopt() */ + + scanopt_destroy(sopt); + + num_input_files = argc - optind; + input_files = argv + optind; set_input_file( num_input_files > 0 ? input_files[0] : NULL ); lastccl = lastsc = lastdfa = lastnfa = 0; @@ -1040,7 +1077,7 @@ _( "Variable trailing context rules entail a large performance penalty\n" ) ); } else - { + { /* In reentrant scanner, stdinit is handled in flex.skl. */ if ( do_stdinit ) { @@ -1065,7 +1102,7 @@ _( "Variable trailing context rules entail a large performance penalty\n" ) ); outn( "#endif" ); } - else + else { outn( "#ifndef YY_REENTRANT" ); outn( yy_nostdinit ); @@ -1102,7 +1139,7 @@ _( "Variable trailing context rules entail a large performance penalty\n" ) ); "\tLexerError( \"yyFlexLexer::yylex invoked but %option yyclass used\" );" ); outn( "\treturn 0;" ); outn( "\t}" ); - + out_str( "\n#define YY_DECL int %s::yylex()\n", yyclass ); } |