/[pcre]/code/branches/pcre16/pcre_exec.c
ViewVC logotype

Diff of /code/branches/pcre16/pcre_exec.c

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

revision 178 by ph10, Wed Jun 13 08:44:34 2007 UTC revision 381 by ph10, Tue Mar 3 16:08:23 2009 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2007 University of Cambridge             Copyright (c) 1997-2009 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 42  POSSIBILITY OF SUCH DAMAGE. Line 42  POSSIBILITY OF SUCH DAMAGE.
42  pattern matching using an NFA algorithm, trying to mimic Perl as closely as  pattern matching using an NFA algorithm, trying to mimic Perl as closely as
43  possible. There are also some static supporting functions. */  possible. There are also some static supporting functions. */
44    
45    #ifdef HAVE_CONFIG_H
46    #include "config.h"
47    #endif
48    
49  #define NLBLOCK md             /* Block containing newline information */  #define NLBLOCK md             /* Block containing newline information */
50  #define PSSTART start_subject  /* Field containing processed string start */  #define PSSTART start_subject  /* Field containing processed string start */
51  #define PSEND   end_subject    /* Field containing processed string end */  #define PSEND   end_subject    /* Field containing processed string end */
# Line 53  possible. There are also some static sup Line 57  possible. There are also some static sup
57  #undef min  #undef min
58  #undef max  #undef max
59    
 /* The chain of eptrblocks for tail recursions uses memory in stack workspace,  
 obtained at top level, the size of which is defined by EPTR_WORK_SIZE. */  
   
 #define EPTR_WORK_SIZE (1000)  
   
60  /* Flag bits for the match() function */  /* Flag bits for the match() function */
61    
62  #define match_condassert     0x01  /* Called to check a condition assertion */  #define match_condassert     0x01  /* Called to check a condition assertion */
63  #define match_cbegroup       0x02  /* Could-be-empty unlimited repeat group */  #define match_cbegroup       0x02  /* Could-be-empty unlimited repeat group */
 #define match_tail_recursed  0x04  /* Tail recursive call */  
