[asperl] various changes to get asperl working under Borland
[p5sagit/p5-mst-13.2.git] / regexec.c
index d74c234..7a0e84a 100644 (file)
--- a/regexec.c
+++ b/regexec.c
 #include "perl.h"
 #include "regcomp.h"
 
-static char *  reginput;       /* String-input pointer. */
-static char *  regbol;         /* Beginning of input, for ^ check. */
-static char *  regeol;         /* End of input, for $ check. */
-static char ** regstartp;      /* Pointer to startp array. */
-static char ** regendp;        /* Ditto for endp. */
-static U32 *   reglastparen;   /* Similarly for lastparen. */
-static char *  regtill;        /* How far we are required to go. */
-static char    regprev;        /* char before regbol, \n if none */
-
-static char *  regprecomp;     /* uncompiled string. */
-static I32             regnpar;        /* () count. */
-static I32             regsize;        /* Largest OPEN seens. */
-static char ** reg_start_tmp;
-static U32 reg_start_tmpl;
-static struct reg_data *data;
-static char *bostr;
-
-static U32 reg_flags;                  /* tainted/warned */
-static I32 reg_eval_set;
-
 #define RF_tainted     1               /* tainted information used? */
 #define RF_warned      2               /* warned about big count? */
 #define RF_evaled      4               /* Did an EVAL? */
@@ -83,27 +63,7 @@ static I32 reg_eval_set;
 #define        STATIC  static
 #endif
 
