From: Will Estes Date: Tue, 27 Aug 2002 18:07:19 +0000 (+0000) Subject: ran the indent target; commit the results X-Git-Tag: flex-2-5-16~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e58ded5164af663649c86ab3f273310c2c57d37;p=flex ran the indent target; commit the results --- diff --git a/buf.c b/buf.c index 63e6a73..c792b75 100644 --- a/buf.c +++ b/buf.c @@ -34,67 +34,67 @@ #include "flexdef.h" /* global buffers. */ -struct Buf userdef_buf; /* for user #definitions triggered by cmd-line. */ -struct Buf defs_buf; /* for #define's autogenerated. */ +struct Buf userdef_buf; /* for user #definitions triggered by cmd-line. */ +struct Buf defs_buf; /* for #define's autogenerated. */ /* functions for growable buffer. */ /* Appends n characters in str to buf. */ -struct Buf* buf_strnappend (buf,str,n) - struct Buf* buf; - const char* str; - int n; +struct Buf *buf_strnappend (buf, str, n) + struct Buf *buf; + const char *str; + int n; { - buf_append(buf, str, n+1); + buf_append (buf, str, n + 1); - /* "undo" the '\0' character that buf_append() already copied. */ - buf->nelts--; + /* "undo" the '\0' character that buf_append() already copied. */ + buf->nelts--; - return buf; + return buf; } /* Appends characters in str to buf. */ -struct Buf* buf_strappend (buf,str) - struct Buf* buf; - const char* str; +struct Buf *buf_strappend (buf, str) + struct Buf *buf; + const char *str; { - return buf_strnappend(buf, str, strlen(str)); + return buf_strnappend (buf, str, strlen (str)); } /* appends "#define str def\n" */ -struct Buf* buf_strdefine (buf,str,def) - struct Buf* buf; - const char* str; - const char* def; +struct Buf *buf_strdefine (buf, str, def) + struct Buf *buf; + const char *str; + const char *def; { - buf_strappend(buf, "#define "); - buf_strappend(buf, " "); - buf_strappend(buf, str); - buf_strappend(buf, " "); - buf_strappend(buf, def); - buf_strappend(buf, "\n"); - return buf; + buf_strappend (buf, "#define "); + buf_strappend (buf, " "); + buf_strappend (buf, str); + buf_strappend (buf, " "); + buf_strappend (buf, def); + buf_strappend (buf, "\n"); + return buf; } /* create buf with 0 elements, each of size elem_size. */ -void buf_init(buf, elem_size) - struct Buf * buf; - size_t elem_size; +void buf_init (buf, elem_size) + struct Buf *buf; + size_t elem_size; { - buf->elts = (void*)0; - buf->nelts = 0; - buf->elt_size = elem_size; - buf->nmax = 0; + buf->elts = (void *) 0; + buf->nelts = 0; + buf->elt_size = elem_size; + buf->nmax = 0; } /* frees memory */ -void buf_destroy(buf) - struct Buf * buf; +void buf_destroy (buf) + struct Buf *buf; { - if(buf && buf->elts) - flex_free(buf->elts); - buf->elts = (void*)0; + if (buf && buf->elts) + flex_free (buf->elts); + buf->elts = (void *) 0; } @@ -104,38 +104,46 @@ void buf_destroy(buf) * We grow by mod(512) boundaries. */ -struct Buf* buf_append(buf,ptr,n_elem) - struct Buf * buf; - const void * ptr; - int n_elem; +struct Buf *buf_append (buf, ptr, n_elem) + struct Buf *buf; + const void *ptr; + int n_elem; { - int n_alloc=0; + int n_alloc = 0; - if (!ptr || n_elem==0) - return buf; + if (!ptr || n_elem == 0) + return buf; - /* May need to alloc more. */ - if (n_elem + buf->nelts > buf->nmax) { + /* May need to alloc more. */ + if (n_elem + buf->nelts > buf->nmax) { - /* exact amount needed... */ - n_alloc = (n_elem + buf->nelts) * buf->elt_size; + /* exact amount needed... */ + n_alloc = (n_elem + buf->nelts) * buf->elt_size; - /* ...plus some extra */ - if (((n_alloc*buf->elt_size)%512) != 0 && buf->elt_size < 512) - n_alloc += (512 - ((n_alloc*buf->elt_size)%512)) / buf->elt_size; + /* ...plus some extra */ + if (((n_alloc * buf->elt_size) % 512) != 0 + && buf->elt_size < 512) + n_alloc += + (512 - + ((n_alloc * buf->elt_size) % 512)) / + buf->elt_size; - if (!buf->elts) - buf->elts = allocate_array( n_alloc , buf->elt_size); - else - buf->elts = reallocate_array(buf->elts, n_alloc, buf->elt_size); + if (!buf->elts) + buf->elts = + allocate_array (n_alloc, buf->elt_size); + else + buf->elts = + reallocate_array (buf->elts, n_alloc, + buf->elt_size); - buf->nmax = n_alloc; - } + buf->nmax = n_alloc; + } - memcpy((char*)buf->elts + buf->nelts*buf->elt_size, ptr, n_elem*buf->elt_size); - buf->nelts += n_elem; + memcpy ((char *) buf->elts + buf->nelts * buf->elt_size, ptr, + n_elem * buf->elt_size); + buf->nelts += n_elem; - return buf; + return buf; } /* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */ diff --git a/ccl.c b/ccl.c index 3149f77..e53f7ba 100644 --- a/ccl.c +++ b/ccl.c @@ -35,61 +35,63 @@ /* ccladd - add a single character to a ccl */ -void ccladd( cclp, ch ) -int cclp; -int ch; - { - int ind, len, newpos, i; +void ccladd (cclp, ch) + int cclp; + int ch; +{ + int ind, len, newpos, i; - check_char( ch ); + check_char (ch); len = ccllen[cclp]; ind = cclmap[cclp]; /* check to see if the character is already in the ccl */ - for ( i = 0; i < len; ++i ) - if ( ccltbl[ind + i] == ch ) + for (i = 0; i < len; ++i) + if (ccltbl[ind + i] == ch) return; /* mark newlines */ if (ch == nlch) ccl_has_nl[cclp] = true; - + newpos = ind + len; - if ( newpos >= current_max_ccl_tbl_size ) - { + if (newpos >= current_max_ccl_tbl_size) { current_max_ccl_tbl_size += MAX_CCL_TBL_SIZE_INCREMENT; ++num_reallocs; - ccltbl = reallocate_Character_array( ccltbl, - current_max_ccl_tbl_size ); - } + ccltbl = reallocate_Character_array (ccltbl, + current_max_ccl_tbl_size); + } ccllen[cclp] = len + 1; ccltbl[newpos] = ch; - } +} /* cclinit - return an empty ccl */ -int cclinit() - { - if ( ++lastccl >= current_maxccls ) - { +int cclinit () +{ + if (++lastccl >= current_maxccls) { current_maxccls += MAX_CCLS_INCREMENT; ++num_reallocs; - cclmap = reallocate_integer_array( cclmap, current_maxccls ); - ccllen = reallocate_integer_array( ccllen, current_maxccls ); - cclng = reallocate_integer_array( cclng, current_maxccls ); - ccl_has_nl = reallocate_bool_array( ccl_has_nl, current_maxccls ); - } + cclmap = + reallocate_integer_array (cclmap, current_maxccls); + ccllen = + reallocate_integer_array (ccllen, current_maxccls); + cclng = reallocate_integer_array (cclng, current_maxccls); + ccl_has_nl = + reallocate_bool_array (ccl_has_nl, + current_maxccls); + } - if ( lastccl == 1 ) + if (lastccl == 1) /* we're making the first ccl */ cclmap[lastccl] = 0; @@ -99,24 +101,25 @@ int cclinit() * ccl, adding the length of the ccl to the cclmap pointer * will produce a cursor to the first free space. */ - cclmap[lastccl] = cclmap[lastccl - 1] + ccllen[lastccl - 1]; + cclmap[lastccl] = + cclmap[lastccl - 1] + ccllen[lastccl - 1]; ccllen[lastccl] = 0; cclng[lastccl] = 0; /* ccl's start out life un-negated */ ccl_has_nl[lastccl] = false; return lastccl; - } +} /* cclnegate - negate the given ccl */ -void cclnegate( cclp ) -int cclp; - { +void cclnegate (cclp) + int cclp; +{ cclng[cclp] = 1; ccl_has_nl[cclp] = !ccl_has_nl[cclp]; - } +} /* list_character_set - list the members of a set of characters in CCL form @@ -126,34 +129,32 @@ int cclp; * has a non-zero value in the cset array. */ -void list_character_set( file, cset ) -FILE *file; -int cset[]; - { +void list_character_set (file, cset) + FILE *file; + int cset[]; +{ register int i; - putc( '[', file ); + putc ('[', file); - for ( i = 0; i < csize; ++i ) - { - if ( cset[i] ) - { + for (i = 0; i < csize; ++i) { + if (cset[i]) { register int start_char = i; - putc( ' ', file ); + putc (' ', file); - fputs( readable_form( i ), file ); + fputs (readable_form (i), file); - while ( ++i < csize && cset[i] ) - ; + while (++i < csize && cset[i]) ; - if ( i - 1 > start_char ) + if (i - 1 > start_char) /* this was a run */ - fprintf( file, "-%s", readable_form( i - 1 ) ); + fprintf (file, "-%s", + readable_form (i - 1)); - putc( ' ', file ); - } + putc (' ', file); } - - putc( ']', file ); } + + putc (']', file); +} diff --git a/dfa.c b/dfa.c index fa1b1d1..b79b7e7 100644 --- a/dfa.c +++ b/dfa.c @@ -34,10 +34,10 @@ /* declare functions that have forward references */ -void dump_associated_rules PROTO((FILE*, int)); -void dump_transitions PROTO((FILE*, int[])); -void sympartition PROTO((int[], int, int[], int[])); -int symfollowset PROTO((int[], int, int, int[])); +void dump_associated_rules PROTO ((FILE *, int)); +void dump_transitions PROTO ((FILE *, int[])); +void sympartition PROTO ((int[], int, int[], int[])); +int symfollowset PROTO ((int[], int, int, int[])); /* check_for_backing_up - check a DFA state for backing up @@ -49,32 +49,29 @@ int symfollowset PROTO((int[], int, int, int[])); * indexed by equivalence class. */ -void check_for_backing_up( ds, state ) -int ds; -int state[]; - { - if ( (reject && ! dfaacc[ds].dfaacc_set) || - (! reject && ! dfaacc[ds].dfaacc_state) ) - { /* state is non-accepting */ +void check_for_backing_up (ds, state) + int ds; + int state[]; +{ + if ((reject && !dfaacc[ds].dfaacc_set) || (!reject && !dfaacc[ds].dfaacc_state)) { /* state is non-accepting */ ++num_backing_up; - if ( backing_up_report ) - { - fprintf( backing_up_file, - _( "State #%d is non-accepting -\n" ), ds ); + if (backing_up_report) { + fprintf (backing_up_file, + _("State #%d is non-accepting -\n"), ds); /* identify the state */ - dump_associated_rules( backing_up_file, ds ); + dump_associated_rules (backing_up_file, ds); /* Now identify it further using the out- and * jam-transitions. */ - dump_transitions( backing_up_file, state ); + dump_transitions (backing_up_file, state); - putc( '\n', backing_up_file ); - } + putc ('\n', backing_up_file); } } +} /* check_trailing_context - check to see if NFA state set constitutes @@ -99,42 +96,38 @@ int state[]; * accset[1 .. nacc] is the list of accepting numbers for the DFA state. */ -void check_trailing_context( nfa_states, num_states, accset, nacc ) -int *nfa_states, num_states; -int *accset; -int nacc; - { +void check_trailing_context (nfa_states, num_states, accset, nacc) + int *nfa_states, num_states; + int *accset; + int nacc; +{ register int i, j; - for ( i = 1; i <= num_states; ++i ) - { - int ns = nfa_states[i]; + for (i = 1; i <= num_states; ++i) { + int ns = nfa_states[i]; register int type = state_type[ns]; register int ar = assoc_rule[ns]; - if ( type == STATE_NORMAL || rule_type[ar] != RULE_VARIABLE ) - { /* do nothing */ - } + if (type == STATE_NORMAL || rule_type[ar] != RULE_VARIABLE) { /* do nothing */ + } - else if ( type == STATE_TRAILING_CONTEXT ) - { + else if (type == STATE_TRAILING_CONTEXT) { /* Potential trouble. Scan set of accepting numbers * for the one marking the end of the "head". We * assume that this looping will be fairly cheap * since it's rare that an accepting number set * is large. */ - for ( j = 1; j <= nacc; ++j ) - if ( accset[j] & YY_TRAILING_HEAD_MASK ) - { - line_warning( - _( "dangerous trailing context" ), - rule_linenum[ar] ); + for (j = 1; j <= nacc; ++j) + if (accset[j] & YY_TRAILING_HEAD_MASK) { + line_warning (_ + ("dangerous trailing context"), +rule_linenum[ar]); return; - } - } + } } } +} /* dump_associated_rules - list the rules associated with a DFA state @@ -144,46 +137,44 @@ int nacc; * and writes a report to the given file. */ -void dump_associated_rules( file, ds ) -FILE *file; -int ds; - { +void dump_associated_rules (file, ds) + FILE *file; + int ds; +{ register int i, j; register int num_associated_rules = 0; - int rule_set[MAX_ASSOC_RULES + 1]; - int *dset = dss[ds]; - int size = dfasiz[ds]; + int rule_set[MAX_ASSOC_RULES + 1]; + int *dset = dss[ds]; + int size = dfasiz[ds]; - for ( i = 1; i <= size; ++i ) - { + for (i = 1; i <= size; ++i) { register int rule_num = rule_linenum[assoc_rule[dset[i]]]; - for ( j = 1; j <= num_associated_rules; ++j ) - if ( rule_num == rule_set[j] ) + for (j = 1; j <= num_associated_rules; ++j) + if (rule_num == rule_set[j]) break; - if ( j > num_associated_rules ) - { /* new rule */ - if ( num_associated_rules < MAX_ASSOC_RULES ) - rule_set[++num_associated_rules] = rule_num; - } + if (j > num_associated_rules) { /* new rule */ + if (num_associated_rules < MAX_ASSOC_RULES) + rule_set[++num_associated_rules] = + rule_num; } + } - bubble( rule_set, num_associated_rules ); - - fprintf( file, _( " associated rule line numbers:" ) ); + bubble (rule_set, num_associated_rules); - for ( i = 1; i <= num_associated_rules; ++i ) - { - if ( i % 8 == 1 ) - putc( '\n', file ); + fprintf (file, _(" associated rule line numbers:")); - fprintf( file, "\t%d", rule_set[i] ); - } + for (i = 1; i <= num_associated_rules; ++i) { + if (i % 8 == 1) + putc ('\n', file); - putc( '\n', file ); + fprintf (file, "\t%d", rule_set[i]); } + putc ('\n', file); +} + /* dump_transitions - list the transitions associated with a DFA state * @@ -196,33 +187,32 @@ int ds; * is done to the given file. */ -void dump_transitions( file, state ) -FILE *file; -int state[]; - { +void dump_transitions (file, state) + FILE *file; + int state[]; +{ register int i, ec; - int out_char_set[CSIZE]; + int out_char_set[CSIZE]; - for ( i = 0; i < csize; ++i ) - { - ec = ABS( ecgroup[i] ); + for (i = 0; i < csize; ++i) { + ec = ABS (ecgroup[i]); out_char_set[i] = state[ec]; - } + } - fprintf( file, _( " out-transitions: " ) ); + fprintf (file, _(" out-transitions: ")); - list_character_set( file, out_char_set ); + list_character_set (file, out_char_set); /* now invert the members of the set to get the jam transitions */ - for ( i = 0; i < csize; ++i ) - out_char_set[i] = ! out_char_set[i]; + for (i = 0; i < csize; ++i) + out_char_set[i] = !out_char_set[i]; - fprintf( file, _( "\n jam-transitions: EOF " ) ); + fprintf (file, _("\n jam-transitions: EOF ")); - list_character_set( file, out_char_set ); + list_character_set (file, out_char_set); - putc( '\n', file ); - } + putc ('\n', file); +} /* epsclosure - construct the epsilon closure of a set of ndfa states @@ -245,13 +235,13 @@ int state[]; * hashval is the hash value for the dfa corresponding to the state set. */ -int *epsclosure( t, ns_addr, accset, nacc_addr, hv_addr ) -int *t, *ns_addr, accset[], *nacc_addr, *hv_addr; - { +int *epsclosure (t, ns_addr, accset, nacc_addr, hv_addr) + int *t, *ns_addr, accset[], *nacc_addr, *hv_addr; +{ register int stkpos, ns, tsp; - int numstates = *ns_addr, nacc, hashval, transsym, nfaccnum; - int stkend, nstate; - static int did_stk_init = false, *stk; + int numstates = *ns_addr, nacc, hashval, transsym, nfaccnum; + int stkend, nstate; + static int did_stk_init = false, *stk; #define MARK_STATE(state) \ do{ trans1[state] = trans1[state] - MARKER_DIFFERENCE;} while(0) @@ -301,90 +291,84 @@ ADD_STATE(state); \ }while(0) - if ( ! did_stk_init ) - { - stk = allocate_integer_array( current_max_dfa_size ); + if (!did_stk_init) { + stk = allocate_integer_array (current_max_dfa_size); did_stk_init = true; - } + } nacc = stkend = hashval = 0; - for ( nstate = 1; nstate <= numstates; ++nstate ) - { + for (nstate = 1; nstate <= numstates; ++nstate) { ns = t[nstate]; /* The state could be marked if we've already pushed it onto * the stack. */ - if ( ! IS_MARKED(ns) ) - { - PUT_ON_STACK(ns); - CHECK_ACCEPT(ns); + if (!IS_MARKED (ns)) { + PUT_ON_STACK (ns); + CHECK_ACCEPT (ns); hashval += ns; - } } + } - for ( stkpos = 1; stkpos <= stkend; ++stkpos ) - { + for (stkpos = 1; stkpos <= stkend; ++stkpos) { ns = stk[stkpos]; transsym = transchar[ns]; - if ( transsym == SYM_EPSILON ) - { + if (transsym == SYM_EPSILON) { tsp = trans1[ns] + MARKER_DIFFERENCE; - if ( tsp != NO_TRANSITION ) - { - if ( ! IS_MARKED(tsp) ) - STACK_STATE(tsp); + if (tsp != NO_TRANSITION) { + if (!IS_MARKED (tsp)) + STACK_STATE (tsp); tsp = trans2[ns]; - if ( tsp != NO_TRANSITION && ! IS_MARKED(tsp) ) - STACK_STATE(tsp); - } + if (tsp != NO_TRANSITION + && !IS_MARKED (tsp)) STACK_STATE (tsp); } } + } /* Clear out "visit" markers. */ - for ( stkpos = 1; stkpos <= stkend; ++stkpos ) - { - if ( IS_MARKED(stk[stkpos]) ) - UNMARK_STATE(stk[stkpos]); + for (stkpos = 1; stkpos <= stkend; ++stkpos) { + if (IS_MARKED (stk[stkpos])) + UNMARK_STATE (stk[stkpos]); else - flexfatal( - _( "consistency check failed in epsclosure()" ) ); - } + flexfatal (_ + ("consistency check failed in epsclosure()")); + } *ns_addr = numstates; *hv_addr = hashval; *nacc_addr = nacc; return t; - } +} /* increase_max_dfas - increase the maximum number of DFAs */ -void increase_max_dfas() - { +void increase_max_dfas () +{ current_max_dfas += MAX_DFAS_INCREMENT; ++num_reallocs; - base = reallocate_integer_array( base, current_max_dfas ); - def = reallocate_integer_array( def, current_max_dfas ); - dfasiz = reallocate_integer_array( dfasiz, current_max_dfas ); - accsiz = reallocate_integer_array( accsiz, current_max_dfas ); - dhash = reallocate_integer_array( dhash, current_max_dfas ); - dss = reallocate_int_ptr_array( dss, current_max_dfas ); - dfaacc = reallocate_dfaacc_union( dfaacc, current_max_dfas ); + base = reallocate_integer_array (base, current_max_dfas); + def = reallocate_integer_array (def, current_max_dfas); + dfasiz = reallocate_integer_array (dfasiz, current_max_dfas); + accsiz = reallocate_integer_array (accsiz, current_max_dfas); + dhash = reallocate_integer_array (dhash, current_max_dfas); + dss = reallocate_int_ptr_array (dss, current_max_dfas); + dfaacc = reallocate_dfaacc_union (dfaacc, current_max_dfas); - if ( nultrans ) + if (nultrans) nultrans = - reallocate_integer_array( nultrans, current_max_dfas ); - } + reallocate_integer_array (nultrans, + current_max_dfas); +} /* ntod - convert an ndfa to a dfa @@ -393,16 +377,16 @@ void increase_max_dfas() * dfa starts out in state #1. */ -void ntod() - { - int *accset, ds, nacc, newds; - int sym, hashval, numstates, dsize; - int num_full_table_rows; /* used only for -f */ - int *nset, *dset; - int targptr, totaltrans, i, comstate, comfreq, targ; - int symlist[CSIZE + 1]; - int num_start_states; - int todo_head, todo_next; +void ntod () +{ + int *accset, ds, nacc, newds; + int sym, hashval, numstates, dsize; + int num_full_table_rows; /* used only for -f */ + int *nset, *dset; + int targptr, totaltrans, i, comstate, comfreq, targ; + int symlist[CSIZE + 1]; + int num_start_states; + int todo_head, todo_next; /* Note that the following are indexed by *equivalence classes* * and not by characters. Since equivalence classes are indexed @@ -411,14 +395,14 @@ void ntod() * equivalence class) these arrays must have room for indices * from 1 to CSIZE, so their size must be CSIZE + 1. */ - int duplist[CSIZE + 1], state[CSIZE + 1]; - int targfreq[CSIZE + 1], targstate[CSIZE + 1]; + int duplist[CSIZE + 1], state[CSIZE + 1]; + int targfreq[CSIZE + 1], targstate[CSIZE + 1]; /* accset needs to be large enough to hold all of the rules present * in the input, *plus* their YY_TRAILING_HEAD_MASK variants. */ - accset = allocate_integer_array( (num_rules + 1) * 2 ); - nset = allocate_integer_array( current_max_dfa_size ); + accset = allocate_integer_array ((num_rules + 1) * 2); + nset = allocate_integer_array (current_max_dfa_size); /* The "todo" queue is represented by the head, which is the DFA * state currently being processed, and the "next", which is the @@ -428,22 +412,20 @@ void ntod() */ todo_head = todo_next = 0; - for ( i = 0; i <= csize; ++i ) - { + for (i = 0; i <= csize; ++i) { duplist[i] = NIL; symlist[i] = false; - } + } - for ( i = 0; i <= num_rules; ++i ) + for (i = 0; i <= num_rules; ++i) accset[i] = NIL; - if ( trace ) - { - dumpnfa( scset[1] ); - fputs( _( "\n\nDFA Dump:\n\n" ), stderr ); - } + if (trace) { + dumpnfa (scset[1]); + fputs (_("\n\nDFA Dump:\n\n"), stderr); + } - inittbl(); + inittbl (); /* Check to see whether we should build a separate table for * transitions on NUL characters. We don't do this for full-speed @@ -477,50 +459,46 @@ void ntod() /* Note that the test for ecgroup[0] == numecs below accomplishes * both (1) and (2) above */ - if ( ! fullspd && ecgroup[0] == numecs ) - { + if (!fullspd && ecgroup[0] == numecs) { /* NUL is alone in its equivalence class, which is the * last one. */ - int use_NUL_table = (numecs == csize); + int use_NUL_table = (numecs == csize); - if ( fulltbl && ! use_NUL_table ) - { + if (fulltbl && !use_NUL_table) { /* We still may want to use the table if numecs * is a power of 2. */ - int power_of_two; + int power_of_two; - for ( power_of_two = 1; power_of_two <= csize; - power_of_two *= 2 ) - if ( numecs == power_of_two ) - { + for (power_of_two = 1; power_of_two <= csize; + power_of_two *= 2) + if (numecs == power_of_two) { use_NUL_table = true; break; - } - } + } + } - if ( use_NUL_table ) - nultrans = allocate_integer_array( current_max_dfas ); + if (use_NUL_table) + nultrans = + allocate_integer_array (current_max_dfas); /* From now on, nultrans != nil indicates that we're * saving null transitions for later, separate encoding. */ - } + } - if ( fullspd ) - { - for ( i = 0; i <= numecs; ++i ) + if (fullspd) { + for (i = 0; i <= numecs; ++i) state[i] = 0; - place_state( state, 0, 0 ); + place_state (state, 0, 0); dfaacc[0].dfaacc_state = 0; - } + } - else if ( fulltbl ) - { - if ( nultrans ) + else if (fulltbl) { + if (nultrans) /* We won't be including NUL's transitions in the * table, so build it for entries from 0 .. numecs - 1. */ @@ -536,68 +514,67 @@ void ntod() /* Unless -Ca, declare it "short" because it's a real * long-shot that that won't be large enough. */ - out_str_dec( "static yyconst %s yy_nxt[][%d] =\n {\n", - long_align ? "long" : "short", num_full_table_rows ); + out_str_dec ("static yyconst %s yy_nxt[][%d] =\n {\n", + long_align ? "long" : "short", + num_full_table_rows); - outn( " {" ); + outn (" {"); /* Generate 0 entries for state #0. */ - for ( i = 0; i < num_full_table_rows; ++i ) - mk2data( 0 ); + for (i = 0; i < num_full_table_rows; ++i) + mk2data (0); - dataflush(); - outn( " },\n" ); - } + dataflush (); + outn (" },\n"); + } /* Create the first states. */ num_start_states = lastsc * 2; - for ( i = 1; i <= num_start_states; ++i ) - { + for (i = 1; i <= num_start_states; ++i) { numstates = 1; /* For each start condition, make one state for the case when * we're at the beginning of the line (the '^' operator) and * one for the case when we're not. */ - if ( i % 2 == 1 ) + if (i % 2 == 1) nset[numstates] = scset[(i / 2) + 1]; else nset[numstates] = - mkbranch( scbol[i / 2], scset[i / 2] ); + mkbranch (scbol[i / 2], scset[i / 2]); - nset = epsclosure( nset, &numstates, accset, &nacc, &hashval ); + nset = + epsclosure (nset, &numstates, accset, &nacc, + &hashval); - if ( snstods( nset, numstates, accset, nacc, hashval, &ds ) ) - { + if (snstods (nset, numstates, accset, nacc, hashval, &ds)) { numas += nacc; totnst += numstates; ++todo_next; - if ( variable_trailing_context_rules && nacc > 0 ) - check_trailing_context( nset, numstates, - accset, nacc ); - } + if (variable_trailing_context_rules && nacc > 0) + check_trailing_context (nset, numstates, + accset, nacc); } + } - if ( ! fullspd ) - { - if ( ! snstods( nset, 0, accset, 0, 0, &end_of_buffer_state ) ) - flexfatal( - _( "could not create unique end-of-buffer state" ) ); + if (!fullspd) { + if (!snstods (nset, 0, accset, 0, 0, &end_of_buffer_state)) + flexfatal (_ + ("could not create unique end-of-buffer state")); ++numas; ++num_start_states; ++todo_next; - } + } - while ( todo_head < todo_next ) - { + while (todo_head < todo_next) { targptr = 0; totaltrans = 0; - for ( i = 1; i <= numecs; ++i ) + for (i = 1; i <= numecs; ++i) state[i] = 0; ds = ++todo_head; @@ -605,53 +582,57 @@ void ntod() dset = dss[ds]; dsize = dfasiz[ds]; - if ( trace ) - fprintf( stderr, _( "state # %d:\n" ), ds ); + if (trace) + fprintf (stderr, _("state # %d:\n"), ds); - sympartition( dset, dsize, symlist, duplist ); + sympartition (dset, dsize, symlist, duplist); - for ( sym = 1; sym <= numecs; ++sym ) - { - if ( symlist[sym] ) - { + for (sym = 1; sym <= numecs; ++sym) { + if (symlist[sym]) { symlist[sym] = 0; - if ( duplist[sym] == NIL ) - { + if (duplist[sym] == NIL) { /* Symbol has unique out-transitions. */ - numstates = symfollowset( dset, dsize, - sym, nset ); - nset = epsclosure( nset, &numstates, - accset, &nacc, &hashval ); - - if ( snstods( nset, numstates, accset, - nacc, hashval, &newds ) ) - { - totnst = totnst + numstates; + numstates = + symfollowset (dset, dsize, + sym, nset); + nset = + epsclosure (nset, + &numstates, + accset, &nacc, + &hashval); + + if (snstods + (nset, numstates, accset, nacc, + hashval, &newds)) { + totnst = + totnst + numstates; ++todo_next; numas += nacc; - if ( - variable_trailing_context_rules && - nacc > 0 ) - check_trailing_context( - nset, numstates, - accset, nacc ); - } + if + (variable_trailing_context_rules + && nacc > 0) + check_trailing_context + (nset, + numstates, + accset, + nacc); + } state[sym] = newds; - if ( trace ) - fprintf( stderr, "\t%d\t%d\n", - sym, newds ); + if (trace) + fprintf (stderr, + "\t%d\t%d\n", sym, + newds); targfreq[++targptr] = 1; targstate[targptr] = newds; ++numuniq; - } + } - else - { + else { /* sym's equivalence class has the same * transitions as duplist(sym)'s * equivalence class. @@ -659,87 +640,83 @@ void ntod() targ = state[duplist[sym]]; state[sym] = targ; - if ( trace ) - fprintf( stderr, "\t%d\t%d\n", - sym, targ ); + if (trace) + fprintf (stderr, + "\t%d\t%d\n", sym, + targ); /* Update frequency count for * destination state. */ i = 0; - while ( targstate[++i] != targ ) - ; + while (targstate[++i] != targ) ; ++targfreq[i]; ++numdup; - } + } ++totaltrans; duplist[sym] = NIL; - } } + } - if ( caseins && ! useecs ) - { + if (caseins && !useecs) { register int j; - for ( i = 'A', j = 'a'; i <= 'Z'; ++i, ++j ) - { - if ( state[i] == 0 && state[j] != 0 ) + for (i = 'A', j = 'a'; i <= 'Z'; ++i, ++j) { + if (state[i] == 0 && state[j] != 0) /* We're adding a transition. */ ++totaltrans; - else if ( state[i] != 0 && state[j] == 0 ) + else if (state[i] != 0 && state[j] == 0) /* We're taking away a transition. */ --totaltrans; state[i] = state[j]; - } } + } numsnpairs += totaltrans; - if ( ds > num_start_states ) - check_for_backing_up( ds, state ); + if (ds > num_start_states) + check_for_backing_up (ds, state); - if ( nultrans ) - { + if (nultrans) { nultrans[ds] = state[NUL_ec]; state[NUL_ec] = 0; /* remove transition */ - } + } - if ( fulltbl ) - { - outn( " {" ); + if (fulltbl) { + outn (" {"); /* Supply array's 0-element. */ - if ( ds == end_of_buffer_state ) - mk2data( -end_of_buffer_state ); + if (ds == end_of_buffer_state) + mk2data (-end_of_buffer_state); else - mk2data( end_of_buffer_state ); + mk2data (end_of_buffer_state); - for ( i = 1; i < num_full_table_rows; ++i ) + for (i = 1; i < num_full_table_rows; ++i) /* Jams are marked by negative of state * number. */ - mk2data( state[i] ? state[i] : -ds ); + mk2data (state[i] ? state[i] : -ds); - dataflush(); - outn( " },\n" ); - } + dataflush (); + outn (" },\n"); + } - else if ( fullspd ) - place_state( state, ds, totaltrans ); + else if (fullspd) + place_state (state, ds, totaltrans); - else if ( ds == end_of_buffer_state ) + else if (ds == end_of_buffer_state) /* Special case this state to make sure it does what * it's supposed to, i.e., jam on end-of-buffer. */ - stack1( ds, 0, 0, JAMSTATE ); + stack1 (ds, 0, 0, JAMSTATE); + + else { /* normal, compressed state */ - else /* normal, compressed state */ - { /* Determine which destination state is the most * common, and how many transitions to it there are. */ @@ -747,41 +724,38 @@ void ntod() comfreq = 0; comstate = 0; - for ( i = 1; i <= targptr; ++i ) - if ( targfreq[i] > comfreq ) - { + for (i = 1; i <= targptr; ++i) + if (targfreq[i] > comfreq) { comfreq = targfreq[i]; comstate = targstate[i]; - } + } - bldtbl( state, ds, totaltrans, comstate, comfreq ); - } + bldtbl (state, ds, totaltrans, comstate, comfreq); } + } - if ( fulltbl ) - dataend(); + if (fulltbl) + dataend (); - else if ( ! fullspd ) - { - cmptmps(); /* create compressed template entries */ + else if (!fullspd) { + cmptmps (); /* create compressed template entries */ /* Create tables for all the states with only one * out-transition. */ - while ( onesp > 0 ) - { - mk1tbl( onestate[onesp], onesym[onesp], onenext[onesp], - onedef[onesp] ); + while (onesp > 0) { + mk1tbl (onestate[onesp], onesym[onesp], + onenext[onesp], onedef[onesp]); --onesp; - } - - mkdeftbl(); } - flex_free( (void *) accset ); - flex_free( (void *) nset ); + mkdeftbl (); } + flex_free ((void *) accset); + flex_free ((void *) nset); +} + /* snstods - converts a set of ndfa states into a dfa state * @@ -793,129 +767,122 @@ void ntod() * On return, the dfa state number is in newds. */ -int snstods( sns, numstates, accset, nacc, hashval, newds_addr ) -int sns[], numstates, accset[], nacc, hashval, *newds_addr; - { - int didsort = 0; +int snstods (sns, numstates, accset, nacc, hashval, newds_addr) + int sns[], numstates, accset[], nacc, hashval, *newds_addr; +{ + int didsort = 0; register int i, j; - int newds, *oldsns; + int newds, *oldsns; - for ( i = 1; i <= lastdfa; ++i ) - if ( hashval == dhash[i] ) - { - if ( numstates == dfasiz[i] ) - { + for (i = 1; i <= lastdfa; ++i) + if (hashval == dhash[i]) { + if (numstates == dfasiz[i]) { oldsns = dss[i]; - if ( ! didsort ) - { + if (!didsort) { /* We sort the states in sns so we * can compare it to oldsns quickly. * We use bubble because there probably * aren't very many states. */ - bubble( sns, numstates ); + bubble (sns, numstates); didsort = 1; - } + } - for ( j = 1; j <= numstates; ++j ) - if ( sns[j] != oldsns[j] ) + for (j = 1; j <= numstates; ++j) + if (sns[j] != oldsns[j]) break; - if ( j > numstates ) - { + if (j > numstates) { ++dfaeql; *newds_addr = i; return 0; - } + } ++hshcol; - } + } else ++hshsave; - } + } /* Make a new dfa. */ - if ( ++lastdfa >= current_max_dfas ) - increase_max_dfas(); + if (++lastdfa >= current_max_dfas) + increase_max_dfas (); newds = lastdfa; - dss[newds] = allocate_integer_array( numstates + 1 ); + dss[newds] = allocate_integer_array (numstates + 1); /* If we haven't already sorted the states in sns, we do so now, * so that future comparisons with it can be made quickly. */ - if ( ! didsort ) - bubble( sns, numstates ); + if (!didsort) + bubble (sns, numstates); - for ( i = 1; i <= numstates; ++i ) + for (i = 1; i <= numstates; ++i) dss[newds][i] = sns[i]; dfasiz[newds] = numstates; dhash[newds] = hashval; - if ( nacc == 0 ) - { - if ( reject ) + if (nacc == 0) { + if (reject) dfaacc[newds].dfaacc_set = (int *) 0; else dfaacc[newds].dfaacc_state = 0; accsiz[newds] = 0; - } + } - else if ( reject ) - { + else if (reject) { /* We sort the accepting set in increasing order so the * disambiguating rule that the first rule listed is considered * match in the event of ties will work. We use a bubble * sort since the list is probably quite small. */ - bubble( accset, nacc ); + bubble (accset, nacc); - dfaacc[newds].dfaacc_set = allocate_integer_array( nacc + 1 ); + dfaacc[newds].dfaacc_set = + allocate_integer_array (nacc + 1); /* Save the accepting set for later */ - for ( i = 1; i <= nacc; ++i ) - { + for (i = 1; i <= nacc; ++i) { dfaacc[newds].dfaacc_set[i] = accset[i]; - if ( accset[i] <= num_rules ) + if (accset[i] <= num_rules) /* Who knows, perhaps a REJECT can yield * this rule. */ rule_useful[accset[i]] = true; - } + } accsiz[newds] = nacc; - } + } - else - { + else { /* Find lowest numbered rule so the disambiguating rule * will work. */ j = num_rules + 1; - for ( i = 1; i <= nacc; ++i ) - if ( accset[i] < j ) + for (i = 1; i <= nacc; ++i) + if (accset[i] < j) j = accset[i]; dfaacc[newds].dfaacc_state = j; - if ( j <= num_rules ) + if (j <= num_rules) rule_useful[j] = true; - } + } *newds_addr = newds; return 1; - } +} /* symfollowset - follow the symbol transitions one step @@ -925,85 +892,79 @@ int sns[], numstates, accset[], nacc, hashval, *newds_addr; * int transsym, int nset[current_max_dfa_size] ); */ -int symfollowset( ds, dsize, transsym, nset ) -int ds[], dsize, transsym, nset[]; - { - int ns, tsp, sym, i, j, lenccl, ch, numstates, ccllist; +int symfollowset (ds, dsize, transsym, nset) + int ds[], dsize, transsym, nset[]; +{ + int ns, tsp, sym, i, j, lenccl, ch, numstates, ccllist; numstates = 0; - for ( i = 1; i <= dsize; ++i ) - { /* for each nfa state ns in the state set of ds */ + for (i = 1; i <= dsize; ++i) { /* for each nfa state ns in the state set of ds */ ns = ds[i]; sym = transchar[ns]; tsp = trans1[ns]; - if ( sym < 0 ) - { /* it's a character class */ + if (sym < 0) { /* it's a character class */ sym = -sym; ccllist = cclmap[sym]; lenccl = ccllen[sym]; - if ( cclng[sym] ) - { - for ( j = 0; j < lenccl; ++j ) - { + if (cclng[sym]) { + for (j = 0; j < lenccl; ++j) { /* Loop through negated character * class. */ ch = ccltbl[ccllist + j]; - if ( ch == 0 ) + if (ch == 0) ch = NUL_ec; - if ( ch > transsym ) + if (ch > transsym) /* Transsym isn't in negated * ccl. */ break; - else if ( ch == transsym ) - /* next 2 */ goto bottom; - } + else if (ch == transsym) + /* next 2 */ + goto bottom; + } /* Didn't find transsym in ccl. */ nset[++numstates] = tsp; - } + } else - for ( j = 0; j < lenccl; ++j ) - { + for (j = 0; j < lenccl; ++j) { ch = ccltbl[ccllist + j]; - if ( ch == 0 ) + if (ch == 0) ch = NUL_ec; - if ( ch > transsym ) + if (ch > transsym) break; - else if ( ch == transsym ) - { + else if (ch == transsym) { nset[++numstates] = tsp; break; - } } - } + } + } - else if ( sym >= 'A' && sym <= 'Z' && caseins ) - flexfatal( - _( "consistency check failed in symfollowset" ) ); + else if (sym >= 'A' && sym <= 'Z' && caseins) + flexfatal (_ + ("consistency check failed in symfollowset")); - else if ( sym == SYM_EPSILON ) - { /* do nothing */ - } + else if (sym == SYM_EPSILON) { /* do nothing */ + } - else if ( ABS( ecgroup[sym] ) == transsym ) + else if (ABS (ecgroup[sym]) == transsym) nset[++numstates] = tsp; - bottom: ; - } + bottom:; + } return numstates; - } +} /* sympartition - partition characters with same out-transitions @@ -1013,86 +974,77 @@ int ds[], dsize, transsym, nset[]; * int symlist[numecs], int duplist[numecs] ); */ -void sympartition( ds, numstates, symlist, duplist ) -int ds[], numstates; -int symlist[], duplist[]; - { - int tch, i, j, k, ns, dupfwd[CSIZE + 1], lenccl, cclp, ich; +void sympartition (ds, numstates, symlist, duplist) + int ds[], numstates; + int symlist[], duplist[]; +{ + int tch, i, j, k, ns, dupfwd[CSIZE + 1], lenccl, cclp, ich; /* Partitioning is done by creating equivalence classes for those * characters which have out-transitions from the given state. Thus * we are really creating equivalence classes of equivalence classes. */ - for ( i = 1; i <= numecs; ++i ) - { /* initialize equivalence class list */ + for (i = 1; i <= numecs; ++i) { /* initialize equivalence class list */ duplist[i] = i - 1; dupfwd[i] = i + 1; - } + } duplist[1] = NIL; dupfwd[numecs] = NIL; - for ( i = 1; i <= numstates; ++i ) - { + for (i = 1; i <= numstates; ++i) { ns = ds[i]; tch = transchar[ns]; - if ( tch != SYM_EPSILON ) - { - if ( tch < -lastccl || tch >= csize ) - { - flexfatal( - _( "bad transition character detected in sympartition()" ) ); - } + if (tch != SYM_EPSILON) { + if (tch < -lastccl || tch >= csize) { + flexfatal (_ + ("bad transition character detected in sympartition()")); + } - if ( tch >= 0 ) - { /* character transition */ - int ec = ecgroup[tch]; + if (tch >= 0) { /* character transition */ + int ec = ecgroup[tch]; - mkechar( ec, dupfwd, duplist ); + mkechar (ec, dupfwd, duplist); symlist[ec] = 1; - } + } - else - { /* character class */ + else { /* character class */ tch = -tch; lenccl = ccllen[tch]; cclp = cclmap[tch]; - mkeccl( ccltbl + cclp, lenccl, dupfwd, - duplist, numecs, NUL_ec ); + mkeccl (ccltbl + cclp, lenccl, dupfwd, + duplist, numecs, NUL_ec); - if ( cclng[tch] ) - { + if (cclng[tch]) { j = 0; - for ( k = 0; k < lenccl; ++k ) - { + for (k = 0; k < lenccl; ++k) { ich = ccltbl[cclp + k]; - if ( ich == 0 ) + if (ich == 0) ich = NUL_ec; - for ( ++j; j < ich; ++j ) + for (++j; j < ich; ++j) symlist[j] = 1; - } + } - for ( ++j; j <= numecs; ++j ) + for (++j; j <= numecs; ++j) symlist[j] = 1; - } + } else - for ( k = 0; k < lenccl; ++k ) - { + for (k = 0; k < lenccl; ++k) { ich = ccltbl[cclp + k]; - if ( ich == 0 ) + if (ich == 0) ich = NUL_ec; symlist[ich] = 1; - } - } + } } } } +} diff --git a/ecs.c b/ecs.c index 883819d..e2abbe4 100644 --- a/ecs.c +++ b/ecs.c @@ -36,12 +36,11 @@ /* ccl2ecl - convert character classes to set of equivalence classes */ -void ccl2ecl() - { - int i, ich, newlen, cclp, ccls, cclmec; +void ccl2ecl () +{ + int i, ich, newlen, cclp, ccls, cclmec; - for ( i = 1; i <= lastccl; ++i ) - { + for (i = 1; i <= lastccl; ++i) { /* We loop through each character class, and for each character * in the class, add the character's equivalence class to the * new "character" class we are creating. Thus when we are all @@ -52,21 +51,19 @@ void ccl2ecl() newlen = 0; cclp = cclmap[i]; - for ( ccls = 0; ccls < ccllen[i]; ++ccls ) - { + for (ccls = 0; ccls < ccllen[i]; ++ccls) { ich = ccltbl[cclp + ccls]; cclmec = ecgroup[ich]; - if ( cclmec > 0 ) - { + if (cclmec > 0) { ccltbl[cclp + newlen] = cclmec; ++newlen; - } } + } ccllen[i] = newlen; - } } +} /* cre8ecs - associate equivalence class numbers with class members @@ -77,10 +74,10 @@ void ccl2ecl() * Returned is the number of classes. */ -int cre8ecs( fwd, bck, num ) -int fwd[], bck[], num; - { - int i, j, numcl; +int cre8ecs (fwd, bck, num) + int fwd[], bck[], num; +{ + int i, j, numcl; numcl = 0; @@ -89,16 +86,15 @@ int fwd[], bck[], num; * is positive, then x is the representative of its equivalence * class. */ - for ( i = 1; i <= num; ++i ) - if ( bck[i] == NIL ) - { + for (i = 1; i <= num; ++i) + if (bck[i] == NIL) { bck[i] = ++numcl; - for ( j = fwd[i]; j != NIL; j = fwd[j] ) + for (j = fwd[i]; j != NIL; j = fwd[j]) bck[j] = -numcl; - } + } return numcl; - } +} /* mkeccl - update equivalence classes based on character class xtions @@ -116,12 +112,12 @@ int fwd[], bck[], num; * NUL_mapping is the value which NUL (0) should be mapped to. */ -void mkeccl( ccls, lenccl, fwd, bck, llsiz, NUL_mapping ) -Char ccls[]; -int lenccl, fwd[], bck[], llsiz, NUL_mapping; - { - int cclp, oldec, newec; - int cclm, i, j; +void mkeccl (ccls, lenccl, fwd, bck, llsiz, NUL_mapping) + Char ccls[]; + int lenccl, fwd[], bck[], llsiz, NUL_mapping; +{ + int cclp, oldec, newec; + int cclm, i, j; static unsigned char cclflags[CSIZE]; /* initialized to all '\0' */ /* Note that it doesn't matter whether or not the character class is @@ -130,11 +126,10 @@ int lenccl, fwd[], bck[], llsiz, NUL_mapping; cclp = 0; - while ( cclp < lenccl ) - { + while (cclp < lenccl) { cclm = ccls[cclp]; - if ( NUL_mapping && cclm == 0 ) + if (NUL_mapping && cclm == 0) cclm = NUL_mapping; oldec = bck[cclm]; @@ -142,22 +137,19 @@ int lenccl, fwd[], bck[], llsiz, NUL_mapping; j = cclp + 1; - for ( i = fwd[cclm]; i != NIL && i <= llsiz; i = fwd[i] ) - { /* look for the symbol in the character class */ - for ( ; j < lenccl; ++j ) - { + for (i = fwd[cclm]; i != NIL && i <= llsiz; i = fwd[i]) { /* look for the symbol in the character class */ + for (; j < lenccl; ++j) { register int ccl_char; - if ( NUL_mapping && ccls[j] == 0 ) + if (NUL_mapping && ccls[j] == 0) ccl_char = NUL_mapping; else ccl_char = ccls[j]; - if ( ccl_char > i ) + if (ccl_char > i) break; - if ( ccl_char == i && ! cclflags[j] ) - { + if (ccl_char == i && !cclflags[j]) { /* We found an old companion of cclm * in the ccl. Link it into the new * equivalence class and flag it as @@ -173,8 +165,8 @@ int lenccl, fwd[], bck[], llsiz, NUL_mapping; /* Get next equivalence class member. */ /* continue 2 */ goto next_pt; - } } + } /* Symbol isn't in character class. Put it in the old * equivalence class. @@ -182,48 +174,46 @@ int lenccl, fwd[], bck[], llsiz, NUL_mapping; bck[i] = oldec; - if ( oldec != NIL ) + if (oldec != NIL) fwd[oldec] = i; oldec = i; - next_pt: ; - } + next_pt:; + } - if ( bck[cclm] != NIL || oldec != bck[cclm] ) - { + if (bck[cclm] != NIL || oldec != bck[cclm]) { bck[cclm] = NIL; fwd[oldec] = NIL; - } + } fwd[newec] = NIL; /* Find next ccl member to process. */ - for ( ++cclp; cclflags[cclp] && cclp < lenccl; ++cclp ) - { + for (++cclp; cclflags[cclp] && cclp < lenccl; ++cclp) { /* Reset "doesn't need processing" flag. */ cclflags[cclp] = 0; - } } } +} /* mkechar - create equivalence class for single character */ -void mkechar( tch, fwd, bck ) -int tch, fwd[], bck[]; - { +void mkechar (tch, fwd, bck) + int tch, fwd[], bck[]; +{ /* If until now the character has been a proper subset of * an equivalence class, break it away to create a new ec */ - if ( fwd[tch] != NIL ) + if (fwd[tch] != NIL) bck[fwd[tch]] = bck[tch]; - if ( bck[tch] != NIL ) + if (bck[tch] != NIL) fwd[bck[tch]] = fwd[tch]; fwd[tch] = NIL; bck[tch] = NIL; - } +} diff --git a/flexdef.h b/flexdef.h index c1e8f2b..6a47bac 100644 --- a/flexdef.h +++ b/flexdef.h @@ -194,10 +194,10 @@ */ #define NIL 0 -#define JAM -1 /* to mark a missing DFA transition */ +#define JAM -1 /* to mark a missing DFA transition */ #define NO_TRANSITION NIL -#define UNIQUE -1 /* marks a symbol as an e.c. representative */ -#define INFINITY -1 /* for x{5,} constructions */ +#define UNIQUE -1 /* marks a symbol as an e.c. representative */ +#define INFINITY -1 /* for x{5,} constructions */ #define INITIAL_MAX_CCLS 100 /* max number of unique character classes */ #define MAX_CCLS_INCREMENT 100 @@ -215,7 +215,7 @@ #define INITIAL_MAX_DFAS 1000 /* default maximum number of dfa states */ #define MAX_DFAS_INCREMENT 1000 -#define JAMSTATE -32766 /* marks a reference to the state that always jams */ +#define JAMSTATE -32766 /* marks a reference to the state that always jams */ /* Maximum number of NFA states. */ #define MAXIMUM_MNS 31999 @@ -240,7 +240,7 @@ #define MAX_SCS_INCREMENT 40 /* amount to bump by if it's not enough */ #define ONE_STACK_SIZE 500 /* stack of states with only one out-transition */ -#define SAME_TRANS -1 /* transition is the same as "default" entry for state */ +#define SAME_TRANS -1 /* transition is the same as "default" entry for state */ /* The following percentages are used to tune table compression: @@ -294,7 +294,7 @@ */ #define PROT_SAVE_SIZE 2000 -#define MSP 50 /* maximum number of saved protos (protos on the proto queue) */ +#define MSP 50 /* maximum number of saved protos (protos on the proto queue) */ /* Maximum number of out-transitions a state can have that we'll rummage * around through the interior of the internal fast table looking for a @@ -369,7 +369,9 @@ * reject_really_used - same for REJECT */ -extern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt; +extern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, + + spprdflt; extern int interactive, caseins, lex_compat, posix_compat, do_yylineno; extern int useecs, fulltbl, usemecs, fullspd; extern int gen_line_dirs, performance_report, backing_up_report; @@ -384,9 +386,9 @@ extern int yymore_used, reject, real_reject, continued_action, in_rule; * tablesfilename - filename for external tables * tablesout - FILE stream for external tables */ -extern bool tablesext, tablestoggle; -extern char* tablesfilename; -extern FILE* tablesout; +extern bool tablesext, tablestoggle; +extern char *tablesfilename; +extern FILE *tablesout; extern int yymore_really_used, reject_really_used; @@ -603,12 +605,13 @@ extern char **scname; extern int current_max_dfa_size, current_max_xpairs; extern int current_max_template_xpairs, current_max_dfas; extern int lastdfa, *nxt, *chk, *tnxt; -extern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz; -extern union dfaacc_union - { - int *dfaacc_set; - int dfaacc_state; - } *dfaacc; +extern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, + + *dfasiz; +extern union dfaacc_union { + int *dfaacc_set; + int dfaacc_state; +} *dfaacc; extern int *accsiz, *dhash, numas; extern int numsnpairs, jambase, jamstate; extern int end_of_buffer_state; @@ -655,12 +658,12 @@ extern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs; extern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave; extern int num_backing_up, bol_needed; -void *allocate_array PROTO((int, size_t)); -void *reallocate_array PROTO((void*, int, size_t)); +void *allocate_array PROTO ((int, size_t)); +void *reallocate_array PROTO ((void *, int, size_t)); -void *flex_alloc PROTO((size_t)); -void *flex_realloc PROTO((void*, size_t)); -void flex_free PROTO((void*)); +void *flex_alloc PROTO ((size_t)); +void *flex_realloc PROTO ((void *, size_t)); +void flex_free PROTO ((void *)); #define allocate_integer_array(size) \ (int *) allocate_array( size, sizeof( int ) ) @@ -718,352 +721,357 @@ extern int yylval; /* from file ccl.c */ -extern void ccladd PROTO((int, int)); /* add a single character to a ccl */ -extern int cclinit PROTO((void)); /* make an empty ccl */ -extern void cclnegate PROTO((int)); /* negate a ccl */ +extern void ccladd PROTO ((int, int)); /* add a single character to a ccl */ +extern int cclinit PROTO ((void)); /* make an empty ccl */ +extern void cclnegate PROTO ((int)); /* negate a ccl */ /* List the members of a set of characters in CCL form. */ -extern void list_character_set PROTO((FILE*, int[])); +extern void list_character_set PROTO ((FILE *, int[])); /* from file dfa.c */ /* Check a DFA state for backing up. */ -extern void check_for_backing_up PROTO((int, int[])); +extern void check_for_backing_up PROTO ((int, int[])); /* Check to see if NFA state set constitutes "dangerous" trailing context. */ -extern void check_trailing_context PROTO((int*, int, int*, int)); +extern void check_trailing_context PROTO ((int *, int, int *, int)); /* Construct the epsilon closure of a set of ndfa states. */ -extern int *epsclosure PROTO((int*, int*, int[], int*, int*)); +extern int *epsclosure PROTO ((int *, int *, int[], int *, int *)); /* Increase the maximum number of dfas. */ -extern void increase_max_dfas PROTO((void)); +extern void increase_max_dfas PROTO ((void)); -extern void ntod PROTO((void)); /* convert a ndfa to a dfa */ +extern void ntod PROTO ((void)); /* convert a ndfa to a dfa */ /* Converts a set of ndfa states into a dfa state. */ -extern int snstods PROTO((int[], int, int[], int, int, int*)); +extern int snstods PROTO ((int[], int, int[], int, int, int *)); /* from file ecs.c */ /* Convert character classes to set of equivalence classes. */ -extern void ccl2ecl PROTO((void)); +extern void ccl2ecl PROTO ((void)); /* Associate equivalence class numbers with class members. */ -extern int cre8ecs PROTO((int[], int[], int)); +extern int cre8ecs PROTO ((int[], int[], int)); /* Update equivalence classes based on character class transitions. */ -extern void mkeccl PROTO((Char[], int, int[], int[], int, int)); +extern void mkeccl PROTO ((Char[], int, int[], int[], int, int)); /* Create equivalence class for single character. */ -extern void mkechar PROTO((int, int[], int[])); +extern void mkechar PROTO ((int, int[], int[])); /* from file gen.c */ -extern void do_indent PROTO((void)); /* indent to the current level */ +extern void do_indent PROTO ((void)); /* indent to the current level */ /* Generate the code to keep backing-up information. */ -extern void gen_backing_up PROTO((void)); +extern void gen_backing_up PROTO ((void)); /* Generate the code to perform the backing up. */ -extern void gen_bu_action PROTO((void)); +extern void gen_bu_action PROTO ((void)); /* Generate full speed compressed transition table. */ -extern void genctbl PROTO((void)); +extern void genctbl PROTO ((void)); /* Generate the code to find the action number. */ -extern void gen_find_action PROTO((void)); +extern void gen_find_action PROTO ((void)); -extern void genftbl PROTO((void)); /* generate full transition table */ +extern void genftbl PROTO ((void)); /* generate full transition table */ /* Generate the code to find the next compressed-table state. */ -extern void gen_next_compressed_state PROTO((char*)); +extern void gen_next_compressed_state PROTO ((char *)); /* Generate the code to find the next match. */ -extern void gen_next_match PROTO((void)); +extern void gen_next_match PROTO ((void)); /* Generate the code to find the next state. */ -extern void gen_next_state PROTO((int)); +extern void gen_next_state PROTO ((int)); /* Generate the code to make a NUL transition. */ -extern void gen_NUL_trans PROTO((void)); +extern void gen_NUL_trans PROTO ((void)); /* Generate the code to find the start state. */ -extern void gen_start_state PROTO((void)); +extern void gen_start_state PROTO ((void)); /* Generate data statements for the transition tables. */ -extern void gentabs PROTO((void)); +extern void gentabs PROTO ((void)); /* Write out a formatted string at the current indentation level. */ -extern void indent_put2s PROTO((const char *, const char *)); +extern void indent_put2s PROTO ((const char *, const char *)); /* Write out a string + newline at the current indentation level. */ -extern void indent_puts PROTO((const char *)); +extern void indent_puts PROTO ((const char *)); -extern void make_tables PROTO((void)); /* generate transition tables */ +extern void make_tables PROTO ((void)); /* generate transition tables */ /* from file main.c */ -extern void check_options PROTO((void)); -extern void flexend PROTO((int)); -extern void usage PROTO((void)); +extern void check_options PROTO ((void)); +extern void flexend PROTO ((int)); +extern void usage PROTO ((void)); /* from file misc.c */ /* Add a #define to the action file. */ -extern void action_define PROTO(( const char *defname, int value )); +extern void action_define PROTO ((const char *defname, int value)); /* Add the given text to the stored actions. */ -extern void add_action PROTO(( char *new_text )); +extern void add_action PROTO ((char *new_text)); /* True if a string is all lower case. */ -extern int all_lower PROTO((register char *)); +extern int all_lower PROTO ((register char *)); /* True if a string is all upper case. */ -extern int all_upper PROTO((register char *)); +extern int all_upper PROTO ((register char *)); /* Bubble sort an integer array. */ -extern void bubble PROTO((int [], int)); +extern void bubble PROTO ((int[], int)); /* Check a character to make sure it's in the expected range. */ -extern void check_char PROTO((int c)); +extern void check_char PROTO ((int c)); /* Replace upper-case letter to lower-case. */ -extern Char clower PROTO((int)); +extern Char clower PROTO ((int)); /* Returns a dynamically allocated copy of a string. */ -extern char *copy_string PROTO((register const char *)); +extern char *copy_string PROTO ((register const char *)); /* Returns a dynamically allocated copy of a (potentially) unsigned string. */ -extern Char *copy_unsigned_string PROTO((register Char *)); +extern Char *copy_unsigned_string PROTO ((register Char *)); /* Shell sort a character array. */ -extern void cshell PROTO((Char [], int, int)); +extern void cshell PROTO ((Char[], int, int)); /* Finish up a block of data declarations. */ -extern void dataend PROTO((void)); +extern void dataend PROTO ((void)); /* Flush generated data statements. */ -extern void dataflush PROTO((void)); +extern void dataflush PROTO ((void)); /* Report an error message and terminate. */ -extern void flexerror PROTO((const char *)); +extern void flexerror PROTO ((const char *)); /* Report a fatal error message and terminate. */ -extern void flexfatal PROTO((const char *)); +extern void flexfatal PROTO ((const char *)); /* Convert a hexadecimal digit string to an integer value. */ -extern int htoi PROTO((Char[])); +extern int htoi PROTO ((Char[])); /* Report an error message formatted with one integer argument. */ -extern void lerrif PROTO((const char *, int)); +extern void lerrif PROTO ((const char *, int)); /* Report an error message formatted with one string argument. */ -extern void lerrsf PROTO((const char *, const char *)); +extern void lerrsf PROTO ((const char *, const char *)); /* Spit out a "#line" statement. */ -extern void line_directive_out PROTO((FILE*, int)); +extern void line_directive_out PROTO ((FILE *, int)); /* Mark the current position in the action array as the end of the section 1 * user defs. */ -extern void mark_defs1 PROTO((void)); +extern void mark_defs1 PROTO ((void)); /* Mark the current position in the action array as the end of the prolog. */ -extern void mark_prolog PROTO((void)); +extern void mark_prolog PROTO ((void)); /* Generate a data statment for a two-dimensional array. */ -extern void mk2data PROTO((int)); +extern void mk2data PROTO ((int)); -extern void mkdata PROTO((int)); /* generate a data statement */ +extern void mkdata PROTO ((int)); /* generate a data statement */ /* Return the integer represented by a string of digits. */ -extern int myctoi PROTO((const char *)); +extern int myctoi PROTO ((const char *)); /* Return character corresponding to escape sequence. */ -extern Char myesc PROTO((Char[])); +extern Char myesc PROTO ((Char[])); /* Convert an octal digit string to an integer value. */ -extern int otoi PROTO((Char [] )); +extern int otoi PROTO ((Char[])); /* Output a (possibly-formatted) string to the generated scanner. */ -extern void out PROTO((const char *)); -extern void out_dec PROTO((const char *, int)); -extern void out_dec2 PROTO((const char *, int, int)); -extern void out_hex PROTO((const char *, unsigned int)); -extern void out_line_count PROTO((const char *)); -extern void out_str PROTO((const char *, const char *)); +extern void out PROTO ((const char *)); +extern void out_dec PROTO ((const char *, int)); +extern void out_dec2 PROTO ((const char *, int, int)); +extern void out_hex PROTO ((const char *, unsigned int)); +extern void out_line_count PROTO ((const char *)); +extern void out_str PROTO ((const char *, const char *)); extern void out_str3 - PROTO((const char *, const char *, const char *, const char *)); -extern void out_str_dec PROTO((const char *, const char *, int)); -extern void outc PROTO((int)); -extern void outn PROTO((const char *)); +PROTO ((const char *, const char *, const char *, const char *)); +extern void out_str_dec PROTO ((const char *, const char *, int)); +extern void outc PROTO ((int)); +extern void outn PROTO ((const char *)); /* Return a printable version of the given character, which might be * 8-bit. */ -extern char *readable_form PROTO((int)); +extern char *readable_form PROTO ((int)); /* Write out one section of the skeleton file. */ -extern void skelout PROTO((void)); +extern void skelout PROTO ((void)); /* Output a yy_trans_info structure. */ -extern void transition_struct_out PROTO((int, int)); +extern void transition_struct_out PROTO ((int, int)); /* Only needed when using certain broken versions of bison to build parse.c. */ -extern void *yy_flex_xmalloc PROTO(( int )); +extern void *yy_flex_xmalloc PROTO ((int)); /* Set a region of memory to 0. */ -extern void zero_out PROTO((char *, size_t)); +extern void zero_out PROTO ((char *, size_t)); /* from file nfa.c */ /* Add an accepting state to a machine. */ -extern void add_accept PROTO((int, int)); +extern void add_accept PROTO ((int, int)); /* Make a given number of copies of a singleton machine. */ -extern int copysingl PROTO((int, int)); +extern int copysingl PROTO ((int, int)); /* Debugging routine to write out an nfa. */ -extern void dumpnfa PROTO((int)); +extern void dumpnfa PROTO ((int)); /* Finish up the processing for a rule. */ -extern void finish_rule PROTO((int, int, int, int, int)); +extern void finish_rule PROTO ((int, int, int, int, int)); /* Connect two machines together. */ -extern int link_machines PROTO((int, int)); +extern int link_machines PROTO ((int, int)); /* Mark each "beginning" state in a machine as being a "normal" (i.e., * not trailing context associated) state. */ -extern void mark_beginning_as_normal PROTO((register int)); +extern void mark_beginning_as_normal PROTO ((register int)); /* Make a machine that branches to two machines. */ -extern int mkbranch PROTO((int, int)); +extern int mkbranch PROTO ((int, int)); -extern int mkclos PROTO((int)); /* convert a machine into a closure */ -extern int mkopt PROTO((int)); /* make a machine optional */ +extern int mkclos PROTO ((int)); /* convert a machine into a closure */ +extern int mkopt PROTO ((int)); /* make a machine optional */ /* Make a machine that matches either one of two machines. */ -extern int mkor PROTO((int, int)); +extern int mkor PROTO ((int, int)); /* Convert a machine into a positive closure. */ -extern int mkposcl PROTO((int)); +extern int mkposcl PROTO ((int)); -extern int mkrep PROTO((int, int, int)); /* make a replicated machine */ +extern int mkrep PROTO ((int, int, int)); /* make a replicated machine */ /* Create a state with a transition on a given symbol. */ -extern int mkstate PROTO((int)); +extern int mkstate PROTO ((int)); -extern void new_rule PROTO((void)); /* initialize for a new rule */ +extern void new_rule PROTO ((void)); /* initialize for a new rule */ /* from file parse.y */ /* Build the "<>" action for the active start conditions. */ -extern void build_eof_action PROTO((void)); +extern void build_eof_action PROTO ((void)); /* Write out a message formatted with one string, pinpointing its location. */ -extern void format_pinpoint_message PROTO((const char *, const char *)); +extern void format_pinpoint_message PROTO ((const char *, const char *)); /* Write out a message, pinpointing its location. */ -extern void pinpoint_message PROTO((const char *)); +extern void pinpoint_message PROTO ((const char *)); /* Write out a warning, pinpointing it at the given line. */ -extern void line_warning PROTO(( const char *, int )); +extern void line_warning PROTO ((const char *, int)); /* Write out a message, pinpointing it at the given line. */ -extern void line_pinpoint PROTO(( const char *, int )); +extern void line_pinpoint PROTO ((const char *, int)); /* Report a formatted syntax error. */ -extern void format_synerr PROTO((const char *, const char *)); -extern void synerr PROTO((const char *)); /* report a syntax error */ -extern void format_warn PROTO((const char *, const char *)); -extern void warn PROTO((const char *)); /* report a warning */ -extern void yyerror PROTO((const char *)); /* report a parse error */ -extern int yyparse PROTO((void)); /* the YACC parser */ +extern void format_synerr PROTO ((const char *, const char *)); +extern void synerr PROTO ((const char *)); /* report a syntax error */ +extern void format_warn PROTO ((const char *, const char *)); +extern void warn PROTO ((const char *)); /* report a warning */ +extern void yyerror PROTO ((const char *)); /* report a parse error */ +extern int yyparse PROTO ((void)); /* the YACC parser */ /* from file scan.l */ /* The Flex-generated scanner for flex. */ -extern int flexscan PROTO((void)); +extern int flexscan PROTO ((void)); /* Open the given file (if NULL, stdin) for scanning. */ -extern void set_input_file PROTO((char*)); +extern void set_input_file PROTO ((char *)); /* Wrapup a file in the lexical analyzer. */ -extern int yywrap PROTO((void)); +extern int yywrap PROTO ((void)); /* from file sym.c */ /* Save the text of a character class. */ -extern void cclinstal PROTO ((Char [], int)); +extern void cclinstal PROTO ((Char[], int)); /* Lookup the number associated with character class. */ -extern int ccllookup PROTO((Char [])); +extern int ccllookup PROTO ((Char[])); -extern void ndinstal PROTO((const char *, Char[])); /* install a name definition */ -extern Char *ndlookup PROTO((const char *)); /* lookup a name definition */ +extern void ndinstal PROTO ((const char *, Char[])); /* install a name definition */ +extern Char *ndlookup PROTO ((const char *)); /* lookup a name definition */ /* Increase maximum number of SC's. */ -extern void scextend PROTO((void)); -extern void scinstal PROTO((const char *, int)); /* make a start condition */ +extern void scextend PROTO ((void)); +extern void scinstal PROTO ((const char *, int)); /* make a start condition */ /* Lookup the number associated with a start condition. */ -extern int sclookup PROTO((const char *)); +extern int sclookup PROTO ((const char *)); /* from file tblcmp.c */ /* Build table entries for dfa state. */ -extern void bldtbl PROTO((int[], int, int, int, int)); +extern void bldtbl PROTO ((int[], int, int, int, int)); + +extern void cmptmps PROTO ((void)); /* compress template table entries */ +extern void expand_nxt_chk PROTO ((void)); /* increase nxt/chk arrays */ -extern void cmptmps PROTO((void)); /* compress template table entries */ -extern void expand_nxt_chk PROTO((void)); /* increase nxt/chk arrays */ /* Finds a space in the table for a state to be placed. */ -extern int find_table_space PROTO((int*, int)); -extern void inittbl PROTO((void)); /* initialize transition tables */ +extern int find_table_space PROTO ((int *, int)); +extern void inittbl PROTO ((void)); /* initialize transition tables */ + /* Make the default, "jam" table entries. */ -extern void mkdeftbl PROTO((void)); +extern void mkdeftbl PROTO ((void)); /* Create table entries for a state (or state fragment) which has * only one out-transition. */ -extern void mk1tbl PROTO((int, int, int, int)); +extern void mk1tbl PROTO ((int, int, int, int)); /* Place a state into full speed transition table. */ -extern void place_state PROTO((int*, int, int)); +extern void place_state PROTO ((int *, int, int)); /* Save states with only one out-transition to be processed later. */ -extern void stack1 PROTO((int, int, int, int)); +extern void stack1 PROTO ((int, int, int, int)); /* from file yylex.c */ -extern int yylex PROTO((void)); +extern int yylex PROTO ((void)); /* A growable array. See buf.c. */ struct Buf { - void * elts; /* elements. */ - int nelts; /* number of elements. */ - size_t elt_size; /* in bytes. */ - int nmax; /* max capacity of elements. */ + void *elts; /* elements. */ + int nelts; /* number of elements. */ + size_t elt_size; /* in bytes. */ + int nmax; /* max capacity of elements. */ }; -extern void buf_init PROTO((struct Buf* buf, size_t elem_size)); -extern void buf_destroy PROTO((struct Buf* buf)); -extern struct Buf* buf_append PROTO((struct Buf* buf, const void* ptr, int n_elem)); -extern struct Buf* buf_strappend PROTO((struct Buf*, const char* str)); -extern struct Buf* buf_strnappend PROTO((struct Buf*, const char* str, int nchars)); -extern struct Buf* buf_strdefine PROTO((struct Buf* buf, const char* str, const char* def)); +extern void buf_init PROTO ((struct Buf * buf, size_t elem_size)); +extern void buf_destroy PROTO ((struct Buf * buf)); +extern struct Buf *buf_append +PROTO ((struct Buf * buf, const void *ptr, int n_elem)); +extern struct Buf *buf_strappend PROTO ((struct Buf *, const char *str)); +extern struct Buf *buf_strnappend +PROTO ((struct Buf *, const char *str, int nchars)); +extern struct Buf *buf_strdefine +PROTO ((struct Buf * buf, const char *str, const char *def)); /* a string buffer for #define's generated by user-options on cmd line. */ extern struct Buf userdef_buf; @@ -1077,14 +1085,15 @@ extern struct Buf defs_buf; /* For setjmp/longjmp (instead of calling exit(2)). Linkage in main.c */ extern jmp_buf flex_main_jmp_buf; + #define FLEX_EXIT(status) longjmp(flex_main_jmp_buf,(status)+1) /* Removes all \n and \r chars from tail of str. returns str. */ -extern char* chomp(char* str); +extern char *chomp (char *str); /* Tables serialization API declarations. */ #include "tables_shared.h" -struct yytbl_data * yytbl_data_create (enum yytbl_id id); +struct yytbl_data *yytbl_data_create (enum yytbl_id id); struct yytbl_data *mkftbl (void); diff --git a/gen.c b/gen.c index 01de24f..a79dc08 100644 --- a/gen.c +++ b/gen.c @@ -36,13 +36,13 @@ /* declare functions that have forward references */ -void gen_next_state PROTO((int)); -void genecs PROTO((void)); -void indent_put2s PROTO((const char *, const char *)); -void indent_puts PROTO((const char *)); +void gen_next_state PROTO ((int)); +void genecs PROTO ((void)); +void indent_put2s PROTO ((const char *, const char *)); +void indent_puts PROTO ((const char *)); -static int indent_level = 0; /* each level is 8 spaces */ +static int indent_level = 0; /* each level is 8 spaces */ #define indent_up() (++indent_level) #define indent_down() (--indent_level) @@ -53,114 +53,121 @@ static int indent_level = 0; /* each level is 8 spaces */ * to this is that the fast table representation generally uses the * 0 elements of its arrays, too.) */ -static const char *C_int_decl = "static yyconst int %s[%d] =\n { 0,\n"; -static const char *C_short_decl = "static yyconst short int %s[%d] =\n { 0,\n"; -static const char *C_long_decl = "static yyconst long int %s[%d] =\n { 0,\n"; +static const char *C_int_decl = + + "static yyconst int %s[%d] =\n { 0,\n"; +static const char *C_short_decl = + + "static yyconst short int %s[%d] =\n { 0,\n"; +static const char *C_long_decl = + + "static yyconst long int %s[%d] =\n { 0,\n"; static const char *C_state_decl = + "static yyconst yy_state_type %s[%d] =\n { 0,\n"; /* Indent to the current level. */ -void do_indent() - { +void do_indent () +{ register int i = indent_level * 8; - while ( i >= 8 ) - { - outc( '\t' ); + while (i >= 8) { + outc ('\t'); i -= 8; - } + } - while ( i > 0 ) - { - outc( ' ' ); + while (i > 0) { + outc (' '); --i; - } } +} /* Generate the table for possible eol matches. */ -static void geneoltbl() +static void geneoltbl () { - int i; + int i; - outn("#ifdef YY_USE_LINENO" ); - outn( "/* Table of booleans, true if rule could match eol. */" ); - out_dec("static const int yy_rule_can_match_eol[%d] =\n {\n ", - num_rules + 1); + outn ("#ifdef YY_USE_LINENO"); + outn ("/* Table of booleans, true if rule could match eol. */"); + out_dec + ("static const int yy_rule_can_match_eol[%d] =\n {\n ", + num_rules + 1); - for (i = 0; i < num_rules; i++){ - out_dec("%d, ", rule_has_nl[i]?1:0); + for (i = 0; i < num_rules; i++) { + out_dec ("%d, ", rule_has_nl[i] ? 1 : 0); /* format nicely, 20 numbers per line. */ - if ((i%20) == 19) - out("\n "); + if ((i % 20) == 19) + out ("\n "); } - out_dec("%d\n };\n", rule_has_nl[i]?1:0); - outn( "#endif" ); + out_dec ("%d\n };\n", rule_has_nl[i] ? 1 : 0); + outn ("#endif"); } /* Generate the code to keep backing-up information. */ -void gen_backing_up() - { - if ( reject || num_backing_up == 0 ) +void gen_backing_up () +{ + if (reject || num_backing_up == 0) return; - if ( fullspd ) - indent_puts( "if ( yy_current_state[-1].yy_nxt )" ); + if (fullspd) + indent_puts ("if ( yy_current_state[-1].yy_nxt )"); else - indent_puts( "if ( yy_accept[yy_current_state] )" ); - - indent_up(); - indent_puts( "{" ); - indent_puts( "YY_G(yy_last_accepting_state) = yy_current_state;" ); - indent_puts( "YY_G(yy_last_accepting_cpos) = yy_cp;" ); - indent_puts( "}" ); - indent_down(); - } + indent_puts ("if ( yy_accept[yy_current_state] )"); + + indent_up (); + indent_puts ("{"); + indent_puts ("YY_G(yy_last_accepting_state) = yy_current_state;"); + indent_puts ("YY_G(yy_last_accepting_cpos) = yy_cp;"); + indent_puts ("}"); + indent_down (); +} /* Generate the code to perform the backing up. */ -void gen_bu_action() - { - if ( reject || num_backing_up == 0 ) +void gen_bu_action () +{ + if (reject || num_backing_up == 0) return; - set_indent( 3 ); + set_indent (3); - indent_puts( "case 0: /* must back up */" ); - indent_puts( "/* undo the effects of YY_DO_BEFORE_ACTION */" ); - indent_puts( "*yy_cp = YY_G(yy_hold_char);" ); + indent_puts ("case 0: /* must back up */"); + indent_puts ("/* undo the effects of YY_DO_BEFORE_ACTION */"); + indent_puts ("*yy_cp = YY_G(yy_hold_char);"); - if ( fullspd || fulltbl ) - indent_puts( "yy_cp = YY_G(yy_last_accepting_cpos) + 1;" ); + if (fullspd || fulltbl) + indent_puts ("yy_cp = YY_G(yy_last_accepting_cpos) + 1;"); else /* Backing-up info for compressed tables is taken \after/ * yy_cp has been incremented for the next state. */ - indent_puts( "yy_cp = YY_G(yy_last_accepting_cpos);" ); + indent_puts ("yy_cp = YY_G(yy_last_accepting_cpos);"); - indent_puts( "yy_current_state = YY_G(yy_last_accepting_state);" ); - indent_puts( "goto yy_find_action;" ); - outc( '\n' ); + indent_puts ("yy_current_state = YY_G(yy_last_accepting_state);"); + indent_puts ("goto yy_find_action;"); + outc ('\n'); - set_indent( 0 ); - } + set_indent (0); +} /* genctbl - generates full speed compressed transition table */ -void genctbl() - { +void genctbl () +{ register int i; - int end_of_buffer_action = num_rules + 1; + int end_of_buffer_action = num_rules + 1; /* Table of verify for transition and offset to next state. */ - out_dec( "static yyconst struct yy_trans_info yy_transition[%d] =\n", - tblend + numecs + 1 ); - outn( " {" ); + out_dec + ("static yyconst struct yy_trans_info yy_transition[%d] =\n", + tblend + numecs + 1); + outn (" {"); /* We want the transition to be represented as the offset to the * next state, not the actual state number, which is what it currently @@ -180,16 +187,16 @@ void genctbl() * there's room for jam entries for other characters. */ - while ( tblend + 2 >= current_max_xpairs ) - expand_nxt_chk(); + while (tblend + 2 >= current_max_xpairs) + expand_nxt_chk (); - while ( lastdfa + 1 >= current_max_dfas ) - increase_max_dfas(); + while (lastdfa + 1 >= current_max_dfas) + increase_max_dfas (); base[lastdfa + 1] = tblend + 2; nxt[tblend + 1] = end_of_buffer_action; chk[tblend + 1] = numecs + 1; - chk[tblend + 2] = 1; /* anything but EOB */ + chk[tblend + 2] = 1; /* anything but EOB */ /* So that "make test" won't show arb. differences. */ nxt[tblend + 2] = 0; @@ -197,53 +204,52 @@ void genctbl() /* Make sure every state has an end-of-buffer transition and an * action #. */ - for ( i = 0; i <= lastdfa; ++i ) - { - int anum = dfaacc[i].dfaacc_state; - int offset = base[i]; + for (i = 0; i <= lastdfa; ++i) { + int anum = dfaacc[i].dfaacc_state; + int offset = base[i]; chk[offset] = EOB_POSITION; chk[offset - 1] = ACTION_POSITION; nxt[offset - 1] = anum; /* action number */ - } + } - for ( i = 0; i <= tblend; ++i ) - { - if ( chk[i] == EOB_POSITION ) - transition_struct_out( 0, base[lastdfa + 1] - i ); + for (i = 0; i <= tblend; ++i) { + if (chk[i] == EOB_POSITION) + transition_struct_out (0, base[lastdfa + 1] - i); - else if ( chk[i] == ACTION_POSITION ) - transition_struct_out( 0, nxt[i] ); + else if (chk[i] == ACTION_POSITION) + transition_struct_out (0, nxt[i]); - else if ( chk[i] > numecs || chk[i] == 0 ) - transition_struct_out( 0, 0 ); /* unused slot */ + else if (chk[i] > numecs || chk[i] == 0) + transition_struct_out (0, 0); /* unused slot */ - else /* verify, transition */ - transition_struct_out( chk[i], - base[nxt[i]] - (i - chk[i]) ); - } + else /* verify, transition */ + transition_struct_out (chk[i], + base[nxt[i]] - (i - + chk[i])); + } /* Here's the final, end-of-buffer state. */ - transition_struct_out( chk[tblend + 1], nxt[tblend + 1] ); - transition_struct_out( chk[tblend + 2], nxt[tblend + 2] ); + transition_struct_out (chk[tblend + 1], nxt[tblend + 1]); + transition_struct_out (chk[tblend + 2], nxt[tblend + 2]); - outn( " };\n" ); + outn (" };\n"); /* Table of pointers to start states. */ - out_dec( - "static yyconst struct yy_trans_info *yy_start_state_list[%d] =\n", - lastsc * 2 + 1 ); - outn( " {" ); + out_dec + ("static yyconst struct yy_trans_info *yy_start_state_list[%d] =\n", + lastsc * 2 + 1); + outn (" {"); - for ( i = 0; i <= lastsc * 2; ++i ) - out_dec( " &yy_transition[%d],\n", base[i] ); + for (i = 0; i <= lastsc * 2; ++i) + out_dec (" &yy_transition[%d],\n", base[i]); - dataend(); + dataend (); - if ( useecs ) - genecs(); - } + if (useecs) + genecs (); +} /* mkecstbl - Make equivalence-class tables. */ @@ -260,7 +266,8 @@ struct yytbl_data *mkecstbl (void) tbl->t_hilen = 0; tbl->t_lolen = csize; - tbl->t_data = tdata = (int32_t *) calloc (tbl->t_lolen, sizeof (int32_t)); + tbl->t_data = tdata = + (int32_t *) calloc (tbl->t_lolen, sizeof (int32_t)); for (i = 1; i < csize; ++i) { if (caseins && isupper (i)) @@ -277,7 +284,8 @@ struct yytbl_data *mkecstbl (void) for (j = 0; j < numrows; ++j) { for (i = j; i < csize; i = i + numrows) { - fprintf (stderr, "%4s = %-2d", readable_form (i), ecgroup[i]); + fprintf (stderr, "%4s = %-2d", + readable_form (i), ecgroup[i]); putc (' ', stderr); } @@ -291,183 +299,180 @@ struct yytbl_data *mkecstbl (void) /* Generate equivalence-class tables. */ -void genecs() - { +void genecs () +{ register int i, j; - int numrows; + int numrows; - out_str_dec( C_int_decl, "yy_ec", csize ); + out_str_dec (C_int_decl, "yy_ec", csize); - for ( i = 1; i < csize; ++i ) - { - if ( caseins && (i >= 'A') && (i <= 'Z') ) - ecgroup[i] = ecgroup[clower( i )]; + for (i = 1; i < csize; ++i) { + if (caseins && (i >= 'A') && (i <= 'Z')) + ecgroup[i] = ecgroup[clower (i)]; - ecgroup[i] = ABS( ecgroup[i] ); - mkdata( ecgroup[i] ); - } + ecgroup[i] = ABS (ecgroup[i]); + mkdata (ecgroup[i]); + } - dataend(); + dataend (); - if ( trace ) - { - fputs( _( "\n\nEquivalence Classes:\n\n" ), stderr ); + if (trace) { + fputs (_("\n\nEquivalence Classes:\n\n"), stderr); numrows = csize / 8; - for ( j = 0; j < numrows; ++j ) - { - for ( i = j; i < csize; i = i + numrows ) - { - fprintf( stderr, "%4s = %-2d", - readable_form( i ), ecgroup[i] ); - - putc( ' ', stderr ); - } + for (j = 0; j < numrows; ++j) { + for (i = j; i < csize; i = i + numrows) { + fprintf (stderr, "%4s = %-2d", + readable_form (i), ecgroup[i]); - putc( '\n', stderr ); + putc (' ', stderr); } + + putc ('\n', stderr); } } +} /* Generate the code to find the action number. */ -void gen_find_action() - { - if ( fullspd ) - indent_puts( "yy_act = yy_current_state[-1].yy_nxt;" ); - - else if ( fulltbl ) - indent_puts( "yy_act = yy_accept[yy_current_state];" ); - - else if ( reject ) - { - indent_puts( "yy_current_state = *--YY_G(yy_state_ptr);" ); - indent_puts( "YY_G(yy_lp) = yy_accept[yy_current_state];" ); - - outn( - "find_rule: /* we branch to this label when backing up */" ); - - indent_puts( - "for ( ; ; ) /* until we find what rule we matched */" ); - - indent_up(); - - indent_puts( "{" ); - - indent_puts( - "if ( YY_G(yy_lp) && YY_G(yy_lp) < yy_accept[yy_current_state + 1] )" ); - indent_up(); - indent_puts( "{" ); - indent_puts( "yy_act = yy_acclist[YY_G(yy_lp)];" ); - - if ( variable_trailing_context_rules ) - { - indent_puts( "if ( yy_act & YY_TRAILING_HEAD_MASK ||" ); - indent_puts( " yy_looking_for_trail_begin )" ); - indent_up(); - indent_puts( "{" ); - - indent_puts( - "if ( yy_act == yy_looking_for_trail_begin )" ); - indent_up(); - indent_puts( "{" ); - indent_puts( "yy_looking_for_trail_begin = 0;" ); - indent_puts( "yy_act &= ~YY_TRAILING_HEAD_MASK;" ); - indent_puts( "break;" ); - indent_puts( "}" ); - indent_down(); - - indent_puts( "}" ); - indent_down(); - - indent_puts( "else if ( yy_act & YY_TRAILING_MASK )" ); - indent_up(); - indent_puts( "{" ); - indent_puts( - "yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;" ); - indent_puts( - "yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;" ); - - if ( real_reject ) - { +void gen_find_action () +{ + if (fullspd) + indent_puts ("yy_act = yy_current_state[-1].yy_nxt;"); + + else if (fulltbl) + indent_puts ("yy_act = yy_accept[yy_current_state];"); + + else if (reject) { + indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);"); + indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];"); + + outn + ("find_rule: /* we branch to this label when backing up */"); + + indent_puts + ("for ( ; ; ) /* until we find what rule we matched */"); + + indent_up (); + + indent_puts ("{"); + + indent_puts + ("if ( YY_G(yy_lp) && YY_G(yy_lp) < yy_accept[yy_current_state + 1] )"); + indent_up (); + indent_puts ("{"); + indent_puts ("yy_act = yy_acclist[YY_G(yy_lp)];"); + + if (variable_trailing_context_rules) { + indent_puts + ("if ( yy_act & YY_TRAILING_HEAD_MASK ||"); + indent_puts (" yy_looking_for_trail_begin )"); + indent_up (); + indent_puts ("{"); + + indent_puts + ("if ( yy_act == yy_looking_for_trail_begin )"); + indent_up (); + indent_puts ("{"); + indent_puts ("yy_looking_for_trail_begin = 0;"); + indent_puts ("yy_act &= ~YY_TRAILING_HEAD_MASK;"); + indent_puts ("break;"); + indent_puts ("}"); + indent_down (); + + indent_puts ("}"); + indent_down (); + + indent_puts + ("else if ( yy_act & YY_TRAILING_MASK )"); + indent_up (); + indent_puts ("{"); + indent_puts + ("yy_looking_for_trail_begin = yy_act & ~YY_TRAILING_MASK;"); + indent_puts + ("yy_looking_for_trail_begin |= YY_TRAILING_HEAD_MASK;"); + + if (real_reject) { /* Remember matched text in case we back up * due to REJECT. */ - indent_puts( "YY_G(yy_full_match) = yy_cp;" ); - indent_puts( "yy_full_state = YY_G(yy_state_ptr);" ); - indent_puts( "yy_full_lp = YY_G(yy_lp);" ); - } - - indent_puts( "}" ); - indent_down(); - - indent_puts( "else" ); - indent_up(); - indent_puts( "{" ); - indent_puts( "YY_G(yy_full_match) = yy_cp;" ); - indent_puts( "yy_full_state = YY_G(yy_state_ptr);" ); - indent_puts( "yy_full_lp = YY_G(yy_lp);" ); - indent_puts( "break;" ); - indent_puts( "}" ); - indent_down(); - - indent_puts( "++YY_G(yy_lp);" ); - indent_puts( "goto find_rule;" ); + indent_puts + ("YY_G(yy_full_match) = yy_cp;"); + indent_puts + ("yy_full_state = YY_G(yy_state_ptr);"); + indent_puts ("yy_full_lp = YY_G(yy_lp);"); } - else - { + indent_puts ("}"); + indent_down (); + + indent_puts ("else"); + indent_up (); + indent_puts ("{"); + indent_puts ("YY_G(yy_full_match) = yy_cp;"); + indent_puts + ("yy_full_state = YY_G(yy_state_ptr);"); + indent_puts ("yy_full_lp = YY_G(yy_lp);"); + indent_puts ("break;"); + indent_puts ("}"); + indent_down (); + + indent_puts ("++YY_G(yy_lp);"); + indent_puts ("goto find_rule;"); + } + + else { /* Remember matched text in case we back up due to * trailing context plus REJECT. */ - indent_up(); - indent_puts( "{" ); - indent_puts( "YY_G(yy_full_match) = yy_cp;" ); - indent_puts( "break;" ); - indent_puts( "}" ); - indent_down(); - } + indent_up (); + indent_puts ("{"); + indent_puts ("YY_G(yy_full_match) = yy_cp;"); + indent_puts ("break;"); + indent_puts ("}"); + indent_down (); + } - indent_puts( "}" ); - indent_down(); + indent_puts ("}"); + indent_down (); - indent_puts( "--yy_cp;" ); + indent_puts ("--yy_cp;"); /* We could consolidate the following two lines with those at * the beginning, but at the cost of complaints that we're * branching inside a loop. */ - indent_puts( "yy_current_state = *--YY_G(yy_state_ptr);" ); - indent_puts( "YY_G(yy_lp) = yy_accept[yy_current_state];" ); + indent_puts ("yy_current_state = *--YY_G(yy_state_ptr);"); + indent_puts ("YY_G(yy_lp) = yy_accept[yy_current_state];"); - indent_puts( "}" ); + indent_puts ("}"); - indent_down(); - } + indent_down (); + } - else - { /* compressed */ - indent_puts( "yy_act = yy_accept[yy_current_state];" ); + else { /* compressed */ + indent_puts ("yy_act = yy_accept[yy_current_state];"); - if ( interactive && ! reject ) - { + if (interactive && !reject) { /* Do the guaranteed-needed backing up to figure out * the match. */ - indent_puts( "if ( yy_act == 0 )" ); - indent_up(); - indent_puts( "{ /* have to back up */" ); - indent_puts( "yy_cp = YY_G(yy_last_accepting_cpos);" ); - indent_puts( - "yy_current_state = YY_G(yy_last_accepting_state);" ); - indent_puts( "yy_act = yy_accept[yy_current_state];" ); - indent_puts( "}" ); - indent_down(); - } + indent_puts ("if ( yy_act == 0 )"); + indent_up (); + indent_puts ("{ /* have to back up */"); + indent_puts + ("yy_cp = YY_G(yy_last_accepting_cpos);"); + indent_puts + ("yy_current_state = YY_G(yy_last_accepting_state);"); + indent_puts + ("yy_act = yy_accept[yy_current_state];"); + indent_puts ("}"); + indent_down (); } } +} /* mkftbl - make the full table and return the struct */ @@ -475,15 +480,16 @@ struct yytbl_data *mkftbl (void) { register int i; int end_of_buffer_action = num_rules + 1; - struct yytbl_data *tbl; + struct yytbl_data *tbl; int32_t *tdata = 0; tbl = yytbl_data_create (YYT_ID_ACCEPT); tbl->t_flags |= YYT_DATA32; - tbl->t_hilen = 0; /* it's a one-dimensional array */ + tbl->t_hilen = 0; /* it's a one-dimensional array */ tbl->t_lolen = lastdfa + 1; - tbl->t_data = tdata = (int32_t *) calloc (tbl->t_lolen, sizeof(int32_t)); + tbl->t_data = tdata = + (int32_t *) calloc (tbl->t_lolen, sizeof (int32_t)); dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action; @@ -493,7 +499,8 @@ struct yytbl_data *mkftbl (void) tdata[i] = anum; if (trace && anum) - fprintf (stderr, _("state # %d accepts: [%d]\n"), i, anum); + fprintf (stderr, _("state # %d accepts: [%d]\n"), + i, anum); } return tbl; @@ -502,59 +509,57 @@ struct yytbl_data *mkftbl (void) /* genftbl - generate full transition table */ -void genftbl() - { +void genftbl () +{ register int i; - int end_of_buffer_action = num_rules + 1; + int end_of_buffer_action = num_rules + 1; - out_str_dec( long_align ? C_long_decl : C_short_decl, - "yy_accept", lastdfa + 1 ); + out_str_dec (long_align ? C_long_decl : C_short_decl, + "yy_accept", lastdfa + 1); dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action; - for ( i = 1; i <= lastdfa; ++i ) - { + for (i = 1; i <= lastdfa; ++i) { register int anum = dfaacc[i].dfaacc_state; - mkdata( anum ); + mkdata (anum); - if ( trace && anum ) - fprintf( stderr, _( "state # %d accepts: [%d]\n" ), - i, anum ); - } + if (trace && anum) + fprintf (stderr, _("state # %d accepts: [%d]\n"), + i, anum); + } - dataend(); + dataend (); - if ( useecs ) - genecs(); + if (useecs) + genecs (); /* Don't have to dump the actual full table entries - they were * created on-the-fly. */ - } +} /* Generate the code to find the next compressed-table state. */ -void gen_next_compressed_state( char_map ) -char *char_map; - { - indent_put2s( "register YY_CHAR yy_c = %s;", char_map ); +void gen_next_compressed_state (char_map) + char *char_map; +{ + indent_put2s ("register YY_CHAR yy_c = %s;", char_map); /* Save the backing-up info \before/ computing the next state * because we always compute one more state than needed - we * always proceed until we reach a jam state */ - gen_backing_up(); + gen_backing_up (); - indent_puts( -"while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )" ); - indent_up(); - indent_puts( "{" ); - indent_puts( "yy_current_state = (int) yy_def[yy_current_state];" ); + indent_puts + ("while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )"); + indent_up (); + indent_puts ("{"); + indent_puts ("yy_current_state = (int) yy_def[yy_current_state];"); - if ( usemecs ) - { + if (usemecs) { /* We've arrange it so that templates are never chained * to one another. This means we can afford to make a * very simple test to see if we need to convert to @@ -562,329 +567,319 @@ char *char_map; * about erroneously looking up the meta-equivalence * class twice */ - do_indent(); + do_indent (); /* lastdfa + 2 is the beginning of the templates */ - out_dec( "if ( yy_current_state >= %d )\n", lastdfa + 2 ); + out_dec ("if ( yy_current_state >= %d )\n", lastdfa + 2); - indent_up(); - indent_puts( "yy_c = yy_meta[(unsigned int) yy_c];" ); - indent_down(); - } + indent_up (); + indent_puts ("yy_c = yy_meta[(unsigned int) yy_c];"); + indent_down (); + } - indent_puts( "}" ); - indent_down(); + indent_puts ("}"); + indent_down (); - indent_puts( -"yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];" ); - } + indent_puts + ("yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];"); +} /* Generate the code to find the next match. */ -void gen_next_match() - { +void gen_next_match () +{ /* NOTE - changes in here should be reflected in gen_next_state() and * gen_NUL_trans(). */ - char *char_map = useecs ? - "yy_ec[YY_SC_TO_UI(*yy_cp)]" : - "YY_SC_TO_UI(*yy_cp)"; - - char *char_map_2 = useecs ? - "yy_ec[YY_SC_TO_UI(*++yy_cp)]" : - "YY_SC_TO_UI(*++yy_cp)"; - - if ( fulltbl ) - { - indent_put2s( - "while ( (yy_current_state = yy_nxt[yy_current_state][%s]) > 0 )", - char_map ); - - indent_up(); - - if ( num_backing_up > 0 ) - { - indent_puts( "{" ); - gen_backing_up(); - outc( '\n' ); - } + char *char_map = useecs ? + + "yy_ec[YY_SC_TO_UI(*yy_cp)]" : "YY_SC_TO_UI(*yy_cp)"; - indent_puts( "++yy_cp;" ); + char *char_map_2 = useecs ? - if ( num_backing_up > 0 ) + "yy_ec[YY_SC_TO_UI(*++yy_cp)]" : "YY_SC_TO_UI(*++yy_cp)"; - indent_puts( "}" ); + if (fulltbl) { + indent_put2s + ("while ( (yy_current_state = yy_nxt[yy_current_state][%s]) > 0 )", + char_map); - indent_down(); + indent_up (); - outc( '\n' ); - indent_puts( "yy_current_state = -yy_current_state;" ); + if (num_backing_up > 0) { + indent_puts ("{"); + gen_backing_up (); + outc ('\n'); } - else if ( fullspd ) - { - indent_puts( "{" ); - indent_puts( - "register yyconst struct yy_trans_info *yy_trans_info;\n" ); - indent_puts( "register YY_CHAR yy_c;\n" ); - indent_put2s( "for ( yy_c = %s;", char_map ); - indent_puts( - " (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->" ); - indent_puts( "yy_verify == yy_c;" ); - indent_put2s( " yy_c = %s )", char_map_2 ); - - indent_up(); - - if ( num_backing_up > 0 ) - indent_puts( "{" ); - - indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" ); - - if ( num_backing_up > 0 ) - { - outc( '\n' ); - gen_backing_up(); - indent_puts( "}" ); - } + indent_puts ("++yy_cp;"); + + if (num_backing_up > 0) - indent_down(); - indent_puts( "}" ); + indent_puts ("}"); + + indent_down (); + + outc ('\n'); + indent_puts ("yy_current_state = -yy_current_state;"); + } + + else if (fullspd) { + indent_puts ("{"); + indent_puts + ("register yyconst struct yy_trans_info *yy_trans_info;\n"); + indent_puts ("register YY_CHAR yy_c;\n"); + indent_put2s ("for ( yy_c = %s;", char_map); + indent_puts + (" (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->"); + indent_puts ("yy_verify == yy_c;"); + indent_put2s (" yy_c = %s )", char_map_2); + + indent_up (); + + if (num_backing_up > 0) + indent_puts ("{"); + + indent_puts ("yy_current_state += yy_trans_info->yy_nxt;"); + + if (num_backing_up > 0) { + outc ('\n'); + gen_backing_up (); + indent_puts ("}"); } - else - { /* compressed */ - indent_puts( "do" ); + indent_down (); + indent_puts ("}"); + } - indent_up(); - indent_puts( "{" ); + else { /* compressed */ + indent_puts ("do"); - gen_next_state( false ); + indent_up (); + indent_puts ("{"); - indent_puts( "++yy_cp;" ); + gen_next_state (false); + indent_puts ("++yy_cp;"); - indent_puts( "}" ); - indent_down(); - do_indent(); + indent_puts ("}"); + indent_down (); - if ( interactive ) - out_dec( "while ( yy_base[yy_current_state] != %d );\n", - jambase ); + do_indent (); + + if (interactive) + out_dec + ("while ( yy_base[yy_current_state] != %d );\n", + jambase); else - out_dec( "while ( yy_current_state != %d );\n", - jamstate ); + out_dec ("while ( yy_current_state != %d );\n", + jamstate); - if ( ! reject && ! interactive ) - { + if (!reject && !interactive) { /* Do the guaranteed-needed backing up to figure out * the match. */ - indent_puts( "yy_cp = YY_G(yy_last_accepting_cpos);" ); - indent_puts( - "yy_current_state = YY_G(yy_last_accepting_state);" ); - } + indent_puts + ("yy_cp = YY_G(yy_last_accepting_cpos);"); + indent_puts + ("yy_current_state = YY_G(yy_last_accepting_state);"); } } +} /* Generate the code to find the next state. */ -void gen_next_state( worry_about_NULs ) -int worry_about_NULs; - { /* NOTE - changes in here should be reflected in gen_next_match() */ - char char_map[256]; - - if ( worry_about_NULs && ! nultrans ) - { - if ( useecs ) - (void) sprintf( char_map, - "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)", - NUL_ec ); +void gen_next_state (worry_about_NULs) + int worry_about_NULs; +{ /* NOTE - changes in here should be reflected in gen_next_match() */ + char char_map[256]; + + if (worry_about_NULs && !nultrans) { + if (useecs) + (void) sprintf (char_map, + "(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : %d)", + NUL_ec); else - (void) sprintf( char_map, - "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)", NUL_ec ); - } + (void) sprintf (char_map, + "(*yy_cp ? YY_SC_TO_UI(*yy_cp) : %d)", + NUL_ec); + } else - strcpy( char_map, useecs ? - "yy_ec[YY_SC_TO_UI(*yy_cp)]" : "YY_SC_TO_UI(*yy_cp)" ); + strcpy (char_map, useecs ? + "yy_ec[YY_SC_TO_UI(*yy_cp)]" : + "YY_SC_TO_UI(*yy_cp)"); - if ( worry_about_NULs && nultrans ) - { - if ( ! fulltbl && ! fullspd ) + if (worry_about_NULs && nultrans) { + if (!fulltbl && !fullspd) /* Compressed tables back up *before* they match. */ - gen_backing_up(); + gen_backing_up (); - indent_puts( "if ( *yy_cp )" ); - indent_up(); - indent_puts( "{" ); - } + indent_puts ("if ( *yy_cp )"); + indent_up (); + indent_puts ("{"); + } - if ( fulltbl ) - indent_put2s( - "yy_current_state = yy_nxt[yy_current_state][%s];", - char_map ); + if (fulltbl) + indent_put2s + ("yy_current_state = yy_nxt[yy_current_state][%s];", + char_map); - else if ( fullspd ) - indent_put2s( - "yy_current_state += yy_current_state[%s].yy_nxt;", - char_map ); + else if (fullspd) + indent_put2s + ("yy_current_state += yy_current_state[%s].yy_nxt;", + char_map); else - gen_next_compressed_state( char_map ); - - if ( worry_about_NULs && nultrans ) - { - - indent_puts( "}" ); - indent_down(); - indent_puts( "else" ); - indent_up(); - indent_puts( - "yy_current_state = yy_NUL_trans[yy_current_state];" ); - indent_down(); - } + gen_next_compressed_state (char_map); - if ( fullspd || fulltbl ) - gen_backing_up(); + if (worry_about_NULs && nultrans) { - if ( reject ) - indent_puts( "*YY_G(yy_state_ptr)++ = yy_current_state;" ); + indent_puts ("}"); + indent_down (); + indent_puts ("else"); + indent_up (); + indent_puts + ("yy_current_state = yy_NUL_trans[yy_current_state];"); + indent_down (); } + if (fullspd || fulltbl) + gen_backing_up (); + + if (reject) + indent_puts ("*YY_G(yy_state_ptr)++ = yy_current_state;"); +} + /* Generate the code to make a NUL transition. */ -void gen_NUL_trans() - { /* NOTE - changes in here should be reflected in gen_next_match() */ +void gen_NUL_trans () +{ /* NOTE - changes in here should be reflected in gen_next_match() */ /* Only generate a definition for "yy_cp" if we'll generate code * that uses it. Otherwise lint and the like complain. */ - int need_backing_up = (num_backing_up > 0 && ! reject); + int need_backing_up = (num_backing_up > 0 && !reject); - if ( need_backing_up && (! nultrans || fullspd || fulltbl) ) + if (need_backing_up && (!nultrans || fullspd || fulltbl)) /* We're going to need yy_cp lying around for the call * below to gen_backing_up(). */ - indent_puts( "register char *yy_cp = YY_G(yy_c_buf_p);" ); + indent_puts ("register char *yy_cp = YY_G(yy_c_buf_p);"); - outc( '\n' ); + outc ('\n'); - if ( nultrans ) - { - indent_puts( - "yy_current_state = yy_NUL_trans[yy_current_state];" ); - indent_puts( "yy_is_jam = (yy_current_state == 0);" ); - } + if (nultrans) { + indent_puts + ("yy_current_state = yy_NUL_trans[yy_current_state];"); + indent_puts ("yy_is_jam = (yy_current_state == 0);"); + } - else if ( fulltbl ) - { - do_indent(); - out_dec( "yy_current_state = yy_nxt[yy_current_state][%d];\n", - NUL_ec ); - indent_puts( "yy_is_jam = (yy_current_state <= 0);" ); - } + else if (fulltbl) { + do_indent (); + out_dec + ("yy_current_state = yy_nxt[yy_current_state][%d];\n", + NUL_ec); + indent_puts ("yy_is_jam = (yy_current_state <= 0);"); + } - else if ( fullspd ) - { - do_indent(); - out_dec( "register int yy_c = %d;\n", NUL_ec ); + else if (fullspd) { + do_indent (); + out_dec ("register int yy_c = %d;\n", NUL_ec); - indent_puts( - "register yyconst struct yy_trans_info *yy_trans_info;\n" ); - indent_puts( - "yy_trans_info = &yy_current_state[(unsigned int) yy_c];" ); - indent_puts( "yy_current_state += yy_trans_info->yy_nxt;" ); + indent_puts + ("register yyconst struct yy_trans_info *yy_trans_info;\n"); + indent_puts + ("yy_trans_info = &yy_current_state[(unsigned int) yy_c];"); + indent_puts ("yy_current_state += yy_trans_info->yy_nxt;"); - indent_puts( - "yy_is_jam = (yy_trans_info->yy_verify != yy_c);" ); - } + indent_puts + ("yy_is_jam = (yy_trans_info->yy_verify != yy_c);"); + } - else - { - char NUL_ec_str[20]; + else { + char NUL_ec_str[20]; - (void) sprintf( NUL_ec_str, "%d", NUL_ec ); - gen_next_compressed_state( NUL_ec_str ); + (void) sprintf (NUL_ec_str, "%d", NUL_ec); + gen_next_compressed_state (NUL_ec_str); - do_indent(); - out_dec( "yy_is_jam = (yy_current_state == %d);\n", jamstate ); + do_indent (); + out_dec ("yy_is_jam = (yy_current_state == %d);\n", + jamstate); - if ( reject ) - { + if (reject) { /* Only stack this state if it's a transition we * actually make. If we stack it on a jam, then * the state stack and yy_c_buf_p get out of sync. */ - indent_puts( "if ( ! yy_is_jam )" ); - indent_up(); - indent_puts( "*YY_G(yy_state_ptr)++ = yy_current_state;" ); - indent_down(); - } + indent_puts ("if ( ! yy_is_jam )"); + indent_up (); + indent_puts + ("*YY_G(yy_state_ptr)++ = yy_current_state;"); + indent_down (); } + } /* If we've entered an accepting state, back up; note that * compressed tables have *already* done such backing up, so * we needn't bother with it again. */ - if ( need_backing_up && (fullspd || fulltbl) ) - { - outc( '\n' ); - indent_puts( "if ( ! yy_is_jam )" ); - indent_up(); - indent_puts( "{" ); - gen_backing_up(); - indent_puts( "}" ); - indent_down(); - } + if (need_backing_up && (fullspd || fulltbl)) { + outc ('\n'); + indent_puts ("if ( ! yy_is_jam )"); + indent_up (); + indent_puts ("{"); + gen_backing_up (); + indent_puts ("}"); + indent_down (); } +} /* Generate the code to find the start state. */ -void gen_start_state() - { - if ( fullspd ) - { - if ( bol_needed ) - { - indent_puts( - "yy_current_state = yy_start_state_list[YY_G(yy_start) + YY_AT_BOL()];" ); - } - else - indent_puts( - "yy_current_state = yy_start_state_list[YY_G(yy_start)];" ); +void gen_start_state () +{ + if (fullspd) { + if (bol_needed) { + indent_puts + ("yy_current_state = yy_start_state_list[YY_G(yy_start) + YY_AT_BOL()];"); } + else + indent_puts + ("yy_current_state = yy_start_state_list[YY_G(yy_start)];"); + } - else - { - indent_puts( "yy_current_state = YY_G(yy_start);" ); + else { + indent_puts ("yy_current_state = YY_G(yy_start);"); - if ( bol_needed ) - indent_puts( "yy_current_state += YY_AT_BOL();" ); + if (bol_needed) + indent_puts ("yy_current_state += YY_AT_BOL();"); - if ( reject ) - { + if (reject) { /* Set up for storing up states. */ - outn("#ifdef YY_USES_REJECT"); - indent_puts( "YY_G(yy_state_ptr) = YY_G(yy_state_buf);" ); - indent_puts( "*YY_G(yy_state_ptr)++ = yy_current_state;" ); - outn("#endif"); - } + outn ("#ifdef YY_USES_REJECT"); + indent_puts + ("YY_G(yy_state_ptr) = YY_G(yy_state_buf);"); + indent_puts + ("*YY_G(yy_state_ptr)++ = yy_current_state;"); + outn ("#endif"); } } +} /* gentabs - generate data statements for the transition tables */ -void gentabs() - { - int i, j, k, *accset, nacc, *acc_array, total_states; - int end_of_buffer_action = num_rules + 1; +void gentabs () +{ + int i, j, k, *accset, nacc, *acc_array, total_states; + int end_of_buffer_action = num_rules + 1; - acc_array = allocate_integer_array( current_max_dfas ); + acc_array = allocate_integer_array (current_max_dfas); nummt = 0; /* The compressed table format jams by entering the "jam state", @@ -894,91 +889,91 @@ void gentabs() */ ++num_backing_up; - if ( reject ) - { + if (reject) { /* Write out accepting list and pointer list. - * + * First we generate the "yy_acclist" array. In the process, * we compute the indices that will go into the "yy_accept" * array, and save the indices in the dfaacc array. */ - int EOB_accepting_list[2]; + int EOB_accepting_list[2]; /* Set up accepting structures for the End Of Buffer state. */ EOB_accepting_list[0] = 0; EOB_accepting_list[1] = end_of_buffer_action; accsiz[end_of_buffer_state] = 1; - dfaacc[end_of_buffer_state].dfaacc_set = EOB_accepting_list; + dfaacc[end_of_buffer_state].dfaacc_set = + EOB_accepting_list; - out_str_dec( long_align ? C_long_decl : C_short_decl, - "yy_acclist", MAX( numas, 1 ) + 1 ); + out_str_dec (long_align ? C_long_decl : C_short_decl, + "yy_acclist", MAX (numas, 1) + 1); - j = 1; /* index into "yy_acclist" array */ + j = 1; /* index into "yy_acclist" array */ - for ( i = 1; i <= lastdfa; ++i ) - { + for (i = 1; i <= lastdfa; ++i) { acc_array[i] = j; - if ( accsiz[i] != 0 ) - { + if (accsiz[i] != 0) { accset = dfaacc[i].dfaacc_set; nacc = accsiz[i]; - if ( trace ) - fprintf( stderr, - _( "state # %d accepts: " ), - i ); + if (trace) + fprintf (stderr, + _("state # %d accepts: "), + i); - for ( k = 1; k <= nacc; ++k ) - { - int accnum = accset[k]; + for (k = 1; k <= nacc; ++k) { + int accnum = accset[k]; ++j; - if ( variable_trailing_context_rules && - ! (accnum & YY_TRAILING_HEAD_MASK) && - accnum > 0 && accnum <= num_rules && - rule_type[accnum] == RULE_VARIABLE ) - { + if (variable_trailing_context_rules + && !(accnum & + YY_TRAILING_HEAD_MASK) + && accnum > 0 + && accnum <= num_rules + && rule_type[accnum] == + RULE_VARIABLE) { /* Special hack to flag * accepting number as part * of trailing context rule. */ accnum |= YY_TRAILING_MASK; - } + } - mkdata( accnum ); + mkdata (accnum); - if ( trace ) - { - fprintf( stderr, "[%d]", - accset[k] ); + if (trace) { + fprintf (stderr, "[%d]", + accset[k]); - if ( k < nacc ) - fputs( ", ", stderr ); + if (k < nacc) + fputs (", ", + stderr); else - putc( '\n', stderr ); - } + putc ('\n', + stderr); } } } + } /* add accepting number for the "jam" state */ acc_array[i] = j; - dataend(); - } + dataend (); + } - else - { - dfaacc[end_of_buffer_state].dfaacc_state = end_of_buffer_action; + else { + dfaacc[end_of_buffer_state].dfaacc_state = + end_of_buffer_action; - for ( i = 1; i <= lastdfa; ++i ) + for (i = 1; i <= lastdfa; ++i) acc_array[i] = dfaacc[i].dfaacc_state; /* add accepting number for jam state */ acc_array[i] = 0; - } + } /* Spit out "yy_accept" array. If we're doing "reject", it'll be * pointers into the "yy_acclist" array. Otherwise it's actual @@ -990,7 +985,7 @@ void gentabs() */ k = lastdfa + 2; - if ( reject ) + if (reject) /* We put a "cap" on the table associating lists of accepting * numbers with state numbers. This is needed because we tell * where the end of an accepting list is by looking at where @@ -998,243 +993,230 @@ void gentabs() */ ++k; - out_str_dec( long_align ? C_long_decl : C_short_decl, "yy_accept", k ); + out_str_dec (long_align ? C_long_decl : C_short_decl, "yy_accept", + k); - for ( i = 1; i <= lastdfa; ++i ) - { - mkdata( acc_array[i] ); + for (i = 1; i <= lastdfa; ++i) { + mkdata (acc_array[i]); - if ( ! reject && trace && acc_array[i] ) - fprintf( stderr, _( "state # %d accepts: [%d]\n" ), - i, acc_array[i] ); - } + if (!reject && trace && acc_array[i]) + fprintf (stderr, _("state # %d accepts: [%d]\n"), + i, acc_array[i]); + } /* Add entry for "jam" state. */ - mkdata( acc_array[i] ); + mkdata (acc_array[i]); - if ( reject ) + if (reject) /* Add "cap" for the list. */ - mkdata( acc_array[i] ); + mkdata (acc_array[i]); - dataend(); + dataend (); - if ( useecs ) - genecs(); + if (useecs) + genecs (); - if ( usemecs ) - { + if (usemecs) { /* Write out meta-equivalence classes (used to index * templates with). */ - if ( trace ) - fputs( _( "\n\nMeta-Equivalence Classes:\n" ), - stderr ); - - out_str_dec( C_int_decl, "yy_meta", numecs + 1 ); + if (trace) + fputs (_("\n\nMeta-Equivalence Classes:\n"), + stderr); - for ( i = 1; i <= numecs; ++i ) - { - if ( trace ) - fprintf( stderr, "%d = %d\n", - i, ABS( tecbck[i] ) ); + out_str_dec (C_int_decl, "yy_meta", numecs + 1); - mkdata( ABS( tecbck[i] ) ); - } + for (i = 1; i <= numecs; ++i) { + if (trace) + fprintf (stderr, "%d = %d\n", + i, ABS (tecbck[i])); - dataend(); + mkdata (ABS (tecbck[i])); } + dataend (); + } + total_states = lastdfa + numtemps; - out_str_dec( (tblend >= MAX_SHORT || long_align) ? - C_long_decl : C_short_decl, - "yy_base", total_states + 1 ); + out_str_dec ((tblend >= MAX_SHORT || long_align) ? + C_long_decl : C_short_decl, + "yy_base", total_states + 1); - for ( i = 1; i <= lastdfa; ++i ) - { + for (i = 1; i <= lastdfa; ++i) { register int d = def[i]; - if ( base[i] == JAMSTATE ) + if (base[i] == JAMSTATE) base[i] = jambase; - if ( d == JAMSTATE ) + if (d == JAMSTATE) def[i] = jamstate; - else if ( d < 0 ) - { + else if (d < 0) { /* Template reference. */ ++tmpuses; def[i] = lastdfa - d + 1; - } - - mkdata( base[i] ); } + mkdata (base[i]); + } + /* Generate jam state's base index. */ - mkdata( base[i] ); + mkdata (base[i]); - for ( ++i /* skip jam state */; i <= total_states; ++i ) - { - mkdata( base[i] ); + for (++i /* skip jam state */ ; i <= total_states; ++i) { + mkdata (base[i]); def[i] = jamstate; - } + } - dataend(); + dataend (); - out_str_dec( (total_states >= MAX_SHORT || long_align) ? - C_long_decl : C_short_decl, - "yy_def", total_states + 1 ); + out_str_dec ((total_states >= MAX_SHORT || long_align) ? + C_long_decl : C_short_decl, + "yy_def", total_states + 1); - for ( i = 1; i <= total_states; ++i ) - mkdata( def[i] ); + for (i = 1; i <= total_states; ++i) + mkdata (def[i]); - dataend(); + dataend (); - out_str_dec( (total_states >= MAX_SHORT || long_align) ? - C_long_decl : C_short_decl, - "yy_nxt", tblend + 1 ); + out_str_dec ((total_states >= MAX_SHORT || long_align) ? + C_long_decl : C_short_decl, "yy_nxt", tblend + 1); - for ( i = 1; i <= tblend; ++i ) - { + for (i = 1; i <= tblend; ++i) { /* Note, the order of the following test is important. * If chk[i] is 0, then nxt[i] is undefined. */ - if ( chk[i] == 0 || nxt[i] == 0 ) + if (chk[i] == 0 || nxt[i] == 0) nxt[i] = jamstate; /* new state is the JAM state */ - mkdata( nxt[i] ); - } + mkdata (nxt[i]); + } - dataend(); + dataend (); - out_str_dec( (total_states >= MAX_SHORT || long_align) ? - C_long_decl : C_short_decl, - "yy_chk", tblend + 1 ); + out_str_dec ((total_states >= MAX_SHORT || long_align) ? + C_long_decl : C_short_decl, "yy_chk", tblend + 1); - for ( i = 1; i <= tblend; ++i ) - { - if ( chk[i] == 0 ) + for (i = 1; i <= tblend; ++i) { + if (chk[i] == 0) ++nummt; - mkdata( chk[i] ); - } + mkdata (chk[i]); + } - dataend(); + dataend (); - flex_free( (void *) acc_array ); - } + flex_free ((void *) acc_array); +} /* Write out a formatted string (with a secondary string argument) at the * current indentation level, adding a final newline. */ -void indent_put2s( fmt, arg ) -const char *fmt, *arg; - { - do_indent(); - out_str( fmt, arg ); - outn( "" ); - } +void indent_put2s (fmt, arg) + const char *fmt, *arg; +{ + do_indent (); + out_str (fmt, arg); + outn (""); +} /* Write out a string at the current indentation level, adding a final * newline. */ -void indent_puts( str ) -const char *str; - { - do_indent(); - outn( str ); - } +void indent_puts (str) + const char *str; +{ + do_indent (); + outn (str); +} /* make_tables - generate transition tables and finishes generating output file */ -void make_tables() - { +void make_tables () +{ register int i; - int did_eof_rule = false; + int did_eof_rule = false; - skelout(); /* %% [2.0] - break point in skel */ + skelout (); /* %% [2.0] - break point in skel */ /* First, take care of YY_DO_BEFORE_ACTION depending on yymore * being used. */ - set_indent( 1 ); + set_indent (1); - if ( yymore_used && ! yytext_is_array ) - { - indent_puts( "YY_G(yytext_ptr) -= YY_G(yy_more_len); \\" ); - indent_puts( "yyleng = (size_t) (yy_cp - YY_G(yytext_ptr)); \\" ); - } + if (yymore_used && !yytext_is_array) { + indent_puts ("YY_G(yytext_ptr) -= YY_G(yy_more_len); \\"); + indent_puts + ("yyleng = (size_t) (yy_cp - YY_G(yytext_ptr)); \\"); + } else - indent_puts( "yyleng = (size_t) (yy_cp - yy_bp); \\" ); + indent_puts ("yyleng = (size_t) (yy_cp - yy_bp); \\"); /* Now also deal with copying yytext_ptr to yytext if needed. */ - skelout(); /* %% [3.0] - break point in skel */ - if ( yytext_is_array ) - { - if ( yymore_used ) - indent_puts( - "if ( yyleng + YY_G(yy_more_offset) >= YYLMAX ) \\" ); - else - indent_puts( "if ( yyleng >= YYLMAX ) \\" ); - - indent_up(); - indent_puts( - "YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\" ); - indent_down(); - - if ( yymore_used ) - { - indent_puts( -"yy_flex_strncpy( &yytext[YY_G(yy_more_offset)], YY_G(yytext_ptr), yyleng + 1 YY_CALL_LAST_ARG); \\" ); - indent_puts( "yyleng += YY_G(yy_more_offset); \\" ); - indent_puts( - "YY_G(yy_prev_more_offset) = YY_G(yy_more_offset); \\" ); - indent_puts( "YY_G(yy_more_offset) = 0; \\" ); - } + skelout (); /* %% [3.0] - break point in skel */ + if (yytext_is_array) { + if (yymore_used) + indent_puts + ("if ( yyleng + YY_G(yy_more_offset) >= YYLMAX ) \\"); else - { - indent_puts( - "yy_flex_strncpy( yytext, YY_G(yytext_ptr), yyleng + 1 YY_CALL_LAST_ARG); \\" ); - } + indent_puts ("if ( yyleng >= YYLMAX ) \\"); + + indent_up (); + indent_puts + ("YY_FATAL_ERROR( \"token too large, exceeds YYLMAX\" ); \\"); + indent_down (); + + if (yymore_used) { + indent_puts + ("yy_flex_strncpy( &yytext[YY_G(yy_more_offset)], YY_G(yytext_ptr), yyleng + 1 YY_CALL_LAST_ARG); \\"); + indent_puts ("yyleng += YY_G(yy_more_offset); \\"); + indent_puts + ("YY_G(yy_prev_more_offset) = YY_G(yy_more_offset); \\"); + indent_puts ("YY_G(yy_more_offset) = 0; \\"); } + else { + indent_puts + ("yy_flex_strncpy( yytext, YY_G(yytext_ptr), yyleng + 1 YY_CALL_LAST_ARG); \\"); + } + } - set_indent( 0 ); + set_indent (0); - skelout(); /* %% [4.0] - break point in skel */ + skelout (); /* %% [4.0] - break point in skel */ - /* This is where we REALLY begin generating the tables. */ + /* This is where we REALLY begin generating the tables. */ - out_dec( "#define YY_NUM_RULES %d\n", num_rules ); - out_dec( "#define YY_END_OF_BUFFER %d\n", num_rules + 1 ); + out_dec ("#define YY_NUM_RULES %d\n", num_rules); + out_dec ("#define YY_END_OF_BUFFER %d\n", num_rules + 1); - if ( fullspd ) - { + if (fullspd) { /* Need to define the transet type as a size large * enough to hold the biggest offset. */ - int total_table_size = tblend + numecs + 1; - char *trans_offset_type = + int total_table_size = tblend + numecs + 1; + char *trans_offset_type = (total_table_size >= MAX_SHORT || long_align) ? - "long" : "short"; + "long" : "short"; - set_indent( 0 ); - indent_puts( "struct yy_trans_info" ); - indent_up(); - indent_puts( "{" ); + set_indent (0); + indent_puts ("struct yy_trans_info"); + indent_up (); + indent_puts ("{"); - if ( long_align ) - indent_puts( "long yy_verify;" ); + if (long_align) + indent_puts ("long yy_verify;"); else - indent_puts( "short yy_verify;" ); + indent_puts ("short yy_verify;"); /* In cases where its sister yy_verify *is* a "yes, there is * a transition", yy_nxt is the offset (in records) to the @@ -1244,518 +1226,491 @@ void make_tables() * for that state. */ - indent_put2s( "%s yy_nxt;", trans_offset_type ); - indent_puts( "};" ); - indent_down(); - } + indent_put2s ("%s yy_nxt;", trans_offset_type); + indent_puts ("};"); + indent_down (); + } - if ( fullspd ) - genctbl(); - else if ( fulltbl ) - genftbl(); + if (fullspd) + genctbl (); + else if (fulltbl) + genftbl (); else - gentabs(); + gentabs (); + + if (do_yylineno) + geneoltbl (); - if ( do_yylineno ) - geneoltbl(); - /* Definitions for backing up. We don't need them if REJECT * is being used because then we use an alternative backin-up * technique instead. */ - if ( num_backing_up > 0 && ! reject ) - { - if ( ! C_plus_plus && !reentrant) - { - indent_puts( - "static yy_state_type yy_last_accepting_state;" ); - indent_puts( - "static char *yy_last_accepting_cpos;\n" ); - } + if (num_backing_up > 0 && !reject) { + if (!C_plus_plus && !reentrant) { + indent_puts + ("static yy_state_type yy_last_accepting_state;"); + indent_puts + ("static char *yy_last_accepting_cpos;\n"); } + } - if ( nultrans ) - { - out_str_dec( C_state_decl, "yy_NUL_trans", lastdfa + 1 ); + if (nultrans) { + out_str_dec (C_state_decl, "yy_NUL_trans", lastdfa + 1); - for ( i = 1; i <= lastdfa; ++i ) - { - if ( fullspd ) - out_dec( " &yy_transition[%d],\n", base[i] ); + for (i = 1; i <= lastdfa; ++i) { + if (fullspd) + out_dec (" &yy_transition[%d],\n", + base[i]); else - mkdata( nultrans[i] ); - } - - dataend(); + mkdata (nultrans[i]); } - if ( ddebug ) - { /* Spit out table mapping rules to line numbers. */ - if ( ! C_plus_plus && ! reentrant ) - { - indent_puts( "extern int yy_flex_debug;" ); - indent_puts( "int yy_flex_debug = 1;\n" ); - } + dataend (); + } - out_str_dec( long_align ? C_long_decl : C_short_decl, - "yy_rule_linenum", num_rules ); - for ( i = 1; i < num_rules; ++i ) - mkdata( rule_linenum[i] ); - dataend(); + if (ddebug) { /* Spit out table mapping rules to line numbers. */ + if (!C_plus_plus && !reentrant) { + indent_puts ("extern int yy_flex_debug;"); + indent_puts ("int yy_flex_debug = 1;\n"); } - if ( reject ) - { - outn("#ifdef YY_USES_REJECT"); - /* Declare state buffer variables. */ - if ( ! C_plus_plus && ! reentrant ) - { - outn( - "static yy_state_type *yy_state_buf=0, *yy_state_ptr=0;" ); - outn( "static char *yy_full_match;" ); - outn( "static int yy_lp;" ); - } - - if ( variable_trailing_context_rules ) - { - if ( ! C_plus_plus ) - { - outn( - "static int yy_looking_for_trail_begin = 0;" ); - outn( "static int yy_full_lp;" ); - outn( "static int *yy_full_state;" ); - } + out_str_dec (long_align ? C_long_decl : C_short_decl, + "yy_rule_linenum", num_rules); + for (i = 1; i < num_rules; ++i) + mkdata (rule_linenum[i]); + dataend (); + } - out_hex( "#define YY_TRAILING_MASK 0x%x\n", - (unsigned int) YY_TRAILING_MASK ); - out_hex( "#define YY_TRAILING_HEAD_MASK 0x%x\n", - (unsigned int) YY_TRAILING_HEAD_MASK ); - } + if (reject) { + outn ("#ifdef YY_USES_REJECT"); + /* Declare state buffer variables. */ + if (!C_plus_plus && !reentrant) { + outn + ("static yy_state_type *yy_state_buf=0, *yy_state_ptr=0;"); + outn ("static char *yy_full_match;"); + outn ("static int yy_lp;"); + } - outn( "#define REJECT \\" ); - outn( "{ \\" ); - outn( - "*yy_cp = YY_G(yy_hold_char); /* undo effects of setting up yytext */ \\" ); - outn( - "yy_cp = YY_G(yy_full_match); /* restore poss. backed-over text */ \\" ); - - if ( variable_trailing_context_rules ) - { - outn( - "YY_G(yy_lp) = yy_full_lp; /* restore orig. accepting pos. */ \\" ); - outn( - "YY_G(yy_state_ptr) = yy_full_state; /* restore orig. state */ \\" ); - outn( - "yy_current_state = *YY_G(yy_state_ptr); /* restore curr. state */ \\" ); + if (variable_trailing_context_rules) { + if (!C_plus_plus) { + outn + ("static int yy_looking_for_trail_begin = 0;"); + outn ("static int yy_full_lp;"); + outn ("static int *yy_full_state;"); } - outn( "++YY_G(yy_lp); \\" ); - outn( "goto find_rule; \\" ); - - outn( "}" ); - outn("#endif"); + out_hex ("#define YY_TRAILING_MASK 0x%x\n", + (unsigned int) YY_TRAILING_MASK); + out_hex ("#define YY_TRAILING_HEAD_MASK 0x%x\n", + (unsigned int) YY_TRAILING_HEAD_MASK); } - else - { - outn( - "/* The intent behind this definition is that it'll catch" ); - outn( " * any uses of REJECT which flex missed." ); - outn( " */" ); - outn( "#define REJECT reject_used_but_not_detected" ); + outn ("#define REJECT \\"); + outn ("{ \\"); + outn + ("*yy_cp = YY_G(yy_hold_char); /* undo effects of setting up yytext */ \\"); + outn + ("yy_cp = YY_G(yy_full_match); /* restore poss. backed-over text */ \\"); + + if (variable_trailing_context_rules) { + outn + ("YY_G(yy_lp) = yy_full_lp; /* restore orig. accepting pos. */ \\"); + outn + ("YY_G(yy_state_ptr) = yy_full_state; /* restore orig. state */ \\"); + outn + ("yy_current_state = *YY_G(yy_state_ptr); /* restore curr. state */ \\"); } - if ( yymore_used ) - { - if ( ! C_plus_plus ) - { - if ( yytext_is_array ) - { - outn( "#ifndef YY_REENTRANT"); - indent_puts( "static int yy_more_offset = 0;" ); - indent_puts( - "static int yy_prev_more_offset = 0;" ); - outn( "#endif" ); - } - else if( !reentrant ) - { - outn( "#ifndef YY_REENTRANT"); - indent_puts( "static int yy_more_flag = 0;" ); - indent_puts( "static int yy_more_len = 0;" ); - outn( "#endif" ); - } - } + outn ("++YY_G(yy_lp); \\"); + outn ("goto find_rule; \\"); + + outn ("}"); + outn ("#endif"); + } + + else { + outn + ("/* The intent behind this definition is that it'll catch"); + outn (" * any uses of REJECT which flex missed."); + outn (" */"); + outn ("#define REJECT reject_used_but_not_detected"); + } - if ( yytext_is_array ) - { - indent_puts( - "#define yymore() (YY_G(yy_more_offset) = yy_flex_strlen( yytext YY_CALL_LAST_ARG))" ); - indent_puts( "#define YY_NEED_STRLEN" ); - indent_puts( "#define YY_MORE_ADJ 0" ); - indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET \\" ); - indent_up(); - indent_puts( "{ \\" ); - indent_puts( "YY_G(yy_more_offset) = YY_G(yy_prev_more_offset); \\" ); - indent_puts( "yyleng -= YY_G(yy_more_offset); \\" ); - indent_puts( "}" ); - indent_down(); + if (yymore_used) { + if (!C_plus_plus) { + if (yytext_is_array) { + outn ("#ifndef YY_REENTRANT"); + indent_puts + ("static int yy_more_offset = 0;"); + indent_puts + ("static int yy_prev_more_offset = 0;"); + outn ("#endif"); } - else - { - indent_puts( "#define yymore() (YY_G(yy_more_flag) = 1)" ); - indent_puts( "#define YY_MORE_ADJ YY_G(yy_more_len)" ); - indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET" ); + else if (!reentrant) { + outn ("#ifndef YY_REENTRANT"); + indent_puts + ("static int yy_more_flag = 0;"); + indent_puts + ("static int yy_more_len = 0;"); + outn ("#endif"); } } - else - { - indent_puts( "#define yymore() yymore_used_but_not_detected" ); - indent_puts( "#define YY_MORE_ADJ 0" ); - indent_puts( "#define YY_RESTORE_YY_MORE_OFFSET" ); + if (yytext_is_array) { + indent_puts + ("#define yymore() (YY_G(yy_more_offset) = yy_flex_strlen( yytext YY_CALL_LAST_ARG))"); + indent_puts ("#define YY_NEED_STRLEN"); + indent_puts ("#define YY_MORE_ADJ 0"); + indent_puts + ("#define YY_RESTORE_YY_MORE_OFFSET \\"); + indent_up (); + indent_puts ("{ \\"); + indent_puts + ("YY_G(yy_more_offset) = YY_G(yy_prev_more_offset); \\"); + indent_puts ("yyleng -= YY_G(yy_more_offset); \\"); + indent_puts ("}"); + indent_down (); } + else { + indent_puts + ("#define yymore() (YY_G(yy_more_flag) = 1)"); + indent_puts + ("#define YY_MORE_ADJ YY_G(yy_more_len)"); + indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET"); + } + } - if ( ! C_plus_plus ) - { - if ( yytext_is_array ) - { - outn( "#ifndef YYLMAX" ); - outn( "#define YYLMAX 8192" ); - outn( "#endif\n" ); - outn( "#ifndef YY_REENTRANT" ); - outn( "char yytext[YYLMAX];" ); - outn( "char *yytext_ptr;" ); - outn( "#endif" ); - } + else { + indent_puts + ("#define yymore() yymore_used_but_not_detected"); + indent_puts ("#define YY_MORE_ADJ 0"); + indent_puts ("#define YY_RESTORE_YY_MORE_OFFSET"); + } - else - { - outn( "#ifndef YY_REENTRANT" ); - outn( "char *yytext;" ); - outn( "#endif" ); - } + if (!C_plus_plus) { + if (yytext_is_array) { + outn ("#ifndef YYLMAX"); + outn ("#define YYLMAX 8192"); + outn ("#endif\n"); + outn ("#ifndef YY_REENTRANT"); + outn ("char yytext[YYLMAX];"); + outn ("char *yytext_ptr;"); + outn ("#endif"); } - out( &action_array[defs1_offset] ); - - line_directive_out( stdout, 0 ); - - skelout(); /* %% [5.0] - break point in skel */ - - if ( ! C_plus_plus ) - { - if ( use_read ) - { - outn( "\terrno=0; \\" ); - outn( -"\twhile ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\" ); - outn( "\t{ \\" ); - outn( "\t\tif( errno != EINTR) \\" ); - outn( "\t\t{ \\" ); - outn( - "\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\" ); - outn( "\t\t\tbreak; \\" ); - outn( "\t\t} \\" ); - outn( "\t\terrno=0; \\" ); - outn( "\t\tclearerr(yyin); \\" ); - outn( "\t}" ); - } + else { + outn ("#ifndef YY_REENTRANT"); + outn ("char *yytext;"); + outn ("#endif"); + } + } - else - { - outn( - "\tif ( YY_G(yy_current_buffer)->yy_is_interactive ) \\" ); - outn( "\t\t{ \\" ); - outn( "\t\tint c = '*'; \\"); - outn( "\t\tsize_t n; \\" ); - outn( "\t\tfor ( n = 0; n < max_size && \\" ); - outn( "\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\" ); - outn( "\t\t\tbuf[n] = (char) c; \\" ); - outn( "\t\tif ( c == '\\n' ) \\" ); - outn( "\t\t\tbuf[n++] = (char) c; \\" ); - outn( "\t\tif ( c == EOF && ferror( yyin ) ) \\" ); - outn( - "\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\" ); - outn( "\t\tresult = n; \\" ); - outn( "\t\t} \\" ); - outn( "\telse \\" ); - outn( "\t\t{ \\" ); - outn( "\t\terrno=0; \\" ); - outn( -"\t\twhile ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \\" ); - outn( "\t\t\t{ \\" ); - outn( "\t\t\tif( errno != EINTR) \\" ); - outn( "\t\t\t\t{ \\" ); - outn( - "\t\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\" ); - outn( "\t\t\t\tbreak; \\" ); - outn( "\t\t\t\t} \\" ); - outn( "\t\t\terrno=0; \\" ); - outn( "\t\t\tclearerr(yyin); \\" ); - outn( "\t\t\t} \\" ); - outn( "\t\t}" ); - } + out (&action_array[defs1_offset]); + + line_directive_out (stdout, 0); + + skelout (); /* %% [5.0] - break point in skel */ + + if (!C_plus_plus) { + if (use_read) { + outn ("\terrno=0; \\"); + outn + ("\twhile ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \\"); + outn ("\t{ \\"); + outn ("\t\tif( errno != EINTR) \\"); + outn ("\t\t{ \\"); + outn + ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\"); + outn ("\t\t\tbreak; \\"); + outn ("\t\t} \\"); + outn ("\t\terrno=0; \\"); + outn ("\t\tclearerr(yyin); \\"); + outn ("\t}"); } - skelout(); /* %% [6.0] - break point in skel */ - - indent_puts( "#define YY_RULE_SETUP \\" ); - indent_up(); - if ( bol_needed ) - { - indent_puts( "if ( yyleng > 0 ) \\" ); - indent_up(); - indent_puts( "YY_G(yy_current_buffer)->yy_at_bol = \\" ); - indent_puts( "\t\t(yytext[yyleng - 1] == '\\n'); \\" ); - indent_down(); + else { + outn + ("\tif ( YY_G(yy_current_buffer)->yy_is_interactive ) \\"); + outn ("\t\t{ \\"); + outn ("\t\tint c = '*'; \\"); + outn ("\t\tsize_t n; \\"); + outn ("\t\tfor ( n = 0; n < max_size && \\"); + outn + ("\t\t\t (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \\"); + outn ("\t\t\tbuf[n] = (char) c; \\"); + outn ("\t\tif ( c == '\\n' ) \\"); + outn ("\t\t\tbuf[n++] = (char) c; \\"); + outn ("\t\tif ( c == EOF && ferror( yyin ) ) \\"); + outn + ("\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\"); + outn ("\t\tresult = n; \\"); + outn ("\t\t} \\"); + outn ("\telse \\"); + outn ("\t\t{ \\"); + outn ("\t\terrno=0; \\"); + outn + ("\t\twhile ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \\"); + outn ("\t\t\t{ \\"); + outn ("\t\t\tif( errno != EINTR) \\"); + outn ("\t\t\t\t{ \\"); + outn + ("\t\t\t\tYY_FATAL_ERROR( \"input in flex scanner failed\" ); \\"); + outn ("\t\t\t\tbreak; \\"); + outn ("\t\t\t\t} \\"); + outn ("\t\t\terrno=0; \\"); + outn ("\t\t\tclearerr(yyin); \\"); + outn ("\t\t\t} \\"); + outn ("\t\t}"); } - indent_puts( "YY_USER_ACTION" ); - indent_down(); + } + + skelout (); /* %% [6.0] - break point in skel */ + + indent_puts ("#define YY_RULE_SETUP \\"); + indent_up (); + if (bol_needed) { + indent_puts ("if ( yyleng > 0 ) \\"); + indent_up (); + indent_puts ("YY_G(yy_current_buffer)->yy_at_bol = \\"); + indent_puts ("\t\t(yytext[yyleng - 1] == '\\n'); \\"); + indent_down (); + } + indent_puts ("YY_USER_ACTION"); + indent_down (); - skelout(); /* %% [7.0] - break point in skel */ + skelout (); /* %% [7.0] - break point in skel */ /* Copy prolog to output file. */ - out( &action_array[prolog_offset] ); + out (&action_array[prolog_offset]); - line_directive_out( stdout, 0 ); + line_directive_out (stdout, 0); - skelout(); /* %% [8.0] - break point in skel */ + skelout (); /* %% [8.0] - break point in skel */ - set_indent( 2 ); + set_indent (2); - if ( yymore_used && ! yytext_is_array ) - { - indent_puts( "YY_G(yy_more_len) = 0;" ); - indent_puts( "if ( YY_G(yy_more_flag) )" ); - indent_up(); - indent_puts( "{" ); - indent_puts( "YY_G(yy_more_len) = YY_G(yy_c_buf_p) - YY_G(yytext_ptr);" ); - indent_puts( "YY_G(yy_more_flag) = 0;" ); - indent_puts( "}" ); - indent_down(); - } + if (yymore_used && !yytext_is_array) { + indent_puts ("YY_G(yy_more_len) = 0;"); + indent_puts ("if ( YY_G(yy_more_flag) )"); + indent_up (); + indent_puts ("{"); + indent_puts + ("YY_G(yy_more_len) = YY_G(yy_c_buf_p) - YY_G(yytext_ptr);"); + indent_puts ("YY_G(yy_more_flag) = 0;"); + indent_puts ("}"); + indent_down (); + } - skelout(); /* %% [9.0] - break point in skel */ + skelout (); /* %% [9.0] - break point in skel */ - gen_start_state(); + gen_start_state (); /* Note, don't use any indentation. */ - outn( "yy_match:" ); - gen_next_match(); - - skelout(); /* %% [10.0] - break point in skel */ - set_indent( 2 ); - gen_find_action(); - - skelout(); /* %% [11.0] - break point in skel */ - outn( "#ifdef YY_USE_LINENO" ); - indent_puts( "if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )" ); - indent_up(); - indent_puts( "{" ); - indent_puts( "int yyl;" ); - do_indent(); - out_str( "for ( yyl = %s; yyl < yyleng; ++yyl )\n", - yymore_used ? (yytext_is_array ? "yy_prev_more_offset" : - "yy_more_len") : "0"); - indent_up(); - indent_puts( "if ( yytext[yyl] == '\\n' )" ); - indent_up(); - indent_puts( "++yylineno;" ); - indent_down(); - indent_down(); - indent_puts( "}" ); - indent_down(); - outn( "#endif" ); - - skelout(); /* %% [12.0] - break point in skel */ - if ( ddebug ) - { - indent_puts( "if ( yy_flex_debug )" ); - indent_up(); - - indent_puts( "{" ); - indent_puts( "if ( yy_act == 0 )" ); - indent_up(); - indent_puts( C_plus_plus ? - "cerr << \"--scanner backing up\\n\";" : - "fprintf( stderr, \"--scanner backing up\\n\" );" ); - indent_down(); - - do_indent(); - out_dec( "else if ( yy_act < %d )\n", num_rules ); - indent_up(); - - if ( C_plus_plus ) - { - indent_puts( - "cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<" ); - indent_puts( - " \"(\\\"\" << yytext << \"\\\")\\n\";" ); - } - else - { - indent_puts( - "fprintf( stderr, \"--accepting rule at line %ld (\\\"%s\\\")\\n\"," ); + outn ("yy_match:"); + gen_next_match (); + + skelout (); /* %% [10.0] - break point in skel */ + set_indent (2); + gen_find_action (); + + skelout (); /* %% [11.0] - break point in skel */ + outn ("#ifdef YY_USE_LINENO"); + indent_puts + ("if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )"); + indent_up (); + indent_puts ("{"); + indent_puts ("int yyl;"); + do_indent (); + out_str ("for ( yyl = %s; yyl < yyleng; ++yyl )\n", + yymore_used ? (yytext_is_array ? "yy_prev_more_offset" : + "yy_more_len") : "0"); + indent_up (); + indent_puts ("if ( yytext[yyl] == '\\n' )"); + indent_up (); + indent_puts ("++yylineno;"); + indent_down (); + indent_down (); + indent_puts ("}"); + indent_down (); + outn ("#endif"); + + skelout (); /* %% [12.0] - break point in skel */ + if (ddebug) { + indent_puts ("if ( yy_flex_debug )"); + indent_up (); + + indent_puts ("{"); + indent_puts ("if ( yy_act == 0 )"); + indent_up (); + indent_puts (C_plus_plus ? + "cerr << \"--scanner backing up\\n\";" : + "fprintf( stderr, \"--scanner backing up\\n\" );"); + indent_down (); + + do_indent (); + out_dec ("else if ( yy_act < %d )\n", num_rules); + indent_up (); + + if (C_plus_plus) { + indent_puts + ("cerr << \"--accepting rule at line \" << yy_rule_linenum[yy_act] <<"); + indent_puts + (" \"(\\\"\" << yytext << \"\\\")\\n\";"); + } + else { + indent_puts + ("fprintf( stderr, \"--accepting rule at line %ld (\\\"%s\\\")\\n\","); - indent_puts( - " (long)yy_rule_linenum[yy_act], yytext );" ); - } + indent_puts + (" (long)yy_rule_linenum[yy_act], yytext );"); + } - indent_down(); + indent_down (); - do_indent(); - out_dec( "else if ( yy_act == %d )\n", num_rules ); - indent_up(); + do_indent (); + out_dec ("else if ( yy_act == %d )\n", num_rules); + indent_up (); - if ( C_plus_plus ) - { - indent_puts( -"cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";" ); - } - else - { - indent_puts( - "fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\"," ); - indent_puts( " yytext );" ); - } + if (C_plus_plus) { + indent_puts + ("cerr << \"--accepting default rule (\\\"\" << yytext << \"\\\")\\n\";"); + } + else { + indent_puts + ("fprintf( stderr, \"--accepting default rule (\\\"%s\\\")\\n\","); + indent_puts (" yytext );"); + } - indent_down(); + indent_down (); - do_indent(); - out_dec( "else if ( yy_act == %d )\n", num_rules + 1 ); - indent_up(); + do_indent (); + out_dec ("else if ( yy_act == %d )\n", num_rules + 1); + indent_up (); - indent_puts( C_plus_plus ? - "cerr << \"--(end of buffer or a NUL)\\n\";" : - "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );" ); + indent_puts (C_plus_plus ? + "cerr << \"--(end of buffer or a NUL)\\n\";" : + "fprintf( stderr, \"--(end of buffer or a NUL)\\n\" );"); - indent_down(); + indent_down (); - do_indent(); - outn( "else" ); - indent_up(); + do_indent (); + outn ("else"); + indent_up (); - if ( C_plus_plus ) - { - indent_puts( - "cerr << \"--EOF (start condition \" << YY_START << \")\\n\";" ); - } - else - { - indent_puts( - "fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );" ); - } + if (C_plus_plus) { + indent_puts + ("cerr << \"--EOF (start condition \" << YY_START << \")\\n\";"); + } + else { + indent_puts + ("fprintf( stderr, \"--EOF (start condition %d)\\n\", YY_START );"); + } - indent_down(); + indent_down (); - indent_puts( "}" ); - indent_down(); - } + indent_puts ("}"); + indent_down (); + } /* Copy actions to output file. */ - skelout(); /* %% [13.0] - break point in skel */ - indent_up(); - gen_bu_action(); - out( &action_array[action_offset] ); + skelout (); /* %% [13.0] - break point in skel */ + indent_up (); + gen_bu_action (); + out (&action_array[action_offset]); - line_directive_out( stdout, 0 ); + line_directive_out (stdout, 0); /* generate cases for any missing EOF rules */ - for ( i = 1; i <= lastsc; ++i ) - if ( ! sceof[i] ) - { - do_indent(); - out_str( "case YY_STATE_EOF(%s):\n", scname[i] ); + for (i = 1; i <= lastsc; ++i) + if (!sceof[i]) { + do_indent (); + out_str ("case YY_STATE_EOF(%s):\n", scname[i]); did_eof_rule = true; - } - - if ( did_eof_rule ) - { - indent_up(); - indent_puts( "yyterminate();" ); - indent_down(); } + if (did_eof_rule) { + indent_up (); + indent_puts ("yyterminate();"); + indent_down (); + } + /* Generate code for handling NUL's, if needed. */ /* First, deal with backing up and setting up yy_cp if the scanner * finds that it should JAM on the NUL. */ - skelout(); /* %% [14.0] - break point in skel */ - set_indent( 4 ); + skelout (); /* %% [14.0] - break point in skel */ + set_indent (4); - if ( fullspd || fulltbl ) - indent_puts( "yy_cp = YY_G(yy_c_buf_p);" ); + if (fullspd || fulltbl) + indent_puts ("yy_cp = YY_G(yy_c_buf_p);"); - else - { /* compressed table */ - if ( ! reject && ! interactive ) - { + else { /* compressed table */ + if (!reject && !interactive) { /* Do the guaranteed-needed backing up to figure * out the match. */ - indent_puts( "yy_cp = YY_G(yy_last_accepting_cpos);" ); - indent_puts( - "yy_current_state = YY_G(yy_last_accepting_state);" ); - } + indent_puts + ("yy_cp = YY_G(yy_last_accepting_cpos);"); + indent_puts + ("yy_current_state = YY_G(yy_last_accepting_state);"); + } else /* Still need to initialize yy_cp, though * yy_current_state was set up by * yy_get_previous_state(). */ - indent_puts( "yy_cp = YY_G(yy_c_buf_p);" ); - } + indent_puts ("yy_cp = YY_G(yy_c_buf_p);"); + } /* Generate code for yy_get_previous_state(). */ - set_indent( 1 ); - skelout(); /* %% [15.0] - break point in skel */ + set_indent (1); + skelout (); /* %% [15.0] - break point in skel */ - gen_start_state(); + gen_start_state (); - set_indent( 2 ); - skelout(); /* %% [16.0] - break point in skel */ - gen_next_state( true ); + set_indent (2); + skelout (); /* %% [16.0] - break point in skel */ + gen_next_state (true); - set_indent( 1 ); - skelout(); /* %% [17.0] - break point in skel */ - gen_NUL_trans(); + set_indent (1); + skelout (); /* %% [17.0] - break point in skel */ + gen_NUL_trans (); - skelout(); /* %% [18.0] - break point in skel */ - skelout(); /* %% [19.0] - break point in skel */ + skelout (); /* %% [18.0] - break point in skel */ + skelout (); /* %% [19.0] - break point in skel */ /* Update BOL and yylineno inside of input(). */ - if ( bol_needed ) - { - indent_puts( "YY_G(yy_current_buffer)->yy_at_bol = (c == '\\n');" ); - if ( do_yylineno ) - { - indent_puts( "if ( YY_G(yy_current_buffer)->yy_at_bol )" ); - indent_up(); - indent_puts( "++yylineno;" ); - indent_down(); - } + if (bol_needed) { + indent_puts + ("YY_G(yy_current_buffer)->yy_at_bol = (c == '\\n');"); + if (do_yylineno) { + indent_puts + ("if ( YY_G(yy_current_buffer)->yy_at_bol )"); + indent_up (); + indent_puts ("++yylineno;"); + indent_down (); } + } - else if ( do_yylineno ) - { - indent_puts( "if ( c == '\\n' )" ); - indent_up(); - indent_puts( "++yylineno;" ); - indent_down(); - } + else if (do_yylineno) { + indent_puts ("if ( c == '\\n' )"); + indent_up (); + indent_puts ("++yylineno;"); + indent_down (); + } - skelout(); + skelout (); /* Copy remainder of input to output. */ - line_directive_out( stdout, 1 ); + line_directive_out (stdout, 1); - if ( sectnum == 3 ) - { - OUT_BEGIN_CODE(); - (void) flexscan(); /* copy remainder of input to output */ - OUT_END_CODE(); - } + if (sectnum == 3) { + OUT_BEGIN_CODE (); + (void) flexscan (); /* copy remainder of input to output */ + OUT_END_CODE (); } +} diff --git a/libmain.c b/libmain.c index deabc2d..49262e4 100644 --- a/libmain.c +++ b/libmain.c @@ -21,14 +21,13 @@ /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ /* PURPOSE. */ -extern int yylex(); +extern int yylex (); -int main( argc, argv ) -int argc; -char *argv[]; - { - while ( yylex() != 0 ) - ; +int main (argc, argv) + int argc; + char *argv[]; +{ + while (yylex () != 0) ; return 0; - } +} diff --git a/libyywrap.c b/libyywrap.c index a572d0b..6345d9d 100644 --- a/libyywrap.c +++ b/libyywrap.c @@ -22,7 +22,7 @@ /* PURPOSE. */ -int yywrap() - { +int yywrap () +{ return 1; - } +} diff --git a/main.c b/main.c index 37dd037..523634a 100644 --- a/main.c +++ b/main.c @@ -44,75 +44,81 @@ static char flex_version[] = FLEX_VERSION; /* declare functions that have forward references */ -void flexinit PROTO((int, char**)); -void readin PROTO((void)); -void set_up_initial_allocations PROTO((void)); -static char * basename2 PROTO((char* path, int should_strip_ext)); +void flexinit PROTO ((int, char **)); +void readin PROTO ((void)); +void set_up_initial_allocations PROTO ((void)); +static char *basename2 PROTO ((char *path, int should_strip_ext)); /* these globals are all defined and commented in flexdef.h */ -int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt; -int interactive, caseins, lex_compat, posix_compat, do_yylineno, useecs, fulltbl, usemecs; -int fullspd, gen_line_dirs, performance_report, backing_up_report; -int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap, csize; -int reentrant, reentrant_bison_pure; -int yymore_used, reject, real_reject, continued_action, in_rule; -int yymore_really_used, reject_really_used; -int datapos, dataline, linenum, out_linenum; -FILE *skelfile = NULL; -int skel_ind = 0; -char *action_array; -int action_size, defs1_offset, prolog_offset, action_offset, action_index; -char *infilename = NULL, *outfilename = NULL, *headerfilename = NULL; -int did_outfilename; -char *prefix, *yyclass; -int do_stdinit, use_stdout; -int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE]; -int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp; -int maximum_mns, current_mns, current_max_rules; -int num_rules, num_eof_rules, default_rule, lastnfa; -int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2; -int *accptnum, *assoc_rule, *state_type; -int *rule_type, *rule_linenum, *rule_useful; -int current_state_type; -int variable_trailing_context_rules; -int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP]; -int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE]; -int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs, tecfwd[CSIZE + 1]; -int tecbck[CSIZE + 1]; -int lastsc, *scset, *scbol, *scxclu, *sceof; -int current_max_scs; -char **scname; -int current_max_dfa_size, current_max_xpairs; -int current_max_template_xpairs, current_max_dfas; -int lastdfa, *nxt, *chk, *tnxt; -int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz; +int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt; +int interactive, caseins, lex_compat, posix_compat, do_yylineno, + useecs, fulltbl, usemecs; +int fullspd, gen_line_dirs, performance_report, backing_up_report; +int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap, + + csize; +int reentrant, reentrant_bison_pure; +int yymore_used, reject, real_reject, continued_action, in_rule; +int yymore_really_used, reject_really_used; +int datapos, dataline, linenum, out_linenum; +FILE *skelfile = NULL; +int skel_ind = 0; +char *action_array; +int action_size, defs1_offset, prolog_offset, action_offset, + + action_index; +char *infilename = NULL, *outfilename = NULL, *headerfilename = NULL; +int did_outfilename; +char *prefix, *yyclass; +int do_stdinit, use_stdout; +int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE]; +int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp; +int maximum_mns, current_mns, current_max_rules; +int num_rules, num_eof_rules, default_rule, lastnfa; +int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2; +int *accptnum, *assoc_rule, *state_type; +int *rule_type, *rule_linenum, *rule_useful; +int current_state_type; +int variable_trailing_context_rules; +int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP]; +int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE]; +int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs, + tecfwd[CSIZE + 1]; +int tecbck[CSIZE + 1]; +int lastsc, *scset, *scbol, *scxclu, *sceof; +int current_max_scs; +char **scname; +int current_max_dfa_size, current_max_xpairs; +int current_max_template_xpairs, current_max_dfas; +int lastdfa, *nxt, *chk, *tnxt; +int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz; union dfaacc_union *dfaacc; -int *accsiz, *dhash, numas; -int numsnpairs, jambase, jamstate; -int lastccl, *cclmap, *ccllen, *cclng, cclreuse; -int current_maxccls, current_max_ccl_tbl_size; -Char *ccltbl; -char nmstr[MAXLINE]; -int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs; -int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave; -int num_backing_up, bol_needed; -FILE *backing_up_file; -int end_of_buffer_state; -char **input_files; -int num_input_files; +int *accsiz, *dhash, numas; +int numsnpairs, jambase, jamstate; +int lastccl, *cclmap, *ccllen, *cclng, cclreuse; +int current_maxccls, current_max_ccl_tbl_size; +Char *ccltbl; +char nmstr[MAXLINE]; +int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs; +int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave; +int num_backing_up, bol_needed; +FILE *backing_up_file; +int end_of_buffer_state; +char **input_files; +int num_input_files; jmp_buf flex_main_jmp_buf; -bool *rule_has_nl, *ccl_has_nl; -int nlch = '\n'; +bool *rule_has_nl, *ccl_has_nl; +int nlch = '\n'; -bool tablesext, tablestoggle; -char* tablesfilename; -FILE* tablesout; +bool tablesext, tablestoggle; +char *tablesfilename; +FILE *tablesout; /* Make sure program_name is initialized so we don't crash if writing * out an error message before getting the program name from argv[0]. */ -char *program_name = "flex"; +char *program_name = "flex"; #ifndef SHORT_FILE_NAMES static char *outfile_template = "lex.%s.%s"; @@ -130,15 +136,15 @@ static char outfile_path[MAXLINE]; static int outfile_created = 0; static char *skelname = NULL; -int flex_main PROTO((int argc,char *argv[])); -int main PROTO((int argc,char *argv[])); -void fix_line_dirs PROTO(( char *, char *, char *, int )); +int flex_main PROTO ((int argc, char *argv[])); +int main PROTO ((int argc, char *argv[])); +void fix_line_dirs PROTO ((char *, char *, char *, int)); -int flex_main( argc, argv ) -int argc; -char *argv[]; - { - int i,exit_status; +int flex_main (argc, argv) + int argc; + char *argv[]; +{ + int i, exit_status; /* Set a longjmp target. Yes, I know it's a hack, but it gets worse: The * return value of setjmp, if non-zero, is the desired exit code PLUS ONE. @@ -147,67 +153,67 @@ char *argv[]; * specify a value of 0 to longjmp. FLEX_EXIT(n) should be used instead of * exit(n); */ - exit_status = setjmp(flex_main_jmp_buf); - if ( exit_status ) + exit_status = setjmp (flex_main_jmp_buf); + if (exit_status) return exit_status - 1; - flexinit( argc, argv ); + flexinit (argc, argv); - readin(); + readin (); - ntod(); + ntod (); - for ( i = 1; i <= num_rules; ++i ) - if ( ! rule_useful[i] && i != default_rule ) - line_warning( _( "rule cannot be matched" ), - rule_linenum[i] ); + for (i = 1; i <= num_rules; ++i) + if (!rule_useful[i] && i != default_rule) + line_warning (_("rule cannot be matched"), + rule_linenum[i]); - if ( spprdflt && ! reject && rule_useful[default_rule] ) - line_warning( - _( "-s option given but default rule can be matched" ), - rule_linenum[default_rule] ); + if (spprdflt && !reject && rule_useful[default_rule]) + line_warning (_ + ("-s option given but default rule can be matched"), +rule_linenum[default_rule]); /* Generate the C state transition tables from the DFA. */ - make_tables(); + make_tables (); /* Note, flexend does not return. It exits with its argument * as status. */ - flexend( 0 ); + flexend (0); - return 0; /* keep compilers/lint happy */ - } + return 0; /* keep compilers/lint happy */ +} /* Wrapper around flex_main, so flex_main can be built as a library. */ -int main( argc, argv ) - int argc; - char *argv[]; +int main (argc, argv) + int argc; + char *argv[]; { #if ENABLE_NLS - setlocale(LC_MESSAGES, ""); - textdomain(PACKAGE); - bindtextdomain(PACKAGE, LOCALEDIR); + setlocale (LC_MESSAGES, ""); + textdomain (PACKAGE); + bindtextdomain (PACKAGE, LOCALEDIR); #endif - return flex_main(argc,argv); + return flex_main (argc, argv); } /* check_options - check user-specified options */ -void check_options() - { - int i; +void check_options () +{ + int i; - if ( lex_compat ) - { - if ( C_plus_plus ) - flexerror( _( "Can't use -+ with -l option" ) ); + if (lex_compat) { + if (C_plus_plus) + flexerror (_("Can't use -+ with -l option")); - if ( fulltbl || fullspd ) - flexerror( _( "Can't use -f or -F with -l option" ) ); + if (fulltbl || fullspd) + flexerror (_("Can't use -f or -F with -l option")); - if( reentrant || reentrant_bison_pure ) - flexerror( _( "Can't use -R or -Rb with -l option" ) ); + if (reentrant || reentrant_bison_pure) + flexerror (_ + ("Can't use -R or -Rb with -l option")); /* Don't rely on detecting use of yymore() and REJECT, * just assume they'll be used. @@ -217,264 +223,254 @@ void check_options() yytext_is_array = true; do_yylineno = true; use_read = false; - } + } /* See comments in flexend() for an explanation of this error condition. */ - if ( use_stdout && headerfilename ) - flexerror( _( "Can't specify header option if writing to stdout.") ); + if (use_stdout && headerfilename) + flexerror (_ + ("Can't specify header option if writing to stdout.")); #if 0 - /* This makes no sense whatsoever. I'm removing it. */ - if ( do_yylineno ) + /* This makes no sense whatsoever. I'm removing it. */ + if (do_yylineno) /* This should really be "maintain_backup_tables = true" */ reject_really_used = true; #endif - if ( csize == unspecified ) - { - if ( (fulltbl || fullspd) && ! useecs ) + if (csize == unspecified) { + if ((fulltbl || fullspd) && !useecs) csize = DEFAULT_CSIZE; else csize = CSIZE; - } + } - if ( interactive == unspecified ) - { - if ( fulltbl || fullspd ) + if (interactive == unspecified) { + if (fulltbl || fullspd) interactive = false; else interactive = true; - } + } - if ( fulltbl || fullspd ) - { - if ( usemecs ) - flexerror( - _( "-Cf/-CF and -Cm don't make sense together" ) ); + if (fulltbl || fullspd) { + if (usemecs) + flexerror (_ + ("-Cf/-CF and -Cm don't make sense together")); - if ( interactive ) - flexerror( _( "-Cf/-CF and -I are incompatible" ) ); + if (interactive) + flexerror (_("-Cf/-CF and -I are incompatible")); - if ( lex_compat ) - flexerror( - _( "-Cf/-CF are incompatible with lex-compatibility mode" ) ); + if (lex_compat) + flexerror (_ + ("-Cf/-CF are incompatible with lex-compatibility mode")); - if ( fulltbl && fullspd ) - flexerror( _( "-Cf and -CF are mutually exclusive" ) ); - } + if (fulltbl && fullspd) + flexerror (_ + ("-Cf and -CF are mutually exclusive")); + } - if ( C_plus_plus && fullspd ) - flexerror( _( "Can't use -+ with -CF option" ) ); + if (C_plus_plus && fullspd) + flexerror (_("Can't use -+ with -CF option")); - if ( C_plus_plus && yytext_is_array ) - { - warn( _( "%array incompatible with -+ option" ) ); + if (C_plus_plus && yytext_is_array) { + warn (_("%array incompatible with -+ option")); yytext_is_array = false; - } + } - if ( C_plus_plus && (reentrant || reentrant_bison_pure) ) - flexerror( _( "Options -+ and -R are mutually exclusive." ) ); + if (C_plus_plus && (reentrant || reentrant_bison_pure)) + flexerror (_("Options -+ and -R are mutually exclusive.")); - if ( useecs ) - { /* Set up doubly-linked equivalence classes. */ + if (useecs) { /* Set up doubly-linked equivalence classes. */ /* We loop all the way up to csize, since ecgroup[csize] is * the position used for NUL characters. */ ecgroup[1] = NIL; - for ( i = 2; i <= csize; ++i ) - { + for (i = 2; i <= csize; ++i) { ecgroup[i] = i - 1; nextecm[i - 1] = i; - } + } nextecm[csize] = NIL; - } + } - else - { + else { /* Put everything in its own equivalence class. */ - for ( i = 1; i <= csize; ++i ) - { + for (i = 1; i <= csize; ++i) { ecgroup[i] = i; nextecm[i] = BAD_SUBSCRIPT; /* to catch errors */ - } } + } - if ( ! use_stdout ) - { - FILE *prev_stdout; + if (!use_stdout) { + FILE *prev_stdout; - if ( ! did_outfilename ) - { - char *suffix; + if (!did_outfilename) { + char *suffix; - if ( C_plus_plus ) + if (C_plus_plus) suffix = "cc"; else suffix = "c"; - sprintf( outfile_path, outfile_template, - prefix, suffix ); + sprintf (outfile_path, outfile_template, + prefix, suffix); outfilename = outfile_path; - } + } - prev_stdout = freopen( outfilename, "w+", stdout ); + prev_stdout = freopen (outfilename, "w+", stdout); - if ( prev_stdout == NULL ) - lerrsf( _( "could not create %s" ), outfilename ); + if (prev_stdout == NULL) + lerrsf (_("could not create %s"), outfilename); outfile_created = 1; - } + } - if ( skelname && (skelfile = fopen( skelname, "r" )) == NULL ) - lerrsf( _( "can't open skeleton file %s" ), skelname ); + if (skelname && (skelfile = fopen (skelname, "r")) == NULL) + lerrsf (_("can't open skeleton file %s"), skelname); - if ( reentrant ) - { - outn("#define YY_REENTRANT 1"); - if( yytext_is_array ) - outn("#define YY_TEXT_IS_ARRAY"); - } + if (reentrant) { + outn ("#define YY_REENTRANT 1"); + if (yytext_is_array) + outn ("#define YY_TEXT_IS_ARRAY"); + } - if ( reentrant_bison_pure ) - outn("#define YY_REENTRANT_BISON_PURE 1"); + if (reentrant_bison_pure) + outn ("#define YY_REENTRANT_BISON_PURE 1"); - if ( strcmp( prefix, "yy" ) ) - { + if (strcmp (prefix, "yy")) { #define GEN_PREFIX(name) out_str3( "#define yy%s %s%s\n", name, prefix, name ) - if ( C_plus_plus ) - GEN_PREFIX( "FlexLexer" ); - else - { - outn( "#ifndef YY_REENTRANT" ); - GEN_PREFIX( "text" ); - GEN_PREFIX( "leng" ); - GEN_PREFIX( "in" ); - GEN_PREFIX( "out" ); - GEN_PREFIX( "_flex_debug" ); - outn( "#endif" ); - GEN_PREFIX( "_create_buffer" ); - GEN_PREFIX( "_delete_buffer" ); - GEN_PREFIX( "_scan_buffer" ); - GEN_PREFIX( "_scan_string" ); - GEN_PREFIX( "_scan_bytes" ); - GEN_PREFIX( "_init_buffer" ); - GEN_PREFIX( "_flush_buffer" ); - GEN_PREFIX( "_load_buffer_state" ); - GEN_PREFIX( "_switch_to_buffer" ); - GEN_PREFIX( "lex" ); - GEN_PREFIX( "restart" ); - GEN_PREFIX( "lex_init" ); - GEN_PREFIX( "lex_destroy" ); - GEN_PREFIX( "get_debug" ); - GEN_PREFIX( "set_debug" ); - GEN_PREFIX( "get_extra" ); - GEN_PREFIX( "set_extra" ); - GEN_PREFIX( "get_in" ); - GEN_PREFIX( "set_in" ); - GEN_PREFIX( "get_out" ); - GEN_PREFIX( "set_out" ); - GEN_PREFIX( "get_leng" ); - GEN_PREFIX( "get_text" ); - GEN_PREFIX( "get_lineno" ); - GEN_PREFIX( "set_lineno" ); - GEN_PREFIX( "alloc" ); - GEN_PREFIX( "realloc" ); - GEN_PREFIX( "free" ); - - outn( "#ifdef YY_REENTRANT_BISON_PURE" ); - GEN_PREFIX( "get_lval" ); - GEN_PREFIX( "set_lval" ); - GEN_PREFIX( "get_lloc" ); - GEN_PREFIX( "set_lloc" ); - outn( "#endif" ); + if (C_plus_plus) + GEN_PREFIX ("FlexLexer"); + else { + outn ("#ifndef YY_REENTRANT"); + GEN_PREFIX ("text"); + GEN_PREFIX ("leng"); + GEN_PREFIX ("in"); + GEN_PREFIX ("out"); + GEN_PREFIX ("_flex_debug"); + outn ("#endif"); + GEN_PREFIX ("_create_buffer"); + GEN_PREFIX ("_delete_buffer"); + GEN_PREFIX ("_scan_buffer"); + GEN_PREFIX ("_scan_string"); + GEN_PREFIX ("_scan_bytes"); + GEN_PREFIX ("_init_buffer"); + GEN_PREFIX ("_flush_buffer"); + GEN_PREFIX ("_load_buffer_state"); + GEN_PREFIX ("_switch_to_buffer"); + GEN_PREFIX ("lex"); + GEN_PREFIX ("restart"); + GEN_PREFIX ("lex_init"); + GEN_PREFIX ("lex_destroy"); + GEN_PREFIX ("get_debug"); + GEN_PREFIX ("set_debug"); + GEN_PREFIX ("get_extra"); + GEN_PREFIX ("set_extra"); + GEN_PREFIX ("get_in"); + GEN_PREFIX ("set_in"); + GEN_PREFIX ("get_out"); + GEN_PREFIX ("set_out"); + GEN_PREFIX ("get_leng"); + GEN_PREFIX ("get_text"); + GEN_PREFIX ("get_lineno"); + GEN_PREFIX ("set_lineno"); + GEN_PREFIX ("alloc"); + GEN_PREFIX ("realloc"); + GEN_PREFIX ("free"); + + outn ("#ifdef YY_REENTRANT_BISON_PURE"); + GEN_PREFIX ("get_lval"); + GEN_PREFIX ("set_lval"); + GEN_PREFIX ("get_lloc"); + GEN_PREFIX ("set_lloc"); + outn ("#endif"); - } + } - if ( do_yylineno && !reentrant ) - GEN_PREFIX( "lineno" ); + if (do_yylineno && !reentrant) + GEN_PREFIX ("lineno"); - if ( do_yywrap ) - GEN_PREFIX( "wrap" ); + if (do_yywrap) + GEN_PREFIX ("wrap"); - outn( "" ); - } + outn (""); + } - if ( did_outfilename ) - line_directive_out( stdout, 0 ); + if (did_outfilename) + line_directive_out (stdout, 0); - if ( do_yylineno ) - buf_strdefine(&userdef_buf,"YY_USE_LINENO","1"); + if (do_yylineno) + buf_strdefine (&userdef_buf, "YY_USE_LINENO", "1"); /* Create the alignment type. */ - buf_strdefine(&userdef_buf,"YY_INT_ALIGNED", - long_align ? "long int" : "short int"); + buf_strdefine (&userdef_buf, "YY_INT_ALIGNED", + long_align ? "long int" : "short int"); /* Dump the user defined preproc directives. */ if (userdef_buf.elts) - outn( (char*)(userdef_buf.elts) ); + outn ((char *) (userdef_buf.elts)); - skelout(); - /* %% [1.0] */ - } + skelout (); + /* %% [1.0] */ +} /* Alter #line directives from the generated source, destined * for the generated header. We chaneg the line number and filename. * linebuf is modified in place. */ -void fix_line_dirs(linebuf, outfilename, headerfilename, nlines) -char * linebuf; -char * outfilename; -char * headerfilename; -int nlines; +void fix_line_dirs (linebuf, outfilename, headerfilename, nlines) + char *linebuf; + char *outfilename; + char *headerfilename; + int nlines; { - char *pname, *p; - /* Match pattern: ^#line +[:digit:]+ +"outfilename" */ - p = linebuf; - if (strncmp(p, "#line ", 6)) - return; - p += 6; - - /* match spaces */ - while (*p == ' ') - p++; - if (!isdigit(*p)) - return; - - /* match numbers */ - while (isdigit(*p)) - p++; - if (*p != ' ') - return; - - /* match spaces */ - while (*p == ' ') - p++; - if (*p != '"') - return; - p++; - - pname = p; - - /* find end of filename. Note: If scanner filename has - * embedded '"' chars, then the generated #line directive - * may fail. */ - while (*p != '\0' && *p != '"') - p++; - if (*p != '"') - return; - - if (strncmp(pname, outfilename, p-pname) != 0) - return; - - /* We have a match. */ - - sprintf(linebuf,"#line %d \"%s\"\n", nlines+2, headerfilename); + char *pname, *p; + + /* Match pattern: ^#line +[:digit:]+ +"outfilename" */ + p = linebuf; + if (strncmp (p, "#line ", 6)) + return; + p += 6; + + /* match spaces */ + while (*p == ' ') + p++; + if (!isdigit (*p)) + return; + + /* match numbers */ + while (isdigit (*p)) + p++; + if (*p != ' ') + return; + + /* match spaces */ + while (*p == ' ') + p++; + if (*p != '"') + return; + p++; + + pname = p; + + /* find end of filename. Note: If scanner filename has + * embedded '"' chars, then the generated #line directive + * may fail. */ + while (*p != '\0' && *p != '"') + p++; + if (*p != '"') + return; + + if (strncmp (pname, outfilename, p - pname) != 0) + return; + + /* We have a match. */ + + sprintf (linebuf, "#line %d \"%s\"\n", nlines + 2, headerfilename); } /* flexend - terminate flex @@ -483,27 +479,26 @@ int nlines; * This routine does not return. */ -void flexend( exit_status ) -int exit_status; +void flexend (exit_status) + int exit_status; - { - static int called_before = -1; /* prevent infinite recursion. */ - int tblsiz; - int i; +{ + static int called_before = -1; /* prevent infinite recursion. */ + int tblsiz; + int i; - if( ++called_before ) - FLEX_EXIT( exit_status ); + if (++called_before) + FLEX_EXIT (exit_status); - if ( skelfile != NULL ) - { - if ( ferror( skelfile ) ) - lerrsf( _( "input error reading skeleton file %s" ), - skelname ); + if (skelfile != NULL) { + if (ferror (skelfile)) + lerrsf (_("input error reading skeleton file %s"), + skelname); - else if ( fclose( skelfile ) ) - lerrsf( _( "error closing skeleton file %s" ), - skelname ); - } + else if (fclose (skelfile)) + lerrsf (_("error closing skeleton file %s"), + skelname); + } /* flex generates the header file by rewinding the output FILE * pointer. However, since we can't rewind stdout, we must disallow @@ -515,907 +510,954 @@ int exit_status; * reason we currently can't provide a mechanism to allow the user * to inject arbitrary class members into the generated C++ scanner. - JM */ - if ( headerfilename && exit_status == 0 && outfile_created && !ferror(stdout)) - { - /* Copy the file we just wrote to a header file. */ + if (headerfilename && exit_status == 0 && outfile_created + && !ferror (stdout)) { + /* Copy the file we just wrote to a header file. */ #define LINE_SZ 512 - FILE *header_out; - char linebuf[LINE_SZ]; - int nlines=0; - int discard = 0; - - /* rewind the outfile file. */ - fflush(stdout); - fseek(stdout, 0L, SEEK_SET); - - header_out = fopen(headerfilename, "w"); - if ( header_out == NULL) - lerrsf( _( "could not create %s"), headerfilename ); - - fprintf(header_out, "#ifndef %sHEADER_H\n", prefix); - fprintf(header_out, "#define %sHEADER_H 1\n",prefix); - fprintf(header_out, "#define %sIN_HEADER 1\n\n",prefix); - fflush(header_out); - - nlines=4; - while(fgets(linebuf, LINE_SZ, stdout)) { - if (strstr(linebuf, "YY-DISCARD-FROM-HEADER")) - discard++; - else if (strstr(linebuf, "YY-END-DISCARD-FROM-HEADER")){ - discard--; - continue; - } - - if (discard) - continue; - - fix_line_dirs(linebuf, outfilename, headerfilename, nlines); - fputs(linebuf, header_out); - nlines++; - } - - fprintf(header_out,"#line %d \"%s\"\n", (++nlines)+1, headerfilename); - - /* Print the start conditions. */ - fprintf(header_out,"#ifdef YY_HEADER_EXPORT_START_CONDITIONS\n"); - fprintf(header_out,"/* Beware! Start conditions are not prefixed. */\n"); - - /* Special case for "INITIAL" */ - fprintf(header_out,"#undef INITIAL\n#define INITIAL 0\n"); - for (i=2; i <= lastsc; i++) - fprintf(header_out, "#define %s %d\n",scname[i], i-1); - fprintf(header_out,"#endif /* YY_HEADER_EXPORT_START_CONDITIONS */\n\n"); - - /* Kill ALL flex-related macros. This is so the user - * can #include more than one generated header file. */ - fprintf(header_out,"#ifndef YY_HEADER_NO_UNDEFS\n"); - fprintf(header_out,"/* Undefine all internal macros, etc., that do no belong in the header. */\n\n"); - - fprintf(header_out,"#undef BEGIN\n"); - fprintf(header_out,"#undef ECHO\n"); - fprintf(header_out,"#undef EOB_ACT_CONTINUE_SCAN\n"); - fprintf(header_out,"#undef EOB_ACT_END_OF_FILE\n"); - fprintf(header_out,"#undef EOB_ACT_LAST_MATCH\n"); - fprintf(header_out,"#undef FLEX_SCANNER\n"); - fprintf(header_out,"#undef FLEX_STD\n"); - fprintf(header_out,"#undef REJECT\n"); - fprintf(header_out,"#undef YYLMAX\n"); - fprintf(header_out,"#undef YYSTATE\n"); - fprintf(header_out,"#undef YY_AT_BOL\n"); - fprintf(header_out,"#undef YY_BREAK\n"); - fprintf(header_out,"#undef YY_BUFFER_EOF_PENDING\n"); - fprintf(header_out,"#undef YY_BUFFER_NEW\n"); - fprintf(header_out,"#undef YY_BUFFER_NORMAL\n"); - fprintf(header_out,"#undef YY_BUF_SIZE\n"); - fprintf(header_out,"#undef YY_CALL_LAST_ARG\n"); - fprintf(header_out,"#undef YY_CALL_ONLY_ARG\n"); - fprintf(header_out,"#undef YY_CURRENT_BUFFER\n"); - fprintf(header_out,"#undef YY_DECL\n"); - fprintf(header_out,"#undef YY_DECL_LAST_ARG\n"); - fprintf(header_out,"#undef YY_DO_BEFORE_ACTION\n"); - fprintf(header_out,"#undef YY_END_OF_BUFFER\n"); - fprintf(header_out,"#undef YY_END_OF_BUFFER_CHAR\n"); - fprintf(header_out,"#undef YY_EXIT_FAILURE\n"); - fprintf(header_out,"#undef YY_EXTRA_TYPE\n"); - fprintf(header_out,"#undef YY_FATAL_ERROR\n"); - fprintf(header_out,"#undef YY_FLEX_DEFINED_ECHO\n"); - fprintf(header_out,"#undef YY_FLEX_LEX_COMPAT\n"); - fprintf(header_out,"#undef YY_FLEX_MAJOR_VERSION\n"); - fprintf(header_out,"#undef YY_FLEX_MINOR_VERSION\n"); - fprintf(header_out,"#undef YY_FLUSH_BUFFER\n"); - fprintf(header_out,"#undef YY_G\n"); - fprintf(header_out,"#undef YY_INPUT\n"); - fprintf(header_out,"#undef YY_INT_ALIGNED\n"); - fprintf(header_out,"#undef YY_INTERACTIVE\n"); - fprintf(header_out,"#undef YY_LAST_ARG\n"); - fprintf(header_out,"#undef YY_LEX_ARGS\n"); - fprintf(header_out,"#undef YY_MAIN\n"); - fprintf(header_out,"#undef YY_MORE_ADJ\n"); - fprintf(header_out,"#undef YY_NEED_STRLEN\n"); - fprintf(header_out,"#undef YY_NEW_FILE\n"); - fprintf(header_out,"#undef YY_NO_FLEX_ALLOC\n"); - fprintf(header_out,"#undef YY_NO_FLEX_REALLOC\n"); - fprintf(header_out,"#undef YY_NO_FLEX_FREE\n"); - fprintf(header_out,"#undef YY_NO_GET_DEBUG\n"); - fprintf(header_out,"#undef YY_NO_GET_EXTRA\n"); - fprintf(header_out,"#undef YY_NO_GET_IN\n"); - fprintf(header_out,"#undef YY_NO_GET_LENG\n"); - fprintf(header_out,"#undef YY_NO_GET_LINENO\n"); - fprintf(header_out,"#undef YY_NO_GET_LLOC\n"); - fprintf(header_out,"#undef YY_NO_GET_LVAL\n"); - fprintf(header_out,"#undef YY_NO_GET_OUT\n"); - fprintf(header_out,"#undef YY_NO_GET_TEXT\n"); - fprintf(header_out,"#undef YY_NO_INPUT\n"); - fprintf(header_out,"#undef YY_NO_POP_STATE\n"); - fprintf(header_out,"#undef YY_NO_PUSH_STATE\n"); - fprintf(header_out,"#undef YY_NO_SCAN_BUFFER\n"); - fprintf(header_out,"#undef YY_NO_SCAN_BYTES\n"); - fprintf(header_out,"#undef YY_NO_SCAN_STRING\n"); - fprintf(header_out,"#undef YY_NO_SET_DEBUG\n"); - fprintf(header_out,"#undef YY_NO_SET_EXTRA\n"); - fprintf(header_out,"#undef YY_NO_SET_IN\n"); - fprintf(header_out,"#undef YY_NO_SET_LINENO\n"); - fprintf(header_out,"#undef YY_NO_SET_LLOC\n"); - fprintf(header_out,"#undef YY_NO_SET_LVAL\n"); - fprintf(header_out,"#undef YY_NO_SET_OUT\n"); - fprintf(header_out,"#undef YY_NO_TOP_STATE\n"); - fprintf(header_out,"#undef YY_NO_UNISTD_H\n"); - fprintf(header_out,"#undef YY_NO_UNPUT\n"); - fprintf(header_out,"#undef YY_NULL\n"); - fprintf(header_out,"#undef YY_NUM_RULES\n"); - fprintf(header_out,"#undef YY_ONLY_ARG\n"); - fprintf(header_out,"#undef YY_PROTO\n"); - fprintf(header_out,"#undef YY_READ_BUF_SIZE\n"); - fprintf(header_out,"#undef YY_REENTRANT\n"); - fprintf(header_out,"#undef YY_REENTRANT_BISON_PURE\n"); - fprintf(header_out,"#undef YY_RESTORE_YY_MORE_OFFSET\n"); - fprintf(header_out,"#undef YY_RULE_SETUP\n"); - fprintf(header_out,"#undef YY_SC_TO_UI\n"); - fprintf(header_out,"#undef YY_SKIP_YYWRAP\n"); - fprintf(header_out,"#undef YY_STACK_USED\n"); - fprintf(header_out,"#undef YY_START\n"); - fprintf(header_out,"#undef YY_START_STACK_INCR\n"); - fprintf(header_out,"#undef YY_STATE_EOF\n"); - fprintf(header_out,"#undef YY_STDINIT\n"); - fprintf(header_out,"#undef YY_TEXT_IS_ARRAY\n"); - fprintf(header_out,"#undef YY_TRAILING_HEAD_MASK\n"); - fprintf(header_out,"#undef YY_TRAILING_MASK\n"); - fprintf(header_out,"#undef YY_USER_ACTION\n"); - fprintf(header_out,"#undef YY_USES_REJECT\n"); - fprintf(header_out,"#undef YY_USE_CONST\n"); - fprintf(header_out,"#undef YY_USE_LINENO\n"); - fprintf(header_out,"#undef YY_USE_PROTOS\n"); - fprintf(header_out,"#undef unput\n"); - fprintf(header_out,"#undef yy_create_buffer\n"); - fprintf(header_out,"#undef yy_delete_buffer\n"); - fprintf(header_out,"#undef yy_flex_debug\n"); - fprintf(header_out,"#undef yy_flush_buffer\n"); - fprintf(header_out,"#undef yy_init_buffer\n"); - fprintf(header_out,"#undef yy_load_buffer_state\n"); - fprintf(header_out,"#undef yy_new_buffer\n"); - fprintf(header_out,"#undef yy_scan_buffer\n"); - fprintf(header_out,"#undef yy_scan_bytes\n"); - fprintf(header_out,"#undef yy_scan_string\n"); - fprintf(header_out,"#undef yy_set_bol\n"); - fprintf(header_out,"#undef yy_set_interactive\n"); - fprintf(header_out,"#undef yy_switch_to_buffer\n"); - fprintf(header_out,"#undef yyconst\n"); - fprintf(header_out,"#undef yyextra\n"); - fprintf(header_out,"#undef yyget_debug\n"); - fprintf(header_out,"#undef yyset_debug\n"); - fprintf(header_out,"#undef yyget_extra\n"); - fprintf(header_out,"#undef yyget_in\n"); - fprintf(header_out,"#undef yyget_leng\n"); - fprintf(header_out,"#undef yyget_lineno\n"); - fprintf(header_out,"#undef yyget_lloc\n"); - fprintf(header_out,"#undef yyget_lval\n"); - fprintf(header_out,"#undef yyget_out\n"); - fprintf(header_out,"#undef yyget_text\n"); - fprintf(header_out,"#undef yyin\n"); - fprintf(header_out,"#undef yyleng\n"); - fprintf(header_out,"#undef yyless\n"); - fprintf(header_out,"#undef yylex\n"); - fprintf(header_out,"#undef yylex_destroy\n"); - fprintf(header_out,"#undef yylex_init\n"); - fprintf(header_out,"#undef yylineno\n"); - fprintf(header_out,"#undef yylloc\n"); - fprintf(header_out,"#undef yylval\n"); - fprintf(header_out,"#undef yymore\n"); - fprintf(header_out,"#undef yyout\n"); - fprintf(header_out,"#undef yyrestart\n"); - fprintf(header_out,"#undef yyset_extra\n"); - fprintf(header_out,"#undef yyset_in\n"); - fprintf(header_out,"#undef yyset_lineno\n"); - fprintf(header_out,"#undef yyset_lloc\n"); - fprintf(header_out,"#undef yyset_lval\n"); - fprintf(header_out,"#undef yyset_out\n"); - fprintf(header_out,"#undef yyterminate\n"); - fprintf(header_out,"#undef yytext\n"); - fprintf(header_out,"#undef yytext_ptr\n"); - fprintf(header_out,"#undef yywrap\n"); - fprintf(header_out,"#undef yyalloc\n"); - fprintf(header_out,"#undef yyrealloc\n"); - fprintf(header_out,"#undef yyfree\n"); - - /* undef any of the auto-generated symbols. */ - for(i=0; i < defs_buf.nelts; i++){ - - /* don't undef start conditions */ - if (sclookup(((char**)defs_buf.elts)[i]) > 0 ) - continue; - fprintf(header_out, "#undef %s\n", ((char**)defs_buf.elts)[i]); - } - - fprintf(header_out,"#endif /* !YY_HEADER_NO_UNDEFS */\n"); - fprintf(header_out, "\n"); - fprintf(header_out, "#undef %sIN_HEADER\n", prefix); - fprintf(header_out, "#endif /* %sHEADER_H */\n", prefix); - - if ( ferror( header_out ) ) - lerrsf( _( "error creating header file %s" ), headerfilename); - fflush(header_out); - fclose(header_out); - } + FILE *header_out; + char linebuf[LINE_SZ]; + int nlines = 0; + int discard = 0; + + /* rewind the outfile file. */ + fflush (stdout); + fseek (stdout, 0L, SEEK_SET); + + header_out = fopen (headerfilename, "w"); + if (header_out == NULL) + lerrsf (_("could not create %s"), headerfilename); + + fprintf (header_out, "#ifndef %sHEADER_H\n", prefix); + fprintf (header_out, "#define %sHEADER_H 1\n", prefix); + fprintf (header_out, "#define %sIN_HEADER 1\n\n", prefix); + fflush (header_out); + + nlines = 4; + while (fgets (linebuf, LINE_SZ, stdout)) { + if (strstr (linebuf, "YY-DISCARD-FROM-HEADER")) + discard++; + else + if (strstr + (linebuf, + "YY-END-DISCARD-FROM-HEADER")) { + discard--; + continue; + } - if ( exit_status != 0 && outfile_created ) - { - if ( ferror( stdout ) ) - lerrsf( _( "error writing output file %s" ), - outfilename ); + if (discard) + continue; - else if ( fclose( stdout ) ) - lerrsf( _( "error closing output file %s" ), - outfilename ); + fix_line_dirs (linebuf, outfilename, + headerfilename, nlines); + fputs (linebuf, header_out); + nlines++; + } - else if ( unlink( outfilename ) ) - lerrsf( _( "error deleting output file %s" ), - outfilename ); + fprintf (header_out, "#line %d \"%s\"\n", (++nlines) + 1, + headerfilename); + + /* Print the start conditions. */ + fprintf (header_out, + "#ifdef YY_HEADER_EXPORT_START_CONDITIONS\n"); + fprintf (header_out, + "/* Beware! Start conditions are not prefixed. */\n"); + + /* Special case for "INITIAL" */ + fprintf (header_out, + "#undef INITIAL\n#define INITIAL 0\n"); + for (i = 2; i <= lastsc; i++) + fprintf (header_out, "#define %s %d\n", scname[i], + i - 1); + fprintf (header_out, + "#endif /* YY_HEADER_EXPORT_START_CONDITIONS */\n\n"); + + /* Kill ALL flex-related macros. This is so the user + * can #include more than one generated header file. */ + fprintf (header_out, "#ifndef YY_HEADER_NO_UNDEFS\n"); + fprintf (header_out, + "/* Undefine all internal macros, etc., that do no belong in the header. */\n\n"); + + fprintf (header_out, "#undef BEGIN\n"); + fprintf (header_out, "#undef ECHO\n"); + fprintf (header_out, "#undef EOB_ACT_CONTINUE_SCAN\n"); + fprintf (header_out, "#undef EOB_ACT_END_OF_FILE\n"); + fprintf (header_out, "#undef EOB_ACT_LAST_MATCH\n"); + fprintf (header_out, "#undef FLEX_SCANNER\n"); + fprintf (header_out, "#undef FLEX_STD\n"); + fprintf (header_out, "#undef REJECT\n"); + fprintf (header_out, "#undef YYLMAX\n"); + fprintf (header_out, "#undef YYSTATE\n"); + fprintf (header_out, "#undef YY_AT_BOL\n"); + fprintf (header_out, "#undef YY_BREAK\n"); + fprintf (header_out, "#undef YY_BUFFER_EOF_PENDING\n"); + fprintf (header_out, "#undef YY_BUFFER_NEW\n"); + fprintf (header_out, "#undef YY_BUFFER_NORMAL\n"); + fprintf (header_out, "#undef YY_BUF_SIZE\n"); + fprintf (header_out, "#undef YY_CALL_LAST_ARG\n"); + fprintf (header_out, "#undef YY_CALL_ONLY_ARG\n"); + fprintf (header_out, "#undef YY_CURRENT_BUFFER\n"); + fprintf (header_out, "#undef YY_DECL\n"); + fprintf (header_out, "#undef YY_DECL_LAST_ARG\n"); + fprintf (header_out, "#undef YY_DO_BEFORE_ACTION\n"); + fprintf (header_out, "#undef YY_END_OF_BUFFER\n"); + fprintf (header_out, "#undef YY_END_OF_BUFFER_CHAR\n"); + fprintf (header_out, "#undef YY_EXIT_FAILURE\n"); + fprintf (header_out, "#undef YY_EXTRA_TYPE\n"); + fprintf (header_out, "#undef YY_FATAL_ERROR\n"); + fprintf (header_out, "#undef YY_FLEX_DEFINED_ECHO\n"); + fprintf (header_out, "#undef YY_FLEX_LEX_COMPAT\n"); + fprintf (header_out, "#undef YY_FLEX_MAJOR_VERSION\n"); + fprintf (header_out, "#undef YY_FLEX_MINOR_VERSION\n"); + fprintf (header_out, "#undef YY_FLUSH_BUFFER\n"); + fprintf (header_out, "#undef YY_G\n"); + fprintf (header_out, "#undef YY_INPUT\n"); + fprintf (header_out, "#undef YY_INT_ALIGNED\n"); + fprintf (header_out, "#undef YY_INTERACTIVE\n"); + fprintf (header_out, "#undef YY_LAST_ARG\n"); + fprintf (header_out, "#undef YY_LEX_ARGS\n"); + fprintf (header_out, "#undef YY_MAIN\n"); + fprintf (header_out, "#undef YY_MORE_ADJ\n"); + fprintf (header_out, "#undef YY_NEED_STRLEN\n"); + fprintf (header_out, "#undef YY_NEW_FILE\n"); + fprintf (header_out, "#undef YY_NO_FLEX_ALLOC\n"); + fprintf (header_out, "#undef YY_NO_FLEX_REALLOC\n"); + fprintf (header_out, "#undef YY_NO_FLEX_FREE\n"); + fprintf (header_out, "#undef YY_NO_GET_DEBUG\n"); + fprintf (header_out, "#undef YY_NO_GET_EXTRA\n"); + fprintf (header_out, "#undef YY_NO_GET_IN\n"); + fprintf (header_out, "#undef YY_NO_GET_LENG\n"); + fprintf (header_out, "#undef YY_NO_GET_LINENO\n"); + fprintf (header_out, "#undef YY_NO_GET_LLOC\n"); + fprintf (header_out, "#undef YY_NO_GET_LVAL\n"); + fprintf (header_out, "#undef YY_NO_GET_OUT\n"); + fprintf (header_out, "#undef YY_NO_GET_TEXT\n"); + fprintf (header_out, "#undef YY_NO_INPUT\n"); + fprintf (header_out, "#undef YY_NO_POP_STATE\n"); + fprintf (header_out, "#undef YY_NO_PUSH_STATE\n"); + fprintf (header_out, "#undef YY_NO_SCAN_BUFFER\n"); + fprintf (header_out, "#undef YY_NO_SCAN_BYTES\n"); + fprintf (header_out, "#undef YY_NO_SCAN_STRING\n"); + fprintf (header_out, "#undef YY_NO_SET_DEBUG\n"); + fprintf (header_out, "#undef YY_NO_SET_EXTRA\n"); + fprintf (header_out, "#undef YY_NO_SET_IN\n"); + fprintf (header_out, "#undef YY_NO_SET_LINENO\n"); + fprintf (header_out, "#undef YY_NO_SET_LLOC\n"); + fprintf (header_out, "#undef YY_NO_SET_LVAL\n"); + fprintf (header_out, "#undef YY_NO_SET_OUT\n"); + fprintf (header_out, "#undef YY_NO_TOP_STATE\n"); + fprintf (header_out, "#undef YY_NO_UNISTD_H\n"); + fprintf (header_out, "#undef YY_NO_UNPUT\n"); + fprintf (header_out, "#undef YY_NULL\n"); + fprintf (header_out, "#undef YY_NUM_RULES\n"); + fprintf (header_out, "#undef YY_ONLY_ARG\n"); + fprintf (header_out, "#undef YY_PROTO\n"); + fprintf (header_out, "#undef YY_READ_BUF_SIZE\n"); + fprintf (header_out, "#undef YY_REENTRANT\n"); + fprintf (header_out, "#undef YY_REENTRANT_BISON_PURE\n"); + fprintf (header_out, "#undef YY_RESTORE_YY_MORE_OFFSET\n"); + fprintf (header_out, "#undef YY_RULE_SETUP\n"); + fprintf (header_out, "#undef YY_SC_TO_UI\n"); + fprintf (header_out, "#undef YY_SKIP_YYWRAP\n"); + fprintf (header_out, "#undef YY_STACK_USED\n"); + fprintf (header_out, "#undef YY_START\n"); + fprintf (header_out, "#undef YY_START_STACK_INCR\n"); + fprintf (header_out, "#undef YY_STATE_EOF\n"); + fprintf (header_out, "#undef YY_STDINIT\n"); + fprintf (header_out, "#undef YY_TEXT_IS_ARRAY\n"); + fprintf (header_out, "#undef YY_TRAILING_HEAD_MASK\n"); + fprintf (header_out, "#undef YY_TRAILING_MASK\n"); + fprintf (header_out, "#undef YY_USER_ACTION\n"); + fprintf (header_out, "#undef YY_USES_REJECT\n"); + fprintf (header_out, "#undef YY_USE_CONST\n"); + fprintf (header_out, "#undef YY_USE_LINENO\n"); + fprintf (header_out, "#undef YY_USE_PROTOS\n"); + fprintf (header_out, "#undef unput\n"); + fprintf (header_out, "#undef yy_create_buffer\n"); + fprintf (header_out, "#undef yy_delete_buffer\n"); + fprintf (header_out, "#undef yy_flex_debug\n"); + fprintf (header_out, "#undef yy_flush_buffer\n"); + fprintf (header_out, "#undef yy_init_buffer\n"); + fprintf (header_out, "#undef yy_load_buffer_state\n"); + fprintf (header_out, "#undef yy_new_buffer\n"); + fprintf (header_out, "#undef yy_scan_buffer\n"); + fprintf (header_out, "#undef yy_scan_bytes\n"); + fprintf (header_out, "#undef yy_scan_string\n"); + fprintf (header_out, "#undef yy_set_bol\n"); + fprintf (header_out, "#undef yy_set_interactive\n"); + fprintf (header_out, "#undef yy_switch_to_buffer\n"); + fprintf (header_out, "#undef yyconst\n"); + fprintf (header_out, "#undef yyextra\n"); + fprintf (header_out, "#undef yyget_debug\n"); + fprintf (header_out, "#undef yyset_debug\n"); + fprintf (header_out, "#undef yyget_extra\n"); + fprintf (header_out, "#undef yyget_in\n"); + fprintf (header_out, "#undef yyget_leng\n"); + fprintf (header_out, "#undef yyget_lineno\n"); + fprintf (header_out, "#undef yyget_lloc\n"); + fprintf (header_out, "#undef yyget_lval\n"); + fprintf (header_out, "#undef yyget_out\n"); + fprintf (header_out, "#undef yyget_text\n"); + fprintf (header_out, "#undef yyin\n"); + fprintf (header_out, "#undef yyleng\n"); + fprintf (header_out, "#undef yyless\n"); + fprintf (header_out, "#undef yylex\n"); + fprintf (header_out, "#undef yylex_destroy\n"); + fprintf (header_out, "#undef yylex_init\n"); + fprintf (header_out, "#undef yylineno\n"); + fprintf (header_out, "#undef yylloc\n"); + fprintf (header_out, "#undef yylval\n"); + fprintf (header_out, "#undef yymore\n"); + fprintf (header_out, "#undef yyout\n"); + fprintf (header_out, "#undef yyrestart\n"); + fprintf (header_out, "#undef yyset_extra\n"); + fprintf (header_out, "#undef yyset_in\n"); + fprintf (header_out, "#undef yyset_lineno\n"); + fprintf (header_out, "#undef yyset_lloc\n"); + fprintf (header_out, "#undef yyset_lval\n"); + fprintf (header_out, "#undef yyset_out\n"); + fprintf (header_out, "#undef yyterminate\n"); + fprintf (header_out, "#undef yytext\n"); + fprintf (header_out, "#undef yytext_ptr\n"); + fprintf (header_out, "#undef yywrap\n"); + fprintf (header_out, "#undef yyalloc\n"); + fprintf (header_out, "#undef yyrealloc\n"); + fprintf (header_out, "#undef yyfree\n"); + + /* undef any of the auto-generated symbols. */ + for (i = 0; i < defs_buf.nelts; i++) { + + /* don't undef start conditions */ + if (sclookup (((char **) defs_buf.elts)[i]) > 0) + continue; + fprintf (header_out, "#undef %s\n", + ((char **) defs_buf.elts)[i]); } + fprintf (header_out, + "#endif /* !YY_HEADER_NO_UNDEFS */\n"); + fprintf (header_out, "\n"); + fprintf (header_out, "#undef %sIN_HEADER\n", prefix); + fprintf (header_out, "#endif /* %sHEADER_H */\n", prefix); + + if (ferror (header_out)) + lerrsf (_("error creating header file %s"), + headerfilename); + fflush (header_out); + fclose (header_out); + } + + if (exit_status != 0 && outfile_created) { + if (ferror (stdout)) + lerrsf (_("error writing output file %s"), + outfilename); + + else if (fclose (stdout)) + lerrsf (_("error closing output file %s"), + outfilename); - if ( backing_up_report && backing_up_file ) - { - if ( num_backing_up == 0 ) - fprintf( backing_up_file, _( "No backing up.\n" ) ); - else if ( fullspd || fulltbl ) - fprintf( backing_up_file, - _( "%d backing up (non-accepting) states.\n" ), - num_backing_up ); + else if (unlink (outfilename)) + lerrsf (_("error deleting output file %s"), + outfilename); + } + + + if (backing_up_report && backing_up_file) { + if (num_backing_up == 0) + fprintf (backing_up_file, _("No backing up.\n")); + else if (fullspd || fulltbl) + fprintf (backing_up_file, + _ + ("%d backing up (non-accepting) states.\n"), + num_backing_up); else - fprintf( backing_up_file, - _( "Compressed tables always back up.\n" ) ); + fprintf (backing_up_file, + _("Compressed tables always back up.\n")); - if ( ferror( backing_up_file ) ) - lerrsf( _( "error writing backup file %s" ), - backing_name ); + if (ferror (backing_up_file)) + lerrsf (_("error writing backup file %s"), + backing_name); - else if ( fclose( backing_up_file ) ) - lerrsf( _( "error closing backup file %s" ), - backing_name ); - } + else if (fclose (backing_up_file)) + lerrsf (_("error closing backup file %s"), + backing_name); + } - if ( printstats ) - { - fprintf( stderr, _( "%s version %s usage statistics:\n" ), - program_name, flex_version ); - - fprintf( stderr, _( " scanner options: -" ) ); - - if ( C_plus_plus ) - putc( '+', stderr ); - if ( backing_up_report ) - putc( 'b', stderr ); - if ( ddebug ) - putc( 'd', stderr ); - if ( caseins ) - putc( 'i', stderr ); - if ( lex_compat ) - putc( 'l', stderr ); - if ( posix_compat ) - putc( 'X', stderr ); - if ( performance_report > 0 ) - putc( 'p', stderr ); - if ( performance_report > 1 ) - putc( 'p', stderr ); - if ( spprdflt ) - putc( 's', stderr ); - if ( reentrant ) - { - putc( 'R', stderr ); - - if( reentrant_bison_pure ) - putc( 'b', stderr ); - } - if ( use_stdout ) - putc( 't', stderr ); - if ( printstats ) - putc( 'v', stderr ); /* always true! */ - if ( nowarn ) - putc( 'w', stderr ); - if ( interactive == false ) - putc( 'B', stderr ); - if ( interactive == true ) - putc( 'I', stderr ); - if ( ! gen_line_dirs ) - putc( 'L', stderr ); - if ( trace ) - putc( 'T', stderr ); - - if ( csize == unspecified ) + if (printstats) { + fprintf (stderr, _("%s version %s usage statistics:\n"), + program_name, flex_version); + + fprintf (stderr, _(" scanner options: -")); + + if (C_plus_plus) + putc ('+', stderr); + if (backing_up_report) + putc ('b', stderr); + if (ddebug) + putc ('d', stderr); + if (caseins) + putc ('i', stderr); + if (lex_compat) + putc ('l', stderr); + if (posix_compat) + putc ('X', stderr); + if (performance_report > 0) + putc ('p', stderr); + if (performance_report > 1) + putc ('p', stderr); + if (spprdflt) + putc ('s', stderr); + if (reentrant) { + putc ('R', stderr); + + if (reentrant_bison_pure) + putc ('b', stderr); + } + if (use_stdout) + putc ('t', stderr); + if (printstats) + putc ('v', stderr); /* always true! */ + if (nowarn) + putc ('w', stderr); + if (interactive == false) + putc ('B', stderr); + if (interactive == true) + putc ('I', stderr); + if (!gen_line_dirs) + putc ('L', stderr); + if (trace) + putc ('T', stderr); + + if (csize == unspecified) /* We encountered an error fairly early on, so csize * never got specified. Define it now, to prevent * bogus table sizes being written out below. */ csize = 256; - if ( csize == 128 ) - putc( '7', stderr ); + if (csize == 128) + putc ('7', stderr); else - putc( '8', stderr ); - - fprintf( stderr, " -C" ); - - if ( long_align ) - putc( 'a', stderr ); - if ( fulltbl ) - putc( 'f', stderr ); - if ( fullspd ) - putc( 'F', stderr ); - if ( useecs ) - putc( 'e', stderr ); - if ( usemecs ) - putc( 'm', stderr ); - if ( use_read ) - putc( 'r', stderr ); - - if ( did_outfilename ) - fprintf( stderr, " -o%s", outfilename ); - - if ( skelname ) - fprintf( stderr, " -S%s", skelname ); - - if ( strcmp( prefix, "yy" ) ) - fprintf( stderr, " -P%s", prefix ); - - putc( '\n', stderr ); - - fprintf( stderr, _( " %d/%d NFA states\n" ), - lastnfa, current_mns ); - fprintf( stderr, _( " %d/%d DFA states (%d words)\n" ), - lastdfa, current_max_dfas, totnst ); - fprintf( stderr, _( " %d rules\n" ), - num_rules + num_eof_rules - 1 /* - 1 for def. rule */ ); - - if ( num_backing_up == 0 ) - fprintf( stderr, _( " No backing up\n" ) ); - else if ( fullspd || fulltbl ) - fprintf( stderr, - _( " %d backing-up (non-accepting) states\n" ), - num_backing_up ); + putc ('8', stderr); + + fprintf (stderr, " -C"); + + if (long_align) + putc ('a', stderr); + if (fulltbl) + putc ('f', stderr); + if (fullspd) + putc ('F', stderr); + if (useecs) + putc ('e', stderr); + if (usemecs) + putc ('m', stderr); + if (use_read) + putc ('r', stderr); + + if (did_outfilename) + fprintf (stderr, " -o%s", outfilename); + + if (skelname) + fprintf (stderr, " -S%s", skelname); + + if (strcmp (prefix, "yy")) + fprintf (stderr, " -P%s", prefix); + + putc ('\n', stderr); + + fprintf (stderr, _(" %d/%d NFA states\n"), + lastnfa, current_mns); + fprintf (stderr, _(" %d/%d DFA states (%d words)\n"), + lastdfa, current_max_dfas, totnst); + fprintf (stderr, _(" %d rules\n"), + num_rules + num_eof_rules - + 1 /* - 1 for def. rule */ ); + + if (num_backing_up == 0) + fprintf (stderr, _(" No backing up\n")); + else if (fullspd || fulltbl) + fprintf (stderr, + _ + (" %d backing-up (non-accepting) states\n"), + num_backing_up); else - fprintf( stderr, - _( " Compressed tables always back-up\n" ) ); - - if ( bol_needed ) - fprintf( stderr, - _( " Beginning-of-line patterns used\n" ) ); - - fprintf( stderr, _( " %d/%d start conditions\n" ), lastsc, - current_max_scs ); - fprintf( stderr, - _( " %d epsilon states, %d double epsilon states\n" ), - numeps, eps2 ); - - if ( lastccl == 0 ) - fprintf( stderr, _( " no character classes\n" ) ); + fprintf (stderr, + _ + (" Compressed tables always back-up\n")); + + if (bol_needed) + fprintf (stderr, + _(" Beginning-of-line patterns used\n")); + + fprintf (stderr, _(" %d/%d start conditions\n"), lastsc, + current_max_scs); + fprintf (stderr, + _ + (" %d epsilon states, %d double epsilon states\n"), + numeps, eps2); + + if (lastccl == 0) + fprintf (stderr, _(" no character classes\n")); else - fprintf( stderr, -_( " %d/%d character classes needed %d/%d words of storage, %d reused\n" ), - lastccl, current_maxccls, - cclmap[lastccl] + ccllen[lastccl], - current_max_ccl_tbl_size, cclreuse ); - - fprintf( stderr, _( " %d state/nextstate pairs created\n" ), - numsnpairs ); - fprintf( stderr, _( " %d/%d unique/duplicate transitions\n" ), - numuniq, numdup ); - - if ( fulltbl ) - { + fprintf (stderr, + _ + (" %d/%d character classes needed %d/%d words of storage, %d reused\n"), + lastccl, current_maxccls, + cclmap[lastccl] + ccllen[lastccl], + current_max_ccl_tbl_size, cclreuse); + + fprintf (stderr, _(" %d state/nextstate pairs created\n"), + numsnpairs); + fprintf (stderr, + _(" %d/%d unique/duplicate transitions\n"), + numuniq, numdup); + + if (fulltbl) { tblsiz = lastdfa * numecs; - fprintf( stderr, _( " %d table entries\n" ), tblsiz ); - } + fprintf (stderr, _(" %d table entries\n"), + tblsiz); + } - else - { + else { tblsiz = 2 * (lastdfa + numtemps) + 2 * tblend; - fprintf( stderr, - _( " %d/%d base-def entries created\n" ), - lastdfa + numtemps, current_max_dfas ); - fprintf( stderr, - _( " %d/%d (peak %d) nxt-chk entries created\n" ), - tblend, current_max_xpairs, peakpairs ); - fprintf( stderr, - _( " %d/%d (peak %d) template nxt-chk entries created\n" ), - numtemps * nummecs, - current_max_template_xpairs, - numtemps * numecs ); - fprintf( stderr, _( " %d empty table entries\n" ), - nummt ); - fprintf( stderr, _( " %d protos created\n" ), - numprots ); - fprintf( stderr, - _( " %d templates created, %d uses\n" ), - numtemps, tmpuses ); - } + fprintf (stderr, + _(" %d/%d base-def entries created\n"), + lastdfa + numtemps, current_max_dfas); + fprintf (stderr, + _ + (" %d/%d (peak %d) nxt-chk entries created\n"), + tblend, current_max_xpairs, peakpairs); + fprintf (stderr, + _ + (" %d/%d (peak %d) template nxt-chk entries created\n"), + numtemps * nummecs, + current_max_template_xpairs, + numtemps * numecs); + fprintf (stderr, _(" %d empty table entries\n"), + nummt); + fprintf (stderr, _(" %d protos created\n"), + numprots); + fprintf (stderr, + _(" %d templates created, %d uses\n"), + numtemps, tmpuses); + } - if ( useecs ) - { + if (useecs) { tblsiz = tblsiz + csize; - fprintf( stderr, - _( " %d/%d equivalence classes created\n" ), - numecs, csize ); - } + fprintf (stderr, + _ + (" %d/%d equivalence classes created\n"), + numecs, csize); + } - if ( usemecs ) - { + if (usemecs) { tblsiz = tblsiz + numecs; - fprintf( stderr, - _( " %d/%d meta-equivalence classes created\n" ), - nummecs, csize ); - } - - fprintf( stderr, - _( " %d (%d saved) hash collisions, %d DFAs equal\n" ), - hshcol, hshsave, dfaeql ); - fprintf( stderr, _( " %d sets of reallocations needed\n" ), - num_reallocs ); - fprintf( stderr, _( " %d total table entries needed\n" ), - tblsiz ); + fprintf (stderr, + _ + (" %d/%d meta-equivalence classes created\n"), + nummecs, csize); } - FLEX_EXIT( exit_status ); + fprintf (stderr, + _ + (" %d (%d saved) hash collisions, %d DFAs equal\n"), + hshcol, hshsave, dfaeql); + fprintf (stderr, _(" %d sets of reallocations needed\n"), + num_reallocs); + fprintf (stderr, _(" %d total table entries needed\n"), + tblsiz); } + FLEX_EXIT (exit_status); +} + /* flexinit - initialize flex */ -void flexinit( argc, argv ) -int argc; -char **argv; - { - int i, sawcmpflag, rv, optind; - char *arg; - scanopt_t sopt; +void flexinit (argc, argv) + int argc; + char **argv; +{ + int i, sawcmpflag, rv, optind; + char *arg; + scanopt_t sopt; printstats = syntaxerror = trace = spprdflt = caseins = false; - lex_compat = posix_compat = C_plus_plus = backing_up_report = ddebug = fulltbl = false; - fullspd = long_align = nowarn = yymore_used = continued_action = false; - do_yylineno = yytext_is_array = in_rule = reject = do_stdinit = false; + lex_compat = posix_compat = C_plus_plus = backing_up_report = + ddebug = fulltbl = false; + fullspd = long_align = nowarn = yymore_used = continued_action = + false; + do_yylineno = yytext_is_array = in_rule = reject = do_stdinit = + false; yymore_really_used = reject_really_used = unspecified; interactive = csize = unspecified; do_yywrap = gen_line_dirs = usemecs = useecs = true; - reentrant = reentrant_bison_pure = false; + reentrant = reentrant_bison_pure = false; performance_report = 0; did_outfilename = 0; prefix = "yy"; yyclass = 0; use_read = use_stdout = false; - tablesext = tablestoggle = false; - tablesfilename = NULL; - tablesout = NULL; + tablesext = tablestoggle = false; + tablesfilename = NULL; + tablesout = NULL; sawcmpflag = false; /* Initialize dynamic array for holding the rule actions. */ action_size = 2048; /* default size of action array in bytes */ - action_array = allocate_character_array( action_size ); + action_array = allocate_character_array (action_size); defs1_offset = prolog_offset = action_offset = action_index = 0; action_array[0] = '\0'; /* Initialize any buffers. */ - buf_init(&userdef_buf, sizeof(char)); - buf_init(&defs_buf, sizeof(char*)); - + buf_init (&userdef_buf, sizeof (char)); + buf_init (&defs_buf, sizeof (char *)); + - /* Enable C++ if program name ends with '+'. */ - program_name = basename2(argv[0],0); + /* Enable C++ if program name ends with '+'. */ + program_name = basename2 (argv[0], 0); - if ( program_name[0] != '\0' && - program_name[strlen( program_name ) - 1] == '+' ) + if (program_name[0] != '\0' && + program_name[strlen (program_name) - 1] == '+') C_plus_plus = true; /* read flags */ - sopt = scanopt_init(flexopts, argc, argv, 0); - if (!sopt) { - /* This will only happen when flexopts array is altered. */ - fprintf(stderr, - _("Internal error. flexopts are malformed.\n")); - FLEX_EXIT(1); - } - - while((rv=scanopt(sopt, &arg, &optind)) != 0){ - - if (rv < 0) { - /* Scanopt has already printed an option-specific error message. */ - fprintf( stderr, _( "Try `%s --help' for more information.\n" ), - program_name ); - FLEX_EXIT(1); - } - - switch ((enum flexopt_flag_t)rv){ - case OPT_CPLUSPLUS: - C_plus_plus = true; - break; - - case OPT_BATCH: - interactive = false; - break; - - case OPT_BACKUP: - backing_up_report = true; - break; - - case OPT_DONOTHING: - break; - - case OPT_COMPRESSION: - if ( ! sawcmpflag ) - { - useecs = false; - usemecs = false; - fulltbl = false; - sawcmpflag = true; - } - - for( i=0 ; arg && arg[i] != '\0'; i++) - switch ( arg[i] ) - { - case 'a': - long_align = true; - break; - - case 'e': - useecs = true; - break; - - case 'F': - fullspd = true; - break; - - case 'f': - fulltbl = true; - break; - - case 'm': - usemecs = true; - break; - - case 'r': - use_read = true; - break; - - default: - lerrif( - _( "unknown -C option '%c'" ), - (int) arg[i] ); - break; - } - break; - - case OPT_DEBUG: - ddebug = true; - break; - - case OPT_NO_DEBUG: - ddebug = false; - break; - - case OPT_FULL: - useecs = usemecs = false; - use_read = fulltbl = true; - break; - - case OPT_FAST: - useecs = usemecs = false; - use_read = fullspd = true; - break; - - case OPT_HELP: - usage(); - FLEX_EXIT( 0 ); - - case OPT_INTERACTIVE: - interactive = true; - break; - - case OPT_CASE_INSENSITIVE: - caseins = true; - break; - - case OPT_LEX_COMPAT: - lex_compat = true; - break; - - case OPT_POSIX_COMPAT: - posix_compat = true; - break; - - case OPT_MAIN: - buf_strdefine(&userdef_buf, "YY_MAIN", "1"); - do_yywrap = false; - break; - - case OPT_NO_MAIN: - buf_strdefine(&userdef_buf, "YY_MAIN", "0"); - break; - - case OPT_NO_LINE: - gen_line_dirs = false; - break; - - case OPT_OUTFILE: - outfilename = arg; - did_outfilename = 1; - break; - - case OPT_PREFIX: - prefix = arg; - break; - - case OPT_PERF_REPORT: - ++performance_report; - break; - - case OPT_REENTRANT_BISON: - reentrant = true; - reentrant_bison_pure = true; - break; - - case OPT_REENTRANT: - reentrant = true; - - /* Optional 'b' follows -R */ - if (arg) { - if (strcmp(arg,"b")==0) - reentrant_bison_pure = true; - else - lerrif(_( "unknown -R option '%c'" ),(int)arg[0]); - } - break; - - case OPT_NO_REENTRANT: - reentrant = reentrant_bison_pure = false; - break; - - case OPT_SKEL: - skelname = arg; - break; - - case OPT_DEFAULT: - spprdflt = false; - break; - - case OPT_NO_DEFAULT: - spprdflt = true; - break; - - case OPT_STDOUT: - use_stdout = true; - break; - - case OPT_NO_UNISTD_H: - buf_strdefine(&userdef_buf,"YY_NO_UNISTD_H", "1"); - break; - - case OPT_TABLES: - tablesext = true; - break; - - case OPT_TRACE: - trace = true; - break; - - case OPT_VERBOSE: - printstats = true; - break; - - case OPT_VERSION: - printf( _( "%s %s\n" ), - program_name, flex_version ); - FLEX_EXIT( 0 ); - - case OPT_WARN: - nowarn = false; - break; - - case OPT_NO_WARN: - nowarn = true; - break; - - case OPT_7BIT: - csize = 128; - break; - - case OPT_8BIT: - csize = CSIZE; - break; - - case OPT_ALIGN: - long_align = true; - break; - - case OPT_NO_ALIGN: - long_align = false; - break; - - case OPT_ALWAYS_INTERACTIVE: - buf_strdefine(&userdef_buf,"YY_ALWAYS_INTERACTIVE", "1"); - break; - - case OPT_NEVER_INTERACTIVE: - buf_strdefine(&userdef_buf, "YY_NEVER_INTERACTIVE", "1" ); - break; - - case OPT_ARRAY: - yytext_is_array = true; - break; - - case OPT_POINTER: - yytext_is_array = false; - break; - - case OPT_ECS: - useecs = true; - break; - - case OPT_NO_ECS: - useecs = false; - break; - - case OPT_HEADER: - headerfilename = arg; - break; - - case OPT_META_ECS: - usemecs = true; - break; - - case OPT_NO_META_ECS: - usemecs = false; - break; - - case OPT_PREPROCDEFINE: - { - /* arg is "symbol" or "symbol=definition". */ - char *def; - - for(def=arg; *def != '\0' && *def!='='; ++def) - ; - - buf_strappend(&userdef_buf,"#define "); - if (*def=='\0'){ - buf_strappend(&userdef_buf,arg); - buf_strappend(&userdef_buf, " 1\n"); - }else{ - buf_strnappend(&userdef_buf, arg,def-arg); - buf_strappend(&userdef_buf, " "); - buf_strappend(&userdef_buf, def+1); - buf_strappend(&userdef_buf, "\n"); - } - } - break; - - case OPT_READ: - use_read = true; - break; - - case OPT_STACK: - buf_strdefine(&userdef_buf,"YY_STACK_USED","1"); - break; - - case OPT_STDINIT: - do_stdinit = true; - break; - - case OPT_NO_STDINIT: - do_stdinit = false; - break; - - case OPT_YYCLASS: - yyclass = arg; - break; - - case OPT_YYLINENO: - do_yylineno = true; - break; - - case OPT_NO_YYLINENO: - do_yylineno = false; - break; - - case OPT_YYWRAP: - do_yywrap = true; - break; - - case OPT_NO_YYWRAP: - do_yywrap = false; - break; - - case OPT_YYMORE: - yymore_really_used = true; - break; - - case OPT_NO_YYMORE: - yymore_really_used = false; - break; - - case OPT_REJECT: - reject_really_used = true; - break; - - case OPT_NO_REJECT: - reject_really_used = false; - break; - - case OPT_NO_YY_PUSH_STATE: - buf_strdefine(&userdef_buf, "YY_NO_PUSH_STATE", "1"); - break; - case OPT_NO_YY_POP_STATE: - buf_strdefine(&userdef_buf, "YY_NO_POP_STATE", "1"); - break; - case OPT_NO_YY_TOP_STATE: - buf_strdefine(&userdef_buf, "YY_NO_TOP_STATE", "1"); - break; - case OPT_NO_UNPUT: - buf_strdefine(&userdef_buf, "YY_NO_UNPUT", "1"); - break; - case OPT_NO_YY_SCAN_BUFFER: - buf_strdefine(&userdef_buf, "YY_NO_SCAN_BUFFER", "1"); - break; - case OPT_NO_YY_SCAN_BYTES: - buf_strdefine(&userdef_buf, "YY_NO_SCAN_BYTES", "1"); - break; - case OPT_NO_YY_SCAN_STRING: - buf_strdefine(&userdef_buf, "YY_NO_SCAN_STRING", "1"); - break; - case OPT_NO_YYGET_EXTRA: - buf_strdefine(&userdef_buf, "YY_NO_GET_EXTRA", "1"); - break; - case OPT_NO_YYSET_EXTRA: - buf_strdefine(&userdef_buf, "YY_NO_SET_EXTRA", "1"); - break; - case OPT_NO_YYGET_LENG: - buf_strdefine(&userdef_buf, "YY_NO_GET_LENG", "1"); - break; - case OPT_NO_YYGET_TEXT: - buf_strdefine(&userdef_buf, "YY_NO_GET_TEXT", "1"); - break; - case OPT_NO_YYGET_LINENO: - buf_strdefine(&userdef_buf, "YY_NO_GET_LINENO", "1"); - break; - case OPT_NO_YYSET_LINENO: - buf_strdefine(&userdef_buf, "YY_NO_SET_LINENO", "1"); - break; - case OPT_NO_YYGET_IN: - buf_strdefine(&userdef_buf, "YY_NO_GET_IN", "1"); - break; - case OPT_NO_YYSET_IN: - buf_strdefine(&userdef_buf, "YY_NO_SET_IN", "1"); - break; - case OPT_NO_YYGET_OUT: - buf_strdefine(&userdef_buf, "YY_NO_GET_OUT", "1"); - break; - case OPT_NO_YYSET_OUT: - buf_strdefine(&userdef_buf, "YY_NO_SET_OUT", "1"); - break; - case OPT_NO_YYGET_LVAL: - buf_strdefine(&userdef_buf, "YY_NO_GET_LVAL", "1"); - break; - case OPT_NO_YYSET_LVAL: - buf_strdefine(&userdef_buf, "YY_NO_SET_LVAL", "1"); - break; - case OPT_NO_YYGET_LLOC: - buf_strdefine(&userdef_buf, "YY_NO_GET_LLOC", "1"); - break; - case OPT_NO_YYSET_LLOC: - buf_strdefine(&userdef_buf, "YY_NO_SET_LLOC", "1"); - break; - - } /* switch */ - } /* while scanopt() */ - - scanopt_destroy(sopt); + sopt = scanopt_init (flexopts, argc, argv, 0); + if (!sopt) { + /* This will only happen when flexopts array is altered. */ + fprintf (stderr, + _("Internal error. flexopts are malformed.\n")); + FLEX_EXIT (1); + } + + while ((rv = scanopt (sopt, &arg, &optind)) != 0) { + + if (rv < 0) { + /* Scanopt has already printed an option-specific error message. */ + fprintf (stderr, + _ + ("Try `%s --help' for more information.\n"), + program_name); + FLEX_EXIT (1); + } + + switch ((enum flexopt_flag_t) rv) { + case OPT_CPLUSPLUS: + C_plus_plus = true; + break; + + case OPT_BATCH: + interactive = false; + break; + + case OPT_BACKUP: + backing_up_report = true; + break; + + case OPT_DONOTHING: + break; + + case OPT_COMPRESSION: + if (!sawcmpflag) { + useecs = false; + usemecs = false; + fulltbl = false; + sawcmpflag = true; + } + + for (i = 0; arg && arg[i] != '\0'; i++) + switch (arg[i]) { + case 'a': + long_align = true; + break; + + case 'e': + useecs = true; + break; + + case 'F': + fullspd = true; + break; + + case 'f': + fulltbl = true; + break; + + case 'm': + usemecs = true; + break; + + case 'r': + use_read = true; + break; + + default: + lerrif (_ + ("unknown -C option '%c'"), + (int) arg[i]); + break; + } + break; + + case OPT_DEBUG: + ddebug = true; + break; + + case OPT_NO_DEBUG: + ddebug = false; + break; + + case OPT_FULL: + useecs = usemecs = false; + use_read = fulltbl = true; + break; + + case OPT_FAST: + useecs = usemecs = false; + use_read = fullspd = true; + break; + + case OPT_HELP: + usage (); + FLEX_EXIT (0); + + case OPT_INTERACTIVE: + interactive = true; + break; + + case OPT_CASE_INSENSITIVE: + caseins = true; + break; + + case OPT_LEX_COMPAT: + lex_compat = true; + break; + + case OPT_POSIX_COMPAT: + posix_compat = true; + break; + + case OPT_MAIN: + buf_strdefine (&userdef_buf, "YY_MAIN", "1"); + do_yywrap = false; + break; + + case OPT_NO_MAIN: + buf_strdefine (&userdef_buf, "YY_MAIN", "0"); + break; + + case OPT_NO_LINE: + gen_line_dirs = false; + break; + + case OPT_OUTFILE: + outfilename = arg; + did_outfilename = 1; + break; + + case OPT_PREFIX: + prefix = arg; + break; + + case OPT_PERF_REPORT: + ++performance_report; + break; + + case OPT_REENTRANT_BISON: + reentrant = true; + reentrant_bison_pure = true; + break; + + case OPT_REENTRANT: + reentrant = true; + + /* Optional 'b' follows -R */ + if (arg) { + if (strcmp (arg, "b") == 0) + reentrant_bison_pure = true; + else + lerrif (_ + ("unknown -R option '%c'"), +(int) arg[0]); + } + break; + + case OPT_NO_REENTRANT: + reentrant = reentrant_bison_pure = false; + break; + + case OPT_SKEL: + skelname = arg; + break; + + case OPT_DEFAULT: + spprdflt = false; + break; + + case OPT_NO_DEFAULT: + spprdflt = true; + break; + + case OPT_STDOUT: + use_stdout = true; + break; + + case OPT_NO_UNISTD_H: + buf_strdefine (&userdef_buf, "YY_NO_UNISTD_H", + "1"); + break; + + case OPT_TABLES: + tablesext = true; + break; + + case OPT_TRACE: + trace = true; + break; + + case OPT_VERBOSE: + printstats = true; + break; + + case OPT_VERSION: + printf (_("%s %s\n"), program_name, flex_version); + FLEX_EXIT (0); + + case OPT_WARN: + nowarn = false; + break; + + case OPT_NO_WARN: + nowarn = true; + break; + + case OPT_7BIT: + csize = 128; + break; + + case OPT_8BIT: + csize = CSIZE; + break; + + case OPT_ALIGN: + long_align = true; + break; + + case OPT_NO_ALIGN: + long_align = false; + break; + + case OPT_ALWAYS_INTERACTIVE: + buf_strdefine (&userdef_buf, + "YY_ALWAYS_INTERACTIVE", "1"); + break; + + case OPT_NEVER_INTERACTIVE: + buf_strdefine (&userdef_buf, + "YY_NEVER_INTERACTIVE", "1"); + break; + + case OPT_ARRAY: + yytext_is_array = true; + break; + + case OPT_POINTER: + yytext_is_array = false; + break; + + case OPT_ECS: + useecs = true; + break; + + case OPT_NO_ECS: + useecs = false; + break; + + case OPT_HEADER: + headerfilename = arg; + break; + + case OPT_META_ECS: + usemecs = true; + break; + + case OPT_NO_META_ECS: + usemecs = false; + break; + + case OPT_PREPROCDEFINE: + { + /* arg is "symbol" or "symbol=definition". */ + char *def; + + for (def = arg; + *def != '\0' && *def != '='; ++def) ; + + buf_strappend (&userdef_buf, "#define "); + if (*def == '\0') { + buf_strappend (&userdef_buf, arg); + buf_strappend (&userdef_buf, + " 1\n"); + } + else { + buf_strnappend (&userdef_buf, arg, + def - arg); + buf_strappend (&userdef_buf, " "); + buf_strappend (&userdef_buf, + def + 1); + buf_strappend (&userdef_buf, "\n"); + } + } + break; + + case OPT_READ: + use_read = true; + break; + + case OPT_STACK: + buf_strdefine (&userdef_buf, "YY_STACK_USED", "1"); + break; + + case OPT_STDINIT: + do_stdinit = true; + break; + + case OPT_NO_STDINIT: + do_stdinit = false; + break; + + case OPT_YYCLASS: + yyclass = arg; + break; + + case OPT_YYLINENO: + do_yylineno = true; + break; + + case OPT_NO_YYLINENO: + do_yylineno = false; + break; + + case OPT_YYWRAP: + do_yywrap = true; + break; + + case OPT_NO_YYWRAP: + do_yywrap = false; + break; + + case OPT_YYMORE: + yymore_really_used = true; + break; + + case OPT_NO_YYMORE: + yymore_really_used = false; + break; + + case OPT_REJECT: + reject_really_used = true; + break; + + case OPT_NO_REJECT: + reject_really_used = false; + break; + + case OPT_NO_YY_PUSH_STATE: + buf_strdefine (&userdef_buf, "YY_NO_PUSH_STATE", + "1"); + break; + case OPT_NO_YY_POP_STATE: + buf_strdefine (&userdef_buf, "YY_NO_POP_STATE", + "1"); + break; + case OPT_NO_YY_TOP_STATE: + buf_strdefine (&userdef_buf, "YY_NO_TOP_STATE", + "1"); + break; + case OPT_NO_UNPUT: + buf_strdefine (&userdef_buf, "YY_NO_UNPUT", "1"); + break; + case OPT_NO_YY_SCAN_BUFFER: + buf_strdefine (&userdef_buf, "YY_NO_SCAN_BUFFER", + "1"); + break; + case OPT_NO_YY_SCAN_BYTES: + buf_strdefine (&userdef_buf, "YY_NO_SCAN_BYTES", + "1"); + break; + case OPT_NO_YY_SCAN_STRING: + buf_strdefine (&userdef_buf, "YY_NO_SCAN_STRING", + "1"); + break; + case OPT_NO_YYGET_EXTRA: + buf_strdefine (&userdef_buf, "YY_NO_GET_EXTRA", + "1"); + break; + case OPT_NO_YYSET_EXTRA: + buf_strdefine (&userdef_buf, "YY_NO_SET_EXTRA", + "1"); + break; + case OPT_NO_YYGET_LENG: + buf_strdefine (&userdef_buf, "YY_NO_GET_LENG", + "1"); + break; + case OPT_NO_YYGET_TEXT: + buf_strdefine (&userdef_buf, "YY_NO_GET_TEXT", + "1"); + break; + case OPT_NO_YYGET_LINENO: + buf_strdefine (&userdef_buf, "YY_NO_GET_LINENO", + "1"); + break; + case OPT_NO_YYSET_LINENO: + buf_strdefine (&userdef_buf, "YY_NO_SET_LINENO", + "1"); + break; + case OPT_NO_YYGET_IN: + buf_strdefine (&userdef_buf, "YY_NO_GET_IN", "1"); + break; + case OPT_NO_YYSET_IN: + buf_strdefine (&userdef_buf, "YY_NO_SET_IN", "1"); + break; + case OPT_NO_YYGET_OUT: + buf_strdefine (&userdef_buf, "YY_NO_GET_OUT", "1"); + break; + case OPT_NO_YYSET_OUT: + buf_strdefine (&userdef_buf, "YY_NO_SET_OUT", "1"); + break; + case OPT_NO_YYGET_LVAL: + buf_strdefine (&userdef_buf, "YY_NO_GET_LVAL", + "1"); + break; + case OPT_NO_YYSET_LVAL: + buf_strdefine (&userdef_buf, "YY_NO_SET_LVAL", + "1"); + break; + case OPT_NO_YYGET_LLOC: + buf_strdefine (&userdef_buf, "YY_NO_GET_LLOC", + "1"); + break; + case OPT_NO_YYSET_LLOC: + buf_strdefine (&userdef_buf, "YY_NO_SET_LLOC", + "1"); + break; + + } /* switch */ + } /* while scanopt() */ + + scanopt_destroy (sopt); num_input_files = argc - optind; input_files = argv + optind; - set_input_file( num_input_files > 0 ? input_files[0] : NULL ); + set_input_file (num_input_files > 0 ? input_files[0] : NULL); lastccl = lastsc = lastdfa = lastnfa = 0; num_rules = num_eof_rules = default_rule = 0; numas = numsnpairs = tmpuses = 0; - numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst = 0; + numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst = + 0; numuniq = numdup = hshsave = eofseen = datapos = dataline = 0; num_backing_up = onesp = numprots = 0; variable_trailing_context_rules = bol_needed = false; @@ -1428,28 +1470,28 @@ char **argv; */ lastprot = 1; - set_up_initial_allocations(); - } + set_up_initial_allocations (); +} /* readin - read in the rules section of the input file(s) */ -void readin() - { +void readin () +{ static char yy_stdinit[] = "FILE *yyin = stdin, *yyout = stdout;"; static char yy_nostdinit[] = + "FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;"; - line_directive_out( (FILE *) 0, 1 ); + line_directive_out ((FILE *) 0, 1); - if ( yyparse() ) - { - pinpoint_message( _( "fatal parse error" ) ); - flexend( 1 ); - } + if (yyparse ()) { + pinpoint_message (_("fatal parse error")); + flexend (1); + } - if ( syntaxerror ) - flexend( 1 ); + if (syntaxerror) + flexend (1); /* If the user explicitly requested posix compatibility by specifing the * posix-compat option, then we check for conflicting options. However, if @@ -1460,395 +1502,372 @@ void readin() * Note: The posix option was added to flex to provide the posix behavior * of the repeat operator in regular expressions, e.g., `ab{3}' */ - if ( posix_compat ) - { + if (posix_compat) { /* TODO: This is where we try to make flex behave according to * posiz, AND check for conflicting options. How far should we go * with this? Should we disable all the neat-o flex features? */ - /* Update: Estes says no, since other flex features don't violate posix. */ - } + /* Update: Estes says no, since other flex features don't violate posix. */ + } - if ( getenv("POSIXLY_CORRECT") ) - { + if (getenv ("POSIXLY_CORRECT")) { posix_compat = true; - } + } - if ( backing_up_report ) - { - backing_up_file = fopen( backing_name, "w" ); - if ( backing_up_file == NULL ) - lerrsf( - _( "could not create backing-up info file %s" ), - backing_name ); - } + if (backing_up_report) { + backing_up_file = fopen (backing_name, "w"); + if (backing_up_file == NULL) + lerrsf (_ + ("could not create backing-up info file %s"), +backing_name); + } else backing_up_file = NULL; - if ( yymore_really_used == true ) + if (yymore_really_used == true) yymore_used = true; - else if ( yymore_really_used == false ) + else if (yymore_really_used == false) yymore_used = false; - if ( reject_really_used == true ) + if (reject_really_used == true) reject = true; - else if ( reject_really_used == false ) + else if (reject_really_used == false) reject = false; - if ( performance_report > 0 ) - { - if ( lex_compat ) - { - fprintf( stderr, -_( "-l AT&T lex compatibility option entails a large performance penalty\n" ) ); - fprintf( stderr, -_( " and may be the actual source of other reported performance penalties\n" ) ); - } + if (performance_report > 0) { + if (lex_compat) { + fprintf (stderr, + _ + ("-l AT&T lex compatibility option entails a large performance penalty\n")); + fprintf (stderr, + _ + (" and may be the actual source of other reported performance penalties\n")); + } - else if ( do_yylineno ) - { - fprintf( stderr, - _( "%%option yylineno entails a large performance penalty\n" ) ); - } + else if (do_yylineno) { + fprintf (stderr, + _ + ("%%option yylineno entails a large performance penalty\n")); + } - if ( performance_report > 1 ) - { - if ( interactive ) - fprintf( stderr, - _( "-I (interactive) entails a minor performance penalty\n" ) ); + if (performance_report > 1) { + if (interactive) + fprintf (stderr, + _ + ("-I (interactive) entails a minor performance penalty\n")); - if ( yymore_used ) - fprintf( stderr, - _( "yymore() entails a minor performance penalty\n" ) ); - } + if (yymore_used) + fprintf (stderr, + _ + ("yymore() entails a minor performance penalty\n")); + } - if ( reject ) - fprintf( stderr, - _( "REJECT entails a large performance penalty\n" ) ); + if (reject) + fprintf (stderr, + _ + ("REJECT entails a large performance penalty\n")); - if ( variable_trailing_context_rules ) - fprintf( stderr, -_( "Variable trailing context rules entail a large performance penalty\n" ) ); - } + if (variable_trailing_context_rules) + fprintf (stderr, + _ + ("Variable trailing context rules entail a large performance penalty\n")); + } - if ( reject ) + if (reject) real_reject = true; - if ( variable_trailing_context_rules ) + if (variable_trailing_context_rules) reject = true; - if ( (fulltbl || fullspd) && reject ) - { - if ( real_reject ) - flexerror( - _( "REJECT cannot be used with -f or -F" ) ); - else if ( do_yylineno ) - flexerror( - _( "%option yylineno cannot be used with REJECT" ) ); + if ((fulltbl || fullspd) && reject) { + if (real_reject) + flexerror (_ + ("REJECT cannot be used with -f or -F")); + else if (do_yylineno) + flexerror (_ + ("%option yylineno cannot be used with REJECT")); else - flexerror( - _( "variable trailing context rules cannot be used with -f or -F" ) ); - } + flexerror (_ + ("variable trailing context rules cannot be used with -f or -F")); + } - if ( reject ) - outn( "\n#define YY_USES_REJECT" ); + if (reject) + outn ("\n#define YY_USES_REJECT"); - if ( ! do_yywrap ) - { - outn( "\n#define yywrap(n) 1" ); - outn( "#define YY_SKIP_YYWRAP" ); - } + if (!do_yywrap) { + outn ("\n#define yywrap(n) 1"); + outn ("#define YY_SKIP_YYWRAP"); + } - if ( ddebug ) - outn( "\n#define FLEX_DEBUG" ); + if (ddebug) + outn ("\n#define FLEX_DEBUG"); - OUT_BEGIN_CODE(); - if ( csize == 256 ) - outn( "typedef unsigned char YY_CHAR;" ); + OUT_BEGIN_CODE (); + if (csize == 256) + outn ("typedef unsigned char YY_CHAR;"); else - outn( "typedef char YY_CHAR;" ); - OUT_END_CODE(); - - if ( C_plus_plus ) - { - outn( "#define yytext_ptr yytext" ); + outn ("typedef char YY_CHAR;"); + OUT_END_CODE (); - if ( interactive ) - outn( "#define YY_INTERACTIVE" ); - } + if (C_plus_plus) { + outn ("#define yytext_ptr yytext"); - else - { - OUT_BEGIN_CODE(); - /* In reentrant scanner, stdinit is handled in flex.skl. */ - if ( do_stdinit ) - { - outn( "#ifdef YY_REENTRANT" ); - outn( "#ifdef VMS" ); - outn( "#ifdef __VMS_POSIX" ); - outn( "#define YY_STDINIT" ); - outn( "#endif" ); - outn( "#else" ); - outn( "#define YY_STDINIT" ); - outn( "#endif" ); - outn( "#else /* end YY_REENTRANT */" ); - outn( "#ifdef VMS" ); - outn( "#ifndef __VMS_POSIX" ); - outn( yy_nostdinit ); - outn( "#else" ); - outn( yy_stdinit ); - outn( "#endif" ); - outn( "#else" ); - outn( yy_stdinit ); - outn( "#endif" ); - outn( "#endif" ); - } + if (interactive) + outn ("#define YY_INTERACTIVE"); + } - else - { - outn( "#ifndef YY_REENTRANT" ); - outn( yy_nostdinit ); - outn( "#endif" ); - } - OUT_END_CODE(); + else { + OUT_BEGIN_CODE (); + /* In reentrant scanner, stdinit is handled in flex.skl. */ + if (do_stdinit) { + outn ("#ifdef YY_REENTRANT"); + outn ("#ifdef VMS"); + outn ("#ifdef __VMS_POSIX"); + outn ("#define YY_STDINIT"); + outn ("#endif"); + outn ("#else"); + outn ("#define YY_STDINIT"); + outn ("#endif"); + outn ("#else /* end YY_REENTRANT */"); + outn ("#ifdef VMS"); + outn ("#ifndef __VMS_POSIX"); + outn (yy_nostdinit); + outn ("#else"); + outn (yy_stdinit); + outn ("#endif"); + outn ("#else"); + outn (yy_stdinit); + outn ("#endif"); + outn ("#endif"); } - OUT_BEGIN_CODE(); - if ( fullspd ) - outn( "typedef yyconst struct yy_trans_info *yy_state_type;" ); - else if ( ! C_plus_plus ) - outn( "typedef int yy_state_type;" ); - OUT_END_CODE(); - - if ( lex_compat ) - outn( "#define YY_FLEX_LEX_COMPAT" ); - - if ( ! C_plus_plus && ! reentrant ) - { - outn( "#ifdef YY_USE_LINENO" ); - outn( "extern int yylineno;" ); - OUT_BEGIN_CODE(); - outn( "int yylineno = 1;" ); - OUT_END_CODE(); - outn( "#endif" ); + else { + outn ("#ifndef YY_REENTRANT"); + outn (yy_nostdinit); + outn ("#endif"); } + OUT_END_CODE (); + } - if ( C_plus_plus ) - { - outn( "\n#include " ); + OUT_BEGIN_CODE (); + if (fullspd) + outn + ("typedef yyconst struct yy_trans_info *yy_state_type;"); + else if (!C_plus_plus) + outn ("typedef int yy_state_type;"); + OUT_END_CODE (); + + if (lex_compat) + outn ("#define YY_FLEX_LEX_COMPAT"); + + if (!C_plus_plus && !reentrant) { + outn ("#ifdef YY_USE_LINENO"); + outn ("extern int yylineno;"); + OUT_BEGIN_CODE (); + outn ("int yylineno = 1;"); + OUT_END_CODE (); + outn ("#endif"); + } - if ( yyclass ) - { - outn( "int yyFlexLexer::yylex()" ); - outn( "\t{" ); - outn( -"\tLexerError( \"yyFlexLexer::yylex invoked but %option yyclass used\" );" ); - outn( "\treturn 0;" ); - outn( "\t}" ); - - out_str( "\n#define YY_DECL int %s::yylex()\n", - yyclass ); - } + if (C_plus_plus) { + outn ("\n#include "); + + if (yyclass) { + outn ("int yyFlexLexer::yylex()"); + outn ("\t{"); + outn + ("\tLexerError( \"yyFlexLexer::yylex invoked but %option yyclass used\" );"); + outn ("\treturn 0;"); + outn ("\t}"); + + out_str ("\n#define YY_DECL int %s::yylex()\n", + yyclass); } + } - else - { + else { /* Watch out: yytext_ptr is a variable when yytext is an array, * but it's a macro when yytext is a pointer. */ - if ( yytext_is_array ) - { - if ( !reentrant ) - outn( "extern char yytext[];\n" ); + if (yytext_is_array) { + if (!reentrant) + outn ("extern char yytext[];\n"); + } + else { + if (reentrant) { + outn ("#define yytext_ptr yytext_r"); + } + else { + outn ("extern char *yytext;"); + outn ("#define yytext_ptr yytext"); } - else - { - if ( reentrant ) - { - outn( "#define yytext_ptr yytext_r" ); - } - else - { - outn( "extern char *yytext;" ); - outn( "#define yytext_ptr yytext" ); - } } - if ( yyclass ) - flexerror( - _( "%option yyclass only meaningful for C++ scanners" ) ); - } + if (yyclass) + flexerror (_ + ("%option yyclass only meaningful for C++ scanners")); + } - if ( useecs ) - numecs = cre8ecs( nextecm, ecgroup, csize ); + if (useecs) + numecs = cre8ecs (nextecm, ecgroup, csize); else numecs = csize; /* Now map the equivalence class for NUL to its expected place. */ ecgroup[0] = ecgroup[csize]; - NUL_ec = ABS( ecgroup[0] ); + NUL_ec = ABS (ecgroup[0]); - if ( useecs ) - ccl2ecl(); - } + if (useecs) + ccl2ecl (); +} /* set_up_initial_allocations - allocate memory for internal tables */ -void set_up_initial_allocations() - { +void set_up_initial_allocations () +{ maximum_mns = (long_align ? MAXIMUM_MNS_LONG : MAXIMUM_MNS); current_mns = INITIAL_MNS; - firstst = allocate_integer_array( current_mns ); - lastst = allocate_integer_array( current_mns ); - finalst = allocate_integer_array( current_mns ); - transchar = allocate_integer_array( current_mns ); - trans1 = allocate_integer_array( current_mns ); - trans2 = allocate_integer_array( current_mns ); - accptnum = allocate_integer_array( current_mns ); - assoc_rule = allocate_integer_array( current_mns ); - state_type = allocate_integer_array( current_mns ); + firstst = allocate_integer_array (current_mns); + lastst = allocate_integer_array (current_mns); + finalst = allocate_integer_array (current_mns); + transchar = allocate_integer_array (current_mns); + trans1 = allocate_integer_array (current_mns); + trans2 = allocate_integer_array (current_mns); + accptnum = allocate_integer_array (current_mns); + assoc_rule = allocate_integer_array (current_mns); + state_type = allocate_integer_array (current_mns); current_max_rules = INITIAL_MAX_RULES; - rule_type = allocate_integer_array( current_max_rules ); - rule_linenum = allocate_integer_array( current_max_rules ); - rule_useful = allocate_integer_array( current_max_rules ); - rule_has_nl = allocate_bool_array( current_max_rules ); + rule_type = allocate_integer_array (current_max_rules); + rule_linenum = allocate_integer_array (current_max_rules); + rule_useful = allocate_integer_array (current_max_rules); + rule_has_nl = allocate_bool_array (current_max_rules); current_max_scs = INITIAL_MAX_SCS; - scset = allocate_integer_array( current_max_scs ); - scbol = allocate_integer_array( current_max_scs ); - scxclu = allocate_integer_array( current_max_scs ); - sceof = allocate_integer_array( current_max_scs ); - scname = allocate_char_ptr_array( current_max_scs ); + scset = allocate_integer_array (current_max_scs); + scbol = allocate_integer_array (current_max_scs); + scxclu = allocate_integer_array (current_max_scs); + sceof = allocate_integer_array (current_max_scs); + scname = allocate_char_ptr_array (current_max_scs); current_maxccls = INITIAL_MAX_CCLS; - cclmap = allocate_integer_array( current_maxccls ); - ccllen = allocate_integer_array( current_maxccls ); - cclng = allocate_integer_array( current_maxccls ); - ccl_has_nl = allocate_bool_array( current_maxccls ); + cclmap = allocate_integer_array (current_maxccls); + ccllen = allocate_integer_array (current_maxccls); + cclng = allocate_integer_array (current_maxccls); + ccl_has_nl = allocate_bool_array (current_maxccls); current_max_ccl_tbl_size = INITIAL_MAX_CCL_TBL_SIZE; - ccltbl = allocate_Character_array( current_max_ccl_tbl_size ); + ccltbl = allocate_Character_array (current_max_ccl_tbl_size); current_max_dfa_size = INITIAL_MAX_DFA_SIZE; current_max_xpairs = INITIAL_MAX_XPAIRS; - nxt = allocate_integer_array( current_max_xpairs ); - chk = allocate_integer_array( current_max_xpairs ); + nxt = allocate_integer_array (current_max_xpairs); + chk = allocate_integer_array (current_max_xpairs); current_max_template_xpairs = INITIAL_MAX_TEMPLATE_XPAIRS; - tnxt = allocate_integer_array( current_max_template_xpairs ); + tnxt = allocate_integer_array (current_max_template_xpairs); current_max_dfas = INITIAL_MAX_DFAS; - base = allocate_integer_array( current_max_dfas ); - def = allocate_integer_array( current_max_dfas ); - dfasiz = allocate_integer_array( current_max_dfas ); - accsiz = allocate_integer_array( current_max_dfas ); - dhash = allocate_integer_array( current_max_dfas ); - dss = allocate_int_ptr_array( current_max_dfas ); - dfaacc = allocate_dfaacc_union( current_max_dfas ); + base = allocate_integer_array (current_max_dfas); + def = allocate_integer_array (current_max_dfas); + dfasiz = allocate_integer_array (current_max_dfas); + accsiz = allocate_integer_array (current_max_dfas); + dhash = allocate_integer_array (current_max_dfas); + dss = allocate_int_ptr_array (current_max_dfas); + dfaacc = allocate_dfaacc_union (current_max_dfas); nultrans = (int *) 0; - } +} /* extracts basename from path, optionally stripping the extension "\.*" * (same concept as /bin/sh `basename`, but different handling of extension). */ -static char * basename2(path, strip_ext) - char * path; - int strip_ext; /* boolean */ +static char *basename2 (path, strip_ext) + char *path; + int strip_ext; /* boolean */ { - char *b, *e=0; - b = path; - for (b=path; *path; path++) - if (*path== '/') - b = path+1; - else if (*path=='.') - e = path; - - if (strip_ext && e && e > b) - *e = '\0'; - return b; + char *b, *e = 0; + + b = path; + for (b = path; *path; path++) + if (*path == '/') + b = path + 1; + else if (*path == '.') + e = path; + + if (strip_ext && e && e > b) + *e = '\0'; + return b; } -void usage() - { - FILE *f = stdout; - if ( ! did_outfilename ) - { - sprintf( outfile_path, outfile_template, - prefix, C_plus_plus ? "cc" : "c" ); - outfilename = outfile_path; - } - - fprintf(f,_( "Usage: %s [OPTIONS] [FILE]...\n"), program_name); - fprintf(f, -_( -"Generates programs that perform pattern-matching on text.\n" -"\n" -"Table Compression:\n" -" -Ca, --align trade off larger tables for better memory alignment\n" -" -Ce, --ecs construct equivalence classes\n" -" -Cf do not compress tables; use -f representation\n" -" -CF do not compress tables; use -F representation\n" -" -Cm, --meta-ecs construct meta-equivalence classes\n" -" -Cr, --read use read() instead of stdio for scanner input\n" -" -f, --full generate fast, large scanner. Same as -Cfr\n" -" -F, --fast use alternate table representation. Same as -CFr\n" -" -Cem default compression (same as --ecs --meta-ecs)\n" - -"\n" -"Debugging:\n" -" -d, --debug enable debug mode in scanner\n" -" -b, --backup write backing-up information to %s\n" -" -p, --perf-report write performance report to stderr\n" -" -s, --nodefault suppress default rule to ECHO unmatched text\n" -" -T, --trace %s should run in trace mode\n" -" -w, --nowarn do not generate warnings\n" -" -v, --verbose write summary of scanner statistics to stdout\n" - -"\n" -"Files:\n" -" -o, --outfile=FILE specify output filename\n" -" -S, --skel=FILE specify skeleton file\n" -" -t, --stdout write scanner on stdout instead of %s\n" -" --yyclass=NAME name of C++ class\n" -" --header=FILE create a C header file in addition to the scanner\n" -" --tables[=FILE] write tables to FILE\n" - -"\n" -"Scanner behavior:\n" -" -7, --7bit generate 7-bit scanner\n" -" -8, --8bit generate 8-bit scanner\n" -" -B, --batch generate batch scanner (opposite of -I)\n" -" -i, --case-insensitive ignore case in patterns\n" -" -l, --lex-compat maximal compatibility with original lex\n" -" -X, --posix-compat maximal compatibility with POSIX lex\n" -" -I, --interactive generate interactive scanner (opposite of -B)\n" -" --yylineno track line count in yylineno\n" - -"\n" -"Generated code:\n" -" -+, --c++ generate C++ scanner class\n" -" -Dmacro[=defn] #define macro defn (default defn is '1')\n" -" -L, --noline suppress #line directives in scanner\n" -" -P, --prefix=STRING use STRING as prefix instead of \"yy\"\n" -" -R, --reentrant generate a reentrant C scanner\n" -" -Rb, --reentrant-bison reentrant scanner for bison pure parser.\n" -" --stdinit initialize yyin/yyout to stdin/stdout\n" -" --nounistd do not include \n" -" --noFUNCTION do not generate a particular FUNCTION\n" - -"\n" -"Miscellaneous:\n" -" -c do-nothing POSIX option\n" -" -n do-nothing POSIX option\n" -" -?\n" -" -h, --help produce this help message\n" -" -V, --version report %s version\n" -), backing_name, program_name, outfile_path, program_name); +void usage () +{ + FILE *f = stdout; + + if (!did_outfilename) { + sprintf (outfile_path, outfile_template, + prefix, C_plus_plus ? "cc" : "c"); + outfilename = outfile_path; + } + + fprintf (f, _("Usage: %s [OPTIONS] [FILE]...\n"), program_name); + fprintf (f, + _ + ("Generates programs that perform pattern-matching on text.\n" + "\n" "Table Compression:\n" + " -Ca, --align trade off larger tables for better memory alignment\n" + " -Ce, --ecs construct equivalence classes\n" + " -Cf do not compress tables; use -f representation\n" + " -CF do not compress tables; use -F representation\n" + " -Cm, --meta-ecs construct meta-equivalence classes\n" + " -Cr, --read use read() instead of stdio for scanner input\n" + " -f, --full generate fast, large scanner. Same as -Cfr\n" + " -F, --fast use alternate table representation. Same as -CFr\n" + " -Cem default compression (same as --ecs --meta-ecs)\n" + "\n" "Debugging:\n" + " -d, --debug enable debug mode in scanner\n" + " -b, --backup write backing-up information to %s\n" + " -p, --perf-report write performance report to stderr\n" + " -s, --nodefault suppress default rule to ECHO unmatched text\n" + " -T, --trace %s should run in trace mode\n" + " -w, --nowarn do not generate warnings\n" + " -v, --verbose write summary of scanner statistics to stdout\n" + "\n" "Files:\n" + " -o, --outfile=FILE specify output filename\n" + " -S, --skel=FILE specify skeleton file\n" + " -t, --stdout write scanner on stdout instead of %s\n" + " --yyclass=NAME name of C++ class\n" + " --header=FILE create a C header file in addition to the scanner\n" + " --tables[=FILE] write tables to FILE\n" "\n" + "Scanner behavior:\n" + " -7, --7bit generate 7-bit scanner\n" + " -8, --8bit generate 8-bit scanner\n" + " -B, --batch generate batch scanner (opposite of -I)\n" + " -i, --case-insensitive ignore case in patterns\n" + " -l, --lex-compat maximal compatibility with original lex\n" + " -X, --posix-compat maximal compatibility with POSIX lex\n" + " -I, --interactive generate interactive scanner (opposite of -B)\n" + " --yylineno track line count in yylineno\n" + "\n" "Generated code:\n" + " -+, --c++ generate C++ scanner class\n" + " -Dmacro[=defn] #define macro defn (default defn is '1')\n" + " -L, --noline suppress #line directives in scanner\n" + " -P, --prefix=STRING use STRING as prefix instead of \"yy\"\n" + " -R, --reentrant generate a reentrant C scanner\n" + " -Rb, --reentrant-bison reentrant scanner for bison pure parser.\n" + " --stdinit initialize yyin/yyout to stdin/stdout\n" + " --nounistd do not include \n" + " --noFUNCTION do not generate a particular FUNCTION\n" + "\n" "Miscellaneous:\n" + " -c do-nothing POSIX option\n" + " -n do-nothing POSIX option\n" + " -?\n" + " -h, --help produce this help message\n" + " -V, --version report %s version\n"), + backing_name, program_name, outfile_path, program_name); } diff --git a/misc.c b/misc.c index cc595fa..7fe6cde 100644 --- a/misc.c +++ b/misc.c @@ -35,40 +35,39 @@ #include "flexdef.h" /* Append "#define defname value\n" to the running buffer. */ -void action_define( defname, value ) -const char *defname; -int value; - { - char buf[MAXLINE]; - char *cpy; - - if ( (int) strlen( defname ) > MAXLINE / 2 ) - { - format_pinpoint_message( _( "name \"%s\" ridiculously long" ), - defname ); +void action_define (defname, value) + const char *defname; + int value; +{ + char buf[MAXLINE]; + char *cpy; + + if ((int) strlen (defname) > MAXLINE / 2) { + format_pinpoint_message (_ + ("name \"%s\" ridiculously long"), + defname); return; - } + } - sprintf( buf, "#define %s %d\n", defname, value ); - add_action( buf ); + sprintf (buf, "#define %s %d\n", defname, value); + add_action (buf); /* track #defines so we can undef them when we're done. */ - cpy = copy_string(defname); - buf_append(&defs_buf, &cpy, 1); - } + cpy = copy_string (defname); + buf_append (&defs_buf, &cpy, 1); +} /* Append "new_text" to the running buffer. */ -void add_action( new_text ) -char *new_text; - { - int len = strlen( new_text ); +void add_action (new_text) + char *new_text; +{ + int len = strlen (new_text); - while ( len + action_index >= action_size - 10 /* slop */ ) - { - int new_size = action_size * 2; + while (len + action_index >= action_size - 10 /* slop */ ) { + int new_size = action_size * 2; - if ( new_size <= 0 ) + if (new_size <= 0) /* Increase just a little, to try to avoid overflow * on 16-bit machines. */ @@ -77,63 +76,62 @@ char *new_text; action_size = new_size; action_array = - reallocate_character_array( action_array, action_size ); - } + reallocate_character_array (action_array, + action_size); + } - strcpy( &action_array[action_index], new_text ); + strcpy (&action_array[action_index], new_text); action_index += len; - } +} /* allocate_array - allocate memory for an integer array of the given size */ -void *allocate_array( size, element_size ) -int size; -size_t element_size; - { +void *allocate_array (size, element_size) + int size; + size_t element_size; +{ register void *mem; - size_t num_bytes = element_size * size; + size_t num_bytes = element_size * size; - mem = flex_alloc( num_bytes ); - if ( ! mem ) - flexfatal( - _( "memory allocation failed in allocate_array()" ) ); + mem = flex_alloc (num_bytes); + if (!mem) + flexfatal (_ + ("memory allocation failed in allocate_array()")); return mem; - } +} /* all_lower - true if a string is all lower-case */ -int all_lower( str ) -register char *str; - { - while ( *str ) - { - if ( ! isascii( (Char) *str ) || ! islower( *str ) ) +int all_lower (str) + register char *str; +{ + while (*str) { + if (!isascii ((Char) * str) || !islower (*str)) return 0; ++str; - } + } return 1; - } +} /* all_upper - true if a string is all upper-case */ -int all_upper( str ) -register char *str; - { - while ( *str ) - { - if ( ! isascii( (Char) *str ) || ! isupper( *str ) ) +int all_upper (str) + register char *str; +{ + while (*str) { + if (!isascii ((Char) * str) || !isupper (*str)) return 0; ++str; - } + } return 1; - } +} /* bubble - bubble sort an integer array in increasing order @@ -151,20 +149,19 @@ register char *str; * n - the number of elements of 'v' to be sorted */ -void bubble( v, n ) -int v[], n; - { +void bubble (v, n) + int v[], n; +{ register int i, j, k; - for ( i = n; i > 1; --i ) - for ( j = 1; j < i; ++j ) - if ( v[j] > v[j + 1] ) /* compare */ - { + for (i = n; i > 1; --i) + for (j = 1; j < i; ++j) + if (v[j] > v[j + 1]) { /* compare */ k = v[j]; /* exchange */ v[j] = v[j + 1]; v[j + 1] = k; - } - } + } +} /* check_char - checks a character to make sure it's within the range @@ -172,78 +169,75 @@ int v[], n; * and exits. */ -void check_char( c ) -int c; - { - if ( c >= CSIZE ) - lerrsf( _( "bad character '%s' detected in check_char()" ), - readable_form( c ) ); - - if ( c >= csize ) - lerrsf( - _( "scanner requires -8 flag to use the character %s" ), - readable_form( c ) ); - } +void check_char (c) + int c; +{ + if (c >= CSIZE) + lerrsf (_("bad character '%s' detected in check_char()"), + readable_form (c)); + + if (c >= csize) + lerrsf (_ + ("scanner requires -8 flag to use the character %s"), +readable_form (c)); +} /* clower - replace upper-case letter to lower-case */ -Char clower( c ) -register int c; - { - return (Char) ((isascii( c ) && isupper( c )) ? tolower( c ) : c); - } +Char clower (c) + register int c; +{ + return (Char) ((isascii (c) && isupper (c)) ? tolower (c) : c); +} /* copy_string - returns a dynamically allocated copy of a string */ -char *copy_string( str ) -register const char *str; - { +char *copy_string (str) + register const char *str; +{ register const char *c1; register char *c2; - char *copy; + char *copy; unsigned int size; /* find length */ - for ( c1 = str; *c1; ++c1 ) - ; + for (c1 = str; *c1; ++c1) ; - size = (c1 - str + 1) * sizeof( char ); - copy = (char *) flex_alloc( size ); + size = (c1 - str + 1) * sizeof (char); - if ( copy == NULL ) - flexfatal( _( "dynamic memory failure in copy_string()" ) ); + copy = (char *) flex_alloc (size); - for ( c2 = copy; (*c2++ = *str++) != 0; ) - ; + if (copy == NULL) + flexfatal (_("dynamic memory failure in copy_string()")); + + for (c2 = copy; (*c2++ = *str++) != 0;) ; return copy; - } +} /* copy_unsigned_string - * returns a dynamically allocated copy of a (potentially) unsigned string */ -Char *copy_unsigned_string( str ) -register Char *str; - { +Char *copy_unsigned_string (str) + register Char *str; +{ register Char *c; - Char *copy; + Char *copy; /* find length */ - for ( c = str; *c; ++c ) - ; + for (c = str; *c; ++c) ; - copy = allocate_Character_array( c - str + 1 ); + copy = allocate_Character_array (c - str + 1); - for ( c = copy; (*c++ = *str++) != 0; ) - ; + for (c = copy; (*c++ = *str++) != 0;) ; return copy; - } +} /* cshell - shell sort a character array in increasing order @@ -264,234 +258,228 @@ register Char *str; * n - number of elements of v to be sorted */ -void cshell( v, n, special_case_0 ) -Char v[]; -int n, special_case_0; - { - int gap, i, j, jg; - Char k; - - for ( gap = n / 2; gap > 0; gap = gap / 2 ) - for ( i = gap; i < n; ++i ) - for ( j = i - gap; j >= 0; j = j - gap ) - { +void cshell (v, n, special_case_0) + Char v[]; + int n, special_case_0; +{ + int gap, i, j, jg; + Char k; + + for (gap = n / 2; gap > 0; gap = gap / 2) + for (i = gap; i < n; ++i) + for (j = i - gap; j >= 0; j = j - gap) { jg = j + gap; - if ( special_case_0 ) - { - if ( v[jg] == 0 ) + if (special_case_0) { + if (v[jg] == 0) break; - else if ( v[j] != 0 && v[j] <= v[jg] ) - break; - } + else if (v[j] != 0 + && v[j] <= v[jg]) break; + } - else if ( v[j] <= v[jg] ) + else if (v[j] <= v[jg]) break; k = v[j]; v[j] = v[jg]; v[jg] = k; - } - } + } +} /* dataend - finish up a block of data declarations */ -void dataend() - { - if ( datapos > 0 ) - dataflush(); +void dataend () +{ + if (datapos > 0) + dataflush (); /* add terminator for initialization; { for vi */ - outn( " } ;\n" ); + outn (" } ;\n"); dataline = 0; datapos = 0; - } +} /* dataflush - flush generated data statements */ -void dataflush() - { - outc( '\n' ); +void dataflush () +{ + outc ('\n'); - if ( ++dataline >= NUMDATALINES ) - { + if (++dataline >= NUMDATALINES) { /* Put out a blank line so that the table is grouped into * large blocks that enable the user to find elements easily. */ - outc( '\n' ); + outc ('\n'); dataline = 0; - } + } /* Reset the number of characters written on the current line. */ datapos = 0; - } +} /* flexerror - report an error message and terminate */ -void flexerror( msg ) -const char *msg; - { - fprintf( stderr, "%s: %s\n", program_name, msg ); - flexend( 1 ); - } +void flexerror (msg) + const char *msg; +{ + fprintf (stderr, "%s: %s\n", program_name, msg); + flexend (1); +} /* flexfatal - report a fatal error message and terminate */ -void flexfatal( msg ) -const char *msg; - { - fprintf( stderr, _( "%s: fatal internal error, %s\n" ), - program_name, msg ); - FLEX_EXIT( 1 ); - } +void flexfatal (msg) + const char *msg; +{ + fprintf (stderr, _("%s: fatal internal error, %s\n"), + program_name, msg); + FLEX_EXIT (1); +} /* htoi - convert a hexadecimal digit string to an integer value */ -int htoi( str ) -Char str[]; - { +int htoi (str) + Char str[]; +{ unsigned int result; - (void) sscanf( (char *) str, "%x", &result ); + (void) sscanf ((char *) str, "%x", &result); return result; - } +} /* lerrif - report an error message formatted with one integer argument */ -void lerrif( msg, arg ) -const char *msg; -int arg; - { - char errmsg[MAXLINE]; - (void) sprintf( errmsg, msg, arg ); - flexerror( errmsg ); - } +void lerrif (msg, arg) + const char *msg; + int arg; +{ + char errmsg[MAXLINE]; + + (void) sprintf (errmsg, msg, arg); + flexerror (errmsg); +} /* lerrsf - report an error message formatted with one string argument */ -void lerrsf( msg, arg ) -const char *msg, arg[]; - { - char errmsg[MAXLINE]; +void lerrsf (msg, arg) + const char *msg, arg[]; +{ + char errmsg[MAXLINE]; - (void) sprintf( errmsg, msg, arg ); - flexerror( errmsg ); - } + (void) sprintf (errmsg, msg, arg); + flexerror (errmsg); +} /* line_directive_out - spit out a "#line" statement */ -void line_directive_out( output_file, do_infile ) -FILE *output_file; -int do_infile; - { - char directive[MAXLINE], filename[MAXLINE]; - char *s1, *s2, *s3; +void line_directive_out (output_file, do_infile) + FILE *output_file; + int do_infile; +{ + char directive[MAXLINE], filename[MAXLINE]; + char *s1, *s2, *s3; static const char *line_fmt = "#line %d \"%s\"\n"; - if ( ! gen_line_dirs ) + if (!gen_line_dirs) return; - if ( (do_infile && ! infilename) || (! do_infile && ! outfilename) ) + if ((do_infile && !infilename) || (!do_infile && !outfilename)) /* don't know the filename to use, skip */ return; s1 = do_infile ? infilename : outfilename; s2 = filename; - s3 = &filename[sizeof( filename ) - 2]; + s3 = &filename[sizeof (filename) - 2]; - while ( s2 < s3 && *s1 ) - { - if ( *s1 == '\\' ) + while (s2 < s3 && *s1) { + if (*s1 == '\\') /* Escape the '\' */ *s2++ = '\\'; *s2++ = *s1++; - } + } *s2 = '\0'; - if ( do_infile ) - sprintf( directive, line_fmt, linenum, filename ); - else - { - if ( output_file == stdout ) + if (do_infile) + sprintf (directive, line_fmt, linenum, filename); + else { + if (output_file == stdout) /* Account for the line directive itself. */ ++out_linenum; - sprintf( directive, line_fmt, out_linenum, filename ); - } + sprintf (directive, line_fmt, out_linenum, filename); + } /* If output_file is nil then we should put the directive in * the accumulated actions. */ - if ( output_file ) - { - fputs( directive, output_file ); - } - else - add_action( directive ); + if (output_file) { + fputs (directive, output_file); } + else + add_action (directive); +} /* mark_defs1 - mark the current position in the action array as * representing where the user's section 1 definitions end * and the prolog begins */ -void mark_defs1() - { +void mark_defs1 () +{ defs1_offset = 0; action_array[action_index++] = '\0'; action_offset = prolog_offset = action_index; action_array[action_index] = '\0'; - } +} /* mark_prolog - mark the current position in the action array as * representing the end of the action prolog */ -void mark_prolog() - { +void mark_prolog () +{ action_array[action_index++] = '\0'; action_offset = action_index; action_array[action_index] = '\0'; - } +} /* mk2data - generate a data statement for a two-dimensional array * * Generates a data statement initializing the current 2-D array to "value". */ -void mk2data( value ) -int value; - { - if ( datapos >= NUMDATAITEMS ) - { - outc( ',' ); - dataflush(); - } +void mk2data (value) + int value; +{ + if (datapos >= NUMDATAITEMS) { + outc (','); + dataflush (); + } - if ( datapos == 0 ) + if (datapos == 0) /* Indent. */ - out( " " ); + out (" "); else - outc( ',' ); + outc (','); ++datapos; - out_dec( "%5d", value ); - } + out_dec ("%5d", value); +} /* mkdata - generate a data statement @@ -499,76 +487,83 @@ int value; * Generates a data statement initializing the current array element to * "value". */ -void mkdata( value ) -int value; - { - if ( datapos >= NUMDATAITEMS ) - { - outc( ',' ); - dataflush(); - } +void mkdata (value) + int value; +{ + if (datapos >= NUMDATAITEMS) { + outc (','); + dataflush (); + } - if ( datapos == 0 ) + if (datapos == 0) /* Indent. */ - out( " " ); + out (" "); else - outc( ',' ); + outc (','); ++datapos; - out_dec( "%5d", value ); - } + out_dec ("%5d", value); +} /* myctoi - return the integer represented by a string of digits */ -int myctoi( array ) -const char *array; - { - int val = 0; +int myctoi (array) + const char *array; +{ + int val = 0; - (void) sscanf( array, "%d", &val ); + (void) sscanf (array, "%d", &val); return val; - } +} /* myesc - return character corresponding to escape sequence */ -Char myesc( array ) -Char array[]; - { - Char c, esc_char; - - switch ( array[1] ) - { - case 'b': return '\b'; - case 'f': return '\f'; - case 'n': return '\n'; - case 'r': return '\r'; - case 't': return '\t'; +Char myesc (array) + Char array[]; +{ + Char c, esc_char; + + switch (array[1]) { + case 'b': + return '\b'; + case 'f': + return '\f'; + case 'n': + return '\n'; + case 'r': + return '\r'; + case 't': + return '\t'; #if __STDC__ - case 'a': return '\a'; - case 'v': return '\v'; + case 'a': + return '\a'; + case 'v': + return '\v'; #else - case 'a': return '\007'; - case 'v': return '\013'; + case 'a': + return '\007'; + case 'v': + return '\013'; #endif - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - { /* \ */ - int sptr = 1; - - while ( isascii( array[sptr] ) && - isdigit( array[sptr] ) ) + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + { /* \ */ + int sptr = 1; + + while (isascii (array[sptr]) && + isdigit (array[sptr])) /* Don't increment inside loop control * because if isdigit() is a macro it might * expand into multiple increments ... @@ -578,19 +573,19 @@ Char array[]; c = array[sptr]; array[sptr] = '\0'; - esc_char = otoi( array + 1 ); + esc_char = otoi (array + 1); array[sptr] = c; return esc_char; - } + } - case 'x': - { /* \x */ - int sptr = 2; + case 'x': + { /* \x */ + int sptr = 2; - while ( isascii( array[sptr] ) && - isxdigit( (char) array[sptr] ) ) + while (isascii (array[sptr]) && + isxdigit ((char) array[sptr])) /* Don't increment inside loop control * because if isdigit() is a macro it might * expand into multiple increments ... @@ -600,119 +595,119 @@ Char array[]; c = array[sptr]; array[sptr] = '\0'; - esc_char = htoi( array + 2 ); + esc_char = htoi (array + 2); array[sptr] = c; return esc_char; - } - - default: - return array[1]; } + + default: + return array[1]; } +} /* otoi - convert an octal digit string to an integer value */ -int otoi( str ) -Char str[]; - { +int otoi (str) + Char str[]; +{ unsigned int result; - (void) sscanf( (char *) str, "%o", &result ); + (void) sscanf ((char *) str, "%o", &result); return result; - } +} /* out - various flavors of outputing a (possibly formatted) string for the * generated scanner, keeping track of the line count. */ -void out( str ) -const char *str; - { - fputs( str, stdout ); - out_line_count( str ); - } +void out (str) + const char *str; +{ + fputs (str, stdout); + out_line_count (str); +} -void out_dec( fmt, n ) -const char *fmt; -int n; - { - printf( fmt, n ); - out_line_count( fmt ); - } +void out_dec (fmt, n) + const char *fmt; + int n; +{ + printf (fmt, n); + out_line_count (fmt); +} -void out_dec2( fmt, n1, n2 ) -const char *fmt; -int n1, n2; - { - printf( fmt, n1, n2 ); - out_line_count( fmt ); - } +void out_dec2 (fmt, n1, n2) + const char *fmt; + int n1, n2; +{ + printf (fmt, n1, n2); + out_line_count (fmt); +} -void out_hex( fmt, x ) -const char *fmt; -unsigned int x; - { - printf( fmt, x ); - out_line_count( fmt ); - } +void out_hex (fmt, x) + const char *fmt; + unsigned int x; +{ + printf (fmt, x); + out_line_count (fmt); +} -void out_line_count( str ) -const char *str; - { +void out_line_count (str) + const char *str; +{ register int i; - for ( i = 0; str[i]; ++i ) - if ( str[i] == '\n' ) + for (i = 0; str[i]; ++i) + if (str[i] == '\n') ++out_linenum; - } +} -void out_str( fmt, str ) -const char *fmt, str[]; - { - printf( fmt, str ); - out_line_count( fmt ); - out_line_count( str ); - } +void out_str (fmt, str) + const char *fmt, str[]; +{ + printf (fmt, str); + out_line_count (fmt); + out_line_count (str); +} -void out_str3( fmt, s1, s2, s3 ) -const char *fmt, s1[], s2[], s3[]; - { - printf( fmt, s1, s2, s3 ); - out_line_count( fmt ); - out_line_count( s1 ); - out_line_count( s2 ); - out_line_count( s3 ); - } +void out_str3 (fmt, s1, s2, s3) + const char *fmt, s1[], s2[], s3[]; +{ + printf (fmt, s1, s2, s3); + out_line_count (fmt); + out_line_count (s1); + out_line_count (s2); + out_line_count (s3); +} -void out_str_dec( fmt, str, n ) -const char *fmt, str[]; -int n; - { - printf( fmt, str, n ); - out_line_count( fmt ); - out_line_count( str ); - } +void out_str_dec (fmt, str, n) + const char *fmt, str[]; + int n; +{ + printf (fmt, str, n); + out_line_count (fmt); + out_line_count (str); +} -void outc( c ) -int c; - { - putc( c, stdout ); +void outc (c) + int c; +{ + putc (c, stdout); - if ( c == '\n' ) + if (c == '\n') ++out_linenum; - } +} -void outn( str ) -const char *str; - { - puts( str ); - out_line_count( str ); +void outn (str) + const char *str; +{ + puts (str); + out_line_count (str); ++out_linenum; - } +} /* readable_form - return the the human-readable form of a character @@ -720,62 +715,65 @@ const char *str; * The returned string is in static storage. */ -char *readable_form( c ) -register int c; - { +char *readable_form (c) + register int c; +{ static char rform[10]; - if ( (c >= 0 && c < 32) || c >= 127 ) - { - switch ( c ) - { - case '\b': return "\\b"; - case '\f': return "\\f"; - case '\n': return "\\n"; - case '\r': return "\\r"; - case '\t': return "\\t"; + if ((c >= 0 && c < 32) || c >= 127) { + switch (c) { + case '\b': + return "\\b"; + case '\f': + return "\\f"; + case '\n': + return "\\n"; + case '\r': + return "\\r"; + case '\t': + return "\\t"; #if __STDC__ - case '\a': return "\\a"; - case '\v': return "\\v"; + case '\a': + return "\\a"; + case '\v': + return "\\v"; #endif - default: - (void) sprintf( rform, "\\%.3o", - (unsigned int) c ); - return rform; - } + default: + (void) sprintf (rform, "\\%.3o", (unsigned int) c); + return rform; } + } - else if ( c == ' ' ) + else if (c == ' ') return "' '"; - else - { + else { rform[0] = c; rform[1] = '\0'; return rform; - } } +} /* reallocate_array - increase the size of a dynamic array */ -void *reallocate_array( array, size, element_size ) -void *array; -int size; -size_t element_size; - { +void *reallocate_array (array, size, element_size) + void *array; + int size; + size_t element_size; +{ register void *new_array; - size_t num_bytes = element_size * size; + size_t num_bytes = element_size * size; - new_array = flex_realloc( array, num_bytes ); - if ( ! new_array ) - flexfatal( _( "attempt to increase array size failed" ) ); + new_array = flex_realloc (array, num_bytes); + if (!new_array) + flexfatal (_("attempt to increase array size failed")); return new_array; - } +} /* skelout - write out one section of the skeleton file @@ -784,82 +782,76 @@ size_t element_size; * Copies skelfile or skel array to stdout until a line beginning with * "%%" or EOF is found. */ -void skelout() - { - char buf_storage[MAXLINE]; - char *buf = buf_storage; - int do_copy = 1; +void skelout () +{ + char buf_storage[MAXLINE]; + char *buf = buf_storage; + int do_copy = 1; /* Loop pulling lines either from the skelfile, if we're using * one, or from the skel[] array. */ - while ( skelfile ? - (fgets( buf, MAXLINE, skelfile ) != NULL) : - ((buf = (char *) skel[skel_ind++]) != 0) ) - { + while (skelfile ? + (fgets (buf, MAXLINE, skelfile) != NULL) : + ((buf = (char *) skel[skel_ind++]) != 0)) { - if (skelfile ) - chomp(buf); + if (skelfile) + chomp (buf); /* copy from skel array */ - if ( buf[0] == '%' ) - { /* control line */ + if (buf[0] == '%') { /* control line */ /* print the control line as a comment. */ - if (buf[1] != '#') - { - if (buf[strlen(buf)-1]=='\\') - out_str("/* %s */\\\n", buf); + if (buf[1] != '#') { + if (buf[strlen (buf) - 1] == '\\') + out_str ("/* %s */\\\n", buf); else - out_str("/* %s */\n", buf); - } - - switch ( buf[1] ) - { - case '%': - return; - - case '+': - do_copy = C_plus_plus; - break; + out_str ("/* %s */\n", buf); + } - case '-': - do_copy = ! C_plus_plus; - break; + switch (buf[1]) { + case '%': + return; - case '*': - do_copy = 1; - break; + case '+': + do_copy = C_plus_plus; + break; - case 'c': /* begin linkage-only (non-header) code. */ - OUT_BEGIN_CODE(); - break; + case '-': + do_copy = !C_plus_plus; + break; - case 'e': /* end linkage-only code. */ - OUT_END_CODE(); - break; - - case '#': - /* a comment in the skel. ignore. */ - break; + case '*': + do_copy = 1; + break; - case 't': - /* %t - toggle tables api */ - tablestoggle = !tablestoggle; - break; + case 'c': /* begin linkage-only (non-header) code. */ + OUT_BEGIN_CODE (); + break; - default: - flexfatal( - _( "bad line in skeleton file" ) ); - } + case 'e': /* end linkage-only code. */ + OUT_END_CODE (); + break; + + case '#': + /* a comment in the skel. ignore. */ + break; + + case 't': + /* %t - toggle tables api */ + tablestoggle = !tablestoggle; + break; + + default: + flexfatal (_("bad line in skeleton file")); } + } - else if ( do_copy ) - { + else if (do_copy) { if (tablesext || !tablestoggle) - outn( buf ); - } + outn (buf); } } +} /* transition_struct_out - output a yy_trans_info structure @@ -868,39 +860,38 @@ void skelout() * element_n. Formats the output with spaces and carriage returns. */ -void transition_struct_out( element_v, element_n ) -int element_v, element_n; - { - out_dec2( " {%4d,%4d },", element_v, element_n ); +void transition_struct_out (element_v, element_n) + int element_v, element_n; +{ + out_dec2 (" {%4d,%4d },", element_v, element_n); datapos += TRANS_STRUCT_PRINT_LENGTH; - if ( datapos >= 79 - TRANS_STRUCT_PRINT_LENGTH ) - { - outc( '\n' ); + if (datapos >= 79 - TRANS_STRUCT_PRINT_LENGTH) { + outc ('\n'); - if ( ++dataline % 10 == 0 ) - outc( '\n' ); + if (++dataline % 10 == 0) + outc ('\n'); datapos = 0; - } } +} /* The following is only needed when building flex's parser using certain * broken versions of bison. */ -void *yy_flex_xmalloc( size ) -int size; - { - void *result = flex_alloc( (size_t) size ); +void *yy_flex_xmalloc (size) + int size; +{ + void *result = flex_alloc ((size_t) size); - if ( ! result ) - flexfatal( - _( "memory allocation failed in yy_flex_xmalloc()" ) ); + if (!result) + flexfatal (_ + ("memory allocation failed in yy_flex_xmalloc()")); return result; - } +} /* zero_out - set a region of memory to 0 @@ -908,37 +899,37 @@ int size; * Sets region_ptr[0] through region_ptr[size_in_bytes - 1] to zero. */ -void zero_out( region_ptr, size_in_bytes ) -char *region_ptr; -size_t size_in_bytes; - { +void zero_out (region_ptr, size_in_bytes) + char *region_ptr; + size_t size_in_bytes; +{ register char *rp, *rp_end; rp = region_ptr; rp_end = region_ptr + size_in_bytes; - while ( rp < rp_end ) + while (rp < rp_end) *rp++ = 0; - } +} /* Remove all '\n' and '\r' characters, if any, from the end of str. * str can be any null-terminated string, or NULL. * returns str. */ -char* chomp(str) - char* str; +char *chomp (str) + char *str; { - char* p=str; - if (!str || !*str) /* s is null or empty string */ - return str; + char *p = str; - /* find end of string minus one*/ - while (*p) - ++p; - --p; + if (!str || !*str) /* s is null or empty string */ + return str; - /* eat newlines */ - while (p >= str && (*p == '\r' || *p == '\n')) - *p-- = 0; - return str; -} + /* find end of string minus one */ + while (*p) + ++p; + --p; + /* eat newlines */ + while (p >= str && (*p == '\r' || *p == '\n')) + *p-- = 0; + return str; +} diff --git a/nfa.c b/nfa.c index 1bd712c..d140f59 100644 --- a/nfa.c +++ b/nfa.c @@ -36,8 +36,8 @@ /* declare functions that have forward references */ -int dupmachine PROTO((int)); -void mkxtion PROTO((int, int)); +int dupmachine PROTO ((int)); +void mkxtion PROTO ((int, int)); /* add_accept - add an accepting state to a machine @@ -45,25 +45,25 @@ void mkxtion PROTO((int, int)); * accepting_number becomes mach's accepting number. */ -void add_accept( mach, accepting_number ) -int mach, accepting_number; - { +void add_accept (mach, accepting_number) + int mach, accepting_number; +{ /* Hang the accepting number off an epsilon state. if it is associated * with a state that has a non-epsilon out-transition, then the state * will accept BEFORE it makes that transition, i.e., one character * too soon. */ - if ( transchar[finalst[mach]] == SYM_EPSILON ) + if (transchar[finalst[mach]] == SYM_EPSILON) accptnum[finalst[mach]] = accepting_number; - else - { - int astate = mkstate( SYM_EPSILON ); + else { + int astate = mkstate (SYM_EPSILON); + accptnum[astate] = accepting_number; - (void) link_machines( mach, astate ); - } + (void) link_machines (mach, astate); } +} /* copysingl - make a given number of copies of a singleton machine @@ -77,31 +77,32 @@ int mach, accepting_number; * num - the number of copies of singl to be present in newsng */ -int copysingl( singl, num ) -int singl, num; - { - int copy, i; +int copysingl (singl, num) + int singl, num; +{ + int copy, i; - copy = mkstate( SYM_EPSILON ); + copy = mkstate (SYM_EPSILON); - for ( i = 1; i <= num; ++i ) - copy = link_machines( copy, dupmachine( singl ) ); + for (i = 1; i <= num; ++i) + copy = link_machines (copy, dupmachine (singl)); return copy; - } +} /* dumpnfa - debugging routine to write out an nfa */ -void dumpnfa( state1 ) -int state1; +void dumpnfa (state1) + int state1; - { - int sym, tsp1, tsp2, anum, ns; +{ + int sym, tsp1, tsp2, anum, ns; - fprintf( stderr, - _( "\n\n********** beginning dump of nfa with start state %d\n" ), - state1 ); + fprintf (stderr, + _ + ("\n\n********** beginning dump of nfa with start state %d\n"), + state1); /* We probably should loop starting at firstst[state1] and going to * lastst[state1], but they're not maintained properly when we "or" @@ -110,26 +111,25 @@ int state1; */ /* for ( ns = firstst[state1]; ns <= lastst[state1]; ++ns ) */ - for ( ns = 1; ns <= lastnfa; ++ns ) - { - fprintf( stderr, _( "state # %4d\t" ), ns ); + for (ns = 1; ns <= lastnfa; ++ns) { + fprintf (stderr, _("state # %4d\t"), ns); sym = transchar[ns]; tsp1 = trans1[ns]; tsp2 = trans2[ns]; anum = accptnum[ns]; - fprintf( stderr, "%3d: %4d, %4d", sym, tsp1, tsp2 ); - - if ( anum != NIL ) - fprintf( stderr, " [%d]", anum ); + fprintf (stderr, "%3d: %4d, %4d", sym, tsp1, tsp2); - fprintf( stderr, "\n" ); - } + if (anum != NIL) + fprintf (stderr, " [%d]", anum); - fprintf( stderr, _( "********** end of dump\n" ) ); + fprintf (stderr, "\n"); } + fprintf (stderr, _("********** end of dump\n")); +} + /* dupmachine - make a duplicate of a given machine * @@ -148,32 +148,30 @@ int state1; * states accessible by the arrays firstst and lastst */ -int dupmachine( mach ) -int mach; - { - int i, init, state_offset; - int state = 0; - int last = lastst[mach]; - - for ( i = firstst[mach]; i <= last; ++i ) - { - state = mkstate( transchar[i] ); - - if ( trans1[i] != NO_TRANSITION ) - { - mkxtion( finalst[state], trans1[i] + state - i ); - - if ( transchar[i] == SYM_EPSILON && - trans2[i] != NO_TRANSITION ) - mkxtion( finalst[state], - trans2[i] + state - i ); - } +int dupmachine (mach) + int mach; +{ + int i, init, state_offset; + int state = 0; + int last = lastst[mach]; - accptnum[state] = accptnum[i]; + for (i = firstst[mach]; i <= last; ++i) { + state = mkstate (transchar[i]); + + if (trans1[i] != NO_TRANSITION) { + mkxtion (finalst[state], trans1[i] + state - i); + + if (transchar[i] == SYM_EPSILON && + trans2[i] != NO_TRANSITION) + mkxtion (finalst[state], + trans2[i] + state - i); } - if ( state == 0 ) - flexfatal( _( "empty machine in dupmachine()" ) ); + accptnum[state] = accptnum[i]; + } + + if (state == 0) + flexfatal (_("empty machine in dupmachine()")); state_offset = state - i + 1; @@ -183,7 +181,7 @@ int mach; lastst[init] = lastst[mach] + state_offset; return init; - } +} /* finish_rule - finish up the processing for a rule @@ -198,12 +196,13 @@ int mach; * context has variable length. */ -void finish_rule( mach, variable_trail_rule, headcnt, trailcnt, pcont_act ) -int mach, variable_trail_rule, headcnt, trailcnt, pcont_act; - { - char action_text[MAXLINE]; +void finish_rule (mach, variable_trail_rule, headcnt, trailcnt, + pcont_act) + int mach, variable_trail_rule, headcnt, trailcnt, pcont_act; +{ + char action_text[MAXLINE]; - add_accept( mach, num_rules ); + add_accept (mach, num_rules); /* We did this in new_rule(), but it often gets the wrong * number because we do it before we start parsing the current rule. @@ -213,80 +212,77 @@ int mach, variable_trail_rule, headcnt, trailcnt, pcont_act; /* If this is a continued action, then the line-number has already * been updated, giving us the wrong number. */ - if ( continued_action ) + if (continued_action) --rule_linenum[num_rules]; /* If the previous rule was continued action, then we inherit the * previous newline flag, possibly overriding the current one. */ - if ( pcont_act && rule_has_nl[num_rules-1] ) + if (pcont_act && rule_has_nl[num_rules - 1]) rule_has_nl[num_rules] = true; - sprintf( action_text, "case %d:\n", num_rules ); - add_action( action_text ); - if ( rule_has_nl[num_rules] ){ - sprintf( action_text, "/* rule %d can match eol */\n", num_rules); - add_action( action_text ); + sprintf (action_text, "case %d:\n", num_rules); + add_action (action_text); + if (rule_has_nl[num_rules]) { + sprintf (action_text, "/* rule %d can match eol */\n", + num_rules); + add_action (action_text); } - if ( variable_trail_rule ) - { + if (variable_trail_rule) { rule_type[num_rules] = RULE_VARIABLE; - if ( performance_report > 0 ) - fprintf( stderr, - _( "Variable trailing context rule at line %d\n" ), - rule_linenum[num_rules] ); + if (performance_report > 0) + fprintf (stderr, + _ + ("Variable trailing context rule at line %d\n"), + rule_linenum[num_rules]); variable_trailing_context_rules = true; - } + } - else - { + else { rule_type[num_rules] = RULE_NORMAL; - if ( headcnt > 0 || trailcnt > 0 ) - { + if (headcnt > 0 || trailcnt > 0) { /* Do trailing context magic to not match the trailing * characters. */ - char *scanner_cp = "YY_G(yy_c_buf_p) = yy_cp"; - char *scanner_bp = "yy_bp"; - - add_action( - "*yy_cp = YY_G(yy_hold_char); /* undo effects of setting up yytext */\n" ); - - if ( headcnt > 0 ) - { - sprintf( action_text, "%s = %s + %d;\n", - scanner_cp, scanner_bp, headcnt ); - add_action( action_text ); - } - - else - { - sprintf( action_text, "%s -= %d;\n", - scanner_cp, trailcnt ); - add_action( action_text ); - } - - add_action( - "YY_DO_BEFORE_ACTION; /* set up yytext again */\n" ); + char *scanner_cp = "YY_G(yy_c_buf_p) = yy_cp"; + char *scanner_bp = "yy_bp"; + + add_action + ("*yy_cp = YY_G(yy_hold_char); /* undo effects of setting up yytext */\n"); + + if (headcnt > 0) { + sprintf (action_text, "%s = %s + %d;\n", + scanner_cp, scanner_bp, headcnt); + add_action (action_text); + } + + else { + sprintf (action_text, "%s -= %d;\n", + scanner_cp, trailcnt); + add_action (action_text); } + + add_action + ("YY_DO_BEFORE_ACTION; /* set up yytext again */\n"); } + } /* Okay, in the action code at this point yytext and yyleng have * their proper final values for this rule, so here's the point * to do any user action. But don't do it for continued actions, * as that'll result in multiple YY_RULE_SETUP's. */ - if ( ! continued_action ) - add_action( "YY_RULE_SETUP\n" ); + if (!continued_action) + add_action ("YY_RULE_SETUP\n"); - line_directive_out( (FILE *) 0, 1 ); - } + line_directive_out ((FILE *) 0, 1); +} /* link_machines - connect two machines together @@ -305,25 +301,24 @@ int mach, variable_trail_rule, headcnt, trailcnt, pcont_act; * FIRST is set to new by the operation. last is unmolested. */ -int link_machines( first, last ) -int first, last; - { - if ( first == NIL ) +int link_machines (first, last) + int first, last; +{ + if (first == NIL) return last; - else if ( last == NIL ) + else if (last == NIL) return first; - else - { - mkxtion( finalst[first], last ); + else { + mkxtion (finalst[first], last); finalst[first] = finalst[last]; - lastst[first] = MAX( lastst[first], lastst[last] ); - firstst[first] = MIN( firstst[first], firstst[last] ); + lastst[first] = MAX (lastst[first], lastst[last]); + firstst[first] = MIN (firstst[first], firstst[last]); return first; - } } +} /* mark_beginning_as_normal - mark each "beginning" state in a machine @@ -333,36 +328,32 @@ int first, last; * The "beginning" states are the epsilon closure of the first state */ -void mark_beginning_as_normal( mach ) -register int mach; - { - switch ( state_type[mach] ) - { - case STATE_NORMAL: - /* Oh, we've already visited here. */ - return; - - case STATE_TRAILING_CONTEXT: - state_type[mach] = STATE_NORMAL; - - if ( transchar[mach] == SYM_EPSILON ) - { - if ( trans1[mach] != NO_TRANSITION ) - mark_beginning_as_normal( - trans1[mach] ); - - if ( trans2[mach] != NO_TRANSITION ) - mark_beginning_as_normal( - trans2[mach] ); - } - break; - - default: - flexerror( - _( "bad state type in mark_beginning_as_normal()" ) ); - break; +void mark_beginning_as_normal (mach) + register int mach; +{ + switch (state_type[mach]) { + case STATE_NORMAL: + /* Oh, we've already visited here. */ + return; + + case STATE_TRAILING_CONTEXT: + state_type[mach] = STATE_NORMAL; + + if (transchar[mach] == SYM_EPSILON) { + if (trans1[mach] != NO_TRANSITION) + mark_beginning_as_normal (trans1[mach]); + + if (trans2[mach] != NO_TRANSITION) + mark_beginning_as_normal (trans2[mach]); } + break; + + default: + flexerror (_ + ("bad state type in mark_beginning_as_normal()")); + break; } +} /* mkbranch - make a machine that branches to two machines @@ -379,24 +370,24 @@ register int mach; * more mkbranch's. Compare with mkor() */ -int mkbranch( first, second ) -int first, second; - { - int eps; +int mkbranch (first, second) + int first, second; +{ + int eps; - if ( first == NO_TRANSITION ) + if (first == NO_TRANSITION) return second; - else if ( second == NO_TRANSITION ) + else if (second == NO_TRANSITION) return first; - eps = mkstate( SYM_EPSILON ); + eps = mkstate (SYM_EPSILON); - mkxtion( eps, first ); - mkxtion( eps, second ); + mkxtion (eps, first); + mkxtion (eps, second); return eps; - } +} /* mkclos - convert a machine into a closure @@ -407,11 +398,11 @@ int first, second; * new - a new state which matches the closure of "state" */ -int mkclos( state ) -int state; - { - return mkopt( mkposcl( state ) ); - } +int mkclos (state) + int state; +{ + return mkopt (mkposcl (state)); +} /* mkopt - make a machine optional @@ -428,28 +419,27 @@ int state; * 2. mach is destroyed by the call */ -int mkopt( mach ) -int mach; - { - int eps; +int mkopt (mach) + int mach; +{ + int eps; - if ( ! SUPER_FREE_EPSILON(finalst[mach]) ) - { - eps = mkstate( SYM_EPSILON ); - mach = link_machines( mach, eps ); - } + if (!SUPER_FREE_EPSILON (finalst[mach])) { + eps = mkstate (SYM_EPSILON); + mach = link_machines (mach, eps); + } /* Can't skimp on the following if FREE_EPSILON(mach) is true because * some state interior to "mach" might point back to the beginning * for a closure. */ - eps = mkstate( SYM_EPSILON ); - mach = link_machines( eps, mach ); + eps = mkstate (SYM_EPSILON); + mach = link_machines (eps, mach); - mkxtion( mach, finalst[mach] ); + mkxtion (mach, finalst[mach]); return mach; - } +} /* mkor - make a machine that matches either one of two machines @@ -466,56 +456,52 @@ int mach; * the number of epsilon states needed */ -int mkor( first, second ) -int first, second; - { - int eps, orend; +int mkor (first, second) + int first, second; +{ + int eps, orend; - if ( first == NIL ) + if (first == NIL) return second; - else if ( second == NIL ) + else if (second == NIL) return first; - else - { + else { /* See comment in mkopt() about why we can't use the first * state of "first" or "second" if they satisfy "FREE_EPSILON". */ - eps = mkstate( SYM_EPSILON ); + eps = mkstate (SYM_EPSILON); - first = link_machines( eps, first ); + first = link_machines (eps, first); - mkxtion( first, second ); + mkxtion (first, second); - if ( SUPER_FREE_EPSILON(finalst[first]) && - accptnum[finalst[first]] == NIL ) - { + if (SUPER_FREE_EPSILON (finalst[first]) && + accptnum[finalst[first]] == NIL) { orend = finalst[first]; - mkxtion( finalst[second], orend ); - } + mkxtion (finalst[second], orend); + } - else if ( SUPER_FREE_EPSILON(finalst[second]) && - accptnum[finalst[second]] == NIL ) - { + else if (SUPER_FREE_EPSILON (finalst[second]) && + accptnum[finalst[second]] == NIL) { orend = finalst[second]; - mkxtion( finalst[first], orend ); - } + mkxtion (finalst[first], orend); + } - else - { - eps = mkstate( SYM_EPSILON ); + else { + eps = mkstate (SYM_EPSILON); - first = link_machines( first, eps ); + first = link_machines (first, eps); orend = finalst[first]; - mkxtion( finalst[second], orend ); - } + mkxtion (finalst[second], orend); } + } finalst[first] = orend; return first; - } +} /* mkposcl - convert a machine into a positive closure @@ -526,24 +512,22 @@ int first, second; * new - a machine matching the positive closure of "state" */ -int mkposcl( state ) -int state; - { - int eps; +int mkposcl (state) + int state; +{ + int eps; - if ( SUPER_FREE_EPSILON(finalst[state]) ) - { - mkxtion( finalst[state], state ); + if (SUPER_FREE_EPSILON (finalst[state])) { + mkxtion (finalst[state], state); return state; - } + } - else - { - eps = mkstate( SYM_EPSILON ); - mkxtion( eps, state ); - return link_machines( state, eps ); - } + else { + eps = mkstate (SYM_EPSILON); + mkxtion (eps, state); + return link_machines (state, eps); } +} /* mkrep - make a replicated machine @@ -558,36 +542,36 @@ int state; * if "ub" is INFINITY then "new" matches "lb" or more occurrences of "mach" */ -int mkrep( mach, lb, ub ) -int mach, lb, ub; - { - int base_mach, tail, copy, i; +int mkrep (mach, lb, ub) + int mach, lb, ub; +{ + int base_mach, tail, copy, i; - base_mach = copysingl( mach, lb - 1 ); + base_mach = copysingl (mach, lb - 1); - if ( ub == INFINITY ) - { - copy = dupmachine( mach ); - mach = link_machines( mach, - link_machines( base_mach, mkclos( copy ) ) ); - } - - else - { - tail = mkstate( SYM_EPSILON ); + if (ub == INFINITY) { + copy = dupmachine (mach); + mach = link_machines (mach, + link_machines (base_mach, + mkclos (copy))); + } - for ( i = lb; i < ub; ++i ) - { - copy = dupmachine( mach ); - tail = mkopt( link_machines( copy, tail ) ); - } + else { + tail = mkstate (SYM_EPSILON); - mach = link_machines( mach, link_machines( base_mach, tail ) ); + for (i = lb; i < ub; ++i) { + copy = dupmachine (mach); + tail = mkopt (link_machines (copy, tail)); } - return mach; + mach = + link_machines (mach, + link_machines (base_mach, tail)); } + return mach; +} + /* mkstate - create a state with a transition on a given symbol * @@ -605,30 +589,31 @@ int mach, lb, ub; * that it admittedly is) */ -int mkstate( sym ) -int sym; - { - if ( ++lastnfa >= current_mns ) - { - if ( (current_mns += MNS_INCREMENT) >= maximum_mns ) - lerrif( - _( "input rules are too complicated (>= %d NFA states)" ), - current_mns ); +int mkstate (sym) + int sym; +{ + if (++lastnfa >= current_mns) { + if ((current_mns += MNS_INCREMENT) >= maximum_mns) + lerrif (_ + ("input rules are too complicated (>= %d NFA states)"), +current_mns); ++num_reallocs; - firstst = reallocate_integer_array( firstst, current_mns ); - lastst = reallocate_integer_array( lastst, current_mns ); - finalst = reallocate_integer_array( finalst, current_mns ); - transchar = reallocate_integer_array( transchar, current_mns ); - trans1 = reallocate_integer_array( trans1, current_mns ); - trans2 = reallocate_integer_array( trans2, current_mns ); - accptnum = reallocate_integer_array( accptnum, current_mns ); + firstst = reallocate_integer_array (firstst, current_mns); + lastst = reallocate_integer_array (lastst, current_mns); + finalst = reallocate_integer_array (finalst, current_mns); + transchar = + reallocate_integer_array (transchar, current_mns); + trans1 = reallocate_integer_array (trans1, current_mns); + trans2 = reallocate_integer_array (trans2, current_mns); + accptnum = + reallocate_integer_array (accptnum, current_mns); assoc_rule = - reallocate_integer_array( assoc_rule, current_mns ); + reallocate_integer_array (assoc_rule, current_mns); state_type = - reallocate_integer_array( state_type, current_mns ); - } + reallocate_integer_array (state_type, current_mns); + } firstst[lastnfa] = lastnfa; finalst[lastnfa] = lastnfa; @@ -649,28 +634,26 @@ int sym; * elsewhere in the input). */ - if ( sym < 0 ) - { + if (sym < 0) { /* We don't have to update the equivalence classes since * that was already done when the ccl was created for the * first time. */ - } + } - else if ( sym == SYM_EPSILON ) + else if (sym == SYM_EPSILON) ++numeps; - else - { - check_char( sym ); + else { + check_char (sym); - if ( useecs ) + if (useecs) /* Map NUL's to csize. */ - mkechar( sym ? sym : csize, nextecm, ecgroup ); - } + mkechar (sym ? sym : csize, nextecm, ecgroup); + } return lastnfa; - } +} /* mkxtion - make a transition from one state to another @@ -683,45 +666,43 @@ int sym; * stateto - the state to which the transition is to be made */ -void mkxtion( statefrom, stateto ) -int statefrom, stateto; - { - if ( trans1[statefrom] == NO_TRANSITION ) +void mkxtion (statefrom, stateto) + int statefrom, stateto; +{ + if (trans1[statefrom] == NO_TRANSITION) trans1[statefrom] = stateto; - else if ( (transchar[statefrom] != SYM_EPSILON) || - (trans2[statefrom] != NO_TRANSITION) ) - flexfatal( _( "found too many transitions in mkxtion()" ) ); + else if ((transchar[statefrom] != SYM_EPSILON) || + (trans2[statefrom] != NO_TRANSITION)) + flexfatal (_("found too many transitions in mkxtion()")); - else - { /* second out-transition for an epsilon state */ + else { /* second out-transition for an epsilon state */ ++eps2; trans2[statefrom] = stateto; - } } +} /* new_rule - initialize for a new rule */ -void new_rule() - { - if ( ++num_rules >= current_max_rules ) - { +void new_rule () +{ + if (++num_rules >= current_max_rules) { ++num_reallocs; current_max_rules += MAX_RULES_INCREMENT; - rule_type = reallocate_integer_array( rule_type, - current_max_rules ); - rule_linenum = reallocate_integer_array( rule_linenum, - current_max_rules ); - rule_useful = reallocate_integer_array( rule_useful, - current_max_rules ); - rule_has_nl = reallocate_bool_array( rule_has_nl, - current_max_rules ); - } + rule_type = reallocate_integer_array (rule_type, + current_max_rules); + rule_linenum = reallocate_integer_array (rule_linenum, + current_max_rules); + rule_useful = reallocate_integer_array (rule_useful, + current_max_rules); + rule_has_nl = reallocate_bool_array (rule_has_nl, + current_max_rules); + } - if ( num_rules > MAX_RULE ) - lerrif( _( "too many rules (> %d)!" ), MAX_RULE ); + if (num_rules > MAX_RULE) + lerrif (_("too many rules (> %d)!"), MAX_RULE); rule_linenum[num_rules] = linenum; rule_useful[num_rules] = false; rule_has_nl[num_rules] = false; - } +} diff --git a/options.c b/options.c index d4d61c1..a6322c1 100644 --- a/options.c +++ b/options.c @@ -40,121 +40,231 @@ /* The command-line options, passed to scanopt_init() */ -optspec_t flexopts[] = { - -{"-7", OPT_7BIT,0}, -{"--7bit", OPT_7BIT,0},/* Generate 7-bit scanner. */ -{"-8", OPT_8BIT,0}, -{"--8bit", OPT_8BIT,0},/* Generate 8-bit scanner. */ -{"--align", OPT_ALIGN,0},/* Trade off larger tables for better memory alignment. */ -{"--noalign", OPT_NO_ALIGN,0}, -{"--always-interactive", OPT_ALWAYS_INTERACTIVE,0}, -{"--array", OPT_ARRAY,0}, -{"-b", OPT_BACKUP,0}, -{"--backup", OPT_BACKUP,0},/* Generate backing-up information to lex.backup. */ -{"-B", OPT_BATCH,0}, -{"--batch", OPT_BATCH,0},/* Generate batch scanner (opposite of -I). */ -{"-i", OPT_CASE_INSENSITIVE,0}, -{"--case-insensitive", OPT_CASE_INSENSITIVE,0},/* Generate case-insensitive scanner. */ -{"-C[aefFmr]", OPT_COMPRESSION,"Specify degree of table compression (default is -Cem)"}, -{"-+", OPT_CPLUSPLUS,0}, -{"--c++", OPT_CPLUSPLUS,0},/* Generate C++ scanner class. */ -{"-d", OPT_DEBUG,0}, -{"--debug", OPT_DEBUG,0},/* Turn on debug mode in generated scanner. */ -{"--nodebug", OPT_NO_DEBUG,0}, -{"-s", OPT_NO_DEFAULT,0}, -{"--nodefault", OPT_NO_DEFAULT,0},/* Suppress default rule to ECHO unmatched text. */ -{"--default", OPT_DEFAULT,0}, -{"-c", OPT_DONOTHING,0},/* For POSIX lex compatibility. */ -{"-n", OPT_DONOTHING,0},/* For POSIX lex compatibility. */ -{"--ecs", OPT_ECS,0},/* Construct equivalence classes. */ -{"--noecs", OPT_NO_ECS,0}, -{"-F", OPT_FAST,0}, -{"--fast", OPT_FAST,0},/* Same as -CFr. */ -{"-f", OPT_FULL,0}, -{"--full", OPT_FULL,0},/* Same as -Cfr. */ -{"--header[=FILE]", OPT_HEADER,0}, -{"-?", OPT_HELP,0}, -{"-h", OPT_HELP,0}, -{"--help", OPT_HELP,0},/* Produce this help message. */ -{"-I", OPT_INTERACTIVE,0}, -{"--interactive", OPT_INTERACTIVE,0},/* Generate interactive scanner (opposite of -B). */ -{"-l", OPT_LEX_COMPAT,0}, -{"--lex-compat", OPT_LEX_COMPAT,0},/* Maximal compatibility with original lex. */ -{"-X", OPT_POSIX_COMPAT,0}, -{"--posix-compat", OPT_POSIX_COMPAT,0},/* Maximal compatibility with POSIX lex. */ -{"-L", OPT_NO_LINE,0},/* Suppress #line directives in scanner. */ -{"--noline", OPT_NO_LINE,0},/* Suppress #line directives in scanner. */ -{"--main", OPT_MAIN,0}, /* use built-in main() function. */ -{"--nomain", OPT_NO_MAIN,0}, -{"--meta-ecs", OPT_META_ECS,0},/* Construct meta-equivalence classes. */ -{"--nometa-ecs", OPT_NO_META_ECS,0}, -{"--never-interactive", OPT_NEVER_INTERACTIVE,0}, -{"-o FILE", OPT_OUTFILE,0}, -{"--outfile=FILE", OPT_OUTFILE,0},/* Write to FILE (default is lex.yy.c) */ -{"-p", OPT_PERF_REPORT,0}, -{"--perf-report", OPT_PERF_REPORT,0},/* Generate performance report to stderr. */ -{"--pointer", OPT_POINTER,0}, -{"-P PREFIX", OPT_PREFIX,0}, -{"--prefix=PREFIX", OPT_PREFIX,0},/* Use PREFIX (default is yy) */ -{"-Dmacro", OPT_PREPROCDEFINE,0},/* Define a preprocessor symbol. */ -{"--read", OPT_READ,0},/* Use read(2) instead of stdio. */ -{"-R[b]", OPT_REENTRANT,0}, -{"--reentrant", OPT_REENTRANT,0},/* Generate a reentrant C scanner. */ -{"--noreentrant", OPT_NO_REENTRANT,0}, -{"--reentrant-bison", OPT_REENTRANT_BISON,0},/* Reentrant scanner to be called by a bison pure parser. */ -{"--reject", OPT_REJECT,0}, -{"--noreject", OPT_NO_REJECT,0}, -{"-S FILE", OPT_SKEL,0}, -{"--skel=FILE", OPT_SKEL,0},/* Use skeleton from FILE */ -{"--stack", OPT_STACK,0}, -{"--stdinit", OPT_STDINIT,0}, -{"--nostdinit", OPT_NO_STDINIT,0}, -{"-t", OPT_STDOUT,0}, -{"--stdout", OPT_STDOUT,0},/* Write generated scanner to stdout. */ -{"-T", OPT_TRACE,0}, -{"--trace", OPT_TRACE,0},/* Flex should run in trace mode. */ -{"--tables[=FILE]", OPT_TABLES,0},/* Save tables to FILE */ -{"--nounistd", OPT_NO_UNISTD_H,0}, /* Do not include unistd.h */ -{"-v", OPT_VERBOSE,0}, -{"--verbose", OPT_VERBOSE,0},/* Write summary of scanner statistics to stdout. */ -{"-V", OPT_VERSION,0}, -{"--version", OPT_VERSION,0},/* Report flex version. */ -{"--warn", OPT_WARN,0}, -{"-w", OPT_NO_WARN,0}, -{"--nowarn", OPT_NO_WARN,0},/* Suppress warning messages. */ -{"--yyclass=NAME", OPT_YYCLASS,0}, -{"--yylineno", OPT_YYLINENO,0}, -{"--noyylineno", OPT_NO_YYLINENO,0}, - -{"--yymore", OPT_YYMORE,0}, -{"--noyymore", OPT_NO_YYMORE,0}, -{"--noyywrap", OPT_NO_YYWRAP,0}, -{"--yywrap" , OPT_YYWRAP,0}, - -{"--nounput", OPT_NO_UNPUT,0}, -{"--noyy_push_state", OPT_NO_YY_PUSH_STATE,0}, -{"--noyy_pop_state", OPT_NO_YY_POP_STATE,0}, -{"--noyy_top_state", OPT_NO_YY_TOP_STATE,0}, -{"--noyy_scan_buffer", OPT_NO_YY_SCAN_BUFFER,0}, -{"--noyy_scan_bytes", OPT_NO_YY_SCAN_BYTES,0}, -{"--noyy_scan_string", OPT_NO_YY_SCAN_STRING,0}, -{"--noyyget_extra", OPT_NO_YYGET_EXTRA,0}, -{"--noyyset_extra", OPT_NO_YYSET_EXTRA,0}, -{"--noyyget_leng", OPT_NO_YYGET_LENG,0}, -{"--noyyget_text", OPT_NO_YYGET_TEXT,0}, -{"--noyyget_lineno", OPT_NO_YYGET_LINENO,0}, -{"--noyyset_lineno", OPT_NO_YYSET_LINENO,0}, -{"--noyyget_in", OPT_NO_YYGET_IN,0}, -{"--noyyset_in", OPT_NO_YYSET_IN,0}, -{"--noyyget_out", OPT_NO_YYGET_OUT,0}, -{"--noyyset_out", OPT_NO_YYSET_OUT,0}, -{"--noyyget_lval", OPT_NO_YYGET_LVAL,0}, -{"--noyyset_lval", OPT_NO_YYSET_LVAL,0}, -{"--noyyget_lloc", OPT_NO_YYGET_LLOC,0}, -{"--noyyset_lloc", OPT_NO_YYSET_LLOC,0}, - -{0,0,0} /* required final NULL entry.*/ +optspec_t flexopts[] = { + + {"-7", OPT_7BIT, 0} + , + {"--7bit", OPT_7BIT, 0} + , /* Generate 7-bit scanner. */ + {"-8", OPT_8BIT, 0} + , + {"--8bit", OPT_8BIT, 0} + , /* Generate 8-bit scanner. */ + {"--align", OPT_ALIGN, 0} + , /* Trade off larger tables for better memory alignment. */ + {"--noalign", OPT_NO_ALIGN, 0} + , + {"--always-interactive", OPT_ALWAYS_INTERACTIVE, 0} + , + {"--array", OPT_ARRAY, 0} + , + {"-b", OPT_BACKUP, 0} + , + {"--backup", OPT_BACKUP, 0} + , /* Generate backing-up information to lex.backup. */ + {"-B", OPT_BATCH, 0} + , + {"--batch", OPT_BATCH, 0} + , /* Generate batch scanner (opposite of -I). */ + {"-i", OPT_CASE_INSENSITIVE, 0} + , + {"--case-insensitive", OPT_CASE_INSENSITIVE, 0} + , /* Generate case-insensitive scanner. */ + + {"-C[aefFmr]", OPT_COMPRESSION, + "Specify degree of table compression (default is -Cem)"}, + {"-+", OPT_CPLUSPLUS, 0} + , + {"--c++", OPT_CPLUSPLUS, 0} + , /* Generate C++ scanner class. */ + {"-d", OPT_DEBUG, 0} + , + {"--debug", OPT_DEBUG, 0} + , /* Turn on debug mode in generated scanner. */ + {"--nodebug", OPT_NO_DEBUG, 0} + , + {"-s", OPT_NO_DEFAULT, 0} + , + {"--nodefault", OPT_NO_DEFAULT, 0} + , /* Suppress default rule to ECHO unmatched text. */ + {"--default", OPT_DEFAULT, 0} + , + {"-c", OPT_DONOTHING, 0} + , /* For POSIX lex compatibility. */ + {"-n", OPT_DONOTHING, 0} + , /* For POSIX lex compatibility. */ + {"--ecs", OPT_ECS, 0} + , /* Construct equivalence classes. */ + {"--noecs", OPT_NO_ECS, 0} + , + {"-F", OPT_FAST, 0} + , + {"--fast", OPT_FAST, 0} + , /* Same as -CFr. */ + {"-f", OPT_FULL, 0} + , + {"--full", OPT_FULL, 0} + , /* Same as -Cfr. */ + {"--header[=FILE]", OPT_HEADER, 0} + , + {"-?", OPT_HELP, 0} + , + {"-h", OPT_HELP, 0} + , + {"--help", OPT_HELP, 0} + , /* Produce this help message. */ + {"-I", OPT_INTERACTIVE, 0} + , + {"--interactive", OPT_INTERACTIVE, 0} + , /* Generate interactive scanner (opposite of -B). */ + {"-l", OPT_LEX_COMPAT, 0} + , + {"--lex-compat", OPT_LEX_COMPAT, 0} + , /* Maximal compatibility with original lex. */ + {"-X", OPT_POSIX_COMPAT, 0} + , + {"--posix-compat", OPT_POSIX_COMPAT, 0} + , /* Maximal compatibility with POSIX lex. */ + {"-L", OPT_NO_LINE, 0} + , /* Suppress #line directives in scanner. */ + {"--noline", OPT_NO_LINE, 0} + , /* Suppress #line directives in scanner. */ + {"--main", OPT_MAIN, 0} + , /* use built-in main() function. */ + {"--nomain", OPT_NO_MAIN, 0} + , + {"--meta-ecs", OPT_META_ECS, 0} + , /* Construct meta-equivalence classes. */ + {"--nometa-ecs", OPT_NO_META_ECS, 0} + , + {"--never-interactive", OPT_NEVER_INTERACTIVE, 0} + , + {"-o FILE", OPT_OUTFILE, 0} + , + {"--outfile=FILE", OPT_OUTFILE, 0} + , /* Write to FILE (default is lex.yy.c) */ + {"-p", OPT_PERF_REPORT, 0} + , + {"--perf-report", OPT_PERF_REPORT, 0} + , /* Generate performance report to stderr. */ + {"--pointer", OPT_POINTER, 0} + , + {"-P PREFIX", OPT_PREFIX, 0} + , + {"--prefix=PREFIX", OPT_PREFIX, 0} + , /* Use PREFIX (default is yy) */ + {"-Dmacro", OPT_PREPROCDEFINE, 0} + , /* Define a preprocessor symbol. */ + {"--read", OPT_READ, 0} + , /* Use read(2) instead of stdio. */ + {"-R[b]", OPT_REENTRANT, 0} + , + {"--reentrant", OPT_REENTRANT, 0} + , /* Generate a reentrant C scanner. */ + {"--noreentrant", OPT_NO_REENTRANT, 0} + , + {"--reentrant-bison", OPT_REENTRANT_BISON, 0} + , /* Reentrant scanner to be called by a bison pure parser. */ + {"--reject", OPT_REJECT, 0} + , + {"--noreject", OPT_NO_REJECT, 0} + , + {"-S FILE", OPT_SKEL, 0} + , + {"--skel=FILE", OPT_SKEL, 0} + , /* Use skeleton from FILE */ + {"--stack", OPT_STACK, 0} + , + {"--stdinit", OPT_STDINIT, 0} + , + {"--nostdinit", OPT_NO_STDINIT, 0} + , + {"-t", OPT_STDOUT, 0} + , + {"--stdout", OPT_STDOUT, 0} + , /* Write generated scanner to stdout. */ + {"-T", OPT_TRACE, 0} + , + {"--trace", OPT_TRACE, 0} + , /* Flex should run in trace mode. */ + {"--tables[=FILE]", OPT_TABLES, 0} + , /* Save tables to FILE */ + {"--nounistd", OPT_NO_UNISTD_H, 0} + , /* Do not include unistd.h */ + {"-v", OPT_VERBOSE, 0} + , + {"--verbose", OPT_VERBOSE, 0} + , /* Write summary of scanner statistics to stdout. */ + {"-V", OPT_VERSION, 0} + , + {"--version", OPT_VERSION, 0} + , /* Report flex version. */ + {"--warn", OPT_WARN, 0} + , + {"-w", OPT_NO_WARN, 0} + , + {"--nowarn", OPT_NO_WARN, 0} + , /* Suppress warning messages. */ + {"--yyclass=NAME", OPT_YYCLASS, 0} + , + {"--yylineno", OPT_YYLINENO, 0} + , + {"--noyylineno", OPT_NO_YYLINENO, 0} + , + + {"--yymore", OPT_YYMORE, 0} + , + {"--noyymore", OPT_NO_YYMORE, 0} + , + {"--noyywrap", OPT_NO_YYWRAP, 0} + , + {"--yywrap", OPT_YYWRAP, 0} + , + + {"--nounput", OPT_NO_UNPUT, 0} + , + {"--noyy_push_state", OPT_NO_YY_PUSH_STATE, 0} + , + {"--noyy_pop_state", OPT_NO_YY_POP_STATE, 0} + , + {"--noyy_top_state", OPT_NO_YY_TOP_STATE, 0} + , + {"--noyy_scan_buffer", OPT_NO_YY_SCAN_BUFFER, 0} + , + {"--noyy_scan_bytes", OPT_NO_YY_SCAN_BYTES, 0} + , + {"--noyy_scan_string", OPT_NO_YY_SCAN_STRING, 0} + , + {"--noyyget_extra", OPT_NO_YYGET_EXTRA, 0} + , + {"--noyyset_extra", OPT_NO_YYSET_EXTRA, 0} + , + {"--noyyget_leng", OPT_NO_YYGET_LENG, 0} + , + {"--noyyget_text", OPT_NO_YYGET_TEXT, 0} + , + {"--noyyget_lineno", OPT_NO_YYGET_LINENO, 0} + , + {"--noyyset_lineno", OPT_NO_YYSET_LINENO, 0} + , + {"--noyyget_in", OPT_NO_YYGET_IN, 0} + , + {"--noyyset_in", OPT_NO_YYSET_IN, 0} + , + {"--noyyget_out", OPT_NO_YYGET_OUT, 0} + , + {"--noyyset_out", OPT_NO_YYSET_OUT, 0} + , + {"--noyyget_lval", OPT_NO_YYGET_LVAL, 0} + , + {"--noyyset_lval", OPT_NO_YYSET_LVAL, 0} + , + {"--noyyget_lloc", OPT_NO_YYGET_LLOC, 0} + , + {"--noyyset_lloc", OPT_NO_YYSET_LLOC, 0} + , + + {0, 0, 0} /* required final NULL entry. */ }; /* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */ diff --git a/options.h b/options.h index cbf6472..b4fe066 100644 --- a/options.h +++ b/options.h @@ -38,90 +38,90 @@ extern optspec_t flexopts[]; enum flexopt_flag_t { - /* Use positive integers only, since they are return codes for scanopt. - * Order is not important. */ - OPT_7BIT=1, - OPT_8BIT, - OPT_ALIGN, - OPT_ALWAYS_INTERACTIVE, - OPT_ARRAY, - OPT_BACKUP, - OPT_BATCH, - OPT_CASE_INSENSITIVE, - OPT_COMPRESSION, - OPT_CPLUSPLUS, - OPT_DEBUG, - OPT_DEFAULT, - OPT_DONOTHING, - OPT_ECS, - OPT_FAST, - OPT_FULL, - OPT_HEADER, - OPT_HELP, - OPT_INTERACTIVE, - OPT_LEX_COMPAT, - OPT_POSIX_COMPAT, - OPT_MAIN, - OPT_META_ECS, - OPT_NEVER_INTERACTIVE, - OPT_NO_ALIGN, - OPT_NO_DEBUG, - OPT_NO_DEFAULT, - OPT_NO_ECS, - OPT_NO_LINE, - OPT_NO_MAIN, - OPT_NO_META_ECS, - OPT_NO_REENTRANT, - OPT_NO_REJECT, - OPT_NO_STDINIT, - OPT_NO_UNPUT, - OPT_NO_WARN, - OPT_NO_YYGET_EXTRA, - OPT_NO_YYGET_IN, - OPT_NO_YYGET_LENG, - OPT_NO_YYGET_LINENO, - OPT_NO_YYGET_LLOC, - OPT_NO_YYGET_LVAL, - OPT_NO_YYGET_OUT, - OPT_NO_YYGET_TEXT, - OPT_NO_YYLINENO, - OPT_NO_YYMORE, - OPT_NO_YYSET_EXTRA, - OPT_NO_YYSET_IN, - OPT_NO_YYSET_LINENO, - OPT_NO_YYSET_LLOC, - OPT_NO_YYSET_LVAL, - OPT_NO_YYSET_OUT, - OPT_NO_YYWRAP, - OPT_NO_YY_POP_STATE, - OPT_NO_YY_PUSH_STATE, - OPT_NO_YY_SCAN_BUFFER, - OPT_NO_YY_SCAN_BYTES, - OPT_NO_YY_SCAN_STRING, - OPT_NO_YY_TOP_STATE, - OPT_OUTFILE, - OPT_PERF_REPORT, - OPT_POINTER, - OPT_PREFIX, - OPT_PREPROCDEFINE, - OPT_READ, - OPT_REENTRANT, - OPT_REENTRANT_BISON, - OPT_REJECT, - OPT_SKEL, - OPT_STACK, - OPT_STDINIT, - OPT_STDOUT, - OPT_TABLES, - OPT_TRACE, - OPT_NO_UNISTD_H, - OPT_VERBOSE, - OPT_VERSION, - OPT_WARN, - OPT_YYCLASS, - OPT_YYLINENO, - OPT_YYMORE, - OPT_YYWRAP + /* Use positive integers only, since they are return codes for scanopt. + * Order is not important. */ + OPT_7BIT = 1, + OPT_8BIT, + OPT_ALIGN, + OPT_ALWAYS_INTERACTIVE, + OPT_ARRAY, + OPT_BACKUP, + OPT_BATCH, + OPT_CASE_INSENSITIVE, + OPT_COMPRESSION, + OPT_CPLUSPLUS, + OPT_DEBUG, + OPT_DEFAULT, + OPT_DONOTHING, + OPT_ECS, + OPT_FAST, + OPT_FULL, + OPT_HEADER, + OPT_HELP, + OPT_INTERACTIVE, + OPT_LEX_COMPAT, + OPT_POSIX_COMPAT, + OPT_MAIN, + OPT_META_ECS, + OPT_NEVER_INTERACTIVE, + OPT_NO_ALIGN, + OPT_NO_DEBUG, + OPT_NO_DEFAULT, + OPT_NO_ECS, + OPT_NO_LINE, + OPT_NO_MAIN, + OPT_NO_META_ECS, + OPT_NO_REENTRANT, + OPT_NO_REJECT, + OPT_NO_STDINIT, + OPT_NO_UNPUT, + OPT_NO_WARN, + OPT_NO_YYGET_EXTRA, + OPT_NO_YYGET_IN, + OPT_NO_YYGET_LENG, + OPT_NO_YYGET_LINENO, + OPT_NO_YYGET_LLOC, + OPT_NO_YYGET_LVAL, + OPT_NO_YYGET_OUT, + OPT_NO_YYGET_TEXT, + OPT_NO_YYLINENO, + OPT_NO_YYMORE, + OPT_NO_YYSET_EXTRA, + OPT_NO_YYSET_IN, + OPT_NO_YYSET_LINENO, + OPT_NO_YYSET_LLOC, + OPT_NO_YYSET_LVAL, + OPT_NO_YYSET_OUT, + OPT_NO_YYWRAP, + OPT_NO_YY_POP_STATE, + OPT_NO_YY_PUSH_STATE, + OPT_NO_YY_SCAN_BUFFER, + OPT_NO_YY_SCAN_BYTES, + OPT_NO_YY_SCAN_STRING, + OPT_NO_YY_TOP_STATE, + OPT_OUTFILE, + OPT_PERF_REPORT, + OPT_POINTER, + OPT_PREFIX, + OPT_PREPROCDEFINE, + OPT_READ, + OPT_REENTRANT, + OPT_REENTRANT_BISON, + OPT_REJECT, + OPT_SKEL, + OPT_STACK, + OPT_STDINIT, + OPT_STDOUT, + OPT_TABLES, + OPT_TRACE, + OPT_NO_UNISTD_H, + OPT_VERBOSE, + OPT_VERSION, + OPT_WARN, + OPT_YYCLASS, + OPT_YYLINENO, + OPT_YYMORE, + OPT_YYWRAP }; #endif diff --git a/scanopt.c b/scanopt.c index d7b0fa0..9fb6e70 100644 --- a/scanopt.c +++ b/scanopt.c @@ -39,15 +39,14 @@ #ifdef HAVE_STRCASECMP #define STRCASECMP(a,b) strcasecmp(a,b) #else -static int STRCASECMP PROTO((const char*, const char*)); +static int STRCASECMP PROTO ((const char *, const char *)); -static int STRCASECMP(a,b) - const char* a; - const char* b; +static int STRCASECMP (a, b) + const char *a; + const char *b; { - while(tolower(*a++) == tolower(*b++)) - ; - return b-a; + while (tolower (*a++) == tolower (*b++)) ; + return b - a; } #endif @@ -57,85 +56,91 @@ static int STRCASECMP(a,b) #define IS_LONG 0x08 struct _aux { - int flags; /* The above hex flags. */ - int namelen; /* Length of the actual option word, e.g., "--file[=foo]" is 4 */ - int printlen; /* Length of entire string, e.g., "--file[=foo]" is 12 */ + int flags; /* The above hex flags. */ + int namelen; /* Length of the actual option word, e.g., "--file[=foo]" is 4 */ + int printlen; /* Length of entire string, e.g., "--file[=foo]" is 12 */ }; -struct _scanopt_t -{ - const optspec_t * options; /* List of options. */ - struct _aux * aux; /* Auxiliary data about options. */ - int optc; /* Number of options. */ - int argc; /* Number of args. */ - char ** argv; /* Array of strings. */ - int index; /* Used as: argv[index][subscript]. */ - int subscript; - char no_err_msg; /* If true, do not print errors. */ - char has_long; - char has_short; +struct _scanopt_t { + const optspec_t *options; /* List of options. */ + struct _aux *aux; /* Auxiliary data about options. */ + int optc; /* Number of options. */ + int argc; /* Number of args. */ + char **argv; /* Array of strings. */ + int index; /* Used as: argv[index][subscript]. */ + int subscript; + char no_err_msg; /* If true, do not print errors. */ + char has_long; + char has_short; }; /* Accessor functions. These WOULD be one-liners, but portability calls. */ -static const char* NAME PROTO((struct _scanopt_t *, int)); -static int PRINTLEN PROTO((struct _scanopt_t *, int)); -static int RVAL PROTO((struct _scanopt_t *, int)); -static int FLAGS PROTO((struct _scanopt_t *, int)); -static const char* DESC PROTO((struct _scanopt_t *, int)); -static int scanopt_err PROTO(( struct _scanopt_t *, int, int, int)); -static int matchlongopt PROTO((char*,char**,int*,char**,int*)); -static int find_opt PROTO(( struct _scanopt_t *, int, char *, int, int *, int* opt_offset)); - -static const char* NAME(s,i) - struct _scanopt_t *s; int i; +static const char *NAME PROTO ((struct _scanopt_t *, int)); +static int PRINTLEN PROTO ((struct _scanopt_t *, int)); +static int RVAL PROTO ((struct _scanopt_t *, int)); +static int FLAGS PROTO ((struct _scanopt_t *, int)); +static const char *DESC PROTO ((struct _scanopt_t *, int)); +static int scanopt_err PROTO ((struct _scanopt_t *, int, int, int)); +static int matchlongopt PROTO ((char *, char **, int *, char **, int *)); +static int find_opt +PROTO ((struct _scanopt_t *, int, char *, int, int *, int *opt_offset)); + +static const char *NAME (s, i) + struct _scanopt_t *s; + int i; { - return s->options[i].opt_fmt + ((s->aux[i].flags & IS_LONG)?2:1); + return s->options[i].opt_fmt + + ((s->aux[i].flags & IS_LONG) ? 2 : 1); } -static int PRINTLEN(s,i) - struct _scanopt_t *s; int i; +static int PRINTLEN (s, i) + struct _scanopt_t *s; + int i; { - return s->aux[i].printlen; + return s->aux[i].printlen; } -static int RVAL(s,i) - struct _scanopt_t *s; int i; +static int RVAL (s, i) + struct _scanopt_t *s; + int i; { - return s->options[i].r_val; + return s->options[i].r_val; } -static int FLAGS(s,i) - struct _scanopt_t *s; int i; +static int FLAGS (s, i) + struct _scanopt_t *s; + int i; { - return s->aux[i].flags; + return s->aux[i].flags; } -static const char* DESC(s,i) - struct _scanopt_t *s; int i; +static const char *DESC (s, i) + struct _scanopt_t *s; + int i; { - return s->options[i].desc ? s->options[i].desc : ""; + return s->options[i].desc ? s->options[i].desc : ""; } #ifndef NO_SCANOPT_USAGE -static int get_cols PROTO((void)); +static int get_cols PROTO ((void)); -static int get_cols() +static int get_cols () { - char *env; - int cols = 80; /* default */ + char *env; + int cols = 80; /* default */ #ifdef HAVE_NCURSES_H - initscr(); - endwin(); - if ( COLS > 0 ) - return COLS; + initscr (); + endwin (); + if (COLS > 0) + return COLS; #endif - if((env = getenv("COLUMNS"))!=NULL) - cols=atoi(env); + if ((env = getenv ("COLUMNS")) != NULL) + cols = atoi (env); - return cols; + return cols; } #endif @@ -153,87 +158,87 @@ static int get_cols() (s)->subscript= 0; \ }while(0) -scanopt_t * -scanopt_init ( options, argc, argv, flags) - const optspec_t* options; - int argc; - char** argv; - int flags; +scanopt_t *scanopt_init (options, argc, argv, flags) + const optspec_t *options; + int argc; + char **argv; + int flags; { - int i; - struct _scanopt_t * s; - s = (struct _scanopt_t*)malloc(sizeof(struct _scanopt_t)); - - s->options = options; - s->optc = 0; - s->argc = argc; - s->argv = (char**)argv; - s->index = 1; - s->subscript = 0; - s->no_err_msg = (flags & SCANOPT_NO_ERR_MSG); - s->has_long = 0; - s->has_short = 0; - - /* Determine option count. (Find entry with all zeros).*/ - s->optc = 0; - while ( options[s->optc].opt_fmt - || options[s->optc].r_val - || options[s->optc].desc ) - s->optc++; - - /* Build auxiliary data */ - s->aux = (struct _aux*)malloc(s->optc * sizeof(struct _aux)); - - for (i=0; i < s->optc; i++) { - const char * p, *pname; - const struct optspec_t* opt; - struct _aux * aux; - - opt = s->options + i; - aux = s->aux + i; - - aux->flags = ARG_NONE; - - if( opt->opt_fmt[0] == '-' && opt->opt_fmt[1] == '-') { - aux->flags |= IS_LONG; - pname = opt->opt_fmt + 2; - s->has_long = 1; - }else{ - pname = opt->opt_fmt + 1; - s->has_short = 1; - } - aux->printlen = strlen(opt->opt_fmt); - - aux->namelen = 0; - for (p=pname+1; *p; p++) { - /* detect required arg */ - if (*p == '=' || isspace(*p) || !(aux->flags & IS_LONG)) { - if (aux->namelen==0) - aux->namelen = p - pname; - aux->flags |= ARG_REQ; - aux->flags &= ~ARG_NONE; - } - /* detect optional arg. This overrides required arg. */ - if (*p == '[') { - if (aux->namelen==0) - aux->namelen = p - pname; - aux->flags &= ~(ARG_REQ|ARG_NONE); - aux->flags |= ARG_OPT; - break; - } - } - if (aux->namelen ==0) - aux->namelen = p - pname; - } - return (scanopt_t*)s; + int i; + struct _scanopt_t *s; + s = (struct _scanopt_t *) malloc (sizeof (struct _scanopt_t)); + + s->options = options; + s->optc = 0; + s->argc = argc; + s->argv = (char **) argv; + s->index = 1; + s->subscript = 0; + s->no_err_msg = (flags & SCANOPT_NO_ERR_MSG); + s->has_long = 0; + s->has_short = 0; + + /* Determine option count. (Find entry with all zeros). */ + s->optc = 0; + while (options[s->optc].opt_fmt + || options[s->optc].r_val || options[s->optc].desc) + s->optc++; + + /* Build auxiliary data */ + s->aux = (struct _aux *) malloc (s->optc * sizeof (struct _aux)); + + for (i = 0; i < s->optc; i++) { + const char *p, *pname; + const struct optspec_t *opt; + struct _aux *aux; + + opt = s->options + i; + aux = s->aux + i; + + aux->flags = ARG_NONE; + + if (opt->opt_fmt[0] == '-' && opt->opt_fmt[1] == '-') { + aux->flags |= IS_LONG; + pname = opt->opt_fmt + 2; + s->has_long = 1; + } + else { + pname = opt->opt_fmt + 1; + s->has_short = 1; + } + aux->printlen = strlen (opt->opt_fmt); + + aux->namelen = 0; + for (p = pname + 1; *p; p++) { + /* detect required arg */ + if (*p == '=' || isspace (*p) + || !(aux->flags & IS_LONG)) { + if (aux->namelen == 0) + aux->namelen = p - pname; + aux->flags |= ARG_REQ; + aux->flags &= ~ARG_NONE; + } + /* detect optional arg. This overrides required arg. */ + if (*p == '[') { + if (aux->namelen == 0) + aux->namelen = p - pname; + aux->flags &= ~(ARG_REQ | ARG_NONE); + aux->flags |= ARG_OPT; + break; + } + } + if (aux->namelen == 0) + aux->namelen = p - pname; + } + return (scanopt_t *) s; } #ifndef NO_SCANOPT_USAGE /* these structs are for scanopt_usage(). */ struct usg_elem { - int idx; - struct usg_elem * next; - struct usg_elem * alias; + int idx; + struct usg_elem *next; + struct usg_elem *alias; }; typedef struct usg_elem usg_elem; @@ -249,101 +254,109 @@ typedef struct usg_elem usg_elem; [indent][option, alias1, alias2...][indent][description line1 description line2...] */ -int scanopt_usage (scanner,fp,usage) - scanopt_t* scanner; - FILE* fp; - const char* usage; +int scanopt_usage (scanner, fp, usage) + scanopt_t *scanner; + FILE *fp; + const char *usage; { - struct _scanopt_t * s; - int i,columns,indent=2; - usg_elem *byr_val=NULL; /* option indices sorted by r_val */ - usg_elem *store; /* array of preallocated elements. */ - int store_idx=0; - usg_elem *ue; - int maxlen[2]; - int desccol=0; - int print_run=0; - - maxlen[0] = 0; - maxlen[1] = 0; - - s = (struct _scanopt_t*)scanner; - - if (usage){ - fprintf(fp,"%s\n",usage); - }else{ - /* Find the basename of argv[0] */ - const char * p; - p = s->argv[0] + strlen(s->argv[0]); - while(p != s->argv[0] && *p != '/') - --p; - if (*p == '/') - p++; - - fprintf(fp,_("Usage: %s [OPTIONS]...\n"), p); - } - fprintf(fp,"\n"); - - /* Sort by r_val and string. Yes, this is O(n*n), but n is small. */ - store = (usg_elem*)malloc(s->optc*sizeof(usg_elem)); - for (i=0; i < s->optc; i++) { - - /* grab the next preallocate node. */ - ue = store + store_idx++; - ue->idx = i; - ue->next = ue->alias = NULL; - - /* insert into list.*/ - if( !byr_val ) - byr_val = ue; - else { - int found_alias=0; - usg_elem **ue_curr, **ptr_if_no_alias=NULL; - ue_curr = &byr_val; - while (*ue_curr) { - if( RVAL(s,(*ue_curr)->idx) == RVAL(s,ue->idx)) { - /* push onto the alias list. */ - ue_curr = &((*ue_curr)->alias); - found_alias=1; - break; - } - if( !ptr_if_no_alias - && STRCASECMP(NAME(s,(*ue_curr)->idx),NAME(s,ue->idx)) > 0){ - ptr_if_no_alias = ue_curr; - } - ue_curr = &((*ue_curr)->next); - } - if (!found_alias && ptr_if_no_alias) - ue_curr = ptr_if_no_alias; - ue->next = *ue_curr; - *ue_curr = ue; - } - } + struct _scanopt_t *s; + int i, columns, indent = 2; + usg_elem *byr_val = NULL; /* option indices sorted by r_val */ + usg_elem *store; /* array of preallocated elements. */ + int store_idx = 0; + usg_elem *ue; + int maxlen[2]; + int desccol = 0; + int print_run = 0; + + maxlen[0] = 0; + maxlen[1] = 0; + + s = (struct _scanopt_t *) scanner; + + if (usage) { + fprintf (fp, "%s\n", usage); + } + else { + /* Find the basename of argv[0] */ + const char *p; + + p = s->argv[0] + strlen (s->argv[0]); + while (p != s->argv[0] && *p != '/') + --p; + if (*p == '/') + p++; + + fprintf (fp, _("Usage: %s [OPTIONS]...\n"), p); + } + fprintf (fp, "\n"); + + /* Sort by r_val and string. Yes, this is O(n*n), but n is small. */ + store = (usg_elem *) malloc (s->optc * sizeof (usg_elem)); + for (i = 0; i < s->optc; i++) { + + /* grab the next preallocate node. */ + ue = store + store_idx++; + ue->idx = i; + ue->next = ue->alias = NULL; + + /* insert into list. */ + if (!byr_val) + byr_val = ue; + else { + int found_alias = 0; + usg_elem **ue_curr, **ptr_if_no_alias = NULL; + + ue_curr = &byr_val; + while (*ue_curr) { + if (RVAL (s, (*ue_curr)->idx) == + RVAL (s, ue->idx)) { + /* push onto the alias list. */ + ue_curr = &((*ue_curr)->alias); + found_alias = 1; + break; + } + if (!ptr_if_no_alias + && + STRCASECMP (NAME (s, (*ue_curr)->idx), + NAME (s, ue->idx)) > 0) { + ptr_if_no_alias = ue_curr; + } + ue_curr = &((*ue_curr)->next); + } + if (!found_alias && ptr_if_no_alias) + ue_curr = ptr_if_no_alias; + ue->next = *ue_curr; + *ue_curr = ue; + } + } #if 0 - if(1){ - printf("ORIGINAL:\n"); - for(i=0; i < s->optc;i++) - printf("%2d: %s\n",i,NAME(s,i)); - printf("SORTED:\n"); - ue = byr_val; - while(ue) { - usg_elem *ue2; - printf("%2d: %s\n",ue->idx,NAME(s,ue->idx)); - for(ue2=ue->alias; ue2; ue2=ue2->next) - printf(" +---> %2d: %s\n", ue2->idx, NAME(s,ue2->idx)); - ue = ue->next; - } - } + if (1) { + printf ("ORIGINAL:\n"); + for (i = 0; i < s->optc; i++) + printf ("%2d: %s\n", i, NAME (s, i)); + printf ("SORTED:\n"); + ue = byr_val; + while (ue) { + usg_elem *ue2; + + printf ("%2d: %s\n", ue->idx, NAME (s, ue->idx)); + for (ue2 = ue->alias; ue2; ue2 = ue2->next) + printf (" +---> %2d: %s\n", ue2->idx, + NAME (s, ue2->idx)); + ue = ue->next; + } + } #endif - /* Now build each row of output. */ + /* Now build each row of output. */ - /* first pass calculate how much room we need. */ - for (ue=byr_val; ue; ue=ue->next) { - usg_elem *ap; - int len=0; - int nshort=0,nlong=0; + /* first pass calculate how much room we need. */ + for (ue = byr_val; ue; ue = ue->next) { + usg_elem *ap; + int len = 0; + int nshort = 0, nlong = 0; #define CALC_LEN(i) do {\ @@ -353,45 +366,45 @@ int scanopt_usage (scanner,fp,usage) len += (nshort++||nlong)? 2+PRINTLEN(s,i) : PRINTLEN(s,i);\ }while(0) - if(!(FLAGS(s,ue->idx) & IS_LONG)) - CALC_LEN(ue->idx); - - /* do short aliases first.*/ - for(ap=ue->alias; ap; ap=ap->next){ - if(FLAGS(s,ap->idx) & IS_LONG) - continue; - CALC_LEN(ap->idx); - } - - if(FLAGS(s,ue->idx) & IS_LONG) - CALC_LEN(ue->idx); - - /* repeat the above loop, this time for long aliases. */ - for(ap=ue->alias; ap; ap=ap->next){ - if( !(FLAGS(s,ap->idx) & IS_LONG)) - continue; - CALC_LEN(ap->idx); - } - - if(len > maxlen[0]) - maxlen[0] = len; - - /* It's much easier to calculate length for description column!*/ - len = strlen(DESC(s,ue->idx)); - if(len > maxlen[1]) - maxlen[1] = len; - } - - /* Determine how much room we have, and how much we will allocate to each col. - * Do not address pathological cases. Output will just be ugly. */ - columns = get_cols() - 1; - if(maxlen[0] + maxlen[1] + indent*2 > columns ) { - /* col 0 gets whatever it wants. we'll wrap the desc col. */ - maxlen[1] = columns - (maxlen[0] + indent*2); - if(maxlen[1]< 14) /* 14 is arbitrary lower limit on desc width.*/ - maxlen[1]= INT_MAX; - } - desccol = maxlen[0] + indent*2; + if (!(FLAGS (s, ue->idx) & IS_LONG)) + CALC_LEN (ue->idx); + + /* do short aliases first. */ + for (ap = ue->alias; ap; ap = ap->next) { + if (FLAGS (s, ap->idx) & IS_LONG) + continue; + CALC_LEN (ap->idx); + } + + if (FLAGS (s, ue->idx) & IS_LONG) + CALC_LEN (ue->idx); + + /* repeat the above loop, this time for long aliases. */ + for (ap = ue->alias; ap; ap = ap->next) { + if (!(FLAGS (s, ap->idx) & IS_LONG)) + continue; + CALC_LEN (ap->idx); + } + + if (len > maxlen[0]) + maxlen[0] = len; + + /* It's much easier to calculate length for description column! */ + len = strlen (DESC (s, ue->idx)); + if (len > maxlen[1]) + maxlen[1] = len; + } + + /* Determine how much room we have, and how much we will allocate to each col. + * Do not address pathological cases. Output will just be ugly. */ + columns = get_cols () - 1; + if (maxlen[0] + maxlen[1] + indent * 2 > columns) { + /* col 0 gets whatever it wants. we'll wrap the desc col. */ + maxlen[1] = columns - (maxlen[0] + indent * 2); + if (maxlen[1] < 14) /* 14 is arbitrary lower limit on desc width. */ + maxlen[1] = INT_MAX; + } + desccol = maxlen[0] + indent * 2; #define PRINT_SPACES(fp,n)\ do{\ @@ -402,27 +415,28 @@ int scanopt_usage (scanner,fp,usage) }while(0) - /* Second pass (same as above loop), this time we print. */ - /* Sloppy hack: We iterate twice. The first time we print short and long options. - The second time we print those lines that have ONLY long options. */ - while(print_run++ < 2) { - for (ue=byr_val; ue; ue=ue->next) { - usg_elem *ap; - int nwords=0,nchars=0,has_short=0; + /* Second pass (same as above loop), this time we print. */ + /* Sloppy hack: We iterate twice. The first time we print short and long options. + The second time we print those lines that have ONLY long options. */ + while (print_run++ < 2) { + for (ue = byr_val; ue; ue = ue->next) { + usg_elem *ap; + int nwords = 0, nchars = 0, has_short = 0; /* TODO: get has_short schtick to work */ - has_short = !(FLAGS(s,ue->idx)&IS_LONG); - for(ap=ue->alias; ap; ap=ap->next){ - if(!(FLAGS(s,ap->idx) & IS_LONG)){ - has_short=1; - break; - } - } - if( (print_run == 1 && !has_short) || - (print_run == 2 && has_short)) - continue; - - PRINT_SPACES(fp,indent);nchars+=indent; + has_short = !(FLAGS (s, ue->idx) & IS_LONG); + for (ap = ue->alias; ap; ap = ap->next) { + if (!(FLAGS (s, ap->idx) & IS_LONG)) { + has_short = 1; + break; + } + } + if ((print_run == 1 && !has_short) || + (print_run == 2 && has_short)) + continue; + + PRINT_SPACES (fp, indent); + nchars += indent; /* Print, adding a ", " between aliases. */ #define PRINT_IT(i) do{\ @@ -431,121 +445,144 @@ int scanopt_usage (scanner,fp,usage) nchars+=fprintf(fp,"%s",s->options[i].opt_fmt);\ }while(0) - if(!(FLAGS(s,ue->idx) & IS_LONG)) - PRINT_IT(ue->idx); - - /* print short aliases first.*/ - for(ap=ue->alias; ap; ap=ap->next){ - if(!(FLAGS(s,ap->idx) & IS_LONG)) - PRINT_IT(ap->idx); - } - - - if(FLAGS(s,ue->idx) & IS_LONG) - PRINT_IT(ue->idx); - - /* repeat the above loop, this time for long aliases. */ - for(ap=ue->alias; ap; ap=ap->next){ - if( FLAGS(s,ap->idx) & IS_LONG) - PRINT_IT(ap->idx); - } - - /* pad to desccol */ - PRINT_SPACES(fp, desccol - nchars); - - /* Print description, wrapped to maxlen[1] columns.*/ - if(1){ - const char * pstart; - pstart = DESC(s,ue->idx); - while(1){ - int n=0; - const char * lastws=NULL,*p; - p=pstart; - - while(*p && n < maxlen[1] && *p != '\n'){ - if(isspace(*p) || *p=='-') - lastws = p; - n++; - p++; - } - - if(!*p){ /* hit end of desc. done. */ - fprintf(fp,"%s\n",pstart); - break; - } - else if(*p == '\n'){ /* print everything up to here then wrap.*/ - fprintf(fp,"%.*s\n",n,pstart); - PRINT_SPACES(fp,desccol); - pstart = p+1; - continue; - } - else{ /* we hit the edge of the screen. wrap at space if possible.*/ - if( lastws){ - fprintf(fp,"%.*s\n",lastws-pstart,pstart); - pstart = lastws+1; - }else{ - fprintf(fp,"%.*s\n",n,pstart); - pstart = p+1; - } - PRINT_SPACES(fp,desccol); - continue; - } - } - } - } - }/* end while */ - free(store); - return 0; + if (!(FLAGS (s, ue->idx) & IS_LONG)) + PRINT_IT (ue->idx); + + /* print short aliases first. */ + for (ap = ue->alias; ap; ap = ap->next) { + if (!(FLAGS (s, ap->idx) & IS_LONG)) + PRINT_IT (ap->idx); + } + + + if (FLAGS (s, ue->idx) & IS_LONG) + PRINT_IT (ue->idx); + + /* repeat the above loop, this time for long aliases. */ + for (ap = ue->alias; ap; ap = ap->next) { + if (FLAGS (s, ap->idx) & IS_LONG) + PRINT_IT (ap->idx); + } + + /* pad to desccol */ + PRINT_SPACES (fp, desccol - nchars); + + /* Print description, wrapped to maxlen[1] columns. */ + if (1) { + const char *pstart; + + pstart = DESC (s, ue->idx); + while (1) { + int n = 0; + const char *lastws = NULL, *p; + + p = pstart; + + while (*p && n < maxlen[1] + && *p != '\n') { + if (isspace (*p) + || *p == '-') lastws = + p; + n++; + p++; + } + + if (!*p) { /* hit end of desc. done. */ + fprintf (fp, "%s\n", + pstart); + break; + } + else if (*p == '\n') { /* print everything up to here then wrap. */ + fprintf (fp, "%.*s\n", n, + pstart); + PRINT_SPACES (fp, desccol); + pstart = p + 1; + continue; + } + else { /* we hit the edge of the screen. wrap at space if possible. */ + if (lastws) { + fprintf (fp, + "%.*s\n", + lastws - + pstart, + pstart); + pstart = + lastws + 1; + } + else { + fprintf (fp, + "%.*s\n", + n, + pstart); + pstart = p + 1; + } + PRINT_SPACES (fp, desccol); + continue; + } + } + } + } + } /* end while */ + free (store); + return 0; } #endif /* no scanopt_usage */ -static int -scanopt_err(s,opt_offset,is_short,err) - struct _scanopt_t * s; - int opt_offset; - int is_short; - int err; +static int scanopt_err (s, opt_offset, is_short, err) + struct _scanopt_t *s; + int opt_offset; + int is_short; + int err; { - const char *optname=""; - char optchar[2]; - const optspec_t * opt=NULL; - - if ( opt_offset >= 0) - opt = s->options + opt_offset; - - if ( !s->no_err_msg ) { - - if( s->index > 0 && s->index < s->argc){ - if (is_short ) { - optchar[0] = s->argv[s->index][s->subscript]; - optchar[1] = '\0'; - optname = optchar; - }else { - optname = s->argv[s->index]; - } - } - - fprintf(stderr,"%s: ", s->argv[0]); - switch (err) { - case SCANOPT_ERR_ARG_NOT_ALLOWED: - fprintf(stderr,_("option `%s' doesn't allow an argument\n"),optname); - break; - case SCANOPT_ERR_ARG_NOT_FOUND: - fprintf(stderr,_("option `%s' requires an argument\n"),optname); - break; - case SCANOPT_ERR_OPT_AMBIGUOUS: - fprintf(stderr,_("option `%s' is ambiguous\n"),optname); - break; - case SCANOPT_ERR_OPT_UNRECOGNIZED: - fprintf(stderr,_("Unrecognized option `%s'\n"),optname); - break; - default: - fprintf(stderr,_("Unknown error=(%d)\n"),err); - break; - } - } - return err; + const char *optname = ""; + char optchar[2]; + const optspec_t *opt = NULL; + + if (opt_offset >= 0) + opt = s->options + opt_offset; + + if (!s->no_err_msg) { + + if (s->index > 0 && s->index < s->argc) { + if (is_short) { + optchar[0] = + s->argv[s->index][s->subscript]; + optchar[1] = '\0'; + optname = optchar; + } + else { + optname = s->argv[s->index]; + } + } + + fprintf (stderr, "%s: ", s->argv[0]); + switch (err) { + case SCANOPT_ERR_ARG_NOT_ALLOWED: + fprintf (stderr, + _ + ("option `%s' doesn't allow an argument\n"), + optname); + break; + case SCANOPT_ERR_ARG_NOT_FOUND: + fprintf (stderr, + _("option `%s' requires an argument\n"), + optname); + break; + case SCANOPT_ERR_OPT_AMBIGUOUS: + fprintf (stderr, _("option `%s' is ambiguous\n"), + optname); + break; + case SCANOPT_ERR_OPT_UNRECOGNIZED: + fprintf (stderr, _("Unrecognized option `%s'\n"), + optname); + break; + default: + fprintf (stderr, _("Unknown error=(%d)\n"), err); + break; + } + } + return err; } @@ -555,46 +592,45 @@ scanopt_err(s,opt_offset,is_short,err) * optname will point to str + 2 * */ -static int -matchlongopt(str, optname ,optlen, arg, arglen) - char* str; - char** optname; - int* optlen; - char** arg; - int* arglen; +static int matchlongopt (str, optname, optlen, arg, arglen) + char *str; + char **optname; + int *optlen; + char **arg; + int *arglen; { - char * p; + char *p; - *optname = *arg = (char*)0; - *optlen = *arglen = 0; + *optname = *arg = (char *) 0; + *optlen = *arglen = 0; - /* Match regex /--./ */ - p = str; - if( p[0]!='-' || p[1]!='-' || !p[2]) - return 0; + /* Match regex /--./ */ + p = str; + if (p[0] != '-' || p[1] != '-' || !p[2]) + return 0; - p += 2; - *optname = (char*)p; + p += 2; + *optname = (char *) p; - /* find the end of optname */ - while(*p && *p != '=') - ++p; + /* find the end of optname */ + while (*p && *p != '=') + ++p; - *optlen = p - *optname; + *optlen = p - *optname; - if (!*p) - /* an option with no '=...' part. */ - return 1; + if (!*p) + /* an option with no '=...' part. */ + return 1; - /* We saw an '=' char. The rest of p is the arg.*/ - p++; - *arg = p; - while(*p) - ++p; - *arglen = p - *arg; + /* We saw an '=' char. The rest of p is the arg. */ + p++; + *arg = p; + while (*p) + ++p; + *arglen = p - *arg; - return 1; + return 1; } @@ -603,220 +639,231 @@ matchlongopt(str, optname ,optlen, arg, arglen) * Short options must be exact. * Return boolean true if found and no error. * Error stored in err_code or zero if no error. */ -static int -find_opt (s, lookup_long, optstart, len, err_code, opt_offset) - struct _scanopt_t * s; - int lookup_long; - char * optstart; - int len; - int *err_code; - int* opt_offset; +static int find_opt (s, lookup_long, optstart, len, err_code, opt_offset) + struct _scanopt_t *s; + int lookup_long; + char *optstart; + int len; + int *err_code; + int *opt_offset; { - int nmatch=0,lastr_val=0,i; - *err_code = 0; - *opt_offset = -1; - - if (!optstart) - return 0; - - for(i=0; i < s->optc; i++) { - char* optname; - optname = (char*)(s->options[i].opt_fmt + (lookup_long?2:1)); - - if (lookup_long && (s->aux[i].flags & IS_LONG)) { - if (len > s->aux[i].namelen) - continue; - - if (strncmp(optname, optstart, len) == 0) { - nmatch++; - *opt_offset = i; - - /* exact match overrides all.*/ - if(len == s->aux[i].namelen){ - nmatch=1; - break; - } - - /* ambiguity is ok between aliases. */ - if(lastr_val && lastr_val == s->options[i].r_val) - nmatch--; - lastr_val = s->options[i].r_val; - } - } - else if ( !lookup_long && !(s->aux[i].flags&IS_LONG)) { - if (optname[0] == optstart[0]){ - nmatch++; - *opt_offset = i; - } - } - } - - if ( nmatch == 0 ) { - *err_code = SCANOPT_ERR_OPT_UNRECOGNIZED; - *opt_offset = -1; - } - else if ( nmatch > 1) { - *err_code = SCANOPT_ERR_OPT_AMBIGUOUS; - *opt_offset = -1; - } - - return *err_code ? 0 : 1; + int nmatch = 0, lastr_val = 0, i; + + *err_code = 0; + *opt_offset = -1; + + if (!optstart) + return 0; + + for (i = 0; i < s->optc; i++) { + char *optname; + + optname = + (char *) (s->options[i].opt_fmt + + (lookup_long ? 2 : 1)); + + if (lookup_long && (s->aux[i].flags & IS_LONG)) { + if (len > s->aux[i].namelen) + continue; + + if (strncmp (optname, optstart, len) == 0) { + nmatch++; + *opt_offset = i; + + /* exact match overrides all. */ + if (len == s->aux[i].namelen) { + nmatch = 1; + break; + } + + /* ambiguity is ok between aliases. */ + if (lastr_val + && lastr_val == + s->options[i].r_val) nmatch--; + lastr_val = s->options[i].r_val; + } + } + else if (!lookup_long && !(s->aux[i].flags & IS_LONG)) { + if (optname[0] == optstart[0]) { + nmatch++; + *opt_offset = i; + } + } + } + + if (nmatch == 0) { + *err_code = SCANOPT_ERR_OPT_UNRECOGNIZED; + *opt_offset = -1; + } + else if (nmatch > 1) { + *err_code = SCANOPT_ERR_OPT_AMBIGUOUS; + *opt_offset = -1; + } + + return *err_code ? 0 : 1; } -int -scanopt (svoid, arg, optindex) - scanopt_t * svoid; - char ** arg; - int * optindex; +int scanopt (svoid, arg, optindex) + scanopt_t *svoid; + char **arg; + int *optindex; { - char * optname=NULL, * optarg=NULL, *pstart; - int namelen=0, arglen=0; - int errcode=0, has_next; - const optspec_t * optp; - struct _scanopt_t* s; - struct _aux * auxp; - int is_short; - int opt_offset = -1; - - s = (struct _scanopt_t*)svoid; - - /* Normalize return-parameters. */ - SAFE_ASSIGN(arg,NULL); - SAFE_ASSIGN(optindex , s->index); - - if ( s->index >= s->argc ) - return 0; - - /* pstart always points to the start of our current scan. */ - pstart = s->argv[s->index] + s->subscript; - if ( !pstart ) - return 0; - - if ( s->subscript == 0 ) { - - /* test for exact match of "--" */ - if ( pstart[0]=='-' && pstart[1]=='-' && !pstart[2]) { - SAFE_ASSIGN(optindex,s->index+1); - INC_INDEX(s,1); - return 0; - } - - /* Match an opt. */ - if(matchlongopt(pstart,&optname,&namelen,&optarg,&arglen)) { - - /* it LOOKS like an opt, but is it one?! */ - if( !find_opt(s, 1, optname, namelen, &errcode,&opt_offset)){ - scanopt_err(s,opt_offset,0,errcode); - return errcode; - } - /* We handle this below. */ - is_short=0; - - /* Check for short opt. */ - }else if ( pstart[0] == '-' && pstart[1]) { - /* Pass through to below. */ - is_short=1; - s->subscript++; - pstart++; - } - - else { - /* It's not an option. We're done. */ - return 0; - } - } - - /* We have to re-check the subscript status because it - * may have changed above. */ - - if(s->subscript != 0){ - - /* we are somewhere in a run of short opts, - * e.g., at the 'z' in `tar -xzf` */ - - optname = pstart; - namelen = 1; - is_short = 1; - - if(!find_opt(s, 0, pstart, namelen, &errcode,&opt_offset)) { - return scanopt_err(s,opt_offset,1,errcode); - } - - optarg = pstart+1; - arglen = 0; - while(optarg[arglen]) - arglen++; - - if (arglen==0) - optarg=NULL; - } - - /* At this point, we have a long or short option matched at opt_offset into - * the s->options array (and corresponding aux array). - * A trailing argument is in {optarg,arglen}, if any. - */ - - /* Look ahead in argv[] to see if there is something - * that we can use as an argument (if needed). */ - has_next = s->index+1 < s->argc - && strcmp("--",s->argv[s->index+1]) != 0; - - optp = s->options + opt_offset; - auxp = s->aux + opt_offset; - - /* case: no args allowed */ - if ( auxp->flags & ARG_NONE) { - if ( optarg){ - scanopt_err(s,opt_offset,is_short,errcode=SCANOPT_ERR_ARG_NOT_ALLOWED); - INC_INDEX(s,1); - return errcode; - } - INC_INDEX(s,1); - return optp->r_val; - } - - /* case: required */ - if (auxp->flags & ARG_REQ) { - if ( !optarg && !has_next) - return scanopt_err(s,opt_offset,is_short,SCANOPT_ERR_ARG_NOT_FOUND); - - if (!optarg) { - /* Let the next argv element become the argument. */ - SAFE_ASSIGN(arg,s->argv[s->index+1]); - INC_INDEX(s,2); - }else{ - SAFE_ASSIGN(arg,(char*)optarg); - INC_INDEX(s,1); - } - return optp->r_val; - } - - /* case: optional */ - if (auxp->flags & ARG_OPT){ - SAFE_ASSIGN(arg,optarg); - INC_INDEX(s,1); - return optp->r_val; - } - - - /* Should not reach here. */ - return 0; + char *optname = NULL, *optarg = NULL, *pstart; + int namelen = 0, arglen = 0; + int errcode = 0, has_next; + const optspec_t *optp; + struct _scanopt_t *s; + struct _aux *auxp; + int is_short; + int opt_offset = -1; + + s = (struct _scanopt_t *) svoid; + + /* Normalize return-parameters. */ + SAFE_ASSIGN (arg, NULL); + SAFE_ASSIGN (optindex, s->index); + + if (s->index >= s->argc) + return 0; + + /* pstart always points to the start of our current scan. */ + pstart = s->argv[s->index] + s->subscript; + if (!pstart) + return 0; + + if (s->subscript == 0) { + + /* test for exact match of "--" */ + if (pstart[0] == '-' && pstart[1] == '-' && !pstart[2]) { + SAFE_ASSIGN (optindex, s->index + 1); + INC_INDEX (s, 1); + return 0; + } + + /* Match an opt. */ + if (matchlongopt + (pstart, &optname, &namelen, &optarg, &arglen)) { + + /* it LOOKS like an opt, but is it one?! */ + if (!find_opt + (s, 1, optname, namelen, &errcode, + &opt_offset)) { + scanopt_err (s, opt_offset, 0, errcode); + return errcode; + } + /* We handle this below. */ + is_short = 0; + + /* Check for short opt. */ + } + else if (pstart[0] == '-' && pstart[1]) { + /* Pass through to below. */ + is_short = 1; + s->subscript++; + pstart++; + } + + else { + /* It's not an option. We're done. */ + return 0; + } + } + + /* We have to re-check the subscript status because it + * may have changed above. */ + + if (s->subscript != 0) { + + /* we are somewhere in a run of short opts, + * e.g., at the 'z' in `tar -xzf` */ + + optname = pstart; + namelen = 1; + is_short = 1; + + if (!find_opt + (s, 0, pstart, namelen, &errcode, &opt_offset)) { + return scanopt_err (s, opt_offset, 1, errcode); + } + + optarg = pstart + 1; + arglen = 0; + while (optarg[arglen]) + arglen++; + + if (arglen == 0) + optarg = NULL; + } + + /* At this point, we have a long or short option matched at opt_offset into + * the s->options array (and corresponding aux array). + * A trailing argument is in {optarg,arglen}, if any. + */ + + /* Look ahead in argv[] to see if there is something + * that we can use as an argument (if needed). */ + has_next = s->index + 1 < s->argc + && strcmp ("--", s->argv[s->index + 1]) != 0; + + optp = s->options + opt_offset; + auxp = s->aux + opt_offset; + + /* case: no args allowed */ + if (auxp->flags & ARG_NONE) { + if (optarg) { + scanopt_err (s, opt_offset, is_short, errcode = + SCANOPT_ERR_ARG_NOT_ALLOWED); + INC_INDEX (s, 1); + return errcode; + } + INC_INDEX (s, 1); + return optp->r_val; + } + + /* case: required */ + if (auxp->flags & ARG_REQ) { + if (!optarg && !has_next) + return scanopt_err (s, opt_offset, is_short, + SCANOPT_ERR_ARG_NOT_FOUND); + + if (!optarg) { + /* Let the next argv element become the argument. */ + SAFE_ASSIGN (arg, s->argv[s->index + 1]); + INC_INDEX (s, 2); + } + else { + SAFE_ASSIGN (arg, (char *) optarg); + INC_INDEX (s, 1); + } + return optp->r_val; + } + + /* case: optional */ + if (auxp->flags & ARG_OPT) { + SAFE_ASSIGN (arg, optarg); + INC_INDEX (s, 1); + return optp->r_val; + } + + + /* Should not reach here. */ + return 0; } -int -scanopt_destroy(svoid) - scanopt_t* svoid; +int scanopt_destroy (svoid) + scanopt_t *svoid; { - struct _scanopt_t* s; - s = (struct _scanopt_t*)svoid; - if ( s ) { - if (s->aux) - free (s->aux); - free(s); - } - return 0; + struct _scanopt_t *s; + + s = (struct _scanopt_t *) svoid; + if (s) { + if (s->aux) + free (s->aux); + free (s); + } + return 0; } diff --git a/scanopt.h b/scanopt.h index 49e303b..359a18a 100644 --- a/scanopt.h +++ b/scanopt.h @@ -45,42 +45,38 @@ #endif #ifdef __cplusplus -extern "C" { +extern "C" { #endif - #ifndef PROTO #define PROTO(args) args #endif - -/* Error codes. */ -enum scanopt_err_t { - SCANOPT_ERR_OPT_UNRECOGNIZED = -1, /* Unrecognized option. */ - SCANOPT_ERR_OPT_AMBIGUOUS = -2, /* It matched more than one option name. */ - SCANOPT_ERR_ARG_NOT_FOUND= -3, /* The required arg was not found.*/ - SCANOPT_ERR_ARG_NOT_ALLOWED = -4 /* Option does not take an argument. */ -}; +/* Error codes. */ enum scanopt_err_t { + SCANOPT_ERR_OPT_UNRECOGNIZED = -1, /* Unrecognized option. */ + SCANOPT_ERR_OPT_AMBIGUOUS = -2, /* It matched more than one option name. */ + SCANOPT_ERR_ARG_NOT_FOUND = -3, /* The required arg was not found. */ + SCANOPT_ERR_ARG_NOT_ALLOWED = -4 /* Option does not take an argument. */ + }; /* flags passed to scanopt_init */ -enum scanopt_flag_t { - SCANOPT_NO_ERR_MSG = 0x01 /* Suppress printing to stderr. */ -}; + enum scanopt_flag_t { + SCANOPT_NO_ERR_MSG = 0x01 /* Suppress printing to stderr. */ + }; /* Specification for a single option. */ -struct optspec_t -{ - const char * opt_fmt; /* e.g., "--foo=FILE", "-f FILE", "-n [NUM]" */ - int r_val; /* Value to be returned by scanopt_ex(). */ - const char* desc; /* Brief description of this option, or NULL. */ -}; -typedef struct optspec_t optspec_t; + struct optspec_t { + const char *opt_fmt; /* e.g., "--foo=FILE", "-f FILE", "-n [NUM]" */ + int r_val; /* Value to be returned by scanopt_ex(). */ + const char *desc; /* Brief description of this option, or NULL. */ + }; + typedef struct optspec_t optspec_t; /* Used internally by scanopt() to maintain state. */ /* Never modify these value directly. */ -typedef void * scanopt_t; - + typedef void *scanopt_t; + /* Initializes scanner and checks option list for errors. * Parameters: * options - Array of options. @@ -89,12 +85,12 @@ typedef void * scanopt_t; * flags - Control behavior. * Return: A malloc'd pointer . */ -scanopt_t* scanopt_init PROTO(( const optspec_t* options, - int argc, char** argv, int flags )); + scanopt_t *scanopt_init PROTO ((const optspec_t * options, + int argc, char **argv, int flags)); /* Frees memory used by scanner. * Always returns 0. */ -int scanopt_destroy PROTO((scanopt_t* scanner)); + int scanopt_destroy PROTO ((scanopt_t * scanner)); #ifndef NO_SCANOPT_USAGE /* Prints a usage message based on contents of optlist. @@ -104,7 +100,10 @@ int scanopt_destroy PROTO((scanopt_t* scanner)); * usage - Text to be prepended to option list. May be NULL. * Return: Always returns 0 (zero). */ -int scanopt_usage PROTO(( scanopt_t* scanner, FILE* fp, const char* usage)); + int scanopt_usage + PROTO ( + (scanopt_t * scanner, FILE * fp, + const char *usage)); #endif /* Scans command-line options in argv[]. @@ -121,11 +120,13 @@ int scanopt_usage PROTO(( scanopt_t* scanner, FILE* fp, const char* usage)); * < 0 on error (return value is an error code). * */ -int scanopt PROTO(( scanopt_t * scanner, char ** optarg, int * optindex)); + int scanopt + PROTO ( + (scanopt_t * scanner, char **optarg, + int *optindex)); #ifdef __cplusplus } #endif #endif - /* vim:set tabstop=8 softtabstop=4 shiftwidth=4: */ diff --git a/sym.c b/sym.c index 16ea004..20cecba 100644 --- a/sym.c +++ b/sym.c @@ -39,13 +39,12 @@ * ccltab - character class text symbol table */ -struct hash_entry - { +struct hash_entry { struct hash_entry *prev, *next; - char *name; - char *str_val; - int int_val; - } ; + char *name; + char *str_val; + int int_val; +}; typedef struct hash_entry **hash_table; @@ -53,17 +52,19 @@ typedef struct hash_entry **hash_table; #define START_COND_HASH_SIZE 101 #define CCL_HASH_SIZE 101 -static struct hash_entry *ndtbl[NAME_TABLE_HASH_SIZE]; +static struct hash_entry *ndtbl[NAME_TABLE_HASH_SIZE]; static struct hash_entry *sctbl[START_COND_HASH_SIZE]; static struct hash_entry *ccltab[CCL_HASH_SIZE]; /* declare functions that have forward references */ -static int addsym PROTO((register char[], char*, int, hash_table, int)); -static struct hash_entry *findsym PROTO(( register const char *sym, - hash_table table, int table_size)); -static int hashfunct PROTO((register const char*, int)); +static int addsym PROTO ((register char[], char *, int, hash_table, int)); +static struct hash_entry *findsym PROTO ((register const char *sym, + hash_table table, + + int table_size)); +static int hashfunct PROTO ((register const char *, int)); /* addsym - add symbol and definitions to symbol table @@ -71,40 +72,37 @@ static int hashfunct PROTO((register const char*, int)); * -1 is returned if the symbol already exists, and the change not made. */ -static int addsym( sym, str_def, int_def, table, table_size ) -register char sym[]; -char *str_def; -int int_def; -hash_table table; -int table_size; - { - int hash_val = hashfunct( sym, table_size ); +static int addsym (sym, str_def, int_def, table, table_size) + register char sym[]; + char *str_def; + int int_def; + hash_table table; + int table_size; +{ + int hash_val = hashfunct (sym, table_size); register struct hash_entry *sym_entry = table[hash_val]; register struct hash_entry *new_entry; register struct hash_entry *successor; - while ( sym_entry ) - { - if ( ! strcmp( sym, sym_entry->name ) ) - { /* entry already exists */ + while (sym_entry) { + if (!strcmp (sym, sym_entry->name)) { /* entry already exists */ return -1; - } + } sym_entry = sym_entry->next; - } + } /* create new entry */ new_entry = (struct hash_entry *) - flex_alloc( sizeof( struct hash_entry ) ); + flex_alloc (sizeof (struct hash_entry)); - if ( new_entry == NULL ) - flexfatal( _( "symbol table memory allocation failed" ) ); + if (new_entry == NULL) + flexfatal (_("symbol table memory allocation failed")); - if ( (successor = table[hash_val]) != 0 ) - { + if ((successor = table[hash_val]) != 0) { new_entry->next = successor; successor->prev = new_entry; - } + } else new_entry->next = NULL; @@ -116,23 +114,22 @@ int table_size; table[hash_val] = new_entry; return 0; - } +} /* cclinstal - save the text of a character class */ -void cclinstal( ccltxt, cclnum ) -Char ccltxt[]; -int cclnum; - { +void cclinstal (ccltxt, cclnum) + Char ccltxt[]; + int cclnum; +{ /* We don't bother checking the return status because we are not * called unless the symbol is new. */ - (void) addsym( (char *) copy_unsigned_string( ccltxt ), - (char *) 0, cclnum, - ccltab, CCL_HASH_SIZE ); - } + (void) addsym ((char *) copy_unsigned_string (ccltxt), + (char *) 0, cclnum, ccltab, CCL_HASH_SIZE); +} /* ccllookup - lookup the number associated with character class text @@ -140,73 +137,71 @@ int cclnum; * Returns 0 if there's no CCL associated with the text. */ -int ccllookup( ccltxt ) -Char ccltxt[]; - { - return findsym( (char *) ccltxt, ccltab, CCL_HASH_SIZE )->int_val; - } +int ccllookup (ccltxt) + Char ccltxt[]; +{ + return findsym ((char *) ccltxt, ccltab, CCL_HASH_SIZE)->int_val; +} /* findsym - find symbol in symbol table */ -static struct hash_entry *findsym( sym, table, table_size ) -register const char *sym; -hash_table table; -int table_size; - { - static struct hash_entry empty_entry = - { +static struct hash_entry *findsym (sym, table, table_size) + register const char *sym; + hash_table table; + int table_size; +{ + static struct hash_entry empty_entry = { (struct hash_entry *) 0, (struct hash_entry *) 0, (char *) 0, (char *) 0, 0, - } ; + }; register struct hash_entry *sym_entry = - table[hashfunct( sym, table_size )]; - while ( sym_entry ) - { - if ( ! strcmp( sym, sym_entry->name ) ) + table[hashfunct (sym, table_size)]; + + while (sym_entry) { + if (!strcmp (sym, sym_entry->name)) return sym_entry; sym_entry = sym_entry->next; - } + } return &empty_entry; - } +} /* hashfunct - compute the hash value for "str" and hash size "hash_size" */ -static int hashfunct( str, hash_size ) -register const char *str; -int hash_size; - { +static int hashfunct (str, hash_size) + register const char *str; + int hash_size; +{ register int hashval; register int locstr; hashval = 0; locstr = 0; - while ( str[locstr] ) - { + while (str[locstr]) { hashval = (hashval << 1) + (unsigned char) str[locstr++]; hashval %= hash_size; - } + } return hashval; - } +} /* ndinstal - install a name definition */ -void ndinstal( name, definition ) -const char *name; -Char definition[]; - { +void ndinstal (name, definition) + const char *name; + Char definition[]; +{ - if ( addsym( copy_string( name ), - (char *) copy_unsigned_string( definition ), 0, - ndtbl, NAME_TABLE_HASH_SIZE ) ) - synerr( _( "name defined twice" ) ); - } + if (addsym (copy_string (name), + (char *) copy_unsigned_string (definition), 0, + ndtbl, NAME_TABLE_HASH_SIZE)) + synerr (_("name defined twice")); +} /* ndlookup - lookup a name definition @@ -214,27 +209,27 @@ Char definition[]; * Returns a nil pointer if the name definition does not exist. */ -Char *ndlookup( nd ) -const char *nd; - { - return (Char *) findsym( nd, ndtbl, NAME_TABLE_HASH_SIZE )->str_val; - } +Char *ndlookup (nd) + const char *nd; +{ + return (Char *) findsym (nd, ndtbl, NAME_TABLE_HASH_SIZE)->str_val; +} /* scextend - increase the maximum number of start conditions */ -void scextend() - { +void scextend () +{ current_max_scs += MAX_SCS_INCREMENT; ++num_reallocs; - scset = reallocate_integer_array( scset, current_max_scs ); - scbol = reallocate_integer_array( scbol, current_max_scs ); - scxclu = reallocate_integer_array( scxclu, current_max_scs ); - sceof = reallocate_integer_array( sceof, current_max_scs ); - scname = reallocate_char_ptr_array( scname, current_max_scs ); - } + scset = reallocate_integer_array (scset, current_max_scs); + scbol = reallocate_integer_array (scbol, current_max_scs); + scxclu = reallocate_integer_array (scxclu, current_max_scs); + sceof = reallocate_integer_array (sceof, current_max_scs); + scname = reallocate_char_ptr_array (scname, current_max_scs); +} /* scinstal - make a start condition @@ -243,30 +238,30 @@ void scextend() * The start condition is "exclusive" if xcluflg is true. */ -void scinstal( str, xcluflg ) -const char *str; -int xcluflg; - { +void scinstal (str, xcluflg) + const char *str; + int xcluflg; +{ /* Generate start condition definition, for use in BEGIN et al. */ - action_define( str, lastsc ); + action_define (str, lastsc); - if ( ++lastsc >= current_max_scs ) - scextend(); + if (++lastsc >= current_max_scs) + scextend (); - scname[lastsc] = copy_string( str ); + scname[lastsc] = copy_string (str); - if ( addsym( scname[lastsc], (char *) 0, lastsc, - sctbl, START_COND_HASH_SIZE ) ) - format_pinpoint_message( - _( "start condition %s declared twice" ), - str ); + if (addsym (scname[lastsc], (char *) 0, lastsc, + sctbl, START_COND_HASH_SIZE)) + format_pinpoint_message (_ + ("start condition %s declared twice"), +str); - scset[lastsc] = mkstate( SYM_EPSILON ); - scbol[lastsc] = mkstate( SYM_EPSILON ); + scset[lastsc] = mkstate (SYM_EPSILON); + scbol[lastsc] = mkstate (SYM_EPSILON); scxclu[lastsc] = xcluflg; sceof[lastsc] = false; - } +} /* sclookup - lookup the number associated with a start condition @@ -274,8 +269,8 @@ int xcluflg; * Returns 0 if no such start condition. */ -int sclookup( str ) -const char *str; - { - return findsym( str, sctbl, START_COND_HASH_SIZE )->int_val; - } +int sclookup (str) + const char *str; +{ + return findsym (str, sctbl, START_COND_HASH_SIZE)->int_val; +} diff --git a/tables.c b/tables.c index 5178f87..426ed72 100644 --- a/tables.c +++ b/tables.c @@ -47,13 +47,16 @@ int yytbl_fwrite32 (FILE * out, uint32_t v); int yytbl_fwrite16 (FILE * out, uint16_t v); int yytbl_fwrite8 (FILE * out, uint8_t v); -void yytbl_hdr_init (struct yytbl_hdr *th, const char *version_str, const char *name) +void yytbl_hdr_init (struct yytbl_hdr *th, const char *version_str, + const char *name) { memset (th, 0, sizeof (struct yytbl_hdr)); th->th_magic = 0xF13C57B1; - th->th_hsize = yypad64 (20 + strlen (version_str) + 1 + strlen (name) + 1); - th->th_ssize = 0; // Not known at this point. + th->th_hsize = + yypad64 (20 + strlen (version_str) + 1 + strlen (name) + + 1); + th->th_ssize = 0; // Not known at this point. th->th_flags = 0; th->th_version = copy_string (version_str); th->th_name = copy_string (name); @@ -65,19 +68,20 @@ struct yytbl_data *yytbl_data_create (enum yytbl_id id) td = (struct yytbl_data *) flex_alloc (sizeof (struct yytbl_data)); memset (td, 0, sizeof (struct yytbl_data)); + td->t_id = id; return td; } -int yytbl_hdr_fwrite (FILE * out, struct yytbl_hdr *th) +int yytbl_hdr_fwrite (FILE * out, struct yytbl_hdr *th) { size_t sz, rv; int pad, bwritten = 0; if (yytbl_fwrite32 (out, th->th_magic) < 0 - || yytbl_fwrite32 (out, th->th_hsize) < 0 - || yytbl_fwrite32 (out, th->th_ssize) < 0 - || yytbl_fwrite16 (out, th->th_flags) < 0) + || yytbl_fwrite32 (out, th->th_hsize) < 0 + || yytbl_fwrite32 (out, th->th_ssize) < 0 + || yytbl_fwrite16 (out, th->th_flags) < 0) return -1; else bwritten += 3 * 4 + 2; @@ -109,7 +113,7 @@ int yytbl_hdr_fwrite (FILE * out, struct yytbl_hdr *th) return bwritten; } -int yytbl_fwrite32 (FILE * out, uint32_t v) +int yytbl_fwrite32 (FILE * out, uint32_t v) { uint32_t vnet; size_t bytes, rv; @@ -122,7 +126,7 @@ int yytbl_fwrite32 (FILE * out, uint32_t v) return bytes; } -int yytbl_fwrite16 (FILE * out, uint16_t v) +int yytbl_fwrite16 (FILE * out, uint16_t v) { uint16_t vnet; size_t bytes, rv; @@ -135,7 +139,7 @@ int yytbl_fwrite16 (FILE * out, uint16_t v) return bytes; } -int yytbl_fwrite8 (FILE * out, uint8_t v) +int yytbl_fwrite8 (FILE * out, uint8_t v) { size_t bytes, rv; @@ -164,7 +168,9 @@ static int min_int_size (void *arr, int32_t len, int sz) curr = abs (((int32_t *) arr)[i]); break; default: - fprintf (stderr, "Illegal size (%d) in min_int_size\n", sz); + fprintf (stderr, + "Illegal size (%d) in min_int_size\n", + sz); return 32; } if (curr > max) @@ -187,15 +193,18 @@ static int32_t yytbl_data_geti (const struct yytbl_data *tbl, int i, int j) } /* Transform data to smallest possible of (int32, int16, int8) */ -void yytbl_data_compress (struct yytbl_data *tbl) +void yytbl_data_compress (struct yytbl_data *tbl) { int32_t i, sz; void *newdata = 0; - if (tbl->t_id != YYT_ID_TRANSITION && tbl->t_id != YYT_ID_START_STATE_LIST) { + if (tbl->t_id != YYT_ID_TRANSITION + && tbl->t_id != YYT_ID_START_STATE_LIST) { if (tbl->t_hilen == 0) { /* Data is a single-dimensional array of ints */ - sz = min_int_size (tbl->t_data, tbl->t_lolen, TFLAGS2BYTES (tbl->t_flags)); + sz = + min_int_size (tbl->t_data, tbl->t_lolen, + TFLAGS2BYTES (tbl->t_flags)); if (sz == TFLAGS2BYTES (tbl->t_flags)) /* No change in this table needed. */ return; @@ -215,12 +224,16 @@ void yytbl_data_compress (struct yytbl_data *tbl) ((int8_t *) newdata)[i] = (int8_t) n; break; case sizeof (int16_t): - ((int16_t *) newdata)[i] = (int16_t) n; + + ((int16_t *) newdata)[i] = + (int16_t) n; break; case sizeof (int32_t): - ((int32_t *) newdata)[i] = (int32_t) n; + + ((int32_t *) newdata)[i] = + (int32_t) n; break; - default: /* TODO: ERROR: unknown 'sz' */ + default: /* TODO: ERROR: unknown 'sz' */ break; } } @@ -233,10 +246,10 @@ void yytbl_data_compress (struct yytbl_data *tbl) } } else if (tbl->t_id == YYT_ID_TRANSITION) { - /* Data is an array of structs */ + /* Data is an array of structs */ } else if (tbl->t_id == YYT_ID_START_STATE_LIST) { - /* Data is an array of pointers */ + /* Data is an array of pointers */ } } diff --git a/tables_shared.h b/tables_shared.h index 3ef0905..bf20668 100644 --- a/tables_shared.h +++ b/tables_shared.h @@ -54,50 +54,45 @@ /** Possible values for t_id field. Each one corresponds to a * scanner table of the same name. */ -enum yytbl_id -{ - YYT_ID_ACCEPT = 0x01, - YYT_ID_BASE = 0x02, - YYT_ID_CHK = 0x03, - YYT_ID_DEF = 0x04, - YYT_ID_EC = 0x05, - YYT_ID_META = 0x06, - YYT_ID_NUL_TRANS = 0x07, - YYT_ID_NXT = 0x08, /**< may be 2 dimensional array */ - YYT_ID_RULE_CAN_MATCH_EOL = 0x09, - YYT_ID_START_STATE_LIST = 0x0A, /**< array of pointers */ - YYT_ID_TRANSITION = 0x0B /**< array of structs */ +enum yytbl_id { + YYT_ID_ACCEPT = 0x01, + YYT_ID_BASE = 0x02, + YYT_ID_CHK = 0x03, + YYT_ID_DEF = 0x04, + YYT_ID_EC = 0x05, + YYT_ID_META = 0x06, + YYT_ID_NUL_TRANS = 0x07, + YYT_ID_NXT = 0x08, /**< may be 2 dimensional array */ + YYT_ID_RULE_CAN_MATCH_EOL = 0x09, + YYT_ID_START_STATE_LIST = 0x0A, /**< array of pointers */ + YYT_ID_TRANSITION = 0x0B /**< array of structs */ }; /** bit flags for t_flags field of struct yytbl_data */ -enum yytbl_flags -{ - YYT_DATA8 = 0x01, /**< data is an array of type int8_t */ - YYT_DATA16 = 0x02, /**< data is an array of type int16_t */ - YYT_DATA32 = 0x04, /**< data is an array of type int32_t */ - YYT_PTRANS = 0x08, /**< data is a list of indexes of entries +enum yytbl_flags { + YYT_DATA8 = 0x01, /**< data is an array of type int8_t */ + YYT_DATA16 = 0x02, /**< data is an array of type int16_t */ + YYT_DATA32 = 0x04, /**< data is an array of type int32_t */ + YYT_PTRANS = 0x08, /**< data is a list of indexes of entries into the expanded `yy_transition' array. See notes in manual. */ }; /* The serialized tables header. */ -struct yytbl_hdr -{ - uint32_t th_magic; /**< Must be 0xF13C57B1 (comes from "Flex Table") */ - uint32_t th_hsize; /**< Size of this header in bytes. */ - uint32_t th_ssize; /**< Size of this dataset, in bytes, including header. */ - uint16_t th_flags; /**< Currently unused, must be 0 */ - char* th_version; /**< Flex version string. NUL terminated. */ - char* th_name; /**< The name of this table set. NUL terminated. */ +struct yytbl_hdr { + uint32_t th_magic; /**< Must be 0xF13C57B1 (comes from "Flex Table") */ + uint32_t th_hsize; /**< Size of this header in bytes. */ + uint32_t th_ssize; /**< Size of this dataset, in bytes, including header. */ + uint16_t th_flags; /**< Currently unused, must be 0 */ + char *th_version; /**< Flex version string. NUL terminated. */ + char *th_name; /**< The name of this table set. NUL terminated. */ }; /** A single serialized table */ -struct yytbl_data -{ - enum yytbl_id t_id; /**< table identifier */ - uint16_t t_flags; /**< how to interpret this data */ - uint32_t t_hilen; /**< num elements in highest dimension array */ - uint32_t t_lolen; /**< num elements in lowest dimension array */ - void* t_data; /**< table data */ +struct yytbl_data { + enum yytbl_id t_id; /**< table identifier */ + uint16_t t_flags; /**< how to interpret this data */ + uint32_t t_hilen; /**< num elements in highest dimension array */ + uint32_t t_lolen; /**< num elements in lowest dimension array */ + void *t_data; /**< table data */ }; - diff --git a/tblcmp.c b/tblcmp.c index 9448b24..a56aaab 100644 --- a/tblcmp.c +++ b/tblcmp.c @@ -36,11 +36,11 @@ /* declarations for functions that have forward references */ -void mkentry PROTO((register int*, int, int, int, int)); -void mkprot PROTO((int[], int, int)); -void mktemplate PROTO((int[], int, int)); -void mv2front PROTO((int)); -int tbldiff PROTO((int[], int, int[])); +void mkentry PROTO ((register int *, int, int, int, int)); +void mkprot PROTO ((int[], int, int)); +void mktemplate PROTO ((int[], int, int)); +void mv2front PROTO ((int)); +int tbldiff PROTO ((int[], int, int[])); /* bldtbl - build table entries for dfa state @@ -78,11 +78,11 @@ int tbldiff PROTO((int[], int, int[])); * cost only one difference. */ -void bldtbl( state, statenum, totaltrans, comstate, comfreq ) -int state[], statenum, totaltrans, comstate, comfreq; - { - int extptr, extrct[2][CSIZE + 1]; - int mindiff, minprot, i, d; +void bldtbl (state, statenum, totaltrans, comstate, comfreq) + int state[], statenum, totaltrans, comstate, comfreq; +{ + int extptr, extrct[2][CSIZE + 1]; + int mindiff, minprot, i, d; /* If extptr is 0 then the first array of extrct holds the result * of the "best difference" to date, which is those transitions @@ -100,35 +100,32 @@ int state[], statenum, totaltrans, comstate, comfreq; * compact its tables. */ - if ( (totaltrans * 100) < (numecs * PROTO_SIZE_PERCENTAGE) ) - mkentry( state, numecs, statenum, JAMSTATE, totaltrans ); + if ((totaltrans * 100) < (numecs * PROTO_SIZE_PERCENTAGE)) + mkentry (state, numecs, statenum, JAMSTATE, totaltrans); - else - { + else { /* "checkcom" is true if we should only check "state" against * protos which have the same "comstate" value. */ - int checkcom = + int checkcom = + comfreq * 100 > totaltrans * CHECK_COM_PERCENTAGE; minprot = firstprot; mindiff = totaltrans; - if ( checkcom ) - { + if (checkcom) { /* Find first proto which has the same "comstate". */ - for ( i = firstprot; i != NIL; i = protnext[i] ) - if ( protcomst[i] == comstate ) - { + for (i = firstprot; i != NIL; i = protnext[i]) + if (protcomst[i] == comstate) { minprot = i; - mindiff = tbldiff( state, minprot, - extrct[extptr] ); + mindiff = tbldiff (state, minprot, + extrct[extptr]); break; - } - } + } + } - else - { + else { /* Since we've decided that the most common destination * out of "state" does not occur with a high enough * frequency, we set the "comstate" to zero, assuring @@ -137,13 +134,12 @@ int state[], statenum, totaltrans, comstate, comfreq; */ comstate = 0; - if ( firstprot != NIL ) - { + if (firstprot != NIL) { minprot = firstprot; - mindiff = tbldiff( state, minprot, - extrct[extptr] ); - } + mindiff = tbldiff (state, minprot, + extrct[extptr]); } + } /* We now have the first interesting proto in "minprot". If * it matches within the tolerances set for the first proto, @@ -151,58 +147,55 @@ int state[], statenum, totaltrans, comstate, comfreq; * to see if we have any other reasonable matches. */ - if ( mindiff * 100 > totaltrans * FIRST_MATCH_DIFF_PERCENTAGE ) - { + if (mindiff * 100 > + totaltrans * FIRST_MATCH_DIFF_PERCENTAGE) { /* Not a good enough match. Scan the rest of the * protos. */ - for ( i = minprot; i != NIL; i = protnext[i] ) - { - d = tbldiff( state, i, extrct[1 - extptr] ); - if ( d < mindiff ) - { + for (i = minprot; i != NIL; i = protnext[i]) { + d = tbldiff (state, i, extrct[1 - extptr]); + if (d < mindiff) { extptr = 1 - extptr; mindiff = d; minprot = i; - } } } + } /* Check if the proto we've decided on as our best bet is close * enough to the state we want to match to be usable. */ - if ( mindiff * 100 > totaltrans * ACCEPTABLE_DIFF_PERCENTAGE ) - { + if (mindiff * 100 > + totaltrans * ACCEPTABLE_DIFF_PERCENTAGE) { /* No good. If the state is homogeneous enough, * we make a template out of it. Otherwise, we * make a proto. */ - if ( comfreq * 100 >= - totaltrans * TEMPLATE_SAME_PERCENTAGE ) - mktemplate( state, statenum, comstate ); + if (comfreq * 100 >= + totaltrans * TEMPLATE_SAME_PERCENTAGE) + mktemplate (state, statenum, + comstate); - else - { - mkprot( state, statenum, comstate ); - mkentry( state, numecs, statenum, - JAMSTATE, totaltrans ); - } + else { + mkprot (state, statenum, comstate); + mkentry (state, numecs, statenum, + JAMSTATE, totaltrans); } + } - else - { /* use the proto */ - mkentry( extrct[extptr], numecs, statenum, - prottbl[minprot], mindiff ); + else { /* use the proto */ + mkentry (extrct[extptr], numecs, statenum, + prottbl[minprot], mindiff); /* If this state was sufficiently different from the * proto we built it from, make it, too, a proto. */ - if ( mindiff * 100 >= - totaltrans * NEW_PROTO_DIFF_PERCENTAGE ) - mkprot( state, statenum, comstate ); + if (mindiff * 100 >= + totaltrans * NEW_PROTO_DIFF_PERCENTAGE) + mkprot (state, statenum, comstate); /* Since mkprot added a new proto to the proto queue, * it's possible that "minprot" is no longer on the @@ -214,10 +207,10 @@ int state[], statenum, totaltrans, comstate, comfreq; * following call will do nothing. */ - mv2front( minprot ); - } + mv2front (minprot); } } +} /* cmptmps - compress template table entries @@ -228,62 +221,56 @@ int state[], statenum, totaltrans, comstate, comfreq; * classes. */ -void cmptmps() - { - int tmpstorage[CSIZE + 1]; +void cmptmps () +{ + int tmpstorage[CSIZE + 1]; register int *tmp = tmpstorage, i, j; - int totaltrans, trans; + int totaltrans, trans; peakpairs = numtemps * numecs + tblend; - if ( usemecs ) - { + if (usemecs) { /* Create equivalence classes based on data gathered on * template transitions. */ - nummecs = cre8ecs( tecfwd, tecbck, numecs ); - } + nummecs = cre8ecs (tecfwd, tecbck, numecs); + } else nummecs = numecs; - while ( lastdfa + numtemps + 1 >= current_max_dfas ) - increase_max_dfas(); + while (lastdfa + numtemps + 1 >= current_max_dfas) + increase_max_dfas (); /* Loop through each template. */ - for ( i = 1; i <= numtemps; ++i ) - { + for (i = 1; i <= numtemps; ++i) { /* Number of non-jam transitions out of this template. */ totaltrans = 0; - for ( j = 1; j <= numecs; ++j ) - { + for (j = 1; j <= numecs; ++j) { trans = tnxt[numecs * i + j]; - if ( usemecs ) - { + if (usemecs) { /* The absolute value of tecbck is the * meta-equivalence class of a given * equivalence class, as set up by cre8ecs(). */ - if ( tecbck[j] > 0 ) - { + if (tecbck[j] > 0) { tmp[tecbck[j]] = trans; - if ( trans > 0 ) + if (trans > 0) ++totaltrans; - } } + } - else - { + else { tmp[j] = trans; - if ( trans > 0 ) + if (trans > 0) ++totaltrans; - } } + } /* It is assumed (in a rather subtle way) in the skeleton * that if we're using meta-equivalence classes, the def[] @@ -293,28 +280,29 @@ void cmptmps() */ /* Leave room for the jam-state after the last real state. */ - mkentry( tmp, nummecs, lastdfa + i + 1, JAMSTATE, totaltrans ); - } + mkentry (tmp, nummecs, lastdfa + i + 1, JAMSTATE, + totaltrans); } +} /* expand_nxt_chk - expand the next check arrays */ -void expand_nxt_chk() - { +void expand_nxt_chk () +{ register int old_max = current_max_xpairs; current_max_xpairs += MAX_XPAIRS_INCREMENT; ++num_reallocs; - nxt = reallocate_integer_array( nxt, current_max_xpairs ); - chk = reallocate_integer_array( chk, current_max_xpairs ); + nxt = reallocate_integer_array (nxt, current_max_xpairs); + chk = reallocate_integer_array (chk, current_max_xpairs); - zero_out( (char *) (chk + old_max), - (size_t) (MAX_XPAIRS_INCREMENT * sizeof( int )) ); - } + zero_out ((char *) (chk + old_max), + (size_t) (MAX_XPAIRS_INCREMENT * sizeof (int))); +} /* find_table_space - finds a space in the table for a state to be placed @@ -336,9 +324,9 @@ void expand_nxt_chk() * and an action number will be added in [-1]. */ -int find_table_space( state, numtrans ) -int *state, numtrans; - { +int find_table_space (state, numtrans) + int *state, numtrans; +{ /* Firstfree is the position of the first possible occurrence of two * consecutive unused records in the chk and nxt arrays. */ @@ -349,19 +337,18 @@ int *state, numtrans; /* If there are too many out-transitions, put the state at the end of * nxt and chk. */ - if ( numtrans > MAX_XTIONS_FULL_INTERIOR_FIT ) - { + if (numtrans > MAX_XTIONS_FULL_INTERIOR_FIT) { /* If table is empty, return the first available spot in * chk/nxt, which should be 1. */ - if ( tblend < 2 ) + if (tblend < 2) return 1; /* Start searching for table space near the end of * chk/nxt arrays. */ i = tblend - numecs; - } + } else /* Start searching for table space from the beginning @@ -370,21 +357,18 @@ int *state, numtrans; */ i = firstfree; - while ( 1 ) /* loops until a space is found */ - { - while ( i + numecs >= current_max_xpairs ) - expand_nxt_chk(); + while (1) { /* loops until a space is found */ + while (i + numecs >= current_max_xpairs) + expand_nxt_chk (); /* Loops until space for end-of-buffer and action number * are found. */ - while ( 1 ) - { + while (1) { /* Check for action number space. */ - if ( chk[i - 1] == 0 ) - { + if (chk[i - 1] == 0) { /* Check for end-of-buffer space. */ - if ( chk[i] == 0 ) + if (chk[i] == 0) break; else @@ -394,19 +378,19 @@ int *state, numtrans; * so we skip a space. */ i += 2; - } + } else ++i; - while ( i + numecs >= current_max_xpairs ) - expand_nxt_chk(); - } + while (i + numecs >= current_max_xpairs) + expand_nxt_chk (); + } /* If we started search from the beginning, store the new * firstfree for the next call of find_table_space(). */ - if ( numtrans <= MAX_XTIONS_FULL_INTERIOR_FIT ) + if (numtrans <= MAX_XTIONS_FULL_INTERIOR_FIT) firstfree = i + 1; /* Check to see if all elements in chk (and therefore nxt) @@ -416,18 +400,18 @@ int *state, numtrans; state_ptr = &state[1]; ptr_to_last_entry_in_state = &chk[i + numecs + 1]; - for ( chk_ptr = &chk[i + 1]; - chk_ptr != ptr_to_last_entry_in_state; ++chk_ptr ) - if ( *(state_ptr++) != 0 && *chk_ptr != 0 ) + for (chk_ptr = &chk[i + 1]; + chk_ptr != ptr_to_last_entry_in_state; ++chk_ptr) + if (*(state_ptr++) != 0 && *chk_ptr != 0) break; - if ( chk_ptr == ptr_to_last_entry_in_state ) + if (chk_ptr == ptr_to_last_entry_in_state) return i; else - ++i; - } + ++i; } +} /* inittbl - initialize transition tables @@ -435,18 +419,19 @@ int *state, numtrans; * Initializes "firstfree" to be one beyond the end of the table. Initializes * all "chk" entries to be zero. */ -void inittbl() - { +void inittbl () +{ register int i; - zero_out( (char *) chk, (size_t) (current_max_xpairs * sizeof( int )) ); + zero_out ((char *) chk, + + (size_t) (current_max_xpairs * sizeof (int))); tblend = 0; firstfree = tblend + 1; numtemps = 0; - if ( usemecs ) - { + if (usemecs) { /* Set up doubly-linked meta-equivalence classes; these * are sets of equivalence classes which all have identical * transitions out of TEMPLATES. @@ -454,39 +439,37 @@ void inittbl() tecbck[1] = NIL; - for ( i = 2; i <= numecs; ++i ) - { + for (i = 2; i <= numecs; ++i) { tecbck[i] = i - 1; tecfwd[i - 1] = i; - } + } tecfwd[numecs] = NIL; - } } +} /* mkdeftbl - make the default, "jam" table entries */ -void mkdeftbl() - { - int i; +void mkdeftbl () +{ + int i; jamstate = lastdfa + 1; - ++tblend; /* room for transition on end-of-buffer character */ + ++tblend; /* room for transition on end-of-buffer character */ - while ( tblend + numecs >= current_max_xpairs ) - expand_nxt_chk(); + while (tblend + numecs >= current_max_xpairs) + expand_nxt_chk (); /* Add in default end-of-buffer transition. */ nxt[tblend] = end_of_buffer_state; chk[tblend] = jamstate; - for ( i = 1; i <= numecs; ++i ) - { + for (i = 1; i <= numecs; ++i) { nxt[tblend + i] = 0; chk[tblend + i] = jamstate; - } + } jambase = tblend; @@ -495,7 +478,7 @@ void mkdeftbl() tblend += numecs; ++numtemps; - } +} /* mkentry - create base/def and nxt/chk entries for transition array @@ -517,46 +500,42 @@ void mkdeftbl() * state array. */ -void mkentry( state, numchars, statenum, deflink, totaltrans ) -register int *state; -int numchars, statenum, deflink, totaltrans; - { +void mkentry (state, numchars, statenum, deflink, totaltrans) + register int *state; + int numchars, statenum, deflink, totaltrans; +{ register int minec, maxec, i, baseaddr; - int tblbase, tbllast; + int tblbase, tbllast; - if ( totaltrans == 0 ) - { /* there are no out-transitions */ - if ( deflink == JAMSTATE ) + if (totaltrans == 0) { /* there are no out-transitions */ + if (deflink == JAMSTATE) base[statenum] = JAMSTATE; else base[statenum] = 0; def[statenum] = deflink; return; - } + } - for ( minec = 1; minec <= numchars; ++minec ) - { - if ( state[minec] != SAME_TRANS ) - if ( state[minec] != 0 || deflink != JAMSTATE ) + for (minec = 1; minec <= numchars; ++minec) { + if (state[minec] != SAME_TRANS) + if (state[minec] != 0 || deflink != JAMSTATE) break; - } + } - if ( totaltrans == 1 ) - { + if (totaltrans == 1) { /* There's only one out-transition. Save it for later to fill * in holes in the tables. */ - stack1( statenum, minec, state[minec], deflink ); + stack1 (statenum, minec, state[minec], deflink); return; - } + } - for ( maxec = numchars; maxec > 0; --maxec ) - { - if ( state[maxec] != SAME_TRANS ) - if ( state[maxec] != 0 || deflink != JAMSTATE ) + for (maxec = numchars; maxec > 0; --maxec) { + if (state[maxec] != SAME_TRANS) + if (state[maxec] != 0 || deflink != JAMSTATE) break; - } + } /* Whether we try to fit the state table in the middle of the table * entries we have already generated, or if we just take the state @@ -568,131 +547,121 @@ int numchars, statenum, deflink, totaltrans; */ /* Find the first transition of state that we need to worry about. */ - if ( totaltrans * 100 <= numchars * INTERIOR_FIT_PERCENTAGE ) - { + if (totaltrans * 100 <= numchars * INTERIOR_FIT_PERCENTAGE) { /* Attempt to squeeze it into the middle of the tables. */ baseaddr = firstfree; - while ( baseaddr < minec ) - { + while (baseaddr < minec) { /* Using baseaddr would result in a negative base * address below; find the next free slot. */ - for ( ++baseaddr; chk[baseaddr] != 0; ++baseaddr ) - ; - } + for (++baseaddr; chk[baseaddr] != 0; ++baseaddr) ; + } - while ( baseaddr + maxec - minec + 1 >= current_max_xpairs ) - expand_nxt_chk(); + while (baseaddr + maxec - minec + 1 >= current_max_xpairs) + expand_nxt_chk (); - for ( i = minec; i <= maxec; ++i ) - if ( state[i] != SAME_TRANS && - (state[i] != 0 || deflink != JAMSTATE) && - chk[baseaddr + i - minec] != 0 ) - { /* baseaddr unsuitable - find another */ - for ( ++baseaddr; - baseaddr < current_max_xpairs && - chk[baseaddr] != 0; ++baseaddr ) - ; + for (i = minec; i <= maxec; ++i) + if (state[i] != SAME_TRANS && + (state[i] != 0 || deflink != JAMSTATE) && + chk[baseaddr + i - minec] != 0) { /* baseaddr unsuitable - find another */ + for (++baseaddr; + baseaddr < current_max_xpairs && + chk[baseaddr] != 0; ++baseaddr) ; - while ( baseaddr + maxec - minec + 1 >= - current_max_xpairs ) - expand_nxt_chk(); + while (baseaddr + maxec - minec + 1 >= + current_max_xpairs) + expand_nxt_chk (); /* Reset the loop counter so we'll start all * over again next time it's incremented. */ i = minec - 1; - } - } + } + } - else - { + else { /* Ensure that the base address we eventually generate is * non-negative. */ - baseaddr = MAX( tblend + 1, minec ); - } + baseaddr = MAX (tblend + 1, minec); + } tblbase = baseaddr - minec; tbllast = tblbase + maxec; - while ( tbllast + 1 >= current_max_xpairs ) - expand_nxt_chk(); + while (tbllast + 1 >= current_max_xpairs) + expand_nxt_chk (); base[statenum] = tblbase; def[statenum] = deflink; - for ( i = minec; i <= maxec; ++i ) - if ( state[i] != SAME_TRANS ) - if ( state[i] != 0 || deflink != JAMSTATE ) - { + for (i = minec; i <= maxec; ++i) + if (state[i] != SAME_TRANS) + if (state[i] != 0 || deflink != JAMSTATE) { nxt[tblbase + i] = state[i]; chk[tblbase + i] = statenum; - } + } - if ( baseaddr == firstfree ) + if (baseaddr == firstfree) /* Find next free slot in tables. */ - for ( ++firstfree; chk[firstfree] != 0; ++firstfree ) - ; + for (++firstfree; chk[firstfree] != 0; ++firstfree) ; - tblend = MAX( tblend, tbllast ); - } + tblend = MAX (tblend, tbllast); +} /* mk1tbl - create table entries for a state (or state fragment) which * has only one out-transition */ -void mk1tbl( state, sym, onenxt, onedef ) -int state, sym, onenxt, onedef; - { - if ( firstfree < sym ) +void mk1tbl (state, sym, onenxt, onedef) + int state, sym, onenxt, onedef; +{ + if (firstfree < sym) firstfree = sym; - while ( chk[firstfree] != 0 ) - if ( ++firstfree >= current_max_xpairs ) - expand_nxt_chk(); + while (chk[firstfree] != 0) + if (++firstfree >= current_max_xpairs) + expand_nxt_chk (); base[state] = firstfree - sym; def[state] = onedef; chk[firstfree] = state; nxt[firstfree] = onenxt; - if ( firstfree > tblend ) - { + if (firstfree > tblend) { tblend = firstfree++; - if ( firstfree >= current_max_xpairs ) - expand_nxt_chk(); - } + if (firstfree >= current_max_xpairs) + expand_nxt_chk (); } +} /* mkprot - create new proto entry */ -void mkprot( state, statenum, comstate ) -int state[], statenum, comstate; - { - int i, slot, tblbase; +void mkprot (state, statenum, comstate) + int state[], statenum, comstate; +{ + int i, slot, tblbase; - if ( ++numprots >= MSP || numecs * numprots >= PROT_SAVE_SIZE ) - { + if (++numprots >= MSP || numecs * numprots >= PROT_SAVE_SIZE) { /* Gotta make room for the new proto by dropping last entry in * the queue. */ slot = lastprot; lastprot = protprev[lastprot]; protnext[lastprot] = NIL; - } + } else slot = numprots; protnext[slot] = firstprot; - if ( firstprot != NIL ) + if (firstprot != NIL) protprev[firstprot] = slot; firstprot = slot; @@ -702,21 +671,21 @@ int state[], statenum, comstate; /* Copy state into save area so it can be compared with rapidly. */ tblbase = numecs * (slot - 1); - for ( i = 1; i <= numecs; ++i ) + for (i = 1; i <= numecs; ++i) protsave[tblbase + i] = state[i]; - } +} /* mktemplate - create a template entry based on a state, and connect the state * to it */ -void mktemplate( state, statenum, comstate ) -int state[], statenum, comstate; - { - int i, numdiff, tmpbase, tmp[CSIZE + 1]; - Char transset[CSIZE + 1]; - int tsptr; +void mktemplate (state, statenum, comstate) + int state[], statenum, comstate; +{ + int i, numdiff, tmpbase, tmp[CSIZE + 1]; + Char transset[CSIZE + 1]; + int tsptr; ++numtemps; @@ -729,60 +698,58 @@ int state[], statenum, comstate; tmpbase = numtemps * numecs; - if ( tmpbase + numecs >= current_max_template_xpairs ) - { - current_max_template_xpairs += MAX_TEMPLATE_XPAIRS_INCREMENT; + if (tmpbase + numecs >= current_max_template_xpairs) { + current_max_template_xpairs += + MAX_TEMPLATE_XPAIRS_INCREMENT; ++num_reallocs; - tnxt = reallocate_integer_array( tnxt, - current_max_template_xpairs ); - } + tnxt = reallocate_integer_array (tnxt, + current_max_template_xpairs); + } - for ( i = 1; i <= numecs; ++i ) - if ( state[i] == 0 ) + for (i = 1; i <= numecs; ++i) + if (state[i] == 0) tnxt[tmpbase + i] = 0; - else - { + else { transset[tsptr++] = i; tnxt[tmpbase + i] = comstate; - } + } - if ( usemecs ) - mkeccl( transset, tsptr, tecfwd, tecbck, numecs, 0 ); + if (usemecs) + mkeccl (transset, tsptr, tecfwd, tecbck, numecs, 0); - mkprot( tnxt + tmpbase, -numtemps, comstate ); + mkprot (tnxt + tmpbase, -numtemps, comstate); /* We rely on the fact that mkprot adds things to the beginning * of the proto queue. */ - numdiff = tbldiff( state, firstprot, tmp ); - mkentry( tmp, numecs, statenum, -numtemps, numdiff ); - } + numdiff = tbldiff (state, firstprot, tmp); + mkentry (tmp, numecs, statenum, -numtemps, numdiff); +} /* mv2front - move proto queue element to front of queue */ -void mv2front( qelm ) -int qelm; - { - if ( firstprot != qelm ) - { - if ( qelm == lastprot ) +void mv2front (qelm) + int qelm; +{ + if (firstprot != qelm) { + if (qelm == lastprot) lastprot = protprev[lastprot]; protnext[protprev[qelm]] = protnext[qelm]; - if ( protnext[qelm] != NIL ) + if (protnext[qelm] != NIL) protprev[protnext[qelm]] = protprev[qelm]; protprev[qelm] = NIL; protnext[qelm] = firstprot; protprev[firstprot] = qelm; firstprot = qelm; - } } +} /* place_state - place a state into full speed transition table @@ -792,12 +759,12 @@ int qelm; * Transnum is the number of out-transitions for the state. */ -void place_state( state, statenum, transnum ) -int *state, statenum, transnum; - { +void place_state (state, statenum, transnum) + int *state, statenum, transnum; +{ register int i; register int *state_ptr; - int position = find_table_space( state, transnum ); + int position = find_table_space (state, transnum); /* "base" is the table of start positions. */ base[statenum] = position; @@ -817,16 +784,15 @@ int *state, statenum, transnum; /* Place the state into chk and nxt. */ state_ptr = &state[1]; - for ( i = 1; i <= numecs; ++i, ++state_ptr ) - if ( *state_ptr != 0 ) - { + for (i = 1; i <= numecs; ++i, ++state_ptr) + if (*state_ptr != 0) { chk[position + i] = i; nxt[position + i] = *state_ptr; - } + } - if ( position + numecs > tblend ) + if (position + numecs > tblend) tblend = position + numecs; - } +} /* stack1 - save states with only one out-transition to be processed later @@ -836,21 +802,20 @@ int *state, statenum, transnum; * no room, we process the sucker right now. */ -void stack1( statenum, sym, nextstate, deflink ) -int statenum, sym, nextstate, deflink; - { - if ( onesp >= ONE_STACK_SIZE - 1 ) - mk1tbl( statenum, sym, nextstate, deflink ); +void stack1 (statenum, sym, nextstate, deflink) + int statenum, sym, nextstate, deflink; +{ + if (onesp >= ONE_STACK_SIZE - 1) + mk1tbl (statenum, sym, nextstate, deflink); - else - { + else { ++onesp; onestate[onesp] = statenum; onesym[onesp] = sym; onenext[onesp] = nextstate; onedef[onesp] = deflink; - } } +} /* tbldiff - compute differences between two state tables @@ -867,24 +832,22 @@ int statenum, sym, nextstate, deflink; * number is "numecs" minus the number of "SAME_TRANS" entries in "ext". */ -int tbldiff( state, pr, ext ) -int state[], pr, ext[]; - { +int tbldiff (state, pr, ext) + int state[], pr, ext[]; +{ register int i, *sp = state, *ep = ext, *protp; register int numdiff = 0; protp = &protsave[numecs * (pr - 1)]; - for ( i = numecs; i > 0; --i ) - { - if ( *++protp == *++sp ) + for (i = numecs; i > 0; --i) { + if (*++protp == *++sp) *++ep = SAME_TRANS; - else - { + else { *++ep = *sp; ++numdiff; - } } + } return numdiff; - } +} diff --git a/yylex.c b/yylex.c index 451bc12..f06e5e6 100644 --- a/yylex.c +++ b/yylex.c @@ -38,42 +38,94 @@ /* yylex - scan for a regular expression token */ -int yylex() - { - int toktype; +int yylex () +{ + int toktype; static int beglin = false; extern char *yytext; - if ( eofseen ) + if (eofseen) toktype = EOF; else - toktype = flexscan(); + toktype = flexscan (); - if ( toktype == EOF || toktype == 0 ) - { + if (toktype == EOF || toktype == 0) { eofseen = 1; - if ( sectnum == 1 ) - { - synerr( _( "premature EOF" ) ); + if (sectnum == 1) { + synerr (_("premature EOF")); sectnum = 2; toktype = SECTEND; - } + } else toktype = 0; - } + } - if ( trace ) - { - if ( beglin ) - { - fprintf( stderr, "%d\t", num_rules + 1 ); + if (trace) { + if (beglin) { + fprintf (stderr, "%d\t", num_rules + 1); beglin = 0; - } + } - switch ( toktype ) - { + switch (toktype) { + case '<': + case '>': + case '^': + case '$': + case '"': + case '[': + case ']': + case '{': + case '}': + case '|': + case '(': + case ')': + case '-': + case '/': + case '\\': + case '?': + case '.': + case '*': + case '+': + case ',': + (void) putc (toktype, stderr); + break; + + case '\n': + (void) putc ('\n', stderr); + + if (sectnum == 2) + beglin = 1; + + break; + + case SCDECL: + fputs ("%s", stderr); + break; + + case XSCDECL: + fputs ("%x", stderr); + break; + + case SECTEND: + fputs ("%%\n", stderr); + + /* We set beglin to be true so we'll start + * writing out numbers as we echo rules. + * flexscan() has already assigned sectnum. + */ + if (sectnum == 2) + beglin = 1; + + break; + + case NAME: + fprintf (stderr, "'%s'", nmstr); + break; + + case CHAR: + switch (yylval) { case '<': case '>': case '^': @@ -94,126 +146,66 @@ int yylex() case '*': case '+': case ',': - (void) putc( toktype, stderr ); - break; - - case '\n': - (void) putc( '\n', stderr ); - - if ( sectnum == 2 ) - beglin = 1; - - break; - - case SCDECL: - fputs( "%s", stderr ); - break; - - case XSCDECL: - fputs( "%x", stderr ); - break; - - case SECTEND: - fputs( "%%\n", stderr ); - - /* We set beglin to be true so we'll start - * writing out numbers as we echo rules. - * flexscan() has already assigned sectnum. - */ - if ( sectnum == 2 ) - beglin = 1; - - break; - - case NAME: - fprintf( stderr, "'%s'", nmstr ); - break; - - case CHAR: - switch ( yylval ) - { - case '<': - case '>': - case '^': - case '$': - case '"': - case '[': - case ']': - case '{': - case '}': - case '|': - case '(': - case ')': - case '-': - case '/': - case '\\': - case '?': - case '.': - case '*': - case '+': - case ',': - fprintf( stderr, "\\%c", - yylval ); - break; - - default: - if ( ! isascii( yylval ) || - ! isprint( yylval ) ) - fprintf( stderr, - "\\%.3o", - (unsigned int) yylval ); - else - (void) putc( yylval, - stderr ); - break; - } - - break; - - case NUMBER: - fprintf( stderr, "%d", yylval ); - break; - - case PREVCCL: - fprintf( stderr, "[%d]", yylval ); - break; - - case EOF_OP: - fprintf( stderr, "<>" ); - break; - - case OPTION_OP: - fprintf( stderr, "%s ", yytext ); - break; - - case OPT_OUTFILE: - case OPT_PREFIX: - case CCE_ALNUM: - case CCE_ALPHA: - case CCE_BLANK: - case CCE_CNTRL: - case CCE_DIGIT: - case CCE_GRAPH: - case CCE_LOWER: - case CCE_PRINT: - case CCE_PUNCT: - case CCE_SPACE: - case CCE_UPPER: - case CCE_XDIGIT: - fprintf( stderr, "%s", yytext ); - break; - - case 0: - fprintf( stderr, _( "End Marker\n" ) ); + fprintf (stderr, "\\%c", yylval); break; default: - fprintf( stderr, - _( "*Something Weird* - tok: %d val: %d\n" ), - toktype, yylval ); + if (!isascii (yylval) || !isprint (yylval)) + fprintf (stderr, + "\\%.3o", + (unsigned int) yylval); + else + (void) putc (yylval, stderr); break; } + + break; + + case NUMBER: + fprintf (stderr, "%d", yylval); + break; + + case PREVCCL: + fprintf (stderr, "[%d]", yylval); + break; + + case EOF_OP: + fprintf (stderr, "<>"); + break; + + case OPTION_OP: + fprintf (stderr, "%s ", yytext); + break; + + case OPT_OUTFILE: + case OPT_PREFIX: + case CCE_ALNUM: + case CCE_ALPHA: + case CCE_BLANK: + case CCE_CNTRL: + case CCE_DIGIT: + case CCE_GRAPH: + case CCE_LOWER: + case CCE_PRINT: + case CCE_PUNCT: + case CCE_SPACE: + case CCE_UPPER: + case CCE_XDIGIT: + fprintf (stderr, "%s", yytext); + break; + + case 0: + fprintf (stderr, _("End Marker\n")); + break; + + default: + fprintf (stderr, + _ + ("*Something Weird* - tok: %d val: %d\n"), + toktype, yylval); + break; } + } return toktype; - } +}