Fix MM doc's use of "SUPER::"
[p5sagit/p5-mst-13.2.git] / regexec.c
index da3097e..57000cf 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -42,7 +42,7 @@
  *
  ****    Alterations to Henry's code are...
  ****
- ****    Copyright (c) 1991-1994, Larry Wall
+ ****    Copyright (c) 1991-1997, Larry Wall
  ****
  ****    You may distribute under the terms of either the GNU General Public
  ****    License or the Artistic License, as specified in the README file.
@@ -207,7 +207,8 @@ I32 safebase;       /* no need to remember string in subbase */
     /* If there is a "must appear" string, look for it. */
     s = startpos;
     if (prog->regmust != Nullsv &&
-       (!(prog->reganch & ROPT_ANCH)
+       !(prog->reganch & ROPT_ANCH_GPOS) &&
+       (!(prog->reganch & ROPT_ANCH_BOL)
         || (multiline && prog->regback >= 0)) )
     {
        if (stringarg == strbeg && screamer) {
@@ -250,11 +251,13 @@ I32 safebase;     /* no need to remember string in subbase */
     regtill = startpos+minend;
 
     /* Simplest case:  anchored match need be tried only once. */
-    /*  [unless multiline is set] */
+    /*  [unless only anchor is BOL and multiline is set] */
     if (prog->reganch & ROPT_ANCH) {
        if (regtry(prog, startpos))
            goto got_it;
-       else if (multiline || (prog->reganch & ROPT_IMPLICIT)) {
+       else if (!(prog->reganch & ROPT_ANCH_GPOS) &&
+                (multiline || (prog->reganch & ROPT_IMPLICIT)))
+       {
            if (minlen)
                dontbother = minlen - 1;
            strend -= dontbother;
@@ -287,7 +290,7 @@ I32 safebase;       /* no need to remember string in subbase */
                s++;
            }
        }
-       else if (SvPOK(prog->regstart) == 3) {
+       else if (SvTYPE(prog->regstart) == SVt_PVBM) {
            /* We know what string it must start with. */
            while ((s = fbm_instr((unsigned char*)s,
              (unsigned char*)strend, prog->regstart)) != NULL)
@@ -297,7 +300,7 @@ I32 safebase;       /* no need to remember string in subbase */
                s++;
            }
        }
-       else {
+       else {                          /* Optimized fbm_instr: */
            c = SvPVX(prog->regstart);
            while ((s = ninstr(s, strend, c, c + SvCUR(prog->regstart))) != NULL)
            {
@@ -524,24 +527,16 @@ got_it:
     prog->subbeg = strbeg;
     prog->subend = strend;
     prog->exec_tainted = regtainted;
-    if (!safebase && (prog->nparens || sawampersand)) {
+
+    /* make sure $`, $&, $', and $digit will work later */
+    if (!safebase && (strbeg != prog->subbase)) {
        I32 i = strend - startpos + (stringarg - strbeg);
-       if (safebase) {                 /* no need for $digit later */
-           s = strbeg;
-           prog->subend = s+i;
-       }
-       else if (strbeg != prog->subbase) {
-           s = savepvn(strbeg,i);      /* so $digit will work later */
-           if (prog->subbase)
-               Safefree(prog->subbase);
-           prog->subbeg = prog->subbase = s;
-           prog->subend = s+i;
-       }
-       else {
-           prog->subbeg = s = prog->subbase;
-           prog->subend = s+i;
-       }
-       s += (stringarg - strbeg);
+       s = savepvn(strbeg, i);
+       Safefree(prog->subbase);
+       prog->subbase = s;
+       prog->subbeg = prog->subbase;
+       prog->subend = prog->subbase + i;
+       s = prog->subbase + (stringarg - strbeg);
        for (i = 0; i <= prog->nparens; i++) {
            if (prog->endp[i]) {
                prog->startp[i] = s + (prog->startp[i] - startpos);
@@ -670,7 +665,7 @@ char *prog;
            if (locinput == regbol && regprev == '\n')
                break;
            sayNO;
-       case GBOL:
+       case GPOS:
            if (locinput == regbol)
                break;
            sayNO;
@@ -727,8 +722,9 @@ char *prog;
                sayNO;
            if (regeol - locinput < ln)
                sayNO;
-           if (ln > 1 && ((OP(scan) == EXACTF)
-                          ? ibcmp : ibcmp_locale)(s, locinput, ln) != 0)
+           if (ln > 1 && (OP(scan) == EXACTF
+                          ? ibcmp(s, locinput, ln)
+                          : ibcmp_locale(s, locinput, ln)))
                sayNO;
            locinput += ln;
            nextchar = UCHARAT(locinput);
@@ -885,19 +881,20 @@ char *prog;
                 * that we can try again after backing off.
                 */
 
+               CHECKPOINT cp;
                CURCUR* cc = regcc;
                n = cc->cur + 1;        /* how many we know we matched */
                reginput = locinput;
 
 #ifdef DEBUGGING
                if (regnarrate)
-                   PerlIO_printf(Perl_debug_log, "%*s  %d  %lx\n", regindent*2, "",
-                       n, (long)cc);
+                   PerlIO_printf(Perl_debug_log, "%*s  %ld  %lx\n", regindent*2, "",
+                       (long)n, (long)cc);
 #endif
 
                /* If degenerate scan matches "", assume scan done. */
 
-               if (locinput == cc->lastloc) {
+               if (locinput == cc->lastloc && n >= cc->min) {
                    regcc = cc->oldcc;
                    ln = regcc->cur;
                    if (regmatch(cc->next))
@@ -923,8 +920,12 @@ char *prog;
                if (cc->minmod) {
                    regcc = cc->oldcc;
                    ln = regcc->cur;
-                   if (regmatch(cc->next))
+                   cp = regcppush(cc->parenfloor);
+                   if (regmatch(cc->next)) {
+                       regcpblow(cp);
                        sayYES; /* All done. */
+                   }
+                   regcppop();
                    regcc->cur = ln;
                    regcc = cc;
 
@@ -935,8 +936,12 @@ char *prog;
                    reginput = locinput;
                    cc->cur = n;
                    cc->lastloc = locinput;
-                   if (regmatch(cc->scan))
+                   cp = regcppush(cc->parenfloor);
+                   if (regmatch(cc->scan)) {
+                       regcpblow(cp);
                        sayYES;
+                   }
+                   regcppop();
                    cc->cur = n - 1;
                    sayNO;
                }
@@ -944,11 +949,13 @@ char *prog;
                /* Prefer scan over next for maximal matching. */
 
                if (n < cc->max) {      /* More greed allowed? */
-                   regcppush(cc->parenfloor);
+                   cp = regcppush(cc->parenfloor);
                    cc->cur = n;
                    cc->lastloc = locinput;
-                   if (regmatch(cc->scan))
+                   if (regmatch(cc->scan)) {
+                       regcpblow(cp);
                        sayYES;
+                   }
                    regcppop();         /* Restore some previous $<digit>s? */
                    reginput = locinput;
                }
@@ -1086,7 +1093,8 @@ char *prog;
                sayNO;
            break;
        default:
-           PerlIO_printf(PerlIO_stderr(), "%x %d\n",(unsigned)scan,scan[1]);
+           PerlIO_printf(PerlIO_stderr(), "%lx %d\n",
+                         (unsigned long)scan, scan[1]);
            FAIL("regexp memory corruption");
        }
        scan = next;