diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2007-09-10 00:42:27 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2007-09-10 00:42:27 (GMT) |
commit | 4240f7301eca750bf27fdd4fc32bb69f1f81db0a (patch) | |
tree | 16d6bac46629691eab7148772a7eea2fa07a5362 | |
parent | 1aec3f216c9ebfc5dd9d7e8146dc452e9f76b7ae (diff) | |
download | tcl-4240f7301eca750bf27fdd4fc32bb69f1f81db0a.zip tcl-4240f7301eca750bf27fdd4fc32bb69f1f81db0a.tar.gz tcl-4240f7301eca750bf27fdd4fc32bb69f1f81db0a.tar.bz2 |
Minor cleanup of RE compiler code, gradually gradually making it more Tcl-ish.
-rw-r--r-- | generic/regc_color.c | 173 | ||||
-rw-r--r-- | generic/regc_nfa.c | 184 | ||||
-rw-r--r-- | generic/regcomp.c | 319 |
3 files changed, 332 insertions, 344 deletions
diff --git a/generic/regc_color.c b/generic/regc_color.c index 1a7eeda..02634d9 100644 --- a/generic/regc_color.c +++ b/generic/regc_color.c @@ -2,7 +2,7 @@ * colorings of characters * This file is #included by regcomp.c. * - * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved. + * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved. * * Development of this software was funded, in part, by Cray Research Inc., * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics @@ -19,7 +19,7 @@ * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; @@ -58,7 +58,7 @@ initcm( cm->max = 0; cm->free = 0; - cd = cm->cd; /* cm->cd[WHITE] */ + cd = cm->cd; /* cm->cd[WHITE] */ cd->sub = NOSUB; cd->arcs = NULL; cd->flags = 0; @@ -68,9 +68,9 @@ initcm( * Upper levels of tree. */ - for (t = &cm->tree[0], j = NBYTS-1; j > 0; t = nextt, j--) { + for (t=&cm->tree[0], j=NBYTS-1 ; j>0 ; t=nextt, j--) { nextt = t + 1; - for (i = BYTTAB-1; i >= 0; i--) { + for (i=BYTTAB-1 ; i>=0 ; i--) { t->tptr[i] = nextt; } } @@ -80,7 +80,7 @@ initcm( */ t = &cm->tree[NBYTS-1]; - for (i = BYTTAB-1; i >= 0; i--) { + for (i=BYTTAB-1 ; i>=0 ; i--) { t->tcolor[i] = WHITE; } cd->block = t; @@ -101,7 +101,7 @@ freecm( if (NBYTS > 1) { cmtreefree(cm, cm->tree, 0); } - for (i = 1; i <= cm->max; i++) { /* skip WHITE */ + for (i=1 ; i<=cm->max ; i++) { /* skip WHITE */ if (!UNUSEDCOLOR(&cm->cd[i])) { cb = cm->cd[i].block; if (cb != NULL) { @@ -122,25 +122,24 @@ static void cmtreefree( struct colormap *cm, union tree *tree, - int level) /* level number (top == 0) of this - * block */ + int level) /* level number (top == 0) of this block */ { int i; union tree *t; union tree *fillt = &cm->tree[level+1]; union tree *cb; - assert(level < NBYTS-1); /* this level has pointers */ - for (i = BYTTAB-1; i >= 0; i--) { + assert(level < NBYTS-1); /* this level has pointers */ + for (i=BYTTAB-1 ; i>=0 ; i--) { t = tree->tptr[i]; assert(t != NULL); if (t != fillt) { if (level < NBYTS-2) { /* more pointer blocks below */ cmtreefree(cm, t, level+1); FREE(t); - } else { /* color block below */ + } else { /* color block below */ cb = cm->cd[t->tcolor[0]].block; - if (t != cb) { /* not a solid block */ + if (t != cb) { /* not a solid block */ FREE(t); } } @@ -152,7 +151,7 @@ cmtreefree( - setcolor - set the color of a character in a colormap ^ static color setcolor(struct colormap *, pchr, pcolor); */ -static color /* previous color */ +static color /* previous color */ setcolor( struct colormap *cm, pchr c, @@ -176,8 +175,7 @@ setcolor( } t = cm->tree; - for (level = 0, shift = BYTBITS * (NBYTS - 1); shift > 0; - level++, shift -= BYTBITS) { + for (level=0, shift=BYTBITS*(NBYTS-1) ; shift>0; level++, shift-=BYTBITS){ b = (uc >> shift) & BYTMASK; lastt = t; t = lastt->tptr[b]; @@ -186,18 +184,16 @@ setcolor( bottom = (shift <= BYTBITS) ? 1 : 0; cb = (bottom) ? cm->cd[t->tcolor[0]].block : fillt; if (t == fillt || t == cb) { /* must allocate a new block */ - newt = (union tree *)MALLOC((bottom) ? + newt = (union tree *) MALLOC((bottom) ? sizeof(struct colors) : sizeof(struct ptrs)); if (newt == NULL) { CERR(REG_ESPACE); return COLORLESS; } if (bottom) { - memcpy(VS(newt->tcolor), VS(t->tcolor), - BYTTAB*sizeof(color)); + memcpy(newt->tcolor, t->tcolor, BYTTAB*sizeof(color)); } else { - memcpy(VS(newt->tptr), VS(t->tptr), - BYTTAB*sizeof(union tree *)); + memcpy(newt->tptr, t->tptr, BYTTAB*sizeof(union tree *)); } t = newt; lastt->tptr[b] = t; @@ -206,7 +202,7 @@ setcolor( b = uc & BYTMASK; prev = t->tcolor[b]; - t->tcolor[b] = (color)co; + t->tcolor[b] = (color) co; return prev; } @@ -222,20 +218,19 @@ maxcolor( return COLORLESS; } - return (color)cm->max; + return (color) cm->max; } /* - newcolor - find a new color (must be subject of setcolor at once) - * Beware: may relocate the colordescs. + * Beware: may relocate the colordescs. ^ static color newcolor(struct colormap *); */ -static color /* COLORLESS for error */ +static color /* COLORLESS for error */ newcolor( struct colormap *cm) { struct colordesc *cd; - struct colordesc *new; size_t n; if (CISERR()) { @@ -244,7 +239,7 @@ newcolor( if (cm->free != 0) { assert(cm->free > 0); - assert((size_t)cm->free < cm->ncds); + assert((size_t) cm->free < cm->ncds); cd = &cm->cd[cm->free]; assert(UNUSEDCOLOR(cd)); assert(cd->arcs == NULL); @@ -253,26 +248,28 @@ newcolor( cm->max++; cd = &cm->cd[cm->max]; } else { + struct colordesc *newCd; + /* * Oops, must allocate more. */ n = cm->ncds * 2; if (cm->cd == cm->cdspace) { - new = (struct colordesc *)MALLOC(n * sizeof(struct colordesc)); - if (new != NULL) { - memcpy(VS(new), VS(cm->cdspace), + newCd = (struct colordesc *) MALLOC(n * sizeof(struct colordesc)); + if (newCd != NULL) { + memcpy(newCd, cm->cdspace, cm->ncds * sizeof(struct colordesc)); } } else { - new = (struct colordesc *)REALLOC(cm->cd, - n * sizeof(struct colordesc)); + newCd = (struct colordesc *) + REALLOC(cm->cd, n * sizeof(struct colordesc)); } - if (new == NULL) { + if (newCd == NULL) { CERR(REG_ESPACE); return COLORLESS; } - cm->cd = new; + cm->cd = newCd; cm->ncds = n; assert(cm->max < cm->ncds - 1); cm->max++; @@ -285,7 +282,7 @@ newcolor( cd->flags = 0; cd->block = NULL; - return (color)(cd - cm->cd); + return (color) (cd - cm->cd); } /* @@ -298,7 +295,7 @@ freecolor( pcolor co) { struct colordesc *cd = &cm->cd[co]; - color pco, nco; /* for freelist scan */ + color pco, nco; /* for freelist scan */ assert(co >= 0); if (co == WHITE) { @@ -311,15 +308,15 @@ freecolor( cd->flags = FREECOL; if (cd->block != NULL) { FREE(cd->block); - cd->block = NULL; /* just paranoia */ + cd->block = NULL; /* just paranoia */ } - if ((size_t)co == cm->max) { + if ((size_t) co == cm->max) { while (cm->max > WHITE && UNUSEDCOLOR(&cm->cd[cm->max])) { cm->max--; } assert(cm->free >= 0); - while ((size_t)cm->free > cm->max) { + while ((size_t) cm->free > cm->max) { cm->free = cm->cd[cm->free].sub; } if (cm->free > 0) { @@ -327,7 +324,7 @@ freecolor( pco = cm->free; nco = cm->cd[pco].sub; while (nco > 0) { - if ((size_t)nco > cm->max) { + if ((size_t) nco > cm->max) { /* * Take this one out of freelist. */ @@ -343,7 +340,7 @@ freecolor( } } else { cd->sub = cm->free; - cm->free = (color)(cd - cm->cd); + cm->free = (color) (cd - cm->cd); } } @@ -375,8 +372,8 @@ subcolor( struct colormap *cm, pchr c) { - color co; /* current color of c */ - color sco; /* new subcolor */ + color co; /* current color of c */ + color sco; /* new subcolor */ co = GETCOLOR(cm, c); sco = newsub(cm, co); @@ -385,8 +382,8 @@ subcolor( } assert(sco != COLORLESS); - if (co == sco) { /* already in an open subcolor */ - return co; /* rest is redundant */ + if (co == sco) { /* already in an open subcolor */ + return co; /* rest is redundant */ } cm->cd[co].nchrs--; cm->cd[sco].nchrs++; @@ -403,20 +400,20 @@ newsub( struct colormap *cm, pcolor co) { - color sco; /* new subcolor */ + color sco; /* new subcolor */ sco = cm->cd[co].sub; - if (sco == NOSUB) { /* color has no open subcolor */ + if (sco == NOSUB) { /* color has no open subcolor */ if (cm->cd[co].nchrs == 1) { /* optimization */ return co; } - sco = newcolor(cm); /* must create subcolor */ + sco = newcolor(cm); /* must create subcolor */ if (sco == COLORLESS) { assert(CISERR()); return COLORLESS; } cm->cd[co].sub = sco; - cm->cd[sco].sub = sco; /* open subcolor points to self */ + cm->cd[sco].sub = sco; /* open subcolor points to self */ } assert(sco != NOSUB); @@ -445,12 +442,12 @@ subrange( * First, align "from" on a tree-block boundary */ - uf = (uchr)from; - i = (int)( ((uf + BYTTAB-1) & (uchr)~BYTMASK) - uf ); - for (; from <= to && i > 0; i--, from++) { + uf = (uchr) from; + i = (int) (((uf + BYTTAB - 1) & (uchr) ~BYTMASK) - uf); + for (; from<=to && i>0; i--, from++) { newarc(v->nfa, PLAIN, subcolor(v->cm, from), lp, rp); } - if (from > to) { /* didn't reach a boundary */ + if (from > to) { /* didn't reach a boundary */ return; } @@ -458,7 +455,7 @@ subrange( * Deal with whole blocks. */ - for (; to - from >= BYTTAB; from += BYTTAB) { + for (; to-from>=BYTTAB ; from+=BYTTAB) { subblock(v, from, lp, rp); } @@ -466,7 +463,7 @@ subrange( * Clean up any remaining partial table. */ - for (; from <= to; from++) { + for (; from<=to ; from++) { newarc(v->nfa, PLAIN, subcolor(v->cm, from), lp, rp); } } @@ -478,7 +475,7 @@ subrange( static void subblock( struct vars *v, - pchr start, /* first of BYTTAB chrs */ + pchr start, /* first of BYTTAB chrs */ struct state *lp, struct state *rp) { @@ -505,21 +502,19 @@ subblock( t = cm->tree; fillt = NULL; - for (level = 0, shift = BYTBITS * (NBYTS - 1); shift > 0; - level++, shift -= BYTBITS) { + for (level=0, shift=BYTBITS*(NBYTS-1); shift>0; level++, shift-=BYTBITS) { b = (uc >> shift) & BYTMASK; lastt = t; t = lastt->tptr[b]; assert(t != NULL); fillt = &cm->tree[level+1]; if (t == fillt && shift > BYTBITS) { /* need new ptr block */ - t = (union tree *)MALLOC(sizeof(struct ptrs)); + t = (union tree *) MALLOC(sizeof(struct ptrs)); if (t == NULL) { CERR(REG_ESPACE); return; } - memcpy(VS(t->tptr), VS(fillt->tptr), - BYTTAB*sizeof(union tree *)); + memcpy(t->tptr, fillt->tptr, BYTTAB*sizeof(union tree *)); lastt->tptr[b] = t; } } @@ -536,13 +531,13 @@ subblock( sco = newsub(cm, co); t = cm->cd[sco].block; - if (t == NULL) { /* must set it up */ - t = (union tree *)MALLOC(sizeof(struct colors)); + if (t == NULL) { /* must set it up */ + t = (union tree *) MALLOC(sizeof(struct colors)); if (t == NULL) { CERR(REG_ESPACE); return; } - for (i = 0; i < BYTTAB; i++) { + for (i=0 ; i<BYTTAB ; i++) { t->tcolor[i] = sco; } cm->cd[sco].block = t; @@ -594,7 +589,7 @@ okcolors( color co; color sco; - for (cd = cm->cd, co = 0; cd < end; cd++, co++) { + for (cd=cm->cd, co=0 ; cd<end ; cd++, co++) { sco = cd->sub; if (UNUSEDCOLOR(cd) || sco == NOSUB) { /* @@ -634,7 +629,7 @@ okcolors( assert(scd->nchrs > 0); assert(scd->sub == sco); scd->sub = NOSUB; - for (a = cd->arcs; a != NULL; a = a->colorchain) { + for (a=cd->arcs ; a!=NULL ; a=a->colorchain) { assert(a->co == co); newarc(nfa, a->type, sco, a->from, a->to); } @@ -670,17 +665,17 @@ uncolorchain( struct arc *aa; aa = cd->arcs; - if (aa == a) { /* easy case */ + if (aa == a) { /* easy case */ cd->arcs = a->colorchain; } else { assert(aa != NULL); - for (; aa->colorchain != a; aa = aa->colorchain) { + for (; aa->colorchain!=a ; aa=aa->colorchain) { assert(aa->colorchain != NULL); continue; } aa->colorchain = a->colorchain; } - a->colorchain = NULL; /* paranoia */ + a->colorchain = NULL; /* paranoia */ } #ifdef REGEXP_MCCE_ENABLED @@ -688,18 +683,14 @@ uncolorchain( - singleton - is this character in its own color? ^ static int singleton(struct colormap *, pchr c); */ -static int /* predicate */ +static int /* predicate */ singleton( struct colormap *cm, pchr c) { - color co; /* color of c */ + color co = GETCOLOR(cm, c); /* color of c */ - co = GETCOLOR(cm, c); - if (cm->cd[co].nchrs == 1 && cm->cd[co].sub == NOSUB) { - return 1; - } - return 0; + return (cm->cd[co].nchrs == 1) && (cm->cd[co].sub == NOSUB); } #endif @@ -713,7 +704,7 @@ rainbow( struct nfa *nfa, struct colormap *cm, int type, - pcolor but, /* COLORLESS if no exceptions */ + pcolor but, /* COLORLESS if no exceptions */ struct state *from, struct state *to) { @@ -721,7 +712,7 @@ rainbow( struct colordesc *end = CDEND(cm); color co; - for (cd = cm->cd, co = 0; cd < end && !CISERR(); cd++, co++) { + for (cd=cm->cd, co=0 ; cd<end && !CISERR(); cd++, co++) { if (!UNUSEDCOLOR(cd) && (cd->sub != co) && (co != but) && !(cd->flags&PSEUDO)) { newarc(nfa, type, co, from, to); @@ -740,8 +731,7 @@ colorcomplement( struct nfa *nfa, struct colormap *cm, int type, - struct state *of, /* complements of this guy's PLAIN - * outarcs */ + struct state *of, /* complements of this guy's PLAIN outarcs */ struct state *from, struct state *to) { @@ -750,7 +740,7 @@ colorcomplement( color co; assert(of != from); - for (cd = cm->cd, co = 0; cd < end && !CISERR(); cd++, co++) { + for (cd=cm->cd, co=0 ; cd<end && !CISERR() ; cd++, co++) { if (!UNUSEDCOLOR(cd) && !(cd->flags&PSEUDO)) { if (findarc(of, PLAIN, co) == NULL) { newarc(nfa, type, co, from, to); @@ -779,26 +769,26 @@ dumpcolors( chr c; char *has; - fprintf(f, "max %ld\n", (long)cm->max); + fprintf(f, "max %ld\n", (long) cm->max); if (NBYTS > 1) { fillcheck(cm, cm->tree, 0, f); } end = CDEND(cm); - for (cd = cm->cd + 1, co = 1; cd < end; cd++, co++) { /* skip 0 */ + for (cd=cm->cd+1, co=1 ; cd<end ; cd++, co++) { /* skip 0 */ if (!UNUSEDCOLOR(cd)) { assert(cd->nchrs > 0); has = (cd->block != NULL) ? "#" : ""; if (cd->flags&PSEUDO) { - fprintf(f, "#%2ld%s(ps): ", (long)co, has); + fprintf(f, "#%2ld%s(ps): ", (long) co, has); } else { - fprintf(f, "#%2ld%s(%2d): ", (long)co, has, cd->nchrs); + fprintf(f, "#%2ld%s(%2d): ", (long) co, has, cd->nchrs); } /* * It's hard to do this more efficiently. */ - for (c = CHR_MIN; c < CHR_MAX; c++) { + for (c=CHR_MIN ; c<CHR_MAX ; c++) { if (GETCOLOR(cm, c) == co) { dumpchr(c, f); } @@ -820,16 +810,15 @@ static void fillcheck( struct colormap *cm, union tree *tree, - int level, /* level number (top == 0) of this - * block */ + int level, /* level number (top == 0) of this block */ FILE *f) { int i; union tree *t; union tree *fillt = &cm->tree[level+1]; - assert(level < NBYTS-1); /* this level has pointers */ - for (i = BYTTAB-1; i >= 0; i--) { + assert(level < NBYTS-1); /* this level has pointers */ + for (i=BYTTAB-1 ; i>=0 ; i--) { t = tree->tptr[i]; if (t == NULL) { fprintf(f, "NULL found in filled tree!\n"); @@ -854,9 +843,9 @@ dumpchr( if (c == '\\') { fprintf(f, "\\\\"); } else if (c > ' ' && c <= '~') { - putc((char)c, f); + putc((char) c, f); } else { - fprintf(f, "\\u%04lx", (long)c); + fprintf(f, "\\u%04lx", (long) c); } } diff --git a/generic/regc_nfa.c b/generic/regc_nfa.c index d5e7e01..9f63f73 100644 --- a/generic/regc_nfa.c +++ b/generic/regc_nfa.c @@ -2,7 +2,7 @@ * NFA utilities. * This file is #included by regcomp.c. * - * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved. + * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved. * * Development of this software was funded, in part, by Cray Research Inc., * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics @@ -19,7 +19,7 @@ * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; @@ -47,7 +47,7 @@ newnfa( { struct nfa *nfa; - nfa = (struct nfa *)MALLOC(sizeof(struct nfa)); + nfa = (struct nfa *) MALLOC(sizeof(struct nfa)); if (nfa == NULL) { return NULL; } @@ -124,7 +124,7 @@ newstate( s = nfa->free; nfa->free = s->next; } else { - s = (struct state *)MALLOC(sizeof(struct state)); + s = (struct state *) MALLOC(sizeof(struct state)); if (s == NULL) { NERR(REG_ESPACE); return NULL; @@ -168,7 +168,7 @@ newfstate( s = newstate(nfa); if (s != NULL) { - s->flag = (char)flag; + s->flag = (char) flag; } return s; } @@ -220,8 +220,7 @@ freestate( nfa->states = s->next; } s->prev = NULL; - s->next = nfa->free; /* don't delete it, put it on the free - * list */ + s->next = nfa->free; /* don't delete it, put it on the free list */ nfa->free = s; } @@ -238,7 +237,7 @@ destroystate( struct arcbatch *abnext; assert(s->no == FREESTATE); - for (ab = s->oas.next; ab != NULL; ab = abnext) { + for (ab=s->oas.next ; ab!=NULL ; ab=abnext) { abnext = ab->next; FREE(ab); } @@ -269,7 +268,7 @@ newarc( * Check for duplicates. */ - for (a = from->outs; a != NULL; a = a->outchain) { + for (a=from->outs ; a!=NULL ; a=a->outchain) { if (a->to == to && a->co == co && a->type == t) { return; } @@ -282,7 +281,7 @@ newarc( assert(a != NULL); a->type = t; - a->co = (color)co; + a->co = (color) co; a->to = to; a->from = from; @@ -304,8 +303,6 @@ newarc( if (COLORED(a) && nfa->parent == NULL) { colorchain(nfa->cm, a); } - - return; } /* @@ -318,8 +315,6 @@ allocarc( struct state *s) { struct arc *a; - struct arcbatch *new; - int i; /* * Shortcut @@ -336,20 +331,23 @@ allocarc( */ if (s->free == NULL) { - new = (struct arcbatch *)MALLOC(sizeof(struct arcbatch)); - if (new == NULL) { + struct arcbatch *newAb = (struct arcbatch *) + MALLOC(sizeof(struct arcbatch)); + int i; + + if (newAb == NULL) { NERR(REG_ESPACE); return NULL; } - new->next = s->oas.next; - s->oas.next = new; + newAb->next = s->oas.next; + s->oas.next = newAb; - for (i = 0; i < ABSIZE; i++) { - new->a[i].type = 0; - new->a[i].freechain = &new->a[i+1]; + for (i=0 ; i<ABSIZE ; i++) { + newAb->a[i].type = 0; + newAb->a[i].freechain = &newAb->a[i+1]; } - new->a[ABSIZE-1].freechain = NULL; - s->free = &new->a[0]; + newAb->a[ABSIZE-1].freechain = NULL; + s->free = &newAb->a[0]; } assert(s->free != NULL); @@ -388,10 +386,10 @@ freearc( assert(from != NULL); assert(from->outs != NULL); a = from->outs; - if (a == victim) { /* simple case: first in chain */ + if (a == victim) { /* simple case: first in chain */ from->outs = victim->outchain; } else { - for (; a != NULL && a->outchain != victim; a = a->outchain) { + for (; a!=NULL && a->outchain!=victim ; a=a->outchain) { continue; } assert(a != NULL); @@ -406,10 +404,10 @@ freearc( assert(to != NULL); assert(to->ins != NULL); a = to->ins; - if (a == victim) { /* simple case: first in chain */ + if (a == victim) { /* simple case: first in chain */ to->ins = victim->inchain; } else { - for (; a->inchain != victim; a = a->inchain) { + for (; a->inchain!=victim ; a=a->inchain) { assert(a->inchain != NULL); continue; } @@ -422,7 +420,7 @@ freearc( */ victim->type = 0; - victim->from = NULL; /* precautions... */ + victim->from = NULL; /* precautions... */ victim->to = NULL; victim->inchain = NULL; victim->outchain = NULL; @@ -443,7 +441,7 @@ findarc( { struct arc *a; - for (a = s->outs; a != NULL; a = a->outchain) { + for (a=s->outs ; a!=NULL ; a=a->outchain) { if (a->type == type && a->co == co) { return a; } @@ -477,19 +475,19 @@ cparc( static void moveins( struct nfa *nfa, - struct state *old, - struct state *new) + struct state *oldState, + struct state *newState) { struct arc *a; - assert(old != new); + assert(oldState != newState); - while ((a = old->ins) != NULL) { - cparc(nfa, a, a->from, new); + while ((a = oldState->ins) != NULL) { + cparc(nfa, a, a->from, newState); freearc(nfa, a); } - assert(old->nins == 0); - assert(old->ins == NULL); + assert(oldState->nins == 0); + assert(oldState->ins == NULL); } /* @@ -499,15 +497,15 @@ moveins( static void copyins( struct nfa *nfa, - struct state *old, - struct state *new) + struct state *oldState, + struct state *newState) { struct arc *a; - assert(old != new); + assert(oldState != newState); - for (a = old->ins; a != NULL; a = a->inchain) { - cparc(nfa, a, a->from, new); + for (a=oldState->ins ; a!=NULL ; a=a->inchain) { + cparc(nfa, a, a->from, newState); } } @@ -518,15 +516,15 @@ copyins( static void moveouts( struct nfa *nfa, - struct state *old, - struct state *new) + struct state *oldState, + struct state *newState) { struct arc *a; - assert(old != new); + assert(oldState != newState); - while ((a = old->outs) != NULL) { - cparc(nfa, a, new, a->to); + while ((a = oldState->outs) != NULL) { + cparc(nfa, a, newState, a->to); freearc(nfa, a); } } @@ -538,15 +536,15 @@ moveouts( static void copyouts( struct nfa *nfa, - struct state *old, - struct state *new) + struct state *oldState, + struct state *newState) { struct arc *a; - assert(old != new); + assert(oldState != newState); - for (a = old->outs; a != NULL; a = a->outchain) { - cparc(nfa, a, new, a->to); + for (a=oldState->outs ; a!=NULL ; a=a->outchain) { + cparc(nfa, a, newState, a->to); } } @@ -567,7 +565,7 @@ cloneouts( assert(old != from); - for (a = old->outs; a != NULL; a = a->outchain) { + for (a=old->outs ; a!=NULL ; a=a->outchain) { newarc(nfa, type, a->co, from, to); } } @@ -639,9 +637,9 @@ deltraverse( /* - dupnfa - duplicate sub-NFA - * Another recursive traversal, this time using tmp to point to duplicates - * as well as mark already-seen states. (You knew there was a reason why - * it's a state pointer, didn't you? :-)) + * Another recursive traversal, this time using tmp to point to duplicates as + * well as mark already-seen states. (You knew there was a reason why it's a + * state pointer, didn't you? :-)) ^ static VOID dupnfa(struct nfa *, struct state *, struct state *, ^ struct state *, struct state *); */ @@ -688,8 +686,8 @@ duptraverse( return; } - for (a = s->outs; a != NULL && !NISERR(); a = a->outchain) { - duptraverse(nfa, a->to, (struct state *)NULL); + for (a=s->outs ; a!=NULL && !NISERR() ; a=a->outchain) { + duptraverse(nfa, a->to, NULL); assert(a->to->tmp != NULL); cparc(nfa, a, s->tmp, a->to->tmp); } @@ -711,7 +709,7 @@ cleartraverse( } s->tmp = NULL; - for (a = s->outs; a != NULL; a = a->outchain) { + for (a=s->outs ; a!=NULL ; a=a->outchain) { cleartraverse(nfa, a->to); } } @@ -800,9 +798,9 @@ pullback( do { progress = 0; - for (s = nfa->states; s != NULL && !NISERR(); s = nexts) { + for (s=nfa->states ; s!=NULL && !NISERR() ; s=nexts) { nexts = s->next; - for (a = s->outs; a != NULL && !NISERR(); a = nexta) { + for (a=s->outs ; a!=NULL && !NISERR() ; a=nexta) { nexta = a->outchain; if (a->type == '^' || a->type == BEHIND) { if (pull(nfa, a)) { @@ -820,7 +818,7 @@ pullback( return; } - for (a = nfa->pre->outs; a != NULL; a = nexta) { + for (a=nfa->pre->outs ; a!=NULL ; a=nexta) { nexta = a->outchain; if (a->type == '^') { assert(a->co == 0 || a->co == 1); @@ -882,7 +880,7 @@ pull( * Propagate the constraint into the from state's inarcs. */ - for (a = from->ins; a != NULL; a = nexta) { + for (a=from->ins ; a!=NULL ; a=nexta) { nexta = a->inchain; switch (combine(con, a)) { case INCOMPATIBLE: /* destroy the arc */ @@ -938,7 +936,7 @@ pushfwd( do { progress = 0; - for (s = nfa->states; s != NULL && !NISERR(); s = nexts) { + for (s=nfa->states ; s!=NULL && !NISERR() ; s=nexts) { nexts = s->next; for (a = s->ins; a != NULL && !NISERR(); a = nexta) { nexta = a->inchain; @@ -1153,8 +1151,8 @@ fixempties( /* - unempty - optimize out an EMPTY arc, if possible - * Actually, as it stands this function always succeeds, but the return - * value is kept with an eye on possible future changes. + * Actually, as it stands this function always succeeds, but the return value + * is kept with an eye on possible future changes. ^ static int unempty(struct nfa *, struct arc *); */ static int /* 0 couldn't, 1 could */ @@ -1178,7 +1176,7 @@ unempty( * Decide which end to work on. */ - usefrom = 1; /* default: attack from */ + usefrom = 1; /* default: attack from */ if (from->nouts > to->nins) { usefrom = 0; } else if (from->nouts == to->nins) { @@ -1194,7 +1192,10 @@ unempty( freearc(nfa, a); if (usefrom) { if (from->nouts == 0) { - /* was the state's only outarc */ + /* + * Was the state's only outarc. + */ + moveins(nfa, from, to); freestate(nfa, from); } else { @@ -1202,7 +1203,10 @@ unempty( } } else { if (to->nins == 0) { - /* was the state's only inarc */ + /* + * Was the state's only inarc. + */ + moveouts(nfa, to, from); freestate(nfa, to); } else { @@ -1230,7 +1234,7 @@ cleanup( * then post to mark can-reach-post. */ - markreachable(nfa, nfa->pre, (struct state *)NULL, nfa->pre); + markreachable(nfa, nfa->pre, NULL, nfa->pre); markcanreach(nfa, nfa->post, nfa->pre, nfa->post); for (s = nfa->states; s != NULL; s = nexts) { nexts = s->next; @@ -1342,7 +1346,7 @@ compact( struct carc *ca; struct carc *first; - assert (!NISERR()); + assert(!NISERR()); nstates = 0; narcs = 0; @@ -1352,8 +1356,8 @@ compact( /* 1 as a fake for flags, nouts for arcs, 1 as endmarker */ } - cnfa->states = (struct carc **)MALLOC(nstates * sizeof(struct carc *)); - cnfa->arcs = (struct carc *)MALLOC(narcs * sizeof(struct carc)); + cnfa->states = (struct carc **) MALLOC(nstates * sizeof(struct carc *)); + cnfa->arcs = (struct carc *) MALLOC(narcs * sizeof(struct carc)); if (cnfa->states == NULL || cnfa->arcs == NULL) { if (cnfa->states != NULL) { FREE(cnfa->states); @@ -1376,7 +1380,7 @@ compact( ca = cnfa->arcs; for (s = nfa->states; s != NULL; s = s->next) { - assert((size_t)s->no < nstates); + assert((size_t) s->no < nstates); cnfa->states[s->no] = ca; ca->co = 0; /* clear and skip flags "arc" */ ca++; @@ -1390,7 +1394,7 @@ compact( break; case LACON: assert(s->no != cnfa->pre); - ca->co = (color)(cnfa->ncolors + a->co); + ca->co = (color) (cnfa->ncolors + a->co); ca->to = a->to->no; ca++; cnfa->flags |= HASLACONS; @@ -1477,16 +1481,16 @@ dumpnfa( fprintf(f, "pre %d, post %d", nfa->pre->no, nfa->post->no); if (nfa->bos[0] != COLORLESS) { - fprintf(f, ", bos [%ld]", (long)nfa->bos[0]); + fprintf(f, ", bos [%ld]", (long) nfa->bos[0]); } if (nfa->bos[1] != COLORLESS) { - fprintf(f, ", bol [%ld]", (long)nfa->bos[1]); + fprintf(f, ", bol [%ld]", (long) nfa->bos[1]); } if (nfa->eos[0] != COLORLESS) { - fprintf(f, ", eos [%ld]", (long)nfa->eos[0]); + fprintf(f, ", eos [%ld]", (long) nfa->eos[0]); } if (nfa->eos[1] != COLORLESS) { - fprintf(f, ", eol [%ld]", (long)nfa->eos[1]); + fprintf(f, ", eol [%ld]", (long) nfa->eos[1]); } fprintf(f, "\n"); for (s = nfa->states; s != NULL; s = s->next) { @@ -1593,25 +1597,25 @@ dumparc( fprintf(f, "\t"); switch (a->type) { case PLAIN: - fprintf(f, "[%ld]", (long)a->co); + fprintf(f, "[%ld]", (long) a->co); break; case AHEAD: - fprintf(f, ">%ld>", (long)a->co); + fprintf(f, ">%ld>", (long) a->co); break; case BEHIND: - fprintf(f, "<%ld<", (long)a->co); + fprintf(f, "<%ld<", (long) a->co); break; case LACON: - fprintf(f, ":%ld:", (long)a->co); + fprintf(f, ":%ld:", (long) a->co); break; case '^': case '$': - fprintf(f, "%c%d", a->type, (int)a->co); + fprintf(f, "%c%d", a->type, (int) a->co); break; case EMPTY: break; default: - fprintf(f, "0x%x/0%lo", a->type, (long)a->co); + fprintf(f, "0x%x/0%lo", a->type, (long) a->co); break; } if (a->from != s) { @@ -1665,16 +1669,16 @@ dumpcnfa( fprintf(f, "pre %d, post %d", cnfa->pre, cnfa->post); if (cnfa->bos[0] != COLORLESS) { - fprintf(f, ", bos [%ld]", (long)cnfa->bos[0]); + fprintf(f, ", bos [%ld]", (long) cnfa->bos[0]); } if (cnfa->bos[1] != COLORLESS) { - fprintf(f, ", bol [%ld]", (long)cnfa->bos[1]); + fprintf(f, ", bol [%ld]", (long) cnfa->bos[1]); } if (cnfa->eos[0] != COLORLESS) { - fprintf(f, ", eos [%ld]", (long)cnfa->eos[0]); + fprintf(f, ", eos [%ld]", (long) cnfa->eos[0]); } if (cnfa->eos[1] != COLORLESS) { - fprintf(f, ", eol [%ld]", (long)cnfa->eos[1]); + fprintf(f, ", eol [%ld]", (long) cnfa->eos[1]); } if (cnfa->flags&HASLACONS) { fprintf(f, ", haslacons"); @@ -1710,9 +1714,9 @@ dumpcstate( pos = 1; for (i = 1; ca[i].co != COLORLESS; i++) { if (ca[i].co < cnfa->ncolors) { - fprintf(f, "\t[%ld]->%d", (long)ca[i].co, ca[i].to); + fprintf(f, "\t[%ld]->%d", (long) ca[i].co, ca[i].to); } else { - fprintf(f, "\t:%ld:->%d", (long)ca[i].co-cnfa->ncolors, ca[i].to); + fprintf(f, "\t:%ld:->%d", (long) ca[i].co-cnfa->ncolors,ca[i].to); } if (pos == 5) { fprintf(f, "\n"); diff --git a/generic/regcomp.c b/generic/regcomp.c index 4137caf..b9169f9 100644 --- a/generic/regcomp.c +++ b/generic/regcomp.c @@ -2,11 +2,11 @@ * re_*comp and friends - compile REs * This file #includes several others (see the bottom). * - * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved. + * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved. * * Development of this software was funded, in part, by Cray Research Inc., * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics - * Corporation, none of whom are responsible for the results. The author + * Corporation, none of whom are responsible for the results. The author * thanks all of them. * * Redistribution and use in source and binary forms -- with or without @@ -19,7 +19,7 @@ * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; @@ -39,148 +39,148 @@ /* automatically gathered by fwd; do not hand-edit */ /* === regcomp.c === */ int compile(regex_t *, const chr *, size_t, int); -static VOID moresubs(struct vars *, int); +static void moresubs(struct vars *, int); static int freev(struct vars *, int); -static VOID makesearch(struct vars *, struct nfa *); +static void makesearch(struct vars *, struct nfa *); static struct subre *parse(struct vars *, int, int, struct state *, struct state *); static struct subre *parsebranch(struct vars *, int, int, struct state *, struct state *, int); -static VOID parseqatom(struct vars *, int, int, struct state *, struct state *, struct subre *); -static VOID nonword(struct vars *, int, struct state *, struct state *); -static VOID word(struct vars *, int, struct state *, struct state *); +static void parseqatom(struct vars *, int, int, struct state *, struct state *, struct subre *); +static void nonword(struct vars *, int, struct state *, struct state *); +static void word(struct vars *, int, struct state *, struct state *); static int scannum(struct vars *); -static VOID repeat(struct vars *, struct state *, struct state *, int, int); -static VOID bracket(struct vars *, struct state *, struct state *); -static VOID cbracket(struct vars *, struct state *, struct state *); -static VOID brackpart(struct vars *, struct state *, struct state *); +static void repeat(struct vars *, struct state *, struct state *, int, int); +static void bracket(struct vars *, struct state *, struct state *); +static void cbracket(struct vars *, struct state *, struct state *); +static void brackpart(struct vars *, struct state *, struct state *); static const chr *scanplain(struct vars *); -static VOID leaders(struct vars *, struct cvec *); -static VOID onechr(struct vars *, pchr, struct state *, struct state *); -static VOID dovec(struct vars *, struct cvec *, struct state *, struct state *); +static void leaders(struct vars *, struct cvec *); +static void onechr(struct vars *, pchr, struct state *, struct state *); +static void dovec(struct vars *, struct cvec *, struct state *, struct state *); #ifdef REGEXP_MCCE_ENABLED static celt nextleader(struct vars *, pchr, pchr); #endif -static VOID wordchrs(struct vars *); +static void wordchrs(struct vars *); static struct subre *subre(struct vars *, int, int, struct state *, struct state *); -static VOID freesubre(struct vars *, struct subre *); -static VOID freesrnode(struct vars *, struct subre *); -static VOID optst(struct vars *, struct subre *); +static void freesubre(struct vars *, struct subre *); +static void freesrnode(struct vars *, struct subre *); +static void optst(struct vars *, struct subre *); static int numst(struct subre *, int); -static VOID markst(struct subre *); -static VOID cleanst(struct vars *); +static void markst(struct subre *); +static void cleanst(struct vars *); static long nfatree(struct vars *, struct subre *, FILE *); static long nfanode(struct vars *, struct subre *, FILE *); static int newlacon(struct vars *, struct state *, struct state *, int); -static VOID freelacons(struct subre *, int); -static VOID rfree(regex_t *); -static VOID dump(regex_t *, FILE *); -static VOID dumpst(struct subre *, FILE *, int); -static VOID stdump(struct subre *, FILE *, int); +static void freelacons(struct subre *, int); +static void rfree(regex_t *); +static void dump(regex_t *, FILE *); +static void dumpst(struct subre *, FILE *, int); +static void stdump(struct subre *, FILE *, int); static const char *stid(struct subre *, char *, size_t); /* === regc_lex.c === */ -static VOID lexstart(struct vars *); -static VOID prefixes(struct vars *); -static VOID lexnest(struct vars *, const chr *, const chr *); -static VOID lexword(struct vars *); +static void lexstart(struct vars *); +static void prefixes(struct vars *); +static void lexnest(struct vars *, const chr *, const chr *); +static void lexword(struct vars *); static int next(struct vars *); static int lexescape(struct vars *); static chr lexdigits(struct vars *, int, int, int); static int brenext(struct vars *, pchr); -static VOID skip(struct vars *); +static void skip(struct vars *); static chr newline(NOPARMS); #ifdef REG_DEBUG static const chr *ch(NOPARMS); #endif static chr chrnamed(struct vars *, const chr *, const chr *, pchr); /* === regc_color.c === */ -static VOID initcm(struct vars *, struct colormap *); -static VOID freecm(struct colormap *); -static VOID cmtreefree(struct colormap *, union tree *, int); +static void initcm(struct vars *, struct colormap *); +static void freecm(struct colormap *); +static void cmtreefree(struct colormap *, union tree *, int); static color setcolor(struct colormap *, pchr, pcolor); static color maxcolor(struct colormap *); static color newcolor(struct colormap *); -static VOID freecolor(struct colormap *, pcolor); +static void freecolor(struct colormap *, pcolor); static color pseudocolor(struct colormap *); static color subcolor(struct colormap *, pchr c); static color newsub(struct colormap *, pcolor); -static VOID subrange(struct vars *, pchr, pchr, struct state *, struct state *); -static VOID subblock(struct vars *, pchr, struct state *, struct state *); -static VOID okcolors(struct nfa *, struct colormap *); -static VOID colorchain(struct colormap *, struct arc *); -static VOID uncolorchain(struct colormap *, struct arc *); +static void subrange(struct vars *, pchr, pchr, struct state *, struct state *); +static void subblock(struct vars *, pchr, struct state *, struct state *); +static void okcolors(struct nfa *, struct colormap *); +static void colorchain(struct colormap *, struct arc *); +static void uncolorchain(struct colormap *, struct arc *); #ifdef REGEXP_MCCE_ENABLED static int singleton(struct colormap *, pchr c); #endif -static VOID rainbow(struct nfa *, struct colormap *, int, pcolor, struct state *, struct state *); -static VOID colorcomplement(struct nfa *, struct colormap *, int, struct state *, struct state *, struct state *); +static void rainbow(struct nfa *, struct colormap *, int, pcolor, struct state *, struct state *); +static void colorcomplement(struct nfa *, struct colormap *, int, struct state *, struct state *, struct state *); #ifdef REG_DEBUG -static VOID dumpcolors(struct colormap *, FILE *); -static VOID fillcheck(struct colormap *, union tree *, int, FILE *); -static VOID dumpchr(pchr, FILE *); +static void dumpcolors(struct colormap *, FILE *); +static void fillcheck(struct colormap *, union tree *, int, FILE *); +static void dumpchr(pchr, FILE *); #endif /* === regc_nfa.c === */ static struct nfa *newnfa(struct vars *, struct colormap *, struct nfa *); -static VOID freenfa(struct nfa *); +static void freenfa(struct nfa *); static struct state *newstate(struct nfa *); static struct state *newfstate(struct nfa *, int flag); -static VOID dropstate(struct nfa *, struct state *); -static VOID freestate(struct nfa *, struct state *); -static VOID destroystate(struct nfa *, struct state *); -static VOID newarc(struct nfa *, int, pcolor, struct state *, struct state *); +static void dropstate(struct nfa *, struct state *); +static void freestate(struct nfa *, struct state *); +static void destroystate(struct nfa *, struct state *); +static void newarc(struct nfa *, int, pcolor, struct state *, struct state *); static struct arc *allocarc(struct nfa *, struct state *); -static VOID freearc(struct nfa *, struct arc *); +static void freearc(struct nfa *, struct arc *); static struct arc *findarc(struct state *, int, pcolor); -static VOID cparc(struct nfa *, struct arc *, struct state *, struct state *); -static VOID moveins(struct nfa *, struct state *, struct state *); -static VOID copyins(struct nfa *, struct state *, struct state *); -static VOID moveouts(struct nfa *, struct state *, struct state *); -static VOID copyouts(struct nfa *, struct state *, struct state *); -static VOID cloneouts(struct nfa *, struct state *, struct state *, struct state *, int); -static VOID delsub(struct nfa *, struct state *, struct state *); -static VOID deltraverse(struct nfa *, struct state *, struct state *); -static VOID dupnfa(struct nfa *, struct state *, struct state *, struct state *, struct state *); -static VOID duptraverse(struct nfa *, struct state *, struct state *); -static VOID cleartraverse(struct nfa *, struct state *); -static VOID specialcolors(struct nfa *); +static void cparc(struct nfa *, struct arc *, struct state *, struct state *); +static void moveins(struct nfa *, struct state *, struct state *); +static void copyins(struct nfa *, struct state *, struct state *); +static void moveouts(struct nfa *, struct state *, struct state *); +static void copyouts(struct nfa *, struct state *, struct state *); +static void cloneouts(struct nfa *, struct state *, struct state *, struct state *, int); +static void delsub(struct nfa *, struct state *, struct state *); +static void deltraverse(struct nfa *, struct state *, struct state *); +static void dupnfa(struct nfa *, struct state *, struct state *, struct state *, struct state *); +static void duptraverse(struct nfa *, struct state *, struct state *); +static void cleartraverse(struct nfa *, struct state *); +static void specialcolors(struct nfa *); static long optimize(struct nfa *, FILE *); -static VOID pullback(struct nfa *, FILE *); +static void pullback(struct nfa *, FILE *); static int pull(struct nfa *, struct arc *); -static VOID pushfwd(struct nfa *, FILE *); +static void pushfwd(struct nfa *, FILE *); static int push(struct nfa *, struct arc *); #define INCOMPATIBLE 1 /* destroys arc */ #define SATISFIED 2 /* constraint satisfied */ #define COMPATIBLE 3 /* compatible but not satisfied yet */ static int combine(struct arc *, struct arc *); -static VOID fixempties(struct nfa *, FILE *); +static void fixempties(struct nfa *, FILE *); static int unempty(struct nfa *, struct arc *); -static VOID cleanup(struct nfa *); -static VOID markreachable(struct nfa *, struct state *, struct state *, struct state *); -static VOID markcanreach(struct nfa *, struct state *, struct state *, struct state *); +static void cleanup(struct nfa *); +static void markreachable(struct nfa *, struct state *, struct state *, struct state *); +static void markcanreach(struct nfa *, struct state *, struct state *, struct state *); static long analyze(struct nfa *); -static VOID compact(struct nfa *, struct cnfa *); -static VOID carcsort(struct carc *, struct carc *); -static VOID freecnfa(struct cnfa *); -static VOID dumpnfa(struct nfa *, FILE *); +static void compact(struct nfa *, struct cnfa *); +static void carcsort(struct carc *, struct carc *); +static void freecnfa(struct cnfa *); +static void dumpnfa(struct nfa *, FILE *); #ifdef REG_DEBUG -static VOID dumpstate(struct state *, FILE *); -static VOID dumparcs(struct state *, FILE *); +static void dumpstate(struct state *, FILE *); +static void dumparcs(struct state *, FILE *); static int dumprarcs(struct arc *, struct state *, FILE *, int); -static VOID dumparc(struct arc *, struct state *, FILE *); +static void dumparc(struct arc *, struct state *, FILE *); #endif -static VOID dumpcnfa(struct cnfa *, FILE *); +static void dumpcnfa(struct cnfa *, FILE *); #ifdef REG_DEBUG -static VOID dumpcstate(int, struct carc *, struct cnfa *, FILE *); +static void dumpcstate(int, struct carc *, struct cnfa *, FILE *); #endif /* === regc_cvec.c === */ static struct cvec *newcvec(int, int, int); static struct cvec *clearcvec(struct cvec *); -static VOID addchr(struct cvec *, pchr); -static VOID addrange(struct cvec *, pchr, pchr); +static void addchr(struct cvec *, pchr); +static void addrange(struct cvec *, pchr, pchr); #ifdef REGEXP_MCCE_ENABLED -static VOID addmcce(struct cvec *, const chr *, const chr *); +static void addmcce(struct cvec *, const chr *, const chr *); #endif static int haschr(struct cvec *, pchr); static struct cvec *getcvec(struct vars *, int, int, int); -static VOID freecvec(struct cvec *); +static void freecvec(struct cvec *); /* === regc_locale.c === */ static int nmcces(struct vars *); static int nleaders(struct vars *); @@ -291,7 +291,7 @@ compile( struct guts *g; int i; size_t j; - FILE *debug = (flags®_PROGRESS) ? stdout : (FILE *)NULL; + FILE *debug = (flags®_PROGRESS) ? stdout : NULL; #define CNOERR() { if (ISERR()) return freev(v, v->err); } /* @@ -353,7 +353,7 @@ compile( if (re->re_guts == NULL) { return freev(v, REG_ESPACE); } - g = (struct guts *)re->re_guts; + g = (struct guts *) re->re_guts; g->tree = NULL; initcm(v, &g->cmap); v->cm = &g->cmap; @@ -374,7 +374,7 @@ compile( leaders(v, v->mcces); #ifdef REGEXP_MCCE_ENABLED /* Function does nothing with NULL pointers */ - addmcce(v->mcces, (const chr *)NULL, (const chr *)NULL); /* dummy */ + addmcce(v->mcces, NULL, NULL); /* dummy */ #endif } CNOERR(); @@ -448,7 +448,7 @@ compile( * Can sacrifice main NFA now, so use it as work area. */ - (DISCARD)optimize(v->nfa, debug); + (DISCARD) optimize(v->nfa, debug); CNOERR(); makesearch(v, v->nfa); CNOERR(); @@ -460,7 +460,7 @@ compile( */ re->re_nsub = v->nsubexp; - v->re = NULL; /* freev no longer frees re */ + v->re = NULL; /* freev no longer frees re */ g->magic = GUTSMAGIC; g->cflags = v->cflags; g->info = re->re_info; @@ -483,7 +483,7 @@ compile( /* - moresubs - enlarge subRE vector - ^ static VOID moresubs(struct vars *, int); + ^ static void moresubs(struct vars *, int); */ static void moresubs( @@ -496,12 +496,12 @@ moresubs( assert(wanted > 0 && (size_t)wanted >= v->nsubs); n = (size_t)wanted * 3 / 2 + 1; if (v->subs == v->sub10) { - p = (struct subre **)MALLOC(n * sizeof(struct subre *)); + p = (struct subre **) MALLOC(n * sizeof(struct subre *)); if (p != NULL) { - memcpy(VS(p), VS(v->subs), v->nsubs * sizeof(struct subre *)); + memcpy(p, v->subs, v->nsubs * sizeof(struct subre *)); } } else { - p = (struct subre **)REALLOC(v->subs, n*sizeof(struct subre *)); + p = (struct subre **) REALLOC(v->subs, n*sizeof(struct subre *)); } if (p == NULL) { ERR(REG_ESPACE); @@ -518,8 +518,8 @@ moresubs( /* - freev - free vars struct's substructures where necessary - * Optionally does error-number setting, and always returns error code - * (if any), to make error-handling code terser. + * Optionally does error-number setting, and always returns error code (if + * any), to make error-handling code terser. ^ static int freev(struct vars *, int); */ static int @@ -566,19 +566,16 @@ freev( /* - makesearch - turn an NFA into a search NFA (implicit prepend of .*?) * NFA must have been optimize()d already. - ^ static VOID makesearch(struct vars *, struct nfa *); + ^ static void makesearch(struct vars *, struct nfa *); */ static void makesearch( struct vars *v, struct nfa *nfa) { - struct arc *a; - struct arc *b; + struct arc *a, *b; struct state *pre = nfa->pre; - struct state *s; - struct state *s2; - struct state *slist; + struct state *s, *s2, *slist; /* * No loops are needed if it's anchored. @@ -619,9 +616,9 @@ makesearch( */ slist = NULL; - for (a = pre->outs; a != NULL; a = a->outchain) { + for (a=pre->outs ; a!=NULL ; a=a->outchain) { s = a->to; - for (b = s->ins; b != NULL; b = b->inchain) { + for (b=s->ins ; b!=NULL ; b=b->inchain) { if (b->from != pre) { break; } @@ -641,11 +638,13 @@ makesearch( * Do the splits. */ - for (s = slist; s != NULL; s = s2) { + for (s=slist ; s!=NULL ; s=s2) { s2 = newstate(nfa); + copyouts(nfa, s, s2); - for (a = s->ins; a != NULL; a = b) { + for (a=s->ins ; a!=NULL ; a=b) { b = a->inchain; + if (a->from != pre) { cparc(nfa, a, a->from, s2); freearc(nfa, a); @@ -658,9 +657,9 @@ makesearch( /* - parse - parse an RE - * This is actually just the top level, which parses a bunch of branches - * tied together with '|'. They appear in the tree as the left children - * of a chain of '|' subres. + * This is actually just the top level, which parses a bunch of branches tied + * together with '|'. They appear in the tree as the left children of a chain + * of '|' subres. ^ static struct subre *parse(struct vars *, int, int, struct state *, ^ struct state *); */ @@ -672,8 +671,7 @@ parse( struct state *init, /* initial state */ struct state *final) /* final state */ { - struct state *left; /* scaffolding for branch */ - struct state *right; + struct state *left, *right; /* scaffolding for branch */ struct subre *branches; /* top level */ struct subre *branch; /* current branch */ struct subre *t; /* temporary */ @@ -792,7 +790,7 @@ parsebranch( * The bookkeeping near the end cooperates very closely with parsebranch(); in * particular, it contains a recursion that can involve parsing the rest of * the branch, making this function's name somewhat inaccurate. - ^ static VOID parseqatom(struct vars *, int, int, struct state *, + ^ static void parseqatom(struct vars *, int, int, struct state *, ^ struct state *, struct subre *); */ static void @@ -824,7 +822,7 @@ parseqatom( atom = NULL; assert(lp->nouts == 0); /* must string new code */ - assert(rp->nins == 0); /* between lp and rp */ + assert(rp->nins == 0); /* between lp and rp */ subno = 0; /* just to shut lint up */ /* @@ -1142,7 +1140,7 @@ parseqatom( } /* - * prepare a general-purpose state skeleton + * Prepare a general-purpose state skeleton. * * ---> [s] ---prefix---> [begin] ---atom---> [end] ----rest---> [rp] * / / @@ -1243,8 +1241,8 @@ parseqatom( */ repeat(v, atom->begin, atom->end, m, n); - atom->min = (short)m; - atom->max = (short)n; + atom->min = (short) m; + atom->max = (short) n; atom->flags |= COMBINE(qprefer, atom->flags); } else if (m == 1 && n == 1) { /* @@ -1288,7 +1286,7 @@ parseqatom( /* - nonword - generate arcs for non-word-character ahead or behind - ^ static VOID nonword(struct vars *, int, struct state *, struct state *); + ^ static void nonword(struct vars *, int, struct state *, struct state *); */ static void nonword( @@ -1308,7 +1306,7 @@ nonword( /* - word - generate arcs for word character ahead or behind - ^ static VOID word(struct vars *, int, struct state *, struct state *); + ^ static void word(struct vars *, int, struct state *, struct state *); */ static void word( @@ -1347,11 +1345,11 @@ scannum( - repeat - replicate subNFA for quantifiers * The duplication sequences used here are chosen carefully so that any * pointers starting out pointing into the subexpression end up pointing into - * the last occurrence. (Note that it may not be strung between the same - * left and right end states, however!) This used to be important for the - * subRE tree, although the important bits are now handled by the in-line - * code in parse(), and when this is called, it doesn't matter any more. - ^ static VOID repeat(struct vars *, struct state *, struct state *, int, int); + * the last occurrence. (Note that it may not be strung between the same left + * and right end states, however!) This used to be important for the subRE + * tree, although the important bits are now handled by the in-line code in + * parse(), and when this is called, it doesn't matter any more. + ^ static void repeat(struct vars *, struct state *, struct state *, int, int); */ static void repeat( @@ -1367,8 +1365,7 @@ repeat( #define REDUCE(x) ( ((x) == INFINITY) ? INF : (((x) > 1) ? SOME : (x)) ) const int rm = REDUCE(m); const int rn = REDUCE(n); - struct state *s; - struct state *s2; + struct state *s, *s2; switch (PAIR(rm, rn)) { case PAIR(0, 0): /* empty string */ @@ -1438,7 +1435,7 @@ repeat( /* - bracket - handle non-complemented bracket expression * Also called from cbracket for complemented bracket expressions. - ^ static VOID bracket(struct vars *, struct state *, struct state *); + ^ static void bracket(struct vars *, struct state *, struct state *); */ static void bracket( @@ -1460,7 +1457,7 @@ bracket( * We do it by calling bracket() with dummy endpoints, and then complementing * the result. The alternative would be to invoke rainbow(), and then delete * arcs as the b.e. is seen... but that gets messy. - ^ static VOID cbracket(struct vars *, struct state *, struct state *); + ^ static void cbracket(struct vars *, struct state *, struct state *); */ static void cbracket( @@ -1471,9 +1468,9 @@ cbracket( struct state *left = newstate(v->nfa); struct state *right = newstate(v->nfa); struct state *s; - struct arc *a; /* arc from lp */ - struct arc *ba; /* arc from left, from bracket() */ - struct arc *pa; /* MCCE-prototype arc */ + struct arc *a; /* arc from lp */ + struct arc *ba; /* arc from left, from bracket() */ + struct arc *pa; /* MCCE-prototype arc */ color co; const chr *p; int i; @@ -1485,7 +1482,7 @@ cbracket( } NOERR(); - assert(lp->nouts == 0); /* all outarcs will be ours */ + assert(lp->nouts == 0); /* all outarcs will be ours */ /* * Easy part of complementing @@ -1493,7 +1490,7 @@ cbracket( colorcomplement(v->nfa, v->cm, PLAIN, left, lp, rp); NOERR(); - if (v->mcces == NULL) { /* no MCCEs -- we're done */ + if (v->mcces == NULL) { /* no MCCEs -- we're done */ dropstate(v->nfa, left); assert(right->nins == 0); freestate(v->nfa, right); @@ -1553,7 +1550,7 @@ cbracket( /* - brackpart - handle one item (or range) within a bracket expression - ^ static VOID brackpart(struct vars *, struct state *, struct state *); + ^ static void brackpart(struct vars *, struct state *, struct state *); */ static void brackpart( @@ -1561,11 +1558,9 @@ brackpart( struct state *lp, struct state *rp) { - celt startc; - celt endc; + celt startc, endc; struct cvec *cv; - const chr *startp; - const chr *endp; + const chr *startp, *endp; chr c[1]; /* @@ -1699,7 +1694,7 @@ scanplain( - leaders - process a cvec of collating elements to also include leaders * Also gives all characters involved their own colors, which is almost * certainly necessary, and sets up little disconnected subNFA. - ^ static VOID leaders(struct vars *, struct cvec *); + ^ static void leaders(struct vars *, struct cvec *); */ static void leaders( @@ -1740,7 +1735,7 @@ leaders( /* - onechr - fill in arcs for a plain character, and possible case complements * This is mostly a shortcut for efficient handling of the common case. - ^ static VOID onechr(struct vars *, pchr, struct state *, struct state *); + ^ static void onechr(struct vars *, pchr, struct state *, struct state *); */ static void onechr( @@ -1761,7 +1756,7 @@ onechr( /* - dovec - fill in arcs for each element of a cvec * This one has to handle the messy cases, like MCCEs and MCCE leaders. - ^ static VOID dovec(struct vars *, struct cvec *, struct state *, + ^ static void dovec(struct vars *, struct cvec *, struct state *, ^ struct state *); */ #ifndef REGEXP_MCCE_ENABLED @@ -1828,7 +1823,7 @@ dovec( } else { leads = NULL; } - + /* * First, get the ordinary characters out of the way. */ @@ -1876,7 +1871,7 @@ dovec( * Possibly just a problem with parens? The original condition was * ((leads == NULL || leads->nchrs == 0) && cv->nmcces == 0) */ - + if (leads == NULL || (leads->nchrs == 0 && cv->nmcces == 0)) { return; } @@ -1976,14 +1971,13 @@ nextleader( * not be called from any unusual lexical context. This should be reconciled * with the \w etc. handling in lex.c, and should be cleaned up to reduce * dependencies on input scanning. - ^ static VOID wordchrs(struct vars *); + ^ static void wordchrs(struct vars *); */ static void wordchrs( struct vars *v) { - struct state *left; - struct state *right; + struct state *left, *right; if (v->wordchrs != NULL) { NEXT(); /* for consistency */ @@ -2021,13 +2015,12 @@ subre( struct state *begin, struct state *end) { - struct subre *ret; + struct subre *ret = v->treefree; - ret = v->treefree; if (ret != NULL) { v->treefree = ret->left; } else { - ret = (struct subre *)MALLOC(sizeof(struct subre)); + ret = (struct subre *) MALLOC(sizeof(struct subre)); if (ret == NULL) { ERR(REG_ESPACE); return NULL; @@ -2054,7 +2047,7 @@ subre( /* - freesubre - free a subRE subtree - ^ static VOID freesubre(struct vars *, struct subre *); + ^ static void freesubre(struct vars *, struct subre *); */ static void freesubre( @@ -2077,7 +2070,7 @@ freesubre( /* - freesrnode - free one node in a subRE subtree - ^ static VOID freesrnode(struct vars *, struct subre *); + ^ static void freesrnode(struct vars *, struct subre *); */ static void freesrnode( @@ -2103,7 +2096,7 @@ freesrnode( /* - optst - optimize a subRE subtree - ^ static VOID optst(struct vars *, struct subre *); + ^ static void optst(struct vars *, struct subre *); */ static void optst( @@ -2140,7 +2133,7 @@ numst( assert(t != NULL); i = start; - t->retry = (short)i++; + t->retry = (short) i++; if (t->left != NULL) { i = numst(t->left, i); } @@ -2152,7 +2145,7 @@ numst( /* - markst - mark tree nodes as INUSE - ^ static VOID markst(struct subre *); + ^ static void markst(struct subre *); */ static void markst( @@ -2171,7 +2164,7 @@ markst( /* - cleanst - free any tree nodes not marked INUSE - ^ static VOID cleanst(struct vars *); + ^ static void cleanst(struct vars *); */ static void cleanst( @@ -2203,10 +2196,10 @@ nfatree( assert(t != NULL && t->begin != NULL); if (t->left != NULL) { - (DISCARD)nfatree(v, t->left, f); + (DISCARD) nfatree(v, t->left, f); } if (t->right != NULL) { - (DISCARD)nfatree(v, t->right, f); + (DISCARD) nfatree(v, t->right, f); } return nfanode(v, t, f); @@ -2258,22 +2251,24 @@ newlacon( struct state *end, int pos) { - int n; struct subre *sub; + int n; if (v->nlacons == 0) { - v->lacons = (struct subre *)MALLOC(2 * sizeof(struct subre)); + v->lacons = (struct subre *) MALLOC(2 * sizeof(struct subre)); n = 1; /* skip 0th */ v->nlacons = 2; } else { - v->lacons = (struct subre *)REALLOC(v->lacons, + v->lacons = (struct subre *) REALLOC(v->lacons, (v->nlacons+1)*sizeof(struct subre)); n = v->nlacons++; } + if (v->lacons == NULL) { ERR(REG_ESPACE); return 0; } + sub = &v->lacons[n]; sub->begin = begin; sub->end = end; @@ -2284,7 +2279,7 @@ newlacon( /* - freelacons - free lookahead-constraint subRE vector - ^ static VOID freelacons(struct subre *, int); + ^ static void freelacons(struct subre *, int); */ static void freelacons( @@ -2305,7 +2300,7 @@ freelacons( /* - rfree - free a whole RE (insides of regfree) - ^ static VOID rfree(regex_t *); + ^ static void rfree(regex_t *); */ static void rfree( @@ -2337,7 +2332,7 @@ rfree( /* - dump - dump an RE in human-readable form - ^ static VOID dump(regex_t *, FILE *); + ^ static void dump(regex_t *, FILE *); */ static void dump( @@ -2356,7 +2351,7 @@ dump( fprintf(f, "NULL guts!!!\n"); return; } - g = (struct guts *)re->re_guts; + g = (struct guts *) re->re_guts; if (g->magic != GUTSMAGIC) { fprintf(f, "bad guts magic number (0x%x not 0x%x)\n", g->magic, GUTSMAGIC); @@ -2383,7 +2378,7 @@ dump( /* - dumpst - dump a subRE tree - ^ static VOID dumpst(struct subre *, FILE *, int); + ^ static void dumpst(struct subre *, FILE *, int); */ static void dumpst( @@ -2401,7 +2396,7 @@ dumpst( /* - stdump - recursive guts of dumpst - ^ static VOID stdump(struct subre *, FILE *, int); + ^ static void stdump(struct subre *, FILE *, int); */ static void stdump( |