64    
65  /* Non-error returns from the match() function. Error returns are externally  /* Non-error returns from the match() function. Error returns are externally
66  defined PCRE_ERROR_xxx codes, which are all negative. */  defined PCRE_ERROR_xxx codes, which are all negative. */
# Line 70  defined PCRE_ERROR_xxx codes, which are Line 68  defined PCRE_ERROR_xxx codes, which are
68  #define MATCH_MATCH        1  #define MATCH_MATCH        1
69  #define MATCH_NOMATCH      0  #define MATCH_NOMATCH      0
70    
71    /* Special internal returns from the match() function. Make them sufficiently
72    negative to avoid the external error codes. */
73    
74    #define MATCH_COMMIT       (-999)
75    #define MATCH_PRUNE        (-998)
76    #define MATCH_SKIP         (-997)
77    #define MATCH_THEN         (-996)
78    
79  /* Maximum number of ints of offset to save on the stack for recursive calls.  /* Maximum number of ints of offset to save on the stack for recursive calls.
80  If the offset vector is bigger, malloc is used. This should be a multiple of 3,  If the offset vector is bigger, malloc is used. This should be a multiple of 3,
81  because the offset vector is always a multiple of 3 long. */  because the offset vector is always a multiple of 3 long. */
# Line 152  printf("\n"); Line 158  printf("\n");
158    
159  if (length > md->end_subject - eptr) return FALSE;  if (length > md->end_subject - eptr) return FALSE;
160    
161  /* Separate the caselesss case for speed */  /* Separate the caseless case for speed. In UTF-8 mode we can only do this
162    properly if Unicode properties are supported. Otherwise, we can check only
163    ASCII characters. */
164    
165  if ((ims & PCRE_CASELESS) != 0)  if ((ims & PCRE_CASELESS) != 0)
166    {    {
167    #ifdef SUPPORT_UTF8
168    #ifdef SUPPORT_UCP
169      if (md->utf8)
170        {
171        USPTR endptr = eptr + length;
172        while (eptr < endptr)
173          {
174          int c, d;
175          GETCHARINC(c, eptr);
176          GETCHARINC(d, p);
177          if (c != d && c != UCD_OTHERCASE(d)) return FALSE;
178          }
179        }
180      else
181    #endif
182    #endif
183    
184      /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
185      is no UCP support. */
186    
187    while (length-- > 0)    while (length-- > 0)
188      if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE;      { if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; }
189    }    }
190    
191    /* In the caseful case, we can just compare the bytes, whether or not we
192    are in UTF-8 mode. */
193    
194  else  else
195    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
196    
# Line 205  variable instead of being passed in the Line 237  variable instead of being passed in the
237  ****************************************************************************  ****************************************************************************
238  ***************************************************************************/  ***************************************************************************/
239    
240    /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN
241  /* Numbers for RMATCH calls */  below must be updated in sync.  */
242    
243  enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM6,  RM7,  RM8,  RM9,  RM10,  enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM6,  RM7,  RM8,  RM9,  RM10,
244         RM11,  RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,         RM11,  RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,
245         RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,         RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,
246         RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,         RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
247         RM41,  RM42, RM43, RM44, RM45, RM46, RM47 };         RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
248           RM51,  RM52, RM53, RM54 };
249    
250  /* 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
251  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 384  Arguments: Line 416  Arguments:
416                   match_condassert - this is an assertion condition                   match_condassert - this is an assertion condition
417                   match_cbegroup - this is the start of an unlimited repeat                   match_cbegroup - this is the start of an unlimited repeat
418                     group that can match an empty string                     group that can match an empty string
                  match_tail_recursed - this is a tail_recursed group  
419     rdepth      the recursion depth     rdepth      the recursion depth
420    
421  Returns:       MATCH_MATCH if matched            )  these values are >= 0  Returns:       MATCH_MATCH if matched            )  these values are >= 0
# Line 586  original_ims = ims;    /* Save for reset Line 617  original_ims = ims;    /* Save for reset
617  string, the match_cbegroup flag is set. When this is the case, add the current  string, the match_cbegroup flag is set. When this is the case, add the current
618  subject pointer to the chain of such remembered pointers, to be checked when we  subject pointer to the chain of such remembered pointers, to be checked when we
619  hit the closing ket, in order to break infinite loops that match no characters.  hit the closing ket, in order to break infinite loops that match no characters.
620  When match() is called in other circumstances, don't add to the chain. If this  When match() is called in other circumstances, don't add to the chain. The
621  is a tail recursion, use a block from the workspace, as the one on the stack is  match_cbegroup flag must NOT be used with tail recursion, because the memory
622  already used. */  block that is used is on the stack, so a new one may be required for each
623    match(). */
624    
625  if ((flags & match_cbegroup) != 0)  if ((flags & match_cbegroup) != 0)
626    {    {
627    eptrblock *p;    newptrb.epb_saved_eptr = eptr;
628    if ((flags & match_tail_recursed) != 0)    newptrb.epb_prev = eptrb;
629      {    eptrb = &newptrb;
     if (md->eptrn >= EPTR_WORK_SIZE) RRETURN(PCRE_ERROR_NULLWSLIMIT);  
     p = md->eptrchain + md->eptrn++;  
     }  
   else p = &newptrb;  
   p->epb_saved_eptr = eptr;  
   p->epb_prev = eptrb;  
   eptrb = p;  
630    }    }
631    
632  /* Now start processing the opcodes. */  /* Now start processing the opcodes. */
# Line 621  for (;;) Line 646  for (;;)
646    
647    switch(op)    switch(op)
648      {      {
649        case OP_FAIL:
650        RRETURN(MATCH_NOMATCH);
651    
652        case OP_PRUNE:
653        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
654          ims, eptrb, flags, RM51);
655        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
656        RRETURN(MATCH_PRUNE);
657    
658        case OP_COMMIT:
659        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
660          ims, eptrb, flags, RM52);
661        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
662        RRETURN(MATCH_COMMIT);
663    
664        case OP_SKIP:
665        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
666          ims, eptrb, flags, RM53);
667        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
668        md->start_match_ptr = eptr;   /* Pass back current position */
669        RRETURN(MATCH_SKIP);
670    
671        case OP_THEN:
672        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
673          ims, eptrb, flags, RM54);
674        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
675        RRETURN(MATCH_THEN);
676    
677      /* 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
678      the current subject position in the working slot at the top of the vector.      the current subject position in the working slot at the top of the vector.
679      We mustn't change the current values of the data slot, because they may be      We mustn't change the current values of the data slot, because they may be
# Line 662  for (;;) Line 715  for (;;)
715          {          {
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, RM1);            ims, eptrb, flags, RM1);
718          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
719          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
720          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
721          }          }
# Line 677  for (;;) Line 730  for (;;)
730        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
731        }        }
732    
733      /* Insufficient room for saving captured contents. Treat as a non-capturing      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
734      bracket. */      as a non-capturing bracket. */
735    
736        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
737        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
738    
739      DPRINTF(("insufficient capture room: treat as non-capturing\n"));      DPRINTF(("insufficient capture room: treat as non-capturing\n"));
740    
741        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
742        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
743    
744      /* Non-capturing bracket. Loop for all the alternatives. When we get to the      /* Non-capturing bracket. Loop for all the alternatives. When we get to the
745      final alternative within the brackets, we would return the result of a      final alternative within the brackets, we would return the result of a
746      recursive call to match() whatever happened. We can reduce stack usage by      recursive call to match() whatever happened. We can reduce stack usage by
747      turning this into a tail recursion. */      turning this into a tail recursion, except in the case when match_cbegroup
748        is set.*/
749    
750      case OP_BRA:      case OP_BRA:
751      case OP_SBRA:      case OP_SBRA:
# Line 693  for (;;) Line 753  for (;;)
753      flags = (op >= OP_SBRA)? match_cbegroup : 0;      flags = (op >= OP_SBRA)? match_cbegroup : 0;
754      for (;;)      for (;;)
755        {        {
756        if (ecode[GET(ecode, 1)] != OP_ALT)        if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */
757          {          {
758          ecode += _pcre_OP_lengths[*ecode];          if (flags == 0)    /* Not a possibly empty group */
759          flags |= match_tail_recursed;            {
760          DPRINTF(("bracket 0 tail recursion\n"));            ecode += _pcre_OP_lengths[*ecode];
761          goto TAIL_RECURSE;            DPRINTF(("bracket 0 tail recursion\n"));
762              goto TAIL_RECURSE;
763              }
764    
765            /* Possibly empty group; can't use tail recursion. */
766    
767            RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
768              eptrb, flags, RM48);
769            RRETURN(rrc);
770          }          }
771    
772        /* For non-final alternatives, continue the loop for a NOMATCH result;        /* For non-final alternatives, continue the loop for a NOMATCH result;
# Line 706  for (;;) Line 774  for (;;)
774    
775        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
776          eptrb, flags, RM2);          eptrb, flags, RM2);
777        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
778        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
779        }        }
780      /* Control never reaches here. */      /* Control never reaches here. */
# Line 719  for (;;) Line 787  for (;;)
787    
788      case OP_COND:      case OP_COND:
789      case OP_SCOND:      case OP_SCOND:
790        /* Because of the way auto-callout works during compile, a callout item is
791        inserted between OP_COND and an assertion condition. */
792    
793        if (ecode[LINK_SIZE+1] == OP_CALLOUT)
794          {
795          if (pcre_callout != NULL)
796            {
797            pcre_callout_block cb;
798            cb.version          = 1;   /* Version 1 of the callout block */
799            cb.callout_number   = ecode[LINK_SIZE+2];
800            cb.offset_vector    = md->offset_vector;
801            cb.subject          = (PCRE_SPTR)md->start_subject;
802            cb.subject_length   = md->end_subject - md->start_subject;
803            cb.start_match      = mstart - md->start_subject;
804            cb.current_position = eptr - md->start_subject;
805            cb.pattern_position = GET(ecode, LINK_SIZE + 3);
806            cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
807            cb.capture_top      = offset_top/2;
808            cb.capture_last     = md->capture_last;
809            cb.callout_data     = md->callout_data;
810            if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);
811            if (rrc < 0) RRETURN(rrc);
812            }
813          ecode += _pcre_OP_lengths[OP_CALLOUT];
814          }
815    
816        /* Now see what the actual condition is */
817    
818      if (ecode[LINK_SIZE+1] == OP_RREF)         /* Recursion test */      if (ecode[LINK_SIZE+1] == OP_RREF)         /* Recursion test */
819        {        {
820        offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/        offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/
# Line 754  for (;;) Line 850  for (;;)
850          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
851          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
852          }          }
853        else if (rrc != MATCH_NOMATCH)        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
854          {          {
855          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
856          }          }
# Line 766  for (;;) Line 862  for (;;)
862        }        }
863    
864      /* We are now at the branch that is to be obeyed. As there is only one,      /* We are now at the branch that is to be obeyed. As there is only one,
865      we can use tail recursion to avoid using another stack frame. If the second      we can use tail recursion to avoid using another stack frame, except when
866      alternative doesn't exist, we can just plough on. */      match_cbegroup is required for an unlimited repeat of a possibly empty
867        group. If the second alternative doesn't exist, we can just plough on. */
868    
869      if (condition || *ecode == OP_ALT)      if (condition || *ecode == OP_ALT)
870        {        {
871        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
872        flags = match_tail_recursed | ((op == OP_SCOND)? match_cbegroup : 0);        if (op == OP_SCOND)        /* Possibly empty group */
873        goto TAIL_RECURSE;          {
874            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
875            RRETURN(rrc);
876            }
877          else                       /* Group must match something */
878            {
879            flags = 0;
880            goto TAIL_RECURSE;
881            }
882        }        }
883      else      else                         /* Condition false & no 2nd alternative */
884        {        {
885        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
886        }        }
887      break;      break;
888    
889    
890      /* End of the pattern. If we are in a top-level recursion, we should      /* End of the pattern, either real or forced. If we are in a top-level
891      restore the offsets appropriately and continue from after the call. */      recursion, we should restore the offsets appropriately and continue from
892        after the call. */
893    
894        case OP_ACCEPT:
895      case OP_END:      case OP_END:
896      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL && md->recursive->group_num == 0)
897        {        {
# Line 805  for (;;) Line 912  for (;;)
912      if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);      if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);
913      md->end_match_ptr = eptr;           /* Record where we ended */      md->end_match_ptr = eptr;           /* Record where we ended */
914      md->end_offset_top = offset_top;    /* and how many extracts were taken */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
915      md->start_match_ptr = mstart;  /* and the start (\K can modify) */      md->start_match_ptr = mstart;       /* and the start (\K can modify) */
916      RRETURN(MATCH_MATCH);      RRETURN(MATCH_MATCH);
917    
918      /* Change option settings */      /* Change option settings */
# Line 829  for (;;) Line 936  for (;;)
936        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
937          RM4);          RM4);
938        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
939        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
940        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
941        }        }
942      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 856  for (;;) Line 963  for (;;)
963        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
964          RM5);          RM5);
965        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
966        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
967        ecode += GET(ecode,1);        ecode += GET(ecode,1);
968        }        }
969      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 880  for (;;) Line 987  for (;;)
987          {          {
988          eptr--;          eptr--;
989          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
990          BACKCHAR(eptr)          BACKCHAR(eptr);
991          }          }
992        }        }
993      else      else
# Line 993  for (;;) Line 1100  for (;;)
1100              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1101            RRETURN(MATCH_MATCH);            RRETURN(MATCH_MATCH);
1102            }            }
1103          else if (rrc != MATCH_NOMATCH)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1104            {            {
1105            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1106            RRETURN(rrc);            RRETURN(rrc);
# Line 1027  for (;;) Line 1134  for (;;)
1134    
1135      do      do
1136        {        {
1137        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
         eptrb, 0, RM7);  
1138        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
1139        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1140        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1141        }        }
1142      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 1073  for (;;) Line 1179  for (;;)
1179    
1180      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1181        {        {
1182        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8);
         RM8);  
1183        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1184        ecode = prev;        ecode = prev;
1185        flags = match_tail_recursed;        flags = 0;
1186        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1187        }        }
1188      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
# Line 1085  for (;;) Line 1190  for (;;)
1190        RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
1191        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1192        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1193        flags = match_tail_recursed;        flags = 0;
1194        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1195        }        }
1196      /* Control never gets here */      /* Control never gets here */
# Line 1097  for (;;) Line 1202  for (;;)
1202      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1203      break;      break;
1204    
1205      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1206      that it may occur zero times. It may repeat infinitely, or not at all -      indicating that it may occur zero times. It may repeat infinitely, or not
1207      i.e. it could be ()* or ()? in the pattern. Brackets with fixed upper      at all - i.e. it could be ()* or ()? or even (){0} in the pattern. Brackets
1208      repeat limits are compiled as a number of copies, with the optional ones      with fixed upper repeat limits are compiled as a number of copies, with the
1209      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1210    
1211      case OP_BRAZERO:      case OP_BRAZERO:
1212        {        {
# Line 1123  for (;;) Line 1228  for (;;)
1228        }        }
1229      break;      break;
1230    
1231        case OP_SKIPZERO:
1232          {
1233          next = ecode+1;
1234          do next += GET(next,1); while (*next == OP_ALT);
1235          ecode = next + 1 + LINK_SIZE;
1236          }
1237        break;
1238    
1239      /* End of a group, repeated or non-repeating. */      /* End of a group, repeated or non-repeating. */
1240    
1241      case OP_KET:      case OP_KET:
# Line 1216  for (;;) Line 1329  for (;;)
1329    
1330      /* The repeating kets try the rest of the pattern or restart from the      /* The repeating kets try the rest of the pattern or restart from the
1331      preceding bracket, in the appropriate order. In the second case, we can use      preceding bracket, in the appropriate order. In the second case, we can use
1332      tail recursion to avoid using another stack frame. */      tail recursion to avoid using another stack frame, unless we have an
1333        unlimited repeat of a group that can match an empty string. */
1334    
1335      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
1336    
1337      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1338        {        {
1339        RMATCH(eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);
         RM12);  
1340        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1341          if (flags != 0)    /* Could match an empty string */
1342            {
1343            RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
1344            RRETURN(rrc);
1345            }
1346        ecode = prev;        ecode = prev;
       flags |= match_tail_recursed;  
1347        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1348        }        }
1349      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
# Line 1234  for (;;) Line 1351  for (;;)
1351        RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
1352        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1353        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1354        flags = match_tail_recursed;        flags = 0;
1355        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1356        }        }
1357      /* Control never gets here */      /* Control never gets here */
# Line 1366  for (;;) Line 1483  for (;;)
1483      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1484    
1485      case OP_ANY:      case OP_ANY:
1486      if ((ims & PCRE_DOTALL) == 0)      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
1487        {      /* Fall through */
1488        if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);  
1489        }      case OP_ALLANY:
1490      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);
1491      if (utf8)      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
       while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
