84 int converttosearch, FILE *f);
92static void dump(
regex_t *re, FILE *f);
93static void dumpst(
struct subre *t, FILE *f,
int nfapresent);
94static void stdump(
struct subre *t, FILE *f,
int nfapresent);
127 color *lastsubcolor);
140static void dumpcolors(
struct colormap *cm, FILE *f);
141static void dumpchr(
chr c, FILE *f);
168 struct state *newState);
170 struct state *newState);
172 struct arc **arcarray,
int arccount);
174 struct state *newState);
176 struct state *newState);
194 struct state **intermediates);
197 struct state **intermediates);
199#define INCOMPATIBLE 1
206 struct state *lastfound,
207 struct arc **inarcsorig);
214 struct state *sclone,
215 struct state *spredecessor,
216 struct arc *refarc,
char *curdonemap,
217 char *outerdonemap,
int nstates);
237static void dumpstate(
struct state *s, FILE *f);
238static void dumparcs(
struct state *s, FILE *f);
239static void dumparc(
struct arc *
a,
struct state *s, FILE *f);
240static void dumpcnfa(
struct cnfa *
cnfa, FILE *f);
241static void dumpcstate(
int st,
struct cnfa *
cnfa, FILE *f);
313#define NEXT() (next(v))
314#define SEE(t) (v->nexttype == (t))
315#define EAT(t) (SEE(t) && next(v))
316#define VISERR(vv) ((vv)->err != 0)
317#define ISERR() VISERR(v)
318#define VERR(vv,e) ((vv)->nexttype = EOS, \
319 (vv)->err = ((vv)->err ? (vv)->err : (e)))
320#define ERR(e) VERR(v, e)
321#define NOERR() {if (ISERR()) return;}
322#define NOERRN() {if (ISERR()) return NULL;}
323#define NOERRZ() {if (ISERR()) return 0;}
324#define INSIST(c, e) do { if (!(c)) ERR(e); } while (0)
325#define NOTE(b) (v->re->re_info |= (b))
326#define EMPTYARC(x, y) newarc(v->nfa, EMPTY, 0, x, y)
354 ((a)->type == PLAIN || (a)->type == AHEAD || (a)->type == BEHIND))
379 struct vars *v = &var;
387 FILE *
debug = (FILE *) NULL;
390#define CNOERR() { if (ISERR()) return freev(v, v->err); }
394 if (re == NULL ||
string == NULL)
430 re->re_csize =
sizeof(
chr);
431 re->re_collation = collation;
437 if (re->re_guts == NULL)
439 g = (
struct guts *) re->re_guts;
486 fprintf(
debug,
"\n\n\n========= TREE FIXED ==========\n");
529 g->
info = re->re_info;
530 g->
nsub = re->re_nsub;
562 n = (size_t) wanted * 3 / 2 + 1;
582 assert((
size_t) wanted < v->nsubs);
632 for (
a = pre->
outs;
a != NULL;
a =
a->outchain)
666 for (
a = pre->
outs;
a != NULL;
a =
a->outchain)
669 for (
b = s->
ins;
b != NULL;
b =
b->inchain)
681 if (
b != NULL && s->
tmp == NULL)
683 s->
tmp = (slist != NULL) ? slist : s;
689 for (s = slist; s != NULL; s =
s2)
695 for (
a = s->
ins;
a != NULL;
a =
b)
723 struct subre *branches;
724 struct subre *lastbranch;
726 assert(stopper ==
')' || stopper ==
EOS);
733 struct subre *branch;
748 branches->
child = branch;
761 if (lastbranch == branches->
child)
765 branches = lastbranch;
770 branches->
child = NULL;
798 t =
subre(v,
'=', 0, left, right);
848#define ARCV(t, val) newarc(v->nfa, t, val, lp, rp)
859 struct subre **atomp;
1016 if ((
size_t) subno >= v->
nsubs)
1046 if (atom->
capno == 0)
1050 atom->
capno = subno;
1062 v->
subs[subno] = atom;
1141 if (m == 0 && n == 0)
1148 if (atom != NULL && (atom->
flags &
CAP))
1166 f = top->
flags | qprefer | ((atom != NULL) ? atom->
flags : 0);
1169 if (!(m == 1 && n == 1))
1187 atom =
subre(v,
'=', 0, lp, rp);
1198 if (atom->
begin == lp || atom->
end == rp)
1295 atom->
min = (short) m;
1296 atom->
max = (short) n;
1301 else if (m == 1 && n == 1 &&
1342 t =
subre(v,
'.', f, s, atom->
end);
1414 else if (t->
child->
op ==
'=' &&
1463 int anchor = (dir ==
AHEAD) ?
'$' :
'^';
1523 struct state *cstate;
1594#define PAIR(x, y) ((x)*4 + (y))
1595#define REDUCE(x) ( ((x) == DUPINF) ? INF : (((x) > 1) ? SOME : (x)) )
1596 const int rm =
REDUCE(m);
1597 const int rn =
REDUCE(n);
1601 switch (
PAIR(rm, rn))
1631 repeat(v, lp, s, 1, n - 1);
1651 repeat(v, lp, s, m - 1, n - 1);
1659 repeat(v, lp, s, m - 1, n);
1687 memset(have_cclassc,
false,
sizeof(have_cclassc));
1700 any_cclassc =
false;
1703 if (have_cclassc[
i])
1788 onechr(v, startc, lp, rp);
1798 startc =
element(v, startp, endp);
1806 startc =
element(v, startp, endp);
1856 endc =
element(v, startp, endp);
1951 for (
a = lp->
outs;
a != NULL;
a =
a->outchain)
1956 cd = &v->
cm->
cd[
a->co];
1963 for (cd = v->
cm->
cd; cd < end; cd++)
1966 cd->
flags &= ~COLMARK;
1976 while ((
a = lp->
outs) != NULL)
1995 struct state *cstate;
2030 struct state *begin,
2087 n =
newlacon(v, begin, end, latype);
2094static struct subre *
2127 assert(strchr(
"=b|.*(",
op) != NULL);
2158 if (sr->
child != NULL)
2353 int converttosearch,
2366 fprintf(f,
"\n\n\n========= TREE NODE %s ==========\n",
2367 stid(t, idbuf,
sizeof(idbuf)));
2378 if (converttosearch && !
ISERR())
2392 struct state *begin,
2397 struct subre *newlacons;
2409 (n + 1) *
sizeof(
struct subre));
2411 if (newlacons == NULL)
2437 for (sub = subs + 1,
i = n - 1;
i > 0; sub++,
i--)
2451 if (re == NULL || re->re_magic !=
REMAGIC)
2455 g = (
struct guts *) re->re_guts;
2462 if (g->
tree != NULL)
2501 fprintf(f,
"bad magic number (0x%x not 0x%x)\n", re->re_magic,
2503 if (re->re_guts == NULL)
2508 g = (
struct guts *) re->re_guts;
2510 fprintf(f,
"bad guts magic number (0x%x not 0x%x)\n", g->
magic,
2513 fprintf(f,
"\n\n\n========= DUMP ==========\n");
2514 fprintf(f,
"nsub %d, info 0%lo, csize %d, ntree %d\n",
2515 (
int) re->re_nsub, re->re_info, re->re_csize, g->
ntree);
2517 dumpcolors(&g->
cmap, f);
2531 latype =
"positive lookahead";
2534 latype =
"negative lookahead";
2537 latype =
"positive lookbehind";
2540 latype =
"negative lookbehind";
2547 dumpcnfa(&lasub->
cnfa, f);
2550 dumpst(g->
tree, f, 0);
2557dumpst(
struct subre *t,
2564 stdump(t, f, nfapresent);
2572stdump(
struct subre *t,
2579 fprintf(f,
"%s. `%c'", stid(t, idbuf,
sizeof(idbuf)), t->
op);
2594 if (t->
latype != (
char) -1)
2600 if (t->
min != 1 || t->
max != 1)
2609 if (t->
child != NULL)
2610 fprintf(f,
" C:%s", stid(t->
child, idbuf,
sizeof(idbuf)));
2619 dumpcnfa(&t->
cnfa, f);
2623 stdump(t2, f, nfapresent);
2630stid(
struct subre *t,
#define fprintf(file, fmt, msg)
void err(int eval, const char *fmt,...)
if(TABLE==NULL||TABLE_index==NULL)
static void const char fflush(stdout)
void pg_set_regex_collation(Oid collation)
static struct state * emptyreachable(struct nfa *nfa, struct state *s, struct state *lastfound, struct arc **inarcsorig)
static void freecvec(struct cvec *cv)
static void mergeins(struct nfa *nfa, struct state *s, struct arc **arcarray, int arccount)
static void subcoloronechr(struct vars *v, chr ch, struct state *lp, struct state *rp, color *lastsubcolor)
static int newhicolorrow(struct colormap *cm, int oldrow)
static int pg_wc_islower(pg_wchar c)
static int pg_wc_isword(pg_wchar c)
static void cleartraverse(struct nfa *nfa, struct state *s)
static void cparc(struct nfa *nfa, struct arc *oa, struct state *from, struct state *to)
static void subcolorcvec(struct vars *v, struct cvec *cv, struct state *lp, struct state *rp)
static void clonesuccessorstates(struct nfa *nfa, struct state *ssource, struct state *sclone, struct state *spredecessor, struct arc *refarc, char *curdonemap, char *outerdonemap, int nstates)
static int pg_wc_isspace(pg_wchar c)
static pg_wchar pg_wc_tolower(pg_wchar c)
static int combine(struct nfa *nfa, struct arc *con, struct arc *a)
static void freecolor(struct colormap *cm, color co)
static void copyouts(struct nfa *nfa, struct state *oldState, struct state *newState)
static void wordchrs(struct vars *v)
static struct arc * findarc(struct state *s, int type, color co)
static int sortins_cmp(const void *a, const void *b)
static int pg_wc_ispunct(pg_wchar c)
static void cleanup(struct nfa *nfa)
static struct cvec * newcvec(int nchrs, int nranges)
static int findconstraintloop(struct nfa *nfa, struct state *s)
static struct arc * allocarc(struct nfa *nfa)
static void compact(struct nfa *nfa, struct cnfa *cnfa)
static int pg_wc_isgraph(pg_wchar c)
static void specialcolors(struct nfa *nfa)
static void freesubreandsiblings(struct vars *v, struct subre *sr)
static void dupnfa(struct nfa *nfa, struct state *start, struct state *stop, struct state *from, struct state *to)
static long analyze(struct nfa *nfa)
static void duptraverse(struct nfa *nfa, struct state *s, struct state *stmp)
static void freesubre(struct vars *v, struct subre *sr)
static void newarc(struct nfa *nfa, int t, color co, struct state *from, struct state *to)
static void repeat(struct vars *v, struct state *lp, struct state *rp, int m, int n)
static int lexescape(struct vars *v)
static pg_wchar pg_wc_toupper(pg_wchar c)
static void makesearch(struct vars *v, struct nfa *nfa)
static void moresubs(struct vars *v, int wanted)
static int casecmp(const chr *x, const chr *y, size_t len)
static bool checkmatchall_recurse(struct nfa *nfa, struct state *s, bool **haspaths)
static const struct fns functions
static void newhicolorcols(struct colormap *cm)
static struct subre * parsebranch(struct vars *v, int stopper, int type, struct state *left, struct state *right, int partial)
static void freenfa(struct nfa *nfa)
static struct state * single_color_transition(struct state *s1, struct state *s2)
static struct nfa * newnfa(struct vars *v, struct colormap *cm, struct nfa *parent)
static void optimizebracket(struct vars *v, struct state *lp, struct state *rp)
static int pg_wc_isprint(pg_wchar c)
static void createarc(struct nfa *nfa, int t, color co, struct state *from, struct state *to)
static int isconstraintarc(struct arc *a)
static int pg_wc_isalnum(pg_wchar c)
static int rstacktoodeep(void)
static void fixempties(struct nfa *nfa, FILE *f)
static int pg_wc_isdigit(pg_wchar c)
static void skip(struct vars *v)
int pg_regcomp(regex_t *re, const chr *string, size_t len, int flags, Oid collation)
static enum char_classes lookupcclass(struct vars *v, const chr *startp, const chr *endp)
static void cleanst(struct vars *v)
static void copyins(struct nfa *nfa, struct state *oldState, struct state *newState)
static int push(struct nfa *nfa, struct arc *con, struct state **intermediates)
static color newcolor(struct colormap *cm)
static void moveouts(struct nfa *nfa, struct state *oldState, struct state *newState)
static chr lexdigits(struct vars *v, int base, int minlen, int maxlen)
static int hasconstraintout(struct state *s)
static void freearc(struct nfa *nfa, struct arc *victim)
static void checkmatchall(struct nfa *nfa)
static void addchr(struct cvec *cv, chr c)
static color subcolorhi(struct colormap *cm, color *pco)
static void colorchain(struct colormap *cm, struct arc *a)
static int scannum(struct vars *v)
static void sortins(struct nfa *nfa, struct state *s)
static void cloneouts(struct nfa *nfa, struct state *old, struct state *from, struct state *to, int type)
static int carc_cmp(const void *a, const void *b)
static struct subre * parseqatom(struct vars *v, int stopper, int type, struct state *lp, struct state *rp, struct subre *top)
static void freecm(struct colormap *cm)
static long optimize(struct nfa *nfa, FILE *f)
static void uncolorchain(struct colormap *cm, struct arc *a)
static struct cvec * eclass(struct vars *v, chr c, int cases)
static struct state * newfstate(struct nfa *nfa, int flag)
static void rfree(regex_t *re)
static void removecantmatch(struct nfa *nfa)
static void sortouts(struct nfa *nfa, struct state *s)
static const chr * scanplain(struct vars *v)
static void deltraverse(struct nfa *nfa, struct state *leftend, struct state *s)
static void dropstate(struct nfa *nfa, struct state *s)
static void okcolors(struct nfa *nfa, struct colormap *cm)
static void addrange(struct cvec *cv, chr from, chr to)
static color maxcolor(struct colormap *cm)
static void initcm(struct vars *v, struct colormap *cm)
static void removetraverse(struct nfa *nfa, struct state *s)
static void charclass(struct vars *v, enum char_classes cls, struct state *lp, struct state *rp)
static struct cvec * clearcvec(struct cvec *cv)
static void bracket(struct vars *v, struct state *lp, struct state *rp)
static void cbracket(struct vars *v, struct state *lp, struct state *rp)
static void pushfwd(struct nfa *nfa, FILE *f)
static color pseudocolor(struct colormap *cm)
static int cmp(const chr *x, const chr *y, size_t len)
static struct cvec * cclasscvec(struct vars *v, enum char_classes cclasscode, int cases)
static struct subre * subre(struct vars *v, int op, int flags, struct state *begin, struct state *end)
static int hasnonemptyout(struct state *s)
static long nfanode(struct vars *v, struct subre *t, int converttosearch, FILE *f)
static void freesrnode(struct vars *v, struct subre *sr)
static void pullback(struct nfa *nfa, FILE *f)
static void markcanreach(struct nfa *nfa, struct state *s, struct state *okay, struct state *mark)
static void removecaptures(struct vars *v, struct subre *t)
static int brenext(struct vars *v, chr c)
static void lexstart(struct vars *v)
static void nonword(struct vars *v, int dir, struct state *lp, struct state *rp)
static void delsub(struct nfa *nfa, struct state *lp, struct state *rp)
static void prefixes(struct vars *v)
static struct cvec * getcvec(struct vars *v, int nchrs, int nranges)
static void moveins(struct nfa *nfa, struct state *oldState, struct state *newState)
static bool check_in_colors_match(struct state *s, color co1, color co2)
static void removeconstraints(struct nfa *nfa, struct state *start, struct state *stop)
static void charclasscomplement(struct vars *v, enum char_classes cls, struct state *lp, struct state *rp)
static struct state * newstate(struct nfa *nfa)
static struct subre * parse(struct vars *v, int stopper, int type, struct state *init, struct state *final)
static int sortouts_cmp(const void *a, const void *b)
static int newlacon(struct vars *v, struct state *begin, struct state *end, int latype)
static color subcolor(struct colormap *cm, chr c)
static void rainbow(struct nfa *nfa, struct colormap *cm, int type, color 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)
static void carcsort(struct carc *first, size_t n)
static int pull(struct nfa *nfa, struct arc *con, struct state **intermediates)
static void subcoloronerange(struct vars *v, chr from, chr to, struct state *lp, struct state *rp, color *lastsubcolor)
static struct cvec * range(struct vars *v, chr a, chr b, int cases)
static void changearctarget(struct arc *a, struct state *newto)
static chr element(struct vars *v, const chr *startp, const chr *endp)
static struct cvec * allcases(struct vars *v, chr c)
static void freelacons(struct subre *subs, int n)
static void processlacon(struct vars *v, struct state *begin, struct state *end, int latype, struct state *lp, struct state *rp)
static void changearcsource(struct arc *a, struct state *newfrom)
static void subcoloronerow(struct vars *v, int rownum, struct state *lp, struct state *rp, color *lastsubcolor)
static void freestate(struct nfa *nfa, struct state *s)
static void dumpnfa(struct nfa *nfa, FILE *f)
static void brackpart(struct vars *v, struct state *lp, struct state *rp, bool *have_cclassc)
static void markreachable(struct nfa *nfa, struct state *s, struct state *okay, struct state *mark)
static int before(chr x, chr y)
static chr chrnamed(struct vars *v, const chr *startp, const chr *endp, chr lastresort)
static void onechr(struct vars *v, chr c, struct state *lp, struct state *rp)
static int numst(struct subre *t, int start)
static void word(struct vars *v, int dir, struct state *lp, struct state *rp)
static void fixconstraintloops(struct nfa *nfa, FILE *f)
static int freev(struct vars *v, int err)
static long nfatree(struct vars *v, struct subre *t, FILE *f)
static int pg_wc_isupper(pg_wchar c)
static bool check_out_colors_match(struct state *s, color co1, color co2)
static void breakconstraintloop(struct nfa *nfa, struct state *sinitial)
static int pg_wc_isalpha(pg_wchar c)
static void markst(struct subre *t)
static int cclass_column_index(struct colormap *cm, chr c)
static void freecnfa(struct cnfa *cnfa)
static color newsub(struct colormap *cm, color co)
static int next(struct vars *v)
#define LATYPE_BEHIND_POS
#define STACK_TOO_DEEP(re)
#define LATYPE_BEHIND_NEG
#define LATYPE_IS_AHEAD(la)
bool stack_is_too_deep(void)