/[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 91 by nigel, Sat Feb 24 21:41:34 2007 UTC revision 563 by ph10, Sun Oct 31 14:15:04 2010 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-2006 University of Cambridge             Copyright (c) 1997-2010 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 42  POSSIBILITY OF SUCH DAMAGE. Line 42  POSSIBILITY OF SUCH DAMAGE.
42  pattern matching using an NFA algorithm, trying to mimic Perl as closely as  pattern matching using an NFA algorithm, trying to mimic Perl as closely as
43  possible. There are also some static supporting functions. */  possible. There are also some static supporting functions. */
44    
45  #define NLBLOCK md           /* The block containing newline information */  #ifdef HAVE_CONFIG_H
46    #include "config.h"
47    #endif
48    
49    #define NLBLOCK md             /* Block containing newline information */
50    #define PSSTART start_subject  /* Field containing processed string start */
51    #define PSEND   end_subject    /* Field containing processed string end */
52    
53  #include "pcre_internal.h"  #include "pcre_internal.h"
54    
55    /* Undefine some potentially clashing cpp symbols */
56    
57  /* Structure for building a chain of data that actually lives on the  #undef min
58  stack, for holding the values of the subject pointer at the start of each  #undef max
 subpattern, so as to detect when an empty string has been matched by a  
 subpattern - to break infinite loops. When NO_RECURSE is set, these blocks  
 are on the heap, not on the stack. */  
   
 typedef struct eptrblock {  
   struct eptrblock *epb_prev;  
   USPTR epb_saved_eptr;  
 } eptrblock;  
59    
60  /* Flag bits for the match() function */  /* Flag bits for the match() function */
61    
62  #define match_condassert   0x01    /* Called to check a condition assertion */  #define match_condassert     0x01  /* Called to check a condition assertion */
63  #define match_isgroup      0x02    /* Set if start of bracketed group */  #define match_cbegroup       0x02  /* Could-be-empty unlimited repeat group */
64    
65  /* Non-error returns from the match() function. Error returns are externally  /* Non-error returns from the match() function. Error returns are externally
66  defined PCRE_ERROR_xxx codes, which are all negative. */  defined PCRE_ERROR_xxx codes, which are all negative. */
# Line 68  defined PCRE_ERROR_xxx codes, which are Line 68  defined PCRE_ERROR_xxx codes, which are
68  #define MATCH_MATCH        1  #define MATCH_MATCH        1
69  #define MATCH_NOMATCH      0  #define MATCH_NOMATCH      0
70    
71    /* Special internal returns from the match() function. Make them sufficiently
72    negative to avoid the external error codes. */
73    
74    #define MATCH_ACCEPT       (-999)
75    #define MATCH_COMMIT       (-998)
76    #define MATCH_PRUNE        (-997)
77    #define MATCH_SKIP         (-996)
78    #define MATCH_SKIP_ARG     (-995)
79    #define MATCH_THEN         (-994)
80    
81    /* This is a convenience macro for code that occurs many times. */
82    
83    #define MRRETURN(ra) \
84      { \
85      md->mark = markptr; \
86      RRETURN(ra); \
87      }
88    
89  /* 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.
90  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,
91  because the offset vector is always a multiple of 3 long. */  because the offset vector is always a multiple of 3 long. */
# Line 81  static const char rep_max[] = { 0, 0, 0, Line 99  static const char rep_max[] = { 0, 0, 0,
99    
100    
101    
102  #ifdef DEBUG  #ifdef PCRE_DEBUG
103  /*************************************************  /*************************************************
104  *        Debugging function to print chars       *  *        Debugging function to print chars       *
105  *************************************************/  *************************************************/
# Line 101  Returns:     nothing Line 119  Returns:     nothing
119  static void  static void
120  pchars(const uschar *p, int length, BOOL is_subject, match_data *md)  pchars(const uschar *p, int length, BOOL is_subject, match_data *md)
121  {  {
122  int c;  unsigned int c;
123  if (is_subject && length > md->end_subject - p) length = md->end_subject - p;  if (is_subject && length > md->end_subject - p) length = md->end_subject - p;
124  while (length-- > 0)  while (length-- > 0)
125    if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c);    if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c);
# Line 133  match_ref(int offset, register USPTR ept Line 151  match_ref(int offset, register USPTR ept
151  {  {
152  USPTR p = md->start_subject + md->offset_vector[offset];  USPTR p = md->start_subject + md->offset_vector[offset];
153    
154  #ifdef DEBUG  #ifdef PCRE_DEBUG
155  if (eptr >= md->end_subject)  if (eptr >= md->end_subject)
156    printf("matching subject <null>");    printf("matching subject <null>");
157  else  else
# Line 150  printf("\n"); Line 168  printf("\n");
168    
169  if (length > md->end_subject - eptr) return FALSE;  if (length > md->end_subject - eptr) return FALSE;
170    
171  /* Separate the caselesss case for speed */  /* Separate the caseless case for speed. In UTF-8 mode we can only do this
172    properly if Unicode properties are supported. Otherwise, we can check only
173    ASCII characters. */
174    
175  if ((ims & PCRE_CASELESS) != 0)  if ((ims & PCRE_CASELESS) != 0)
176    {    {
177    #ifdef SUPPORT_UTF8
178    #ifdef SUPPORT_UCP
179      if (md->utf8)
180        {
181        USPTR endptr = eptr + length;
182        while (eptr < endptr)
183          {
184          int c, d;
185          GETCHARINC(c, eptr);
186          GETCHARINC(d, p);
187          if (c != d && c != UCD_OTHERCASE(d)) return FALSE;
188          }
189        }
190      else
191    #endif
192    #endif
193    
194      /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
195      is no UCP support. */
196    
197    while (length-- > 0)    while (length-- > 0)
198      if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE;      { if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; }
199    }    }
200    
201    /* In the caseful case, we can just compare the bytes, whether or not we
202    are in UTF-8 mode. */
203    
204  else  else
205    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
206    
# Line 186  calls by keeping local variables that ne Line 230  calls by keeping local variables that ne
230  obtained from malloc() instead instead of on the stack. Macros are used to  obtained from malloc() instead instead of on the stack. Macros are used to
231  achieve this so that the actual code doesn't look very different to what it  achieve this so that the actual code doesn't look very different to what it
232  always used to.  always used to.
233    
234    The original heap-recursive code used longjmp(). However, it seems that this
235    can be very slow on some operating systems. Following a suggestion from Stan
236    Switzer, the use of longjmp() has been abolished, at the cost of having to
237    provide a unique number for each call to RMATCH. There is no way of generating
238    a sequence of numbers at compile time in C. I have given them names, to make
239    them stand out more clearly.
240    
241    Crude tests on x86 Linux show a small speedup of around 5-8%. However, on
242    FreeBSD, avoiding longjmp() more than halves the time taken to run the standard
243    tests. Furthermore, not using longjmp() means that local dynamic variables
244    don't have indeterminate values; this has meant that the frame size can be
245    reduced because the result can be "passed back" by straight setting of the
246    variable instead of being passed in the frame.
247  ****************************************************************************  ****************************************************************************
248  ***************************************************************************/  ***************************************************************************/
249    
250    /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN
251    below must be updated in sync.  */
252    
253    enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM6,  RM7,  RM8,  RM9,  RM10,
254           RM11,  RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,
255           RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,
256           RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
257           RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
258           RM51,  RM52, RM53, RM54, RM55, RM56, RM57, RM58, RM59, RM60,
259           RM61,  RM62 };
260    
261  /* 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
262  versions and production versions. */  versions and production versions. Note that the "rw" argument of RMATCH isn't
263    actually used in this definition. */
264    
265  #ifndef NO_RECURSE  #ifndef NO_RECURSE
266  #define REGISTER register  #define REGISTER register
267  #ifdef DEBUG  
268  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #ifdef PCRE_DEBUG
269    #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
270    { \    { \
271    printf("match() called in line %d\n", __LINE__); \    printf("match() called in line %d\n", __LINE__); \
272    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1); \    rrc = match(ra,rb,mstart,markptr,rc,rd,re,rf,rg,rdepth+1); \
273    printf("to line %d\n", __LINE__); \    printf("to line %d\n", __LINE__); \
274    }    }
275  #define RRETURN(ra) \  #define RRETURN(ra) \
# Line 208  versions and production versions. */ Line 278  versions and production versions. */
278    return ra; \    return ra; \
279    }    }
280  #else  #else
281  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
282    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1)    rrc = match(ra,rb,mstart,markptr,rc,rd,re,rf,rg,rdepth+1)
283  #define RRETURN(ra) return ra  #define RRETURN(ra) return ra
284  #endif  #endif
285    
286  #else  #else
287    
288    
289  /* These versions of the macros manage a private stack on the heap. Note  /* These versions of the macros manage a private stack on the heap. Note that
290  that the rd argument of RMATCH isn't actually used. It's the md argument of  the "rd" argument of RMATCH isn't actually used in this definition. It's the md
291  match(), which never changes. */  argument of match(), which never changes. */
292    
293  #define REGISTER  #define REGISTER
294    
295  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg)\  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\
296    {\    {\
297    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\    heapframe *newframe = (heapframe *)(pcre_stack_malloc)(sizeof(heapframe));\
298    if (setjmp(frame->Xwhere) == 0)\    if (newframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\
299      {\    frame->Xwhere = rw; \
300      newframe->Xeptr = ra;\    newframe->Xeptr = ra;\
301      newframe->Xecode = rb;\    newframe->Xecode = rb;\
302      newframe->Xoffset_top = rc;\    newframe->Xmstart = mstart;\
303      newframe->Xims = re;\    newframe->Xmarkptr = markptr;\
304      newframe->Xeptrb = rf;\    newframe->Xoffset_top = rc;\
305      newframe->Xflags = rg;\    newframe->Xims = re;\
306      newframe->Xrdepth = frame->Xrdepth + 1;\    newframe->Xeptrb = rf;\
307      newframe->Xprevframe = frame;\    newframe->Xflags = rg;\
308      frame = newframe;\    newframe->Xrdepth = frame->Xrdepth + 1;\
309      DPRINTF(("restarting from line %d\n", __LINE__));\    newframe->Xprevframe = frame;\
310      goto HEAP_RECURSE;\    frame = newframe;\
311      }\    DPRINTF(("restarting from line %d\n", __LINE__));\
312    else\    goto HEAP_RECURSE;\
313      {\    L_##rw:\
314      DPRINTF(("longjumped back to line %d\n", __LINE__));\    DPRINTF(("jumped back to line %d\n", __LINE__));\
     frame = md->thisframe;\  
     rx = frame->Xresult;\  
     }\  
315    }    }
316    
317  #define RRETURN(ra)\  #define RRETURN(ra)\
318    {\    {\
319    heapframe *newframe = frame;\    heapframe *oldframe = frame;\
320    frame = newframe->Xprevframe;\    frame = oldframe->Xprevframe;\
321    (pcre_stack_free)(newframe);\    (pcre_stack_free)(oldframe);\
322    if (frame != NULL)\    if (frame != NULL)\
323      {\      {\
324      frame->Xresult = ra;\      rrc = ra;\
325      md->thisframe = frame;\      goto HEAP_RETURN;\
     longjmp(frame->Xwhere, 1);\  
326      }\      }\
327    return ra;\    return ra;\
328    }    }
# Line 269  typedef struct heapframe { Line 335  typedef struct heapframe {
335    
336    /* Function arguments that may change */    /* Function arguments that may change */
337    
338    const uschar *Xeptr;    USPTR Xeptr;
339    const uschar *Xecode;    const uschar *Xecode;
340      USPTR Xmstart;
341      USPTR Xmarkptr;
342    int Xoffset_top;    int Xoffset_top;
343    long int Xims;    long int Xims;
344    eptrblock *Xeptrb;    eptrblock *Xeptrb;
# Line 279  typedef struct heapframe { Line 347  typedef struct heapframe {
347    
348    /* Function local variables */    /* Function local variables */
349    
350    const uschar *Xcallpat;    USPTR Xcallpat;
351    const uschar *Xcharptr;  #ifdef SUPPORT_UTF8
352    const uschar *Xdata;    USPTR Xcharptr;
353    const uschar *Xnext;  #endif
354    const uschar *Xpp;    USPTR Xdata;
355    const uschar *Xprev;    USPTR Xnext;
356    const uschar *Xsaved_eptr;    USPTR Xpp;
357      USPTR Xprev;
358      USPTR Xsaved_eptr;
359    
360    recursion_info Xnew_recursive;    recursion_info Xnew_recursive;
361    
362    BOOL Xcur_is_word;    BOOL Xcur_is_word;
363    BOOL Xcondition;    BOOL Xcondition;
   BOOL Xminimize;  
364    BOOL Xprev_is_word;    BOOL Xprev_is_word;
365    
366    unsigned long int Xoriginal_ims;    unsigned long int Xoriginal_ims;
# Line 303  typedef struct heapframe { Line 372  typedef struct heapframe {
372    int Xprop_category;    int Xprop_category;
373    int Xprop_chartype;    int Xprop_chartype;
374    int Xprop_script;    int Xprop_script;
375    int *Xprop_test_variable;    int Xoclength;
376      uschar Xocchars[8];
377  #endif  #endif
378    
379      int Xcodelink;
380    int Xctype;    int Xctype;
381    int Xfc;    unsigned int Xfc;
382    int Xfi;    int Xfi;
383    int Xlength;    int Xlength;
384    int Xmax;    int Xmax;
# Line 321  typedef struct heapframe { Line 392  typedef struct heapframe {
392    
393    eptrblock Xnewptrb;    eptrblock Xnewptrb;
394    
395    /* Place to pass back result, and where to jump back to */    /* Where to jump back to */
396    
397    int  Xresult;    int Xwhere;
   jmp_buf Xwhere;  
398    
399  } heapframe;  } heapframe;
400    
# Line 340  typedef struct heapframe { Line 410  typedef struct heapframe {
410  *         Match from current position            *  *         Match from current position            *
411  *************************************************/  *************************************************/
412    
413  /* On entry ecode points to the first opcode, and eptr to the first character  /* This function is called recursively in many circumstances. Whenever it
 in the subject string, while eptrb holds the value of eptr at the start of the  
 last bracketed group - used for breaking infinite loops matching zero-length  
 strings. This function is called recursively in many circumstances. Whenever it  
414  returns a negative (error) response, the outer incarnation must also return the  returns a negative (error) response, the outer incarnation must also return the
415  same response.  same response. */
416    
417    /* These macros pack up tests that are used for partial matching, and which
418    appears several times in the code. We set the "hit end" flag if the pointer is
419    at the end of the subject and also past the start of the subject (i.e.
420    something has been matched). For hard partial matching, we then return
421    immediately. The second one is used when we already know we are past the end of
422    the subject. */
423    
424    #define CHECK_PARTIAL()\
425      if (md->partial != 0 && eptr >= md->end_subject && \
426          eptr > md->start_used_ptr) \
427        { \
428        md->hitend = TRUE; \
429        if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL); \
430        }
431    
432    #define SCHECK_PARTIAL()\
433      if (md->partial != 0 && eptr > md->start_used_ptr) \
434        { \
435        md->hitend = TRUE; \
436        if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL); \
437        }
438    
439    
440  Performance note: It might be tempting to extract commonly used fields from the  /* Performance note: It might be tempting to extract commonly used fields from
441  md structure (e.g. utf8, end_subject) into individual variables to improve  the md structure (e.g. utf8, end_subject) into individual variables to improve
442  performance. Tests using gcc on a SPARC disproved this; in the first case, it  performance. Tests using gcc on a SPARC disproved this; in the first case, it
443  made performance worse.  made performance worse.
444    
445  Arguments:  Arguments:
446     eptr        pointer in subject     eptr        pointer to current character in subject
447     ecode       position in code     ecode       pointer to current position in compiled code
448       mstart      pointer to the current match start position (can be modified
449                     by encountering \K)
450       markptr     pointer to the most recent MARK name, or NULL
451     offset_top  current top pointer     offset_top  current top pointer
452     md          pointer to "static" info for the match     md          pointer to "static" info for the match
453     ims         current /i, /m, and /s options     ims         current /i, /m, and /s options
# Line 362  Arguments: Line 455  Arguments:
455                   brackets - for testing for empty matches                   brackets - for testing for empty matches
456     flags       can contain     flags       can contain
457                   match_condassert - this is an assertion condition                   match_condassert - this is an assertion condition
458                   match_isgroup - this is the start of a bracketed group                   match_cbegroup - this is the start of an unlimited repeat
459                       group that can match an empty string
460     rdepth      the recursion depth     rdepth      the recursion depth
461    
462  Returns:       MATCH_MATCH if matched            )  these values are >= 0  Returns:       MATCH_MATCH if matched            )  these values are >= 0
463                 MATCH_NOMATCH if failed to match  )                 MATCH_NOMATCH if failed to match  )
464                   a negative MATCH_xxx value for PRUNE, SKIP, etc
465                 a negative PCRE_ERROR_xxx value if aborted by an error condition                 a negative PCRE_ERROR_xxx value if aborted by an error condition
466                   (e.g. stopped by repeated call or recursion limit)                   (e.g. stopped by repeated call or recursion limit)
467  */  */
468    
469  static int  static int
470  match(REGISTER USPTR eptr, REGISTER const uschar *ecode,  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart,
471    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,    const uschar *markptr, int offset_top, match_data *md, unsigned long int ims,
472    int flags, unsigned int rdepth)    eptrblock *eptrb, int flags, unsigned int rdepth)
473  {  {
474  /* 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,
475  so they can be ordinary variables in all cases. Mark them with "register"  so they can be ordinary variables in all cases. Mark some of them with
476  because they are used a lot in loops. */  "register" because they are used a lot in loops. */
477    
478  register int  rrc;         /* Returns from recursive calls */  register int  rrc;         /* Returns from recursive calls */
479  register int  i;           /* Used for loops not involving calls to RMATCH() */  register int  i;           /* Used for loops not involving calls to RMATCH() */
480  register unsigned int  c;  /* Character values not kept over RMATCH() calls */  register unsigned int c;   /* Character values not kept over RMATCH() calls */
481  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
482    
483    BOOL minimize, possessive; /* Quantifier options */
484    int condcode;
485    
486  /* 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
487  preserved over calls to RMATCH() are part of a "frame" which is obtained from  preserved over calls to RMATCH() are part of a "frame" which is obtained from
488  heap storage. Set up the top-level frame here; others are obtained from the  heap storage. Set up the top-level frame here; others are obtained from the
489  heap whenever RMATCH() does a "recursion". See the macro definitions above. */  heap whenever RMATCH() does a "recursion". See the macro definitions above. */
490    
491  #ifdef NO_RECURSE  #ifdef NO_RECURSE
492  heapframe *frame = (pcre_stack_malloc)(sizeof(heapframe));  heapframe *frame = (heapframe *)(pcre_stack_malloc)(sizeof(heapframe));
493    if (frame == NULL) RRETURN(PCRE_ERROR_NOMEMORY);
494  frame->Xprevframe = NULL;            /* Marks the top level */  frame->Xprevframe = NULL;            /* Marks the top level */
495    
496  /* Copy in the original argument variables */  /* Copy in the original argument variables */
497    
498  frame->Xeptr = eptr;  frame->Xeptr = eptr;
499  frame->Xecode = ecode;  frame->Xecode = ecode;
500    frame->Xmstart = mstart;
501    frame->Xmarkptr = markptr;
502  frame->Xoffset_top = offset_top;  frame->Xoffset_top = offset_top;
503  frame->Xims = ims;  frame->Xims = ims;
504  frame->Xeptrb = eptrb;  frame->Xeptrb = eptrb;
# Line 412  HEAP_RECURSE: Line 513  HEAP_RECURSE:
513    
514  #define eptr               frame->Xeptr  #define eptr               frame->Xeptr
515  #define ecode              frame->Xecode  #define ecode              frame->Xecode
516    #define mstart             frame->Xmstart
517    #define markptr            frame->Xmarkptr
518  #define offset_top         frame->Xoffset_top  #define offset_top         frame->Xoffset_top
519  #define ims                frame->Xims  #define ims                frame->Xims
520  #define eptrb              frame->Xeptrb  #define eptrb              frame->Xeptrb
# Line 424  HEAP_RECURSE: Line 527  HEAP_RECURSE:
527  #define charptr            frame->Xcharptr  #define charptr            frame->Xcharptr
528  #endif  #endif
529  #define callpat            frame->Xcallpat  #define callpat            frame->Xcallpat
530    #define codelink           frame->Xcodelink
531  #define data               frame->Xdata  #define data               frame->Xdata
532  #define next               frame->Xnext  #define next               frame->Xnext
533  #define pp                 frame->Xpp  #define pp                 frame->Xpp
# Line 434  HEAP_RECURSE: Line 538  HEAP_RECURSE:
538    
539  #define cur_is_word        frame->Xcur_is_word  #define cur_is_word        frame->Xcur_is_word
540  #define condition          frame->Xcondition  #define condition          frame->Xcondition
 #define minimize           frame->Xminimize  
541  #define prev_is_word       frame->Xprev_is_word  #define prev_is_word       frame->Xprev_is_word
542    
543  #define original_ims       frame->Xoriginal_ims  #define original_ims       frame->Xoriginal_ims
# Line 446  HEAP_RECURSE: Line 549  HEAP_RECURSE:
549  #define prop_category      frame->Xprop_category  #define prop_category      frame->Xprop_category
550  #define prop_chartype      frame->Xprop_chartype  #define prop_chartype      frame->Xprop_chartype
551  #define prop_script        frame->Xprop_script  #define prop_script        frame->Xprop_script
552  #define prop_test_variable frame->Xprop_test_variable  #define oclength           frame->Xoclength
553    #define occhars            frame->Xocchars
554  #endif  #endif
555    
556  #define ctype              frame->Xctype  #define ctype              frame->Xctype
# Line 470  HEAP_RECURSE: Line 574  HEAP_RECURSE:
574  get preserved during recursion in the normal way. In this environment, fi and  get preserved during recursion in the normal way. In this environment, fi and
575  i, and fc and c, can be the same variables. */  i, and fc and c, can be the same variables. */
576    
577  #else  #else         /* NO_RECURSE not defined */
578  #define fi i  #define fi i
579  #define fc c  #define fc c
580    
# Line 489  recursion_info new_recursive;      /* wi Line 593  recursion_info new_recursive;      /* wi
593                                     /* that do not have to be preserved over  */                                     /* that do not have to be preserved over  */
594  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */
595  BOOL condition;  BOOL condition;
 BOOL minimize;  
596  BOOL prev_is_word;  BOOL prev_is_word;
597    
598  unsigned long int original_ims;  unsigned long int original_ims;
# Line 501  int prop_fail_result; Line 604  int prop_fail_result;
604  int prop_category;  int prop_category;
605  int prop_chartype;  int prop_chartype;
606  int prop_script;  int prop_script;
607  int *prop_test_variable;  int oclength;
608    uschar occhars[8];
609  #endif  #endif
610    
611    int codelink;
612  int ctype;  int ctype;
613  int length;  int length;
614  int max;  int max;
# Line 516  int save_offset1, save_offset2, save_off Line 621  int save_offset1, save_offset2, save_off
621  int stacksave[REC_STACK_SAVE_MAX];  int stacksave[REC_STACK_SAVE_MAX];
622    
623  eptrblock newptrb;  eptrblock newptrb;
624  #endif  #endif     /* NO_RECURSE */
625    
626  /* These statements are here to stop the compiler complaining about unitialized  /* These statements are here to stop the compiler complaining about unitialized
627  variables. */  variables. */
# Line 524  variables. */ Line 629  variables. */
629  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
630  prop_value = 0;  prop_value = 0;
631  prop_fail_result = 0;  prop_fail_result = 0;
 prop_test_variable = NULL;  
632  #endif  #endif
633    
634    
635  /* This label is used for tail recursion, which is used in a few cases even  /* This label is used for tail recursion, which is used in a few cases even
636  when NO_RECURSE is not defined, in order to reduce the amount of stack that is  when NO_RECURSE is not defined, in order to reduce the amount of stack that is
637  used. Thanks to Ian Taylor for noticing this possibility and sending the  used. Thanks to Ian Taylor for noticing this possibility and sending the
# Line 537  TAIL_RECURSE: Line 642  TAIL_RECURSE:
642  /* OK, now we can get on with the real code of the function. Recursive calls  /* OK, now we can get on with the real code of the function. Recursive calls
643  are specified by the macro RMATCH and RRETURN is used to return. When  are specified by the macro RMATCH and RRETURN is used to return. When
644  NO_RECURSE is *not* defined, these just turn into a recursive call to match()  NO_RECURSE is *not* defined, these just turn into a recursive call to match()
645  and a "return", respectively (possibly with some debugging if DEBUG is  and a "return", respectively (possibly with some debugging if PCRE_DEBUG is
646  defined). However, RMATCH isn't like a function call because it's quite a  defined). However, RMATCH isn't like a function call because it's quite a
647  complicated macro. It has to be used in one particular way. This shouldn't,  complicated macro. It has to be used in one particular way. This shouldn't,
648  however, impact performance when true recursion is being used. */  however, impact performance when true recursion is being used. */
649    
650    #ifdef SUPPORT_UTF8
651    utf8 = md->utf8;       /* Local copy of the flag */
652    #else
653    utf8 = FALSE;
654    #endif
655    
656  /* First check that we haven't called match() too many times, or that we  /* First check that we haven't called match() too many times, or that we
657  haven't exceeded the recursive call limit. */  haven't exceeded the recursive call limit. */
658    
# Line 550  if (rdepth >= md->match_limit_recursion) Line 661  if (rdepth >= md->match_limit_recursion)
661    
662  original_ims = ims;    /* Save for resetting on ')' */  original_ims = ims;    /* Save for resetting on ')' */
663    
664  #ifdef SUPPORT_UTF8  /* At the start of a group with an unlimited repeat that may match an empty
665  utf8 = md->utf8;       /* Local copy of the flag */  string, the match_cbegroup flag is set. When this is the case, add the current
666  #else  subject pointer to the chain of such remembered pointers, to be checked when we
667  utf8 = FALSE;  hit the closing ket, in order to break infinite loops that match no characters.
668  #endif  When match() is called in other circumstances, don't add to the chain. The
669    match_cbegroup flag must NOT be used with tail recursion, because the memory
670  /* At the start of a bracketed group, add the current subject pointer to the  block that is used is on the stack, so a new one may be required for each
671  stack of such pointers, to be re-instated at the end of the group when we hit  match(). */
 the closing ket. When match() is called in other circumstances, we don't add to  
 this stack. */  
672    
673  if ((flags & match_isgroup) != 0)  if ((flags & match_cbegroup) != 0)
674    {    {
   newptrb.epb_prev = eptrb;  
675    newptrb.epb_saved_eptr = eptr;    newptrb.epb_saved_eptr = eptr;
676      newptrb.epb_prev = eptrb;
677    eptrb = &newptrb;    eptrb = &newptrb;
678    }    }
679    
680  /* Now start processing the operations. */  /* Now start processing the opcodes. */
681    
682  for (;;)  for (;;)
683    {    {
684      minimize = possessive = FALSE;
685    op = *ecode;    op = *ecode;
   minimize = FALSE;  
686    
687    /* For partial matching, remember if we ever hit the end of the subject after    switch(op)
   matching at least one subject character. */  
   
   if (md->partial &&  
       eptr >= md->end_subject &&  
       eptr > md->start_match)  
     md->hitend = TRUE;  
   
   /* Opening capturing bracket. If there is space in the offset vector, save  
   the current subject position in the working slot at the top of the vector. We  
   mustn't change the current values of the data slot, because they may be set  
   from a previous iteration of this group, and be referred to by a reference  
   inside the group.  
   
   If the bracket fails to match, we need to restore this value and also the  
   values of the final offsets, in case they were set by a previous iteration of  
   the same bracket.  
   
   If there isn't enough space in the offset vector, treat this as if it were a  
   non-capturing bracket. Don't worry about setting the flag for the error case  
   here; that is handled in the code for KET. */  
   
   if (op > OP_BRA)  
688      {      {
689      number = op - OP_BRA;      case OP_MARK:
690        markptr = ecode + 2;
691      /* For extended extraction brackets (large number), we have to fish out the      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
692      number from a dummy opcode at the start. */        ims, eptrb, flags, RM55);
693    
694      if (number > EXTRACT_BASIC_MAX)      /* A return of MATCH_SKIP_ARG means that matching failed at SKIP with an
695        number = GET2(ecode, 2+LINK_SIZE);      argument, and we must check whether that argument matches this MARK's
696        argument. It is passed back in md->start_match_ptr (an overloading of that
697        variable). If it does match, we reset that variable to the current subject
698        position and return MATCH_SKIP. Otherwise, pass back the return code
699        unaltered. */
700    
701        if (rrc == MATCH_SKIP_ARG &&
702            strcmp((char *)markptr, (char *)(md->start_match_ptr)) == 0)
703          {
704          md->start_match_ptr = eptr;
705          RRETURN(MATCH_SKIP);
706          }
707    
708        if (md->mark == NULL) md->mark = markptr;
709        RRETURN(rrc);
710    
711        case OP_FAIL:
712        MRRETURN(MATCH_NOMATCH);
713    
714        /* COMMIT overrides PRUNE, SKIP, and THEN */
715    
716        case OP_COMMIT:
717        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
718          ims, eptrb, flags, RM52);
719        if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE &&
720            rrc != MATCH_SKIP && rrc != MATCH_SKIP_ARG &&
721            rrc != MATCH_THEN)
722          RRETURN(rrc);
723        MRRETURN(MATCH_COMMIT);
724    
725        /* PRUNE overrides THEN */
726    
727        case OP_PRUNE:
728        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
729          ims, eptrb, flags, RM51);
730        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
731        MRRETURN(MATCH_PRUNE);
732    
733        case OP_PRUNE_ARG:
734        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
735          ims, eptrb, flags, RM56);
736        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
737        md->mark = ecode + 2;
738        RRETURN(MATCH_PRUNE);
739    
740        /* SKIP overrides PRUNE and THEN */
741    
742        case OP_SKIP:
743        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
744          ims, eptrb, flags, RM53);
745        if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)
746          RRETURN(rrc);
747        md->start_match_ptr = eptr;   /* Pass back current position */
748        MRRETURN(MATCH_SKIP);
749    
750        case OP_SKIP_ARG:
751        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
752          ims, eptrb, flags, RM57);
753        if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)
754          RRETURN(rrc);
755    
756        /* Pass back the current skip name by overloading md->start_match_ptr and
757        returning the special MATCH_SKIP_ARG return code. This will either be
758        caught by a matching MARK, or get to the top, where it is treated the same
759        as PRUNE. */
760    
761        md->start_match_ptr = ecode + 2;
762        RRETURN(MATCH_SKIP_ARG);
763    
764        /* For THEN (and THEN_ARG) we pass back the address of the bracket or
765        the alt that is at the start of the current branch. This makes it possible
766        to skip back past alternatives that precede the THEN within the current
767        branch. */
768    
769        case OP_THEN:
770        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
771          ims, eptrb, flags, RM54);
772        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
773        md->start_match_ptr = ecode - GET(ecode, 1);
774        MRRETURN(MATCH_THEN);
775    
776        case OP_THEN_ARG:
777        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1+LINK_SIZE],
778          offset_top, md, ims, eptrb, flags, RM58);
779        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
780        md->start_match_ptr = ecode - GET(ecode, 1);
781        md->mark = ecode + LINK_SIZE + 2;
782        RRETURN(MATCH_THEN);
783    
784        /* Handle a capturing bracket. If there is space in the offset vector, save
785        the current subject position in the working slot at the top of the vector.
786        We mustn't change the current values of the data slot, because they may be
787        set from a previous iteration of this group, and be referred to by a
788        reference inside the group.
789    
790        If the bracket fails to match, we need to restore this value and also the
791        values of the final offsets, in case they were set by a previous iteration
792        of the same bracket.
793    
794        If there isn't enough space in the offset vector, treat this as if it were
795        a non-capturing bracket. Don't worry about setting the flag for the error
796        case here; that is handled in the code for KET. */
797    
798        case OP_CBRA:
799        case OP_SCBRA:
800        number = GET2(ecode, 1+LINK_SIZE);
801      offset = number << 1;      offset = number << 1;
802    
803  #ifdef DEBUG  #ifdef PCRE_DEBUG
804      printf("start bracket %d subject=", number);      printf("start bracket %d\n", number);
805        printf("subject=");
806      pchars(eptr, 16, TRUE, md);      pchars(eptr, 16, TRUE, md);
807      printf("\n");      printf("\n");
808  #endif  #endif
# Line 622  for (;;) Line 815  for (;;)
815        save_capture_last = md->capture_last;        save_capture_last = md->capture_last;
816    
817        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
818        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;        md->offset_vector[md->offset_end - number] =
819            (int)(eptr - md->start_subject);
820    
821          flags = (op == OP_SCBRA)? match_cbegroup : 0;
822        do        do
823          {          {
824          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
825            match_isgroup);            ims, eptrb, flags, RM1);
826          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH &&
827                (rrc != MATCH_THEN || md->start_match_ptr != ecode))
828              RRETURN(rrc);
829          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
830          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
831          }          }
# Line 640  for (;;) Line 837  for (;;)
837        md->offset_vector[offset+1] = save_offset2;        md->offset_vector[offset+1] = save_offset2;
838        md->offset_vector[md->offset_end - number] = save_offset3;        md->offset_vector[md->offset_end - number] = save_offset3;
839    
840          if (rrc != MATCH_THEN) md->mark = markptr;
841        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
842        }        }
843    
844      /* Insufficient room for saving captured contents */      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
845        as a non-capturing bracket. */
     else op = OP_BRA;  
     }  
   
   /* Other types of node can be handled by a switch */  