1492      ecode++;      ecode++;
1493      break;      break;
1494    
# Line 1471  for (;;) Line 1587  for (;;)
1587        case 0x000d:        case 0x000d:
1588        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1589        break;        break;
1590    
1591        case 0x000a:        case 0x000a:
1592          break;
1593    
1594        case 0x000b:        case 0x000b:
1595        case 0x000c:        case 0x000c:
1596        case 0x0085:        case 0x0085:
1597        case 0x2028:        case 0x2028:
1598        case 0x2029:        case 0x2029:
1599          if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
1600        break;        break;
1601        }        }
1602      ecode++;      ecode++;
# Line 1587  for (;;) Line 1707  for (;;)
1707      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1708      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1709        {        {
1710        int chartype, script;        const ucd_record * prop = GET_UCD(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1711    
1712        switch(ecode[1])        switch(ecode[1])
1713          {          {
# Line 1597  for (;;) Line 1716  for (;;)
1716          break;          break;
1717    
1718          case PT_LAMP:          case PT_LAMP:
1719          if ((chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
1720               chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
1721               chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
1722            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1723           break;           break;
1724    
1725          case PT_GC:          case PT_GC:
1726          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
1727            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1728          break;          break;
1729    
1730          case PT_PC:          case PT_PC:
1731          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
1732            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1733          break;          break;
1734    
1735          case PT_SC:          case PT_SC:
1736          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
1737            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1738          break;          break;
1739    
# Line 1633  for (;;) Line 1752  for (;;)
1752      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1753      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1754        {        {
1755        int chartype, script;        int category = UCD_CATEGORY(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1756        if (category == ucp_M) RRETURN(MATCH_NOMATCH);        if (category == ucp_M) RRETURN(MATCH_NOMATCH);
1757        while (eptr < md->end_subject)        while (eptr < md->end_subject)
1758          {          {
# Line 1643  for (;;) Line 1761  for (;;)
1761            {            {
1762            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
1763            }            }
1764          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
1765          if (category != ucp_M) break;          if (category != ucp_M) break;
1766          eptr += len;          eptr += len;
1767          }          }
# Line 1664  for (;;) Line 1782  for (;;)
1782      case OP_REF:      case OP_REF:
1783        {        {
1784        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
1785        ecode += 3;                                 /* Advance past item */        ecode += 3;
1786    
1787          /* If the reference is unset, there are two possibilities:
1788    
1789          (a) In the default, Perl-compatible state, set the length to be longer
1790          than the amount of subject left; this ensures that every attempt at a
1791          match fails. We can't just fail here, because of the possibility of
1792          quantifiers with zero minima.
1793    
1794          (b) If the JavaScript compatibility flag is set, set the length to zero
1795          so that the back reference matches an empty string.
1796    
1797          Otherwise, set the length to the length of what was matched by the
1798          referenced subpattern. */
1799    
1800        /* If the reference is unset, set the length to be longer than the amount        if (offset >= offset_top || md->offset_vector[offset] < 0)
1801        of subject left; this ensures that every attempt at a match fails. We          length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
1802        can't just fail here, because of the possibility of quantifiers with zero        else
1803        minima. */          length = md->offset_vector[offset+1] - md->offset_vector[offset];
   
       length = (offset >= offset_top || md->offset_vector[offset] < 0)?  
         md->end_subject - eptr + 1 :  
         md->offset_vector[offset+1] - md->offset_vector[offset];  
1804    
1805        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
1806    
# Line 2033  for (;;) Line 2160  for (;;)
2160            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2161            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2162            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2163            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2164            }            }
2165          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2166          }          }
# Line 2099  for (;;) Line 2226  for (;;)
2226          if (fc != dc)          if (fc != dc)
2227            {            {
2228  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2229            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2230  #endif  #endif
2231              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2232            }            }
# Line 2190  for (;;) Line 2317  for (;;)
2317  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2318          unsigned int othercase;          unsigned int othercase;
2319          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2320              (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR)              (othercase = UCD_OTHERCASE(fc)) != fc)
2321            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2322          else oclength = 0;          else oclength = 0;
2323  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
# Line 2510  for (;;) Line 2637  for (;;)
2637              {              {
2638              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
2639              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2640                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2641              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2642              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
2643              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
2644                RRETURN(MATCH_NOMATCH);  
2645              }              }
2646            }            }
2647          else          else
# Line 2619  for (;;) Line 2747  for (;;)
2747              {              {
2748              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
2749              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2750                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2751              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2752              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
2753              }              }
2754            }            }
2755          else          else
# Line 2786  for (;;) Line 2914  for (;;)
2914            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2915              {              {
2916              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2917              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2918              }              }
2919            break;            break;
2920    
# Line 2794  for (;;) Line 2922  for (;;)
2922            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2923              {              {
2924              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2925              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2926              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
2927              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
2928                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
2929                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2807  for (;;) Line 2935  for (;;)
2935            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2936              {              {
2937              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2938              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2939              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
2940              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
2941                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2942              }              }
# Line 2818  for (;;) Line 2946  for (;;)
2946            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2947              {              {
2948              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2949              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2950              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
2951              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
2952                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2953              }              }
# Line 2829  for (;;) Line 2957  for (;;)
2957            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2958              {              {
2959              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2960              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2961              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
2962              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
2963                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2964              }              }
# Line 2849  for (;;) Line 2977  for (;;)
2977          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2978            {            {
2979            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
2980            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
2981            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
2982            while (eptr < md->end_subject)            while (eptr < md->end_subject)
2983              {              {
# Line 2858  for (;;) Line 2986  for (;;)
2986                {                {
2987                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
2988                }                }
2989              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
2990              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
2991              eptr += len;              eptr += len;
2992              }              }
# Line 2876  for (;;) Line 3004  for (;;)
3004          case OP_ANY:          case OP_ANY:
3005          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3006            {            {
3007            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject || IS_NEWLINE(eptr))
                ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))  
3008              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3009            eptr++;            eptr++;
3010            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3011            }            }
3012          break;          break;
3013    
3014            case OP_ALLANY:
3015            for (i = 1; i <= min; i++)
3016              {
3017              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3018              eptr++;
3019              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3020              }
3021            break;
3022    
3023          case OP_ANYBYTE:          case OP_ANYBYTE:
3024          eptr += min;          eptr += min;
3025          break;          break;
# Line 2899  for (;;) Line 3035  for (;;)
3035              case 0x000d:              case 0x000d:
3036              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3037              break;              break;
3038    
3039              case 0x000a:              case 0x000a:
3040                break;
3041    
3042              case 0x000b:              case 0x000b:
3043              case 0x000c:              case 0x000c:
3044              case 0x0085:              case 0x0085:
3045              case 0x2028:              case 0x2028:
3046              case 0x2029:              case 0x2029:
3047                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3048              break;              break;
3049              }              }
3050            }            }
# Line 2941  for (;;) Line 3081  for (;;)
3081              }              }
3082            }            }
3083          break;          break;
3084    
3085          case OP_HSPACE:          case OP_HSPACE:
3086          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3087            {            {
# Line 2973  for (;;) Line 3113  for (;;)
3113              }              }
3114            }            }
3115          break;          break;
3116    
3117          case OP_NOT_VSPACE:          case OP_NOT_VSPACE:
3118          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3119            {            {
# Line 2993  for (;;) Line 3133  for (;;)
3133              }              }
3134            }            }
3135          break;          break;
3136    
3137          case OP_VSPACE:          case OP_VSPACE:
3138          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3139            {            {
# Line 3009  for (;;) Line 3149  for (;;)
3149              case 0x85:      /* NEL */              case 0x85:      /* NEL */
3150              case 0x2028:    /* LINE SEPARATOR */              case 0x2028:    /* LINE SEPARATOR */
3151              case 0x2029:    /* PARAGRAPH SEPARATOR */              case 0x2029:    /* PARAGRAPH SEPARATOR */
3152              break;              break;
3153              }              }
3154            }            }
3155          break;          break;
# Line 3038  for (;;) Line 3178  for (;;)
3178          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3179            {            {
3180            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3181               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0))
3182              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3183            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3184            }            }
3185          break;          break;
3186    
# Line 3058  for (;;) Line 3198  for (;;)
3198          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3199            {            {
3200            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3201               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))
3202              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3203            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3204            }            }
3205          break;          break;
3206    
# Line 3088  for (;;) Line 3228  for (;;)
3228        switch(ctype)        switch(ctype)
3229          {          {
3230          case OP_ANY:          case OP_ANY:
3231          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3232            {            {
3233            for (i = 1; i <= min; i++)            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3234              {            eptr++;
             if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);  
             eptr++;  
             }  
3235            }            }
3236          else eptr += min;          break;
3237    
3238            case OP_ALLANY:
3239            eptr += min;
3240          break;          break;
3241    
3242          case OP_ANYBYTE:          case OP_ANYBYTE:
# Line 3117  for (;;) Line 3257  for (;;)
3257              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3258              break;              break;
3259              case 0x000a:              case 0x000a:
3260                break;
3261    
3262              case 0x000b:              case 0x000b:
3263              case 0x000c:              case 0x000c:
3264              case 0x0085:              case 0x0085:
3265                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3266              break;              break;
3267              }              }
3268            }            }
# Line 3150  for (;;) Line 3293  for (;;)
3293              case 0x09:      /* HT */              case 0x09:      /* HT */
3294              case 0x20:      /* SPACE */              case 0x20:      /* SPACE */
3295              case 0xa0:      /* NBSP */              case 0xa0:      /* NBSP */
3296              break;              break;
3297              }              }
3298            }            }
3299          break;          break;
# Line 3184  for (;;) Line 3327  for (;;)
3327              case 0x0c:      /* FF */              case 0x0c:      /* FF */
3328              case 0x0d:      /* CR */              case 0x0d:      /* CR */
3329              case 0x85:      /* NEL */              case 0x85:      /* NEL */
3330              break;              break;
3331              }              }
3332            }            }
3333          break;          break;
# Line 3259  for (;;) Line 3402  for (;;)
3402              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3403              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3404              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3405              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3406              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3407                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3408                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 3274  for (;;) Line 3417  for (;;)
3417              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3418              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3419              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3420              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3421              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3422                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3423              }              }
# Line 3287  for (;;) Line 3430  for (;;)
3430              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3431              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3432              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3433              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3434              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3435                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3436              }              }
# Line 3300  for (;;) Line 3443  for (;;)
3443              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3444              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3445              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3446              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3447              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3448                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3449              }              }
# Line 3322  for (;;) Line 3465  for (;;)
3465            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3466            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3467            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3468            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3469            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3470            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3471              {              {
# Line 3331  for (;;) Line 3474  for (;;)
3474                {                {
3475                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3476                }                }
3477              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3478              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3479              eptr += len;              eptr += len;
3480              }              }
# Line 3350  for (;;) Line 3493  for (;;)
3493            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
3494            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3495            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max || eptr >= md->end_subject ||
3496                 (ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 &&                 (ctype == OP_ANY && IS_NEWLINE(eptr)))
                 IS_NEWLINE(eptr)))  
