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