[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.14

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