3497              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3498    
3499            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3500            switch(ctype)            switch(ctype)
3501              {              {
3502              case OP_ANY:        /* This is the DOTALL case */              case OP_ANY:        /* This is the non-NL case */
3503              break;              case OP_ALLANY:
   
3504              case OP_ANYBYTE:              case OP_ANYBYTE:
3505              break;              break;
3506    
# Line 3371  for (;;) Line 3512  for (;;)
3512                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3513                break;                break;
3514                case 0x000a:                case 0x000a:
3515                  break;
3516    
3517                case 0x000b:                case 0x000b:
3518                case 0x000c:                case 0x000c:
3519                case 0x0085:                case 0x0085:
3520                case 0x2028:                case 0x2028:
3521                case 0x2029:                case 0x2029:
3522                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3523                break;                break;
3524                }                }
3525              break;              break;
# Line 3508  for (;;) Line 3652  for (;;)
3652            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
3653            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3654            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max || eptr >= md->end_subject ||
3655                 ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))                 (ctype == OP_ANY && IS_NEWLINE(eptr)))
3656              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3657    
3658            c = *eptr++;            c = *eptr++;
3659            switch(ctype)            switch(ctype)
3660              {              {
3661              case OP_ANY:   /* This is the DOTALL case */              case OP_ANY:     /* This is the non-NL case */
3662              break;              case OP_ALLANY:
   
3663              case OP_ANYBYTE:              case OP_ANYBYTE:
3664              break;              break;
3665    
# Line 3527  for (;;) Line 3670  for (;;)
3670                case 0x000d:                case 0x000d:
3671                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3672                break;                break;
3673    
3674                case 0x000a:                case 0x000a:
3675                  break;
3676    
3677                case 0x000b:                case 0x000b:
3678                case 0x000c:                case 0x000c:
3679                case 0x0085:                case 0x0085:
3680                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3681                break;                break;
3682                }                }
3683              break;              break;
# Line 3645  for (;;) Line 3792  for (;;)
3792              int len = 1;              int len = 1;
3793              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3794              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3795              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3796              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3797                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3798                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 3660  for (;;) Line 3807  for (;;)
3807              int len = 1;              int len = 1;
3808              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3809              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3810              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3811              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3812                break;                break;
3813              eptr+= len;              eptr+= len;
# Line 3673  for (;;) Line 3820  for (;;)
3820              int len = 1;              int len = 1;
3821              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3822              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3823              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3824              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3825                break;                break;
3826              eptr+= len;              eptr+= len;
# Line 3686  for (;;) Line 3833  for (;;)
3833              int len = 1;              int len = 1;
3834              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3835              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3836              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3837              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3838                break;                break;
3839              eptr+= len;              eptr+= len;
# Line 3702  for (;;) Line 3849  for (;;)
3849            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);
3850            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3851            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
3852            BACKCHAR(eptr);            if (utf8) BACKCHAR(eptr);
3853            }            }
3854          }          }
3855    
# Line 3715  for (;;) Line 3862  for (;;)
3862            {            {
3863            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
3864            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3865            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3866            if (prop_category == ucp_M) break;            if (prop_category == ucp_M) break;
3867            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3868              {              {
# Line 3724  for (;;) Line 3871  for (;;)
3871                {                {
3872                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3873                }                }
3874              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3875              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3876              eptr += len;              eptr += len;
3877              }              }
# Line 3741  for (;;) Line 3888  for (;;)
3888            for (;;)                        /* Move back over one extended */            for (;;)                        /* Move back over one extended */
3889              {              {
3890              int len = 1;              int len = 1;
             BACKCHAR(eptr);  
3891              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr; else
3892                {                {
3893                  BACKCHAR(eptr);
3894                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3895                }                }
3896              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3897              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3898              eptr--;              eptr--;
3899              }              }
# Line 3764  for (;;) Line 3911  for (;;)
3911          switch(ctype)          switch(ctype)
3912            {            {
3913            case OP_ANY:            case OP_ANY:
   
           /* Special code is required for UTF8, but when the maximum is  
           unlimited we don't need it, so we repeat the non-UTF8 code. This is  
           probably worth it, because .* is quite a common idiom. */  
   
3914            if (max < INT_MAX)            if (max < INT_MAX)
3915              {              {
3916              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
               {  
               for (i = min; i < max; i++)  
                 {  
                 if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;  
                 eptr++;  
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
               }  
             else  
3917                {                {
3918                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
3919                  {                eptr++;
3920                  if (eptr >= md->end_subject) break;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 eptr++;  
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
3921                }                }
3922              }              }
3923    
# Line 3795  for (;;) Line 3925  for (;;)
3925    
3926            else            else
3927              {              {
3928              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
3929                {                {
3930                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
3931                  {                eptr++;
3932                  if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 eptr++;  
                 }  
               break;  
3933                }                }
3934              else              }
3935              break;
3936    
3937              case OP_ALLANY:
3938              if (max < INT_MAX)
3939                {
3940                for (i = min; i < max; i++)
3941                {                {
3942                c = max - min;                if (eptr >= md->end_subject) break;
3943                if (c > (unsigned int)(md->end_subject - eptr))                eptr++;
3944                  c = md->end_subject - eptr;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
               eptr += c;  
3945                }                }
3946              }              }
3947              else eptr = md->end_subject;   /* Unlimited UTF-8 repeat */
3948            break;            break;
3949    
3950            /* The byte case is the same as non-UTF8 */            /* The byte case is the same as non-UTF8 */
# Line 3836  for (;;) Line 3969  for (;;)
3969                }                }
3970              else              else
3971                {                {
3972                if (c != 0x000a && c != 0x000b && c != 0x000c &&                if (c != 0x000a &&
3973                    c != 0x0085 && c != 0x2028 && c != 0x2029)                    (md->bsr_anycrlf ||
3974                       (c != 0x000b && c != 0x000c &&
3975                        c != 0x0085 && c != 0x2028 && c != 0x2029)))
3976                  break;                  break;
3977                eptr += len;                eptr += len;
3978                }                }
# Line 3845  for (;;) Line 3980  for (;;)
3980            break;            break;
3981    
3982            case OP_NOT_HSPACE:            case OP_NOT_HSPACE:
3983            case OP_HSPACE:            case OP_HSPACE:
3984            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3985              {              {
3986              BOOL gotspace;              BOOL gotspace;
3987              int len = 1;              int len = 1;
3988              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3989              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3990              switch(c)              switch(c)
3991                {                {
3992                default: gotspace = FALSE; break;                default: gotspace = FALSE; break;
3993                case 0x09:      /* HT */                case 0x09:      /* HT */
3994                case 0x20:      /* SPACE */                case 0x20:      /* SPACE */
3995                case 0xa0:      /* NBSP */                case 0xa0:      /* NBSP */
# Line 3875  for (;;) Line 4010  for (;;)
4010                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
4011                case 0x3000:    /* IDEOGRAPHIC SPACE */                case 0x3000:    /* IDEOGRAPHIC SPACE */
4012                gotspace = TRUE;                gotspace = TRUE;
4013                break;                break;
4014                }                }
4015              if (gotspace == (ctype == OP_NOT_HSPACE)) break;              if (gotspace == (ctype == OP_NOT_HSPACE)) break;
4016              eptr += len;              eptr += len;
# Line 3883  for (;;) Line 4018  for (;;)
4018            break;            break;
4019    
4020            case OP_NOT_VSPACE:            case OP_NOT_VSPACE:
4021            case OP_VSPACE:            case OP_VSPACE:
4022            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4023              {              {
4024              BOOL gotspace;              BOOL gotspace;
4025              int len = 1;              int len = 1;
4026              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
4027              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4028              switch(c)              switch(c)
4029                {                {
4030                default: gotspace = FALSE; break;                default: gotspace = FALSE; break;
4031                case 0x0a:      /* LF */                case 0x0a:      /* LF */
4032                case 0x0b:      /* VT */                case 0x0b:      /* VT */
4033                case 0x0c:      /* FF */                case 0x0c:      /* FF */
# Line 3903  for (;;) Line 4038  for (;;)
4038                gotspace = TRUE;                gotspace = TRUE;
4039                break;                break;
4040                }                }
4041              if (gotspace == (ctype == OP_NOT_VSPACE)) break;              if (gotspace == (ctype == OP_NOT_VSPACE)) break;
4042              eptr += len;              eptr += len;
4043              }              }
4044            break;            break;
# Line 3990  for (;;) Line 4125  for (;;)
4125            }            }
4126          }          }
4127        else        else
4128  #endif  #endif  /* SUPPORT_UTF8 */
4129    
4130        /* Not UTF-8 mode */        /* Not UTF-8 mode */
4131          {          {
4132          switch(ctype)          switch(ctype)
4133            {            {
4134            case OP_ANY:            case OP_ANY:
4135            if ((ims & PCRE_DOTALL) == 0)            for (i = min; i < max; i++)
4136              {              {
4137              for (i = min; i < max; i++)              if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
4138                {              eptr++;
               if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;  
               eptr++;  
               }  
             break;  
4139              }              }
4140            /* For DOTALL case, fall through and treat as \C */            break;
4141    
4142              case OP_ALLANY:
4143            case OP_ANYBYTE:            case OP_ANYBYTE:
4144            c = max - min;            c = max - min;
4145            if (c > (unsigned int)(md->end_subject - eptr))            if (c > (unsigned int)(md->end_subject - eptr))
# Line 4027  for (;;) Line 4159  for (;;)
4159                }                }
4160              else              else
4161                {                {
4162                if (c != 0x000a && c != 0x000b && c != 0x000c && c != 0x0085)                if (c != 0x000a &&
4163                      (md->bsr_anycrlf ||
4164                        (c != 0x000b && c != 0x000c && c != 0x0085)))
4165                  break;                  break;
4166                eptr++;                eptr++;
4167                }                }
# Line 4040  for (;;) Line 4174  for (;;)
4174              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
4175              c = *eptr;              c = *eptr;
4176              if (c == 0x09 || c == 0x20 || c == 0xa0) break;              if (c == 0x09 || c == 0x20 || c == 0xa0) break;
4177              eptr++;              eptr++;
4178              }              }
4179            break;            break;
4180    
# Line 4050  for (;;) Line 4184  for (;;)
4184              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
4185              c = *eptr;              c = *eptr;
4186              if (c != 0x09 && c != 0x20 && c != 0xa0) break;              if (c != 0x09 && c != 0x20 && c != 0xa0) break;
4187              eptr++;              eptr++;
4188              }              }
4189            break;            break;
4190    
# Line 4061  for (;;) Line 4195  for (;;)
4195              c = *eptr;              c = *eptr;
4196              if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)              if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)
4197                break;                break;
4198              eptr++;              eptr++;
4199              }              }
4200            break;            break;
4201    
# Line 4177  HEAP_RETURN: Line 4311  HEAP_RETURN:
4311  switch (frame->Xwhere)  switch (frame->Xwhere)
4312    {    {
4313    LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)    LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)
4314    LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(16)    LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)
4315    LBL(17) LBL(18) LBL(19) LBL(20) LBL(21) LBL(22) LBL(23) LBL(24)    LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)
4316    LBL(25) LBL(26) LBL(27) LBL(28) LBL(29) LBL(30) LBL(31) LBL(32)    LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
4317    LBL(33) LBL(34) LBL(35) LBL(36) LBL(37) LBL(38) LBL(39) LBL(40)    LBL(53) LBL(54)
4318    LBL(41) LBL(42) LBL(43) LBL(44) LBL(45) LBL(46) LBL(47)  #ifdef SUPPORT_UTF8
4319      LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)
4320      LBL(32) LBL(34) LBL(42) LBL(46)
4321    #ifdef SUPPORT_UCP
4322      LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
4323    #endif  /* SUPPORT_UCP */
4324    #endif  /* SUPPORT_UTF8 */
4325    default:    default:
4326    DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));    DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));
4327    return PCRE_ERROR_INTERNAL;    return PCRE_ERROR_INTERNAL;
# Line 4273  Returns:          > 0 => success; value Line 4413  Returns:          > 0 => success; value
4413                   < -1 => some kind of unexpected problem                   < -1 => some kind of unexpected problem
4414  */  */
4415    
4416  PCRE_EXP_DEFN int  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
4417  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
4418    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
4419    int offsetcount)    int offsetcount)
# Line 4298  const uschar *start_bits = NULL; Line 4438  const uschar *start_bits = NULL;
4438  USPTR start_match = (USPTR)subject + start_offset;  USPTR start_match = (USPTR)subject + start_offset;
4439  USPTR end_subject;  USPTR end_subject;
4440  USPTR req_byte_ptr = start_match - 1;  USPTR req_byte_ptr = start_match - 1;
 eptrblock eptrchain[EPTR_WORK_SIZE];  
