
Go to the source code of this file.
Defines | |
| #define | CISERR() VISERR(cm->v) |
| #define | CERR(e) VERR(cm->v, (e)) |
Functions | |
| static void | initcm (struct vars *v, struct colormap *cm) |
| static void | freecm (struct colormap *cm) |
| static void | cmtreefree (struct colormap *cm, union tree *tree, int level) |
| static color | setcolor (struct colormap *cm, chr c, pcolor co) |
| static color | maxcolor (struct colormap *cm) |
| static color | newcolor (struct colormap *cm) |
| static void | freecolor (struct colormap *cm, pcolor co) |
| static color | pseudocolor (struct colormap *cm) |
| static color | subcolor (struct colormap *cm, chr c) |
| static color | newsub (struct colormap *cm, pcolor co) |
| static void | subrange (struct vars *v, chr from, chr to, struct state *lp, struct state *rp) |
| static void | subblock (struct vars *v, chr start, struct state *lp, struct state *rp) |
| static void | okcolors (struct nfa *nfa, struct colormap *cm) |
| static void | colorchain (struct colormap *cm, struct arc *a) |
| static void | uncolorchain (struct colormap *cm, struct arc *a) |
| static void | rainbow (struct nfa *nfa, struct colormap *cm, int type, pcolor but, struct state *from, struct state *to) |
| static void | colorcomplement (struct nfa *nfa, struct colormap *cm, int type, struct state *of, struct state *from, struct state *to) |
Definition at line 41 of file regc_color.c.
Referenced by newcolor(), setcolor(), and subblock().
| #define CISERR | ( | ) | VISERR(cm->v) |
Definition at line 40 of file regc_color.c.
Referenced by colorcomplement(), maxcolor(), newcolor(), newsub(), pseudocolor(), rainbow(), setcolor(), and subcolor().
Definition at line 114 of file regc_color.c.
References assert, colordesc::block, BYTTAB, colormap::cd, FREE, i, NBYTS, NULL, and colormap::tree.
Referenced by freecm().
{
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--)
{
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 */
cb = cm->cd[t->tcolor[0]].block;
if (t != cb) /* not a solid block */
FREE(t);
}
}
}
}
Definition at line 616 of file regc_color.c.
References colordesc::arcs, colormap::cd, arc::co, arc::colorchain, arc::colorchainRev, and NULL.
Referenced by newarc(), and okcolors().
{
struct colordesc *cd = &cm->cd[a->co];
if (cd->arcs != NULL)
cd->arcs->colorchainRev = a;
a->colorchain = cd->arcs;
a->colorchainRev = NULL;
cd->arcs = a;
}
| static void colorcomplement | ( | struct nfa * | nfa, | |
| struct colormap * | cm, | |||
| int | type, | |||
| struct state * | of, | |||
| struct state * | from, | |||
| struct state * | to | |||
| ) | [static] |
Definition at line 681 of file regc_color.c.
References assert, colormap::cd, CDEND, CISERR, end, findarc(), colordesc::flags, newarc(), NULL, PLAIN, PSEUDO, and UNUSEDCOLOR.
| static void freecm | ( | struct colormap * | cm | ) | [static] |
Definition at line 91 of file regc_color.c.
References colordesc::block, colormap::cd, colormap::cdspace, cmtreefree(), FREE, i, colormap::magic, colormap::max, NBYTS, NULL, colormap::tree, and UNUSEDCOLOR.
Definition at line 295 of file regc_color.c.
References colordesc::arcs, assert, colordesc::block, colormap::cd, colordesc::flags, colormap::free, FREE, colormap::max, colordesc::nchrs, NOSUB, NULL, colordesc::sub, UNUSEDCOLOR, and WHITE.
Referenced by okcolors().
{
struct colordesc *cd = &cm->cd[co];
color pco,
nco; /* for freelist scan */
assert(co >= 0);
if (co == WHITE)
return;
assert(cd->arcs == NULL);
assert(cd->sub == NOSUB);
assert(cd->nchrs == 0);
cd->flags = FREECOL;
if (cd->block != NULL)
{
FREE(cd->block);
cd->block = NULL; /* just paranoia */
}
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)
cm->free = cm->cd[cm->free].sub;
if (cm->free > 0)
{
assert(cm->free < cm->max);
pco = cm->free;
nco = cm->cd[pco].sub;
while (nco > 0)
if ((size_t) nco > cm->max)
{
/* take this one out of freelist */
nco = cm->cd[nco].sub;
cm->cd[pco].sub = nco;
}
else
{
assert(nco < cm->max);
pco = nco;
nco = cm->cd[pco].sub;
}
}
}
else
{
cd->sub = cm->free;
cm->free = (color) (cd - cm->cd);
}
}
Definition at line 49 of file regc_color.c.
References colordesc::arcs, colordesc::block, BYTTAB, colormap::cd, colormap::cdspace, CHR_MAX, CHR_MIN, colordesc::firstchr, colordesc::flags, colormap::free, i, colormap::magic, colormap::max, NBYTS, colormap::ncds, colordesc::nchrs, colordesc::sub, colormap::tree, colormap::v, and WHITE.
{
int i;
int j;
union tree *t;
union tree *nextt;
struct colordesc *cd;
cm->magic = CMMAGIC;
cm->v = v;
cm->ncds = NINLINECDS;
cm->cd = cm->cdspace;
cm->max = 0;
cm->free = 0;
cd = cm->cd; /* cm->cd[WHITE] */
cd->sub = NOSUB;
cd->arcs = NULL;
cd->firstchr = CHR_MIN;
cd->nchrs = CHR_MAX - CHR_MIN + 1;
cd->flags = 0;
/* upper levels of tree */
for (t = &cm->tree[0], j = NBYTS - 1; j > 0; t = nextt, j--)
{
nextt = t + 1;
for (i = BYTTAB - 1; i >= 0; i--)
t->tptr[i] = nextt;
}
/* bottom level is solid white */
t = &cm->tree[NBYTS - 1];
for (i = BYTTAB - 1; i >= 0; i--)
t->tcolor[i] = WHITE;
cd->block = t;
}
Definition at line 210 of file regc_color.c.
References CISERR, and colormap::max.
Referenced by compact().
Definition at line 223 of file regc_color.c.
References colordesc::arcs, assert, colordesc::block, colormap::cd, colormap::cdspace, CERR, CISERR, colordesc::firstchr, colordesc::flags, colormap::free, MALLOC, colormap::max, MAX_COLOR, colormap::ncds, colordesc::nchrs, NULL, REALLOC, REG_ECOLORS, REG_ESPACE, colordesc::sub, UNUSEDCOLOR, and VS.
Referenced by newsub(), and pseudocolor().
{
struct colordesc *cd;
size_t n;
if (CISERR())
return COLORLESS;
if (cm->free != 0)
{
assert(cm->free > 0);
assert((size_t) cm->free < cm->ncds);
cd = &cm->cd[cm->free];
assert(UNUSEDCOLOR(cd));
assert(cd->arcs == NULL);
cm->free = cd->sub;
}
else if (cm->max < cm->ncds - 1)
{
cm->max++;
cd = &cm->cd[cm->max];
}
else
{
/* oops, must allocate more */
struct colordesc *newCd;
if (cm->max == MAX_COLOR)
{
CERR(REG_ECOLORS);
return COLORLESS; /* too many colors */
}
n = cm->ncds * 2;
if (n > MAX_COLOR + 1)
n = MAX_COLOR + 1;
if (cm->cd == cm->cdspace)
{
newCd = (struct colordesc *) MALLOC(n * sizeof(struct colordesc));
if (newCd != NULL)
memcpy(VS(newCd), VS(cm->cdspace), cm->ncds *
sizeof(struct colordesc));
}
else
newCd = (struct colordesc *)
REALLOC(cm->cd, n * sizeof(struct colordesc));
if (newCd == NULL)
{
CERR(REG_ESPACE);
return COLORLESS;
}
cm->cd = newCd;
cm->ncds = n;
assert(cm->max < cm->ncds - 1);
cm->max++;
cd = &cm->cd[cm->max];
}
cd->nchrs = 0;
cd->sub = NOSUB;
cd->arcs = NULL;
cd->firstchr = CHR_MIN; /* in case never set otherwise */
cd->flags = 0;
cd->block = NULL;
return (color) (cd - cm->cd);
}
Definition at line 395 of file regc_color.c.
References assert, colormap::cd, CISERR, COLORLESS, colordesc::nchrs, newcolor(), NOSUB, and colordesc::sub.
Referenced by subblock(), and subcolor().
{
color sco; /* new subcolor */
sco = cm->cd[co].sub;
if (sco == NOSUB)
{ /* color has no open subcolor */
if (cm->cd[co].nchrs == 1) /* optimization */
return co;
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 */
}
assert(sco != NOSUB);
return sco;
}
Definition at line 557 of file regc_color.c.
References colordesc::arcs, assert, colormap::cd, CDEND, arc::co, arc::colorchain, colorchain(), end, freecolor(), arc::from, colordesc::nchrs, newarc(), NOSUB, NULL, colordesc::sub, arc::to, arc::type, uncolorchain(), and UNUSEDCOLOR.
{
struct colordesc *cd;
struct colordesc *end = CDEND(cm);
struct colordesc *scd;
struct arc *a;
color co;
color sco;
for (cd = cm->cd, co = 0; cd < end; cd++, co++)
{
sco = cd->sub;
if (UNUSEDCOLOR(cd) || sco == NOSUB)
{
/* has no subcolor, no further action */
}
else if (sco == co)
{
/* is subcolor, let parent deal with it */
}
else if (cd->nchrs == 0)
{
/* parent empty, its arcs change color to subcolor */
cd->sub = NOSUB;
scd = &cm->cd[sco];
assert(scd->nchrs > 0);
assert(scd->sub == sco);
scd->sub = NOSUB;
while ((a = cd->arcs) != NULL)
{
assert(a->co == co);
uncolorchain(cm, a);
a->co = sco;
colorchain(cm, a);
}
freecolor(cm, co);
}
else
{
/* parent's arcs must gain parallel subcolor arcs */
cd->sub = NOSUB;
scd = &cm->cd[sco];
assert(scd->nchrs > 0);
assert(scd->sub == sco);
scd->sub = NOSUB;
for (a = cd->arcs; a != NULL; a = a->colorchain)
{
assert(a->co == co);
newarc(nfa, a->type, sco, a->from, a->to);
}
}
}
}
Definition at line 354 of file regc_color.c.
References colormap::cd, CISERR, colordesc::flags, colordesc::nchrs, and newcolor().
Referenced by specialcolors().
| static void rainbow | ( | struct nfa * | nfa, | |
| struct colormap * | cm, | |||
| int | type, | |||
| pcolor | but, | |||
| struct state * | from, | |||
| struct state * | to | |||
| ) | [static] |
Definition at line 658 of file regc_color.c.
References colormap::cd, CDEND, CISERR, end, colordesc::flags, newarc(), PSEUDO, colordesc::sub, and UNUSEDCOLOR.
Referenced by newnfa().
Definition at line 149 of file regc_color.c.
References assert, colordesc::block, BYTBITS, BYTMASK, BYTTAB, colormap::cd, CERR, CISERR, CMMAGIC, COLORLESS, colormap::magic, MALLOC, NBYTS, NULL, REG_ESPACE, colormap::tree, and VS.
Referenced by subcolor().
{
uchr uc = c;
int shift;
int level;
int b;
int bottom;
union tree *t;
union tree *newt;
union tree *fillt;
union tree *lastt;
union tree *cb;
color prev;
assert(cm->magic == CMMAGIC);
if (CISERR() || co == COLORLESS)
return COLORLESS;
t = cm->tree;
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];
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) ?
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));
else
memcpy(VS(newt->tptr), VS(t->tptr),
BYTTAB * sizeof(union tree *));
t = newt;
lastt->tptr[b] = t;
}
}
b = uc & BYTMASK;
prev = t->tcolor[b];
t->tcolor[b] = (color) co;
return prev;
}
Definition at line 460 of file regc_color.c.
References assert, colordesc::block, BYTBITS, BYTMASK, BYTTAB, colormap::cd, CERR, vars::cm, i, MALLOC, NBYTS, colordesc::nchrs, newarc(), newsub(), vars::nfa, NULL, PLAIN, REG_ESPACE, tcolor, colormap::tree, and VS.
Referenced by subrange().
{
uchr uc = start;
struct colormap *cm = v->cm;
int shift;
int level;
int i;
int b;
union tree *t;
union tree *cb;
union tree *fillt;
union tree *lastt;
int previ;
int ndone;
color co;
color sco;
assert((uc % BYTTAB) == 0);
/* find its color block, making new pointer blocks as needed */
t = cm->tree;
fillt = NULL;
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));
if (t == NULL)
{
CERR(REG_ESPACE);
return;
}
memcpy(VS(t->tptr), VS(fillt->tptr),
BYTTAB * sizeof(union tree *));
lastt->tptr[b] = t;
}
}
/* special cases: fill block or solid block */
co = t->tcolor[0];
cb = cm->cd[co].block;
if (t == fillt || t == cb)
{
/* either way, we want a subcolor solid block */
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)
{
CERR(REG_ESPACE);
return;
}
for (i = 0; i < BYTTAB; i++)
t->tcolor[i] = sco;
cm->cd[sco].block = t;
}
/* find loop must have run at least once */
lastt->tptr[b] = t;
newarc(v->nfa, PLAIN, sco, lp, rp);
cm->cd[co].nchrs -= BYTTAB;
cm->cd[sco].nchrs += BYTTAB;
return;
}
/* general case, a mixed block to be altered */
i = 0;
while (i < BYTTAB)
{
co = t->tcolor[i];
sco = newsub(cm, co);
newarc(v->nfa, PLAIN, sco, lp, rp);
previ = i;
do
{
t->tcolor[i++] = sco;
} while (i < BYTTAB && t->tcolor[i] == co);
ndone = i - previ;
cm->cd[co].nchrs -= ndone;
cm->cd[sco].nchrs += ndone;
}
}
Definition at line 370 of file regc_color.c.
References assert, colormap::cd, CISERR, COLORLESS, colordesc::firstchr, colordesc::nchrs, newsub(), and setcolor().
Referenced by subrange().
{
color co; /* current color of c */
color sco; /* new subcolor */
co = GETCOLOR(cm, c);
sco = newsub(cm, co);
if (CISERR())
return COLORLESS;
assert(sco != COLORLESS);
if (co == sco) /* already in an open subcolor */
return co; /* rest is redundant */
cm->cd[co].nchrs--;
if (cm->cd[sco].nchrs == 0)
cm->cd[sco].firstchr = c;
cm->cd[sco].nchrs++;
setcolor(cm, c, sco);
return sco;
}
| static void subrange | ( | struct vars * | v, | |
| chr | from, | |||
| chr | to, | |||
| struct state * | lp, | |||
| struct state * | rp | |||
| ) | [static] |
Definition at line 423 of file regc_color.c.
References assert, BYTMASK, BYTTAB, vars::cm, i, newarc(), vars::nfa, PLAIN, subblock(), and subcolor().
{
uchr uf;
int i;
assert(from <= to);
/* 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++)
newarc(v->nfa, PLAIN, subcolor(v->cm, from), lp, rp);
if (from > to) /* didn't reach a boundary */
return;
/* deal with whole blocks */
for (; to - from >= BYTTAB; from += BYTTAB)
subblock(v, from, lp, rp);
/* clean up any remaining partial table */
for (; from <= to; from++)
newarc(v->nfa, PLAIN, subcolor(v->cm, from), lp, rp);
}
Definition at line 632 of file regc_color.c.
References colordesc::arcs, assert, colormap::cd, arc::co, arc::colorchain, arc::colorchainRev, and NULL.
Referenced by freearc(), and okcolors().
{
struct colordesc *cd = &cm->cd[a->co];
struct arc *aa = a->colorchainRev;
if (aa == NULL)
{
assert(cd->arcs == a);
cd->arcs = a->colorchain;
}
else
{
assert(aa->colorchain == a);
aa->colorchain = a->colorchain;
}
if (a->colorchain != NULL)
a->colorchain->colorchainRev = aa;
a->colorchain = NULL; /* paranoia */
a->colorchainRev = NULL;
}
1.7.1