/[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 501 by ph10, Sun Mar 7 11:49:54 2010 UTC revision 617 by ph10, Tue Jul 12 11:00:10 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 71  defined PCRE_ERROR_xxx codes, which are Line 73  defined PCRE_ERROR_xxx codes, which are
73  /* Special internal returns from the match() function. Make them sufficiently  /* Special internal returns from the match() function. Make them sufficiently
74  negative to avoid the external error codes. */  negative to avoid the external error codes. */
75    
76  #define MATCH_COMMIT       (-999)  #define MATCH_ACCEPT       (-999)
77  #define MATCH_PRUNE        (-998)  #define MATCH_COMMIT       (-998)
78  #define MATCH_SKIP         (-997)  #define MATCH_KETRPOS      (-997)
79  #define MATCH_THEN         (-996)  #define MATCH_PRUNE        (-996)
80    #define MATCH_SKIP         (-995)
81    #define MATCH_SKIP_ARG     (-994)
82    #define MATCH_THEN         (-993)
83    
84    /* This is a convenience macro for code that occurs many times. */
85    
86    #define MRRETURN(ra) \
87      { \
88      md->mark = markptr; \
89      RRETURN(ra); \
90      }
91    
92  /* Maximum number of ints of offset to save on the stack for recursive calls.  /* Maximum number of ints of offset to save on the stack for recursive calls.
93  If the offset vector is bigger, malloc is used. This should be a multiple of 3,  If the offset vector is bigger, malloc is used. This should be a multiple of 3,
# Line 122  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 154  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 183  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 245  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 255  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 267  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 281  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 304  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 328  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 351  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 410  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) RRETURN(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) RRETURN(PCRE_ERROR_PARTIAL);\      if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL); \
451      }      }
452    
453    
# Line 437  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
472                 MATCH_NOMATCH if failed to match  )                 MATCH_NOMATCH if failed to match  )
473                   a negative MATCH_xxx value for PRUNE, SKIP, etc
474                 a negative PCRE_ERROR_xxx value if aborted by an error condition                 a negative PCRE_ERROR_xxx value if aborted by an error condition
475                   (e.g. stopped by repeated call or recursion limit)                   (e.g. stopped by repeated call or recursion limit)
476  */  */
477    
478  static int  static int
479  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart, USPTR  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart,
480    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 467  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 475  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 485  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 501  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 525  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 563  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 608  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 644  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 668  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:
712        markptr = ecode + 2;
713        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
714          eptrb, RM55);
715    
716        /* 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
718        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
720        position and return MATCH_SKIP. Otherwise, pass back the return code
721        unaltered. */
722    
723        if (rrc == MATCH_SKIP_ARG &&
724            strcmp((char *)markptr, (char *)(md->start_match_ptr)) == 0)
725          {
726          md->start_match_ptr = eptr;
727          RRETURN(MATCH_SKIP);
728          }
729    
730        if (md->mark == NULL) md->mark = markptr;
731        RRETURN(rrc);
732    
733      case OP_FAIL:      case OP_FAIL:
734      RRETURN(MATCH_NOMATCH);      MRRETURN(MATCH_NOMATCH);
735    
736        /* COMMIT overrides PRUNE, SKIP, and THEN */
737    
738        case OP_COMMIT:
739        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
740          eptrb, RM52);
741        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);
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);
754    
755        case OP_PRUNE_ARG:
756        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
757          eptrb, RM56);
758        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
759        md->mark = ecode + 2;
760      RRETURN(MATCH_PRUNE);      RRETURN(MATCH_PRUNE);
761    
762      case OP_COMMIT:      /* SKIP overrides PRUNE and THEN */
     RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,  
       ims, eptrb, flags, RM52);  
     if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
     RRETURN(MATCH_COMMIT);  
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      RRETURN(MATCH_SKIP);      MRRETURN(MATCH_SKIP);
771    
772        case OP_SKIP_ARG:
773        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
774          eptrb, RM57);
775        if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)
776          RRETURN(rrc);
777    
778        /* Pass back the current skip name by overloading md->start_match_ptr and
779        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. */
782    
783        md->start_match_ptr = ecode + 2;
784        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);
795        md->start_match_ptr = ecode - GET(ecode, 1);
796        MRRETURN(MATCH_THEN);
797    
798        case OP_THEN_ARG:
799        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1+LINK_SIZE],
800          offset_top, md, eptrb, RM58);
801      if (rrc != MATCH_NOMATCH) RRETURN(rrc);      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
802        md->start_match_ptr = ecode - GET(ecode, 1);
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. A failure to match might occur after the group has succeeded,
812      If the bracket fails to match, we need to restore this value and also the      if something later on doesn't match. For this reason, we need to restore
813      values of the final offsets, in case they were set by a previous iteration      the working value and also the values of the final offsets, in case they
814      of the same bracket.      were set by a previous iteration of the same bracket.
815    
816      If there isn't enough space in the offset vector, treat this as if it were      If there isn't enough space in the offset vector, treat this as if it were
817      a non-capturing bracket. Don't worry about setting the flag for the error      a non-capturing bracket. Don't worry about setting the flag for the error
# Line 717  for (;;) Line 821  for (;;)
821      case OP_SCBRA:      case OP_SCBRA:
822      number = GET2(ecode, 1+LINK_SIZE);      number = GET2(ecode, 1+LINK_SIZE);
823      offset = number << 1;      offset = number << 1;
824    
825  #ifdef PCRE_DEBUG  #ifdef PCRE_DEBUG
826      printf("start bracket %d\n", number);      printf("start bracket %d\n", number);
827      printf("subject=");      printf("subject=");
# Line 733  for (;;) Line 837  for (;;)
837        save_capture_last = md->capture_last;        save_capture_last = md->capture_last;
838    
839        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
840        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;        md->offset_vector[md->offset_end - number] =
841            (int)(eptr - md->start_subject);
842    
843        flags = (op == OP_SCBRA)? match_cbegroup : 0;        for (;;)
       do  
844          {          {
845          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,          if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
846            ims, eptrb, flags, RM1);          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
847          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);            eptrb, RM1);
848            if (rrc != MATCH_NOMATCH &&
849                (rrc != MATCH_THEN || md->start_match_ptr != ecode))
850              RRETURN(rrc);
851          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
852          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
853            if (*ecode != OP_ALT) break;
854          }          }
       while (*ecode == OP_ALT);  
855    
856        DPRINTF(("bracket %d failed\n", number));        DPRINTF(("bracket %d failed\n", number));
857    
# Line 752  for (;;) Line 859  for (;;)
859        md->offset_vector[offset+1] = save_offset2;        md->offset_vector[offset+1] = save_offset2;
860        md->offset_vector[md->offset_end - number] = save_offset3;        md->offset_vector[md->offset_end - number] = save_offset3;
861    
862          if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr;
863        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
864        }        }
865    
# Line 766  for (;;) Line 874  for (;;)
874      /* VVVVVVVVVVVVVVVVVVVVVVVVV */      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
875      /* VVVVVVVVVVVVVVVVVVVVVVVVV */      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
876    
877      /* Non-capturing bracket. Loop for all the alternatives. When we get to the      /* Non-capturing bracket, except for possessive with unlimited repeat. Loop
878      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
879      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()
880      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
881      is set.*/      into a tail recursion, except in the case of a possibly empty group.
882        However, now that there is the possiblity of (*THEN) occurring in the final
883        alternative, this optimization is no longer possible. */
884    
885      case OP_BRA:      case OP_BRA:
886      case OP_SBRA:      case OP_SBRA:
887      DPRINTF(("start non-capturing bracket\n"));      DPRINTF(("start non-capturing bracket\n"));
     flags = (op >= OP_SBRA)? match_cbegroup : 0;  
888      for (;;)      for (;;)
889        {        {
890        if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */        if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
891          {        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, eptrb,
892          if (flags == 0)    /* Not a possibly empty group */          RM2);
893            {        if (rrc != MATCH_NOMATCH &&
894            ecode += _pcre_OP_lengths[*ecode];            (rrc != MATCH_THEN || md->start_match_ptr != ecode))
895            DPRINTF(("bracket 0 tail recursion\n"));          RRETURN(rrc);
896            goto TAIL_RECURSE;        ecode += GET(ecode, 1);
897            }        if (*ecode != OP_ALT) break;
898          }
899    
900          /* Possibly empty group; can't use tail recursion. */      if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr;
901        RRETURN(MATCH_NOMATCH);
902    
903          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,      /* Handle possessive capturing brackets with an unlimited repeat. We come
904            eptrb, flags, RM48);      here from BRAZERO with allow_zero set TRUE. The offset_vector values are
905          RRETURN(rrc);      handled similarly to the normal case above. However, the matching is
906        different. The end of these brackets will always be OP_KETRPOS, which
907        returns MATCH_KETRPOS without going further in the pattern. By this means
908        we can handle the group by iteration rather than recursion, thereby
909        reducing the amount of stack needed. */
910    
911        case OP_CBRAPOS:
912        case OP_SCBRAPOS:
913        allow_zero = FALSE;
914    
915        POSSESSIVE_CAPTURE:
916        number = GET2(ecode, 1+LINK_SIZE);
917        offset = number << 1;
918    
919    #ifdef PCRE_DEBUG
920        printf("start possessive bracket %d\n", number);
921        printf("subject=");
922        pchars(eptr, 16, TRUE, md);
923        printf("\n");
924    #endif
925    
926        if (offset < md->offset_max)
927          {
928          matched_once = FALSE;
929          code_offset = ecode - md->start_code;
930    
931          save_offset1 = md->offset_vector[offset];
932          save_offset2 = md->offset_vector[offset+1];
933          save_offset3 = md->offset_vector[md->offset_end - number];
934          save_capture_last = md->capture_last;
935    
936          DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
937    
938          /* Each time round the loop, save the current subject position for use
939          when the group matches. For MATCH_MATCH, the group has matched, so we
940          restart it with a new subject starting position, remembering that we had
941          at least one match. For MATCH_NOMATCH, carry on with the alternatives, as
942          usual. If we haven't matched any alternatives in any iteration, check to
943          see if a previous iteration matched. If so, the group has matched;
944          continue from afterwards. Otherwise it has failed; restore the previous
945          capture values before returning NOMATCH. */
946    
947          for (;;)
948            {
949            md->offset_vector[md->offset_end - number] =
950              (int)(eptr - md->start_subject);
951            if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
952            RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
953              eptrb, RM63);
954            if (rrc == MATCH_KETRPOS)
955              {
956              offset_top = md->end_offset_top;
957              eptr = md->end_match_ptr;
958              ecode = md->start_code + code_offset;
959              save_capture_last = md->capture_last;
960              matched_once = TRUE;
961              continue;
962              }
963            if (rrc != MATCH_NOMATCH &&
964                (rrc != MATCH_THEN || md->start_match_ptr != ecode))
965              RRETURN(rrc);
966            md->capture_last = save_capture_last;
967            ecode += GET(ecode, 1);
968            if (*ecode != OP_ALT) break;
969          }          }
970    
971        /* For non-final alternatives, continue the loop for a NOMATCH result;        if (!matched_once)
972        otherwise return. */          {
973            md->offset_vector[offset] = save_offset1;
974            md->offset_vector[offset+1] = save_offset2;
975            md->offset_vector[md->offset_end - number] = save_offset3;
976            }
977    
978          if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr;
979          if (allow_zero || matched_once)
980            {
981            ecode += 1 + LINK_SIZE;
982            break;
983            }
984    
985          RRETURN(MATCH_NOMATCH);
986          }
987    
988        /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
989        as a non-capturing bracket. */
990    
991        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
992        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
993    
994        DPRINTF(("insufficient capture room: treat as non-capturing\n"));
995    
996        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
997        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
998    
999        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,      /* Non-capturing possessive bracket with unlimited repeat. We come here
1000          eptrb, flags, RM2);      from BRAZERO with allow_zero = TRUE. The code is similar to the above,
1001        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);      without the capturing complication. It is written out separately for speed
1002        and cleanliness. */
1003    
1004        case OP_BRAPOS:
1005        case OP_SBRAPOS:
1006        allow_zero = FALSE;
1007    
1008        POSSESSIVE_NON_CAPTURE:
1009        matched_once = FALSE;
1010        code_offset = ecode - md->start_code;
1011    
1012        for (;;)
1013          {
1014          if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
1015          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
1016            eptrb, RM48);
1017          if (rrc == MATCH_KETRPOS)
1018            {
1019            offset_top = md->end_offset_top;
1020            eptr = md->end_match_ptr;
1021            ecode = md->start_code + code_offset;
1022            matched_once = TRUE;
1023            continue;
1024            }
1025          if (rrc != MATCH_NOMATCH &&
1026              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1027            RRETURN(rrc);
1028        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1029          if (*ecode != OP_ALT) break;
1030        }        }
1031    
1032        if (matched_once || allow_zero)
1033          {
1034          ecode += 1 + LINK_SIZE;
1035          break;
1036          }
1037        RRETURN(MATCH_NOMATCH);
1038    
1039      /* Control never reaches here. */      /* Control never reaches here. */
1040    
1041      /* Conditional group: compilation checked that there are no more than      /* Conditional group: compilation checked that there are no more than
1042      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
1043      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
1044      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. */  
1045    
1046      case OP_COND:      case OP_COND:
1047      case OP_SCOND:      case OP_SCOND:
1048      codelink= GET(ecode, 1);      codelink = GET(ecode, 1);
1049    
1050      /* 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
1051      inserted between OP_COND and an assertion condition. */      inserted between OP_COND and an assertion condition. */
# Line 826  for (;;) Line 1059  for (;;)
1059          cb.callout_number   = ecode[LINK_SIZE+2];          cb.callout_number   = ecode[LINK_SIZE+2];
1060          cb.offset_vector    = md->offset_vector;          cb.offset_vector    = md->offset_vector;
1061          cb.subject          = (PCRE_SPTR)md->start_subject;          cb.subject          = (PCRE_SPTR)md->start_subject;
1062          cb.subject_length   = md->end_subject - md->start_subject;          cb.subject_length   = (int)(md->end_subject - md->start_subject);
1063          cb.start_match      = mstart - md->start_subject;          cb.start_match      = (int)(mstart - md->start_subject);
1064          cb.current_position = eptr - md->start_subject;          cb.current_position = (int)(eptr - md->start_subject);
1065          cb.pattern_position = GET(ecode, LINK_SIZE + 3);          cb.pattern_position = GET(ecode, LINK_SIZE + 3);
1066          cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);          cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
1067          cb.capture_top      = offset_top/2;          cb.capture_top      = offset_top/2;
1068          cb.capture_last     = md->capture_last;          cb.capture_last     = md->capture_last;
1069          cb.callout_data     = md->callout_data;          cb.callout_data     = md->callout_data;
1070          if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);          if ((rrc = (*pcre_callout)(&cb)) > 0) MRRETURN(MATCH_NOMATCH);
1071          if (rrc < 0) RRETURN(rrc);          if (rrc < 0) RRETURN(rrc);
1072          }          }
1073        ecode += _pcre_OP_lengths[OP_CALLOUT];        ecode += _pcre_OP_lengths[OP_CALLOUT];
# Line 987  for (;;) Line 1220  for (;;)
1220        }        }
1221    
1222      /* The condition is an assertion. Call match() to evaluate it - setting      /* The condition is an assertion. Call match() to evaluate it - setting
1223      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
1224      assertion. */      an assertion. */
1225    
1226      else      else
1227        {        {
1228        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        md->match_function_type = MATCH_CONDASSERT;
1229            match_condassert, RM3);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM3);
1230        if (rrc == MATCH_MATCH)        if (rrc == MATCH_MATCH)
1231          {          {
1232          condition = TRUE;          condition = TRUE;
1233          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
1234          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
1235          }          }
1236        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)        else if (rrc != MATCH_NOMATCH &&
1237                  (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1238          {          {
1239          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
1240          }          }
# Line 1012  for (;;) Line 1246  for (;;)
1246        }        }
1247    
1248      /* 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,
1249      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
1250      match_cbegroup is required for an unlimited repeat of a possibly empty      when there was unlimited repeat of a possibly empty group. However, that
1251      group. If the second alternative doesn't exist, we can just plough on. */      strategy no longer works because of the possibilty of (*THEN) being
1252        encountered in the branch. A recursive call to match() is always required,
1253        unless the second alternative doesn't exist, in which case we can just
1254        plough on. */
1255    
1256      if (condition || *ecode == OP_ALT)      if (condition || *ecode == OP_ALT)
1257        {        {
1258        ecode += 1 + LINK_SIZE;        if (op == OP_SCOND) md->match_function_type = MATCH_CBEGROUP;
1259        if (op == OP_SCOND)        /* Possibly empty group */        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM49);
1260          {        if (rrc == MATCH_THEN && md->start_match_ptr == ecode)
1261          RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);          rrc = MATCH_NOMATCH;
1262          RRETURN(rrc);        RRETURN(rrc);
         }  
       else                       /* Group must match something */  
         {  
         flags = 0;  
         goto TAIL_RECURSE;  
         }  
