/[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 530 by ph10, Tue Jun 1 13:42:06 2010 UTC revision 551 by ph10, Sun Oct 10 17:33:07 2010 UTC
# Line 295  argument of match(), which never changes Line 295  argument of match(), which never changes
295  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\
296    {\    {\
297    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\
298      if (newframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\
299    frame->Xwhere = rw; \    frame->Xwhere = rw; \
300    newframe->Xeptr = ra;\    newframe->Xeptr = ra;\
301    newframe->Xecode = rb;\    newframe->Xecode = rb;\
# Line 488  heap whenever RMATCH() does a "recursion Line 489  heap whenever RMATCH() does a "recursion
489    
490  #ifdef NO_RECURSE  #ifdef NO_RECURSE
491  heapframe *frame = (pcre_stack_malloc)(sizeof(heapframe));  heapframe *frame = (pcre_stack_malloc)(sizeof(heapframe));
492    if (frame == NULL) RRETURN(PCRE_ERROR_NOMEMORY);
493  frame->Xprevframe = NULL;            /* Marks the top level */  frame->Xprevframe = NULL;            /* Marks the top level */
494    
495  /* Copy in the original argument variables */  /* Copy in the original argument variables */
# Line 708  for (;;) Line 710  for (;;)
710      case OP_FAIL:      case OP_FAIL:
711      MRRETURN(MATCH_NOMATCH);      MRRETURN(MATCH_NOMATCH);
712    
713        /* COMMIT overrides PRUNE, SKIP, and THEN */
714    
715      case OP_COMMIT:      case OP_COMMIT:
716      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
717        ims, eptrb, flags, RM52);        ims, eptrb, flags, RM52);
718      if (rrc != MATCH_NOMATCH) RRETURN(rrc);      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE &&
719            rrc != MATCH_SKIP && rrc != MATCH_SKIP_ARG &&
720            rrc != MATCH_THEN)
721          RRETURN(rrc);
722      MRRETURN(MATCH_COMMIT);      MRRETURN(MATCH_COMMIT);
723    
724        /* PRUNE overrides THEN */
725    
726      case OP_PRUNE:      case OP_PRUNE:
727      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
728        ims, eptrb, flags, RM51);        ims, eptrb, flags, RM51);
729      if (rrc != MATCH_NOMATCH) RRETURN(rrc);      if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
730      MRRETURN(MATCH_PRUNE);      MRRETURN(MATCH_PRUNE);
731    
732      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
733      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
734        ims, eptrb, flags, RM56);        ims, eptrb, flags, RM56);
735      if (rrc != MATCH_NOMATCH) RRETURN(rrc);      if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
736      md->mark = ecode + 2;      md->mark = ecode + 2;
737      RRETURN(MATCH_PRUNE);      RRETURN(MATCH_PRUNE);
738    
739        /* SKIP overrides PRUNE and THEN */
740    
741      case OP_SKIP:      case OP_SKIP:
742      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
743        ims, eptrb, flags, RM53);        ims, eptrb, flags, RM53);
744      if (rrc != MATCH_NOMATCH) RRETURN(rrc);      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)
745          RRETURN(rrc);
746      md->start_match_ptr = eptr;   /* Pass back current position */      md->start_match_ptr = eptr;   /* Pass back current position */
747      MRRETURN(MATCH_SKIP);      MRRETURN(MATCH_SKIP);
748    
749      case OP_SKIP_ARG:      case OP_SKIP_ARG:
750      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
751        ims, eptrb, flags, RM57);        ims, eptrb, flags, RM57);
752      if (rrc != MATCH_NOMATCH) RRETURN(rrc);      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)
753          RRETURN(rrc);
754    
755      /* Pass back the current skip name by overloading md->start_match_ptr and      /* Pass back the current skip name by overloading md->start_match_ptr and
756      returning the special MATCH_SKIP_ARG return code. This will either be      returning the special MATCH_SKIP_ARG return code. This will either be
# Line 746  for (;;) Line 759  for (;;)
759    
760      md->start_match_ptr = ecode + 2;      md->start_match_ptr = ecode + 2;
761      RRETURN(MATCH_SKIP_ARG);      RRETURN(MATCH_SKIP_ARG);
762    
763        /* For THEN (and THEN_ARG) we pass back the address of the bracket or
764        the alt that is at the start of the current branch. This makes it possible
765        to skip back past alternatives that precede the THEN within the current
766        branch. */
767    
768      case OP_THEN:      case OP_THEN:
769      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
770        ims, eptrb, flags, RM54);        ims, eptrb, flags, RM54);
771      if (rrc != MATCH_NOMATCH) RRETURN(rrc);      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
772        md->start_match_ptr = ecode - GET(ecode, 1);
773      MRRETURN(MATCH_THEN);      MRRETURN(MATCH_THEN);
774    
775      case OP_THEN_ARG:      case OP_THEN_ARG:
776      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1+LINK_SIZE],
777        ims, eptrb, flags, RM58);        offset_top, md, ims, eptrb, flags, RM58);
778      if (rrc != MATCH_NOMATCH) RRETURN(rrc);      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
779      md->mark = ecode + 2;      md->start_match_ptr = ecode - GET(ecode, 1);
780        md->mark = ecode + LINK_SIZE + 2;
781      RRETURN(MATCH_THEN);      RRETURN(MATCH_THEN);
782    
783      /* Handle a capturing bracket. If there is space in the offset vector, save      /* Handle a capturing bracket. If there is space in the offset vector, save
# Line 794  for (;;) Line 814  for (;;)
814        save_capture_last = md->capture_last;        save_capture_last = md->capture_last;
815    
816        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
817        md->offset_vector[md->offset_end - number] =        md->offset_vector[md->offset_end - number] =
818          (int)(eptr - md->start_subject);          (int)(eptr - md->start_subject);
819    
820        flags = (op == OP_SCBRA)? match_cbegroup : 0;        flags = (op == OP_SCBRA)? match_cbegroup : 0;
# Line 802  for (;;) Line 822  for (;;)
822          {          {
823          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
824            ims, eptrb, flags, RM1);            ims, eptrb, flags, RM1);
825          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);          if (rrc != MATCH_NOMATCH &&
826                (rrc != MATCH_THEN || md->start_match_ptr != ecode))
827              RRETURN(rrc);
828          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
829          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
830          }          }
# Line 863  for (;;) Line 885  for (;;)
885    
886        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
887          eptrb, flags, RM2);          eptrb, flags, RM2);
888        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH &&
889              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
890            RRETURN(rrc);
891        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
892        }        }
893      /* Control never reaches here. */      /* Control never reaches here. */
# Line 1064  for (;;) Line 1088  for (;;)
1088          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
1089          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
1090          }          }
1091        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)        else if (rrc != MATCH_NOMATCH &&
1092                  (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1093          {          {
1094          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
1095          }          }
# Line 1192  for (;;) Line 1217  for (;;)
1217          mstart = md->start_match_ptr;   /* In case \K reset it */          mstart = md->start_match_ptr;   /* In case \K reset it */
1218          break;          break;
1219          }          }
1220        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH &&
1221              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1222            RRETURN(rrc);
1223        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1224        }        }
1225      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 1226  for (;;) Line 1253  for (;;)
1253          do ecode += GET(ecode,1); while (*ecode == OP_ALT);          do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1254          break;          break;
1255          }          }
1256        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH &&
1257              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1258            RRETURN(rrc);
1259        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1260        }        }
1261      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 1363  for (;;) Line 1392  for (;;)
1392              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1393            MRRETURN(MATCH_MATCH);            MRRETURN(MATCH_MATCH);
1394            }            }
1395          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)          else if (rrc != MATCH_NOMATCH &&
1396                    (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1397            {            {
1398            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1399            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
# Line 1406  for (;;) Line 1436  for (;;)
1436          mstart = md->start_match_ptr;          mstart = md->start_match_ptr;
1437          break;          break;
1438          }          }
1439        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH &&
1440              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1441            RRETURN(rrc);
1442        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1443        }        }
1444      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 5957  for(;;) Line 5989  for(;;)
5989        while (start_match < end_subject)        while (start_match < end_subject)
5990          {          {
5991          register unsigned int c = *start_match;          register unsigned int c = *start_match;
5992          if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++;          if ((start_bits[c/8] & (1 << (c&7))) == 0)
5993            else break;            {
5994              start_match++;
5995    #ifdef SUPPORT_UTF8
5996              if (utf8)
5997                while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
5998                  start_match++;
5999    #endif
6000              }
6001            else break;
6002          }          }
6003        }        }
6004      }   /* Starting optimizations */      }   /* Starting optimizations */
# Line 6059  for(;;) Line 6099  for(;;)
6099    
6100    switch(rc)    switch(rc)
6101      {      {
6102      /* NOMATCH and PRUNE advance by one character. If MATCH_SKIP_ARG reaches      /* SKIP passes back the next starting point explicitly, but if it is the
6103      this level it means that a MARK that matched the SKIP's arg was not found.      same as the match we have just done, treat it as NOMATCH. */
6104      We treat this as NOMATCH. THEN at this level acts exactly like PRUNE. */  
6105        case MATCH_SKIP:
6106        if (md->start_match_ptr != start_match)
6107          {
6108          new_start_match = md->start_match_ptr;
6109          break;
6110          }
6111        /* Fall through */
6112    
6113        /* If MATCH_SKIP_ARG reaches this level it means that a MARK that matched
6114        the SKIP's arg was not found. We also treat this as NOMATCH. */
6115    
6116        case MATCH_SKIP_ARG:
6117        /* Fall through */
6118    
6119        /* NOMATCH and PRUNE advance by one character. THEN at this level acts
6120        exactly like PRUNE. */
6121    
6122      case MATCH_NOMATCH:      case MATCH_NOMATCH:
6123      case MATCH_PRUNE:      case MATCH_PRUNE:
     case MATCH_SKIP_ARG:  
6124      case MATCH_THEN:      case MATCH_THEN:
6125      new_start_match = start_match + 1;      new_start_match = start_match + 1;
6126  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 6075  for(;;) Line 6130  for(;;)
6130  #endif  #endif
6131      break;      break;
6132    
     /* SKIP passes back the next starting point explicitly. */  
   
     case MATCH_SKIP:  
     new_start_match = md->start_match_ptr;  
     break;  
   
6133      /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */      /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */
6134    
6135      case MATCH_COMMIT:      case MATCH_COMMIT:

Legend:
Removed from v.530  
changed lines
  Added in v.551

  ViewVC Help
Powered by ViewVC 1.1.5