2 * This code is derived from OpenBSD's libc/regex, original license follows:
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
39 * The matching engine and friends. This file is #included by regexec.c
40 * after suitable #defines of a variety of macros used herein, so that
41 * different state representations can be used without duplicating masses
46 #define matcher smatcher
49 #define dissect sdissect
50 #define backref sbackref
56 #define step_back sstep_back
59 #define matcher lmatcher
62 #define dissect ldissect
63 #define backref lbackref
69 #define step_back lstep_back
72 /* another structure passed up and down to avoid zillions of parameters */
76 llvm_regmatch_t *pmatch; /* [nsub+1] (0 element unused) */
77 const char *offp; /* offsets work from here */
78 const char *beginp; /* start of string -- virtual NUL precedes */
79 const char *endp; /* end of string -- virtual NUL here */
80 const char *coldp; /* can be no match starting before here */
81 const char **lastpos; /* [nplus+1] */
83 states st; /* current states */
84 states fresh; /* states for a fresh start */
85 states tmp; /* temporary */
86 states empty; /* empty set of states */
89 static int matcher(struct re_guts *, const char *, size_t,
90 llvm_regmatch_t[], int);
91 static const char *dissect(struct match *, const char *, const char *, sopno,
93 static const char *backref(struct match *, const char *, const char *, sopno,
95 static const char *fast(struct match *, const char *, const char *, sopno, sopno);
96 static const char *slow(struct match *, const char *, const char *, sopno, sopno);
97 static states step(struct re_guts *, sopno, sopno, states, int, states);
98 #define MAX_RECURSION 100
101 #define BOLEOL (BOL+2)
102 #define NOTHING (BOL+3)
105 #define CODEMAX (BOL+5) /* highest code used */
106 #define NONCHAR(c) ((c) > CHAR_MAX)
107 #define NNONCHAR (CODEMAX-CHAR_MAX)
109 static void print(struct match *, const char *, states, int, FILE *);
113 struct match *, const char *, const char *, const char *, sopno, sopno);
116 static char *pchar(int);
120 #define SP(t, s, c) print(m, t, s, c, stdout)
121 #define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2)
122 #define NOTE(str) { if (m->eflags®_TRACE) (void)printf("=%s\n", (str)); }
125 #define SP(t, s, c) /* nothing */
126 #define AT(t, p1, p2, s1, s2) /* nothing */
127 #define NOTE(s) /* nothing */
131 - matcher - the actual matching engine
133 static int /* 0 success, REG_NOMATCH failure */
134 matcher(struct re_guts *g, const char *string, size_t nmatch,
135 llvm_regmatch_t pmatch[],
141 struct match *m = &mv;
143 const sopno gf = g->firststate+1; /* +1 for OEND */
144 const sopno gl = g->laststate;
148 /* simplify the situation where possible */
149 if (g->cflags®_NOSUB)
151 if (eflags®_STARTEND) {
152 start = string + pmatch[0].rm_so;
153 stop = string + pmatch[0].rm_eo;
156 stop = start + strlen(start);
161 /* prescreening; this does wonders for this rather slow code */
162 if (g->must != NULL) {
163 for (dp = start; dp < stop; dp++)
164 if (*dp == g->must[0] && stop - dp >= g->mlen &&
165 memcmp(dp, g->must, (size_t)g->mlen) == 0)
167 if (dp == stop) /* we didn't find g->must */
171 /* match struct setup */
186 /* this loop does only one repetition except for backrefs */
188 endp = fast(m, start, stop, gf, gl);
189 if (endp == NULL) { /* a miss */
191 free((void*)m->lastpos);
195 if (nmatch == 0 && !g->backrefs)
196 break; /* no further info needed */
199 assert(m->coldp != NULL);
201 NOTE("finding start");
202 endp = slow(m, m->coldp, stop, gf, gl);
205 assert(m->coldp < m->endp);
208 if (nmatch == 1 && !g->backrefs)
209 break; /* no further info needed */
211 /* oh my, they want the subexpressions... */
212 if (m->pmatch == NULL)
213 m->pmatch = (llvm_regmatch_t *)malloc((m->g->nsub + 1) *
214 sizeof(llvm_regmatch_t));
215 if (m->pmatch == NULL) {
219 for (i = 1; i <= m->g->nsub; i++)
220 m->pmatch[i].rm_so = m->pmatch[i].rm_eo = -1;
221 if (!g->backrefs && !(m->eflags®_BACKR)) {
223 dp = dissect(m, m->coldp, endp, gf, gl);
225 if (g->nplus > 0 && m->lastpos == NULL)
226 m->lastpos = (const char **)malloc((g->nplus+1) *
228 if (g->nplus > 0 && m->lastpos == NULL) {
233 NOTE("backref dissect");
234 dp = backref(m, m->coldp, endp, gf, gl, (sopno)0, 0);
239 /* uh-oh... we couldn't find a subexpression-level match */
240 assert(g->backrefs); /* must be back references doing it */
241 assert(g->nplus == 0 || m->lastpos != NULL);
243 if (dp != NULL || endp <= m->coldp)
246 endp = slow(m, m->coldp, endp-1, gf, gl);
249 /* try it on a shorter possibility */
251 for (i = 1; i <= m->g->nsub; i++) {
252 assert(m->pmatch[i].rm_so == -1);
253 assert(m->pmatch[i].rm_eo == -1);
256 NOTE("backoff dissect");
257 dp = backref(m, m->coldp, endp, gf, gl, (sopno)0, 0);
259 assert(dp == NULL || dp == endp);
260 if (dp != NULL) /* found a shorter one */
263 /* despite initial appearances, there is no match here */
265 if (m->coldp == stop)
267 start = m->coldp + 1; /* recycle starting later */
270 /* fill in the details if requested */
272 pmatch[0].rm_so = m->coldp - m->offp;
273 pmatch[0].rm_eo = endp - m->offp;
276 assert(m->pmatch != NULL);
277 for (i = 1; i < nmatch; i++)
279 pmatch[i] = m->pmatch[i];
281 pmatch[i].rm_so = -1;
282 pmatch[i].rm_eo = -1;
286 if (m->pmatch != NULL)
287 free((char *)m->pmatch);
288 if (m->lastpos != NULL)
289 free((char *)m->lastpos);
294 /* Step back from "stop" to a position where the strip startst..stopst might
295 * match. This can always conservatively return "stop - 1", but may return an
296 * earlier position if matches at later positions are impossible. */
298 step_back(struct re_guts *g, const char *start, const char *stop, sopno startst,
301 /* Always step back at least one character. */
302 assert(stop > start);
303 const char *res = stop - 1;
305 /* Check whether the strip startst..stropst starts with a fixed character,
306 * ignoring any closing parentheses. If not, return a conservative result. */
308 if (startst >= stopst)
310 if (OP(g->strip[startst]) != ORPAREN)
314 if (OP(g->strip[startst]) != OCHAR)
317 /* Find the character that starts the following match. */
318 char ch = OPND(g->strip[startst]);
319 for (; res != start; --res) {
321 /* Try to check the next fixed character as well. */
322 sopno nextst = startst + 1;
323 const char *next = res + 1;
324 if (nextst >= stopst || OP(g->strip[nextst]) != OCHAR || next >= stop ||
325 *next == (char)OPND(g->strip[nextst]))
333 - dissect - figure out what matched what, no back references
335 static const char * /* == stop (success) always */
336 dissect(struct match *m, const char *start, const char *stop, sopno startst,
340 sopno ss; /* start sop of current subRE */
341 sopno es; /* end sop of current subRE */
342 const char *sp; /* start of string matched by it */
343 const char *stp; /* string matched by it cannot pass here */
344 const char *rest; /* start of rest of string */
345 const char *tail; /* string unmatched by rest of RE */
346 sopno ssub; /* start sop of subsubRE */
347 sopno esub; /* end sop of subsubRE */
348 const char *ssp; /* start of string matched by subsubRE */
349 const char *sep; /* end of string matched by subsubRE */
350 const char *oldssp; /* previous ssp */
352 AT("diss", start, stop, startst, stopst);
354 for (ss = startst; ss < stopst; ss = es) {
355 /* identify end of subRE */
357 switch (OP(m->g->strip[es])) {
360 es += OPND(m->g->strip[es]);
363 while (OP(m->g->strip[es]) != O_CH)
364 es += OPND(m->g->strip[es]);
369 /* figure out what it matched */
370 switch (OP(m->g->strip[ss])) {
390 /* cases where length of match is hard to find */
394 /* how long could this one be? */
395 rest = slow(m, sp, stp, ss, es);
396 assert(rest != NULL); /* it did match */
397 /* could the rest match the rest? */
398 tail = slow(m, rest, stop, es, stopst);
401 /* no -- try a shorter match for this one */
402 stp = step_back(m->g, sp, rest, es, stopst);
403 assert(stp >= sp); /* it did work */
407 /* did innards match? */
408 if (slow(m, sp, rest, ssub, esub) != NULL) {
409 const char *dp = dissect(m, sp, rest, ssub, esub);
410 (void)dp; /* avoid warning if assertions off */
419 /* how long could this one be? */
420 rest = slow(m, sp, stp, ss, es);
421 assert(rest != NULL); /* it did match */
422 /* could the rest match the rest? */
423 tail = slow(m, rest, stop, es, stopst);
426 /* no -- try a shorter match for this one */
427 stp = step_back(m->g, sp, rest, es, stopst);
428 assert(stp >= sp); /* it did work */
434 for (;;) { /* find last match of innards */
435 sep = slow(m, ssp, rest, ssub, esub);
436 if (sep == NULL || sep == ssp)
437 break; /* failed or matched null */
438 oldssp = ssp; /* on to next try */
442 /* last successful match */
446 assert(sep == rest); /* must exhaust substring */
447 assert(slow(m, ssp, sep, ssub, esub) == rest);
449 const char *dp = dissect(m, ssp, sep, ssub, esub);
450 (void)dp; /* avoid warning if assertions off */
458 /* how long could this one be? */
459 rest = slow(m, sp, stp, ss, es);
460 assert(rest != NULL); /* it did match */
461 /* could the rest match the rest? */
462 tail = slow(m, rest, stop, es, stopst);
465 /* no -- try a shorter match for this one */
467 assert(stp >= sp); /* it did work */
470 esub = ss + OPND(m->g->strip[ss]) - 1;
471 assert(OP(m->g->strip[esub]) == OOR1);
472 for (;;) { /* find first matching branch */
473 if (slow(m, sp, rest, ssub, esub) == rest)
474 break; /* it matched all of it */
475 /* that one missed, try next one */
476 assert(OP(m->g->strip[esub]) == OOR1);
478 assert(OP(m->g->strip[esub]) == OOR2);
480 esub += OPND(m->g->strip[esub]);
481 if (OP(m->g->strip[esub]) == OOR2)
484 assert(OP(m->g->strip[esub]) == O_CH);
487 const char *dp = dissect(m, sp, rest, ssub, esub);
488 (void)dp; /* avoid warning if assertions off */
501 i = OPND(m->g->strip[ss]);
502 assert(0 < i && i <= m->g->nsub);
503 m->pmatch[i].rm_so = sp - m->offp;
506 i = OPND(m->g->strip[ss]);
507 assert(0 < i && i <= m->g->nsub);
508 m->pmatch[i].rm_eo = sp - m->offp;
521 - backref - figure out what matched what, figuring in back references
523 static const char * /* == stop (success) or NULL (failure) */
524 backref(struct match *m, const char *start, const char *stop, sopno startst,
525 sopno stopst, sopno lev, int rec) /* PLUS nesting level */
528 sopno ss; /* start sop of current subRE */
529 const char *sp; /* start of string matched by it */
530 sopno ssub; /* start sop of subsubRE */
531 sopno esub; /* end sop of subsubRE */
532 const char *ssp; /* start of string matched by subsubRE */
537 llvm_regoff_t offsave;
540 AT("back", start, stop, startst, stopst);
543 /* get as far as we can with easy stuff */
545 for (ss = startst; !hard && ss < stopst; ss++)
546 switch (OP(s = m->g->strip[ss])) {
548 if (sp == stop || *sp++ != (char)OPND(s))
557 cs = &m->g->sets[OPND(s)];
558 if (sp == stop || !CHIN(cs, *sp++))
562 if ( (sp == m->beginp && !(m->eflags®_NOTBOL)) ||
563 (sp < m->endp && *(sp-1) == '\n' &&
564 (m->g->cflags®_NEWLINE)) )
570 if ( (sp == m->endp && !(m->eflags®_NOTEOL)) ||
571 (sp < m->endp && *sp == '\n' &&
572 (m->g->cflags®_NEWLINE)) )
578 if (( (sp == m->beginp && !(m->eflags®_NOTBOL)) ||
579 (sp < m->endp && *(sp-1) == '\n' &&
580 (m->g->cflags®_NEWLINE)) ||
582 !ISWORD(*(sp-1))) ) &&
583 (sp < m->endp && ISWORD(*sp)) )
589 if (( (sp == m->endp && !(m->eflags®_NOTEOL)) ||
590 (sp < m->endp && *sp == '\n' &&
591 (m->g->cflags®_NEWLINE)) ||
592 (sp < m->endp && !ISWORD(*sp)) ) &&
593 (sp > m->beginp && ISWORD(*(sp-1))) )
601 case OOR1: /* matches null but needs to skip */
605 assert(OP(s) == OOR2);
607 } while (OP(s = m->g->strip[ss]) != O_CH);
608 /* note that the ss++ gets us past the O_CH */
610 default: /* have to make a choice */
614 if (!hard) { /* that was it! */
619 ss--; /* adjust for the for's final increment */
622 AT("hard", sp, stop, ss, stopst);
625 case OBACK_: /* the vilest depths */
627 assert(0 < i && i <= m->g->nsub);
628 if (m->pmatch[i].rm_eo == -1)
630 assert(m->pmatch[i].rm_so != -1);
631 len = m->pmatch[i].rm_eo - m->pmatch[i].rm_so;
632 if (len == 0 && rec++ > MAX_RECURSION)
634 assert(stop - m->beginp >= len);
636 return(NULL); /* not enough left to match */
637 ssp = m->offp + m->pmatch[i].rm_so;
638 if (memcmp(sp, ssp, len) != 0)
640 while (m->g->strip[ss] != SOP(O_BACK, i))
642 return(backref(m, sp+len, stop, ss+1, stopst, lev, rec));
644 case OQUEST_: /* to null or not */
645 dp = backref(m, sp, stop, ss+1, stopst, lev, rec);
647 return(dp); /* not */
648 return(backref(m, sp, stop, ss+OPND(s)+1, stopst, lev, rec));
651 assert(m->lastpos != NULL);
652 assert(lev+1 <= m->g->nplus);
653 m->lastpos[lev+1] = sp;
654 return(backref(m, sp, stop, ss+1, stopst, lev+1, rec));
657 if (sp == m->lastpos[lev]) /* last pass matched null */
658 return(backref(m, sp, stop, ss+1, stopst, lev-1, rec));
659 /* try another pass */
660 m->lastpos[lev] = sp;
661 dp = backref(m, sp, stop, ss-OPND(s)+1, stopst, lev, rec);
663 return(backref(m, sp, stop, ss+1, stopst, lev-1, rec));
667 case OCH_: /* find the right one, if any */
669 esub = ss + OPND(s) - 1;
670 assert(OP(m->g->strip[esub]) == OOR1);
671 for (;;) { /* find first matching branch */
672 dp = backref(m, sp, stop, ssub, stopst, lev, rec);
675 /* that one missed, try next one */
676 if (OP(m->g->strip[esub]) == O_CH)
677 return(NULL); /* there is none */
679 assert(OP(m->g->strip[esub]) == OOR2);
681 esub += OPND(m->g->strip[esub]);
682 if (OP(m->g->strip[esub]) == OOR2)
685 assert(OP(m->g->strip[esub]) == O_CH);
688 case OLPAREN: /* must undo assignment if rest fails */
690 assert(0 < i && i <= m->g->nsub);
691 offsave = m->pmatch[i].rm_so;
692 m->pmatch[i].rm_so = sp - m->offp;
693 dp = backref(m, sp, stop, ss+1, stopst, lev, rec);
696 m->pmatch[i].rm_so = offsave;
699 case ORPAREN: /* must undo assignment if rest fails */
701 assert(0 < i && i <= m->g->nsub);
702 offsave = m->pmatch[i].rm_eo;
703 m->pmatch[i].rm_eo = sp - m->offp;
704 dp = backref(m, sp, stop, ss+1, stopst, lev, rec);
707 m->pmatch[i].rm_eo = offsave;
722 - fast - step through the string at top speed
724 static const char * /* where tentative match ended, or NULL */
725 fast(struct match *m, const char *start, const char *stop, sopno startst,
729 states fresh = m->fresh;
731 const char *p = start;
732 int c = (start == m->beginp) ? OUT : *(start-1);
733 int lastc; /* previous c */
736 const char *coldp; /* last p after which no match was underway */
740 st = step(m->g, startst, stopst, st, NOTHING, st);
747 c = (p == m->endp) ? OUT : *p;
751 /* is there an EOL and/or BOL between lastc and c? */
754 if ( (lastc == '\n' && m->g->cflags®_NEWLINE) ||
755 (lastc == OUT && !(m->eflags®_NOTBOL)) ) {
759 if ( (c == '\n' && m->g->cflags®_NEWLINE) ||
760 (c == OUT && !(m->eflags®_NOTEOL)) ) {
761 flagch = (flagch == BOL) ? BOLEOL : EOL;
766 st = step(m->g, startst, stopst, st, flagch, st);
770 /* how about a word boundary? */
771 if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
772 (c != OUT && ISWORD(c)) ) {
775 if ( (lastc != OUT && ISWORD(lastc)) &&
776 (flagch == EOL || (c != OUT && !ISWORD(c))) ) {
779 if (flagch == BOW || flagch == EOW) {
780 st = step(m->g, startst, stopst, st, flagch, st);
785 if (ISSET(st, stopst) || p == stop)
786 break; /* NOTE BREAK OUT */
788 /* no, we must deal with this character */
792 st = step(m->g, startst, stopst, tmp, c, st);
794 assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
798 assert(coldp != NULL);
800 if (ISSET(st, stopst))
807 - slow - step through the string more deliberately
809 static const char * /* where it ended */
810 slow(struct match *m, const char *start, const char *stop, sopno startst,
813 /* Quickly skip over fixed character matches at the start. */
814 const char *p = start;
815 for (; startst < stopst; ++startst) {
817 sop s = m->g->strip[startst];
821 /* Not relevant here. */
824 if (p == stop || *p != (char)OPND(s))
837 states empty = m->empty;
839 int c = (p == m->beginp) ? OUT : *(p-1);
840 int lastc; /* previous c */
843 const char *matchp; /* last p at which a match ended */
845 AT("slow", start, stop, startst, stopst);
848 SP("sstart", st, *p);
849 st = step(m->g, startst, stopst, st, NOTHING, st);
854 c = (p == m->endp) ? OUT : *p;
856 /* is there an EOL and/or BOL between lastc and c? */
859 if ( (lastc == '\n' && m->g->cflags®_NEWLINE) ||
860 (lastc == OUT && !(m->eflags®_NOTBOL)) ) {
864 if ( (c == '\n' && m->g->cflags®_NEWLINE) ||
865 (c == OUT && !(m->eflags®_NOTEOL)) ) {
866 flagch = (flagch == BOL) ? BOLEOL : EOL;
871 st = step(m->g, startst, stopst, st, flagch, st);
872 SP("sboleol", st, c);
875 /* how about a word boundary? */
876 if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
877 (c != OUT && ISWORD(c)) ) {
880 if ( (lastc != OUT && ISWORD(lastc)) &&
881 (flagch == EOL || (c != OUT && !ISWORD(c))) ) {
884 if (flagch == BOW || flagch == EOW) {
885 st = step(m->g, startst, stopst, st, flagch, st);
886 SP("sboweow", st, c);
890 if (ISSET(st, stopst))
892 if (EQ(st, empty) || p == stop)
893 break; /* NOTE BREAK OUT */
895 /* no, we must deal with this character */
899 st = step(m->g, startst, stopst, tmp, c, st);
901 assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
910 - step - map set of states reachable before char to set reachable after
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
1030 print(struct match *m, const char *caption, states st, int ch, FILE *d)
1032 struct re_guts *g = m->g;
1036 if (!(m->eflags®_TRACE))
1039 (void)fprintf(d, "%s", caption);
1041 (void)fprintf(d, " %s", pchar(ch));
1042 for (i = 0; i < g->nstates; i++)
1044 (void)fprintf(d, "%s%d", (first) ? "\t" : ", ", i);
1047 (void)fprintf(d, "\n");
1051 - at - print current situation
1054 at(struct match *m, const char *title, const char *start, const char *stop,
1055 sopno startst, sopno stopst)
1057 if (!(m->eflags®_TRACE))
1060 (void)printf("%s %s-", title, pchar(*start));
1061 (void)printf("%s ", pchar(*stop));
1062 (void)printf("%ld-%ld\n", (long)startst, (long)stopst);
1066 #define PCHARDONE /* never again */
1068 - pchar - make a character printable
1070 * Is this identical to regchar() over in debug.c? Well, yes. But a
1071 * duplicate here avoids having a debugging-capable regexec.o tied to
1072 * a matching debug.o, and this is convenient. It all disappears in
1073 * the non-debug compilation anyway, so it doesn't matter much.
1075 static char * /* -> representation */
1078 static char pbuf[10];
1080 if (isprint(ch) || ch == ' ')
1081 (void)snprintf(pbuf, sizeof pbuf, "%c", ch);
1083 (void)snprintf(pbuf, sizeof pbuf, "\\%o", ch);