1263        }        }
1264      else                         /* Condition false & no alternative */      else                         /* Condition false & no alternative */
1265        {        {
# Line 1054  for (;;) Line 1285  for (;;)
1285        {        {
1286        md->offset_vector[offset] =        md->offset_vector[offset] =
1287          md->offset_vector[md->offset_end - number];          md->offset_vector[md->offset_end - number];
1288        md->offset_vector[offset+1] = eptr - md->start_subject;        md->offset_vector[offset+1] = (int)(eptr - md->start_subject);
1289        if (offset_top <= offset) offset_top = offset + 2;        if (offset_top <= offset) offset_top = offset + 2;
1290        }        }
1291      ecode += 3;      ecode += 3;
1292      break;      break;
1293    
1294    
1295      /* 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
1296      recursion, we should restore the offsets appropriately and continue from      should restore the offsets appropriately, and if it's a top-level
1297      after the call. */      recursion, continue from after the call. */
1298    
1299      case OP_ACCEPT:      case OP_ACCEPT:
1300        case OP_ASSERT_ACCEPT:
1301      case OP_END:      case OP_END:
1302      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL)
1303        {        {
1304        recursion_info *rec = md->recursive;        recursion_info *rec = md->recursive;
       DPRINTF(("End of pattern in a (?0) recursion\n"));  
1305        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
1306        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
1307          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
1308        offset_top = rec->save_offset_top;        offset_top = rec->save_offset_top;
1309        ims = original_ims;        if (rec->group_num == 0)
1310        ecode = rec->after_call;          {
1311        break;          ecode = rec->after_call;
1312            break;
1313            }
1314        }        }
1315    
1316      /* Otherwise, if we have matched an empty string, fail if PCRE_NOTEMPTY is      /* Otherwise, if we have matched an empty string, fail if not in an
1317      set, or if PCRE_NOTEMPTY_ATSTART is set and we have matched at the start of      assertion and if either PCRE_NOTEMPTY is set, or if PCRE_NOTEMPTY_ATSTART
1318      the subject. In both cases, backtracking will then try other alternatives,      is set and we have matched at the start of the subject. In both cases,
1319      if any. */      backtracking will then try other alternatives, if any. */
1320    
1321      if (eptr == mstart &&      else if (eptr == mstart && op != OP_ASSERT_ACCEPT &&
1322          (md->notempty ||          (md->notempty ||
1323            (md->notempty_atstart &&            (md->notempty_atstart &&
1324              mstart == md->start_subject + md->start_offset)))              mstart == md->start_subject + md->start_offset)))
1325        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1326    
1327      /* Otherwise, we have a match. */      /* Otherwise, we have a match. */
1328    
1329      md->end_match_ptr = eptr;           /* Record where we ended */      md->end_match_ptr = eptr;           /* Record where we ended */
1330      md->end_offset_top = offset_top;    /* and how many extracts were taken */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
1331      md->start_match_ptr = mstart;       /* and the start (\K can modify) */      md->start_match_ptr = mstart;       /* and the start (\K can modify) */
     RRETURN(MATCH_MATCH);  
1332    
1333      /* Change option settings */      /* For some reason, the macros don't work properly if an expression is
1334        given as the argument to MRRETURN when the heap is in use. */
1335    
1336      case OP_OPT:      rrc = (op == OP_END)? MATCH_MATCH : MATCH_ACCEPT;
1337      ims = ecode[1];      MRRETURN(rrc);
     ecode += 2;  
     DPRINTF(("ims set to %02lx\n", ims));  
     break;  
1338    
1339      /* Assertion brackets. Check the alternative branches in turn - the      /* Assertion brackets. Check the alternative branches in turn - the
1340      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,
1341      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
1342      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
1343      this level is identical to the lookahead case. */      this level is identical to the lookahead case. When the assertion is part
1344        of a condition, we want to return immediately afterwards. The caller of
1345        this incarnation of the match() function will have set MATCH_CONDASSERT in
1346        md->match_function type, and one of these opcodes will be the first opcode
1347        that is processed. We use a local variable that is preserved over calls to
1348        match() to remember this case. */
1349    
1350      case OP_ASSERT:      case OP_ASSERT:
1351      case OP_ASSERTBACK:      case OP_ASSERTBACK:
1352        if (md->match_function_type == MATCH_CONDASSERT)
1353          {
1354          condassert = TRUE;
1355          md->match_function_type = 0;
1356          }
1357        else condassert = FALSE;
1358    
1359      do      do
1360        {        {
1361        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM4);
1362          RM4);        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
       if (rrc == MATCH_MATCH)  
1363          {          {
1364          mstart = md->start_match_ptr;   /* In case \K reset it */          mstart = md->start_match_ptr;   /* In case \K reset it */
1365          break;          break;
1366          }          }
1367        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH &&
1368              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1369            RRETURN(rrc);
1370        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1371        }        }
1372      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
1373      if (*ecode == OP_KET) RRETURN(MATCH_NOMATCH);  
1374        if (*ecode == OP_KET) MRRETURN(MATCH_NOMATCH);
1375    
1376      /* If checking an assertion for a condition, return MATCH_MATCH. */      /* If checking an assertion for a condition, return MATCH_MATCH. */
1377    
1378      if ((flags & match_condassert) != 0) RRETURN(MATCH_MATCH);      if (condassert) RRETURN(MATCH_MATCH);
1379    
1380      /* Continue from after the assertion, updating the offsets high water      /* Continue from after the assertion, updating the offsets high water
1381      mark, since extracts may have been taken during the assertion. */      mark, since extracts may have been taken during the assertion. */
# Line 1147  for (;;) Line 1391  for (;;)
1391    
1392      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1393      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1394        if (md->match_function_type == MATCH_CONDASSERT)
1395          {
1396          condassert = TRUE;
1397          md->match_function_type = 0;
1398          }
1399        else condassert = FALSE;
1400    
1401      do      do
1402        {        {
1403        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5);
1404          RM5);        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) MRRETURN(MATCH_NOMATCH);
       if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);  
1405        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)
1406          {          {
1407          do ecode += GET(ecode,1); while (*ecode == OP_ALT);          do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1408          break;          break;
1409          }          }
1410        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH &&
1411              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1412            RRETURN(rrc);
1413        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1414        }        }
1415      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
1416    
1417      if ((flags & match_condassert) != 0) RRETURN(MATCH_MATCH);      if (condassert) RRETURN(MATCH_MATCH);  /* Condition assertion */
1418    
1419      ecode += 1 + LINK_SIZE;      ecode += 1 + LINK_SIZE;
1420      continue;      continue;
1421    
# Line 1180  for (;;) Line 1432  for (;;)
1432        while (i-- > 0)        while (i-- > 0)
1433          {          {
1434          eptr--;          eptr--;
1435          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) MRRETURN(MATCH_NOMATCH);
1436          BACKCHAR(eptr);          BACKCHAR(eptr);
1437          }          }
1438        }        }
# Line 1191  for (;;) Line 1443  for (;;)
1443    
1444        {        {
1445        eptr -= GET(ecode, 1);        eptr -= GET(ecode, 1);
1446        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) MRRETURN(MATCH_NOMATCH);
1447        }        }
1448    
1449      /* Save the earliest consulted character, then skip to next op code */      /* Save the earliest consulted character, then skip to next op code */
# Line 1212  for (;;) Line 1464  for (;;)
1464        cb.callout_number   = ecode[1];        cb.callout_number   = ecode[1];
1465        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1466        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1467        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = (int)(md->end_subject - md->start_subject);
1468        cb.start_match      = mstart - md->start_subject;        cb.start_match      = (int)(mstart - md->start_subject);
1469        cb.current_position = eptr - md->start_subject;        cb.current_position = (int)(eptr - md->start_subject);
1470        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
1471        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
1472        cb.capture_top      = offset_top/2;        cb.capture_top      = offset_top/2;
1473        cb.capture_last     = md->capture_last;        cb.capture_last     = md->capture_last;
1474        cb.callout_data     = md->callout_data;        cb.callout_data     = md->callout_data;
1475        if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);        if ((rrc = (*pcre_callout)(&cb)) > 0) MRRETURN(MATCH_NOMATCH);
1476        if (rrc < 0) RRETURN(rrc);        if (rrc < 0) RRETURN(rrc);
1477        }        }
1478      ecode += 2 + 2*LINK_SIZE;      ecode += 2 + 2*LINK_SIZE;
# Line 1237  for (;;) Line 1489  for (;;)
1489      65535 such values, which is too large to put on the stack, but using malloc      65535 such values, which is too large to put on the stack, but using malloc
1490      for small numbers seems expensive. As a compromise, the stack is used when      for small numbers seems expensive. As a compromise, the stack is used when
1491      there are no more than REC_STACK_SAVE_MAX values to store; otherwise malloc      there are no more than REC_STACK_SAVE_MAX values to store; otherwise malloc
1492      is used. A problem is what to do if the malloc fails ... there is no way of      is used.
     returning to the top level with an error. Save the top REC_STACK_SAVE_MAX  
     values on the stack, and accept that the rest may be wrong.  
1493    
1494      There are also other values that have to be saved. We use a chained      There are also other values that have to be saved. We use a chained
1495      sequence of blocks that actually live on the stack. Thanks to Robin Houston      sequence of blocks that actually live on the stack. Thanks to Robin Houston
# Line 1276  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)          if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
1541            {            {
1542            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
1543            md->recursive = new_recursive.prevrec;            md->recursive = new_recursive.prevrec;
1544            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
1545              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1546            RRETURN(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 1313  for (;;) Line 1565  for (;;)
1565        md->recursive = new_recursive.prevrec;        md->recursive = new_recursive.prevrec;
1566        if (new_recursive.offset_save != stacksave)        if (new_recursive.offset_save != stacksave)
1567          (pcre_free)(new_recursive.offset_save);          (pcre_free)(new_recursive.offset_save);
1568        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1569        }        }
1570      /* Control never reaches here */      /* Control never reaches here */
1571    
# Line 1331  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)        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 1346  for (;;) Line 1600  for (;;)
1600    
1601      if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);      if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);
1602    
1603      /* Continue as from after the assertion, updating the offsets high water      /* Continue after the group, updating the offsets high water mark, since
1604      mark, since extracts may have been taken. */      extracts may have been taken. */
1605    
1606      do ecode += GET(ecode, 1); while (*ecode == OP_ALT);      do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
1607    
# Line 1357  for (;;) Line 1611  for (;;)
1611      /* For a non-repeating ket, just continue at this level. This also      /* For a non-repeating ket, just continue at this level. This also
1612      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.
1613      This is the forcible breaking of infinite loops as implemented in Perl      This is the forcible breaking of infinite loops as implemented in Perl
1614      5.005. If there is an options reset, it will get obeyed in the normal      5.005. */
     course of events. */  