846    
847    switch(op)      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
848      {      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
     case OP_BRA:     /* Non-capturing bracket: optimized */  
     DPRINTF(("start bracket 0\n"));  
849    
850      /* Loop for all the alternatives */      DPRINTF(("insufficient capture room: treat as non-capturing\n"));
851    
852        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
853        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
854    
855        /* Non-capturing bracket. Loop for all the alternatives. When we get to the
856        final alternative within the brackets, we would return the result of a
857        recursive call to match() whatever happened. We can reduce stack usage by
858        turning this into a tail recursion, except in the case when match_cbegroup
859        is set.*/
860    
861        case OP_BRA:
862        case OP_SBRA:
863        DPRINTF(("start non-capturing bracket\n"));
864        flags = (op >= OP_SBRA)? match_cbegroup : 0;
865      for (;;)      for (;;)
866        {        {
867        /* When we get to the final alternative within the brackets, we would        if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */
868        return the result of a recursive call to match() whatever happened. We          {
869        can reduce stack usage by turning this into a tail recursion. */          if (flags == 0)    /* Not a possibly empty group */
870              {
871        if (ecode[GET(ecode, 1)] != OP_ALT)            ecode += _pcre_OP_lengths[*ecode];
872         {            DPRINTF(("bracket 0 tail recursion\n"));
873         ecode += 1 + LINK_SIZE;            goto TAIL_RECURSE;
874         flags = match_isgroup;            }
875         DPRINTF(("bracket 0 tail recursion\n"));  
876         goto TAIL_RECURSE;          /* Possibly empty group; can't use tail recursion. */
877         }  
878            RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
879              eptrb, flags, RM48);
880            if (rrc == MATCH_NOMATCH) md->mark = markptr;
881            RRETURN(rrc);
882            }
883    
884        /* For non-final alternatives, continue the loop for a NOMATCH result;        /* For non-final alternatives, continue the loop for a NOMATCH result;
885        otherwise return. */        otherwise return. */
886    
887        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
888          match_isgroup);          eptrb, flags, RM2);
889        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH &&
890              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
891            RRETURN(rrc);
892        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
893        }        }
894      /* Control never reaches here. */      /* Control never reaches here. */
# Line 688  for (;;) Line 900  for (;;)
900      obeyed, we can use tail recursion to avoid using another stack frame. */      obeyed, we can use tail recursion to avoid using another stack frame. */
901    
902      case OP_COND:      case OP_COND:
903      if (ecode[LINK_SIZE+1] == OP_CREF) /* Condition extract or recurse test */      case OP_SCOND:
904        codelink= GET(ecode, 1);
905    
906        /* Because of the way auto-callout works during compile, a callout item is
907        inserted between OP_COND and an assertion condition. */
908    
909        if (ecode[LINK_SIZE+1] == OP_CALLOUT)
910          {
911          if (pcre_callout != NULL)
912            {
913            pcre_callout_block cb;
914            cb.version          = 1;   /* Version 1 of the callout block */
915            cb.callout_number   = ecode[LINK_SIZE+2];
916            cb.offset_vector    = md->offset_vector;
917            cb.subject          = (PCRE_SPTR)md->start_subject;
918            cb.subject_length   = (int)(md->end_subject - md->start_subject);
919            cb.start_match      = (int)(mstart - md->start_subject);
920            cb.current_position = (int)(eptr - md->start_subject);
921            cb.pattern_position = GET(ecode, LINK_SIZE + 3);
922            cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
923            cb.capture_top      = offset_top/2;
924            cb.capture_last     = md->capture_last;
925            cb.callout_data     = md->callout_data;
926            if ((rrc = (*pcre_callout)(&cb)) > 0) MRRETURN(MATCH_NOMATCH);
927            if (rrc < 0) RRETURN(rrc);
928            }
929          ecode += _pcre_OP_lengths[OP_CALLOUT];
930          }
931    
932        condcode = ecode[LINK_SIZE+1];
933    
934        /* Now see what the actual condition is */
935    
936        if (condcode == OP_RREF || condcode == OP_NRREF)    /* Recursion test */
937          {
938          if (md->recursive == NULL)                /* Not recursing => FALSE */
939            {
940            condition = FALSE;
941            ecode += GET(ecode, 1);
942            }
943          else
944            {
945            int recno = GET2(ecode, LINK_SIZE + 2);   /* Recursion group number*/
946            condition =  (recno == RREF_ANY || recno == md->recursive->group_num);
947    
948            /* If the test is for recursion into a specific subpattern, and it is
949            false, but the test was set up by name, scan the table to see if the
950            name refers to any other numbers, and test them. The condition is true
951            if any one is set. */
952    
953            if (!condition && condcode == OP_NRREF && recno != RREF_ANY)
954              {
955              uschar *slotA = md->name_table;
956              for (i = 0; i < md->name_count; i++)
957                {
958                if (GET2(slotA, 0) == recno) break;
959                slotA += md->name_entry_size;
960                }
961    
962              /* Found a name for the number - there can be only one; duplicate
963              names for different numbers are allowed, but not vice versa. First
964              scan down for duplicates. */
965    
966              if (i < md->name_count)
967                {
968                uschar *slotB = slotA;
969                while (slotB > md->name_table)
970                  {
971                  slotB -= md->name_entry_size;
972                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
973                    {
974                    condition = GET2(slotB, 0) == md->recursive->group_num;
975                    if (condition) break;
976                    }
977                  else break;
978                  }
979    
980                /* Scan up for duplicates */
981    
982                if (!condition)
983                  {
984                  slotB = slotA;
985                  for (i++; i < md->name_count; i++)
986                    {
987                    slotB += md->name_entry_size;
988                    if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
989                      {
990                      condition = GET2(slotB, 0) == md->recursive->group_num;
991                      if (condition) break;
992                      }
993                    else break;
994                    }
995                  }
996                }
997              }
998    
999            /* Chose branch according to the condition */
1000    
1001            ecode += condition? 3 : GET(ecode, 1);
1002            }
1003          }
1004    
1005        else if (condcode == OP_CREF || condcode == OP_NCREF)  /* Group used test */
1006        {        {
1007        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
1008        condition = (offset == CREF_RECURSE * 2)?        condition = offset < offset_top && md->offset_vector[offset] >= 0;
1009          (md->recursive != NULL) :  
1010          (offset < offset_top && md->offset_vector[offset] >= 0);        /* If the numbered capture is unset, but the reference was by name,
1011        ecode += condition? (LINK_SIZE + 4) : (LINK_SIZE + 1 + GET(ecode, 1));        scan the table to see if the name refers to any other numbers, and test
1012        flags = match_isgroup;        them. The condition is true if any one is set. This is tediously similar
1013        goto TAIL_RECURSE;        to the code above, but not close enough to try to amalgamate. */
1014    
1015          if (!condition && condcode == OP_NCREF)
1016            {
1017            int refno = offset >> 1;
1018            uschar *slotA = md->name_table;
1019    
1020            for (i = 0; i < md->name_count; i++)
1021              {
1022              if (GET2(slotA, 0) == refno) break;
1023              slotA += md->name_entry_size;
1024              }
1025    
1026            /* Found a name for the number - there can be only one; duplicate names
1027            for different numbers are allowed, but not vice versa. First scan down
1028            for duplicates. */
1029    
1030            if (i < md->name_count)
1031              {
1032              uschar *slotB = slotA;
1033              while (slotB > md->name_table)
1034                {
1035                slotB -= md->name_entry_size;
1036                if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
1037                  {
1038                  offset = GET2(slotB, 0) << 1;
1039                  condition = offset < offset_top &&
1040                    md->offset_vector[offset] >= 0;
1041                  if (condition) break;
1042                  }
1043                else break;
1044                }
1045    
1046              /* Scan up for duplicates */
1047    
1048              if (!condition)
1049                {
1050                slotB = slotA;
1051                for (i++; i < md->name_count; i++)
1052                  {
1053                  slotB += md->name_entry_size;
1054                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
1055                    {
1056                    offset = GET2(slotB, 0) << 1;
1057                    condition = offset < offset_top &&
1058                      md->offset_vector[offset] >= 0;
1059                    if (condition) break;
1060                    }
1061                  else break;
1062                  }
1063                }
1064              }
1065            }
1066    
1067          /* Chose branch according to the condition */
1068    
1069          ecode += condition? 3 : GET(ecode, 1);
1070          }
1071    
1072        else if (condcode == OP_DEF)     /* DEFINE - always false */
1073          {
1074          condition = FALSE;
1075          ecode += GET(ecode, 1);
1076        }        }
1077    
1078      /* The condition is an assertion. Call match() to evaluate it - setting      /* The condition is an assertion. Call match() to evaluate it - setting
1079      the final argument TRUE causes it to stop at the end of an assertion. */      the final argument match_condassert causes it to stop at the end of an
1080        assertion. */
1081    
1082      else      else
1083        {        {
1084        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
1085            match_condassert | match_isgroup);            match_condassert, RM3);
1086        if (rrc == MATCH_MATCH)        if (rrc == MATCH_MATCH)
1087          {          {
1088          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE+2);          condition = TRUE;
1089            ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
1090          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
1091          }          }
1092        else if (rrc != MATCH_NOMATCH)        else if (rrc != MATCH_NOMATCH &&
1093                  (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1094          {          {
1095          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
1096          }          }
1097        else ecode += GET(ecode, 1);        else
1098            {
1099            condition = FALSE;
1100            ecode += codelink;
1101            }
1102          }
1103    
1104        /* 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,
1105        we can use tail recursion to avoid using another stack frame. */      we can use tail recursion to avoid using another stack frame, except when
1106        match_cbegroup is required for an unlimited repeat of a possibly empty
1107        group. If the second alternative doesn't exist, we can just plough on. */
1108    
1109        if (condition || *ecode == OP_ALT)
1110          {
1111        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1112        flags = match_isgroup;        if (op == OP_SCOND)        /* Possibly empty group */
1113        goto TAIL_RECURSE;          {
1114            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
1115            RRETURN(rrc);
1116            }
1117          else                       /* Group must match something */
1118            {
1119            flags = 0;
1120            goto TAIL_RECURSE;
1121            }
1122        }        }
1123      /* Control never reaches here */      else                         /* Condition false & no alternative */
1124          {
1125          ecode += 1 + LINK_SIZE;
1126          }
1127        break;
1128    
1129    
1130      /* Skip over conditional reference or large extraction number data if      /* Before OP_ACCEPT there may be any number of OP_CLOSE opcodes,
1131      encountered. */      to close any currently open capturing brackets. */
1132    
1133      case OP_CREF:      case OP_CLOSE:
1134      case OP_BRANUMBER:      number = GET2(ecode, 1);
1135        offset = number << 1;
1136    
1137    #ifdef PCRE_DEBUG
1138          printf("end bracket %d at *ACCEPT", number);
1139          printf("\n");
1140    #endif
1141    
1142        md->capture_last = number;
1143        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1144          {
1145          md->offset_vector[offset] =
1146            md->offset_vector[md->offset_end - number];
1147          md->offset_vector[offset+1] = (int)(eptr - md->start_subject);
1148          if (offset_top <= offset) offset_top = offset + 2;
1149          }
1150      ecode += 3;      ecode += 3;
1151      break;      break;
1152    
     /* End of the pattern. If we are in a recursion, we should restore the  
     offsets appropriately and continue from after the call. */  
