/[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 531 by ph10, Tue Jun 1 13:53:26 2010 UTC revision 613 by ph10, Sat Jul 2 16:59:52 2011 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2010 University of Cambridge             Copyright (c) 1997-2011 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 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 132  while (length-- > 0) Line 135  while (length-- > 0)
135  *          Match a back-reference                *  *          Match a back-reference                *
136  *************************************************/  *************************************************/
137    
138  /* If a back reference hasn't been set, the length that is passed is greater  /* Normally, if a back reference hasn't been set, the length that is passed is
139  than the number of characters left in the string, so the match fails.  negative, so the match always fails. However, in JavaScript compatibility mode,
140    the length passed is zero. Note that in caseless UTF-8 mode, the number of
141    subject bytes matched may be different to the number of reference bytes.
142    
143  Arguments:  Arguments:
144    offset      index into the offset vector    offset      index into the offset vector
145    eptr        points into the subject    eptr        pointer into the subject
146    length      length to be matched    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:      TRUE if matched  Returns:      < 0 if not matched, otherwise the number of subject bytes matched
151  */  */
152    
153  static BOOL  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 p = md->start_subject + md->offset_vector[offset];  USPTR eptr_start = eptr;
158    register USPTR p = md->start_subject + md->offset_vector[offset];
159    
160  #ifdef PCRE_DEBUG  #ifdef PCRE_DEBUG
161  if (eptr >= md->end_subject)  if (eptr >= md->end_subject)
# Line 164  pchars(p, length, FALSE, md); Line 170  pchars(p, length, FALSE, md);
170  printf("\n");  printf("\n");
171  #endif  #endif
172    
173  /* Always fail if not enough characters left */  /* Always fail if reference not set (and not JavaScript compatible). */
174    
175  if (length > md->end_subject - eptr) return FALSE;  if (length < 0) return -1;
176    
177  /* Separate the caseless case for speed. In UTF-8 mode we can only do this  /* Separate the caseless case for speed. In UTF-8 mode we can only do this
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
185    if (md->utf8)    if (md->utf8)
186      {      {
187      USPTR endptr = eptr + length;      /* Match characters up to the end of the reference. NOTE: the number of
188      while (eptr < endptr)      bytes matched may differ, because there are some characters whose upper and
189        lower case versions code as different numbers of bytes. For example, U+023A
190        (2 bytes in UTF-8) is the upper case version of U+2C65 (3 bytes in UTF-8);
191        a sequence of 3 of the former uses 6 bytes, as does a sequence of two of
192        the latter. It is important, therefore, to check the length along the
193        reference, not along the subject (earlier code did this wrong). */
194    
195        USPTR endptr = p + length;
196        while (p < endptr)
197        {        {
198        int c, d;        int c, d;
199          if (eptr >= md->end_subject) return -1;
200        GETCHARINC(c, eptr);        GETCHARINC(c, eptr);
201        GETCHARINC(d, p);        GETCHARINC(d, p);
202        if (c != d && c != UCD_OTHERCASE(d)) return FALSE;        if (c != d && c != UCD_OTHERCASE(d)) return -1;
203        }        }
204      }      }
205    else    else
# Line 193  if ((ims & PCRE_CASELESS) != 0) Line 208  if ((ims & PCRE_CASELESS) != 0)
208    
209    /* The same code works when not in UTF-8 mode and in UTF-8 mode when there    /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
210    is no UCP support. */    is no UCP support. */
211        {
212    while (length-- > 0)      if (eptr + length > md->end_subject) return -1;
213      { if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; }      while (length-- > 0)
214          { if (md->lcc[*p++] != md->lcc[*eptr++]) return -1; }
215        }
216    }    }
217    
218  /* In the caseful case, we can just compare the bytes, whether or not we  /* In the caseful case, we can just compare the bytes, whether or not we
219  are in UTF-8 mode. */  are in UTF-8 mode. */
220    
221  else  else
222    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }    {
223      if (eptr + length > md->end_subject) return -1;
224      while (length-- > 0) if (*p++ != *eptr++) return -1;
225      }
226    
227  return TRUE;  return eptr - eptr_start;
228  }  }
229    
230    
# Line 256  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 266  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 278  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 292  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 = (pcre_stack_malloc)(sizeof(heapframe));\    heapframe *newframe = (heapframe *)(pcre_stack_malloc)(sizeof(heapframe));\
318    if (heapframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\    if (newframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\
319    frame->Xwhere = rw; \    frame->Xwhere = rw; \
320    newframe->Xeptr = ra;\    newframe->Xeptr = ra;\
321    newframe->Xecode = rb;\    newframe->Xecode = rb;\
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 340  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 363  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 422  immediately. The second one is used when Line 436  immediately. The second one is used when
436  the subject. */  the subject. */
437    
438  #define CHECK_PARTIAL()\  #define CHECK_PARTIAL()\
439    if (md->partial != 0 && eptr >= md->end_subject && eptr > mstart)\    if (md->partial != 0 && eptr >= md->end_subject && \
440      {\        eptr > md->start_used_ptr) \
441      md->hitend = TRUE;\      { \
442      if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL);\      md->hitend = TRUE; \
443        if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL); \
444      }      }
445    
446  #define SCHECK_PARTIAL()\  #define SCHECK_PARTIAL()\
447    if (md->partial != 0 && eptr > mstart)\    if (md->partial != 0 && eptr > md->start_used_ptr) \
448      {\      { \
449      md->hitend = TRUE;\      md->hitend = TRUE; \
450      if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL);\      if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL); \
451      }      }
452    
453    
# Line 449  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 467  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 480  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 488  heap storage. Set up the top-level frame Line 499  heap storage. Set up the top-level frame
499  heap whenever RMATCH() does a "recursion". See the macro definitions above. */  heap whenever RMATCH() does a "recursion". See the macro definitions above. */
500    
501  #ifdef NO_RECURSE  #ifdef NO_RECURSE
502  heapframe *frame = (pcre_stack_malloc)(sizeof(heapframe));  heapframe *frame = (heapframe *)(pcre_stack_malloc)(sizeof(heapframe));
503  if (frame == NULL) RRETURN(PCRE_ERROR_NOMEMORY);  if (frame == NULL) RRETURN(PCRE_ERROR_NOMEMORY);
504  frame->Xprevframe = NULL;            /* Marks the top level */  frame->Xprevframe = NULL;            /* Marks the top level */
505    
# Line 499  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 515  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 539  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 577  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 622  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 658  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 682  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 710  for (;;) Line 733  for (;;)
733      case OP_FAIL:      case OP_FAIL:
734      MRRETURN(MATCH_NOMATCH);      MRRETURN(MATCH_NOMATCH);
735    
736        /* COMMIT overrides PRUNE, SKIP, and THEN */
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) RRETURN(rrc);      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE &&
742            rrc != MATCH_SKIP && rrc != MATCH_SKIP_ARG &&
743            rrc != MATCH_THEN)
744          RRETURN(rrc);
745      MRRETURN(MATCH_COMMIT);      MRRETURN(MATCH_COMMIT);
746    
747        /* PRUNE overrides THEN */
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) 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) 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);
761    
762        /* SKIP overrides PRUNE and THEN */
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) RRETURN(rrc);      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)
768          RRETURN(rrc);
769      md->start_match_ptr = eptr;   /* Pass back current position */      md->start_match_ptr = eptr;   /* Pass back current position */
770      MRRETURN(MATCH_SKIP);      MRRETURN(MATCH_SKIP);
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) RRETURN(rrc);      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)
776          RRETURN(rrc);
777    
778      /* Pass back the current skip name by overloading md->start_match_ptr and      /* Pass back the current skip name by overloading md->start_match_ptr and
779      returning the special MATCH_SKIP_ARG return code. This will either be      returning the special MATCH_SKIP_ARG return code. This will either be
# Line 749  for (;;) Line 783  for (;;)
783      md->start_match_ptr = ecode + 2;      md->start_match_ptr = ecode + 2;
784      RRETURN(MATCH_SKIP_ARG);      RRETURN(MATCH_SKIP_ARG);
785    
786        /* For THEN (and THEN_ARG) we pass back the address of the bracket or
787        the alt that is at the start of the current branch. This makes it possible
788        to skip back past alternatives that precede the THEN within the current
789        branch. */
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);
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], offset_top, md,      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1+LINK_SIZE],
800        ims, eptrb, flags, RM58);        offset_top, md, eptrb, RM58);
801      if (rrc != MATCH_NOMATCH) RRETURN(rrc);      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
802      md->mark = ecode + 2;      md->start_match_ptr = ecode - GET(ecode, 1);
803        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 780  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 799  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          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);            eptrb, RM1);
847            if (rrc != MATCH_NOMATCH &&
848                (rrc != MATCH_THEN || md->start_match_ptr != ecode))
849              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 816  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 831  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          if (flags == 0)    /* Not a possibly empty group */          RM2);
892            {        if (rrc != MATCH_NOMATCH &&
893            ecode += _pcre_OP_lengths[*ecode];            (rrc != MATCH_THEN || md->start_match_ptr != ecode))
894            DPRINTF(("bracket 0 tail recursion\n"));          RRETURN(rrc);
895            goto TAIL_RECURSE;        ecode += GET(ecode, 1);
896            }        if (*ecode != OP_ALT) break;
897          }
898    
899          /* Possibly empty group; can't use tail recursion. */      if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr;
900        RRETURN(MATCH_NOMATCH);
901    
902          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,      /* Handle possessive capturing brackets with an unlimited repeat. We come
903            eptrb, flags, RM48);      here from BRAZERO with allow_zero set TRUE. The offset_vector values are
904          if (rrc == MATCH_NOMATCH) md->mark = markptr;      handled similarly to the normal case above. However, the matching is
905          RRETURN(rrc);      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            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              offset_top = md->end_offset_top;
956              eptr = md->end_match_ptr;
957              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        /* For non-final alternatives, continue the loop for a NOMATCH result;        if (!matched_once)
971        otherwise return. */          {
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        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
991        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
992    
993        DPRINTF(("insufficient capture room: treat as non-capturing\n"));
994    
995        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
996          eptrb, flags, RM2);      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
997        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);  
998        /* Non-capturing possessive bracket with unlimited repeat. We come here
999        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 &&
1025              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1026            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 1053  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;
1232          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
1233          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
1234          }          }
1235        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)        else if (rrc != MATCH_NOMATCH &&
1236                  (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1237          {          {
1238          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
1239          }          }
# Line 1078  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 1127  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 1169  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 */
1364          break;          break;
1365          }          }
1366        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH &&
1367              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1368            RRETURN(rrc);
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 1218  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          {          {
1406          do ecode += GET(ecode,1); while (*ecode == OP_ALT);          do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1407          break;          break;
1408          }          }
1409        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH &&
1410              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1411            RRETURN(rrc);
1412        ecode += GET(ecode,1);        ecode += GET(ecode,1);
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 1347  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 1365  for (;;) Line 1546  for (;;)
1546              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1547            MRRETURN(MATCH_MATCH);            MRRETURN(MATCH_MATCH);
1548            }            }
1549          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)          else if (rrc != MATCH_NOMATCH &&
1550                    (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1551            {            {
1552            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1553            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
# Line 1402  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;
1591          break;          break;
1592          }          }
1593        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH &&
1594              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1595            RRETURN(rrc);
1596        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1597        }        }
1598      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 1439  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 1479  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 1547  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 1578  for (;;) Line 1758  for (;;)
1758            rec->saved_max * sizeof(int));            rec->saved_max * sizeof(int));
1759          offset_top = rec->save_offset_top;          offset_top = rec->save_offset_top;
1760          ecode = rec->after_call;          ecode = rec->after_call;
         ims = original_ims;  
