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