1153    
1154        /* End of the pattern, either real or forced. If we are in a top-level
1155        recursion, we should restore the offsets appropriately and continue from
1156        after the call. */
1157    
1158        case OP_ACCEPT:
1159      case OP_END:      case OP_END:
1160      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL && md->recursive->group_num == 0)
1161        {        {
# Line 745  for (;;) Line 1164  for (;;)
1164        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
1165        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
1166          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
1167        md->start_match = rec->save_start;        offset_top = rec->save_offset_top;
1168        ims = original_ims;        ims = original_ims;
1169        ecode = rec->after_call;        ecode = rec->after_call;
1170        break;        break;
1171        }        }
1172    
1173      /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty      /* Otherwise, if we have matched an empty string, fail if PCRE_NOTEMPTY is
1174      string - backtracking will then try other alternatives, if any. */      set, or if PCRE_NOTEMPTY_ATSTART is set and we have matched at the start of
1175        the subject. In both cases, backtracking will then try other alternatives,
1176        if any. */
1177    
1178        if (eptr == mstart &&
1179            (md->notempty ||
1180              (md->notempty_atstart &&
1181                mstart == md->start_subject + md->start_offset)))
1182          MRRETURN(MATCH_NOMATCH);
1183    
1184        /* Otherwise, we have a match. */
1185    
1186        md->end_match_ptr = eptr;           /* Record where we ended */
1187        md->end_offset_top = offset_top;    /* and how many extracts were taken */
1188        md->start_match_ptr = mstart;       /* and the start (\K can modify) */
1189    
1190      if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH);      /* For some reason, the macros don't work properly if an expression is
1191      md->end_match_ptr = eptr;          /* Record where we ended */      given as the argument to MRRETURN when the heap is in use. */
1192      md->end_offset_top = offset_top;   /* and how many extracts were taken */  
1193      RRETURN(MATCH_MATCH);      rrc = (op == OP_END)? MATCH_MATCH : MATCH_ACCEPT;
1194        MRRETURN(rrc);
1195    
1196      /* Change option settings */      /* Change option settings */
1197    
# Line 777  for (;;) Line 1211  for (;;)
1211      case OP_ASSERTBACK:      case OP_ASSERTBACK:
1212      do      do
1213        {        {
1214        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1215          match_isgroup);          RM4);
1216        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
1217        if (rrc != MATCH_NOMATCH) RRETURN(rrc);          {
1218            mstart = md->start_match_ptr;   /* In case \K reset it */
1219            break;
1220            }
1221          if (rrc != MATCH_NOMATCH &&
1222              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1223            RRETURN(rrc);
1224        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1225        }        }
1226      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
1227      if (*ecode == OP_KET) RRETURN(MATCH_NOMATCH);      if (*ecode == OP_KET) MRRETURN(MATCH_NOMATCH);
1228    
1229      /* If checking an assertion for a condition, return MATCH_MATCH. */      /* If checking an assertion for a condition, return MATCH_MATCH. */
1230    
# Line 798  for (;;) Line 1238  for (;;)
1238      offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1239      continue;      continue;
1240    
1241      /* Negative assertion: all branches must fail to match */      /* Negative assertion: all branches must fail to match. Encountering SKIP,
1242        PRUNE, or COMMIT means we must assume failure without checking subsequent
1243        branches. */
1244    
1245      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1246      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1247      do      do
1248        {        {
1249        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1250          match_isgroup);          RM5);
1251        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) MRRETURN(MATCH_NOMATCH);
1252        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)
1253            {
1254            do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1255            break;
1256            }
1257          if (rrc != MATCH_NOMATCH &&
1258              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1259            RRETURN(rrc);
1260        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1261        }        }
1262      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 826  for (;;) Line 1275  for (;;)
1275  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1276      if (utf8)      if (utf8)
1277        {        {
1278        c = GET(ecode,1);        i = GET(ecode, 1);
1279        for (i = 0; i < c; i++)        while (i-- > 0)
1280          {          {
1281          eptr--;          eptr--;
1282          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) MRRETURN(MATCH_NOMATCH);
1283          BACKCHAR(eptr)          BACKCHAR(eptr);
1284          }          }
1285        }        }
1286      else      else
# Line 840  for (;;) Line 1289  for (;;)
1289      /* No UTF-8 support, or not in UTF-8 mode: count is byte count */      /* No UTF-8 support, or not in UTF-8 mode: count is byte count */
1290    
1291        {        {
1292        eptr -= GET(ecode,1);        eptr -= GET(ecode, 1);
1293        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) MRRETURN(MATCH_NOMATCH);
1294        }        }
1295    
1296      /* Skip to next op code */      /* Save the earliest consulted character, then skip to next op code */
1297    
1298        if (eptr < md->start_used_ptr) md->start_used_ptr = eptr;
1299      ecode += 1 + LINK_SIZE;      ecode += 1 + LINK_SIZE;
1300      break;      break;
1301    
# Line 861  for (;;) Line 1311  for (;;)
1311        cb.callout_number   = ecode[1];        cb.callout_number   = ecode[1];
1312        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1313        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1314        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = (int)(md->end_subject - md->start_subject);
1315        cb.start_match      = md->start_match - md->start_subject;        cb.start_match      = (int)(mstart - md->start_subject);
1316        cb.current_position = eptr - md->start_subject;        cb.current_position = (int)(eptr - md->start_subject);
1317        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
1318        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
1319        cb.capture_top      = offset_top/2;        cb.capture_top      = offset_top/2;
1320        cb.capture_last     = md->capture_last;        cb.capture_last     = md->capture_last;
1321        cb.callout_data     = md->callout_data;        cb.callout_data     = md->callout_data;
1322        if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);        if ((rrc = (*pcre_callout)(&cb)) > 0) MRRETURN(MATCH_NOMATCH);
1323        if (rrc < 0) RRETURN(rrc);        if (rrc < 0) RRETURN(rrc);
1324        }        }
1325      ecode += 2 + 2*LINK_SIZE;      ecode += 2 + 2*LINK_SIZE;
# Line 897  for (;;) Line 1347  for (;;)
1347      case OP_RECURSE:      case OP_RECURSE:
1348        {        {
1349        callpat = md->start_code + GET(ecode, 1);        callpat = md->start_code + GET(ecode, 1);
1350        new_recursive.group_num = *callpat - OP_BRA;        new_recursive.group_num = (callpat == md->start_code)? 0 :
1351            GET2(callpat, 1 + LINK_SIZE);
       /* For extended extraction brackets (large number), we have to fish out  
       the number from a dummy opcode at the start. */  
   
       if (new_recursive.group_num > EXTRACT_BASIC_MAX)  
         new_recursive.group_num = GET2(callpat, 2+LINK_SIZE);  
1352    
1353        /* Add to "recursing stack" */        /* Add to "recursing stack" */
1354    
# Line 929  for (;;) Line 1374  for (;;)
1374    
1375        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1376              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1377        new_recursive.save_start = md->start_match;        new_recursive.save_offset_top = offset_top;
       md->start_match = eptr;  
1378    
1379        /* 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
1380        restore the offset and recursion data. */        restore the offset and recursion data. */
1381    
1382        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
1383          flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
1384        do        do
1385          {          {
1386          RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1387              eptrb, match_isgroup);            md, ims, eptrb, flags, RM6);
1388          if (rrc == MATCH_MATCH)          if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
1389            {            {
1390            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
1391            md->recursive = new_recursive.prevrec;            md->recursive = new_recursive.prevrec;
1392            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
1393              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1394            RRETURN(MATCH_MATCH);            MRRETURN(MATCH_MATCH);
1395            }            }
1396          else if (rrc != MATCH_NOMATCH)          else if (rrc != MATCH_NOMATCH &&
1397                    (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1398            {            {
1399            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1400              if (new_recursive.offset_save != stacksave)
1401                (pcre_free)(new_recursive.offset_save);
1402            RRETURN(rrc);            RRETURN(rrc);
1403            }            }
1404    
# Line 965  for (;;) Line 1413  for (;;)
1413        md->recursive = new_recursive.prevrec;        md->recursive = new_recursive.prevrec;
1414        if (new_recursive.offset_save != stacksave)        if (new_recursive.offset_save != stacksave)
1415          (pcre_free)(new_recursive.offset_save);          (pcre_free)(new_recursive.offset_save);
1416        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1417        }        }
1418      /* Control never reaches here */      /* Control never reaches here */
1419    
# Line 974  for (;;) Line 1422  for (;;)
1422      a move back into the brackets. Friedl calls these "atomic" subpatterns.      a move back into the brackets. Friedl calls these "atomic" subpatterns.
1423      Check the alternative branches in turn - the matching won't pass the KET      Check the alternative branches in turn - the matching won't pass the KET
1424      for this kind of subpattern. If any one branch matches, we carry on as at      for this kind of subpattern. If any one branch matches, we carry on as at
1425      the end of a normal bracket, leaving the subject pointer. */      the end of a normal bracket, leaving the subject pointer, but resetting
1426        the start-of-match value in case it was changed by \K. */
1427    
1428      case OP_ONCE:      case OP_ONCE:
1429      prev = ecode;      prev = ecode;
# Line 982  for (;;) Line 1431  for (;;)
1431    
1432      do      do
1433        {        {
1434        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
1435          eptrb, match_isgroup);        if (rrc == MATCH_MATCH)  /* Note: _not_ MATCH_ACCEPT */
1436        if (rrc == MATCH_MATCH) break;          {
1437        if (rrc != MATCH_NOMATCH) RRETURN(rrc);          mstart = md->start_match_ptr;
1438            break;
1439            }
1440          if (rrc != MATCH_NOMATCH &&
1441              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1442            RRETURN(rrc);
1443        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1444        }        }
1445      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 997  for (;;) Line 1451  for (;;)
1451      /* Continue as from after the assertion, updating the offsets high water      /* Continue as from after the assertion, updating the offsets high water
1452      mark, since extracts may have been taken. */      mark, since extracts may have been taken. */
1453    
1454      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
1455    
1456      offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1457      eptr = md->end_match_ptr;      eptr = md->end_match_ptr;
# Line 1028  for (;;) Line 1482  for (;;)
1482    
1483      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1484        {        {
1485        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8);
1486        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1487        ecode = prev;        ecode = prev;
1488        flags = match_isgroup;        flags = 0;
1489        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1490        }        }
1491      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1492        {        {
1493        RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
1494        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1495        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1496        flags = 0;        flags = 0;
# Line 1051  for (;;) Line 1505  for (;;)
1505      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1506      break;      break;
1507    
1508      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1509      that it may occur zero times. It may repeat infinitely, or not at all -      indicating that it may occur zero times. It may repeat infinitely, or not
1510      i.e. it could be ()* or ()? in the pattern. Brackets with fixed upper      at all - i.e. it could be ()* or ()? or even (){0} in the pattern. Brackets
1511      repeat limits are compiled as a number of copies, with the optional ones      with fixed upper repeat limits are compiled as a number of copies, with the
1512      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1513    
1514      case OP_BRAZERO:      case OP_BRAZERO:
1515        {        {
1516        next = ecode+1;        next = ecode+1;
1517        RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
1518        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1519        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next,1); while (*next == OP_ALT);
1520        ecode = next + 1+LINK_SIZE;        ecode = next + 1 + LINK_SIZE;
1521        }        }
1522      break;      break;
1523    
1524      case OP_BRAMINZERO:      case OP_BRAMINZERO:
1525        {        {
1526        next = ecode+1;        next = ecode+1;
1527        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next, 1); while (*next == OP_ALT);
1528        RMATCH(rrc, eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb,        RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11);
         match_isgroup);  
1529        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1530        ecode++;        ecode++;
1531        }        }
1532      break;      break;
1533    
1534      /* End of a group, repeated or non-repeating. If we are at the end of      case OP_SKIPZERO:
1535      an assertion "group", stop matching and return MATCH_MATCH, but record the        {
1536      current high water mark for use by positive assertions. Do this also        next = ecode+1;
1537      for the "once" (not-backup up) groups. */        do next += GET(next,1); while (*next == OP_ALT);
1538          ecode = next + 1 + LINK_SIZE;
1539          }
1540        break;
1541    
1542        /* End of a group, repeated or non-repeating. */
1543    
1544      case OP_KET:      case OP_KET:
1545      case OP_KETRMIN:      case OP_KETRMIN:
1546      case OP_KETRMAX:      case OP_KETRMAX:
1547      prev = ecode - GET(ecode, 1);      prev = ecode - GET(ecode, 1);
     saved_eptr = eptrb->epb_saved_eptr;  