1615    
1616      if (*ecode == OP_KET || eptr == saved_eptr)      if (*ecode == OP_KET || eptr == saved_eptr)
1617        {        {
# Line 1368  for (;;) Line 1621  for (;;)
1621    
1622      /* 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
1623      preceding bracket, in the appropriate order. The second "call" of match()      preceding bracket, in the appropriate order. The second "call" of match()
1624      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));  
       }  
1625    
1626      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1627        {        {
1628        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM8);
1629        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1630        ecode = prev;        ecode = prev;
       flags = 0;  
       goto TAIL_RECURSE;  
1631        }        }
1632      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1633        {        {
1634        RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);        md->match_function_type = MATCH_CBEGROUP;
1635          RMATCH(eptr, prev, offset_top, md, eptrb, RM9);
1636        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1637        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
       flags = 0;  
       goto TAIL_RECURSE;  
1638        }        }
1639        goto TAIL_RECURSE;
1640    
1641      /* Control never gets here */      /* Control never gets here */
1642    
1643      /* An alternation is the end of a branch; scan along to find the end of the      /* An alternation is the end of a branch; scan along to find the end of the
# Line 1408  for (;;) Line 1652  for (;;)
1652      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
1653      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
1654      optional ones preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1655    
1656      case OP_BRAZERO:      case OP_BRAZERO:
1657        {      next = ecode + 1;
1658        next = ecode+1;      RMATCH(eptr, next, offset_top, md, eptrb, RM10);
1659        RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1660        if (rrc != MATCH_NOMATCH) RRETURN(rrc);      do next += GET(next, 1); while (*next == OP_ALT);
1661        do next += GET(next,1); while (*next == OP_ALT);      ecode = next + 1 + LINK_SIZE;
       ecode = next + 1 + LINK_SIZE;  
       }  
1662      break;      break;
1663    
1664      case OP_BRAMINZERO:      case OP_BRAMINZERO:
1665        {      next = ecode + 1;
1666        next = ecode+1;      do next += GET(next, 1); while (*next == OP_ALT);
1667        do next += GET(next, 1); while (*next == OP_ALT);      RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, eptrb, RM11);
1668        RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11);      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1669        if (rrc != MATCH_NOMATCH) RRETURN(rrc);      ecode++;
       ecode++;  
       }  
1670      break;      break;
1671    
1672      case OP_SKIPZERO:      case OP_SKIPZERO:
1673        {      next = ecode+1;
1674        next = ecode+1;      do next += GET(next,1); while (*next == OP_ALT);
1675        do next += GET(next,1); while (*next == OP_ALT);      ecode = next + 1 + LINK_SIZE;
       ecode = next + 1 + LINK_SIZE;  
       }  
1676      break;      break;
1677    
1678        /* BRAPOSZERO occurs before a possessive bracket group. Don't do anything
1679        here; just jump to the group, with allow_zero set TRUE. */
1680    
1681        case OP_BRAPOSZERO:
1682        op = *(++ecode);
1683        allow_zero = TRUE;
1684        if (op == OP_CBRAPOS || op == OP_SCBRAPOS) goto POSSESSIVE_CAPTURE;
1685          goto POSSESSIVE_NON_CAPTURE;
1686    
1687      /* End of a group, repeated or non-repeating. */      /* End of a group, repeated or non-repeating. */
1688    
1689      case OP_KET:      case OP_KET:
1690      case OP_KETRMIN:      case OP_KETRMIN:
1691      case OP_KETRMAX:      case OP_KETRMAX:
1692        case OP_KETRPOS:
1693      prev = ecode - GET(ecode, 1);      prev = ecode - GET(ecode, 1);
1694    
1695      /* 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 1467  for (;;) Line 1715  for (;;)
1715        md->end_match_ptr = eptr;      /* For ONCE */        md->end_match_ptr = eptr;      /* For ONCE */
1716        md->end_offset_top = offset_top;        md->end_offset_top = offset_top;
1717        md->start_match_ptr = mstart;        md->start_match_ptr = mstart;
1718        RRETURN(MATCH_MATCH);        MRRETURN(MATCH_MATCH);
1719        }        }
1720    
1721      /* For capturing groups we have to check the group number back at the start      /* For capturing groups we have to check the group number back at the start
# Line 1476  for (;;) Line 1724  for (;;)
1724      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
1725      when the OP_END is reached. Other recursion is handled here. */      when the OP_END is reached. Other recursion is handled here. */
1726    
1727      if (*prev == OP_CBRA || *prev == OP_SCBRA)      if (*prev == OP_CBRA || *prev == OP_SCBRA ||
1728            *prev == OP_CBRAPOS || *prev == OP_SCBRAPOS)
1729        {        {
1730        number = GET2(prev, 1+LINK_SIZE);        number = GET2(prev, 1+LINK_SIZE);
1731        offset = number << 1;        offset = number << 1;
# Line 1489  for (;;) Line 1738  for (;;)
1738        md->capture_last = number;        md->capture_last = number;
1739        if (offset >= md->offset_max) md->offset_overflow = TRUE; else        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1740          {          {
1741            /* If offset is greater than offset_top, it means that we are
1742            "skipping" a capturing group, and that group's offsets must be marked
1743            unset. In earlier versions of PCRE, all the offsets were unset at the
1744            start of matching, but this doesn't work because atomic groups and
1745            assertions can cause a value to be set that should later be unset.
1746            Example: matching /(?>(a))b|(a)c/ against "ac". This sets group 1 as
1747            part of the atomic group, but this is not on the final matching path,
1748            so must be unset when 2 is set. (If there is no group 2, there is no
1749            problem, because offset_top will then be 2, indicating no capture.) */
1750    
1751            if (offset > offset_top)
1752              {
1753              register int *iptr = md->offset_vector + offset_top;
1754              register int *iend = md->offset_vector + offset;
1755              while (iptr < iend) *iptr++ = -1;
1756              }
1757    
1758            /* Now make the extraction */
1759    
1760          md->offset_vector[offset] =          md->offset_vector[offset] =
1761            md->offset_vector[md->offset_end - number];            md->offset_vector[md->offset_end - number];
1762          md->offset_vector[offset+1] = eptr - md->start_subject;          md->offset_vector[offset+1] = (int)(eptr - md->start_subject);
1763          if (offset_top <= offset) offset_top = offset + 2;          if (offset_top <= offset) offset_top = offset + 2;
1764          }          }
1765    
# Line 1507  for (;;) Line 1775  for (;;)
1775            rec->saved_max * sizeof(int));            rec->saved_max * sizeof(int));
1776          offset_top = rec->save_offset_top;          offset_top = rec->save_offset_top;
1777          ecode = rec->after_call;          ecode = rec->after_call;
         ims = original_ims;  
1778          break;          break;
1779          }          }
1780        }        }
1781    
     /* 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));  
   
1782      /* For a non-repeating ket, just continue at this level. This also      /* For a non-repeating ket, just continue at this level. This also
1783      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.
1784      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 1529  for (;;) Line 1790  for (;;)
1790        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1791        break;        break;
1792        }        }
1793    
1794      /* The repeating kets try the rest of the pattern or restart from the      /* OP_KETRPOS is a possessive repeating ket. Remember the current position,
1795      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
1796      tail recursion to avoid using another stack frame, unless we have an      at a time from the outer level, thus saving stack. */
1797    
1798        if (*ecode == OP_KETRPOS)
1799          {
1800          md->end_match_ptr = eptr;
1801          md->end_offset_top = offset_top;
1802          RRETURN(MATCH_KETRPOS);
1803          }
1804    
1805        /* The normal repeating kets try the rest of the pattern or restart from
1806        the preceding bracket, in the appropriate order. In the second case, we can
1807        use tail recursion to avoid using another stack frame, unless we have an
1808      unlimited repeat of a group that can match an empty string. */      unlimited repeat of a group that can match an empty string. */
1809    
     flags = (*prev >= OP_SBRA)? match_cbegroup : 0;  
   
1810      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1811        {        {
1812        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM12);
1813        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1814        if (flags != 0)    /* Could match an empty string */        if (*prev >= OP_SBRA)    /* Could match an empty string */
1815          {          {
1816          RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);          md->match_function_type = MATCH_CBEGROUP;
1817            RMATCH(eptr, prev, offset_top, md, eptrb, RM50);
1818          RRETURN(rrc);          RRETURN(rrc);
1819          }          }
1820        ecode = prev;        ecode = prev;
# Line 1551  for (;;) Line 1822  for (;;)
1822        }        }
1823      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1824        {        {
1825        RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);        if (*prev >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
1826          RMATCH(eptr, prev, offset_top, md, eptrb, RM13);
1827        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1828        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
       flags = 0;  
1829        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1830        }        }
1831      /* Control never gets here */      /* Control never gets here */
1832    
1833      /* Start of subject unless notbol, or after internal newline if multiline */      /* Not multiline mode: start of subject assertion, unless notbol. */
1834    
1835      case OP_CIRC:      case OP_CIRC:
1836      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);      if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH);
1837      if ((ims & PCRE_MULTILINE) != 0)  
       {  
       if (eptr != md->start_subject &&  
           (eptr == md->end_subject || !WAS_NEWLINE(eptr)))  
         RRETURN(MATCH_NOMATCH);  
       ecode++;  
       break;  
       }  
     /* ... else fall through */  
   
