void flexinit(int argc, char **argv) { int i, sawcmpflag; char *arg, *flex_gettime(), *mktemp(); printstats = syntaxerror = trace = spprdflt = interactive = caseins = false; backtrack_report = performance_report = ddebug = fulltbl = fullspd = false; yymore_used = continued_action = reject = false; yymore_really_used = reject_really_used = false; gen_line_dirs = usemecs = useecs = true; sawcmpflag = false; use_stdout = false; csize = DEFAULT_CSIZE; program_name = argv[0]; /* read flags */ for ( --argc, ++argv; argc ; --argc, ++argv ) { if ( argv[0][0] != '-' || argv[0][1] == '\0' ) break; arg = argv[0]; for ( i = 1; arg[i] != '\0'; ++i ) switch ( arg[i] ) { case 'b': backtrack_report = true; break; case 'c': fprintf( stderr, "%s: Assuming use of deprecated -c flag is really intended to be -C\n", program_name ); /* fall through */ 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 'e': useecs = true; break; case 'F': fullspd = true; break; case 'f': fulltbl = true; break; case 'm': usemecs = 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; fulltbl = true; break; case 'F': useecs = usemecs = false; fullspd = true; break; case 'I': interactive = true; break; case 'i': caseins = true; break; case 'L': gen_line_dirs = false; break; case 'n': /* stupid do-nothing deprecated option */ break; case 'p': performance_report = true; break; 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 '8': csize = CSIZE; break; default: lerrif( "unknown flag '%c'", (int) arg[i] ); break; } get_next_arg: /* used by -C and -S flags in lieu of a "continue 2" control */ ; } if ( (fulltbl || fullspd) && usemecs ) flexerror( "full table and -Cm don't make sense together" ); if ( (fulltbl || fullspd) && interactive ) flexerror( "full table and -I are (currently) incompatible" ); if ( fulltbl && fullspd ) flexerror( "full table and -F are mutually exclusive" ); if ( ! skelname ) { static char skeleton_name_storage[400]; skelname = skeleton_name_storage; (void) strcpy( skelname, ENQUOTE(DEFAULT_SKELETON_FILE) ); } if ( ! use_stdout ) { FILE *prev_stdout = freopen( outfile, "w", stdout ); if ( prev_stdout == NULL ) lerrsf( "could not create %s", outfile ); outfile_created = 1; } num_input_files = argc; input_files = argv; set_input_file( num_input_files > 0 ? input_files[0] : NULL ); if ( backtrack_report ) { #ifndef SHORT_FILE_NAMES backtrack_file = fopen( "lex.backtrack", "w" ); #else backtrack_file = fopen( "lex.bck", "w" ); #endif if ( backtrack_file == NULL ) flexerror( "could not create lex.backtrack" ); } else backtrack_file = NULL; lastccl = 0; lastsc = 0; /* initialize the statistics */ starttime = flex_gettime(); if ( (skelfile = fopen( skelname, "r" )) == NULL ) lerrsf( "can't open skeleton file %s", skelname ); epicsTempName ( action_file_name, sizeof ( action_file_name ) ); if ( action_file_name[0] == '\0' ) { lerrsf( "can't create temporary file name", "" ); } if ( ( temp_action_file = fopen ( action_file_name, "w" ) ) == NULL ) lerrsf( "can't open temporary action file %s", action_file_name ); lastdfa = lastnfa = num_rules = numas = numsnpairs = tmpuses = 0; numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst = 0; numuniq = numdup = hshsave = eofseen = datapos = dataline = 0; num_backtracking = onesp = numprots = 0; variable_trailing_context_rules = bol_needed = false; linenum = sectnum = 1; firstprot = NIL; /* used in mkprot() so that the first proto goes in slot 1 * of the proto queue */ lastprot = 1; if ( useecs ) { /* set up doubly-linked equivalence classes */ /* We loop all the way up to csize, since ecgroup[csize] is the * position used for NUL characters */ ecgroup[1] = NIL; for ( i = 2; i <= csize; ++i ) { ecgroup[i] = i - 1; nextecm[i - 1] = i; } nextecm[csize] = NIL; } else { /* put everything in its own equivalence class */ for ( i = 1; i <= csize; ++i ) { ecgroup[i] = i; nextecm[i] = BAD_SUBSCRIPT; /* to catch errors */ } } set_up_initial_allocations(); }
void flexinit(int argc, char **argv) { int i, sawcmpflag; char *arg; printstats = syntaxerror = trace = spprdflt = caseins = false; lex_compat = C_plus_plus = backing_up_report = ddebug = fulltbl = false; fullspd = long_align = nowarn = yymore_used = continued_action = false; do_yylineno = yytext_is_array = in_rule = reject = do_stdinit = false; yymore_really_used = reject_really_used = unspecified; interactive = csize = unspecified; do_yywrap = gen_line_dirs = usemecs = useecs = true; performance_report = 0; did_outfilename = 0; prefix = "yy"; yyclass = NULL; use_read = use_stdout = false; sawcmpflag = false; /* Initialize dynamic array for holding the rule actions. */ action_size = 2048; /* default size of action array in bytes */ action_array = allocate_character_array( action_size ); defs1_offset = prolog_offset = action_offset = action_index = 0; action_array[0] = '\0'; program_name = argv[0]; if ( program_name[0] != '\0' && program_name[strlen( program_name ) - 1] == '+' ) C_plus_plus = true; /* read flags */ for ( --argc, ++argv; argc ; --argc, ++argv ) { arg = argv[0]; 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; } } 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 '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; set_input_file( num_input_files > 0 ? input_files[0] : NULL ); lastccl = lastsc = lastdfa = lastnfa = 0; num_rules = num_eof_rules = default_rule = 0; numas = numsnpairs = tmpuses = 0; numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst = 0; numuniq = numdup = hshsave = eofseen = datapos = dataline = 0; num_backing_up = onesp = numprots = 0; variable_trailing_context_rules = bol_needed = false; out_linenum = linenum = sectnum = 1; firstprot = NIL; /* Used in mkprot() so that the first proto goes in slot 1 * of the proto queue. */ lastprot = 1; set_up_initial_allocations(); }
void flexinit (int argc, char **argv) { int i, sawcmpflag, rv, optind; char *arg; scanopt_t sopt; printstats = syntaxerror = trace = spprdflt = false; lex_compat = posix_compat = C_plus_plus = backing_up_report = ddebug = fulltbl = false; fullspd = long_align = nowarn = yymore_used = continued_action = false; do_yylineno = yytext_is_array = in_rule = reject = do_stdinit = false; yymore_really_used = reject_really_used = unspecified; interactive = csize = unspecified; do_yywrap = gen_line_dirs = usemecs = useecs = true; reentrant = bison_bridge_lval = bison_bridge_lloc = false; performance_report = 0; did_outfilename = 0; prefix = "yy"; yyclass = 0; use_read = use_stdout = false; tablesext = tablesverify = false; gentables = true; tablesfilename = tablesname = NULL; sawcmpflag = false; /* Initialize dynamic array for holding the rule actions. */ action_size = 2048; /* default size of action array in bytes */ action_array = allocate_character_array (action_size); defs1_offset = prolog_offset = action_offset = action_index = 0; action_array[0] = '\0'; /* Initialize any buffers. */ buf_init (&userdef_buf, sizeof (char)); /* one long string */ buf_init (&defs_buf, sizeof (char *)); /* list of strings */ buf_init (&yydmap_buf, sizeof (char)); /* one long string */ buf_init (&top_buf, sizeof (char)); /* one long string */ { const char * m4defs_init_str[] = {"m4_changequote\n", "m4_changequote([[, ]])\n"}; buf_init (&m4defs_buf, sizeof (char *)); buf_append (&m4defs_buf, &m4defs_init_str, 2); } sf_init (); /* initialize regex lib */ flex_init_regex(); /* Enable C++ if program name ends with '+'. */ program_name = basename (argv[0]); if (program_name != NULL && program_name[strlen (program_name) - 1] == '+') C_plus_plus = true; /* read flags */ 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")); FLEX_EXIT (1); } while ((rv = scanopt (sopt, &arg, &optind)) != 0) { if (rv < 0) { /* Scanopt has already printed an option-specific error message. */ fprintf (stderr, _ ("Try `%s --help' for more information.\n"), program_name); FLEX_EXIT (1); } 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_DONOTHING: 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: lerr (_ ("unknown -C option '%c'"), arg[i]); break; } break; case OPT_DEBUG: ddebug = true; break; case OPT_NO_DEBUG: ddebug = false; 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 (); FLEX_EXIT (0); case OPT_INTERACTIVE: interactive = true; break; case OPT_CASE_INSENSITIVE: sf_set_case_ins(true); break; case OPT_LEX_COMPAT: lex_compat = true; break; case OPT_POSIX_COMPAT: posix_compat = true; break; case OPT_PREPROC_LEVEL: preproc_level = (int) strtol(arg,NULL,0); break; case OPT_MAIN: buf_strdefine (&userdef_buf, "YY_MAIN", "1"); do_yywrap = false; break; case OPT_NO_MAIN: buf_strdefine (&userdef_buf, "YY_MAIN", "0"); break; case OPT_NO_LINE: 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_BISON_BRIDGE: bison_bridge_lval = true; break; case OPT_BISON_BRIDGE_LOCATIONS: bison_bridge_lval = bison_bridge_lloc = true; break; case OPT_REENTRANT: reentrant = true; break; case OPT_NO_REENTRANT: reentrant = false; break; case OPT_SKEL: skelname = arg; break; case OPT_DEFAULT: spprdflt = false; break; case OPT_NO_DEFAULT: spprdflt = true; break; case OPT_STDOUT: use_stdout = true; break; case OPT_NO_UNISTD_H: //buf_strdefine (&userdef_buf, "YY_NO_UNISTD_H", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_UNISTD_H",0); break; case OPT_TABLES_FILE: tablesext = true; tablesfilename = arg; break; case OPT_TABLES_VERIFY: tablesverify = true; break; case OPT_TRACE: trace = true; break; case OPT_VERBOSE: printstats = true; break; case OPT_VERSION: printf (_("%s %s\n"), program_name, flex_version); FLEX_EXIT (0); case OPT_WARN: nowarn = false; break; case OPT_NO_WARN: nowarn = true; break; case OPT_7BIT: csize = 128; break; case OPT_8BIT: csize = CSIZE; break; case OPT_ALIGN: long_align = true; break; case OPT_NO_ALIGN: long_align = false; break; case OPT_ALWAYS_INTERACTIVE: buf_m4_define (&m4defs_buf, "M4_YY_ALWAYS_INTERACTIVE", 0); break; case OPT_NEVER_INTERACTIVE: buf_m4_define( &m4defs_buf, "M4_YY_NEVER_INTERACTIVE", 0); 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_NO_ECS: useecs = false; break; case OPT_HEADER_FILE: headerfilename = arg; break; case OPT_META_ECS: usemecs = true; break; case OPT_NO_META_ECS: usemecs = false; break; case OPT_PREPROCDEFINE: { /* arg is "symbol" or "symbol=definition". */ char *def; for (def = arg; *def != '\0' && *def != '='; ++def) ; buf_strappend (&userdef_buf, "#define "); if (*def == '\0') { buf_strappend (&userdef_buf, arg); buf_strappend (&userdef_buf, " 1\n"); } else { buf_strnappend (&userdef_buf, arg, (int) (def - arg)); buf_strappend (&userdef_buf, " "); buf_strappend (&userdef_buf, def + 1); buf_strappend (&userdef_buf, "\n"); } } break; case OPT_READ: use_read = true; break; case OPT_STACK: //buf_strdefine (&userdef_buf, "YY_STACK_USED", "1"); buf_m4_define( &m4defs_buf, "M4_YY_STACK_USED",0); break; case OPT_STDINIT: do_stdinit = true; break; case OPT_NO_STDINIT: do_stdinit = false; break; case OPT_YYCLASS: yyclass = arg; break; case OPT_YYLINENO: do_yylineno = true; break; case OPT_NO_YYLINENO: do_yylineno = false; break; case OPT_YYWRAP: do_yywrap = true; break; case OPT_NO_YYWRAP: do_yywrap = false; break; case OPT_YYMORE: yymore_really_used = true; break; case OPT_NO_YYMORE: yymore_really_used = false; break; case OPT_REJECT: reject_really_used = true; break; case OPT_NO_REJECT: reject_really_used = false; break; case OPT_NO_YY_PUSH_STATE: //buf_strdefine (&userdef_buf, "YY_NO_PUSH_STATE", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_PUSH_STATE",0); break; case OPT_NO_YY_POP_STATE: //buf_strdefine (&userdef_buf, "YY_NO_POP_STATE", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_POP_STATE",0); break; case OPT_NO_YY_TOP_STATE: //buf_strdefine (&userdef_buf, "YY_NO_TOP_STATE", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_TOP_STATE",0); break; case OPT_NO_UNPUT: //buf_strdefine (&userdef_buf, "YY_NO_UNPUT", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_UNPUT",0); break; case OPT_NO_YY_SCAN_BUFFER: //buf_strdefine (&userdef_buf, "YY_NO_SCAN_BUFFER", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_BUFFER",0); break; case OPT_NO_YY_SCAN_BYTES: //buf_strdefine (&userdef_buf, "YY_NO_SCAN_BYTES", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_BYTES",0); break; case OPT_NO_YY_SCAN_STRING: //buf_strdefine (&userdef_buf, "YY_NO_SCAN_STRING", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_STRING",0); break; case OPT_NO_YYGET_EXTRA: //buf_strdefine (&userdef_buf, "YY_NO_GET_EXTRA", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_EXTRA",0); break; case OPT_NO_YYSET_EXTRA: //buf_strdefine (&userdef_buf, "YY_NO_SET_EXTRA", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_EXTRA",0); break; case OPT_NO_YYGET_LENG: //buf_strdefine (&userdef_buf, "YY_NO_GET_LENG", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LENG",0); break; case OPT_NO_YYGET_TEXT: //buf_strdefine (&userdef_buf, "YY_NO_GET_TEXT", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_TEXT",0); break; case OPT_NO_YYGET_LINENO: //buf_strdefine (&userdef_buf, "YY_NO_GET_LINENO", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LINENO",0); break; case OPT_NO_YYSET_LINENO: //buf_strdefine (&userdef_buf, "YY_NO_SET_LINENO", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LINENO",0); break; case OPT_NO_YYGET_IN: //buf_strdefine (&userdef_buf, "YY_NO_GET_IN", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_IN",0); break; case OPT_NO_YYSET_IN: //buf_strdefine (&userdef_buf, "YY_NO_SET_IN", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_IN",0); break; case OPT_NO_YYGET_OUT: //buf_strdefine (&userdef_buf, "YY_NO_GET_OUT", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_OUT",0); break; case OPT_NO_YYSET_OUT: //buf_strdefine (&userdef_buf, "YY_NO_SET_OUT", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_OUT",0); break; case OPT_NO_YYGET_LVAL: //buf_strdefine (&userdef_buf, "YY_NO_GET_LVAL", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LVAL",0); break; case OPT_NO_YYSET_LVAL: //buf_strdefine (&userdef_buf, "YY_NO_SET_LVAL", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LVAL",0); break; case OPT_NO_YYGET_LLOC: //buf_strdefine (&userdef_buf, "YY_NO_GET_LLOC", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LLOC",0); break; case OPT_NO_YYSET_LLOC: //buf_strdefine (&userdef_buf, "YY_NO_SET_LLOC", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LLOC",0); break; case OPT_HEX: trace_hex = 1; break; case OPT_NO_SECT3_ESCAPE: no_section3_escape = 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; num_rules = num_eof_rules = default_rule = 0; numas = numsnpairs = tmpuses = 0; numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst = 0; numuniq = numdup = hshsave = eofseen = datapos = dataline = 0; num_backing_up = onesp = numprots = 0; variable_trailing_context_rules = bol_needed = false; linenum = sectnum = 1; firstprot = NIL; /* Used in mkprot() so that the first proto goes in slot 1 * of the proto queue. */ lastprot = 1; set_up_initial_allocations (); }