/[pcre]/code/trunk/pcre_exec.c
ViewVC logotype

Diff of /code/trunk/pcre_exec.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 615 by ph10, Mon Jul 11 14:23:06 2011 UTC revision 619 by ph10, Sun Jul 17 13:23:14 2011 UTC
# Line 76  negative to avoid the external error cod Line 76  negative to avoid the external error cod
76  #define MATCH_ACCEPT       (-999)  #define MATCH_ACCEPT       (-999)
77  #define MATCH_COMMIT       (-998)  #define MATCH_COMMIT       (-998)
78  #define MATCH_KETRPOS      (-997)  #define MATCH_KETRPOS      (-997)
79  #define MATCH_PRUNE        (-996)  #define MATCH_ONCE         (-996)
80  #define MATCH_SKIP         (-995)  #define MATCH_PRUNE        (-995)
81  #define MATCH_SKIP_ARG     (-994)  #define MATCH_SKIP         (-994)
82  #define MATCH_THEN         (-993)  #define MATCH_SKIP_ARG     (-993)
83    #define MATCH_THEN         (-992)
84    
85  /* This is a convenience macro for code that occurs many times. */  /* This is a convenience macro for code that occurs many times. */
86    
# Line 276  enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM Line 277  enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM
277         RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,         RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
278         RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,         RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
279         RM51,  RM52, RM53, RM54, RM55, RM56, RM57, RM58, RM59, RM60,         RM51,  RM52, RM53, RM54, RM55, RM56, RM57, RM58, RM59, RM60,
280         RM61,  RM62, RM63};         RM61,  RM62, RM63, RM64, RM65, RM66 };
281    
282  /* These versions of the macros use the stack, as normal. There are debugging  /* These versions of the macros use the stack, as normal. There are debugging
283  versions and production versions. Note that the "rw" argument of RMATCH isn't  versions and production versions. Note that the "rw" argument of RMATCH isn't
# Line 808  for (;;) Line 809  for (;;)
809      subject position in the working slot at the top of the vector. We mustn't      subject position in the working slot at the top of the vector. We mustn't
810      change the current values of the data slot, because they may be set from a      change the current values of the data slot, because they may be set from a
811      previous iteration of this group, and be referred to by a reference inside      previous iteration of this group, and be referred to by a reference inside
812      the group. If we fail to match, we need to restore this value and also the      the group. A failure to match might occur after the group has succeeded,
813      values of the final offsets, in case they were set by a previous iteration      if something later on doesn't match. For this reason, we need to restore
814      of the same bracket.      the working value and also the values of the final offsets, in case they
815        were set by a previous iteration of the same bracket.
816    
817      If there isn't enough space in the offset vector, treat this as if it were      If there isn't enough space in the offset vector, treat this as if it were
818      a non-capturing bracket. Don't worry about setting the flag for the error      a non-capturing bracket. Don't worry about setting the flag for the error
# Line 844  for (;;) Line 846  for (;;)
846          if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;          if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
847          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
848            eptrb, RM1);            eptrb, RM1);
849            if (rrc == MATCH_ONCE) break;  /* Backing up through an atomic group */
850          if (rrc != MATCH_NOMATCH &&          if (rrc != MATCH_NOMATCH &&
851              (rrc != MATCH_THEN || md->start_match_ptr != ecode))              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
852            RRETURN(rrc);            RRETURN(rrc);
# Line 853  for (;;) Line 856  for (;;)
856          }          }
857    
858        DPRINTF(("bracket %d failed\n", number));        DPRINTF(("bracket %d failed\n", number));
   
