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