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