-#ifdef DEBUGGING
-static I32     regnarrate = 0;
-static regnode* regprogram = 0;
-#endif
-
-/* Current curly descriptor */
-typedef struct curcur CURCUR;
-struct curcur {
-    int                parenfloor;     /* how far back to strip paren data */
-    int                cur;            /* how many instances of scan we've matched */
-    int                min;            /* the minimal number of scans to match */
-    int                max;            /* the maximal number of scans to match */
-    int                minmod;         /* whether to work our way up or down */
-    regnode *  scan;           /* the thing to match */
-    regnode *  next;           /* what has to match after it */
-    char *     lastloc;        /* where we started matching this scan */
-    CURCUR *   oldcc;          /* current curly before we started this one */
-};
-
-static CURCUR* regcc;
-
+#ifndef PERL_OBJECT
 typedef I32 CHECKPOINT;
 
 /*
@@ -117,8 +77,9 @@ static I32 regtry _((regexp *prog, char *startpos));
 static bool reginclass _((char *p, I32 c));
 static CHECKPOINT regcppush _((I32 parenfloor));
 static char * regcppop _((void));
+#endif
 
-static CHECKPOINT
+STATIC CHECKPOINT
 regcppush(I32 parenfloor)
 {
     dTHR;
@@ -130,7 +91,7 @@ regcppush(I32 parenfloor)
     for (p = regsize; p > parenfloor; p--) {
        SSPUSHPTR(regendp[p]);
        SSPUSHPTR(regstartp[p]);
-       SSPUSHINT(reg_start_tmp[p]);
+       SSPUSHPTR(reg_start_tmp[p]);
        SSPUSHINT(p);
     }
     SSPUSHINT(regsize);
@@ -145,7 +106,7 @@ regcppush(I32 parenfloor)
 #  define REGCP_SET  DEBUG_r(PerlIO_printf(Perl_debug_log, "  Setting an EVAL scope, savestack=%i\n", savestack_ix)); lastcp = savestack_ix
 #  define REGCP_UNWIND  DEBUG_r(lastcp != savestack_ix ? PerlIO_printf(Perl_debug_log,"  Clearing an EVAL scope, savestack=%i..%i\n", lastcp, savestack_ix) : 0); regcpblow(lastcp)
 
-static char *
+STATIC char *
 regcppop(void)
 {
     dTHR;
@@ -411,7 +372,7 @@ regexec_flags(register regexp *prog, char *stringarg, register char *strend, cha
        goto phooey;
     } else if (c = prog->regstclass) {
        I32 doevery = (prog->reganch & ROPT_SKIP) == 0;
-       char *class;
+       char *Class;
 
        if (minlen)
            dontbother = minlen - 1;
@@ -420,9 +381,9 @@ regexec_flags(register regexp *prog, char *stringarg, register char *strend, cha
        /* We know what class it must start with. */
        switch (OP(c)) {
        case ANYOF:
-           class = OPERAND(c);
+           Class = (char *) OPERAND(c);
            while (s < strend) {
-               if (reginclass(class, *s)) {
+               if (reginclass(Class, *s)) {
                    if (tmp && regtry(prog, s))
                        goto got_it;
                    else
@@ -678,7 +639,7 @@ phooey:
 /*
  - regtry - try match at specific point
  */
-static I32                     /* 0 failure, 1 success */
+STATIC I32                     /* 0 failure, 1 success */
 regtry(regexp *prog, char *startpos)
 {
     dTHR;
@@ -703,7 +664,7 @@ regtry(regexp *prog, char *startpos)
 
     sp = prog->startp;
     ep = prog->endp;
-    data = prog->data;
+    regdata = prog->data;
     if (prog->nparens) {
        for (i = prog->nparens; i >= 0; i--) {
            *sp++ = NULL;
@@ -734,14 +695,14 @@ regtry(regexp *prog, char *startpos)
  * maybe save a little bit of pushing and popping on the stack.  It also takes
  * advantage of machines that use a register save mask on subroutine entry.
  */
-static I32                     /* 0 failure, 1 success */
+STATIC I32                     /* 0 failure, 1 success */
 regmatch(regnode *prog)
 {
     dTHR;
     register regnode *scan;    /* Current node. */
     regnode *next;             /* Next node. */
     regnode *inner;            /* Next node in internal branch. */
-    register I32 nextchar;
+    register I32 nextchr; /* renamed nextchr - nextchar colides with function of same name */
     register I32 n;            /* no or next */
     register I32 ln;           /* len or last */
     register char *s;          /* operand or save */
@@ -749,11 +710,10 @@ regmatch(regnode *prog)
     register I32 c1, c2, paren;        /* case fold search, parenth */
     int minmod = 0, sw = 0, logical = 0;
 #ifdef DEBUGGING
-    static int regindent = 0;
     regindent++;
 #endif
 
-    nextchar = UCHARAT(locinput);
+    nextchr = UCHARAT(locinput);
     scan = prog;
     while (scan != NULL) {
 #define sayNO_L (logical ? (logical = 0, sw = 0, goto cont) : sayNO)
@@ -804,7 +764,7 @@ regmatch(regnode *prog)
            if (locinput == regbol
                ? regprev == '\n'
                : (multiline && 
-                  (nextchar || locinput < regeol) && locinput[-1] == '\n') )
+                  (nextchr || locinput < regeol) && locinput[-1] == '\n') )
            {
                /* regtill = regbol; */
                break;
@@ -813,7 +773,7 @@ regmatch(regnode *prog)
        case MBOL:
            if (locinput == regbol
                ? regprev == '\n'
-               : ((nextchar || locinput < regeol) && locinput[-1] == '\n') )
+               : ((nextchr || locinput < regeol) && locinput[-1] == '\n') )
            {
                break;
            }
@@ -833,49 +793,49 @@ regmatch(regnode *prog)
                goto seol;
        case MEOL:
          meol:
-           if ((nextchar || locinput < regeol) && nextchar != '\n')
+           if ((nextchr || locinput < regeol) && nextchr != '\n')
                sayNO;
            break;
        case SEOL:
          seol:
-           if ((nextchar || locinput < regeol) && nextchar != '\n')
+           if ((nextchr || locinput < regeol) && nextchr != '\n')
                sayNO;
            if (regeol - locinput > 1)
                sayNO;
            break;
        case SANY:
-           if (!nextchar && locinput >= regeol)
+           if (!nextchr && locinput >= regeol)
                sayNO;
-           nextchar = UCHARAT(++locinput);
+           nextchr = UCHARAT(++locinput);
            break;
        case ANY:
-           if (!nextchar && locinput >= regeol || nextchar == '\n')
+           if (!nextchr && locinput >= regeol || nextchr == '\n')
                sayNO;
-           nextchar = UCHARAT(++locinput);
+           nextchr = UCHARAT(++locinput);
            break;
        case EXACT:
-           s = OPERAND(scan);
+           s = (char *) OPERAND(scan);
            ln = UCHARAT(s++);
            /* Inline the first character, for speed. */
-           if (UCHARAT(s) != nextchar)
+           if (UCHARAT(s) != nextchr)
                sayNO;
            if (regeol - locinput < ln)
                sayNO;
            if (ln > 1 && memNE(s, locinput, ln))
                sayNO;
            locinput += ln;
-           nextchar = UCHARAT(locinput);
+           nextchr = UCHARAT(locinput);
            break;
        case EXACTFL:
            reg_flags |= RF_tainted;
            /* FALL THROUGH */
        case EXACTF:
-           s = OPERAND(scan);
+           s = (char *) OPERAND(scan);
            ln = UCHARAT(s++);
            /* Inline the first character, for speed. */
-           if (UCHARAT(s) != nextchar &&
+           if (UCHARAT(s) != nextchr &&
                UCHARAT(s) != ((OP(scan) == EXACTF)
-                              ? fold : fold_locale)[nextchar])
+                              ? fold : fold_locale)[nextchr])
                sayNO;
            if (regeol - locinput < ln)
                sayNO;
@@ -884,39 +844,39 @@ regmatch(regnode *prog)
                           : ibcmp_locale(s, locinput, ln)))
                sayNO;
            locinput += ln;
-           nextchar = UCHARAT(locinput);
+           nextchr = UCHARAT(locinput);
            break;
        case ANYOF:
-           s = OPERAND(scan);
-           if (nextchar < 0)
-               nextchar = UCHARAT(locinput);
-           if (!reginclass(s, nextchar))
+           s = (char *) OPERAND(scan);
+           if (nextchr < 0)
+               nextchr = UCHARAT(locinput);
+           if (!reginclass(s, nextchr))
                sayNO;
-           if (!nextchar && locinput >= regeol)
+           if (!nextchr && locinput >= regeol)
                sayNO;
-           nextchar = UCHARAT(++locinput);
+           nextchr = UCHARAT(++locinput);
            break;
        case ALNUML:
            reg_flags |= RF_tainted;
            /* FALL THROUGH */
        case ALNUM:
-           if (!nextchar)
+           if (!nextchr)
                sayNO;
            if (!(OP(scan) == ALNUM
-                 ? isALNUM(nextchar) : isALNUM_LC(nextchar)))
+                 ? isALNUM(nextchr) : isALNUM_LC(nextchr)))
                sayNO;
-           nextchar = UCHARAT(++locinput);
+           nextchr = UCHARAT(++locinput);
            break;
        case NALNUML:
            reg_flags |= RF_tainted;
            /* FALL THROUGH */
        case NALNUM:
-           if (!nextchar && locinput >= regeol)
+           if (!nextchr && locinput >= regeol)
                sayNO;
            if (OP(scan) == NALNUM
-               ? isALNUM(nextchar) : isALNUM_LC(nextchar))
+               ? isALNUM(nextchr) : isALNUM_LC(nextchr))
                sayNO;
-           nextchar = UCHARAT(++locinput);
+           nextchr = UCHARAT(++locinput);
            break;
        case BOUNDL:
        case NBOUNDL:
@@ -928,11 +888,11 @@ regmatch(regnode *prog)
            ln = (locinput != regbol) ? UCHARAT(locinput - 1) : regprev;
            if (OP(scan) == BOUND || OP(scan) == NBOUND) {
                ln = isALNUM(ln);
-               n = isALNUM(nextchar);
+               n = isALNUM(nextchr);
            }
            else {
                ln = isALNUM_LC(ln);
-               n = isALNUM_LC(nextchar);
+               n = isALNUM_LC(nextchr);
            }
            if (((!ln) == (!n)) == (OP(scan) == BOUND || OP(scan) == BOUNDL))
                sayNO;
@@ -941,35 +901,35 @@ regmatch(regnode *prog)
            reg_flags |= RF_tainted;
            /* FALL THROUGH */
        case SPACE:
-           if (!nextchar && locinput >= regeol)
+           if (!nextchr && locinput >= regeol)
                sayNO;
            if (!(OP(scan) == SPACE
-                 ? isSPACE(nextchar) : isSPACE_LC(nextchar)))
+                 ? isSPACE(nextchr) : isSPACE_LC(nextchr)))
                sayNO;
