/[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 529 by ph10, Mon May 31 17:28:08 2010 UTC revision 550 by ph10, Sun Oct 10 16:24:11 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 746  for (;;) Line 748  for (;;)
748    
749      md->start_match_ptr = ecode + 2;      md->start_match_ptr = ecode + 2;
750      RRETURN(MATCH_SKIP_ARG);      RRETURN(MATCH_SKIP_ARG);
751    
752        /* For THEN (and THEN_ARG) we pass back the address of the bracket or
753        the alt that is at the start of the current branch. This makes it possible
754        to skip back past alternatives that precede the THEN within the current
755        branch. */
756    
757      case OP_THEN:      case OP_THEN:
758      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
759        ims, eptrb, flags, RM54);        ims, eptrb, flags, RM54);
760      if (rrc != MATCH_NOMATCH) RRETURN(rrc);      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
761        md->start_match_ptr = ecode - GET(ecode, 1);
762      MRRETURN(MATCH_THEN);      MRRETURN(MATCH_THEN);
763    
764      case OP_THEN_ARG:      case OP_THEN_ARG:
765      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1+LINK_SIZE],
766        ims, eptrb, flags, RM58);        offset_top, md, ims, eptrb, flags, RM58);
767      if (rrc != MATCH_NOMATCH) RRETURN(rrc);      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
768      md->mark = ecode + 2;      md->start_match_ptr = ecode - GET(ecode, 1);
769        md->mark = ecode + LINK_SIZE + 2;
770      RRETURN(MATCH_THEN);      RRETURN(MATCH_THEN);
771    
772      /* 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 803  for (;;)
803        save_capture_last = md->capture_last;        save_capture_last = md->capture_last;
804    
805        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
806        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;        md->offset_vector[md->offset_end - number] =
807            (int)(eptr - md->start_subject);
808    
809        flags = (op == OP_SCBRA)? match_cbegroup : 0;        flags = (op == OP_SCBRA)? match_cbegroup : 0;
810        do        do
811          {          {
812          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
813            ims, eptrb, flags, RM1);            ims, eptrb, flags, RM1);
814          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);          if (rrc != MATCH_NOMATCH &&
815                (rrc != MATCH_THEN || md->start_match_ptr != ecode))
816              RRETURN(rrc);
817          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
818          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
819          }          }
# Line 862  for (;;) Line 874  for (;;)
874    
875        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
876          eptrb, flags, RM2);          eptrb, flags, RM2);
877        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH &&
878              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
879            RRETURN(rrc);
880        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
881        }        }
882      /* Control never reaches here. */      /* Control never reaches here. */
# Line 889  for (;;) Line 903  for (;;)
903          cb.callout_number   = ecode[LINK_SIZE+2];          cb.callout_number   = ecode[LINK_SIZE+2];
904          cb.offset_vector    = md->offset_vector;          cb.offset_vector    = md->offset_vector;
905          cb.subject          = (PCRE_SPTR)md->start_subject;          cb.subject          = (PCRE_SPTR)md->start_subject;
906          cb.subject_length   = md->end_subject - md->start_subject;          cb.subject_length   = (int)(md->end_subject - md->start_subject);
907          cb.start_match      = mstart - md->start_subject;          cb.start_match      = (int)(mstart - md->start_subject);
908          cb.current_position = eptr - md->start_subject;          cb.current_position = (int)(eptr - md->start_subject);
909          cb.pattern_position = GET(ecode, LINK_SIZE + 3);          cb.pattern_position = GET(ecode, LINK_SIZE + 3);
910          cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);          cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
911          cb.capture_top      = offset_top/2;          cb.capture_top      = offset_top/2;
# Line 1063  for (;;) Line 1077  for (;;)
1077          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
1078          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
1079          }          }
1080        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)        else if (rrc != MATCH_NOMATCH &&
1081                  (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1082          {          {
1083          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
1084          }          }
# Line 1117  for (;;) Line 1132  for (;;)
1132        {        {
1133        md->offset_vector[offset] =        md->offset_vector[offset] =
1134          md->offset_vector[md->offset_end - number];          md->offset_vector[md->offset_end - number];
1135        md->offset_vector[offset+1] = eptr - md->start_subject;        md->offset_vector[offset+1] = (int)(eptr - md->start_subject);
1136        if (offset_top <= offset) offset_top = offset + 2;        if (offset_top <= offset) offset_top = offset + 2;
1137        }        }
1138      ecode += 3;      ecode += 3;
# Line 1191  for (;;) Line 1206  for (;;)
1206          mstart = md->start_match_ptr;   /* In case \K reset it */          mstart = md->start_match_ptr;   /* In case \K reset it */
1207          break;          break;
1208          }          }
1209        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH &&
1210              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1211            RRETURN(rrc);
1212        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1213        }        }
1214      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 1225  for (;;) Line 1242  for (;;)
1242          do ecode += GET(ecode,1); while (*ecode == OP_ALT);          do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1243          break;          break;
1244          }          }
1245        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH &&
1246              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1247            RRETURN(rrc);
1248        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1249        }        }
1250      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 1280  for (;;) Line 1299  for (;;)
1299        cb.callout_number   = ecode[1];        cb.callout_number   = ecode[1];
1300        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1301        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1302        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = (int)(md->end_subject - md->start_subject);
1303        cb.start_match      = mstart - md->start_subject;        cb.start_match      = (int)(mstart - md->start_subject);
1304        cb.current_position = eptr - md->start_subject;        cb.current_position = (int)(eptr - md->start_subject);
1305        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
1306        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
1307        cb.capture_top      = offset_top/2;        cb.capture_top      = offset_top/2;
# Line 1362  for (;;) Line 1381  for (;;)
1381              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1382            MRRETURN(MATCH_MATCH);            MRRETURN(MATCH_MATCH);
1383            }            }
1384          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)          else if (rrc != MATCH_NOMATCH &&
1385                    (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1386            {            {
1387            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1388            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
# Line 1405  for (;;) Line 1425  for (;;)
1425          mstart = md->start_match_ptr;          mstart = md->start_match_ptr;
1426          break;          break;
1427          }          }
1428        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH &&
1429              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1430            RRETURN(rrc);
1431        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1432        }        }
1433      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 1559  for (;;) Line 1581  for (;;)
1581          {          {
1582          md->offset_vector[offset] =          md->offset_vector[offset] =
1583            md->offset_vector[md->offset_end - number];            md->offset_vector[md->offset_end - number];
1584          md->offset_vector[offset+1] = eptr - md->start_subject;          md->offset_vector[offset+1] = (int)(eptr - md->start_subject);
1585          if (offset_top <= offset) offset_top = offset + 2;          if (offset_top <= offset) offset_top = offset + 2;
1586          }          }
1587    
# Line 2233  for (;;) Line 2255  for (;;)
2255        referenced subpattern. */        referenced subpattern. */
2256    
2257        if (offset >= offset_top || md->offset_vector[offset] < 0)        if (offset >= offset_top || md->offset_vector[offset] < 0)
2258          length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;          length = (md->jscript_compat)? 0 : (int)(md->end_subject - eptr + 1);
2259        else        else
2260          length = md->offset_vector[offset+1] - md->offset_vector[offset];          length = md->offset_vector[offset+1] - md->offset_vector[offset];
2261    
# Line 5956  for(;;) Line 5978  for(;;)
5978        while (start_match < end_subject)        while (start_match < end_subject)
5979          {          {
5980          register unsigned int c = *start_match;          register unsigned int c = *start_match;
5981          if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++;          if ((start_bits[c/8] & (1 << (c&7))) == 0)
5982            else break;            {
5983              start_match++;
5984    #ifdef SUPPORT_UTF8
5985              if (utf8)
5986                while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
5987                  start_match++;
5988    #endif
5989              }
5990            else break;
5991          }          }
5992        }        }
5993      }   /* Starting optimizations */      }   /* Starting optimizations */
# Line 6058  for(;;) Line 6088  for(;;)
6088    
6089    switch(rc)    switch(rc)
6090      {      {
6091      /* 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
6092      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. */
6093      We treat this as NOMATCH. THEN at this level acts exactly like PRUNE. */  
6094        case MATCH_SKIP:
6095        if (md->start_match_ptr != start_match)
6096          {
6097          new_start_match = md->start_match_ptr;
6098          break;
6099          }
6100        /* Fall through */
6101    
6102        /* If MATCH_SKIP_ARG reaches this level it means that a MARK that matched
6103        the SKIP's arg was not found. We also treat this as NOMATCH. */
6104    
6105        case MATCH_SKIP_ARG:
6106        /* Fall through */
6107    
6108        /* NOMATCH and PRUNE advance by one character. THEN at this level acts
6109        exactly like PRUNE. */
6110    
6111      case MATCH_NOMATCH:      case MATCH_NOMATCH:
6112      case MATCH_PRUNE:      case MATCH_PRUNE:
     case MATCH_SKIP_ARG:  
6113      case MATCH_THEN:      case MATCH_THEN:
6114      new_start_match = start_match + 1;      new_start_match = start_match + 1;
6115  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 6074  for(;;) Line 6119  for(;;)
6119  #endif  #endif
6120      break;      break;
6121    
     /* SKIP passes back the next starting point explicitly. */  
   
     case MATCH_SKIP:  
     new_start_match = md->start_match_ptr;  
     break;  
   
6122      /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */      /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */
6123    
6124      case MATCH_COMMIT:      case MATCH_COMMIT:
# Line 6176  if (rc == MATCH_MATCH || rc == MATCH_ACC Line 6215  if (rc == MATCH_MATCH || rc == MATCH_ACC
6215    
6216    if (offsetcount < 2) rc = 0; else    if (offsetcount < 2) rc = 0; else
6217      {      {
6218      offsets[0] = md->start_match_ptr - md->start_subject;      offsets[0] = (int)(md->start_match_ptr - md->start_subject);
6219      offsets[1] = md->end_match_ptr - md->start_subject;      offsets[1] = (int)(md->end_match_ptr - md->start_subject);
6220      }      }
6221    
6222    DPRINTF((">>>> returning %d\n", rc));    DPRINTF((">>>> returning %d\n", rc));
# Line 6209  if (start_partial != NULL) Line 6248  if (start_partial != NULL)
6248    md->mark = NULL;    md->mark = NULL;
6249    if (offsetcount > 1)    if (offsetcount > 1)
6250      {      {
6251      offsets[0] = start_partial - (USPTR)subject;      offsets[0] = (int)(start_partial - (USPTR)subject);
6252      offsets[1] = end_subject - (USPTR)subject;      offsets[1] = (int)(end_subject - (USPTR)subject);
6253      }      }
6254    rc = PCRE_ERROR_PARTIAL;    rc = PCRE_ERROR_PARTIAL;
6255    }    }

Legend:
Removed from v.529  
changed lines
  Added in v.550

  ViewVC Help
Powered by ViewVC 1.1.5