859        md->offset_vector[offset] = save_offset1;        md->offset_vector[offset] = save_offset1;
860        md->offset_vector[offset+1] = save_offset2;        md->offset_vector[offset+1] = save_offset2;
861        md->offset_vector[md->offset_end - number] = save_offset3;        md->offset_vector[md->offset_end - number] = save_offset3;
862    
863          /* At this point, rrc will be one of MATCH_ONCE, MATCH_NOMATCH, or
864          MATCH_THEN. */
865    
866        if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr;        if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr;
867        RRETURN(MATCH_NOMATCH);        RRETURN(((rrc == MATCH_ONCE)? MATCH_ONCE:MATCH_NOMATCH));
868        }        }
869    
870      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
# Line 873  for (;;) Line 878  for (;;)
878      /* VVVVVVVVVVVVVVVVVVVVVVVVV */      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
879      /* VVVVVVVVVVVVVVVVVVVVVVVVV */      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
880    
881      /* Non-capturing bracket, except for possessive with unlimited repeat. Loop      /* Non-capturing or atomic group, except for possessive with unlimited
882      for all the alternatives. When we get to the final alternative within the      repeat. Loop for all the alternatives. When we get to the final alternative
883      brackets, we used to return the result of a recursive call to match()      within the brackets, we used to return the result of a recursive call to
884      whatever happened so it was possible to reduce stack usage by turning this      match() whatever happened so it was possible to reduce stack usage by
885      into a tail recursion, except in the case of a possibly empty group.      turning this into a tail recursion, except in the case of a possibly empty
886      However, now that there is the possiblity of (*THEN) occurring in the final      group. However, now that there is the possiblity of (*THEN) occurring in
887      alternative, this optimization is no longer possible. */      the final alternative, this optimization is no longer possible.
888    
889        MATCH_ONCE is returned when the end of an atomic group is successfully
890        reached, but subsequent matching fails. It passes back up the tree (causing
891        captured values to be reset) until the original atomic group level is
892        reached. This is tested by comparing md->once_target with the start of the
893        group. At this point, the return is converted into MATCH_NOMATCH so that
894        previous backup points can be taken. */
895    
896        case OP_ONCE:
897      case OP_BRA:      case OP_BRA:
898      case OP_SBRA:      case OP_SBRA:
899      DPRINTF(("start non-capturing bracket\n"));      DPRINTF(("start non-capturing bracket\n"));
900    
901      for (;;)      for (;;)
902        {        {
903        if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;        if (op >= OP_SBRA || op == OP_ONCE) md->match_function_type = MATCH_CBEGROUP;
904        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, eptrb,        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, eptrb,
905          RM2);          RM2);
906        if (rrc != MATCH_NOMATCH &&        if (rrc != MATCH_NOMATCH &&
907            (rrc != MATCH_THEN || md->start_match_ptr != ecode))            (rrc != MATCH_THEN || md->start_match_ptr != ecode))
908            {
909            if (rrc == MATCH_ONCE)
910              {
911              const uschar *scode = ecode;
912              if (*scode != OP_ONCE)           /* If not at start, find it */
913                {
914                while (*scode == OP_ALT) scode += GET(scode, 1);
915                scode -= GET(scode, 1);
916                }
917              if (md->once_target == scode) rrc = MATCH_NOMATCH;
918              }
919          RRETURN(rrc);          RRETURN(rrc);
920            }
921        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
922        if (*ecode != OP_ALT) break;        if (*ecode != OP_ALT) break;
923        }        }
   