-           nextchar = UCHARAT(++locinput);
+           nextchr = UCHARAT(++locinput);
            break;
        case NSPACEL:
            reg_flags |= RF_tainted;
            /* FALL THROUGH */
        case NSPACE:
-           if (!nextchar)
+           if (!nextchr)
                sayNO;
            if (OP(scan) == SPACE
-               ? isSPACE(nextchar) : isSPACE_LC(nextchar))
+               ? isSPACE(nextchr) : isSPACE_LC(nextchr))
                sayNO;
-           nextchar = UCHARAT(++locinput);
+           nextchr = UCHARAT(++locinput);
            break;
        case DIGIT:
-           if (!isDIGIT(nextchar))
+           if (!isDIGIT(nextchr))
                sayNO;
-           nextchar = UCHARAT(++locinput);
+           nextchr = UCHARAT(++locinput);
            break;
        case NDIGIT:
-           if (!nextchar && locinput >= regeol)
+           if (!nextchr && locinput >= regeol)
                sayNO;
-           if (isDIGIT(nextchar))
+           if (isDIGIT(nextchr))
                sayNO;
-           nextchar = UCHARAT(++locinput);
+           nextchr = UCHARAT(++locinput);
            break;
        case REFFL:
            reg_flags |= RF_tainted;
@@ -979,14 +939,14 @@ regmatch(regnode *prog)
            n = ARG(scan);  /* which paren pair */
            s = regstartp[n];
            if (*reglastparen < n || !s)
