/[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 598 by ph10, Sat May 7 15:37:31 2011 UTC revision 615 by ph10, Mon Jul 11 14:23:06 2011 UTC
# Line 57  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    
60  /* Flag bits for the match() function */  /* Values for setting in md->match_function_type to indicate two special types
61    of call to match(). We do it this way to save on using another stack variable,
62    as stack usage is to be discouraged. */
63    
64  #define match_condassert     0x01  /* Called to check a condition assertion */  #define MATCH_CONDASSERT     1  /* Called to check a condition assertion */
65  #define match_cbegroup       0x02  /* Could-be-empty unlimited repeat group */  #define MATCH_CBEGROUP       2  /* Could-be-empty unlimited repeat group */
66    
67  /* Non-error returns from the match() function. Error returns are externally  /* Non-error returns from the match() function. Error returns are externally
68  defined PCRE_ERROR_xxx codes, which are all negative. */  defined PCRE_ERROR_xxx codes, which are all negative. */
# Line 73  negative to avoid the external error cod Line 75  negative to avoid the external error cod
75    
76  #define MATCH_ACCEPT       (-999)  #define MATCH_ACCEPT       (-999)
77  #define MATCH_COMMIT       (-998)  #define MATCH_COMMIT       (-998)
78  #define MATCH_PRUNE        (-997)  #define MATCH_KETRPOS      (-997)
79  #define MATCH_SKIP         (-996)  #define MATCH_PRUNE        (-996)
80  #define MATCH_SKIP_ARG     (-995)  #define MATCH_SKIP         (-995)
81  #define MATCH_THEN         (-994)  #define MATCH_SKIP_ARG     (-994)
82    #define MATCH_THEN         (-993)
83    
84  /* This is a convenience macro for code that occurs many times. */  /* This is a convenience macro for code that occurs many times. */
85    
# Line 142  Arguments: Line 145  Arguments:
145    eptr        pointer into the subject    eptr        pointer into the subject
146    length      length of reference to be matched (number of bytes)    length      length of reference to be matched (number of bytes)
147    md          points to match data block    md          points to match data block
148    ims         the ims flags    caseless    TRUE if caseless
149    
150  Returns:      < 0 if not matched, otherwise the number of subject bytes matched  Returns:      < 0 if not matched, otherwise the number of subject bytes matched
151  */  */
152    
153  static int  static int
154  match_ref(int offset, register USPTR eptr, int length, match_data *md,  match_ref(int offset, register USPTR eptr, int length, match_data *md,
155    unsigned long int ims)    BOOL caseless)
156  {  {
157  USPTR eptr_start = eptr;  USPTR eptr_start = eptr;
158  register USPTR p = md->start_subject + md->offset_vector[offset];  register USPTR p = md->start_subject + md->offset_vector[offset];
# Line 175  if (length < 0) return -1; Line 178  if (length < 0) return -1;
178  properly if Unicode properties are supported. Otherwise, we can check only  properly if Unicode properties are supported. Otherwise, we can check only
179  ASCII characters. */  ASCII characters. */
180    
181  if ((ims & PCRE_CASELESS) != 0)  if (caseless)
182    {    {
183  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
184  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 273  enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM Line 276  enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM
276         RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,         RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
277         RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,         RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
278         RM51,  RM52, RM53, RM54, RM55, RM56, RM57, RM58, RM59, RM60,         RM51,  RM52, RM53, RM54, RM55, RM56, RM57, RM58, RM59, RM60,
279         RM61,  RM62 };         RM61,  RM62, RM63};
280    
281  /* 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
282  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 283  actually used in this definition. */ Line 286  actually used in this definition. */
286  #define REGISTER register  #define REGISTER register
287    
288  #ifdef PCRE_DEBUG  #ifdef PCRE_DEBUG
289  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \  #define RMATCH(ra,rb,rc,rd,re,rw) \
290    { \    { \
291    printf("match() called in line %d\n", __LINE__); \    printf("match() called in line %d\n", __LINE__); \
292    rrc = match(ra,rb,mstart,markptr,rc,rd,re,rf,rg,rdepth+1); \    rrc = match(ra,rb,mstart,markptr,rc,rd,re,rdepth+1); \
293    printf("to line %d\n", __LINE__); \    printf("to line %d\n", __LINE__); \
294    }    }
295  #define RRETURN(ra) \  #define RRETURN(ra) \
# Line 295  actually used in this definition. */ Line 298  actually used in this definition. */
298    return ra; \    return ra; \
299    }    }
300  #else  #else
301  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \  #define RMATCH(ra,rb,rc,rd,re,rw) \
302    rrc = match(ra,rb,mstart,markptr,rc,rd,re,rf,rg,rdepth+1)    rrc = match(ra,rb,mstart,markptr,rc,rd,re,rdepth+1)
303  #define RRETURN(ra) return ra  #define RRETURN(ra) return ra
304  #endif  #endif
305    
# Line 309  argument of match(), which never changes Line 312  argument of match(), which never changes
312    
313  #define REGISTER  #define REGISTER
314    
315  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\  #define RMATCH(ra,rb,rc,rd,re,rw)\
316    {\    {\
317    heapframe *newframe = (heapframe *)(pcre_stack_malloc)(sizeof(heapframe));\    heapframe *newframe = (heapframe *)(pcre_stack_malloc)(sizeof(heapframe));\
318    if (newframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\    if (newframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\
# Line 319  argument of match(), which never changes Line 322  argument of match(), which never changes
322    newframe->Xmstart = mstart;\    newframe->Xmstart = mstart;\
323    newframe->Xmarkptr = markptr;\    newframe->Xmarkptr = markptr;\
324    newframe->Xoffset_top = rc;\    newframe->Xoffset_top = rc;\
325    newframe->Xims = re;\    newframe->Xeptrb = re;\
   newframe->Xeptrb = rf;\  
   newframe->Xflags = rg;\  
326    newframe->Xrdepth = frame->Xrdepth + 1;\    newframe->Xrdepth = frame->Xrdepth + 1;\
327    newframe->Xprevframe = frame;\    newframe->Xprevframe = frame;\
328    frame = newframe;\    frame = newframe;\
# Line 357  typedef struct heapframe { Line 358  typedef struct heapframe {
358    USPTR Xmstart;    USPTR Xmstart;
359    USPTR Xmarkptr;    USPTR Xmarkptr;
360    int Xoffset_top;    int Xoffset_top;
   long int Xims;  
361    eptrblock *Xeptrb;    eptrblock *Xeptrb;
   int Xflags;  
362    unsigned int Xrdepth;    unsigned int Xrdepth;
363    
364    /* Function local variables */    /* Function local variables */
# Line 380  typedef struct heapframe { Line 379  typedef struct heapframe {
379    BOOL Xcondition;    BOOL Xcondition;
380    BOOL Xprev_is_word;    BOOL Xprev_is_word;
381    
   unsigned long int Xoriginal_ims;  
   
382  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
383    int Xprop_type;    int Xprop_type;
384    int Xprop_value;    int Xprop_value;
# Line 467  Arguments: Line 464  Arguments:
464     markptr     pointer to the most recent MARK name, or NULL     markptr     pointer to the most recent MARK name, or NULL
465     offset_top  current top pointer     offset_top  current top pointer
466     md          pointer to "static" info for the match     md          pointer to "static" info for the match
    ims         current /i, /m, and /s options  
467     eptrb       pointer to chain of blocks containing eptr at start of     eptrb       pointer to chain of blocks containing eptr at start of
468                   brackets - for testing for empty matches                   brackets - for testing for empty matches
    flags       can contain  
                  match_condassert - this is an assertion condition  
                  match_cbegroup - this is the start of an unlimited repeat  
                    group that can match an empty string  
469     rdepth      the recursion depth     rdepth      the recursion depth
470    
471  Returns:       MATCH_MATCH if matched            )  these values are >= 0  Returns:       MATCH_MATCH if matched            )  these values are >= 0
# Line 485  Returns:       MATCH_MATCH if matched Line 477  Returns:       MATCH_MATCH if matched
477    
478  static int  static int
479  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart,  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart,
480    const uschar *markptr, int offset_top, match_data *md, unsigned long int ims,    const uschar *markptr, int offset_top, match_data *md, eptrblock *eptrb,
481    eptrblock *eptrb, int flags, unsigned int rdepth)    unsigned int rdepth)
482  {  {
483  /* These variables do not need to be preserved over recursion in this function,  /* These variables do not need to be preserved over recursion in this function,
484  so they can be ordinary variables in all cases. Mark some of them with  so they can be ordinary variables in all cases. Mark some of them with
# Line 498  register unsigned int c;   /* Character Line 490  register unsigned int c;   /* Character
490  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
491    
492  BOOL minimize, possessive; /* Quantifier options */  BOOL minimize, possessive; /* Quantifier options */
493    BOOL caseless;
494  int condcode;  int condcode;
495    
496  /* When recursion is not being used, all "local" variables that have to be  /* When recursion is not being used, all "local" variables that have to be
# Line 517  frame->Xecode = ecode; Line 510  frame->Xecode = ecode;
510  frame->Xmstart = mstart;  frame->Xmstart = mstart;
511  frame->Xmarkptr = markptr;  frame->Xmarkptr = markptr;
512  frame->Xoffset_top = offset_top;  frame->Xoffset_top = offset_top;
 frame->Xims = ims;  
513  frame->Xeptrb = eptrb;  frame->Xeptrb = eptrb;
 frame->Xflags = flags;  
514  frame->Xrdepth = rdepth;  frame->Xrdepth = rdepth;
515    
516  /* This is where control jumps back to to effect "recursion" */  /* This is where control jumps back to to effect "recursion" */
# Line 533  HEAP_RECURSE: Line 524  HEAP_RECURSE:
524  #define mstart             frame->Xmstart  #define mstart             frame->Xmstart
525  #define markptr            frame->Xmarkptr  #define markptr            frame->Xmarkptr
526  #define offset_top         frame->Xoffset_top  #define offset_top         frame->Xoffset_top
 #define ims                frame->Xims  
527  #define eptrb              frame->Xeptrb  #define eptrb              frame->Xeptrb
 #define flags              frame->Xflags  
528  #define rdepth             frame->Xrdepth  #define rdepth             frame->Xrdepth
529    
530  /* Ditto for the local variables */  /* Ditto for the local variables */
# Line 557  HEAP_RECURSE: Line 546  HEAP_RECURSE:
546  #define condition          frame->Xcondition  #define condition          frame->Xcondition
547  #define prev_is_word       frame->Xprev_is_word  #define prev_is_word       frame->Xprev_is_word
548    
 #define original_ims       frame->Xoriginal_ims  
   
549  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
550  #define prop_type          frame->Xprop_type  #define prop_type          frame->Xprop_type
551  #define prop_value         frame->Xprop_value  #define prop_value         frame->Xprop_value
# Line 595  i, and fc and c, can be the same variabl Line 582  i, and fc and c, can be the same variabl
582  #define fi i  #define fi i
583  #define fc c  #define fc c
584    
585    /* Many of the following variables are used only in small blocks of the code.
586  #ifdef SUPPORT_UTF8                /* Many of these variables are used only  */  My normal style of coding would have declared them within each of those blocks.
587  const uschar *charptr;             /* in small blocks of the code. My normal */  However, in order to accommodate the version of this code that uses an external
588  #endif                             /* style of coding would have declared    */  "stack" implemented on the heap, it is easier to declare them all here, so the
589  const uschar *callpat;             /* them within each of those blocks.      */  declarations can be cut out in a block. The only declarations within blocks
590  const uschar *data;                /* However, in order to accommodate the   */  below are for variables that do not have to be preserved over a recursive call
591  const uschar *next;                /* version of this code that uses an      */  to RMATCH(). */
592  USPTR         pp;                  /* external "stack" implemented on the    */  
593  const uschar *prev;                /* heap, it is easier to declare them all */  #ifdef SUPPORT_UTF8
594  USPTR         saved_eptr;          /* here, so the declarations can be cut   */  const uschar *charptr;
595                                     /* out in a block. The only declarations  */  #endif
596  recursion_info new_recursive;      /* within blocks below are for variables  */  const uschar *callpat;
597                                     /* that do not have to be preserved over  */  const uschar *data;
598  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */  const uschar *next;
599    USPTR         pp;
600    const uschar *prev;
601    USPTR         saved_eptr;
602    
603    recursion_info new_recursive;
604    
605    BOOL cur_is_word;
606  BOOL condition;  BOOL condition;
607  BOOL prev_is_word;  BOOL prev_is_word;
608    
 unsigned long int original_ims;  
   
609  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
610  int prop_type;  int prop_type;
611  int prop_value;  int prop_value;
# Line 640  int stacksave[REC_STACK_SAVE_MAX]; Line 632  int stacksave[REC_STACK_SAVE_MAX];
632  eptrblock newptrb;  eptrblock newptrb;
633  #endif     /* NO_RECURSE */  #endif     /* NO_RECURSE */
634    
635    /* To save space on the stack and in the heap frame, I have doubled up on some
636    of the local variables that are used only in localised parts of the code, but
637    still need to be preserved over recursive calls of match(). These macros define
638    the alternative names that are used. */
639    
640    #define allow_zero    cur_is_word
641    #define cbegroup      condition
642    #define code_offset   codelink
643    #define condassert    condition
644    #define matched_once  prev_is_word
645    
646  /* These statements are here to stop the compiler complaining about unitialized  /* These statements are here to stop the compiler complaining about unitialized
647  variables. */  variables. */
648    
# Line 676  haven't exceeded the recursive call limi Line 679  haven't exceeded the recursive call limi
679  if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT);  if (md->match_call_count++ >= md->match_limit) RRETURN(PCRE_ERROR_MATCHLIMIT);
680  if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT);  if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT);
681    
 original_ims = ims;    /* Save for resetting on ')' */  
   
