2 * Copyright (c) 1992, 1993, 1994 Henry Spencer.
3 * Copyright (c) 1992, 1993, 1994
4 * The Regents of the University of California. All rights reserved.
6 * This code is derived from software contributed to Berkeley by
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * @(#)engine.c 8.5 (Berkeley) 3/20/94
39 * $FreeBSD: src/lib/libc/regex/engine.c,v 1.5.8.1 2000/07/31 06:30:37 dcs Exp $
40 * $DragonFly: src/lib/libc/regex/engine.c,v 1.6 2005/01/08 19:17:01 dillon Exp $
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 matcher smatcher
54 #define dissect sdissect
55 #define backref sbackref
62 #define matcher lmatcher
65 #define dissect ldissect
66 #define backref lbackref
73 /* another structure passed up and down to avoid zillions of parameters */
77 regmatch_t *pmatch; /* [nsub+1] (0 element unused) */
78 char *offp; /* offsets work from here */
79 char *beginp; /* start of string -- virtual NUL precedes */
80 char *endp; /* end of string -- virtual NUL here */
81 char *coldp; /* can be no match starting before here */
82 char **lastpos; /* [nplus+1] */
84 states st; /* current states */
85 states fresh; /* states for a fresh start */
86 states tmp; /* temporary */
87 states empty; /* empty set of states */
90 /* ========= begin header generated by ./mkh ========= */
95 /* === engine.c === */
96 static int matcher(struct re_guts *g, char *string, size_t nmatch, regmatch_t pmatch[], int eflags);
97 static char *dissect(struct match *m, char *start, char *stop, sopno startst, sopno stopst);
98 static char *backref(struct match *m, char *start, char *stop, sopno startst, sopno stopst, sopno lev);
99 static char *fast(struct match *m, char *start, char *stop, sopno startst, sopno stopst);
100 static char *slow(struct match *m, char *start, char *stop, sopno startst, sopno stopst);
101 static states step(struct re_guts *g, sopno start, sopno stop, states bef, int ch, states aft);
104 #define BOLEOL (BOL+2)
105 #define NOTHING (BOL+3)
108 #define CODEMAX (BOL+5) /* highest code used */
109 #define NONCHAR(c) ((c) > CHAR_MAX)
110 #define NNONCHAR (CODEMAX-CHAR_MAX)
112 static void print(struct match *m, char *caption, states st, int ch, FILE *d);
115 static void at(struct match *m, char *title, char *start, char *stop, sopno startst, sopno stopst);
118 static char *pchar(int ch);
124 /* ========= end header generated by ./mkh ========= */
127 #define SP(t, s, c) print(m, t, s, c, stdout)
128 #define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2)
129 #define NOTE(str) { if (m->eflags®_TRACE) printf("=%s\n", (str)); }
131 #define SP(t, s, c) /* nothing */
132 #define AT(t, p1, p2, s1, s2) /* nothing */
133 #define NOTE(s) /* nothing */
137 - matcher - the actual matching engine
138 == static int matcher(struct re_guts *g, char *string, \
139 == size_t nmatch, regmatch_t pmatch[], int eflags);
141 static int /* 0 success, REG_NOMATCH failure */
142 matcher(struct re_guts *g, char *string, size_t nmatch, regmatch_t pmatch[],
148 struct match *m = &mv;
150 const sopno gf = g->firststate+1; /* +1 for OEND */
151 const sopno gl = g->laststate;
154 /* Boyer-Moore algorithms variables */
162 /* simplify the situation where possible */
163 if (g->cflags®_NOSUB)
165 if (eflags®_STARTEND) {
166 start = string + pmatch[0].rm_so;
167 stop = string + pmatch[0].rm_eo;
170 stop = start + strlen(start);
175 /* prescreening; this does wonders for this rather slow code */
176 if (g->must != NULL) {
177 if (g->charjump != NULL && g->matchjump != NULL) {
179 mustlast = g->must + g->mlen - 1;
180 charjump = g->charjump;
181 matchjump = g->matchjump;
183 for (dp = start+g->mlen-1; dp < stop;) {
184 /* Fast skip non-matches */
185 while (dp < stop && charjump[*dp])
192 /* We depend on not being used for
193 * for strings of length 1
195 while (*--dp == *--pp && pp != mustfirst);
200 /* Jump to next possible match */
201 mj = matchjump[pp - mustfirst];
203 dp += (cj < mj ? mj : cj);
209 for (dp = start; dp < stop; dp++)
210 if (*dp == g->must[0] &&
211 stop - dp >= g->mlen &&
212 memcmp(dp, g->must, (size_t)g->mlen) == 0)
214 if (dp == stop) /* we didn't find g->must */
219 /* match struct setup */
234 /* Adjust start according to moffset, to speed things up */
236 start = ((dp - g->moffset) < start) ? start : dp - g->moffset;
238 /* this loop does only one repetition except for backrefs */
240 endp = fast(m, start, stop, gf, gl);
241 if (endp == NULL) { /* a miss */
242 if (m->pmatch != NULL)
243 free((char *)m->pmatch);
244 if (m->lastpos != NULL)
245 free((char *)m->lastpos);
249 if (nmatch == 0 && !g->backrefs)
250 break; /* no further info needed */
253 assert(m->coldp != NULL);
255 NOTE("finding start");
256 endp = slow(m, m->coldp, stop, gf, gl);
259 assert(m->coldp < m->endp);
262 if (nmatch == 1 && !g->backrefs)
263 break; /* no further info needed */
265 /* oh my, he wants the subexpressions... */
266 if (m->pmatch == NULL)
267 m->pmatch = (regmatch_t *)malloc((m->g->nsub + 1) *
269 if (m->pmatch == NULL) {
273 for (i = 1; i <= m->g->nsub; i++)
274 m->pmatch[i].rm_so = m->pmatch[i].rm_eo = -1;
275 if (!g->backrefs && !(m->eflags®_BACKR)) {
277 dp = dissect(m, m->coldp, endp, gf, gl);
279 if (g->nplus > 0 && m->lastpos == NULL)
280 m->lastpos = (char **)malloc((g->nplus+1) *
282 if (g->nplus > 0 && m->lastpos == NULL) {
287 NOTE("backref dissect");
288 dp = backref(m, m->coldp, endp, gf, gl, (sopno)0);
293 /* uh-oh... we couldn't find a subexpression-level match */
294 assert(g->backrefs); /* must be back references doing it */
295 assert(g->nplus == 0 || m->lastpos != NULL);
297 if (dp != NULL || endp <= m->coldp)
300 endp = slow(m, m->coldp, endp-1, gf, gl);
303 /* try it on a shorter possibility */
305 for (i = 1; i <= m->g->nsub; i++) {
306 assert(m->pmatch[i].rm_so == -1);
307 assert(m->pmatch[i].rm_eo == -1);
310 NOTE("backoff dissect");
311 dp = backref(m, m->coldp, endp, gf, gl, (sopno)0);
313 assert(dp == NULL || dp == endp);
314 if (dp != NULL) /* found a shorter one */
317 /* despite initial appearances, there is no match here */
319 start = m->coldp + 1; /* recycle starting later */
320 assert(start <= stop);
323 /* fill in the details if requested */
325 pmatch[0].rm_so = m->coldp - m->offp;
326 pmatch[0].rm_eo = endp - m->offp;
329 assert(m->pmatch != NULL);
330 for (i = 1; i < nmatch; i++)
332 pmatch[i] = m->pmatch[i];
334 pmatch[i].rm_so = -1;
335 pmatch[i].rm_eo = -1;
339 if (m->pmatch != NULL)
340 free((char *)m->pmatch);
341 if (m->lastpos != NULL)
342 free((char *)m->lastpos);
348 - dissect - figure out what matched what, no back references
349 == static char *dissect(struct match *m, char *start, \
350 == char *stop, sopno startst, sopno stopst);
352 static char * /* == stop (success) always */
353 dissect(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
356 sopno ss; /* start sop of current subRE */
357 sopno es; /* end sop of current subRE */
358 char *sp; /* start of string matched by it */
359 char *stp; /* string matched by it cannot pass here */
360 char *rest; /* start of rest of string */
361 char *tail; /* string unmatched by rest of RE */
362 sopno ssub; /* start sop of subsubRE */
363 sopno esub; /* end sop of subsubRE */
364 char *ssp; /* start of string matched by subsubRE */
365 char *sep; /* end of string matched by subsubRE */
366 char *oldssp; /* previous ssp */
369 AT("diss", start, stop, startst, stopst);
371 for (ss = startst; ss < stopst; ss = es) {
372 /* identify end of subRE */
374 switch (OP(m->g->strip[es])) {
377 es += OPND(m->g->strip[es]);
380 while (OP(m->g->strip[es]) != O_CH)
381 es += OPND(m->g->strip[es]);
386 /* figure out what it matched */
387 switch (OP(m->g->strip[ss])) {
407 /* cases where length of match is hard to find */
411 /* how long could this one be? */
412 rest = slow(m, sp, stp, ss, es);
413 assert(rest != NULL); /* it did match */
414 /* could the rest match the rest? */
415 tail = slow(m, rest, stop, es, stopst);
418 /* no -- try a shorter match for this one */
420 assert(stp >= sp); /* it did work */
424 /* did innards match? */
425 if (slow(m, sp, rest, ssub, esub) != NULL) {
426 dp = dissect(m, sp, rest, ssub, esub);
435 /* how long could this one be? */
436 rest = slow(m, sp, stp, ss, es);
437 assert(rest != NULL); /* it did match */
438 /* could the rest match the rest? */
439 tail = slow(m, rest, stop, es, stopst);
442 /* no -- try a shorter match for this one */
444 assert(stp >= sp); /* it did work */
450 for (;;) { /* find last match of innards */
451 sep = slow(m, ssp, rest, ssub, esub);
452 if (sep == NULL || sep == ssp)
453 break; /* failed or matched null */
454 oldssp = ssp; /* on to next try */
458 /* last successful match */
462 assert(sep == rest); /* must exhaust substring */
463 assert(slow(m, ssp, sep, ssub, esub) == rest);
464 dp = dissect(m, ssp, sep, ssub, esub);
471 /* how long could this one be? */
472 rest = slow(m, sp, stp, ss, es);
473 assert(rest != NULL); /* it did match */
474 /* could the rest match the rest? */
475 tail = slow(m, rest, stop, es, stopst);
478 /* no -- try a shorter match for this one */
480 assert(stp >= sp); /* it did work */
483 esub = ss + OPND(m->g->strip[ss]) - 1;
484 assert(OP(m->g->strip[esub]) == OOR1);
485 for (;;) { /* find first matching branch */
486 if (slow(m, sp, rest, ssub, esub) == rest)
487 break; /* it matched all of it */
488 /* that one missed, try next one */
489 assert(OP(m->g->strip[esub]) == OOR1);
491 assert(OP(m->g->strip[esub]) == OOR2);
493 esub += OPND(m->g->strip[esub]);
494 if (OP(m->g->strip[esub]) == OOR2)
497 assert(OP(m->g->strip[esub]) == O_CH);
499 dp = dissect(m, sp, rest, ssub, esub);
511 i = OPND(m->g->strip[ss]);
512 assert(0 < i && i <= m->g->nsub);
513 m->pmatch[i].rm_so = sp - m->offp;
516 i = OPND(m->g->strip[ss]);
517 assert(0 < i && i <= m->g->nsub);
518 m->pmatch[i].rm_eo = sp - m->offp;
531 - backref - figure out what matched what, figuring in back references
532 == static char *backref(struct match *m, char *start, \
533 == char *stop, sopno startst, sopno stopst, sopno lev);
535 static char * /* == stop (success) or NULL (failure) */
536 backref(struct match *m, char *start, char *stop, sopno startst, sopno stopst,
537 sopno lev) /* PLUS nesting level */
540 sopno ss; /* start sop of current subRE */
541 char *sp; /* start of string matched by it */
542 sopno ssub; /* start sop of subsubRE */
543 sopno esub; /* end sop of subsubRE */
544 char *ssp; /* start of string matched by subsubRE */
552 AT("back", start, stop, startst, stopst);
555 /* get as far as we can with easy stuff */
557 for (ss = startst; !hard && ss < stopst; ss++)
558 switch (OP(s = m->g->strip[ss])) {
560 if (sp == stop || *sp++ != (char)OPND(s))
569 cs = &m->g->sets[OPND(s)];
570 if (sp == stop || !CHIN(cs, *sp++))
574 if ( (sp == m->beginp && !(m->eflags®_NOTBOL)) ||
575 (sp < m->endp && *(sp-1) == '\n' &&
576 (m->g->cflags®_NEWLINE)) )
582 if ( (sp == m->endp && !(m->eflags®_NOTEOL)) ||
583 (sp < m->endp && *sp == '\n' &&
584 (m->g->cflags®_NEWLINE)) )
590 if (( (sp == m->beginp && !(m->eflags®_NOTBOL)) ||
591 (sp < m->endp && *(sp-1) == '\n' &&
592 (m->g->cflags®_NEWLINE)) ||
594 !ISWORD(*(sp-1))) ) &&
595 (sp < m->endp && ISWORD(*sp)) )
601 if (( (sp == m->endp && !(m->eflags®_NOTEOL)) ||
602 (sp < m->endp && *sp == '\n' &&
603 (m->g->cflags®_NEWLINE)) ||
604 (sp < m->endp && !ISWORD(*sp)) ) &&
605 (sp > m->beginp && ISWORD(*(sp-1))) )
612 case OOR1: /* matches null but needs to skip */
616 assert(OP(s) == OOR2);
618 } while (OP(s = m->g->strip[ss]) != O_CH);
619 /* note that the ss++ gets us past the O_CH */
621 default: /* have to make a choice */
625 if (!hard) { /* that was it! */
630 ss--; /* adjust for the for's final increment */
633 AT("hard", sp, stop, ss, stopst);
636 case OBACK_: /* the vilest depths */
638 assert(0 < i && i <= m->g->nsub);
639 if (m->pmatch[i].rm_eo == -1)
641 assert(m->pmatch[i].rm_so != -1);
642 len = m->pmatch[i].rm_eo - m->pmatch[i].rm_so;
643 assert(stop - m->beginp >= len);
645 return(NULL); /* not enough left to match */
646 ssp = m->offp + m->pmatch[i].rm_so;
647 if (memcmp(sp, ssp, len) != 0)
649 while (m->g->strip[ss] != SOP(O_BACK, i))
651 return(backref(m, sp+len, stop, ss+1, stopst, lev));
653 case OQUEST_: /* to null or not */
654 dp = backref(m, sp, stop, ss+1, stopst, lev);
656 return(dp); /* not */
657 return(backref(m, sp, stop, ss+OPND(s)+1, stopst, lev));
660 assert(m->lastpos != NULL);
661 assert(lev+1 <= m->g->nplus);
662 m->lastpos[lev+1] = sp;
663 return(backref(m, sp, stop, ss+1, stopst, lev+1));
666 if (sp == m->lastpos[lev]) /* last pass matched null */
667 return(backref(m, sp, stop, ss+1, stopst, lev-1));
668 /* try another pass */
669 m->lastpos[lev] = sp;
670 dp = backref(m, sp, stop, ss-OPND(s)+1, stopst, lev);
672 return(backref(m, sp, stop, ss+1, stopst, lev-1));
676 case OCH_: /* find the right one, if any */
678 esub = ss + OPND(s) - 1;
679 assert(OP(m->g->strip[esub]) == OOR1);
680 for (;;) { /* find first matching branch */
681 dp = backref(m, sp, stop, ssub, esub, lev);
684 /* that one missed, try next one */
685 if (OP(m->g->strip[esub]) == O_CH)
686 return(NULL); /* there is none */
688 assert(OP(m->g->strip[esub]) == OOR2);
690 esub += OPND(m->g->strip[esub]);
691 if (OP(m->g->strip[esub]) == OOR2)
694 assert(OP(m->g->strip[esub]) == O_CH);
697 case OLPAREN: /* must undo assignment if rest fails */
699 assert(0 < i && i <= m->g->nsub);
700 offsave = m->pmatch[i].rm_so;
701 m->pmatch[i].rm_so = sp - m->offp;
702 dp = backref(m, sp, stop, ss+1, stopst, lev);
705 m->pmatch[i].rm_so = offsave;
708 case ORPAREN: /* must undo assignment if rest fails */
710 assert(0 < i && i <= m->g->nsub);
711 offsave = m->pmatch[i].rm_eo;
712 m->pmatch[i].rm_eo = sp - m->offp;
713 dp = backref(m, sp, stop, ss+1, stopst, lev);
716 m->pmatch[i].rm_eo = offsave;
727 return "shut up gcc";
731 - fast - step through the string at top speed
732 == static char *fast(struct match *m, char *start, \
733 == char *stop, sopno startst, sopno stopst);
735 static char * /* where tentative match ended, or NULL */
736 fast(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
739 states fresh = m->fresh;
742 int c = (start == m->beginp) ? OUT : *(start-1);
743 int lastc; /* previous c */
746 char *coldp; /* last p after which no match was underway */
750 st = step(m->g, startst, stopst, st, NOTHING, st);
757 c = (p == m->endp) ? OUT : *p;
761 /* is there an EOL and/or BOL between lastc and c? */
764 if ( (lastc == '\n' && m->g->cflags®_NEWLINE) ||
765 (lastc == OUT && !(m->eflags®_NOTBOL)) ) {
769 if ( (c == '\n' && m->g->cflags®_NEWLINE) ||
770 (c == OUT && !(m->eflags®_NOTEOL)) ) {
771 flagch = (flagch == BOL) ? BOLEOL : EOL;
776 st = step(m->g, startst, stopst, st, flagch, st);
780 /* how about a word boundary? */
781 if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
782 (c != OUT && ISWORD(c)) ) {
785 if ( (lastc != OUT && ISWORD(lastc)) &&
786 (flagch == EOL || (c != OUT && !ISWORD(c))) ) {
789 if (flagch == BOW || flagch == EOW) {
790 st = step(m->g, startst, stopst, st, flagch, st);
795 if (ISSET(st, stopst) || p == stop)
796 break; /* NOTE BREAK OUT */
798 /* no, we must deal with this character */
802 st = step(m->g, startst, stopst, tmp, c, st);
804 assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
808 assert(coldp != NULL);
810 if (ISSET(st, stopst))
817 - slow - step through the string more deliberately
818 == static char *slow(struct match *m, char *start, \
819 == char *stop, sopno startst, sopno stopst);
821 static char * /* where it ended */
822 slow(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
825 states empty = m->empty;
828 int c = (start == m->beginp) ? OUT : *(start-1);
829 int lastc; /* previous c */
832 char *matchp; /* last p at which a match ended */
834 AT("slow", start, stop, startst, stopst);
837 SP("sstart", st, *p);
838 st = step(m->g, startst, stopst, st, NOTHING, st);
843 c = (p == m->endp) ? OUT : *p;
845 /* is there an EOL and/or BOL between lastc and c? */
848 if ( (lastc == '\n' && m->g->cflags®_NEWLINE) ||
849 (lastc == OUT && !(m->eflags®_NOTBOL)) ) {
853 if ( (c == '\n' && m->g->cflags®_NEWLINE) ||
854 (c == OUT && !(m->eflags®_NOTEOL)) ) {
855 flagch = (flagch == BOL) ? BOLEOL : EOL;
860 st = step(m->g, startst, stopst, st, flagch, st);
861 SP("sboleol", st, c);
864 /* how about a word boundary? */
865 if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
866 (c != OUT && ISWORD(c)) ) {
869 if ( (lastc != OUT && ISWORD(lastc)) &&
870 (flagch == EOL || (c != OUT && !ISWORD(c))) ) {
873 if (flagch == BOW || flagch == EOW) {
874 st = step(m->g, startst, stopst, st, flagch, st);
875 SP("sboweow", st, c);
879 if (ISSET(st, stopst))
881 if (EQ(st, empty) || p == stop)
882 break; /* NOTE BREAK OUT */
884 /* no, we must deal with this character */
888 st = step(m->g, startst, stopst, tmp, c, st);
890 assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
899 - step - map set of states reachable before char to set reachable after
900 == static states step(struct re_guts *g, sopno start, sopno stop, \
901 == states bef, int ch, states aft);
902 == #define BOL (OUT+1)
903 == #define EOL (BOL+1)
904 == #define BOLEOL (BOL+2)
905 == #define NOTHING (BOL+3)
906 == #define BOW (BOL+4)
907 == #define EOW (BOL+5)
908 == #define CODEMAX (BOL+5) // highest code used
909 == #define NONCHAR(c) ((c) > CHAR_MAX)
910 == #define NNONCHAR (CODEMAX-CHAR_MAX)
913 step(struct re_guts *g,
914 sopno start, /* start state within strip */
915 sopno stop, /* state after stop state within strip */
916 states bef, /* states reachable before */
917 int ch, /* character or NONCHAR code */
918 states aft) /* states already known reachable after */
923 onestate here; /* note, macros know this name */
927 for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) {
931 assert(pc == stop-1);
934 /* only characters can match */
935 assert(!NONCHAR(ch) || ch != (char)OPND(s));
936 if (ch == (char)OPND(s))
940 if (ch == BOL || ch == BOLEOL)
944 if (ch == EOL || ch == BOLEOL)
960 cs = &g->sets[OPND(s)];
961 if (!NONCHAR(ch) && CHIN(cs, ch))
964 case OBACK_: /* ignored here */
968 case OPLUS_: /* forward, this is just an empty */
971 case O_PLUS: /* both forward and back */
973 i = ISSETBACK(aft, OPND(s));
974 BACK(aft, aft, OPND(s));
975 if (!i && ISSETBACK(aft, OPND(s))) {
976 /* oho, must reconsider loop body */
981 case OQUEST_: /* two branches, both forward */
983 FWD(aft, aft, OPND(s));
985 case O_QUEST: /* just an empty */
988 case OLPAREN: /* not significant here */
992 case OCH_: /* mark the first two branches */
994 assert(OP(g->strip[pc+OPND(s)]) == OOR2);
995 FWD(aft, aft, OPND(s));
997 case OOR1: /* done a branch, find the O_CH */
998 if (ISSTATEIN(aft, here)) {
1000 OP(s = g->strip[pc+look]) != O_CH;
1002 assert(OP(s) == OOR2);
1003 FWD(aft, aft, look);
1006 case OOR2: /* propagate OCH_'s marking */
1008 if (OP(g->strip[pc+OPND(s)]) != O_CH) {
1009 assert(OP(g->strip[pc+OPND(s)]) == OOR2);
1010 FWD(aft, aft, OPND(s));
1013 case O_CH: /* just empty */
1016 default: /* ooooops... */
1027 - print - print a set of states
1029 == static void print(struct match *m, char *caption, states st, \
1030 == int ch, FILE *d);
1034 print(struct match *m, char *caption, states st, int ch, FILE *d)
1036 struct re_guts *g = m->g;
1040 if (!(m->eflags®_TRACE))
1043 fprintf(d, "%s", caption);
1045 fprintf(d, " %s", pchar(ch));
1046 for (i = 0; i < g->nstates; i++)
1048 fprintf(d, "%s%d", (first) ? "\t" : ", ", i);
1055 - at - print current situation
1057 == static void at(struct match *m, char *title, char *start, char *stop, \
1058 == sopno startst, sopno stopst);
1062 at(struct match *m, char *title, char *start, char *stop, sopno startst,
1065 if (!(m->eflags®_TRACE))
1068 printf("%s %s-", title, pchar(*start));
1069 printf("%s ", pchar(*stop));
1070 printf("%ld-%ld\n", (long)startst, (long)stopst);
1074 #define PCHARDONE /* never again */
1076 - pchar - make a character printable
1078 == static char *pchar(int ch);
1081 * Is this identical to regchar() over in debug.c? Well, yes. But a
1082 * duplicate here avoids having a debugging-capable regexec.o tied to
1083 * a matching debug.o, and this is convenient. It all disappears in
1084 * the non-debug compilation anyway, so it doesn't matter much.
1086 static char * /* -> representation */
1089 static char pbuf[10];
1091 if (isprint((uch)ch) || ch == ' ')
1092 sprintf(pbuf, "%c", ch);
1094 sprintf(pbuf, "\\%o", ch);