/[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 511 by ph10, Mon Mar 29 09:25:38 2010 UTC revision 610 by ph10, Tue Jun 28 15:58:34 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 255  enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM Line 275  enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM
275         RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,         RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,
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 };         RM51,  RM52, RM53, RM54, RM55, RM56, RM57, RM58, RM59, RM60,
279           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 265  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 277  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 291  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 (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 314  argument of match(), which never changes Line 334  argument of match(), which never changes
334    
335  #define RRETURN(ra)\  #define RRETURN(ra)\
336    {\    {\
337    heapframe *newframe = frame;\    heapframe *oldframe = frame;\
338    frame = newframe->Xprevframe;\    frame = oldframe->Xprevframe;\
339    (pcre_stack_free)(newframe);\    (pcre_stack_free)(oldframe);\
340    if (frame != NULL)\    if (frame != NULL)\
341      {\      {\
342      rrc = ra;\      rrc = ra;\
# Line 338  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 361  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 420  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 447  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 465  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 478  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 486  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);
504  frame->Xprevframe = NULL;            /* Marks the top level */  frame->Xprevframe = NULL;            /* Marks the top level */
505    
506  /* Copy in the original argument variables */  /* Copy in the original argument variables */
# Line 496  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 512  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 536  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 574  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 619  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 655  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 679  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, RM51);        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
718      argument. It is passed back in md->start_match_ptr (an overloading of that      argument. It is passed back in md->start_match_ptr (an overloading of that
719      variable). If it does match, we reset that variable to the current subject      variable). If it does match, we reset that variable to the current subject
720      position and return MATCH_SKIP. Otherwise, pass back the return code      position and return MATCH_SKIP. Otherwise, pass back the return code
721      unaltered. */      unaltered. */
722    
723      if (rrc == MATCH_SKIP_ARG &&      if (rrc == MATCH_SKIP_ARG &&
724          strcmp((char *)markptr, (char *)(md->start_match_ptr)) == 0)          strcmp((char *)markptr, (char *)(md->start_match_ptr)) == 0)
725        {        {
726        md->start_match_ptr = eptr;        md->start_match_ptr = eptr;
727        RRETURN(MATCH_SKIP);        RRETURN(MATCH_SKIP);
728        }        }
729    
730      if (md->mark == NULL) md->mark = markptr;      if (md->mark == NULL) md->mark = markptr;
731      RRETURN(rrc);      RRETURN(rrc);
732    
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, RM51);        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, RM53);        eptrb, RM57);
775      if (rrc != MATCH_NOMATCH) RRETURN(rrc);      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)
776          RRETURN(rrc);
777      /* Pass back the current skip name by overloading md->start_match_ptr and  
778      returning the special MATCH_SKIP_ARG return code. This will either be      /* Pass back the current skip name by overloading md->start_match_ptr and
779      caught by a matching MARK, or get to the top, where it is treated the same      returning the special MATCH_SKIP_ARG return code. This will either be
780        caught by a matching MARK, or get to the top, where it is treated the same
781      as PRUNE. */      as PRUNE. */
782    
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, RM54);        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 777  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 793  for (;;) Line 836  for (;;)
836        save_capture_last = md->capture_last;        save_capture_last = md->capture_last;
837    
838        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
839        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;        md->offset_vector[md->offset_end - number] =
840            (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 812  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 827  for (;;) Line 873  for (;;)
873      /* VVVVVVVVVVVVVVVVVVVVVVVVV */      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
874      /* VVVVVVVVVVVVVVVVVVVVVVVVV */      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
875    
876      /* Non-capturing bracket. Loop for all the alternatives. When we get to the      /* Non-capturing bracket, except for possessive with unlimited repeat. Loop
877      final alternative within the brackets, we would return the result of a      for all the alternatives. When we get to the final alternative within the
878      recursive call to match() whatever happened. We can reduce stack usage by      brackets, we used to return the result of a recursive call to match()
879      turning this into a tail recursion, except in the case when match_cbegroup      whatever happened so it was possible to reduce stack usage by turning this
880      is set.*/      into a tail recursion, except in the case of a possibly empty group.
881        However, now that there is the possiblity of (*THEN) occurring in the final
882        alternative, this optimization is no longer possible. */
883    
884      case OP_BRA:      case OP_BRA:
885      case OP_SBRA:      case OP_SBRA:
886      DPRINTF(("start non-capturing bracket\n"));      DPRINTF(("start non-capturing bracket\n"));
     flags = (op >= OP_SBRA)? match_cbegroup : 0;  
887      for (;;)      for (;;)
888        {        {
889        if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */        if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
890          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, eptrb,
891            RM2);
892          if (rrc != MATCH_NOMATCH &&
893              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
894            RRETURN(rrc);
895          ecode += GET(ecode, 1);
896          if (*ecode != OP_ALT) break;
897          }
898    
899        if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr;
900        RRETURN(MATCH_NOMATCH);
901    
902        /* Handle possessive capturing brackets with an unlimited repeat. We come
903        here from BRAZERO with allow_zero set TRUE. The offset_vector values are
904        handled similarly to the normal case above. However, the matching is
905        different. The end of these brackets will always be OP_KETRPOS, which
906        returns MATCH_KETRPOS without going further in the pattern. By this means
907        we can handle the group by iteration rather than recursion, thereby
908        reducing the amount of stack needed. */
909    
910        case OP_CBRAPOS:
911        case OP_SCBRAPOS:
912        allow_zero = FALSE;
913    
914        POSSESSIVE_CAPTURE:
915        number = GET2(ecode, 1+LINK_SIZE);
916        offset = number << 1;
917    
918    #ifdef PCRE_DEBUG
919        printf("start possessive bracket %d\n", number);
920        printf("subject=");
921        pchars(eptr, 16, TRUE, md);
922        printf("\n");
923    #endif
924    
925        if (offset < md->offset_max)
926          {
927          matched_once = FALSE;
928          code_offset = ecode - md->start_code;
929    
930          save_offset1 = md->offset_vector[offset];
931          save_offset2 = md->offset_vector[offset+1];
932          save_offset3 = md->offset_vector[md->offset_end - number];
933          save_capture_last = md->capture_last;
934    
935          DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
936    
937          /* Each time round the loop, save the current subject position for use
938          when the group matches. For MATCH_MATCH, the group has matched, so we
939          restart it with a new subject starting position, remembering that we had
940          at least one match. For MATCH_NOMATCH, carry on with the alternatives, as
941          usual. If we haven't matched any alternatives in any iteration, check to
942          see if a previous iteration matched. If so, the group has matched;
943          continue from afterwards. Otherwise it has failed; restore the previous
944          capture values before returning NOMATCH. */
945    
946          for (;;)
947          {          {
948          if (flags == 0)    /* Not a possibly empty group */          md->offset_vector[md->offset_end - number] =
949              (int)(eptr - md->start_subject);
950            if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
951            RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
952              eptrb, RM63);
953            if (rrc == MATCH_KETRPOS)
954            {            {
955            ecode += _pcre_OP_lengths[*ecode];            offset_top = md->end_offset_top;
956            DPRINTF(("bracket 0 tail recursion\n"));            eptr = md->end_match_ptr;
957            goto TAIL_RECURSE;            ecode = md->start_code + code_offset;
958            }            save_capture_last = md->capture_last;
959              matched_once = TRUE;
960              continue;
961              }
962            if (rrc != MATCH_NOMATCH &&
963                (rrc != MATCH_THEN || md->start_match_ptr != ecode))
964              RRETURN(rrc);
965            md->capture_last = save_capture_last;
966            ecode += GET(ecode, 1);
967            if (*ecode != OP_ALT) break;
968            }
969    
970          /* Possibly empty group; can't use tail recursion. */        if (!matched_once)
971            {
972            md->offset_vector[offset] = save_offset1;
973            md->offset_vector[offset+1] = save_offset2;
974            md->offset_vector[md->offset_end - number] = save_offset3;
975            }
976    
977          if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr;
978          if (allow_zero || matched_once)
979            {
980            ecode += 1 + LINK_SIZE;
981            break;
982            }
983    
984          RRETURN(MATCH_NOMATCH);
985          }
986    
987        /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
988        as a non-capturing bracket. */
989    
990          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
991            eptrb, flags, RM48);      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
         if (rrc == MATCH_NOMATCH) md->mark = markptr;  
         RRETURN(rrc);  
         }  
