6b5e5868e7ebf1aff3a5abd7d0c4ef0e5fbf3648Garrett D'Amore * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
33f5ff17089e3a43e6e730bf80384c233123dbd9Milan Jurik * Copyright 2012 Milan Jurik. All rights reserved.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * Copyright (c) 1992, 1993, 1994 Henry Spencer.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * Copyright (c) 1992, 1993, 1994
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * The Regents of the University of California. All rights reserved.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * This code is derived from software contributed to Berkeley by
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * Henry Spencer.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * Redistribution and use in source and binary forms, with or without
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * modification, are permitted provided that the following conditions
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * 1. Redistributions of source code must retain the above copyright
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * notice, this list of conditions and the following disclaimer.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * 2. Redistributions in binary form must reproduce the above copyright
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * notice, this list of conditions and the following disclaimer in the
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * documentation and/or other materials provided with the distribution.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * 4. Neither the name of the University nor the names of its contributors
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * may be used to endorse or promote products derived from this software
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * without specific prior written permission.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * SUCH DAMAGE.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * The matching engine and friends. This file is #included by regexec.c
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * after suitable #defines of a variety of macros used herein, so that
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * different state representations can be used without duplicating masses
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore/* another structure passed up and down to avoid zillions of parameters */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore regmatch_t *pmatch; /* [nsub+1] (0 element unused) */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore const char *offp; /* offsets work from here */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore const char *beginp; /* start of string -- virtual NUL precedes */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore const char *endp; /* end of string -- virtual NUL here */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore const char *coldp; /* can be no match starting before here */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore states fresh; /* states for a fresh start */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore mbstate_t mbs; /* multibyte conversion state */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore/* ========= begin header generated by ./mkh ========= */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic int matcher(struct re_guts *, const char *, size_t, regmatch_t[], int);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic const char *dissect(struct match *, const char *, const char *,
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic const char *backref(struct match *, const char *, const char *, sopno,
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic const char *fast(struct match *, const char *, const char *, sopno,
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic const char *slow(struct match *, const char *, const char *, sopno,
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic states step(struct re_guts *, sopno, sopno, states, wint_t, states);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic void print(struct match *, const char *, states, int, FILE *);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic void at(struct match *, const char *, const char *, const char *,
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore/* ========= end header generated by ./mkh ========= */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore#define SP(t, s, c) print(m, t, s, c, stdout)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore#define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore#define NOTE(str) { if (m->eflags®_TRACE) printf("=%s\n", (str)); }
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * matcher - the actual matching engine
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic int /* 0 success, REG_NOMATCH failure */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore const sopno gf = g->firststate+1; /* +1 for OEND */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* Boyer-Moore algorithms variables */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* simplify the situation where possible */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* prescreening; this does wonders for this rather slow code */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (g->charjump != NULL && g->matchjump != NULL) {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* Fast skip non-matches */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* Greedy matcher */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * We depend on not being used for
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * for strings of length 1
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* Jump to next possible match */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (dp == stop) /* we didn't find g->must */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* match struct setup */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* Adjust start according to moffset, to speed things up */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore start = ((dp - g->moffset) < start) ? start : dp - g->moffset;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* this loop does only one repetition except for backrefs */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore break; /* no further info needed */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore break; /* no further info needed */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* oh my, he wants the subexpressions... */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore m->pmatch = (regmatch_t *)malloc((m->g->nsub + 1) *
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore m->pmatch[i].rm_so = m->pmatch[i].rm_eo = -1;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* NB: FreeBSD has REG_BACKR, we do not */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (!g->backrefs /* && !(m->eflags®_BACKR) */) {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore sizeof (const char *));
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore dp = backref(m, m->coldp, endp, gf, gl, (sopno)0, 0);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* uh-oh... we couldn't find a subexpression-level match */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore assert(g->backrefs); /* must be back references doing it */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore assert(g->nplus == 0 || m->lastpos != NULL);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore break; /* defeat */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore break; /* defeat */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* try it on a shorter possibility */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore dp = backref(m, m->coldp, endp, gf, gl, (sopno)0, 0);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* despite initial appearances, there is no match here */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* recycle starting later */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* fill in the details if requested */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (i <= m->g->nsub)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * dissect - figure out what matched what, no back references
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic const char *
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amoredissect(struct match *m, const char *start, const char *stop, sopno startst,
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore const char *sp; /* start of string matched by it */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore const char *stp; /* string matched by it cannot pass here */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore const char *rest; /* start of rest of string */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore const char *tail; /* string unmatched by rest of RE */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore const char *ssp; /* start of string matched by subsubRE */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore const char *sep; /* end of string matched by subsubRE */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* identify end of subRE */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* figure out what it matched */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore sp += XMBRTOWC(NULL, sp, stop - start, &m->mbs, 0);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore sp += XMBRTOWC(NULL, sp, stop - start, &m->mbs, 0);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* cases where length of match is hard to find */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* how long could this one be? */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* could the rest match the rest? */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore break; /* yes! */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* no -- try a shorter match for this one */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* did innards match? */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (slow(m, sp, rest, ssub, esub) != NULL) {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore } else /* no */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* how long could this one be? */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* could the rest match the rest? */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore break; /* yes! */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* no -- try a shorter match for this one */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore for (;;) { /* find last match of innards */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore break; /* failed or matched null */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* last successful match */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore assert(sep == rest); /* must exhaust substring */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore assert(slow(m, ssp, sep, ssub, esub) == rest);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* how long could this one be? */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* could the rest match the rest? */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore break; /* yes! */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* no -- try a shorter match for this one */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore for (;;) { /* find first matching branch */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore break; /* it matched all of it */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* that one missed, try next one */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore default: /* uh oh */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * backref - figure out what matched what, figuring in back references
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic const char *
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorebackref(struct match *m, const char *start, const char *stop, sopno startst,
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore sopno stopst, sopno lev, /* PLUS nesting level */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore const char *sp; /* start of string matched by it */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore const char *ssp; /* start of string matched by subsubRE */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* get as far as we can with easy stuff */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore for (ss = startst; !hard && ss < stopst; ss++)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if ((sp == m->beginp && !(m->eflags®_NOTBOL)) ||
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if ((sp == m->endp && !(m->eflags®_NOTEOL)) ||
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (((sp == m->beginp && !(m->eflags®_NOTBOL)) ||
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (((sp == m->endp && !(m->eflags®_NOTEOL)) ||
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore case OOR1: /* matches null but needs to skip */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* note that the ss++ gets us past the O_CH */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore default: /* have to make a choice */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore ss--; /* adjust for the for's final increment */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* the hard stuff */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore switch (OP(s)) {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore len = m->pmatch[i].rm_eo - m->pmatch[i].rm_so;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore return (NULL); /* not enough left to match */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore return (backref(m, sp+len, stop, ss+1, stopst, lev, rec));
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore dp = backref(m, sp, stop, ss+1, stopst, lev, rec);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore return (backref(m, sp, stop, ss+OPND(s)+1, stopst, lev, rec));
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore return (backref(m, sp, stop, ss+1, stopst, lev+1, rec));
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (sp == m->lastpos[lev]) /* last pass matched null */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore return (backref(m, sp, stop, ss+1, stopst, lev-1, rec));
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* try another pass */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore dp = backref(m, sp, stop, ss-OPND(s)+1, stopst, lev, rec);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore return (backref(m, sp, stop, ss+1, stopst, lev-1, rec));
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore for (;;) { /* find first matching branch */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore dp = backref(m, sp, stop, ssub, esub, lev, rec);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* that one missed, try next one */
33f5ff17089e3a43e6e730bf80384c233123dbd9Milan Jurik /* NOTREACHED */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore case OLPAREN: /* must undo assignment if rest fails */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore dp = backref(m, sp, stop, ss+1, stopst, lev, rec);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore case ORPAREN: /* must undo assignment if rest fails */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore dp = backref(m, sp, stop, ss+1, stopst, lev, rec);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore default: /* uh oh */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* "can't happen" */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * fast - step through the string at top speed
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic const char *
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorefast(struct match *m, const char *start, const char *stop, sopno startst,
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore const char *p = start;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore const char *coldp; /* last p after which no match was underway */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore st = step(m->g, startst, stopst, st, NOTHING, st);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * XXX Wrong if the previous character was multi-byte.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * Newline never is (in encodings supported by FreeBSD),
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * so this only breaks the ISWORD tests below.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* next character */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (p == m->endp) {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore clen = XMBRTOWC(&c, p, m->endp - p, &m->mbs, BADCHAR);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* is there an EOL and/or BOL between lastc and c? */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if ((lastc == '\n' && m->g->cflags®_NEWLINE) ||
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore (lastc == OUT && !(m->eflags®_NOTBOL))) {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if ((c == '\n' && m->g->cflags®_NEWLINE) ||
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (i != 0) {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore for (; i > 0; i--)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* how about a word boundary? */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if ((flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore (flagch == EOL || (c != OUT && !ISWORD(c)))) {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore st = step(m->g, startst, stopst, st, flagch, st);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* are we done? */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (ISSET(st, stopst) || p == stop || clen > stop - p)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore break; /* NOTE BREAK OUT */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* no, we must deal with this character */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore st = step(m->g, startst, stopst, tmp, c, st);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore return (p+XMBRTOWC(NULL, p, stop - p, &m->mbs, 0));
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * slow - step through the string more deliberately
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic const char *
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amoreslow(struct match *m, const char *start, const char *stop, sopno startst,
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore const char *p = start;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore const char *matchp; /* last p at which a match ended */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore st = step(m->g, startst, stopst, st, NOTHING, st);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * XXX Wrong if the previous character was multi-byte.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * Newline never is (in encodings supported by FreeBSD),
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * so this only breaks the ISWORD tests below.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* next character */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (p == m->endp) {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore clen = XMBRTOWC(&c, p, m->endp - p, &m->mbs, BADCHAR);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* is there an EOL and/or BOL between lastc and c? */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if ((lastc == '\n' && m->g->cflags®_NEWLINE) ||
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore (lastc == OUT && !(m->eflags®_NOTBOL))) {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if ((c == '\n' && m->g->cflags®_NEWLINE) ||
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (i != 0) {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore for (; i > 0; i--)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* how about a word boundary? */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if ((flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore (flagch == EOL || (c != OUT && !ISWORD(c)))) {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore st = step(m->g, startst, stopst, st, flagch, st);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* are we done? */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (EQ(st, empty) || p == stop || clen > stop - p)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore break; /* NOTE BREAK OUT */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* no, we must deal with this character */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore st = step(m->g, startst, stopst, tmp, c, st);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * step - map set of states reachable before char to set reachable after
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore sopno stop, /* state after stop state within strip */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore states aft) /* states already known reachable after */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore onestate here; /* note, macros know this name */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore switch (OP(s)) {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* only characters can match */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore case OPLUS_: /* forward, this is just an empty */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* oho, must reconsider loop body */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore case OQUEST_: /* two branches, both forward */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore case OCH_: /* mark the first two branches */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore case OOR1: /* done a branch, find the O_CH */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore default: /* ooooops... */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * print - print a set of states
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amoreprint(struct match *m, const char *caption, states st, int ch, FILE *d)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore struct re_guts *g = m->g;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore for (i = 0; i < g->nstates; i++)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore (void) fprintf(d, "%s%d", (first) ? "\t" : ", ", i);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * at - print current situation
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amoreat(struct match *m, const char *title, const char *start, const char *stop,
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore (void) printf("%s %s-", title, pchar(*start));
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore (void) printf("%ld-%ld\n", (long)startst, (long)stopst);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * pchar - make a character printable
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * Is this identical to regchar() over in debug.c? Well, yes. But a
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * duplicate here avoids having a debugging-capable regexec.o tied to
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * a matching debug.o, and this is convenient. It all disappears in
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * the non-debug compilation anyway, so it doesn't matter much.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic const char *