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