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