4441    
4442  pcre_study_data internal_study;  pcre_study_data internal_study;
4443  const pcre_study_data *study;  const pcre_study_data *study;
# Line 4361  if (re->magic_number != MAGIC_NUMBER) Line 4500  if (re->magic_number != MAGIC_NUMBER)
4500  /* Set up other data */  /* Set up other data */
4501    
4502  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;
4503  startline = (re->options & PCRE_STARTLINE) != 0;  startline = (re->flags & PCRE_STARTLINE) != 0;
4504  firstline = (re->options & PCRE_FIRSTLINE) != 0;  firstline = (re->options & PCRE_FIRSTLINE) != 0;
4505    
4506  /* The code starts after the real_pcre block and the capture name table. */  /* The code starts after the real_pcre block and the capture name table. */
# Line 4376  end_subject = md->end_subject; Line 4515  end_subject = md->end_subject;
4515    
4516  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
4517  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
4518    md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
4519    
4520  md->notbol = (options & PCRE_NOTBOL) != 0;  md->notbol = (options & PCRE_NOTBOL) != 0;
4521  md->noteol = (options & PCRE_NOTEOL) != 0;  md->noteol = (options & PCRE_NOTEOL) != 0;
# Line 4384  md->partial = (options & PCRE_PARTIAL) ! Line 4524  md->partial = (options & PCRE_PARTIAL) !
4524  md->hitend = FALSE;  md->hitend = FALSE;
4525    
4526  md->recursive = NULL;                   /* No recursion at top level */  md->recursive = NULL;                   /* No recursion at top level */
 md->eptrchain = eptrchain;              /* Make workspace generally available */  