-               break;                  /* Zero length always matches */
+               sayNO;                  /* Do not match unless seen CLOSEn. */
            if (s == regendp[n])
                break;
            /* Inline the first character, for speed. */
-           if (UCHARAT(s) != nextchar &&
+           if (UCHARAT(s) != nextchr &&
                (OP(scan) == REF ||
                 (UCHARAT(s) != ((OP(scan) == REFF
-                                 ? fold : fold_locale)[nextchar]))))
+                                 ? fold : fold_locale)[nextchr]))))
                sayNO;
            ln = regendp[n] - s;
            if (locinput + ln > regeol)
@@ -998,7 +958,7 @@ regmatch(regnode *prog)
                              : ibcmp_locale(s, locinput, ln))))
                sayNO;
            locinput += ln;
-           nextchar = UCHARAT(locinput);
+           nextchr = UCHARAT(locinput);
            break;
 
        case NOTHING:
@@ -1015,9 +975,9 @@ regmatch(regnode *prog)
            SV *ret;
            
            n = ARG(scan);
-           op = (OP_4tree*)data->data[n];
+           op = (OP_4tree*)regdata->data[n];
            DEBUG_r( PerlIO_printf(Perl_debug_log, "  re_eval 0x%x\n", op) );
-           curpad = AvARRAY((AV*)data->data[n + 1]);
+           curpad = AvARRAY((AV*)regdata->data[n + 1]);
            if (!reg_eval_set) {
                /* Preserve whatever is on stack now, otherwise
                   OP_NEXTSTATE will overwrite it. */
@@ -1035,7 +995,7 @@ regmatch(regnode *prog)
                   cxstack[cxstack_ix].blk_gimme = G_SCALAR; */
            }
 
-           runops();                   /* Scalar context. */
+           CALLRUNOPS();                       /* Scalar context. */
            SPAGAIN;
            ret = POPs;
            PUTBACK;
@@ -1576,8 +1536,10 @@ regmatch(regnode *prog)
                logical = 0;
                sw = 1;
            }
-           if (OP(scan) == SUSPEND)
+           if (OP(scan) == SUSPEND) {
                locinput = reginput;
+               nextchr = UCHARAT(locinput);
+           }
            /* FALL THROUGH. */
        case LONGJMP:
          do_longjump:
@@ -1622,7 +1584,7 @@ no:
  * That was true before, but now we assume scan - reginput is the count,
  * rather than incrementing count on every character.]
  */
-static I32
+STATIC I32
 regrepeat(regnode *p, I32 max)
 {
     register char *scan;
@@ -1633,7 +1595,7 @@ regrepeat(regnode *p, I32 max)
     scan = reginput;
     if (max != REG_INFTY && max < loceol - scan)
       loceol = scan + max;
-    opnd = OPERAND(p);
+    opnd = (char *) OPERAND(p);
     switch (OP(p)) {
     case ANY:
        while (scan < loceol && *scan != '\n')
@@ -1734,7 +1696,7 @@ regrepeat(regnode *p, I32 max)
  * The repeater is supposed to have constant length.
  */
 
-static I32
+STATIC I32
 regrepeat_hard(regnode *p, I32 max, I32 *lp)
 {
     register char *scan;
@@ -1765,7 +1727,7 @@ regrepeat_hard(regnode *p, I32 max, I32 *lp)
  - regclass - determine if a character falls into a character class
  */
 
-static bool
+STATIC bool
 reginclass(register char *p, register I32 c)
 {
     char flags = *p;
@@ -1801,3 +1763,5 @@ reginclass(register char *p, register I32 c)
     return match ^ ((flags & ANYOF_INVERT) != 0);
 }
 
+
+