81 static void dump(
regex_t *, FILE *);
82 static void dumpst(
struct subre *, FILE *,
int);
83 static void stdump(
struct subre *, FILE *,
int);
84 static const char *stid(
struct subre *,
char *,
size_t);
120 static void dumpcolors(
struct colormap *, FILE *);
121 static void dumpchr(
chr, FILE *);
140 static int sortins_cmp(
const void *,
const void *);
164 #define INCOMPATIBLE 1 179 char *,
char *,
int);
191 static int carc_cmp(
const void *,
const void *);
196 static void dumpstate(
struct state *, FILE *);
197 static void dumparcs(
struct state *, FILE *);
198 static void dumparc(
struct arc *,
struct state *, FILE *);
199 static void dumpcnfa(
struct cnfa *, FILE *);
200 static void dumpcstate(
int,
struct cnfa *, FILE *);
233 static int cmp(
const chr *,
const chr *,
size_t);
270 #define NEXT() (next(v)) 271 #define SEE(t) (v->nexttype == (t)) 272 #define EAT(t) (SEE(t) && next(v)) 273 #define VISERR(vv) ((vv)->err != 0) 274 #define ISERR() VISERR(v) 275 #define VERR(vv,e) ((vv)->nexttype = EOS, \ 276 (vv)->err = ((vv)->err ? (vv)->err : (e))) 277 #define ERR(e) VERR(v, e) 278 #define NOERR() {if (ISERR()) return;} 279 #define NOERRN() {if (ISERR()) return NULL;} 280 #define NOERRZ() {if (ISERR()) return 0;} 281 #define INSIST(c, e) do { if (!(c)) ERR(e); } while (0) 282 #define NOTE(b) (v->re->re_info |= (b)) 283 #define EMPTYARC(x, y) newarc(v->nfa, EMPTY, 0, x, y) 310 ((a)->type == PLAIN || (a)->type == AHEAD || (a)->type == BEHIND)) 336 struct vars *v = &var;
344 FILE *debug = (FILE *) NULL;
347 #define CNOERR() { if (ISERR()) return freev(v, v->err); } 351 if (re == NULL ||
string == NULL)
371 for (j = 0; j < v->
nsubs; j++)
430 fprintf(debug,
"\n\n\n========= RAW ==========\n");
432 dumpst(v->
tree, debug, 1);
442 fprintf(debug,
"\n\n\n========= TREE FIXED ==========\n");
443 dumpst(v->
tree, debug, 1);
451 for (i = 1; i < v->
nlacons; i++)
457 fprintf(debug,
"\n\n\n========= LA%d ==========\n", i);
470 fprintf(debug,
"\n\n\n========= SEARCH ==========\n");
518 n = (size_t) wanted * 3 / 2 + 1;
591 if (a->
co != nfa->
bos[0] && a->
co != nfa->
bos[1])
630 if (b != NULL && s->
tmp == NULL)
632 s->
tmp = (slist != NULL) ? slist : s;
638 for (s = slist; s != NULL; s =
s2)
644 for (a = s->
ins; a != NULL; a = b)
653 s2 = (s->
tmp != s) ? s->
tmp : NULL;
665 static struct subre *
672 struct subre *branches;
673 struct subre *lastbranch;
675 assert(stopper ==
')' || stopper ==
EOS);
682 struct subre *branch;
692 branch =
parsebranch(v, stopper, type, left, right, 0);
697 branches->
child = branch;
710 if (lastbranch == branches->
child)
714 branches = lastbranch;
719 branches->
child = NULL;
733 static struct subre *
747 t =
subre(v,
'=', 0, left, right);
793 #define ARCV(t, val) newarc(v->nfa, t, val, lp, rp) 804 struct subre **atomp;
961 if ((
size_t) subno >= v->
nsubs)
980 atom =
parse(v,
')', type, s, s2);
987 v->
subs[subno] = atom;
988 if (atom->
capno == 0)
1079 if (m == 0 && n == 0)
1083 if (atomtype ==
'(')
1084 v->
subs[subno] = NULL;
1092 f = top->
flags | qprefer | ((atom != NULL) ? atom->
flags : 0);
1095 if (!(m == 1 && n == 1))
1113 atom =
subre(v,
'=', 0, lp, rp);
1203 atom->
min = (short) m;
1204 atom->
max = (short) n;
1209 else if (m == 1 && n == 1 &&
1250 t =
subre(v,
'.', f, s, atom->
end);
1269 t =
subre(v,
'*', f, s, s2);
1324 else if (t->
child->
op ==
'=' &&
1381 int anchor = (dir ==
AHEAD) ?
'$' :
'^';
1441 struct state *cstate;
1512 #define PAIR(x, y) ((x)*4 + (y)) 1513 #define REDUCE(x) ( ((x) == DUPINF) ? INF : (((x) > 1) ? SOME : (x)) ) 1514 const int rm =
REDUCE(m);
1515 const int rn =
REDUCE(n);
1519 switch (
PAIR(rm, rn))
1549 repeat(v, lp, s, 1, n - 1);
1569 repeat(v, lp, s, m - 1, n - 1);
1577 repeat(v, lp, s, m - 1, n);
1605 memset(have_cclassc,
false,
sizeof(have_cclassc));
1618 any_cclassc =
false;
1621 if (have_cclassc[i])
1706 onechr(v, startc, lp, rp);
1716 startc =
element(v, startp, endp);
1724 startc =
element(v, startp, endp);
1774 endc =
element(v, startp, endp);
1881 for (cd = v->
cm->
cd; cd < end; cd++)
1894 while ((a = lp->
outs) != NULL)
1913 struct state *cstate;
1948 struct state *begin,
2005 n =
newlacon(v, begin, end, latype);
2012 static struct subre *
2045 assert(strchr(
"=b|.*(", op) != NULL);
2076 if (sr->
child != NULL)
2198 for (t = v->
treechain; t != NULL; t = next)
2234 int converttosearch,
2247 fprintf(f,
"\n\n\n========= TREE NODE %s ==========\n",
2248 stid(t, idbuf,
sizeof(idbuf)));
2258 if (converttosearch && !
ISERR())
2272 struct state *begin,
2277 struct subre *newlacons;
2289 (n + 1) *
sizeof(
struct subre));
2291 if (newlacons == NULL)
2317 for (sub = subs + 1, i = n - 1; i > 0; sub++, i--)
2342 if (g->
tree != NULL)
2406 fprintf(f,
"bad guts magic number (0x%x not 0x%x)\n", g->
magic,
2409 fprintf(f,
"\n\n\n========= DUMP ==========\n");
2410 fprintf(f,
"nsub %d, info 0%lo, csize %d, ntree %d\n",
2413 dumpcolors(&g->
cmap, f);
2419 for (i = 1; i < g->
nlacons; i++)
2427 latype =
"positive lookahead";
2430 latype =
"negative lookahead";
2433 latype =
"positive lookbehind";
2436 latype =
"negative lookbehind";
2442 fprintf(f,
"\nla%d (%s):\n", i, latype);
2443 dumpcnfa(&lasub->
cnfa, f);
2446 dumpst(g->
tree, f, 0);
2453 dumpst(
struct subre *t,
2460 stdump(t, f, nfapresent);
2468 stdump(
struct subre *t,
2475 fprintf(f,
"%s. `%c'", stid(t, idbuf,
sizeof(idbuf)), t->
op);
2488 if (t->
latype != (
char) -1)
2494 if (t->
min != 1 || t->
max != 1)
2503 if (t->
child != NULL)
2504 fprintf(f,
" C:%s", stid(t->
child, idbuf,
sizeof(idbuf)));
2513 dumpcnfa(&t->
cnfa, f);
2517 stdump(t2, f, nfapresent);
2524 stid(
struct subre *t,
2529 if (bufsize <
sizeof(
void *) * 2 + 3 || bufsize <
sizeof(t->
id) * 3 + 1)
static color newcolor(struct colormap *)
static void subcolorcvec(struct vars *, struct cvec *, struct state *, struct state *)
static int scannum(struct vars *)
static int isconstraintarc(struct arc *)
static void changearcsource(struct arc *, struct state *)
static void cloneouts(struct nfa *, struct state *, struct state *, struct state *, int)
static int pg_wc_islower(pg_wchar c)
static void sortouts(struct nfa *, struct state *)
static void optst(struct vars *, struct subre *)
static void cparc(struct nfa *, struct arc *, struct state *, struct state *)
static int lexescape(struct vars *)
static int pg_wc_isgraph(pg_wchar c)
static void okcolors(struct nfa *, struct colormap *)
static void changearctarget(struct arc *, struct state *)
volatile sig_atomic_t QueryCancelPending
static void freelacons(struct subre *, int)
static int numst(struct subre *, int)
static long optimize(struct nfa *, FILE *)
static void rfree(regex_t *)
static int brenext(struct vars *, chr)
static void charclass(struct vars *, enum char_classes, struct state *, struct state *)
static chr element(struct vars *, const chr *, const chr *)
static int rcancelrequested(void)
static void bracket(struct vars *, struct state *, struct state *)
static long nfatree(struct vars *, struct subre *, FILE *)
static void brackpart(struct vars *, struct state *, struct state *, bool *)
static chr lexdigits(struct vars *, int, int, int)
static void freecm(struct colormap *)
static void nonword(struct vars *, int, struct state *, struct state *)
static void mergeins(struct nfa *, struct state *, struct arc **, int)
static int pg_wc_isspace(pg_wchar c)
static int cclass_column_index(struct colormap *, chr)
static int freev(struct vars *, int)
static void carcsort(struct carc *, size_t)
static void specialcolors(struct nfa *)
static void prefixes(struct vars *)
static void markreachable(struct nfa *, struct state *, struct state *, struct state *)
#define LATYPE_BEHIND_POS
static struct cvec * newcvec(int, int)
static struct cvec * getcvec(struct vars *, int, int)
static void colorchain(struct colormap *, struct arc *)
static struct cvec * range(struct vars *, chr, chr, int)
static void fixempties(struct nfa *, FILE *)
static int pg_wc_isword(pg_wchar c)
static struct cvec * eclass(struct vars *, chr, int)
static struct subre * subre(struct vars *, int, int, struct state *, struct state *)
static void pushfwd(struct nfa *, FILE *)
static int hasconstraintout(struct state *)
static bool check_in_colors_match(struct state *, color, color)
static struct arc * allocarc(struct nfa *)
static struct state * emptyreachable(struct nfa *, struct state *, struct state *, struct arc **)
static void onechr(struct vars *, chr, struct state *, struct state *)
static color subcolor(struct colormap *, chr)
static void parseqatom(struct vars *, int, int, struct state *, struct state *, struct subre *)
static void wordchrs(struct vars *)
static int hasnonemptyout(struct state *)
static void subcoloronechr(struct vars *, chr, struct state *, struct state *, color *)
static void makesearch(struct vars *, struct nfa *)
int pg_regcomp(regex_t *re, const chr *string, size_t len, int flags, Oid collation)
static int sortouts_cmp(const void *, const void *)
static void dupnfa(struct nfa *, struct state *, struct state *, struct state *, struct state *)
static struct state * single_color_transition(struct state *, struct state *)
static void addchr(struct cvec *, chr)
static int push(struct nfa *, struct arc *, struct state **)
static void newhicolorcols(struct colormap *)
static void freesrnode(struct vars *, struct subre *)
static void duptraverse(struct nfa *, struct state *, struct state *)
static void dumpnfa(struct nfa *, FILE *)
static int newhicolorrow(struct colormap *, int)
static void rainbow(struct nfa *, struct colormap *, int, color, struct state *, struct state *)
static void checkmatchall(struct nfa *)
static void removeconstraints(struct nfa *, struct state *, struct state *)
static void uncolorchain(struct colormap *, struct arc *)
static struct cvec * cclasscvec(struct vars *, enum char_classes, int)
static void clonesuccessorstates(struct nfa *, struct state *, struct state *, struct state *, struct arc *, char *, char *, int)
static void markst(struct subre *)
static void fixconstraintloops(struct nfa *, FILE *)
static void freesubre(struct vars *, struct subre *)
static void processlacon(struct vars *, struct state *, struct state *, int, struct state *, struct state *)
static long analyze(struct nfa *)
static int next(struct vars *)
static struct nfa * newnfa(struct vars *, struct colormap *, struct nfa *)
static int pg_wc_isupper(pg_wchar c)
static void freecolor(struct colormap *, color)
#define LATYPE_IS_AHEAD(la)
static void moveins(struct nfa *, struct state *, struct state *)
static void freesubreandsiblings(struct vars *, struct subre *)
static pg_wchar pg_wc_tolower(pg_wchar c)
static void moveouts(struct nfa *, struct state *, struct state *)
static const chr * scanplain(struct vars *)
static int findconstraintloop(struct nfa *, struct state *)
static int pg_wc_isdigit(pg_wchar c)
static struct cvec * clearcvec(struct cvec *)
static void sortins(struct nfa *, struct state *)
static struct cvec * allcases(struct vars *, chr)
static struct state * newstate(struct nfa *)
static void delsub(struct nfa *, struct state *, struct state *)
static void copyouts(struct nfa *, struct state *, struct state *)
static struct state * newfstate(struct nfa *, int flag)
static void copyins(struct nfa *, struct state *, struct state *)
#define LATYPE_BEHIND_NEG
static long nfanode(struct vars *, struct subre *, int, FILE *)
static int pg_wc_isalpha(pg_wchar c)
static color subcolorhi(struct colormap *, color *)
static void freestate(struct nfa *, struct state *)
static int pull(struct nfa *, struct arc *, struct state **)
static chr chrnamed(struct vars *, const chr *, const chr *, chr)
static bool checkmatchall_recurse(struct nfa *, struct state *, bool, int, bool *)
static struct subre * parsebranch(struct vars *, int, int, struct state *, struct state *, int)
static void cleanup(struct nfa *)
static color newsub(struct colormap *, color)
static int rstacktoodeep(void)
static void createarc(struct nfa *, int, color, struct state *, struct state *)
static void cbracket(struct vars *, struct state *, struct state *)
static void deltraverse(struct nfa *, struct state *, struct state *)
static void removetraverse(struct nfa *, struct state *)
volatile sig_atomic_t ProcDiePending
void pg_set_regex_collation(Oid collation)
static void skip(struct vars *)
static void newarc(struct nfa *, int, color, struct state *, struct state *)
static int carc_cmp(const void *, const void *)
static pg_wchar pg_wc_toupper(pg_wchar c)
static int pg_wc_isalnum(pg_wchar c)
static const struct fns functions
static void subcoloronerange(struct vars *, chr, chr, struct state *, struct state *, color *)
volatile sig_atomic_t InterruptPending
static int sortins_cmp(const void *, const void *)
static int cmp(const chr *, const chr *, size_t)
static void initcm(struct vars *, struct colormap *)
static void subcoloronerow(struct vars *, int, struct state *, struct state *, color *)
static void pullback(struct nfa *, FILE *)
static void repeat(struct vars *, struct state *, struct state *, int, int)
static void charclasscomplement(struct vars *, enum char_classes, struct state *, struct state *)
static void word(struct vars *, int, struct state *, struct state *)
static void freecvec(struct cvec *)
static void optimizebracket(struct vars *, struct state *, struct state *)
static int pg_wc_isprint(pg_wchar c)
static struct arc * findarc(struct state *, int, color)
static int before(chr, chr)
static void addrange(struct cvec *, chr, chr)
static void lexstart(struct vars *)
static int casecmp(const chr *, const chr *, size_t)
static color pseudocolor(struct colormap *)
static enum char_classes lookupcclass(struct vars *, const chr *, const chr *)
static void freearc(struct nfa *, struct arc *)
static void freenfa(struct nfa *)
static color maxcolor(struct colormap *)
static void cleanst(struct vars *)
static void dropstate(struct nfa *, struct state *)
static bool check_out_colors_match(struct state *, color, color)
static void freecnfa(struct cnfa *)
static int pg_wc_ispunct(pg_wchar c)
static void breakconstraintloop(struct nfa *, struct state *)
static void compact(struct nfa *, struct cnfa *)
static void moresubs(struct vars *, int)
static void cleartraverse(struct nfa *, struct state *)
#define STACK_TOO_DEEP(re)
static int newlacon(struct vars *, struct state *, struct state *, int)
static void markcanreach(struct nfa *, struct state *, struct state *, struct state *)
static struct subre * parse(struct vars *, int, int, struct state *, struct state *)
bool stack_is_too_deep(void)
static int combine(struct nfa *nfa, struct arc *con, struct arc *a)
static void colorcomplement(struct nfa *, struct colormap *, int, struct state *, struct state *, struct state *)