1548    
1549      /* Back up the stack of bracket start pointers. */      /* If this was a group that remembered the subject start, in order to break
1550        infinite repeats of empty string matches, retrieve the subject start from
1551        the chain. Otherwise, set it NULL. */
1552    
1553        if (*prev >= OP_SBRA)
1554          {
1555          saved_eptr = eptrb->epb_saved_eptr;   /* Value at start of group */
1556          eptrb = eptrb->epb_prev;              /* Backup to previous group */
1557          }
1558        else saved_eptr = NULL;
1559    
1560      eptrb = eptrb->epb_prev;      /* If we are at the end of an assertion group or an atomic group, stop
1561        matching and return MATCH_MATCH, but record the current high water mark for
1562        use by positive assertions. We also need to record the match start in case
1563        it was changed by \K. */
1564    
1565      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
1566          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
# Line 1099  for (;;) Line 1568  for (;;)
1568        {        {
1569        md->end_match_ptr = eptr;      /* For ONCE */        md->end_match_ptr = eptr;      /* For ONCE */
1570        md->end_offset_top = offset_top;        md->end_offset_top = offset_top;
1571        RRETURN(MATCH_MATCH);        md->start_match_ptr = mstart;
1572          MRRETURN(MATCH_MATCH);
1573        }        }
1574    
1575      /* In all other cases except a conditional group we have to check the      /* For capturing groups we have to check the group number back at the start
1576      group number back at the start and if necessary complete handling an      and if necessary complete handling an extraction by setting the offsets and
1577      extraction by setting the offsets and bumping the high water mark. */      bumping the high water mark. Note that whole-pattern recursion is coded as
1578        a recurse into group 0, so it won't be picked up here. Instead, we catch it
1579        when the OP_END is reached. Other recursion is handled here. */
1580    
1581      if (*prev != OP_COND)      if (*prev == OP_CBRA || *prev == OP_SCBRA)
1582        {        {
1583        number = *prev - OP_BRA;        number = GET2(prev, 1+LINK_SIZE);
   
       /* For extended extraction brackets (large number), we have to fish out  
       the number from a dummy opcode at the start. */  
   
       if (number > EXTRACT_BASIC_MAX) number = GET2(prev, 2+LINK_SIZE);  
1584        offset = number << 1;        offset = number << 1;
1585    
1586  #ifdef DEBUG  #ifdef PCRE_DEBUG
1587        printf("end bracket %d", number);        printf("end bracket %d", number);
1588        printf("\n");        printf("\n");
1589  #endif  #endif
1590    
1591        /* Test for a numbered group. This includes groups called as a result        md->capture_last = number;
1592        of recursion. Note that whole-pattern recursion is coded as a recurse        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
       into group 0, so it won't be picked up here. Instead, we catch it when  
       the OP_END is reached. */  
   
       if (number > 0)  
1593          {          {
1594          md->capture_last = number;          md->offset_vector[offset] =
1595          if (offset >= md->offset_max) md->offset_overflow = TRUE; else            md->offset_vector[md->offset_end - number];
1596            {          md->offset_vector[offset+1] = (int)(eptr - md->start_subject);
1597            md->offset_vector[offset] =          if (offset_top <= offset) offset_top = offset + 2;
1598              md->offset_vector[md->offset_end - number];          }
1599            md->offset_vector[offset+1] = eptr - md->start_subject;  
1600            if (offset_top <= offset) offset_top = offset + 2;        /* Handle a recursively called group. Restore the offsets
1601            }        appropriately and continue from after the call. */
1602    
1603          /* Handle a recursively called group. Restore the offsets        if (md->recursive != NULL && md->recursive->group_num == number)
1604          appropriately and continue from after the call. */          {
1605            recursion_info *rec = md->recursive;
1606          if (md->recursive != NULL && md->recursive->group_num == number)          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1607            {          md->recursive = rec->prevrec;
1608            recursion_info *rec = md->recursive;          memcpy(md->offset_vector, rec->offset_save,
1609            DPRINTF(("Recursion (%d) succeeded - continuing\n", number));            rec->saved_max * sizeof(int));
1610            md->recursive = rec->prevrec;          offset_top = rec->save_offset_top;
1611            md->start_match = rec->save_start;          ecode = rec->after_call;
1612            memcpy(md->offset_vector, rec->offset_save,          ims = original_ims;
1613              rec->saved_max * sizeof(int));          break;
           ecode = rec->after_call;  
           ims = original_ims;  
           break;  
           }  
1614          }          }
1615        }        }
1616    
1617      /* Reset the value of the ims flags, in case they got changed during      /* For both capturing and non-capturing groups, reset the value of the ims
1618      the group. */      flags, in case they got changed during the group. */
1619    
1620      ims = original_ims;      ims = original_ims;
1621      DPRINTF(("ims reset to %02lx\n", ims));      DPRINTF(("ims reset to %02lx\n", ims));
# Line 1175  for (;;) Line 1634  for (;;)
1634    
1635      /* 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
1636      preceding bracket, in the appropriate order. In the second case, we can use      preceding bracket, in the appropriate order. In the second case, we can use
1637      tail recursion to avoid using another stack frame. */      tail recursion to avoid using another stack frame, unless we have an
1638        unlimited repeat of a group that can match an empty string. */
1639    
1640        flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
1641    
1642      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1643        {        {
1644        RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);
1645        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1646          if (flags != 0)    /* Could match an empty string */
1647            {
1648            RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
1649            RRETURN(rrc);
1650            }
1651        ecode = prev;        ecode = prev;
       flags = match_isgroup;  
1652        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1653        }        }
1654      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1655        {        {
1656        RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
1657        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1658        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1659        flags = 0;        flags = 0;
# Line 1198  for (;;) Line 1664  for (;;)
1664      /* Start of subject unless notbol, or after internal newline if multiline */      /* Start of subject unless notbol, or after internal newline if multiline */
1665    
1666      case OP_CIRC:      case OP_CIRC:
1667      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);      if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH);
1668      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1669        {        {
1670        if (eptr != md->start_subject &&        if (eptr != md->start_subject &&
1671            (eptr == md->end_subject ||            (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
1672             eptr < md->start_subject + md->nllen ||          MRRETURN(MATCH_NOMATCH);
            !IS_NEWLINE(eptr - md->nllen)))  
         RRETURN(MATCH_NOMATCH);  
1673        ecode++;        ecode++;
1674        break;        break;
1675        }        }
# Line 1214  for (;;) Line 1678  for (;;)
1678      /* Start of subject assertion */      /* Start of subject assertion */
1679    
1680      case OP_SOD:      case OP_SOD:
1681      if (eptr != md->start_subject) RRETURN(MATCH_NOMATCH);      if (eptr != md->start_subject) MRRETURN(MATCH_NOMATCH);
1682      ecode++;      ecode++;
1683      break;      break;
1684    
1685      /* Start of match assertion */      /* Start of match assertion */
1686    
1687      case OP_SOM:      case OP_SOM:
1688      if (eptr != md->start_subject + md->start_offset) RRETURN(MATCH_NOMATCH);      if (eptr != md->start_subject + md->start_offset) MRRETURN(MATCH_NOMATCH);
1689        ecode++;
1690        break;
1691    
1692        /* Reset the start of match point */
1693    
1694        case OP_SET_SOM:
1695        mstart = eptr;
1696      ecode++;      ecode++;
1697      break;      break;
1698    
# Line 1232  for (;;) Line 1703  for (;;)
1703      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1704        {        {
1705        if (eptr < md->end_subject)        if (eptr < md->end_subject)
1706          { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }          { if (!IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH); }
1707        else        else
1708          { if (md->noteol) RRETURN(MATCH_NOMATCH); }          {
1709            if (md->noteol) MRRETURN(MATCH_NOMATCH);
1710            SCHECK_PARTIAL();
1711            }
1712        ecode++;        ecode++;
1713        break;        break;
1714        }        }
1715      else      else  /* Not multiline */
1716        {        {
1717        if (md->noteol) RRETURN(MATCH_NOMATCH);        if (md->noteol) MRRETURN(MATCH_NOMATCH);
1718        if (!md->endonly)        if (!md->endonly) goto ASSERT_NL_OR_EOS;
         {  
         if (eptr != md->end_subject &&  
             (eptr != md->end_subject - md->nllen || !IS_NEWLINE(eptr)))  
           RRETURN(MATCH_NOMATCH);  
         ecode++;  
         break;  
         }  
1719        }        }
1720    
1721      /* ... else fall through for endonly */      /* ... else fall through for endonly */
1722    
1723      /* End of subject assertion (\z) */      /* End of subject assertion (\z) */
1724    
1725      case OP_EOD:      case OP_EOD:
1726      if (eptr < md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr < md->end_subject) MRRETURN(MATCH_NOMATCH);
1727        SCHECK_PARTIAL();
1728      ecode++;      ecode++;
1729      break;      break;
1730    
1731      /* End of subject or ending \n assertion (\Z) */      /* End of subject or ending \n assertion (\Z) */
1732    
1733      case OP_EODN:      case OP_EODN:
1734      if (eptr != md->end_subject &&      ASSERT_NL_OR_EOS:
1735          (eptr != md->end_subject - md->nllen || !IS_NEWLINE(eptr)))      if (eptr < md->end_subject &&
1736        RRETURN(MATCH_NOMATCH);          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1737          MRRETURN(MATCH_NOMATCH);
1738    
1739        /* Either at end of string or \n before end. */
1740    
1741        SCHECK_PARTIAL();
1742      ecode++;      ecode++;
1743      break;      break;
1744    
# Line 1276  for (;;) Line 1750  for (;;)
1750    
1751        /* Find out if the previous and current characters are "word" characters.        /* Find out if the previous and current characters are "word" characters.
1752        It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to        It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to
1753        be "non-word" characters. */        be "non-word" characters. Remember the earliest consulted character for
1754          partial matching. */
1755    
1756  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1757        if (utf8)        if (utf8)
1758          {          {
1759            /* Get status of previous character */
1760    
1761          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
1762            {            {
1763            const uschar *lastptr = eptr - 1;            USPTR lastptr = eptr - 1;
1764            while((*lastptr & 0xc0) == 0x80) lastptr--;            while((*lastptr & 0xc0) == 0x80) lastptr--;
1765              if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;
1766            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
1767    #ifdef SUPPORT_UCP
1768              if (md->use_ucp)
1769                {
1770                if (c == '_') prev_is_word = TRUE; else
1771                  {
1772                  int cat = UCD_CATEGORY(c);
1773                  prev_is_word = (cat == ucp_L || cat == ucp_N);
1774                  }
1775                }
1776              else
1777    #endif
1778            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1779            }            }
1780          if (eptr >= md->end_subject) cur_is_word = FALSE; else  
1781            /* Get status of next character */
1782    
1783            if (eptr >= md->end_subject)
1784              {
1785              SCHECK_PARTIAL();
1786              cur_is_word = FALSE;
1787              }
1788            else
1789            {            {
1790            GETCHAR(c, eptr);            GETCHAR(c, eptr);
1791    #ifdef SUPPORT_UCP
1792              if (md->use_ucp)
1793                {
1794                if (c == '_') cur_is_word = TRUE; else
1795                  {
1796                  int cat = UCD_CATEGORY(c);
1797                  cur_is_word = (cat == ucp_L || cat == ucp_N);
1798                  }
1799                }
1800              else
1801    #endif
1802            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1803            }            }
1804          }          }
1805        else        else
1806  #endif  #endif
1807    
1808        /* More streamlined when not in UTF-8 mode */        /* Not in UTF-8 mode, but we may still have PCRE_UCP set, and for
1809          consistency with the behaviour of \w we do use it in this case. */
1810    
1811          {          {
1812          prev_is_word = (eptr != md->start_subject) &&          /* Get status of previous character */
           ((md->ctypes[eptr[-1]] & ctype_word) != 0);  
         cur_is_word = (eptr < md->end_subject) &&  
           ((md->ctypes[*eptr] & ctype_word) != 0);  
         }  
1813    
1814        /* Now see if the situation is what we want */          if (eptr == md->start_subject) prev_is_word = FALSE; else
1815              {
1816              if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1;
1817    #ifdef SUPPORT_UCP
1818              if (md->use_ucp)
1819                {
1820                c = eptr[-1];
1821                if (c == '_') prev_is_word = TRUE; else
1822                  {
1823                  int cat = UCD_CATEGORY(c);
1824                  prev_is_word = (cat == ucp_L || cat == ucp_N);
1825                  }
1826                }
1827              else
1828    #endif
1829              prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);
1830              }
1831    
1832        if ((*ecode++ == OP_WORD_BOUNDARY)?          /* Get status of next character */
1833             cur_is_word == prev_is_word : cur_is_word != prev_is_word)  
1834          RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject)
1835              {
1836              SCHECK_PARTIAL();
1837              cur_is_word = FALSE;
1838              }
1839            else
1840    #ifdef SUPPORT_UCP
1841            if (md->use_ucp)
1842              {
1843              c = *eptr;
1844              if (c == '_') cur_is_word = TRUE; else
1845                {
1846                int cat = UCD_CATEGORY(c);
1847                cur_is_word = (cat == ucp_L || cat == ucp_N);
1848                }
1849              }
1850            else
1851    #endif
1852            cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);
1853            }
1854    
1855          /* Now see if the situation is what we want */
1856    
1857          if ((*ecode++ == OP_WORD_BOUNDARY)?
1858               cur_is_word == prev_is_word : cur_is_word != prev_is_word)
1859            MRRETURN(MATCH_NOMATCH);
1860        }        }
1861      break;      break;
1862    
1863      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1864    
1865      case OP_ANY:      case OP_ANY:
1866      if ((ims & PCRE_DOTALL) == 0)      if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);
1867        /* Fall through */
1868    
1869        case OP_ALLANY:
1870        if (eptr++ >= md->end_subject)
1871        {        {
1872        if (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))        SCHECK_PARTIAL();
1873          RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1874        }        }
1875      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
     if (utf8)  
       while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
