49#define HASH(bv, nw) (((nw) == 1) ? *(bv) : hash(bv, nw))
50#define HIT(h,bv,ss,nw) ((ss)->hash == (h) && ((nw) == 1 || \
51 memcmp(VS(bv), VS((ss)->states), (nw)*sizeof(unsigned)) == 0))
101#define DOMALLOC ((struct smalldfa *)NULL)
126#define VISERR(vv) ((vv)->err != 0)
127#define ISERR() VISERR(v)
128#define VERR(vv,e) ((vv)->err = ((vv)->err ? (vv)->err : (e)))
129#define ERR(e) VERR(v, e)
130#define NOERR() {if (ISERR()) return v->err;}
131#define OFF(p) ((p) - v->start)
132#define LOFF(p) ((long)OFF(p))
170static unsigned hash(
unsigned *
uv,
int n);
195 struct vars *v = &var;
210 if (re->re_csize !=
sizeof(
chr))
212 if (search_start >
len)
220 v->
g = (
struct guts *) re->re_guts;
247 if (nmatch > v->
g->
nsub + 1)
248 nmatch = v->
g->
nsub + 1;
275 for (
i = 0;
i < n;
i++)
288 for (
i = 0;
i < n;
i++)
297 for (
i = 0;
i < n;
i++)
334 for (
i = 0;
i < n;
i++)
345 for (
i = 0;
i < n;
i++)
465 for (begin =
open; begin <=
close; begin++)
467 MDEBUG((
"\nfind trying at %ld\n",
LOFF(begin)));
587 for (begin =
open; begin <=
close; begin++)
589 MDEBUG((
"\ncfind trying at %ld\n",
LOFF(begin)));
668 for (
i = n - 1;
i > 0;
i--)
710 if ((
size_t) n >= v->
nmatch)
858 MDEBUG((
"%d: tentative midpoint %ld\n", t->
id,
LOFF(mid)));
873 MDEBUG((
"%d: successful\n", t->
id));
888 MDEBUG((
"%d: no midpoint\n", t->
id));
896 MDEBUG((
"%d: failed midpoint\n", t->
id));
939 MDEBUG((
"%d: tentative midpoint %ld\n", t->
id,
LOFF(mid)));
954 MDEBUG((
"%d: successful\n", t->
id));
969 MDEBUG((
"%d: no midpoint\n", t->
id));
977 MDEBUG((
"%d: failed midpoint\n", t->
id));
1013 MDEBUG((
"%d: cbrdissect %d{%d-%d} %ld-%ld\n", t->
id, n, min, max,
1017 if (v->
pmatch[n].rm_so == -1)
1029 if (begin == end && min <= max)
1031 MDEBUG((
"%d: backref matched trivially\n", t->
id));
1041 MDEBUG((
"%d: backref matched trivially\n", t->
id));
1068 MDEBUG((
"%d: backref matched\n", t->
id));
1098 if (
longest(v, d, begin, end, (
int *)
NULL) == end)
1100 MDEBUG((
"%d: caltdissect matched\n", t->
id));
1209 MDEBUG((
"%d: working endpoint %d: %ld\n",
1267 MDEBUG((
"%d: successful\n", t->
id));
1307 if (t->
min == 0 && begin == end)
1309 MDEBUG((
"%d: allowing zero matches\n", t->
id));
1353 MDEBUG((
"%d: allowing zero matches\n", t->
id));
1404 if (limit ==
endpts[k - 1] &&
1427 MDEBUG((
"%d: working endpoint %d: %ld\n",
1480 MDEBUG((
"%d: successful\n", t->
id));
static void cleanup(void)
void pg_set_regex_collation(Oid collation)
static int find(struct vars *v, struct cnfa *cnfa, struct colormap *cm)
static int citerdissect(struct vars *v, struct subre *t, chr *begin, chr *end)
static void freedfa(struct dfa *d)
static chr * shortest(struct vars *v, struct dfa *d, chr *start, chr *min, chr *max, chr **coldp, int *hitstopp)
static void zapallsubs(regmatch_t *p, size_t n)
static chr * dfa_backref(struct vars *v, struct dfa *d, chr *start, chr *min, chr *max, bool shortest)
static int lacon(struct vars *v, struct cnfa *pcnfa, chr *cp, color co)
static int ccondissect(struct vars *v, struct subre *t, chr *begin, chr *end)
static int cfind(struct vars *v, struct cnfa *cnfa, struct colormap *cm)
static int creviterdissect(struct vars *v, struct subre *t, chr *begin, chr *end)
static int cfindloop(struct vars *v, struct cnfa *cnfa, struct colormap *cm, struct dfa *d, struct dfa *s, chr **coldp)
static unsigned hash(unsigned *uv, int n)
static int cbrdissect(struct vars *v, struct subre *t, chr *begin, chr *end)
static struct dfa * getladfa(struct vars *v, int n)
static chr * lastcold(struct vars *v, struct dfa *d)
static struct dfa * getsubdfa(struct vars *v, struct subre *t)
static chr * longest(struct vars *v, struct dfa *d, chr *start, chr *stop, int *hitstopp)
static struct sset * getvacant(struct vars *v, struct dfa *d, chr *cp, chr *start)
static int crevcondissect(struct vars *v, struct subre *t, chr *begin, chr *end)
static struct sset * miss(struct vars *v, struct dfa *d, struct sset *css, color co, chr *cp, chr *start)
static struct dfa * newdfa(struct vars *v, struct cnfa *cnfa, struct colormap *cm, struct smalldfa *sml)
static int cdissect(struct vars *v, struct subre *t, chr *begin, chr *end)
static void zaptreesubs(struct vars *v, struct subre *t)
static struct sset * pickss(struct vars *v, struct dfa *d, chr *cp, chr *start)
static int caltdissect(struct vars *v, struct subre *t, chr *begin, chr *end)
static void subset(struct vars *v, struct subre *sub, chr *begin, chr *end)
int pg_regexec(regex_t *re, const chr *string, size_t len, size_t search_start, rm_detail_t *details, size_t nmatch, regmatch_t pmatch[], int flags)
static int matchuntil(struct vars *v, struct dfa *d, chr *probe, struct sset **lastcss, chr **lastcp)
#define STACK_TOO_DEEP(re)
unsigned statesarea[FEWSTATES *2+WORK]
struct arcp incarea[FEWSTATES *2 *FEWCOLORS]
struct sset * outsarea[FEWSTATES *2 *FEWCOLORS]
struct sset ssets[FEWSTATES *2]