682  /* At the start of a group with an unlimited repeat that may match an empty  /* At the start of a group with an unlimited repeat that may match an empty
683  string, the match_cbegroup flag is set. When this is the case, add the current  string, the variable md->match_function_type is set to MATCH_CBEGROUP. It is
684  subject pointer to the chain of such remembered pointers, to be checked when we  done this way to save having to use another function argument, which would take
685  hit the closing ket, in order to break infinite loops that match no characters.  up space on the stack. See also MATCH_CONDASSERT below.
686  When match() is called in other circumstances, don't add to the chain. The  
687  match_cbegroup flag must NOT be used with tail recursion, because the memory  When MATCH_CBEGROUP is set, add the current subject pointer to the chain of
688  block that is used is on the stack, so a new one may be required for each  such remembered pointers, to be checked when we hit the closing ket, in order
689  match(). */  to break infinite loops that match no characters. When match() is called in
690    other circumstances, don't add to the chain. The MATCH_CBEGROUP feature must
691    NOT be used with tail recursion, because the memory block that is used is on
692    the stack, so a new one may be required for each match(). */
693    
694  if ((flags & match_cbegroup) != 0)  if (md->match_function_type == MATCH_CBEGROUP)
695    {    {
696    newptrb.epb_saved_eptr = eptr;    newptrb.epb_saved_eptr = eptr;
697    newptrb.epb_prev = eptrb;    newptrb.epb_prev = eptrb;
698    eptrb = &newptrb;    eptrb = &newptrb;
699      md->match_function_type = 0;
700    }    }
701    
702  /* Now start processing the opcodes. */  /* Now start processing the opcodes. */
# Line 700  for (;;) Line 705  for (;;)
705    {    {
706    minimize = possessive = FALSE;    minimize = possessive = FALSE;
707    op = *ecode;    op = *ecode;
708    
709    switch(op)    switch(op)
710      {      {
711      case OP_MARK:      case OP_MARK:
712      markptr = ecode + 2;      markptr = ecode + 2;
713      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
714        ims, eptrb, flags, RM55);        eptrb, RM55);
715    
716      /* A return of MATCH_SKIP_ARG means that matching failed at SKIP with an      /* A return of MATCH_SKIP_ARG means that matching failed at SKIP with an
717      argument, and we must check whether that argument matches this MARK's      argument, and we must check whether that argument matches this MARK's
# Line 732  for (;;) Line 737  for (;;)
737    
738      case OP_COMMIT:      case OP_COMMIT:
739      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
740        ims, eptrb, flags, RM52);        eptrb, RM52);
741      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE &&      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE &&
742          rrc != MATCH_SKIP && rrc != MATCH_SKIP_ARG &&          rrc != MATCH_SKIP && rrc != MATCH_SKIP_ARG &&
743          rrc != MATCH_THEN)          rrc != MATCH_THEN)
# Line 743  for (;;) Line 748  for (;;)
748    
749      case OP_PRUNE:      case OP_PRUNE:
750      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
751        ims, eptrb, flags, RM51);        eptrb, RM51);
752      if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);      if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
753      MRRETURN(MATCH_PRUNE);      MRRETURN(MATCH_PRUNE);
754    
755      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
756      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
757        ims, eptrb, flags, RM56);        eptrb, RM56);
758      if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);      if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
759      md->mark = ecode + 2;      md->mark = ecode + 2;
760      RRETURN(MATCH_PRUNE);      RRETURN(MATCH_PRUNE);
# Line 758  for (;;) Line 763  for (;;)
763    
764      case OP_SKIP:      case OP_SKIP:
765      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
766        ims, eptrb, flags, RM53);        eptrb, RM53);
767      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)
768        RRETURN(rrc);        RRETURN(rrc);
769      md->start_match_ptr = eptr;   /* Pass back current position */      md->start_match_ptr = eptr;   /* Pass back current position */
# Line 766  for (;;) Line 771  for (;;)
771    
772      case OP_SKIP_ARG:      case OP_SKIP_ARG:
773      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
774        ims, eptrb, flags, RM57);        eptrb, RM57);
775      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)
776        RRETURN(rrc);        RRETURN(rrc);
777    
# Line 785  for (;;) Line 790  for (;;)
790    
791      case OP_THEN:      case OP_THEN:
792      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
793        ims, eptrb, flags, RM54);        eptrb, RM54);
794      if (rrc != MATCH_NOMATCH) RRETURN(rrc);      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
795      md->start_match_ptr = ecode - GET(ecode, 1);      md->start_match_ptr = ecode - GET(ecode, 1);
796      MRRETURN(MATCH_THEN);      MRRETURN(MATCH_THEN);
797    
798      case OP_THEN_ARG:      case OP_THEN_ARG:
799      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1+LINK_SIZE],      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1+LINK_SIZE],
800        offset_top, md, ims, eptrb, flags, RM58);        offset_top, md, eptrb, RM58);
801      if (rrc != MATCH_NOMATCH) RRETURN(rrc);      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
802      md->start_match_ptr = ecode - GET(ecode, 1);      md->start_match_ptr = ecode - GET(ecode, 1);
803      md->mark = ecode + LINK_SIZE + 2;      md->mark = ecode + LINK_SIZE + 2;
804      RRETURN(MATCH_THEN);      RRETURN(MATCH_THEN);
805    
806      /* Handle a capturing bracket. If there is space in the offset vector, save      /* Handle a capturing bracket, other than those that are possessive with an
807      the current subject position in the working slot at the top of the vector.      unlimited repeat. If there is space in the offset vector, save the current
808      We mustn't change the current values of the data slot, because they may be      subject position in the working slot at the top of the vector. We mustn't
809      set from a previous iteration of this group, and be referred to by a      change the current values of the data slot, because they may be set from a
810      reference inside the group.      previous iteration of this group, and be referred to by a reference inside
811        the group. If we fail to match, we need to restore this value and also the
     If the bracket fails to match, we need to restore this value and also the  
812      values of the final offsets, in case they were set by a previous iteration      values of the final offsets, in case they were set by a previous iteration
813      of the same bracket.      of the same bracket.
814    
# Line 816  for (;;) Line 820  for (;;)
820      case OP_SCBRA:      case OP_SCBRA:
821      number = GET2(ecode, 1+LINK_SIZE);      number = GET2(ecode, 1+LINK_SIZE);
822      offset = number << 1;      offset = number << 1;
823    
824  #ifdef PCRE_DEBUG  #ifdef PCRE_DEBUG
825      printf("start bracket %d\n", number);      printf("start bracket %d\n", number);
826      printf("subject=");      printf("subject=");
# Line 835  for (;;) Line 839  for (;;)
839        md->offset_vector[md->offset_end - number] =        md->offset_vector[md->offset_end - number] =
840          (int)(eptr - md->start_subject);          (int)(eptr - md->start_subject);
841    
842        flags = (op == OP_SCBRA)? match_cbegroup : 0;        for (;;)
       do  
843          {          {
844          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,          if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
845            ims, eptrb, flags, RM1);          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
846              eptrb, RM1);
847          if (rrc != MATCH_NOMATCH &&          if (rrc != MATCH_NOMATCH &&
848              (rrc != MATCH_THEN || md->start_match_ptr != ecode))              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
849            RRETURN(rrc);            RRETURN(rrc);
850          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
851          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
852            if (*ecode != OP_ALT) break;
853          }          }
       while (*ecode == OP_ALT);  
854    
855        DPRINTF(("bracket %d failed\n", number));        DPRINTF(("bracket %d failed\n", number));
856    
# Line 854  for (;;) Line 858  for (;;)
858        md->offset_vector[offset+1] = save_offset2;        md->offset_vector[offset+1] = save_offset2;
859        md->offset_vector[md->offset_end - number] = save_offset3;        md->offset_vector[md->offset_end - number] = save_offset3;
860    
861        if (rrc != MATCH_THEN) md->mark = markptr;        if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr;
862        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
863        }        }
864    
# Line 869  for (;;) Line 873  for (;;)
873      /* VVVVVVVVVVVVVVVVVVVVVVVVV */      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
874      /* VVVVVVVVVVVVVVVVVVVVVVVVV */      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
875    
876      /* Non-capturing bracket. Loop for all the alternatives. When we get to the      /* Non-capturing bracket, except for possessive with unlimited repeat. Loop
877      final alternative within the brackets, we would return the result of a      for all the alternatives. When we get to the final alternative within the
878      recursive call to match() whatever happened. We can reduce stack usage by      brackets, we used to return the result of a recursive call to match()
879      turning this into a tail recursion, except in the case when match_cbegroup      whatever happened so it was possible to reduce stack usage by turning this
880      is set.*/      into a tail recursion, except in the case of a possibly empty group.
881        However, now that there is the possiblity of (*THEN) occurring in the final
882        alternative, this optimization is no longer possible. */
883    
884      case OP_BRA:      case OP_BRA:
885      case OP_SBRA:      case OP_SBRA:
886      DPRINTF(("start non-capturing bracket\n"));      DPRINTF(("start non-capturing bracket\n"));
     flags = (op >= OP_SBRA)? match_cbegroup : 0;  