1838      /* Start of subject assertion */      /* Start of subject assertion */
1839    
1840      case OP_SOD:      case OP_SOD:
1841      if (eptr != md->start_subject) RRETURN(MATCH_NOMATCH);      if (eptr != md->start_subject) MRRETURN(MATCH_NOMATCH);
1842        ecode++;
1843        break;
1844    
1845        /* Multiline mode: start of subject unless notbol, or after any newline. */
1846    
1847        case OP_CIRCM:
1848        if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH);
1849        if (eptr != md->start_subject &&
1850            (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
1851          MRRETURN(MATCH_NOMATCH);
1852      ecode++;      ecode++;
1853      break;      break;
1854    
1855      /* Start of match assertion */      /* Start of match assertion */
1856    
1857      case OP_SOM:      case OP_SOM:
1858      if (eptr != md->start_subject + md->start_offset) RRETURN(MATCH_NOMATCH);      if (eptr != md->start_subject + md->start_offset) MRRETURN(MATCH_NOMATCH);
1859      ecode++;      ecode++;
1860      break;      break;
1861    
# Line 1594  for (;;) Line 1866  for (;;)
1866      ecode++;      ecode++;
1867      break;      break;
1868    
1869      /* Assert before internal newline if multiline, or before a terminating      /* Multiline mode: assert before any newline, or before end of subject
1870      newline unless endonly is set, else end of subject unless noteol is set. */      unless noteol is set. */
1871    
1872      case OP_DOLL:      case OP_DOLLM:
1873      if ((ims & PCRE_MULTILINE) != 0)      if (eptr < md->end_subject)
1874        {        { if (!IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH); }
       if (eptr < md->end_subject)  
         { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }  
       else  
         { if (md->noteol) RRETURN(MATCH_NOMATCH); }  
       ecode++;  
       break;  
       }  
1875      else      else
1876        {        {
1877        if (md->noteol) RRETURN(MATCH_NOMATCH);        if (md->noteol) MRRETURN(MATCH_NOMATCH);
1878        if (!md->endonly)        SCHECK_PARTIAL();
         {  
         if (eptr != md->end_subject &&  
             (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))  
           RRETURN(MATCH_NOMATCH);  
         ecode++;  
         break;  
         }  
1879        }        }
1880        ecode++;
1881        break;
1882    
1883        /* Not multiline mode: assert before a terminating newline or before end of
1884        subject unless noteol is set. */
1885    
1886        case OP_DOLL:
1887        if (md->noteol) MRRETURN(MATCH_NOMATCH);
1888        if (!md->endonly) goto ASSERT_NL_OR_EOS;
1889    
1890      /* ... else fall through for endonly */      /* ... else fall through for endonly */
1891    
1892      /* End of subject assertion (\z) */      /* End of subject assertion (\z) */
1893    
1894      case OP_EOD:      case OP_EOD:
1895      if (eptr < md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr < md->end_subject) MRRETURN(MATCH_NOMATCH);
1896        SCHECK_PARTIAL();
1897      ecode++;      ecode++;
1898      break;      break;
1899    
1900      /* End of subject or ending \n assertion (\Z) */      /* End of subject or ending \n assertion (\Z) */
1901    
1902      case OP_EODN:      case OP_EODN:
1903      if (eptr != md->end_subject &&      ASSERT_NL_OR_EOS:
1904        if (eptr < md->end_subject &&
1905          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1906        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1907    
1908        /* Either at end of string or \n before end. */
1909    
1910        SCHECK_PARTIAL();
1911      ecode++;      ecode++;
1912      break;      break;
1913    
# Line 1651  for (;;) Line 1925  for (;;)
1925  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1926        if (utf8)        if (utf8)
1927          {          {
1928            /* Get status of previous character */
1929    
1930          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
1931            {            {
1932            USPTR lastptr = eptr - 1;            USPTR lastptr = eptr - 1;
1933            while((*lastptr & 0xc0) == 0x80) lastptr--;            while((*lastptr & 0xc0) == 0x80) lastptr--;
1934            if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;            if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;
1935            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
1936    #ifdef SUPPORT_UCP
1937              if (md->use_ucp)
1938                {
1939                if (c == '_') prev_is_word = TRUE; else
1940                  {
1941                  int cat = UCD_CATEGORY(c);
1942                  prev_is_word = (cat == ucp_L || cat == ucp_N);
1943                  }
1944                }
1945              else
1946    #endif
1947            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1948            }            }
1949    
1950            /* Get status of next character */
1951    
1952          if (eptr >= md->end_subject)          if (eptr >= md->end_subject)
1953            {            {
1954            SCHECK_PARTIAL();            SCHECK_PARTIAL();
# Line 1667  for (;;) Line 1957  for (;;)
1957          else          else
1958            {            {
1959            GETCHAR(c, eptr);            GETCHAR(c, eptr);
1960    #ifdef SUPPORT_UCP
1961              if (md->use_ucp)
1962                {
1963                if (c == '_') cur_is_word = TRUE; else
1964                  {
1965                  int cat = UCD_CATEGORY(c);
1966                  cur_is_word = (cat == ucp_L || cat == ucp_N);
1967                  }
1968                }
1969              else
1970    #endif
1971            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1972            }            }
1973          }          }
1974        else        else
1975  #endif  #endif
1976    
1977        /* Not in UTF-8 mode */        /* Not in UTF-8 mode, but we may still have PCRE_UCP set, and for
1978          consistency with the behaviour of \w we do use it in this case. */
1979    
1980          {          {
1981            /* Get status of previous character */
1982    
1983          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
1984            {            {
1985            if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1;            if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1;
1986    #ifdef SUPPORT_UCP
1987              if (md->use_ucp)
1988                {
1989                c = eptr[-1];
1990                if (c == '_') prev_is_word = TRUE; else
1991                  {
1992                  int cat = UCD_CATEGORY(c);
1993                  prev_is_word = (cat == ucp_L || cat == ucp_N);
1994                  }
1995                }
1996              else
1997    #endif
1998            prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);            prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);
1999            }            }
2000    
2001            /* Get status of next character */
2002    
2003          if (eptr >= md->end_subject)          if (eptr >= md->end_subject)
2004            {            {
2005            SCHECK_PARTIAL();            SCHECK_PARTIAL();
2006            cur_is_word = FALSE;            cur_is_word = FALSE;
2007            }            }
2008          else cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);          else
2009    #ifdef SUPPORT_UCP
2010            if (md->use_ucp)
2011              {
2012              c = *eptr;
2013              if (c == '_') cur_is_word = TRUE; else
2014                {
2015                int cat = UCD_CATEGORY(c);
2016                cur_is_word = (cat == ucp_L || cat == ucp_N);
2017                }
2018              }
2019            else
2020    #endif
2021            cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);
2022          }          }
2023    
2024        /* Now see if the situation is what we want */        /* Now see if the situation is what we want */
2025    
2026        if ((*ecode++ == OP_WORD_BOUNDARY)?        if ((*ecode++ == OP_WORD_BOUNDARY)?
2027             cur_is_word == prev_is_word : cur_is_word != prev_is_word)             cur_is_word == prev_is_word : cur_is_word != prev_is_word)
2028          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2029        }        }
2030      break;      break;
2031    
2032      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
2033    
2034      case OP_ANY:      case OP_ANY:
2035      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);      if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);
2036      /* Fall through */      /* Fall through */
2037    
2038      case OP_ALLANY:      case OP_ALLANY:
2039      if (eptr++ >= md->end_subject)      if (eptr++ >= md->end_subject)
2040        {        {
2041        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2042        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2043        }        }
2044      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
2045      ecode++;      ecode++;
# Line 1720  for (;;) Line 2052  for (;;)
2052      if (eptr++ >= md->end_subject)      if (eptr++ >= md->end_subject)
2053        {        {
2054        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2055        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2056        }        }
2057      ecode++;      ecode++;
2058      break;      break;
# Line 1729  for (;;) Line 2061  for (;;)
2061      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2062        {        {
2063        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2064        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2065        }        }
2066      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2067      if (      if (
# Line 1738  for (;;) Line 2070  for (;;)
2070  #endif  #endif
2071         (md->ctypes[c] & ctype_digit) != 0         (md->ctypes[c] & ctype_digit) != 0
2072         )         )
2073        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2074      ecode++;      ecode++;
2075      break;      break;
2076    
# Line 1746  for (;;) Line 2078  for (;;)
2078      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2079        {        {
2080        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2081        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2082        }        }
2083      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2084      if (      if (
# Line 1755  for (;;) Line 2087  for (;;)
2087  #endif  #endif
2088         (md->ctypes[c] & ctype_digit) == 0         (md->ctypes[c] & ctype_digit) == 0
2089         )         )
2090        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2091      ecode++;      ecode++;
2092      break;      break;
2093    
# Line 1763  for (;;) Line 2095  for (;;)
2095      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2096        {        {
2097        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2098        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2099        }        }
2100      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2101      if (      if (
# Line 1772  for (;;) Line 2104  for (;;)
2104  #endif  #endif
2105         (md->ctypes[c] & ctype_space) != 0         (md->ctypes[c] & ctype_space) != 0
2106         )         )
2107        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2108      ecode++;      ecode++;
2109      break;      break;
2110    
# Line 1780  for (;;) Line 2112  for (;;)
2112      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2113        {        {
2114        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2115        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2116        }        }
2117      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2118      if (      if (
# Line 1789  for (;;) Line 2121  for (;;)
2121  #endif  #endif
2122         (md->ctypes[c] & ctype_space) == 0         (md->ctypes[c] & ctype_space) == 0
2123         )         )
2124        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2125      ecode++;      ecode++;
2126      break;      break;
2127    
# Line 1797  for (;;) Line 2129  for (;;)
2129      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2130        {        {
2131        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2132        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2133        }        }
2134      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2135      if (      if (
# Line 1806  for (;;) Line 2138  for (;;)
2138  #endif  #endif
2139         (md->ctypes[c] & ctype_word) != 0         (md->ctypes[c] & ctype_word) != 0
2140         )         )
2141        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2142      ecode++;      ecode++;
2143      break;      break;
2144    
# Line 1814  for (;;) Line 2146  for (;;)
2146      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2147        {        {
2148        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2149        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2150        }        }
2151      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2152      if (      if (
# Line 1823  for (;;) Line 2155  for (;;)
2155  #endif  #endif
2156         (md->ctypes[c] & ctype_word) == 0         (md->ctypes[c] & ctype_word) == 0
2157         )         )
2158        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2159      ecode++;      ecode++;
2160      break;      break;
2161    
# Line 1831  for (;;) Line 2163  for (;;)
2163      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2164        {        {
2165        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2166        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2167        }        }
2168      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2169      switch(c)      switch(c)
2170        {        {
2171        default: RRETURN(MATCH_NOMATCH);        default: MRRETURN(MATCH_NOMATCH);
2172    
2173        case 0x000d:        case 0x000d:
2174        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
2175        break;        break;
# Line 1849  for (;;) Line 2182  for (;;)
2182        case 0x0085:        case 0x0085:
2183        case 0x2028:        case 0x2028:
2184        case 0x2029:        case 0x2029:
2185        if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);        if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
2186        break;        break;
2187        }        }
2188      ecode++;      ecode++;
# Line 1859  for (;;) Line 2192  for (;;)
2192      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2193        {        {
2194        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2195        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2196        }        }
2197      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2198      switch(c)      switch(c)
# Line 1884  for (;;) Line 2217  for (;;)
2217        case 0x202f:    /* NARROW NO-BREAK SPACE */        case 0x202f:    /* NARROW NO-BREAK SPACE */
2218        case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */        case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
2219        case 0x3000:    /* IDEOGRAPHIC SPACE */        case 0x3000:    /* IDEOGRAPHIC SPACE */
2220        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2221        }        }
2222      ecode++;      ecode++;
2223      break;      break;
# Line 1893  for (;;) Line 2226  for (;;)
2226      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2227        {        {
2228        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2229        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2230        }        }
2231      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2232      switch(c)      switch(c)
2233        {        {
2234        default: RRETURN(MATCH_NOMATCH);        default: MRRETURN(MATCH_NOMATCH);
2235        case 0x09:      /* HT */        case 0x09:      /* HT */
2236        case 0x20:      /* SPACE */        case 0x20:      /* SPACE */
2237        case 0xa0:      /* NBSP */        case 0xa0:      /* NBSP */
# Line 1927  for (;;) Line 2260  for (;;)
2260      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2261        {        {
2262        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2263        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2264        }        }
2265      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2266      switch(c)      switch(c)
# Line 1940  for (;;) Line 2273  for (;;)
2273        case 0x85:      /* NEL */        case 0x85:      /* NEL */
2274        case 0x2028:    /* LINE SEPARATOR */        case 0x2028:    /* LINE SEPARATOR */
2275        case 0x2029:    /* PARAGRAPH SEPARATOR */        case 0x2029:    /* PARAGRAPH SEPARATOR */
2276        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2277        }        }
2278      ecode++;      ecode++;
2279      break;      break;
# Line 1949  for (;;) Line 2282  for (;;)
2282      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2283        {        {
2284        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2285        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2286        }        }
2287      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2288      switch(c)      switch(c)
2289        {        {
2290        default: RRETURN(MATCH_NOMATCH);        default: MRRETURN(MATCH_NOMATCH);
2291        case 0x0a:      /* LF */        case 0x0a:      /* LF */
2292        case 0x0b:      /* VT */        case 0x0b:      /* VT */
2293        case 0x0c:      /* FF */        case 0x0c:      /* FF */
# Line 1976  for (;;) Line 2309  for (;;)
2309      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2310        {        {
2311        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2312        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2313        }        }
2314      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2315        {        {
# Line 1985  for (;;) Line 2318  for (;;)
2318        switch(ecode[1])        switch(ecode[1])
2319          {          {
2320          case PT_ANY:          case PT_ANY:
2321          if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH);          if (op == OP_NOTPROP) MRRETURN(MATCH_NOMATCH);
2322          break;          break;
2323    
2324          case PT_LAMP:          case PT_LAMP:
2325          if ((prop->chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
2326               prop->chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
2327               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
2328            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2329           break;          break;
2330    
2331          case PT_GC:          case PT_GC:
2332          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
2333            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2334          break;          break;
2335    
2336          case PT_PC:          case PT_PC:
2337          if ((ecode[2] != prop->chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
2338            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2339          break;          break;
2340    
2341          case PT_SC:          case PT_SC:
2342          if ((ecode[2] != prop->script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
2343            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2344          break;          break;
2345    
2346            /* These are specials */
2347    
2348            case PT_ALNUM:
2349            if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||
2350                 _pcre_ucp_gentype[prop->chartype] == ucp_N) == (op == OP_NOTPROP))
2351              MRRETURN(MATCH_NOMATCH);
2352            break;
2353    
2354            case PT_SPACE:    /* Perl space */
2355            if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||
2356                 c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)
2357                   == (op == OP_NOTPROP))
2358              MRRETURN(MATCH_NOMATCH);
2359            break;
2360    
2361            case PT_PXSPACE:  /* POSIX space */
2362            if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||
2363                 c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
2364                 c == CHAR_FF || c == CHAR_CR)
2365                   == (op == OP_NOTPROP))
2366              MRRETURN(MATCH_NOMATCH);
2367            break;
2368    
2369            case PT_WORD:
2370            if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||
2371                 _pcre_ucp_gentype[prop->chartype] == ucp_N ||
2372                 c == CHAR_UNDERSCORE) == (op == OP_NOTPROP))
2373              MRRETURN(MATCH_NOMATCH);
2374            break;
2375    
2376            /* This should never occur */
2377    
2378          default:          default:
2379          RRETURN(PCRE_ERROR_INTERNAL);          RRETURN(PCRE_ERROR_INTERNAL);
2380          }          }
# Line 2025  for (;;) Line 2390  for (;;)
2390      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2391        {        {
2392        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2393        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2394        }        }
2395      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2396        {        {
2397        int category = UCD_CATEGORY(c);        int category = UCD_CATEGORY(c);
2398        if (category == ucp_M) RRETURN(MATCH_NOMATCH);        if (category == ucp_M) MRRETURN(MATCH_NOMATCH);
2399        while (eptr < md->end_subject)        while (eptr < md->end_subject)
2400          {          {
2401          int len = 1;          int len = 1;
# Line 2057  for (;;) Line 2422  for (;;)
2422      loops). */      loops). */
2423    
2424      case OP_REF:      case OP_REF:
2425        {      case OP_REFI:
2426        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */      caseless = op == OP_REFI;
2427        ecode += 3;      offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
2428        ecode += 3;
2429    
2430        /* If the reference is unset, there are two possibilities:      /* If the reference is unset, there are two possibilities:
2431    
2432        (a) In the default, Perl-compatible state, set the length to be longer      (a) In the default, Perl-compatible state, set the length negative;
2433        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
2434        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.  
2435    
2436        (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
2437        so that the back reference matches an empty string.      so that the back reference matches an empty string.
2438    
2439        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
2440        referenced subpattern. */      referenced subpattern. */
2441    
2442        if (offset >= offset_top || md->offset_vector[offset] < 0)      if (offset >= offset_top || md->offset_vector[offset] < 0)
2443          length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;        length = (md->jscript_compat)? 0 : -1;
2444        else      else
2445          length = md->offset_vector[offset+1] - md->offset_vector[offset];        length = md->offset_vector[offset+1] - md->offset_vector[offset];
2446    
2447        /* Set up for repetition, or handle the non-repeated case */      /* Set up for repetition, or handle the non-repeated case */
2448    
2449        switch (*ecode)      switch (*ecode)
2450          {
2451          case OP_CRSTAR:
2452          case OP_CRMINSTAR:
2453          case OP_CRPLUS:
2454          case OP_CRMINPLUS:
2455          case OP_CRQUERY:
2456          case OP_CRMINQUERY:
2457          c = *ecode++ - OP_CRSTAR;
2458          minimize = (c & 1) != 0;
2459          min = rep_min[c];                 /* Pick up values from tables; */
2460          max = rep_max[c];                 /* zero for max => infinity */
2461          if (max == 0) max = INT_MAX;
2462          break;
2463    
2464          case OP_CRRANGE:
2465          case OP_CRMINRANGE:
2466          minimize = (*ecode == OP_CRMINRANGE);
2467          min = GET2(ecode, 1);
2468          max = GET2(ecode, 3);
2469          if (max == 0) max = INT_MAX;
2470          ecode += 5;
2471          break;
2472    
2473          default:               /* No repeat follows */
2474          if ((length = match_ref(offset, eptr, length, md, caseless)) < 0)
2475          {          {
2476          case OP_CRSTAR:          CHECK_PARTIAL();
2477          case OP_CRMINSTAR:          MRRETURN(MATCH_NOMATCH);
2478          case OP_CRPLUS:          }
2479          case OP_CRMINPLUS:        eptr += length;
2480          case OP_CRQUERY:        continue;              /* With the main loop */
2481          case OP_CRMINQUERY:        }
         c = *ecode++ - OP_CRSTAR;  
         minimize = (c & 1) != 0;  
         min = rep_min[c];                 /* Pick up values from tables; */  
         max = rep_max[c];                 /* zero for max => infinity */  
         if (max == 0) max = INT_MAX;  
         break;  
2482    
2483          case OP_CRRANGE:      /* Handle repeated back references. If the length of the reference is
2484          case OP_CRMINRANGE:      zero, just continue with the main loop. */
         minimize = (*ecode == OP_CRMINRANGE);  
         min = GET2(ecode, 1);  
         max = GET2(ecode, 3);  
         if (max == 0) max = INT_MAX;  
         ecode += 5;  
         break;  
2485    
2486          default:               /* No repeat follows */      if (length == 0) continue;
2487          if (!match_ref(offset, eptr, length, md, ims))  
2488            {      /* First, ensure the minimum number of matches are present. We get back
2489            CHECK_PARTIAL();      the length of the reference string explicitly rather than passing the
2490            RRETURN(MATCH_NOMATCH);      address of eptr, so that eptr can be a register variable. */
2491            }  
2492          eptr += length;      for (i = 1; i <= min; i++)
2493          continue;              /* With the main loop */        {
2494          int slength;
2495          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2496            {
2497            CHECK_PARTIAL();
2498            MRRETURN(MATCH_NOMATCH);
2499          }          }
2500          eptr += slength;
2501          }
2502    
2503        /* If the length of the reference is zero, just continue with the      /* If min = max, continue at the same level without recursion.
2504        main loop. */      They are not both allowed to be zero. */
2505    
2506        if (length == 0) continue;      if (min == max) continue;
2507    
2508        /* First, ensure the minimum number of matches are present. We get back      /* If minimizing, keep trying and advancing the pointer */
       the length of the reference string explicitly rather than passing the  
       address of eptr, so that eptr can be a register variable. */  
2509    
2510        for (i = 1; i <= min; i++)      if (minimize)
2511          {
2512          for (fi = min;; fi++)
2513          {          {
2514          if (!match_ref(offset, eptr, length, md, ims))          int slength;
2515            RMATCH(eptr, ecode, offset_top, md, eptrb, RM14);
2516            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2517            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2518            if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2519            {            {
2520            CHECK_PARTIAL();            CHECK_PARTIAL();
2521            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2522            }            }
2523          eptr += length;          eptr += slength;
2524          }          }
2525          /* Control never gets here */
2526          }
2527    
2528        /* If min = max, continue at the same level without recursion.      /* If maximizing, find the longest string and work backwards */
       They are not both allowed to be zero. */  
   
       if (min == max) continue;  
   
       /* If minimizing, keep trying and advancing the pointer */  
2529    
2530        if (minimize)      else
2531          {
2532          pp = eptr;
2533          for (i = min; i < max; i++)
2534          {          {
2535          for (fi = min;; fi++)          int slength;
2536            if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2537            {            {
2538            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);            CHECK_PARTIAL();
2539            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            break;
           if (fi >= max) RRETURN(MATCH_NOMATCH);  
           if (!match_ref(offset, eptr, length, md, ims))  
             {  
             CHECK_PARTIAL();  
             RRETURN(MATCH_NOMATCH);  
             }  
           eptr += length;  
2540            }            }
2541          /* Control never gets here */          eptr += slength;
2542          }          }
2543          while (eptr >= pp)
       /* If maximizing, find the longest string and work backwards */  
   
       else  
2544          {          {
2545          pp = eptr;          RMATCH(eptr, ecode, offset_top, md, eptrb, RM15);
2546          for (i = min; i < max; i++)          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2547            {          eptr -= length;
           if (!match_ref(offset, eptr, length, md, ims))  
             {  
             CHECK_PARTIAL();  
             break;  
             }  
           eptr += length;  
           }  
         while (eptr >= pp)  
           {  
           RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);  
           if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
           eptr -= length;  
           }  
         RRETURN(MATCH_NOMATCH);  
2548          }          }
2549          MRRETURN(MATCH_NOMATCH);
2550        }        }
2551      /* Control never gets here */      /* Control never gets here */
2552    
# Line 2240  for (;;) Line 2607  for (;;)
2607            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
2608              {              {
2609              SCHECK_PARTIAL();              SCHECK_PARTIAL();
2610              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
2611              }              }
2612            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
2613            if (c > 255)            if (c > 255)
2614              {              {
2615              if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);              if (op == OP_CLASS) MRRETURN(MATCH_NOMATCH);
2616              }              }
2617            else            else
2618              {              {
2619              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2620              }              }
2621            }            }
2622          }          }
# Line 2262  for (;;) Line 2629  for (;;)
2629            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
2630              {              {
2631              SCHECK_PARTIAL();              SCHECK_PARTIAL();
2632              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
2633              }              }
2634            c = *eptr++;            c = *eptr++;
2635            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);            if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2636            }            }
2637          }          }
2638    
# Line 2285  for (;;) Line 2652  for (;;)
2652            {            {
2653            for (fi = min;; fi++)            for (fi = min;; fi++)
2654              {              {
2655              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM16);
2656              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2657              if (fi >= max) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2658              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
2659                {                {
2660                SCHECK_PARTIAL();                SCHECK_PARTIAL();
2661                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
2662                }                }
2663              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
2664              if (c > 255)              if (c > 255)
2665                {                {
2666                if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);                if (op == OP_CLASS) MRRETURN(MATCH_NOMATCH);
2667                }                }
2668              else              else
2669                {                {
2670                if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);                if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2671                }                }
2672              }              }
2673            }            }
# Line 2310  for (;;) Line 2677  for (;;)
2677            {            {
2678            for (fi = min;; fi++)            for (fi = min;; fi++)
2679              {              {
2680              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM17);
2681              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2682              if (fi >= max) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2683              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
2684                {                {
2685                SCHECK_PARTIAL();                SCHECK_PARTIAL();
2686                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
2687                }                }
2688              c = *eptr++;              c = *eptr++;
2689              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2690              }              }
2691            }            }
2692          /* Control never gets here */          /* Control never gets here */
# Line 2356  for (;;) Line 2723  for (;;)
2723              }              }
2724            for (;;)            for (;;)
2725              {              {
2726              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM18);
2727              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2728              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2729              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2379  for (;;) Line 2746  for (;;)
2746              }              }
2747            while (eptr >= pp)            while (eptr >= pp)
2748              {              {
2749              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM19);
2750              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2751              eptr--;              eptr--;
2752              }              }
2753            }            }
2754    
2755          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2756          }          }
2757        }        }
2758      /* Control never gets here */      /* Control never gets here */
# Line 2437  for (;;) Line 2804  for (;;)
2804          if (eptr >= md->end_subject)          if (eptr >= md->end_subject)
2805            {            {
2806            SCHECK_PARTIAL();            SCHECK_PARTIAL();
2807            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2808            }            }
2809          GETCHARINCTEST(c, eptr);          GETCHARINCTEST(c, eptr);
2810          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);          if (!_pcre_xclass(c, data)) MRRETURN(MATCH_NOMATCH);
2811          }          }
2812    
2813        /* If max == min we can continue with the main loop without the        /* If max == min we can continue with the main loop without the
# Line 2455  for (;;) Line 2822  for (;;)
2822          {          {
2823          for (fi = min;; fi++)          for (fi = min;; fi++)
2824            {            {
2825            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM20);
2826            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2827            if (fi >= max) RRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2828            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
2829              {              {
2830              SCHECK_PARTIAL();              SCHECK_PARTIAL();
2831              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
2832              }              }
2833            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
2834            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            if (!_pcre_xclass(c, data)) MRRETURN(MATCH_NOMATCH);
2835            }            }
2836          /* Control never gets here */          /* Control never gets here */
2837          }          }
# Line 2488  for (;;) Line 2855  for (;;)
2855            }            }
2856          for(;;)          for(;;)
2857            {            {
2858            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM21);
2859            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2860            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2861            if (utf8) BACKCHAR(eptr);            if (utf8) BACKCHAR(eptr);
2862            }            }
2863          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2864          }          }
2865    
2866        /* Control never gets here */        /* Control never gets here */
# Line 2512  for (;;) Line 2879  for (;;)
2879        if (length > md->end_subject - eptr)        if (length > md->end_subject - eptr)
2880          {          {
2881          CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */          CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2882          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2883          }          }
2884        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);        while (length-- > 0) if (*ecode++ != *eptr++) MRRETURN(MATCH_NOMATCH);
2885        }        }
2886      else      else
2887  #endif  #endif
# Line 2524  for (;;) Line 2891  for (;;)
2891        if (md->end_subject - eptr < 1)        if (md->end_subject - eptr < 1)
2892          {          {
2893          SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */          SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2894          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2895          }          }
2896        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);        if (ecode[1] != *eptr++) MRRETURN(MATCH_NOMATCH);
2897        ecode += 2;        ecode += 2;
2898        }        }
2899      break;      break;
2900    
2901      /* Match a single character, caselessly */      /* Match a single character, caselessly */
2902    
2903      case OP_CHARNC:      case OP_CHARI:
2904  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2905      if (utf8)      if (utf8)
2906        {        {
# Line 2544  for (;;) Line 2911  for (;;)
2911        if (length > md->end_subject - eptr)        if (length > md->end_subject - eptr)
2912          {          {
2913          CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */          CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2914          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2915          }          }
2916    
2917        /* If the pattern character's value is < 128, we have only one byte, and        /* If the pattern character's value is < 128, we have only one byte, and
# Line 2552  for (;;) Line 2919  for (;;)
2919    
2920        if (fc < 128)        if (fc < 128)
2921          {          {
2922          if (md->lcc[*ecode++] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          if (md->lcc[*ecode++] != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
2923          }          }
2924    
2925        /* Otherwise we must pick up the subject character */        /* Otherwise we must pick up the subject character */
# Line 2571  for (;;) Line 2938  for (;;)
2938  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2939            if (dc != UCD_OTHERCASE(fc))            if (dc != UCD_OTHERCASE(fc))
2940  #endif  #endif
2941              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
2942            }            }
2943          }          }
2944        }        }
# Line 2583  for (;;) Line 2950  for (;;)
2950        if (md->end_subject - eptr < 1)        if (md->end_subject - eptr < 1)
2951          {          {
2952          SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */          SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2953          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2954          }          }
2955        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
2956        ecode += 2;        ecode += 2;
2957        }        }
2958      break;      break;
# Line 2593  for (;;) Line 2960  for (;;)
2960      /* Match a single character repeatedly. */      /* Match a single character repeatedly. */
2961    
2962      case OP_EXACT:      case OP_EXACT:
2963        case OP_EXACTI:
2964      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
2965      ecode += 3;      ecode += 3;
2966      goto REPEATCHAR;      goto REPEATCHAR;
2967    
2968      case OP_POSUPTO:      case OP_POSUPTO:
2969        case OP_POSUPTOI:
2970      possessive = TRUE;      possessive = TRUE;
2971      /* Fall through */      /* Fall through */
2972    
2973      case OP_UPTO:      case OP_UPTO:
2974        case OP_UPTOI:
2975      case OP_MINUPTO:      case OP_MINUPTO:
2976        case OP_MINUPTOI:
2977      min = 0;      min = 0;
2978      max = GET2(ecode, 1);      max = GET2(ecode, 1);
2979      minimize = *ecode == OP_MINUPTO;      minimize = *ecode == OP_MINUPTO || *ecode == OP_MINUPTOI;
2980      ecode += 3;      ecode += 3;
2981      goto REPEATCHAR;      goto REPEATCHAR;
2982    
2983      case OP_POSSTAR:      case OP_POSSTAR:
2984        case OP_POSSTARI:
2985      possessive = TRUE;      possessive = TRUE;
2986      min = 0;      min = 0;
2987      max = INT_MAX;      max = INT_MAX;
# Line 2617  for (;;) Line 2989  for (;;)
2989      goto REPEATCHAR;      goto REPEATCHAR;
2990    
2991      case OP_POSPLUS:      case OP_POSPLUS:
2992        case OP_POSPLUSI:
2993      possessive = TRUE;      possessive = TRUE;
2994      min = 1;      min = 1;
2995      max = INT_MAX;      max = INT_MAX;
# Line 2624  for (;;) Line 2997  for (;;)
2997      goto REPEATCHAR;      goto REPEATCHAR;
2998    
2999      case OP_POSQUERY:      case OP_POSQUERY:
3000        case OP_POSQUERYI:
3001      possessive = TRUE;      possessive = TRUE;
3002      min = 0;      min = 0;
3003      max = 1;      max = 1;
# Line 2631  for (;;) Line 3005  for (;;)
3005      goto REPEATCHAR;      goto REPEATCHAR;
3006    
3007      case OP_STAR:      case OP_STAR:
3008        case OP_STARI:
3009      case OP_MINSTAR:      case OP_MINSTAR:
3010        case OP_MINSTARI:
3011      case OP_PLUS:      case OP_PLUS:
3012        case OP_PLUSI:
3013      case OP_MINPLUS:      case OP_MINPLUS:
3014        case OP_MINPLUSI:
3015      case OP_QUERY:      case OP_QUERY:
3016        case OP_QUERYI:
3017      case OP_MINQUERY:      case OP_MINQUERY:
3018      c = *ecode++ - OP_STAR;      case OP_MINQUERYI:
3019        c = *ecode++ - ((op < OP_STARI)? OP_STAR : OP_STARI);
3020      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
   
