5 * "A fair jaw-cracker dwarf-language must be." --Samwise Gamgee
8 /* NOTE: this is derived from Henry Spencer's regexp code, and should not
9 * confused with the original package (see point 3 below). Thanks, Henry!
12 /* Additional note: this code is very heavily munged from Henry's version
13 * in places. In some spots I've traded clarity for efficiency, so don't
14 * blame Henry for some of the lack of readability.
17 /* The names of the functions have been changed from regcomp and
18 * regexec to pregcomp and pregexec in order to avoid conflicts
19 * with the POSIX routines of the same names.
24 * pregcomp and pregexec -- regsub and regerror are not used in perl
26 * Copyright (c) 1986 by University of Toronto.
27 * Written by Henry Spencer. Not derived from licensed software.
29 * Permission is granted to anyone to use this software for any
30 * purpose on any computer system, and to redistribute it freely,
31 * subject to the following restrictions:
33 * 1. The author is not responsible for the consequences of use of
34 * this software, no matter how awful, even if they arise
37 * 2. The origin of this software must not be misrepresented, either
38 * by explicit claim or by omission.
40 * 3. Altered versions must be plainly marked as such, and must not
41 * be misrepresented as being the original software.
44 **** Alterations to Henry's code are...
46 **** Copyright (c) 1991-1994, Larry Wall
48 **** You may distribute under the terms of either the GNU General Public
49 **** License or the Artistic License, as specified in the README file.
52 * Beware that some of this code is subtly aware of the way operator
53 * precedence is structured in regular expressions. Serious changes in
54 * regular-expression syntax might require a total rethink.
62 # if defined(BUGGY_MSC6)
63 /* MSC 6.00A breaks on op/regexp.t test 85 unless we turn this off */
64 # pragma optimize("a",off)
65 /* But MSC 6.00A is happy with 'w', for aliases only across function calls*/
66 # pragma optimize("w",on )
67 # endif /* BUGGY_MSC6 */
74 #define ISMULT1(c) ((c) == '*' || (c) == '+' || (c) == '?')
75 #define ISMULT2(s) ((*s) == '*' || (*s) == '+' || (*s) == '?' || \
76 ((*s) == '{' && regcurly(s)))
78 #define PERL_META "^$.[()|?+*\\"
80 #define META "^$.[()|?+*\\"
84 #undef SPSTART /* dratted cpp namespace... */
87 * Flags to be passed up and down.
89 #define WORST 0 /* Worst case. */
90 #define HASWIDTH 0x1 /* Known never to match null string. */
91 #define SIMPLE 0x2 /* Simple enough to be STAR/PLUS operand. */
92 #define SPSTART 0x4 /* Starts with * or +. */
93 #define TRYAGAIN 0x8 /* Weeded out a declaration. */
96 * Forward declarations for pregcomp()'s friends.
99 static char *reg _((I32, I32 *));
100 static char *reganode _((char, unsigned short));
101 static char *regatom _((I32 *));
102 static char *regbranch _((I32 *));
103 static void regc _((char));
104 static char *regclass _((void));
105 STATIC I32 regcurly _((char *));
106 static char *regnode _((char));
107 static char *regpiece _((I32 *));
108 static void reginsert _((char, char *));
109 static void regoptail _((char *, char *));
110 static void regset _((char *, I32));
111 static void regtail _((char *, char *));
112 static char* nextchar _((void));
115 - pregcomp - compile a regular expression into internal code
117 * We can't allocate space until we know how big the compiled form will be,
118 * but we can't compile it (and thus know how big it is) until we've got a
119 * place to put the code. So we cheat: we compile it twice, once with code
120 * generation turned off and size counting turned on, and once "for real".
121 * This also means that we don't allocate space until we are sure that the
122 * thing really will compile successfully, and we never have to move the
123 * code and thus invalidate pointers into it. (Note that it has to be in
124 * one piece because free() must be able to free it all.) [NB: not true in perl]
126 * Beware that the optimization-preparation code in here knows about some
127 * of the structure of the compiled regexp. [I'll say.]
130 pregcomp(exp,xend,pm)
137 register SV *longish;
140 register char *first;
150 croak("NULL regexp argument");
152 regprecomp = savepvn(exp, xend - exp);
153 regflags = pm->op_pmflags;
156 /* First pass: determine size, legality. */
164 if (reg(0, &flags) == NULL) {
165 Safefree(regprecomp);
170 /* Small enough for pointer-storage convention? */
171 if (regsize >= 32767L) /* Probably could be 65535L. */
172 FAIL("regexp too big");
174 /* Allocate space and initialize. */
175 Newc(1001, r, sizeof(regexp) + (unsigned)regsize, char, regexp);
177 FAIL("regexp out of space");
178 r->prelen = xend - exp;
179 r->precomp = regprecomp;
180 r->subbeg = r->subbase = NULL;
182 /* Second pass: emit code. */
187 regcode = r->program;
189 if (reg(0, &flags) == NULL)
192 /* Dig out information for optimizations. */
193 pm->op_pmflags = regflags;
194 r->regstart = Nullsv; /* Worst-case defaults. */
198 r->regstclass = Nullch;
199 r->naughty = regnaughty >= 10; /* Probably an expensive pattern. */
200 scan = r->program+1; /* First BRANCH. */
201 if (OP(regnext(scan)) == END) {/* Only one top-level choice. */
202 scan = NEXTOPER(scan);
205 while ((OP(first) == OPEN && (sawopen = 1)) ||
206 (OP(first) == BRANCH && OP(regnext(first)) != BRANCH) ||
207 (OP(first) == PLUS) ||
208 (OP(first) == MINMOD) ||
209 (regkind[(U8)OP(first)] == CURLY && ARG1(first) > 0) ) {
210 if (OP(first) == PLUS)
213 first += regarglen[(U8)OP(first)];
214 first = NEXTOPER(first);
217 /* Starting-point info. */
219 if (OP(first) == EXACT) {
220 r->regstart = newSVpv(OPERAND(first)+1,*OPERAND(first));
221 if (SvCUR(r->regstart) > !sawstudy)
222 fbm_compile(r->regstart);
223 (void)SvUPGRADE(r->regstart, SVt_PVBM);
225 else if (strchr(simple+2,OP(first)))
226 r->regstclass = first;
227 else if (regkind[(U8)OP(first)] == BOUND ||
228 regkind[(U8)OP(first)] == NBOUND)
229 r->regstclass = first;
230 else if (regkind[(U8)OP(first)] == BOL) {
231 r->reganch = ROPT_ANCH;
232 first = NEXTOPER(first);
235 else if ((OP(first) == STAR &&
236 regkind[(U8)OP(NEXTOPER(first))] == ANY) &&
237 !(r->reganch & ROPT_ANCH) )
239 /* turn .* into ^.* with an implied $*=1 */
240 r->reganch = ROPT_ANCH | ROPT_IMPLICIT;
241 first = NEXTOPER(first);
244 if (sawplus && (!sawopen || !regsawback))
245 r->reganch |= ROPT_SKIP; /* x+ must match 1st of run */
247 DEBUG_r(PerlIO_printf(Perl_debug_log, "first %d next %d offset %d\n",
248 OP(first), OP(NEXTOPER(first)), first - scan));
250 * If there's something expensive in the r.e., find the
251 * longest literal string that must appear and make it the
252 * regmust. Resolve ties in favor of later strings, since
253 * the regstart check works with the beginning of the r.e.
254 * and avoiding duplication strengthens checking. Not a
255 * strong reason, but sufficient in the absence of others.
256 * [Now we resolve ties in favor of the earlier string if
257 * it happens that curback has been invalidated, since the
258 * earlier string may buy us something the later one won't.]
260 longish = newSVpv("",0);
261 longest = newSVpv("",0);
267 while (OP(scan) != END) {
268 if (OP(scan) == BRANCH) {
269 if (OP(regnext(scan)) == BRANCH) {
271 while (OP(scan) == BRANCH)
272 scan = regnext(scan);
274 else /* single branch is ok */
275 scan = NEXTOPER(scan);
278 if (OP(scan) == UNLESSM) {
280 scan = regnext(scan);
283 if (OP(scan) == EXACT) {
287 while (OP(t = regnext(scan)) == CLOSE)
289 minlen += *OPERAND(first);
290 if (curback - backish == len) {
291 sv_catpvn(longish, OPERAND(first)+1,
293 len += *OPERAND(first);
294 curback += *OPERAND(first);
295 first = regnext(scan);
297 else if (*OPERAND(first) >= len + (curback >= 0)) {
298 len = *OPERAND(first);
299 sv_setpvn(longish, OPERAND(first)+1,len);
302 first = regnext(scan);
305 curback += *OPERAND(first);
307 else if (strchr(varies,OP(scan))) {
310 if (SvCUR(longish) > SvCUR(longest)) {
311 sv_setsv(longest,longish);
314 sv_setpvn(longish,"",0);
315 if (OP(scan) == PLUS && strchr(simple,OP(NEXTOPER(scan))))
317 else if (regkind[(U8)OP(scan)] == CURLY &&
318 strchr(simple,OP(NEXTOPER(scan)+4)))
319 minlen += ARG1(scan);
321 else if (strchr(simple,OP(scan))) {
325 if (SvCUR(longish) > SvCUR(longest)) {
326 sv_setsv(longest,longish);
329 sv_setpvn(longish,"",0);
331 scan = regnext(scan);
334 /* Prefer earlier on tie, unless we can tail match latter */
336 if (SvCUR(longish) + (regkind[(U8)OP(first)] == EOL)
339 sv_setsv(longest,longish);
343 sv_setpvn(longish,"",0);
346 || !fbm_instr((unsigned char*) SvPVX(r->regstart),
347 (unsigned char *) (SvPVX(r->regstart)
348 + SvCUR(r->regstart)),
351 r->regmust = longest;
354 r->regback = backest;
355 if (SvCUR(longest) > !(sawstudy || regkind[(U8)OP(first)] == EOL))
356 fbm_compile(r->regmust);
357 (void)SvUPGRADE(r->regmust, SVt_PVBM);
358 BmUSEFUL(r->regmust) = 100;
359 if (regkind[(U8)OP(first)] == EOL && SvCUR(longish))
360 SvTAIL_on(r->regmust);
363 SvREFCNT_dec(longest);
366 SvREFCNT_dec(longish);
369 r->nparens = regnpar - 1;
371 Newz(1002, r->startp, regnpar, char*);
372 Newz(1002, r->endp, regnpar, char*);
378 - reg - regular expression, i.e. main body or parenthesized thing
380 * Caller must absorb opening parenthesis.
382 * Combining parenthesis handling with the base level of regular expression
383 * is a trifle forced, but the need to tie the tails of the branches to what
384 * follows makes it hard to avoid.
388 I32 paren; /* Parenthesized? */
393 register char *ender = 0;
394 register I32 parno = 0;
397 *flagp = HASWIDTH; /* Tentatively. */
399 /* Make an OPEN node, if parenthesized. */
401 if (*regparse == '?') {
412 croak("Sequence (?%c...) not implemented", paren);
415 while (*regparse && *regparse != ')')
417 if (*regparse != ')')
418 croak("Sequence (?#... not terminated");
424 while (*regparse && strchr("iogmsx", *regparse))
425 pmflag(®flags, *regparse++);
426 if (*regparse != ')')
427 croak("Sequence (?%c...) not recognized", *regparse);
436 ret = reganode(OPEN, parno);
441 /* Pick up the branches, linking them together. */
442 br = regbranch(&flags);
446 regtail(ret, br); /* OPEN -> first. */
449 if (!(flags&HASWIDTH))
451 *flagp |= flags&SPSTART;
452 while (*regparse == '|') {
454 br = regbranch(&flags);
457 regtail(ret, br); /* BRANCH -> BRANCH. */
458 if (!(flags&HASWIDTH))
460 *flagp |= flags&SPSTART;
463 /* Make a closing node, and hook it on the end. */
466 ender = regnode(NOTHING);
469 ender = reganode(CLOSE, parno);
473 ender = regnode(SUCCEED);
477 ender = regnode(END);
482 /* Hook the tails of the branches to the closing node. */
483 for (br = ret; br != NULL; br = regnext(br))
484 regoptail(br, ender);
487 reginsert(IFMATCH,ret);
488 regtail(ret, regnode(NOTHING));
490 else if (paren == '!') {
491 reginsert(UNLESSM,ret);
492 regtail(ret, regnode(NOTHING));
495 /* Check for proper termination. */
496 if (paren && (regparse >= regxend || *nextchar() != ')')) {
497 FAIL("unmatched () in regexp");
498 } else if (!paren && regparse < regxend) {
499 if (*regparse == ')') {
500 FAIL("unmatched () in regexp");
502 FAIL("junk on end of regexp"); /* "Can't happen". */
510 - regbranch - one alternative of an | operator
512 * Implements the concatenation operator.
519 register char *chain;
520 register char *latest;
523 *flagp = WORST; /* Tentatively. */
525 ret = regnode(BRANCH);
529 while (regparse < regxend && *regparse != '|' && *regparse != ')') {
531 latest = regpiece(&flags);
532 if (latest == NULL) {
533 if (flags & TRYAGAIN)
537 *flagp |= flags&HASWIDTH;
538 if (chain == NULL) /* First piece. */
539 *flagp |= flags&SPSTART;
542 regtail(chain, latest);
546 if (chain == NULL) /* Loop ran zero times. */
547 (void) regnode(NOTHING);
553 - regpiece - something followed by possible [*+?]
555 * Note that the branching code sequences used for ? and the general cases
556 * of * and + are somewhat optimized: they use the same NOTHING node as
557 * both the endmarker for their branch list and the body of the last branch.
558 * It might seem that this node could be dispensed with entirely, but the
559 * endmarker role is not redundant.
569 char *origparse = regparse;
574 ret = regatom(&flags);
576 if (flags & TRYAGAIN)
582 if (op == '(' && regparse[1] == '?' && regparse[2] == '#') {
583 while (op && op != ')')
591 if (op == '{' && regcurly(regparse)) {
594 while (isDIGIT(*next) || *next == ',') {
603 if (*next == '}') { /* got one */
607 min = atoi(regparse);
613 if (!max && *maxpos != '0')
614 max = 32767; /* meaning "infinity" */
619 if ((flags&SIMPLE)) {
620 regnaughty += 2 + regnaughty / 2;
621 reginsert(CURLY, ret);
624 regnaughty += 4 + regnaughty; /* compound interest */
625 regtail(ret, regnode(WHILEM));
626 reginsert(CURLYX,ret);
627 regtail(ret, regnode(NOTHING));
631 *flagp = (WORST|HASWIDTH);
632 if (max && max < min)
633 croak("Can't do {n,m} with n > m");
634 if (regcode != ®dummy) {
636 *(unsigned short *)(ret+3) = min;
637 *(unsigned short *)(ret+5) = max;
639 ret[3] = min >> 8; ret[4] = min & 0377;
640 ret[5] = max >> 8; ret[6] = max & 0377;
654 *flagp = (op != '+') ? (WORST|SPSTART) : (WORST|HASWIDTH);
656 if (op == '*' && (flags&SIMPLE)) {
657 reginsert(STAR, ret);
660 else if (op == '*') {
663 } else if (op == '+' && (flags&SIMPLE)) {
664 reginsert(PLUS, ret);
667 else if (op == '+') {
670 } else if (op == '?') {
675 if (dowarn && regcode != ®dummy && !(flags&HASWIDTH) && max > 10000) {
676 warn("%.*s matches null string many times",
677 regparse - origparse, origparse);
680 if (*regparse == '?') {
682 reginsert(MINMOD, ret);
684 regtail(ret, ret + 4);
686 regtail(ret, ret + 3);
689 if (ISMULT2(regparse))
690 FAIL("nested *?+ in regexp");
696 - regatom - the lowest level
698 * Optimization: gobbles an entire sequence of ordinary characters so that
699 * it can turn them into a single node, which is smaller to store and
700 * faster to run. Backslashed characters are exceptions, each becoming a
701 * separate node; the code is simpler that way and it's not worth fixing.
703 * [Yes, it is worth fixing, some scripts can run twice the speed.]
709 register char *ret = 0;
712 *flagp = WORST; /* Tentatively. */
718 if (regflags & PMf_MULTILINE)
720 else if (regflags & PMf_SINGLELINE)
727 if (regflags & PMf_MULTILINE)
729 else if (regflags & PMf_SINGLELINE)
736 if (regflags & PMf_SINGLELINE)
741 *flagp |= HASWIDTH|SIMPLE;
746 *flagp |= HASWIDTH|SIMPLE;
750 ret = reg(1, &flags);
752 if (flags & TRYAGAIN)
756 *flagp |= flags&(HASWIDTH|SPSTART);
760 if (flags & TRYAGAIN) {
764 croak("internal urp in regexp at /%s/", regparse);
765 /* Supposed to be caught earlier. */
770 FAIL("?+* follows nothing in regexp");
773 switch (*++regparse) {
790 ret = regnode((regflags & PMf_LOCALE) ? ALNUML : ALNUM);
791 *flagp |= HASWIDTH|SIMPLE;
795 ret = regnode((regflags & PMf_LOCALE) ? NALNUML : NALNUM);
796 *flagp |= HASWIDTH|SIMPLE;
800 ret = regnode((regflags & PMf_LOCALE) ? BOUNDL : BOUND);
805 ret = regnode((regflags & PMf_LOCALE) ? NBOUNDL : NBOUND);
810 ret = regnode((regflags & PMf_LOCALE) ? SPACEL : SPACE);
811 *flagp |= HASWIDTH|SIMPLE;
815 ret = regnode((regflags & PMf_LOCALE) ? NSPACEL : NSPACE);
816 *flagp |= HASWIDTH|SIMPLE;
820 ret = regnode(DIGIT);
821 *flagp |= HASWIDTH|SIMPLE;
825 ret = regnode(NDIGIT);
826 *flagp |= HASWIDTH|SIMPLE;
839 case '1': case '2': case '3': case '4':
840 case '5': case '6': case '7': case '8': case '9':
842 I32 num = atoi(regparse);
844 if (num > 9 && num >= regnpar)
848 ret = reganode(REF, num);
850 while (isDIGIT(*regparse))
858 if (regparse >= regxend)
859 FAIL("trailing \\ in regexp");
867 if (regflags & PMf_EXTENDED) {
868 while (regparse < regxend && *regparse != '\n') regparse++;
869 if (regparse < regxend)
884 ret = regnode((regflags & PMf_FOLD)
885 ? ((regflags & PMf_LOCALE) ? EXACTFL : EXACTF)
887 regc(0); /* save spot for len */
888 for (len = 0, p = regparse - 1;
889 len < 127 && p < regxend;
942 ender = scan_hex(++p, 2, &numlen);
947 ender = UCHARAT(p++);
948 ender = toCTRL(ender);
950 case '0': case '1': case '2': case '3':case '4':
951 case '5': case '6': case '7': case '8':case '9':
953 (isDIGIT(p[1]) && atoi(p) >= regnpar) ) {
954 ender = scan_oct(p, 3, &numlen);
964 FAIL("trailing \\ in regexp");
972 if (regflags & PMf_EXTENDED) {
973 while (p < regxend && *p != '\n') p++;
976 case ' ': case '\t': case '\n': case '\r': case '\f': case '\v':
977 if (regflags & PMf_EXTENDED) {
987 if (ISMULT2(p)) { /* Back off on ?+*. */
1002 FAIL("internal disaster in regexp");
1007 if (regcode != ®dummy)
1008 *OPERAND(ret) = len;
1022 if (opnd == ®dummy)
1025 opnd[1 + (c >> 3)] |= (1 << (c & 7));
1031 register char *opnd;
1033 register I32 lastclass = 1234;
1034 register I32 range = 0;
1039 ret = regnode(ANYOF);
1041 for (class = 0; class < 33; class++)
1043 if (*regparse == '^') { /* Complement of range. */
1046 if (opnd != ®dummy)
1047 *opnd |= ANYOF_INVERT;
1049 if (opnd != ®dummy) {
1050 if (regflags & PMf_FOLD)
1051 *opnd |= ANYOF_FOLD;
1052 if (regflags & PMf_LOCALE)
1053 *opnd |= ANYOF_LOCALE;
1055 if (*regparse == ']' || *regparse == '-')
1056 goto skipcond; /* allow 1st char to be ] or - */
1057 while (regparse < regxend && *regparse != ']') {
1059 class = UCHARAT(regparse++);
1060 if (class == '\\') {
1061 class = UCHARAT(regparse++);
1064 if (regflags & PMf_LOCALE) {
1065 if (opnd != ®dummy)
1066 *opnd |= ANYOF_ALNUML;
1069 for (class = 0; class < 256; class++)
1071 regset(opnd, class);
1076 if (regflags & PMf_LOCALE) {
1077 if (opnd != ®dummy)
1078 *opnd |= ANYOF_NALNUML;
1081 for (class = 0; class < 256; class++)
1082 if (!isALNUM(class))
1083 regset(opnd, class);
1088 if (regflags & PMf_LOCALE) {
1089 if (opnd != ®dummy)
1090 *opnd |= ANYOF_SPACEL;
1093 for (class = 0; class < 256; class++)
1095 regset(opnd, class);
1100 if (regflags & PMf_LOCALE) {
1101 if (opnd != ®dummy)
1102 *opnd |= ANYOF_NSPACEL;
1105 for (class = 0; class < 256; class++)
1106 if (!isSPACE(class))
1107 regset(opnd, class);
1112 for (class = '0'; class <= '9'; class++)
1113 regset(opnd, class);
1117 for (class = 0; class < '0'; class++)
1118 regset(opnd, class);
1119 for (class = '9' + 1; class < 256; class++)
1120 regset(opnd, class);
1145 class = scan_hex(regparse, 2, &numlen);
1149 class = UCHARAT(regparse++);
1150 class = toCTRL(class);
1152 case '0': case '1': case '2': case '3': case '4':
1153 case '5': case '6': case '7': case '8': case '9':
1154 class = scan_oct(--regparse, 3, &numlen);
1160 if (lastclass > class)
1161 FAIL("invalid [] range in regexp");
1166 if (*regparse == '-' && regparse+1 < regxend &&
1167 regparse[1] != ']') {
1170 continue; /* do it next time */
1173 for ( ; lastclass <= class; lastclass++)
1174 regset(opnd, lastclass);
1177 if (*regparse != ']')
1178 FAIL("unmatched [] in regexp");
1186 char* retval = regparse++;
1189 if (*regparse == '(' && regparse[1] == '?' &&
1190 regparse[2] == '#') {
1191 while (*regparse && *regparse != ')')
1196 if (regflags & PMf_EXTENDED) {
1197 if (isSPACE(*regparse)) {
1201 else if (*regparse == '#') {
1202 while (*regparse && *regparse != '\n')
1213 - regnode - emit a node
1215 #ifdef CAN_PROTOTYPE
1216 static char * /* Location. */
1219 static char * /* Location. */
1228 if (ret == ®dummy) {
1239 if (!((long)ret & 1))
1245 *ptr++ = '\0'; /* Null "next" pointer. */
1253 - reganode - emit a node with an argument
1255 #ifdef CAN_PROTOTYPE
1256 static char * /* Location. */
1257 reganode(char op, unsigned short arg)
1259 static char * /* Location. */
1269 if (ret == ®dummy) {
1280 if (!((long)ret & 1))
1286 *ptr++ = '\0'; /* Null "next" pointer. */
1289 *(unsigned short *)(ret+3) = arg;
1291 ret[3] = arg >> 8; ret[4] = arg & 0377;
1300 - regc - emit (if appropriate) a byte of code
1302 #ifdef CAN_PROTOTYPE
1311 if (regcode != ®dummy)
1318 - reginsert - insert an operator in front of already-emitted operand
1320 * Means relocating the operand.
1322 #ifdef CAN_PROTOTYPE
1324 reginsert(char op, char *opnd)
1334 register char *place;
1335 register int offset = (regkind[(U8)op] == CURLY ? 4 : 0);
1337 if (regcode == ®dummy) {
1339 regsize += 4 + offset;
1341 regsize += 3 + offset;
1348 regcode += 4 + offset;
1350 regcode += 3 + offset;
1356 place = opnd; /* Op node, where operand used to be. */
1360 while (offset-- > 0)
1368 - regtail - set the next-pointer at the end of a node chain
1375 register char *scan;
1376 register char *temp;
1377 register I32 offset;
1382 /* Find last node. */
1385 temp = regnext(scan);
1392 offset = val - scan;
1394 *(short*)(scan+1) = offset;
1399 if (OP(scan) == BACK)
1400 offset = scan - val;
1402 offset = val - scan;
1403 *(scan+1) = (offset>>8)&0377;
1404 *(scan+2) = offset&0377;
1409 - regoptail - regtail on operand of first argument; nop if operandless
1416 /* "Operandless" and "op != BRANCH" are synonymous in practice. */
1417 if (p == NULL || p == ®dummy || regkind[(U8)OP(p)] != BRANCH)
1419 regtail(NEXTOPER(p), val);
1423 - regcurly - a little FSA that accepts {\d+,?\d*}
1447 - regdump - dump a regexp onto Perl_debug_log in vaguely comprehensible form
1454 register char op = EXACT; /* Arbitrary non-END op. */
1455 register char *next;
1459 while (op != END) { /* While that wasn't END last time... */
1465 PerlIO_printf(Perl_debug_log, "%2d%s", s-r->program, regprop(s)); /* Where, what. */
1467 s += regarglen[(U8)op];
1468 if (next == NULL) /* Next ptr. */
1469 PerlIO_printf(Perl_debug_log, "(0)");
1471 PerlIO_printf(Perl_debug_log, "(%d)", (s-r->program)+(next-s));
1476 if (regkind[(U8)op] == EXACT) {
1477 /* Literal string, where present. */
1479 (void)PerlIO_putc(Perl_debug_log, ' ');
1480 (void)PerlIO_putc(Perl_debug_log, '<');
1481 while (*s != '\0') {
1482 (void)PerlIO_putc(Perl_debug_log,*s);
1485 (void)PerlIO_putc(Perl_debug_log, '>');
1488 (void)PerlIO_putc(Perl_debug_log, '\n');
1491 /* Header fields of interest. */
1493 PerlIO_printf(Perl_debug_log, "start `%s' ", SvPVX(r->regstart));
1495 PerlIO_printf(Perl_debug_log, "stclass `%s' ", regprop(r->regstclass));
1496 if (r->reganch & ROPT_ANCH)
1497 PerlIO_printf(Perl_debug_log, "anchored ");
1498 if (r->reganch & ROPT_SKIP)
1499 PerlIO_printf(Perl_debug_log, "plus ");
1500 if (r->reganch & ROPT_IMPLICIT)
1501 PerlIO_printf(Perl_debug_log, "implicit ");
1502 if (r->regmust != NULL)
1503 PerlIO_printf(Perl_debug_log, "must have \"%s\" back %ld ", SvPVX(r->regmust),
1505 PerlIO_printf(Perl_debug_log, "minlen %ld ", (long) r->minlen);
1506 PerlIO_printf(Perl_debug_log, "\n");
1510 - regprop - printable representation of opcode
1516 register char *p = 0;
1518 (void) strcpy(buf, ":");
1582 (void)sprintf(buf+strlen(buf), "CURLY {%d,%d}", ARG1(op),ARG2(op));
1586 (void)sprintf(buf+strlen(buf), "CURLYX {%d,%d}", ARG1(op),ARG2(op));
1590 (void)sprintf(buf+strlen(buf), "REF%d", ARG1(op));
1594 (void)sprintf(buf+strlen(buf), "OPEN%d", ARG1(op));
1598 (void)sprintf(buf+strlen(buf), "CLOSE%d", ARG1(op));
1656 FAIL("corrupted regexp opcode");
1659 (void) strcat(buf, p);
1662 #endif /* DEBUGGING */
1671 Safefree(r->precomp);
1672 r->precomp = Nullch;
1675 Safefree(r->subbase);
1676 r->subbase = Nullch;
1679 SvREFCNT_dec(r->regmust);
1680 r->regmust = Nullsv;
1683 SvREFCNT_dec(r->regstart);
1684 r->regstart = Nullsv;
1686 Safefree(r->startp);