992    
993        /* For non-final alternatives, continue the loop for a NOMATCH result;      DPRINTF(("insufficient capture room: treat as non-capturing\n"));
       otherwise return. */  
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 888  for (;;) Line 1058  for (;;)
1058          cb.callout_number   = ecode[LINK_SIZE+2];          cb.callout_number   = ecode[LINK_SIZE+2];
1059          cb.offset_vector    = md->offset_vector;          cb.offset_vector    = md->offset_vector;
1060          cb.subject          = (PCRE_SPTR)md->start_subject;          cb.subject          = (PCRE_SPTR)md->start_subject;
1061          cb.subject_length   = md->end_subject - md->start_subject;          cb.subject_length   = (int)(md->end_subject - md->start_subject);
1062          cb.start_match      = mstart - md->start_subject;          cb.start_match      = (int)(mstart - md->start_subject);
1063          cb.current_position = eptr - md->start_subject;          cb.current_position = (int)(eptr - md->start_subject);
1064          cb.pattern_position = GET(ecode, LINK_SIZE + 3);          cb.pattern_position = GET(ecode, LINK_SIZE + 3);
1065          cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);          cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
1066          cb.capture_top      = offset_top/2;          cb.capture_top      = offset_top/2;
# Line 1049  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 1074  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 1116  for (;;) Line 1284  for (;;)
1284        {        {
1285        md->offset_vector[offset] =        md->offset_vector[offset] =
1286          md->offset_vector[md->offset_end - number];          md->offset_vector[md->offset_end - number];
1287        md->offset_vector[offset+1] = eptr - md->start_subject;        md->offset_vector[offset+1] = (int)(eptr - md->start_subject);
1288        if (offset_top <= offset) offset_top = offset + 2;        if (offset_top <= offset) offset_top = offset + 2;
1289        }        }
1290      ecode += 3;      ecode += 3;
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_END:      case OP_END:
1300      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL)
1301        {        {
1302        recursion_info *rec = md->recursive;        recursion_info *rec = md->recursive;
       DPRINTF(("End of pattern in a (?0) recursion\n"));  
1303        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
1304        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
1305          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
1306        offset_top = rec->save_offset_top;        offset_top = rec->save_offset_top;
1307        ims = original_ims;        if (rec->group_num == 0)
1308        ecode = rec->after_call;          {
1309        break;          ecode = rec->after_call;
1310            break;
1311            }
1312        }        }
1313    
1314      /* Otherwise, if we have matched an empty string, fail if PCRE_NOTEMPTY is      /* Otherwise, if we have matched an empty string, fail if PCRE_NOTEMPTY is
# Line 1147  for (;;) Line 1316  for (;;)
1316      the subject. In both cases, backtracking will then try other alternatives,      the subject. In both cases, backtracking will then try other alternatives,
1317      if any. */      if any. */
1318    
1319      if (eptr == mstart &&      else if (eptr == mstart &&
1320          (md->notempty ||          (md->notempty ||
1321            (md->notempty_atstart &&            (md->notempty_atstart &&
1322              mstart == md->start_subject + md->start_offset)))              mstart == md->start_subject + md->start_offset)))
1323        MRRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1324    
1325      /* Otherwise, we have a match. */      /* Otherwise, we have a match. */
1326    
1327      md->end_match_ptr = eptr;           /* Record where we ended */      md->end_match_ptr = eptr;           /* Record where we ended */
1328      md->end_offset_top = offset_top;    /* and how many extracts were taken */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
1329      md->start_match_ptr = mstart;       /* and the start (\K can modify) */      md->start_match_ptr = mstart;       /* and the start (\K can modify) */
     MRRETURN(((op == OP_END)? MATCH_MATCH : MATCH_ACCEPT));  
1330    
1331      /* Change option settings */      /* For some reason, the macros don't work properly if an expression is
1332        given as the argument to MRRETURN when the heap is in use. */
1333    
1334      case OP_OPT:      rrc = (op == OP_END)? MATCH_MATCH : MATCH_ACCEPT;
1335      ims = ecode[1];      MRRETURN(rrc);
     ecode += 2;  
     DPRINTF(("ims set to %02lx\n", ims));  
     break;  
1336    
1337      /* Assertion brackets. Check the alternative branches in turn - the      /* Assertion brackets. Check the alternative branches in turn - the
1338      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,
1339      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
1340      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
1341      this level is identical to the lookahead case. */      this level is identical to the lookahead case. When the assertion is part
1342        of a condition, we want to return immediately afterwards. The caller of
1343        this incarnation of the match() function will have set MATCH_CONDASSERT in
1344        md->match_function type, and one of these opcodes will be the first opcode
1345        that is processed. We use a local variable that is preserved over calls to
1346        match() to remember this case. */
1347    
1348      case OP_ASSERT:      case OP_ASSERT:
1349      case OP_ASSERTBACK:      case OP_ASSERTBACK:
1350        if (md->match_function_type == MATCH_CONDASSERT)
1351          {
1352          condassert = TRUE;
1353          md->match_function_type = 0;
1354          }
1355        else condassert = FALSE;
1356    
1357      do      do
1358        {        {
1359        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM4);
         RM4);  
1360        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
1361          {          {
1362          mstart = md->start_match_ptr;   /* In case \K reset it */          mstart = md->start_match_ptr;   /* In case \K reset it */
1363          break;          break;
1364          }          }
1365        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH &&
1366              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1367            RRETURN(rrc);
1368        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1369        }        }
1370      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
1371    
1372      if (*ecode == OP_KET) MRRETURN(MATCH_NOMATCH);      if (*ecode == OP_KET) MRRETURN(MATCH_NOMATCH);
1373    
1374      /* If checking an assertion for a condition, return MATCH_MATCH. */      /* If checking an assertion for a condition, return MATCH_MATCH. */
1375    
1376      if ((flags & match_condassert) != 0) RRETURN(MATCH_MATCH);      if (condassert) RRETURN(MATCH_MATCH);
1377    
1378      /* Continue from after the assertion, updating the offsets high water      /* Continue from after the assertion, updating the offsets high water
1379      mark, since extracts may have been taken during the assertion. */      mark, since extracts may have been taken during the assertion. */
# Line 1209  for (;;) Line 1389  for (;;)
1389    
1390      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1391      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1392        if (md->match_function_type == MATCH_CONDASSERT)
1393          {
1394          condassert = TRUE;
1395          md->match_function_type = 0;
1396          }
1397        else condassert = FALSE;
1398    
1399      do      do
1400        {        {
1401        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5);
         RM5);  
1402        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) MRRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) MRRETURN(MATCH_NOMATCH);
1403        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)
1404          {          {
1405          do ecode += GET(ecode,1); while (*ecode == OP_ALT);          do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1406          break;          break;
1407          }          }
1408        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH &&
1409              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1410            RRETURN(rrc);
1411        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1412        }        }
1413      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
1414    
1415      if ((flags & match_condassert) != 0) RRETURN(MATCH_MATCH);      if (condassert) RRETURN(MATCH_MATCH);  /* Condition assertion */
1416    
1417      ecode += 1 + LINK_SIZE;      ecode += 1 + LINK_SIZE;
1418      continue;      continue;
1419    
# Line 1274  for (;;) Line 1462  for (;;)
1462        cb.callout_number   = ecode[1];        cb.callout_number   = ecode[1];
1463        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1464        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1465        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = (int)(md->end_subject - md->start_subject);
1466        cb.start_match      = mstart - md->start_subject;        cb.start_match      = (int)(mstart - md->start_subject);
1467        cb.current_position = eptr - md->start_subject;        cb.current_position = (int)(eptr - md->start_subject);
1468        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
1469        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
1470        cb.capture_top      = offset_top/2;        cb.capture_top      = offset_top/2;
# Line 1338  for (;;) Line 1526  for (;;)
1526        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1527              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1528        new_recursive.save_offset_top = offset_top;        new_recursive.save_offset_top = offset_top;
1529    
1530        /* 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
1531        restore the offset and recursion data. */        restore the offset and recursion data. */
1532    
1533        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
1534        flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;        cbegroup = (*callpat >= OP_SBRA);
1535        do        do
1536          {          {
1537            if (cbegroup) md->match_function_type = MATCH_CBEGROUP;
1538          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1539            md, ims, eptrb, flags, RM6);            md, eptrb, RM6);
1540          if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)          if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
1541            {            {
1542            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
# Line 1356  for (;;) Line 1545  for (;;)
1545              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1546            MRRETURN(MATCH_MATCH);            MRRETURN(MATCH_MATCH);
1547            }            }
1548          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)          else if (rrc != MATCH_NOMATCH &&
1549                    (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1550            {            {
1551            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1552            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
# Line 1393  for (;;) Line 1583  for (;;)
1583    
1584      do      do
1585        {        {
1586        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM7);
1587        if (rrc == MATCH_MATCH)  /* Note: _not_ MATCH_ACCEPT */        if (rrc == MATCH_MATCH)  /* Note: _not_ MATCH_ACCEPT */
1588          {          {
1589          mstart = md->start_match_ptr;          mstart = md->start_match_ptr;
1590          break;          break;
1591          }          }
1592        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH &&
1593              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1594            RRETURN(rrc);
1595        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1596        }        }
1597      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 1430  for (;;) Line 1622  for (;;)
1622    
1623      /* 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
1624      preceding bracket, in the appropriate order. The second "call" of match()      preceding bracket, in the appropriate order. The second "call" of match()
1625      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));  
       }  
1626    
1627      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1628        {        {
1629        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM8);
1630        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1631        ecode = prev;        ecode = prev;
       flags = 0;  
1632        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1633        }        }
1634      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1635        {        {
1636        RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);        md->match_function_type = MATCH_CBEGROUP;
1637          RMATCH(eptr, prev, offset_top, md, eptrb, RM9);
1638        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1639        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
       flags = 0;  
1640        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1641        }        }
1642      /* Control never gets here */      /* Control never gets here */
# Line 1470  for (;;) Line 1653  for (;;)
1653      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
1654      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
1655      optional ones preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1656    
1657      case OP_BRAZERO:      case OP_BRAZERO:
1658        {      next = ecode + 1;
1659        next = ecode+1;      RMATCH(eptr, next, offset_top, md, eptrb, RM10);
1660        RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1661        if (rrc != MATCH_NOMATCH) RRETURN(rrc);      do next += GET(next, 1); while (*next == OP_ALT);
1662        do next += GET(next,1); while (*next == OP_ALT);      ecode = next + 1 + LINK_SIZE;
       ecode = next + 1 + LINK_SIZE;  
       }  
1663      break;      break;
1664    
1665      case OP_BRAMINZERO:      case OP_BRAMINZERO:
1666        {      next = ecode + 1;
1667        next = ecode+1;      do next += GET(next, 1); while (*next == OP_ALT);
1668        do next += GET(next, 1); while (*next == OP_ALT);      RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, eptrb, RM11);
1669        RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11);      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1670        if (rrc != MATCH_NOMATCH) RRETURN(rrc);      ecode++;
       ecode++;  
       }  
1671      break;      break;
1672    
1673      case OP_SKIPZERO:      case OP_SKIPZERO:
1674        {      next = ecode+1;
1675        next = ecode+1;      do next += GET(next,1); while (*next == OP_ALT);
1676        do next += GET(next,1); while (*next == OP_ALT);      ecode = next + 1 + LINK_SIZE;
       ecode = next + 1 + LINK_SIZE;  
       }  
1677      break;      break;
1678    
1679        /* BRAPOSZERO occurs before a possessive bracket group. Don't do anything
1680        here; just jump to the group, with allow_zero set TRUE. */
1681    
1682        case OP_BRAPOSZERO:
1683        op = *(++ecode);
1684        allow_zero = TRUE;
1685        if (op == OP_CBRAPOS || op == OP_SCBRAPOS) goto POSSESSIVE_CAPTURE;
1686          goto POSSESSIVE_NON_CAPTURE;
1687    
1688      /* End of a group, repeated or non-repeating. */      /* End of a group, repeated or non-repeating. */
1689    
1690      case OP_KET:      case OP_KET:
1691      case OP_KETRMIN:      case OP_KETRMIN:
1692      case OP_KETRMAX:      case OP_KETRMAX:
1693        case OP_KETRPOS:
1694      prev = ecode - GET(ecode, 1);      prev = ecode - GET(ecode, 1);
1695    
1696      /* 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 1538  for (;;) Line 1725  for (;;)
1725      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
1726      when the OP_END is reached. Other recursion is handled here. */      when the OP_END is reached. Other recursion is handled here. */
1727    
1728      if (*prev == OP_CBRA || *prev == OP_SCBRA)      if (*prev == OP_CBRA || *prev == OP_SCBRA ||
1729            *prev == OP_CBRAPOS || *prev == OP_SCBRAPOS)
1730        {        {
1731        number = GET2(prev, 1+LINK_SIZE);        number = GET2(prev, 1+LINK_SIZE);
1732        offset = number << 1;        offset = number << 1;
# Line 1553  for (;;) Line 1741  for (;;)
1741          {          {
1742          md->offset_vector[offset] =          md->offset_vector[offset] =
1743            md->offset_vector[md->offset_end - number];            md->offset_vector[md->offset_end - number];
1744          md->offset_vector[offset+1] = eptr - md->start_subject;          md->offset_vector[offset+1] = (int)(eptr - md->start_subject);
1745          if (offset_top <= offset) offset_top = offset + 2;          if (offset_top <= offset) offset_top = offset + 2;
1746          }          }
1747    
# Line 1569  for (;;) Line 1757  for (;;)
1757            rec->saved_max * sizeof(int));            rec->saved_max * sizeof(int));
1758          offset_top = rec->save_offset_top;          offset_top = rec->save_offset_top;
1759          ecode = rec->after_call;          ecode = rec->after_call;
         ims = original_ims;  
1760          break;          break;
1761          }          }
1762        }        }
1763    
     /* 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));  
   
1764      /* For a non-repeating ket, just continue at this level. This also      /* For a non-repeating ket, just continue at this level. This also
1765      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.
1766      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 1591  for (;;) Line 1772  for (;;)
1772        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1773        break;        break;
1774        }        }
1775    
1776      /* The repeating kets try the rest of the pattern or restart from the      /* OP_KETRPOS is a possessive repeating ket. Remember the current position,
1777      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
1778      tail recursion to avoid using another stack frame, unless we have an      at a time from the outer level, thus saving stack. */
1779    
1780        if (*ecode == OP_KETRPOS)
1781          {
1782          md->end_match_ptr = eptr;
1783          md->end_offset_top = offset_top;
1784          RRETURN(MATCH_KETRPOS);
1785          }
1786    
1787        /* The normal repeating kets try the rest of the pattern or restart from
1788        the preceding bracket, in the appropriate order. In the second case, we can
1789        use tail recursion to avoid using another stack frame, unless we have an
1790      unlimited repeat of a group that can match an empty string. */      unlimited repeat of a group that can match an empty string. */
1791    
     flags = (*prev >= OP_SBRA)? match_cbegroup : 0;  
   
