summaryrefslogtreecommitdiff
path: root/usr.bin/lex
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2015-11-19 22:55:14 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2015-11-19 22:55:14 +0000
commit6bb8cbd8a2ab003261f213f1296b37379eaf5dec (patch)
treeb6356f0a4f566daea4d25d27294f237f72ed9824 /usr.bin/lex
parent9b738dfeed804665d9b66252352eff329895b05c (diff)
mechanical knf
Diffstat (limited to 'usr.bin/lex')
-rw-r--r--usr.bin/lex/ccl.c224
-rw-r--r--usr.bin/lex/tblcmp.c400
2 files changed, 330 insertions, 294 deletions
diff --git a/usr.bin/lex/ccl.c b/usr.bin/lex/ccl.c
index 628edcac6ab..6bd2ecf87fd 100644
--- a/usr.bin/lex/ccl.c
+++ b/usr.bin/lex/ccl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ccl.c,v 1.7 2015/11/19 19:43:40 tedu Exp $ */
+/* $OpenBSD: ccl.c,v 1.8 2015/11/19 22:55:13 tedu Exp $ */
/* ccl - routines for character classes */
@@ -10,7 +10,7 @@
/* The United States Government has rights in this work pursuant */
/* to contract no. DE-AC03-76SF00098 between the United States */
- /* Department of Energy and the University of California. */
+ /* Department of Energy and the University of California. */
/* This file is part of flex. */
@@ -37,9 +37,9 @@
/* return true if the chr is in the ccl. Takes negation into account. */
static bool
-ccl_contains (const int cclp, const int ch)
+ccl_contains(const int cclp, const int ch)
{
- int ind, len, i;
+ int ind, len, i;
len = ccllen[cclp];
ind = cclmap[cclp];
@@ -48,19 +48,20 @@ ccl_contains (const int cclp, const int ch)
if (ccltbl[ind + i] == ch)
return !cclng[cclp];
- return cclng[cclp];
+ return cclng[cclp];
}
/* ccladd - add a single character to a ccl */
-void ccladd (cclp, ch)
- int cclp;
- int ch;
+void
+ccladd(cclp, ch)
+ int cclp;
+ int ch;
{
- int ind, len, newpos, i;
+ int ind, len, newpos, i;
- check_char (ch);
+ check_char(ch);
len = ccllen[cclp];
ind = cclmap[cclp];
@@ -82,112 +83,114 @@ void ccladd (cclp, ch)
++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;
}
/* dump_cclp - same thing as list_character_set, but for cclps. */
-static void dump_cclp (FILE* file, int cclp)
+static void
+dump_cclp(FILE * file, int cclp)
{
int i;
- putc ('[', file);
+ putc('[', file);
for (i = 0; i < csize; ++i) {
- if (ccl_contains(cclp, i)){
+ if (ccl_contains(cclp, i)) {
int start_char = i;
- putc (' ', file);
+ putc(' ', file);
- fputs (readable_form (i), file);
+ fputs(readable_form(i), file);
- while (++i < csize && ccl_contains(cclp,i)) ;
+ while (++i < csize && ccl_contains(cclp, i));
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);
}
/* ccl_set_diff - create a new ccl as the set difference of the two given ccls. */
int
-ccl_set_diff (int a, int b)
+ccl_set_diff(int a, int b)
{
- int d, ch;
-
- /* create new class */
- d = cclinit();
-
- /* In order to handle negation, we spin through all possible chars,
- * addding each char in a that is not in b.
- * (This could be O(n^2), but n is small and bounded.)
- */
- for ( ch = 0; ch < csize; ++ch )
- if (ccl_contains (a, ch) && !ccl_contains(b, ch))
- ccladd (d, ch);
-
- /* debug */
- if (0){
- fprintf(stderr, "ccl_set_diff (");
- fprintf(stderr, "\n ");
- dump_cclp (stderr, a);
- fprintf(stderr, "\n ");
- dump_cclp (stderr, b);
- fprintf(stderr, "\n ");
- dump_cclp (stderr, d);
- fprintf(stderr, "\n)\n");
- }
- return d;
+ int d, ch;
+
+ /* create new class */
+ d = cclinit();
+
+ /*
+ * In order to handle negation, we spin through all possible chars,
+ * addding each char in a that is not in b. (This could be O(n^2),
+ * but n is small and bounded.)
+ */
+ for (ch = 0; ch < csize; ++ch)
+ if (ccl_contains(a, ch) && !ccl_contains(b, ch))
+ ccladd(d, ch);
+
+ /* debug */
+ if (0) {
+ fprintf(stderr, "ccl_set_diff (");
+ fprintf(stderr, "\n ");
+ dump_cclp(stderr, a);
+ fprintf(stderr, "\n ");
+ dump_cclp(stderr, b);
+ fprintf(stderr, "\n ");
+ dump_cclp(stderr, d);
+ fprintf(stderr, "\n)\n");
+ }
+ return d;
}
/* ccl_set_union - create a new ccl as the set union of the two given ccls. */
int
-ccl_set_union (int a, int b)
+ccl_set_union(int a, int b)
{
- int d, i;
-
- /* create new class */
- d = cclinit();
-
- /* Add all of a */
- for (i = 0; i < ccllen[a]; ++i)
- ccladd (d, ccltbl[cclmap[a] + i]);
-
- /* Add all of b */
- for (i = 0; i < ccllen[b]; ++i)
- ccladd (d, ccltbl[cclmap[b] + i]);
-
- /* debug */
- if (0){
- fprintf(stderr, "ccl_set_union (%d + %d = %d", a, b, d);
- fprintf(stderr, "\n ");
- dump_cclp (stderr, a);
- fprintf(stderr, "\n ");
- dump_cclp (stderr, b);
- fprintf(stderr, "\n ");
- dump_cclp (stderr, d);
- fprintf(stderr, "\n)\n");
- }
- return d;
+ int d, i;
+
+ /* create new class */
+ d = cclinit();
+
+ /* Add all of a */
+ for (i = 0; i < ccllen[a]; ++i)
+ ccladd(d, ccltbl[cclmap[a] + i]);
+
+ /* Add all of b */
+ for (i = 0; i < ccllen[b]; ++i)
+ ccladd(d, ccltbl[cclmap[b] + i]);
+
+ /* debug */
+ if (0) {
+ fprintf(stderr, "ccl_set_union (%d + %d = %d", a, b, d);
+ fprintf(stderr, "\n ");
+ dump_cclp(stderr, a);
+ fprintf(stderr, "\n ");
+ dump_cclp(stderr, b);
+ fprintf(stderr, "\n ");
+ dump_cclp(stderr, d);
+ fprintf(stderr, "\n)\n");
+ }
+ return d;
}
/* cclinit - return an empty ccl */
-int cclinit ()
+int
+cclinit()
{
if (++lastccl >= current_maxccls) {
current_maxccls += MAX_CCLS_INCREMENT;
@@ -195,27 +198,27 @@ int cclinit ()
++num_reallocs;
cclmap =
- reallocate_integer_array (cclmap, current_maxccls);
+ reallocate_integer_array(cclmap, current_maxccls);
ccllen =
- reallocate_integer_array (ccllen, current_maxccls);
- cclng = reallocate_integer_array (cclng, current_maxccls);
+ reallocate_integer_array(ccllen, current_maxccls);
+ cclng = reallocate_integer_array(cclng, current_maxccls);
ccl_has_nl =
- reallocate_bool_array (ccl_has_nl,
- current_maxccls);
+ reallocate_bool_array(ccl_has_nl,
+ current_maxccls);
}
-
if (lastccl == 1)
/* we're making the first ccl */
cclmap[lastccl] = 0;
else
- /* The new pointer is just past the end of the last ccl.
- * Since the cclmap points to the \first/ character of a
- * ccl, adding the length of the ccl to the cclmap pointer
- * will produce a cursor to the first free space.
+ /*
+ * The new pointer is just past the end of the last ccl.
+ * Since the cclmap points to the \first/ character of a 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 - 1] + ccllen[lastccl - 1];
ccllen[lastccl] = 0;
cclng[lastccl] = 0; /* ccl's start out life un-negated */
@@ -227,8 +230,9 @@ int cclinit ()
/* 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];
@@ -242,34 +246,35 @@ void cclnegate (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[];
{
int i;
- putc ('[', file);
+ putc('[', file);
for (i = 0; i < csize; ++i) {
if (cset[i]) {
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)
/* 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);
}
/** Determines if the range [c1-c2] is unambiguous in a case-insensitive
@@ -283,13 +288,14 @@ void list_character_set (file, cset)
* @param c2 the upper end of the range
* @return true if [c1-c2] is not ambiguous for a caseless scanner.
*/
-bool range_covers_case (int c1, int c2)
+bool
+range_covers_case(int c1, int c2)
{
- int i, o;
+ int i, o;
for (i = c1; i <= c2; i++) {
- if (has_case (i)) {
- o = reverse_case (i);
+ if (has_case(i)) {
+ o = reverse_case(i);
if (o < c1 || c2 < o)
return false;
}
@@ -300,13 +306,15 @@ bool range_covers_case (int c1, int c2)
/** Reverse the case of a character, if possible.
* @return c if case-reversal does not apply.
*/
-int reverse_case (int c)
+int
+reverse_case(int c)
{
- return isupper (c) ? tolower (c) : (islower (c) ? toupper (c) : c);
+ return isupper(c) ? tolower(c) : (islower(c) ? toupper(c) : c);
}
/** Return true if c is uppercase or lowercase. */
-bool has_case (int c)
+bool
+has_case(int c)
{
- return (isupper (c) || islower (c)) ? true : false;
+ return (isupper(c) || islower(c)) ? true : false;
}
diff --git a/usr.bin/lex/tblcmp.c b/usr.bin/lex/tblcmp.c
index 7d5e60503ac..36ad171707f 100644
--- a/usr.bin/lex/tblcmp.c
+++ b/usr.bin/lex/tblcmp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tblcmp.c,v 1.7 2015/11/19 19:43:40 tedu Exp $ */
+/* $OpenBSD: tblcmp.c,v 1.8 2015/11/19 22:55:13 tedu Exp $ */
/* tblcmp - table compression routines */
@@ -38,11 +38,11 @@
/* declarations for functions that have forward references */
-void mkentry PROTO ((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((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
@@ -80,38 +80,42 @@ int tbldiff PROTO ((int[], int, int[]));
* cost only one difference.
*/
-void bldtbl (state, statenum, totaltrans, comstate, comfreq)
- int state[], statenum, totaltrans, comstate, comfreq;
+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
- * which occur in "state" but not in the proto which, to date,
- * has the fewest differences between itself and "state". If
- * extptr is 1 then the second array of extrct hold the best
- * difference. The two arrays are toggled between so that the
- * best difference to date can be kept around and also a difference
- * just created by checking against a candidate "best" proto.
+ 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 which
+ * occur in "state" but not in the proto which, to date, has the
+ * fewest differences between itself and "state". If extptr is 1
+ * then the second array of extrct hold the best difference. The two
+ * arrays are toggled between so that the best difference to date can
+ * be kept around and also a difference just created by checking
+ * against a candidate "best" proto.
*/
extptr = 0;
- /* If the state has too few out-transitions, don't bother trying to
+ /*
+ * If the state has too few out-transitions, don't bother trying to
* compact its tables.
*/
if ((totaltrans * 100) < (numecs * PROTO_SIZE_PERCENTAGE))
- mkentry (state, numecs, statenum, JAMSTATE, totaltrans);
+ mkentry(state, numecs, statenum, JAMSTATE, totaltrans);
else {
- /* "checkcom" is true if we should only check "state" against
+ /*
+ * "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;
+ comfreq * 100 > totaltrans * CHECK_COM_PERCENTAGE;
minprot = firstprot;
mindiff = totaltrans;
@@ -121,41 +125,43 @@ void bldtbl (state, statenum, totaltrans, comstate, comfreq)
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 {
- /* 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
- * that if this state is entered into the proto list,
- * it will not be considered a template.
+ } 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 that if this state is entered into
+ * the proto list, it will not be considered a
+ * template.
*/
comstate = 0;
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
+ /*
+ * We now have the first interesting proto in "minprot". If
* it matches within the tolerances set for the first proto,
- * we don't want to bother scanning the rest of the proto list
- * to see if we have any other reasonable matches.
+ * we don't want to bother scanning the rest of the proto
+ * list to see if we have any other reasonable matches.
*/
if (mindiff * 100 >
totaltrans * FIRST_MATCH_DIFF_PERCENTAGE) {
- /* Not a good enough match. Scan the rest of the
+ /*
+ * 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]);
+ d = tbldiff(state, i, extrct[1 - extptr]);
if (d < mindiff) {
extptr = 1 - extptr;
mindiff = d;
@@ -163,43 +169,44 @@ void bldtbl (state, statenum, totaltrans, comstate, comfreq)
}
}
}
-
- /* 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.
+ /*
+ * 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) {
- /* No good. If the state is homogeneous enough,
- * we make a template out of it. Otherwise, we
- * make a proto.
+ /*
+ * 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);
+ mktemplate(state, statenum,
+ comstate);
else {
- mkprot (state, statenum, comstate);
- mkentry (state, numecs, statenum,
- JAMSTATE, totaltrans);
+ 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
+ /*
+ * 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);
+ mkprot(state, statenum, comstate);
- /* Since mkprot added a new proto to the proto queue,
+ /*
+ * Since mkprot added a new proto to the proto queue,
* it's possible that "minprot" is no longer on the
* proto queue (if it happened to have been the last
* entry, it would have been bumped off). If it's
@@ -209,7 +216,7 @@ void bldtbl (state, statenum, totaltrans, comstate, comfreq)
* following call will do nothing.
*/
- mv2front (minprot);
+ mv2front(minprot);
}
}
}
@@ -223,26 +230,26 @@ void bldtbl (state, statenum, totaltrans, comstate, comfreq)
* classes.
*/
-void cmptmps ()
+void
+cmptmps()
{
- int tmpstorage[CSIZE + 1];
+ int tmpstorage[CSIZE + 1];
int *tmp = tmpstorage, i, j;
- int totaltrans, trans;
+ int totaltrans, trans;
peakpairs = numtemps * numecs + tblend;
if (usemecs) {
- /* Create equivalence classes based on data gathered on
+ /*
+ * Create equivalence classes based on data gathered on
* template transitions.
*/
- nummecs = cre8ecs (tecfwd, tecbck, numecs);
- }
-
- else
+ nummecs = cre8ecs(tecfwd, tecbck, numecs);
+ } else
nummecs = numecs;
while (lastdfa + numtemps + 1 >= current_max_dfas)
- increase_max_dfas ();
+ increase_max_dfas();
/* Loop through each template. */
@@ -254,7 +261,8 @@ void cmptmps ()
trans = tnxt[numecs * i + j];
if (usemecs) {
- /* The absolute value of tecbck is the
+ /*
+ * The absolute value of tecbck is the
* meta-equivalence class of a given
* equivalence class, as set up by cre8ecs().
*/
@@ -264,9 +272,7 @@ void cmptmps ()
if (trans > 0)
++totaltrans;
}
- }
-
- else {
+ } else {
tmp[j] = trans;
if (trans > 0)
@@ -274,7 +280,8 @@ void cmptmps ()
}
}
- /* It is assumed (in a rather subtle way) in the skeleton
+ /*
+ * It is assumed (in a rather subtle way) in the skeleton
* that if we're using meta-equivalence classes, the def[]
* entry for all templates is the jam template, i.e.,
* templates never default to other non-jam table entries
@@ -282,8 +289,8 @@ 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);
}
}
@@ -291,7 +298,8 @@ void cmptmps ()
/* expand_nxt_chk - expand the next check arrays */
-void expand_nxt_chk ()
+void
+expand_nxt_chk()
{
int old_max = current_max_xpairs;
@@ -299,11 +307,11 @@ void expand_nxt_chk ()
++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)));
}
@@ -326,45 +334,50 @@ 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
+ /*
+ * Firstfree is the position of the first possible occurrence of two
* consecutive unused records in the chk and nxt arrays.
*/
int i;
int *state_ptr, *chk_ptr;
int *ptr_to_last_entry_in_state;
- /* If there are too many out-transitions, put the state at the end of
+ /*
+ * 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 table is empty, return the first available spot in
+ /*
+ * If table is empty, return the first available spot in
* chk/nxt, which should be 1.
*/
if (tblend < 2)
return 1;
- /* Start searching for table space near the end of
- * chk/nxt arrays.
+ /*
+ * Start searching for table space near the end of chk/nxt
+ * arrays.
*/
i = tblend - numecs;
- }
-
- else
- /* Start searching for table space from the beginning
- * (skipping only the elements which will definitely not
- * hold the new state).
+ } else
+ /*
+ * Start searching for table space from the beginning
+ * (skipping only the elements which will definitely not hold
+ * the new state).
*/
i = firstfree;
while (1) { /* loops until a space is found */
while (i + numecs >= current_max_xpairs)
- expand_nxt_chk ();
+ expand_nxt_chk();
- /* Loops until space for end-of-buffer and action number
- * are found.
+ /*
+ * Loops until space for end-of-buffer and action number are
+ * found.
*/
while (1) {
/* Check for action number space. */
@@ -374,28 +387,29 @@ int find_table_space (state, numtrans)
break;
else
- /* Since i != 0, there is no use
+ /*
+ * Since i != 0, there is no use
* checking to see if (++i) - 1 == 0,
* because that's the same as i == 0,
* so we skip a space.
*/
i += 2;
- }
-
- else
+ } else
++i;
while (i + numecs >= current_max_xpairs)
- expand_nxt_chk ();
+ expand_nxt_chk();
}
- /* If we started search from the beginning, store the new
+ /*
+ * 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)
firstfree = i + 1;
- /* Check to see if all elements in chk (and therefore nxt)
+ /*
+ * Check to see if all elements in chk (and therefore nxt)
* that are needed for the new state have not yet been taken.
*/
@@ -403,7 +417,7 @@ int find_table_space (state, numtrans)
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)
+ chk_ptr != ptr_to_last_entry_in_state; ++chk_ptr)
if (*(state_ptr++) != 0 && *chk_ptr != 0)
break;
@@ -421,21 +435,23 @@ int find_table_space (state, numtrans)
* Initializes "firstfree" to be one beyond the end of the table. Initializes
* all "chk" entries to be zero.
*/
-void inittbl ()
+void
+inittbl()
{
int i;
- zero_out ((char *) chk,
+ zero_out((char *) chk,
- (size_t) (current_max_xpairs * sizeof (int)));
+ (size_t) (current_max_xpairs * sizeof(int)));
tblend = 0;
firstfree = tblend + 1;
numtemps = 0;
if (usemecs) {
- /* Set up doubly-linked meta-equivalence classes; these
- * are sets of equivalence classes which all have identical
+ /*
+ * Set up doubly-linked meta-equivalence classes; these are
+ * sets of equivalence classes which all have identical
* transitions out of TEMPLATES.
*/
@@ -453,16 +469,18 @@ void inittbl ()
/* mkdeftbl - make the default, "jam" table entries */
-void mkdeftbl ()
+void
+mkdeftbl()
{
- int i;
+ 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 ();
+ expand_nxt_chk();
/* Add in default end-of-buffer transition. */
nxt[tblend] = end_of_buffer_state;
@@ -502,12 +520,13 @@ void mkdeftbl ()
* state array.
*/
-void mkentry (state, numchars, statenum, deflink, totaltrans)
- int *state;
- int numchars, statenum, deflink, totaltrans;
+void
+mkentry(state, numchars, statenum, deflink, totaltrans)
+ int *state;
+ int numchars, statenum, deflink, totaltrans;
{
int minec, maxec, i, baseaddr;
- int tblbase, tbllast;
+ int tblbase, tbllast;
if (totaltrans == 0) { /* there are no out-transitions */
if (deflink == JAMSTATE)
@@ -518,7 +537,6 @@ void mkentry (state, numchars, statenum, deflink, totaltrans)
def[statenum] = deflink;
return;
}
-
for (minec = 1; minec <= numchars; ++minec) {
if (state[minec] != SAME_TRANS)
if (state[minec] != 0 || deflink != JAMSTATE)
@@ -526,20 +544,21 @@ void mkentry (state, numchars, statenum, deflink, totaltrans)
}
if (totaltrans == 1) {
- /* There's only one out-transition. Save it for later to fill
- * in holes in the tables.
+ /*
+ * 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)
break;
}
- /* Whether we try to fit the state table in the middle of the table
+ /*
+ * 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
* table at the end of the nxt/chk tables, we must make sure that we
* have a valid base address (i.e., non-negative). Note that
@@ -554,47 +573,49 @@ void mkentry (state, numchars, statenum, deflink, totaltrans)
baseaddr = firstfree;
while (baseaddr < minec) {
- /* Using baseaddr would result in a negative base
+ /*
+ * 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 ();
+ 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 */
+ chk[baseaddr + i - minec] != 0) { /* baseaddr unsuitable -
+ * find another */
for (++baseaddr;
- baseaddr < current_max_xpairs &&
- chk[baseaddr] != 0; ++baseaddr) ;
+ baseaddr < current_max_xpairs &&
+ chk[baseaddr] != 0; ++baseaddr);
while (baseaddr + maxec - minec + 1 >=
- current_max_xpairs)
- expand_nxt_chk ();
+ current_max_xpairs)
+ expand_nxt_chk();
- /* Reset the loop counter so we'll start all
+ /*
+ * Reset the loop counter so we'll start all
* over again next time it's incremented.
*/
i = minec - 1;
}
- }
-
- else {
- /* Ensure that the base address we eventually generate is
+ } 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 ();
+ expand_nxt_chk();
base[statenum] = tblbase;
def[statenum] = deflink;
@@ -605,12 +626,11 @@ void mkentry (state, numchars, statenum, deflink, totaltrans)
nxt[tblbase + i] = state[i];
chk[tblbase + i] = statenum;
}
-
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);
}
@@ -618,15 +638,16 @@ void mkentry (state, numchars, statenum, deflink, totaltrans)
* has only one out-transition
*/
-void mk1tbl (state, sym, onenxt, onedef)
- int state, sym, onenxt, onedef;
+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 ();
+ expand_nxt_chk();
base[state] = firstfree - sym;
def[state] = onedef;
@@ -637,28 +658,28 @@ void mk1tbl (state, sym, onenxt, onedef)
tblend = firstfree++;
if (firstfree >= current_max_xpairs)
- expand_nxt_chk ();
+ expand_nxt_chk();
}
}
/* mkprot - create new proto entry */
-void mkprot (state, statenum, comstate)
- int state[], statenum, comstate;
+void
+mkprot(state, statenum, comstate)
+ int state[], statenum, comstate;
{
- int i, slot, tblbase;
+ int i, slot, tblbase;
if (++numprots >= MSP || numecs * numprots >= PROT_SAVE_SIZE) {
- /* Gotta make room for the new proto by dropping last entry in
- * the queue.
+ /*
+ * Gotta make room for the new proto by dropping last entry
+ * in the queue.
*/
slot = lastprot;
lastprot = protprev[lastprot];
protnext[lastprot] = NIL;
- }
-
- else
+ } else
slot = numprots;
protnext[slot] = firstprot;
@@ -682,34 +703,35 @@ void mkprot (state, statenum, comstate)
* to it
*/
-void mktemplate (state, statenum, comstate)
- int state[], statenum, comstate;
+void
+mktemplate(state, statenum, comstate)
+ int state[], statenum, comstate;
{
- int i, numdiff, tmpbase, tmp[CSIZE + 1];
- Char transset[CSIZE + 1];
- int tsptr;
+ int i, numdiff, tmpbase, tmp[CSIZE + 1];
+ Char transset[CSIZE + 1];
+ int tsptr;
++numtemps;
tsptr = 0;
- /* Calculate where we will temporarily store the transition table
- * of the template in the tnxt[] array. The final transition table
- * gets created by cmptmps().
+ /*
+ * Calculate where we will temporarily store the transition table of
+ * the template in the tnxt[] array. The final transition table gets
+ * created by cmptmps().
*/
tmpbase = numtemps * numecs;
if (tmpbase + numecs >= current_max_template_xpairs) {
current_max_template_xpairs +=
- MAX_TEMPLATE_XPAIRS_INCREMENT;
+ 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)
tnxt[tmpbase + i] = 0;
@@ -719,23 +741,25 @@ void mktemplate (state, statenum, comstate)
}
if (usemecs)
- mkeccl (transset, tsptr, tecfwd, tecbck, numecs, 0);
+ 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.
+ /*
+ * 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;
+void
+mv2front(qelm)
+ int qelm;
{
if (firstprot != qelm) {
if (qelm == lastprot)
@@ -761,24 +785,27 @@ void mv2front (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;
{
int i;
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;
- /* Put in action number marker; this non-zero number makes sure that
+ /*
+ * Put in action number marker; this non-zero number makes sure that
* find_table_space() knows that this position in chk/nxt is taken
* and should not be used for another accepting number in another
* state.
*/
chk[position - 1] = 1;
- /* Put in end-of-buffer marker; this is for the same purposes as
+ /*
+ * Put in end-of-buffer marker; this is for the same purposes as
* above.
*/
chk[position] = 1;
@@ -791,7 +818,6 @@ void place_state (state, statenum, transnum)
chk[position + i] = i;
nxt[position + i] = *state_ptr;
}
-
if (position + numecs > tblend)
tblend = position + numecs;
}
@@ -804,11 +830,12 @@ void place_state (state, statenum, transnum)
* no room, we process the sucker right now.
*/
-void stack1 (statenum, sym, nextstate, deflink)
- int 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);
+ mk1tbl(statenum, sym, nextstate, deflink);
else {
++onesp;
@@ -834,8 +861,9 @@ void stack1 (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[];
{
int i, *sp = state, *ep = ext, *protp;
int numdiff = 0;