2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
5 * Copyright (c) 1992, 1993, 1994
6 * The Regents of the University of California. All rights reserved.
8 * This code is derived from software contributed to Berkeley by
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * @(#)engine.c 8.5 (Berkeley) 3/20/94
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
44 * The matching engine and friends. This file is #included by regexec.c
45 * after suitable #defines of a variety of macros used herein, so that
46 * different state representations can be used without duplicating masses
51 #define stepback sstepback
52 #define matcher smatcher
54 #define dissect sdissect
55 #define backref sbackref
62 #define stepback lstepback
63 #define matcher lmatcher
65 #define dissect ldissect
66 #define backref lbackref
73 #define stepback mstepback
74 #define matcher mmatcher
76 #define dissect mdissect
77 #define backref mbackref
84 /* another structure passed up and down to avoid zillions of parameters */
88 regmatch_t *pmatch; /* [nsub+1] (0 element unused) */
89 const char *offp; /* offsets work from here */
90 const char *beginp; /* start of string -- virtual NUL precedes */
91 const char *endp; /* end of string -- virtual NUL here */
92 const char *coldp; /* can be no match starting before here */
93 const char **lastpos; /* [nplus+1] */
95 states st; /* current states */
96 states fresh; /* states for a fresh start */
97 states tmp; /* temporary */
98 states empty; /* empty set of states */
99 mbstate_t mbs; /* multibyte conversion state */
102 /* ========= begin header generated by ./mkh ========= */
107 /* === engine.c === */
108 static int matcher(struct re_guts *g, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags);
109 static const char *dissect(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst);
110 static const char *backref(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst, sopno lev, int);
111 static const char *walk(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst, bool fast);
112 static states step(struct re_guts *g, sopno start, sopno stop, states bef, wint_t ch, states aft);
113 #define MAX_RECURSION 100
116 #define BOLEOL (BOL-2)
117 #define NOTHING (BOL-3)
120 #define BADCHAR (BOL-6)
121 #define NONCHAR(c) ((c) <= OUT)
123 static void print(struct match *m, const char *caption, states st, int ch, FILE *d);
126 static void at(struct match *m, const char *title, const char *start, const char *stop, sopno startst, sopno stopst);
129 static const char *pchar(int ch);
135 /* ========= end header generated by ./mkh ========= */
138 #define SP(t, s, c) print(m, t, s, c, stdout)
139 #define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2)
140 #define NOTE(str) { if (m->eflags®_TRACE) printf("=%s\n", (str)); }
142 #define SP(t, s, c) /* nothing */
143 #define AT(t, p1, p2, s1, s2) /* nothing */
144 #define NOTE(s) /* nothing */
148 * Given a multibyte string pointed to by start, step back nchar characters
149 * from current position pointed to by cur.
152 stepback(const char *start, const char *cur, int nchar)
160 return ((cur - nchar) > start ? cur - nchar : NULL);
163 for (wc = nchar; wc > 0; wc--) {
164 for (mbc = 1; mbc <= MB_CUR_MAX; mbc++) {
165 if ((ret - mbc) < start)
167 memset(&mbs, 0, sizeof(mbs));
168 clen = mbrtowc(NULL, ret - mbc, mbc, &mbs);
169 if (clen != (size_t)-1 && clen != (size_t)-2)
172 if (mbc > MB_CUR_MAX)
181 - matcher - the actual matching engine
182 == static int matcher(struct re_guts *g, const char *string, \
183 == size_t nmatch, regmatch_t pmatch[], int eflags);
185 static int /* 0 success, REG_NOMATCH failure */
186 matcher(struct re_guts *g,
195 struct match *m = &mv;
196 const char *dp = NULL;
197 const sopno gf = g->firststate+1; /* +1 for OEND */
198 const sopno gl = g->laststate;
201 /* Boyer-Moore algorithms variables */
204 const char *mustfirst;
205 const char *mustlast;
209 /* simplify the situation where possible */
210 if (g->cflags®_NOSUB)
212 if (eflags®_STARTEND) {
213 start = string + pmatch[0].rm_so;
214 stop = string + pmatch[0].rm_eo;
217 stop = start + strlen(start);
222 /* prescreening; this does wonders for this rather slow code */
223 if (g->must != NULL) {
224 if (g->charjump != NULL && g->matchjump != NULL) {
226 mustlast = g->must + g->mlen - 1;
227 charjump = g->charjump;
228 matchjump = g->matchjump;
230 for (dp = start+g->mlen-1; dp < stop;) {
231 /* Fast skip non-matches */
232 while (dp < stop && charjump[(int)*dp])
233 dp += charjump[(int)*dp];
239 /* We depend on not being used for
240 * for strings of length 1
242 while (*--dp == *--pp && pp != mustfirst);
247 /* Jump to next possible match */
248 mj = matchjump[pp - mustfirst];
249 cj = charjump[(int)*dp];
250 dp += (cj < mj ? mj : cj);
256 for (dp = start; dp < stop; dp++)
257 if (*dp == g->must[0] &&
258 stop - dp >= g->mlen &&
259 memcmp(dp, g->must, (size_t)g->mlen) == 0)
261 if (dp == stop) /* we didn't find g->must */
266 /* match struct setup */
282 /* Adjust start according to moffset, to speed things up */
283 if (dp != NULL && g->moffset > -1) {
286 nstart = stepback(start, dp, g->moffset);
291 SP("mloop", m->st, *start);
293 /* this loop does only one repetition except for backrefs */
295 endp = walk(m, start, stop, gf, gl, true);
296 if (endp == NULL) { /* a miss */
297 if (m->pmatch != NULL)
298 free((char *)m->pmatch);
299 if (m->lastpos != NULL)
300 free((char *)m->lastpos);
304 if (nmatch == 0 && !g->backrefs)
305 break; /* no further info needed */
308 assert(m->coldp != NULL);
310 NOTE("finding start");
311 endp = walk(m, m->coldp, stop, gf, gl, false);
314 assert(m->coldp < m->endp);
315 m->coldp += XMBRTOWC(NULL, m->coldp,
316 m->endp - m->coldp, &m->mbs, 0);
318 if (nmatch == 1 && !g->backrefs)
319 break; /* no further info needed */
321 /* oh my, he wants the subexpressions... */
322 if (m->pmatch == NULL)
323 m->pmatch = (regmatch_t *)malloc((m->g->nsub + 1) *
325 if (m->pmatch == NULL) {
329 for (i = 1; i <= m->g->nsub; i++)
330 m->pmatch[i].rm_so = m->pmatch[i].rm_eo = -1;
331 if (!g->backrefs && !(m->eflags®_BACKR)) {
333 dp = dissect(m, m->coldp, endp, gf, gl);
335 if (g->nplus > 0 && m->lastpos == NULL)
336 m->lastpos = malloc((g->nplus+1) *
337 sizeof(const char *));
338 if (g->nplus > 0 && m->lastpos == NULL) {
343 NOTE("backref dissect");
344 dp = backref(m, m->coldp, endp, gf, gl, (sopno)0, 0);
349 /* uh-oh... we couldn't find a subexpression-level match */
350 assert(g->backrefs); /* must be back references doing it */
351 assert(g->nplus == 0 || m->lastpos != NULL);
353 if (dp != NULL || endp <= m->coldp)
356 endp = walk(m, m->coldp, endp-1, gf, gl, false);
359 /* try it on a shorter possibility */
361 for (i = 1; i <= m->g->nsub; i++) {
362 assert(m->pmatch[i].rm_so == -1);
363 assert(m->pmatch[i].rm_eo == -1);
366 NOTE("backoff dissect");
367 dp = backref(m, m->coldp, endp, gf, gl, (sopno)0, 0);
369 assert(dp == NULL || dp == endp);
370 if (dp != NULL) /* found a shorter one */
373 /* despite initial appearances, there is no match here */
375 /* recycle starting later */
376 start = m->coldp + XMBRTOWC(NULL, m->coldp,
377 stop - m->coldp, &m->mbs, 0);
378 assert(start <= stop);
381 /* fill in the details if requested */
383 pmatch[0].rm_so = m->coldp - m->offp;
384 pmatch[0].rm_eo = endp - m->offp;
387 assert(m->pmatch != NULL);
388 for (i = 1; i < nmatch; i++)
390 pmatch[i] = m->pmatch[i];
392 pmatch[i].rm_so = -1;
393 pmatch[i].rm_eo = -1;
397 if (m->pmatch != NULL)
398 free((char *)m->pmatch);
399 if (m->lastpos != NULL)
400 free((char *)m->lastpos);
406 - dissect - figure out what matched what, no back references
407 == static const char *dissect(struct match *m, const char *start, \
408 == const char *stop, sopno startst, sopno stopst);
410 static const char * /* == stop (success) always */
411 dissect(struct match *m,
418 sopno ss; /* start sop of current subRE */
419 sopno es; /* end sop of current subRE */
420 const char *sp; /* start of string matched by it */
421 const char *stp; /* string matched by it cannot pass here */
422 const char *rest; /* start of rest of string */
423 const char *tail; /* string unmatched by rest of RE */
424 sopno ssub; /* start sop of subsubRE */
425 sopno esub; /* end sop of subsubRE */
426 const char *ssp; /* start of string matched by subsubRE */
427 const char *sep; /* end of string matched by subsubRE */
428 const char *oldssp; /* previous ssp */
429 const char *dp __unused;
431 AT("diss", start, stop, startst, stopst);
433 for (ss = startst; ss < stopst; ss = es) {
434 /* identify end of subRE */
436 switch (OP(m->g->strip[es])) {
439 es += OPND(m->g->strip[es]);
442 while (OP(m->g->strip[es]) != (sop)O_CH)
443 es += OPND(m->g->strip[es]);
448 /* figure out what it matched */
449 switch (OP(m->g->strip[ss])) {
454 sp += XMBRTOWC(NULL, sp, stop - start, &m->mbs, 0);
463 sp += XMBRTOWC(NULL, sp, stop - start, &m->mbs, 0);
469 /* cases where length of match is hard to find */
473 /* how long could this one be? */
474 rest = walk(m, sp, stp, ss, es, false);
475 assert(rest != NULL); /* it did match */
476 /* could the rest match the rest? */
477 tail = walk(m, rest, stop, es, stopst, false);
480 /* no -- try a shorter match for this one */
482 assert(stp >= sp); /* it did work */
486 /* did innards match? */
487 if (walk(m, sp, rest, ssub, esub, false) != NULL) {
488 dp = dissect(m, sp, rest, ssub, esub);
497 /* how long could this one be? */
498 rest = walk(m, sp, stp, ss, es, false);
499 assert(rest != NULL); /* it did match */
500 /* could the rest match the rest? */
501 tail = walk(m, rest, stop, es, stopst, false);
504 /* no -- try a shorter match for this one */
506 assert(stp >= sp); /* it did work */
512 for (;;) { /* find last match of innards */
513 sep = walk(m, ssp, rest, ssub, esub, false);
514 if (sep == NULL || sep == ssp)
515 break; /* failed or matched null */
516 oldssp = ssp; /* on to next try */
520 /* last successful match */
524 assert(sep == rest); /* must exhaust substring */
525 assert(walk(m, ssp, sep, ssub, esub, false) == rest);
526 dp = dissect(m, ssp, sep, ssub, esub);
533 /* how long could this one be? */
534 rest = walk(m, sp, stp, ss, es, false);
535 assert(rest != NULL); /* it did match */
536 /* could the rest match the rest? */
537 tail = walk(m, rest, stop, es, stopst, false);
540 /* no -- try a shorter match for this one */
542 assert(stp >= sp); /* it did work */
545 esub = ss + OPND(m->g->strip[ss]) - 1;
546 assert(OP(m->g->strip[esub]) == OOR1);
547 for (;;) { /* find first matching branch */
548 if (walk(m, sp, rest, ssub, esub, false) == rest)
549 break; /* it matched all of it */
550 /* that one missed, try next one */
551 assert(OP(m->g->strip[esub]) == OOR1);
553 assert(OP(m->g->strip[esub]) == OOR2);
555 esub += OPND(m->g->strip[esub]);
556 if (OP(m->g->strip[esub]) == (sop)OOR2)
559 assert(OP(m->g->strip[esub]) == O_CH);
561 dp = dissect(m, sp, rest, ssub, esub);
573 i = OPND(m->g->strip[ss]);
574 assert(0 < i && i <= m->g->nsub);
575 m->pmatch[i].rm_so = sp - m->offp;
578 i = OPND(m->g->strip[ss]);
579 assert(0 < i && i <= m->g->nsub);
580 m->pmatch[i].rm_eo = sp - m->offp;
593 - backref - figure out what matched what, figuring in back references
594 == static const char *backref(struct match *m, const char *start, \
595 == const char *stop, sopno startst, sopno stopst, sopno lev);
597 static const char * /* == stop (success) or NULL (failure) */
598 backref(struct match *m,
603 sopno lev, /* PLUS nesting level */
607 sopno ss; /* start sop of current subRE */
608 const char *sp; /* start of string matched by it */
609 sopno ssub; /* start sop of subsubRE */
610 sopno esub; /* end sop of subsubRE */
611 const char *ssp; /* start of string matched by subsubRE */
620 AT("back", start, stop, startst, stopst);
623 /* get as far as we can with easy stuff */
625 for (ss = startst; !hard && ss < stopst; ss++)
626 switch (OP(s = m->g->strip[ss])) {
630 sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR);
637 sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR);
644 cs = &m->g->sets[OPND(s)];
645 sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR);
646 if (wc == BADCHAR || !CHIN(cs, wc))
650 if ((sp == m->beginp && !(m->eflags®_NOTBOL)) ||
651 (sp > m->offp && sp < m->endp &&
652 *(sp-1) == '\n' && (m->g->cflags®_NEWLINE)))
658 if ( (sp == m->endp && !(m->eflags®_NOTEOL)) ||
659 (sp < m->endp && *sp == '\n' &&
660 (m->g->cflags®_NEWLINE)) )
666 if (sp < m->endp && ISWORD(*sp) &&
667 ((sp == m->beginp && !(m->eflags®_NOTBOL)) ||
668 (sp > m->offp && !ISWORD(*(sp-1)))))
674 if (( (sp == m->endp && !(m->eflags®_NOTEOL)) ||
675 (sp < m->endp && *sp == '\n' &&
676 (m->g->cflags®_NEWLINE)) ||
677 (sp < m->endp && !ISWORD(*sp)) ) &&
678 (sp > m->beginp && ISWORD(*(sp-1))) )
685 case OOR1: /* matches null but needs to skip */
689 assert(OP(s) == OOR2);
691 } while (OP(s = m->g->strip[ss]) != (sop)O_CH);
692 /* note that the ss++ gets us past the O_CH */
694 default: /* have to make a choice */
698 if (!hard) { /* that was it! */
703 ss--; /* adjust for the for's final increment */
706 AT("hard", sp, stop, ss, stopst);
709 case OBACK_: /* the vilest depths */
711 assert(0 < i && i <= m->g->nsub);
712 if (m->pmatch[i].rm_eo == -1)
714 assert(m->pmatch[i].rm_so != -1);
715 len = m->pmatch[i].rm_eo - m->pmatch[i].rm_so;
716 if (len == 0 && rec++ > MAX_RECURSION)
718 assert(stop - m->beginp >= len);
720 return(NULL); /* not enough left to match */
721 ssp = m->offp + m->pmatch[i].rm_so;
722 if (memcmp(sp, ssp, len) != 0)
724 while (m->g->strip[ss] != (sop)SOP(O_BACK, i))
726 return(backref(m, sp+len, stop, ss+1, stopst, lev, rec));
727 case OQUEST_: /* to null or not */
728 dp = backref(m, sp, stop, ss+1, stopst, lev, rec);
730 return(dp); /* not */
731 return(backref(m, sp, stop, ss+OPND(s)+1, stopst, lev, rec));
733 assert(m->lastpos != NULL);
734 assert(lev+1 <= m->g->nplus);
735 m->lastpos[lev+1] = sp;
736 return(backref(m, sp, stop, ss+1, stopst, lev+1, rec));
738 if (sp == m->lastpos[lev]) /* last pass matched null */
739 return(backref(m, sp, stop, ss+1, stopst, lev-1, rec));
740 /* try another pass */
741 m->lastpos[lev] = sp;
742 dp = backref(m, sp, stop, ss-OPND(s)+1, stopst, lev, rec);
744 return(backref(m, sp, stop, ss+1, stopst, lev-1, rec));
747 case OCH_: /* find the right one, if any */
749 esub = ss + OPND(s) - 1;
750 assert(OP(m->g->strip[esub]) == OOR1);
751 for (;;) { /* find first matching branch */
752 dp = backref(m, sp, stop, ssub, esub, lev, rec);
755 /* that one missed, try next one */
756 if (OP(m->g->strip[esub]) == (sop)O_CH)
757 return(NULL); /* there is none */
759 assert(OP(m->g->strip[esub]) == (sop)OOR2);
761 esub += OPND(m->g->strip[esub]);
762 if (OP(m->g->strip[esub]) == (sop)OOR2)
765 assert(OP(m->g->strip[esub]) == O_CH);
769 case OLPAREN: /* must undo assignment if rest fails */
771 assert(0 < i && i <= m->g->nsub);
772 offsave = m->pmatch[i].rm_so;
773 m->pmatch[i].rm_so = sp - m->offp;
774 dp = backref(m, sp, stop, ss+1, stopst, lev, rec);
777 m->pmatch[i].rm_so = offsave;
779 case ORPAREN: /* must undo assignment if rest fails */
781 assert(0 < i && i <= m->g->nsub);
782 offsave = m->pmatch[i].rm_eo;
783 m->pmatch[i].rm_eo = sp - m->offp;
784 dp = backref(m, sp, stop, ss+1, stopst, lev, rec);
787 m->pmatch[i].rm_eo = offsave;
797 return "shut up gcc";
801 - walk - step through the string either quickly or slowly
802 == static const char *walk(struct match *m, const char *start, \
803 == const char *stop, sopno startst, sopno stopst, bool fast);
805 static const char * /* where it ended, or NULL */
806 walk(struct match *m, const char *start, const char *stop, sopno startst,
807 sopno stopst, bool fast)
810 states fresh = m->fresh;
811 states empty = m->empty;
813 const char *p = start;
815 wint_t lastc; /* previous c */
818 const char *matchp; /* last p at which a match ended */
821 AT("slow", start, stop, startst, stopst);
824 SP("sstart", st, *p);
825 st = step(m->g, startst, stopst, st, NOTHING, st);
829 if (start == m->offp || (start == m->beginp && !(m->eflags®_NOTBOL)))
833 * XXX Wrong if the previous character was multi-byte.
834 * Newline never is (in encodings supported by FreeBSD),
835 * so this only breaks the ISWORD tests below.
837 c = (uch)*(start - 1);
846 clen = XMBRTOWC(&c, p, m->endp - p, &m->mbs, BADCHAR);
848 if (fast && EQ(st, fresh))
851 /* is there an EOL and/or BOL between lastc and c? */
854 if ( (lastc == '\n' && m->g->cflags®_NEWLINE) ||
855 (lastc == OUT && !(m->eflags®_NOTBOL)) ) {
859 if ( (c == '\n' && m->g->cflags®_NEWLINE) ||
860 (c == OUT && !(m->eflags®_NOTEOL)) ) {
861 flagch = (flagch == BOL) ? BOLEOL : EOL;
866 st = step(m->g, startst, stopst, st, flagch, st);
867 SP("sboleol", st, c);
870 /* how about a word boundary? */
871 if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
872 (c != OUT && ISWORD(c)) ) {
875 if ( (lastc != OUT && ISWORD(lastc)) &&
876 (flagch == EOL || (c != OUT && !ISWORD(c))) ) {
879 if (flagch == BOW || flagch == EOW) {
880 st = step(m->g, startst, stopst, st, flagch, st);
881 SP("sboweow", st, c);
885 if (ISSET(st, stopst)) {
891 if (EQ(st, empty) || p == stop || clen > (size_t)(stop - p))
892 break; /* NOTE BREAK OUT */
894 /* no, we must deal with this character */
901 st = step(m->g, startst, stopst, tmp, c, st);
903 assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
908 assert(matchp != NULL);
910 if (ISSET(st, stopst))
911 return (p + XMBRTOWC(NULL, p, stop - p, &m->mbs, 0));
919 - step - map set of states reachable before char to set reachable after
920 == static states step(struct re_guts *g, sopno start, sopno stop, \
921 == states bef, int ch, states aft);
922 == #define BOL (OUT-1)
923 == #define EOL (BOL-1)
924 == #define BOLEOL (BOL-2)
925 == #define NOTHING (BOL-3)
926 == #define BOW (BOL-4)
927 == #define EOW (BOL-5)
928 == #define BADCHAR (BOL-6)
929 == #define NONCHAR(c) ((c) <= OUT)
932 step(struct re_guts *g,
933 sopno start, /* start state within strip */
934 sopno stop, /* state after stop state within strip */
935 states bef, /* states reachable before */
936 wint_t ch, /* character or NONCHAR code */
937 states aft) /* states already known reachable after */
942 onestate here; /* note, macros know this name */
946 for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) {
950 assert(pc == stop-1);
953 /* only characters can match */
954 assert(!NONCHAR(ch) || ch != OPND(s));
959 if (ch == BOL || ch == BOLEOL)
963 if (ch == EOL || ch == BOLEOL)
979 cs = &g->sets[OPND(s)];
980 if (!NONCHAR(ch) && CHIN(cs, ch))
983 case OBACK_: /* ignored here */
987 case OPLUS_: /* forward, this is just an empty */
990 case O_PLUS: /* both forward and back */
992 i = ISSETBACK(aft, OPND(s));
993 BACK(aft, aft, OPND(s));
994 if (!i && ISSETBACK(aft, OPND(s))) {
995 /* oho, must reconsider loop body */
1000 case OQUEST_: /* two branches, both forward */
1002 FWD(aft, aft, OPND(s));
1004 case O_QUEST: /* just an empty */
1007 case OLPAREN: /* not significant here */
1011 case OCH_: /* mark the first two branches */
1013 assert(OP(g->strip[pc+OPND(s)]) == (sop)OOR2);
1014 FWD(aft, aft, OPND(s));
1016 case OOR1: /* done a branch, find the O_CH */
1017 if (ISSTATEIN(aft, here)) {
1019 OP(s = g->strip[pc+look]) != (sop)O_CH;
1021 assert(OP(s) == (sop)OOR2);
1022 FWD(aft, aft, look + 1);
1025 case OOR2: /* propagate OCH_'s marking */
1027 if (OP(g->strip[pc+OPND(s)]) != (sop)O_CH) {
1028 assert(OP(g->strip[pc+OPND(s)]) == (sop)OOR2);
1029 FWD(aft, aft, OPND(s));
1032 case O_CH: /* just empty */
1035 default: /* ooooops... */
1046 - print - print a set of states
1048 == static void print(struct match *m, const char *caption, states st, \
1049 == int ch, FILE *d);
1053 print(struct match *m,
1054 const char *caption,
1059 struct re_guts *g = m->g;
1063 if (!(m->eflags®_TRACE))
1066 fprintf(d, "%s", caption);
1068 fprintf(d, " %s", pchar(ch));
1069 for (i = 0; i < g->nstates; i++)
1071 fprintf(d, "%s%d", (first) ? "\t" : ", ", i);
1078 - at - print current situation
1080 == static void at(struct match *m, const char *title, const char *start, \
1081 == const char *stop, sopno startst, sopno stopst);
1085 at( struct match *m,
1092 if (!(m->eflags®_TRACE))
1095 printf("%s %s-", title, pchar(*start));
1096 printf("%s ", pchar(*stop));
1097 printf("%ld-%ld\n", (long)startst, (long)stopst);
1101 #define PCHARDONE /* never again */
1103 - pchar - make a character printable
1105 == static const char *pchar(int ch);
1108 * Is this identical to regchar() over in debug.c? Well, yes. But a
1109 * duplicate here avoids having a debugging-capable regexec.o tied to
1110 * a matching debug.o, and this is convenient. It all disappears in
1111 * the non-debug compilation anyway, so it doesn't matter much.
1113 static const char * /* -> representation */
1116 static char pbuf[10];
1118 if (isprint((uch)ch) || ch == ' ')
1119 sprintf(pbuf, "%c", ch);
1121 sprintf(pbuf, "\\%o", ch);