1792      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1793        {        {
1794        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM12);
1795        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1796        if (flags != 0)    /* Could match an empty string */        if (*prev >= OP_SBRA)    /* Could match an empty string */
1797          {          {
1798          RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);          md->match_function_type = MATCH_CBEGROUP;
1799            RMATCH(eptr, prev, offset_top, md, eptrb, RM50);
1800          RRETURN(rrc);          RRETURN(rrc);
1801          }          }
1802        ecode = prev;        ecode = prev;
# Line 1613  for (;;) Line 1804  for (;;)
1804        }        }
1805      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1806        {        {
1807        RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);        if (*prev >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
1808          RMATCH(eptr, prev, offset_top, md, eptrb, RM13);
1809        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1810        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
       flags = 0;  
1811        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1812        }        }
1813      /* Control never gets here */      /* Control never gets here */
1814    
1815      /* Start of subject unless notbol, or after internal newline if multiline */      /* Not multiline mode: start of subject assertion, unless notbol. */
1816    
1817      case OP_CIRC:      case OP_CIRC:
1818      if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH);      if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH);
1819      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 */  
   
1820      /* Start of subject assertion */      /* Start of subject assertion */
1821    
1822      case OP_SOD:      case OP_SOD:
1823      if (eptr != md->start_subject) MRRETURN(MATCH_NOMATCH);      if (eptr != md->start_subject) MRRETURN(MATCH_NOMATCH);
1824      ecode++;      ecode++;
1825      break;      break;
1826    
1827        /* Multiline mode: start of subject unless notbol, or after any newline. */
1828    
1829        case OP_CIRCM:
1830        if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH);
1831        if (eptr != md->start_subject &&
1832            (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
1833          MRRETURN(MATCH_NOMATCH);
1834        ecode++;
1835        break;
1836    
1837      /* Start of match assertion */      /* Start of match assertion */
1838    
# Line 1656  for (;;) Line 1848  for (;;)
1848      ecode++;      ecode++;
1849      break;      break;
1850    
1851      /* Assert before internal newline if multiline, or before a terminating      /* Multiline mode: assert before any newline, or before end of subject
1852      newline unless endonly is set, else end of subject unless noteol is set. */      unless noteol is set. */
1853    
1854      case OP_DOLL:      case OP_DOLLM:
1855      if ((ims & PCRE_MULTILINE) != 0)      if (eptr < md->end_subject)
1856        {        { 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;  
       }  
1857      else      else
1858        {        {
1859        if (md->noteol) MRRETURN(MATCH_NOMATCH);        if (md->noteol) MRRETURN(MATCH_NOMATCH);
1860        if (!md->endonly)        SCHECK_PARTIAL();
         {  
         if (eptr != md->end_subject &&  
             (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))  
           MRRETURN(MATCH_NOMATCH);  
         ecode++;  
         break;  
         }  
1861        }        }
1862        ecode++;
1863        break;
1864    
1865        /* Not multiline mode: assert before a terminating newline or before end of
1866        subject unless noteol is set. */
1867    
1868        case OP_DOLL:
1869        if (md->noteol) MRRETURN(MATCH_NOMATCH);
1870        if (!md->endonly) goto ASSERT_NL_OR_EOS;
1871    
1872      /* ... else fall through for endonly */      /* ... else fall through for endonly */
1873    
1874      /* End of subject assertion (\z) */      /* End of subject assertion (\z) */
1875    
1876      case OP_EOD:      case OP_EOD:
1877      if (eptr < md->end_subject) MRRETURN(MATCH_NOMATCH);      if (eptr < md->end_subject) MRRETURN(MATCH_NOMATCH);
1878        SCHECK_PARTIAL();
1879      ecode++;      ecode++;
1880      break;      break;
1881    
1882      /* End of subject or ending \n assertion (\Z) */      /* End of subject or ending \n assertion (\Z) */
1883    
1884      case OP_EODN:      case OP_EODN:
1885      if (eptr != md->end_subject &&      ASSERT_NL_OR_EOS:
1886        if (eptr < md->end_subject &&
1887          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1888        MRRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1889    
1890        /* Either at end of string or \n before end. */
1891    
1892        SCHECK_PARTIAL();
1893      ecode++;      ecode++;
1894      break;      break;
1895    
# Line 1713  for (;;) Line 1907  for (;;)
1907  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1908        if (utf8)        if (utf8)
1909          {          {
1910            /* Get status of previous character */
1911    
1912          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
1913            {            {
1914            USPTR lastptr = eptr - 1;            USPTR lastptr = eptr - 1;
1915            while((*lastptr & 0xc0) == 0x80) lastptr--;            while((*lastptr & 0xc0) == 0x80) lastptr--;
1916            if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;            if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;
1917            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
1918    #ifdef SUPPORT_UCP
1919              if (md->use_ucp)
1920                {
1921                if (c == '_') prev_is_word = TRUE; else
1922                  {
1923                  int cat = UCD_CATEGORY(c);
1924                  prev_is_word = (cat == ucp_L || cat == ucp_N);
1925                  }
1926                }
1927              else
1928    #endif
1929            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1930            }            }
1931    
1932            /* Get status of next character */
1933    
1934          if (eptr >= md->end_subject)          if (eptr >= md->end_subject)
1935            {            {
1936            SCHECK_PARTIAL();            SCHECK_PARTIAL();
# Line 1729  for (;;) Line 1939  for (;;)
1939          else          else
1940            {            {
1941            GETCHAR(c, eptr);            GETCHAR(c, eptr);
1942    #ifdef SUPPORT_UCP
1943              if (md->use_ucp)
1944                {
1945                if (c == '_') cur_is_word = TRUE; else
1946                  {
1947                  int cat = UCD_CATEGORY(c);
1948                  cur_is_word = (cat == ucp_L || cat == ucp_N);
1949                  }
1950                }
1951              else
1952    #endif
1953            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1954            }            }
1955          }          }
1956        else        else
1957  #endif  #endif
1958    
1959        /* Not in UTF-8 mode */        /* Not in UTF-8 mode, but we may still have PCRE_UCP set, and for
1960          consistency with the behaviour of \w we do use it in this case. */
1961    
1962          {          {
1963            /* Get status of previous character */
1964    
1965          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
1966            {            {
1967            if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1;            if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1;
1968    #ifdef SUPPORT_UCP
1969              if (md->use_ucp)
1970                {
1971                c = eptr[-1];
1972                if (c == '_') prev_is_word = TRUE; else
1973                  {
1974                  int cat = UCD_CATEGORY(c);
1975                  prev_is_word = (cat == ucp_L || cat == ucp_N);
1976                  }
1977                }
1978              else
1979    #endif
1980            prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);            prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);
1981            }            }
1982    
1983            /* Get status of next character */
1984    
1985          if (eptr >= md->end_subject)          if (eptr >= md->end_subject)
1986            {            {
1987            SCHECK_PARTIAL();            SCHECK_PARTIAL();
1988            cur_is_word = FALSE;            cur_is_word = FALSE;
1989            }            }
1990          else cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);          else
1991    #ifdef SUPPORT_UCP
1992            if (md->use_ucp)
1993              {
1994              c = *eptr;
1995              if (c == '_') cur_is_word = TRUE; else
1996                {
1997                int cat = UCD_CATEGORY(c);
1998                cur_is_word = (cat == ucp_L || cat == ucp_N);
1999                }
2000              }
2001            else
2002    #endif
2003            cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);
2004          }          }
2005    
2006        /* Now see if the situation is what we want */        /* Now see if the situation is what we want */
# Line 1899  for (;;) Line 2151  for (;;)
2151      switch(c)      switch(c)
2152        {        {
2153        default: MRRETURN(MATCH_NOMATCH);        default: MRRETURN(MATCH_NOMATCH);
2154    
2155        case 0x000d:        case 0x000d:
2156        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
2157        break;        break;
# Line 2055  for (;;) Line 2308  for (;;)
2308               prop->chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
2309               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
2310            MRRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2311           break;          break;
2312    
2313          case PT_GC:          case PT_GC:
2314          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
# Line 2072  for (;;) Line 2325  for (;;)
2325            MRRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2326          break;          break;
2327    
2328            /* These are specials */
2329    
2330            case PT_ALNUM:
2331            if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||
2332                 _pcre_ucp_gentype[prop->chartype] == ucp_N) == (op == OP_NOTPROP))
2333              MRRETURN(MATCH_NOMATCH);
2334            break;
2335    
2336            case PT_SPACE:    /* Perl space */
2337            if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||
2338                 c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)
2339                   == (op == OP_NOTPROP))
2340              MRRETURN(MATCH_NOMATCH);
2341            break;
2342    
2343            case PT_PXSPACE:  /* POSIX space */
2344            if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||
2345                 c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
2346                 c == CHAR_FF || c == CHAR_CR)
2347                   == (op == OP_NOTPROP))
2348              MRRETURN(MATCH_NOMATCH);
2349            break;
2350    
2351            case PT_WORD:
2352            if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||
2353                 _pcre_ucp_gentype[prop->chartype] == ucp_N ||
2354                 c == CHAR_UNDERSCORE) == (op == OP_NOTPROP))
2355              MRRETURN(MATCH_NOMATCH);
2356            break;
2357    
2358            /* This should never occur */
2359    
2360          default:          default:
2361          RRETURN(PCRE_ERROR_INTERNAL);          RRETURN(PCRE_ERROR_INTERNAL);
2362          }          }
# Line 2119  for (;;) Line 2404  for (;;)
2404      loops). */      loops). */
2405    
2406      case OP_REF:      case OP_REF:
2407        {      case OP_REFI:
2408        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */      caseless = op == OP_REFI;
2409        ecode += 3;      offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
2410        ecode += 3;
2411    
2412        /* If the reference is unset, there are two possibilities:      /* If the reference is unset, there are two possibilities:
2413    
2414        (a) In the default, Perl-compatible state, set the length to be longer      (a) In the default, Perl-compatible state, set the length negative;
2415        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
2416        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.  
2417    
2418        (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
2419        so that the back reference matches an empty string.      so that the back reference matches an empty string.
2420    
2421        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
2422        referenced subpattern. */      referenced subpattern. */
2423    
2424        if (offset >= offset_top || md->offset_vector[offset] < 0)      if (offset >= offset_top || md->offset_vector[offset] < 0)
2425          length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;        length = (md->jscript_compat)? 0 : -1;
2426        else      else
2427          length = md->offset_vector[offset+1] - md->offset_vector[offset];        length = md->offset_vector[offset+1] - md->offset_vector[offset];
2428    
2429        /* Set up for repetition, or handle the non-repeated case */      /* Set up for repetition, or handle the non-repeated case */
2430    
2431        switch (*ecode)      switch (*ecode)
2432          {        {
2433          case OP_CRSTAR:        case OP_CRSTAR:
2434          case OP_CRMINSTAR:        case OP_CRMINSTAR:
2435          case OP_CRPLUS:        case OP_CRPLUS:
2436          case OP_CRMINPLUS:        case OP_CRMINPLUS:
2437          case OP_CRQUERY:        case OP_CRQUERY:
2438          case OP_CRMINQUERY:        case OP_CRMINQUERY:
2439          c = *ecode++ - OP_CRSTAR;        c = *ecode++ - OP_CRSTAR;
2440          minimize = (c & 1) != 0;        minimize = (c & 1) != 0;
2441          min = rep_min[c];                 /* Pick up values from tables; */        min = rep_min[c];                 /* Pick up values from tables; */
2442          max = rep_max[c];                 /* zero for max => infinity */        max = rep_max[c];                 /* zero for max => infinity */
2443          if (max == 0) max = INT_MAX;        if (max == 0) max = INT_MAX;
2444          break;        break;
2445    
2446          case OP_CRRANGE:        case OP_CRRANGE:
2447          case OP_CRMINRANGE:        case OP_CRMINRANGE:
2448          minimize = (*ecode == OP_CRMINRANGE);        minimize = (*ecode == OP_CRMINRANGE);
2449          min = GET2(ecode, 1);        min = GET2(ecode, 1);
2450          max = GET2(ecode, 3);        max = GET2(ecode, 3);
2451          if (max == 0) max = INT_MAX;        if (max == 0) max = INT_MAX;
2452          ecode += 5;        ecode += 5;
2453          break;        break;
2454    
2455          default:               /* No repeat follows */        default:               /* No repeat follows */
2456          if (!match_ref(offset, eptr, length, md, ims))        if ((length = match_ref(offset, eptr, length, md, caseless)) < 0)
2457            {          {
2458            CHECK_PARTIAL();          CHECK_PARTIAL();
2459            MRRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
           }  
         eptr += length;  
         continue;              /* With the main loop */  
2460          }          }
2461          eptr += length;
2462          continue;              /* With the main loop */
2463          }
2464    
2465        /* If the length of the reference is zero, just continue with the      /* Handle repeated back references. If the length of the reference is
2466        main loop. */      zero, just continue with the main loop. */
2467    
2468        if (length == 0) continue;      if (length == 0) continue;
2469    
2470        /* First, ensure the minimum number of matches are present. We get back      /* First, ensure the minimum number of matches are present. We get back
2471        the length of the reference string explicitly rather than passing the      the length of the reference string explicitly rather than passing the
2472        address of eptr, so that eptr can be a register variable. */      address of eptr, so that eptr can be a register variable. */
2473    
2474        for (i = 1; i <= min; i++)      for (i = 1; i <= min; i++)
2475          {
2476          int slength;
2477          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2478          {          {
2479          if (!match_ref(offset, eptr, length, md, ims))          CHECK_PARTIAL();
2480            {          MRRETURN(MATCH_NOMATCH);
           CHECK_PARTIAL();  
           MRRETURN(MATCH_NOMATCH);  
           }  
         eptr += length;  
2481          }          }
2482          eptr += slength;
2483          }
2484    
2485        /* If min = max, continue at the same level without recursion.      /* If min = max, continue at the same level without recursion.
2486        They are not both allowed to be zero. */      They are not both allowed to be zero. */
   
       if (min == max) continue;  
   
       /* If minimizing, keep trying and advancing the pointer */  
2487    
2488        if (minimize)      if (min == max) continue;
         {  
         for (fi = min;; fi++)  
           {  
           RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);  
           if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
           if (fi >= max) MRRETURN(MATCH_NOMATCH);  
           if (!match_ref(offset, eptr, length, md, ims))  
             {  
             CHECK_PARTIAL();  
             MRRETURN(MATCH_NOMATCH);  
             }  
           eptr += length;  
           }  
         /* Control never gets here */  
         }  
