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.5 2004/10/25 19:38:01 drhodus 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 */
245 if (nmatch == 0 && !g->backrefs)
246 break; /* no further info needed */
249 assert(m->coldp != NULL);
251 NOTE("finding start");
252 endp = slow(m, m->coldp, stop, gf, gl);
255 assert(m->coldp < m->endp);
258 if (nmatch == 1 && !g->backrefs)
259 break; /* no further info needed */
261 /* oh my, he wants the subexpressions... */
262 if (m->pmatch == NULL)
263 m->pmatch = (regmatch_t *)malloc((m->g->nsub + 1) *
265 if (m->pmatch == NULL) {
269 for (i = 1; i <= m->g->nsub; i++)
270 m->pmatch[i].rm_so = m->pmatch[i].rm_eo = -1;
271 if (!g->backrefs && !(m->eflags®_BACKR)) {
273 dp = dissect(m, m->coldp, endp, gf, gl);
275 if (g->nplus > 0 && m->lastpos == NULL)
276 m->lastpos = (char **)malloc((g->nplus+1) *
278 if (g->nplus > 0 && m->lastpos == NULL) {
283 NOTE("backref dissect");
284 dp = backref(m, m->coldp, endp, gf, gl, (sopno)0);
289 /* uh-oh... we couldn't find a subexpression-level match */
290 assert(g->backrefs); /* must be back references doing it */
291 assert(g->nplus == 0 || m->lastpos != NULL);
293 if (dp != NULL || endp <= m->coldp)
296 endp = slow(m, m->coldp, endp-1, gf, gl);
299 /* try it on a shorter possibility */
301 for (i = 1; i <= m->g->nsub; i++) {
302 assert(m->pmatch[i].rm_so == -1);
303 assert(m->pmatch[i].rm_eo == -1);
306 NOTE("backoff dissect");
307 dp = backref(m, m->coldp, endp, gf, gl, (sopno)0);
309 assert(dp == NULL || dp == endp);
310 if (dp != NULL) /* found a shorter one */
313 /* despite initial appearances, there is no match here */
315 start = m->coldp + 1; /* recycle starting later */
316 assert(start <= stop);
319 /* fill in the details if requested */
321 pmatch[0].rm_so = m->coldp - m->offp;
322 pmatch[0].rm_eo = endp - m->offp;
325 assert(m->pmatch != NULL);
326 for (i = 1; i < nmatch; i++)
328 pmatch[i] = m->pmatch[i];
330 pmatch[i].rm_so = -1;
331 pmatch[i].rm_eo = -1;
335 if (m->pmatch != NULL)
336 free((char *)m->pmatch);
337 if (m->lastpos != NULL)
338 free((char *)m->lastpos);
344 - dissect - figure out what matched what, no back references
345 == static char *dissect(struct match *m, char *start, \
346 == char *stop, sopno startst, sopno stopst);
348 static char * /* == stop (success) always */
349 dissect(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
352 sopno ss; /* start sop of current subRE */
353 sopno es; /* end sop of current subRE */
354 char *sp; /* start of string matched by it */
355 char *stp; /* string matched by it cannot pass here */
356 char *rest; /* start of rest of string */
357 char *tail; /* string unmatched by rest of RE */
358 sopno ssub; /* start sop of subsubRE */
359 sopno esub; /* end sop of subsubRE */
360 char *ssp; /* start of string matched by subsubRE */
361 char *sep; /* end of string matched by subsubRE */
362 char *oldssp; /* previous ssp */
365 AT("diss", start, stop, startst, stopst);
367 for (ss = startst; ss < stopst; ss = es) {
368 /* identify end of subRE */
370 switch (OP(m->g->strip[es])) {
373 es += OPND(m->g->strip[es]);
376 while (OP(m->g->strip[es]) != O_CH)
377 es += OPND(m->g->strip[es]);
382 /* figure out what it matched */
383 switch (OP(m->g->strip[ss])) {
403 /* cases where length of match is hard to find */
407 /* how long could this one be? */
408 rest = slow(m, sp, stp, ss, es);
409 assert(rest != NULL); /* it did match */
410 /* could the rest match the rest? */
411 tail = slow(m, rest, stop, es, stopst);
414 /* no -- try a shorter match for this one */
416 assert(stp >= sp); /* it did work */
420 /* did innards match? */
421 if (slow(m, sp, rest, ssub, esub) != NULL) {
422 dp = dissect(m, sp, rest, ssub, esub);
431 /* how long could this one be? */
432 rest = slow(m, sp, stp, ss, es);
433 assert(rest != NULL); /* it did match */
434 /* could the rest match the rest? */
435 tail = slow(m, rest, stop, es, stopst);
438 /* no -- try a shorter match for this one */
440 assert(stp >= sp); /* it did work */
446 for (;;) { /* find last match of innards */
447 sep = slow(m, ssp, rest, ssub, esub);
448 if (sep == NULL || sep == ssp)
449 break; /* failed or matched null */
450 oldssp = ssp; /* on to next try */
454 /* last successful match */
458 assert(sep == rest); /* must exhaust substring */
459 assert(slow(m, ssp, sep, ssub, esub) == rest);
460 dp = dissect(m, ssp, sep, ssub, esub);
467 /* how long could this one be? */
468 rest = slow(m, sp, stp, ss, es);
469 assert(rest != NULL); /* it did match */
470 /* could the rest match the rest? */
471 tail = slow(m, rest, stop, es, stopst);
474 /* no -- try a shorter match for this one */
476 assert(stp >= sp); /* it did work */
479 esub = ss + OPND(m->g->strip[ss]) - 1;
480 assert(OP(m->g->strip[esub]) == OOR1);
481 for (;;) { /* find first matching branch */
482 if (slow(m, sp, rest, ssub, esub) == rest)
483 break; /* it matched all of it */
484 /* that one missed, try next one */
485 assert(OP(m->g->strip[esub]) == OOR1);
487 assert(OP(m->g->strip[esub]) == OOR2);
489 esub += OPND(m->g->strip[esub]);
490 if (OP(m->g->strip[esub]) == OOR2)
493 assert(OP(m->g->strip[esub]) == O_CH);
495 dp = dissect(m, sp, rest, ssub, esub);
507 i = OPND(m->g->strip[ss]);
508 assert(0 < i && i <= m->g->nsub);
509 m->pmatch[i].rm_so = sp - m->offp;
512 i = OPND(m->g->strip[ss]);
513 assert(0 < i && i <= m->g->nsub);
514 m->pmatch[i].rm_eo = sp - m->offp;
527 - backref - figure out what matched what, figuring in back references
528 == static char *backref(struct match *m, char *start, \
529 == char *stop, sopno startst, sopno stopst, sopno lev);
531 static char * /* == stop (success) or NULL (failure) */
532 backref(struct match *m, char *start, char *stop, sopno startst, sopno stopst,
533 sopno lev) /* PLUS nesting level */
536 sopno ss; /* start sop of current subRE */
537 char *sp; /* start of string matched by it */
538 sopno ssub; /* start sop of subsubRE */
539 sopno esub; /* end sop of subsubRE */
540 char *ssp; /* start of string matched by subsubRE */
548 AT("back", start, stop, startst, stopst);
551 /* get as far as we can with easy stuff */
553 for (ss = startst; !hard && ss < stopst; ss++)
554 switch (OP(s = m->g->strip[ss])) {
556 if (sp == stop || *sp++ != (char)OPND(s))
565 cs = &m->g->sets[OPND(s)];
566 if (sp == stop || !CHIN(cs, *sp++))
570 if ( (sp == m->beginp && !(m->eflags®_NOTBOL)) ||
571 (sp < m->endp && *(sp-1) == '\n' &&
572 (m->g->cflags®_NEWLINE)) )
578 if ( (sp == m->endp && !(m->eflags®_NOTEOL)) ||
579 (sp < m->endp && *sp == '\n' &&
580 (m->g->cflags®_NEWLINE)) )
586 if (( (sp == m->beginp && !(m->eflags®_NOTBOL)) ||
587 (sp < m->endp && *(sp-1) == '\n' &&
588 (m->g->cflags®_NEWLINE)) ||
590 !ISWORD(*(sp-1))) ) &&
591 (sp < m->endp && ISWORD(*sp)) )
597 if (( (sp == m->endp && !(m->eflags®_NOTEOL)) ||
598 (sp < m->endp && *sp == '\n' &&
599 (m->g->cflags®_NEWLINE)) ||
600 (sp < m->endp && !ISWORD(*sp)) ) &&
601 (sp > m->beginp && ISWORD(*(sp-1))) )
608 case OOR1: /* matches null but needs to skip */
612 assert(OP(s) == OOR2);
614 } while (OP(s = m->g->strip[ss]) != O_CH);
615 /* note that the ss++ gets us past the O_CH */
617 default: /* have to make a choice */
621 if (!hard) { /* that was it! */
626 ss--; /* adjust for the for's final increment */
629 AT("hard", sp, stop, ss, stopst);
632 case OBACK_: /* the vilest depths */
634 assert(0 < i && i <= m->g->nsub);
635 if (m->pmatch[i].rm_eo == -1)
637 assert(m->pmatch[i].rm_so != -1);
638 len = m->pmatch[i].rm_eo - m->pmatch[i].rm_so;
639 assert(stop - m->beginp >= len);
641 return(NULL); /* not enough left to match */
642 ssp = m->offp + m->pmatch[i].rm_so;
643 if (memcmp(sp, ssp, len) != 0)
645 while (m->g->strip[ss] != SOP(O_BACK, i))
647 return(backref(m, sp+len, stop, ss+1, stopst, lev));
649 case OQUEST_: /* to null or not */
650 dp = backref(m, sp, stop, ss+1, stopst, lev);
652 return(dp); /* not */
653 return(backref(m, sp, stop, ss+OPND(s)+1, stopst, lev));
656 assert(m->lastpos != NULL);
657 assert(lev+1 <= m->g->nplus);
658 m->lastpos[lev+1] = sp;
659 return(backref(m, sp, stop, ss+1, stopst, lev+1));
662 if (sp == m->lastpos[lev]) /* last pass matched null */
663 return(backref(m, sp, stop, ss+1, stopst, lev-1));
664 /* try another pass */
665 m->lastpos[lev] = sp;
666 dp = backref(m, sp, stop, ss-OPND(s)+1, stopst, lev);
668 return(backref(m, sp, stop, ss+1, stopst, lev-1));
672 case OCH_: /* find the right one, if any */
674 esub = ss + OPND(s) - 1;
675 assert(OP(m->g->strip[esub]) == OOR1);
676 for (;;) { /* find first matching branch */
677 dp = backref(m, sp, stop, ssub, esub, lev);
680 /* that one missed, try next one */
681 if (OP(m->g->strip[esub]) == O_CH)
682 return(NULL); /* there is none */
684 assert(OP(m->g->strip[esub]) == OOR2);
686 esub += OPND(m->g->strip[esub]);
687 if (OP(m->g->strip[esub]) == OOR2)
690 assert(OP(m->g->strip[esub]) == O_CH);
693 case OLPAREN: /* must undo assignment if rest fails */
695 assert(0 < i && i <= m->g->nsub);
696 offsave = m->pmatch[i].rm_so;
697 m->pmatch[i].rm_so = sp - m->offp;
698 dp = backref(m, sp, stop, ss+1, stopst, lev);
701 m->pmatch[i].rm_so = offsave;
704 case ORPAREN: /* must undo assignment if rest fails */
706 assert(0 < i && i <= m->g->nsub);
707 offsave = m->pmatch[i].rm_eo;
708 m->pmatch[i].rm_eo = sp - m->offp;
709 dp = backref(m, sp, stop, ss+1, stopst, lev);
712 m->pmatch[i].rm_eo = offsave;
723 return "shut up gcc";
727 - fast - step through the string at top speed
728 == static char *fast(struct match *m, char *start, \
729 == char *stop, sopno startst, sopno stopst);
731 static char * /* where tentative match ended, or NULL */
732 fast(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
735 states fresh = m->fresh;
738 int c = (start == m->beginp) ? OUT : *(start-1);
739 int lastc; /* previous c */
742 char *coldp; /* last p after which no match was underway */
746 st = step(m->g, startst, stopst, st, NOTHING, st);
753 c = (p == m->endp) ? OUT : *p;
757 /* is there an EOL and/or BOL between lastc and c? */
760 if ( (lastc == '\n' && m->g->cflags®_NEWLINE) ||
761 (lastc == OUT && !(m->eflags®_NOTBOL)) ) {
765 if ( (c == '\n' && m->g->cflags®_NEWLINE) ||
766 (c == OUT && !(m->eflags®_NOTEOL)) ) {
767 flagch = (flagch == BOL) ? BOLEOL : EOL;
772 st = step(m->g, startst, stopst, st, flagch, st);
776 /* how about a word boundary? */
777 if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
778 (c != OUT && ISWORD(c)) ) {
781 if ( (lastc != OUT && ISWORD(lastc)) &&
782 (flagch == EOL || (c != OUT && !ISWORD(c))) ) {
785 if (flagch == BOW || flagch == EOW) {
786 st = step(m->g, startst, stopst, st, flagch, st);
791 if (ISSET(st, stopst) || p == stop)
792 break; /* NOTE BREAK OUT */
794 /* no, we must deal with this character */
798 st = step(m->g, startst, stopst, tmp, c, st);
800 assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
804 assert(coldp != NULL);
806 if (ISSET(st, stopst))
813 - slow - step through the string more deliberately
814 == static char *slow(struct match *m, char *start, \
815 == char *stop, sopno startst, sopno stopst);
817 static char * /* where it ended */
818 slow(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
821 states empty = m->empty;
824 int c = (start == m->beginp) ? OUT : *(start-1);
825 int lastc; /* previous c */
828 char *matchp; /* last p at which a match ended */
830 AT("slow", start, stop, startst, stopst);
833 SP("sstart", st, *p);
834 st = step(m->g, startst, stopst, st, NOTHING, st);
839 c = (p == m->endp) ? OUT : *p;
841 /* is there an EOL and/or BOL between lastc and c? */
844 if ( (lastc == '\n' && m->g->cflags®_NEWLINE) ||
845 (lastc == OUT && !(m->eflags®_NOTBOL)) ) {
849 if ( (c == '\n' && m->g->cflags®_NEWLINE) ||
850 (c == OUT && !(m->eflags®_NOTEOL)) ) {
851 flagch = (flagch == BOL) ? BOLEOL : EOL;
856 st = step(m->g, startst, stopst, st, flagch, st);
857 SP("sboleol", st, c);
860 /* how about a word boundary? */
861 if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
862 (c != OUT && ISWORD(c)) ) {
865 if ( (lastc != OUT && ISWORD(lastc)) &&
866 (flagch == EOL || (c != OUT && !ISWORD(c))) ) {
869 if (flagch == BOW || flagch == EOW) {
870 st = step(m->g, startst, stopst, st, flagch, st);
871 SP("sboweow", st, c);
875 if (ISSET(st, stopst))
877 if (EQ(st, empty) || p == stop)
878 break; /* NOTE BREAK OUT */
880 /* no, we must deal with this character */
884 st = step(m->g, startst, stopst, tmp, c, st);
886 assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
895 - step - map set of states reachable before char to set reachable after
896 == static states step(struct re_guts *g, sopno start, sopno stop, \
897 == states bef, int ch, states aft);
898 == #define BOL (OUT+1)
899 == #define EOL (BOL+1)
900 == #define BOLEOL (BOL+2)
901 == #define NOTHING (BOL+3)
902 == #define BOW (BOL+4)
903 == #define EOW (BOL+5)
904 == #define CODEMAX (BOL+5) // highest code used
905 == #define NONCHAR(c) ((c) > CHAR_MAX)
906 == #define NNONCHAR (CODEMAX-CHAR_MAX)
909 step(struct re_guts *g,
910 sopno start, /* start state within strip */
911 sopno stop, /* state after stop state within strip */
912 states bef, /* states reachable before */
913 int ch, /* character or NONCHAR code */
914 states aft) /* states already known reachable after */
919 onestate here; /* note, macros know this name */
923 for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) {
927 assert(pc == stop-1);
930 /* only characters can match */
931 assert(!NONCHAR(ch) || ch != (char)OPND(s));
932 if (ch == (char)OPND(s))
936 if (ch == BOL || ch == BOLEOL)
940 if (ch == EOL || ch == BOLEOL)
956 cs = &g->sets[OPND(s)];
957 if (!NONCHAR(ch) && CHIN(cs, ch))
960 case OBACK_: /* ignored here */
964 case OPLUS_: /* forward, this is just an empty */
967 case O_PLUS: /* both forward and back */
969 i = ISSETBACK(aft, OPND(s));
970 BACK(aft, aft, OPND(s));
971 if (!i && ISSETBACK(aft, OPND(s))) {
972 /* oho, must reconsider loop body */
977 case OQUEST_: /* two branches, both forward */
979 FWD(aft, aft, OPND(s));
981 case O_QUEST: /* just an empty */
984 case OLPAREN: /* not significant here */
988 case OCH_: /* mark the first two branches */
990 assert(OP(g->strip[pc+OPND(s)]) == OOR2);
991 FWD(aft, aft, OPND(s));
993 case OOR1: /* done a branch, find the O_CH */
994 if (ISSTATEIN(aft, here)) {
996 OP(s = g->strip[pc+look]) != O_CH;
998 assert(OP(s) == OOR2);
1002 case OOR2: /* propagate OCH_'s marking */
1004 if (OP(g->strip[pc+OPND(s)]) != O_CH) {
1005 assert(OP(g->strip[pc+OPND(s)]) == OOR2);
1006 FWD(aft, aft, OPND(s));
1009 case O_CH: /* just empty */
1012 default: /* ooooops... */
1023 - print - print a set of states
1025 == static void print(struct match *m, char *caption, states st, \
1026 == int ch, FILE *d);
1030 print(struct match *m, char *caption, states st, int ch, FILE *d)
1032 struct re_guts *g = m->g;
1036 if (!(m->eflags®_TRACE))
1039 fprintf(d, "%s", caption);
1041 fprintf(d, " %s", pchar(ch));
1042 for (i = 0; i < g->nstates; i++)
1044 fprintf(d, "%s%d", (first) ? "\t" : ", ", i);
1051 - at - print current situation
1053 == static void at(struct match *m, char *title, char *start, char *stop, \
1054 == sopno startst, sopno stopst);
1058 at(struct match *m, char *title, char *start, char *stop, sopno startst,
1061 if (!(m->eflags®_TRACE))
1064 printf("%s %s-", title, pchar(*start));
1065 printf("%s ", pchar(*stop));
1066 printf("%ld-%ld\n", (long)startst, (long)stopst);
1070 #define PCHARDONE /* never again */
1072 - pchar - make a character printable
1074 == static char *pchar(int ch);
1077 * Is this identical to regchar() over in debug.c? Well, yes. But a
1078 * duplicate here avoids having a debugging-capable regexec.o tied to
1079 * a matching debug.o, and this is convenient. It all disappears in
1080 * the non-debug compilation anyway, so it doesn't matter much.
1082 static char * /* -> representation */
1085 static char pbuf[10];
1087 if (isprint((uch)ch) || ch == ' ')
1088 sprintf(pbuf, "%c", ch);
1090 sprintf(pbuf, "\\%o", ch);