1876      ecode++;      ecode++;
1877      break;      break;
1878    
# Line 1332  for (;;) Line 1880  for (;;)
1880      any byte, even newline, independent of the setting of PCRE_DOTALL. */      any byte, even newline, independent of the setting of PCRE_DOTALL. */
1881    
1882      case OP_ANYBYTE:      case OP_ANYBYTE:
1883      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject)
1884          {
1885          SCHECK_PARTIAL();
1886          MRRETURN(MATCH_NOMATCH);
1887          }
1888      ecode++;      ecode++;
1889      break;      break;
1890    
1891      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
1892      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1893          {
1894          SCHECK_PARTIAL();
1895          MRRETURN(MATCH_NOMATCH);
1896          }
1897      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1898      if (      if (
1899  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1345  for (;;) Line 1901  for (;;)
1901  #endif  #endif
1902         (md->ctypes[c] & ctype_digit) != 0         (md->ctypes[c] & ctype_digit) != 0
1903         )         )
1904        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1905      ecode++;      ecode++;
1906      break;      break;
1907    
1908      case OP_DIGIT:      case OP_DIGIT:
1909      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1910          {
1911          SCHECK_PARTIAL();
1912          MRRETURN(MATCH_NOMATCH);
1913          }
1914      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1915      if (      if (
1916  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1358  for (;;) Line 1918  for (;;)
1918  #endif  #endif
1919         (md->ctypes[c] & ctype_digit) == 0         (md->ctypes[c] & ctype_digit) == 0
1920         )         )
1921        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1922      ecode++;      ecode++;
1923      break;      break;
1924    
1925      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
1926      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1927          {
1928          SCHECK_PARTIAL();
1929          MRRETURN(MATCH_NOMATCH);
1930          }
1931      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1932      if (      if (
1933  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1371  for (;;) Line 1935  for (;;)
1935  #endif  #endif
1936         (md->ctypes[c] & ctype_space) != 0         (md->ctypes[c] & ctype_space) != 0
1937         )         )
1938        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1939      ecode++;      ecode++;
1940      break;      break;
1941    
1942      case OP_WHITESPACE:      case OP_WHITESPACE:
1943      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1944          {
1945          SCHECK_PARTIAL();
1946          MRRETURN(MATCH_NOMATCH);
1947          }
1948      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1949      if (      if (
1950  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1384  for (;;) Line 1952  for (;;)
1952  #endif  #endif
1953         (md->ctypes[c] & ctype_space) == 0         (md->ctypes[c] & ctype_space) == 0
1954         )         )
1955        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1956      ecode++;      ecode++;
1957      break;      break;
1958    
1959      case OP_NOT_WORDCHAR:      case OP_NOT_WORDCHAR:
1960      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1961          {
1962          SCHECK_PARTIAL();
1963          MRRETURN(MATCH_NOMATCH);
1964          }
1965      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1966      if (      if (
1967  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1397  for (;;) Line 1969  for (;;)
1969  #endif  #endif
1970         (md->ctypes[c] & ctype_word) != 0         (md->ctypes[c] & ctype_word) != 0
1971         )         )
1972        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1973      ecode++;      ecode++;
1974      break;      break;
1975    
1976      case OP_WORDCHAR:      case OP_WORDCHAR:
1977      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1978          {
1979          SCHECK_PARTIAL();
1980          MRRETURN(MATCH_NOMATCH);
1981          }
1982      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1983      if (      if (
1984  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1410  for (;;) Line 1986  for (;;)
1986  #endif  #endif
1987         (md->ctypes[c] & ctype_word) == 0         (md->ctypes[c] & ctype_word) == 0
1988         )         )
1989        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1990        ecode++;
1991        break;
1992    
1993        case OP_ANYNL:
1994        if (eptr >= md->end_subject)
1995          {
1996          SCHECK_PARTIAL();
1997          MRRETURN(MATCH_NOMATCH);
1998          }
1999        GETCHARINCTEST(c, eptr);
2000        switch(c)
2001          {
2002          default: MRRETURN(MATCH_NOMATCH);
2003          case 0x000d:
2004          if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
2005          break;
2006    
2007          case 0x000a:
2008          break;
2009    
2010          case 0x000b:
2011          case 0x000c:
2012          case 0x0085:
2013          case 0x2028:
2014          case 0x2029:
2015          if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
2016          break;
2017          }
2018        ecode++;
2019        break;
2020    
2021        case OP_NOT_HSPACE:
2022        if (eptr >= md->end_subject)
2023          {
2024          SCHECK_PARTIAL();
2025          MRRETURN(MATCH_NOMATCH);
2026          }
2027        GETCHARINCTEST(c, eptr);
2028        switch(c)
2029          {
2030          default: break;
2031          case 0x09:      /* HT */
2032          case 0x20:      /* SPACE */
2033          case 0xa0:      /* NBSP */
2034          case 0x1680:    /* OGHAM SPACE MARK */
2035          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
2036          case 0x2000:    /* EN QUAD */
2037          case 0x2001:    /* EM QUAD */
2038          case 0x2002:    /* EN SPACE */
2039          case 0x2003:    /* EM SPACE */
2040          case 0x2004:    /* THREE-PER-EM SPACE */
2041          case 0x2005:    /* FOUR-PER-EM SPACE */
2042          case 0x2006:    /* SIX-PER-EM SPACE */
2043          case 0x2007:    /* FIGURE SPACE */
2044          case 0x2008:    /* PUNCTUATION SPACE */
2045          case 0x2009:    /* THIN SPACE */
2046          case 0x200A:    /* HAIR SPACE */
2047          case 0x202f:    /* NARROW NO-BREAK SPACE */
2048          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
2049          case 0x3000:    /* IDEOGRAPHIC SPACE */
2050          MRRETURN(MATCH_NOMATCH);
2051          }
2052        ecode++;
2053        break;
2054    
2055        case OP_HSPACE:
2056        if (eptr >= md->end_subject)
2057          {
2058          SCHECK_PARTIAL();
2059          MRRETURN(MATCH_NOMATCH);
2060          }
2061        GETCHARINCTEST(c, eptr);
2062        switch(c)
2063          {
2064          default: MRRETURN(MATCH_NOMATCH);
2065          case 0x09:      /* HT */
2066          case 0x20:      /* SPACE */
2067          case 0xa0:      /* NBSP */
2068          case 0x1680:    /* OGHAM SPACE MARK */
2069          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
2070          case 0x2000:    /* EN QUAD */
2071          case 0x2001:    /* EM QUAD */
2072          case 0x2002:    /* EN SPACE */
2073          case 0x2003:    /* EM SPACE */
2074          case 0x2004:    /* THREE-PER-EM SPACE */
2075          case 0x2005:    /* FOUR-PER-EM SPACE */
2076          case 0x2006:    /* SIX-PER-EM SPACE */
2077          case 0x2007:    /* FIGURE SPACE */
2078          case 0x2008:    /* PUNCTUATION SPACE */
2079          case 0x2009:    /* THIN SPACE */
2080          case 0x200A:    /* HAIR SPACE */
2081          case 0x202f:    /* NARROW NO-BREAK SPACE */
2082          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
2083          case 0x3000:    /* IDEOGRAPHIC SPACE */
2084          break;
2085          }
2086        ecode++;
2087        break;
2088    
2089        case OP_NOT_VSPACE:
2090        if (eptr >= md->end_subject)
2091          {
2092          SCHECK_PARTIAL();
2093          MRRETURN(MATCH_NOMATCH);
2094          }
2095        GETCHARINCTEST(c, eptr);
2096        switch(c)
2097          {
2098          default: break;
2099          case 0x0a:      /* LF */
2100          case 0x0b:      /* VT */
2101          case 0x0c:      /* FF */
2102          case 0x0d:      /* CR */
2103          case 0x85:      /* NEL */
2104          case 0x2028:    /* LINE SEPARATOR */
2105          case 0x2029:    /* PARAGRAPH SEPARATOR */
2106          MRRETURN(MATCH_NOMATCH);
2107          }
2108        ecode++;
2109        break;
2110    
2111        case OP_VSPACE:
2112        if (eptr >= md->end_subject)
2113          {
2114          SCHECK_PARTIAL();
2115          MRRETURN(MATCH_NOMATCH);
2116          }
2117        GETCHARINCTEST(c, eptr);
2118        switch(c)
2119          {
2120          default: MRRETURN(MATCH_NOMATCH);
2121          case 0x0a:      /* LF */
2122          case 0x0b:      /* VT */
2123          case 0x0c:      /* FF */
2124          case 0x0d:      /* CR */
2125          case 0x85:      /* NEL */
2126          case 0x2028:    /* LINE SEPARATOR */
2127          case 0x2029:    /* PARAGRAPH SEPARATOR */
2128          break;
2129          }
2130      ecode++;      ecode++;
2131      break;      break;
2132    
# Line 1420  for (;;) Line 2136  for (;;)
2136    
2137      case OP_PROP:      case OP_PROP:
2138      case OP_NOTPROP:      case OP_NOTPROP:
2139      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2140          {
2141          SCHECK_PARTIAL();
2142          MRRETURN(MATCH_NOMATCH);
2143          }
2144      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2145        {        {
2146        int chartype, script;        const ucd_record *prop = GET_UCD(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
2147    
2148        switch(ecode[1])        switch(ecode[1])
2149          {          {
2150          case PT_ANY:          case PT_ANY:
2151          if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH);          if (op == OP_NOTPROP) MRRETURN(MATCH_NOMATCH);
2152          break;          break;
2153    
2154          case PT_LAMP:          case PT_LAMP:
2155          if ((chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
2156               chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
2157               chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
2158            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2159           break;          break;
2160    
2161          case PT_GC:          case PT_GC:
2162          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
2163            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2164          break;          break;
2165    
2166          case PT_PC:          case PT_PC:
2167          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
2168            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2169          break;          break;
2170    
2171          case PT_SC:          case PT_SC:
2172          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
2173            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2174            break;
2175    
2176            /* These are specials */
2177    
2178            case PT_ALNUM:
2179            if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||
2180                 _pcre_ucp_gentype[prop->chartype] == ucp_N) == (op == OP_NOTPROP))
2181              MRRETURN(MATCH_NOMATCH);
2182            break;
2183    
2184            case PT_SPACE:    /* Perl space */
2185            if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||
2186                 c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)
2187                   == (op == OP_NOTPROP))
2188              MRRETURN(MATCH_NOMATCH);
2189            break;
2190    
2191            case PT_PXSPACE:  /* POSIX space */
2192            if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||
2193                 c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
2194                 c == CHAR_FF || c == CHAR_CR)
2195                   == (op == OP_NOTPROP))
2196              MRRETURN(MATCH_NOMATCH);
2197          break;          break;
2198    
2199            case PT_WORD:
2200            if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||
2201                 _pcre_ucp_gentype[prop->chartype] == ucp_N ||
2202                 c == CHAR_UNDERSCORE) == (op == OP_NOTPROP))
2203              MRRETURN(MATCH_NOMATCH);
2204            break;
2205    
2206            /* This should never occur */
2207    
2208          default:          default:
2209          RRETURN(PCRE_ERROR_INTERNAL);          RRETURN(PCRE_ERROR_INTERNAL);
         break;  