924      if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr;      if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr;
925      RRETURN(MATCH_NOMATCH);      RRETURN(MATCH_NOMATCH);
926    
# Line 1228  for (;;) Line 1253  for (;;)
1253        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM3);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM3);
1254        if (rrc == MATCH_MATCH)        if (rrc == MATCH_MATCH)
1255          {          {
1256            if (md->end_offset_top > offset_top)
1257              offset_top = md->end_offset_top;  /* Captures may have happened */
1258          condition = TRUE;          condition = TRUE;
1259          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
1260          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
# Line 1291  for (;;) Line 1318  for (;;)
1318      break;      break;
1319    
1320    
1321      /* End of the pattern, either real or forced. If we are in a recursion, we      /* End of the pattern, either real or forced. */
     should restore the offsets appropriately, and if it's a top-level  
     recursion, continue from after the call. */  
1322    
1323        case OP_END:
1324      case OP_ACCEPT:      case OP_ACCEPT:
1325      case OP_ASSERT_ACCEPT:      case OP_ASSERT_ACCEPT:
1326      case OP_END:  
1327      if (md->recursive != NULL)      /* If we have matched an empty string, fail if not in an assertion and not
1328        {      in a recursion if either PCRE_NOTEMPTY is set, or if PCRE_NOTEMPTY_ATSTART
       recursion_info *rec = md->recursive;  
       md->recursive = rec->prevrec;  
       memmove(md->offset_vector, rec->offset_save,  
         rec->saved_max * sizeof(int));  
       offset_top = rec->save_offset_top;  
       if (rec->group_num == 0)  
         {  
         ecode = rec->after_call;  
         break;  
         }  
       }  
   
     /* Otherwise, if we have matched an empty string, fail if not in an  
     assertion and if either PCRE_NOTEMPTY is set, or if PCRE_NOTEMPTY_ATSTART  
1329      is set and we have matched at the start of the subject. In both cases,      is set and we have matched at the start of the subject. In both cases,
1330      backtracking will then try other alternatives, if any. */      backtracking will then try other alternatives, if any. */
1331    
1332      else if (eptr == mstart && op != OP_ASSERT_ACCEPT &&      if (eptr == mstart && op != OP_ASSERT_ACCEPT &&
1333          (md->notempty ||           md->recursive == NULL &&
1334            (md->notempty_atstart &&           (md->notempty ||
1335              mstart == md->start_subject + md->start_offset)))             (md->notempty_atstart &&
1336                 mstart == md->start_subject + md->start_offset)))
1337        MRRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1338    
1339      /* Otherwise, we have a match. */      /* Otherwise, we have a match. */
# Line 1480  for (;;) Line 1493  for (;;)
1493      /* Recursion either matches the current regex, or some subexpression. The      /* Recursion either matches the current regex, or some subexpression. The
1494      offset data is the offset to the starting bracket from the start of the      offset data is the offset to the starting bracket from the start of the
1495      whole pattern. (This is so that it works from duplicated subpatterns.)      whole pattern. (This is so that it works from duplicated subpatterns.)
1496    
1497      If there are any capturing brackets started but not finished, we have to      The state of the capturing groups is preserved over recursion, and
1498      save their starting points and reinstate them after the recursion. However,      re-instated afterwards. We don't know how many are started and not yet
1499      we don't know how many such there are (offset_top records the completed      finished (offset_top records the completed total) so we just have to save
1500      total) so we just have to save all the potential data. There may be up to      all the potential data. There may be up to 65535 such values, which is too
1501      65535 such values, which is too large to put on the stack, but using malloc      large to put on the stack, but using malloc for small numbers seems
1502      for small numbers seems expensive. As a compromise, the stack is used when      expensive. As a compromise, the stack is used when there are no more than
1503      there are no more than REC_STACK_SAVE_MAX values to store; otherwise malloc      REC_STACK_SAVE_MAX values to store; otherwise malloc is used.
     is used. A problem is what to do if the malloc fails ... there is no way of  
     returning to the top level with an error. Save the top REC_STACK_SAVE_MAX  
     values on the stack, and accept that the rest may be wrong.  
1504    
1505      There are also other values that have to be saved. We use a chained      There are also other values that have to be saved. We use a chained
1506      sequence of blocks that actually live on the stack. Thanks to Robin Houston      sequence of blocks that actually live on the stack. Thanks to Robin Houston
1507      for the original version of this logic. */      for the original version of this logic. It has, however, been hacked around
1508        a lot, so he is not to blame for the current way it works. */
1509    
1510      case OP_RECURSE:      case OP_RECURSE:
1511        {        {
# Line 1507  for (;;) Line 1518  for (;;)
1518        new_recursive.prevrec = md->recursive;        new_recursive.prevrec = md->recursive;
1519        md->recursive = &new_recursive;        md->recursive = &new_recursive;
1520    
1521        /* Find where to continue from afterwards */        /* Where to continue from afterwards */
1522    
1523        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
       new_recursive.after_call = ecode;  
1524    
1525        /* Now save the offset data. */        /* Now save the offset data */
1526    
1527        new_recursive.saved_max = md->offset_end;        new_recursive.saved_max = md->offset_end;
1528        if (new_recursive.saved_max <= REC_STACK_SAVE_MAX)        if (new_recursive.saved_max <= REC_STACK_SAVE_MAX)
# Line 1523  for (;;) Line 1533  for (;;)
1533            (int *)(pcre_malloc)(new_recursive.saved_max * sizeof(int));            (int *)(pcre_malloc)(new_recursive.saved_max * sizeof(int));
1534          if (new_recursive.offset_save == NULL) RRETURN(PCRE_ERROR_NOMEMORY);          if (new_recursive.offset_save == NULL) RRETURN(PCRE_ERROR_NOMEMORY);
1535          }          }
   
1536        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1537              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
       new_recursive.save_offset_top = offset_top;  
1538    
1539        /* OK, now we can do the recursion. For each top-level alternative we        /* OK, now we can do the recursion. After processing each alternative,
1540        restore the offset and recursion data. */        restore the offset data. If there were nested recursions, md->recursive
1541          might be changed, so reset it before looping. */
1542    
1543        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
1544        cbegroup = (*callpat >= OP_SBRA);        cbegroup = (*callpat >= OP_SBRA);
# Line 1538  for (;;) Line 1547  for (;;)
1547          if (cbegroup) md->match_function_type = MATCH_CBEGROUP;          if (cbegroup) md->match_function_type = MATCH_CBEGROUP;
1548          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1549            md, eptrb, RM6);            md, eptrb, RM6);
1550            memcpy(md->offset_vector, new_recursive.offset_save,
1551                new_recursive.saved_max * sizeof(int));
1552          if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)          if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
1553            {            {
1554            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
1555            md->recursive = new_recursive.prevrec;            md->recursive = new_recursive.prevrec;
1556            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
1557              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1558            MRRETURN(MATCH_MATCH);  
1559              /* Set where we got to in the subject, and reset the start in case
1560              it was changed by \K. This *is* propagated back out of a recursion,
1561              for Perl compatibility. */
1562    
1563              eptr = md->end_match_ptr;
1564              mstart = md->start_match_ptr;
1565              goto RECURSION_MATCHED;        /* Exit loop; end processing */
1566            }            }
1567          else if (rrc != MATCH_NOMATCH &&          else if (rrc != MATCH_NOMATCH &&
1568                  (rrc != MATCH_THEN || md->start_match_ptr != ecode))                  (rrc != MATCH_THEN || md->start_match_ptr != ecode))
# Line 1556  for (;;) Line 1574  for (;;)
1574            }            }
1575    
1576          md->recursive = &new_recursive;          md->recursive = &new_recursive;
         memcpy(md->offset_vector, new_recursive.offset_save,  
             new_recursive.saved_max * sizeof(int));  