3021      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
3022      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
3023      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
# Line 2661  for (;;) Line 3040  for (;;)
3040          {          {
3041  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3042          unsigned int othercase;          unsigned int othercase;
3043          if ((ims & PCRE_CASELESS) != 0 &&          if (op >= OP_STARI &&     /* Caseless */
3044              (othercase = UCD_OTHERCASE(fc)) != fc)              (othercase = UCD_OTHERCASE(fc)) != fc)
3045            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
3046          else oclength = 0;          else oclength = 0;
# Line 2679  for (;;) Line 3058  for (;;)
3058            else            else
3059              {              {
3060              CHECK_PARTIAL();              CHECK_PARTIAL();
3061              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
3062              }              }
3063            }            }
3064    
# Line 2689  for (;;) Line 3068  for (;;)
3068            {            {
3069            for (fi = min;; fi++)            for (fi = min;; fi++)
3070              {              {
3071              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM22);
3072              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3073              if (fi >= max) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3074              if (eptr <= md->end_subject - length &&              if (eptr <= md->end_subject - length &&
3075                memcmp(eptr, charptr, length) == 0) eptr += length;                memcmp(eptr, charptr, length) == 0) eptr += length;
3076  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2702  for (;;) Line 3081  for (;;)
3081              else              else
3082                {                {
3083                CHECK_PARTIAL();                CHECK_PARTIAL();
3084                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3085                }                }
3086              }              }
3087            /* Control never gets here */            /* Control never gets here */
# Line 2731  for (;;) Line 3110  for (;;)
3110    
3111            for(;;)            for(;;)
3112              {              {
3113              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM23);
3114              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3115              if (eptr == pp) { RRETURN(MATCH_NOMATCH); }              if (eptr == pp) { MRRETURN(MATCH_NOMATCH); }
3116  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3117              eptr--;              eptr--;
3118              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2768  for (;;) Line 3147  for (;;)
3147      DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc, min, max,      DPRINTF(("matching %c{%d,%d} against subject %.*s\n", fc, min, max,
3148        max, eptr));        max, eptr));
3149    
3150      if ((ims & PCRE_CASELESS) != 0)      if (op >= OP_STARI)  /* Caseless */
3151        {        {
3152        fc = md->lcc[fc];        fc = md->lcc[fc];
3153        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
# Line 2776  for (;;) Line 3155  for (;;)
3155          if (eptr >= md->end_subject)          if (eptr >= md->end_subject)
3156            {            {
3157            SCHECK_PARTIAL();            SCHECK_PARTIAL();
3158            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
3159            }            }
3160          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          if (fc != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
3161          }          }
3162        if (min == max) continue;        if (min == max) continue;
3163        if (minimize)        if (minimize)
3164          {          {
3165          for (fi = min;; fi++)          for (fi = min;; fi++)
3166            {            {
3167            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM24);
3168            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3169            if (fi >= max) RRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
3170            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
3171              {              {
3172              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3173              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
3174              }              }
3175            if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);            if (fc != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
3176            }            }
3177          /* Control never gets here */          /* Control never gets here */
3178          }          }
# Line 2815  for (;;) Line 3194  for (;;)
3194    
3195          while (eptr >= pp)          while (eptr >= pp)
3196            {            {
3197            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM25);
3198            eptr--;            eptr--;
3199            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3200            }            }
3201          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
3202          }          }
3203        /* Control never gets here */        /* Control never gets here */
3204        }        }
# Line 2833  for (;;) Line 3212  for (;;)
3212          if (eptr >= md->end_subject)          if (eptr >= md->end_subject)
3213            {            {
3214            SCHECK_PARTIAL();            SCHECK_PARTIAL();
3215            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
3216            }            }
3217          if (fc != *eptr++) RRETURN(MATCH_NOMATCH);          if (fc != *eptr++) MRRETURN(MATCH_NOMATCH);
3218          }          }
3219    
3220        if (min == max) continue;        if (min == max) continue;
# Line 2844  for (;;) Line 3223  for (;;)
3223          {          {
3224          for (fi = min;; fi++)          for (fi = min;; fi++)
3225            {            {
3226            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM26);
3227            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3228            if (fi >= max) RRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
3229            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
3230              {              {
3231              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3232              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
3233              }              }
3234            if (fc != *eptr++) RRETURN(MATCH_NOMATCH);            if (fc != *eptr++) MRRETURN(MATCH_NOMATCH);
3235            }            }
3236          /* Control never gets here */          /* Control never gets here */
3237          }          }
# Line 2873  for (;;) Line 3252  for (;;)
3252    
3253          while (eptr >= pp)          while (eptr >= pp)
3254            {            {
3255            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM27);
3256            eptr--;            eptr--;
3257            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3258            }            }
3259          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
3260          }          }
3261        }        }
3262      /* Control never gets here */      /* Control never gets here */
# Line 2886  for (;;) Line 3265  for (;;)
3265      checking can be multibyte. */      checking can be multibyte. */
3266    
3267      case OP_NOT:      case OP_NOT:
3268        case OP_NOTI:
3269      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
3270        {        {
3271        SCHECK_PARTIAL();        SCHECK_PARTIAL();
3272        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
3273        }        }
3274      ecode++;      ecode++;
3275      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
3276      if ((ims & PCRE_CASELESS) != 0)      if (op == OP_NOTI)         /* The caseless case */
3277        {        {
3278  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
3279        if (c < 256)        if (c < 256)
3280  #endif  #endif
3281        c = md->lcc[c];        c = md->lcc[c];
3282        if (md->lcc[*ecode++] == c) RRETURN(MATCH_NOMATCH);        if (md->lcc[*ecode++] == c) MRRETURN(MATCH_NOMATCH);
3283        }        }
3284      else      else    /* Caseful */
3285        {        {
3286        if (*ecode++ == c) RRETURN(MATCH_NOMATCH);        if (*ecode++ == c) MRRETURN(MATCH_NOMATCH);
3287        }        }
3288      break;      break;
3289    
# Line 2915  for (;;) Line 3295  for (;;)
3295      about... */      about... */
3296    
3297      case OP_NOTEXACT:      case OP_NOTEXACT:
3298        case OP_NOTEXACTI:
3299      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
3300      ecode += 3;      ecode += 3;
3301      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3302    
3303      case OP_NOTUPTO:      case OP_NOTUPTO:
3304        case OP_NOTUPTOI:
3305      case OP_NOTMINUPTO:      case OP_NOTMINUPTO:
3306        case OP_NOTMINUPTOI:
3307      min = 0;      min = 0;
3308      max = GET2(ecode, 1);      max = GET2(ecode, 1);
3309      minimize = *ecode == OP_NOTMINUPTO;      minimize = *ecode == OP_NOTMINUPTO || *ecode == OP_NOTMINUPTOI;
3310      ecode += 3;      ecode += 3;
3311      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3312    
3313      case OP_NOTPOSSTAR:      case OP_NOTPOSSTAR:
3314        case OP_NOTPOSSTARI:
3315      possessive = TRUE;      possessive = TRUE;
3316      min = 0;      min = 0;
3317      max = INT_MAX;      max = INT_MAX;
# Line 2935  for (;;) Line 3319  for (;;)
3319      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3320    
3321      case OP_NOTPOSPLUS:      case OP_NOTPOSPLUS:
3322        case OP_NOTPOSPLUSI:
3323      possessive = TRUE;      possessive = TRUE;
3324      min = 1;      min = 1;
3325      max = INT_MAX;      max = INT_MAX;
# Line 2942  for (;;) Line 3327  for (;;)
3327      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3328    
3329      case OP_NOTPOSQUERY:      case OP_NOTPOSQUERY:
3330        case OP_NOTPOSQUERYI:
3331      possessive = TRUE;      possessive = TRUE;
3332      min = 0;      min = 0;
3333      max = 1;      max = 1;
# Line 2949  for (;;) Line 3335  for (;;)
3335      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3336    
3337      case OP_NOTPOSUPTO:      case OP_NOTPOSUPTO:
3338        case OP_NOTPOSUPTOI:
3339      possessive = TRUE;      possessive = TRUE;
3340      min = 0;      min = 0;
3341      max = GET2(ecode, 1);      max = GET2(ecode, 1);
# Line 2956  for (;;) Line 3343  for (;;)
3343      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3344    
3345      case OP_NOTSTAR:      case OP_NOTSTAR:
3346        case OP_NOTSTARI:
3347      case OP_NOTMINSTAR:      case OP_NOTMINSTAR:
3348        case OP_NOTMINSTARI:
3349      case OP_NOTPLUS:      case OP_NOTPLUS:
3350        case OP_NOTPLUSI:
3351      case OP_NOTMINPLUS:      case OP_NOTMINPLUS:
3352        case OP_NOTMINPLUSI:
3353      case OP_NOTQUERY:      case OP_NOTQUERY:
3354        case OP_NOTQUERYI:
3355      case OP_NOTMINQUERY:      case OP_NOTMINQUERY:
3356      c = *ecode++ - OP_NOTSTAR;      case OP_NOTMINQUERYI:
3357        c = *ecode++ - ((op >= OP_NOTSTARI)? OP_NOTSTARI: OP_NOTSTAR);
3358      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
3359      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
3360      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
# Line 2983  for (;;) Line 3376  for (;;)
3376      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,
3377        max, eptr));        max, eptr));
3378    
3379      if ((ims & PCRE_CASELESS) != 0)      if (op >= OP_NOTSTARI)     /* Caseless */
3380        {        {
3381        fc = md->lcc[fc];        fc = md->lcc[fc];
3382    
# Line 2997  for (;;) Line 3390  for (;;)
3390            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
3391              {              {
3392              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3393              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
3394              }              }
3395            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3396            if (d < 256) d = md->lcc[d];            if (d < 256) d = md->lcc[d];
3397            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) MRRETURN(MATCH_NOMATCH);
3398            }            }
3399          }          }
3400        else        else
# Line 3014  for (;;) Line 3407  for (;;)
3407            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
3408              {              {
3409              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3410              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
3411              }              }
3412            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);            if (fc == md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
3413            }            }
3414          }          }
3415    
# Line 3031  for (;;) Line 3424  for (;;)
3424            register unsigned int d;            register unsigned int d;
3425            for (fi = min;; fi++)            for (fi = min;; fi++)
3426              {              {
3427              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM28);
3428              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3429              if (fi >= max) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3430              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3431                {                {
3432                SCHECK_PARTIAL();                SCHECK_PARTIAL();
3433                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3434                }                }
3435              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3436              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
3437              if (fc == d) RRETURN(MATCH_NOMATCH);              if (fc == d) MRRETURN(MATCH_NOMATCH);
3438              }              }
3439            }            }
3440          else          else
# Line 3050  for (;;) Line 3443  for (;;)
3443            {            {
3444            for (fi = min;; fi++)            for (fi = min;; fi++)
3445              {              {
3446              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM29);
3447              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3448              if (fi >= max) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3449              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3450                {                {
3451                SCHECK_PARTIAL();                SCHECK_PARTIAL();
3452                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3453                }                }
3454              if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);              if (fc == md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
3455              }              }
3456            }            }
3457          /* Control never gets here */          /* Control never gets here */
# Line 3091  for (;;) Line 3484  for (;;)
3484          if (possessive) continue;          if (possessive) continue;
3485          for(;;)          for(;;)
3486              {              {
3487              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM30);
3488              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3489              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3490              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 3114  for (;;) Line 3507  for (;;)
3507            if (possessive) continue;            if (possessive) continue;
3508            while (eptr >= pp)            while (eptr >= pp)
3509              {              {
3510              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM31);
3511              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3512              eptr--;              eptr--;
3513              }              }
3514            }            }
3515    
3516          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
3517          }          }
3518        /* Control never gets here */        /* Control never gets here */
3519        }        }
# Line 3139  for (;;) Line 3532  for (;;)
3532            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
3533              {              {
3534              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3535              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
3536              }              }
3537            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3538            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) MRRETURN(MATCH_NOMATCH);
3539            }            }
3540          }          }
3541        else        else
# Line 3154  for (;;) Line 3547  for (;;)
3547            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
3548              {              {
3549              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3550              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
3551              }              }
3552            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);            if (fc == *eptr++) MRRETURN(MATCH_NOMATCH);
3553            }            }
3554          }          }
3555    
# Line 3171  for (;;) Line 3564  for (;;)
3564            register unsigned int d;            register unsigned int d;
3565            for (fi = min;; fi++)            for (fi = min;; fi++)
3566              {              {
3567              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM32);
3568              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3569              if (fi >= max) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3570              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3571                {                {
3572                SCHECK_PARTIAL();                SCHECK_PARTIAL();
3573                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3574                }                }
3575              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3576              if (fc == d) RRETURN(MATCH_NOMATCH);              if (fc == d) MRRETURN(MATCH_NOMATCH);
3577              }              }
3578            }            }
3579          else          else
# Line 3189  for (;;) Line 3582  for (;;)
3582            {            {
3583            for (fi = min;; fi++)            for (fi = min;; fi++)
3584              {              {
3585              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM33);
3586              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3587              if (fi >= max) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3588              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3589                {                {
3590                SCHECK_PARTIAL();                SCHECK_PARTIAL();
3591                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3592                }                }
3593              if (fc == *eptr++) RRETURN(MATCH_NOMATCH);              if (fc == *eptr++) MRRETURN(MATCH_NOMATCH);
3594              }              }
3595            }            }
3596          /* Control never gets here */          /* Control never gets here */
# Line 3229  for (;;) Line 3622  for (;;)
3622            if (possessive) continue;            if (possessive) continue;
3623            for(;;)            for(;;)
3624              {              {
3625              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM34);
3626              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3627              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3628              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 3252  for (;;) Line 3645  for (;;)
3645            if (possessive) continue;            if (possessive) continue;
3646            while (eptr >= pp)            while (eptr >= pp)
3647              {              {
3648              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM35);
3649              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3650              eptr--;              eptr--;
3651              }              }
3652            }            }
3653    
3654          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
3655          }          }
3656        }        }
3657      /* Control never gets here */      /* Control never gets here */
# Line 3352  for (;;) Line 3745  for (;;)
3745          switch(prop_type)          switch(prop_type)
3746            {            {
3747            case PT_ANY:            case PT_ANY:
3748            if (prop_fail_result) RRETURN(MATCH_NOMATCH);            if (prop_fail_result) MRRETURN(MATCH_NOMATCH);
3749            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3750              {              {
3751              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3752                {                {
3753                SCHECK_PARTIAL();                SCHECK_PARTIAL();
3754                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3755                }                }
3756              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3757              }              }
# Line 3370  for (;;) Line 3763  for (;;)
3763              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3764                {                {
3765                SCHECK_PARTIAL();                SCHECK_PARTIAL();
3766                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3767                }                }
3768              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3769              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
3770              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3771                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3772                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
3773                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3774              }              }
3775            break;            break;
3776    
# Line 3387  for (;;) Line 3780  for (;;)
3780              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3781                {                {
3782                SCHECK_PARTIAL();                SCHECK_PARTIAL();
3783                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3784                }                }
3785              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3786              prop_category = UCD_CATEGORY(c);              prop_category = UCD_CATEGORY(c);
3787              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3788                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3789              }              }
3790            break;            break;
3791    
# Line 3402  for (;;) Line 3795  for (;;)
3795              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3796                {                {
3797                SCHECK_PARTIAL();                SCHECK_PARTIAL();
3798                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3799                }                }
3800              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3801              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
3802              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3803                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3804              }              }
3805            break;            break;
3806    
# Line 3417  for (;;) Line 3810  for (;;)
3810              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3811                {                {
3812                SCHECK_PARTIAL();                SCHECK_PARTIAL();
3813                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3814                }                }
3815              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3816              prop_script = UCD_SCRIPT(c);              prop_script = UCD_SCRIPT(c);
3817              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3818                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3819                }
3820              break;
3821    
3822              case PT_ALNUM:
3823              for (i = 1; i <= min; i++)
3824                {
3825                if (eptr >= md->end_subject)
3826                  {
3827                  SCHECK_PARTIAL();
3828                  MRRETURN(MATCH_NOMATCH);
3829                  }
3830                GETCHARINCTEST(c, eptr);
3831                prop_category = UCD_CATEGORY(c);
3832                if ((prop_category == ucp_L || prop_category == ucp_N)
3833                       == prop_fail_result)
3834                  MRRETURN(MATCH_NOMATCH);
3835                }
3836              break;
3837    
3838              case PT_SPACE:    /* Perl space */
3839              for (i = 1; i <= min; i++)
3840                {
3841                if (eptr >= md->end_subject)
3842                  {
3843                  SCHECK_PARTIAL();
3844                  MRRETURN(MATCH_NOMATCH);
3845                  }
3846                GETCHARINCTEST(c, eptr);
3847                prop_category = UCD_CATEGORY(c);
3848                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
3849                     c == CHAR_FF || c == CHAR_CR)
3850                       == prop_fail_result)
3851                  MRRETURN(MATCH_NOMATCH);
3852                }
3853              break;
3854    
3855              case PT_PXSPACE:  /* POSIX space */
3856              for (i = 1; i <= min; i++)
3857                {
3858                if (eptr >= md->end_subject)
3859                  {
3860                  SCHECK_PARTIAL();
3861                  MRRETURN(MATCH_NOMATCH);
3862                  }
3863                GETCHARINCTEST(c, eptr);
3864                prop_category = UCD_CATEGORY(c);
3865                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
3866                     c == CHAR_VT || c == CHAR_FF || c == CHAR_CR)
3867                       == prop_fail_result)
3868                  MRRETURN(MATCH_NOMATCH);
3869                }
3870              break;
3871    
3872              case PT_WORD:
3873              for (i = 1; i <= min; i++)
3874                {
3875                if (eptr >= md->end_subject)
3876                  {
3877                  SCHECK_PARTIAL();
3878                  MRRETURN(MATCH_NOMATCH);
3879                  }
3880                GETCHARINCTEST(c, eptr);
3881                prop_category = UCD_CATEGORY(c);
3882                if ((prop_category == ucp_L || prop_category == ucp_N ||
3883                     c == CHAR_UNDERSCORE)
3884                       == prop_fail_result)
3885                  MRRETURN(MATCH_NOMATCH);
3886              }              }
3887            break;            break;
3888    
3889              /* This should not occur */
3890    
3891            default:            default:
3892            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
3893            }            }
# Line 3441  for (;;) Line 3903  for (;;)
3903            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
3904              {              {
3905              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3906              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
3907              }              }
3908            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3909            prop_category = UCD_CATEGORY(c);            prop_category = UCD_CATEGORY(c);
3910            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) MRRETURN(MATCH_NOMATCH);
3911            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3912              {              {
3913              int len = 1;              int len = 1;
# Line 3472  for (;;) Line 3934  for (;;)
3934            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
3935              {              {
3936              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3937              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
3938              }              }
3939            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);            if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);
3940            eptr++;            eptr++;
3941            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3942            }            }
# Line 3486  for (;;) Line 3948  for (;;)
3948            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
3949              {              {
3950              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3951              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
3952              }              }
3953            eptr++;            eptr++;
3954            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
# Line 3494  for (;;) Line 3956  for (;;)
3956          break;          break;
3957    
3958          case OP_ANYBYTE:          case OP_ANYBYTE:
3959          if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH);          if (eptr > md->end_subject - min) MRRETURN(MATCH_NOMATCH);
3960          eptr += min;          eptr += min;
3961          break;          break;
3962    
# Line 3504  for (;;) Line 3966  for (;;)
3966            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
3967              {              {
3968              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3969              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
3970              }              }
3971            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3972            switch(c)            switch(c)
3973              {              {
3974              default: RRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
3975    
3976              case 0x000d:              case 0x000d:
3977              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3978              break;              break;
# Line 3522  for (;;) Line 3985  for (;;)
3985              case 0x0085:              case 0x0085:
3986              case 0x2028:              case 0x2028:
3987              case 0x2029:              case 0x2029:
3988              if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);              if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
3989              break;              break;
3990              }              }
3991            }            }
# Line 3534  for (;;) Line 3997  for (;;)
3997            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
3998              {              {
3999              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4000              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4001              }              }
4002            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
4003            switch(c)            switch(c)
# Line 3559  for (;;) Line 4022  for (;;)
4022              case 0x202f:    /* NARROW NO-BREAK SPACE */              case 0x202f:    /* NARROW NO-BREAK SPACE */
4023              case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */              case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
4024              case 0x3000:    /* IDEOGRAPHIC SPACE */              case 0x3000:    /* IDEOGRAPHIC SPACE */
4025              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4026              }              }
4027            }            }
4028          break;          break;
# Line 3570  for (;;) Line 4033  for (;;)
4033            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4034              {              {
4035              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4036              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4037              }              }
4038            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
4039            switch(c)            switch(c)
4040              {              {
4041              default: RRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
4042              case 0x09:      /* HT */              case 0x09:      /* HT */
4043              case 0x20:      /* SPACE */              case 0x20:      /* SPACE */
4044              case 0xa0:      /* NBSP */              case 0xa0:      /* NBSP */
# Line 3606  for (;;) Line 4069  for (;;)
4069            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4070              {              {
4071              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4072              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4073              }              }
4074            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
4075            switch(c)            switch(c)
# Line 3619  for (;;) Line 4082  for (;;)
4082              case 0x85:      /* NEL */              case 0x85:      /* NEL */
4083              case 0x2028:    /* LINE SEPARATOR */              case 0x2028:    /* LINE SEPARATOR */
4084              case 0x2029:    /* PARAGRAPH SEPARATOR */              case 0x2029:    /* PARAGRAPH SEPARATOR */
4085              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4086              }              }
4087            }            }
4088          break;          break;
# Line 3630  for (;;) Line 4093  for (;;)
4093            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4094              {              {
4095              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4096              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4097              }              }
4098            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
4099            switch(c)            switch(c)
4100              {              {
4101              default: RRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
4102              case 0x0a:      /* LF */              case 0x0a:      /* LF */
4103              case 0x0b:      /* VT */              case 0x0b:      /* VT */
4104              case 0x0c:      /* FF */              case 0x0c:      /* FF */
# Line 3654  for (;;) Line 4117  for (;;)
4117            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4118              {              {
4119              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4120              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4121              }              }
4122            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
4123            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)
4124              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4125            }            }
4126          break;          break;
4127    
# Line 3668  for (;;) Line 4131  for (;;)
4131            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4132              {              {
4133              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4134              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4135              }              }
4136            if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)            if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)
4137              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4138            /* No need to skip more bytes - we know it's a 1-byte character */            /* No need to skip more bytes - we know it's a 1-byte character */
4139            }            }
4140          break;          break;
# Line 3682  for (;;) Line 4145  for (;;)
4145            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4146              {              {
4147              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4148              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4149              }              }
4150            if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)            if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)
4151              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4152            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
4153            }            }
4154          break;          break;
# Line 3696  for (;;) Line 4159  for (;;)
4159            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4160              {              {
4161              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4162              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4163              }              }
4164            if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)            if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)
4165              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4166            /* No need to skip more bytes - we know it's a 1-byte character */            /* No need to skip more bytes - we know it's a 1-byte character */
4167            }            }
4168          break;          break;
# Line 3710  for (;;) Line 4173  for (;;)
4173            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4174              {              {
4175              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4176              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4177              }              }
4178            if (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)            if (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)
4179              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4180            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
4181            }            }
4182          break;          break;
# Line 3724  for (;;) Line 4187  for (;;)
4187            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4188              {              {
4189              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4190              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4191              }              }
4192            if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)            if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)
4193              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4194            /* No need to skip more bytes - we know it's a 1-byte character */            /* No need to skip more bytes - we know it's a 1-byte character */
4195            }            }
4196          break;          break;
# Line 3750  for (;;) Line 4213  for (;;)
4213            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4214              {              {
4215              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4216              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4217              }              }
4218            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);            if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);
4219            eptr++;            eptr++;
4220            }            }
4221          break;          break;
# Line 3761  for (;;) Line 4224  for (;;)
4224          if (eptr > md->end_subject - min)          if (eptr > md->end_subject - min)
4225            {            {
4226            SCHECK_PARTIAL();            SCHECK_PARTIAL();
4227            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
4228            }            }
4229          eptr += min;          eptr += min;
4230          break;          break;
# Line 3770  for (;;) Line 4233  for (;;)
4233          if (eptr > md->end_subject - min)          if (eptr > md->end_subject - min)
4234            {            {
4235            SCHECK_PARTIAL();            SCHECK_PARTIAL();
4236            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
4237            }            }
4238          eptr += min;          eptr += min;
4239          break;          break;
# Line 3781  for (;;) Line 4244  for (;;)
4244            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4245              {              {
4246              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4247              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4248              }              }
4249            switch(*eptr++)            switch(*eptr++)
4250              {              {
4251              default: RRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
4252    
4253              case 0x000d:              case 0x000d:
4254              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
4255              break;              break;
4256    
4257              case 0x000a:              case 0x000a:
4258              break;              break;
4259    
4260              case 0x000b:              case 0x000b:
4261              case 0x000c:              case 0x000c:
4262              case 0x0085:              case 0x0085:
4263              if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);              if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
4264              break;              break;
4265              }              }
4266            }            }
# Line 3807  for (;;) Line 4272  for (;;)
4272            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4273              {              {
4274              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4275              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4276              }              }
4277            switch(*eptr++)            switch(*eptr++)
4278              {              {
# Line 3815  for (;;) Line 4280  for (;;)
4280              case 0x09:      /* HT */              case 0x09:      /* HT */
4281              case 0x20:      /* SPACE */              case 0x20:      /* SPACE */
4282              case 0xa0:      /* NBSP */              case 0xa0:      /* NBSP */
4283              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4284              }              }
4285            }            }
4286          break;          break;
# Line 3826  for (;;) Line 4291  for (;;)
4291            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4292              {              {
4293              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4294              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4295              }              }
4296            switch(*eptr++)            switch(*eptr++)
4297              {              {
4298              default: RRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
4299              case 0x09:      /* HT */              case 0x09:      /* HT */
4300              case 0x20:      /* SPACE */              case 0x20:      /* SPACE */
4301              case 0xa0:      /* NBSP */              case 0xa0:      /* NBSP */
# Line 3845  for (;;) Line 4310  for (;;)
4310            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4311              {              {
4312              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4313              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4314              }              }
4315            switch(*eptr++)            switch(*eptr++)
4316              {              {
# Line 3855  for (;;) Line 4320  for (;;)
4320              case 0x0c:      /* FF */              case 0x0c:      /* FF */
4321              case 0x0d:      /* CR */              case 0x0d:      /* CR */
4322              case 0x85:      /* NEL */              case 0x85:      /* NEL */
4323              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4324              }              }
4325            }            }
4326          break;          break;
# Line 3866  for (;;) Line 4331  for (;;)
4331            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4332              {              {
4333              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4334              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4335              }              }
4336            switch(*eptr++)            switch(*eptr++)
4337              {              {
4338              default: RRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
4339              case 0x0a:      /* LF */              case 0x0a:      /* LF */
4340              case 0x0b:      /* VT */              case 0x0b:      /* VT */
4341              case 0x0c:      /* FF */              case 0x0c:      /* FF */
# Line 3887  for (;;) Line 4352  for (;;)
4352            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4353              {              {
4354              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4355              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4356              }              }
4357            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) != 0) MRRETURN(MATCH_NOMATCH);
4358            }            }
4359          break;          break;
4360    
# Line 3899  for (;;) Line 4364  for (;;)
4364            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4365              {              {
4366              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4367              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4368              }              }
4369            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) == 0) MRRETURN(MATCH_NOMATCH);
4370            }            }
4371          break;          break;
4372    
# Line 3911  for (;;) Line 4376  for (;;)
4376            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4377              {              {
4378              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4379              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4380              }              }
4381            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) != 0) MRRETURN(MATCH_NOMATCH);
4382            }            }
4383          break;          break;
4384    
# Line 3923  for (;;) Line 4388  for (;;)
4388            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4389              {              {
4390              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4391              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4392              }              }
4393            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) == 0) MRRETURN(MATCH_NOMATCH);
4394            }            }
4395          break;          break;
4396    
# Line 3935  for (;;) Line 4400  for (;;)
4400            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4401              {              {
4402              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4403              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4404              }              }
4405            if ((md->ctypes[*eptr++] & ctype_word) != 0)            if ((md->ctypes[*eptr++] & ctype_word) != 0)
4406              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4407            }            }
4408          break;          break;
4409    
# Line 3948  for (;;) Line 4413  for (;;)
4413            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4414              {              {
4415              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4416              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4417              }              }
4418            if ((md->ctypes[*eptr++] & ctype_word) == 0)            if ((md->ctypes[*eptr++] & ctype_word) == 0)
4419              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4420            }            }
4421          break;          break;
4422    
# Line 3978  for (;;) Line 4443  for (;;)
4443            case PT_ANY:            case PT_ANY:
4444            for (fi = min;; fi++)            for (fi = min;; fi++)
4445              {              {
4446              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM36);
4447              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4448              if (fi >= max) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4449              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
4450                {                {
4451                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4452                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4453                }                }
4454              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
4455              if (prop_fail_result) RRETURN(MATCH_NOMATCH);              if (prop_fail_result) MRRETURN(MATCH_NOMATCH);
4456              }              }
4457            /* Control never gets here */            /* Control never gets here */
4458    
4459            case PT_LAMP:            case PT_LAMP:
4460            for (fi = min;; fi++)            for (fi = min;; fi++)
4461              {              {
4462              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM37);
4463              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4464              if (fi >= max) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4465              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
4466                {                {
4467                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4468                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4469                }                }
4470              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
4471              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
4472              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
4473                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
4474                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
4475                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4476              }              }
4477            /* Control never gets here */            /* Control never gets here */
4478    
4479            case PT_GC:            case PT_GC:
4480            for (fi = min;; fi++)            for (fi = min;; fi++)
4481              {              {
4482              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM38);
4483              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4484              if (fi >= max) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4485              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
4486                {                {
4487                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4488                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4489                }                }
4490              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
4491              prop_category = UCD_CATEGORY(c);              prop_category = UCD_CATEGORY(c);
4492              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
4493                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4494              }              }
4495            /* Control never gets here */            /* Control never gets here */
4496    
4497            case PT_PC:            case PT_PC:
4498            for (fi = min;; fi++)            for (fi = min;; fi++)
4499              {              {
4500              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM39);
4501              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4502              if (fi >= max) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4503              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
4504                {                {
4505                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4506                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4507                }                }
4508              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
4509              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
4510              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
4511                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4512              }              }
4513            /* Control never gets here */            /* Control never gets here */
4514    
4515            case PT_SC:            case PT_SC:
4516            for (fi = min;; fi++)            for (fi = min;; fi++)
4517              {              {
4518              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM40);
4519              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4520              if (fi >= max) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4521              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
4522                {                {
4523                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4524                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4525                }                }
4526              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
4527              prop_script = UCD_SCRIPT(c);              prop_script = UCD_SCRIPT(c);
4528              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
4529                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4530                }
4531              /* Control never gets here */
4532    
4533              case PT_ALNUM:
4534              for (fi = min;; fi++)
4535                {
4536                RMATCH(eptr, ecode, offset_top, md, eptrb, RM59);
4537                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4538                if (fi >= max) MRRETURN(MATCH_NOMATCH);
4539                if (eptr >= md->end_subject)
4540                  {
4541                  SCHECK_PARTIAL();
4542                  MRRETURN(MATCH_NOMATCH);
4543                  }
4544                GETCHARINCTEST(c, eptr);
4545                prop_category = UCD_CATEGORY(c);
4546                if ((prop_category == ucp_L || prop_category == ucp_N)
4547                       == prop_fail_result)
4548                  MRRETURN(MATCH_NOMATCH);
4549                }
4550              /* Control never gets here */
4551    
4552              case PT_SPACE:    /* Perl space */
4553              for (fi = min;; fi++)
4554                {
4555                RMATCH(eptr, ecode, offset_top, md, eptrb, RM60);
4556                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4557                if (fi >= max) MRRETURN(MATCH_NOMATCH);
4558                if (eptr >= md->end_subject)
4559                  {
4560                  SCHECK_PARTIAL();
4561                  MRRETURN(MATCH_NOMATCH);
4562                  }
4563                GETCHARINCTEST(c, eptr);
4564                prop_category = UCD_CATEGORY(c);
4565                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
4566                     c == CHAR_FF || c == CHAR_CR)
4567                       == prop_fail_result)
4568                  MRRETURN(MATCH_NOMATCH);
4569                }
4570              /* Control never gets here */
4571    
4572              case PT_PXSPACE:  /* POSIX space */
4573              for (fi = min;; fi++)
4574                {
4575                RMATCH(eptr, ecode, offset_top, md, eptrb, RM61);
4576                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4577                if (fi >= max) MRRETURN(MATCH_NOMATCH);
4578                if (eptr >= md->end_subject)
4579                  {
4580                  SCHECK_PARTIAL();
4581                  MRRETURN(MATCH_NOMATCH);
4582                  }
4583                GETCHARINCTEST(c, eptr);
4584                prop_category = UCD_CATEGORY(c);
4585                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
4586                     c == CHAR_VT || c == CHAR_FF || c == CHAR_CR)
4587                       == prop_fail_result)
4588                  MRRETURN(MATCH_NOMATCH);
4589                }
4590              /* Control never gets here */
4591    
4592              case PT_WORD:
4593              for (fi = min;; fi++)
4594                {
4595                RMATCH(eptr, ecode, offset_top, md, eptrb, RM62);
4596                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4597                if (fi >= max) MRRETURN(MATCH_NOMATCH);
4598                if (eptr >= md->end_subject)
4599                  {
4600                  SCHECK_PARTIAL();
4601                  MRRETURN(MATCH_NOMATCH);
4602                  }
4603                GETCHARINCTEST(c, eptr);
4604                prop_category = UCD_CATEGORY(c);
4605                if ((prop_category == ucp_L ||
4606                     prop_category == ucp_N ||
4607                     c == CHAR_UNDERSCORE)
4608                       == prop_fail_result)
4609                  MRRETURN(MATCH_NOMATCH);
4610              }              }
4611            /* Control never gets here */            /* Control never gets here */
4612    
4613              /* This should never occur */
4614    
4615            default:            default:
4616            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
4617            }            }
# Line 4077  for (;;) Line 4624  for (;;)
4624          {          {
4625          for (fi = min;; fi++)          for (fi = min;; fi++)
4626            {            {
4627            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM41);
4628            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4629            if (fi >= max) RRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
4630            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4631              {              {
4632              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4633              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4634              }              }
4635            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
4636            prop_category = UCD_CATEGORY(c);            prop_category = UCD_CATEGORY(c);
4637            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) MRRETURN(MATCH_NOMATCH);
4638            while (eptr < md->end_subject)            while (eptr < md->end_subject)
4639              {              {
4640              int len = 1;              int len = 1;
# Line 4109  for (;;) Line 4656  for (;;)
4656          {          {
4657          for (fi = min;; fi++)          for (fi = min;; fi++)
4658            {            {
4659            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM42);
4660            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4661            if (fi >= max) RRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
4662            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4663              {              {
4664              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4665              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4666              }              }
4667            if (ctype == OP_ANY && IS_NEWLINE(eptr))            if (ctype == OP_ANY && IS_NEWLINE(eptr))
4668              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4669            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
4670            switch(ctype)            switch(ctype)
4671              {              {
# Line 4130  for (;;) Line 4677  for (;;)
4677              case OP_ANYNL:              case OP_ANYNL:
4678              switch(c)              switch(c)
4679                {                {
4680                default: RRETURN(MATCH_NOMATCH);                default: MRRETURN(MATCH_NOMATCH);
4681                case 0x000d:                case 0x000d:
4682                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
4683                break;                break;
# Line 4142  for (;;) Line 4689  for (;;)
4689                case 0x0085:                case 0x0085:
4690                case 0x2028:                case 0x2028:
4691                case 0x2029:                case 0x2029:
4692                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);                if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
4693                break;                break;
4694                }                }
4695              break;              break;
# Line 4170  for (;;) Line 4717  for (;;)
4717                case 0x202f:    /* NARROW NO-BREAK SPACE */                case 0x202f:    /* NARROW NO-BREAK SPACE */
4718                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
4719                case 0x3000:    /* IDEOGRAPHIC SPACE */                case 0x3000:    /* IDEOGRAPHIC SPACE */
4720                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4721                }                }
4722              break;              break;
4723    
4724              case OP_HSPACE:              case OP_HSPACE:
4725              switch(c)              switch(c)
4726                {                {
4727                default: RRETURN(MATCH_NOMATCH);                default: MRRETURN(MATCH_NOMATCH);
4728                case 0x09:      /* HT */                case 0x09:      /* HT */
4729                case 0x20:      /* SPACE */                case 0x20:      /* SPACE */
4730                case 0xa0:      /* NBSP */                case 0xa0:      /* NBSP */
# Line 4212  for (;;) Line 4759  for (;;)
4759                case 0x85:      /* NEL */                case 0x85:      /* NEL */
4760                case 0x2028:    /* LINE SEPARATOR */                case 0x2028:    /* LINE SEPARATOR */
4761                case 0x2029:    /* PARAGRAPH SEPARATOR */                case 0x2029:    /* PARAGRAPH SEPARATOR */
4762                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4763                }                }
4764              break;              break;
4765    
4766              case OP_VSPACE:              case OP_VSPACE:
4767              switch(c)              switch(c)
4768                {                {
4769                default: RRETURN(MATCH_NOMATCH);                default: MRRETURN(MATCH_NOMATCH);
4770                case 0x0a:      /* LF */                case 0x0a:      /* LF */
4771                case 0x0b:      /* VT */                case 0x0b:      /* VT */
4772                case 0x0c:      /* FF */                case 0x0c:      /* FF */
# Line 4233  for (;;) Line 4780  for (;;)
4780    
4781              case OP_NOT_DIGIT:              case OP_NOT_DIGIT:
4782              if (c < 256 && (md->ctypes[c] & ctype_digit) != 0)              if (c < 256 && (md->ctypes[c] & ctype_digit) != 0)
4783                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4784              break;              break;
4785    
4786              case OP_DIGIT:              case OP_DIGIT:
4787              if (c >= 256 || (md->ctypes[c] & ctype_digit) == 0)              if (c >= 256 || (md->ctypes[c] & ctype_digit) == 0)
4788                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4789              break;              break;
4790    
4791              case OP_NOT_WHITESPACE:              case OP_NOT_WHITESPACE:
4792              if (c < 256 && (md->ctypes[c] & ctype_space) != 0)              if (c < 256 && (md->ctypes[c] & ctype_space) != 0)
4793                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4794              break;              break;
4795    
4796              case OP_WHITESPACE:              case OP_WHITESPACE:
4797              if  (c >= 256 || (md->ctypes[c] & ctype_space) == 0)              if  (c >= 256 || (md->ctypes[c] & ctype_space) == 0)
4798                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4799              break;              break;
4800    
4801              case OP_NOT_WORDCHAR:              case OP_NOT_WORDCHAR:
4802              if (c < 256 && (md->ctypes[c] & ctype_word) != 0)