2489    
2490        /* If maximizing, find the longest string and work backwards */      /* If minimizing, keep trying and advancing the pointer */
2491    
2492        else      if (minimize)
2493          {
2494          for (fi = min;; fi++)
2495          {          {
2496          pp = eptr;          int slength;
2497          for (i = min; i < max; i++)          RMATCH(eptr, ecode, offset_top, md, eptrb, RM14);
2498            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2499            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2500            if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2501            {            {
2502            if (!match_ref(offset, eptr, length, md, ims))            CHECK_PARTIAL();
2503              {            MRRETURN(MATCH_NOMATCH);
             CHECK_PARTIAL();  
             break;  
             }  
           eptr += length;  
2504            }            }
2505          while (eptr >= pp)          eptr += slength;
2506            }
2507          /* Control never gets here */
2508          }
2509    
2510        /* If maximizing, find the longest string and work backwards */
2511    
2512        else
2513          {
2514          pp = eptr;
2515          for (i = min; i < max; i++)
2516            {
2517            int slength;
2518            if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2519            {            {
2520            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);            CHECK_PARTIAL();
2521            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            break;
           eptr -= length;  
2522            }            }
2523          MRRETURN(MATCH_NOMATCH);          eptr += slength;
2524            }
2525          while (eptr >= pp)
2526            {
2527            RMATCH(eptr, ecode, offset_top, md, eptrb, RM15);
2528            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2529            eptr -= length;
2530          }          }
2531          MRRETURN(MATCH_NOMATCH);
2532        }        }
2533      /* Control never gets here */      /* Control never gets here */
2534    
# Line 2347  for (;;) Line 2634  for (;;)
2634            {            {
2635            for (fi = min;; fi++)            for (fi = min;; fi++)
2636              {              {
2637              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM16);
2638              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2639              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2640              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 2372  for (;;) Line 2659  for (;;)
2659            {            {
2660            for (fi = min;; fi++)            for (fi = min;; fi++)
2661              {              {
2662              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM17);
2663              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2664              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2665              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 2418  for (;;) Line 2705  for (;;)
2705              }              }
2706            for (;;)            for (;;)
2707              {              {
2708              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM18);
2709              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2710              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2711              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2441  for (;;) Line 2728  for (;;)
2728              }              }
2729            while (eptr >= pp)            while (eptr >= pp)
2730              {              {
2731              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM19);
2732              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2733              eptr--;              eptr--;
2734              }              }
# Line 2517  for (;;) Line 2804  for (;;)
2804          {          {
2805          for (fi = min;; fi++)          for (fi = min;; fi++)
2806            {            {
2807            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM20);
2808            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2809            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2810            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
# Line 2550  for (;;) Line 2837  for (;;)
2837            }            }
2838          for(;;)          for(;;)
2839            {            {
2840            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM21);
2841            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2842            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2843            if (utf8) BACKCHAR(eptr);            if (utf8) BACKCHAR(eptr);
# Line 2595  for (;;) Line 2882  for (;;)
2882    
2883      /* Match a single character, caselessly */      /* Match a single character, caselessly */
2884    
2885      case OP_CHARNC:      case OP_CHARI:
2886  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2887      if (utf8)      if (utf8)
2888        {        {
# Line 2655  for (;;) Line 2942  for (;;)
2942      /* Match a single character repeatedly. */      /* Match a single character repeatedly. */
2943    
2944      case OP_EXACT:      case OP_EXACT:
2945        case OP_EXACTI:
2946      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
2947      ecode += 3;      ecode += 3;
2948      goto REPEATCHAR;      goto REPEATCHAR;
2949    
2950      case OP_POSUPTO:      case OP_POSUPTO:
2951        case OP_POSUPTOI:
2952      possessive = TRUE;      possessive = TRUE;
2953      /* Fall through */      /* Fall through */
2954    
2955      case OP_UPTO:      case OP_UPTO:
2956        case OP_UPTOI:
2957      case OP_MINUPTO:      case OP_MINUPTO:
2958        case OP_MINUPTOI:
2959      min = 0;      min = 0;
2960      max = GET2(ecode, 1);      max = GET2(ecode, 1);
2961      minimize = *ecode == OP_MINUPTO;      minimize = *ecode == OP_MINUPTO || *ecode == OP_MINUPTOI;
2962      ecode += 3;      ecode += 3;
2963      goto REPEATCHAR;      goto REPEATCHAR;
2964    
2965      case OP_POSSTAR:      case OP_POSSTAR:
2966        case OP_POSSTARI:
2967      possessive = TRUE;      possessive = TRUE;
2968      min = 0;      min = 0;
2969      max = INT_MAX;      max = INT_MAX;
# Line 2679  for (;;) Line 2971  for (;;)
2971      goto REPEATCHAR;      goto REPEATCHAR;
2972    
2973      case OP_POSPLUS:      case OP_POSPLUS:
2974        case OP_POSPLUSI:
2975      possessive = TRUE;      possessive = TRUE;
2976      min = 1;      min = 1;
2977      max = INT_MAX;      max = INT_MAX;
# Line 2686  for (;;) Line 2979  for (;;)
2979      goto REPEATCHAR;      goto REPEATCHAR;
2980    
2981      case OP_POSQUERY:      case OP_POSQUERY:
2982        case OP_POSQUERYI:
2983      possessive = TRUE;      possessive = TRUE;
2984      min = 0;      min = 0;
2985      max = 1;      max = 1;
# Line 2693  for (;;) Line 2987  for (;;)
2987      goto REPEATCHAR;      goto REPEATCHAR;
2988    
2989      case OP_STAR:      case OP_STAR:
2990        case OP_STARI:
2991      case OP_MINSTAR:      case OP_MINSTAR:
2992        case OP_MINSTARI:
2993      case OP_PLUS:      case OP_PLUS:
2994        case OP_PLUSI:
2995      case OP_MINPLUS:      case OP_MINPLUS:
2996        case OP_MINPLUSI:
2997      case OP_QUERY:      case OP_QUERY:
2998        case OP_QUERYI:
2999      case OP_MINQUERY:      case OP_MINQUERY:
3000      c = *ecode++ - OP_STAR;      case OP_MINQUERYI:
3001        c = *ecode++ - ((op < OP_STARI)? OP_STAR : OP_STARI);
3002      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
   
3003      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
3004      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
3005      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
# Line 2723  for (;;) Line 3022  for (;;)
3022          {          {
3023  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3024          unsigned int othercase;          unsigned int othercase;
3025          if ((ims & PCRE_CASELESS) != 0 &&          if (op >= OP_STARI &&     /* Caseless */
3026              (othercase = UCD_OTHERCASE(fc)) != fc)              (othercase = UCD_OTHERCASE(fc)) != fc)
3027            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
3028          else oclength = 0;          else oclength = 0;
# Line 2751  for (;;) Line 3050  for (;;)
3050            {            {
3051            for (fi = min;; fi++)            for (fi = min;; fi++)
3052              {              {
3053              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM22);
3054              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3055              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3056              if (eptr <= md->end_subject - length &&              if (eptr <= md->end_subject - length &&
# Line 2793  for (;;) Line 3092  for (;;)
3092    
3093            for(;;)            for(;;)
3094              {              {
3095              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM23);
3096              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3097              if (eptr == pp) { MRRETURN(MATCH_NOMATCH); }              if (eptr == pp) { MRRETURN(MATCH_NOMATCH); }
3098  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2830  for (;;) Line 3129  for (;;)
3129      DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc, min, max,      DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc, min, max,
3130        max, eptr));        max, eptr));
3131    
3132      if ((ims & PCRE_CASELESS) != 0)      if (op >= OP_STARI)  /* Caseless */
3133        {        {
3134        fc = md->lcc[fc];        fc = md->lcc[fc];
3135        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
# Line 2847  for (;;) Line 3146  for (;;)
3146          {          {
3147          for (fi = min;; fi++)          for (fi = min;; fi++)
3148            {            {
3149            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM24);
3150            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3151            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
3152            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
# Line 2877  for (;;) Line 3176  for (;;)
3176    
3177          while (eptr >= pp)          while (eptr >= pp)
3178            {            {
3179            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM25);
3180            eptr--;            eptr--;
3181            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3182            }            }
# Line 2906  for (;;) Line 3205  for (;;)
3205          {          {
3206          for (fi = min;; fi++)          for (fi = min;; fi++)
3207            {            {
3208            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM26);
3209            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3210            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
3211            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
# Line 2935  for (;;) Line 3234  for (;;)
3234    
3235          while (eptr >= pp)          while (eptr >= pp)
3236            {            {
3237            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM27);
3238            eptr--;            eptr--;
3239            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3240            }            }
# Line 2948  for (;;) Line 3247  for (;;)
3247      checking can be multibyte. */      checking can be multibyte. */
3248    
3249      case OP_NOT:      case OP_NOT:
3250        case OP_NOTI:
3251      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
3252        {        {
3253        SCHECK_PARTIAL();        SCHECK_PARTIAL();
# Line 2955  for (;;) Line 3255  for (;;)
3255        }        }
3256      ecode++;      ecode++;
3257      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
3258      if ((ims & PCRE_CASELESS) != 0)      if (op == OP_NOTI)         /* The caseless case */
3259        {        {
3260  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
3261        if (c < 256)        if (c < 256)
# Line 2963  for (;;) Line 3263  for (;;)
3263        c = md->lcc[c];        c = md->lcc[c];
3264        if (md->lcc[*ecode++] == c) MRRETURN(MATCH_NOMATCH);        if (md->lcc[*ecode++] == c) MRRETURN(MATCH_NOMATCH);
3265        }        }
3266      else      else    /* Caseful */
3267        {        {
3268        if (*ecode++ == c) MRRETURN(MATCH_NOMATCH);        if (*ecode++ == c) MRRETURN(MATCH_NOMATCH);
3269        }        }
# Line 2977  for (;;) Line 3277  for (;;)
3277      about... */      about... */
3278    
3279      case OP_NOTEXACT:      case OP_NOTEXACT:
3280        case OP_NOTEXACTI:
3281      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
3282      ecode += 3;      ecode += 3;
3283      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3284    
3285      case OP_NOTUPTO:      case OP_NOTUPTO:
3286        case OP_NOTUPTOI:
3287      case OP_NOTMINUPTO:      case OP_NOTMINUPTO:
3288        case OP_NOTMINUPTOI:
3289      min = 0;      min = 0;
3290      max = GET2(ecode, 1);      max = GET2(ecode, 1);
3291      minimize = *ecode == OP_NOTMINUPTO;      minimize = *ecode == OP_NOTMINUPTO || *ecode == OP_NOTMINUPTOI;
3292      ecode += 3;      ecode += 3;
3293      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3294    
3295      case OP_NOTPOSSTAR:      case OP_NOTPOSSTAR:
3296        case OP_NOTPOSSTARI:
3297      possessive = TRUE;      possessive = TRUE;
3298      min = 0;      min = 0;
3299      max = INT_MAX;      max = INT_MAX;
# Line 2997  for (;;) Line 3301  for (;;)
3301      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3302    
3303      case OP_NOTPOSPLUS:      case OP_NOTPOSPLUS:
3304        case OP_NOTPOSPLUSI:
3305      possessive = TRUE;      possessive = TRUE;
3306      min = 1;      min = 1;
3307      max = INT_MAX;      max = INT_MAX;
# Line 3004  for (;;) Line 3309  for (;;)
3309      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3310    
3311      case OP_NOTPOSQUERY:      case OP_NOTPOSQUERY:
3312        case OP_NOTPOSQUERYI:
3313      possessive = TRUE;      possessive = TRUE;
3314      min = 0;      min = 0;
3315      max = 1;      max = 1;
# Line 3011  for (;;) Line 3317  for (;;)
3317      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3318    
3319      case OP_NOTPOSUPTO:      case OP_NOTPOSUPTO:
3320        case OP_NOTPOSUPTOI:
3321      possessive = TRUE;      possessive = TRUE;
3322      min = 0;      min = 0;
3323      max = GET2(ecode, 1);      max = GET2(ecode, 1);
# Line 3018  for (;;) Line 3325  for (;;)
3325      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3326    
3327      case OP_NOTSTAR:      case OP_NOTSTAR:
3328        case OP_NOTSTARI:
3329      case OP_NOTMINSTAR:      case OP_NOTMINSTAR:
3330        case OP_NOTMINSTARI:
3331      case OP_NOTPLUS:      case OP_NOTPLUS:
3332        case OP_NOTPLUSI:
3333      case OP_NOTMINPLUS:      case OP_NOTMINPLUS:
3334        case OP_NOTMINPLUSI:
3335      case OP_NOTQUERY:      case OP_NOTQUERY:
3336        case OP_NOTQUERYI:
3337      case OP_NOTMINQUERY:      case OP_NOTMINQUERY:
3338      c = *ecode++ - OP_NOTSTAR;      case OP_NOTMINQUERYI:
3339        c = *ecode++ - ((op >= OP_NOTSTARI)? OP_NOTSTARI: OP_NOTSTAR);
3340      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
3341      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
3342      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
# Line 3045  for (;;) Line 3358  for (;;)
3358      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,
3359        max, eptr));        max, eptr));
3360    
3361      if ((ims & PCRE_CASELESS) != 0)      if (op >= OP_NOTSTARI)     /* Caseless */
3362        {        {
3363        fc = md->lcc[fc];        fc = md->lcc[fc];
3364    
# Line 3093  for (;;) Line 3406  for (;;)
3406            register unsigned int d;            register unsigned int d;
3407            for (fi = min;; fi++)            for (fi = min;; fi++)
3408              {              {
3409              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM28);
3410              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3411              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3412              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 3112  for (;;) Line 3425  for (;;)
3425            {            {
3426            for (fi = min;; fi++)            for (fi = min;; fi++)
3427              {              {
3428              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM29);
3429              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3430              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3431              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 3153  for (;;) Line 3466  for (;;)
3466          if (possessive) continue;          if (possessive) continue;
3467          for(;;)          for(;;)
3468              {              {
3469              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM30);
3470              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3471              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3472              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 3176  for (;;) Line 3489  for (;;)
3489            if (possessive) continue;            if (possessive) continue;
3490            while (eptr >= pp)            while (eptr >= pp)
3491              {              {
3492              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM31);
3493              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3494              eptr--;              eptr--;
3495              }              }
# Line 3233  for (;;) Line 3546  for (;;)
3546            register unsigned int d;            register unsigned int d;
3547            for (fi = min;; fi++)            for (fi = min;; fi++)
3548              {              {
3549              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM32);
3550              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3551              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3552              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 3251  for (;;) Line 3564  for (;;)
3564            {            {
3565            for (fi = min;; fi++)            for (fi = min;; fi++)
3566              {              {
3567              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM33);
3568              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3569              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3570              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 3291  for (;;) Line 3604  for (;;)
3604            if (possessive) continue;            if (possessive) continue;
3605            for(;;)            for(;;)
3606              {              {
3607              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM34);
3608              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3609              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3610              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 3314  for (;;) Line 3627  for (;;)
3627            if (possessive) continue;            if (possessive) continue;
3628            while (eptr >= pp)            while (eptr >= pp)
3629              {              {
3630              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM35);
3631              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3632              eptr--;              eptr--;
3633              }              }
# Line 3488  for (;;) Line 3801  for (;;)
3801              }              }
3802            break;            break;
3803    
3804              case PT_ALNUM:
3805              for (i = 1; i <= min; i++)
3806                {
3807                if (eptr >= md->end_subject)
3808                  {
3809                  SCHECK_PARTIAL();
3810                  MRRETURN(MATCH_NOMATCH);
3811                  }
3812                GETCHARINCTEST(c, eptr);
3813                prop_category = UCD_CATEGORY(c);
3814                if ((prop_category == ucp_L || prop_category == ucp_N)
3815                       == prop_fail_result)
3816                  MRRETURN(MATCH_NOMATCH);
3817                }
3818              break;
3819    
3820              case PT_SPACE:    /* Perl space */
3821              for (i = 1; i <= min; i++)
3822                {
3823                if (eptr >= md->end_subject)
3824                  {
3825                  SCHECK_PARTIAL();
3826                  MRRETURN(MATCH_NOMATCH);
3827                  }
3828                GETCHARINCTEST(c, eptr);
3829                prop_category = UCD_CATEGORY(c);
3830                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
3831                     c == CHAR_FF || c == CHAR_CR)
3832                       == prop_fail_result)
3833                  MRRETURN(MATCH_NOMATCH);
3834                }
3835              break;
3836    
3837              case PT_PXSPACE:  /* POSIX space */
3838              for (i = 1; i <= min; i++)
3839                {
3840                if (eptr >= md->end_subject)
3841                  {
3842                  SCHECK_PARTIAL();
3843                  MRRETURN(MATCH_NOMATCH);
3844                  }
3845                GETCHARINCTEST(c, eptr);
3846                prop_category = UCD_CATEGORY(c);
3847                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
3848                     c == CHAR_VT || c == CHAR_FF || c == CHAR_CR)
3849                       == prop_fail_result)
3850                  MRRETURN(MATCH_NOMATCH);
3851                }
3852              break;
3853    
3854              case PT_WORD:
3855              for (i = 1; i <= min; i++)
3856                {
3857                if (eptr >= md->end_subject)
3858                  {
3859                  SCHECK_PARTIAL();
3860                  MRRETURN(MATCH_NOMATCH);
3861                  }
3862                GETCHARINCTEST(c, eptr);
3863                prop_category = UCD_CATEGORY(c);
3864                if ((prop_category == ucp_L || prop_category == ucp_N ||
3865                     c == CHAR_UNDERSCORE)
3866                       == prop_fail_result)
3867                  MRRETURN(MATCH_NOMATCH);
3868                }
3869              break;
3870    
3871              /* This should not occur */
3872    
3873            default:            default:
3874            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
3875            }            }
# Line 3572  for (;;) Line 3954  for (;;)
3954            switch(c)            switch(c)
3955              {              {
3956              default: MRRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
3957    
3958              case 0x000d:              case 0x000d:
3959              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3960              break;              break;
# Line 3848  for (;;) Line 4231  for (;;)
4231            switch(*eptr++)            switch(*eptr++)
4232              {              {
4233              default: MRRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
4234    
4235              case 0x000d:              case 0x000d:
4236              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
4237              break;              break;
4238    
4239              case 0x000a:              case 0x000a:
4240              break;              break;
4241    
# Line 4040  for (;;) Line 4425  for (;;)
4425            case PT_ANY:            case PT_ANY:
4426            for (fi = min;; fi++)            for (fi = min;; fi++)
4427              {              {
4428              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM36);
4429              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4430              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4431              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4048  for (;;) Line 4433  for (;;)
4433                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4434                MRRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4435                }                }
4436              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
4437              if (prop_fail_result) MRRETURN(MATCH_NOMATCH);              if (prop_fail_result) MRRETURN(MATCH_NOMATCH);
4438              }              }
4439            /* Control never gets here */            /* Control never gets here */
# Line 4056  for (;;) Line 4441  for (;;)
4441            case PT_LAMP:            case PT_LAMP:
4442            for (fi = min;; fi++)            for (fi = min;; fi++)
4443              {              {
4444              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM37);
4445              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4446              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4447              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4064  for (;;) Line 4449  for (;;)
4449                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4450                MRRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4451                }                }
4452              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
4453              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
4454              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
4455                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
# Line 4076  for (;;) Line 4461  for (;;)
4461            case PT_GC:            case PT_GC:
4462            for (fi = min;; fi++)            for (fi = min;; fi++)
4463              {              {
4464              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM38);
4465              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4466              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4467              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4084  for (;;) Line 4469  for (;;)
4469                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4470                MRRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4471                }                }
4472              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
4473              prop_category = UCD_CATEGORY(c);              prop_category = UCD_CATEGORY(c);
4474              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
4475                MRRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
# Line 4094  for (;;) Line 4479  for (;;)
4479            case PT_PC:            case PT_PC:
4480            for (fi = min;; fi++)            for (fi = min;; fi++)
4481              {              {
4482              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM39);
4483              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4484              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4485              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4102  for (;;) Line 4487  for (;;)
4487                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4488                MRRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4489                }                }
4490              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
4491              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
4492              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
4493                MRRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
# Line 4112  for (;;) Line 4497  for (;;)
4497            case PT_SC:            case PT_SC:
4498            for (fi = min;; fi++)            for (fi = min;; fi++)
4499              {              {
4500              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM40);
4501              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4502              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4503              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
# Line 4120  for (;;) Line 4505  for (;;)
4505                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4506                MRRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4507                }                }
4508              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
4509              prop_script = UCD_SCRIPT(c);              prop_script = UCD_SCRIPT(c);
4510              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
4511                MRRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4512              }              }
4513            /* Control never gets here */            /* Control never gets here */
4514    
4515              case PT_ALNUM:
4516              for (fi = min;; fi++)
4517                {
4518                RMATCH(eptr, ecode, offset_top, md, eptrb, RM59);
4519                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4520                if (fi >= max) MRRETURN(MATCH_NOMATCH);
4521                if (eptr >= md->end_subject)
4522                  {
4523                  SCHECK_PARTIAL();
4524                  MRRETURN(MATCH_NOMATCH);
4525                  }
4526                GETCHARINCTEST(c, eptr);
4527                prop_category = UCD_CATEGORY(c);
4528                if ((prop_category == ucp_L || prop_category == ucp_N)
4529                       == prop_fail_result)
4530                  MRRETURN(MATCH_NOMATCH);
4531                }
4532              /* Control never gets here */
4533    
4534              case PT_SPACE:    /* Perl space */
4535              for (fi = min;; fi++)
4536                {
4537                RMATCH(eptr, ecode, offset_top, md, eptrb, RM60);
4538                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4539                if (fi >= max) MRRETURN(MATCH_NOMATCH);
4540                if (eptr >= md->end_subject)
4541                  {
4542                  SCHECK_PARTIAL();
4543                  MRRETURN(MATCH_NOMATCH);
4544                  }
4545                GETCHARINCTEST(c, eptr);
4546                prop_category = UCD_CATEGORY(c);
4547                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
4548                     c == CHAR_FF || c == CHAR_CR)
4549                       == prop_fail_result)
4550                  MRRETURN(MATCH_NOMATCH);
4551                }
4552              /* Control never gets here */
4553    
4554              case PT_PXSPACE:  /* POSIX space */
4555              for (fi = min;; fi++)
4556                {
4557                RMATCH(eptr, ecode, offset_top, md, eptrb, RM61);
4558                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4559                if (fi >= max) MRRETURN(MATCH_NOMATCH);
4560                if (eptr >= md->end_subject)
4561                  {
4562                  SCHECK_PARTIAL();
4563                  MRRETURN(MATCH_NOMATCH);
4564                  }
4565                GETCHARINCTEST(c, eptr);
4566                prop_category = UCD_CATEGORY(c);
4567                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
4568                     c == CHAR_VT || c == CHAR_FF || c == CHAR_CR)
4569                       == prop_fail_result)
4570                  MRRETURN(MATCH_NOMATCH);
4571                }
4572              /* Control never gets here */
4573    
4574              case PT_WORD:
4575              for (fi = min;; fi++)
4576                {
4577                RMATCH(eptr, ecode, offset_top, md, eptrb, RM62);
4578                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4579                if (fi >= max) MRRETURN(MATCH_NOMATCH);
4580                if (eptr >= md->end_subject)
4581                  {
4582                  SCHECK_PARTIAL();
4583                  MRRETURN(MATCH_NOMATCH);
4584                  }
4585                GETCHARINCTEST(c, eptr);
4586                prop_category = UCD_CATEGORY(c);
4587                if ((prop_category == ucp_L ||
4588                     prop_category == ucp_N ||
4589                     c == CHAR_UNDERSCORE)
4590                       == prop_fail_result)
4591                  MRRETURN(MATCH_NOMATCH);
4592                }
4593              /* Control never gets here */
4594    
4595              /* This should never occur */
4596    
4597            default:            default:
4598            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
4599            }            }
# Line 4139  for (;;) Line 4606  for (;;)
4606          {          {
4607          for (fi = min;; fi++)          for (fi = min;; fi++)
4608            {            {
4609            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM41);
4610            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4611            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
4612            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
# Line 4171  for (;;) Line 4638  for (;;)
4638          {          {
4639          for (fi = min;; fi++)          for (fi = min;; fi++)
4640            {            {
4641            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM42);
4642            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4643            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
4644            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
# Line 4334  for (;;) Line 4801  for (;;)
4801          {          {
4802          for (fi = min;; fi++)          for (fi = min;; fi++)
4803            {            {
4804            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM43);
4805            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4806            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
4807            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
# Line 4473  for (;;) Line 4940  for (;;)
4940                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4941                break;                break;
4942                }                }
4943              GETCHARLEN(c, eptr, len);              GETCHARLENTEST(c, eptr, len);
4944              if (prop_fail_result) break;              if (prop_fail_result) break;
4945              eptr+= len;              eptr+= len;
4946              }              }
# Line 4488  for (;;) Line 4955  for (;;)
4955                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4956                break;                break;
4957                }                }
4958              GETCHARLEN(c, eptr, len);              GETCHARLENTEST(c, eptr, len);
4959              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
4960              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
4961                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
# Line 4507  for (;;) Line 4974  for (;;)
4974                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4975                break;                break;
4976                }                }
4977              GETCHARLEN(c, eptr, len);              GETCHARLENTEST(c, eptr, len);
4978              prop_category = UCD_CATEGORY(c);              prop_category = UCD_CATEGORY(c);
4979              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
4980                break;                break;
# Line 4524  for (;;) Line 4991  for (;;)
4991                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4992                break;                break;
4993                }                }
4994              GETCHARLEN(c, eptr, len);              GETCHARLENTEST(c, eptr, len);
4995              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
4996              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
4997                break;                break;
# Line 4541  for (;;) Line 5008  for (;;)
5008                SCHECK_PARTIAL();                SCHECK_PARTIAL();
5009                break;                break;
5010                }                }
5011              GETCHARLEN(c, eptr, len);              GETCHARLENTEST(c, eptr, len);
5012              prop_script = UCD_SCRIPT(c);              prop_script = UCD_SCRIPT(c);
5013              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
5014                break;                break;
5015              eptr+= len;              eptr+= len;
5016              }              }
5017            break;            break;
5018    
5019              case PT_ALNUM:
5020              for (i = min; i < max; i++)
5021                {
5022                int len = 1;
5023                if (eptr >= md->end_subject)
5024                  {
5025                  SCHECK_PARTIAL();
5026                  break;
5027                  }
5028                GETCHARLENTEST(c, eptr, len);
5029                prop_category = UCD_CATEGORY(c);
5030                if ((prop_category == ucp_L || prop_category == ucp_N)
5031                     == prop_fail_result)
5032                  break;
5033                eptr+= len;
5034                }
5035              break;
5036    
5037              case PT_SPACE:    /* Perl space */
5038              for (i = min; i < max; i++)
5039                {
5040                int len = 1;
5041                if (eptr >= md->end_subject)
5042                  {
5043                  SCHECK_PARTIAL();
5044                  break;
5045                  }
5046                GETCHARLENTEST(c, eptr, len);
5047                prop_category = UCD_CATEGORY(c);
5048                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
5049                     c == CHAR_FF || c == CHAR_CR)
5050                     == prop_fail_result)
5051                  break;
5052                eptr+= len;
5053                }
5054              break;
5055    
5056              case PT_PXSPACE:  /* POSIX space */
5057              for (i = min; i < max; i++)
5058                {
5059                int len = 1;
5060                if (eptr >= md->end_subject)
5061                  {
5062                  SCHECK_PARTIAL();
5063                  break;
5064                  }
5065                GETCHARLENTEST(c, eptr, len);
5066                prop_category = UCD_CATEGORY(c);
5067                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
5068                     c == CHAR_VT || c == CHAR_FF || c == CHAR_CR)
5069                     == prop_fail_result)
5070                  break;
5071                eptr+= len;
5072                }
5073              break;
5074    
5075              case PT_WORD:
5076              for (i = min; i < max; i++)
5077                {
5078                int len = 1;
5079                if (eptr >= md->end_subject)
5080                  {
5081                  SCHECK_PARTIAL();
5082                  break;
5083                  }
5084                GETCHARLENTEST(c, eptr, len);
5085                prop_category = UCD_CATEGORY(c);
5086                if ((prop_category == ucp_L || prop_category == ucp_N ||
5087                     c == CHAR_UNDERSCORE) == prop_fail_result)
5088                  break;
5089                eptr+= len;
5090                }
5091              break;
5092    
5093              default:
5094              RRETURN(PCRE_ERROR_INTERNAL);
5095            }            }
5096    
5097          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
# Line 4555  for (;;) Line 5099  for (;;)
5099          if (possessive) continue;          if (possessive) continue;
5100          for(;;)          for(;;)
5101            {            {
5102            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM44);
5103            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5104            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
5105            if (utf8) BACKCHAR(eptr);            if (utf8) BACKCHAR(eptr);
# Line 4596  for (;;) Line 5140  for (;;)
5140    
5141          for(;;)          for(;;)
5142            {            {
5143            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM45);
5144            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5145            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
5146            for (;;)                        /* Move back over one extended */            for (;;)                        /* Move back over one extended */
# Line 4880  for (;;) Line 5424  for (;;)
5424            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
5425            }            }
5426    
5427          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run. If possessive, we are
5428            done (no backing up). Otherwise, match at this position; anything other
5429            than no match is immediately returned. For nomatch, back up one
5430            character, unless we are matching \R and the last thing matched was
5431            \r\n, in which case, back up two bytes. */
5432    
5433          if (possessive) continue;          if (possessive) continue;
5434          for(;;)          for(;;)
5435            {            {
5436            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM46);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM46);
5437            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5438            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
5439            BACKCHAR(eptr);            BACKCHAR(eptr);
5440              if (ctype == OP_ANYNL && eptr > pp  && *eptr == '\n' &&
5441                  eptr[-1] == '\r') eptr--;
5442            }            }
5443          }          }
5444        else        else
# Line 5087  for (;;) Line 5637  for (;;)
5637            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
5638            }            }
5639    
5640          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run. If possessive, we are
5641            done (no backing up). Otherwise, match at this position; anything other
5642            than no match is immediately returned. For nomatch, back up one
5643            character (byte), unless we are matching \R and the last thing matched
5644            was \r\n, in which case, back up two bytes. */
5645    
5646          if (possessive) continue;          if (possessive) continue;
5647          while (eptr >= pp)          while (eptr >= pp)
5648            {            {
5649            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM47);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM47);
           eptr--;  
