Annotation of src/usr.bin/lex/flexdef.h, Revision 1.13
1.13 ! mmcc 1: /* $OpenBSD: flexdef.h,v 1.12 2015/11/19 23:20:34 tedu Exp $ */
1.2 deraadt 2:
1.1 deraadt 3: /* flexdef - definitions file for flex */
4:
1.9 tedu 5: /* Copyright (c) 1990 The Regents of the University of California. */
6: /* All rights reserved. */
7:
8: /* This code is derived from software contributed to Berkeley by */
9: /* Vern Paxson. */
1.1 deraadt 10:
1.9 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.1 deraadt 35:
1.9 tedu 36: #ifndef FLEXDEF_H
37: #define FLEXDEF_H 1
1.1 deraadt 38:
1.9 tedu 39: #ifdef HAVE_CONFIG_H
40: #include <config.h>
41: #endif
1.1 deraadt 42:
1.9 tedu 43: /* AIX requires this to be the first thing in the file. */
44: #ifndef __GNUC__
45: # if HAVE_ALLOCA_H
46: # include <alloca.h>
47: # else
48: # ifdef _AIX
49: #pragma alloca
50: # else
51: # ifndef alloca /* predefined by HP cc +Olibcalls */
52: char *alloca ();
53: # endif
54: # endif
55: # endif
1.1 deraadt 56: #endif
57:
1.9 tedu 58: #ifdef STDC_HEADERS
59: #include <stdio.h>
60: #include <stdlib.h>
61: #include <stdarg.h>
62: #include <setjmp.h>
63: #include <ctype.h>
1.1 deraadt 64: #include <string.h>
1.9 tedu 65: #include <math.h>
66: #endif
67: #ifdef HAVE_ASSERT_H
68: #include <assert.h>
1.1 deraadt 69: #else
1.9 tedu 70: #define assert(Pred)
1.1 deraadt 71: #endif
72:
1.9 tedu 73: #ifdef HAVE_LIMITS_H
74: #include <limits.h>
1.1 deraadt 75: #endif
1.9 tedu 76: #ifdef HAVE_UNISTD_H
1.8 deraadt 77: #include <unistd.h>
1.9 tedu 78: #endif
79: #ifdef HAVE_NETINET_IN_H
80: #include <netinet/in.h>
81: #endif
82: #ifdef HAVE_SYS_PARAMS_H
83: #include <sys/params.h>
84: #endif
85: #ifdef HAVE_SYS_WAIT_H
86: #include <sys/wait.h>
87: #endif
88: #ifdef HAVE_STDBOOL_H
89: #include <stdbool.h>
1.7 espie 90: #else
1.9 tedu 91: #define bool int
92: #define true 1
93: #define false 0
1.1 deraadt 94: #endif
1.9 tedu 95: #ifdef HAVE_REGEX_H
96: #include <regex.h>
1.7 espie 97: #endif
1.9 tedu 98: #include "flexint.h"
1.1 deraadt 99:
1.9 tedu 100: /* We use gettext. So, when we write strings which should be translated, we mark them with _() */
101: #ifdef ENABLE_NLS
102: #ifdef HAVE_LOCALE_H
103: #include <locale.h>
104: #endif /* HAVE_LOCALE_H */
105: #include "gettext.h"
106: #define _(String) gettext (String)
107: #else
108: #define _(STRING) STRING
109: #endif /* ENABLE_NLS */
1.1 deraadt 110:
111: /* Always be prepared to generate an 8-bit scanner. */
112: #define CSIZE 256
113:
114: /* Size of input alphabet - should be size of ASCII set. */
115: #ifndef DEFAULT_CSIZE
116: #define DEFAULT_CSIZE 128
117: #endif
118:
119: #ifndef PROTO
1.9 tedu 120: #if defined(__STDC__)
1.1 deraadt 121: #define PROTO(proto) proto
122: #else
123: #define PROTO(proto) ()
124: #endif
125: #endif
126:
127: /* Maximum line length we'll have to deal with. */
128: #define MAXLINE 2048
129:
130: #ifndef MIN
131: #define MIN(x,y) ((x) < (y) ? (x) : (y))
132: #endif
133: #ifndef MAX
134: #define MAX(x,y) ((x) > (y) ? (x) : (y))
135: #endif
136: #ifndef ABS
137: #define ABS(x) ((x) < 0 ? -(x) : (x))
138: #endif
139:
140:
141: /* ANSI C does not guarantee that isascii() is defined */
142: #ifndef isascii
143: #define isascii(c) ((c) <= 0177)
144: #endif
145:
146: #define unspecified -1
147:
148: /* Special chk[] values marking the slots taking by end-of-buffer and action
149: * numbers.
150: */
151: #define EOB_POSITION -1
152: #define ACTION_POSITION -2
153:
154: /* Number of data items per line for -f output. */
155: #define NUMDATAITEMS 10
156:
157: /* Number of lines of data in -f output before inserting a blank line for
158: * readability.
159: */
160: #define NUMDATALINES 10
161:
162: /* transition_struct_out() definitions. */
163: #define TRANS_STRUCT_PRINT_LENGTH 14
164:
165: /* Returns true if an nfa state has an epsilon out-transition slot
166: * that can be used. This definition is currently not used.
167: */
168: #define FREE_EPSILON(state) \
169: (transchar[state] == SYM_EPSILON && \
170: trans2[state] == NO_TRANSITION && \
171: finalst[state] != state)
172:
173: /* Returns true if an nfa state has an epsilon out-transition character
174: * and both slots are free
175: */
176: #define SUPER_FREE_EPSILON(state) \
177: (transchar[state] == SYM_EPSILON && \
178: trans1[state] == NO_TRANSITION) \
179:
180: /* Maximum number of NFA states that can comprise a DFA state. It's real
181: * big because if there's a lot of rules, the initial state will have a
182: * huge epsilon closure.
183: */
184: #define INITIAL_MAX_DFA_SIZE 750
185: #define MAX_DFA_SIZE_INCREMENT 750
186:
187:
188: /* A note on the following masks. They are used to mark accepting numbers
189: * as being special. As such, they implicitly limit the number of accepting
190: * numbers (i.e., rules) because if there are too many rules the rule numbers
191: * will overload the mask bits. Fortunately, this limit is \large/ (0x2000 ==
192: * 8192) so unlikely to actually cause any problems. A check is made in
193: * new_rule() to ensure that this limit is not reached.
194: */
195:
196: /* Mask to mark a trailing context accepting number. */
197: #define YY_TRAILING_MASK 0x2000
198:
199: /* Mask to mark the accepting number of the "head" of a trailing context
200: * rule.
201: */
202: #define YY_TRAILING_HEAD_MASK 0x4000
203:
204: /* Maximum number of rules, as outlined in the above note. */
205: #define MAX_RULE (YY_TRAILING_MASK - 1)
206:
207:
208: /* NIL must be 0. If not, its special meaning when making equivalence classes
209: * (it marks the representative of a given e.c.) will be unidentifiable.
210: */
211: #define NIL 0
212:
1.9 tedu 213: #define JAM -1 /* to mark a missing DFA transition */
1.1 deraadt 214: #define NO_TRANSITION NIL
1.9 tedu 215: #define UNIQUE -1 /* marks a symbol as an e.c. representative */
216: #define INFINITE_REPEAT -1 /* for x{5,} constructions */
1.1 deraadt 217:
218: #define INITIAL_MAX_CCLS 100 /* max number of unique character classes */
219: #define MAX_CCLS_INCREMENT 100
220:
221: /* Size of table holding members of character classes. */
222: #define INITIAL_MAX_CCL_TBL_SIZE 500
223: #define MAX_CCL_TBL_SIZE_INCREMENT 250
224:
225: #define INITIAL_MAX_RULES 100 /* default maximum number of rules */
226: #define MAX_RULES_INCREMENT 100
227:
228: #define INITIAL_MNS 2000 /* default maximum number of nfa states */
229: #define MNS_INCREMENT 1000 /* amount to bump above by if it's not enough */
230:
231: #define INITIAL_MAX_DFAS 1000 /* default maximum number of dfa states */
232: #define MAX_DFAS_INCREMENT 1000
233:
1.9 tedu 234: #define JAMSTATE -32766 /* marks a reference to the state that always jams */
1.1 deraadt 235:
236: /* Maximum number of NFA states. */
237: #define MAXIMUM_MNS 31999
1.9 tedu 238: #define MAXIMUM_MNS_LONG 1999999999
1.1 deraadt 239:
240: /* Enough so that if it's subtracted from an NFA state number, the result
241: * is guaranteed to be negative.
242: */
1.9 tedu 243: #define MARKER_DIFFERENCE (maximum_mns+2)
1.1 deraadt 244:
245: /* Maximum number of nxt/chk pairs for non-templates. */
246: #define INITIAL_MAX_XPAIRS 2000
247: #define MAX_XPAIRS_INCREMENT 2000
248:
249: /* Maximum number of nxt/chk pairs needed for templates. */
250: #define INITIAL_MAX_TEMPLATE_XPAIRS 2500
251: #define MAX_TEMPLATE_XPAIRS_INCREMENT 2500
252:
253: #define SYM_EPSILON (CSIZE + 1) /* to mark transitions on the symbol epsilon */
254:
255: #define INITIAL_MAX_SCS 40 /* maximum number of start conditions */
256: #define MAX_SCS_INCREMENT 40 /* amount to bump by if it's not enough */
257:
258: #define ONE_STACK_SIZE 500 /* stack of states with only one out-transition */
1.9 tedu 259: #define SAME_TRANS -1 /* transition is the same as "default" entry for state */
1.1 deraadt 260:
261: /* The following percentages are used to tune table compression:
262:
263: * The percentage the number of out-transitions a state must be of the
264: * number of equivalence classes in order to be considered for table
265: * compaction by using protos.
266: */
267: #define PROTO_SIZE_PERCENTAGE 15
268:
269: /* The percentage the number of homogeneous out-transitions of a state
270: * must be of the number of total out-transitions of the state in order
1.9 tedu 271: * that the state's transition table is first compared with a potential
1.1 deraadt 272: * template of the most common out-transition instead of with the first
273: * proto in the proto queue.
274: */
275: #define CHECK_COM_PERCENTAGE 50
276:
277: /* The percentage the number of differences between a state's transition
278: * table and the proto it was first compared with must be of the total
279: * number of out-transitions of the state in order to keep the first
280: * proto as a good match and not search any further.
281: */
282: #define FIRST_MATCH_DIFF_PERCENTAGE 10
283:
284: /* The percentage the number of differences between a state's transition
285: * table and the most similar proto must be of the state's total number
286: * of out-transitions to use the proto as an acceptable close match.
287: */
288: #define ACCEPTABLE_DIFF_PERCENTAGE 50
289:
290: /* The percentage the number of homogeneous out-transitions of a state
291: * must be of the number of total out-transitions of the state in order
292: * to consider making a template from the state.
293: */
294: #define TEMPLATE_SAME_PERCENTAGE 60
295:
296: /* The percentage the number of differences between a state's transition
297: * table and the most similar proto must be of the state's total number
298: * of out-transitions to create a new proto from the state.
299: */
300: #define NEW_PROTO_DIFF_PERCENTAGE 20
301:
302: /* The percentage the total number of out-transitions of a state must be
303: * of the number of equivalence classes in order to consider trying to
304: * fit the transition table into "holes" inside the nxt/chk table.
305: */
306: #define INTERIOR_FIT_PERCENTAGE 15
307:
308: /* Size of region set aside to cache the complete transition table of
309: * protos on the proto queue to enable quick comparisons.
310: */
311: #define PROT_SAVE_SIZE 2000
312:
1.9 tedu 313: #define MSP 50 /* maximum number of saved protos (protos on the proto queue) */
1.1 deraadt 314:
315: /* Maximum number of out-transitions a state can have that we'll rummage
316: * around through the interior of the internal fast table looking for a
317: * spot for it.
318: */
319: #define MAX_XTIONS_FULL_INTERIOR_FIT 4
320:
321: /* Maximum number of rules which will be reported as being associated
322: * with a DFA state.
323: */
324: #define MAX_ASSOC_RULES 100
325:
326: /* Number that, if used to subscript an array, has a good chance of producing
327: * an error; should be small enough to fit into a short.
328: */
329: #define BAD_SUBSCRIPT -32767
330:
331: /* Absolute value of largest number that can be stored in a short, with a
332: * bit of slop thrown in for general paranoia.
333: */
334: #define MAX_SHORT 32700
335:
336:
337: /* Declarations for global variables. */
338:
339:
340: /* Variables for flags:
341: * printstats - if true (-v), dump statistics
342: * syntaxerror - true if a syntax error has been found
343: * eofseen - true if we've seen an eof in the input file
344: * ddebug - if true (-d), make a "debug" scanner
345: * trace - if true (-T), trace processing
346: * nowarn - if true (-w), do not generate warnings
347: * spprdflt - if true (-s), suppress the default rule
348: * interactive - if true (-I), generate an interactive scanner
349: * lex_compat - if true (-l), maximize compatibility with AT&T lex
1.9 tedu 350: * posix_compat - if true (-X), maximize compatibility with POSIX lex
1.1 deraadt 351: * do_yylineno - if true, generate code to maintain yylineno
352: * useecs - if true (-Ce flag), use equivalence classes
353: * fulltbl - if true (-Cf flag), don't compress the DFA state table
354: * usemecs - if true (-Cm flag), use meta-equivalence classes
355: * fullspd - if true (-F flag), use Jacobson method of table representation
356: * gen_line_dirs - if true (i.e., no -L flag), generate #line directives
357: * performance_report - if > 0 (i.e., -p flag), generate a report relating
358: * to scanner performance; if > 1 (-p -p), report on minor performance
359: * problems, too
360: * backing_up_report - if true (i.e., -b flag), generate "lex.backup" file
361: * listing backing-up states
362: * C_plus_plus - if true (i.e., -+ flag), generate a C++ scanner class;
363: * otherwise, a standard C scanner
1.9 tedu 364: * reentrant - if true (-R), generate a reentrant C scanner.
365: * bison_bridge_lval - if true (--bison-bridge), bison pure calling convention.
366: * bison_bridge_lloc - if true (--bison-locations), bison yylloc.
1.1 deraadt 367: * long_align - if true (-Ca flag), favor long-word alignment.
368: * use_read - if true (-f, -F, or -Cr) then use read() for scanner input;
369: * otherwise, use fread().
370: * yytext_is_array - if true (i.e., %array directive), then declare
371: * yytext as a array instead of a character pointer. Nice and inefficient.
372: * do_yywrap - do yywrap() processing on EOF. If false, EOF treated as
373: * "no more files".
374: * csize - size of character set for the scanner we're generating;
375: * 128 for 7-bit chars and 256 for 8-bit
376: * yymore_used - if true, yymore() is used in input rules
377: * reject - if true, generate back-up tables for REJECT macro
378: * real_reject - if true, scanner really uses REJECT (as opposed to just
379: * having "reject" set for variable trailing context)
380: * continued_action - true if this rule's action is to "fall through" to
381: * the next rule's action (i.e., the '|' action)
382: * in_rule - true if we're inside an individual rule, false if not.
383: * yymore_really_used - whether to treat yymore() as really used, regardless
384: * of what we think based on references to it in the user's actions.
385: * reject_really_used - same for REJECT
386: */
387:
1.9 tedu 388: extern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn,
389: spprdflt;
390: extern int interactive, lex_compat, posix_compat, do_yylineno;
1.1 deraadt 391: extern int useecs, fulltbl, usemecs, fullspd;
392: extern int gen_line_dirs, performance_report, backing_up_report;
1.9 tedu 393: extern int reentrant, bison_bridge_lval, bison_bridge_lloc;
394: extern bool ansi_func_defs, ansi_func_protos;
1.1 deraadt 395: extern int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap;
396: extern int csize;
397: extern int yymore_used, reject, real_reject, continued_action, in_rule;
398:
399: extern int yymore_really_used, reject_really_used;
400:
401:
402: /* Variables used in the flex input routines:
403: * datapos - characters on current output line
404: * dataline - number of contiguous lines of data in current data
405: * statement. Used to generate readable -f output
406: * linenum - current input line number
407: * skelfile - the skeleton file
408: * skel - compiled-in skeleton array
409: * skel_ind - index into "skel" array, if skelfile is nil
410: * yyin - input file
411: * backing_up_file - file to summarize backing-up states to
412: * infilename - name of input file
413: * outfilename - name of output file
1.9 tedu 414: * headerfilename - name of the .h file to generate
1.1 deraadt 415: * did_outfilename - whether outfilename was explicitly set
416: * prefix - the prefix used for externally visible names ("yy" by default)
417: * yyclass - yyFlexLexer subclass to use for YY_DECL
418: * do_stdinit - whether to initialize yyin/yyout to stdin/stdout
419: * use_stdout - the -t flag
420: * input_files - array holding names of input files
421: * num_input_files - size of input_files array
1.9 tedu 422: * program_name - name with which program was invoked
1.1 deraadt 423: *
424: * action_array - array to hold the rule actions
425: * action_size - size of action_array
426: * defs1_offset - index where the user's section 1 definitions start
427: * in action_array
428: * prolog_offset - index where the prolog starts in action_array
429: * action_offset - index where the non-prolog starts in action_array
430: * action_index - index where the next action should go, with respect
431: * to "action_array"
432: */
433:
1.9 tedu 434: extern int datapos, dataline, linenum;
1.1 deraadt 435: extern FILE *skelfile, *yyin, *backing_up_file;
436: extern const char *skel[];
437: extern int skel_ind;
1.9 tedu 438: extern char *infilename, *outfilename, *headerfilename;
1.1 deraadt 439: extern int did_outfilename;
1.9 tedu 440: extern char *prefix, *yyclass, *extra_type;
1.1 deraadt 441: extern int do_stdinit, use_stdout;
442: extern char **input_files;
443: extern int num_input_files;
444: extern char *program_name;
445:
446: extern char *action_array;
447: extern int action_size;
448: extern int defs1_offset, prolog_offset, action_offset, action_index;
449:
450:
451: /* Variables for stack of states having only one out-transition:
452: * onestate - state number
453: * onesym - transition symbol
454: * onenext - target state
455: * onedef - default base entry
456: * onesp - stack pointer
457: */
458:
459: extern int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
460: extern int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
461:
462:
463: /* Variables for nfa machine data:
1.9 tedu 464: * maximum_mns - maximal number of NFA states supported by tables
1.1 deraadt 465: * current_mns - current maximum on number of NFA states
466: * num_rules - number of the last accepting state; also is number of
467: * rules created so far
468: * num_eof_rules - number of <<EOF>> rules
469: * default_rule - number of the default rule
470: * current_max_rules - current maximum number of rules
471: * lastnfa - last nfa state number created
472: * firstst - physically the first state of a fragment
473: * lastst - last physical state of fragment
474: * finalst - last logical state of fragment
475: * transchar - transition character
476: * trans1 - transition state
477: * trans2 - 2nd transition state for epsilons
478: * accptnum - accepting number
479: * assoc_rule - rule associated with this NFA state (or 0 if none)
480: * state_type - a STATE_xxx type identifying whether the state is part
481: * of a normal rule, the leading state in a trailing context
482: * rule (i.e., the state which marks the transition from
483: * recognizing the text-to-be-matched to the beginning of
484: * the trailing context), or a subsequent state in a trailing
485: * context rule
486: * rule_type - a RULE_xxx type identifying whether this a ho-hum
487: * normal rule or one which has variable head & trailing
488: * context
489: * rule_linenum - line number associated with rule
490: * rule_useful - true if we've determined that the rule can be matched
1.9 tedu 491: * rule_has_nl - true if rule could possibly match a newline
492: * ccl_has_nl - true if current ccl could match a newline
493: * nlch - default eol char
1.1 deraadt 494: */
495:
1.9 tedu 496: extern int maximum_mns, current_mns, current_max_rules;
1.1 deraadt 497: extern int num_rules, num_eof_rules, default_rule, lastnfa;
498: extern int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
499: extern int *accptnum, *assoc_rule, *state_type;
500: extern int *rule_type, *rule_linenum, *rule_useful;
1.9 tedu 501: extern bool *rule_has_nl, *ccl_has_nl;
502: extern int nlch;
1.1 deraadt 503:
504: /* Different types of states; values are useful as masks, as well, for
505: * routines like check_trailing_context().
506: */
507: #define STATE_NORMAL 0x1
508: #define STATE_TRAILING_CONTEXT 0x2
509:
510: /* Global holding current type of state we're making. */
511:
512: extern int current_state_type;
513:
514: /* Different types of rules. */
515: #define RULE_NORMAL 0
516: #define RULE_VARIABLE 1
517:
518: /* True if the input rules include a rule with both variable-length head
519: * and trailing context, false otherwise.
520: */
521: extern int variable_trailing_context_rules;
522:
523:
524: /* Variables for protos:
525: * numtemps - number of templates created
526: * numprots - number of protos created
527: * protprev - backlink to a more-recently used proto
528: * protnext - forward link to a less-recently used proto
529: * prottbl - base/def table entry for proto
530: * protcomst - common state of proto
531: * firstprot - number of the most recently used proto
532: * lastprot - number of the least recently used proto
533: * protsave contains the entire state array for protos
534: */
535:
536: extern int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
537: extern int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
538:
539:
540: /* Variables for managing equivalence classes:
541: * numecs - number of equivalence classes
542: * nextecm - forward link of Equivalence Class members
543: * ecgroup - class number or backward link of EC members
544: * nummecs - number of meta-equivalence classes (used to compress
545: * templates)
546: * tecfwd - forward link of meta-equivalence classes members
547: * tecbck - backward link of MEC's
548: */
549:
550: /* Reserve enough room in the equivalence class arrays so that we
551: * can use the CSIZE'th element to hold equivalence class information
552: * for the NUL character. Later we'll move this information into
553: * the 0th element.
554: */
555: extern int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs;
556:
557: /* Meta-equivalence classes are indexed starting at 1, so it's possible
558: * that they will require positions from 1 .. CSIZE, i.e., CSIZE + 1
559: * slots total (since the arrays are 0-based). nextecm[] and ecgroup[]
560: * don't require the extra position since they're indexed from 1 .. CSIZE - 1.
561: */
562: extern int tecfwd[CSIZE + 1], tecbck[CSIZE + 1];
563:
564:
565: /* Variables for start conditions:
566: * lastsc - last start condition created
567: * current_max_scs - current limit on number of start conditions
568: * scset - set of rules active in start condition
569: * scbol - set of rules active only at the beginning of line in a s.c.
570: * scxclu - true if start condition is exclusive
571: * sceof - true if start condition has EOF rule
572: * scname - start condition name
573: */
574:
575: extern int lastsc, *scset, *scbol, *scxclu, *sceof;
576: extern int current_max_scs;
577: extern char **scname;
578:
579:
580: /* Variables for dfa machine data:
581: * current_max_dfa_size - current maximum number of NFA states in DFA
582: * current_max_xpairs - current maximum number of non-template xtion pairs
583: * current_max_template_xpairs - current maximum number of template pairs
584: * current_max_dfas - current maximum number DFA states
585: * lastdfa - last dfa state number created
586: * nxt - state to enter upon reading character
587: * chk - check value to see if "nxt" applies
588: * tnxt - internal nxt table for templates
589: * base - offset into "nxt" for given state
590: * def - where to go if "chk" disallows "nxt" entry
591: * nultrans - NUL transition for each state
592: * NUL_ec - equivalence class of the NUL character
593: * tblend - last "nxt/chk" table entry being used
594: * firstfree - first empty entry in "nxt/chk" table
595: * dss - nfa state set for each dfa
596: * dfasiz - size of nfa state set for each dfa
597: * dfaacc - accepting set for each dfa state (if using REJECT), or accepting
598: * number, if not
599: * accsiz - size of accepting set for each dfa state
600: * dhash - dfa state hash value
601: * numas - number of DFA accepting states created; note that this
602: * is not necessarily the same value as num_rules, which is the analogous
603: * value for the NFA
604: * numsnpairs - number of state/nextstate transition pairs
605: * jambase - position in base/def where the default jam table starts
606: * jamstate - state number corresponding to "jam" state
607: * end_of_buffer_state - end-of-buffer dfa state number
608: */
609:
610: extern int current_max_dfa_size, current_max_xpairs;
611: extern int current_max_template_xpairs, current_max_dfas;
612: extern int lastdfa, *nxt, *chk, *tnxt;
1.9 tedu 613: extern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss,
614: *dfasiz;
615: extern union dfaacc_union {
616: int *dfaacc_set;
617: int dfaacc_state;
618: } *dfaacc;
1.1 deraadt 619: extern int *accsiz, *dhash, numas;
620: extern int numsnpairs, jambase, jamstate;
621: extern int end_of_buffer_state;
622:
623: /* Variables for ccl information:
624: * lastccl - ccl index of the last created ccl
625: * current_maxccls - current limit on the maximum number of unique ccl's
626: * cclmap - maps a ccl index to its set pointer
627: * ccllen - gives the length of a ccl
628: * cclng - true for a given ccl if the ccl is negated
629: * cclreuse - counts how many times a ccl is re-used
630: * current_max_ccl_tbl_size - current limit on number of characters needed
631: * to represent the unique ccl's
632: * ccltbl - holds the characters in each ccl - indexed by cclmap
633: */
634:
635: extern int lastccl, *cclmap, *ccllen, *cclng, cclreuse;
636: extern int current_maxccls, current_max_ccl_tbl_size;
1.13 ! mmcc 637: extern u_char *ccltbl;
1.1 deraadt 638:
639:
640: /* Variables for miscellaneous information:
641: * nmstr - last NAME scanned by the scanner
642: * sectnum - section number currently being parsed
643: * nummt - number of empty nxt/chk table entries
644: * hshcol - number of hash collisions detected by snstods
645: * dfaeql - number of times a newly created dfa was equal to an old one
646: * numeps - number of epsilon NFA states created
647: * eps2 - number of epsilon states which have 2 out-transitions
648: * num_reallocs - number of times it was necessary to realloc() a group
649: * of arrays
650: * tmpuses - number of DFA states that chain to templates
651: * totnst - total number of NFA states used to make DFA states
652: * peakpairs - peak number of transition pairs we had to store internally
653: * numuniq - number of unique transitions
654: * numdup - number of duplicate transitions
655: * hshsave - number of hash collisions saved by checking number of states
656: * num_backing_up - number of DFA states requiring backing up
657: * bol_needed - whether scanner needs beginning-of-line recognition
658: */
659:
660: extern char nmstr[MAXLINE];
661: extern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
662: extern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
663: extern int num_backing_up, bol_needed;
664:
1.9 tedu 665: void *allocate_array PROTO ((int, size_t));
666: void *reallocate_array PROTO ((void *, int, size_t));
1.1 deraadt 667:
668: #define allocate_integer_array(size) \
669: (int *) allocate_array( size, sizeof( int ) )
670:
671: #define reallocate_integer_array(array,size) \
672: (int *) reallocate_array( (void *) array, size, sizeof( int ) )
673:
1.9 tedu 674: #define allocate_bool_array(size) \
675: (bool *) allocate_array( size, sizeof( bool ) )
676:
677: #define reallocate_bool_array(array,size) \
678: (bool *) reallocate_array( (void *) array, size, sizeof( bool ) )
679:
1.1 deraadt 680: #define allocate_int_ptr_array(size) \
681: (int **) allocate_array( size, sizeof( int * ) )
682:
683: #define allocate_char_ptr_array(size) \
684: (char **) allocate_array( size, sizeof( char * ) )
685:
686: #define allocate_dfaacc_union(size) \
687: (union dfaacc_union *) \
688: allocate_array( size, sizeof( union dfaacc_union ) )
689:
690: #define reallocate_int_ptr_array(array,size) \
691: (int **) reallocate_array( (void *) array, size, sizeof( int * ) )
692:
693: #define reallocate_char_ptr_array(array,size) \
694: (char **) reallocate_array( (void *) array, size, sizeof( char * ) )
695:
696: #define reallocate_dfaacc_union(array, size) \
697: (union dfaacc_union *) \
698: reallocate_array( (void *) array, size, sizeof( union dfaacc_union ) )
699:
700: #define allocate_character_array(size) \
701: (char *) allocate_array( size, sizeof( char ) )
702:
703: #define reallocate_character_array(array,size) \
704: (char *) reallocate_array( (void *) array, size, sizeof( char ) )
705:
706: #define allocate_Character_array(size) \
1.13 ! mmcc 707: (u_char *) allocate_array( size, sizeof( u_char ) )
1.1 deraadt 708:
709: #define reallocate_Character_array(array,size) \
1.13 ! mmcc 710: (u_char *) reallocate_array( (void *) array, size, sizeof( u_char ) )
1.1 deraadt 711:
712:
713: /* Used to communicate between scanner and parser. The type should really
714: * be YYSTYPE, but we can't easily get our hands on it.
715: */
716: extern int yylval;
717:
718:
719: /* External functions that are cross-referenced among the flex source files. */
720:
721:
722: /* from file ccl.c */
723:
1.9 tedu 724: extern void ccladd PROTO ((int, int)); /* add a single character to a ccl */
725: extern int cclinit PROTO ((void)); /* make an empty ccl */
726: extern void cclnegate PROTO ((int)); /* negate a ccl */
727: extern int ccl_set_diff (int a, int b); /* set difference of two ccls. */
728: extern int ccl_set_union (int a, int b); /* set union of two ccls. */
1.1 deraadt 729:
730: /* List the members of a set of characters in CCL form. */
1.9 tedu 731: extern void list_character_set PROTO ((FILE *, int[]));
1.1 deraadt 732:
733:
734: /* from file dfa.c */
735:
736: /* Check a DFA state for backing up. */
1.9 tedu 737: extern void check_for_backing_up PROTO ((int, int[]));
1.1 deraadt 738:
739: /* Check to see if NFA state set constitutes "dangerous" trailing context. */
1.9 tedu 740: extern void check_trailing_context PROTO ((int *, int, int *, int));
1.1 deraadt 741:
742: /* Construct the epsilon closure of a set of ndfa states. */
1.9 tedu 743: extern int *epsclosure PROTO ((int *, int *, int[], int *, int *));
1.1 deraadt 744:
745: /* Increase the maximum number of dfas. */
1.9 tedu 746: extern void increase_max_dfas PROTO ((void));
1.1 deraadt 747:
1.9 tedu 748: extern void ntod PROTO ((void)); /* convert a ndfa to a dfa */
1.1 deraadt 749:
750: /* Converts a set of ndfa states into a dfa state. */
1.9 tedu 751: extern int snstods PROTO ((int[], int, int[], int, int, int *));
1.1 deraadt 752:
753:
754: /* from file ecs.c */
755:
756: /* Convert character classes to set of equivalence classes. */
1.9 tedu 757: extern void ccl2ecl PROTO ((void));
1.1 deraadt 758:
759: /* Associate equivalence class numbers with class members. */
1.9 tedu 760: extern int cre8ecs PROTO ((int[], int[], int));
1.1 deraadt 761:
762: /* Update equivalence classes based on character class transitions. */
1.13 ! mmcc 763: extern void mkeccl PROTO ((u_char[], int, int[], int[], int, int));
1.1 deraadt 764:
765: /* Create equivalence class for single character. */
1.9 tedu 766: extern void mkechar PROTO ((int, int[], int[]));
1.1 deraadt 767:
768:
769: /* from file gen.c */
770:
1.9 tedu 771: extern void do_indent PROTO ((void)); /* indent to the current level */
1.1 deraadt 772:
773: /* Generate the code to keep backing-up information. */
1.9 tedu 774: extern void gen_backing_up PROTO ((void));
1.1 deraadt 775:
776: /* Generate the code to perform the backing up. */
1.9 tedu 777: extern void gen_bu_action PROTO ((void));
1.1 deraadt 778:
779: /* Generate full speed compressed transition table. */
1.9 tedu 780: extern void genctbl PROTO ((void));
1.1 deraadt 781:
782: /* Generate the code to find the action number. */
1.9 tedu 783: extern void gen_find_action PROTO ((void));
1.1 deraadt 784:
1.9 tedu 785: extern void genftbl PROTO ((void)); /* generate full transition table */
1.1 deraadt 786:
787: /* Generate the code to find the next compressed-table state. */
1.9 tedu 788: extern void gen_next_compressed_state PROTO ((char *));
1.1 deraadt 789:
790: /* Generate the code to find the next match. */
1.9 tedu 791: extern void gen_next_match PROTO ((void));
1.1 deraadt 792:
793: /* Generate the code to find the next state. */
1.9 tedu 794: extern void gen_next_state PROTO ((int));
1.1 deraadt 795:
796: /* Generate the code to make a NUL transition. */
1.9 tedu 797: extern void gen_NUL_trans PROTO ((void));
1.1 deraadt 798:
799: /* Generate the code to find the start state. */
1.9 tedu 800: extern void gen_start_state PROTO ((void));
1.1 deraadt 801:
802: /* Generate data statements for the transition tables. */
1.9 tedu 803: extern void gentabs PROTO ((void));
1.1 deraadt 804:
805: /* Write out a formatted string at the current indentation level. */
1.9 tedu 806: extern void indent_put2s PROTO ((const char *, const char *));
1.1 deraadt 807:
808: /* Write out a string + newline at the current indentation level. */
1.9 tedu 809: extern void indent_puts PROTO ((const char *));
1.1 deraadt 810:
1.9 tedu 811: extern void make_tables PROTO ((void)); /* generate transition tables */
1.1 deraadt 812:
813:
814: /* from file main.c */
815:
1.9 tedu 816: extern void check_options PROTO ((void));
817: extern void flexend PROTO ((int));
818: extern void usage PROTO ((void));
1.1 deraadt 819:
820:
821: /* from file misc.c */
822:
823: /* Add a #define to the action file. */
1.9 tedu 824: extern void action_define PROTO ((const char *defname, int value));
1.1 deraadt 825:
826: /* Add the given text to the stored actions. */
1.9 tedu 827: extern void add_action PROTO ((const char *new_text));
1.1 deraadt 828:
829: /* True if a string is all lower case. */
1.9 tedu 830: extern int all_lower PROTO ((char *));
1.1 deraadt 831:
832: /* True if a string is all upper case. */
1.9 tedu 833: extern int all_upper PROTO ((char *));
1.1 deraadt 834:
1.9 tedu 835: /* Compare two integers for use by qsort. */
836: extern int intcmp PROTO ((const void *, const void *));
1.1 deraadt 837:
838: /* Check a character to make sure it's in the expected range. */
1.9 tedu 839: extern void check_char PROTO ((int c));
1.1 deraadt 840:
841: /* Replace upper-case letter to lower-case. */
1.13 ! mmcc 842: extern u_char clower PROTO ((int));
1.1 deraadt 843:
844: /* Returns a dynamically allocated copy of a string. */
1.9 tedu 845: extern char *copy_string PROTO ((const char *));
1.1 deraadt 846:
847: /* Returns a dynamically allocated copy of a (potentially) unsigned string. */
1.13 ! mmcc 848: extern u_char *copy_unsigned_string PROTO ((u_char *));
1.1 deraadt 849:
1.9 tedu 850: /* Compare two characters for use by qsort with '\0' sorting last. */
851: extern int cclcmp PROTO ((const void *, const void *));
1.1 deraadt 852:
853: /* Finish up a block of data declarations. */
1.9 tedu 854: extern void dataend PROTO ((void));
1.1 deraadt 855:
856: /* Flush generated data statements. */
1.9 tedu 857: extern void dataflush PROTO ((void));
1.1 deraadt 858:
859: /* Report an error message and terminate. */
1.9 tedu 860: extern void flexerror PROTO ((const char *));
1.1 deraadt 861:
862: /* Report a fatal error message and terminate. */
1.9 tedu 863: extern void flexfatal PROTO ((const char *));
864:
865: /* Report a fatal error with a pinpoint, and terminate */
866: #if HAVE_DECL___FUNC__
867: #define flex_die(msg) \
868: do{ \
869: fprintf (stderr,\
870: _("%s: fatal internal error at %s:%d (%s): %s\n"),\
871: program_name, __FILE__, (int)__LINE__,\
872: __func__,msg);\
873: FLEX_EXIT(1);\
874: }while(0)
875: #else /* ! HAVE_DECL___FUNC__ */
876: #define flex_die(msg) \
877: do{ \
878: fprintf (stderr,\
879: _("%s: fatal internal error at %s:%d %s\n"),\
880: program_name, __FILE__, (int)__LINE__,\
881: msg);\
882: FLEX_EXIT(1);\
883: }while(0)
884: #endif /* ! HAVE_DECL___func__ */
1.1 deraadt 885:
886: /* Convert a hexadecimal digit string to an integer value. */
1.13 ! mmcc 887: extern int htoi PROTO ((u_char[]));
1.1 deraadt 888:
889: /* Report an error message formatted with one integer argument. */
1.9 tedu 890: extern void lerrif PROTO ((const char *, int));
1.1 deraadt 891:
892: /* Report an error message formatted with one string argument. */
1.9 tedu 893: extern void lerrsf PROTO ((const char *, const char *));
894:
895: /* Like lerrsf, but also exit after displaying message. */
896: extern void lerrsf_fatal PROTO ((const char *, const char *));
1.1 deraadt 897:
898: /* Spit out a "#line" statement. */
1.9 tedu 899: extern void line_directive_out PROTO ((FILE *, int));
1.1 deraadt 900:
901: /* Mark the current position in the action array as the end of the section 1
902: * user defs.
903: */
1.9 tedu 904: extern void mark_defs1 PROTO ((void));
1.1 deraadt 905:
906: /* Mark the current position in the action array as the end of the prolog. */
1.9 tedu 907: extern void mark_prolog PROTO ((void));
1.1 deraadt 908:
909: /* Generate a data statment for a two-dimensional array. */
1.9 tedu 910: extern void mk2data PROTO ((int));
1.1 deraadt 911:
1.9 tedu 912: extern void mkdata PROTO ((int)); /* generate a data statement */
1.1 deraadt 913:
914: /* Return the integer represented by a string of digits. */
1.9 tedu 915: extern int myctoi PROTO ((const char *));
1.1 deraadt 916:
917: /* Return character corresponding to escape sequence. */
1.13 ! mmcc 918: extern u_char myesc PROTO ((u_char[]));
1.1 deraadt 919:
920: /* Convert an octal digit string to an integer value. */
1.13 ! mmcc 921: extern int otoi PROTO ((u_char[]));
1.1 deraadt 922:
923: /* Output a (possibly-formatted) string to the generated scanner. */
1.9 tedu 924: extern void out PROTO ((const char *));
925: extern void out_dec PROTO ((const char *, int));
926: extern void out_dec2 PROTO ((const char *, int, int));
927: extern void out_hex PROTO ((const char *, unsigned int));
928: extern void out_str PROTO ((const char *, const char *));
1.1 deraadt 929: extern void out_str3
1.9 tedu 930: PROTO ((const char *, const char *, const char *, const char *));
931: extern void out_str_dec PROTO ((const char *, const char *, int));
932: extern void outc PROTO ((int));
933: extern void outn PROTO ((const char *));
934: extern void out_m4_define (const char* def, const char* val);
1.1 deraadt 935:
936: /* Return a printable version of the given character, which might be
937: * 8-bit.
938: */
1.9 tedu 939: extern char *readable_form PROTO ((int));
1.1 deraadt 940:
941: /* Write out one section of the skeleton file. */
1.9 tedu 942: extern void skelout PROTO ((void));
1.1 deraadt 943:
944: /* Output a yy_trans_info structure. */
1.9 tedu 945: extern void transition_struct_out PROTO ((int, int));
1.1 deraadt 946:
947: /* Only needed when using certain broken versions of bison to build parse.c. */
1.9 tedu 948: extern void *yy_flex_xmalloc PROTO ((int));
1.1 deraadt 949:
950: /* from file nfa.c */
951:
952: /* Add an accepting state to a machine. */
1.9 tedu 953: extern void add_accept PROTO ((int, int));
1.1 deraadt 954:
955: /* Make a given number of copies of a singleton machine. */
1.9 tedu 956: extern int copysingl PROTO ((int, int));
1.1 deraadt 957:
958: /* Debugging routine to write out an nfa. */
1.9 tedu 959: extern void dumpnfa PROTO ((int));
1.1 deraadt 960:
961: /* Finish up the processing for a rule. */
1.9 tedu 962: extern void finish_rule PROTO ((int, int, int, int, int));
1.1 deraadt 963:
964: /* Connect two machines together. */
1.9 tedu 965: extern int link_machines PROTO ((int, int));
1.1 deraadt 966:
967: /* Mark each "beginning" state in a machine as being a "normal" (i.e.,
968: * not trailing context associated) state.
969: */
1.9 tedu 970: extern void mark_beginning_as_normal PROTO ((int));
1.1 deraadt 971:
972: /* Make a machine that branches to two machines. */
1.9 tedu 973: extern int mkbranch PROTO ((int, int));
1.1 deraadt 974:
1.9 tedu 975: extern int mkclos PROTO ((int)); /* convert a machine into a closure */
976: extern int mkopt PROTO ((int)); /* make a machine optional */
1.1 deraadt 977:
978: /* Make a machine that matches either one of two machines. */
1.9 tedu 979: extern int mkor PROTO ((int, int));
1.1 deraadt 980:
981: /* Convert a machine into a positive closure. */
1.9 tedu 982: extern int mkposcl PROTO ((int));
1.1 deraadt 983:
1.9 tedu 984: extern int mkrep PROTO ((int, int, int)); /* make a replicated machine */
1.1 deraadt 985:
986: /* Create a state with a transition on a given symbol. */
1.9 tedu 987: extern int mkstate PROTO ((int));
1.1 deraadt 988:
1.9 tedu 989: extern void new_rule PROTO ((void)); /* initialize for a new rule */
1.1 deraadt 990:
991:
992: /* from file parse.y */
993:
994: /* Build the "<<EOF>>" action for the active start conditions. */
1.9 tedu 995: extern void build_eof_action PROTO ((void));
1.1 deraadt 996:
997: /* Write out a message formatted with one string, pinpointing its location. */
1.9 tedu 998: extern void format_pinpoint_message PROTO ((const char *, const char *));
1.1 deraadt 999:
1000: /* Write out a message, pinpointing its location. */
1.9 tedu 1001: extern void pinpoint_message PROTO ((const char *));
1.1 deraadt 1002:
1003: /* Write out a warning, pinpointing it at the given line. */
1.9 tedu 1004: extern void line_warning PROTO ((const char *, int));
1.1 deraadt 1005:
1006: /* Write out a message, pinpointing it at the given line. */
1.9 tedu 1007: extern void line_pinpoint PROTO ((const char *, int));
1.1 deraadt 1008:
1009: /* Report a formatted syntax error. */
1.9 tedu 1010: extern void format_synerr PROTO ((const char *, const char *));
1011: extern void synerr PROTO ((const char *)); /* report a syntax error */
1012: extern void format_warn PROTO ((const char *, const char *));
1013: extern void warn PROTO ((const char *)); /* report a warning */
1014: extern void yyerror PROTO ((const char *)); /* report a parse error */
1015: extern int yyparse PROTO ((void)); /* the YACC parser */
1.1 deraadt 1016:
1017:
1018: /* from file scan.l */
1019:
1020: /* The Flex-generated scanner for flex. */
1.9 tedu 1021: extern int flexscan PROTO ((void));
1.1 deraadt 1022:
1023: /* Open the given file (if NULL, stdin) for scanning. */
1.9 tedu 1024: extern void set_input_file PROTO ((char *));
1.1 deraadt 1025:
1026: /* Wrapup a file in the lexical analyzer. */
1.9 tedu 1027: extern int yywrap PROTO ((void));
1.1 deraadt 1028:
1029:
1030: /* from file sym.c */
1031:
1032: /* Save the text of a character class. */
1.13 ! mmcc 1033: extern void cclinstal PROTO ((u_char[], int));
1.1 deraadt 1034:
1035: /* Lookup the number associated with character class. */
1.13 ! mmcc 1036: extern int ccllookup PROTO ((u_char[]));
1.1 deraadt 1037:
1.13 ! mmcc 1038: extern void ndinstal PROTO ((const char *, u_char[])); /* install a name definition */
! 1039: extern u_char *ndlookup PROTO ((const char *)); /* lookup a name definition */
1.1 deraadt 1040:
1041: /* Increase maximum number of SC's. */
1.9 tedu 1042: extern void scextend PROTO ((void));
1043: extern void scinstal PROTO ((const char *, int)); /* make a start condition */
1.1 deraadt 1044:
1045: /* Lookup the number associated with a start condition. */
1.9 tedu 1046: extern int sclookup PROTO ((const char *));
1.1 deraadt 1047:
1048:
1049: /* from file tblcmp.c */
1050:
1051: /* Build table entries for dfa state. */
1.9 tedu 1052: extern void bldtbl PROTO ((int[], int, int, int, int));
1053:
1054: extern void cmptmps PROTO ((void)); /* compress template table entries */
1055: extern void expand_nxt_chk PROTO ((void)); /* increase nxt/chk arrays */
1.1 deraadt 1056:
1057: /* Finds a space in the table for a state to be placed. */
1.9 tedu 1058: extern int find_table_space PROTO ((int *, int));
1059: extern void inittbl PROTO ((void)); /* initialize transition tables */
1060:
1.1 deraadt 1061: /* Make the default, "jam" table entries. */
1.9 tedu 1062: extern void mkdeftbl PROTO ((void));
1.1 deraadt 1063:
1064: /* Create table entries for a state (or state fragment) which has
1065: * only one out-transition.
1066: */
1.9 tedu 1067: extern void mk1tbl PROTO ((int, int, int, int));
1.1 deraadt 1068:
1069: /* Place a state into full speed transition table. */
1.9 tedu 1070: extern void place_state PROTO ((int *, int, int));
1.1 deraadt 1071:
1072: /* Save states with only one out-transition to be processed later. */
1.9 tedu 1073: extern void stack1 PROTO ((int, int, int, int));
1.1 deraadt 1074:
1075:
1076: /* from file yylex.c */
1077:
1.9 tedu 1078: extern int yylex PROTO ((void));
1079:
1080: /* A growable array. See buf.c. */
1081: struct Buf {
1082: void *elts; /* elements. */
1083: int nelts; /* number of elements. */
1084: size_t elt_size; /* in bytes. */
1085: int nmax; /* max capacity of elements. */
1086: };
1087:
1088: extern void buf_init PROTO ((struct Buf * buf, size_t elem_size));
1089: extern void buf_destroy PROTO ((struct Buf * buf));
1090: extern struct Buf *buf_append
1091: PROTO ((struct Buf * buf, const void *ptr, int n_elem));
1092: extern struct Buf *buf_concat PROTO((struct Buf* dest, const struct Buf* src));
1093: extern struct Buf *buf_strappend PROTO ((struct Buf *, const char *str));
1094: extern struct Buf *buf_strnappend
1095: PROTO ((struct Buf *, const char *str, int nchars));
1096: extern struct Buf *buf_strdefine
1097: PROTO ((struct Buf * buf, const char *str, const char *def));
1098: extern struct Buf *buf_prints PROTO((struct Buf *buf, const char *fmt, const char* s));
1099: extern struct Buf *buf_m4_define PROTO((struct Buf *buf, const char* def, const char* val));
1100: extern struct Buf *buf_m4_undefine PROTO((struct Buf *buf, const char* def));
1101: extern struct Buf *buf_print_strings PROTO((struct Buf * buf, FILE* out));
1102: extern struct Buf *buf_linedir PROTO((struct Buf *buf, const char* filename, int lineno));
1103:
1104: extern struct Buf userdef_buf; /* a string buffer for #define's generated by user-options on cmd line. */
1105: extern struct Buf defs_buf; /* a char* buffer to save #define'd some symbols generated by flex. */
1106: extern struct Buf yydmap_buf; /* a string buffer to hold yydmap elements */
1107: extern struct Buf m4defs_buf; /* Holds m4 definitions. */
1108: extern struct Buf top_buf; /* contains %top code. String buffer. */
1109:
1110: /* For blocking out code from the header file. */
1111: #define OUT_BEGIN_CODE() outn("m4_ifdef( [[M4_YY_IN_HEADER]],,[[")
1112: #define OUT_END_CODE() outn("]])")
1113:
1114: /* For setjmp/longjmp (instead of calling exit(2)). Linkage in main.c */
1115: extern jmp_buf flex_main_jmp_buf;
1116:
1117: #define FLEX_EXIT(status) longjmp(flex_main_jmp_buf,(status)+1)
1118:
1119: /* Removes all \n and \r chars from tail of str. returns str. */
1120: extern char *chomp (char *str);
1121:
1122: /* ctype functions forced to return boolean */
1123: #define b_isalnum(c) (isalnum(c)?true:false)
1124: #define b_isalpha(c) (isalpha(c)?true:false)
1125: #define b_isascii(c) (isascii(c)?true:false)
1126: #define b_isblank(c) (isblank(c)?true:false)
1127: #define b_iscntrl(c) (iscntrl(c)?true:false)
1128: #define b_isdigit(c) (isdigit(c)?true:false)
1129: #define b_isgraph(c) (isgraph(c)?true:false)
1130: #define b_islower(c) (islower(c)?true:false)
1131: #define b_isprint(c) (isprint(c)?true:false)
1132: #define b_ispunct(c) (ispunct(c)?true:false)
1133: #define b_isspace(c) (isspace(c)?true:false)
1134: #define b_isupper(c) (isupper(c)?true:false)
1135: #define b_isxdigit(c) (isxdigit(c)?true:false)
1136:
1137: /* return true if char is uppercase or lowercase. */
1138: bool has_case(int c);
1139:
1140: /* Change case of character if possible. */
1141: int reverse_case(int c);
1142:
1143: /* return false if [c1-c2] is ambiguous for a caseless scanner. */
1144: bool range_covers_case (int c1, int c2);
1145:
1146: /*
1147: * From "filter.c"
1148: */
1149:
1150: /** A single stdio filter to execute.
1151: * The filter may be external, such as "sed", or it
1152: * may be internal, as a function call.
1153: */
1154: struct filter {
1155: int (*filter_func)(struct filter*); /**< internal filter function */
1156: void * extra; /**< extra data passed to filter_func */
1157: int argc; /**< arg count */
1158: const char ** argv; /**< arg vector, \0-terminated */
1159: struct filter * next; /**< next filter or NULL */
1160: };
1161:
1162: /* output filter chain */
1163: extern struct filter * output_chain;
1164: extern struct filter *filter_create_ext PROTO((struct filter * chain, const char *cmd, ...));
1165: struct filter *filter_create_int PROTO((struct filter *chain,
1166: int (*filter_func) (struct filter *),
1167: void *extra));
1168: extern bool filter_apply_chain PROTO((struct filter * chain));
1169: extern int filter_truncate (struct filter * chain, int max_len);
1170: extern int filter_tee_header PROTO((struct filter *chain));
1171: extern int filter_fix_linedirs PROTO((struct filter *chain));
1172:
1173:
1174: /*
1175: * From "regex.c"
1176: */
1177:
1178: extern regex_t regex_linedir, regex_blank_line;
1179: bool flex_init_regex(void);
1180: void flex_regcomp(regex_t *preg, const char *regex, int cflags);
1181: char *regmatch_dup (regmatch_t * m, const char *src);
1182: char *regmatch_cpy (regmatch_t * m, char *dest, const char *src);
1183: int regmatch_len (regmatch_t * m);
1184: int regmatch_strtol (regmatch_t * m, const char *src, char **endptr, int base);
1185: bool regmatch_empty (regmatch_t * m);
1186:
1187: /* From "scanflags.h" */
1188: typedef unsigned int scanflags_t;
1189: extern scanflags_t* _sf_stk;
1190: extern size_t _sf_top_ix, _sf_max; /**< stack of scanner flags. */
1191: #define _SF_CASE_INS 0x0001
1192: #define _SF_DOT_ALL 0x0002
1193: #define _SF_SKIP_WS 0x0004
1194: #define sf_top() (_sf_stk[_sf_top_ix])
1195: #define sf_case_ins() (sf_top() & _SF_CASE_INS)
1196: #define sf_dot_all() (sf_top() & _SF_DOT_ALL)
1197: #define sf_skip_ws() (sf_top() & _SF_SKIP_WS)
1198: #define sf_set_case_ins(X) ((X) ? (sf_top() |= _SF_CASE_INS) : (sf_top() &= ~_SF_CASE_INS))
1199: #define sf_set_dot_all(X) ((X) ? (sf_top() |= _SF_DOT_ALL) : (sf_top() &= ~_SF_DOT_ALL))
1200: #define sf_set_skip_ws(X) ((X) ? (sf_top() |= _SF_SKIP_WS) : (sf_top() &= ~_SF_SKIP_WS))
1201: extern void sf_init(void);
1202: extern void sf_push(void);
1203: extern void sf_pop(void);
1204:
1205:
1206: #endif /* not defined FLEXDEF_H */