887      for (;;)      for (;;)
888        {        {
889        if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */        if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
890          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, eptrb,
891            RM2);
892          if (rrc != MATCH_NOMATCH &&
893              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
894            RRETURN(rrc);
895          ecode += GET(ecode, 1);
896          if (*ecode != OP_ALT) break;
897          }
898    
899        if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr;
900        RRETURN(MATCH_NOMATCH);
901    
902        /* Handle possessive capturing brackets with an unlimited repeat. We come
903        here from BRAZERO with allow_zero set TRUE. The offset_vector values are
904        handled similarly to the normal case above. However, the matching is
905        different. The end of these brackets will always be OP_KETRPOS, which
906        returns MATCH_KETRPOS without going further in the pattern. By this means
907        we can handle the group by iteration rather than recursion, thereby
908        reducing the amount of stack needed. */
909    
910        case OP_CBRAPOS:
911        case OP_SCBRAPOS:
912        allow_zero = FALSE;
913    
914        POSSESSIVE_CAPTURE:
915        number = GET2(ecode, 1+LINK_SIZE);
916        offset = number << 1;
917    
918    #ifdef PCRE_DEBUG
919        printf("start possessive bracket %d\n", number);
920        printf("subject=");
921        pchars(eptr, 16, TRUE, md);
922        printf("\n");
923    #endif
924    
925        if (offset < md->offset_max)
926          {
927          matched_once = FALSE;
928          code_offset = ecode - md->start_code;
929    
930          save_offset1 = md->offset_vector[offset];
931          save_offset2 = md->offset_vector[offset+1];
932          save_offset3 = md->offset_vector[md->offset_end - number];
933          save_capture_last = md->capture_last;
934    
935          DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
936    
937          /* Each time round the loop, save the current subject position for use
938          when the group matches. For MATCH_MATCH, the group has matched, so we
939          restart it with a new subject starting position, remembering that we had
940          at least one match. For MATCH_NOMATCH, carry on with the alternatives, as
941          usual. If we haven't matched any alternatives in any iteration, check to
942          see if a previous iteration matched. If so, the group has matched;
943          continue from afterwards. Otherwise it has failed; restore the previous
944          capture values before returning NOMATCH. */
945    
946          for (;;)
947          {          {
948          if (flags == 0)    /* Not a possibly empty group */          md->offset_vector[md->offset_end - number] =
949              (int)(eptr - md->start_subject);
950            if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
951            RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
952              eptrb, RM63);
953            if (rrc == MATCH_KETRPOS)
954            {            {
955            ecode += _pcre_OP_lengths[*ecode];            offset_top = md->end_offset_top;
956            DPRINTF(("bracket 0 tail recursion\n"));            eptr = md->end_match_ptr;
957            goto TAIL_RECURSE;            ecode = md->start_code + code_offset;
958            }            save_capture_last = md->capture_last;
959              matched_once = TRUE;
960              continue;
961              }
962            if (rrc != MATCH_NOMATCH &&
963                (rrc != MATCH_THEN || md->start_match_ptr != ecode))
964              RRETURN(rrc);
965            md->capture_last = save_capture_last;
966            ecode += GET(ecode, 1);
967            if (*ecode != OP_ALT) break;
968            }
969    
970          /* Possibly empty group; can't use tail recursion. */        if (!matched_once)
971            {
972            md->offset_vector[offset] = save_offset1;
973            md->offset_vector[offset+1] = save_offset2;
974            md->offset_vector[md->offset_end - number] = save_offset3;
975            }
976    
977          if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr;
978          if (allow_zero || matched_once)
979            {
980            ecode += 1 + LINK_SIZE;
981            break;
982            }
983    
984          RRETURN(MATCH_NOMATCH);
985          }
986    
987        /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
988        as a non-capturing bracket. */
989    
990          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
991            eptrb, flags, RM48);      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
992          if (rrc == MATCH_NOMATCH) md->mark = markptr;  
993          RRETURN(rrc);      DPRINTF(("insufficient capture room: treat as non-capturing\n"));
         }  
994    
995        /* For non-final alternatives, continue the loop for a NOMATCH result;      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
996        otherwise return. */      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
997    
998        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,      /* Non-capturing possessive bracket with unlimited repeat. We come here
999          eptrb, flags, RM2);      from BRAZERO with allow_zero = TRUE. The code is similar to the above,
1000        without the capturing complication. It is written out separately for speed
1001        and cleanliness. */
1002    
1003        case OP_BRAPOS:
1004        case OP_SBRAPOS:
1005        allow_zero = FALSE;
1006    
1007        POSSESSIVE_NON_CAPTURE:
1008        matched_once = FALSE;
1009        code_offset = ecode - md->start_code;
1010    
1011        for (;;)
1012          {
1013          if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
1014          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
1015            eptrb, RM48);
1016          if (rrc == MATCH_KETRPOS)
1017            {
1018            offset_top = md->end_offset_top;
1019            eptr = md->end_match_ptr;
1020            ecode = md->start_code + code_offset;
1021            matched_once = TRUE;
1022            continue;
1023            }
1024        if (rrc != MATCH_NOMATCH &&        if (rrc != MATCH_NOMATCH &&
1025            (rrc != MATCH_THEN || md->start_match_ptr != ecode))            (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1026          RRETURN(rrc);          RRETURN(rrc);
1027        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1028          if (*ecode != OP_ALT) break;
1029        }        }
1030    
1031        if (matched_once || allow_zero)
1032          {
1033          ecode += 1 + LINK_SIZE;
1034          break;
1035          }
1036        RRETURN(MATCH_NOMATCH);
1037    
1038      /* Control never reaches here. */      /* Control never reaches here. */
1039    
1040      /* Conditional group: compilation checked that there are no more than      /* Conditional group: compilation checked that there are no more than
1041      two branches. If the condition is false, skipping the first branch takes us      two branches. If the condition is false, skipping the first branch takes us
1042      past the end if there is only one branch, but that's OK because that is      past the end if there is only one branch, but that's OK because that is
1043      exactly what going to the ket would do. As there is only one branch to be      exactly what going to the ket would do. */
     obeyed, we can use tail recursion to avoid using another stack frame. */  
1044    
1045      case OP_COND:      case OP_COND:
1046      case OP_SCOND:      case OP_SCOND:
1047      codelink= GET(ecode, 1);      codelink = GET(ecode, 1);
1048    
1049      /* Because of the way auto-callout works during compile, a callout item is      /* Because of the way auto-callout works during compile, a callout item is
1050      inserted between OP_COND and an assertion condition. */      inserted between OP_COND and an assertion condition. */
# Line 1093  for (;;) Line 1219  for (;;)
1219        }        }
1220    
1221      /* The condition is an assertion. Call match() to evaluate it - setting      /* The condition is an assertion. Call match() to evaluate it - setting
1222      the final argument match_condassert causes it to stop at the end of an      md->match_function_type to MATCH_CONDASSERT causes it to stop at the end of
1223      assertion. */      an assertion. */
1224    
1225      else      else
1226        {        {
1227        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        md->match_function_type = MATCH_CONDASSERT;
1228            match_condassert, RM3);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM3);
1229        if (rrc == MATCH_MATCH)        if (rrc == MATCH_MATCH)
1230          {          {
1231          condition = TRUE;          condition = TRUE;
# Line 1119  for (;;) Line 1245  for (;;)
1245        }        }
1246    
1247      /* 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,
1248      we can use tail recursion to avoid using another stack frame, except when      we used to use tail recursion to avoid using another stack frame, except
1249      match_cbegroup is required for an unlimited repeat of a possibly empty      when there was unlimited repeat of a possibly empty group. However, that
1250      group. If the second alternative doesn't exist, we can just plough on. */      strategy no longer works because of the possibilty of (*THEN) being
1251        encountered in the branch. A recursive call to match() is always required,
1252        unless the second alternative doesn't exist, in which case we can just
1253        plough on. */
1254    
1255      if (condition || *ecode == OP_ALT)      if (condition || *ecode == OP_ALT)
1256        {        {
1257        ecode += 1 + LINK_SIZE;        if (op == OP_SCOND) md->match_function_type = MATCH_CBEGROUP;
1258        if (op == OP_SCOND)        /* Possibly empty group */        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM49);
1259          {        if (rrc == MATCH_THEN && md->start_match_ptr == ecode)
1260          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);          rrc = MATCH_NOMATCH;
1261          RRETURN(rrc);        RRETURN(rrc);
         }  
       else                       /* Group must match something */  
         {  
         flags = 0;  
         goto TAIL_RECURSE;  
         }  