1761          break;          break;
1762          }          }
1763        }        }
1764    
     /* 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));  
   
1765      /* For a non-repeating ket, just continue at this level. This also      /* For a non-repeating ket, just continue at this level. This also
1766      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.
1767      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 1600  for (;;) Line 1773  for (;;)
1773        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1774        break;        break;
1775        }        }
1776    
1777      /* The repeating kets try the rest of the pattern or restart from the      /* OP_KETRPOS is a possessive repeating ket. Remember the current position,
1778      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
1779      tail recursion to avoid using another stack frame, unless we have an      at a time from the outer level, thus saving stack. */
1780    
1781        if (*ecode == OP_KETRPOS)
1782          {
1783          md->end_match_ptr = eptr;
1784          md->end_offset_top = offset_top;
1785          RRETURN(MATCH_KETRPOS);
1786          }
1787    
1788        /* The normal repeating kets try the rest of the pattern or restart from
1789        the preceding bracket, in the appropriate order. In the second case, we can
1790        use tail recursion to avoid using another stack frame, unless we have an
1791      unlimited repeat of a group that can match an empty string. */      unlimited repeat of a group that can match an empty string. */
1792    
     flags = (*prev >= OP_SBRA)? match_cbegroup : 0;  
   
1793      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1794        {        {
1795        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM12);
1796        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1797        if (flags != 0)    /* Could match an empty string */        if (*prev >= OP_SBRA)    /* Could match an empty string */
1798          {          {
1799          RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);          md->match_function_type = MATCH_CBEGROUP;
1800            RMATCH(eptr, prev, offset_top, md, eptrb, RM50);
1801          RRETURN(rrc);          RRETURN(rrc);
1802          }          }
1803        ecode = prev;        ecode = prev;
# Line 1622  for (;;) Line 1805  for (;;)
1805        }        }
1806      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1807        {        {
1808        RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);        if (*prev >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
1809          RMATCH(eptr, prev, offset_top, md, eptrb, RM13);
1810        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1811        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
       flags = 0;  
1812        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1813        }        }
1814      /* Control never gets here */      /* Control never gets here */
1815    
1816      /* Start of subject unless notbol, or after internal newline if multiline */      /* Not multiline mode: start of subject assertion, unless notbol. */
1817    
1818      case OP_CIRC:      case OP_CIRC:
1819      if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH);      if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH);
1820      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 */  
   