1577          callpat += GET(callpat, 1);          callpat += GET(callpat, 1);
1578          }          }
1579        while (*callpat == OP_ALT);        while (*callpat == OP_ALT);
# Line 1568  for (;;) Line 1584  for (;;)
1584          (pcre_free)(new_recursive.offset_save);          (pcre_free)(new_recursive.offset_save);
1585        MRRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1586        }        }
1587      /* Control never reaches here */  
1588        RECURSION_MATCHED:
1589      /* "Once" brackets are like assertion brackets except that after a match,      break;
     the point in the subject string is not moved back. Thus there can never be  
     a move back into the brackets. Friedl calls these "atomic" subpatterns.  
     Check the alternative branches in turn - the matching won't pass the KET  
     for this kind of subpattern. If any one branch matches, we carry on as at  
     the end of a normal bracket, leaving the subject pointer, but resetting  
     the start-of-match value in case it was changed by \K. */  
   
     case OP_ONCE:  
     prev = ecode;  
     saved_eptr = eptr;  
   
     do  
       {  
       RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM7);  
       if (rrc == MATCH_MATCH)  /* Note: _not_ MATCH_ACCEPT */  
         {  
         mstart = md->start_match_ptr;  
         break;  
         }  
       if (rrc != MATCH_NOMATCH &&  
           (rrc != MATCH_THEN || md->start_match_ptr != ecode))  
         RRETURN(rrc);  
       ecode += GET(ecode,1);  
       }  
     while (*ecode == OP_ALT);  
   
     /* If hit the end of the group (which could be repeated), fail */  
   
     if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);  
   
     /* Continue after the group, updating the offsets high water mark, since  
     extracts may have been taken. */  
   
     do ecode += GET(ecode, 1); while (*ecode == OP_ALT);  
   
     offset_top = md->end_offset_top;  
     eptr = md->end_match_ptr;  
   
     /* For a non-repeating ket, just continue at this level. This also  
     happens for a repeating ket if no characters were matched in the group.  
     This is the forcible breaking of infinite loops as implemented in Perl  
     5.005. If there is an options reset, it will get obeyed in the normal  
     course of events. */  
   
     if (*ecode == OP_KET || eptr == saved_eptr)  
       {  
       ecode += 1+LINK_SIZE;  
       break;  
       }  
   
     /* The repeating kets try the rest of the pattern or restart from the  
     preceding bracket, in the appropriate order. The second "call" of match()  
     uses tail recursion, to avoid using another stack frame. */  
   
     if (*ecode == OP_KETRMIN)  
       {  
       RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM8);  
       if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
       ecode = prev;  
       goto TAIL_RECURSE;  
       }  
     else  /* OP_KETRMAX */  
       {  
       md->match_function_type = MATCH_CBEGROUP;  
       RMATCH(eptr, prev, offset_top, md, eptrb, RM9);  
       if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
       ecode += 1 + LINK_SIZE;  
       goto TAIL_RECURSE;  
       }  
     /* Control never gets here */  