1262        }        }
1263      else                         /* Condition false & no alternative */      else                         /* Condition false & no alternative */
1264        {        {
# Line 1168  for (;;) Line 1291  for (;;)
1291      break;      break;
1292    
1293    
1294      /* End of the pattern, either real or forced. If we are in a top-level      /* End of the pattern, either real or forced. If we are in a recursion, we
1295      recursion, we should restore the offsets appropriately and continue from      should restore the offsets appropriately, and if it's a top-level
1296      after the call. */      recursion, continue from after the call. */
1297    
1298      case OP_ACCEPT:      case OP_ACCEPT:
1299        case OP_ASSERT_ACCEPT:
1300      case OP_END:      case OP_END:
1301      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL)
1302        {        {
1303        recursion_info *rec = md->recursive;        recursion_info *rec = md->recursive;
       DPRINTF(("End of pattern in a (?0) recursion\n"));  
1304        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
1305        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
1306          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
1307        offset_top = rec->save_offset_top;        offset_top = rec->save_offset_top;
1308        ims = original_ims;        if (rec->group_num == 0)
1309        ecode = rec->after_call;          {
1310        break;          ecode = rec->after_call;
1311            break;
1312            }
1313        }        }
1314    
1315      /* Otherwise, if we have matched an empty string, fail if PCRE_NOTEMPTY is      /* Otherwise, if we have matched an empty string, fail if not in an
1316      set, or if PCRE_NOTEMPTY_ATSTART is set and we have matched at the start of      assertion and if either PCRE_NOTEMPTY is set, or if PCRE_NOTEMPTY_ATSTART
1317      the subject. In both cases, backtracking will then try other alternatives,      is set and we have matched at the start of the subject. In both cases,
1318      if any. */      backtracking will then try other alternatives, if any. */
1319    
1320      if (eptr == mstart &&      else if (eptr == mstart && op != OP_ASSERT_ACCEPT &&
1321          (md->notempty ||          (md->notempty ||
1322            (md->notempty_atstart &&            (md->notempty_atstart &&
1323              mstart == md->start_subject + md->start_offset)))              mstart == md->start_subject + md->start_offset)))
1324        MRRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1325    
1326      /* Otherwise, we have a match. */      /* Otherwise, we have a match. */
1327    
1328      md->end_match_ptr = eptr;           /* Record where we ended */      md->end_match_ptr = eptr;           /* Record where we ended */
1329      md->end_offset_top = offset_top;    /* and how many extracts were taken */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
1330      md->start_match_ptr = mstart;       /* and the start (\K can modify) */      md->start_match_ptr = mstart;       /* and the start (\K can modify) */
# Line 1210  for (;;) Line 1335  for (;;)
1335      rrc = (op == OP_END)? MATCH_MATCH : MATCH_ACCEPT;      rrc = (op == OP_END)? MATCH_MATCH : MATCH_ACCEPT;
1336      MRRETURN(rrc);      MRRETURN(rrc);
1337    
     /* Change option settings */  
   
     case OP_OPT:  
     ims = ecode[1];  
     ecode += 2;  
     DPRINTF(("ims set to %02lx\n", ims));  
     break;  
   
1338      /* Assertion brackets. Check the alternative branches in turn - the      /* Assertion brackets. Check the alternative branches in turn - the
1339      matching won't pass the KET for an assertion. If any one branch matches,      matching won't pass the KET for an assertion. If any one branch matches,
1340      the assertion is true. Lookbehind assertions have an OP_REVERSE item at the      the assertion is true. Lookbehind assertions have an OP_REVERSE item at the
1341      start of each branch to move the current point backwards, so the code at      start of each branch to move the current point backwards, so the code at
1342      this level is identical to the lookahead case. */      this level is identical to the lookahead case. When the assertion is part
1343        of a condition, we want to return immediately afterwards. The caller of
1344        this incarnation of the match() function will have set MATCH_CONDASSERT in
1345        md->match_function type, and one of these opcodes will be the first opcode
1346        that is processed. We use a local variable that is preserved over calls to
1347        match() to remember this case. */
1348    
1349      case OP_ASSERT:      case OP_ASSERT:
1350      case OP_ASSERTBACK:      case OP_ASSERTBACK:
1351        if (md->match_function_type == MATCH_CONDASSERT)
1352          {
1353          condassert = TRUE;
1354          md->match_function_type = 0;
1355          }
1356        else condassert = FALSE;
1357    
1358      do      do
1359        {        {
1360        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM4);
         RM4);  
1361        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
1362          {          {
1363          mstart = md->start_match_ptr;   /* In case \K reset it */          mstart = md->start_match_ptr;   /* In case \K reset it */
# Line 1241  for (;;) Line 1369  for (;;)
1369        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1370        }        }
1371      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
1372    
1373      if (*ecode == OP_KET) MRRETURN(MATCH_NOMATCH);      if (*ecode == OP_KET) MRRETURN(MATCH_NOMATCH);
1374    
1375      /* If checking an assertion for a condition, return MATCH_MATCH. */      /* If checking an assertion for a condition, return MATCH_MATCH. */
1376    
1377      if ((flags & match_condassert) != 0) RRETURN(MATCH_MATCH);      if (condassert) RRETURN(MATCH_MATCH);
1378    
1379      /* Continue from after the assertion, updating the offsets high water      /* Continue from after the assertion, updating the offsets high water
1380      mark, since extracts may have been taken during the assertion. */      mark, since extracts may have been taken during the assertion. */
# Line 1261  for (;;) Line 1390  for (;;)
1390    
1391      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1392      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1393        if (md->match_function_type == MATCH_CONDASSERT)
1394          {
1395          condassert = TRUE;
1396          md->match_function_type = 0;
1397          }
1398        else condassert = FALSE;
1399    
1400      do      do
1401        {        {
1402        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5);
         RM5);  
1403        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) MRRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) MRRETURN(MATCH_NOMATCH);
1404        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)
1405          {          {
# Line 1278  for (;;) Line 1413  for (;;)
1413        }        }
1414      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
1415    
1416      if ((flags & match_condassert) != 0) RRETURN(MATCH_MATCH);      if (condassert) RRETURN(MATCH_MATCH);  /* Condition assertion */
1417    
1418      ecode += 1 + LINK_SIZE;      ecode += 1 + LINK_SIZE;
1419      continue;      continue;
1420    
# Line 1392  for (;;) Line 1527  for (;;)
1527        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1528              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1529        new_recursive.save_offset_top = offset_top;        new_recursive.save_offset_top = offset_top;
1530    
1531        /* OK, now we can do the recursion. For each top-level alternative we        /* OK, now we can do the recursion. For each top-level alternative we
1532        restore the offset and recursion data. */        restore the offset and recursion data. */
1533    
1534        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
1535        flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;        cbegroup = (*callpat >= OP_SBRA);
1536        do        do
1537          {          {
1538            if (cbegroup) md->match_function_type = MATCH_CBEGROUP;
1539          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1540            md, ims, eptrb, flags, RM6);            md, eptrb, RM6);
1541          if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)          if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
1542            {            {
1543            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
# Line 1448  for (;;) Line 1584  for (;;)
1584    
1585      do      do
1586        {        {
1587        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM7);
1588        if (rrc == MATCH_MATCH)  /* Note: _not_ MATCH_ACCEPT */        if (rrc == MATCH_MATCH)  /* Note: _not_ MATCH_ACCEPT */
1589          {          {
1590          mstart = md->start_match_ptr;          mstart = md->start_match_ptr;
# Line 1465  for (;;) Line 1601  for (;;)
1601    
1602      if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);      if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);
1603    
1604      /* Continue as from after the assertion, updating the offsets high water      /* Continue after the group, updating the offsets high water mark, since
1605      mark, since extracts may have been taken. */      extracts may have been taken. */
1606    
1607      do ecode += GET(ecode, 1); while (*ecode == OP_ALT);      do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
1608    
# Line 1487  for (;;) Line 1623  for (;;)
1623    
1624      /* 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
1625      preceding bracket, in the appropriate order. The second "call" of match()      preceding bracket, in the appropriate order. The second "call" of match()
1626      uses tail recursion, to avoid using another stack frame. We need to reset      uses tail recursion, to avoid using another stack frame. */
     any options that changed within the bracket before re-running it, so  
     check the next opcode. */  
   
     if (ecode[1+LINK_SIZE] == OP_OPT)  
       {  
       ims = (ims & ~PCRE_IMS) | ecode[4];  
       DPRINTF(("ims set to %02lx at group repeat\n", ims));  
       }  
1627    
1628      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1629        {        {
1630        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM8);
1631        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1632        ecode = prev;        ecode = prev;
       flags = 0;  
1633        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1634        }        }
1635      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1636        {        {
1637        RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);        md->match_function_type = MATCH_CBEGROUP;
1638          RMATCH(eptr, prev, offset_top, md, eptrb, RM9);
1639        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1640        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
       flags = 0;  
1641        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1642        }        }
1643      /* Control never gets here */      /* Control never gets here */
# Line 1527  for (;;) Line 1654  for (;;)
1654      at all - i.e. it could be ()* or ()? or even (){0} in the pattern. Brackets      at all - i.e. it could be ()* or ()? or even (){0} in the pattern. Brackets
1655      with fixed upper repeat limits are compiled as a number of copies, with the      with fixed upper repeat limits are compiled as a number of copies, with the
1656      optional ones preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1657    
1658      case OP_BRAZERO:      case OP_BRAZERO:
1659        {      next = ecode + 1;
1660        next = ecode+1;      RMATCH(eptr, next, offset_top, md, eptrb, RM10);
1661        RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1662        if (rrc != MATCH_NOMATCH) RRETURN(rrc);      do next += GET(next, 1); while (*next == OP_ALT);
1663        do next += GET(next,1); while (*next == OP_ALT);      ecode = next + 1 + LINK_SIZE;
       ecode = next + 1 + LINK_SIZE;  
       }  
1664      break;      break;
1665    
1666      case OP_BRAMINZERO:      case OP_BRAMINZERO:
1667        {      next = ecode + 1;
1668        next = ecode+1;      do next += GET(next, 1); while (*next == OP_ALT);
1669        do next += GET(next, 1); while (*next == OP_ALT);      RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, eptrb, RM11);
1670        RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11);      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1671        if (rrc != MATCH_NOMATCH) RRETURN(rrc);      ecode++;
       ecode++;  
       }  
1672      break;      break;
1673    
1674      case OP_SKIPZERO:      case OP_SKIPZERO:
1675        {      next = ecode+1;
1676        next = ecode+1;      do next += GET(next,1); while (*next == OP_ALT);
1677        do next += GET(next,1); while (*next == OP_ALT);      ecode = next + 1 + LINK_SIZE;
       ecode = next + 1 + LINK_SIZE;  
       }  
