Import regex from tcl 8.4.5

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/RXSPENCER@3276 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Ryan Norton
1999-08-05 01:16:56 +00:00
parent 376c9a9ab8
commit 2e792cdea3
2 changed files with 818 additions and 824 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -28,19 +28,19 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Header$
*
*/ */
/* /*
* longest - longest-preferred matching engine - longest - longest-preferred matching engine
^ static chr *longest(struct vars *, struct dfa *, chr *, chr *, int *);
*/ */
static chr * /* endpoint, or NULL */ static chr * /* endpoint, or NULL */
longest(struct vars * v, /* used only for debug and exec flags */ longest(v, d, start, stop, hitstopp)
struct dfa * d, struct vars *v; /* used only for debug and exec flags */
chr *start, /* where the match should start */ struct dfa *d;
chr *stop, /* match must end at or before here */ chr *start; /* where the match should start */
int *hitstopp) /* record whether hit v->stop, if non-NULL */ chr *stop; /* match must end at or before here */
int *hitstopp; /* record whether hit v->stop, if non-NULL */
{ {
chr *cp; chr *cp;
chr *realstop = (stop == v->stop) ? stop : stop + 1; chr *realstop = (stop == v->stop) ? stop : stop + 1;
@@ -59,13 +59,10 @@ longest(struct vars * v, /* used only for debug and exec flags */
/* startup */ /* startup */
FDEBUG(("+++ startup +++\n")); FDEBUG(("+++ startup +++\n"));
if (cp == v->start) if (cp == v->start) {
{
co = d->cnfa->bos[(v->eflags&REG_NOTBOL) ? 0 : 1]; co = d->cnfa->bos[(v->eflags&REG_NOTBOL) ? 0 : 1];
FDEBUG(("color %ld\n", (long)co)); FDEBUG(("color %ld\n", (long)co));
} } else {
else
{
co = GETCOLOR(cm, *(cp - 1)); co = GETCOLOR(cm, *(cp - 1));
FDEBUG(("char %c, color %ld\n", (char)*(cp-1), (long)co)); FDEBUG(("char %c, color %ld\n", (char)*(cp-1), (long)co));
} }
@@ -76,14 +73,12 @@ longest(struct vars * v, /* used only for debug and exec flags */
/* main loop */ /* main loop */
if (v->eflags&REG_FTRACE) if (v->eflags&REG_FTRACE)
while (cp < realstop) while (cp < realstop) {
{
FDEBUG(("+++ at c%d +++\n", css - d->ssets)); FDEBUG(("+++ at c%d +++\n", css - d->ssets));
co = GETCOLOR(cm, *cp); co = GETCOLOR(cm, *cp);
FDEBUG(("char %c, color %ld\n", (char)*cp, (long)co)); FDEBUG(("char %c, color %ld\n", (char)*cp, (long)co));
ss = css->outs[co]; ss = css->outs[co];
if (ss == NULL) if (ss == NULL) {
{
ss = miss(v, d, css, co, cp+1, start); ss = miss(v, d, css, co, cp+1, start);
if (ss == NULL) if (ss == NULL)
break; /* NOTE BREAK OUT */ break; /* NOTE BREAK OUT */
@@ -93,12 +88,10 @@ longest(struct vars * v, /* used only for debug and exec flags */
css = ss; css = ss;
} }
else else
while (cp < realstop) while (cp < realstop) {
{
co = GETCOLOR(cm, *cp); co = GETCOLOR(cm, *cp);
ss = css->outs[co]; ss = css->outs[co];
if (ss == NULL) if (ss == NULL) {
{
ss = miss(v, d, css, co, cp+1, start); ss = miss(v, d, css, co, cp+1, start);
if (ss == NULL) if (ss == NULL)
break; /* NOTE BREAK OUT */ break; /* NOTE BREAK OUT */
@@ -110,8 +103,7 @@ longest(struct vars * v, /* used only for debug and exec flags */
/* shutdown */ /* shutdown */
FDEBUG(("+++ shutdown at c%d +++\n", css - d->ssets)); FDEBUG(("+++ shutdown at c%d +++\n", css - d->ssets));
if (cp == v->stop && stop == v->stop) if (cp == v->stop && stop == v->stop) {
{
if (hitstopp != NULL) if (hitstopp != NULL)
*hitstopp = 1; *hitstopp = 1;
co = d->cnfa->eos[(v->eflags&REG_NOTEOL) ? 0 : 1]; co = d->cnfa->eos[(v->eflags&REG_NOTEOL) ? 0 : 1];
@@ -137,17 +129,19 @@ longest(struct vars * v, /* used only for debug and exec flags */
} }
/* /*
* shortest - shortest-preferred matching engine - shortest - shortest-preferred matching engine
^ static chr *shortest(struct vars *, struct dfa *, chr *, chr *, chr *,
^ chr **, int *);
*/ */
static chr * /* endpoint, or NULL */ static chr * /* endpoint, or NULL */
shortest(struct vars * v, shortest(v, d, start, min, max, coldp, hitstopp)
struct dfa * d, struct vars *v;
chr *start, /* where the match should start */ struct dfa *d;
chr *min, /* match must end at or after here */ chr *start; /* where the match should start */
chr *max, /* match must end at or before here */ chr *min; /* match must end at or after here */
chr **coldp, /* store coldstart pointer here, if chr *max; /* match must end at or before here */
* nonNULL */ chr **coldp; /* store coldstart pointer here, if nonNULL */
int *hitstopp) /* record whether hit v->stop, if non-NULL */ int *hitstopp; /* record whether hit v->stop, if non-NULL */
{ {
chr *cp; chr *cp;
chr *realmin = (min == v->stop) ? min : min + 1; chr *realmin = (min == v->stop) ? min : min + 1;
@@ -165,13 +159,10 @@ shortest(struct vars * v,
/* startup */ /* startup */
FDEBUG(("--- startup ---\n")); FDEBUG(("--- startup ---\n"));
if (cp == v->start) if (cp == v->start) {
{
co = d->cnfa->bos[(v->eflags&REG_NOTBOL) ? 0 : 1]; co = d->cnfa->bos[(v->eflags&REG_NOTBOL) ? 0 : 1];
FDEBUG(("color %ld\n", (long)co)); FDEBUG(("color %ld\n", (long)co));
} } else {
else
{
co = GETCOLOR(cm, *(cp - 1)); co = GETCOLOR(cm, *(cp - 1));
FDEBUG(("char %c, color %ld\n", (char)*(cp-1), (long)co)); FDEBUG(("char %c, color %ld\n", (char)*(cp-1), (long)co));
} }
@@ -183,14 +174,12 @@ shortest(struct vars * v,
/* main loop */ /* main loop */
if (v->eflags&REG_FTRACE) if (v->eflags&REG_FTRACE)
while (cp < realmax) while (cp < realmax) {
{
FDEBUG(("--- at c%d ---\n", css - d->ssets)); FDEBUG(("--- at c%d ---\n", css - d->ssets));
co = GETCOLOR(cm, *cp); co = GETCOLOR(cm, *cp);
FDEBUG(("char %c, color %ld\n", (char)*cp, (long)co)); FDEBUG(("char %c, color %ld\n", (char)*cp, (long)co));
ss = css->outs[co]; ss = css->outs[co];
if (ss == NULL) if (ss == NULL) {
{
ss = miss(v, d, css, co, cp+1, start); ss = miss(v, d, css, co, cp+1, start);
if (ss == NULL) if (ss == NULL)
break; /* NOTE BREAK OUT */ break; /* NOTE BREAK OUT */
@@ -202,12 +191,10 @@ shortest(struct vars * v,
break; /* NOTE BREAK OUT */ break; /* NOTE BREAK OUT */
} }
else else
while (cp < realmax) while (cp < realmax) {
{
co = GETCOLOR(cm, *cp); co = GETCOLOR(cm, *cp);
ss = css->outs[co]; ss = css->outs[co];
if (ss == NULL) if (ss == NULL) {
{
ss = miss(v, d, css, co, cp+1, start); ss = miss(v, d, css, co, cp+1, start);
if (ss == NULL) if (ss == NULL)
break; /* NOTE BREAK OUT */ break; /* NOTE BREAK OUT */
@@ -222,17 +209,13 @@ shortest(struct vars * v,
if (ss == NULL) if (ss == NULL)
return NULL; return NULL;
if (coldp != NULL) /* report last no-progress state set, if if (coldp != NULL) /* report last no-progress state set, if any */
* any */
*coldp = lastcold(v, d); *coldp = lastcold(v, d);
if ((ss->flags & POSTSTATE) && cp > min) if ((ss->flags&POSTSTATE) && cp > min) {
{
assert(cp >= realmin); assert(cp >= realmin);
cp--; cp--;
} } else if (cp == v->stop && max == v->stop) {
else if (cp == v->stop && max == v->stop)
{
co = d->cnfa->eos[(v->eflags&REG_NOTEOL) ? 0 : 1]; co = d->cnfa->eos[(v->eflags&REG_NOTEOL) ? 0 : 1];
FDEBUG(("color %ld\n", (long)co)); FDEBUG(("color %ld\n", (long)co));
ss = miss(v, d, css, co, cp, start); ss = miss(v, d, css, co, cp, start);
@@ -248,11 +231,13 @@ shortest(struct vars * v,
} }
/* /*
* lastcold - determine last point at which no progress had been made - lastcold - determine last point at which no progress had been made
^ static chr *lastcold(struct vars *, struct dfa *);
*/ */
static chr * /* endpoint, or NULL */ static chr * /* endpoint, or NULL */
lastcold(struct vars * v, lastcold(v, d)
struct dfa * d) struct vars *v;
struct dfa *d;
{ {
struct sset *ss; struct sset *ss;
chr *nopr; chr *nopr;
@@ -268,13 +253,16 @@ lastcold(struct vars * v,
} }
/* /*
* newdfa - set up a fresh DFA - newdfa - set up a fresh DFA
^ static struct dfa *newdfa(struct vars *, struct cnfa *,
^ struct colormap *, struct smalldfa *);
*/ */
static struct dfa * static struct dfa *
newdfa(struct vars * v, newdfa(v, cnfa, cm, small)
struct cnfa * cnfa, struct vars *v;
struct colormap * cm, struct cnfa *cnfa;
struct smalldfa * small) /* preallocated space, may be NULL */ struct colormap *cm;
struct smalldfa *small; /* preallocated space, may be NULL */
{ {
struct dfa *d; struct dfa *d;
size_t nss = cnfa->nstates * 2; size_t nss = cnfa->nstates * 2;
@@ -283,15 +271,12 @@ newdfa(struct vars * v,
assert(cnfa != NULL && cnfa->nstates != 0); assert(cnfa != NULL && cnfa->nstates != 0);
if (nss <= FEWSTATES && cnfa->ncolors <= FEWCOLORS) if (nss <= FEWSTATES && cnfa->ncolors <= FEWCOLORS) {
{
assert(wordsper == 1); assert(wordsper == 1);
if (small == NULL) if (small == NULL) {
{
small = (struct smalldfa *)MALLOC( small = (struct smalldfa *)MALLOC(
sizeof(struct smalldfa)); sizeof(struct smalldfa));
if (small == NULL) if (small == NULL) {
{
ERR(REG_ESPACE); ERR(REG_ESPACE);
return NULL; return NULL;
} }
@@ -304,12 +289,9 @@ newdfa(struct vars * v,
d->incarea = small->incarea; d->incarea = small->incarea;
d->cptsmalloced = 0; d->cptsmalloced = 0;
d->mallocarea = (smallwas == NULL) ? (char *)small : NULL; d->mallocarea = (smallwas == NULL) ? (char *)small : NULL;
} } else {
else
{
d = (struct dfa *)MALLOC(sizeof(struct dfa)); d = (struct dfa *)MALLOC(sizeof(struct dfa));
if (d == NULL) if (d == NULL) {
{
ERR(REG_ESPACE); ERR(REG_ESPACE);
return NULL; return NULL;
} }
@@ -324,8 +306,7 @@ newdfa(struct vars * v,
d->cptsmalloced = 1; d->cptsmalloced = 1;
d->mallocarea = (char *)d; d->mallocarea = (char *)d;
if (d->ssets == NULL || d->statesarea == NULL || if (d->ssets == NULL || d->statesarea == NULL ||
d->outsarea == NULL || d->incarea == NULL) d->outsarea == NULL || d->incarea == NULL) {
{
freedfa(d); freedfa(d);
ERR(REG_ESPACE); ERR(REG_ESPACE);
return NULL; return NULL;
@@ -349,13 +330,14 @@ newdfa(struct vars * v,
} }
/* /*
* freedfa - free a DFA - freedfa - free a DFA
^ static VOID freedfa(struct dfa *);
*/ */
static void static VOID
freedfa(struct dfa * d) freedfa(d)
{ struct dfa *d;
if (d->cptsmalloced)
{ {
if (d->cptsmalloced) {
if (d->ssets != NULL) if (d->ssets != NULL)
FREE(d->ssets); FREE(d->ssets);
if (d->statesarea != NULL) if (d->statesarea != NULL)
@@ -371,13 +353,14 @@ freedfa(struct dfa * d)
} }
/* /*
* hash - construct a hash code for a bitvector - hash - construct a hash code for a bitvector
*
* There are probably better ways, but they're more expensive. * There are probably better ways, but they're more expensive.
^ static unsigned hash(unsigned *, int);
*/ */
static unsigned static unsigned
hash(unsigned *uv, hash(uv, n)
int n) unsigned *uv;
int n;
{ {
int i; int i;
unsigned h; unsigned h;
@@ -389,12 +372,14 @@ hash(unsigned *uv,
} }
/* /*
* initialize - hand-craft a cache entry for startup, otherwise get ready - initialize - hand-craft a cache entry for startup, otherwise get ready
^ static struct sset *initialize(struct vars *, struct dfa *, chr *);
*/ */
static struct sset * static struct sset *
initialize(struct vars * v, /* used only for debug flags */ initialize(v, d, start)
struct dfa * d, struct vars *v; /* used only for debug flags */
chr *start) struct dfa *d;
chr *start;
{ {
struct sset *ss; struct sset *ss;
int i; int i;
@@ -402,8 +387,7 @@ initialize(struct vars * v, /* used only for debug flags */
/* is previous one still there? */ /* is previous one still there? */
if (d->nssused > 0 && (d->ssets[0].flags&STARTER)) if (d->nssused > 0 && (d->ssets[0].flags&STARTER))
ss = &d->ssets[0]; ss = &d->ssets[0];
else else { /* no, must (re)build it */
{ /* no, must (re)build it */
ss = getvacant(v, d, start, start); ss = getvacant(v, d, start, start);
for (i = 0; i < d->wordsper; i++) for (i = 0; i < d->wordsper; i++)
ss->states[i] = 0; ss->states[i] = 0;
@@ -423,15 +407,18 @@ initialize(struct vars * v, /* used only for debug flags */
} }
/* /*
* miss - handle a cache miss - miss - handle a cache miss
^ static struct sset *miss(struct vars *, struct dfa *, struct sset *,
^ pcolor, chr *, chr *);
*/ */
static struct sset * /* NULL if goes to empty set */ static struct sset * /* NULL if goes to empty set */
miss(struct vars * v, /* used only for debug flags */ miss(v, d, css, co, cp, start)
struct dfa * d, struct vars *v; /* used only for debug flags */
struct sset * css, struct dfa *d;
pcolor co, struct sset *css;
chr *cp, /* next chr */ pcolor co;
chr *start) /* where the attempt got started */ chr *cp; /* next chr */
chr *start; /* where the attempt got started */
{ {
struct cnfa *cnfa = d->cnfa; struct cnfa *cnfa = d->cnfa;
int i; int i;
@@ -445,8 +432,7 @@ miss(struct vars * v, /* used only for debug flags */
int sawlacons; int sawlacons;
/* for convenience, we can be called even if it might not be a miss */ /* for convenience, we can be called even if it might not be a miss */
if (css->outs[co] != NULL) if (css->outs[co] != NULL) {
{
FDEBUG(("hit\n")); FDEBUG(("hit\n"));
return css->outs[co]; return css->outs[co];
} }
@@ -461,8 +447,7 @@ miss(struct vars * v, /* used only for debug flags */
for (i = 0; i < d->nstates; i++) for (i = 0; i < d->nstates; i++)
if (ISBSET(css->states, i)) if (ISBSET(css->states, i))
for (ca = cnfa->states[i]+1; ca->co != COLORLESS; ca++) for (ca = cnfa->states[i]+1; ca->co != COLORLESS; ca++)
if (ca->co == co) if (ca->co == co) {
{
BSET(d->work, ca->to); BSET(d->work, ca->to);
gotstate = 1; gotstate = 1;
if (ca->to == cnfa->post) if (ca->to == cnfa->post)
@@ -473,14 +458,12 @@ miss(struct vars * v, /* used only for debug flags */
} }
dolacons = (gotstate) ? (cnfa->flags&HASLACONS) : 0; dolacons = (gotstate) ? (cnfa->flags&HASLACONS) : 0;
sawlacons = 0; sawlacons = 0;
while (dolacons) while (dolacons) { /* transitive closure */
{ /* transitive closure */
dolacons = 0; dolacons = 0;
for (i = 0; i < d->nstates; i++) for (i = 0; i < d->nstates; i++)
if (ISBSET(d->work, i)) if (ISBSET(d->work, i))
for (ca = cnfa->states[i]+1; ca->co != COLORLESS; for (ca = cnfa->states[i]+1; ca->co != COLORLESS;
ca++) ca++) {
{
if (ca->co <= cnfa->ncolors) if (ca->co <= cnfa->ncolors)
continue; /* NOTE CONTINUE */ continue; /* NOTE CONTINUE */
sawlacons = 1; sawlacons = 1;
@@ -503,13 +486,11 @@ miss(struct vars * v, /* used only for debug flags */
/* next, is that in the cache? */ /* next, is that in the cache? */
for (p = d->ssets, i = d->nssused; i > 0; p++, i--) for (p = d->ssets, i = d->nssused; i > 0; p++, i--)
if (HIT(h, d->work, p, d->wordsper)) if (HIT(h, d->work, p, d->wordsper)) {
{
FDEBUG(("cached c%d\n", p - d->ssets)); FDEBUG(("cached c%d\n", p - d->ssets));
break; /* NOTE BREAK OUT */ break; /* NOTE BREAK OUT */
} }
if (i == 0) if (i == 0) { /* nope, need a new cache entry */
{ /* nope, need a new cache entry */
p = getvacant(v, d, cp, start); p = getvacant(v, d, cp, start);
assert(p != css); assert(p != css);
for (i = 0; i < d->wordsper; i++) for (i = 0; i < d->wordsper; i++)
@@ -521,8 +502,7 @@ miss(struct vars * v, /* used only for debug flags */
/* lastseen to be dealt with by caller */ /* lastseen to be dealt with by caller */
} }
if (!sawlacons) if (!sawlacons) { /* lookahead conds. always cache miss */
{ /* lookahead conds. always cache miss */
FDEBUG(("c%d[%d]->c%d\n", css - d->ssets, co, p - d->ssets)); FDEBUG(("c%d[%d]->c%d\n", css - d->ssets, co, p - d->ssets));
css->outs[co] = p; css->outs[co] = p;
css->inchain[co] = p->ins; css->inchain[co] = p->ins;
@@ -533,13 +513,15 @@ miss(struct vars * v, /* used only for debug flags */
} }
/* /*
* lacon - lookahead-constraint checker for miss() - lacon - lookahead-constraint checker for miss()
^ static int lacon(struct vars *, struct cnfa *, chr *, pcolor);
*/ */
static int /* predicate: constraint satisfied? */ static int /* predicate: constraint satisfied? */
lacon(struct vars * v, lacon(v, pcnfa, cp, co)
struct cnfa * pcnfa, /* parent cnfa */ struct vars *v;
chr *cp, struct cnfa *pcnfa; /* parent cnfa */
pcolor co) /* "color" of the lookahead constraint */ chr *cp;
pcolor co; /* "color" of the lookahead constraint */
{ {
int n; int n;
struct subre *sub; struct subre *sub;
@@ -552,8 +534,7 @@ lacon(struct vars * v,
FDEBUG(("=== testing lacon %d\n", n)); FDEBUG(("=== testing lacon %d\n", n));
sub = &v->g->lacons[n]; sub = &v->g->lacons[n];
d = newdfa(v, &sub->cnfa, &v->g->cmap, &sd); d = newdfa(v, &sub->cnfa, &v->g->cmap, &sd);
if (d == NULL) if (d == NULL) {
{
ERR(REG_ESPACE); ERR(REG_ESPACE);
return 0; return 0;
} }
@@ -564,15 +545,17 @@ lacon(struct vars * v,
} }
/* /*
* getvacant - get a vacant state set - getvacant - get a vacant state set
* This routine clears out the inarcs and outarcs, but does not otherwise * This routine clears out the inarcs and outarcs, but does not otherwise
* clear the innards of the state set -- that's up to the caller. * clear the innards of the state set -- that's up to the caller.
^ static struct sset *getvacant(struct vars *, struct dfa *, chr *, chr *);
*/ */
static struct sset * static struct sset *
getvacant(struct vars * v, /* used only for debug flags */ getvacant(v, d, cp, start)
struct dfa * d, struct vars *v; /* used only for debug flags */
chr *cp, struct dfa *d;
chr *start) chr *cp;
chr *start;
{ {
int i; int i;
struct sset *ss; struct sset *ss;
@@ -586,8 +569,7 @@ getvacant(struct vars * v, /* used only for debug flags */
/* clear out its inarcs, including self-referential ones */ /* clear out its inarcs, including self-referential ones */
ap = ss->ins; ap = ss->ins;
while ((p = ap.ss) != NULL) while ((p = ap.ss) != NULL) {
{
co = ap.co; co = ap.co;
FDEBUG(("zapping c%d's %ld outarc\n", p - d->ssets, (long)co)); FDEBUG(("zapping c%d's %ld outarc\n", p - d->ssets, (long)co));
p->outs[co] = NULL; p->outs[co] = NULL;
@@ -597,8 +579,7 @@ getvacant(struct vars * v, /* used only for debug flags */
ss->ins.ss = NULL; ss->ins.ss = NULL;
/* take it off the inarc chains of the ssets reached by its outarcs */ /* take it off the inarc chains of the ssets reached by its outarcs */
for (i = 0; i < d->ncolors; i++) for (i = 0; i < d->ncolors; i++) {
{
p = ss->outs[i]; p = ss->outs[i];
assert(p != ss); /* not self-referential */ assert(p != ss); /* not self-referential */
if (p == NULL) if (p == NULL)
@@ -606,8 +587,7 @@ getvacant(struct vars * v, /* used only for debug flags */
FDEBUG(("del outarc %d from c%d's in chn\n", i, p - d->ssets)); FDEBUG(("del outarc %d from c%d's in chn\n", i, p - d->ssets));
if (p->ins.ss == ss && p->ins.co == i) if (p->ins.ss == ss && p->ins.co == i)
p->ins = ss->inchain[i]; p->ins = ss->inchain[i];
else else {
{
assert(p->ins.ss != NULL); assert(p->ins.ss != NULL);
for (ap = p->ins; ap.ss != NULL && for (ap = p->ins; ap.ss != NULL &&
!(ap.ss == ss && ap.co == i); !(ap.ss == ss && ap.co == i);
@@ -634,13 +614,15 @@ getvacant(struct vars * v, /* used only for debug flags */
} }
/* /*
* pickss - pick the next stateset to be used - pickss - pick the next stateset to be used
^ static struct sset *pickss(struct vars *, struct dfa *, chr *, chr *);
*/ */
static struct sset * static struct sset *
pickss(struct vars * v, /* used only for debug flags */ pickss(v, d, cp, start)
struct dfa * d, struct vars *v; /* used only for debug flags */
chr *cp, struct dfa *d;
chr *start) chr *cp;
chr *start;
{ {
int i; int i;
struct sset *ss; struct sset *ss;
@@ -648,8 +630,7 @@ pickss(struct vars * v, /* used only for debug flags */
chr *ancient; chr *ancient;
/* shortcut for cases where cache isn't full */ /* shortcut for cases where cache isn't full */
if (d->nssused < d->nssets) if (d->nssused < d->nssets) {
{
i = d->nssused; i = d->nssused;
d->nssused++; d->nssused++;
ss = &d->ssets[i]; ss = &d->ssets[i];
@@ -661,8 +642,7 @@ pickss(struct vars * v, /* used only for debug flags */
ss->ins.co = WHITE; /* give it some value */ ss->ins.co = WHITE; /* give it some value */
ss->outs = &d->outsarea[i * d->ncolors]; ss->outs = &d->outsarea[i * d->ncolors];
ss->inchain = &d->incarea[i * d->ncolors]; ss->inchain = &d->incarea[i * d->ncolors];
for (i = 0; i < d->ncolors; i++) for (i = 0; i < d->ncolors; i++) {
{
ss->outs[i] = NULL; ss->outs[i] = NULL;
ss->inchain[i].ss = NULL; ss->inchain[i].ss = NULL;
} }
@@ -676,16 +656,14 @@ pickss(struct vars * v, /* used only for debug flags */
ancient = start; ancient = start;
for (ss = d->search, end = &d->ssets[d->nssets]; ss < end; ss++) for (ss = d->search, end = &d->ssets[d->nssets]; ss < end; ss++)
if ((ss->lastseen == NULL || ss->lastseen < ancient) && if ((ss->lastseen == NULL || ss->lastseen < ancient) &&
!(ss->flags & LOCKED)) !(ss->flags&LOCKED)) {
{
d->search = ss + 1; d->search = ss + 1;
FDEBUG(("replacing c%d\n", ss - d->ssets)); FDEBUG(("replacing c%d\n", ss - d->ssets));
return ss; return ss;
} }
for (ss = d->ssets, end = d->search; ss < end; ss++) for (ss = d->ssets, end = d->search; ss < end; ss++)
if ((ss->lastseen == NULL || ss->lastseen < ancient) && if ((ss->lastseen == NULL || ss->lastseen < ancient) &&
!(ss->flags & LOCKED)) !(ss->flags&LOCKED)) {
{
d->search = ss + 1; d->search = ss + 1;
FDEBUG(("replacing c%d\n", ss - d->ssets)); FDEBUG(("replacing c%d\n", ss - d->ssets));
return ss; return ss;