84 int converttosearch, FILE *f);
92 static void dump(
regex_t *re, FILE *f);
93 static void dumpst(
struct subre *t, FILE *f,
int nfapresent);
94 static void stdump(
struct subre *t, FILE *f,
int nfapresent);
127 color *lastsubcolor);
140 static void dumpcolors(
struct colormap *cm, FILE *f);
141 static 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);
236 static void dumpstate(
struct state *s, FILE *f);
237 static void dumparcs(
struct state *s, FILE *f);
238 static void dumparc(
struct arc *
a,
struct state *s, FILE *f);
239 static void dumpcnfa(
struct cnfa *
cnfa, FILE *f);
240 static void dumpcstate(
int st,
struct cnfa *
cnfa, FILE *f);
312 #define NEXT() (next(v))
313 #define SEE(t) (v->nexttype == (t))
314 #define EAT(t) (SEE(t) && next(v))
315 #define VISERR(vv) ((vv)->err != 0)
316 #define ISERR() VISERR(v)
317 #define VERR(vv,e) ((vv)->nexttype = EOS, \
318 (vv)->err = ((vv)->err ? (vv)->err : (e)))
319 #define ERR(e) VERR(v, e)
320 #define NOERR() {if (ISERR()) return;}
321 #define NOERRN() {if (ISERR()) return NULL;}
322 #define NOERRZ() {if (ISERR()) return 0;}
323 #define INSIST(c, e) do { if (!(c)) ERR(e); } while (0)
324 #define NOTE(b) (v->re->re_info |= (b))
325 #define EMPTYARC(x, y) newarc(v->nfa, EMPTY, 0, x, y)
352 ((a)->type == PLAIN || (a)->type == AHEAD || (a)->type == BEHIND))
377 struct vars *v = &var;
385 FILE *
debug = (FILE *) NULL;
388 #define CNOERR() { if (ISERR()) return freev(v, v->err); }
392 if (re == NULL ||
string == NULL)
428 re->re_csize =
sizeof(
chr);
429 re->re_collation = collation;
435 if (re->re_guts == NULL)
437 g = (
struct guts *) re->re_guts;
484 fprintf(
debug,
"\n\n\n========= TREE FIXED ==========\n");
527 g->
info = re->re_info;
528 g->
nsub = re->re_nsub;
560 n = (size_t) wanted * 3 / 2 + 1;
580 assert((
size_t) wanted < v->nsubs);
630 for (
a = pre->
outs;
a != NULL;
a =
a->outchain)
664 for (
a = pre->
outs;
a != NULL;
a =
a->outchain)
667 for (
b = s->
ins;
b != NULL;
b =
b->inchain)
679 if (
b != NULL && s->
tmp == NULL)
681 s->
tmp = (slist != NULL) ? slist : s;
687 for (s = slist; s != NULL; s =
s2)
693 for (
a = s->
ins;
a != NULL;
a =
b)
714 static struct subre *
721 struct subre *branches;
722 struct subre *lastbranch;
724 assert(stopper ==
')' || stopper ==
EOS);
731 struct subre *branch;
746 branches->
child = branch;
759 if (lastbranch == branches->
child)
763 branches = lastbranch;
768 branches->
child = NULL;
782 static struct subre *
796 t =
subre(v,
'=', 0, left, right);
835 static struct subre *
846 #define ARCV(t, val) newarc(v->nfa, t, val, lp, rp)
857 struct subre **atomp;
1014 if ((
size_t) subno >= v->
nsubs)
1044 if (atom->
capno == 0)
1048 atom->
capno = subno;
1060 v->
subs[subno] = atom;
1139 if (m == 0 && n == 0)
1146 if (atom != NULL && (atom->
flags &
CAP))
1164 f = top->
flags | qprefer | ((atom != NULL) ? atom->
flags : 0);
1167 if (!(m == 1 && n == 1))
1185 atom =
subre(v,
'=', 0, lp, rp);
1196 if (atom->
begin == lp || atom->
end == rp)
1293 atom->
min = (short) m;
1294 atom->
max = (short) n;
1299 else if (m == 1 && n == 1 &&
1340 t =
subre(v,
'.', f, s, atom->
end);
1412 else if (t->
child->
op ==
'=' &&
1461 int anchor = (dir ==
AHEAD) ?
'$' :
'^';
1521 struct state *cstate;
1592 #define PAIR(x, y) ((x)*4 + (y))
1593 #define REDUCE(x) ( ((x) == DUPINF) ? INF : (((x) > 1) ? SOME : (x)) )
1594 const int rm =
REDUCE(m);
1595 const int rn =
REDUCE(n);
1599 switch (
PAIR(rm, rn))
1629 repeat(v, lp, s, 1, n - 1);
1649 repeat(v, lp, s, m - 1, n - 1);
1657 repeat(v, lp, s, m - 1, n);
1685 memset(have_cclassc,
false,
sizeof(have_cclassc));
1698 any_cclassc =
false;
1701 if (have_cclassc[
i])
1786 onechr(v, startc, lp, rp);
1796 startc =
element(v, startp, endp);
1804 startc =
element(v, startp, endp);
1854 endc =
element(v, startp, endp);
1949 for (
a = lp->
outs;
a != NULL;
a =
a->outchain)
1954 cd = &v->
cm->
cd[
a->co];
1961 for (cd = v->
cm->
cd; cd < end; cd++)
1974 while ((
a = lp->
outs) != NULL)
1993 struct state *cstate;
2028 struct state *begin,
2085 n =
newlacon(v, begin, end, latype);
2092 static struct subre *
2125 assert(strchr(
"=b|.*(",
op) != NULL);
2156 if (sr->
child != NULL)
2351 int converttosearch,
2364 fprintf(f,
"\n\n\n========= TREE NODE %s ==========\n",
2365 stid(t, idbuf,
sizeof(idbuf)));
2375 if (converttosearch && !
ISERR())
2389 struct state *begin,
2394 struct subre *newlacons;
2406 (n + 1) *
sizeof(
struct subre));
2408 if (newlacons == NULL)
2434 for (sub = subs + 1,
i = n - 1;
i > 0; sub++,
i--)
2448 if (re == NULL || re->re_magic !=
REMAGIC)
2452 g = (
struct guts *) re->re_guts;
2459 if (g->
tree != NULL)
2498 fprintf(f,
"bad magic number (0x%x not 0x%x)\n", re->re_magic,
2500 if (re->re_guts == NULL)
2505 g = (
struct guts *) re->re_guts;
2507 fprintf(f,
"bad guts magic number (0x%x not 0x%x)\n", g->
magic,
2510 fprintf(f,
"\n\n\n========= DUMP ==========\n");
2511 fprintf(f,
"nsub %d, info 0%lo, csize %d, ntree %d\n",
2512 (
int) re->re_nsub, re->re_info, re->re_csize, g->
ntree);
2514 dumpcolors(&g->
cmap, f);
2528 latype =
"positive lookahead";
2531 latype =
"negative lookahead";
2534 latype =
"positive lookbehind";
2537 latype =
"negative lookbehind";
2544 dumpcnfa(&lasub->
cnfa, f);
2547 dumpst(g->
tree, f, 0);
2554 dumpst(
struct subre *t,
2561 stdump(t, f, nfapresent);
2569 stdump(
struct subre *t,
2576 fprintf(f,
"%s. `%c'", stid(t, idbuf,
sizeof(idbuf)), t->
op);
2591 if (t->
latype != (
char) -1)
2597 if (t->
min != 1 || t->
max != 1)
2606 if (t->
child != NULL)
2607 fprintf(f,
" C:%s", stid(t->
child, idbuf,
sizeof(idbuf)));
2616 dumpcnfa(&t->
cnfa, f);
2620 stdump(t2, f, nfapresent);
2627 stid(
struct subre *t,
void err(int eval, const char *fmt,...)
if(TABLE==NULL||TABLE_index==NULL)
static void const char fflush(stdout)
bool stack_is_too_deep(void)
void pg_set_regex_collation(Oid collation)
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 struct cvec * cclasscvec(struct vars *v, enum char_classes cclasscode, int cases)
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 struct state * emptyreachable(struct nfa *nfa, struct state *s, struct state *lastfound, struct arc **inarcsorig)
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 int sortins_cmp(const void *a, const void *b)
static int pg_wc_ispunct(pg_wchar c)
static void cleanup(struct nfa *nfa)
static int findconstraintloop(struct nfa *nfa, struct state *s)
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 struct cvec * range(struct vars *v, chr a, chr b, int cases)
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 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 struct arc * allocarc(struct nfa *nfa)
static struct state * single_color_transition(struct state *s1, struct state *s2)
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 struct state * newfstate(struct nfa *nfa, int flag)
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 struct nfa * newnfa(struct vars *v, struct colormap *cm, struct nfa *parent)
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 void rfree(regex_t *re)
static struct cvec * eclass(struct vars *v, chr c, int cases)
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 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 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 struct state * newstate(struct nfa *nfa)
static void delsub(struct nfa *nfa, struct state *lp, struct state *rp)
static struct cvec * clearcvec(struct cvec *cv)
static void prefixes(struct vars *v)
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 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 struct cvec * getcvec(struct vars *v, int nchrs, int nranges)
static void rainbow(struct nfa *nfa, struct colormap *cm, int type, color but, struct state *from, struct state *to)
static struct cvec * allcases(struct vars *v, chr c)
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 void changearctarget(struct arc *a, struct state *newto)
static chr element(struct vars *v, const chr *startp, const chr *endp)
static void freelacons(struct subre *subs, int n)
static struct arc * findarc(struct state *s, int type, color co)
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 struct cvec * newcvec(int nchrs, int nranges)
static int next(struct vars *v)
#define LATYPE_BEHIND_POS
#define STACK_TOO_DEEP(re)
#define LATYPE_BEHIND_NEG
#define LATYPE_IS_AHEAD(la)