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. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)engine.c 8.5 (Berkeley) 3/20/94
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
42 * The matching engine and friends. This file is #included by regexec.c
43 * after suitable #defines of a variety of macros used herein, so that
44 * different state representations can be used without duplicating masses
49 #define matcher smatcher
51 #define dissect sdissect
52 #define backref sbackref
59 #define matcher lmatcher
61 #define dissect ldissect
62 #define backref lbackref
69 #define matcher mmatcher
71 #define dissect mdissect
72 #define backref mbackref
79 /* another structure passed up and down to avoid zillions of parameters */
83 regmatch_t *pmatch; /* [nsub+1] (0 element unused) */
84 const char *offp; /* offsets work from here */
85 const char *beginp; /* start of string -- virtual NUL precedes */
86 const char *endp; /* end of string -- virtual NUL here */
87 const char *coldp; /* can be no match starting before here */
88 const char **lastpos; /* [nplus+1] */
90 states st; /* current states */
91 states fresh; /* states for a fresh start */
92 states tmp; /* temporary */
93 states empty; /* empty set of states */
94 mbstate_t mbs; /* multibyte conversion state */
97 /* ========= begin header generated by ./mkh ========= */
102 /* === engine.c === */
103 static int matcher(struct re_guts *g, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags);
104 static const char *dissect(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst);
105 static const char *backref(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst, sopno lev, int);
106 static const char *walk(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst, bool fast);
107 static states step(struct re_guts *g, sopno start, sopno stop, states bef, wint_t ch, states aft);
108 #define MAX_RECURSION 100
111 #define BOLEOL (BOL-2)
112 #define NOTHING (BOL-3)
115 #define BADCHAR (BOL-6)
116 #define NONCHAR(c) ((c) <= OUT)
118 static void print(struct match *m, const char *caption, states st, int ch, FILE *d);
121 static void at(struct match *m, const char *title, const char *start, const char *stop, sopno startst, sopno stopst);
124 static const char *pchar(int ch);
130 /* ========= end header generated by ./mkh ========= */
133 #define SP(t, s, c) print(m, t, s, c, stdout)
134 #define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2)
135 #define NOTE(str) { if (m->eflags®_TRACE) printf("=%s\n", (str)); }
137 #define SP(t, s, c) /* nothing */
138 #define AT(t, p1, p2, s1, s2) /* nothing */
139 #define NOTE(s) /* nothing */
143 - matcher - the actual matching engine
144 == static int matcher(struct re_guts *g, const char *string, \
145 == size_t nmatch, regmatch_t pmatch[], int eflags);
147 static int /* 0 success, REG_NOMATCH failure */
148 matcher(struct re_guts *g,
157 struct match *m = &mv;
158 const char *dp = NULL;
159 const sopno gf = g->firststate+1; /* +1 for OEND */
160 const sopno gl = g->laststate;
163 /* Boyer-Moore algorithms variables */
166 const char *mustfirst;
167 const char *mustlast;
171 /* simplify the situation where possible */
172 if (g->cflags®_NOSUB)
174 if (eflags®_STARTEND) {
175 start = string + pmatch[0].rm_so;
176 stop = string + pmatch[0].rm_eo;
179 stop = start + strlen(start);
184 /* prescreening; this does wonders for this rather slow code */
185 if (g->must != NULL) {
186 if (g->charjump != NULL && g->matchjump != NULL) {
188 mustlast = g->must + g->mlen - 1;
189 charjump = g->charjump;
190 matchjump = g->matchjump;
192 for (dp = start+g->mlen-1; dp < stop;) {
193 /* Fast skip non-matches */
194 while (dp < stop && charjump[(int)*dp])
195 dp += charjump[(int)*dp];
201 /* We depend on not being used for
202 * for strings of length 1
204 while (*--dp == *--pp && pp != mustfirst);
209 /* Jump to next possible match */
210 mj = matchjump[pp - mustfirst];
211 cj = charjump[(int)*dp];
212 dp += (cj < mj ? mj : cj);
218 for (dp = start; dp < stop; dp++)
219 if (*dp == g->must[0] &&
220 stop - dp >= g->mlen &&
221 memcmp(dp, g->must, (size_t)g->mlen) == 0)
223 if (dp == stop) /* we didn't find g->must */
228 /* match struct setup */
244 /* Adjust start according to moffset, to speed things up */
245 if (dp != NULL && g->moffset > -1)
246 start = ((dp - g->moffset) < start) ? start : dp - g->moffset;
248 SP("mloop", m->st, *start);
250 /* this loop does only one repetition except for backrefs */
252 endp = walk(m, start, stop, gf, gl, true);
253 if (endp == NULL) { /* a miss */
254 if (m->pmatch != NULL)
255 free((char *)m->pmatch);
256 if (m->lastpos != NULL)
257 free((char *)m->lastpos);
261 if (nmatch == 0 && !g->backrefs)
262 break; /* no further info needed */
265 assert(m->coldp != NULL);
267 NOTE("finding start");
268 endp = walk(m, m->coldp, stop, gf, gl, false);
271 assert(m->coldp < m->endp);
272 m->coldp += XMBRTOWC(NULL, m->coldp,
273 m->endp - m->coldp, &m->mbs, 0);
275 if (nmatch == 1 && !g->backrefs)
276 break; /* no further info needed */
278 /* oh my, he wants the subexpressions... */
279 if (m->pmatch == NULL)
280 m->pmatch = (regmatch_t *)malloc((m->g->nsub + 1) *
282 if (m->pmatch == NULL) {
286 for (i = 1; i <= m->g->nsub; i++)
287 m->pmatch[i].rm_so = m->pmatch[i].rm_eo = -1;
288 if (!g->backrefs && !(m->eflags®_BACKR)) {
290 dp = dissect(m, m->coldp, endp, gf, gl);
292 if (g->nplus > 0 && m->lastpos == NULL)
293 m->lastpos = malloc((g->nplus+1) *
294 sizeof(const char *));
295 if (g->nplus > 0 && m->lastpos == NULL) {
300 NOTE("backref dissect");
301 dp = backref(m, m->coldp, endp, gf, gl, (sopno)0, 0);
306 /* uh-oh... we couldn't find a subexpression-level match */
307 assert(g->backrefs); /* must be back references doing it */
308 assert(g->nplus == 0 || m->lastpos != NULL);
310 if (dp != NULL || endp <= m->coldp)
313 endp = walk(m, m->coldp, endp-1, gf, gl, false);
316 /* try it on a shorter possibility */
318 for (i = 1; i <= m->g->nsub; i++) {
319 assert(m->pmatch[i].rm_so == -1);
320 assert(m->pmatch[i].rm_eo == -1);
323 NOTE("backoff dissect");
324 dp = backref(m, m->coldp, endp, gf, gl, (sopno)0, 0);
326 assert(dp == NULL || dp == endp);
327 if (dp != NULL) /* found a shorter one */
330 /* despite initial appearances, there is no match here */
332 /* recycle starting later */
333 start = m->coldp + XMBRTOWC(NULL, m->coldp,
334 stop - m->coldp, &m->mbs, 0);
335 assert(start <= stop);
338 /* fill in the details if requested */
340 pmatch[0].rm_so = m->coldp - m->offp;
341 pmatch[0].rm_eo = endp - m->offp;
344 assert(m->pmatch != NULL);
345 for (i = 1; i < nmatch; i++)
347 pmatch[i] = m->pmatch[i];
349 pmatch[i].rm_so = -1;
350 pmatch[i].rm_eo = -1;
354 if (m->pmatch != NULL)
355 free((char *)m->pmatch);
356 if (m->lastpos != NULL)
357 free((char *)m->lastpos);
363 - dissect - figure out what matched what, no back references
364 == static const char *dissect(struct match *m, const char *start, \
365 == const char *stop, sopno startst, sopno stopst);
367 static const char * /* == stop (success) always */
368 dissect(struct match *m,
375 sopno ss; /* start sop of current subRE */
376 sopno es; /* end sop of current subRE */
377 const char *sp; /* start of string matched by it */
378 const char *stp; /* string matched by it cannot pass here */
379 const char *rest; /* start of rest of string */
380 const char *tail; /* string unmatched by rest of RE */
381 sopno ssub; /* start sop of subsubRE */
382 sopno esub; /* end sop of subsubRE */
383 const char *ssp; /* start of string matched by subsubRE */
384 const char *sep; /* end of string matched by subsubRE */
385 const char *oldssp; /* previous ssp */
388 AT("diss", start, stop, startst, stopst);
390 for (ss = startst; ss < stopst; ss = es) {
391 /* identify end of subRE */
393 switch (OP(m->g->strip[es])) {
396 es += OPND(m->g->strip[es]);
399 while (OP(m->g->strip[es]) != O_CH)
400 es += OPND(m->g->strip[es]);
405 /* figure out what it matched */
406 switch (OP(m->g->strip[ss])) {
411 sp += XMBRTOWC(NULL, sp, stop - start, &m->mbs, 0);
420 sp += XMBRTOWC(NULL, sp, stop - start, &m->mbs, 0);
426 /* cases where length of match is hard to find */
430 /* how long could this one be? */
431 rest = walk(m, sp, stp, ss, es, false);
432 assert(rest != NULL); /* it did match */
433 /* could the rest match the rest? */
434 tail = walk(m, rest, stop, es, stopst, false);
437 /* no -- try a shorter match for this one */
439 assert(stp >= sp); /* it did work */
443 /* did innards match? */
444 if (walk(m, sp, rest, ssub, esub, false) != NULL) {
445 dp = dissect(m, sp, rest, ssub, esub);
454 /* how long could this one be? */
455 rest = walk(m, sp, stp, ss, es, false);
456 assert(rest != NULL); /* it did match */
457 /* could the rest match the rest? */
458 tail = walk(m, rest, stop, es, stopst, false);
461 /* no -- try a shorter match for this one */
463 assert(stp >= sp); /* it did work */
469 for (;;) { /* find last match of innards */
470 sep = walk(m, ssp, rest, ssub, esub, false);
471 if (sep == NULL || sep == ssp)
472 break; /* failed or matched null */
473 oldssp = ssp; /* on to next try */
477 /* last successful match */
481 assert(sep == rest); /* must exhaust substring */
482 assert(walk(m, ssp, sep, ssub, esub, false) == rest);
483 dp = dissect(m, ssp, sep, ssub, esub);
490 /* how long could this one be? */
491 rest = walk(m, sp, stp, ss, es, false);
492 assert(rest != NULL); /* it did match */
493 /* could the rest match the rest? */
494 tail = walk(m, rest, stop, es, stopst, false);
497 /* no -- try a shorter match for this one */
499 assert(stp >= sp); /* it did work */
502 esub = ss + OPND(m->g->strip[ss]) - 1;
503 assert(OP(m->g->strip[esub]) == OOR1);
504 for (;;) { /* find first matching branch */
505 if (walk(m, sp, rest, ssub, esub, false) == rest)
506 break; /* it matched all of it */
507 /* that one missed, try next one */
508 assert(OP(m->g->strip[esub]) == OOR1);
510 assert(OP(m->g->strip[esub]) == OOR2);
512 esub += OPND(m->g->strip[esub]);
513 if (OP(m->g->strip[esub]) == OOR2)
516 assert(OP(m->g->strip[esub]) == O_CH);
518 dp = dissect(m, sp, rest, ssub, esub);
530 i = OPND(m->g->strip[ss]);
531 assert(0 < i && i <= m->g->nsub);
532 m->pmatch[i].rm_so = sp - m->offp;
535 i = OPND(m->g->strip[ss]);
536 assert(0 < i && i <= m->g->nsub);
537 m->pmatch[i].rm_eo = sp - m->offp;
550 - backref - figure out what matched what, figuring in back references
551 == static const char *backref(struct match *m, const char *start, \
552 == const char *stop, sopno startst, sopno stopst, sopno lev);
554 static const char * /* == stop (success) or NULL (failure) */
555 backref(struct match *m,
560 sopno lev, /* PLUS nesting level */
564 sopno ss; /* start sop of current subRE */
565 const char *sp; /* start of string matched by it */
566 sopno ssub; /* start sop of subsubRE */
567 sopno esub; /* end sop of subsubRE */
568 const char *ssp; /* start of string matched by subsubRE */
577 AT("back", start, stop, startst, stopst);
580 /* get as far as we can with easy stuff */
582 for (ss = startst; !hard && ss < stopst; ss++)
583 switch (OP(s = m->g->strip[ss])) {
587 sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR);
594 sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR);
601 cs = &m->g->sets[OPND(s)];
602 sp += XMBRTOWC(&wc, sp, stop - sp, &m->mbs, BADCHAR);
603 if (wc == BADCHAR || !CHIN(cs, wc))
607 if ((sp == m->beginp && !(m->eflags®_NOTBOL)) ||
608 (sp > m->offp && sp < m->endp &&
609 *(sp-1) == '\n' && (m->g->cflags®_NEWLINE)))
615 if ( (sp == m->endp && !(m->eflags®_NOTEOL)) ||
616 (sp < m->endp && *sp == '\n' &&
617 (m->g->cflags®_NEWLINE)) )
623 if (sp < m->endp && ISWORD(*sp) &&
624 ((sp == m->beginp && !(m->eflags®_NOTBOL)) ||
625 (sp > m->offp && !ISWORD(*(sp-1)))))
631 if (( (sp == m->endp && !(m->eflags®_NOTEOL)) ||
632 (sp < m->endp && *sp == '\n' &&
633 (m->g->cflags®_NEWLINE)) ||
634 (sp < m->endp && !ISWORD(*sp)) ) &&
635 (sp > m->beginp && ISWORD(*(sp-1))) )
642 case OOR1: /* matches null but needs to skip */
646 assert(OP(s) == OOR2);
648 } while (OP(s = m->g->strip[ss]) != O_CH);
649 /* note that the ss++ gets us past the O_CH */
651 default: /* have to make a choice */
655 if (!hard) { /* that was it! */
660 ss--; /* adjust for the for's final increment */
663 AT("hard", sp, stop, ss, stopst);
666 case OBACK_: /* the vilest depths */
668 assert(0 < i && i <= m->g->nsub);
669 if (m->pmatch[i].rm_eo == -1)
671 assert(m->pmatch[i].rm_so != -1);
672 len = m->pmatch[i].rm_eo - m->pmatch[i].rm_so;
673 if (len == 0 && rec++ > MAX_RECURSION)
675 assert(stop - m->beginp >= len);
677 return(NULL); /* not enough left to match */
678 ssp = m->offp + m->pmatch[i].rm_so;
679 if (memcmp(sp, ssp, len) != 0)
681 while (m->g->strip[ss] != SOP(O_BACK, i))
683 return(backref(m, sp+len, stop, ss+1, stopst, lev, rec));
684 case OQUEST_: /* to null or not */
685 dp = backref(m, sp, stop, ss+1, stopst, lev, rec);
687 return(dp); /* not */
688 return(backref(m, sp, stop, ss+OPND(s)+1, stopst, lev, rec));
690 assert(m->lastpos != NULL);
691 assert(lev+1 <= m->g->nplus);
692 m->lastpos[lev+1] = sp;
693 return(backref(m, sp, stop, ss+1, stopst, lev+1, rec));
695 if (sp == m->lastpos[lev]) /* last pass matched null */
696 return(backref(m, sp, stop, ss+1, stopst, lev-1, rec));
697 /* try another pass */
698 m->lastpos[lev] = sp;
699 dp = backref(m, sp, stop, ss-OPND(s)+1, stopst, lev, rec);
701 return(backref(m, sp, stop, ss+1, stopst, lev-1, rec));
704 case OCH_: /* find the right one, if any */
706 esub = ss + OPND(s) - 1;
707 assert(OP(m->g->strip[esub]) == OOR1);
708 for (;;) { /* find first matching branch */
709 dp = backref(m, sp, stop, ssub, esub, lev, rec);
712 /* that one missed, try next one */
713 if (OP(m->g->strip[esub]) == O_CH)
714 return(NULL); /* there is none */
716 assert(OP(m->g->strip[esub]) == OOR2);
718 esub += OPND(m->g->strip[esub]);
719 if (OP(m->g->strip[esub]) == OOR2)
722 assert(OP(m->g->strip[esub]) == O_CH);
726 case OLPAREN: /* must undo assignment if rest fails */
728 assert(0 < i && i <= m->g->nsub);
729 offsave = m->pmatch[i].rm_so;
730 m->pmatch[i].rm_so = sp - m->offp;
731 dp = backref(m, sp, stop, ss+1, stopst, lev, rec);
734 m->pmatch[i].rm_so = offsave;
736 case ORPAREN: /* must undo assignment if rest fails */
738 assert(0 < i && i <= m->g->nsub);
739 offsave = m->pmatch[i].rm_eo;
740 m->pmatch[i].rm_eo = sp - m->offp;
741 dp = backref(m, sp, stop, ss+1, stopst, lev, rec);
744 m->pmatch[i].rm_eo = offsave;
754 return "shut up gcc";
758 - walk - step through the string either quickly or slowly
759 == static const char *walk(struct match *m, const char *start, \
760 == const char *stop, sopno startst, sopno stopst, bool fast);
762 static const char * /* where it ended, or NULL */
763 walk(struct match *m, const char *start, const char *stop, sopno startst,
764 sopno stopst, bool fast)
767 states fresh = m->fresh;
768 states empty = m->empty;
770 const char *p = start;
772 wint_t lastc; /* previous c */
775 const char *matchp; /* last p at which a match ended */
778 AT("slow", start, stop, startst, stopst);
781 SP("sstart", st, *p);
782 st = step(m->g, startst, stopst, st, NOTHING, st);
786 if (start == m->offp || (start == m->beginp && !(m->eflags®_NOTBOL)))
790 * XXX Wrong if the previous character was multi-byte.
791 * Newline never is (in encodings supported by FreeBSD),
792 * so this only breaks the ISWORD tests below.
794 c = (uch)*(start - 1);
803 clen = XMBRTOWC(&c, p, m->endp - p, &m->mbs, BADCHAR);
805 if (fast && EQ(st, fresh))
808 /* is there an EOL and/or BOL between lastc and c? */
811 if ( (lastc == '\n' && m->g->cflags®_NEWLINE) ||
812 (lastc == OUT && !(m->eflags®_NOTBOL)) ) {
816 if ( (c == '\n' && m->g->cflags®_NEWLINE) ||
817 (c == OUT && !(m->eflags®_NOTEOL)) ) {
818 flagch = (flagch == BOL) ? BOLEOL : EOL;
823 st = step(m->g, startst, stopst, st, flagch, st);
824 SP("sboleol", st, c);
827 /* how about a word boundary? */
828 if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
829 (c != OUT && ISWORD(c)) ) {
832 if ( (lastc != OUT && ISWORD(lastc)) &&
833 (flagch == EOL || (c != OUT && !ISWORD(c))) ) {
836 if (flagch == BOW || flagch == EOW) {
837 st = step(m->g, startst, stopst, st, flagch, st);
838 SP("sboweow", st, c);
842 if (ISSET(st, stopst)) {
848 if (EQ(st, empty) || p == stop || clen > stop - p)
849 break; /* NOTE BREAK OUT */
851 /* no, we must deal with this character */
858 st = step(m->g, startst, stopst, tmp, c, st);
860 assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
865 assert(matchp != NULL);
867 if (ISSET(st, stopst))
868 return (p + XMBRTOWC(NULL, p, stop - p, &m->mbs, 0));
876 - step - map set of states reachable before char to set reachable after
877 == static states step(struct re_guts *g, sopno start, sopno stop, \
878 == states bef, int ch, states aft);
879 == #define BOL (OUT-1)
880 == #define EOL (BOL-1)
881 == #define BOLEOL (BOL-2)
882 == #define NOTHING (BOL-3)
883 == #define BOW (BOL-4)
884 == #define EOW (BOL-5)
885 == #define BADCHAR (BOL-6)
886 == #define NONCHAR(c) ((c) <= OUT)
889 step(struct re_guts *g,
890 sopno start, /* start state within strip */
891 sopno stop, /* state after stop state within strip */
892 states bef, /* states reachable before */
893 wint_t ch, /* character or NONCHAR code */
894 states aft) /* states already known reachable after */
899 onestate here; /* note, macros know this name */
903 for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) {
907 assert(pc == stop-1);
910 /* only characters can match */
911 assert(!NONCHAR(ch) || ch != OPND(s));
916 if (ch == BOL || ch == BOLEOL)
920 if (ch == EOL || ch == BOLEOL)
936 cs = &g->sets[OPND(s)];
937 if (!NONCHAR(ch) && CHIN(cs, ch))
940 case OBACK_: /* ignored here */
944 case OPLUS_: /* forward, this is just an empty */
947 case O_PLUS: /* both forward and back */
949 i = ISSETBACK(aft, OPND(s));
950 BACK(aft, aft, OPND(s));
951 if (!i && ISSETBACK(aft, OPND(s))) {
952 /* oho, must reconsider loop body */
957 case OQUEST_: /* two branches, both forward */
959 FWD(aft, aft, OPND(s));
961 case O_QUEST: /* just an empty */
964 case OLPAREN: /* not significant here */
968 case OCH_: /* mark the first two branches */
970 assert(OP(g->strip[pc+OPND(s)]) == OOR2);
971 FWD(aft, aft, OPND(s));
973 case OOR1: /* done a branch, find the O_CH */
974 if (ISSTATEIN(aft, here)) {
976 OP(s = g->strip[pc+look]) != O_CH;
978 assert(OP(s) == OOR2);
979 FWD(aft, aft, look + 1);
982 case OOR2: /* propagate OCH_'s marking */
984 if (OP(g->strip[pc+OPND(s)]) != O_CH) {
985 assert(OP(g->strip[pc+OPND(s)]) == OOR2);
986 FWD(aft, aft, OPND(s));
989 case O_CH: /* just empty */
992 default: /* ooooops... */
1003 - print - print a set of states
1005 == static void print(struct match *m, const char *caption, states st, \
1006 == int ch, FILE *d);
1010 print(struct match *m,
1011 const char *caption,
1016 struct re_guts *g = m->g;
1020 if (!(m->eflags®_TRACE))
1023 fprintf(d, "%s", caption);
1025 fprintf(d, " %s", pchar(ch));
1026 for (i = 0; i < g->nstates; i++)
1028 fprintf(d, "%s%d", (first) ? "\t" : ", ", i);
1035 - at - print current situation
1037 == static void at(struct match *m, const char *title, const char *start, \
1038 == const char *stop, sopno startst, sopno stopst);
1042 at( struct match *m,
1049 if (!(m->eflags®_TRACE))
1052 printf("%s %s-", title, pchar(*start));
1053 printf("%s ", pchar(*stop));
1054 printf("%ld-%ld\n", (long)startst, (long)stopst);
1058 #define PCHARDONE /* never again */
1060 - pchar - make a character printable
1062 == static const char *pchar(int ch);
1065 * Is this identical to regchar() over in debug.c? Well, yes. But a
1066 * duplicate here avoids having a debugging-capable regexec.o tied to
1067 * a matching debug.o, and this is convenient. It all disappears in
1068 * the non-debug compilation anyway, so it doesn't matter much.
1070 static const char * /* -> representation */
1073 static char pbuf[10];
1075 if (isprint((uch)ch) || ch == ' ')
1076 sprintf(pbuf, "%c", ch);
1078 sprintf(pbuf, "\\%o", ch);