5650            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5651              eptr--;
5652              if (ctype == OP_ANYNL && eptr > pp  && *eptr == '\n' &&
5653                  eptr[-1] == '\r') eptr--;
5654            }            }
5655          }          }
5656    
# Line 5133  switch (frame->Xwhere) Line 5689  switch (frame->Xwhere)
5689    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)
5690    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)
5691    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)
5692    LBL(53) LBL(54)    LBL(53) LBL(54) LBL(55) LBL(56) LBL(57) LBL(58) LBL(63)
5693  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
5694    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)
5695    LBL(32) LBL(34) LBL(42) LBL(46)    LBL(32) LBL(34) LBL(42) LBL(46)
5696  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
5697    LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)    LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
5698      LBL(59) LBL(60) LBL(61) LBL(62)
5699  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
5700  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF8 */
5701    default:    default:
# Line 5161  Undefine all the macros that were define Line 5718  Undefine all the macros that were define
5718  #undef ecode  #undef ecode
5719  #undef mstart  #undef mstart
5720  #undef offset_top  #undef offset_top
 #undef ims  
5721  #undef eptrb  #undef eptrb
5722  #undef flags  #undef flags
5723    
# Line 5179  Undefine all the macros that were define Line 5735  Undefine all the macros that were define
5735  #undef condition  #undef condition
5736  #undef prev_is_word  #undef prev_is_word
5737    
 #undef original_ims  
   
