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, 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)
135 I32 fold = pm->op_pmflags & PMf_FOLD;
138 register SV *longish;
141 register char *first;
151 croak("NULL regexp argument");
153 /* First pass: determine size, legality. */
154 regflags = pm->op_pmflags;
157 regprecomp = savepvn(exp,xend-exp);
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. */
175 Newc(1001, r, sizeof(regexp) + (unsigned)regsize, char, regexp);
177 FAIL("regexp out of space");
179 /* Second pass: emit code. */
180 r->prelen = xend-exp;
181 r->precomp = regprecomp;
182 r->subbeg = r->subbase = NULL;
186 regcode = r->program;
188 if (reg(0, &flags) == NULL)
191 /* Dig out information for optimizations. */
192 pm->op_pmflags = regflags;
193 fold = pm->op_pmflags & PMf_FOLD;
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) == EXACTLY) {
220 r->regstart = newSVpv(OPERAND(first)+1,*OPERAND(first));
221 if (SvCUR(r->regstart) > !(sawstudy|fold))
222 fbm_compile(r->regstart,fold);
224 sv_upgrade(r->regstart, SVt_PVBM);
226 else if (strchr(simple+2,OP(first)))
227 r->regstclass = first;
228 else if (OP(first) == BOUND || 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(fprintf(stderr,"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) == EXACTLY) {
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);
348 !fbm_instr((unsigned char*) SvPVX(r->regstart),
349 (unsigned char *) SvPVX(r->regstart)
350 + SvCUR(r->regstart),
355 r->regmust = longest;
358 r->regback = backest;
359 if (SvCUR(longest) > !(sawstudy || fold ||
360 regkind[(U8)OP(first)]==EOL))
361 fbm_compile(r->regmust,fold);
362 (void)SvUPGRADE(r->regmust, SVt_PVBM);
363 BmUSEFUL(r->regmust) = 100;
364 if (regkind[(U8)OP(first)] == EOL && SvCUR(longish))
365 SvTAIL_on(r->regmust);
368 SvREFCNT_dec(longest);
371 SvREFCNT_dec(longish);
374 r->do_folding = fold;
375 r->nparens = regnpar - 1;
377 Newz(1002, r->startp, regnpar, char*);
378 Newz(1002, r->endp, regnpar, char*);
384 - reg - regular expression, i.e. main body or parenthesized thing
386 * Caller must absorb opening parenthesis.
388 * Combining parenthesis handling with the base level of regular expression
389 * is a trifle forced, but the need to tie the tails of the branches to what
390 * follows makes it hard to avoid.
394 I32 paren; /* Parenthesized? */
399 register char *ender = 0;
400 register I32 parno = 0;
403 *flagp = HASWIDTH; /* Tentatively. */
405 /* Make an OPEN node, if parenthesized. */
407 if (*regparse == '?') {
418 croak("Sequence (?%c...) not implemented", paren);
421 while (*regparse && *regparse != ')')
423 if (*regparse != ')')
424 croak("Sequence (?#... not terminated");
430 while (*regparse && strchr("iogmsx", *regparse))
431 pmflag(®flags, *regparse++);
432 if (*regparse != ')')
433 croak("Sequence (?%c...) not recognized", *regparse);
442 ret = reganode(OPEN, parno);
447 /* Pick up the branches, linking them together. */
448 br = regbranch(&flags);
452 regtail(ret, br); /* OPEN -> first. */
455 if (!(flags&HASWIDTH))
457 *flagp |= flags&SPSTART;
458 while (*regparse == '|') {
460 br = regbranch(&flags);
463 regtail(ret, br); /* BRANCH -> BRANCH. */
464 if (!(flags&HASWIDTH))
466 *flagp |= flags&SPSTART;
469 /* Make a closing node, and hook it on the end. */
472 ender = regnode(NOTHING);
475 ender = reganode(CLOSE, parno);
479 ender = regnode(SUCCEED);
483 ender = regnode(END);
488 /* Hook the tails of the branches to the closing node. */
489 for (br = ret; br != NULL; br = regnext(br))
490 regoptail(br, ender);
493 reginsert(IFMATCH,ret);
494 regtail(ret, regnode(NOTHING));
496 else if (paren == '!') {
497 reginsert(UNLESSM,ret);
498 regtail(ret, regnode(NOTHING));
501 /* Check for proper termination. */
502 if (paren && (regparse >= regxend || *nextchar() != ')')) {
503 FAIL("unmatched () in regexp");
504 } else if (!paren && regparse < regxend) {
505 if (*regparse == ')') {
506 FAIL("unmatched () in regexp");
508 FAIL("junk on end of regexp"); /* "Can't happen". */
516 - regbranch - one alternative of an | operator
518 * Implements the concatenation operator.
525 register char *chain;
526 register char *latest;
529 *flagp = WORST; /* Tentatively. */
531 ret = regnode(BRANCH);
535 while (regparse < regxend && *regparse != '|' && *regparse != ')') {
537 latest = regpiece(&flags);
538 if (latest == NULL) {
539 if (flags & TRYAGAIN)
543 *flagp |= flags&HASWIDTH;
544 if (chain == NULL) /* First piece. */
545 *flagp |= flags&SPSTART;
548 regtail(chain, latest);
552 if (chain == NULL) /* Loop ran zero times. */
553 (void) regnode(NOTHING);
559 - regpiece - something followed by possible [*+?]
561 * Note that the branching code sequences used for ? and the general cases
562 * of * and + are somewhat optimized: they use the same NOTHING node as
563 * both the endmarker for their branch list and the body of the last branch.
564 * It might seem that this node could be dispensed with entirely, but the
565 * endmarker role is not redundant.
575 char *origparse = regparse;
580 ret = regatom(&flags);
582 if (flags & TRYAGAIN)
588 if (op == '(' && regparse[1] == '?' && regparse[2] == '#') {
589 while (op && op != ')')
597 if (op == '{' && regcurly(regparse)) {
600 while (isDIGIT(*next) || *next == ',') {
609 if (*next == '}') { /* got one */
613 min = atoi(regparse);
619 if (!max && *maxpos != '0')
620 max = 32767; /* meaning "infinity" */
625 if ((flags&SIMPLE)) {
626 regnaughty += 2 + regnaughty / 2;
627 reginsert(CURLY, ret);
630 regnaughty += 4 + regnaughty; /* compound interest */
631 regtail(ret, regnode(WHILEM));
632 reginsert(CURLYX,ret);
633 regtail(ret, regnode(NOTHING));
637 *flagp = (WORST|HASWIDTH);
638 if (max && max < min)
639 croak("Can't do {n,m} with n > m");
640 if (regcode != ®dummy) {
642 *(unsigned short *)(ret+3) = min;
643 *(unsigned short *)(ret+5) = max;
645 ret[3] = min >> 8; ret[4] = min & 0377;
646 ret[5] = max >> 8; ret[6] = max & 0377;
660 *flagp = (op != '+') ? (WORST|SPSTART) : (WORST|HASWIDTH);
662 if (op == '*' && (flags&SIMPLE)) {
663 reginsert(STAR, ret);
666 else if (op == '*') {
669 } else if (op == '+' && (flags&SIMPLE)) {
670 reginsert(PLUS, ret);
673 else if (op == '+') {
676 } else if (op == '?') {
681 if (dowarn && regcode != ®dummy && !(flags&HASWIDTH) && max > 10000) {
682 warn("%.*s matches null string many times",
683 regparse - origparse, origparse);
686 if (*regparse == '?') {
688 reginsert(MINMOD, ret);
690 regtail(ret, ret + 4);
692 regtail(ret, ret + 3);
695 if (ISMULT2(regparse))
696 FAIL("nested *?+ in regexp");
702 - regatom - the lowest level
704 * Optimization: gobbles an entire sequence of ordinary characters so that
705 * it can turn them into a single node, which is smaller to store and
706 * faster to run. Backslashed characters are exceptions, each becoming a
707 * separate node; the code is simpler that way and it's not worth fixing.
709 * [Yes, it is worth fixing, some scripts can run twice the speed.]
715 register char *ret = 0;
718 *flagp = WORST; /* Tentatively. */
724 if (regflags & PMf_MULTILINE)
726 else if (regflags & PMf_SINGLELINE)
733 if (regflags & PMf_MULTILINE)
735 else if (regflags & PMf_SINGLELINE)
742 if (regflags & PMf_SINGLELINE)
747 *flagp |= HASWIDTH|SIMPLE;
752 *flagp |= HASWIDTH|SIMPLE;
756 ret = reg(1, &flags);
758 if (flags & TRYAGAIN)
762 *flagp |= flags&(HASWIDTH|SPSTART);
766 if (flags & TRYAGAIN) {
770 croak("internal urp in regexp at /%s/", regparse);
771 /* Supposed to be caught earlier. */
776 FAIL("?+* follows nothing in regexp");
779 switch (*++regparse) {
796 ret = regnode(ALNUM);
797 *flagp |= HASWIDTH|SIMPLE;
801 ret = regnode(NALNUM);
802 *flagp |= HASWIDTH|SIMPLE;
806 ret = regnode(BOUND);
811 ret = regnode(NBOUND);
816 ret = regnode(SPACE);
817 *flagp |= HASWIDTH|SIMPLE;
821 ret = regnode(NSPACE);
822 *flagp |= HASWIDTH|SIMPLE;
826 ret = regnode(DIGIT);
827 *flagp |= HASWIDTH|SIMPLE;
831 ret = regnode(NDIGIT);
832 *flagp |= HASWIDTH|SIMPLE;
845 case '1': case '2': case '3': case '4':
846 case '5': case '6': case '7': case '8': case '9':
848 I32 num = atoi(regparse);
850 if (num > 9 && num >= regnpar)
854 ret = reganode(REF, num);
856 while (isDIGIT(*regparse))
864 if (regparse >= regxend)
865 FAIL("trailing \\ in regexp");
873 if (regflags & PMf_EXTENDED) {
874 while (regparse < regxend && *regparse != '\n') regparse++;
875 if (regparse < regxend)
890 ret = regnode(EXACTLY);
891 regc(0); /* save spot for len */
892 for (len = 0, p = regparse - 1;
893 len < 127 && p < regxend;
946 ender = scan_hex(++p, 2, &numlen);
953 ender = toUPPER(ender);
956 case '0': case '1': case '2': case '3':case '4':
957 case '5': case '6': case '7': case '8':case '9':
959 (isDIGIT(p[1]) && atoi(p) >= regnpar) ) {
960 ender = scan_oct(p, 3, &numlen);
970 FAIL("trailing \\ in regexp");
978 if (regflags & PMf_EXTENDED) {
979 while (p < regxend && *p != '\n') p++;
982 case ' ': case '\t': case '\n': case '\r': case '\f': case '\v':
983 if (regflags & PMf_EXTENDED) {
993 if (regflags & PMf_FOLD && isUPPER(ender))
994 ender = toLOWER(ender);
995 if (ISMULT2(p)) { /* Back off on ?+*. */
1010 FAIL("internal disaster in regexp");
1015 if (regcode != ®dummy)
1016 *OPERAND(ret) = len;
1031 if (regcode == ®dummy)
1035 bits[c >> 3] &= ~(1 << (c & 7));
1037 bits[c >> 3] |= (1 << (c & 7));
1043 register char *bits;
1045 register I32 lastclass = 1234;
1046 register I32 range = 0;
1051 ret = regnode(ANYOF);
1052 if (*regparse == '^') { /* Complement of range. */
1060 for (class = 0; class < 32; class++)
1062 if (*regparse == ']' || *regparse == '-')
1063 goto skipcond; /* allow 1st char to be ] or - */
1064 while (regparse < regxend && *regparse != ']') {
1066 class = UCHARAT(regparse++);
1067 if (class == '\\') {
1068 class = UCHARAT(regparse++);
1071 for (class = 0; class < 256; class++)
1073 regset(bits,def,class);
1077 for (class = 0; class < 256; class++)
1078 if (!isALNUM(class))
1079 regset(bits,def,class);
1083 for (class = 0; class < 256; class++)
1085 regset(bits,def,class);
1089 for (class = 0; class < 256; class++)
1090 if (!isSPACE(class))
1091 regset(bits,def,class);
1095 for (class = '0'; class <= '9'; class++)
1096 regset(bits,def,class);
1100 for (class = 0; class < '0'; class++)
1101 regset(bits,def,class);
1102 for (class = '9' + 1; class < 256; class++)
1103 regset(bits,def,class);
1128 class = scan_hex(regparse, 2, &numlen);
1132 class = *regparse++;
1134 class = toUPPER(class);
1137 case '0': case '1': case '2': case '3': case '4':
1138 case '5': case '6': case '7': case '8': case '9':
1139 class = scan_oct(--regparse, 3, &numlen);
1145 if (lastclass > class)
1146 FAIL("invalid [] range in regexp");
1151 if (*regparse == '-' && regparse+1 < regxend &&
1152 regparse[1] != ']') {
1155 continue; /* do it next time */
1158 for ( ; lastclass <= class; lastclass++) {
1159 regset(bits,def,lastclass);
1160 if (regflags & PMf_FOLD && isUPPER(lastclass))
1161 regset(bits,def,toLOWER(lastclass));
1165 if (*regparse != ']')
1166 FAIL("unmatched [] in regexp");
1174 char* retval = regparse++;
1177 if (*regparse == '(' && regparse[1] == '?' &&
1178 regparse[2] == '#') {
1179 while (*regparse && *regparse != ')')
1184 if (regflags & PMf_EXTENDED) {
1185 if (isSPACE(*regparse)) {
1189 else if (*regparse == '#') {
1190 while (*regparse && *regparse != '\n')
1201 - regnode - emit a node
1203 #ifdef CAN_PROTOTYPE
1204 static char * /* Location. */
1207 static char * /* Location. */
1216 if (ret == ®dummy) {
1227 if (!((long)ret & 1))
1233 *ptr++ = '\0'; /* Null "next" pointer. */
1241 - reganode - emit a node with an argument
1243 #ifdef CAN_PROTOTYPE
1244 static char * /* Location. */
1245 reganode(char op, unsigned short arg)
1247 static char * /* Location. */
1257 if (ret == ®dummy) {
1268 if (!((long)ret & 1))
1274 *ptr++ = '\0'; /* Null "next" pointer. */
1277 *(unsigned short *)(ret+3) = arg;
1279 ret[3] = arg >> 8; ret[4] = arg & 0377;
1288 - regc - emit (if appropriate) a byte of code
1290 #ifdef CAN_PROTOTYPE
1299 if (regcode != ®dummy)
1306 - reginsert - insert an operator in front of already-emitted operand
1308 * Means relocating the operand.
1310 #ifdef CAN_PROTOTYPE
1312 reginsert(char op, char *opnd)
1322 register char *place;
1323 register int offset = (regkind[(U8)op] == CURLY ? 4 : 0);
1325 if (regcode == ®dummy) {
1327 regsize += 4 + offset;
1329 regsize += 3 + offset;
1336 regcode += 4 + offset;
1338 regcode += 3 + offset;
1344 place = opnd; /* Op node, where operand used to be. */
1348 while (offset-- > 0)
1356 - regtail - set the next-pointer at the end of a node chain
1363 register char *scan;
1364 register char *temp;
1365 register I32 offset;
1370 /* Find last node. */
1373 temp = regnext(scan);
1380 offset = val - scan;
1382 *(short*)(scan+1) = offset;
1387 if (OP(scan) == BACK)
1388 offset = scan - val;
1390 offset = val - scan;
1391 *(scan+1) = (offset>>8)&0377;
1392 *(scan+2) = offset&0377;
1397 - regoptail - regtail on operand of first argument; nop if operandless
1404 /* "Operandless" and "op != BRANCH" are synonymous in practice. */
1405 if (p == NULL || p == ®dummy || regkind[(U8)OP(p)] != BRANCH)
1407 regtail(NEXTOPER(p), val);
1411 - regcurly - a little FSA that accepts {\d+,?\d*}
1435 - regdump - dump a regexp onto stderr in vaguely comprehensible form
1442 register char op = EXACTLY; /* Arbitrary non-END op. */
1443 register char *next;
1447 while (op != END) { /* While that wasn't END last time... */
1453 fprintf(stderr,"%2d%s", s-r->program, regprop(s)); /* Where, what. */
1455 s += regarglen[(U8)op];
1456 if (next == NULL) /* Next ptr. */
1457 fprintf(stderr,"(0)");
1459 fprintf(stderr,"(%d)", (s-r->program)+(next-s));
1464 if (op == EXACTLY) {
1465 /* Literal string, where present. */
1467 (void)putc(' ', stderr);
1468 (void)putc('<', stderr);
1469 while (*s != '\0') {
1470 (void)putc(*s, stderr);
1473 (void)putc('>', stderr);
1476 (void)putc('\n', stderr);
1479 /* Header fields of interest. */
1481 fprintf(stderr,"start `%s' ", SvPVX(r->regstart));
1483 fprintf(stderr,"stclass `%s' ", regprop(r->regstclass));
1484 if (r->reganch & ROPT_ANCH)
1485 fprintf(stderr,"anchored ");
1486 if (r->reganch & ROPT_SKIP)
1487 fprintf(stderr,"plus ");
1488 if (r->reganch & ROPT_IMPLICIT)
1489 fprintf(stderr,"implicit ");
1490 if (r->regmust != NULL)
1491 fprintf(stderr,"must have \"%s\" back %ld ", SvPVX(r->regmust),
1493 fprintf(stderr, "minlen %ld ", (long) r->minlen);
1494 fprintf(stderr,"\n");
1498 - regprop - printable representation of opcode
1504 register char *p = 0;
1506 (void) strcpy(buf, ":");
1576 (void)sprintf(buf+strlen(buf), "CURLY {%d,%d}", ARG1(op),ARG2(op));
1580 (void)sprintf(buf+strlen(buf), "CURLYX {%d,%d}", ARG1(op),ARG2(op));
1584 (void)sprintf(buf+strlen(buf), "REF%d", ARG1(op));
1588 (void)sprintf(buf+strlen(buf), "OPEN%d", ARG1(op));
1592 (void)sprintf(buf+strlen(buf), "CLOSE%d", ARG1(op));
1620 FAIL("corrupted regexp opcode");
1623 (void) strcat(buf, p);
1626 #endif /* DEBUGGING */
1635 Safefree(r->precomp);
1636 r->precomp = Nullch;
1639 Safefree(r->subbase);
1640 r->subbase = Nullch;
1643 SvREFCNT_dec(r->regmust);
1644 r->regmust = Nullsv;
1647 SvREFCNT_dec(r->regstart);
1648 r->regstart = Nullsv;
1650 Safefree(r->startp);