2210          }          }
2211    
2212        ecode += 3;        ecode += 3;
# Line 1467  for (;;) Line 2217  for (;;)
2217      is in the binary; otherwise a compile-time error occurs. */      is in the binary; otherwise a compile-time error occurs. */
2218    
2219      case OP_EXTUNI:      case OP_EXTUNI:
2220      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2221          {
2222          SCHECK_PARTIAL();
2223          MRRETURN(MATCH_NOMATCH);
2224          }
2225      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2226        {        {
2227        int chartype, script;        int category = UCD_CATEGORY(c);
2228        int category = _pcre_ucp_findprop(c, &chartype, &script);        if (category == ucp_M) MRRETURN(MATCH_NOMATCH);
       if (category == ucp_M) RRETURN(MATCH_NOMATCH);  
2229        while (eptr < md->end_subject)        while (eptr < md->end_subject)
2230          {          {
2231          int len = 1;          int len = 1;
# Line 1480  for (;;) Line 2233  for (;;)
2233            {            {
2234            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
2235            }            }
2236          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
2237          if (category != ucp_M) break;          if (category != ucp_M) break;
2238          eptr += len;          eptr += len;
2239          }          }
# Line 1501  for (;;) Line 2254  for (;;)
2254      case OP_REF:      case OP_REF:
2255        {        {
2256        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
2257        ecode += 3;                                 /* Advance past item */        ecode += 3;
2258    
2259          /* If the reference is unset, there are two possibilities:
2260    
2261        /* If the reference is unset, set the length to be longer than the amount        (a) In the default, Perl-compatible state, set the length to be longer
2262        of subject left; this ensures that every attempt at a match fails. We        than the amount of subject left; this ensures that every attempt at a
2263        can't just fail here, because of the possibility of quantifiers with zero        match fails. We can't just fail here, because of the possibility of
2264        minima. */        quantifiers with zero minima.
2265    
2266        length = (offset >= offset_top || md->offset_vector[offset] < 0)?        (b) If the JavaScript compatibility flag is set, set the length to zero
2267          md->end_subject - eptr + 1 :        so that the back reference matches an empty string.
2268          md->offset_vector[offset+1] - md->offset_vector[offset];  
2269          Otherwise, set the length to the length of what was matched by the
2270          referenced subpattern. */
2271    
2272          if (offset >= offset_top || md->offset_vector[offset] < 0)
2273            length = (md->jscript_compat)? 0 : (int)(md->end_subject - eptr + 1);
2274          else
2275            length = md->offset_vector[offset+1] - md->offset_vector[offset];
2276    
2277        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
2278    
# Line 1539  for (;;) Line 2301  for (;;)
2301          break;          break;
2302    
2303          default:               /* No repeat follows */          default:               /* No repeat follows */
2304          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
2305              {
2306              CHECK_PARTIAL();
2307              MRRETURN(MATCH_NOMATCH);
2308              }
2309          eptr += length;          eptr += length;
2310          continue;              /* With the main loop */          continue;              /* With the main loop */
2311          }          }
# Line 1555  for (;;) Line 2321  for (;;)
2321    
2322        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2323          {          {
2324          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
2325              {
2326              CHECK_PARTIAL();
2327              MRRETURN(MATCH_NOMATCH);
2328              }
2329          eptr += length;          eptr += length;
2330          }          }
2331    
# Line 1570  for (;;) Line 2340  for (;;)
2340          {          {
2341          for (fi = min;; fi++)          for (fi = min;; fi++)
2342            {            {
2343            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
2344            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2345            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2346              RRETURN(MATCH_NOMATCH);            if (!match_ref(offset, eptr, length, md, ims))
2347                {
2348                CHECK_PARTIAL();
2349                MRRETURN(MATCH_NOMATCH);
2350                }
2351            eptr += length;            eptr += length;
2352            }            }
2353          /* Control never gets here */          /* Control never gets here */
# Line 1586  for (;;) Line 2360  for (;;)
2360          pp = eptr;          pp = eptr;
2361          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2362            {            {
2363            if (!match_ref(offset, eptr, length, md, ims)) break;            if (!match_ref(offset, eptr, length, md, ims))
2364                {
2365                CHECK_PARTIAL();
2366                break;
2367                }
2368            eptr += length;            eptr += length;
2369            }            }
2370          while (eptr >= pp)          while (eptr >= pp)
2371            {            {
2372            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
2373            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2374            eptr -= length;            eptr -= length;
2375            }            }
2376          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2377          }          }
2378        }        }
2379      /* Control never gets here */      /* Control never gets here */
2380    
   
   
2381      /* Match a bit-mapped character class, possibly repeatedly. This op code is      /* Match a bit-mapped character class, possibly repeatedly. This op code is
2382      used when all the characters in the class have values in the range 0-255,      used when all the characters in the class have values in the range 0-255,
2383      and either the matching is caseful, or the characters are in the range      and either the matching is caseful, or the characters are in the range
# Line 1656  for (;;) Line 2432  for (;;)
2432          {          {
2433          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2434            {            {
2435            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2436                {
2437                SCHECK_PARTIAL();
2438                MRRETURN(MATCH_NOMATCH);
2439                }
2440            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
2441            if (c > 255)            if (c > 255)
2442              {              {
2443              if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);              if (op == OP_CLASS) MRRETURN(MATCH_NOMATCH);
2444              }              }
2445            else            else
2446              {              {
2447              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2448              }              }
2449            }            }
2450          }          }
# Line 1674  for (;;) Line 2454  for (;;)
2454          {          {
2455          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2456            {            {
2457            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2458                {
2459                SCHECK_PARTIAL();
2460                MRRETURN(MATCH_NOMATCH);
2461                }
2462            c = *eptr++;            c = *eptr++;
2463            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);            if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2464            }            }
2465          }          }
2466    
# Line 1696  for (;;) Line 2480  for (;;)
2480            {            {
2481            for (fi = min;; fi++)            for (fi = min;; fi++)
2482              {              {
2483              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
2484              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2485              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2486                if (eptr >= md->end_subject)
2487                  {
2488                  SCHECK_PARTIAL();
2489                  MRRETURN(MATCH_NOMATCH);
2490                  }
2491              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
2492              if (c > 255)              if (c > 255)
2493                {                {
2494                if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);                if (op == OP_CLASS) MRRETURN(MATCH_NOMATCH);
2495                }                }
2496              else              else
2497                {                {
2498                if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);                if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2499                }                }
2500              }              }
2501            }            }
# Line 1716  for (;;) Line 2505  for (;;)
2505            {            {
2506            for (fi = min;; fi++)            for (fi = min;; fi++)
2507              {              {
2508              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
2509              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2510              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2511                if (eptr >= md->end_subject)
2512                  {
2513                  SCHECK_PARTIAL();
2514                  MRRETURN(MATCH_NOMATCH);
2515                  }
2516              c = *eptr++;              c = *eptr++;
2517              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2518              }              }
2519            }            }
2520          /* Control never gets here */          /* Control never gets here */
# Line 1739  for (;;) Line 2533  for (;;)
2533            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2534              {              {
2535              int len = 1;              int len = 1;
2536              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
2537                  {
2538                  SCHECK_PARTIAL();
2539                  break;
2540                  }
2541              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
2542              if (c > 255)              if (c > 255)
2543                {                {
# Line 1753  for (;;) Line 2551  for (;;)
2551              }              }
2552            for (;;)            for (;;)
2553              {              {
2554              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
2555              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2556              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2557              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 1765  for (;;) Line 2563  for (;;)
2563            {            {
2564            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2565              {              {
2566              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
2567                  {
2568                  SCHECK_PARTIAL();
2569                  break;
2570                  }
2571              c = *eptr;              c = *eptr;
2572              if ((data[c/8] & (1 << (c&7))) == 0) break;              if ((data[c/8] & (1 << (c&7))) == 0) break;
2573              eptr++;              eptr++;
2574              }              }
2575            while (eptr >= pp)            while (eptr >= pp)
2576              {              {
2577              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
2578              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2579              eptr--;              eptr--;
2580              }              }
2581            }            }
2582    
2583          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2584          }          }
2585        }        }
2586      /* Control never gets here */      /* Control never gets here */
2587    
2588    
2589      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2590      in UTF-8 mode, because that's the only time it is compiled. */      when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8
2591        mode, because Unicode properties are supported in non-UTF-8 mode. */
2592    
2593  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2594      case OP_XCLASS:      case OP_XCLASS:
# Line 1826  for (;;) Line 2629  for (;;)
2629    
2630        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2631          {          {
2632          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject)
2633          GETCHARINC(c, eptr);            {
2634          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            SCHECK_PARTIAL();
2635              MRRETURN(MATCH_NOMATCH);
2636              }
2637            GETCHARINCTEST(c, eptr);
2638            if (!_pcre_xclass(c, data)) MRRETURN(MATCH_NOMATCH);
2639          }          }
2640    
2641        /* 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 1843  for (;;) Line 2650  for (;;)
2650          {          {
2651          for (fi = min;; fi++)          for (fi = min;; fi++)
2652            {            {
2653            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2654            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2655            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2656            GETCHARINC(c, eptr);            if (eptr >= md->end_subject)
2657            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);              {
2658                SCHECK_PARTIAL();
2659                MRRETURN(MATCH_NOMATCH);
2660                }
2661              GETCHARINCTEST(c, eptr);
2662              if (!_pcre_xclass(c, data)) MRRETURN(MATCH_NOMATCH);
2663            }            }
2664          /* Control never gets here */          /* Control never gets here */
2665          }          }
# Line 1860  for (;;) Line 2672  for (;;)
2672          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2673            {            {
2674            int len = 1;            int len = 1;
2675            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject)
2676            GETCHARLEN(c, eptr, len);              {
2677                SCHECK_PARTIAL();
2678                break;
2679                }
2680              GETCHARLENTEST(c, eptr, len);
2681            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2682            eptr += len;            eptr += len;
2683            }            }
2684          for(;;)          for(;;)
2685            {            {
2686            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2687            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2688            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2689            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2690            }            }
2691          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2692          }          }
2693    
2694        /* Control never gets here */        /* Control never gets here */
# Line 1888  for (;;) Line 2704  for (;;)
2704        length = 1;        length = 1;
2705        ecode++;        ecode++;
2706        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2707        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2708        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);          {
2709            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2710            MRRETURN(MATCH_NOMATCH);
2711            }
2712          while (length-- > 0) if (*ecode++ != *eptr++) MRRETURN(MATCH_NOMATCH);
2713        }        }
2714      else      else
2715  #endif  #endif
2716    
2717      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2718        {        {
2719        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2720        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);          {
2721            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2722            MRRETURN(MATCH_NOMATCH);
2723            }
2724          if (ecode[1] != *eptr++) MRRETURN(MATCH_NOMATCH);
2725        ecode += 2;        ecode += 2;
2726        }        }
2727      break;      break;
# Line 1912  for (;;) Line 2736  for (;;)
2736        ecode++;        ecode++;
2737        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2738    
2739        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2740            {
2741            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2742            MRRETURN(MATCH_NOMATCH);
2743            }
2744    
2745        /* 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
2746        can use the fast lookup table. */        can use the fast lookup table. */
2747    
2748        if (fc < 128)        if (fc < 128)
2749          {          {
2750          if (md->lcc[*ecode++] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          if (md->lcc[*ecode++] != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
2751          }          }
2752    
2753        /* Otherwise we must pick up the subject character */        /* Otherwise we must pick up the subject character */
2754    
2755        else        else
2756          {          {
2757          int dc;          unsigned int dc;
2758          GETCHARINC(dc, eptr);          GETCHARINC(dc, eptr);
2759          ecode += length;          ecode += length;
2760    
# Line 1936  for (;;) Line 2764  for (;;)
2764          if (fc != dc)          if (fc != dc)
2765            {            {
2766  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2767            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2768  #endif  #endif
2769              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
2770            }            }
2771          }          }
2772        }        }
# Line 1947  for (;;) Line 2775  for (;;)
2775    
2776      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2777        {        {
2778        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2779        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          {
2780            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2781            MRRETURN(MATCH_NOMATCH);
2782            }
2783          if (md->lcc[ecode[1]] != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
2784        ecode += 2;        ecode += 2;
2785        }        }
2786      break;      break;
2787    
2788      /* Match a single character repeatedly; different opcodes share code. */      /* Match a single character repeatedly. */
2789    
2790      case OP_EXACT:      case OP_EXACT:
2791      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
2792      ecode += 3;      ecode += 3;
2793      goto REPEATCHAR;      goto REPEATCHAR;
2794    
2795        case OP_POSUPTO:
2796        possessive = TRUE;
2797        /* Fall through */
2798    
2799      case OP_UPTO:      case OP_UPTO:
2800      case OP_MINUPTO:      case OP_MINUPTO:
2801      min = 0;      min = 0;
# Line 1968  for (;;) Line 2804  for (;;)
2804      ecode += 3;      ecode += 3;
2805      goto REPEATCHAR;      goto REPEATCHAR;
2806    
2807        case OP_POSSTAR:
2808        possessive = TRUE;
2809        min = 0;
2810        max = INT_MAX;
2811        ecode++;
2812        goto REPEATCHAR;
2813    
2814        case OP_POSPLUS:
2815        possessive = TRUE;
2816        min = 1;
2817        max = INT_MAX;
2818        ecode++;
2819        goto REPEATCHAR;
2820    
2821        case OP_POSQUERY:
2822        possessive = TRUE;
2823        min = 0;
2824        max = 1;
2825        ecode++;
2826        goto REPEATCHAR;
2827    
2828      case OP_STAR:      case OP_STAR:
2829      case OP_MINSTAR:      case OP_MINSTAR:
2830      case OP_PLUS:      case OP_PLUS:
# Line 1976  for (;;) Line 2833  for (;;)
2833      case OP_MINQUERY:      case OP_MINQUERY:
2834      c = *ecode++ - OP_STAR;      c = *ecode++ - OP_STAR;
2835      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
2836    
2837      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
2838      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2839      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2840    
2841      /* Common code for all repeated single-character matches. We can give      /* Common code for all repeated single-character matches. */
     up quickly if there are fewer than the minimum number of characters left in  
     the subject. */  
2842    
2843      REPEATCHAR:      REPEATCHAR:
2844  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1991  for (;;) Line 2847  for (;;)
2847        length = 1;        length = 1;
2848        charptr = ecode;        charptr = ecode;
2849        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
       if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2850        ecode += length;        ecode += length;
2851    
2852        /* Handle multibyte character matching specially here. There is        /* Handle multibyte character matching specially here. There is
# Line 1999  for (;;) Line 2854  for (;;)
2854    
2855        if (length > 1)        if (length > 1)
2856          {          {
         int oclength = 0;  
         uschar occhars[8];  
   
2857  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2858          int othercase;          unsigned int othercase;
2859          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2860              (othercase = _pcre_ucp_othercase(fc)) >= 0 &&              (othercase = UCD_OTHERCASE(fc)) != fc)
              othercase >= 0)  
2861            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2862            else oclength = 0;
2863  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2864    
2865          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2866            {            {
2867            if (memcmp(eptr, charptr, length) == 0) eptr += length;            if (eptr <= md->end_subject - length &&
2868            /* Need braces because of following else */              memcmp(eptr, charptr, length) == 0) eptr += length;
2869            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }  #ifdef SUPPORT_UCP
2870              else if (oclength > 0 &&
2871                       eptr <= md->end_subject - oclength &&
2872                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2873    #endif  /* SUPPORT_UCP */
2874            else            else
2875              {              {
2876              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);              CHECK_PARTIAL();
2877              eptr += oclength;              MRRETURN(MATCH_NOMATCH);
2878              }              }
2879            }            }
2880    
# Line 2028  for (;;) Line 2884  for (;;)
2884            {            {
2885            for (fi = min;; fi++)            for (fi = min;; fi++)
2886              {              {
2887              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2888              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2889              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2890              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (eptr <= md->end_subject - length &&
2891              /* Need braces because of following else */                memcmp(eptr, charptr, length) == 0) eptr += length;
2892              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }  #ifdef SUPPORT_UCP
2893                else if (oclength > 0 &&
2894                         eptr <= md->end_subject - oclength &&
2895                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2896    #endif  /* SUPPORT_UCP */
2897              else              else
2898                {                {
2899                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);                CHECK_PARTIAL();
2900                eptr += oclength;                MRRETURN(MATCH_NOMATCH);
2901                }                }
2902              }              }
2903            /* Control never gets here */            /* Control never gets here */
2904            }            }
2905          else  
2906            else  /* Maximize */
2907            {            {
2908            pp = eptr;            pp = eptr;
2909            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2910              {              {
2911              if (eptr > md->end_subject - length) break;              if (eptr <= md->end_subject - length &&
2912              if (memcmp(eptr, charptr, length) == 0) eptr += length;                  memcmp(eptr, charptr, length) == 0) eptr += length;
2913              else if (oclength == 0) break;  #ifdef SUPPORT_UCP
2914                else if (oclength > 0 &&
2915                         eptr <= md->end_subject - oclength &&
2916                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2917    #endif  /* SUPPORT_UCP */
2918              else              else
2919                {                {
2920                if (memcmp(eptr, occhars, oclength) != 0) break;                CHECK_PARTIAL();
2921                eptr += oclength;                break;
2922                }                }
2923              }              }
2924            while (eptr >= pp)  
2925             {            if (possessive) continue;
2926             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);  
2927             if (rrc != MATCH_NOMATCH) RRETURN(rrc);            for(;;)
2928             eptr -= length;              {
2929             }              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2930            RRETURN(MATCH_NOMATCH);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2931                if (eptr == pp) { MRRETURN(MATCH_NOMATCH); }
2932    #ifdef SUPPORT_UCP
2933                eptr--;
2934                BACKCHAR(eptr);
2935    #else   /* without SUPPORT_UCP */
2936                eptr -= length;
2937    #endif  /* SUPPORT_UCP */
2938                }
2939            }            }
2940          /* Control never gets here */          /* Control never gets here */
2941          }          }
# Line 2075  for (;;) Line 2948  for (;;)
2948  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF8 */
2949    
2950      /* When not in UTF-8 mode, load a single-byte character. */      /* When not in UTF-8 mode, load a single-byte character. */
2951        {  
2952        if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);      fc = *ecode++;
       fc = *ecode++;  
       }  
