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