5738  #undef ctype  #undef ctype
5739  #undef length  #undef length
5740  #undef max  #undef max
# Line 5242  int first_byte = -1; Line 5796  int first_byte = -1;
5796  int req_byte = -1;  int req_byte = -1;
5797  int req_byte2 = -1;  int req_byte2 = -1;
5798  int newline;  int newline;
 unsigned long int ims;  
5799  BOOL using_temporary_offsets = FALSE;  BOOL using_temporary_offsets = FALSE;
5800  BOOL anchored;  BOOL anchored;
5801  BOOL startline;  BOOL startline;
# Line 5272  if ((options & ~PUBLIC_EXEC_OPTIONS) != Line 5825  if ((options & ~PUBLIC_EXEC_OPTIONS) !=
5825  if (re == NULL || subject == NULL ||  if (re == NULL || subject == NULL ||
5826     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;
5827  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
5828    if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET;
5829    
5830  /* This information is for finding all the numbers associated with a given  /* This information is for finding all the numbers associated with a given
5831  name, for condition testing. */  name, for condition testing. */
# Line 5342  end_subject = md->end_subject; Line 5896  end_subject = md->end_subject;
5896    
5897  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
5898  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
5899    md->use_ucp = (re->options & PCRE_UCP) != 0;
5900  md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;  md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
5901    
5902  md->notbol = (options & PCRE_NOTBOL) != 0;  md->notbol = (options & PCRE_NOTBOL) != 0;
# Line 5431  defined (though never set). So there's n Line 5986  defined (though never set). So there's n
5986  if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)  if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
5987    return PCRE_ERROR_BADPARTIAL;    return PCRE_ERROR_BADPARTIAL;
5988    
5989  /* 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
5990  back the character offset. */  code for an invalid string if a results vector is available. */
5991    
5992  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
5993  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
5994    {    {
5995    if (_pcre_valid_utf8((USPTR)subject, length) >= 0)    int erroroffset;
5996      return PCRE_ERROR_BADUTF8;    int errorcode = _pcre_valid_utf8((USPTR)subject, length, &erroroffset);
5997    if (start_offset > 0 && start_offset < length)    if (errorcode != 0)
5998      {      {
5999      int tb = ((USPTR)subject)[start_offset];      if (offsetcount >= 2)
     if (tb > 127)  
6000        {        {
6001        tb &= 0xc0;        offsets[0] = erroroffset;
6002        if (tb != 0 && tb != 0xc0) return PCRE_ERROR_BADUTF8_OFFSET;        offsets[1] = errorcode;
6003        }        }
6004      }      return (errorcode <= PCRE_UTF8_ERR5 && md->partial > 1)?
6005          PCRE_ERROR_SHORTUTF8 : PCRE_ERROR_BADUTF8;
6006        }
6007    
6008      /* Check that a start_offset points to the start of a UTF-8 character. */
6009    
6010      if (start_offset > 0 && start_offset < length &&
6011          (((USPTR)subject)[start_offset] & 0xc0) == 0x80)
6012        return PCRE_ERROR_BADUTF8_OFFSET;
6013    }    }
6014  #endif  #endif
6015    
 /* 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);  
   
6016  /* 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
6017  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.
6018  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 5574  for(;;) Line 6130  for(;;)
6130    /* There are some optimizations that avoid running the match if a known    /* There are some optimizations that avoid running the match if a known
6131    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.
6132    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
6133    that all callouts do actually occur. */    that all callouts do actually occur. The option can be set in the regex by
6134      (*NO_START_OPT) or passed in match-time options. */
6135    
6136    if ((options & PCRE_NO_START_OPTIMIZE) == 0)    if (((options | re->options) & PCRE_NO_START_OPTIMIZE) == 0)
6137      {      {
6138      /* Advance to a unique first byte if there is one. */      /* Advance to a unique first byte if there is one. */
6139    
# Line 5630  for(;;) Line 6187  for(;;)
6187        while (start_match < end_subject)        while (start_match < end_subject)
6188          {          {
6189          register unsigned int c = *start_match;          register unsigned int c = *start_match;
6190          if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++;          if ((start_bits[c/8] & (1 << (c&7))) == 0)
6191            else break;            {
6192              start_match++;
6193    #ifdef SUPPORT_UTF8
6194              if (utf8)
6195                while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
6196                  start_match++;
6197    #endif
6198              }
6199            else break;
6200          }          }
6201        }        }
6202      }   /* Starting optimizations */      }   /* Starting optimizations */
# Line 5722  for(;;) Line 6287  for(;;)
6287    
6288    /* OK, we can now run the match. If "hitend" is set afterwards, remember the    /* OK, we can now run the match. If "hitend" is set afterwards, remember the
6289    first starting point for which a partial match was found. */    first starting point for which a partial match was found. */
6290    
6291    md->start_match_ptr = start_match;    md->start_match_ptr = start_match;
6292    md->start_used_ptr = start_match;    md->start_used_ptr = start_match;
6293    md->match_call_count = 0;    md->match_call_count = 0;
6294    rc = match(start_match, md->start_code, start_match, NULL, 2, md, ims, NULL,    md->match_function_type = 0;
6295      0, 0);    rc = match(start_match, md->start_code, start_match, NULL, 2, md, NULL, 0);
6296    if (md->hitend && start_partial == NULL) start_partial = md->start_used_ptr;    if (md->hitend && start_partial == NULL) start_partial = md->start_used_ptr;
6297    
6298    switch(rc)    switch(rc)
6299      {      {
6300      /* 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
6301      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. */
6302      We treat this as NOMATCH. THEN at this level acts exactly like PRUNE. */  
6303        case MATCH_SKIP:
6304        if (md->start_match_ptr != start_match)
6305          {
6306          new_start_match = md->start_match_ptr;
6307          break;
6308          }
6309        /* Fall through */
6310    
6311        /* If MATCH_SKIP_ARG reaches this level it means that a MARK that matched
6312        the SKIP's arg was not found. We also treat this as NOMATCH. */
6313    
6314        case MATCH_SKIP_ARG:
6315        /* Fall through */
6316    
6317        /* NOMATCH and PRUNE advance by one character. THEN at this level acts
6318        exactly like PRUNE. */
6319    
6320      case MATCH_NOMATCH:      case MATCH_NOMATCH:
6321      case MATCH_PRUNE:      case MATCH_PRUNE:
     case MATCH_SKIP_ARG:  
6322      case MATCH_THEN:      case MATCH_THEN:
6323      new_start_match = start_match + 1;      new_start_match = start_match + 1;
6324  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 5748  for(;;) Line 6328  for(;;)
6328  #endif  #endif
6329      break;      break;
6330    
     /* SKIP passes back the next starting point explicitly. */  
   
     case MATCH_SKIP:  
     new_start_match = md->start_match_ptr;  
     break;  
   
6331      /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */      /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */
6332    
6333      case MATCH_COMMIT:      case MATCH_COMMIT:
# Line 5841  if (rc == MATCH_MATCH || rc == MATCH_ACC Line 6415  if (rc == MATCH_MATCH || rc == MATCH_ACC
6415    
6416    /* 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
6417    too many to fit into the vector. */    too many to fit into the vector. */
6418    
6419    rc = md->offset_overflow? 0 : md->end_offset_top/2;    rc = md->offset_overflow? 0 : md->end_offset_top/2;
6420    
6421    /* 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
# Line 5850  if (rc == MATCH_MATCH || rc == MATCH_ACC Line 6424  if (rc == MATCH_MATCH || rc == MATCH_ACC
6424    
6425    if (offsetcount < 2) rc = 0; else    if (offsetcount < 2) rc = 0; else
6426      {      {
6427      offsets[0] = md->start_match_ptr - md->start_subject;      offsets[0] = (int)(md->start_match_ptr - md->start_subject);
6428      offsets[1] = md->end_match_ptr - md->start_subject;      offsets[1] = (int)(md->end_match_ptr - md->start_subject);
6429      }      }
6430    
6431    DPRINTF((">>>> returning %d\n", rc));    DPRINTF((">>>> returning %d\n", rc));
# Line 5866  if (using_temporary_offsets) Line 6440  if (using_temporary_offsets)
6440    DPRINTF(("Freeing temporary memory\n"));    DPRINTF(("Freeing temporary memory\n"));
6441    (pcre_free)(md->offset_vector);    (pcre_free)(md->offset_vector);
6442    }    }
6443    
6444  /* For anything other than nomatch or partial match, just return the code. */  /* For anything other than nomatch or partial match, just return the code. */
6445    
6446  if (rc != MATCH_NOMATCH && rc != PCRE_ERROR_PARTIAL)  if (rc != MATCH_NOMATCH && rc != PCRE_ERROR_PARTIAL)
6447    {    {
6448    DPRINTF((">>>> error: returning %d\n", rc));    DPRINTF((">>>> error: returning %d\n", rc));
6449    return rc;    return rc;
6450    }    }
6451    
6452  /* Handle partial matches - disable any mark data */  /* Handle partial matches - disable any mark data */
6453    
6454  if (start_partial != NULL)  if (start_partial != NULL)
6455    {    {
6456    DPRINTF((">>>> returning PCRE_ERROR_PARTIAL\n"));    DPRINTF((">>>> returning PCRE_ERROR_PARTIAL\n"));
6457    md->mark = NULL;    md->mark = NULL;
6458    if (offsetcount > 1)    if (offsetcount > 1)
6459      {      {
6460      offsets[0] = start_partial - (USPTR)subject;      offsets[0] = (int)(start_partial - (USPTR)subject);
6461      offsets[1] = end_subject - (USPTR)subject;      offsets[1] = (int)(end_subject - (USPTR)subject);
6462      }      }
6463    rc = PCRE_ERROR_PARTIAL;    rc = PCRE_ERROR_PARTIAL;
6464    }    }
6465    
6466  /* This is the classic nomatch case */  /* This is the classic nomatch case */
6467    
6468  else  else
6469    {    {
6470    DPRINTF((">>>> returning PCRE_ERROR_NOMATCH\n"));    DPRINTF((">>>> returning PCRE_ERROR_NOMATCH\n"));
6471    rc = PCRE_ERROR_NOMATCH;    rc = PCRE_ERROR_NOMATCH;
6472    }    }
6473    
6474  /* Return the MARK data if it has been requested. */  /* Return the MARK data if it has been requested. */
6475    
6476  RETURN_MARK:  RETURN_MARK:
6477    
6478  if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_MARK) != 0)  if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_MARK) != 0)
6479    *(extra_data->mark) = (unsigned char *)(md->mark);    *(extra_data->mark) = (unsigned char *)(md->mark);
6480  return rc;  return rc;
6481  }  }
6482    
6483  /* End of pcre_exec.c */  /* End of pcre_exec.c */

Legend:
Removed from v.511  
changed lines
  Added in v.610

  ViewVC Help
Powered by ViewVC 1.1.5