[BACK]Return to flexdef.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / lex

Annotation of src/usr.bin/lex/flexdef.h, Revision 1.16

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