1678      break;      break;
1679    
1680        /* BRAPOSZERO occurs before a possessive bracket group. Don't do anything
1681        here; just jump to the group, with allow_zero set TRUE. */
1682    
1683        case OP_BRAPOSZERO:
1684        op = *(++ecode);
1685        allow_zero = TRUE;
1686        if (op == OP_CBRAPOS || op == OP_SCBRAPOS) goto POSSESSIVE_CAPTURE;
1687          goto POSSESSIVE_NON_CAPTURE;
1688    
1689      /* End of a group, repeated or non-repeating. */      /* End of a group, repeated or non-repeating. */
1690    
1691      case OP_KET:      case OP_KET:
1692      case OP_KETRMIN:      case OP_KETRMIN:
1693      case OP_KETRMAX:      case OP_KETRMAX:
1694        case OP_KETRPOS:
1695      prev = ecode - GET(ecode, 1);      prev = ecode - GET(ecode, 1);
1696    
1697      /* If this was a group that remembered the subject start, in order to break      /* If this was a group that remembered the subject start, in order to break
# Line 1595  for (;;) Line 1726  for (;;)
1726      a recurse into group 0, so it won't be picked up here. Instead, we catch it      a recurse into group 0, so it won't be picked up here. Instead, we catch it
1727      when the OP_END is reached. Other recursion is handled here. */      when the OP_END is reached. Other recursion is handled here. */
1728    
1729      if (*prev == OP_CBRA || *prev == OP_SCBRA)      if (*prev == OP_CBRA || *prev == OP_SCBRA ||
1730            *prev == OP_CBRAPOS || *prev == OP_SCBRAPOS)
1731        {        {
1732        number = GET2(prev, 1+LINK_SIZE);        number = GET2(prev, 1+LINK_SIZE);
1733        offset = number << 1;        offset = number << 1;
# Line 1608  for (;;) Line 1740  for (;;)
1740        md->capture_last = number;        md->capture_last = number;
1741        if (offset >= md->offset_max) md->offset_overflow = TRUE; else        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1742          {          {
1743            /* If offset is greater than offset_top, it means that we are
1744            "skipping" a capturing group, and that group's offsets must be marked
1745            unset. In earlier versions of PCRE, all the offsets were unset at the
1746            start of matching, but this doesn't work because atomic groups and
1747            assertions can cause a value to be set that should later be unset.
1748            Example: matching /(?>(a))b|(a)c/ against "ac". This sets group 1 as
1749            part of the atomic group, but this is not on the final matching path,
1750            so must be unset when 2 is set. (If there is no group 2, there is no
1751            problem, because offset_top will then be 2, indicating no capture.) */
1752    
1753            if (offset > offset_top)
1754              {
1755              register int *iptr = md->offset_vector + offset_top;
1756              register int *iend = md->offset_vector + offset;
1757              while (iptr < iend) *iptr++ = -1;
1758              }
1759    
1760            /* Now make the extraction */
1761    
1762          md->offset_vector[offset] =          md->offset_vector[offset] =
1763            md->offset_vector[md->offset_end - number];            md->offset_vector[md->offset_end - number];
1764          md->offset_vector[offset+1] = (int)(eptr - md->start_subject);          md->offset_vector[offset+1] = (int)(eptr - md->start_subject);
# Line 1626  for (;;) Line 1777  for (;;)
1777            rec->saved_max * sizeof(int));            rec->saved_max * sizeof(int));
1778          offset_top = rec->save_offset_top;          offset_top = rec->save_offset_top;
1779          ecode = rec->after_call;          ecode = rec->after_call;
         ims = original_ims;  
1780          break;          break;
1781          }          }
1782        }        }
1783    
     /* For both capturing and non-capturing groups, reset the value of the ims  
     flags, in case they got changed during the group. */  
   
     ims = original_ims;  
     DPRINTF(("ims reset to %02lx\n", ims));  
   
1784      /* For a non-repeating ket, just continue at this level. This also      /* For a non-repeating ket, just continue at this level. This also
1785      happens for a repeating ket if no characters were matched in the group.      happens for a repeating ket if no characters were matched in the group.
1786      This is the forcible breaking of infinite loops as implemented in Perl      This is the forcible breaking of infinite loops as implemented in Perl
# Line 1648  for (;;) Line 1792  for (;;)
1792        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1793        break;        break;
1794        }        }
1795    
1796      /* The repeating kets try the rest of the pattern or restart from the      /* OP_KETRPOS is a possessive repeating ket. Remember the current position,
1797      preceding bracket, in the appropriate order. In the second case, we can use      and return the MATCH_KETRPOS. This makes it possible to do the repeats one
1798      tail recursion to avoid using another stack frame, unless we have an      at a time from the outer level, thus saving stack. */
1799    
1800        if (*ecode == OP_KETRPOS)
1801          {
1802          md->end_match_ptr = eptr;
1803          md->end_offset_top = offset_top;
1804          RRETURN(MATCH_KETRPOS);
1805          }
1806    
1807        /* The normal repeating kets try the rest of the pattern or restart from
1808        the preceding bracket, in the appropriate order. In the second case, we can
1809        use tail recursion to avoid using another stack frame, unless we have an
1810      unlimited repeat of a group that can match an empty string. */      unlimited repeat of a group that can match an empty string. */
1811    
     flags = (*prev >= OP_SBRA)? match_cbegroup : 0;  
   
1812      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1813        {        {
1814        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM12);
1815        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1816        if (flags != 0)    /* Could match an empty string */        if (*prev >= OP_SBRA)    /* Could match an empty string */
1817          {          {
1818          RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);          md->match_function_type = MATCH_CBEGROUP;
1819            RMATCH(eptr, prev, offset_top, md, eptrb, RM50);
1820          RRETURN(rrc);          RRETURN(rrc);
1821          }          }
1822        ecode = prev;        ecode = prev;
# Line 1670  for (;;) Line 1824  for (;;)
1824        }        }
1825      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1826        {        {
1827        RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);        if (*prev >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
1828          RMATCH(eptr, prev, offset_top, md, eptrb, RM13);
1829        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1830        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
       flags = 0;  
1831        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1832        }        }
1833      /* Control never gets here */      /* Control never gets here */
1834    
1835      /* Start of subject unless notbol, or after internal newline if multiline */      /* Not multiline mode: start of subject assertion, unless notbol. */
1836    
1837      case OP_CIRC:      case OP_CIRC:
1838      if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH);      if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH);
1839      if ((ims & PCRE_MULTILINE) != 0)  
       {  
       if (eptr != md->start_subject &&  
           (eptr == md->end_subject || !WAS_NEWLINE(eptr)))  
         MRRETURN(MATCH_NOMATCH);  
       ecode++;  
       break;  
       }  
     /* ... else fall through */  
   