2953    
2954      /* The value of fc at this point is always less than 256, though we may or      /* The value of fc at this point is always less than 256, though we may or
2955      may not be in UTF-8 mode. The code is duplicated for the caseless and      may not be in UTF-8 mode. The code is duplicated for the caseless and
# Line 2096  for (;;) Line 2967  for (;;)
2967        {        {
2968        fc = md->lcc[fc];        fc = md->lcc[fc];
2969        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2970          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          {
2971            if (eptr >= md->end_subject)
2972              {
2973              SCHECK_PARTIAL();
2974              MRRETURN(MATCH_NOMATCH);
2975              }
2976            if (fc != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
2977            }
2978        if (min == max) continue;        if (min == max) continue;
2979        if (minimize)        if (minimize)
2980          {          {
2981          for (fi = min;; fi++)          for (fi = min;; fi++)
2982            {            {
2983            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2984            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2985            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2986                fc != md->lcc[*eptr++])            if (eptr >= md->end_subject)
2987              RRETURN(MATCH_NOMATCH);              {
2988                SCHECK_PARTIAL();
2989                MRRETURN(MATCH_NOMATCH);
2990                }
2991              if (fc != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
2992            }            }
2993          /* Control never gets here */          /* Control never gets here */
2994          }          }
2995        else        else  /* Maximize */
2996          {          {
2997          pp = eptr;          pp = eptr;
2998          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2999            {            {
3000            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject)
3001                {
3002                SCHECK_PARTIAL();
3003                break;
3004                }
3005              if (fc != md->lcc[*eptr]) break;
3006            eptr++;            eptr++;
3007            }            }
3008    
3009            if (possessive) continue;
3010    
3011          while (eptr >= pp)          while (eptr >= pp)
3012            {            {
3013            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
3014            eptr--;            eptr--;
3015            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3016            }            }
3017          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
3018          }          }
3019        /* Control never gets here */        /* Control never gets here */
3020        }        }
# Line 2133  for (;;) Line 3023  for (;;)
3023    
3024      else      else
3025        {        {
3026        for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH);        for (i = 1; i <= min; i++)
3027            {
3028            if (eptr >= md->end_subject)
3029              {
3030              SCHECK_PARTIAL();
3031              MRRETURN(MATCH_NOMATCH);
3032              }
3033            if (fc != *eptr++) MRRETURN(MATCH_NOMATCH);
3034            }
3035    
3036        if (min == max) continue;        if (min == max) continue;
3037    
3038        if (minimize)        if (minimize)
3039          {          {
3040          for (fi = min;; fi++)          for (fi = min;; fi++)
3041            {            {
3042            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
3043            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3044            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max) MRRETURN(MATCH_NOMATCH);
3045              RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3046                {
3047                SCHECK_PARTIAL();
3048                MRRETURN(MATCH_NOMATCH);
3049                }
3050              if (fc != *eptr++) MRRETURN(MATCH_NOMATCH);
3051            }            }
3052          /* Control never gets here */          /* Control never gets here */
3053          }          }
3054        else        else  /* Maximize */
3055          {          {
3056          pp = eptr;          pp = eptr;
3057          for (i = min; i < max; i++)          for (i = min; i < max; i++)
3058            {            {
3059            if (eptr >= md->end_subject || fc != *eptr) break;            if (eptr >= md->end_subject)
3060                {
3061                SCHECK_PARTIAL();
3062                break;
3063                }
3064              if (fc != *eptr) break;
3065            eptr++;            eptr++;
3066            }            }
3067            if (possessive) continue;
3068    
3069          while (eptr >= pp)          while (eptr >= pp)
3070            {            {
3071            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
3072            eptr--;            eptr--;
3073            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3074            }            }
3075          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
3076          }          }
3077        }        }
3078      /* Control never gets here */      /* Control never gets here */
# Line 2169  for (;;) Line 3081  for (;;)
3081      checking can be multibyte. */      checking can be multibyte. */
3082    
3083      case OP_NOT:      case OP_NOT:
3084      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
3085          {
3086          SCHECK_PARTIAL();
3087          MRRETURN(MATCH_NOMATCH);
3088          }
3089      ecode++;      ecode++;
3090      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
3091      if ((ims & PCRE_CASELESS) != 0)      if ((ims & PCRE_CASELESS) != 0)
# Line 2178  for (;;) Line 3094  for (;;)
3094        if (c < 256)        if (c < 256)
3095  #endif  #endif
3096        c = md->lcc[c];        c = md->lcc[c];
3097        if (md->lcc[*ecode++] == c) RRETURN(MATCH_NOMATCH);        if (md->lcc[*ecode++] == c) MRRETURN(MATCH_NOMATCH);
3098        }        }
3099      else      else
3100        {        {
3101        if (*ecode++ == c) RRETURN(MATCH_NOMATCH);        if (*ecode++ == c) MRRETURN(MATCH_NOMATCH);
3102        }        }
3103      break;      break;
3104    
# Line 2206  for (;;) Line 3122  for (;;)
3122      ecode += 3;      ecode += 3;
3123      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3124    
3125        case OP_NOTPOSSTAR:
3126        possessive = TRUE;
3127        min = 0;
3128        max = INT_MAX;
3129        ecode++;
3130        goto REPEATNOTCHAR;
3131    
3132        case OP_NOTPOSPLUS:
3133        possessive = TRUE;
3134        min = 1;
3135        max = INT_MAX;
3136        ecode++;
3137        goto REPEATNOTCHAR;
3138    
3139        case OP_NOTPOSQUERY:
3140        possessive = TRUE;
3141        min = 0;
3142        max = 1;
3143        ecode++;
3144        goto REPEATNOTCHAR;
3145    
3146        case OP_NOTPOSUPTO:
3147        possessive = TRUE;
3148        min = 0;
3149        max = GET2(ecode, 1);
3150        ecode += 3;
3151        goto REPEATNOTCHAR;
3152    
3153      case OP_NOTSTAR:      case OP_NOTSTAR:
3154      case OP_NOTMINSTAR:      case OP_NOTMINSTAR:
3155      case OP_NOTPLUS:      case OP_NOTPLUS:
# Line 2218  for (;;) Line 3162  for (;;)
3162      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
3163      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
3164    
3165      /* Common code for all repeated single-byte matches. We can give up quickly      /* Common code for all repeated single-byte matches. */
     if there are fewer than the minimum number of bytes left in the  
     subject. */  
