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