1821      /* Start of subject assertion */      /* Start of subject assertion */
1822    
1823      case OP_SOD:      case OP_SOD:
1824      if (eptr != md->start_subject) MRRETURN(MATCH_NOMATCH);      if (eptr != md->start_subject) MRRETURN(MATCH_NOMATCH);
1825      ecode++;      ecode++;
1826      break;      break;
1827    
1828        /* Multiline mode: start of subject unless notbol, or after any newline. */
1829    
1830        case OP_CIRCM:
1831        if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH);
1832        if (eptr != md->start_subject &&
1833            (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
1834          MRRETURN(MATCH_NOMATCH);
1835        ecode++;
1836        break;
1837    
1838      /* Start of match assertion */      /* Start of match assertion */
1839    
# Line 1665  for (;;) Line 1849  for (;;)
1849      ecode++;      ecode++;
1850      break;      break;
1851    
1852      /* Assert before internal newline if multiline, or before a terminating      /* Multiline mode: assert before any newline, or before end of subject
1853      newline unless endonly is set, else end of subject unless noteol is set. */      unless noteol is set. */
1854    
1855      case OP_DOLL:      case OP_DOLLM:
1856      if ((ims & PCRE_MULTILINE) != 0)      if (eptr < md->end_subject)
1857        {        { if (!IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH); }
       if (eptr < md->end_subject)  
         { if (!IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH); }  
       else  
         { if (md->noteol) MRRETURN(MATCH_NOMATCH); }  
       ecode++;  
       break;  
       }  
1858      else      else
1859        {        {
1860        if (md->noteol) MRRETURN(MATCH_NOMATCH);        if (md->noteol) MRRETURN(MATCH_NOMATCH);
1861        if (!md->endonly)        SCHECK_PARTIAL();
         {  
         if (eptr != md->end_subject &&  
             (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))  
           MRRETURN(MATCH_NOMATCH);  
         ecode++;  
         break;  
         }  
1862        }        }
1863        ecode++;
1864        break;
1865    
1866        /* Not multiline mode: assert before a terminating newline or before end of
1867        subject unless noteol is set. */
1868    
1869        case OP_DOLL:
1870        if (md->noteol) MRRETURN(MATCH_NOMATCH);
1871        if (!md->endonly) goto ASSERT_NL_OR_EOS;
1872    
1873      /* ... else fall through for endonly */      /* ... else fall through for endonly */
1874    
1875      /* End of subject assertion (\z) */      /* End of subject assertion (\z) */
1876    
1877      case OP_EOD:      case OP_EOD:
1878      if (eptr < md->end_subject) MRRETURN(MATCH_NOMATCH);      if (eptr < md->end_subject) MRRETURN(MATCH_NOMATCH);
1879        SCHECK_PARTIAL();
1880      ecode++;      ecode++;
1881      break;      break;
1882    
1883      /* End of subject or ending \n assertion (\Z) */      /* End of subject or ending \n assertion (\Z) */
1884    
1885      case OP_EODN:      case OP_EODN:
1886      if (eptr != md->end_subject &&      ASSERT_NL_OR_EOS:
1887        if (eptr < md->end_subject &&
1888          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1889        MRRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1890    
1891        /* Either at end of string or \n before end. */
1892    
1893        SCHECK_PARTIAL();
1894      ecode++;      ecode++;
1895      break;      break;
1896    
# Line 1966  for (;;) Line 2152  for (;;)
2152      switch(c)      switch(c)
2153        {        {
2154        default: MRRETURN(MATCH_NOMATCH);        default: MRRETURN(MATCH_NOMATCH);
2155    
2156        case 0x000d:        case 0x000d:
2157        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
2158        break;        break;
# Line 2218  for (;;) Line 2405  for (;;)
2405      loops). */      loops). */
2406    
2407      case OP_REF:      case OP_REF:
2408        {      case OP_REFI:
2409        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */      caseless = op == OP_REFI;
2410        ecode += 3;      offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
2411        ecode += 3;
2412    
2413        /* If the reference is unset, there are two possibilities:      /* If the reference is unset, there are two possibilities:
2414    
2415        (a) In the default, Perl-compatible state, set the length to be longer      (a) In the default, Perl-compatible state, set the length negative;
2416        than the amount of subject left; this ensures that every attempt at a      this ensures that every attempt at a match fails. We can't just fail
2417        match fails. We can't just fail here, because of the possibility of      here, because of the possibility of quantifiers with zero minima.
       quantifiers with zero minima.  
2418    
2419        (b) If the JavaScript compatibility flag is set, set the length to zero      (b) If the JavaScript compatibility flag is set, set the length to zero
2420        so that the back reference matches an empty string.      so that the back reference matches an empty string.
2421    
2422        Otherwise, set the length to the length of what was matched by the      Otherwise, set the length to the length of what was matched by the
2423        referenced subpattern. */      referenced subpattern. */
2424    
2425        if (offset >= offset_top || md->offset_vector[offset] < 0)      if (offset >= offset_top || md->offset_vector[offset] < 0)
2426          length = (md->jscript_compat)? 0 : (int)(md->end_subject - eptr + 1);        length = (md->jscript_compat)? 0 : -1;
2427        else      else
2428          length = md->offset_vector[offset+1] - md->offset_vector[offset];        length = md->offset_vector[offset+1] - md->offset_vector[offset];
2429    
2430        /* Set up for repetition, or handle the non-repeated case */      /* Set up for repetition, or handle the non-repeated case */
2431    
2432        switch (*ecode)      switch (*ecode)
2433          {        {
2434          case OP_CRSTAR:        case OP_CRSTAR:
2435          case OP_CRMINSTAR:        case OP_CRMINSTAR:
2436          case OP_CRPLUS:        case OP_CRPLUS:
2437          case OP_CRMINPLUS:        case OP_CRMINPLUS:
2438          case OP_CRQUERY:        case OP_CRQUERY:
2439          case OP_CRMINQUERY:        case OP_CRMINQUERY:
2440          c = *ecode++ - OP_CRSTAR;        c = *ecode++ - OP_CRSTAR;
2441          minimize = (c & 1) != 0;        minimize = (c & 1) != 0;
2442          min = rep_min[c];                 /* Pick up values from tables; */        min = rep_min[c];                 /* Pick up values from tables; */
2443          max = rep_max[c];                 /* zero for max => infinity */        max = rep_max[c];                 /* zero for max => infinity */
2444          if (max == 0) max = INT_MAX;        if (max == 0) max = INT_MAX;
2445          break;        break;
2446    
2447          case OP_CRRANGE:        case OP_CRRANGE:
2448          case OP_CRMINRANGE:        case OP_CRMINRANGE:
2449          minimize = (*ecode == OP_CRMINRANGE);        minimize = (*ecode == OP_CRMINRANGE);
2450          min = GET2(ecode, 1);        min = GET2(ecode, 1);
2451          max = GET2(ecode, 3);        max = GET2(ecode, 3);
2452          if (max == 0) max = INT_MAX;        if (max == 0) max = INT_MAX;
2453          ecode += 5;        ecode += 5;
2454          break;        break;
2455    
2456          default:               /* No repeat follows */        default:               /* No repeat follows */
2457          if (!match_ref(offset, eptr, length, md, ims))        if ((length = match_ref(offset, eptr, length, md, caseless)) < 0)
2458            {          {
2459            CHECK_PARTIAL();          CHECK_PARTIAL();
2460            MRRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
           }  
         eptr += length;  
         continue;              /* With the main loop */  
2461          }          }
2462          eptr += length;
2463          continue;              /* With the main loop */
2464          }
2465    
2466        /* If the length of the reference is zero, just continue with the      /* Handle repeated back references. If the length of the reference is
2467        main loop. */      zero, just continue with the main loop. */
2468    
2469        if (length == 0) continue;      if (length == 0) continue;
2470    
2471        /* First, ensure the minimum number of matches are present. We get back      /* First, ensure the minimum number of matches are present. We get back
2472        the length of the reference string explicitly rather than passing the      the length of the reference string explicitly rather than passing the
2473        address of eptr, so that eptr can be a register variable. */      address of eptr, so that eptr can be a register variable. */
2474    
2475        for (i = 1; i <= min; i++)      for (i = 1; i <= min; i++)
2476          {
2477          int slength;
2478          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2479          {          {
2480          if (!match_ref(offset, eptr, length, md, ims))          CHECK_PARTIAL();
2481            {          MRRETURN(MATCH_NOMATCH);
           CHECK_PARTIAL();  
           MRRETURN(MATCH_NOMATCH);  
           }  
         eptr += length;  
2482          }          }
2483          eptr += slength;
2484          }
2485    
2486        /* If min = max, continue at the same level without recursion.      /* If min = max, continue at the same level without recursion.
2487        They are not both allowed to be zero. */      They are not both allowed to be zero. */
2488    
2489        if (min == max) continue;      if (min == max) continue;
2490    
2491        /* If minimizing, keep trying and advancing the pointer */      /* If minimizing, keep trying and advancing the pointer */
2492    
2493        if (minimize)      if (minimize)
2494          {
2495          for (fi = min;; fi++)
2496          {          {
2497          for (fi = min;; fi++)          int slength;
2498            RMATCH(eptr, ecode, offset_top, md, eptrb, RM14);
2499            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2500            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2501            if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2502            {            {
2503            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);            CHECK_PARTIAL();
2504            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            MRRETURN(MATCH_NOMATCH);
           if (fi >= max) MRRETURN(MATCH_NOMATCH);  
           if (!match_ref(offset, eptr, length, md, ims))  
             {  
             CHECK_PARTIAL();  
             MRRETURN(MATCH_NOMATCH);  
             }  
           eptr += length;  
2505            }            }
2506          /* Control never gets here */          eptr += slength;
2507          }          }
2508          /* Control never gets here */
2509          }
2510    
2511        /* If maximizing, find the longest string and work backwards */      /* If maximizing, find the longest string and work backwards */
2512    
2513        else      else
2514          {
2515          pp = eptr;
2516          for (i = min; i < max; i++)
2517          {          {
2518          pp = eptr;          int slength;
2519          for (i = min; i < max; i++)          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2520            {            {
2521            if (!match_ref(offset, eptr, length, md, ims))            CHECK_PARTIAL();
2522              {            break;
             CHECK_PARTIAL();  
             break;  
             }  
           eptr += length;  
           }  
         while (eptr >= pp)  
           {  
           RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);  
           if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
           eptr -= length;  
2523            }            }
2524          MRRETURN(MATCH_NOMATCH);          eptr += slength;
2525            }
2526          while (eptr >= pp)
2527            {
2528            RMATCH(eptr, ecode, offset_top, md, eptrb, RM15);
2529            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2530            eptr -= length;
2531          }          }
2532          MRRETURN(MATCH_NOMATCH);
2533        }        }
2534      /* Control never gets here */      /* Control never gets here */
2535    
# Line 2446  for (;;) Line 2635  for (;;)
2635            {            {
2636            for (fi = min;; fi++)            for (fi = min;; fi++)
2637              {              {
2638              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM16);
2639              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2640              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2641              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 2471  for (;;) Line 2660  for (;;)
2660            {            {
2661            for (fi = min;; fi++)            for (fi = min;; fi++)
2662              {              {
2663              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM17);
2664              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2665              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2666              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 2517  for (;;) Line 2706  for (;;)
2706              }              }
2707            for (;;)            for (;;)
2708              {              {
2709              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM18);
2710              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2711              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2712              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2540  for (;;) Line 2729  for (;;)
2729              }              }
2730            while (eptr >= pp)            while (eptr >= pp)
2731              {              {
2732              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM19);
2733              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2734              eptr--;              eptr--;
2735              }              }
# Line 2616  for (;;) Line 2805  for (;;)
2805          {          {
2806          for (fi = min;; fi++)          for (fi = min;; fi++)
2807            {            {
2808            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM20);
2809            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2810            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2811            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
# Line 2649  for (;;) Line 2838  for (;;)
2838            }            }
2839          for(;;)          for(;;)
2840            {            {
2841            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM21);
2842            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2843            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2844            if (utf8) BACKCHAR(eptr);            if (utf8) BACKCHAR(eptr);
# Line 2694  for (;;) Line 2883  for (;;)
2883    
2884      /* Match a single character, caselessly */      /* Match a single character, caselessly */
2885    
2886      case OP_CHARNC:      case OP_CHARI:
2887  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2888      if (utf8)      if (utf8)
2889        {        {
# Line 2754  for (;;) Line 2943  for (;;)
2943      /* Match a single character repeatedly. */      /* Match a single character repeatedly. */
2944    
2945      case OP_EXACT:      case OP_EXACT:
2946        case OP_EXACTI:
2947      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
2948      ecode += 3;      ecode += 3;
2949      goto REPEATCHAR;      goto REPEATCHAR;
2950    
2951      case OP_POSUPTO:      case OP_POSUPTO:
2952        case OP_POSUPTOI:
2953      possessive = TRUE;      possessive = TRUE;
2954      /* Fall through */      /* Fall through */
2955    
2956      case OP_UPTO:      case OP_UPTO:
2957        case OP_UPTOI:
2958      case OP_MINUPTO:      case OP_MINUPTO:
2959        case OP_MINUPTOI:
2960      min = 0;      min = 0;
2961      max = GET2(ecode, 1);      max = GET2(ecode, 1);
2962      minimize = *ecode == OP_MINUPTO;      minimize = *ecode == OP_MINUPTO || *ecode == OP_MINUPTOI;
2963      ecode += 3;      ecode += 3;
2964      goto REPEATCHAR;      goto REPEATCHAR;
2965    
2966      case OP_POSSTAR:      case OP_POSSTAR:
2967        case OP_POSSTARI:
2968      possessive = TRUE;      possessive = TRUE;
2969      min = 0;      min = 0;
2970      max = INT_MAX;      max = INT_MAX;
# Line 2778  for (;;) Line 2972  for (;;)
2972      goto REPEATCHAR;      goto REPEATCHAR;
2973    
2974      case OP_POSPLUS:      case OP_POSPLUS:
2975        case OP_POSPLUSI:
2976      possessive = TRUE;      possessive = TRUE;
2977      min = 1;      min = 1;
2978      max = INT_MAX;      max = INT_MAX;
# Line 2785  for (;;) Line 2980  for (;;)
2980      goto REPEATCHAR;      goto REPEATCHAR;
2981    
2982      case OP_POSQUERY:      case OP_POSQUERY:
2983        case OP_POSQUERYI:
2984      possessive = TRUE;      possessive = TRUE;
2985      min = 0;      min = 0;
2986      max = 1;      max = 1;
# Line 2792  for (;;) Line 2988  for (;;)
2988      goto REPEATCHAR;      goto REPEATCHAR;
2989    
2990      case OP_STAR:      case OP_STAR:
2991        case OP_STARI:
2992      case OP_MINSTAR:      case OP_MINSTAR:
2993        case OP_MINSTARI:
2994      case OP_PLUS:      case OP_PLUS:
2995        case OP_PLUSI:
2996      case OP_MINPLUS:      case OP_MINPLUS:
2997        case OP_MINPLUSI:
2998      case OP_QUERY:      case OP_QUERY:
2999        case OP_QUERYI:
3000      case OP_MINQUERY:      case OP_MINQUERY:
3001      c = *ecode++ - OP_STAR;      case OP_MINQUERYI:
3002        c = *ecode++ - ((op < OP_STARI)? OP_STAR : OP_STARI);
3003      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
   
3004      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
3005      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
3006      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
# Line 2822  for (;;) Line 3023  for (;;)
3023          {          {
3024  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3025          unsigned int othercase;          unsigned int othercase;
3026          if ((ims & PCRE_CASELESS) != 0 &&          if (op >= OP_STARI &&     /* Caseless */
3027              (othercase = UCD_OTHERCASE(fc)) != fc)              (othercase = UCD_OTHERCASE(fc)) != fc)
3028            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
3029          else oclength = 0;          else oclength = 0;
# Line 2850  for (;;) Line 3051  for (;;)
3051            {            {
3052            for (fi = min;; fi++)            for (fi = min;; fi++)
3053              {              {
3054              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM22);
3055              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3056              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3057              if (eptr <= md->end_subject - length &&              if (eptr <= md->end_subject - length &&
# Line 2892  for (;;) Line 3093  for (;;)
3093    
3094            for(;;)            for(;;)
3095              {              {
3096              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM23);
3097              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3098              if (eptr == pp) { MRRETURN(MATCH_NOMATCH); }              if (eptr == pp) { MRRETURN(MATCH_NOMATCH); }
3099  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2929  for (;;) Line 3130  for (;;)
3130      DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc, min, max,      DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc, min, max,
3131        max, eptr));        max, eptr));
3132    
3133      if ((ims & PCRE_CASELESS) != 0)      if (op >= OP_STARI)  /* Caseless */
3134        {        {
3135        fc = md->lcc[fc];        fc = md->lcc[fc];
3136        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
# Line 2946  for (;;) Line 3147  for (;;)
3147          {          {
3148          for (fi = min;; fi++)          for (fi = min;; fi++)
3149            {            {
3150            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM24);
3151            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3152            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
3153            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
# Line 2976  for (;;) Line 3177  for (;;)
3177    
3178          while (eptr >= pp)          while (eptr >= pp)
3179            {            {
3180            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM25);
3181            eptr--;            eptr--;
3182            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3183            }            }
# Line 3005  for (;;) Line 3206  for (;;)
3206          {          {
3207          for (fi = min;; fi++)          for (fi = min;; fi++)
3208            {            {
3209            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM26);
3210            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3211            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
3212            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
# Line 3034  for (;;) Line 3235  for (;;)
3235    
3236          while (eptr >= pp)          while (eptr >= pp)
3237            {            {
3238            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM27);
3239            eptr--;            eptr--;
3240            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3241            }            }
# Line 3047  for (;;) Line 3248  for (;;)
3248      checking can be multibyte. */      checking can be multibyte. */
3249    
3250      case OP_NOT:      case OP_NOT:
3251        case OP_NOTI:
3252      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
3253        {        {
3254        SCHECK_PARTIAL();        SCHECK_PARTIAL();
# Line 3054  for (;;) Line 3256  for (;;)
3256        }        }
3257      ecode++;      ecode++;
3258      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
3259      if ((ims & PCRE_CASELESS) != 0)      if (op == OP_NOTI)         /* The caseless case */
3260        {        {
3261  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
3262        if (c < 256)        if (c < 256)
# Line 3062  for (;;) Line 3264  for (;;)
3264        c = md->lcc[c];        c = md->lcc[c];
3265        if (md->lcc[*ecode++] == c) MRRETURN(MATCH_NOMATCH);        if (md->lcc[*ecode++] == c) MRRETURN(MATCH_NOMATCH);
3266        }        }
3267      else      else    /* Caseful */
3268        {        {
3269        if (*ecode++ == c) MRRETURN(MATCH_NOMATCH);        if (*ecode++ == c) MRRETURN(MATCH_NOMATCH);
3270        }        }
# Line 3076  for (;;) Line 3278  for (;;)
3278      about... */      about... */
3279    
3280      case OP_NOTEXACT:      case OP_NOTEXACT:
3281        case OP_NOTEXACTI:
3282      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
3283      ecode += 3;      ecode += 3;
3284      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3285    
3286      case OP_NOTUPTO:      case OP_NOTUPTO:
3287        case OP_NOTUPTOI:
3288      case OP_NOTMINUPTO:      case OP_NOTMINUPTO:
3289        case OP_NOTMINUPTOI:
3290      min = 0;      min = 0;
3291      max = GET2(ecode, 1);      max = GET2(ecode, 1);
3292      minimize = *ecode == OP_NOTMINUPTO;      minimize = *ecode == OP_NOTMINUPTO || *ecode == OP_NOTMINUPTOI;
3293      ecode += 3;      ecode += 3;
3294      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3295    
3296      case OP_NOTPOSSTAR:      case OP_NOTPOSSTAR:
3297        case OP_NOTPOSSTARI:
3298      possessive = TRUE;      possessive = TRUE;
3299      min = 0;      min = 0;
3300      max = INT_MAX;      max = INT_MAX;
# Line 3096  for (;;) Line 3302  for (;;)
3302      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3303    
3304      case OP_NOTPOSPLUS:      case OP_NOTPOSPLUS:
3305        case OP_NOTPOSPLUSI:
3306      possessive = TRUE;      possessive = TRUE;
3307      min = 1;      min = 1;
3308      max = INT_MAX;      max = INT_MAX;
# Line 3103  for (;;) Line 3310  for (;;)
3310      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3311    
3312      case OP_NOTPOSQUERY:      case OP_NOTPOSQUERY:
3313        case OP_NOTPOSQUERYI:
3314      possessive = TRUE;      possessive = TRUE;
3315      min = 0;      min = 0;
3316      max = 1;      max = 1;
# Line 3110  for (;;) Line 3318  for (;;)
3318      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3319    
3320      case OP_NOTPOSUPTO:      case OP_NOTPOSUPTO:
3321        case OP_NOTPOSUPTOI:
3322      possessive = TRUE;      possessive = TRUE;
3323      min = 0;      min = 0;
3324      max = GET2(ecode, 1);      max = GET2(ecode, 1);
# Line 3117  for (;;) Line 3326  for (;;)
3326      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3327    
3328      case OP_NOTSTAR:      case OP_NOTSTAR:
3329        case OP_NOTSTARI:
3330      case OP_NOTMINSTAR:      case OP_NOTMINSTAR:
3331        case OP_NOTMINSTARI:
3332      case OP_NOTPLUS:      case OP_NOTPLUS:
3333        case OP_NOTPLUSI:
3334      case OP_NOTMINPLUS:      case OP_NOTMINPLUS:
3335        case OP_NOTMINPLUSI:
3336      case OP_NOTQUERY:      case OP_NOTQUERY:
3337        case OP_NOTQUERYI:
3338      case OP_NOTMINQUERY:      case OP_NOTMINQUERY:
3339      c = *ecode++ - OP_NOTSTAR;      case OP_NOTMINQUERYI:
3340        c = *ecode++ - ((op >= OP_NOTSTARI)? OP_NOTSTARI: OP_NOTSTAR);
3341      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
3342      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
3343      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
# Line 3144  for (;;) Line 3359  for (;;)
3359      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,
3360        max, eptr));        max, eptr));
3361    
3362      if ((ims & PCRE_CASELESS) != 0)      if (op >= OP_NOTSTARI)     /* Caseless */
3363        {        {
3364        fc = md->lcc[fc];        fc = md->lcc[fc];
3365    
# Line 3192  for (;;) Line 3407  for (;;)
3407            register unsigned int d;            register unsigned int d;
3408            for (fi = min;; fi++)            for (fi = min;; fi++)
3409              {              {
3410              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM28);
3411              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3412              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3413              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 3211  for (;;) Line 3426  for (;;)
3426            {            {
3427            for (fi = min;; fi++)            for (fi = min;; fi++)
3428              {              {
3429              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM29);
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 3252  for (;;) Line 3467  for (;;)
3467          if (possessive) continue;          if (possessive) continue;
3468          for(;;)          for(;;)
3469              {              {
3470              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM30);
3471              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3472              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3473              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 3275  for (;;) Line 3490  for (;;)
3490            if (possessive) continue;            if (possessive) continue;
3491            while (eptr >= pp)            while (eptr >= pp)
3492              {              {
3493              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM31);
3494              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3495              eptr--;              eptr--;
3496              }              }
# Line 3332  for (;;) Line 3547  for (;;)
3547            register unsigned int d;            register unsigned int d;
3548            for (fi = min;; fi++)            for (fi = min;; fi++)
3549              {              {
3550              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM32);
3551              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3552              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3553              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 3350  for (;;) Line 3565  for (;;)
3565            {            {
3566            for (fi = min;; fi++)            for (fi = min;; fi++)
3567              {              {
3568              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM33);
3569              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3570              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3571              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 3390  for (;;) Line 3605  for (;;)
3605            if (possessive) continue;            if (possessive) continue;
3606            for(;;)            for(;;)
3607              {              {
3608              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM34);
3609              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3610              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3611              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 3413  for (;;) Line 3628  for (;;)
3628            if (possessive) continue;            if (possessive) continue;
3629            while (eptr >= pp)            while (eptr >= pp)
3630              {              {
3631              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM35);
3632              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3633              eptr--;              eptr--;
3634              }              }
# Line 3740  for (;;) Line 3955  for (;;)
3955            switch(c)            switch(c)
3956              {              {
3957              default: MRRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
3958    
3959              case 0x000d:              case 0x000d:
3960              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3961              break;              break;
# Line 4016  for (;;) Line 4232  for (;;)
4232            switch(*eptr++)            switch(*eptr++)
4233              {              {
4234              default: MRRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
4235    
4236              case 0x000d:              case 0x000d:
4237              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
4238              break;              break;
4239    
4240              case 0x000a:              case 0x000a:
4241              break;              break;
4242    
# Line 4208  for (;;) Line 4426  for (;;)
4426            case PT_ANY:            case PT_ANY:
4427            for (fi = min;; fi++)            for (fi = min;; fi++)
4428              {              {
4429              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM36);
4430              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4431              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4432              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4224  for (;;) Line 4442  for (;;)
4442            case PT_LAMP:            case PT_LAMP:
4443            for (fi = min;; fi++)            for (fi = min;; fi++)
4444              {              {
4445              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM37);
4446              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4447              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4448              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4244  for (;;) Line 4462  for (;;)
4462            case PT_GC:            case PT_GC:
4463            for (fi = min;; fi++)            for (fi = min;; fi++)
4464              {              {
4465              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM38);
4466              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4467              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4468              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4262  for (;;) Line 4480  for (;;)
4480            case PT_PC:            case PT_PC:
4481            for (fi = min;; fi++)            for (fi = min;; fi++)
4482              {              {
4483              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM39);
4484              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4485              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4486              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4280  for (;;) Line 4498  for (;;)
4498            case PT_SC:            case PT_SC:
4499            for (fi = min;; fi++)            for (fi = min;; fi++)
4500              {              {
4501              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM40);
4502              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4503              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4504              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4298  for (;;) Line 4516  for (;;)
4516            case PT_ALNUM:            case PT_ALNUM:
4517            for (fi = min;; fi++)            for (fi = min;; fi++)
4518              {              {
4519              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM59);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM59);
4520              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4521              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4522              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4317  for (;;) Line 4535  for (;;)
4535            case PT_SPACE:    /* Perl space */            case PT_SPACE:    /* Perl space */
4536            for (fi = min;; fi++)            for (fi = min;; fi++)
4537              {              {
4538              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM60);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM60);
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 4337  for (;;) Line 4555  for (;;)
4555            case PT_PXSPACE:  /* POSIX space */            case PT_PXSPACE:  /* POSIX space */
4556            for (fi = min;; fi++)            for (fi = min;; fi++)
4557              {              {
4558              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM61);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM61);
4559              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4560              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4561              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4357  for (;;) Line 4575  for (;;)
4575            case PT_WORD:            case PT_WORD:
4576            for (fi = min;; fi++)            for (fi = min;; fi++)
4577              {              {
4578              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM62);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM62);
4579              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4580              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4581              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4389  for (;;) Line 4607  for (;;)
4607          {          {
4608          for (fi = min;; fi++)          for (fi = min;; fi++)
4609            {            {
4610            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM41);
4611            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4612            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
4613            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
# Line 4421  for (;;) Line 4639  for (;;)
4639          {          {
4640          for (fi = min;; fi++)          for (fi = min;; fi++)
4641            {            {
4642            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM42);
4643            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4644            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
4645            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
# Line 4584  for (;;) Line 4802  for (;;)
4802          {          {
4803          for (fi = min;; fi++)          for (fi = min;; fi++)
4804            {            {
4805            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM43);
4806            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4807            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
4808            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
# Line 4882  for (;;) Line 5100  for (;;)
5100          if (possessive) continue;          if (possessive) continue;
5101          for(;;)          for(;;)
5102            {            {
5103            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM44);
5104            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5105            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
5106            if (utf8) BACKCHAR(eptr);            if (utf8) BACKCHAR(eptr);
# Line 4923  for (;;) Line 5141  for (;;)
5141    
5142          for(;;)          for(;;)
5143            {            {
5144            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM45);
5145            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5146            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
5147            for (;;)                        /* Move back over one extended */            for (;;)                        /* Move back over one extended */
# Line 5207  for (;;) Line 5425  for (;;)
5425            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
5426            }            }
5427    
5428          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run. If possessive, we are
5429            done (no backing up). Otherwise, match at this position; anything other
5430            than no match is immediately returned. For nomatch, back up one
5431            character, unless we are matching \R and the last thing matched was
5432            \r\n, in which case, back up two bytes. */
5433    
5434          if (possessive) continue;          if (possessive) continue;
5435          for(;;)          for(;;)
5436            {            {
5437            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM46);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM46);
5438            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5439            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
5440            BACKCHAR(eptr);            BACKCHAR(eptr);
5441              if (ctype == OP_ANYNL && eptr > pp  && *eptr == '\n' &&
5442                  eptr[-1] == '\r') eptr--;
5443            }            }
5444          }          }
5445        else        else
# Line 5414  for (;;) Line 5638  for (;;)
5638            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
5639            }            }
5640    
5641          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run. If possessive, we are
5642            done (no backing up). Otherwise, match at this position; anything other
5643            than no match is immediately returned. For nomatch, back up one
5644            character (byte), unless we are matching \R and the last thing matched
5645            was \r\n, in which case, back up two bytes. */
5646    
5647          if (possessive) continue;          if (possessive) continue;
5648          while (eptr >= pp)          while (eptr >= pp)
5649            {            {
5650            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM47);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM47);
           eptr--;  
5651            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5652              eptr--;
5653              if (ctype == OP_ANYNL && eptr > pp  && *eptr == '\n' &&
5654                  eptr[-1] == '\r') eptr--;
5655            }            }
5656          }          }
5657    
# Line 5460  switch (frame->Xwhere) Line 5690  switch (frame->Xwhere)
5690    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)
5691    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)
5692    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)
5693    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)
5694  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
5695    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)
5696    LBL(32) LBL(34) LBL(42) LBL(46)    LBL(32) LBL(34) LBL(42) LBL(46)
# Line 5489  Undefine all the macros that were define Line 5719  Undefine all the macros that were define
5719  #undef ecode  #undef ecode
5720  #undef mstart  #undef mstart
5721  #undef offset_top  #undef offset_top
 #undef ims  
5722  #undef eptrb  #undef eptrb
5723  #undef flags  #undef flags
5724    
# Line 5507  Undefine all the macros that were define Line 5736  Undefine all the macros that were define
5736  #undef condition  #undef condition
5737  #undef prev_is_word  #undef prev_is_word
5738    
 #undef original_ims  
   
5739  #undef ctype  #undef ctype
5740  #undef length  #undef length
5741  #undef max  #undef max
# Line 5570  int first_byte = -1; Line 5797  int first_byte = -1;
5797  int req_byte = -1;  int req_byte = -1;
5798  int req_byte2 = -1;  int req_byte2 = -1;
5799  int newline;  int newline;
 unsigned long int ims;  
5800  BOOL using_temporary_offsets = FALSE;  BOOL using_temporary_offsets = FALSE;
5801  BOOL anchored;  BOOL anchored;
5802  BOOL startline;  BOOL startline;
# Line 5600  if ((options & ~PUBLIC_EXEC_OPTIONS) != Line 5826  if ((options & ~PUBLIC_EXEC_OPTIONS) !=
5826  if (re == NULL || subject == NULL ||  if (re == NULL || subject == NULL ||
5827     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;
5828  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
5829    if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET;
5830    
5831  /* This information is for finding all the numbers associated with a given  /* This information is for finding all the numbers associated with a given
5832  name, for condition testing. */  name, for condition testing. */
# Line 5673  utf8 = md->utf8 = (re->options & PCRE_UT Line 5900  utf8 = md->utf8 = (re->options & PCRE_UT
5900  md->use_ucp = (re->options & PCRE_UCP) != 0;  md->use_ucp = (re->options & PCRE_UCP) != 0;
5901  md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;  md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
5902    
5903    /* Some options are unpacked into BOOL variables in the hope that testing
5904    them will be faster than individual option bits. */
5905    
5906  md->notbol = (options & PCRE_NOTBOL) != 0;  md->notbol = (options & PCRE_NOTBOL) != 0;
5907  md->noteol = (options & PCRE_NOTEOL) != 0;  md->noteol = (options & PCRE_NOTEOL) != 0;
5908  md->notempty = (options & PCRE_NOTEMPTY) != 0;  md->notempty = (options & PCRE_NOTEMPTY) != 0;
5909  md->notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;  md->notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;
5910  md->partial = ((options & PCRE_PARTIAL_HARD) != 0)? 2 :  md->partial = ((options & PCRE_PARTIAL_HARD) != 0)? 2 :
5911                ((options & PCRE_PARTIAL_SOFT) != 0)? 1 : 0;                ((options & PCRE_PARTIAL_SOFT) != 0)? 1 : 0;
5912    
5913    
5914  md->hitend = FALSE;  md->hitend = FALSE;
5915  md->mark = NULL;                        /* In case never set */  md->mark = NULL;                        /* In case never set */
5916    
# Line 5760  defined (though never set). So there's n Line 5992  defined (though never set). So there's n
5992  if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)  if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
5993    return PCRE_ERROR_BADPARTIAL;    return PCRE_ERROR_BADPARTIAL;
5994    
5995  /* Check a UTF-8 string if required. Unfortunately there's no way of passing  /* Check a UTF-8 string if required. Pass back the character offset and error
5996  back the character offset. */  code for an invalid string if a results vector is available. */
5997    
5998  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
5999  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
6000    {    {
6001    if (_pcre_valid_utf8((USPTR)subject, length) >= 0)    int erroroffset;
6002      return PCRE_ERROR_BADUTF8;    int errorcode = _pcre_valid_utf8((USPTR)subject, length, &erroroffset);
6003    if (start_offset > 0 && start_offset < length)    if (errorcode != 0)
6004      {      {
6005      int tb = ((USPTR)subject)[start_offset];      if (offsetcount >= 2)
     if (tb > 127)  
6006        {        {
6007        tb &= 0xc0;        offsets[0] = erroroffset;
6008        if (tb != 0 && tb != 0xc0) return PCRE_ERROR_BADUTF8_OFFSET;        offsets[1] = errorcode;
6009        }        }
6010      }      return (errorcode <= PCRE_UTF8_ERR5 && md->partial > 1)?
6011          PCRE_ERROR_SHORTUTF8 : PCRE_ERROR_BADUTF8;
6012        }
6013    
6014      /* Check that a start_offset points to the start of a UTF-8 character. */
6015    
6016      if (start_offset > 0 && start_offset < length &&
6017          (((USPTR)subject)[start_offset] & 0xc0) == 0x80)
6018        return PCRE_ERROR_BADUTF8_OFFSET;
6019    }    }
6020  #endif  #endif
6021    
 /* 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);  
   
6022  /* 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
6023  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.
6024  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 5903  for(;;) Line 6136  for(;;)
6136    /* There are some optimizations that avoid running the match if a known    /* There are some optimizations that avoid running the match if a known
6137    starting point is not found, or if a known later character is not present.    starting point is not found, or if a known later character is not present.
6138    However, there is an option that disables these, for testing and for ensuring    However, there is an option that disables these, for testing and for ensuring
6139    that all callouts do actually occur. */    that all callouts do actually occur. The option can be set in the regex by
6140      (*NO_START_OPT) or passed in match-time options. */
6141    
6142    if ((options & PCRE_NO_START_OPTIMIZE) == 0)    if (((options | re->options) & PCRE_NO_START_OPTIMIZE) == 0)
6143      {      {
6144      /* Advance to a unique first byte if there is one. */      /* Advance to a unique first byte if there is one. */
6145    
# Line 5959  for(;;) Line 6193  for(;;)
6193        while (start_match < end_subject)        while (start_match < end_subject)
6194          {          {
6195          register unsigned int c = *start_match;          register unsigned int c = *start_match;
6196          if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++;          if ((start_bits[c/8] & (1 << (c&7))) == 0)
6197            else break;            {
6198              start_match++;
6199    #ifdef SUPPORT_UTF8
6200              if (utf8)
6201                while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
6202                  start_match++;
6203    #endif
6204              }
6205            else break;
6206          }          }
6207        }        }
6208      }   /* Starting optimizations */      }   /* Starting optimizations */
# Line 6055  for(;;) Line 6297  for(;;)
6297    md->start_match_ptr = start_match;    md->start_match_ptr = start_match;
6298    md->start_used_ptr = start_match;    md->start_used_ptr = start_match;
6299    md->match_call_count = 0;    md->match_call_count = 0;
6300    rc = match(start_match, md->start_code, start_match, NULL, 2, md, ims, NULL,    md->match_function_type = 0;
6301      0, 0);    rc = match(start_match, md->start_code, start_match, NULL, 2, md, NULL, 0);
6302    if (md->hitend && start_partial == NULL) start_partial = md->start_used_ptr;    if (md->hitend && start_partial == NULL) start_partial = md->start_used_ptr;
6303    
6304    switch(rc)    switch(rc)
6305      {      {
6306      /* NOMATCH and PRUNE advance by one character. If MATCH_SKIP_ARG reaches      /* SKIP passes back the next starting point explicitly, but if it is the
6307      this level it means that a MARK that matched the SKIP's arg was not found.      same as the match we have just done, treat it as NOMATCH. */
6308      We treat this as NOMATCH. THEN at this level acts exactly like PRUNE. */  
6309        case MATCH_SKIP:
6310        if (md->start_match_ptr != start_match)
6311          {
6312          new_start_match = md->start_match_ptr;
6313          break;
6314          }
6315        /* Fall through */
6316    
6317        /* If MATCH_SKIP_ARG reaches this level it means that a MARK that matched
6318        the SKIP's arg was not found. We also treat this as NOMATCH. */
6319    
6320        case MATCH_SKIP_ARG:
6321        /* Fall through */
6322    
6323        /* NOMATCH and PRUNE advance by one character. THEN at this level acts
6324        exactly like PRUNE. */
6325    
6326      case MATCH_NOMATCH:      case MATCH_NOMATCH:
6327      case MATCH_PRUNE:      case MATCH_PRUNE:
     case MATCH_SKIP_ARG:  
6328      case MATCH_THEN:      case MATCH_THEN:
6329      new_start_match = start_match + 1;      new_start_match = start_match + 1;
6330  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 6077  for(;;) Line 6334  for(;;)
6334  #endif  #endif
6335      break;      break;
6336    
     /* SKIP passes back the next starting point explicitly. */  
   
     case MATCH_SKIP:  
     new_start_match = md->start_match_ptr;  
     break;  
   
6337      /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */      /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */
6338    
6339      case MATCH_COMMIT:      case MATCH_COMMIT:
# Line 6170  if (rc == MATCH_MATCH || rc == MATCH_ACC Line 6421  if (rc == MATCH_MATCH || rc == MATCH_ACC
6421    
6422    /* 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
6423    too many to fit into the vector. */    too many to fit into the vector. */
6424    
6425    rc = md->offset_overflow? 0 : md->end_offset_top/2;    rc = md->offset_overflow? 0 : md->end_offset_top/2;
6426    
6427    /* 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.531  
changed lines
  Added in v.613

  ViewVC Help
Powered by ViewVC 1.1.5