3166    
3167      REPEATNOTCHAR:      REPEATNOTCHAR:
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
3168      fc = *ecode++;      fc = *ecode++;
3169    
3170      /* The code is duplicated for the caseless and caseful cases, for speed,      /* The code is duplicated for the caseless and caseful cases, for speed,
# Line 2245  for (;;) Line 3186  for (;;)
3186        /* UTF-8 mode */        /* UTF-8 mode */
3187        if (utf8)        if (utf8)
3188          {          {
3189          register int d;          register unsigned int d;
3190          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3191            {            {
3192              if (eptr >= md->end_subject)
3193                {
3194                SCHECK_PARTIAL();
3195                MRRETURN(MATCH_NOMATCH);
3196                }
3197            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3198            if (d < 256) d = md->lcc[d];            if (d < 256) d = md->lcc[d];
3199            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) MRRETURN(MATCH_NOMATCH);
3200            }            }
3201          }          }
3202        else        else
# Line 2259  for (;;) Line 3205  for (;;)
3205        /* Not UTF-8 mode */        /* Not UTF-8 mode */
3206          {          {
3207          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3208            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);            {
3209              if (eptr >= md->end_subject)
3210                {
3211                SCHECK_PARTIAL();
3212                MRRETURN(MATCH_NOMATCH);
3213                }
3214              if (fc == md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
3215              }
3216          }          }
3217    
3218        if (min == max) continue;        if (min == max) continue;
# Line 2270  for (;;) Line 3223  for (;;)
3223          /* UTF-8 mode */          /* UTF-8 mode */
3224          if (utf8)          if (utf8)
3225            {            {
3226            register int d;            register unsigned int d;
3227            for (fi = min;; fi++)            for (fi = min;; fi++)
3228              {              {
3229              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
3230              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3231                if (fi >= max) MRRETURN(MATCH_NOMATCH);
3232                if (eptr >= md->end_subject)
3233                  {
3234                  SCHECK_PARTIAL();
3235                  MRRETURN(MATCH_NOMATCH);
3236                  }
3237              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3238              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
3239              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) MRRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
3240              }              }
3241            }            }
3242          else          else
# Line 2287  for (;;) Line 3245  for (;;)
3245            {            {
3246            for (fi = min;; fi++)            for (fi = min;; fi++)
3247              {              {
3248              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
3249              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3250              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3251                RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3252                  {
3253                  SCHECK_PARTIAL();
3254                  MRRETURN(MATCH_NOMATCH);
3255                  }
3256                if (fc == md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
3257              }              }
3258            }            }
3259          /* Control never gets here */          /* Control never gets here */
# Line 2306  for (;;) Line 3269  for (;;)
3269          /* UTF-8 mode */          /* UTF-8 mode */
3270          if (utf8)          if (utf8)
3271            {            {
3272            register int d;            register unsigned int d;
3273            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3274              {              {
3275              int len = 1;              int len = 1;
3276              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
3277                  {
3278                  SCHECK_PARTIAL();
3279                  break;
3280                  }
3281              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3282              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
3283              if (fc == d) break;              if (fc == d) break;
3284              eptr += len;              eptr += len;
3285              }              }
3286            for(;;)          if (possessive) continue;
3287            for(;;)
3288              {              {
3289              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
3290              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3291              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3292              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2330  for (;;) Line 3298  for (;;)
3298            {            {
3299            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3300              {              {
3301              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;              if (eptr >= md->end_subject)
3302                  {
3303                  SCHECK_PARTIAL();
3304                  break;
3305                  }
3306                if (fc == md->lcc[*eptr]) break;
3307              eptr++;              eptr++;
3308              }              }
3309              if (possessive) continue;
3310            while (eptr >= pp)            while (eptr >= pp)
3311              {              {
3312              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
3313              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3314              eptr--;              eptr--;
3315              }              }
3316            }            }
3317    
3318          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
3319          }          }
3320        /* Control never gets here */        /* Control never gets here */
3321        }        }
# Line 2354  for (;;) Line 3328  for (;;)
3328        /* UTF-8 mode */        /* UTF-8 mode */
3329        if (utf8)        if (utf8)
3330          {          {
3331          register int d;          register unsigned int d;
3332          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3333            {            {
3334              if (eptr >= md->end_subject)
3335                {
3336                SCHECK_PARTIAL();
3337                MRRETURN(MATCH_NOMATCH);
3338                }
3339            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3340            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) MRRETURN(MATCH_NOMATCH);
3341            }            }
3342          }          }
3343        else        else
# Line 2366  for (;;) Line 3345  for (;;)
3345        /* Not UTF-8 mode */        /* Not UTF-8 mode */
3346          {          {
3347          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3348            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);            {
3349          }            if (eptr >= md->end_subject)
3350                {
3351        if (min == max) continue;              SCHECK_PARTIAL();
3352                MRRETURN(MATCH_NOMATCH);
3353                }
3354              if (fc == *eptr++) MRRETURN(MATCH_NOMATCH);
3355              }
3356            }
3357    
3358          if (min == max) continue;
3359    
3360        if (minimize)        if (minimize)
3361          {          {
# Line 2377  for (;;) Line 3363  for (;;)
3363          /* UTF-8 mode */          /* UTF-8 mode */
3364          if (utf8)          if (utf8)
3365            {            {
3366            register int d;            register unsigned int d;
3367            for (fi = min;; fi++)            for (fi = min;; fi++)
3368              {              {
3369              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
3370              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3371                if (fi >= max) MRRETURN(MATCH_NOMATCH);
3372                if (eptr >= md->end_subject)
3373                  {
3374                  SCHECK_PARTIAL();
3375                  MRRETURN(MATCH_NOMATCH);
3376                  }
3377              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3378              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) MRRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
3379              }              }
3380            }            }
3381          else          else
# Line 2393  for (;;) Line 3384  for (;;)
3384            {            {
3385            for (fi = min;; fi++)            for (fi = min;; fi++)
3386              {              {
3387              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
3388              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3389              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3390                RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3391                  {
3392                  SCHECK_PARTIAL();
3393                  MRRETURN(MATCH_NOMATCH);
3394                  }
3395                if (fc == *eptr++) MRRETURN(MATCH_NOMATCH);
3396              }              }
3397            }            }
3398          /* Control never gets here */          /* Control never gets here */
# Line 2412  for (;;) Line 3408  for (;;)
3408          /* UTF-8 mode */          /* UTF-8 mode */
3409          if (utf8)          if (utf8)
3410            {            {
3411            register int d;            register unsigned int d;
3412            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3413              {              {
3414              int len = 1;              int len = 1;
3415              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
3416                  {
3417                  SCHECK_PARTIAL();
3418                  break;
3419                  }
3420              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3421              if (fc == d) break;              if (fc == d) break;
3422              eptr += len;              eptr += len;
3423              }              }
3424              if (possessive) continue;
3425            for(;;)            for(;;)
3426              {              {
3427              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
3428              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3429              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3430              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2435  for (;;) Line 3436  for (;;)
3436            {            {
3437            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3438              {              {
3439              if (eptr >= md->end_subject || fc == *eptr) break;              if (eptr >= md->end_subject)
3440                  {
3441                  SCHECK_PARTIAL();
3442                  break;
3443                  }
3444                if (fc == *eptr) break;
3445              eptr++;              eptr++;
3446              }              }
3447              if (possessive) continue;
3448            while (eptr >= pp)            while (eptr >= pp)
3449              {              {
3450              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
3451              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3452              eptr--;              eptr--;
3453              }              }
3454            }            }
3455    
3456          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
3457          }          }
3458        }        }
3459      /* Control never gets here */      /* Control never gets here */
# Line 2469  for (;;) Line 3476  for (;;)
3476      ecode += 3;      ecode += 3;
3477      goto REPEATTYPE;      goto REPEATTYPE;
3478    
3479        case OP_TYPEPOSSTAR:
3480        possessive = TRUE;
3481        min = 0;
3482        max = INT_MAX;
3483        ecode++;
3484        goto REPEATTYPE;
3485    
3486        case OP_TYPEPOSPLUS:
3487        possessive = TRUE;
3488        min = 1;
3489        max = INT_MAX;
3490        ecode++;
3491        goto REPEATTYPE;
3492    
3493        case OP_TYPEPOSQUERY:
3494        possessive = TRUE;
3495        min = 0;
3496        max = 1;
3497        ecode++;
3498        goto REPEATTYPE;
3499    
3500        case OP_TYPEPOSUPTO:
3501        possessive = TRUE;
3502        min = 0;
3503        max = GET2(ecode, 1);
3504        ecode += 3;
3505        goto REPEATTYPE;
3506    
3507      case OP_TYPESTAR:      case OP_TYPESTAR:
3508      case OP_TYPEMINSTAR:      case OP_TYPEMINSTAR:
3509      case OP_TYPEPLUS:      case OP_TYPEPLUS:
# Line 2500  for (;;) Line 3535  for (;;)
3535    
3536      /* First, ensure the minimum number of matches are present. Use inline      /* First, ensure the minimum number of matches are present. Use inline
3537      code for maximizing the speed, and do the type test once at the start      code for maximizing the speed, and do the type test once at the start
3538      (i.e. keep it out of the loop). Also we can test that there are at least      (i.e. keep it out of the loop). Separate the UTF-8 code completely as that
     the minimum number of bytes before we start. This isn't as effective in  
     UTF-8 mode, but it does no harm. Separate the UTF-8 code completely as that  
3539      is tidier. Also separate the UCP code, which can be the same for both UTF-8      is tidier. Also separate the UCP code, which can be the same for both UTF-8
3540      and single-bytes. */      and single-bytes. */
3541    
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
3542      if (min > 0)      if (min > 0)
3543        {        {
3544  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2515  for (;;) Line 3547  for (;;)
3547          switch(prop_type)          switch(prop_type)
3548            {            {
3549            case PT_ANY:            case PT_ANY:
3550            if (prop_fail_result) RRETURN(MATCH_NOMATCH);            if (prop_fail_result) MRRETURN(MATCH_NOMATCH);
3551            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3552              {              {
3553              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3554              GETCHARINC(c, eptr);                {
3555                  SCHECK_PARTIAL();
3556                  MRRETURN(MATCH_NOMATCH);
3557                  }
3558                GETCHARINCTEST(c, eptr);
3559              }              }
3560            break;            break;
3561    
3562            case PT_LAMP:            case PT_LAMP:
3563            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3564              {              {
3565              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3566              GETCHARINC(c, eptr);                {
3567              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3568                  MRRETURN(MATCH_NOMATCH);
3569                  }
3570                GETCHARINCTEST(c, eptr);
3571                prop_chartype = UCD_CHARTYPE(c);
3572              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3573                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3574                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
3575                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3576              }              }
3577            break;            break;
3578    
3579            case PT_GC:            case PT_GC:
3580            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3581              {              {
3582              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3583              GETCHARINC(c, eptr);                {
3584              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3585                  MRRETURN(MATCH_NOMATCH);
3586                  }
3587                GETCHARINCTEST(c, eptr);
3588                prop_category = UCD_CATEGORY(c);
3589              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3590                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3591              }              }
3592            break;            break;
3593    
3594            case PT_PC:            case PT_PC:
3595            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3596              {              {
3597              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3598              GETCHARINC(c, eptr);                {
3599              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3600                  MRRETURN(MATCH_NOMATCH);
3601                  }
3602                GETCHARINCTEST(c, eptr);
3603                prop_chartype = UCD_CHARTYPE(c);
3604              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3605                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3606              }              }
3607            break;            break;
3608    
3609            case PT_SC:            case PT_SC:
3610            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3611              {              {
3612              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3613              GETCHARINC(c, eptr);                {
3614              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3615                  MRRETURN(MATCH_NOMATCH);
3616                  }
3617                GETCHARINCTEST(c, eptr);
3618                prop_script = UCD_SCRIPT(c);
3619              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3620                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3621                }
3622              break;
3623    
3624              case PT_ALNUM:
3625              for (i = 1; i <= min; i++)
3626                {
3627                if (eptr >= md->end_subject)
3628                  {
3629                  SCHECK_PARTIAL();
3630                  MRRETURN(MATCH_NOMATCH);
3631                  }
3632                GETCHARINCTEST(c, eptr);
3633                prop_category = UCD_CATEGORY(c);
3634                if ((prop_category == ucp_L || prop_category == ucp_N)
3635                       == prop_fail_result)
3636                  MRRETURN(MATCH_NOMATCH);
3637                }
3638              break;
3639    
3640              case PT_SPACE:    /* Perl space */
3641              for (i = 1; i <= min; i++)
3642                {
3643                if (eptr >= md->end_subject)
3644                  {
3645                  SCHECK_PARTIAL();
3646                  MRRETURN(MATCH_NOMATCH);
3647                  }
3648                GETCHARINCTEST(c, eptr);
3649                prop_category = UCD_CATEGORY(c);
3650                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
3651                     c == CHAR_FF || c == CHAR_CR)
3652                       == prop_fail_result)
3653                  MRRETURN(MATCH_NOMATCH);
3654                }
3655              break;
3656    
3657              case PT_PXSPACE:  /* POSIX space */
3658              for (i = 1; i <= min; i++)
3659                {
3660                if (eptr >= md->end_subject)
3661                  {
3662                  SCHECK_PARTIAL();
3663                  MRRETURN(MATCH_NOMATCH);
3664                  }
3665                GETCHARINCTEST(c, eptr);
3666                prop_category = UCD_CATEGORY(c);
3667                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
3668                     c == CHAR_VT || c == CHAR_FF || c == CHAR_CR)
3669                       == prop_fail_result)
3670                  MRRETURN(MATCH_NOMATCH);
3671                }
3672              break;
3673    
3674              case PT_WORD:
3675              for (i = 1; i <= min; i++)
3676                {
3677                if (eptr >= md->end_subject)
3678                  {
3679                  SCHECK_PARTIAL();
3680                  MRRETURN(MATCH_NOMATCH);
3681                  }
3682                GETCHARINCTEST(c, eptr);
3683                prop_category = UCD_CATEGORY(c);
3684                if ((prop_category == ucp_L || prop_category == ucp_N ||
3685                     c == CHAR_UNDERSCORE)
3686                       == prop_fail_result)
3687                  MRRETURN(MATCH_NOMATCH);
3688              }              }
3689            break;            break;
3690    
3691              /* This should not occur */
3692    
3693            default:            default:
3694            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
           break;  
3695            }            }
3696          }          }
3697    
# Line 2582  for (;;) Line 3702  for (;;)
3702          {          {
3703          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3704            {            {
3705              if (eptr >= md->end_subject)
3706                {
3707                SCHECK_PARTIAL();
3708                MRRETURN(MATCH_NOMATCH);
3709                }
3710            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3711            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3712            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) MRRETURN(MATCH_NOMATCH);
3713            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3714              {              {
3715              int len = 1;              int len = 1;
3716              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3717                {                else { GETCHARLEN(c, eptr, len); }
3718                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);  
3719              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3720              eptr += len;              eptr += len;
3721              }              }
# Line 2610  for (;;) Line 3733  for (;;)
3733          case OP_ANY:          case OP_ANY:
3734          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3735            {            {
3736            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3737                 ((ims & PCRE_DOTALL) == 0 &&              {
3738                   eptr <= md->end_subject - md->nllen &&              SCHECK_PARTIAL();
3739                   IS_NEWLINE(eptr)))              MRRETURN(MATCH_NOMATCH);
3740              RRETURN(MATCH_NOMATCH);              }
3741              if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);
3742              eptr++;
3743              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3744              }
3745            break;
3746    
3747            case OP_ALLANY:
3748            for (i = 1; i <= min; i++)
3749              {
3750              if (eptr >= md->end_subject)
3751                {
3752                SCHECK_PARTIAL();
3753                MRRETURN(MATCH_NOMATCH);
3754                }
3755            eptr++;            eptr++;
3756            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3757            }            }
3758          break;          break;
3759    
3760          case OP_ANYBYTE:          case OP_ANYBYTE:
3761            if (eptr > md->end_subject - min) MRRETURN(MATCH_NOMATCH);
3762          eptr += min;          eptr += min;
3763          break;          break;
3764    
3765            case OP_ANYNL:
3766            for (i = 1; i <= min; i++)
3767              {
3768              if (eptr >= md->end_subject)
3769                {
3770                SCHECK_PARTIAL();
3771                MRRETURN(MATCH_NOMATCH);
3772                }
3773              GETCHARINC(c, eptr);
3774              switch(c)
3775                {
3776                default: MRRETURN(MATCH_NOMATCH);
3777                case 0x000d:
3778                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3779                break;
3780    
3781                case 0x000a:
3782                break;
3783    
3784                case 0x000b:
3785                case 0x000c:
3786                case 0x0085:
3787                case 0x2028:
3788                case 0x2029:
3789                if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
3790                break;
3791                }
3792              }
3793            break;
3794    
3795            case OP_NOT_HSPACE:
3796            for (i = 1; i <= min; i++)
3797              {
3798              if (eptr >= md->end_subject)
3799                {
3800                SCHECK_PARTIAL();
3801                MRRETURN(MATCH_NOMATCH);
3802                }
3803              GETCHARINC(c, eptr);
3804              switch(c)
3805                {
3806                default: break;
3807                case 0x09:      /* HT */
3808                case 0x20:      /* SPACE */
3809                case 0xa0:      /* NBSP */
3810                case 0x1680:    /* OGHAM SPACE MARK */
3811                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3812                case 0x2000:    /* EN QUAD */
3813                case 0x2001:    /* EM QUAD */
3814                case 0x2002:    /* EN SPACE */
3815                case 0x2003:    /* EM SPACE */
3816                case 0x2004:    /* THREE-PER-EM SPACE */
3817                case 0x2005:    /* FOUR-PER-EM SPACE */
3818                case 0x2006:    /* SIX-PER-EM SPACE */
3819                case 0x2007:    /* FIGURE SPACE */
3820                case 0x2008:    /* PUNCTUATION SPACE */
3821                case 0x2009:    /* THIN SPACE */
3822                case 0x200A:    /* HAIR SPACE */
3823                case 0x202f:    /* NARROW NO-BREAK SPACE */
3824                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3825                case 0x3000:    /* IDEOGRAPHIC SPACE */
3826                MRRETURN(MATCH_NOMATCH);
3827                }
3828              }
3829            break;
3830    
3831            case OP_HSPACE:
3832            for (i = 1; i <= min; i++)
3833              {
3834              if (eptr >= md->end_subject)
3835                {
3836                SCHECK_PARTIAL();
3837                MRRETURN(MATCH_NOMATCH);
3838                }
3839              GETCHARINC(c, eptr);
3840              switch(c)
3841                {