xref: /dragonfly/contrib/flex/src/flexdef.h (revision e6d22e9b)
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 #include <math.h>
50 
51 #ifdef HAVE_ASSERT_H
52 #include <assert.h>
53 #else
54 #define assert(Pred)
55 #endif
56 
57 #ifdef HAVE_LIMITS_H
58 #include <limits.h>
59 #endif
60 /* Required: dup() and dup2() in <unistd.h> */
61 #include <unistd.h>
62 #ifdef HAVE_NETINET_IN_H
63 #include <netinet/in.h>
64 #endif
65 #ifdef HAVE_SYS_PARAMS_H
66 #include <sys/params.h>
67 #endif
68 /* Required: stat() in <sys/stat.h> */
69 #include <sys/stat.h>
70 /* Required: wait() in <sys/wait.h> */
71 #include <sys/wait.h>
72 #include <stdbool.h>
73 #include <stdarg.h>
74 /* Required: regcomp(), regexec() and regerror() in <regex.h> */
75 #include <regex.h>
76 /* Required: strcasecmp() in <strings.h> */
77 #include <strings.h>
78 #include "flexint.h"
79 
80 /* We use gettext. So, when we write strings which should be translated, we mark them with _() */
81 #ifdef ENABLE_NLS
82 #ifdef HAVE_LOCALE_H
83 #include <locale.h>
84 #endif /* HAVE_LOCALE_H */
85 #include "gettext.h"
86 #define _(String) gettext (String)
87 #else
88 #define _(STRING) STRING
89 #endif /* ENABLE_NLS */
90 
91 /* Always be prepared to generate an 8-bit scanner. */
92 #define CSIZE 256
93 
94 /* Size of input alphabet - should be size of ASCII set. */
95 #ifndef DEFAULT_CSIZE
96 #define DEFAULT_CSIZE 128
97 #endif
98 
99 /* Maximum line length we'll have to deal with. */
100 #define MAXLINE 2048
101 
102 #ifndef MIN
103 #define MIN(x,y) ((x) < (y) ? (x) : (y))
104 #endif
105 #ifndef MAX
106 #define MAX(x,y) ((x) > (y) ? (x) : (y))
107 #endif
108 #ifndef ABS
109 #define ABS(x) ((x) < 0 ? -(x) : (x))
110 #endif
111 
112 /* Whether an integer is a power of two */
113 #define is_power_of_2(n) ((n) > 0 && ((n) & ((n) - 1)) == 0)
114 
115 #define unspecified -1
116 
117 /* Special chk[] values marking the slots taking by end-of-buffer and action
118  * numbers.
119  */
120 #define EOB_POSITION -1
121 #define ACTION_POSITION -2
122 
123 /* Number of data items per line for -f output. */
124 #define NUMDATAITEMS 10
125 
126 /* Number of lines of data in -f output before inserting a blank line for
127  * readability.
128  */
129 #define NUMDATALINES 10
130 
131 /* transition_struct_out() definitions. */
132 #define TRANS_STRUCT_PRINT_LENGTH 14
133 
134 /* Returns true if an nfa state has an epsilon out-transition slot
135  * that can be used.  This definition is currently not used.
136  */
137 #define FREE_EPSILON(state) \
138 	(transchar[state] == SYM_EPSILON && \
139 	 trans2[state] == NO_TRANSITION && \
140 	 finalst[state] != state)
141 
142 /* Returns true if an nfa state has an epsilon out-transition character
143  * and both slots are free
144  */
145 #define SUPER_FREE_EPSILON(state) \
146 	(transchar[state] == SYM_EPSILON && \
147 	 trans1[state] == NO_TRANSITION) \
148 
149 /* Maximum number of NFA states that can comprise a DFA state.  It's real
150  * big because if there's a lot of rules, the initial state will have a
151  * huge epsilon closure.
152  */
153 #define INITIAL_MAX_DFA_SIZE 750
154 #define MAX_DFA_SIZE_INCREMENT 750
155 
156 
157 /* A note on the following masks.  They are used to mark accepting numbers
158  * as being special.  As such, they implicitly limit the number of accepting
159  * numbers (i.e., rules) because if there are too many rules the rule numbers
160  * will overload the mask bits.  Fortunately, this limit is \large/ (0x2000 ==
161  * 8192) so unlikely to actually cause any problems.  A check is made in
162  * new_rule() to ensure that this limit is not reached.
163  */
164 
165 /* Mask to mark a trailing context accepting number. */
166 #define YY_TRAILING_MASK 0x2000
167 
168 /* Mask to mark the accepting number of the "head" of a trailing context
169  * rule.
170  */
171 #define YY_TRAILING_HEAD_MASK 0x4000
172 
173 /* Maximum number of rules, as outlined in the above note. */
174 #define MAX_RULE (YY_TRAILING_MASK - 1)
175 
176 
177 /* NIL must be 0.  If not, its special meaning when making equivalence classes
178  * (it marks the representative of a given e.c.) will be unidentifiable.
179  */
180 #define NIL 0
181 
182 #define JAM -1			/* to mark a missing DFA transition */
183 #define NO_TRANSITION NIL
184 #define UNIQUE -1		/* marks a symbol as an e.c. representative */
185 #define INFINITE_REPEAT -1		/* for x{5,} constructions */
186 
187 #define INITIAL_MAX_CCLS 100	/* max number of unique character classes */
188 #define MAX_CCLS_INCREMENT 100
189 
190 /* Size of table holding members of character classes. */
191 #define INITIAL_MAX_CCL_TBL_SIZE 500
192 #define MAX_CCL_TBL_SIZE_INCREMENT 250
193 
194 #define INITIAL_MAX_RULES 100	/* default maximum number of rules */
195 #define MAX_RULES_INCREMENT 100
196 
197 #define INITIAL_MNS 2000	/* default maximum number of nfa states */
198 #define MNS_INCREMENT 1000	/* amount to bump above by if it's not enough */
199 
200 #define INITIAL_MAX_DFAS 1000	/* default maximum number of dfa states */
201 #define MAX_DFAS_INCREMENT 1000
202 
203 #define JAMSTATE -32766		/* marks a reference to the state that always jams */
204 
205 /* Maximum number of NFA states. */
206 #define MAXIMUM_MNS 31999
207 #define MAXIMUM_MNS_LONG 1999999999
208 
209 /* Enough so that if it's subtracted from an NFA state number, the result
210  * is guaranteed to be negative.
211  */
212 #define MARKER_DIFFERENCE (maximum_mns+2)
213 
214 /* Maximum number of nxt/chk pairs for non-templates. */
215 #define INITIAL_MAX_XPAIRS 2000
216 #define MAX_XPAIRS_INCREMENT 2000
217 
218 /* Maximum number of nxt/chk pairs needed for templates. */
219 #define INITIAL_MAX_TEMPLATE_XPAIRS 2500
220 #define MAX_TEMPLATE_XPAIRS_INCREMENT 2500
221 
222 #define SYM_EPSILON (CSIZE + 1)	/* to mark transitions on the symbol epsilon */
223 
224 #define INITIAL_MAX_SCS 40	/* maximum number of start conditions */
225 #define MAX_SCS_INCREMENT 40	/* amount to bump by if it's not enough */
226 
227 #define ONE_STACK_SIZE 500	/* stack of states with only one out-transition */
228 #define SAME_TRANS -1		/* transition is the same as "default" entry for state */
229 
230 /* The following percentages are used to tune table compression:
231 
232  * The percentage the number of out-transitions a state must be of the
233  * number of equivalence classes in order to be considered for table
234  * compaction by using protos.
235  */
236 #define PROTO_SIZE_PERCENTAGE 15
237 
238 /* The percentage the number of homogeneous out-transitions of a state
239  * must be of the number of total out-transitions of the state in order
240  * that the state's transition table is first compared with a potential
241  * template of the most common out-transition instead of with the first
242  * proto in the proto queue.
243  */
244 #define CHECK_COM_PERCENTAGE 50
245 
246 /* The percentage the number of differences between a state's transition
247  * table and the proto it was first compared with must be of the total
248  * number of out-transitions of the state in order to keep the first
249  * proto as a good match and not search any further.
250  */
251 #define FIRST_MATCH_DIFF_PERCENTAGE 10
252 
253 /* The percentage the number of differences between a state's transition
254  * table and the most similar proto must be of the state's total number
255  * of out-transitions to use the proto as an acceptable close match.
256  */
257 #define ACCEPTABLE_DIFF_PERCENTAGE 50
258 
259 /* The percentage the number of homogeneous out-transitions of a state
260  * must be of the number of total out-transitions of the state in order
261  * to consider making a template from the state.
262  */
263 #define TEMPLATE_SAME_PERCENTAGE 60
264 
265 /* The percentage the number of differences between a state's transition
266  * table and the most similar proto must be of the state's total number
267  * of out-transitions to create a new proto from the state.
268  */
269 #define NEW_PROTO_DIFF_PERCENTAGE 20
270 
271 /* The percentage the total number of out-transitions of a state must be
272  * of the number of equivalence classes in order to consider trying to
273  * fit the transition table into "holes" inside the nxt/chk table.
274  */
275 #define INTERIOR_FIT_PERCENTAGE 15
276 
277 /* Size of region set aside to cache the complete transition table of
278  * protos on the proto queue to enable quick comparisons.
279  */
280 #define PROT_SAVE_SIZE 2000
281 
282 #define MSP 50			/* maximum number of saved protos (protos on the proto queue) */
283 
284 /* Maximum number of out-transitions a state can have that we'll rummage
285  * around through the interior of the internal fast table looking for a
286  * spot for it.
287  */
288 #define MAX_XTIONS_FULL_INTERIOR_FIT 4
289 
290 /* Maximum number of rules which will be reported as being associated
291  * with a DFA state.
292  */
293 #define MAX_ASSOC_RULES 100
294 
295 /* Number that, if used to subscript an array, has a good chance of producing
296  * an error; should be small enough to fit into a short.
297  */
298 #define BAD_SUBSCRIPT -32767
299 
300 /* Absolute value of largest number that can be stored in a short, with a
301  * bit of slop thrown in for general paranoia.
302  */
303 #define MAX_SHORT 32700
304 
305 
306 /* Declarations for global variables. */
307 
308 
309 /* Variables for flags:
310  * printstats - if true (-v), dump statistics
311  * syntaxerror - true if a syntax error has been found
312  * eofseen - true if we've seen an eof in the input file
313  * ddebug - if true (-d), make a "debug" scanner
314  * trace - if true (-T), trace processing
315  * nowarn - if true (-w), do not generate warnings
316  * spprdflt - if true (-s), suppress the default rule
317  * interactive - if true (-I), generate an interactive scanner
318  * lex_compat - if true (-l), maximize compatibility with AT&T lex
319  * posix_compat - if true (-X), maximize compatibility with POSIX lex
320  * do_yylineno - if true, generate code to maintain yylineno
321  * useecs - if true (-Ce flag), use equivalence classes
322  * fulltbl - if true (-Cf flag), don't compress the DFA state table
323  * usemecs - if true (-Cm flag), use meta-equivalence classes
324  * fullspd - if true (-F flag), use Jacobson method of table representation
325  * gen_line_dirs - if true (i.e., no -L flag), generate #line directives
326  * performance_report - if > 0 (i.e., -p flag), generate a report relating
327  *   to scanner performance; if > 1 (-p -p), report on minor performance
328  *   problems, too
329  * backing_up_report - if true (i.e., -b flag), generate "lex.backup" file
330  *   listing backing-up states
331  * C_plus_plus - if true (i.e., -+ flag), generate a C++ scanner class;
332  *   otherwise, a standard C scanner
333  * reentrant - if true (-R), generate a reentrant C scanner.
334  * bison_bridge_lval - if true (--bison-bridge), bison pure calling convention.
335  * bison_bridge_lloc - if true (--bison-locations), bison yylloc.
336  * long_align - if true (-Ca flag), favor long-word alignment.
337  * use_read - if true (-f, -F, or -Cr) then use read() for scanner input;
338  *   otherwise, use fread().
339  * yytext_is_array - if true (i.e., %array directive), then declare
340  *   yytext as a array instead of a character pointer.  Nice and inefficient.
341  * do_yywrap - do yywrap() processing on EOF.  If false, EOF treated as
342  *   "no more files".
343  * csize - size of character set for the scanner we're generating;
344  *   128 for 7-bit chars and 256 for 8-bit
345  * yymore_used - if true, yymore() is used in input rules
346  * reject - if true, generate back-up tables for REJECT macro
347  * real_reject - if true, scanner really uses REJECT (as opposed to just
348  *   having "reject" set for variable trailing context)
349  * continued_action - true if this rule's action is to "fall through" to
350  *   the next rule's action (i.e., the '|' action)
351  * in_rule - true if we're inside an individual rule, false if not.
352  * yymore_really_used - whether to treat yymore() as really used, regardless
353  *   of what we think based on references to it in the user's actions.
354  * reject_really_used - same for REJECT
355  * trace_hex - use hexadecimal numbers in trace/debug outputs instead of octals
356  */
357 
358 extern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn,
359 	spprdflt;
360 extern int interactive, lex_compat, posix_compat, do_yylineno;
361 extern int useecs, fulltbl, usemecs, fullspd;
362 extern int gen_line_dirs, performance_report, backing_up_report;
363 extern int reentrant, bison_bridge_lval, bison_bridge_lloc;
364 extern int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap;
365 extern int csize;
366 extern int yymore_used, reject, real_reject, continued_action, in_rule;
367 
368 extern int yymore_really_used, reject_really_used;
369 extern int trace_hex;
370 
371 /* Variables used in the flex input routines:
372  * datapos - characters on current output line
373  * dataline - number of contiguous lines of data in current data
374  * 	statement.  Used to generate readable -f output
375  * linenum - current input line number
376  * skelfile - the skeleton file
377  * skel - compiled-in skeleton array
378  * skel_ind - index into "skel" array, if skelfile is nil
379  * yyin - input file
380  * backing_up_file - file to summarize backing-up states to
381  * infilename - name of input file
382  * outfilename - name of output file
383  * headerfilename - name of the .h file to generate
384  * did_outfilename - whether outfilename was explicitly set
385  * prefix - the prefix used for externally visible names ("yy" by default)
386  * yyclass - yyFlexLexer subclass to use for YY_DECL
387  * do_stdinit - whether to initialize yyin/yyout to stdin/stdout
388  * use_stdout - the -t flag
389  * input_files - array holding names of input files
390  * num_input_files - size of input_files array
391  * program_name - name with which program was invoked
392  *
393  * action_array - array to hold the rule actions
394  * action_size - size of action_array
395  * defs1_offset - index where the user's section 1 definitions start
396  *	in action_array
397  * prolog_offset - index where the prolog starts in action_array
398  * action_offset - index where the non-prolog starts in action_array
399  * action_index - index where the next action should go, with respect
400  * 	to "action_array"
401  */
402 
403 extern int datapos, dataline, linenum;
404 extern FILE *skelfile, *backing_up_file;
405 extern const char *skel[];
406 extern int skel_ind;
407 extern char *infilename, *outfilename, *headerfilename;
408 extern int did_outfilename;
409 extern char *prefix, *yyclass, *extra_type;
410 extern int do_stdinit, use_stdout;
411 extern char **input_files;
412 extern int num_input_files;
413 extern char *program_name;
414 
415 extern char *action_array;
416 extern int action_size;
417 extern int defs1_offset, prolog_offset, action_offset, action_index;
418 
419 
420 /* Variables for stack of states having only one out-transition:
421  * onestate - state number
422  * onesym - transition symbol
423  * onenext - target state
424  * onedef - default base entry
425  * onesp - stack pointer
426  */
427 
428 extern int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
429 extern int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
430 
431 
432 /* Variables for nfa machine data:
433  * maximum_mns - maximal number of NFA states supported by tables
434  * current_mns - current maximum on number of NFA states
435  * num_rules - number of the last accepting state; also is number of
436  * 	rules created so far
437  * num_eof_rules - number of <<EOF>> rules
438  * default_rule - number of the default rule
439  * current_max_rules - current maximum number of rules
440  * lastnfa - last nfa state number created
441  * firstst - physically the first state of a fragment
442  * lastst - last physical state of fragment
443  * finalst - last logical state of fragment
444  * transchar - transition character
445  * trans1 - transition state
446  * trans2 - 2nd transition state for epsilons
447  * accptnum - accepting number
448  * assoc_rule - rule associated with this NFA state (or 0 if none)
449  * state_type - a STATE_xxx type identifying whether the state is part
450  * 	of a normal rule, the leading state in a trailing context
451  * 	rule (i.e., the state which marks the transition from
452  * 	recognizing the text-to-be-matched to the beginning of
453  * 	the trailing context), or a subsequent state in a trailing
454  * 	context rule
455  * rule_type - a RULE_xxx type identifying whether this a ho-hum
456  * 	normal rule or one which has variable head & trailing
457  * 	context
458  * rule_linenum - line number associated with rule
459  * rule_useful - true if we've determined that the rule can be matched
460  * rule_has_nl - true if rule could possibly match a newline
461  * ccl_has_nl - true if current ccl could match a newline
462  * nlch - default eol char
463  */
464 
465 extern int maximum_mns, current_mns, current_max_rules;
466 extern int num_rules, num_eof_rules, default_rule, lastnfa;
467 extern int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
468 extern int *accptnum, *assoc_rule, *state_type;
469 extern int *rule_type, *rule_linenum, *rule_useful;
470 extern bool *rule_has_nl, *ccl_has_nl;
471 extern int nlch;
472 
473 /* Different types of states; values are useful as masks, as well, for
474  * routines like check_trailing_context().
475  */
476 #define STATE_NORMAL 0x1
477 #define STATE_TRAILING_CONTEXT 0x2
478 
479 /* Global holding current type of state we're making. */
480 
481 extern int current_state_type;
482 
483 /* Different types of rules. */
484 #define RULE_NORMAL 0
485 #define RULE_VARIABLE 1
486 
487 /* True if the input rules include a rule with both variable-length head
488  * and trailing context, false otherwise.
489  */
490 extern int variable_trailing_context_rules;
491 
492 
493 /* Variables for protos:
494  * numtemps - number of templates created
495  * numprots - number of protos created
496  * protprev - backlink to a more-recently used proto
497  * protnext - forward link to a less-recently used proto
498  * prottbl - base/def table entry for proto
499  * protcomst - common state of proto
500  * firstprot - number of the most recently used proto
501  * lastprot - number of the least recently used proto
502  * protsave contains the entire state array for protos
503  */
504 
505 extern int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
506 extern int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
507 
508 
509 /* Variables for managing equivalence classes:
510  * numecs - number of equivalence classes
511  * nextecm - forward link of Equivalence Class members
512  * ecgroup - class number or backward link of EC members
513  * nummecs - number of meta-equivalence classes (used to compress
514  *   templates)
515  * tecfwd - forward link of meta-equivalence classes members
516  * tecbck - backward link of MEC's
517  */
518 
519 /* Reserve enough room in the equivalence class arrays so that we
520  * can use the CSIZE'th element to hold equivalence class information
521  * for the NUL character.  Later we'll move this information into
522  * the 0th element.
523  */
524 extern int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs;
525 
526 /* Meta-equivalence classes are indexed starting at 1, so it's possible
527  * that they will require positions from 1 .. CSIZE, i.e., CSIZE + 1
528  * slots total (since the arrays are 0-based).  nextecm[] and ecgroup[]
529  * don't require the extra position since they're indexed from 1 .. CSIZE - 1.
530  */
531 extern int tecfwd[CSIZE + 1], tecbck[CSIZE + 1];
532 
533 
534 /* Variables for start conditions:
535  * lastsc - last start condition created
536  * current_max_scs - current limit on number of start conditions
537  * scset - set of rules active in start condition
538  * scbol - set of rules active only at the beginning of line in a s.c.
539  * scxclu - true if start condition is exclusive
540  * sceof - true if start condition has EOF rule
541  * scname - start condition name
542  */
543 
544 extern int lastsc, *scset, *scbol, *scxclu, *sceof;
545 extern int current_max_scs;
546 extern char **scname;
547 
548 
549 /* Variables for dfa machine data:
550  * current_max_dfa_size - current maximum number of NFA states in DFA
551  * current_max_xpairs - current maximum number of non-template xtion pairs
552  * current_max_template_xpairs - current maximum number of template pairs
553  * current_max_dfas - current maximum number DFA states
554  * lastdfa - last dfa state number created
555  * nxt - state to enter upon reading character
556  * chk - check value to see if "nxt" applies
557  * tnxt - internal nxt table for templates
558  * base - offset into "nxt" for given state
559  * def - where to go if "chk" disallows "nxt" entry
560  * nultrans - NUL transition for each state
561  * NUL_ec - equivalence class of the NUL character
562  * tblend - last "nxt/chk" table entry being used
563  * firstfree - first empty entry in "nxt/chk" table
564  * dss - nfa state set for each dfa
565  * dfasiz - size of nfa state set for each dfa
566  * dfaacc - accepting set for each dfa state (if using REJECT), or accepting
567  *	number, if not
568  * accsiz - size of accepting set for each dfa state
569  * dhash - dfa state hash value
570  * numas - number of DFA accepting states created; note that this
571  *	is not necessarily the same value as num_rules, which is the analogous
572  *	value for the NFA
573  * numsnpairs - number of state/nextstate transition pairs
574  * jambase - position in base/def where the default jam table starts
575  * jamstate - state number corresponding to "jam" state
576  * end_of_buffer_state - end-of-buffer dfa state number
577  */
578 
579 extern int current_max_dfa_size, current_max_xpairs;
580 extern int current_max_template_xpairs, current_max_dfas;
581 extern int lastdfa, *nxt, *chk, *tnxt;
582 extern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss,
583 	*dfasiz;
584 extern union dfaacc_union {
585 	int    *dfaacc_set;
586 	int     dfaacc_state;
587 }      *dfaacc;
588 extern int *accsiz, *dhash, numas;
589 extern int numsnpairs, jambase, jamstate;
590 extern int end_of_buffer_state;
591 
592 /* Variables for ccl information:
593  * lastccl - ccl index of the last created ccl
594  * current_maxccls - current limit on the maximum number of unique ccl's
595  * cclmap - maps a ccl index to its set pointer
596  * ccllen - gives the length of a ccl
597  * cclng - true for a given ccl if the ccl is negated
598  * cclreuse - counts how many times a ccl is re-used
599  * current_max_ccl_tbl_size - current limit on number of characters needed
600  *	to represent the unique ccl's
601  * ccltbl - holds the characters in each ccl - indexed by cclmap
602  */
603 
604 extern int lastccl, *cclmap, *ccllen, *cclng, cclreuse;
605 extern int current_maxccls, current_max_ccl_tbl_size;
606 extern unsigned char *ccltbl;
607 
608 
609 /* Variables for miscellaneous information:
610  * nmstr - last NAME scanned by the scanner
611  * sectnum - section number currently being parsed
612  * nummt - number of empty nxt/chk table entries
613  * hshcol - number of hash collisions detected by snstods
614  * dfaeql - number of times a newly created dfa was equal to an old one
615  * numeps - number of epsilon NFA states created
616  * eps2 - number of epsilon states which have 2 out-transitions
617  * num_reallocs - number of times it was necessary to realloc() a group
618  *	  of arrays
619  * tmpuses - number of DFA states that chain to templates
620  * totnst - total number of NFA states used to make DFA states
621  * peakpairs - peak number of transition pairs we had to store internally
622  * numuniq - number of unique transitions
623  * numdup - number of duplicate transitions
624  * hshsave - number of hash collisions saved by checking number of states
625  * num_backing_up - number of DFA states requiring backing up
626  * bol_needed - whether scanner needs beginning-of-line recognition
627  */
628 
629 extern char nmstr[MAXLINE];
630 extern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
631 extern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
632 extern int num_backing_up, bol_needed;
633 
634 #ifndef HAVE_REALLOCARRAY
635 void *reallocarray(void *, size_t, size_t);
636 #endif
637 
638 void   *allocate_array(int, size_t);
639 void   *reallocate_array(void *, int, size_t);
640 
641 #define allocate_integer_array(size) \
642 	allocate_array(size, sizeof(int))
643 
644 #define reallocate_integer_array(array,size) \
645 	reallocate_array((void *) array, size, sizeof(int))
646 
647 #define allocate_bool_array(size) \
648 	allocate_array(size, sizeof(bool))
649 
650 #define reallocate_bool_array(array,size) \
651 	reallocate_array((void *) array, size, sizeof(bool))
652 
653 #define allocate_int_ptr_array(size) \
654 	allocate_array(size, sizeof(int *))
655 
656 #define allocate_char_ptr_array(size) \
657 	allocate_array(size, sizeof(char *))
658 
659 #define allocate_dfaacc_union(size) \
660 	allocate_array(size, sizeof(union dfaacc_union))
661 
662 #define reallocate_int_ptr_array(array,size) \
663 	reallocate_array((void *) array, size, sizeof(int *))
664 
665 #define reallocate_char_ptr_array(array,size) \
666 	reallocate_array((void *) array, size, sizeof(char *))
667 
668 #define reallocate_dfaacc_union(array, size) \
669 	reallocate_array((void *) array, size, sizeof(union dfaacc_union))
670 
671 #define allocate_character_array(size) \
672 	allocate_array( size, sizeof(char))
673 
674 #define reallocate_character_array(array,size) \
675 	reallocate_array((void *) array, size, sizeof(char))
676 
677 #define allocate_Character_array(size) \
678 	allocate_array(size, sizeof(unsigned char))
679 
680 #define reallocate_Character_array(array,size) \
681 	reallocate_array((void *) array, size, sizeof(unsigned char))
682 
683 
684 extern int yylval;
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