Annotation of src/usr.bin/lex/main.c, Revision 1.18
1.18 ! tedu 1: /* $OpenBSD: main.c,v 1.17 2015/11/19 22:35:19 tedu Exp $ */
1.2 deraadt 2:
1.1 deraadt 3: /* flex - tool to generate fast lexical analyzers */
4:
1.16 tedu 5: /* Copyright (c) 1990 The Regents of the University of California. */
6: /* All rights reserved. */
1.1 deraadt 7:
1.16 tedu 8: /* This code is derived from software contributed to Berkeley by */
9: /* Vern Paxson. */
1.1 deraadt 10:
1.16 tedu 11: /* The United States Government has rights in this work pursuant */
12: /* to contract no. DE-AC03-76SF00098 between the United States */
13: /* Department of Energy and the University of California. */
14:
15: /* This file is part of flex. */
16:
17: /* Redistribution and use in source and binary forms, with or without */
18: /* modification, are permitted provided that the following conditions */
19: /* are met: */
20:
21: /* 1. Redistributions of source code must retain the above copyright */
22: /* notice, this list of conditions and the following disclaimer. */
23: /* 2. Redistributions in binary form must reproduce the above copyright */
24: /* notice, this list of conditions and the following disclaimer in the */
25: /* documentation and/or other materials provided with the distribution. */
26:
27: /* Neither the name of the University nor the names of its contributors */
28: /* may be used to endorse or promote products derived from this software */
29: /* without specific prior written permission. */
30:
31: /* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */
32: /* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */
33: /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */
34: /* PURPOSE. */
1.18 ! tedu 35:
! 36:
1.1 deraadt 37:
38: #include "flexdef.h"
39: #include "version.h"
1.16 tedu 40: #include "options.h"
41: #include "tables.h"
1.1 deraadt 42:
43: static char flex_version[] = FLEX_VERSION;
44:
45: /* declare functions that have forward references */
46:
1.18 ! tedu 47: void flexinit PROTO((int, char **));
! 48: void readin PROTO((void));
! 49: void set_up_initial_allocations PROTO((void));
! 50: static char *basename2 PROTO((char *path, int should_strip_ext));
1.1 deraadt 51:
52:
53: /* these globals are all defined and commented in flexdef.h */
1.18 ! tedu 54: int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt;
! 55: int interactive, lex_compat, posix_compat, do_yylineno, useecs, fulltbl,
! 56: usemecs;
! 57: int fullspd, gen_line_dirs, performance_report, backing_up_report;
! 58: int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap, csize;
! 59: int reentrant, bison_bridge_lval, bison_bridge_lloc;
! 60: int yymore_used, reject, real_reject, continued_action, in_rule;
! 61: int yymore_really_used, reject_really_used;
! 62: int datapos, dataline, linenum;
! 63: FILE *skelfile = NULL;
! 64: int skel_ind = 0;
! 65: char *action_array;
! 66: int action_size, defs1_offset, prolog_offset, action_offset, action_index;
! 67: char *infilename = NULL, *outfilename = NULL, *headerfilename = NULL;
! 68: int did_outfilename;
! 69: char *prefix, *yyclass, *extra_type = NULL;
! 70: int do_stdinit, use_stdout;
! 71: int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
! 72: int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
! 73: int maximum_mns, current_mns, current_max_rules;
! 74: int num_rules, num_eof_rules, default_rule, lastnfa;
! 75: int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
! 76: int *accptnum, *assoc_rule, *state_type;
! 77: int *rule_type, *rule_linenum, *rule_useful;
! 78: int current_state_type;
! 79: int variable_trailing_context_rules;
! 80: int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
! 81: int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
! 82: int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs, tecfwd[CSIZE + 1];
! 83: int tecbck[CSIZE + 1];
! 84: int lastsc, *scset, *scbol, *scxclu, *sceof;
! 85: int current_max_scs;
! 86: char **scname;
! 87: int current_max_dfa_size, current_max_xpairs;
! 88: int current_max_template_xpairs, current_max_dfas;
! 89: int lastdfa, *nxt, *chk, *tnxt;
! 90: int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz;
1.1 deraadt 91: union dfaacc_union *dfaacc;
1.18 ! tedu 92: int *accsiz, *dhash, numas;
! 93: int numsnpairs, jambase, jamstate;
! 94: int lastccl, *cclmap, *ccllen, *cclng, cclreuse;
! 95: int current_maxccls, current_max_ccl_tbl_size;
! 96: Char *ccltbl;
! 97: char nmstr[MAXLINE];
! 98: int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
! 99: int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
! 100: int num_backing_up, bol_needed;
! 101: FILE *backing_up_file;
! 102: int end_of_buffer_state;
! 103: char **input_files;
! 104: int num_input_files;
1.16 tedu 105: jmp_buf flex_main_jmp_buf;
1.18 ! tedu 106: bool *rule_has_nl, *ccl_has_nl;
! 107: int nlch = '\n';
! 108: bool ansi_func_defs, ansi_func_protos;
1.16 tedu 109:
1.18 ! tedu 110: bool tablesext, tablesverify, gentables;
! 111: char *tablesfilename = 0, *tablesname = 0;
1.16 tedu 112: struct yytbl_writer tableswr;
1.1 deraadt 113:
114: /* Make sure program_name is initialized so we don't crash if writing
115: * out an error message before getting the program name from argv[0].
116: */
1.18 ! tedu 117: char *program_name = "flex";
1.1 deraadt 118:
119: #ifndef SHORT_FILE_NAMES
1.16 tedu 120: static const char *outfile_template = "lex.%s.%s";
121: static const char *backing_name = "lex.backup";
122: static const char *tablesfile_template = "lex.%s.tables";
1.1 deraadt 123: #else
1.16 tedu 124: static const char *outfile_template = "lex%s.%s";
125: static const char *backing_name = "lex.bck";
126: static const char *tablesfile_template = "lex%s.tbl";
1.1 deraadt 127: #endif
128:
129: #ifdef MS_DOS
130: extern unsigned _stklen = 16384;
131: #endif
132:
1.16 tedu 133: /* From scan.l */
1.18 ! tedu 134: extern FILE *yyout;
1.16 tedu 135:
1.1 deraadt 136: static char outfile_path[MAXLINE];
137: static int outfile_created = 0;
138: static char *skelname = NULL;
1.18 ! tedu 139: static int _stdout_closed = 0; /* flag to prevent double-fclose() on stdout. */
1.16 tedu 140: const char *escaped_qstart = "[[]]M4_YY_NOOP[M4_YY_NOOP[M4_YY_NOOP[[]]";
1.18 ! tedu 141: const char *escaped_qend = "[[]]M4_YY_NOOP]M4_YY_NOOP]M4_YY_NOOP[[]]";
1.16 tedu 142:
143: /* For debugging. The max number of filters to apply to skeleton. */
144: static int preproc_level = 1000;
145:
1.18 ! tedu 146: int flex_main PROTO((int argc, char *argv[]));
! 147: int main PROTO((int argc, char *argv[]));
1.16 tedu 148:
1.18 ! tedu 149: int
! 150: flex_main(argc, argv)
! 151: int argc;
! 152: char *argv[];
1.16 tedu 153: {
1.18 ! tedu 154: int i, exit_status, child_status;
1.16 tedu 155:
1.18 ! tedu 156: /*
! 157: * Set a longjmp target. Yes, I know it's a hack, but it gets worse:
! 158: * The return value of setjmp, if non-zero, is the desired exit code
! 159: * PLUS ONE. For example, if you want 'main' to return with code '2',
! 160: * then call longjmp() with an argument of 3. This is because it is
! 161: * invalid to specify a value of 0 to longjmp. FLEX_EXIT(n) should be
! 162: * used instead of exit(n);
1.16 tedu 163: */
1.18 ! tedu 164: exit_status = setjmp(flex_main_jmp_buf);
! 165: if (exit_status) {
! 166: if (stdout && !_stdout_closed && !ferror(stdout)) {
! 167: fflush(stdout);
! 168: fclose(stdout);
! 169: }
! 170: while (wait(&child_status) > 0) {
! 171: if (!WIFEXITED(child_status)
! 172: || WEXITSTATUS(child_status) != 0) {
! 173: /*
! 174: * report an error of a child
! 175: */
! 176: if (exit_status <= 1)
! 177: exit_status = 2;
1.16 tedu 178:
1.18 ! tedu 179: }
! 180: }
! 181: return exit_status - 1;
! 182: }
! 183: flexinit(argc, argv);
1.16 tedu 184:
1.18 ! tedu 185: readin();
1.16 tedu 186:
1.18 ! tedu 187: skelout();
1.16 tedu 188: /* %% [1.5] DFA */
1.18 ! tedu 189: ntod();
1.16 tedu 190:
191: for (i = 1; i <= num_rules; ++i)
192: if (!rule_useful[i] && i != default_rule)
1.18 ! tedu 193: line_warning(_("rule cannot be matched"),
! 194: rule_linenum[i]);
1.16 tedu 195:
196: if (spprdflt && !reject && rule_useful[default_rule])
1.18 ! tedu 197: line_warning(_
! 198: ("-s option given but default rule can be matched"),
! 199: rule_linenum[default_rule]);
1.1 deraadt 200:
201: /* Generate the C state transition tables from the DFA. */
1.18 ! tedu 202: make_tables();
1.1 deraadt 203:
1.18 ! tedu 204: /*
! 205: * Note, flexend does not return. It exits with its argument as
! 206: * status.
1.1 deraadt 207: */
1.18 ! tedu 208: flexend(0);
1.1 deraadt 209:
1.16 tedu 210: return 0; /* keep compilers/lint happy */
211: }
1.1 deraadt 212:
1.16 tedu 213: /* Wrapper around flex_main, so flex_main can be built as a library. */
1.18 ! tedu 214: int
! 215: main(argc, argv)
! 216: int argc;
! 217: char *argv[];
1.16 tedu 218: {
219: #if ENABLE_NLS
220: #if HAVE_LOCALE_H
1.18 ! tedu 221: setlocale(LC_MESSAGES, "");
! 222: setlocale(LC_CTYPE, "");
! 223: textdomain(PACKAGE);
! 224: bindtextdomain(PACKAGE, LOCALEDIR);
1.16 tedu 225: #endif
226: #endif
1.1 deraadt 227:
1.18 ! tedu 228: if (pledge("stdio rpath wpath cpath proc exec", NULL) == -1) {
! 229: fprintf(stderr, _("%s: pledge\n"),
! 230: program_name);
1.16 tedu 231: exit(1);
232: }
1.18 ! tedu 233: return flex_main(argc, argv);
1.16 tedu 234: }
1.1 deraadt 235:
1.16 tedu 236: /* check_options - check user-specified options */
1.1 deraadt 237:
1.18 ! tedu 238: void
! 239: check_options()
1.16 tedu 240: {
1.18 ! tedu 241: int i;
! 242: const char *m4 = NULL;
1.16 tedu 243:
244: if (lex_compat) {
245: if (C_plus_plus)
1.18 ! tedu 246: flexerror(_("Can't use -+ with -l option"));
1.16 tedu 247:
248: if (fulltbl || fullspd)
1.18 ! tedu 249: flexerror(_("Can't use -f or -F with -l option"));
1.16 tedu 250:
251: if (reentrant || bison_bridge_lval)
1.18 ! tedu 252: flexerror(_
! 253: ("Can't use --reentrant or --bison-bridge with -l option"));
1.1 deraadt 254:
255: yytext_is_array = true;
256: do_yylineno = true;
257: use_read = false;
1.16 tedu 258: }
259: #if 0
260: /* This makes no sense whatsoever. I'm removing it. */
261: if (do_yylineno)
1.1 deraadt 262: /* This should really be "maintain_backup_tables = true" */
263: reject_really_used = true;
1.16 tedu 264: #endif
1.1 deraadt 265:
1.16 tedu 266: if (csize == unspecified) {
267: if ((fulltbl || fullspd) && !useecs)
1.1 deraadt 268: csize = DEFAULT_CSIZE;
269: else
270: csize = CSIZE;
1.16 tedu 271: }
272: if (interactive == unspecified) {
273: if (fulltbl || fullspd)
1.1 deraadt 274: interactive = false;
275: else
276: interactive = true;
1.16 tedu 277: }
278: if (fulltbl || fullspd) {
279: if (usemecs)
1.18 ! tedu 280: flexerror(_
! 281: ("-Cf/-CF and -Cm don't make sense together"));
1.16 tedu 282:
283: if (interactive)
1.18 ! tedu 284: flexerror(_("-Cf/-CF and -I are incompatible"));
1.16 tedu 285:
286: if (lex_compat)
1.18 ! tedu 287: flexerror(_
! 288: ("-Cf/-CF are incompatible with lex-compatibility mode"));
1.16 tedu 289:
290:
291: if (fulltbl && fullspd)
1.18 ! tedu 292: flexerror(_
! 293: ("-Cf and -CF are mutually exclusive"));
1.16 tedu 294: }
295: if (C_plus_plus && fullspd)
1.18 ! tedu 296: flexerror(_("Can't use -+ with -CF option"));
1.1 deraadt 297:
1.16 tedu 298: if (C_plus_plus && yytext_is_array) {
1.18 ! tedu 299: warn(_("%array incompatible with -+ option"));
1.16 tedu 300: yytext_is_array = false;
301: }
302: if (C_plus_plus && (reentrant))
1.18 ! tedu 303: flexerror(_("Options -+ and --reentrant are mutually exclusive."));
1.1 deraadt 304:
1.16 tedu 305: if (C_plus_plus && bison_bridge_lval)
1.18 ! tedu 306: flexerror(_("bison bridge not supported for the C++ scanner."));
1.1 deraadt 307:
308:
1.16 tedu 309: if (useecs) { /* Set up doubly-linked equivalence classes. */
1.1 deraadt 310:
1.18 ! tedu 311: /*
! 312: * We loop all the way up to csize, since ecgroup[csize] is
1.1 deraadt 313: * the position used for NUL characters.
314: */
315: ecgroup[1] = NIL;
316:
1.16 tedu 317: for (i = 2; i <= csize; ++i) {
1.1 deraadt 318: ecgroup[i] = i - 1;
319: nextecm[i - 1] = i;
1.16 tedu 320: }
1.1 deraadt 321:
322: nextecm[csize] = NIL;
1.18 ! tedu 323: } else {
1.1 deraadt 324: /* Put everything in its own equivalence class. */
1.16 tedu 325: for (i = 1; i <= csize; ++i) {
1.1 deraadt 326: ecgroup[i] = i;
327: nextecm[i] = BAD_SUBSCRIPT; /* to catch errors */
328: }
1.16 tedu 329: }
330:
1.18 ! tedu 331: if (!ansi_func_defs)
! 332: buf_m4_define(&m4defs_buf, "M4_YY_NO_ANSI_FUNC_DEFS", NULL);
1.16 tedu 333:
1.18 ! tedu 334: if (!ansi_func_protos)
! 335: buf_m4_define(&m4defs_buf, "M4_YY_NO_ANSI_FUNC_PROTOS", NULL);
1.16 tedu 336:
1.18 ! tedu 337: if (extra_type)
! 338: buf_m4_define(&m4defs_buf, "M4_EXTRA_TYPE_DEFS", extra_type);
1.1 deraadt 339:
1.16 tedu 340: if (!use_stdout) {
1.18 ! tedu 341: FILE *prev_stdout;
1.1 deraadt 342:
1.16 tedu 343: if (!did_outfilename) {
1.18 ! tedu 344: char *suffix;
1.1 deraadt 345:
1.16 tedu 346: if (C_plus_plus)
1.1 deraadt 347: suffix = "cc";
348: else
349: suffix = "c";
350:
1.18 ! tedu 351: snprintf(outfile_path, sizeof(outfile_path), outfile_template,
! 352: prefix, suffix);
1.1 deraadt 353:
354: outfilename = outfile_path;
1.16 tedu 355: }
1.18 ! tedu 356: prev_stdout = freopen(outfilename, "w+", stdout);
1.1 deraadt 357:
1.16 tedu 358: if (prev_stdout == NULL)
1.18 ! tedu 359: lerrsf(_("could not create %s"), outfilename);
1.1 deraadt 360:
361: outfile_created = 1;
1.16 tedu 362: }
1.18 ! tedu 363: /* Setup the filter chain. */
! 364: output_chain = filter_create_int(NULL, filter_tee_header, headerfilename);
! 365: if (!(m4 = getenv("M4")))
! 366: m4 = M4;
! 367: filter_create_ext(output_chain, m4, "-P", 0);
! 368: filter_create_int(output_chain, filter_fix_linedirs, NULL);
! 369:
! 370: /* For debugging, only run the requested number of filters. */
! 371: if (preproc_level > 0) {
! 372: filter_truncate(output_chain, preproc_level);
! 373: filter_apply_chain(output_chain);
! 374: }
! 375: yyout = stdout;
1.16 tedu 376:
377:
378: /* always generate the tablesverify flag. */
1.18 ! tedu 379: buf_m4_define(&m4defs_buf, "M4_YY_TABLES_VERIFY", tablesverify ? "1" : "0");
1.16 tedu 380: if (tablesext)
381: gentables = false;
382:
383: if (tablesverify)
384: /* force generation of C tables. */
385: gentables = true;
386:
387:
388: if (tablesext) {
1.18 ! tedu 389: FILE *tablesout;
1.16 tedu 390: struct yytbl_hdr hdr;
1.18 ! tedu 391: char *pname = 0;
! 392: int nbytes = 0;
1.16 tedu 393:
1.18 ! tedu 394: buf_m4_define(&m4defs_buf, "M4_YY_TABLES_EXTERNAL", NULL);
1.16 tedu 395:
396: if (!tablesfilename) {
1.18 ! tedu 397: nbytes = strlen(prefix) + strlen(tablesfile_template) + 2;
! 398: tablesfilename = pname = (char *) calloc(nbytes, 1);
! 399: snprintf(pname, nbytes, tablesfile_template, prefix);
1.16 tedu 400: }
1.18 ! tedu 401: if ((tablesout = fopen(tablesfilename, "w")) == NULL)
! 402: lerrsf(_("could not create %s"), tablesfilename);
1.16 tedu 403: if (pname)
1.18 ! tedu 404: free(pname);
1.16 tedu 405: tablesfilename = 0;
406:
1.18 ! tedu 407: yytbl_writer_init(&tableswr, tablesout);
1.16 tedu 408:
1.18 ! tedu 409: nbytes = strlen(prefix) + strlen("tables") + 2;
! 410: tablesname = (char *) calloc(nbytes, 1);
! 411: snprintf(tablesname, nbytes, "%stables", prefix);
! 412: yytbl_hdr_init(&hdr, flex_version, tablesname);
1.1 deraadt 413:
1.18 ! tedu 414: if (yytbl_hdr_fwrite(&tableswr, &hdr) <= 0)
! 415: flexerror(_("could not write tables header"));
1.16 tedu 416: }
1.18 ! tedu 417: if (skelname && (skelfile = fopen(skelname, "r")) == NULL)
! 418: lerrsf(_("can't open skeleton file %s"), skelname);
1.1 deraadt 419:
1.16 tedu 420: if (reentrant) {
1.18 ! tedu 421: buf_m4_define(&m4defs_buf, "M4_YY_REENTRANT", NULL);
1.16 tedu 422: if (yytext_is_array)
1.18 ! tedu 423: buf_m4_define(&m4defs_buf, "M4_YY_TEXT_IS_ARRAY", NULL);
1.16 tedu 424: }
1.18 ! tedu 425: if (bison_bridge_lval)
! 426: buf_m4_define(&m4defs_buf, "M4_YY_BISON_LVAL", NULL);
1.1 deraadt 427:
1.18 ! tedu 428: if (bison_bridge_lloc)
! 429: buf_m4_define(&m4defs_buf, "<M4_YY_BISON_LLOC>", NULL);
1.1 deraadt 430:
1.17 tedu 431: buf_m4_define(&m4defs_buf, "M4_YY_PREFIX", prefix);
1.1 deraadt 432:
1.16 tedu 433: if (did_outfilename)
1.18 ! tedu 434: line_directive_out(stdout, 0);
1.16 tedu 435:
436: if (do_yylineno)
1.18 ! tedu 437: buf_m4_define(&m4defs_buf, "M4_YY_USE_LINENO", NULL);
1.16 tedu 438:
439: /* Create the alignment type. */
1.18 ! tedu 440: buf_strdefine(&userdef_buf, "YY_INT_ALIGNED",
! 441: long_align ? "long int" : "short int");
! 442:
! 443: /* Define the start condition macros. */
! 444: {
! 445: struct Buf tmpbuf;
! 446: buf_init(&tmpbuf, sizeof(char));
! 447: for (i = 1; i <= lastsc; i++) {
! 448: char *str, *fmt = "#define %s %d\n";
! 449: size_t strsz;
! 450:
! 451: str = (char *) flex_alloc(strsz = strlen(fmt) + strlen(scname[i]) + (int) (1 + log10(i)) + 2);
! 452: if (!str)
! 453: flexfatal(_("allocation of macro definition failed"));
! 454: snprintf(str, strsz, fmt, scname[i], i - 1);
! 455: buf_strappend(&tmpbuf, str);
! 456: free(str);
! 457: }
! 458: buf_m4_define(&m4defs_buf, "M4_YY_SC_DEFS", tmpbuf.elts);
! 459: buf_destroy(&tmpbuf);
! 460: }
! 461:
! 462: /* This is where we begin writing to the file. */
1.16 tedu 463:
1.18 ! tedu 464: /* Dump the %top code. */
! 465: if (top_buf.elts)
! 466: outn((char *) top_buf.elts);
1.16 tedu 467:
1.18 ! tedu 468: /* Dump the m4 definitions. */
! 469: buf_print_strings(&m4defs_buf, stdout);
! 470: m4defs_buf.nelts = 0; /* memory leak here. */
! 471:
! 472: /* Place a bogus line directive, it will be fixed in the filter. */
! 473: outn("#line 0 \"M4_YY_OUTFILE_NAME\"\n");
1.16 tedu 474:
475: /* Dump the user defined preproc directives. */
476: if (userdef_buf.elts)
1.18 ! tedu 477: outn((char *) (userdef_buf.elts));
1.16 tedu 478:
1.18 ! tedu 479: skelout();
1.16 tedu 480: /* %% [1.0] */
481: }
1.1 deraadt 482:
483: /* flexend - terminate flex
484: *
485: * note
486: * This routine does not return.
487: */
488:
1.18 ! tedu 489: void
! 490: flexend(exit_status)
! 491: int exit_status;
1.16 tedu 492:
493: {
494: static int called_before = -1; /* prevent infinite recursion. */
1.18 ! tedu 495: int tblsiz;
1.16 tedu 496:
497: if (++called_before)
1.18 ! tedu 498: FLEX_EXIT(exit_status);
1.16 tedu 499:
500: if (skelfile != NULL) {
1.18 ! tedu 501: if (ferror(skelfile))
! 502: lerrsf(_("input error reading skeleton file %s"),
! 503: skelname);
! 504:
! 505: else if (fclose(skelfile))
! 506: lerrsf(_("error closing skeleton file %s"),
! 507: skelname);
1.16 tedu 508: }
1.18 ! tedu 509: #if 0
! 510: fprintf(header_out,
! 511: "#ifdef YY_HEADER_EXPORT_START_CONDITIONS\n");
! 512: fprintf(header_out,
! 513: "/* Beware! Start conditions are not prefixed. */\n");
! 514:
! 515: /* Special case for "INITIAL" */
! 516: fprintf(header_out,
! 517: "#undef INITIAL\n#define INITIAL 0\n");
! 518: for (i = 2; i <= lastsc; i++)
! 519: fprintf(header_out, "#define %s %d\n", scname[i], i - 1);
! 520: fprintf(header_out,
! 521: "#endif /* YY_HEADER_EXPORT_START_CONDITIONS */\n\n");
! 522:
! 523: /*
! 524: * Kill ALL flex-related macros. This is so the user can #include
! 525: * more than one generated header file.
! 526: */
! 527: fprintf(header_out, "#ifndef YY_HEADER_NO_UNDEFS\n");
! 528: fprintf(header_out,
! 529: "/* Undefine all internal macros, etc., that do no belong in the header. */\n\n");
1.1 deraadt 530:
1.18 ! tedu 531: {
! 532: const char *undef_list[] = {
1.16 tedu 533:
1.18 ! tedu 534: "BEGIN",
! 535: "ECHO",
! 536: "EOB_ACT_CONTINUE_SCAN",
! 537: "EOB_ACT_END_OF_FILE",
! 538: "EOB_ACT_LAST_MATCH",
! 539: "FLEX_SCANNER",
! 540: "FLEX_STD",
! 541: "REJECT",
! 542: "YYFARGS0",
! 543: "YYFARGS1",
! 544: "YYFARGS2",
! 545: "YYFARGS3",
! 546: "YYLMAX",
! 547: "YYSTATE",
! 548: "YY_AT_BOL",
! 549: "YY_BREAK",
! 550: "YY_BUFFER_EOF_PENDING",
! 551: "YY_BUFFER_NEW",
! 552: "YY_BUFFER_NORMAL",
! 553: "YY_BUF_SIZE",
! 554: "M4_YY_CALL_LAST_ARG",
! 555: "M4_YY_CALL_ONLY_ARG",
! 556: "YY_CURRENT_BUFFER",
! 557: "YY_DECL",
! 558: "M4_YY_DECL_LAST_ARG",
! 559: "M4_YY_DEF_LAST_ARG",
! 560: "M4_YY_DEF_ONLY_ARG",
! 561: "YY_DO_BEFORE_ACTION",
! 562: "YY_END_OF_BUFFER",
! 563: "YY_END_OF_BUFFER_CHAR",
! 564: "YY_EXIT_FAILURE",
! 565: "YY_EXTRA_TYPE",
! 566: "YY_FATAL_ERROR",
! 567: "YY_FLEX_DEFINED_ECHO",
! 568: "YY_FLEX_LEX_COMPAT",
! 569: "YY_FLEX_MAJOR_VERSION",
! 570: "YY_FLEX_MINOR_VERSION",
! 571: "YY_FLEX_SUBMINOR_VERSION",
! 572: "YY_FLUSH_BUFFER",
! 573: "YY_G",
! 574: "YY_INPUT",
! 575: "YY_INTERACTIVE",
! 576: "YY_INT_ALIGNED",
! 577: "YY_LAST_ARG",
! 578: "YY_LESS_LINENO",
! 579: "YY_LEX_ARGS",
! 580: "YY_LEX_DECLARATION",
! 581: "YY_LEX_PROTO",
! 582: "YY_MAIN",
! 583: "YY_MORE_ADJ",
! 584: "YY_NEED_STRLEN",
! 585: "YY_NEW_FILE",
! 586: "YY_NULL",
! 587: "YY_NUM_RULES",
! 588: "YY_ONLY_ARG",
! 589: "YY_PARAMS",
! 590: "YY_PROTO",
! 591: "M4_YY_PROTO_LAST_ARG",
! 592: "M4_YY_PROTO_ONLY_ARG void",
! 593: "YY_READ_BUF_SIZE",
! 594: "YY_REENTRANT",
! 595: "YY_RESTORE_YY_MORE_OFFSET",
! 596: "YY_RULE_SETUP",
! 597: "YY_SC_TO_UI",
! 598: "YY_SKIP_YYWRAP",
! 599: "YY_START",
! 600: "YY_START_STACK_INCR",
! 601: "YY_STATE_EOF",
! 602: "YY_STDINIT",
! 603: "YY_TRAILING_HEAD_MASK",
! 604: "YY_TRAILING_MASK",
! 605: "YY_USER_ACTION",
! 606: "YY_USE_CONST",
! 607: "YY_USE_PROTOS",
! 608: "unput",
! 609: "yyTABLES_NAME",
! 610: "yy_create_buffer",
! 611: "yy_delete_buffer",
! 612: "yy_flex_debug",
! 613: "yy_flush_buffer",
! 614: "yy_init_buffer",
! 615: "yy_load_buffer_state",
! 616: "yy_new_buffer",
! 617: "yy_scan_buffer",
! 618: "yy_scan_bytes",
! 619: "yy_scan_string",
! 620: "yy_set_bol",
! 621: "yy_set_interactive",
! 622: "yy_switch_to_buffer",
! 623: "yypush_buffer_state",
! 624: "yypop_buffer_state",
! 625: "yyensure_buffer_stack",
! 626: "yyalloc",
! 627: "yyconst",
! 628: "yyextra",
! 629: "yyfree",
! 630: "yyget_debug",
! 631: "yyget_extra",
! 632: "yyget_in",
! 633: "yyget_leng",
! 634: "yyget_lineno",
! 635: "yyget_lloc",
! 636: "yyget_lval",
! 637: "yyget_out",
! 638: "yyget_text",
! 639: "yyin",
! 640: "yyleng",
! 641: "yyless",
! 642: "yylex",
! 643: "yylex_destroy",
! 644: "yylex_init",
! 645: "yylex_init_extra",
! 646: "yylineno",
! 647: "yylloc",
! 648: "yylval",
! 649: "yymore",
! 650: "yyout",
! 651: "yyrealloc",
! 652: "yyrestart",
! 653: "yyset_debug",
! 654: "yyset_extra",
! 655: "yyset_in",
! 656: "yyset_lineno",
! 657: "yyset_lloc",
! 658: "yyset_lval",
! 659: "yyset_out",
! 660: "yytables_destroy",
! 661: "yytables_fload",
! 662: "yyterminate",
! 663: "yytext",
! 664: "yytext_ptr",
! 665: "yywrap",
! 666:
! 667: /* must be null-terminated */
! 668: NULL};
! 669:
! 670:
! 671: for (i = 0; undef_list[i] != NULL; i++)
! 672: fprintf(header_out, "#undef %s\n", undef_list[i]);
! 673: }
! 674:
! 675: /* undef any of the auto-generated symbols. */
! 676: for (i = 0; i < defs_buf.nelts; i++) {
! 677:
! 678: /* don't undef start conditions */
! 679: if (sclookup(((char **) defs_buf.elts)[i]) > 0)
! 680: continue;
! 681: fprintf(header_out, "#undef %s\n",
! 682: ((char **) defs_buf.elts)[i]);
! 683: }
! 684:
! 685: fprintf(header_out,
! 686: "#endif /* !YY_HEADER_NO_UNDEFS */\n");
! 687: fprintf(header_out, "\n");
! 688: fprintf(header_out, "#undef %sIN_HEADER\n", prefix);
! 689: fprintf(header_out, "#endif /* %sHEADER_H */\n", prefix);
! 690:
! 691: if (ferror(header_out))
! 692: lerrsf(_("error creating header file %s"),
! 693: headerfilename);
! 694: fflush(header_out);
! 695: fclose(header_out);
1.16 tedu 696: #endif
1.1 deraadt 697:
1.16 tedu 698: if (exit_status != 0 && outfile_created) {
1.18 ! tedu 699: if (ferror(stdout))
! 700: lerrsf(_("error writing output file %s"),
! 701: outfilename);
! 702:
! 703: else if ((_stdout_closed = 1) && fclose(stdout))
! 704: lerrsf(_("error closing output file %s"),
! 705: outfilename);
! 706:
! 707: else if (unlink(outfilename))
! 708: lerrsf(_("error deleting output file %s"),
! 709: outfilename);
1.16 tedu 710: }
711: if (backing_up_report && backing_up_file) {
712: if (num_backing_up == 0)
1.18 ! tedu 713: fprintf(backing_up_file, _("No backing up.\n"));
1.16 tedu 714: else if (fullspd || fulltbl)
1.18 ! tedu 715: fprintf(backing_up_file,
! 716: _
! 717: ("%d backing up (non-accepting) states.\n"),
! 718: num_backing_up);
1.1 deraadt 719: else
1.18 ! tedu 720: fprintf(backing_up_file,
! 721: _("Compressed tables always back up.\n"));
1.1 deraadt 722:
1.18 ! tedu 723: if (ferror(backing_up_file))
! 724: lerrsf(_("error writing backup file %s"),
! 725: backing_name);
! 726:
! 727: else if (fclose(backing_up_file))
! 728: lerrsf(_("error closing backup file %s"),
! 729: backing_name);
1.16 tedu 730: }
731: if (printstats) {
1.18 ! tedu 732: fprintf(stderr, _("%s version %s usage statistics:\n"),
! 733: program_name, flex_version);
1.16 tedu 734:
1.18 ! tedu 735: fprintf(stderr, _(" scanner options: -"));
1.16 tedu 736:
737: if (C_plus_plus)
1.18 ! tedu 738: putc('+', stderr);
1.16 tedu 739: if (backing_up_report)
1.18 ! tedu 740: putc('b', stderr);
1.16 tedu 741: if (ddebug)
1.18 ! tedu 742: putc('d', stderr);
1.16 tedu 743: if (sf_case_ins())
1.18 ! tedu 744: putc('i', stderr);
1.16 tedu 745: if (lex_compat)
1.18 ! tedu 746: putc('l', stderr);
1.16 tedu 747: if (posix_compat)
1.18 ! tedu 748: putc('X', stderr);
1.16 tedu 749: if (performance_report > 0)
1.18 ! tedu 750: putc('p', stderr);
1.16 tedu 751: if (performance_report > 1)
1.18 ! tedu 752: putc('p', stderr);
1.16 tedu 753: if (spprdflt)
1.18 ! tedu 754: putc('s', stderr);
1.16 tedu 755: if (reentrant)
1.18 ! tedu 756: fputs("--reentrant", stderr);
1.17 tedu 757: if (bison_bridge_lval)
1.18 ! tedu 758: fputs("--bison-bridge", stderr);
1.17 tedu 759: if (bison_bridge_lloc)
1.18 ! tedu 760: fputs("--bison-locations", stderr);
1.16 tedu 761: if (use_stdout)
1.18 ! tedu 762: putc('t', stderr);
1.16 tedu 763: if (printstats)
1.18 ! tedu 764: putc('v', stderr); /* always true! */
1.16 tedu 765: if (nowarn)
1.18 ! tedu 766: putc('w', stderr);
1.16 tedu 767: if (interactive == false)
1.18 ! tedu 768: putc('B', stderr);
1.16 tedu 769: if (interactive == true)
1.18 ! tedu 770: putc('I', stderr);
1.16 tedu 771: if (!gen_line_dirs)
1.18 ! tedu 772: putc('L', stderr);
1.16 tedu 773: if (trace)
1.18 ! tedu 774: putc('T', stderr);
1.1 deraadt 775:
1.16 tedu 776: if (csize == unspecified)
1.18 ! tedu 777: /*
! 778: * We encountered an error fairly early on, so csize
1.1 deraadt 779: * never got specified. Define it now, to prevent
780: * bogus table sizes being written out below.
781: */
782: csize = 256;
783:
1.16 tedu 784: if (csize == 128)
1.18 ! tedu 785: putc('7', stderr);
1.1 deraadt 786: else
1.18 ! tedu 787: putc('8', stderr);
1.1 deraadt 788:
1.18 ! tedu 789: fprintf(stderr, " -C");
1.1 deraadt 790:
1.16 tedu 791: if (long_align)
1.18 ! tedu 792: putc('a', stderr);
1.16 tedu 793: if (fulltbl)
1.18 ! tedu 794: putc('f', stderr);
1.16 tedu 795: if (fullspd)
1.18 ! tedu 796: putc('F', stderr);
1.16 tedu 797: if (useecs)
1.18 ! tedu 798: putc('e', stderr);
1.16 tedu 799: if (usemecs)
1.18 ! tedu 800: putc('m', stderr);
1.16 tedu 801: if (use_read)
1.18 ! tedu 802: putc('r', stderr);
1.16 tedu 803:
804: if (did_outfilename)
1.18 ! tedu 805: fprintf(stderr, " -o%s", outfilename);
1.16 tedu 806:
807: if (skelname)
1.18 ! tedu 808: fprintf(stderr, " -S%s", skelname);
1.16 tedu 809:
1.18 ! tedu 810: if (strcmp(prefix, "yy"))
! 811: fprintf(stderr, " -P%s", prefix);
1.16 tedu 812:
1.18 ! tedu 813: putc('\n', stderr);
1.16 tedu 814:
1.18 ! tedu 815: fprintf(stderr, _(" %d/%d NFA states\n"),
! 816: lastnfa, current_mns);
! 817: fprintf(stderr, _(" %d/%d DFA states (%d words)\n"),
! 818: lastdfa, current_max_dfas, totnst);
! 819: fprintf(stderr, _(" %d rules\n"),
! 820: num_rules + num_eof_rules -
! 821: 1 /* - 1 for def. rule */ );
1.16 tedu 822:
823: if (num_backing_up == 0)
1.18 ! tedu 824: fprintf(stderr, _(" No backing up\n"));
1.16 tedu 825: else if (fullspd || fulltbl)
1.18 ! tedu 826: fprintf(stderr,
! 827: _
! 828: (" %d backing-up (non-accepting) states\n"),
! 829: num_backing_up);
1.1 deraadt 830: else
1.18 ! tedu 831: fprintf(stderr,
! 832: _
! 833: (" Compressed tables always back-up\n"));
1.16 tedu 834:
835: if (bol_needed)
1.18 ! tedu 836: fprintf(stderr,
! 837: _(" Beginning-of-line patterns used\n"));
1.16 tedu 838:
1.18 ! tedu 839: fprintf(stderr, _(" %d/%d start conditions\n"), lastsc,
! 840: current_max_scs);
! 841: fprintf(stderr,
! 842: _
! 843: (" %d epsilon states, %d double epsilon states\n"),
! 844: numeps, eps2);
1.1 deraadt 845:
1.16 tedu 846: if (lastccl == 0)
1.18 ! tedu 847: fprintf(stderr, _(" no character classes\n"));
1.1 deraadt 848: else
1.18 ! tedu 849: fprintf(stderr,
! 850: _
! 851: (" %d/%d character classes needed %d/%d words of storage, %d reused\n"),
! 852: lastccl, current_maxccls,
! 853: cclmap[lastccl] + ccllen[lastccl],
! 854: current_max_ccl_tbl_size, cclreuse);
! 855:
! 856: fprintf(stderr, _(" %d state/nextstate pairs created\n"),
! 857: numsnpairs);
! 858: fprintf(stderr,
! 859: _(" %d/%d unique/duplicate transitions\n"),
! 860: numuniq, numdup);
1.1 deraadt 861:
1.16 tedu 862: if (fulltbl) {
1.1 deraadt 863: tblsiz = lastdfa * numecs;
1.18 ! tedu 864: fprintf(stderr, _(" %d table entries\n"),
! 865: tblsiz);
! 866: } else {
1.1 deraadt 867: tblsiz = 2 * (lastdfa + numtemps) + 2 * tblend;
868:
1.18 ! tedu 869: fprintf(stderr,
! 870: _(" %d/%d base-def entries created\n"),
! 871: lastdfa + numtemps, current_max_dfas);
! 872: fprintf(stderr,
! 873: _
! 874: (" %d/%d (peak %d) nxt-chk entries created\n"),
! 875: tblend, current_max_xpairs, peakpairs);
! 876: fprintf(stderr,
! 877: _
! 878: (" %d/%d (peak %d) template nxt-chk entries created\n"),
! 879: numtemps * nummecs,
! 880: current_max_template_xpairs,
! 881: numtemps * numecs);
! 882: fprintf(stderr, _(" %d empty table entries\n"),
! 883: nummt);
! 884: fprintf(stderr, _(" %d protos created\n"),
! 885: numprots);
! 886: fprintf(stderr,
! 887: _(" %d templates created, %d uses\n"),
! 888: numtemps, tmpuses);
1.16 tedu 889: }
1.1 deraadt 890:
1.16 tedu 891: if (useecs) {
1.1 deraadt 892: tblsiz = tblsiz + csize;
1.18 ! tedu 893: fprintf(stderr,
! 894: _
! 895: (" %d/%d equivalence classes created\n"),
! 896: numecs, csize);
1.16 tedu 897: }
898: if (usemecs) {
1.1 deraadt 899: tblsiz = tblsiz + numecs;
1.18 ! tedu 900: fprintf(stderr,
! 901: _
! 902: (" %d/%d meta-equivalence classes created\n"),
! 903: nummecs, csize);
1.1 deraadt 904: }
1.18 ! tedu 905: fprintf(stderr,
! 906: _
! 907: (" %d (%d saved) hash collisions, %d DFAs equal\n"),
! 908: hshcol, hshsave, dfaeql);
! 909: fprintf(stderr, _(" %d sets of reallocations needed\n"),
! 910: num_reallocs);
! 911: fprintf(stderr, _(" %d total table entries needed\n"),
! 912: tblsiz);
1.1 deraadt 913: }
1.18 ! tedu 914: FLEX_EXIT(exit_status);
1.16 tedu 915: }
916:
1.1 deraadt 917:
918: /* flexinit - initialize flex */
919:
1.18 ! tedu 920: void
! 921: flexinit(argc, argv)
! 922: int argc;
! 923: char **argv;
1.16 tedu 924: {
1.18 ! tedu 925: int i, sawcmpflag, rv, optind;
! 926: char *arg;
1.16 tedu 927: scanopt_t sopt;
928:
929: printstats = syntaxerror = trace = spprdflt = false;
930: lex_compat = posix_compat = C_plus_plus = backing_up_report =
1.18 ! tedu 931: ddebug = fulltbl = false;
1.16 tedu 932: fullspd = long_align = nowarn = yymore_used = continued_action =
1.18 ! tedu 933: false;
1.16 tedu 934: do_yylineno = yytext_is_array = in_rule = reject = do_stdinit =
1.18 ! tedu 935: false;
1.1 deraadt 936: yymore_really_used = reject_really_used = unspecified;
937: interactive = csize = unspecified;
938: do_yywrap = gen_line_dirs = usemecs = useecs = true;
1.16 tedu 939: reentrant = bison_bridge_lval = bison_bridge_lloc = false;
1.1 deraadt 940: performance_report = 0;
941: did_outfilename = 0;
942: prefix = "yy";
943: yyclass = 0;
944: use_read = use_stdout = false;
1.16 tedu 945: tablesext = tablesverify = false;
946: gentables = true;
947: tablesfilename = tablesname = NULL;
1.18 ! tedu 948: ansi_func_defs = ansi_func_protos = true;
1.1 deraadt 949:
950: sawcmpflag = false;
951:
952: /* Initialize dynamic array for holding the rule actions. */
953: action_size = 2048; /* default size of action array in bytes */
1.18 ! tedu 954: action_array = allocate_character_array(action_size);
1.1 deraadt 955: defs1_offset = prolog_offset = action_offset = action_index = 0;
956: action_array[0] = '\0';
957:
1.16 tedu 958: /* Initialize any buffers. */
1.18 ! tedu 959: buf_init(&userdef_buf, sizeof(char)); /* one long string */
! 960: buf_init(&defs_buf, sizeof(char *)); /* list of strings */
! 961: buf_init(&yydmap_buf, sizeof(char)); /* one long string */
! 962: buf_init(&top_buf, sizeof(char)); /* one long string */
1.16 tedu 963:
1.18 ! tedu 964: {
! 965: const char *m4defs_init_str[] = {"m4_changequote\n",
! 966: "m4_changequote([[, ]])\n"};
! 967: buf_init(&m4defs_buf, sizeof(char *));
! 968: buf_append(&m4defs_buf, &m4defs_init_str, 2);
! 969: }
! 970:
! 971: sf_init();
1.16 tedu 972:
1.18 ! tedu 973: /* initialize regex lib */
! 974: flex_init_regex();
1.16 tedu 975:
976: /* Enable C++ if program name ends with '+'. */
1.18 ! tedu 977: program_name = basename2(argv[0], 0);
1.1 deraadt 978:
1.16 tedu 979: if (program_name[0] != '\0' &&
1.18 ! tedu 980: program_name[strlen(program_name) - 1] == '+')
1.1 deraadt 981: C_plus_plus = true;
982:
983: /* read flags */
1.18 ! tedu 984: sopt = scanopt_init(flexopts, argc, argv, 0);
1.16 tedu 985: if (!sopt) {
986: /* This will only happen when flexopts array is altered. */
1.18 ! tedu 987: fprintf(stderr,
! 988: _("Internal error. flexopts are malformed.\n"));
! 989: FLEX_EXIT(1);
1.16 tedu 990: }
1.18 ! tedu 991: while ((rv = scanopt(sopt, &arg, &optind)) != 0) {
1.1 deraadt 992:
1.16 tedu 993: if (rv < 0) {
1.18 ! tedu 994: /*
! 995: * Scanopt has already printed an option-specific
! 996: * error message.
! 997: */
! 998: fprintf(stderr,
! 999: _
! 1000: ("Try `%s --help' for more information.\n"),
! 1001: program_name);
! 1002: FLEX_EXIT(1);
1.16 tedu 1003: }
1004: switch ((enum flexopt_flag_t) rv) {
1005: case OPT_CPLUSPLUS:
1006: C_plus_plus = true;
1007: break;
1.1 deraadt 1008:
1.16 tedu 1009: case OPT_BATCH:
1010: interactive = false;
1011: break;
1.1 deraadt 1012:
1.16 tedu 1013: case OPT_BACKUP:
1014: backing_up_report = true;
1015: break;
1.1 deraadt 1016:
1.16 tedu 1017: case OPT_DONOTHING:
1018: break;
1.1 deraadt 1019:
1.16 tedu 1020: case OPT_COMPRESSION:
1021: if (!sawcmpflag) {
1022: useecs = false;
1023: usemecs = false;
1024: fulltbl = false;
1025: sawcmpflag = true;
1026: }
1027: for (i = 0; arg && arg[i] != '\0'; i++)
1028: switch (arg[i]) {
1029: case 'a':
1030: long_align = true;
1.1 deraadt 1031: break;
1032:
1.16 tedu 1033: case 'e':
1034: useecs = true;
1.1 deraadt 1035: break;
1036:
1037: case 'F':
1.16 tedu 1038: fullspd = true;
1.1 deraadt 1039: break;
1040:
1.16 tedu 1041: case 'f':
1042: fulltbl = true;
1043: break;
1.1 deraadt 1044:
1.16 tedu 1045: case 'm':
1046: usemecs = true;
1.1 deraadt 1047: break;
1048:
1.16 tedu 1049: case 'r':
1050: use_read = true;
1.1 deraadt 1051: break;
1052:
1.16 tedu 1053: default:
1.18 ! tedu 1054: lerrif(_
! 1055: ("unknown -C option '%c'"),
! 1056: (int) arg[i]);
1.1 deraadt 1057: break;
1.16 tedu 1058: }
1059: break;
1.1 deraadt 1060:
1.16 tedu 1061: case OPT_DEBUG:
1062: ddebug = true;
1063: break;
1064:
1065: case OPT_NO_DEBUG:
1066: ddebug = false;
1067: break;
1068:
1069: case OPT_FULL:
1070: useecs = usemecs = false;
1071: use_read = fulltbl = true;
1072: break;
1073:
1074: case OPT_FAST:
1075: useecs = usemecs = false;
1076: use_read = fullspd = true;
1077: break;
1078:
1079: case OPT_HELP:
1.18 ! tedu 1080: usage();
! 1081: FLEX_EXIT(0);
1.16 tedu 1082:
1083: case OPT_INTERACTIVE:
1084: interactive = true;
1085: break;
1086:
1087: case OPT_CASE_INSENSITIVE:
1088: sf_set_case_ins(true);
1089: break;
1090:
1091: case OPT_LEX_COMPAT:
1092: lex_compat = true;
1093: break;
1094:
1095: case OPT_POSIX_COMPAT:
1096: posix_compat = true;
1097: break;
1098:
1.18 ! tedu 1099: case OPT_PREPROC_LEVEL:
! 1100: preproc_level = strtol(arg, NULL, 0);
! 1101: break;
1.16 tedu 1102:
1103: case OPT_MAIN:
1.18 ! tedu 1104: buf_strdefine(&userdef_buf, "YY_MAIN", "1");
1.16 tedu 1105: do_yywrap = false;
1106: break;
1107:
1108: case OPT_NO_MAIN:
1.18 ! tedu 1109: buf_strdefine(&userdef_buf, "YY_MAIN", "0");
1.16 tedu 1110: break;
1111:
1112: case OPT_NO_LINE:
1113: gen_line_dirs = false;
1114: break;
1115:
1116: case OPT_OUTFILE:
1117: outfilename = arg;
1118: did_outfilename = 1;
1119: break;
1120:
1121: case OPT_PREFIX:
1122: prefix = arg;
1123: break;
1124:
1125: case OPT_PERF_REPORT:
1126: ++performance_report;
1127: break;
1128:
1129: case OPT_BISON_BRIDGE:
1130: bison_bridge_lval = true;
1131: break;
1132:
1133: case OPT_BISON_BRIDGE_LOCATIONS:
1134: bison_bridge_lval = bison_bridge_lloc = true;
1135: break;
1136:
1137: case OPT_REENTRANT:
1138: reentrant = true;
1139: break;
1140:
1141: case OPT_NO_REENTRANT:
1142: reentrant = false;
1143: break;
1144:
1145: case OPT_SKEL:
1146: skelname = arg;
1147: break;
1148:
1149: case OPT_DEFAULT:
1150: spprdflt = false;
1151: break;
1152:
1153: case OPT_NO_DEFAULT:
1154: spprdflt = true;
1155: break;
1156:
1157: case OPT_STDOUT:
1158: use_stdout = true;
1159: break;
1160:
1161: case OPT_NO_UNISTD_H:
1.18 ! tedu 1162: //buf_strdefine(&userdef_buf, "YY_NO_UNISTD_H", "1");
! 1163: buf_m4_define(&m4defs_buf, "M4_YY_NO_UNISTD_H", 0);
1.16 tedu 1164: break;
1165:
1166: case OPT_TABLES_FILE:
1167: tablesext = true;
1168: tablesfilename = arg;
1169: break;
1170:
1171: case OPT_TABLES_VERIFY:
1172: tablesverify = true;
1173: break;
1174:
1175: case OPT_TRACE:
1176: trace = true;
1177: break;
1178:
1179: case OPT_VERBOSE:
1180: printstats = true;
1181: break;
1182:
1183: case OPT_VERSION:
1.18 ! tedu 1184: printf(_("%s %s\n"), program_name, flex_version);
! 1185: FLEX_EXIT(0);
1.16 tedu 1186:
1187: case OPT_WARN:
1188: nowarn = false;
1189: break;
1190:
1191: case OPT_NO_WARN:
1192: nowarn = true;
1193: break;
1194:
1195: case OPT_7BIT:
1196: csize = 128;
1197: break;
1.1 deraadt 1198:
1.16 tedu 1199: case OPT_8BIT:
1200: csize = CSIZE;
1201: break;
1.1 deraadt 1202:
1.16 tedu 1203: case OPT_ALIGN:
1204: long_align = true;
1205: break;
1.1 deraadt 1206:
1.16 tedu 1207: case OPT_NO_ALIGN:
1208: long_align = false;
1209: break;
1.1 deraadt 1210:
1.16 tedu 1211: case OPT_ALWAYS_INTERACTIVE:
1.18 ! tedu 1212: buf_m4_define(&m4defs_buf, "M4_YY_ALWAYS_INTERACTIVE", 0);
1.16 tedu 1213: break;
1.1 deraadt 1214:
1.16 tedu 1215: case OPT_NEVER_INTERACTIVE:
1.18 ! tedu 1216: buf_m4_define(&m4defs_buf, "M4_YY_NEVER_INTERACTIVE", 0);
1.16 tedu 1217: break;
1.1 deraadt 1218:
1.16 tedu 1219: case OPT_ARRAY:
1220: yytext_is_array = true;
1221: break;
1.1 deraadt 1222:
1.16 tedu 1223: case OPT_POINTER:
1224: yytext_is_array = false;
1225: break;
1.1 deraadt 1226:
1.16 tedu 1227: case OPT_ECS:
1228: useecs = true;
1229: break;
1.1 deraadt 1230:
1.16 tedu 1231: case OPT_NO_ECS:
1232: useecs = false;
1233: break;
1.1 deraadt 1234:
1.16 tedu 1235: case OPT_HEADER_FILE:
1236: headerfilename = arg;
1237: break;
1.1 deraadt 1238:
1.16 tedu 1239: case OPT_META_ECS:
1240: usemecs = true;
1241: break;
1.1 deraadt 1242:
1.16 tedu 1243: case OPT_NO_META_ECS:
1244: usemecs = false;
1245: break;
1.1 deraadt 1246:
1.16 tedu 1247: case OPT_PREPROCDEFINE:
1248: {
1249: /* arg is "symbol" or "symbol=definition". */
1.18 ! tedu 1250: char *def;
1.1 deraadt 1251:
1.16 tedu 1252: for (def = arg;
1.18 ! tedu 1253: *def != '\0' && *def != '='; ++def);
1.1 deraadt 1254:
1.18 ! tedu 1255: buf_strappend(&userdef_buf, "#define ");
1.16 tedu 1256: if (*def == '\0') {
1.18 ! tedu 1257: buf_strappend(&userdef_buf, arg);
! 1258: buf_strappend(&userdef_buf,
! 1259: " 1\n");
! 1260: } else {
! 1261: buf_strnappend(&userdef_buf, arg,
! 1262: def - arg);
! 1263: buf_strappend(&userdef_buf, " ");
! 1264: buf_strappend(&userdef_buf,
! 1265: def + 1);
! 1266: buf_strappend(&userdef_buf, "\n");
1.1 deraadt 1267: }
1.16 tedu 1268: }
1269: break;
1270:
1271: case OPT_READ:
1272: use_read = true;
1273: break;
1.1 deraadt 1274:
1.16 tedu 1275: case OPT_STACK:
1.18 ! tedu 1276: //buf_strdefine(&userdef_buf, "YY_STACK_USED", "1");
! 1277: buf_m4_define(&m4defs_buf, "M4_YY_STACK_USED", 0);
1.16 tedu 1278: break;
1279:
1280: case OPT_STDINIT:
1281: do_stdinit = true;
1282: break;
1283:
1284: case OPT_NO_STDINIT:
1285: do_stdinit = false;
1286: break;
1287:
1288: case OPT_YYCLASS:
1289: yyclass = arg;
1290: break;
1291:
1292: case OPT_YYLINENO:
1293: do_yylineno = true;
1294: break;
1295:
1296: case OPT_NO_YYLINENO:
1297: do_yylineno = false;
1298: break;
1299:
1300: case OPT_YYWRAP:
1301: do_yywrap = true;
1302: break;
1303:
1304: case OPT_NO_YYWRAP:
1305: do_yywrap = false;
1306: break;
1307:
1308: case OPT_YYMORE:
1309: yymore_really_used = true;
1310: break;
1311:
1312: case OPT_NO_YYMORE:
1313: yymore_really_used = false;
1314: break;
1315:
1316: case OPT_REJECT:
1317: reject_really_used = true;
1318: break;
1319:
1320: case OPT_NO_REJECT:
1321: reject_really_used = false;
1322: break;
1323:
1.18 ! tedu 1324: case OPT_NO_ANSI_FUNC_DEFS:
! 1325: ansi_func_defs = false;
! 1326: break;
! 1327:
! 1328: case OPT_NO_ANSI_FUNC_PROTOS:
! 1329: ansi_func_protos = false;
! 1330: break;
1.16 tedu 1331:
1332: case OPT_NO_YY_PUSH_STATE:
1.18 ! tedu 1333: //buf_strdefine(&userdef_buf, "YY_NO_PUSH_STATE", "1");
! 1334: buf_m4_define(&m4defs_buf, "M4_YY_NO_PUSH_STATE", 0);
1.16 tedu 1335: break;
1336: case OPT_NO_YY_POP_STATE:
1.18 ! tedu 1337: //buf_strdefine(&userdef_buf, "YY_NO_POP_STATE", "1");
! 1338: buf_m4_define(&m4defs_buf, "M4_YY_NO_POP_STATE", 0);
1.16 tedu 1339: break;
1340: case OPT_NO_YY_TOP_STATE:
1.18 ! tedu 1341: //buf_strdefine(&userdef_buf, "YY_NO_TOP_STATE", "1");
! 1342: buf_m4_define(&m4defs_buf, "M4_YY_NO_TOP_STATE", 0);
1.16 tedu 1343: break;
1344: case OPT_NO_UNPUT:
1.18 ! tedu 1345: //buf_strdefine(&userdef_buf, "YY_NO_UNPUT", "1");
! 1346: buf_m4_define(&m4defs_buf, "M4_YY_NO_UNPUT", 0);
1.16 tedu 1347: break;
1348: case OPT_NO_YY_SCAN_BUFFER:
1.18 ! tedu 1349: //buf_strdefine(&userdef_buf, "YY_NO_SCAN_BUFFER", "1");
! 1350: buf_m4_define(&m4defs_buf, "M4_YY_NO_SCAN_BUFFER", 0);
1.16 tedu 1351: break;
1352: case OPT_NO_YY_SCAN_BYTES:
1.18 ! tedu 1353: //buf_strdefine(&userdef_buf, "YY_NO_SCAN_BYTES", "1");
! 1354: buf_m4_define(&m4defs_buf, "M4_YY_NO_SCAN_BYTES", 0);
1.16 tedu 1355: break;
1356: case OPT_NO_YY_SCAN_STRING:
1.18 ! tedu 1357: //buf_strdefine(&userdef_buf, "YY_NO_SCAN_STRING", "1");
! 1358: buf_m4_define(&m4defs_buf, "M4_YY_NO_SCAN_STRING", 0);
1.16 tedu 1359: break;
1360: case OPT_NO_YYGET_EXTRA:
1.18 ! tedu 1361: //buf_strdefine(&userdef_buf, "YY_NO_GET_EXTRA", "1");
! 1362: buf_m4_define(&m4defs_buf, "M4_YY_NO_GET_EXTRA", 0);
1.16 tedu 1363: break;
1364: case OPT_NO_YYSET_EXTRA:
1.18 ! tedu 1365: //buf_strdefine(&userdef_buf, "YY_NO_SET_EXTRA", "1");
! 1366: buf_m4_define(&m4defs_buf, "M4_YY_NO_SET_EXTRA", 0);
1.16 tedu 1367: break;
1368: case OPT_NO_YYGET_LENG:
1.18 ! tedu 1369: //buf_strdefine(&userdef_buf, "YY_NO_GET_LENG", "1");
! 1370: buf_m4_define(&m4defs_buf, "M4_YY_NO_GET_LENG", 0);
1.16 tedu 1371: break;
1372: case OPT_NO_YYGET_TEXT:
1.18 ! tedu 1373: //buf_strdefine(&userdef_buf, "YY_NO_GET_TEXT", "1");
! 1374: buf_m4_define(&m4defs_buf, "M4_YY_NO_GET_TEXT", 0);
1.16 tedu 1375: break;
1376: case OPT_NO_YYGET_LINENO:
1.18 ! tedu 1377: //buf_strdefine(&userdef_buf, "YY_NO_GET_LINENO", "1");
! 1378: buf_m4_define(&m4defs_buf, "M4_YY_NO_GET_LINENO", 0);
1.16 tedu 1379: break;
1380: case OPT_NO_YYSET_LINENO:
1.18 ! tedu 1381: //buf_strdefine(&userdef_buf, "YY_NO_SET_LINENO", "1");
! 1382: buf_m4_define(&m4defs_buf, "M4_YY_NO_SET_LINENO", 0);
1.16 tedu 1383: break;
1384: case OPT_NO_YYGET_IN:
1.18 ! tedu 1385: //buf_strdefine(&userdef_buf, "YY_NO_GET_IN", "1");
! 1386: buf_m4_define(&m4defs_buf, "M4_YY_NO_GET_IN", 0);
1.16 tedu 1387: break;
1388: case OPT_NO_YYSET_IN:
1.18 ! tedu 1389: //buf_strdefine(&userdef_buf, "YY_NO_SET_IN", "1");
! 1390: buf_m4_define(&m4defs_buf, "M4_YY_NO_SET_IN", 0);
1.16 tedu 1391: break;
1392: case OPT_NO_YYGET_OUT:
1.18 ! tedu 1393: //buf_strdefine(&userdef_buf, "YY_NO_GET_OUT", "1");
! 1394: buf_m4_define(&m4defs_buf, "M4_YY_NO_GET_OUT", 0);
1.16 tedu 1395: break;
1396: case OPT_NO_YYSET_OUT:
1.18 ! tedu 1397: //buf_strdefine(&userdef_buf, "YY_NO_SET_OUT", "1");
! 1398: buf_m4_define(&m4defs_buf, "M4_YY_NO_SET_OUT", 0);
1.16 tedu 1399: break;
1400: case OPT_NO_YYGET_LVAL:
1.18 ! tedu 1401: //buf_strdefine(&userdef_buf, "YY_NO_GET_LVAL", "1");
! 1402: buf_m4_define(&m4defs_buf, "M4_YY_NO_GET_LVAL", 0);
1.16 tedu 1403: break;
1404: case OPT_NO_YYSET_LVAL:
1.18 ! tedu 1405: //buf_strdefine(&userdef_buf, "YY_NO_SET_LVAL", "1");
! 1406: buf_m4_define(&m4defs_buf, "M4_YY_NO_SET_LVAL", 0);
1.16 tedu 1407: break;
1408: case OPT_NO_YYGET_LLOC:
1.18 ! tedu 1409: //buf_strdefine(&userdef_buf, "YY_NO_GET_LLOC", "1");
! 1410: buf_m4_define(&m4defs_buf, "M4_YY_NO_GET_LLOC", 0);
1.16 tedu 1411: break;
1412: case OPT_NO_YYSET_LLOC:
1.18 ! tedu 1413: //buf_strdefine(&userdef_buf, "YY_NO_SET_LLOC", "1");
! 1414: buf_m4_define(&m4defs_buf, "M4_YY_NO_SET_LLOC", 0);
1.16 tedu 1415: break;
1416:
1417: } /* switch */
1418: } /* while scanopt() */
1419:
1.18 ! tedu 1420: scanopt_destroy(sopt);
1.1 deraadt 1421:
1.16 tedu 1422: num_input_files = argc - optind;
1423: input_files = argv + optind;
1.18 ! tedu 1424: set_input_file(num_input_files > 0 ? input_files[0] : NULL);
1.1 deraadt 1425:
1426: lastccl = lastsc = lastdfa = lastnfa = 0;
1427: num_rules = num_eof_rules = default_rule = 0;
1428: numas = numsnpairs = tmpuses = 0;
1.16 tedu 1429: numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst =
1.18 ! tedu 1430: 0;
1.1 deraadt 1431: numuniq = numdup = hshsave = eofseen = datapos = dataline = 0;
1432: num_backing_up = onesp = numprots = 0;
1433: variable_trailing_context_rules = bol_needed = false;
1434:
1.16 tedu 1435: linenum = sectnum = 1;
1.1 deraadt 1436: firstprot = NIL;
1437:
1.18 ! tedu 1438: /*
! 1439: * Used in mkprot() so that the first proto goes in slot 1 of the
! 1440: * proto queue.
1.1 deraadt 1441: */
1442: lastprot = 1;
1443:
1.18 ! tedu 1444: set_up_initial_allocations();
1.16 tedu 1445: }
1.1 deraadt 1446:
1447:
1448: /* readin - read in the rules section of the input file(s) */
1449:
1.18 ! tedu 1450: void
! 1451: readin()
1.16 tedu 1452: {
1.1 deraadt 1453: static char yy_stdinit[] = "FILE *yyin = stdin, *yyout = stdout;";
1454: static char yy_nostdinit[] =
1.18 ! tedu 1455: "FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;";
1.1 deraadt 1456:
1.18 ! tedu 1457: line_directive_out((FILE *) 0, 1);
1.1 deraadt 1458:
1.18 ! tedu 1459: if (yyparse()) {
! 1460: pinpoint_message(_("fatal parse error"));
! 1461: flexend(1);
1.16 tedu 1462: }
1463: if (syntaxerror)
1.18 ! tedu 1464: flexend(1);
1.16 tedu 1465:
1.18 ! tedu 1466: /*
! 1467: * If the user explicitly requested posix compatibility by specifing
! 1468: * the posix-compat option, then we check for conflicting options.
! 1469: * However, if the POSIXLY_CORRECT variable is set, then we quietly
! 1470: * make flex as posix-compatible as possible. This is the
! 1471: * recommended behavior according to the GNU Coding Standards.
! 1472: *
! 1473: * Note: The posix option was added to flex to provide the posix
! 1474: * behavior of the repeat operator in regular expressions, e.g.,
! 1475: * `ab{3}'
1.16 tedu 1476: */
1477: if (posix_compat) {
1.18 ! tedu 1478: /*
! 1479: * TODO: This is where we try to make flex behave according
! 1480: * to posiz, AND check for conflicting options. How far
! 1481: * should we go with this? Should we disable all the neat-o
! 1482: * flex features?
! 1483: */
! 1484: /*
! 1485: * Update: Estes says no, since other flex features don't
! 1486: * violate posix.
1.16 tedu 1487: */
1488: }
1.18 ! tedu 1489: if (getenv("POSIXLY_CORRECT")) {
1.16 tedu 1490: posix_compat = true;
1491: }
1492: if (backing_up_report) {
1.18 ! tedu 1493: backing_up_file = fopen(backing_name, "w");
1.16 tedu 1494: if (backing_up_file == NULL)
1.18 ! tedu 1495: lerrsf(_
! 1496: ("could not create backing-up info file %s"),
! 1497: backing_name);
! 1498: } else
1.1 deraadt 1499: backing_up_file = NULL;
1500:
1.16 tedu 1501: if (yymore_really_used == true)
1.1 deraadt 1502: yymore_used = true;
1.16 tedu 1503: else if (yymore_really_used == false)
1.1 deraadt 1504: yymore_used = false;
1505:
1.16 tedu 1506: if (reject_really_used == true)
1.1 deraadt 1507: reject = true;
1.16 tedu 1508: else if (reject_really_used == false)
1.1 deraadt 1509: reject = false;
1510:
1.16 tedu 1511: if (performance_report > 0) {
1512: if (lex_compat) {
1.18 ! tedu 1513: fprintf(stderr,
! 1514: _
! 1515: ("-l AT&T lex compatibility option entails a large performance penalty\n"));
! 1516: fprintf(stderr,
! 1517: _
! 1518: (" and may be the actual source of other reported performance penalties\n"));
! 1519: } else if (do_yylineno) {
! 1520: fprintf(stderr,
! 1521: _
! 1522: ("%%option yylineno entails a performance penalty ONLY on rules that can match newline characters\n"));
1.16 tedu 1523: }
1524: if (performance_report > 1) {
1525: if (interactive)
1.18 ! tedu 1526: fprintf(stderr,
! 1527: _
! 1528: ("-I (interactive) entails a minor performance penalty\n"));
1.16 tedu 1529:
1530: if (yymore_used)
1.18 ! tedu 1531: fprintf(stderr,
! 1532: _
! 1533: ("yymore() entails a minor performance penalty\n"));
1.16 tedu 1534: }
1535: if (reject)
1.18 ! tedu 1536: fprintf(stderr,
! 1537: _
! 1538: ("REJECT entails a large performance penalty\n"));
1.16 tedu 1539:
1540: if (variable_trailing_context_rules)
1.18 ! tedu 1541: fprintf(stderr,
! 1542: _
! 1543: ("Variable trailing context rules entail a large performance penalty\n"));
1.16 tedu 1544: }
1545: if (reject)
1.1 deraadt 1546: real_reject = true;
1547:
1.16 tedu 1548: if (variable_trailing_context_rules)
1.1 deraadt 1549: reject = true;
1550:
1.16 tedu 1551: if ((fulltbl || fullspd) && reject) {
1552: if (real_reject)
1.18 ! tedu 1553: flexerror(_
! 1554: ("REJECT cannot be used with -f or -F"));
1.16 tedu 1555: else if (do_yylineno)
1.18 ! tedu 1556: flexerror(_
! 1557: ("%option yylineno cannot be used with REJECT"));
1.1 deraadt 1558: else
1.18 ! tedu 1559: flexerror(_
! 1560: ("variable trailing context rules cannot be used with -f or -F"));
! 1561: }
! 1562: if (reject) {
! 1563: out_m4_define("M4_YY_USES_REJECT", NULL);
! 1564: //outn("\n#define YY_USES_REJECT");
1.16 tedu 1565: }
1566: if (!do_yywrap) {
1567: if (!C_plus_plus)
1.18 ! tedu 1568: if (reentrant)
! 1569: outn("\n#define yywrap(yyscanner) 1");
! 1570: else
! 1571: outn("\n#define yywrap() 1");
! 1572: outn("#define YY_SKIP_YYWRAP");
1.16 tedu 1573: }
1574: if (ddebug)
1.18 ! tedu 1575: outn("\n#define FLEX_DEBUG");
1.1 deraadt 1576:
1.18 ! tedu 1577: OUT_BEGIN_CODE();
1.16 tedu 1578: if (csize == 256)
1.18 ! tedu 1579: outn("typedef unsigned char YY_CHAR;");
1.1 deraadt 1580: else
1.18 ! tedu 1581: outn("typedef char YY_CHAR;");
! 1582: OUT_END_CODE();
1.16 tedu 1583:
1584: if (C_plus_plus) {
1.18 ! tedu 1585: outn("#define yytext_ptr yytext");
1.1 deraadt 1586:
1.16 tedu 1587: if (interactive)
1.18 ! tedu 1588: outn("#define YY_INTERACTIVE");
! 1589: } else {
! 1590: OUT_BEGIN_CODE();
1.16 tedu 1591: /* In reentrant scanner, stdinit is handled in flex.skl. */
1592: if (do_stdinit) {
1.18 ! tedu 1593: if (reentrant) {
! 1594: outn("#ifdef VMS");
! 1595: outn("#ifdef __VMS_POSIX");
! 1596: outn("#define YY_STDINIT");
! 1597: outn("#endif");
! 1598: outn("#else");
! 1599: outn("#define YY_STDINIT");
! 1600: outn("#endif");
1.17 tedu 1601: }
1.18 ! tedu 1602: outn("#ifdef VMS");
! 1603: outn("#ifndef __VMS_POSIX");
! 1604: outn(yy_nostdinit);
! 1605: outn("#else");
! 1606: outn(yy_stdinit);
! 1607: outn("#endif");
! 1608: outn("#else");
! 1609: outn(yy_stdinit);
! 1610: outn("#endif");
1.17 tedu 1611: } else {
1.18 ! tedu 1612: if (!reentrant)
! 1613: outn(yy_nostdinit);
1.1 deraadt 1614: }
1.18 ! tedu 1615: OUT_END_CODE();
1.16 tedu 1616: }
1.1 deraadt 1617:
1.18 ! tedu 1618: OUT_BEGIN_CODE();
1.16 tedu 1619: if (fullspd)
1.18 ! tedu 1620: outn("typedef yyconst struct yy_trans_info *yy_state_type;");
1.16 tedu 1621: else if (!C_plus_plus)
1.18 ! tedu 1622: outn("typedef int yy_state_type;");
! 1623: OUT_END_CODE();
1.16 tedu 1624:
1625: if (lex_compat)
1.18 ! tedu 1626: outn("#define YY_FLEX_LEX_COMPAT");
1.16 tedu 1627:
1628: if (!C_plus_plus && !reentrant) {
1.18 ! tedu 1629: outn("extern int yylineno;");
! 1630: OUT_BEGIN_CODE();
! 1631: outn("int yylineno = 1;");
! 1632: OUT_END_CODE();
1.16 tedu 1633: }
1634: if (C_plus_plus) {
1.18 ! tedu 1635: outn("\n#include <FlexLexer.h>");
1.1 deraadt 1636:
1.18 ! tedu 1637: if (!do_yywrap) {
1.16 tedu 1638: outn("\nint yyFlexLexer::yywrap() { return 1; }");
1.1 deraadt 1639: }
1.16 tedu 1640: if (yyclass) {
1.18 ! tedu 1641: outn("int yyFlexLexer::yylex()");
! 1642: outn("\t{");
! 1643: outn("\tLexerError( \"yyFlexLexer::yylex invoked but %option yyclass used\" );");
! 1644: outn("\treturn 0;");
! 1645: outn("\t}");
1.1 deraadt 1646:
1.18 ! tedu 1647: out_str("\n#define YY_DECL int %s::yylex()\n",
! 1648: yyclass);
1.1 deraadt 1649: }
1.18 ! tedu 1650: } else {
1.1 deraadt 1651:
1.18 ! tedu 1652: /*
! 1653: * Watch out: yytext_ptr is a variable when yytext is an
! 1654: * array, but it's a macro when yytext is a pointer.
1.16 tedu 1655: */
1656: if (yytext_is_array) {
1657: if (!reentrant)
1.18 ! tedu 1658: outn("extern char yytext[];\n");
! 1659: } else {
1.16 tedu 1660: if (reentrant) {
1.18 ! tedu 1661: outn("#define yytext_ptr yytext_r");
! 1662: } else {
! 1663: outn("extern char *yytext;");
! 1664: outn("#define yytext_ptr yytext");
1.1 deraadt 1665: }
1.16 tedu 1666: }
1.1 deraadt 1667:
1.16 tedu 1668: if (yyclass)
1.18 ! tedu 1669: flexerror(_
! 1670: ("%option yyclass only meaningful for C++ scanners"));
1.16 tedu 1671: }
1.1 deraadt 1672:
1.16 tedu 1673: if (useecs)
1.18 ! tedu 1674: numecs = cre8ecs(nextecm, ecgroup, csize);
1.1 deraadt 1675: else
1676: numecs = csize;
1677:
1678: /* Now map the equivalence class for NUL to its expected place. */
1679: ecgroup[0] = ecgroup[csize];
1.18 ! tedu 1680: NUL_ec = ABS(ecgroup[0]);
1.1 deraadt 1681:
1.16 tedu 1682: if (useecs)
1.18 ! tedu 1683: ccl2ecl();
1.16 tedu 1684: }
1.1 deraadt 1685:
1686:
1687: /* set_up_initial_allocations - allocate memory for internal tables */
1688:
1.18 ! tedu 1689: void
! 1690: set_up_initial_allocations()
1.16 tedu 1691: {
1692: maximum_mns = (long_align ? MAXIMUM_MNS_LONG : MAXIMUM_MNS);
1.1 deraadt 1693: current_mns = INITIAL_MNS;
1.18 ! tedu 1694: firstst = allocate_integer_array(current_mns);
! 1695: lastst = allocate_integer_array(current_mns);
! 1696: finalst = allocate_integer_array(current_mns);
! 1697: transchar = allocate_integer_array(current_mns);
! 1698: trans1 = allocate_integer_array(current_mns);
! 1699: trans2 = allocate_integer_array(current_mns);
! 1700: accptnum = allocate_integer_array(current_mns);
! 1701: assoc_rule = allocate_integer_array(current_mns);
! 1702: state_type = allocate_integer_array(current_mns);
1.1 deraadt 1703:
1704: current_max_rules = INITIAL_MAX_RULES;
1.18 ! tedu 1705: rule_type = allocate_integer_array(current_max_rules);
! 1706: rule_linenum = allocate_integer_array(current_max_rules);
! 1707: rule_useful = allocate_integer_array(current_max_rules);
! 1708: rule_has_nl = allocate_bool_array(current_max_rules);
1.1 deraadt 1709:
1710: current_max_scs = INITIAL_MAX_SCS;
1.18 ! tedu 1711: scset = allocate_integer_array(current_max_scs);
! 1712: scbol = allocate_integer_array(current_max_scs);
! 1713: scxclu = allocate_integer_array(current_max_scs);
! 1714: sceof = allocate_integer_array(current_max_scs);
! 1715: scname = allocate_char_ptr_array(current_max_scs);
1.1 deraadt 1716:
1717: current_maxccls = INITIAL_MAX_CCLS;
1.18 ! tedu 1718: cclmap = allocate_integer_array(current_maxccls);
! 1719: ccllen = allocate_integer_array(current_maxccls);
! 1720: cclng = allocate_integer_array(current_maxccls);
! 1721: ccl_has_nl = allocate_bool_array(current_maxccls);
1.1 deraadt 1722:
1723: current_max_ccl_tbl_size = INITIAL_MAX_CCL_TBL_SIZE;
1.18 ! tedu 1724: ccltbl = allocate_Character_array(current_max_ccl_tbl_size);
1.1 deraadt 1725:
1726: current_max_dfa_size = INITIAL_MAX_DFA_SIZE;
1727:
1728: current_max_xpairs = INITIAL_MAX_XPAIRS;
1.18 ! tedu 1729: nxt = allocate_integer_array(current_max_xpairs);
! 1730: chk = allocate_integer_array(current_max_xpairs);
1.1 deraadt 1731:
1732: current_max_template_xpairs = INITIAL_MAX_TEMPLATE_XPAIRS;
1.18 ! tedu 1733: tnxt = allocate_integer_array(current_max_template_xpairs);
1.1 deraadt 1734:
1735: current_max_dfas = INITIAL_MAX_DFAS;
1.18 ! tedu 1736: base = allocate_integer_array(current_max_dfas);
! 1737: def = allocate_integer_array(current_max_dfas);
! 1738: dfasiz = allocate_integer_array(current_max_dfas);
! 1739: accsiz = allocate_integer_array(current_max_dfas);
! 1740: dhash = allocate_integer_array(current_max_dfas);
! 1741: dss = allocate_int_ptr_array(current_max_dfas);
! 1742: dfaacc = allocate_dfaacc_union(current_max_dfas);
1.1 deraadt 1743:
1744: nultrans = (int *) 0;
1.16 tedu 1745: }
1.1 deraadt 1746:
1747:
1.16 tedu 1748: /* extracts basename from path, optionally stripping the extension "\.*"
1749: * (same concept as /bin/sh `basename`, but different handling of extension). */
1.18 ! tedu 1750: static char *
! 1751: basename2(path, strip_ext)
! 1752: char *path;
! 1753: int strip_ext; /* boolean */
1.16 tedu 1754: {
1.18 ! tedu 1755: char *b, *e = 0;
1.16 tedu 1756:
1757: b = path;
1758: for (b = path; *path; path++)
1759: if (*path == '/')
1760: b = path + 1;
1761: else if (*path == '.')
1762: e = path;
1763:
1764: if (strip_ext && e && e > b)
1765: *e = '\0';
1766: return b;
1767: }
1768:
1.18 ! tedu 1769: void
! 1770: usage()
1.16 tedu 1771: {
1.18 ! tedu 1772: FILE *f = stdout;
1.16 tedu 1773:
1774: if (!did_outfilename) {
1.18 ! tedu 1775: snprintf(outfile_path, sizeof(outfile_path), outfile_template,
! 1776: prefix, C_plus_plus ? "cc" : "c");
1.16 tedu 1777: outfilename = outfile_path;
1778: }
1.18 ! tedu 1779: fprintf(f, _("Usage: %s [OPTIONS] [FILE]...\n"), program_name);
! 1780: fprintf(f,
! 1781: _
! 1782: ("Generates programs that perform pattern-matching on text.\n"
! 1783: "\n" "Table Compression:\n"
! 1784: " -Ca, --align trade off larger tables for better memory alignment\n"
! 1785: " -Ce, --ecs construct equivalence classes\n"
! 1786: " -Cf do not compress tables; use -f representation\n"
! 1787: " -CF do not compress tables; use -F representation\n"
! 1788: " -Cm, --meta-ecs construct meta-equivalence classes\n"
! 1789: " -Cr, --read use read() instead of stdio for scanner input\n"
! 1790: " -f, --full generate fast, large scanner. Same as -Cfr\n"
! 1791: " -F, --fast use alternate table representation. Same as -CFr\n"
! 1792: " -Cem default compression (same as --ecs --meta-ecs)\n"
! 1793: "\n" "Debugging:\n"
! 1794: " -d, --debug enable debug mode in scanner\n"
! 1795: " -b, --backup write backing-up information to %s\n"
! 1796: " -p, --perf-report write performance report to stderr\n"
! 1797: " -s, --nodefault suppress default rule to ECHO unmatched text\n"
! 1798: " -T, --trace %s should run in trace mode\n"
! 1799: " -w, --nowarn do not generate warnings\n"
! 1800: " -v, --verbose write summary of scanner statistics to stdout\n"
! 1801: "\n" "Files:\n"
! 1802: " -o, --outfile=FILE specify output filename\n"
! 1803: " -S, --skel=FILE specify skeleton file\n"
! 1804: " -t, --stdout write scanner on stdout instead of %s\n"
! 1805: " --yyclass=NAME name of C++ class\n"
! 1806: " --header-file=FILE create a C header file in addition to the scanner\n"
! 1807: " --tables-file[=FILE] write tables to FILE\n" "\n"
! 1808: "Scanner behavior:\n"
! 1809: " -7, --7bit generate 7-bit scanner\n"
! 1810: " -8, --8bit generate 8-bit scanner\n"
! 1811: " -B, --batch generate batch scanner (opposite of -I)\n"
! 1812: " -i, --case-insensitive ignore case in patterns\n"
! 1813: " -l, --lex-compat maximal compatibility with original lex\n"
! 1814: " -X, --posix-compat maximal compatibility with POSIX lex\n"
! 1815: " -I, --interactive generate interactive scanner (opposite of -B)\n"
! 1816: " --yylineno track line count in yylineno\n"
! 1817: "\n" "Generated code:\n"
! 1818: " -+, --c++ generate C++ scanner class\n"
! 1819: " -Dmacro[=defn] #define macro defn (default defn is '1')\n"
! 1820: " -L, --noline suppress #line directives in scanner\n"
! 1821: " -P, --prefix=STRING use STRING as prefix instead of \"yy\"\n"
! 1822: " -R, --reentrant generate a reentrant C scanner\n"
! 1823: " --bison-bridge scanner for bison pure parser.\n"
! 1824: " --bison-locations include yylloc support.\n"
! 1825: " --stdinit initialize yyin/yyout to stdin/stdout\n"
! 1826: " --noansi-definitions old-style function definitions\n"
! 1827: " --noansi-prototypes empty parameter list in prototypes\n"
! 1828: " --nounistd do not include <unistd.h>\n"
! 1829: " --noFUNCTION do not generate a particular FUNCTION\n"
! 1830: "\n" "Miscellaneous:\n"
! 1831: " -n do-nothing POSIX option\n"
! 1832: " -?\n"
! 1833: " -h, --help produce this help message\n"
! 1834: " -V, --version report %s version\n"),
! 1835: backing_name, program_name, outfile_path, program_name);
1.1 deraadt 1836:
1.16 tedu 1837: }