1590    
1591      /* An alternation is the end of a branch; scan along to find the end of the      /* An alternation is the end of a branch; scan along to find the end of the
1592      bracketed group and go to there. */      bracketed group and go to there. */
# Line 1693  for (;;) Line 1639  for (;;)
1639      case OP_KETRMAX:      case OP_KETRMAX:
1640      case OP_KETRPOS:      case OP_KETRPOS:
1641      prev = ecode - GET(ecode, 1);      prev = ecode - GET(ecode, 1);
1642    
1643      /* If this was a group that remembered the subject start, in order to break      /* If this was a group that remembered the subject start, in order to break
1644      infinite repeats of empty string matches, retrieve the subject start from      infinite repeats of empty string matches, retrieve the subject start from
1645      the chain. Otherwise, set it NULL. */      the chain. Otherwise, set it NULL. */
1646    
1647      if (*prev >= OP_SBRA)      if (*prev >= OP_SBRA || *prev == OP_ONCE)
1648        {        {
1649        saved_eptr = eptrb->epb_saved_eptr;   /* Value at start of group */        saved_eptr = eptrb->epb_saved_eptr;   /* Value at start of group */
1650        eptrb = eptrb->epb_prev;              /* Backup to previous group */        eptrb = eptrb->epb_prev;              /* Backup to previous group */
1651        }        }
1652      else saved_eptr = NULL;      else saved_eptr = NULL;
1653    
1654      /* If we are at the end of an assertion group or an atomic group, stop      /* If we are at the end of an assertion group, stop matching and return
1655      matching and return MATCH_MATCH, but record the current high water mark for      MATCH_MATCH, but record the current high water mark for use by positive
1656      use by positive assertions. We also need to record the match start in case      assertions. We also need to record the match start in case it was changed
1657      it was changed by \K. */      by \K. */
1658    
1659      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
1660          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT)
         *prev == OP_ONCE)  