4527    
4528  md->lcc = tables + lcc_offset;  md->lcc = tables + lcc_offset;
4529  md->ctypes = tables + ctypes_offset;  md->ctypes = tables + ctypes_offset;
4530    
4531    /* Handle different \R options. */
4532    
4533    switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
4534      {
4535      case 0:
4536      if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0)
4537        md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0;
4538      else
4539    #ifdef BSR_ANYCRLF
4540      md->bsr_anycrlf = TRUE;
4541    #else
4542      md->bsr_anycrlf = FALSE;
4543    #endif
4544      break;
4545    
4546      case PCRE_BSR_ANYCRLF:
4547      md->bsr_anycrlf = TRUE;
4548      break;
4549    
4550      case PCRE_BSR_UNICODE:
4551      md->bsr_anycrlf = FALSE;
4552      break;
4553    
4554      default: return PCRE_ERROR_BADNEWLINE;
4555      }
4556    
4557  /* Handle different types of newline. The three bits give eight cases. If  /* Handle different types of newline. The three bits give eight cases. If
4558  nothing is set at run time, whatever was used at compile time applies. */  nothing is set at run time, whatever was used at compile time applies. */
4559    
4560  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : (pcre_uint32)options) &  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options :
4561         PCRE_NEWLINE_BITS)          (pcre_uint32)options) & PCRE_NEWLINE_BITS)
4562    {    {
4563    case 0: newline = NEWLINE; break;   /* Compile-time default */    case 0: newline = NEWLINE; break;   /* Compile-time default */
4564    case PCRE_NEWLINE_CR: newline = '\r'; break;    case PCRE_NEWLINE_CR: newline = '\r'; break;
# Line 4432  else Line 4597  else
4597  /* Partial matching is supported only for a restricted set of regexes at the  /* Partial matching is supported only for a restricted set of regexes at the
4598  moment. */  moment. */
4599    
4600  if (md->partial && (re->options & PCRE_NOPARTIAL) != 0)  if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
4601    return PCRE_ERROR_BADPARTIAL;    return PCRE_ERROR_BADPARTIAL;
4602    
4603  /* Check a UTF-8 string if required. Unfortunately there's no way of passing  /* Check a UTF-8 string if required. Unfortunately there's no way of passing
# Line 4509  studied, there may be a bitmap of possib Line 4674  studied, there may be a bitmap of possib
4674    
4675  if (!anchored)  if (!anchored)
4676    {    {
4677    if ((re->options & PCRE_FIRSTSET) != 0)    if ((re->flags & PCRE_FIRSTSET) != 0)
4678      {      {
4679      first_byte = re->first_byte & 255;      first_byte = re->first_byte & 255;
4680      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)
# Line 4524  if (!anchored) Line 4689  if (!anchored)
4689  /* For anchored or unanchored matches, there may be a "last known required  /* For anchored or unanchored matches, there may be a "last known required
4690  character" set. */  character" set. */
4691    
4692  if ((re->options & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
4693    {    {
4694    req_byte = re->req_byte & 255;    req_byte = re->req_byte & 255;
4695    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;
# Line 4540  the loop runs just once. */ Line 4705  the loop runs just once. */
4705  for(;;)  for(;;)
4706    {    {
4707    USPTR save_end_subject = end_subject;    USPTR save_end_subject = end_subject;
4708      USPTR new_start_match;
4709    
4710    /* Reset the maximum number of extractions we might see. */    /* Reset the maximum number of extractions we might see. */
4711    
# Line 4559  for(;;) Line 4725  for(;;)
4725    if (firstline)    if (firstline)
4726      {      {
4727      USPTR t = start_match;      USPTR t = start_match;
4728    #ifdef SUPPORT_UTF8
4729        if (utf8)
4730          {
4731          while (t < md->end_subject && !IS_NEWLINE(t))
4732            {
4733            t++;
4734            while (t < end_subject && (*t & 0xc0) == 0x80) t++;
4735            }
4736          }
4737        else
4738    #endif
4739      while (t < md->end_subject && !IS_NEWLINE(t)) t++;      while (t < md->end_subject && !IS_NEWLINE(t)) t++;
4740      end_subject = t;      end_subject = t;
4741      }      }
4742    
4743    /* Now test for a unique first byte */    /* Now advance to a unique first byte if there is one. */
4744    
4745    if (first_byte >= 0)    if (first_byte >= 0)
4746      {      {
4747      if (first_byte_caseless)      if (first_byte_caseless)
4748        while (start_match < end_subject &&        while (start_match < end_subject && md->lcc[*start_match] != first_byte)
              md->lcc[*start_match] != first_byte)  
4749          start_match++;          start_match++;
4750      else      else
4751        while (start_match < end_subject && *start_match != first_byte)        while (start_match < end_subject && *start_match != first_byte)
4752          start_match++;          start_match++;
4753      }      }
4754    
4755    /* Or to just after a linebreak for a multiline match if possible */    /* Or to just after a linebreak for a multiline match */
4756    
4757    else if (startline)    else if (startline)
4758      {      {
4759      if (start_match > md->start_subject + start_offset)      if (start_match > md->start_subject + start_offset)
4760        {        {
4761        while (start_match <= end_subject && !WAS_NEWLINE(start_match))  #ifdef SUPPORT_UTF8
4762          if (utf8)
4763            {
4764            while (start_match < end_subject && !WAS_NEWLINE(start_match))
4765              {
4766              start_match++;
4767              while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
4768                start_match++;
4769              }
4770            }
4771          else
4772    #endif
4773          while (start_match < end_subject && !WAS_NEWLINE(start_match))
4774          start_match++;          start_match++;
4775    
4776        /* If we have just passed a CR and the newline option is ANY or ANYCRLF,        /* If we have just passed a CR and the newline option is ANY or ANYCRLF,
# Line 4597  for(;;) Line 4785  for(;;)
4785        }        }
4786      }      }
4787    
4788    /* Or to a non-unique first char after study */    /* Or to a non-unique first byte after study */
4789    
4790    else if (start_bits != NULL)    else if (start_bits != NULL)
4791      {      {
4792      while (start_match < end_subject)      while (start_match < end_subject)
4793        {        {
4794        register unsigned int c = *start_match;        register unsigned int c = *start_match;
4795        if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++; else break;        if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++;
4796            else break;
4797        }        }
4798      }      }
4799    
# Line 4680  for(;;) Line 4869  for(;;)
4869    
4870    /* OK, we can now run the match. */    /* OK, we can now run the match. */
4871    
4872    md->start_match_ptr = start_match;      /* Insurance */    md->start_match_ptr = start_match;
4873    md->match_call_count = 0;    md->match_call_count = 0;
4874    md->eptrn = 0;                          /* Next free eptrchain slot */    rc = match(start_match, md->start_code, start_match, 2, md, ims, NULL, 0, 0);
   rc = match(start_match, md->start_code, start_match, 2, md,  
     ims, NULL, 0, 0);  
4875    
4876    /* Any return other than MATCH_NOMATCH breaks the loop. */    switch(rc)
4877        {
4878        /* NOMATCH and PRUNE advance by one character. THEN at this level acts
4879        exactly like PRUNE. */
4880    
4881    if (rc != MATCH_NOMATCH) break;      case MATCH_NOMATCH:
4882        case MATCH_PRUNE:
4883        case MATCH_THEN:
4884        new_start_match = start_match + 1;
4885    #ifdef SUPPORT_UTF8
4886        if (utf8)
4887          while(new_start_match < end_subject && (*new_start_match & 0xc0) == 0x80)
4888            new_start_match++;
4889    #endif
4890        break;
4891    
4892        /* SKIP passes back the next starting point explicitly. */
4893    
4894        case MATCH_SKIP:
4895        new_start_match = md->start_match_ptr;
4896        break;
4897    
4898        /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */
4899    
4900        case MATCH_COMMIT:
4901        rc = MATCH_NOMATCH;
4902        goto ENDLOOP;
4903    
4904        /* Any other return is some kind of error. */
4905    
4906        default:
4907        goto ENDLOOP;
4908        }
4909    
4910      /* Control reaches here for the various types of "no match at this point"
4911      result. Reset the code to MATCH_NOMATCH for subsequent checking. */
4912    
4913      rc = MATCH_NOMATCH;
4914    
4915    /* If PCRE_FIRSTLINE is set, the match must happen before or at the first    /* If PCRE_FIRSTLINE is set, the match must happen before or at the first
4916    newline in the subject (though it may continue over the newline). Therefore,    newline in the subject (though it may continue over the newline). Therefore,
# Line 4696  for(;;) Line 4918  for(;;)
4918    
4919    if (firstline && IS_NEWLINE(start_match)) break;    if (firstline && IS_NEWLINE(start_match)) break;
4920    
4921    /* Advance the match position by one character. */    /* Advance to new matching position */
4922    
4923    start_match++;    start_match = new_start_match;
 #ifdef SUPPORT_UTF8  
   if (utf8)  
     while(start_match < end_subject && (*start_match & 0xc0) == 0x80)  
       start_match++;  
 #endif  
4924    
4925    /* Break the loop if the pattern is anchored or if we have passed the end of    /* Break the loop if the pattern is anchored or if we have passed the end of
4926    the subject. */    the subject. */
4927    
4928    if (anchored || start_match > end_subject) break;    if (anchored || start_match > end_subject) break;
4929    
4930    /* If we have just passed a CR and the newline option is CRLF or ANY or    /* If we have just passed a CR and we are now at a LF, and the pattern does
4931    ANYCRLF, and we are now at a LF, advance the match position by one more    not contain any explicit matches for \r or \n, and the newline option is CRLF
4932    character. */    or ANY or ANYCRLF, advance the match position by one more character. */
4933    
4934    if (start_match[-1] == '\r' &&    if (start_match[-1] == '\r' &&
4935         (md->nltype == NLTYPE_ANY ||        start_match < end_subject &&
4936          md->nltype == NLTYPE_ANYCRLF ||        *start_match == '\n' &&
4937          md->nllen == 2) &&        (re->flags & PCRE_HASCRORLF) == 0 &&
4938         start_match < end_subject &&          (md->nltype == NLTYPE_ANY ||
4939         *start_match == '\n')           md->nltype == NLTYPE_ANYCRLF ||
4940             md->nllen == 2))
4941      start_match++;      start_match++;
4942    
4943    }   /* End of for(;;) "bumpalong" loop */    }   /* End of for(;;) "bumpalong" loop */
# Line 4729  for(;;) Line 4947  for(;;)
4947  /* We reach here when rc is not MATCH_NOMATCH, or if one of the stopping  /* We reach here when rc is not MATCH_NOMATCH, or if one of the stopping
4948  conditions is true:  conditions is true:
4949    
4950  (1) The pattern is anchored;  (1) The pattern is anchored or the match was failed by (*COMMIT);
4951    
4952  (2) We are past the end of the subject;  (2) We are past the end of the subject;
4953    
# Line 4744  processing, copy those that we can. In t Line 4962  processing, copy those that we can. In t
4962  certain parts of the pattern were not used, even though there are more  certain parts of the pattern were not used, even though there are more
4963  capturing parentheses than vector slots. */  capturing parentheses than vector slots. */
4964    
4965    ENDLOOP:
4966    
4967  if (rc == MATCH_MATCH)  if (rc == MATCH_MATCH)
4968    {    {
4969    if (using_temporary_offsets)    if (using_temporary_offsets)

Legend:
Removed from v.178  
changed lines
  Added in v.381

  ViewVC Help
Powered by ViewVC 1.1.5