1840      /* Start of subject assertion */      /* Start of subject assertion */
1841    
1842      case OP_SOD:      case OP_SOD:
1843      if (eptr != md->start_subject) MRRETURN(MATCH_NOMATCH);      if (eptr != md->start_subject) MRRETURN(MATCH_NOMATCH);
1844      ecode++;      ecode++;
1845      break;      break;
1846    
1847        /* Multiline mode: start of subject unless notbol, or after any newline. */
1848    
1849        case OP_CIRCM:
1850        if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH);
1851        if (eptr != md->start_subject &&
1852            (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
1853          MRRETURN(MATCH_NOMATCH);
1854        ecode++;
1855        break;
1856    
1857      /* Start of match assertion */      /* Start of match assertion */
1858    
# Line 1713  for (;;) Line 1868  for (;;)
1868      ecode++;      ecode++;
1869      break;      break;
1870    
1871      /* Assert before internal newline if multiline, or before a terminating      /* Multiline mode: assert before any newline, or before end of subject
1872      newline unless endonly is set, else end of subject unless noteol is set. */      unless noteol is set. */
1873    
1874      case OP_DOLL:      case OP_DOLLM:
1875      if ((ims & PCRE_MULTILINE) != 0)      if (eptr < md->end_subject)
1876        {        { if (!IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH); }
1877        if (eptr < md->end_subject)      else
         { if (!IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH); }  
       else  
         {  
         if (md->noteol) MRRETURN(MATCH_NOMATCH);  
         SCHECK_PARTIAL();  
         }  
       ecode++;  
       break;  
       }  
     else  /* Not multiline */  
1878        {        {
1879        if (md->noteol) MRRETURN(MATCH_NOMATCH);        if (md->noteol) MRRETURN(MATCH_NOMATCH);
1880        if (!md->endonly) goto ASSERT_NL_OR_EOS;        SCHECK_PARTIAL();
1881        }        }
1882        ecode++;
1883        break;
1884    
1885        /* Not multiline mode: assert before a terminating newline or before end of
1886        subject unless noteol is set. */
1887    
1888        case OP_DOLL:
1889        if (md->noteol) MRRETURN(MATCH_NOMATCH);
1890        if (!md->endonly) goto ASSERT_NL_OR_EOS;
1891    
1892      /* ... else fall through for endonly */      /* ... else fall through for endonly */
1893    
# Line 2017  for (;;) Line 2171  for (;;)
2171      switch(c)      switch(c)
2172        {        {
2173        default: MRRETURN(MATCH_NOMATCH);        default: MRRETURN(MATCH_NOMATCH);
2174    
2175        case 0x000d:        case 0x000d:
2176        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
2177        break;        break;
# Line 2269  for (;;) Line 2424  for (;;)
2424      loops). */      loops). */
2425    
2426      case OP_REF:      case OP_REF:
2427        case OP_REFI:
2428        caseless = op == OP_REFI;
2429      offset = GET2(ecode, 1) << 1;               /* Doubled ref number */      offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
2430      ecode += 3;      ecode += 3;
2431    
# Line 2316  for (;;) Line 2473  for (;;)
2473        break;        break;
2474    
2475        default:               /* No repeat follows */        default:               /* No repeat follows */
2476        if ((length = match_ref(offset, eptr, length, md, ims)) < 0)        if ((length = match_ref(offset, eptr, length, md, caseless)) < 0)
2477          {          {
2478          CHECK_PARTIAL();          CHECK_PARTIAL();
2479          MRRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
# Line 2337  for (;;) Line 2494  for (;;)
2494      for (i = 1; i <= min; i++)      for (i = 1; i <= min; i++)
2495        {        {
2496        int slength;        int slength;
2497        if ((slength = match_ref(offset, eptr, length, md, ims)) < 0)        if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2498          {          {
2499          CHECK_PARTIAL();          CHECK_PARTIAL();
2500          MRRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
# Line 2357  for (;;) Line 2514  for (;;)
2514        for (fi = min;; fi++)        for (fi = min;; fi++)
2515          {          {
2516          int slength;          int slength;
2517          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);          RMATCH(eptr, ecode, offset_top, md, eptrb, RM14);
2518          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2519          if (fi >= max) MRRETURN(MATCH_NOMATCH);          if (fi >= max) MRRETURN(MATCH_NOMATCH);
2520          if ((slength = match_ref(offset, eptr, length, md, ims)) < 0)          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2521            {            {
2522            CHECK_PARTIAL();            CHECK_PARTIAL();
2523            MRRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
# Line 2378  for (;;) Line 2535  for (;;)
2535        for (i = min; i < max; i++)        for (i = min; i < max; i++)
2536          {          {
2537          int slength;          int slength;
2538          if ((slength = match_ref(offset, eptr, length, md, ims)) < 0)          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2539            {            {
2540            CHECK_PARTIAL();            CHECK_PARTIAL();
2541            break;            break;
# Line 2387  for (;;) Line 2544  for (;;)
2544          }          }
2545        while (eptr >= pp)        while (eptr >= pp)
2546          {          {
2547          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);          RMATCH(eptr, ecode, offset_top, md, eptrb, RM15);
2548          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2549          eptr -= length;          eptr -= length;
2550          }          }
# Line 2497  for (;;) Line 2654  for (;;)
2654            {            {
2655            for (fi = min;; fi++)            for (fi = min;; fi++)
2656              {              {
2657              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM16);
2658              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2659              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2660              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 2522  for (;;) Line 2679  for (;;)
2679            {            {
2680            for (fi = min;; fi++)            for (fi = min;; fi++)
2681              {              {
2682              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM17);
2683              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2684              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2685              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 2568  for (;;) Line 2725  for (;;)
2725              }              }
2726            for (;;)            for (;;)
2727              {              {
2728              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM18);
2729              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2730              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2731              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2591  for (;;) Line 2748  for (;;)
2748              }              }
2749            while (eptr >= pp)            while (eptr >= pp)
2750              {              {
2751              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM19);
2752              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2753              eptr--;              eptr--;
2754              }              }
# Line 2667  for (;;) Line 2824  for (;;)
2824          {          {
2825          for (fi = min;; fi++)          for (fi = min;; fi++)
2826            {            {
2827            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM20);
2828            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2829            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2830            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
# Line 2700  for (;;) Line 2857  for (;;)
2857            }            }
2858          for(;;)          for(;;)
2859            {            {
2860            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM21);
2861            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2862            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2863            if (utf8) BACKCHAR(eptr);            if (utf8) BACKCHAR(eptr);
# Line 2745  for (;;) Line 2902  for (;;)
2902    
2903      /* Match a single character, caselessly */      /* Match a single character, caselessly */
2904    
2905      case OP_CHARNC:      case OP_CHARI:
2906  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2907      if (utf8)      if (utf8)
2908        {        {
# Line 2805  for (;;) Line 2962  for (;;)
2962      /* Match a single character repeatedly. */      /* Match a single character repeatedly. */
2963    
2964      case OP_EXACT:      case OP_EXACT:
2965        case OP_EXACTI:
2966      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
2967      ecode += 3;      ecode += 3;
2968      goto REPEATCHAR;      goto REPEATCHAR;
2969    
2970      case OP_POSUPTO:      case OP_POSUPTO:
2971        case OP_POSUPTOI:
2972      possessive = TRUE;      possessive = TRUE;
2973      /* Fall through */      /* Fall through */
2974    
2975      case OP_UPTO:      case OP_UPTO:
2976        case OP_UPTOI:
2977      case OP_MINUPTO:      case OP_MINUPTO:
2978        case OP_MINUPTOI:
2979      min = 0;      min = 0;
2980      max = GET2(ecode, 1);      max = GET2(ecode, 1);
2981      minimize = *ecode == OP_MINUPTO;      minimize = *ecode == OP_MINUPTO || *ecode == OP_MINUPTOI;
2982      ecode += 3;      ecode += 3;
2983      goto REPEATCHAR;      goto REPEATCHAR;
2984    
2985      case OP_POSSTAR:      case OP_POSSTAR:
2986        case OP_POSSTARI:
2987      possessive = TRUE;      possessive = TRUE;
2988      min = 0;      min = 0;
2989      max = INT_MAX;      max = INT_MAX;
# Line 2829  for (;;) Line 2991  for (;;)
2991      goto REPEATCHAR;      goto REPEATCHAR;
2992    
2993      case OP_POSPLUS:      case OP_POSPLUS:
2994        case OP_POSPLUSI:
2995      possessive = TRUE;      possessive = TRUE;
2996      min = 1;      min = 1;
2997      max = INT_MAX;      max = INT_MAX;
# Line 2836  for (;;) Line 2999  for (;;)
2999      goto REPEATCHAR;      goto REPEATCHAR;
3000    
3001      case OP_POSQUERY:      case OP_POSQUERY:
3002        case OP_POSQUERYI:
3003      possessive = TRUE;      possessive = TRUE;
3004      min = 0;      min = 0;
3005      max = 1;      max = 1;
# Line 2843  for (;;) Line 3007  for (;;)
3007      goto REPEATCHAR;      goto REPEATCHAR;
3008    
3009      case OP_STAR:      case OP_STAR:
3010        case OP_STARI:
3011      case OP_MINSTAR:      case OP_MINSTAR:
3012        case OP_MINSTARI:
3013      case OP_PLUS:      case OP_PLUS:
3014        case OP_PLUSI:
3015      case OP_MINPLUS:      case OP_MINPLUS:
3016        case OP_MINPLUSI:
3017      case OP_QUERY:      case OP_QUERY:
3018        case OP_QUERYI:
3019      case OP_MINQUERY:      case OP_MINQUERY:
3020      c = *ecode++ - OP_STAR;      case OP_MINQUERYI:
3021        c = *ecode++ - ((op < OP_STARI)? OP_STAR : OP_STARI);
3022      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
   
3023      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
3024      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
3025      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
# Line 2873  for (;;) Line 3042  for (;;)
3042          {          {
3043  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3044          unsigned int othercase;          unsigned int othercase;
3045          if ((ims & PCRE_CASELESS) != 0 &&          if (op >= OP_STARI &&     /* Caseless */
3046              (othercase = UCD_OTHERCASE(fc)) != fc)              (othercase = UCD_OTHERCASE(fc)) != fc)
3047            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
3048          else oclength = 0;          else oclength = 0;
# Line 2901  for (;;) Line 3070  for (;;)
3070            {            {
3071            for (fi = min;; fi++)            for (fi = min;; fi++)
3072              {              {
3073              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM22);
3074              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3075              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3076              if (eptr <= md->end_subject - length &&              if (eptr <= md->end_subject - length &&
# Line 2943  for (;;) Line 3112  for (;;)
3112    
3113            for(;;)            for(;;)
3114              {              {
3115              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM23);
3116              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3117              if (eptr == pp) { MRRETURN(MATCH_NOMATCH); }              if (eptr == pp) { MRRETURN(MATCH_NOMATCH); }
3118  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2980  for (;;) Line 3149  for (;;)
3149      DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc, min, max,      DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc, min, max,
3150        max, eptr));        max, eptr));
3151    
3152      if ((ims & PCRE_CASELESS) != 0)      if (op >= OP_STARI)  /* Caseless */
3153        {        {
3154        fc = md->lcc[fc];        fc = md->lcc[fc];
3155        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
# Line 2997  for (;;) Line 3166  for (;;)
3166          {          {
3167          for (fi = min;; fi++)          for (fi = min;; fi++)
3168            {            {
3169            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM24);
3170            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3171            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
3172            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
# Line 3027  for (;;) Line 3196  for (;;)
3196    
3197          while (eptr >= pp)          while (eptr >= pp)
3198            {            {
3199            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM25);
3200            eptr--;            eptr--;
3201            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3202            }            }
# Line 3056  for (;;) Line 3225  for (;;)
3225          {          {
3226          for (fi = min;; fi++)          for (fi = min;; fi++)
3227            {            {
3228            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM26);
3229            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3230            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
3231            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
# Line 3085  for (;;) Line 3254  for (;;)
3254    
3255          while (eptr >= pp)          while (eptr >= pp)
3256            {            {
3257            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM27);
3258            eptr--;            eptr--;
3259            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3260            }            }
# Line 3098  for (;;) Line 3267  for (;;)
3267      checking can be multibyte. */      checking can be multibyte. */
3268    
3269      case OP_NOT:      case OP_NOT:
3270        case OP_NOTI:
3271      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
3272        {        {
3273        SCHECK_PARTIAL();        SCHECK_PARTIAL();
# Line 3105  for (;;) Line 3275  for (;;)
3275        }        }
3276      ecode++;      ecode++;
3277      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
3278      if ((ims & PCRE_CASELESS) != 0)      if (op == OP_NOTI)         /* The caseless case */
3279        {        {
3280  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
3281        if (c < 256)        if (c < 256)
# Line 3113  for (;;) Line 3283  for (;;)
3283        c = md->lcc[c];        c = md->lcc[c];
3284        if (md->lcc[*ecode++] == c) MRRETURN(MATCH_NOMATCH);        if (md->lcc[*ecode++] == c) MRRETURN(MATCH_NOMATCH);
3285        }        }
3286      else      else    /* Caseful */
3287        {        {
3288        if (*ecode++ == c) MRRETURN(MATCH_NOMATCH);        if (*ecode++ == c) MRRETURN(MATCH_NOMATCH);
3289        }        }
# Line 3127  for (;;) Line 3297  for (;;)
3297      about... */      about... */
3298    
3299      case OP_NOTEXACT:      case OP_NOTEXACT:
3300        case OP_NOTEXACTI:
3301      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
3302      ecode += 3;      ecode += 3;
3303      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3304    
3305      case OP_NOTUPTO:      case OP_NOTUPTO:
3306        case OP_NOTUPTOI:
3307      case OP_NOTMINUPTO:      case OP_NOTMINUPTO:
3308        case OP_NOTMINUPTOI:
3309      min = 0;      min = 0;
3310      max = GET2(ecode, 1);      max = GET2(ecode, 1);
3311      minimize = *ecode == OP_NOTMINUPTO;      minimize = *ecode == OP_NOTMINUPTO || *ecode == OP_NOTMINUPTOI;
3312      ecode += 3;      ecode += 3;
3313      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3314    
3315      case OP_NOTPOSSTAR:      case OP_NOTPOSSTAR:
3316        case OP_NOTPOSSTARI:
3317      possessive = TRUE;      possessive = TRUE;
3318      min = 0;      min = 0;
3319      max = INT_MAX;      max = INT_MAX;
# Line 3147  for (;;) Line 3321  for (;;)
3321      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3322    
3323      case OP_NOTPOSPLUS:      case OP_NOTPOSPLUS:
3324        case OP_NOTPOSPLUSI:
3325      possessive = TRUE;      possessive = TRUE;
3326      min = 1;      min = 1;
3327      max = INT_MAX;      max = INT_MAX;
# Line 3154  for (;;) Line 3329  for (;;)
3329      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3330    
3331      case OP_NOTPOSQUERY:      case OP_NOTPOSQUERY:
3332        case OP_NOTPOSQUERYI:
3333      possessive = TRUE;      possessive = TRUE;
3334      min = 0;      min = 0;
3335      max = 1;      max = 1;
# Line 3161  for (;;) Line 3337  for (;;)
3337      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3338    
3339      case OP_NOTPOSUPTO:      case OP_NOTPOSUPTO:
3340        case OP_NOTPOSUPTOI:
3341      possessive = TRUE;      possessive = TRUE;
3342      min = 0;      min = 0;
3343      max = GET2(ecode, 1);      max = GET2(ecode, 1);
# Line 3168  for (;;) Line 3345  for (;;)
3345      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3346    
3347      case OP_NOTSTAR:      case OP_NOTSTAR:
3348        case OP_NOTSTARI:
3349      case OP_NOTMINSTAR:      case OP_NOTMINSTAR:
3350        case OP_NOTMINSTARI:
3351      case OP_NOTPLUS:      case OP_NOTPLUS:
3352        case OP_NOTPLUSI:
3353      case OP_NOTMINPLUS:      case OP_NOTMINPLUS:
3354        case OP_NOTMINPLUSI:
3355      case OP_NOTQUERY:      case OP_NOTQUERY:
3356        case OP_NOTQUERYI:
3357      case OP_NOTMINQUERY:      case OP_NOTMINQUERY:
3358      c = *ecode++ - OP_NOTSTAR;      case OP_NOTMINQUERYI:
3359        c = *ecode++ - ((op >= OP_NOTSTARI)? OP_NOTSTARI: OP_NOTSTAR);
3360      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
3361      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
3362      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
# Line 3195  for (;;) Line 3378  for (;;)
3378      DPRINTF(("negative matching %c{%d,%d} against subject %.*s\n", fc, min, max,      DPRINTF(("negative matching %c{%d,%d} against subject %.*s\n", fc, min, max,
3379        max, eptr));        max, eptr));
3380    
3381      if ((ims & PCRE_CASELESS) != 0)      if (op >= OP_NOTSTARI)     /* Caseless */
3382        {        {
3383        fc = md->lcc[fc];        fc = md->lcc[fc];
3384    
# Line 3243  for (;;) Line 3426  for (;;)
3426            register unsigned int d;            register unsigned int d;
3427            for (fi = min;; fi++)            for (fi = min;; fi++)
3428              {              {
3429              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM28);
3430              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3431              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3432              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 3262  for (;;) Line 3445  for (;;)
3445            {            {
3446            for (fi = min;; fi++)            for (fi = min;; fi++)
3447              {              {
3448              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM29);
3449              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3450              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3451              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 3303  for (;;) Line 3486  for (;;)
3486          if (possessive) continue;          if (possessive) continue;
3487          for(;;)          for(;;)
3488              {              {
3489              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM30);
3490              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3491              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3492              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 3326  for (;;) Line 3509  for (;;)
3509            if (possessive) continue;            if (possessive) continue;
3510            while (eptr >= pp)            while (eptr >= pp)
3511              {              {
3512              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM31);
3513              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3514              eptr--;              eptr--;
3515              }              }
# Line 3383  for (;;) Line 3566  for (;;)
3566            register unsigned int d;            register unsigned int d;
3567            for (fi = min;; fi++)            for (fi = min;; fi++)
3568              {              {
3569              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM32);
3570              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3571              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3572              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 3401  for (;;) Line 3584  for (;;)
3584            {            {
3585            for (fi = min;; fi++)            for (fi = min;; fi++)
3586              {              {
3587              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM33);
3588              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3589              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3590              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 3441  for (;;) Line 3624  for (;;)
3624            if (possessive) continue;            if (possessive) continue;
3625            for(;;)            for(;;)
3626              {              {
3627              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM34);
3628              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3629              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3630              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 3464  for (;;) Line 3647  for (;;)
3647            if (possessive) continue;            if (possessive) continue;
3648            while (eptr >= pp)            while (eptr >= pp)
3649              {              {
3650              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM35);
3651              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3652              eptr--;              eptr--;
3653              }              }
# Line 3791  for (;;) Line 3974  for (;;)
3974            switch(c)            switch(c)
3975              {              {
3976              default: MRRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
3977    
3978              case 0x000d:              case 0x000d:
3979              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3980              break;              break;
# Line 4067  for (;;) Line 4251  for (;;)
4251            switch(*eptr++)            switch(*eptr++)
4252              {              {
4253              default: MRRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
4254    
4255              case 0x000d:              case 0x000d:
4256              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
4257              break;              break;
4258    
4259              case 0x000a:              case 0x000a:
4260              break;              break;
4261    
# Line 4259  for (;;) Line 4445  for (;;)
4445            case PT_ANY:            case PT_ANY:
4446            for (fi = min;; fi++)            for (fi = min;; fi++)
4447              {              {
4448              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM36);
4449              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4450              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4451              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4275  for (;;) Line 4461  for (;;)
4461            case PT_LAMP:            case PT_LAMP:
4462            for (fi = min;; fi++)            for (fi = min;; fi++)
4463              {              {
4464              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM37);
4465              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4466              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4467              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4295  for (;;) Line 4481  for (;;)
4481            case PT_GC:            case PT_GC:
4482            for (fi = min;; fi++)            for (fi = min;; fi++)
4483              {              {
4484              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM38);
4485              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4486              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4487              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4313  for (;;) Line 4499  for (;;)
4499            case PT_PC:            case PT_PC:
4500            for (fi = min;; fi++)            for (fi = min;; fi++)
4501              {              {
4502              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM39);
4503              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4504              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4505              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4331  for (;;) Line 4517  for (;;)
4517            case PT_SC:            case PT_SC:
4518            for (fi = min;; fi++)            for (fi = min;; fi++)
4519              {              {
4520              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM40);
4521              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4522              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4523              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4349  for (;;) Line 4535  for (;;)
4535            case PT_ALNUM:            case PT_ALNUM:
4536            for (fi = min;; fi++)            for (fi = min;; fi++)
4537              {              {
4538              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM59);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM59);
4539              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4540              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4541              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4368  for (;;) Line 4554  for (;;)
4554            case PT_SPACE:    /* Perl space */            case PT_SPACE:    /* Perl space */
4555            for (fi = min;; fi++)            for (fi = min;; fi++)
4556              {              {
4557              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM60);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM60);
4558              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4559              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4560              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4388  for (;;) Line 4574  for (;;)
4574            case PT_PXSPACE:  /* POSIX space */            case PT_PXSPACE:  /* POSIX space */
4575            for (fi = min;; fi++)            for (fi = min;; fi++)
4576              {              {
4577              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM61);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM61);
4578              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4579              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4580              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4408  for (;;) Line 4594  for (;;)
4594            case PT_WORD:            case PT_WORD:
4595            for (fi = min;; fi++)            for (fi = min;; fi++)
4596              {              {
4597              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM62);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM62);
4598              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4599              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4600              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4440  for (;;) Line 4626  for (;;)
4626          {          {
4627          for (fi = min;; fi++)          for (fi = min;; fi++)
4628            {            {
4629            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM41);
4630            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4631            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
4632            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
# Line 4472  for (;;) Line 4658  for (;;)
4658          {          {
4659          for (fi = min;; fi++)          for (fi = min;; fi++)
4660            {            {
4661            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM42);
4662            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4663            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
4664            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
# Line 4635  for (;;) Line 4821  for (;;)
4821          {          {
4822          for (fi = min;; fi++)          for (fi = min;; fi++)
4823            {            {
4824            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM43);
4825            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4826            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
4827            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
# Line 4933  for (;;) Line 5119  for (;;)
5119          if (possessive) continue;          if (possessive) continue;
5120          for(;;)          for(;;)
5121            {            {
5122            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM44);
5123            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5124            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
5125            if (utf8) BACKCHAR(eptr);            if (utf8) BACKCHAR(eptr);
# Line 4974  for (;;) Line 5160  for (;;)
5160    
5161          for(;;)          for(;;)
5162            {            {
5163            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM45);
5164            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5165            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
5166            for (;;)                        /* Move back over one extended */            for (;;)                        /* Move back over one extended */
# Line 5258  for (;;) Line 5444  for (;;)
5444            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
5445            }            }
5446    
5447          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run. If possessive, we are
5448            done (no backing up). Otherwise, match at this position; anything other
5449            than no match is immediately returned. For nomatch, back up one
5450            character, unless we are matching \R and the last thing matched was
5451            \r\n, in which case, back up two bytes. */
5452    
5453          if (possessive) continue;          if (possessive) continue;
5454          for(;;)          for(;;)
5455            {            {
5456            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM46);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM46);
5457            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5458            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
5459            BACKCHAR(eptr);            BACKCHAR(eptr);
5460              if (ctype == OP_ANYNL && eptr > pp  && *eptr == '\n' &&
5461                  eptr[-1] == '\r') eptr--;
5462            }            }
5463          }          }
5464        else        else
# Line 5465  for (;;) Line 5657  for (;;)
5657            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
5658            }            }
5659    
5660          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run. If possessive, we are
5661            done (no backing up). Otherwise, match at this position; anything other
5662            than no match is immediately returned. For nomatch, back up one
5663            character (byte), unless we are matching \R and the last thing matched
5664            was \r\n, in which case, back up two bytes. */
5665    
5666          if (possessive) continue;          if (possessive) continue;
5667          while (eptr >= pp)          while (eptr >= pp)
5668            {            {
5669            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM47);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM47);
           eptr--;  
5670            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5671              eptr--;
5672              if (ctype == OP_ANYNL && eptr > pp  && *eptr == '\n' &&
5673                  eptr[-1] == '\r') eptr--;
5674            }            }
5675          }          }
5676    
# Line 5511  switch (frame->Xwhere) Line 5709  switch (frame->Xwhere)
5709    LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)    LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)
5710    LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)    LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)
5711    LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)    LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
5712    LBL(53) LBL(54) LBL(55) LBL(56) LBL(57) LBL(58)    LBL(53) LBL(54) LBL(55) LBL(56) LBL(57) LBL(58) LBL(63)
5713  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
5714    LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)    LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)
5715    LBL(32) LBL(34) LBL(42) LBL(46)    LBL(32) LBL(34) LBL(42) LBL(46)
# Line 5540  Undefine all the macros that were define Line 5738  Undefine all the macros that were define
5738  #undef ecode  #undef ecode
5739  #undef mstart  #undef mstart
5740  #undef offset_top  #undef offset_top
 #undef ims  
5741  #undef eptrb  #undef eptrb
5742  #undef flags  #undef flags
5743    
# Line 5558  Undefine all the macros that were define Line 5755  Undefine all the macros that were define
5755  #undef condition  #undef condition
5756  #undef prev_is_word  #undef prev_is_word
5757    
 #undef original_ims  
   
5758  #undef ctype  #undef ctype
5759  #undef length  #undef length
5760  #undef max  #undef max
# Line 5616  pcre_exec(const pcre *argument_re, const Line 5811  pcre_exec(const pcre *argument_re, const
5811    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
5812    int offsetcount)    int offsetcount)
5813  {  {
5814  int rc, resetcount, ocount;  int rc, ocount;
5815  int first_byte = -1;  int first_byte = -1;
5816  int req_byte = -1;  int req_byte = -1;
5817  int req_byte2 = -1;  int req_byte2 = -1;
5818  int newline;  int newline;
 unsigned long int ims;  
5819  BOOL using_temporary_offsets = FALSE;  BOOL using_temporary_offsets = FALSE;
5820  BOOL anchored;  BOOL anchored;
5821  BOOL startline;  BOOL startline;
# Line 5725  utf8 = md->utf8 = (re->options & PCRE_UT Line 5919  utf8 = md->utf8 = (re->options & PCRE_UT
5919  md->use_ucp = (re->options & PCRE_UCP) != 0;  md->use_ucp = (re->options & PCRE_UCP) != 0;
5920  md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;  md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
5921    
5922    /* Some options are unpacked into BOOL variables in the hope that testing
5923    them will be faster than individual option bits. */
5924    
5925  md->notbol = (options & PCRE_NOTBOL) != 0;  md->notbol = (options & PCRE_NOTBOL) != 0;
5926  md->noteol = (options & PCRE_NOTEOL) != 0;  md->noteol = (options & PCRE_NOTEOL) != 0;
5927  md->notempty = (options & PCRE_NOTEMPTY) != 0;  md->notempty = (options & PCRE_NOTEMPTY) != 0;
5928  md->notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;  md->notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;
5929  md->partial = ((options & PCRE_PARTIAL_HARD) != 0)? 2 :  md->partial = ((options & PCRE_PARTIAL_HARD) != 0)? 2 :
5930                ((options & PCRE_PARTIAL_SOFT) != 0)? 1 : 0;                ((options & PCRE_PARTIAL_SOFT) != 0)? 1 : 0;
5931    
5932    
5933  md->hitend = FALSE;  md->hitend = FALSE;
5934  md->mark = NULL;                        /* In case never set */  md->mark = NULL;                        /* In case never set */
5935    
# Line 5813  if (md->partial && (re->flags & PCRE_NOP Line 6012  if (md->partial && (re->flags & PCRE_NOP
6012    return PCRE_ERROR_BADPARTIAL;    return PCRE_ERROR_BADPARTIAL;
6013    
6014  /* Check a UTF-8 string if required. Pass back the character offset and error  /* Check a UTF-8 string if required. Pass back the character offset and error
6015  code if a results vector is available. */  code for an invalid string if a results vector is available. */
6016    
6017  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
6018  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
6019    {    {
6020    int errorcode;    int erroroffset;
6021    int tb = _pcre_valid_utf8((USPTR)subject, length, &errorcode);    int errorcode = _pcre_valid_utf8((USPTR)subject, length, &erroroffset);
6022    if (tb >= 0)    if (errorcode != 0)
6023      {      {
6024      if (offsetcount >= 2)      if (offsetcount >= 2)
6025        {        {
6026        offsets[0] = tb;        offsets[0] = erroroffset;
6027        offsets[1] = errorcode;        offsets[1] = errorcode;
6028        }        }
6029      return (errorcode <= PCRE_UTF8_ERR5 && md->partial > 1)?      return (errorcode <= PCRE_UTF8_ERR5 && md->partial > 1)?
6030        PCRE_ERROR_SHORTUTF8 : PCRE_ERROR_BADUTF8;        PCRE_ERROR_SHORTUTF8 : PCRE_ERROR_BADUTF8;
6031      }      }
6032    if (start_offset > 0 && start_offset < length)  
6033      {    /* Check that a start_offset points to the start of a UTF-8 character. */
6034      tb = ((USPTR)subject)[start_offset] & 0xc0;  
6035      if (tb == 0x80) return PCRE_ERROR_BADUTF8_OFFSET;    if (start_offset > 0 && start_offset < length &&
6036      }        (((USPTR)subject)[start_offset] & 0xc0) == 0x80)
6037        return PCRE_ERROR_BADUTF8_OFFSET;
6038    }    }
6039  #endif  #endif
6040    
 /* The ims options can vary during the matching as a result of the presence  
 of (?ims) items in the pattern. They are kept in a local variable so that  
 restoring at the exit of a group is easy. */  
   
 ims = re->options & (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL);  
   
6041  /* If the expression has got more back references than the offsets supplied can  /* If the expression has got more back references than the offsets supplied can
6042  hold, we get a temporary chunk of working store to use during the matching.  hold, we get a temporary chunk of working store to use during the matching.
6043  Otherwise, we can use the vector supplied, rounding down its size to a multiple  Otherwise, we can use the vector supplied, rounding down its size to a multiple
# Line 5866  md->offset_max = (2*ocount)/3; Line 6060  md->offset_max = (2*ocount)/3;
6060  md->offset_overflow = FALSE;  md->offset_overflow = FALSE;
6061  md->capture_last = -1;  md->capture_last = -1;
6062    
 /* Compute the minimum number of offsets that we need to reset each time. Doing  
 this makes a huge difference to execution time when there aren't many brackets  
 in the pattern. */  
   
 resetcount = 2 + re->top_bracket * 2;  
 if (resetcount > offsetcount) resetcount = ocount;  
   
6063  /* Reset the working variable associated with each extraction. These should  /* Reset the working variable associated with each extraction. These should
6064  never be used unless previously set, but they get saved and restored, and so we  never be used unless previously set, but they get saved and restored, and so we
6065  initialize them to avoid reading uninitialized locations. */  initialize them to avoid reading uninitialized locations. Also, unset the
6066    offsets for the matched string. This is really just for tidiness with callouts,
6067    in case they inspect these fields. */
6068    
6069  if (md->offset_vector != NULL)  if (md->offset_vector != NULL)
6070    {    {
6071    register int *iptr = md->offset_vector + ocount;    register int *iptr = md->offset_vector + ocount;
6072    register int *iend = iptr - resetcount/2 + 1;    register int *iend = iptr - re->top_bracket;
6073      if (iend < md->offset_vector + 2) iend = md->offset_vector + 2;
6074    while (--iptr >= iend) *iptr = -1;    while (--iptr >= iend) *iptr = -1;
6075      md->offset_vector[0] = md->offset_vector[1] = -1;
6076    }    }
6077    
6078  /* Set up the first character to match, if available. The first_byte value is  /* Set up the first character to match, if available. The first_byte value is
# Line 5915  if ((re->flags & PCRE_REQCHSET) != 0) Line 6106  if ((re->flags & PCRE_REQCHSET) != 0)
6106    }    }
6107    
6108    
6109    
6110    
6111  /* ==========================================================================*/  /* ==========================================================================*/
6112    
6113  /* Loop for handling unanchored repeated matching attempts; for anchored regexs  /* Loop for handling unanchored repeated matching attempts; for anchored regexs
# Line 5925  for(;;) Line 6118  for(;;)
6118    USPTR save_end_subject = end_subject;    USPTR save_end_subject = end_subject;
6119    USPTR new_start_match;    USPTR new_start_match;
6120    
   /* Reset the maximum number of extractions we might see. */  
   
   if (md->offset_vector != NULL)  
     {  
     register int *iptr = md->offset_vector;  
     register int *iend = iptr + resetcount;  
     while (iptr < iend) *iptr++ = -1;  
     }  
   
6121    /* If firstline is TRUE, the start of the match is constrained to the first    /* If firstline is TRUE, the start of the match is constrained to the first
6122    line of a multiline string. That is, the match must be before or at the first    line of a multiline string. That is, the match must be before or at the first
6123    newline. Implement this by temporarily adjusting end_subject so that we stop    newline. Implement this by temporarily adjusting end_subject so that we stop
# Line 6122  for(;;) Line 6306  for(;;)
6306    md->start_match_ptr = start_match;    md->start_match_ptr = start_match;
6307    md->start_used_ptr = start_match;    md->start_used_ptr = start_match;
6308    md->match_call_count = 0;    md->match_call_count = 0;
6309    rc = match(start_match, md->start_code, start_match, NULL, 2, md, ims, NULL,    md->match_function_type = 0;
6310      0, 0);    md->end_offset_top = 0;
6311      rc = match(start_match, md->start_code, start_match, NULL, 2, md, NULL, 0);
6312    if (md->hitend && start_partial == NULL) start_partial = md->start_used_ptr;    if (md->hitend && start_partial == NULL) start_partial = md->start_used_ptr;
6313    
6314    switch(rc)    switch(rc)
# Line 6246  if (rc == MATCH_MATCH || rc == MATCH_ACC Line 6431  if (rc == MATCH_MATCH || rc == MATCH_ACC
6431    
6432    /* Set the return code to the number of captured strings, or 0 if there are    /* Set the return code to the number of captured strings, or 0 if there are
6433    too many to fit into the vector. */    too many to fit into the vector. */
6434    
6435    rc = md->offset_overflow? 0 : md->end_offset_top/2;    rc = md->offset_overflow? 0 : md->end_offset_top/2;
6436    
6437    /* If there is space, set up the whole thing as substring 0. The value of    /* If there is space, set up the whole thing as substring 0. The value of

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

  ViewVC Help
Powered by ViewVC 1.1.5