1661        {        {
1662        md->end_match_ptr = eptr;      /* For ONCE */        md->end_match_ptr = eptr;      /* For ONCE */
1663        md->end_offset_top = offset_top;        md->end_offset_top = offset_top;
# Line 1722  for (;;) Line 1667  for (;;)
1667    
1668      /* For capturing groups we have to check the group number back at the start      /* For capturing groups we have to check the group number back at the start
1669      and if necessary complete handling an extraction by setting the offsets and      and if necessary complete handling an extraction by setting the offsets and
1670      bumping the high water mark. Note that whole-pattern recursion is coded as      bumping the high water mark. Whole-pattern recursion is coded as a recurse
1671      a recurse into group 0, so it won't be picked up here. Instead, we catch it      into group 0, so it won't be picked up here. Instead, we catch it when the
1672      when the OP_END is reached. Other recursion is handled here. */      OP_END is reached. Other recursion is handled here. We just have to record
1673        the current subject position and start match pointer and give a MATCH
1674        return. */
1675    
1676      if (*prev == OP_CBRA || *prev == OP_SCBRA ||      if (*prev == OP_CBRA || *prev == OP_SCBRA ||
1677          *prev == OP_CBRAPOS || *prev == OP_SCBRAPOS)          *prev == OP_CBRAPOS || *prev == OP_SCBRAPOS)
# Line 1737  for (;;) Line 1684  for (;;)
1684        printf("\n");        printf("\n");
1685  #endif  #endif
1686    
1687          /* Handle a recursively called group. */
1688    
1689          if (md->recursive != NULL && md->recursive->group_num == number)
1690            {
1691            md->end_match_ptr = eptr;
1692            md->start_match_ptr = mstart;
1693            RRETURN(MATCH_MATCH);
1694            }
1695    
1696          /* Deal with capturing */
1697    
1698        md->capture_last = number;        md->capture_last = number;
1699        if (offset >= md->offset_max) md->offset_overflow = TRUE; else        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1700          {          {
# Line 1764  for (;;) Line 1722  for (;;)
1722          md->offset_vector[offset+1] = (int)(eptr - md->start_subject);          md->offset_vector[offset+1] = (int)(eptr - md->start_subject);
1723          if (offset_top <= offset) offset_top = offset + 2;          if (offset_top <= offset) offset_top = offset + 2;
1724          }          }
   
       /* Handle a recursively called group. Restore the offsets  
       appropriately and continue from after the call. */  
   
       if (md->recursive != NULL && md->recursive->group_num == number)  
         {  
         recursion_info *rec = md->recursive;  
         DPRINTF(("Recursion (%d) succeeded - continuing\n", number));  
         md->recursive = rec->prevrec;  
         memcpy(md->offset_vector, rec->offset_save,  
           rec->saved_max * sizeof(int));  
         offset_top = rec->save_offset_top;  
         ecode = rec->after_call;  
         break;  
         }  
1725        }        }
1726    
1727      /* For a non-repeating ket, just continue at this level. This also      /* For an ordinary non-repeating ket, just continue at this level. This
1728      happens for a repeating ket if no characters were matched in the group.      also happens for a repeating ket if no characters were matched in the
1729      This is the forcible breaking of infinite loops as implemented in Perl      group. This is the forcible breaking of infinite loops as implemented in
1730      5.005. If there is an options reset, it will get obeyed in the normal      Perl 5.005. For a non-repeating atomic group, establish a backup point by
1731      course of events. */      processing the rest of the pattern at a lower level. If this results in a
1732        NOMATCH return, pass MATCH_ONCE back to the original OP_ONCE level, thereby
1733        bypassing intermediate backup points, but resetting any captures that
1734        happened along the way. */
1735    
1736      if (*ecode == OP_KET || eptr == saved_eptr)      if (*ecode == OP_KET || eptr == saved_eptr)
1737        {        {
1738        ecode += 1 + LINK_SIZE;        if (*prev == OP_ONCE)
1739            {
1740            RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM12);
1741            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1742            md->once_target = prev;  /* Level at which to change to MATCH_NOMATCH */
1743            RRETURN(MATCH_ONCE);
1744            }
1745          ecode += 1 + LINK_SIZE;    /* Carry on at this level */
1746        break;        break;
1747        }        }
1748    
# Line 1807  for (;;) Line 1760  for (;;)
1760      /* The normal repeating kets try the rest of the pattern or restart from      /* The normal repeating kets try the rest of the pattern or restart from
1761      the preceding bracket, in the appropriate order. In the second case, we can      the preceding bracket, in the appropriate order. In the second case, we can
1762      use tail recursion to avoid using another stack frame, unless we have an      use tail recursion to avoid using another stack frame, unless we have an
1763      unlimited repeat of a group that can match an empty string. */      an atomic group or an unlimited repeat of a group that can match an empty
1764        string. */
1765    
1766      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1767        {        {
1768        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM12);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM64);
1769        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1770          if (*prev == OP_ONCE)
1771            {
1772            RMATCH(eptr, prev, offset_top, md, eptrb, RM66);
1773            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1774            md->once_target = prev;  /* Level at which to change to MATCH_NOMATCH */
1775            RRETURN(MATCH_ONCE);
1776            }
1777        if (*prev >= OP_SBRA)    /* Could match an empty string */        if (*prev >= OP_SBRA)    /* Could match an empty string */
1778          {          {
1779          md->match_function_type = MATCH_CBEGROUP;          md->match_function_type = MATCH_CBEGROUP;
# Line 1826  for (;;) Line 1787  for (;;)
1787        {        {
1788        if (*prev >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;        if (*prev >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
1789        RMATCH(eptr, prev, offset_top, md, eptrb, RM13);        RMATCH(eptr, prev, offset_top, md, eptrb, RM13);
1790          if (rrc == MATCH_ONCE && md->once_target == prev) rrc = MATCH_NOMATCH;
1791        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1792          if (*prev == OP_ONCE)
1793            {
1794            RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM65);
1795            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1796            md->once_target = prev;
1797            RRETURN(MATCH_ONCE);
1798            }
1799        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1800        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1801        }        }
# Line 5709  switch (frame->Xwhere) Line 5678  switch (frame->Xwhere)
5678    LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)    LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)
5679    LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)    LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)
5680    LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)    LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
5681    LBL(53) LBL(54) LBL(55) LBL(56) LBL(57) LBL(58) LBL(63)    LBL(53) LBL(54) LBL(55) LBL(56) LBL(57) LBL(58) LBL(63) LBL(64)
5682      LBL(65) LBL(66)
5683  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
5684    LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)    LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)
5685    LBL(32) LBL(34) LBL(42) LBL(46)    LBL(32) LBL(34) LBL(42) LBL(46)

Legend:
Removed from v.615  
changed lines
  Added in v.619

  ViewVC Help
Powered by ViewVC 1.1.5