/[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 87 by nigel, Sat Feb 24 21:41:21 2007 UTC revision 400 by ph10, Sat Mar 21 16:59:40 2009 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-2009 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    #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_COMMIT       (-999)
75    #define MATCH_PRUNE        (-998)
76    #define MATCH_SKIP         (-997)
77    #define MATCH_THEN         (-996)
78    
79  /* 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.
80  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,
81  because the offset vector is always a multiple of 3 long. */  because the offset vector is always a multiple of 3 long. */
# Line 101  Returns:     nothing Line 109  Returns:     nothing
109  static void  static void
110  pchars(const uschar *p, int length, BOOL is_subject, match_data *md)  pchars(const uschar *p, int length, BOOL is_subject, match_data *md)
111  {  {
112  int c;  unsigned int c;
113  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;
114  while (length-- > 0)  while (length-- > 0)
115    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 150  printf("\n"); Line 158  printf("\n");
158    
159  if (length > md->end_subject - eptr) return FALSE;  if (length > md->end_subject - eptr) return FALSE;
160    
161  /* Separate the caselesss case for speed */  /* Separate the caseless case for speed. In UTF-8 mode we can only do this
162    properly if Unicode properties are supported. Otherwise, we can check only
163    ASCII characters. */
164    
165  if ((ims & PCRE_CASELESS) != 0)  if ((ims & PCRE_CASELESS) != 0)
166    {    {
167    #ifdef SUPPORT_UTF8
168    #ifdef SUPPORT_UCP
169      if (md->utf8)
170        {
171        USPTR endptr = eptr + length;
172        while (eptr < endptr)
173          {
174          int c, d;
175          GETCHARINC(c, eptr);
176          GETCHARINC(d, p);
177          if (c != d && c != UCD_OTHERCASE(d)) return FALSE;
178          }
179        }
180      else
181    #endif
182    #endif
183    
184      /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
185      is no UCP support. */
186    
187    while (length-- > 0)    while (length-- > 0)
188      if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE;      { if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; }
189    }    }
190    
191    /* In the caseful case, we can just compare the bytes, whether or not we
192    are in UTF-8 mode. */
193    
194  else  else
195    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
196    
# Line 186  calls by keeping local variables that ne Line 220  calls by keeping local variables that ne
220  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
221  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
222  always used to.  always used to.
223    
224    The original heap-recursive code used longjmp(). However, it seems that this
225    can be very slow on some operating systems. Following a suggestion from Stan
226    Switzer, the use of longjmp() has been abolished, at the cost of having to
227    provide a unique number for each call to RMATCH. There is no way of generating
228    a sequence of numbers at compile time in C. I have given them names, to make
229    them stand out more clearly.
230    
231    Crude tests on x86 Linux show a small speedup of around 5-8%. However, on
232    FreeBSD, avoiding longjmp() more than halves the time taken to run the standard
233    tests. Furthermore, not using longjmp() means that local dynamic variables
234    don't have indeterminate values; this has meant that the frame size can be
235    reduced because the result can be "passed back" by straight setting of the
236    variable instead of being passed in the frame.
237  ****************************************************************************  ****************************************************************************
238  ***************************************************************************/  ***************************************************************************/
239    
240    /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN
241    below must be updated in sync.  */
242    
243    enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM6,  RM7,  RM8,  RM9,  RM10,
244           RM11,  RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,
245           RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,
246           RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
247           RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
248           RM51,  RM52, RM53, RM54 };
249    
250  /* 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
251  versions and production versions. */  versions and production versions. Note that the "rw" argument of RMATCH isn't
252    actuall used in this definition. */
253    
254  #ifndef NO_RECURSE  #ifndef NO_RECURSE
255  #define REGISTER register  #define REGISTER register
256    
257  #ifdef DEBUG  #ifdef DEBUG
258  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
259    { \    { \
260    printf("match() called in line %d\n", __LINE__); \    printf("match() called in line %d\n", __LINE__); \
261    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1); \    rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1); \
262    printf("to line %d\n", __LINE__); \    printf("to line %d\n", __LINE__); \
263    }    }
264  #define RRETURN(ra) \  #define RRETURN(ra) \
# Line 208  versions and production versions. */ Line 267  versions and production versions. */
267    return ra; \    return ra; \
268    }    }
269  #else  #else
270  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
271    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1)    rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1)
272  #define RRETURN(ra) return ra  #define RRETURN(ra) return ra
273  #endif  #endif
274    
275  #else  #else
276    
277    
278  /* 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
279  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
280  match(), which never changes. */  argument of match(), which never changes. */
281    
282  #define REGISTER  #define REGISTER
283    
284  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg)\  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\
285    {\    {\
286    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\
287    if (setjmp(frame->Xwhere) == 0)\    frame->Xwhere = rw; \
288      {\    newframe->Xeptr = ra;\
289      newframe->Xeptr = ra;\    newframe->Xecode = rb;\
290      newframe->Xecode = rb;\    newframe->Xmstart = mstart;\
291      newframe->Xoffset_top = rc;\    newframe->Xoffset_top = rc;\
292      newframe->Xims = re;\    newframe->Xims = re;\
293      newframe->Xeptrb = rf;\    newframe->Xeptrb = rf;\
294      newframe->Xflags = rg;\    newframe->Xflags = rg;\
295      newframe->Xrdepth = frame->Xrdepth + 1;\    newframe->Xrdepth = frame->Xrdepth + 1;\
296      newframe->Xprevframe = frame;\    newframe->Xprevframe = frame;\
297      frame = newframe;\    frame = newframe;\
298      DPRINTF(("restarting from line %d\n", __LINE__));\    DPRINTF(("restarting from line %d\n", __LINE__));\
299      goto HEAP_RECURSE;\    goto HEAP_RECURSE;\
300      }\    L_##rw:\
301    else\    DPRINTF(("jumped back to line %d\n", __LINE__));\
     {\  
     DPRINTF(("longjumped back to line %d\n", __LINE__));\  
     frame = md->thisframe;\  
     rx = frame->Xresult;\  
     }\  
302    }    }
303    
304  #define RRETURN(ra)\  #define RRETURN(ra)\
# Line 254  match(), which never changes. */ Line 308  match(), which never changes. */
308    (pcre_stack_free)(newframe);\    (pcre_stack_free)(newframe);\
309    if (frame != NULL)\    if (frame != NULL)\
310      {\      {\
311      frame->Xresult = ra;\      rrc = ra;\
312      md->thisframe = frame;\      goto HEAP_RETURN;\
     longjmp(frame->Xwhere, 1);\  
313      }\      }\
314    return ra;\    return ra;\
315    }    }
# Line 271  typedef struct heapframe { Line 324  typedef struct heapframe {
324    
325    const uschar *Xeptr;    const uschar *Xeptr;
326    const uschar *Xecode;    const uschar *Xecode;
327      const uschar *Xmstart;
328    int Xoffset_top;    int Xoffset_top;
329    long int Xims;    long int Xims;
330    eptrblock *Xeptrb;    eptrblock *Xeptrb;
331    int Xflags;    int Xflags;
332    int Xrdepth;    unsigned int Xrdepth;
333    
334    /* Function local variables */    /* Function local variables */
335    
# Line 291  typedef struct heapframe { Line 345  typedef struct heapframe {
345    
346    BOOL Xcur_is_word;    BOOL Xcur_is_word;
347    BOOL Xcondition;    BOOL Xcondition;
   BOOL Xminimize;  
348    BOOL Xprev_is_word;    BOOL Xprev_is_word;
349    
350    unsigned long int Xoriginal_ims;    unsigned long int Xoriginal_ims;
# Line 303  typedef struct heapframe { Line 356  typedef struct heapframe {
356    int Xprop_category;    int Xprop_category;
357    int Xprop_chartype;    int Xprop_chartype;
358    int Xprop_script;    int Xprop_script;
359    int *Xprop_test_variable;    int Xoclength;
360      uschar Xocchars[8];
361  #endif  #endif
362    
363    int Xctype;    int Xctype;
364    int Xfc;    unsigned int Xfc;
365    int Xfi;    int Xfi;
366    int Xlength;    int Xlength;
367    int Xmax;    int Xmax;
# Line 321  typedef struct heapframe { Line 375  typedef struct heapframe {
375    
376    eptrblock Xnewptrb;    eptrblock Xnewptrb;
377    
378    /* Place to pass back result, and where to jump back to */    /* Where to jump back to */
379    
380    int  Xresult;    int Xwhere;
   jmp_buf Xwhere;  
381    
382  } heapframe;  } heapframe;
383    
# Line 340  typedef struct heapframe { Line 393  typedef struct heapframe {
393  *         Match from current position            *  *         Match from current position            *
394  *************************************************/  *************************************************/
395    
396  /* 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  
397  returns a negative (error) response, the outer incarnation must also return the  returns a negative (error) response, the outer incarnation must also return the
398  same response.  same response.
399    
# Line 353  performance. Tests using gcc on a SPARC Line 403  performance. Tests using gcc on a SPARC
403  made performance worse.  made performance worse.
404    
405  Arguments:  Arguments:
406     eptr        pointer in subject     eptr        pointer to current character in subject
407     ecode       position in code     ecode       pointer to current position in compiled code
408       mstart      pointer to the current match start position (can be modified
409                     by encountering \K)
410     offset_top  current top pointer     offset_top  current top pointer
411     md          pointer to "static" info for the match     md          pointer to "static" info for the match
412     ims         current /i, /m, and /s options     ims         current /i, /m, and /s options
# Line 362  Arguments: Line 414  Arguments:
414                   brackets - for testing for empty matches                   brackets - for testing for empty matches
415     flags       can contain     flags       can contain
416                   match_condassert - this is an assertion condition                   match_condassert - this is an assertion condition
417                   match_isgroup - this is the start of a bracketed group                   match_cbegroup - this is the start of an unlimited repeat
418                       group that can match an empty string
419     rdepth      the recursion depth     rdepth      the recursion depth
420    
421  Returns:       MATCH_MATCH if matched            )  these values are >= 0  Returns:       MATCH_MATCH if matched            )  these values are >= 0
# Line 372  Returns:       MATCH_MATCH if matched Line 425  Returns:       MATCH_MATCH if matched
425  */  */
426    
427  static int  static int
428  match(REGISTER USPTR eptr, REGISTER const uschar *ecode,  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, const uschar *mstart,
429    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,
430    int flags, int rdepth)    int flags, unsigned int rdepth)
431  {  {
432  /* 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,
433  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
434  because they are used a lot in loops. */  "register" because they are used a lot in loops. */
435    
436  register int  rrc;    /* Returns from recursive calls */  register int  rrc;         /* Returns from recursive calls */
437  register int  i;      /* Used for loops not involving calls to RMATCH() */  register int  i;           /* Used for loops not involving calls to RMATCH() */
438  register int  c;      /* Character values not kept over RMATCH() calls */  register unsigned int c;   /* Character values not kept over RMATCH() calls */
439  register BOOL utf8;   /* Local copy of UTF-8 flag for speed */  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
440    
441    BOOL minimize, possessive; /* Quantifier options */
442    
443  /* 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
444  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
# Line 398  frame->Xprevframe = NULL;            /* Line 453  frame->Xprevframe = NULL;            /*
453    
454  frame->Xeptr = eptr;  frame->Xeptr = eptr;
455  frame->Xecode = ecode;  frame->Xecode = ecode;
456    frame->Xmstart = mstart;
457  frame->Xoffset_top = offset_top;  frame->Xoffset_top = offset_top;
458  frame->Xims = ims;  frame->Xims = ims;
459  frame->Xeptrb = eptrb;  frame->Xeptrb = eptrb;
# Line 412  HEAP_RECURSE: Line 468  HEAP_RECURSE:
468    
469  #define eptr               frame->Xeptr  #define eptr               frame->Xeptr
470  #define ecode              frame->Xecode  #define ecode              frame->Xecode
471    #define mstart             frame->Xmstart
472  #define offset_top         frame->Xoffset_top  #define offset_top         frame->Xoffset_top
473  #define ims                frame->Xims  #define ims                frame->Xims
474  #define eptrb              frame->Xeptrb  #define eptrb              frame->Xeptrb
# Line 434  HEAP_RECURSE: Line 491  HEAP_RECURSE:
491    
492  #define cur_is_word        frame->Xcur_is_word  #define cur_is_word        frame->Xcur_is_word
493  #define condition          frame->Xcondition  #define condition          frame->Xcondition
 #define minimize           frame->Xminimize  
494  #define prev_is_word       frame->Xprev_is_word  #define prev_is_word       frame->Xprev_is_word
495    
496  #define original_ims       frame->Xoriginal_ims  #define original_ims       frame->Xoriginal_ims
# Line 446  HEAP_RECURSE: Line 502  HEAP_RECURSE:
502  #define prop_category      frame->Xprop_category  #define prop_category      frame->Xprop_category
503  #define prop_chartype      frame->Xprop_chartype  #define prop_chartype      frame->Xprop_chartype
504  #define prop_script        frame->Xprop_script  #define prop_script        frame->Xprop_script
505  #define prop_test_variable frame->Xprop_test_variable  #define oclength           frame->Xoclength
506    #define occhars            frame->Xocchars
507  #endif  #endif
508    
509  #define ctype              frame->Xctype  #define ctype              frame->Xctype
# Line 470  HEAP_RECURSE: Line 527  HEAP_RECURSE:
527  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
528  i, and fc and c, can be the same variables. */  i, and fc and c, can be the same variables. */
529    
530  #else  #else         /* NO_RECURSE not defined */
531  #define fi i  #define fi i
532  #define fc c  #define fc c
533    
# Line 489  recursion_info new_recursive;      /* wi Line 546  recursion_info new_recursive;      /* wi
546                                     /* that do not have to be preserved over  */                                     /* that do not have to be preserved over  */
547  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */
548  BOOL condition;  BOOL condition;
 BOOL minimize;  
549  BOOL prev_is_word;  BOOL prev_is_word;
550    
551  unsigned long int original_ims;  unsigned long int original_ims;
# Line 501  int prop_fail_result; Line 557  int prop_fail_result;
557  int prop_category;  int prop_category;
558  int prop_chartype;  int prop_chartype;
559  int prop_script;  int prop_script;
560  int *prop_test_variable;  int oclength;
561    uschar occhars[8];
562  #endif  #endif
563    
564    int codelink;
565    int condcode;
566  int ctype;  int ctype;
567  int length;  int length;
568  int max;  int max;
# Line 516  int save_offset1, save_offset2, save_off Line 575  int save_offset1, save_offset2, save_off
575  int stacksave[REC_STACK_SAVE_MAX];  int stacksave[REC_STACK_SAVE_MAX];
576    
577  eptrblock newptrb;  eptrblock newptrb;
578  #endif  #endif     /* NO_RECURSE */
579    
580  /* These statements are here to stop the compiler complaining about unitialized  /* These statements are here to stop the compiler complaining about unitialized
581  variables. */  variables. */
# Line 524  variables. */ Line 583  variables. */
583  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
584  prop_value = 0;  prop_value = 0;
585  prop_fail_result = 0;  prop_fail_result = 0;
 prop_test_variable = NULL;  
586  #endif  #endif
587    
588    
589    /* This label is used for tail recursion, which is used in a few cases even
590    when NO_RECURSE is not defined, in order to reduce the amount of stack that is
591    used. Thanks to Ian Taylor for noticing this possibility and sending the
592    original patch. */
593    
594    TAIL_RECURSE:
595    
596  /* 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
597  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
598  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()
# Line 535  defined). However, RMATCH isn't like a f Line 601  defined). However, RMATCH isn't like a f
601  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,
602  however, impact performance when true recursion is being used. */  however, impact performance when true recursion is being used. */
603    
604    #ifdef SUPPORT_UTF8
605    utf8 = md->utf8;       /* Local copy of the flag */
606    #else
607    utf8 = FALSE;
608    #endif
609    
610  /* 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
611  haven't exceeded the recursive call limit. */  haven't exceeded the recursive call limit. */
612    
# Line 542  if (md->match_call_count++ >= md->match_ Line 614  if (md->match_call_count++ >= md->match_
614  if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT);  if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT);
615    
616  original_ims = ims;    /* Save for resetting on ')' */  original_ims = ims;    /* Save for resetting on ')' */
 utf8 = md->utf8;       /* Local copy of the flag */  
617    
618  /* At the start of a bracketed group, add the current subject pointer to the  /* At the start of a group with an unlimited repeat that may match an empty
619  stack of such pointers, to be re-instated at the end of the group when we hit  string, the match_cbegroup flag is set. When this is the case, add the current
620  the closing ket. When match() is called in other circumstances, we don't add to  subject pointer to the chain of such remembered pointers, to be checked when we
621  this stack. */  hit the closing ket, in order to break infinite loops that match no characters.
622    When match() is called in other circumstances, don't add to the chain. The
623    match_cbegroup flag must NOT be used with tail recursion, because the memory
624    block that is used is on the stack, so a new one may be required for each
625    match(). */
626    
627  if ((flags & match_isgroup) != 0)  if ((flags & match_cbegroup) != 0)
628    {    {
   newptrb.epb_prev = eptrb;  
629    newptrb.epb_saved_eptr = eptr;    newptrb.epb_saved_eptr = eptr;
630      newptrb.epb_prev = eptrb;
631    eptrb = &newptrb;    eptrb = &newptrb;
632    }    }
633    
634  /* Now start processing the operations. */  /* Now start processing the opcodes. */
635    
636  for (;;)  for (;;)
637    {    {
638      minimize = possessive = FALSE;
639    op = *ecode;    op = *ecode;
640    minimize = FALSE;  
   
641    /* For partial matching, remember if we ever hit the end of the subject after    /* For partial matching, remember if we ever hit the end of the subject after
642    matching at least one subject character. */    matching at least one subject character. */
643    
644    if (md->partial &&    if (md->partial &&
645        eptr >= md->end_subject &&        eptr >= md->end_subject &&
646        eptr > md->start_match)        eptr > mstart)
647      md->hitend = TRUE;      md->hitend = TRUE;
648    
649    /* Opening capturing bracket. If there is space in the offset vector, save    switch(op)
   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)  
650      {      {
651      number = op - OP_BRA;      case OP_FAIL:
652        RRETURN(MATCH_NOMATCH);
     /* For extended extraction brackets (large number), we have to fish out the  
     number from a dummy opcode at the start. */  
653    
654      if (number > EXTRACT_BASIC_MAX)      case OP_PRUNE:
655        number = GET2(ecode, 2+LINK_SIZE);      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
656          ims, eptrb, flags, RM51);
657        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
658        RRETURN(MATCH_PRUNE);
659    
660        case OP_COMMIT:
661        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
662          ims, eptrb, flags, RM52);
663        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
664        RRETURN(MATCH_COMMIT);
665    
666        case OP_SKIP:
667        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
668          ims, eptrb, flags, RM53);
669        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
670        md->start_match_ptr = eptr;   /* Pass back current position */
671        RRETURN(MATCH_SKIP);
672    
673        case OP_THEN:
674        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
675          ims, eptrb, flags, RM54);
676        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
677        RRETURN(MATCH_THEN);
678    
679        /* Handle a capturing bracket. If there is space in the offset vector, save
680        the current subject position in the working slot at the top of the vector.
681        We mustn't change the current values of the data slot, because they may be
682        set from a previous iteration of this group, and be referred to by a
683        reference inside the group.
684    
685        If the bracket fails to match, we need to restore this value and also the
686        values of the final offsets, in case they were set by a previous iteration
687        of the same bracket.
688    
689        If there isn't enough space in the offset vector, treat this as if it were
690        a non-capturing bracket. Don't worry about setting the flag for the error
691        case here; that is handled in the code for KET. */
692    
693        case OP_CBRA:
694        case OP_SCBRA:
695        number = GET2(ecode, 1+LINK_SIZE);
696      offset = number << 1;      offset = number << 1;
697    
698  #ifdef DEBUG  #ifdef DEBUG
699      printf("start bracket %d subject=", number);      printf("start bracket %d\n", number);
700        printf("subject=");
701      pchars(eptr, 16, TRUE, md);      pchars(eptr, 16, TRUE, md);
702      printf("\n");      printf("\n");
703  #endif  #endif
# Line 612  for (;;) Line 712  for (;;)
712        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
713        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;
714    
715          flags = (op == OP_SCBRA)? match_cbegroup : 0;
716        do        do
717          {          {
718          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
719            match_isgroup);            ims, eptrb, flags, RM1);
720          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
721          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
722          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
723          }          }
# Line 631  for (;;) Line 732  for (;;)
732        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
733        }        }
734    
735      /* Insufficient room for saving captured contents */      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
736        as a non-capturing bracket. */
737    
738      else op = OP_BRA;      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
739      }      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
740    
741    /* Other types of node can be handled by a switch */      DPRINTF(("insufficient capture room: treat as non-capturing\n"));
742    
743    switch(op)      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
744      {      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
745      case OP_BRA:     /* Non-capturing bracket: optimized */  
746      DPRINTF(("start bracket 0\n"));      /* Non-capturing bracket. Loop for all the alternatives. When we get to the
747      do      final alternative within the brackets, we would return the result of a
748        recursive call to match() whatever happened. We can reduce stack usage by
749        turning this into a tail recursion, except in the case when match_cbegroup
750        is set.*/
751    
752        case OP_BRA:
753        case OP_SBRA:
754        DPRINTF(("start non-capturing bracket\n"));
755        flags = (op >= OP_SBRA)? match_cbegroup : 0;
756        for (;;)
757        {        {
758        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,        if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */
759          match_isgroup);          {
760        if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (flags == 0)    /* Not a possibly empty group */
761              {
762              ecode += _pcre_OP_lengths[*ecode];
763              DPRINTF(("bracket 0 tail recursion\n"));
764              goto TAIL_RECURSE;
765              }
766    
767            /* Possibly empty group; can't use tail recursion. */
768    
769            RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
770              eptrb, flags, RM48);
771            RRETURN(rrc);
772            }
773    
774          /* For non-final alternatives, continue the loop for a NOMATCH result;
775          otherwise return. */
776    
777          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
778            eptrb, flags, RM2);
779          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
780        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
781        }        }
782      while (*ecode == OP_ALT);      /* Control never reaches here. */
     DPRINTF(("bracket 0 failed\n"));  
     RRETURN(MATCH_NOMATCH);  
783    
784      /* Conditional group: compilation checked that there are no more than      /* Conditional group: compilation checked that there are no more than
785      two branches. If the condition is false, skipping the first branch takes us      two branches. If the condition is false, skipping the first branch takes us
786      past the end if there is only one branch, but that's OK because that is      past the end if there is only one branch, but that's OK because that is
787      exactly what going to the ket would do. */      exactly what going to the ket would do. As there is only one branch to be
788        obeyed, we can use tail recursion to avoid using another stack frame. */
789    
790      case OP_COND:      case OP_COND:
791      if (ecode[LINK_SIZE+1] == OP_CREF) /* Condition extract or recurse test */      case OP_SCOND:
792        codelink= GET(ecode, 1);
793    
794        /* Because of the way auto-callout works during compile, a callout item is
795        inserted between OP_COND and an assertion condition. */
796    
797        if (ecode[LINK_SIZE+1] == OP_CALLOUT)
798          {
799          if (pcre_callout != NULL)
800            {
801            pcre_callout_block cb;
802            cb.version          = 1;   /* Version 1 of the callout block */
803            cb.callout_number   = ecode[LINK_SIZE+2];
804            cb.offset_vector    = md->offset_vector;
805            cb.subject          = (PCRE_SPTR)md->start_subject;
806            cb.subject_length   = md->end_subject - md->start_subject;
807            cb.start_match      = mstart - md->start_subject;
808            cb.current_position = eptr - md->start_subject;
809            cb.pattern_position = GET(ecode, LINK_SIZE + 3);
810            cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
811            cb.capture_top      = offset_top/2;
812            cb.capture_last     = md->capture_last;
813            cb.callout_data     = md->callout_data;
814            if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);
815            if (rrc < 0) RRETURN(rrc);
816            }
817          ecode += _pcre_OP_lengths[OP_CALLOUT];
818          }
819    
820        condcode = ecode[LINK_SIZE+1];
821    
822        /* Now see what the actual condition is */
823    
824        if (condcode == OP_RREF)         /* Recursion test */
825          {
826          offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/
827          condition = md->recursive != NULL &&
828            (offset == RREF_ANY || offset == md->recursive->group_num);
829          ecode += condition? 3 : GET(ecode, 1);
830          }
831    
832        else if (condcode == OP_CREF)    /* Group used test */
833        {        {
834        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
835        condition = (offset == CREF_RECURSE * 2)?        condition = offset < offset_top && md->offset_vector[offset] >= 0;
836          (md->recursive != NULL) :        ecode += condition? 3 : GET(ecode, 1);
837          (offset < offset_top && md->offset_vector[offset] >= 0);        }
838        RMATCH(rrc, eptr, ecode + (condition?  
839          (LINK_SIZE + 4) : (LINK_SIZE + 1 + GET(ecode, 1))),      else if (condcode == OP_DEF)     /* DEFINE - always false */
840          offset_top, md, ims, eptrb, match_isgroup);        {
841        RRETURN(rrc);        condition = FALSE;
842          ecode += GET(ecode, 1);
843        }        }
844    
845      /* The condition is an assertion. Call match() to evaluate it - setting      /* The condition is an assertion. Call match() to evaluate it - setting
846      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
847        assertion. */
848    
849      else      else
850        {        {
851        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
852            match_condassert | match_isgroup);            match_condassert, RM3);
853        if (rrc == MATCH_MATCH)        if (rrc == MATCH_MATCH)
854          {          {
855          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE+2);          condition = TRUE;
856            ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
857          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
858          }          }
859        else if (rrc != MATCH_NOMATCH)        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
860          {          {
861          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
862          }          }
863        else ecode += GET(ecode, 1);        else
864        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,          {
865          match_isgroup);          condition = FALSE;
866        RRETURN(rrc);          ecode += codelink;
867            }
868        }        }
     /* Control never reaches here */  
869    
870      /* Skip over conditional reference or large extraction number data if      /* We are now at the branch that is to be obeyed. As there is only one,
871      encountered. */      we can use tail recursion to avoid using another stack frame, except when
872        match_cbegroup is required for an unlimited repeat of a possibly empty
873        group. If the second alternative doesn't exist, we can just plough on. */
874    
875      case OP_CREF:      if (condition || *ecode == OP_ALT)
876      case OP_BRANUMBER:        {
877      ecode += 3;        ecode += 1 + LINK_SIZE;
878          if (op == OP_SCOND)        /* Possibly empty group */
879            {
880            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
881            RRETURN(rrc);
882            }
883          else                       /* Group must match something */
884            {
885            flags = 0;
886            goto TAIL_RECURSE;
887            }
888          }
889        else                         /* Condition false & no alternative */
890          {
891          ecode += 1 + LINK_SIZE;
892          }
893      break;      break;
894    
     /* End of the pattern. If we are in a recursion, we should restore the  
     offsets appropriately and continue from after the call. */  
895    
896        /* End of the pattern, either real or forced. If we are in a top-level
897        recursion, we should restore the offsets appropriately and continue from
898        after the call. */
899    
900        case OP_ACCEPT:
901      case OP_END:      case OP_END:
902      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL && md->recursive->group_num == 0)
903        {        {
# Line 713  for (;;) Line 906  for (;;)
906        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
907        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
908          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
909        md->start_match = rec->save_start;        mstart = rec->save_start;
910        ims = original_ims;        ims = original_ims;
911        ecode = rec->after_call;        ecode = rec->after_call;
912        break;        break;
# Line 722  for (;;) Line 915  for (;;)
915      /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty      /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty
916      string - backtracking will then try other alternatives, if any. */      string - backtracking will then try other alternatives, if any. */
917    
918      if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH);      if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);
919      md->end_match_ptr = eptr;          /* Record where we ended */      md->end_match_ptr = eptr;           /* Record where we ended */
920      md->end_offset_top = offset_top;   /* and how many extracts were taken */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
921        md->start_match_ptr = mstart;       /* and the start (\K can modify) */
922      RRETURN(MATCH_MATCH);      RRETURN(MATCH_MATCH);
923    
924      /* Change option settings */      /* Change option settings */
# Line 745  for (;;) Line 939  for (;;)
939      case OP_ASSERTBACK:      case OP_ASSERTBACK:
940      do      do
941        {        {
942        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
943          match_isgroup);          RM4);
944        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
945        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
946        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
947        }        }
948      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 772  for (;;) Line 966  for (;;)
966      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
967      do      do
968        {        {
969        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
970          match_isgroup);          RM5);
971        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
972        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
973        ecode += GET(ecode,1);        ecode += GET(ecode,1);
974        }        }
975      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 794  for (;;) Line 988  for (;;)
988  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
989      if (utf8)      if (utf8)
990        {        {
991        c = GET(ecode,1);        i = GET(ecode, 1);
992        for (i = 0; i < c; i++)        while (i-- > 0)
993          {          {
994          eptr--;          eptr--;
995          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
996          BACKCHAR(eptr)          BACKCHAR(eptr);
997          }          }
998        }        }
999      else      else
# Line 808  for (;;) Line 1002  for (;;)
1002      /* 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 */
1003    
1004        {        {
1005        eptr -= GET(ecode,1);        eptr -= GET(ecode, 1);
1006        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1007        }        }
1008    
# Line 830  for (;;) Line 1024  for (;;)
1024        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1025        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1026        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = md->end_subject - md->start_subject;
1027        cb.start_match      = md->start_match - md->start_subject;        cb.start_match      = mstart - md->start_subject;
1028        cb.current_position = eptr - md->start_subject;        cb.current_position = eptr - md->start_subject;
1029        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
1030        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
# Line 865  for (;;) Line 1059  for (;;)
1059      case OP_RECURSE:      case OP_RECURSE:
1060        {        {
1061        callpat = md->start_code + GET(ecode, 1);        callpat = md->start_code + GET(ecode, 1);
1062        new_recursive.group_num = *callpat - OP_BRA;        new_recursive.group_num = (callpat == md->start_code)? 0 :
1063            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);  
1064    
1065        /* Add to "recursing stack" */        /* Add to "recursing stack" */
1066    
# Line 897  for (;;) Line 1086  for (;;)
1086    
1087        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1088              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1089        new_recursive.save_start = md->start_match;        new_recursive.save_start = mstart;
1090        md->start_match = eptr;        mstart = eptr;
1091    
1092        /* 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
1093        restore the offset and recursion data. */        restore the offset and recursion data. */
1094    
1095        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
1096          flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
1097        do        do
1098          {          {
1099          RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1100              eptrb, match_isgroup);            md, ims, eptrb, flags, RM6);
1101          if (rrc == MATCH_MATCH)          if (rrc == MATCH_MATCH)
1102            {            {
1103            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
# Line 916  for (;;) Line 1106  for (;;)
1106              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1107            RRETURN(MATCH_MATCH);            RRETURN(MATCH_MATCH);
1108            }            }
1109          else if (rrc != MATCH_NOMATCH)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1110            {            {
1111            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1112              if (new_recursive.offset_save != stacksave)
1113                (pcre_free)(new_recursive.offset_save);
1114            RRETURN(rrc);            RRETURN(rrc);
1115            }            }
1116    
# Line 945  for (;;) Line 1137  for (;;)
1137      the end of a normal bracket, leaving the subject pointer. */      the end of a normal bracket, leaving the subject pointer. */
1138    
1139      case OP_ONCE:      case OP_ONCE:
1140        {      prev = ecode;
1141        prev = ecode;      saved_eptr = eptr;
       saved_eptr = eptr;  
1142    
1143        do      do
1144          {        {
1145          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
1146            eptrb, match_isgroup);        if (rrc == MATCH_MATCH) break;
1147          if (rrc == MATCH_MATCH) break;        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1148          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        ecode += GET(ecode,1);
1149          ecode += GET(ecode,1);        }
1150          }      while (*ecode == OP_ALT);
       while (*ecode == OP_ALT);  
1151    
1152        /* If hit the end of the group (which could be repeated), fail */      /* If hit the end of the group (which could be repeated), fail */
1153    
1154        if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);      if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);
1155    
1156        /* Continue as from after the assertion, updating the offsets high water      /* Continue as from after the assertion, updating the offsets high water
1157        mark, since extracts may have been taken. */      mark, since extracts may have been taken. */
1158    
1159        do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
1160    
1161        offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1162        eptr = md->end_match_ptr;      eptr = md->end_match_ptr;
1163    
1164        /* For a non-repeating ket, just continue at this level. This also      /* For a non-repeating ket, just continue at this level. This also
1165        happens for a repeating ket if no characters were matched in the group.      happens for a repeating ket if no characters were matched in the group.
1166        This is the forcible breaking of infinite loops as implemented in Perl      This is the forcible breaking of infinite loops as implemented in Perl
1167        5.005. If there is an options reset, it will get obeyed in the normal      5.005. If there is an options reset, it will get obeyed in the normal
1168        course of events. */      course of events. */
1169    
1170        if (*ecode == OP_KET || eptr == saved_eptr)      if (*ecode == OP_KET || eptr == saved_eptr)
1171          {        {
1172          ecode += 1+LINK_SIZE;        ecode += 1+LINK_SIZE;
1173          break;        break;
1174          }        }
1175    
1176        /* 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
1177        preceding bracket, in the appropriate order. We need to reset any options      preceding bracket, in the appropriate order. The second "call" of match()
1178        that changed within the bracket before re-running it, so check the next      uses tail recursion, to avoid using another stack frame. We need to reset
1179        opcode. */      any options that changed within the bracket before re-running it, so
1180        check the next opcode. */
1181    
1182        if (ecode[1+LINK_SIZE] == OP_OPT)      if (ecode[1+LINK_SIZE] == OP_OPT)
1183          {        {
1184          ims = (ims & ~PCRE_IMS) | ecode[4];        ims = (ims & ~PCRE_IMS) | ecode[4];
1185          DPRINTF(("ims set to %02lx at group repeat\n", ims));        DPRINTF(("ims set to %02lx at group repeat\n", ims));
1186          }        }
1187    
1188        if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1189          {        {
1190          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);
1191          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1192          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        ecode = prev;
1193          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        flags = 0;
1194          }        goto TAIL_RECURSE;
       else  /* OP_KETRMAX */  
         {  
         RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);  
         if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
         RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);  
         if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
         }  
1195        }        }
1196      RRETURN(MATCH_NOMATCH);      else  /* OP_KETRMAX */
1197          {
1198          RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
1199          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1200          ecode += 1 + LINK_SIZE;
1201          flags = 0;
1202          goto TAIL_RECURSE;
1203          }
1204        /* Control never gets here */
1205    
1206      /* An alternation is the end of a branch; scan along to find the end of the      /* An alternation is the end of a branch; scan along to find the end of the
1207      bracketed group and go to there. */      bracketed group and go to there. */
# Line 1018  for (;;) Line 1210  for (;;)
1210      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1211      break;      break;
1212    
1213      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1214      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
1215      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
1216      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
1217      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1218    
1219      case OP_BRAZERO:      case OP_BRAZERO:
1220        {        {
1221        next = ecode+1;        next = ecode+1;
1222        RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
1223        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1224        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next,1); while (*next == OP_ALT);
1225        ecode = next + 1+LINK_SIZE;        ecode = next + 1 + LINK_SIZE;
1226        }        }
1227      break;      break;
1228    
1229      case OP_BRAMINZERO:      case OP_BRAMINZERO:
1230        {        {
1231        next = ecode+1;        next = ecode+1;
1232        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next, 1); while (*next == OP_ALT);
1233        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);  
1234        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1235        ecode++;        ecode++;
1236        }        }
1237      break;      break;
1238    
1239      /* End of a group, repeated or non-repeating. If we are at the end of      case OP_SKIPZERO:
1240      an assertion "group", stop matching and return MATCH_MATCH, but record the        {
1241      current high water mark for use by positive assertions. Do this also        next = ecode+1;
1242      for the "once" (not-backup up) groups. */        do next += GET(next,1); while (*next == OP_ALT);
1243          ecode = next + 1 + LINK_SIZE;
1244          }
1245        break;
1246    
1247        /* End of a group, repeated or non-repeating. */
1248    
1249      case OP_KET:      case OP_KET:
1250      case OP_KETRMIN:      case OP_KETRMIN:
1251      case OP_KETRMAX:      case OP_KETRMAX:
1252        {      prev = ecode - GET(ecode, 1);
       prev = ecode - GET(ecode, 1);  
       saved_eptr = eptrb->epb_saved_eptr;  
1253    
1254        /* Back up the stack of bracket start pointers. */      /* If this was a group that remembered the subject start, in order to break
1255        infinite repeats of empty string matches, retrieve the subject start from
1256        the chain. Otherwise, set it NULL. */
1257    
1258        eptrb = eptrb->epb_prev;      if (*prev >= OP_SBRA)
1259          {
1260        if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||        saved_eptr = eptrb->epb_saved_eptr;   /* Value at start of group */
1261            *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||        eptrb = eptrb->epb_prev;              /* Backup to previous group */
1262            *prev == OP_ONCE)        }
1263          {      else saved_eptr = NULL;
         md->end_match_ptr = eptr;      /* For ONCE */  
         md->end_offset_top = offset_top;  
         RRETURN(MATCH_MATCH);  
         }  
1264    
1265        /* In all other cases except a conditional group we have to check the      /* If we are at the end of an assertion group, stop matching and return
1266        group number back at the start and if necessary complete handling an      MATCH_MATCH, but record the current high water mark for use by positive
1267        extraction by setting the offsets and bumping the high water mark. */      assertions. Do this also for the "once" (atomic) groups. */
1268    
1269        if (*prev != OP_COND)      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
1270          {          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
1271          number = *prev - OP_BRA;          *prev == OP_ONCE)
1272          {
1273          md->end_match_ptr = eptr;      /* For ONCE */
1274          md->end_offset_top = offset_top;
1275          RRETURN(MATCH_MATCH);
1276          }
1277    
1278          /* For extended extraction brackets (large number), we have to fish out      /* For capturing groups we have to check the group number back at the start
1279          the number from a dummy opcode at the start. */      and if necessary complete handling an extraction by setting the offsets and
1280        bumping the high water mark. Note that whole-pattern recursion is coded as
1281        a recurse into group 0, so it won't be picked up here. Instead, we catch it
1282        when the OP_END is reached. Other recursion is handled here. */
1283    
1284          if (number > EXTRACT_BASIC_MAX) number = GET2(prev, 2+LINK_SIZE);      if (*prev == OP_CBRA || *prev == OP_SCBRA)
1285          offset = number << 1;        {
1286          number = GET2(prev, 1+LINK_SIZE);
1287          offset = number << 1;
1288    
1289  #ifdef DEBUG  #ifdef DEBUG
1290          printf("end bracket %d", number);        printf("end bracket %d", number);
1291          printf("\n");        printf("\n");
1292  #endif  #endif
1293    
1294          /* Test for a numbered group. This includes groups called as a result        md->capture_last = number;
1295          of recursion. Note that whole-pattern recursion is coded as a recurse        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1296          into group 0, so it won't be picked up here. Instead, we catch it when          {
1297          the OP_END is reached. */          md->offset_vector[offset] =
1298              md->offset_vector[md->offset_end - number];
1299          if (number > 0)          md->offset_vector[offset+1] = eptr - md->start_subject;
1300            {          if (offset_top <= offset) offset_top = offset + 2;
1301            md->capture_last = number;          }
           if (offset >= md->offset_max) md->offset_overflow = TRUE; else  
             {  
             md->offset_vector[offset] =  
               md->offset_vector[md->offset_end - number];  
             md->offset_vector[offset+1] = eptr - md->start_subject;  
             if (offset_top <= offset) offset_top = offset + 2;  
             }  
1302    
1303            /* Handle a recursively called group. Restore the offsets        /* Handle a recursively called group. Restore the offsets
1304            appropriately and continue from after the call. */        appropriately and continue from after the call. */
1305    
1306            if (md->recursive != NULL && md->recursive->group_num == number)        if (md->recursive != NULL && md->recursive->group_num == number)
1307              {          {
1308              recursion_info *rec = md->recursive;          recursion_info *rec = md->recursive;
1309              DPRINTF(("Recursion (%d) succeeded - continuing\n", number));          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1310              md->recursive = rec->prevrec;          md->recursive = rec->prevrec;
1311              md->start_match = rec->save_start;          mstart = rec->save_start;
1312              memcpy(md->offset_vector, rec->offset_save,          memcpy(md->offset_vector, rec->offset_save,
1313                rec->saved_max * sizeof(int));            rec->saved_max * sizeof(int));
1314              ecode = rec->after_call;          ecode = rec->after_call;
1315              ims = original_ims;          ims = original_ims;
1316              break;          break;
             }  
           }  
1317          }          }
1318          }
1319    
1320        /* 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
1321        the group. */      flags, in case they got changed during the group. */
1322    
1323        ims = original_ims;      ims = original_ims;
1324        DPRINTF(("ims reset to %02lx\n", ims));      DPRINTF(("ims reset to %02lx\n", ims));
1325    
1326        /* For a non-repeating ket, just continue at this level. This also      /* For a non-repeating ket, just continue at this level. This also
1327        happens for a repeating ket if no characters were matched in the group.      happens for a repeating ket if no characters were matched in the group.
1328        This is the forcible breaking of infinite loops as implemented in Perl      This is the forcible breaking of infinite loops as implemented in Perl
1329        5.005. If there is an options reset, it will get obeyed in the normal      5.005. If there is an options reset, it will get obeyed in the normal
1330        course of events. */      course of events. */
1331    
1332        if (*ecode == OP_KET || eptr == saved_eptr)      if (*ecode == OP_KET || eptr == saved_eptr)
1333          {        {
1334          ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1335          break;        break;
1336          }        }
1337    
1338        /* 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
1339        preceding bracket, in the appropriate order. */      preceding bracket, in the appropriate order. In the second case, we can use
1340        tail recursion to avoid using another stack frame, unless we have an
1341        unlimited repeat of a group that can match an empty string. */
1342    
1343        if (*ecode == OP_KETRMIN)      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
1344          {  
1345          RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);      if (*ecode == OP_KETRMIN)
1346          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        {
1347          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);
1348          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1349          }        if (flags != 0)    /* Could match an empty string */
       else  /* OP_KETRMAX */  
1350          {          {
1351          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);          RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
1352          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          RRETURN(rrc);
         RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);  
         if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
1353          }          }
1354          ecode = prev;
1355          goto TAIL_RECURSE;
1356        }        }
1357        else  /* OP_KETRMAX */
1358      RRETURN(MATCH_NOMATCH);        {
1359          RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
1360          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1361          ecode += 1 + LINK_SIZE;
1362          flags = 0;
1363          goto TAIL_RECURSE;
1364          }
1365        /* Control never gets here */
1366    
1367      /* Start of subject unless notbol, or after internal newline if multiline */      /* Start of subject unless notbol, or after internal newline if multiline */
1368    
# Line 1168  for (;;) Line 1370  for (;;)
1370      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);
1371      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1372        {        {
1373        if (eptr != md->start_subject && eptr[-1] != NEWLINE)        if (eptr != md->start_subject &&
1374              (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
1375          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
1376        ecode++;        ecode++;
1377        break;        break;
# Line 1189  for (;;) Line 1392  for (;;)
1392      ecode++;      ecode++;
1393      break;      break;
1394    
1395        /* Reset the start of match point */
1396    
1397        case OP_SET_SOM:
1398        mstart = eptr;
1399        ecode++;
1400        break;
1401    
1402      /* Assert before internal newline if multiline, or before a terminating      /* Assert before internal newline if multiline, or before a terminating
1403      newline unless endonly is set, else end of subject unless noteol is set. */      newline unless endonly is set, else end of subject unless noteol is set. */
1404    
# Line 1196  for (;;) Line 1406  for (;;)
1406      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1407        {        {
1408        if (eptr < md->end_subject)        if (eptr < md->end_subject)
1409          { if (*eptr != NEWLINE) RRETURN(MATCH_NOMATCH); }          { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }
1410        else        else
1411          { if (md->noteol) RRETURN(MATCH_NOMATCH); }          { if (md->noteol) RRETURN(MATCH_NOMATCH); }
1412        ecode++;        ecode++;
# Line 1207  for (;;) Line 1417  for (;;)
1417        if (md->noteol) RRETURN(MATCH_NOMATCH);        if (md->noteol) RRETURN(MATCH_NOMATCH);
1418        if (!md->endonly)        if (!md->endonly)
1419          {          {
1420          if (eptr < md->end_subject - 1 ||          if (eptr != md->end_subject &&
1421             (eptr == md->end_subject - 1 && *eptr != NEWLINE))              (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1422            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1423          ecode++;          ecode++;
1424          break;          break;
1425          }          }
1426        }        }
1427      /* ... else fall through */      /* ... else fall through for endonly */
1428    
1429      /* End of subject assertion (\z) */      /* End of subject assertion (\z) */
1430    
# Line 1226  for (;;) Line 1436  for (;;)
1436      /* End of subject or ending \n assertion (\Z) */      /* End of subject or ending \n assertion (\Z) */
1437    
1438      case OP_EODN:      case OP_EODN:
1439      if (eptr < md->end_subject - 1 ||      if (eptr != md->end_subject &&
1440         (eptr == md->end_subject - 1 && *eptr != NEWLINE)) RRETURN(MATCH_NOMATCH);          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1441          RRETURN(MATCH_NOMATCH);
1442      ecode++;      ecode++;
1443      break;      break;
1444    
# Line 1280  for (;;) Line 1491  for (;;)
1491      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1492    
1493      case OP_ANY:      case OP_ANY:
1494      if ((ims & PCRE_DOTALL) == 0 && eptr < md->end_subject && *eptr == NEWLINE)      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
1495        RRETURN(MATCH_NOMATCH);      /* Fall through */
1496    
1497        case OP_ALLANY:
1498      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);
1499  #ifdef SUPPORT_UTF8      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
     if (utf8)  
       while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
 #endif  
1500      ecode++;      ecode++;
1501      break;      break;
1502    
# Line 1376  for (;;) Line 1586  for (;;)
1586      ecode++;      ecode++;
1587      break;      break;
1588    
1589        case OP_ANYNL:
1590        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1591        GETCHARINCTEST(c, eptr);
1592        switch(c)
1593          {
1594          default: RRETURN(MATCH_NOMATCH);
1595          case 0x000d:
1596          if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1597          break;
1598    
1599          case 0x000a:
1600          break;
1601    
1602          case 0x000b:
1603          case 0x000c:
1604          case 0x0085:
1605          case 0x2028:
1606          case 0x2029:
1607          if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
1608          break;
1609          }
1610        ecode++;
1611        break;
1612    
1613        case OP_NOT_HSPACE:
1614        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1615        GETCHARINCTEST(c, eptr);
1616        switch(c)
1617          {
1618          default: break;
1619          case 0x09:      /* HT */
1620          case 0x20:      /* SPACE */
1621          case 0xa0:      /* NBSP */
1622          case 0x1680:    /* OGHAM SPACE MARK */
1623          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1624          case 0x2000:    /* EN QUAD */
1625          case 0x2001:    /* EM QUAD */
1626          case 0x2002:    /* EN SPACE */
1627          case 0x2003:    /* EM SPACE */
1628          case 0x2004:    /* THREE-PER-EM SPACE */
1629          case 0x2005:    /* FOUR-PER-EM SPACE */
1630          case 0x2006:    /* SIX-PER-EM SPACE */
1631          case 0x2007:    /* FIGURE SPACE */
1632          case 0x2008:    /* PUNCTUATION SPACE */
1633          case 0x2009:    /* THIN SPACE */
1634          case 0x200A:    /* HAIR SPACE */
1635          case 0x202f:    /* NARROW NO-BREAK SPACE */
1636          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1637          case 0x3000:    /* IDEOGRAPHIC SPACE */
1638          RRETURN(MATCH_NOMATCH);
1639          }
1640        ecode++;
1641        break;
1642    
1643        case OP_HSPACE:
1644        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1645        GETCHARINCTEST(c, eptr);
1646        switch(c)
1647          {
1648          default: RRETURN(MATCH_NOMATCH);
1649          case 0x09:      /* HT */
1650          case 0x20:      /* SPACE */
1651          case 0xa0:      /* NBSP */
1652          case 0x1680:    /* OGHAM SPACE MARK */
1653          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1654          case 0x2000:    /* EN QUAD */
1655          case 0x2001:    /* EM QUAD */
1656          case 0x2002:    /* EN SPACE */
1657          case 0x2003:    /* EM SPACE */
1658          case 0x2004:    /* THREE-PER-EM SPACE */
1659          case 0x2005:    /* FOUR-PER-EM SPACE */
1660          case 0x2006:    /* SIX-PER-EM SPACE */
1661          case 0x2007:    /* FIGURE SPACE */
1662          case 0x2008:    /* PUNCTUATION SPACE */
1663          case 0x2009:    /* THIN SPACE */
1664          case 0x200A:    /* HAIR SPACE */
1665          case 0x202f:    /* NARROW NO-BREAK SPACE */
1666          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1667          case 0x3000:    /* IDEOGRAPHIC SPACE */
1668          break;
1669          }
1670        ecode++;
1671        break;
1672    
1673        case OP_NOT_VSPACE:
1674        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1675        GETCHARINCTEST(c, eptr);
1676        switch(c)
1677          {
1678          default: break;
1679          case 0x0a:      /* LF */
1680          case 0x0b:      /* VT */
1681          case 0x0c:      /* FF */
1682          case 0x0d:      /* CR */
1683          case 0x85:      /* NEL */
1684          case 0x2028:    /* LINE SEPARATOR */
1685          case 0x2029:    /* PARAGRAPH SEPARATOR */
1686          RRETURN(MATCH_NOMATCH);
1687          }
1688        ecode++;
1689        break;
1690    
1691        case OP_VSPACE:
1692        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1693        GETCHARINCTEST(c, eptr);
1694        switch(c)
1695          {
1696          default: RRETURN(MATCH_NOMATCH);
1697          case 0x0a:      /* LF */
1698          case 0x0b:      /* VT */
1699          case 0x0c:      /* FF */
1700          case 0x0d:      /* CR */
1701          case 0x85:      /* NEL */
1702          case 0x2028:    /* LINE SEPARATOR */
1703          case 0x2029:    /* PARAGRAPH SEPARATOR */
1704          break;
1705          }
1706        ecode++;
1707        break;
1708    
1709  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
1710      /* Check the next character by Unicode property. We will get here only      /* Check the next character by Unicode property. We will get here only
1711      if the support is in the binary; otherwise a compile-time error occurs. */      if the support is in the binary; otherwise a compile-time error occurs. */
# Line 1385  for (;;) Line 1715  for (;;)
1715      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1716      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1717        {        {
1718        int chartype, script;        const ucd_record *prop = GET_UCD(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1719    
1720        switch(ecode[1])        switch(ecode[1])
1721          {          {
# Line 1395  for (;;) Line 1724  for (;;)
1724          break;          break;
1725    
1726          case PT_LAMP:          case PT_LAMP:
1727          if ((chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
1728               chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
1729               chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
1730            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1731           break;           break;
1732    
1733          case PT_GC:          case PT_GC:
1734          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
1735            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1736          break;          break;
1737    
1738          case PT_PC:          case PT_PC:
1739          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
1740            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1741          break;          break;
1742    
1743          case PT_SC:          case PT_SC:
1744          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
1745            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1746          break;          break;
1747    
1748          default:          default:
1749          RRETURN(PCRE_ERROR_INTERNAL);          RRETURN(PCRE_ERROR_INTERNAL);
         break;  
1750          }          }
1751    
1752        ecode += 3;        ecode += 3;
# Line 1432  for (;;) Line 1760  for (;;)
1760      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1761      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1762        {        {
1763        int chartype, script;        int category = UCD_CATEGORY(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1764        if (category == ucp_M) RRETURN(MATCH_NOMATCH);        if (category == ucp_M) RRETURN(MATCH_NOMATCH);
1765        while (eptr < md->end_subject)        while (eptr < md->end_subject)
1766          {          {
# Line 1442  for (;;) Line 1769  for (;;)
1769            {            {
1770            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
1771            }            }
1772          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
1773          if (category != ucp_M) break;          if (category != ucp_M) break;
1774          eptr += len;          eptr += len;
1775          }          }
# Line 1463  for (;;) Line 1790  for (;;)
1790      case OP_REF:      case OP_REF:
1791        {        {
1792        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
1793        ecode += 3;                                 /* Advance past item */        ecode += 3;
1794    
1795          /* If the reference is unset, there are two possibilities:
1796    
1797        /* 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
1798        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
1799        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
1800        minima. */        quantifiers with zero minima.
1801    
1802        length = (offset >= offset_top || md->offset_vector[offset] < 0)?        (b) If the JavaScript compatibility flag is set, set the length to zero
1803          md->end_subject - eptr + 1 :        so that the back reference matches an empty string.
1804          md->offset_vector[offset+1] - md->offset_vector[offset];  
1805          Otherwise, set the length to the length of what was matched by the
1806          referenced subpattern. */
1807    
1808          if (offset >= offset_top || md->offset_vector[offset] < 0)
1809            length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
1810          else
1811            length = md->offset_vector[offset+1] - md->offset_vector[offset];
1812    
1813        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
1814    
# Line 1532  for (;;) Line 1868  for (;;)
1868          {          {
1869          for (fi = min;; fi++)          for (fi = min;; fi++)
1870            {            {
1871            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
1872            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1873            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max || !match_ref(offset, eptr, length, md, ims))
1874              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
# Line 1553  for (;;) Line 1889  for (;;)
1889            }            }
1890          while (eptr >= pp)          while (eptr >= pp)
1891            {            {
1892            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
1893            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1894            eptr -= length;            eptr -= length;
1895            }            }
# Line 1658  for (;;) Line 1994  for (;;)
1994            {            {
1995            for (fi = min;; fi++)            for (fi = min;; fi++)
1996              {              {
1997              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
1998              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1999              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2000              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
# Line 1678  for (;;) Line 2014  for (;;)
2014            {            {
2015            for (fi = min;; fi++)            for (fi = min;; fi++)
2016              {              {
2017              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
2018              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2019              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2020              c = *eptr++;              c = *eptr++;
# Line 1715  for (;;) Line 2051  for (;;)
2051              }              }
2052            for (;;)            for (;;)
2053              {              {
2054              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
2055              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2056              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2057              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 1734  for (;;) Line 2070  for (;;)
2070              }              }
2071            while (eptr >= pp)            while (eptr >= pp)
2072              {              {
2073              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
2074              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2075              eptr--;              eptr--;
2076              }              }
# Line 1747  for (;;) Line 2083  for (;;)
2083    
2084    
2085      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2086      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
2087        mode, because Unicode properties are supported in non-UTF-8 mode. */
2088    
2089  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2090      case OP_XCLASS:      case OP_XCLASS:
# Line 1789  for (;;) Line 2126  for (;;)
2126        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2127          {          {
2128          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2129          GETCHARINC(c, eptr);          GETCHARINCTEST(c, eptr);
2130          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2131          }          }
2132    
# Line 1805  for (;;) Line 2142  for (;;)
2142          {          {
2143          for (fi = min;; fi++)          for (fi = min;; fi++)
2144            {            {
2145            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2146            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2147            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2148            GETCHARINC(c, eptr);            GETCHARINCTEST(c, eptr);
2149            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2150            }            }
2151          /* Control never gets here */          /* Control never gets here */
# Line 1823  for (;;) Line 2160  for (;;)
2160            {            {
2161            int len = 1;            int len = 1;
2162            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
2163            GETCHARLEN(c, eptr, len);            GETCHARLENTEST(c, eptr, len);
2164            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2165            eptr += len;            eptr += len;
2166            }            }
2167          for(;;)          for(;;)
2168            {            {
2169            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2170            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2171            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2172            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2173            }            }
2174          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2175          }          }
# Line 1888  for (;;) Line 2225  for (;;)
2225    
2226        else        else
2227          {          {
2228          int dc;          unsigned int dc;
2229          GETCHARINC(dc, eptr);          GETCHARINC(dc, eptr);
2230          ecode += length;          ecode += length;
2231    
# Line 1898  for (;;) Line 2235  for (;;)
2235          if (fc != dc)          if (fc != dc)
2236            {            {
2237  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2238            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2239  #endif  #endif
2240              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2241            }            }
# Line 1915  for (;;) Line 2252  for (;;)
2252        }        }
2253      break;      break;
2254    
2255      /* Match a single character repeatedly; different opcodes share code. */      /* Match a single character repeatedly. */
2256    
2257      case OP_EXACT:      case OP_EXACT:
2258      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
2259      ecode += 3;      ecode += 3;
2260      goto REPEATCHAR;      goto REPEATCHAR;
2261    
2262        case OP_POSUPTO:
2263        possessive = TRUE;
2264        /* Fall through */
2265    
2266      case OP_UPTO:      case OP_UPTO:
2267      case OP_MINUPTO:      case OP_MINUPTO:
2268      min = 0;      min = 0;
# Line 1930  for (;;) Line 2271  for (;;)
2271      ecode += 3;      ecode += 3;
2272      goto REPEATCHAR;      goto REPEATCHAR;
2273    
2274        case OP_POSSTAR:
2275        possessive = TRUE;
2276        min = 0;
2277        max = INT_MAX;
2278        ecode++;
2279        goto REPEATCHAR;
2280    
2281        case OP_POSPLUS:
2282        possessive = TRUE;
2283        min = 1;
2284        max = INT_MAX;
2285        ecode++;
2286        goto REPEATCHAR;
2287    
2288        case OP_POSQUERY:
2289        possessive = TRUE;
2290        min = 0;
2291        max = 1;
2292        ecode++;
2293        goto REPEATCHAR;
2294    
2295      case OP_STAR:      case OP_STAR:
2296      case OP_MINSTAR:      case OP_MINSTAR:
2297      case OP_PLUS:      case OP_PLUS:
# Line 1961  for (;;) Line 2323  for (;;)
2323    
2324        if (length > 1)        if (length > 1)
2325          {          {
         int oclength = 0;  
         uschar occhars[8];  
   
2326  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2327          int othercase;          unsigned int othercase;
2328          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2329              (othercase = _pcre_ucp_othercase(fc)) >= 0 &&              (othercase = UCD_OTHERCASE(fc)) != fc)
              othercase >= 0)  
2330            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2331            else oclength = 0;
2332  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2333    
2334          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2335            {            {
2336            if (memcmp(eptr, charptr, length) == 0) eptr += length;            if (memcmp(eptr, charptr, length) == 0) eptr += length;
2337    #ifdef SUPPORT_UCP
2338            /* Need braces because of following else */            /* Need braces because of following else */
2339            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }
2340            else            else
# Line 1982  for (;;) Line 2342  for (;;)
2342              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);
2343              eptr += oclength;              eptr += oclength;
2344              }              }
2345    #else   /* without SUPPORT_UCP */
2346              else { RRETURN(MATCH_NOMATCH); }
2347    #endif  /* SUPPORT_UCP */
2348            }            }
2349    
2350          if (min == max) continue;          if (min == max) continue;
# Line 1990  for (;;) Line 2353  for (;;)
2353            {            {
2354            for (fi = min;; fi++)            for (fi = min;; fi++)
2355              {              {
2356              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2357              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2358              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2359              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (memcmp(eptr, charptr, length) == 0) eptr += length;
2360    #ifdef SUPPORT_UCP
2361              /* Need braces because of following else */              /* Need braces because of following else */
2362              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }
2363              else              else
# Line 2001  for (;;) Line 2365  for (;;)
2365                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);
2366                eptr += oclength;                eptr += oclength;
2367                }                }
2368    #else   /* without SUPPORT_UCP */
2369                else { RRETURN (MATCH_NOMATCH); }
2370    #endif  /* SUPPORT_UCP */
2371              }              }
2372            /* Control never gets here */            /* Control never gets here */
2373            }            }
2374          else  
2375            else  /* Maximize */
2376            {            {
2377            pp = eptr;            pp = eptr;
2378            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2379              {              {
2380              if (eptr > md->end_subject - length) break;              if (eptr > md->end_subject - length) break;
2381              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (memcmp(eptr, charptr, length) == 0) eptr += length;
2382    #ifdef SUPPORT_UCP
2383              else if (oclength == 0) break;              else if (oclength == 0) break;
2384              else              else
2385                {                {
2386                if (memcmp(eptr, occhars, oclength) != 0) break;                if (memcmp(eptr, occhars, oclength) != 0) break;
2387                eptr += oclength;                eptr += oclength;
2388                }                }
2389    #else   /* without SUPPORT_UCP */
2390                else break;
2391    #endif  /* SUPPORT_UCP */
2392              }              }
2393            while (eptr >= pp)  
2394              if (possessive) continue;
2395              for(;;)
2396             {             {
2397             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2398             if (rrc != MATCH_NOMATCH) RRETURN(rrc);             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2399               if (eptr == pp) RRETURN(MATCH_NOMATCH);
2400    #ifdef SUPPORT_UCP
2401               eptr--;
2402               BACKCHAR(eptr);
2403    #else   /* without SUPPORT_UCP */
2404             eptr -= length;             eptr -= length;
2405    #endif  /* SUPPORT_UCP */
2406             }             }
           RRETURN(MATCH_NOMATCH);  
2407            }            }
2408          /* Control never gets here */          /* Control never gets here */
2409          }          }
# Line 2064  for (;;) Line 2443  for (;;)
2443          {          {
2444          for (fi = min;; fi++)          for (fi = min;; fi++)
2445            {            {
2446            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2447            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2448            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max || eptr >= md->end_subject ||
2449                fc != md->lcc[*eptr++])                fc != md->lcc[*eptr++])
# Line 2072  for (;;) Line 2451  for (;;)
2451            }            }
2452          /* Control never gets here */          /* Control never gets here */
2453          }          }
2454        else        else  /* Maximize */
2455          {          {
2456          pp = eptr;          pp = eptr;
2457          for (i = min; i < max; i++)          for (i = min; i < max; i++)
# Line 2080  for (;;) Line 2459  for (;;)
2459            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;
2460            eptr++;            eptr++;
2461            }            }
2462            if (possessive) continue;
2463          while (eptr >= pp)          while (eptr >= pp)
2464            {            {
2465            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
2466            eptr--;            eptr--;
2467            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2468            }            }
# Line 2101  for (;;) Line 2481  for (;;)
2481          {          {
2482          for (fi = min;; fi++)          for (fi = min;; fi++)
2483            {            {
2484            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
2485            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2486            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)
2487              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2488            }            }
2489          /* Control never gets here */          /* Control never gets here */
2490          }          }
2491        else        else  /* Maximize */
2492          {          {
2493          pp = eptr;          pp = eptr;
2494          for (i = min; i < max; i++)          for (i = min; i < max; i++)
# Line 2116  for (;;) Line 2496  for (;;)
2496            if (eptr >= md->end_subject || fc != *eptr) break;            if (eptr >= md->end_subject || fc != *eptr) break;
2497            eptr++;            eptr++;
2498            }            }
2499            if (possessive) continue;
2500          while (eptr >= pp)          while (eptr >= pp)
2501            {            {
2502            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
2503            eptr--;            eptr--;
2504            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2505            }            }
# Line 2168  for (;;) Line 2549  for (;;)
2549      ecode += 3;      ecode += 3;
2550      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
2551    
2552        case OP_NOTPOSSTAR:
2553        possessive = TRUE;
2554        min = 0;
2555        max = INT_MAX;
2556        ecode++;
2557        goto REPEATNOTCHAR;
2558    
2559        case OP_NOTPOSPLUS:
2560        possessive = TRUE;
2561        min = 1;
2562        max = INT_MAX;
2563        ecode++;
2564        goto REPEATNOTCHAR;
2565    
2566        case OP_NOTPOSQUERY:
2567        possessive = TRUE;
2568        min = 0;
2569        max = 1;
2570        ecode++;
2571        goto REPEATNOTCHAR;
2572    
2573        case OP_NOTPOSUPTO:
2574        possessive = TRUE;
2575        min = 0;
2576        max = GET2(ecode, 1);
2577        ecode += 3;
2578        goto REPEATNOTCHAR;
2579    
2580      case OP_NOTSTAR:      case OP_NOTSTAR:
2581      case OP_NOTMINSTAR:      case OP_NOTMINSTAR:
2582      case OP_NOTPLUS:      case OP_NOTPLUS:
# Line 2207  for (;;) Line 2616  for (;;)
2616        /* UTF-8 mode */        /* UTF-8 mode */
2617        if (utf8)        if (utf8)
2618          {          {
2619          register int d;          register unsigned int d;
2620          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2621            {            {
2622            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
# Line 2232  for (;;) Line 2641  for (;;)
2641          /* UTF-8 mode */          /* UTF-8 mode */
2642          if (utf8)          if (utf8)
2643            {            {
2644            register int d;            register unsigned int d;
2645            for (fi = min;; fi++)            for (fi = min;; fi++)
2646              {              {
2647              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
2648              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2649                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2650              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2651              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
2652              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
2653                RRETURN(MATCH_NOMATCH);  
2654              }              }
2655            }            }
2656          else          else
# Line 2249  for (;;) Line 2659  for (;;)
2659            {            {
2660            for (fi = min;; fi++)            for (fi = min;; fi++)
2661              {              {
2662              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
2663              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2664              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])
2665                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
# Line 2268  for (;;) Line 2678  for (;;)
2678          /* UTF-8 mode */          /* UTF-8 mode */
2679          if (utf8)          if (utf8)
2680            {            {
2681            register int d;            register unsigned int d;
2682            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2683              {              {
2684              int len = 1;              int len = 1;
# Line 2278  for (;;) Line 2688  for (;;)
2688              if (fc == d) break;              if (fc == d) break;
2689              eptr += len;              eptr += len;
2690              }              }
2691            for(;;)          if (possessive) continue;
2692            for(;;)
2693              {              {
2694              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
2695              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2696              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2697              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2295  for (;;) Line 2706  for (;;)
2706              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;
2707              eptr++;              eptr++;
2708              }              }
2709              if (possessive) continue;
2710            while (eptr >= pp)            while (eptr >= pp)
2711              {              {
2712              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
2713              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2714              eptr--;              eptr--;
2715              }              }
# Line 2316  for (;;) Line 2728  for (;;)
2728        /* UTF-8 mode */        /* UTF-8 mode */
2729        if (utf8)        if (utf8)
2730          {          {
2731          register int d;          register unsigned int d;
2732          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2733            {            {
2734            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
# Line 2339  for (;;) Line 2751  for (;;)
2751          /* UTF-8 mode */          /* UTF-8 mode */
2752          if (utf8)          if (utf8)
2753            {            {
2754            register int d;            register unsigned int d;
2755            for (fi = min;; fi++)            for (fi = min;; fi++)
2756              {              {
2757              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
2758              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2759                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2760              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2761              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
2762              }              }
2763            }            }
2764          else          else
# Line 2355  for (;;) Line 2767  for (;;)
2767            {            {
2768            for (fi = min;; fi++)            for (fi = min;; fi++)
2769              {              {
2770              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
2771              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2772              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)
2773                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
# Line 2374  for (;;) Line 2786  for (;;)
2786          /* UTF-8 mode */          /* UTF-8 mode */
2787          if (utf8)          if (utf8)
2788            {            {
2789            register int d;            register unsigned int d;
2790            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2791              {              {
2792              int len = 1;              int len = 1;
# Line 2383  for (;;) Line 2795  for (;;)
2795              if (fc == d) break;              if (fc == d) break;
2796              eptr += len;              eptr += len;
2797              }              }
2798              if (possessive) continue;
2799            for(;;)            for(;;)
2800              {              {
2801              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
2802              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2803              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2804              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2400  for (;;) Line 2813  for (;;)
2813              if (eptr >= md->end_subject || fc == *eptr) break;              if (eptr >= md->end_subject || fc == *eptr) break;
2814              eptr++;              eptr++;
2815              }              }
2816              if (possessive) continue;
2817            while (eptr >= pp)            while (eptr >= pp)
2818              {              {
2819              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
2820              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2821              eptr--;              eptr--;
2822              }              }
# Line 2431  for (;;) Line 2845  for (;;)
2845      ecode += 3;      ecode += 3;
2846      goto REPEATTYPE;      goto REPEATTYPE;
2847    
2848        case OP_TYPEPOSSTAR:
2849        possessive = TRUE;
2850        min = 0;
2851        max = INT_MAX;
2852        ecode++;
2853        goto REPEATTYPE;
2854    
2855        case OP_TYPEPOSPLUS:
2856        possessive = TRUE;
2857        min = 1;
2858        max = INT_MAX;
2859        ecode++;
2860        goto REPEATTYPE;
2861    
2862        case OP_TYPEPOSQUERY:
2863        possessive = TRUE;
2864        min = 0;
2865        max = 1;
2866        ecode++;
2867        goto REPEATTYPE;
2868    
2869        case OP_TYPEPOSUPTO:
2870        possessive = TRUE;
2871        min = 0;
2872        max = GET2(ecode, 1);
2873        ecode += 3;
2874        goto REPEATTYPE;
2875    
2876      case OP_TYPESTAR:      case OP_TYPESTAR:
2877      case OP_TYPEMINSTAR:      case OP_TYPEMINSTAR:
2878      case OP_TYPEPLUS:      case OP_TYPEPLUS:
# Line 2481  for (;;) Line 2923  for (;;)
2923            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2924              {              {
2925              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2926              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2927              }              }
2928            break;            break;
2929    
# Line 2489  for (;;) Line 2931  for (;;)
2931            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2932              {              {
2933              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2934              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2935              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
2936              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
2937                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
2938                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2502  for (;;) Line 2944  for (;;)
2944            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2945              {              {
2946              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2947              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2948              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
2949              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
2950                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2951              }              }
# Line 2513  for (;;) Line 2955  for (;;)
2955            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2956              {              {
2957              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2958              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2959              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
2960              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
2961                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2962              }              }
# Line 2524  for (;;) Line 2966  for (;;)
2966            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2967              {              {
2968              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2969              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2970              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
2971              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
2972                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2973              }              }
# Line 2533  for (;;) Line 2975  for (;;)
2975    
2976            default:            default:
2977            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
           break;  
2978            }            }
2979          }          }
2980    
# Line 2545  for (;;) Line 2986  for (;;)
2986          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2987            {            {
2988            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
2989            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
2990            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
2991            while (eptr < md->end_subject)            while (eptr < md->end_subject)
2992              {              {
# Line 2554  for (;;) Line 2995  for (;;)
2995                {                {
2996                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
2997                }                }
2998              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
2999              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3000              eptr += len;              eptr += len;
3001              }              }
# Line 2572  for (;;) Line 3013  for (;;)
3013          case OP_ANY:          case OP_ANY:
3014          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3015            {            {
3016            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject || IS_NEWLINE(eptr))
              (*eptr++ == NEWLINE && (ims & PCRE_DOTALL) == 0))  
3017              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3018              eptr++;
3019              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3020              }
3021            break;
3022    
3023            case OP_ALLANY:
3024            for (i = 1; i <= min; i++)
3025              {
3026              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3027              eptr++;
3028            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3029            }            }
3030          break;          break;
# Line 2583  for (;;) Line 3033  for (;;)
3033          eptr += min;          eptr += min;
3034          break;          break;
3035    
3036            case OP_ANYNL:
3037            for (i = 1; i <= min; i++)
3038              {
3039              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3040              GETCHARINC(c, eptr);
3041              switch(c)
3042                {
3043                default: RRETURN(MATCH_NOMATCH);
3044                case 0x000d:
3045                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3046                break;
3047    
3048                case 0x000a:
3049                break;
3050    
3051                case 0x000b:
3052                case 0x000c:
3053                case 0x0085:
3054                case 0x2028:
3055                case 0x2029:
3056                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3057                break;
3058                }
3059              }
3060            break;
3061    
3062            case OP_NOT_HSPACE:
3063            for (i = 1; i <= min; i++)
3064              {
3065              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3066              GETCHARINC(c, eptr);
3067              switch(c)
3068                {
3069                default: break;
3070                case 0x09:      /* HT */
3071                case 0x20:      /* SPACE */
3072                case 0xa0:      /* NBSP */
3073                case 0x1680:    /* OGHAM SPACE MARK */
3074                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3075                case 0x2000:    /* EN QUAD */
3076                case 0x2001:    /* EM QUAD */
3077                case 0x2002:    /* EN SPACE */
3078                case 0x2003:    /* EM SPACE */
3079                case 0x2004:    /* THREE-PER-EM SPACE */
3080                case 0x2005:    /* FOUR-PER-EM SPACE */
3081                case 0x2006:    /* SIX-PER-EM SPACE */
3082                case 0x2007:    /* FIGURE SPACE */
3083                case 0x2008:    /* PUNCTUATION SPACE */
3084                case 0x2009:    /* THIN SPACE */
3085                case 0x200A:    /* HAIR SPACE */
3086                case 0x202f:    /* NARROW NO-BREAK SPACE */
3087                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3088                case 0x3000:    /* IDEOGRAPHIC SPACE */
3089                RRETURN(MATCH_NOMATCH);
3090                }
3091              }
3092            break;
3093    
3094            case OP_HSPACE:
3095            for (i = 1; i <= min; i++)
3096              {
3097              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3098              GETCHARINC(c, eptr);
3099              switch(c)
3100                {
3101                default: RRETURN(MATCH_NOMATCH);
3102                case 0x09:      /* HT */
3103                case 0x20:      /* SPACE */
3104                case 0xa0:      /* NBSP */
3105                case 0x1680:    /* OGHAM SPACE MARK */
3106                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3107                case 0x2000:    /* EN QUAD */
3108                case 0x2001:    /* EM QUAD */
3109                case 0x2002:    /* EN SPACE */
3110                case 0x2003:    /* EM SPACE */
3111                case 0x2004:    /* THREE-PER-EM SPACE */
3112                case 0x2005:    /* FOUR-PER-EM SPACE */
3113                case 0x2006:    /* SIX-PER-EM SPACE */
3114                case 0x2007:    /* FIGURE SPACE */
3115                case 0x2008:    /* PUNCTUATION SPACE */
3116                case 0x2009:    /* THIN SPACE */
3117                case 0x200A:    /* HAIR SPACE */
3118                case 0x202f:    /* NARROW NO-BREAK SPACE */
3119                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3120                case 0x3000:    /* IDEOGRAPHIC SPACE */
3121                break;
3122                }
3123              }
3124            break;
3125    
3126            case OP_NOT_VSPACE:
3127            for (i = 1; i <= min; i++)
3128              {
3129              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3130              GETCHARINC(c, eptr);
3131              switch(c)
3132                {
3133                default: break;
3134                case 0x0a:      /* LF */
3135                case 0x0b:      /* VT */
3136                case 0x0c:      /* FF */
3137                case 0x0d:      /* CR */
3138                case 0x85:      /* NEL */
3139                case 0x2028:    /* LINE SEPARATOR */
3140                case 0x2029:    /* PARAGRAPH SEPARATOR */
3141                RRETURN(MATCH_NOMATCH);
3142                }
3143              }
3144            break;
3145    
3146            case OP_VSPACE:
3147            for (i = 1; i <= min; i++)
3148              {
3149              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3150              GETCHARINC(c, eptr);
3151              switch(c)
3152                {
3153                default: RRETURN(MATCH_NOMATCH);
3154                case 0x0a:      /* LF */
3155                case 0x0b:      /* VT */
3156                case 0x0c:      /* FF */
3157                case 0x0d:      /* CR */
3158                case 0x85:      /* NEL */
3159                case 0x2028:    /* LINE SEPARATOR */
3160                case 0x2029:    /* PARAGRAPH SEPARATOR */
3161                break;
3162                }
3163              }
3164            break;
3165    
3166          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3167          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3168            {            {
# Line 2607  for (;;) Line 3187  for (;;)
3187          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3188            {            {
3189            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3190               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0))
3191              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3192            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3193            }            }
3194          break;          break;
3195    
# Line 2627  for (;;) Line 3207  for (;;)
3207          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3208            {            {
3209            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3210               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))
3211              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3212            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3213            }            }
3214          break;          break;
3215    
# Line 2651  for (;;) Line 3231  for (;;)
3231  #endif     /* SUPPORT_UTF8 */  #endif     /* SUPPORT_UTF8 */
3232    
3233        /* Code for the non-UTF-8 case for minimum matching of operators other        /* Code for the non-UTF-8 case for minimum matching of operators other
3234        than OP_PROP and OP_NOTPROP. */        than OP_PROP and OP_NOTPROP. We can assume that there are the minimum
3235          number of bytes present, as this was tested above. */
3236    
3237        switch(ctype)        switch(ctype)
3238          {          {
3239          case OP_ANY:          case OP_ANY:
3240          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3241            {            {
3242            for (i = 1; i <= min; i++)            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3243              if (*eptr++ == NEWLINE) RRETURN(MATCH_NOMATCH);            eptr++;
3244            }            }
3245          else eptr += min;          break;
3246    
3247            case OP_ALLANY:
3248            eptr += min;
3249          break;          break;
3250    
3251          case OP_ANYBYTE:          case OP_ANYBYTE:
3252          eptr += min;          eptr += min;
3253          break;          break;
3254    
3255            /* Because of the CRLF case, we can't assume the minimum number of
3256            bytes are present in this case. */
3257    
3258            case OP_ANYNL:
3259            for (i = 1; i <= min; i++)
3260              {
3261              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3262              switch(*eptr++)
3263                {
3264                default: RRETURN(MATCH_NOMATCH);
3265                case 0x000d:
3266                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3267                break;
3268                case 0x000a:
3269                break;
3270    
3271                case 0x000b:
3272                case 0x000c:
3273                case 0x0085:
3274                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3275                break;
3276                }
3277              }
3278            break;
3279    
3280            case OP_NOT_HSPACE:
3281            for (i = 1; i <= min; i++)
3282              {
3283              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3284              switch(*eptr++)
3285                {
3286                default: break;
3287                case 0x09:      /* HT */
3288                case 0x20:      /* SPACE */
3289                case 0xa0:      /* NBSP */
3290                RRETURN(MATCH_NOMATCH);
3291                }
3292              }
3293            break;
3294    
3295            case OP_HSPACE:
3296            for (i = 1; i <= min; i++)
3297              {
3298              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3299              switch(*eptr++)
3300                {
3301                default: RRETURN(MATCH_NOMATCH);
3302                case 0x09:      /* HT */
3303                case 0x20:      /* SPACE */
3304                case 0xa0:      /* NBSP */
3305                break;
3306                }
3307              }
3308            break;
3309    
3310            case OP_NOT_VSPACE:
3311            for (i = 1; i <= min; i++)
3312              {
3313              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3314              switch(*eptr++)
3315                {
3316                default: break;
3317                case 0x0a:      /* LF */
3318                case 0x0b:      /* VT */
3319                case 0x0c:      /* FF */
3320                case 0x0d:      /* CR */
3321                case 0x85:      /* NEL */
3322                RRETURN(MATCH_NOMATCH);
3323                }
3324              }
3325            break;
3326    
3327            case OP_VSPACE:
3328            for (i = 1; i <= min; i++)
3329              {
3330              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3331              switch(*eptr++)
3332                {
3333                default: RRETURN(MATCH_NOMATCH);
3334                case 0x0a:      /* LF */
3335                case 0x0b:      /* VT */
3336                case 0x0c:      /* FF */
3337                case 0x0d:      /* CR */
3338                case 0x85:      /* NEL */
3339                break;
3340                }
3341              }
3342            break;
3343    
3344          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3345          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3346            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
# Line 2723  for (;;) Line 3396  for (;;)
3396            case PT_ANY:            case PT_ANY:
3397            for (fi = min;; fi++)            for (fi = min;; fi++)
3398              {              {
3399              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
3400              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3401              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3402              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3403              if (prop_fail_result) RRETURN(MATCH_NOMATCH);              if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3404              }              }
3405            break;            /* Control never gets here */
3406    
3407            case PT_LAMP:            case PT_LAMP:
3408            for (fi = min;; fi++)            for (fi = min;; fi++)
3409              {              {
3410              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
3411              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3412              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3413              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3414              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3415              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3416                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3417                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
3418                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3419              }              }
3420            break;            /* Control never gets here */
3421    
3422            case PT_GC:            case PT_GC:
3423            for (fi = min;; fi++)            for (fi = min;; fi++)
3424              {              {
3425              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
3426              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3427              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3428              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3429              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3430              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3431                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3432              }              }
3433            break;            /* Control never gets here */
3434    
3435            case PT_PC:            case PT_PC:
3436            for (fi = min;; fi++)            for (fi = min;; fi++)
3437              {              {
3438              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
3439              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3440              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3441              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3442              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3443              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3444                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3445              }              }
3446            break;            /* Control never gets here */
3447    
3448            case PT_SC:            case PT_SC:
3449            for (fi = min;; fi++)            for (fi = min;; fi++)
3450              {              {
3451              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
3452              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3453              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3454              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3455              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3456              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3457                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3458              }              }
3459            break;            /* Control never gets here */
3460    
3461            default:            default:
3462            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
           break;  
3463            }            }
3464          }          }
3465    
# Line 2798  for (;;) Line 3470  for (;;)
3470          {          {
3471          for (fi = min;; fi++)          for (fi = min;; fi++)
3472            {            {
3473            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
3474            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3475            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3476            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3477            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3478            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3479            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3480              {              {
# Line 2811  for (;;) Line 3483  for (;;)
3483                {                {
3484                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3485                }                }
3486              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3487              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3488              eptr += len;              eptr += len;
3489              }              }
# Line 2827  for (;;) Line 3499  for (;;)
3499          {          {
3500          for (fi = min;; fi++)          for (fi = min;; fi++)
3501            {            {
3502            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
3503            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3504            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject ||
3505                   (ctype == OP_ANY && IS_NEWLINE(eptr)))
3506                RRETURN(MATCH_NOMATCH);
3507    
3508            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3509            switch(ctype)            switch(ctype)
3510              {              {
3511              case OP_ANY:              case OP_ANY:        /* This is the non-NL case */
3512              if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) RRETURN(MATCH_NOMATCH);              case OP_ALLANY:
3513                case OP_ANYBYTE:
3514              break;              break;
3515    
3516              case OP_ANYBYTE:              case OP_ANYNL:
3517                switch(c)
3518                  {
3519                  default: RRETURN(MATCH_NOMATCH);
3520                  case 0x000d:
3521                  if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3522                  break;
3523                  case 0x000a:
3524                  break;
3525    
3526                  case 0x000b:
3527                  case 0x000c:
3528                  case 0x0085:
3529                  case 0x2028:
3530                  case 0x2029:
3531                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3532                  break;
3533                  }
3534                break;
3535    
3536                case OP_NOT_HSPACE:
3537                switch(c)
3538                  {
3539                  default: break;
3540                  case 0x09:      /* HT */
3541                  case 0x20:      /* SPACE */
3542                  case 0xa0:      /* NBSP */
3543                  case 0x1680:    /* OGHAM SPACE MARK */
3544                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3545                  case 0x2000:    /* EN QUAD */
3546                  case 0x2001:    /* EM QUAD */
3547                  case 0x2002:    /* EN SPACE */
3548                  case 0x2003:    /* EM SPACE */
3549                  case 0x2004:    /* THREE-PER-EM SPACE */
3550                  case 0x2005:    /* FOUR-PER-EM SPACE */
3551                  case 0x2006:    /* SIX-PER-EM SPACE */
3552                  case 0x2007:    /* FIGURE SPACE */
3553                  case 0x2008:    /* PUNCTUATION SPACE */
3554                  case 0x2009:    /* THIN SPACE */
3555                  case 0x200A:    /* HAIR SPACE */
3556                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3557                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3558                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3559                  RRETURN(MATCH_NOMATCH);
3560                  }
3561                break;
3562    
3563                case OP_HSPACE:
3564                switch(c)
3565                  {
3566                  default: RRETURN(MATCH_NOMATCH);
3567                  case 0x09:      /* HT */
3568                  case 0x20:      /* SPACE */
3569                  case 0xa0:      /* NBSP */
3570                  case 0x1680:    /* OGHAM SPACE MARK */
3571                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3572                  case 0x2000:    /* EN QUAD */
3573                  case 0x2001:    /* EM QUAD */
3574                  case 0x2002:    /* EN SPACE */
3575                  case 0x2003:    /* EM SPACE */
3576                  case 0x2004:    /* THREE-PER-EM SPACE */
3577                  case 0x2005:    /* FOUR-PER-EM SPACE */
3578                  case 0x2006:    /* SIX-PER-EM SPACE */
3579                  case 0x2007:    /* FIGURE SPACE */
3580                  case 0x2008:    /* PUNCTUATION SPACE */
3581                  case 0x2009:    /* THIN SPACE */
3582                  case 0x200A:    /* HAIR SPACE */
3583                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3584                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3585                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3586                  break;
3587                  }
3588                break;
3589    
3590                case OP_NOT_VSPACE:
3591                switch(c)
3592                  {
3593                  default: break;
3594                  case 0x0a:      /* LF */
3595                  case 0x0b:      /* VT */
3596                  case 0x0c:      /* FF */
3597                  case 0x0d:      /* CR */
3598                  case 0x85:      /* NEL */
3599                  case 0x2028:    /* LINE SEPARATOR */
3600                  case 0x2029:    /* PARAGRAPH SEPARATOR */
3601                  RRETURN(MATCH_NOMATCH);
3602                  }
3603                break;
3604    
3605                case OP_VSPACE:
3606                switch(c)
3607                  {
3608                  default: RRETURN(MATCH_NOMATCH);
3609                  case 0x0a:      /* LF */
3610                  case 0x0b:      /* VT */
3611                  case 0x0c:      /* FF */
3612                  case 0x0d:      /* CR */
3613                  case 0x85:      /* NEL */
3614                  case 0x2028:    /* LINE SEPARATOR */
3615                  case 0x2029:    /* PARAGRAPH SEPARATOR */
3616                  break;
3617                  }
3618              break;              break;
3619    
3620              case OP_NOT_DIGIT:              case OP_NOT_DIGIT:
# Line 2882  for (;;) Line 3658  for (;;)
3658          {          {
3659          for (fi = min;; fi++)          for (fi = min;; fi++)
3660            {            {
3661            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
3662            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3663            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject ||
3664                   (ctype == OP_ANY && IS_NEWLINE(eptr)))
3665                RRETURN(MATCH_NOMATCH);
3666    
3667            c = *eptr++;            c = *eptr++;
3668            switch(ctype)            switch(ctype)
3669              {              {
3670              case OP_ANY:              case OP_ANY:     /* This is the non-NL case */
3671              if ((ims & PCRE_DOTALL) == 0 && c == NEWLINE) RRETURN(MATCH_NOMATCH);              case OP_ALLANY:
3672                case OP_ANYBYTE:
3673              break;              break;
3674    
3675              case OP_ANYBYTE:              case OP_ANYNL:
3676                switch(c)
3677                  {
3678                  default: RRETURN(MATCH_NOMATCH);
3679                  case 0x000d:
3680                  if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3681                  break;
3682    
3683                  case 0x000a:
3684                  break;
3685    
3686                  case 0x000b:
3687                  case 0x000c:
3688                  case 0x0085:
3689                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3690                  break;
3691                  }
3692                break;
3693    
3694                case OP_NOT_HSPACE:
3695                switch(c)
3696                  {
3697                  default: break;
3698                  case 0x09:      /* HT */
3699                  case 0x20:      /* SPACE */
3700                  case 0xa0:      /* NBSP */
3701                  RRETURN(MATCH_NOMATCH);
3702                  }
3703                break;
3704    
3705                case OP_HSPACE:
3706                switch(c)
3707                  {
3708                  default: RRETURN(MATCH_NOMATCH);
3709                  case 0x09:      /* HT */
3710                  case 0x20:      /* SPACE */
3711                  case 0xa0:      /* NBSP */
3712                  break;
3713                  }
3714                break;
3715    
3716                case OP_NOT_VSPACE:
3717                switch(c)
3718                  {
3719                  default: break;
3720                  case 0x0a:      /* LF */
3721                  case 0x0b:      /* VT */
3722                  case 0x0c:      /* FF */
3723                  case 0x0d:      /* CR */
3724                  case 0x85:      /* NEL */
3725                  RRETURN(MATCH_NOMATCH);
3726                  }
3727                break;
3728    
3729                case OP_VSPACE:
3730                switch(c)
3731                  {
3732                  default: RRETURN(MATCH_NOMATCH);
3733                  case 0x0a:      /* LF */
3734                  case 0x0b:      /* VT */
3735                  case 0x0c:      /* FF */
3736                  case 0x0d:      /* CR */
3737                  case 0x85:      /* NEL */
3738                  break;
3739                  }
3740              break;              break;
3741    
3742              case OP_NOT_DIGIT:              case OP_NOT_DIGIT:
# Line 2927  for (;;) Line 3771  for (;;)
3771        /* Control never gets here */        /* Control never gets here */
3772        }        }
3773    
3774      /* If maximizing it is worth using inline code for speed, doing the type      /* If maximizing, it is worth using inline code for speed, doing the type
3775      test once at the start (i.e. keep it out of the loop). Again, keep the      test once at the start (i.e. keep it out of the loop). Again, keep the
3776      UTF-8 and UCP stuff separate. */      UTF-8 and UCP stuff separate. */
3777    
# Line 2957  for (;;) Line 3801  for (;;)
3801              int len = 1;              int len = 1;
3802              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3803              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3804              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3805              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3806                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3807                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2972  for (;;) Line 3816  for (;;)
3816              int len = 1;              int len = 1;
3817              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3818              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3819              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3820              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3821                break;                break;
3822              eptr+= len;              eptr+= len;
# Line 2985  for (;;) Line 3829  for (;;)
3829              int len = 1;              int len = 1;
3830              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3831              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3832              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3833              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3834                break;                break;
3835              eptr+= len;              eptr+= len;
# Line 2998  for (;;) Line 3842  for (;;)
3842              int len = 1;              int len = 1;
3843              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3844              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3845              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3846              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3847                break;                break;
3848              eptr+= len;              eptr+= len;
# Line 3008  for (;;) Line 3852  for (;;)
3852    
3853          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
3854    
3855            if (possessive) continue;
3856          for(;;)          for(;;)
3857            {            {
3858            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);
3859            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3860            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
3861            BACKCHAR(eptr);            if (utf8) BACKCHAR(eptr);
3862            }            }
3863          }          }
3864    
# Line 3026  for (;;) Line 3871  for (;;)
3871            {            {
3872            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
3873            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3874            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3875            if (prop_category == ucp_M) break;            if (prop_category == ucp_M) break;
3876            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3877              {              {
# Line 3035  for (;;) Line 3880  for (;;)
3880                {                {
3881                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3882                }                }
3883              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3884              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3885              eptr += len;              eptr += len;
3886              }              }
# Line 3043  for (;;) Line 3888  for (;;)
3888    
3889          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
3890    
3891            if (possessive) continue;
3892          for(;;)          for(;;)
3893            {            {
3894            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);
3895            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3896            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
3897            for (;;)                        /* Move back over one extended */            for (;;)                        /* Move back over one extended */
3898              {              {
3899              int len = 1;              int len = 1;
             BACKCHAR(eptr);  
3900              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr; else
3901                {                {
3902                  BACKCHAR(eptr);
3903                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3904                }                }
3905              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3906              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3907              eptr--;              eptr--;
3908              }              }
# Line 3074  for (;;) Line 3920  for (;;)
3920          switch(ctype)          switch(ctype)
3921            {            {
3922            case OP_ANY:            case OP_ANY:
   
           /* Special code is required for UTF8, but when the maximum is unlimited  
           we don't need it, so we repeat the non-UTF8 code. This is probably  
           worth it, because .* is quite a common idiom. */  
   
3923            if (max < INT_MAX)            if (max < INT_MAX)
3924              {              {
3925              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
               {  
               for (i = min; i < max; i++)  
                 {  
                 if (eptr >= md->end_subject || *eptr == NEWLINE) break;  
                 eptr++;  
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
               }  
             else  
3926                {                {
3927                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
3928                  {                eptr++;
3929                  eptr++;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
3930                }                }
3931              }              }
3932    
# Line 3104  for (;;) Line 3934  for (;;)
3934    
3935            else            else
3936              {              {
3937              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
3938                {                {
3939                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
3940                  {                eptr++;
3941                  if (eptr >= md->end_subject || *eptr == NEWLINE) break;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 eptr++;  
                 }  
               break;  
3942                }                }
3943              else              }
3944              break;
3945    
3946              case OP_ALLANY:
3947              if (max < INT_MAX)
3948                {
3949                for (i = min; i < max; i++)
3950                {                {
3951                c = max - min;                if (eptr >= md->end_subject) break;
3952                if (c > md->end_subject - eptr) c = md->end_subject - eptr;                eptr++;
3953                eptr += c;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3954                }                }
3955              }              }
3956              else eptr = md->end_subject;   /* Unlimited UTF-8 repeat */
3957            break;            break;
3958    
3959            /* The byte case is the same as non-UTF8 */            /* The byte case is the same as non-UTF8 */
3960    
3961            case OP_ANYBYTE:            case OP_ANYBYTE:
3962            c = max - min;            c = max - min;
3963            if (c > md->end_subject - eptr) c = md->end_subject - eptr;            if (c > (unsigned int)(md->end_subject - eptr))
3964                c = md->end_subject - eptr;
3965            eptr += c;            eptr += c;
3966            break;            break;
3967    
3968              case OP_ANYNL:
3969              for (i = min; i < max; i++)
3970                {
3971                int len = 1;
3972                if (eptr >= md->end_subject) break;
3973                GETCHARLEN(c, eptr, len);
3974                if (c == 0x000d)
3975                  {
3976                  if (++eptr >= md->end_subject) break;
3977                  if (*eptr == 0x000a) eptr++;
3978                  }
3979                else
3980                  {
3981                  if (c != 0x000a &&
3982                      (md->bsr_anycrlf ||
3983                       (c != 0x000b && c != 0x000c &&
3984                        c != 0x0085 && c != 0x2028 && c != 0x2029)))
3985                    break;
3986                  eptr += len;
3987                  }
3988                }
3989              break;
3990    
3991              case OP_NOT_HSPACE:
3992              case OP_HSPACE:
3993              for (i = min; i < max; i++)
3994                {
3995                BOOL gotspace;
3996                int len = 1;
3997                if (eptr >= md->end_subject) break;
3998                GETCHARLEN(c, eptr, len);
3999                switch(c)
4000                  {
4001                  default: gotspace = FALSE; break;
4002                  case 0x09:      /* HT */
4003                  case 0x20:      /* SPACE */
4004                  case 0xa0:      /* NBSP */
4005                  case 0x1680:    /* OGHAM SPACE MARK */
4006                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
4007                  case 0x2000:    /* EN QUAD */
4008                  case 0x2001:    /* EM QUAD */
4009                  case 0x2002:    /* EN SPACE */
4010                  case 0x2003:    /* EM SPACE */
4011                  case 0x2004:    /* THREE-PER-EM SPACE */
4012                  case 0x2005:    /* FOUR-PER-EM SPACE */
4013                  case 0x2006:    /* SIX-PER-EM SPACE */
4014                  case 0x2007:    /* FIGURE SPACE */
4015                  case 0x2008:    /* PUNCTUATION SPACE */
4016                  case 0x2009:    /* THIN SPACE */
4017                  case 0x200A:    /* HAIR SPACE */
4018                  case 0x202f:    /* NARROW NO-BREAK SPACE */
4019                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
4020                  case 0x3000:    /* IDEOGRAPHIC SPACE */
4021                  gotspace = TRUE;
4022                  break;
4023                  }
4024                if (gotspace == (ctype == OP_NOT_HSPACE)) break;
4025                eptr += len;
4026                }
4027              break;
4028    
4029              case OP_NOT_VSPACE:
4030              case OP_VSPACE:
4031              for (i = min; i < max; i++)
4032                {
4033                BOOL gotspace;
4034                int len = 1;
4035                if (eptr >= md->end_subject) break;
4036                GETCHARLEN(c, eptr, len);
4037                switch(c)
4038                  {
4039                  default: gotspace = FALSE; break;
4040                  case 0x0a:      /* LF */
4041                  case 0x0b:      /* VT */
4042                  case 0x0c:      /* FF */
4043                  case 0x0d:      /* CR */
4044                  case 0x85:      /* NEL */
4045                  case 0x2028:    /* LINE SEPARATOR */
4046                  case 0x2029:    /* PARAGRAPH SEPARATOR */
4047                  gotspace = TRUE;
4048                  break;
4049                  }
4050                if (gotspace == (ctype == OP_NOT_VSPACE)) break;
4051                eptr += len;
4052                }
4053              break;
4054    
4055            case OP_NOT_DIGIT:            case OP_NOT_DIGIT:
4056            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4057              {              {
# Line 3202  for (;;) Line 4124  for (;;)
4124    
4125          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
4126    
4127            if (possessive) continue;
4128          for(;;)          for(;;)
4129            {            {
4130            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM46);
4131            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4132            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
4133            BACKCHAR(eptr);            BACKCHAR(eptr);
4134            }            }
4135          }          }
4136        else        else
4137  #endif  #endif  /* SUPPORT_UTF8 */
4138    
4139        /* Not UTF-8 mode */        /* Not UTF-8 mode */
4140          {          {
4141          switch(ctype)          switch(ctype)
4142            {            {
4143            case OP_ANY:            case OP_ANY:
4144            if ((ims & PCRE_DOTALL) == 0)            for (i = min; i < max; i++)
4145              {              {
4146              for (i = min; i < max; i++)              if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
4147                {              eptr++;
               if (eptr >= md->end_subject || *eptr == NEWLINE) break;  
               eptr++;  
               }  
             break;  
4148              }              }
4149            /* For DOTALL case, fall through and treat as \C */            break;
4150    
4151              case OP_ALLANY:
4152            case OP_ANYBYTE:            case OP_ANYBYTE:
4153            c = max - min;            c = max - min;
4154            if (c > md->end_subject - eptr) c = md->end_subject - eptr;            if (c > (unsigned int)(md->end_subject - eptr))
4155                c = md->end_subject - eptr;
4156            eptr += c;            eptr += c;
4157            break;            break;
4158    
4159              case OP_ANYNL:
4160              for (i = min; i < max; i++)
4161                {
4162                if (eptr >= md->end_subject) break;
4163                c = *eptr;
4164                if (c == 0x000d)
4165                  {
4166                  if (++eptr >= md->end_subject) break;
4167                  if (*eptr == 0x000a) eptr++;
4168                  }
4169                else
4170                  {
4171                  if (c != 0x000a &&
4172                      (md->bsr_anycrlf ||
4173                        (c != 0x000b && c != 0x000c && c != 0x0085)))
4174                    break;
4175                  eptr++;
4176                  }
4177                }
4178              break;
4179    
4180              case OP_NOT_HSPACE:
4181              for (i = min; i < max; i++)
4182                {
4183                if (eptr >= md->end_subject) break;
4184                c = *eptr;
4185                if (c == 0x09 || c == 0x20 || c == 0xa0) break;
4186                eptr++;
4187                }
4188              break;
4189    
4190              case OP_HSPACE:
4191              for (i = min; i < max; i++)
4192                {
4193                if (eptr >= md->end_subject) break;
4194                c = *eptr;
4195                if (c != 0x09 && c != 0x20 && c != 0xa0) break;
4196                eptr++;
4197                }
4198              break;
4199    
4200              case OP_NOT_VSPACE:
4201              for (i = min; i < max; i++)
4202                {
4203                if (eptr >= md->end_subject) break;
4204                c = *eptr;
4205                if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)
4206                  break;
4207                eptr++;
4208                }
4209              break;
4210    
4211              case OP_VSPACE:
4212              for (i = min; i < max; i++)
4213                {
4214                if (eptr >= md->end_subject) break;
4215                c = *eptr;
4216                if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85)
4217                  break;
4218                eptr++;
4219                }
4220              break;
4221    
4222            case OP_NOT_DIGIT:            case OP_NOT_DIGIT:
4223            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4224              {              {
# Line 3295  for (;;) Line 4279  for (;;)
4279    
4280          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
4281    
4282            if (possessive) continue;
4283          while (eptr >= pp)          while (eptr >= pp)
4284            {            {
4285            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM47);
4286            eptr--;            eptr--;
4287            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4288            }            }
# Line 3309  for (;;) Line 4294  for (;;)
4294        }        }
4295      /* Control never gets here */      /* Control never gets here */
4296    
4297      /* There's been some horrible disaster. Since all codes > OP_BRA are      /* There's been some horrible disaster. Arrival here can only mean there is
4298      for capturing brackets, and there shouldn't be any gaps between 0 and      something seriously wrong in the code above or the OP_xxx definitions. */
     OP_BRA, arrival here can only mean there is something seriously wrong  
     in the code above or the OP_xxx definitions. */  
4299    
4300      default:      default:
4301      DPRINTF(("Unknown opcode %d\n", *ecode));      DPRINTF(("Unknown opcode %d\n", *ecode));
4302      RRETURN(PCRE_ERROR_UNKNOWN_NODE);      RRETURN(PCRE_ERROR_UNKNOWN_OPCODE);
4303      }      }
4304    
4305    /* Do not stick any code in here without much thought; it is assumed    /* Do not stick any code in here without much thought; it is assumed
# Line 3325  for (;;) Line 4308  for (;;)
4308    
4309    }             /* End of main loop */    }             /* End of main loop */
4310  /* Control never reaches here */  /* Control never reaches here */
4311    
4312    
4313    /* When compiling to use the heap rather than the stack for recursive calls to
4314    match(), the RRETURN() macro jumps here. The number that is saved in
4315    frame->Xwhere indicates which label we actually want to return to. */
4316    
4317    #ifdef NO_RECURSE
4318    #define LBL(val) case val: goto L_RM##val;
4319    HEAP_RETURN:
4320    switch (frame->Xwhere)
4321      {
4322      LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)
4323      LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)
4324      LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)
4325      LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
4326      LBL(53) LBL(54)
4327    #ifdef SUPPORT_UTF8
4328      LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)
4329      LBL(32) LBL(34) LBL(42) LBL(46)
4330    #ifdef SUPPORT_UCP
4331      LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
4332    #endif  /* SUPPORT_UCP */
4333    #endif  /* SUPPORT_UTF8 */
4334      default:
4335      DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));
4336      return PCRE_ERROR_INTERNAL;
4337      }
4338    #undef LBL
4339    #endif  /* NO_RECURSE */
4340  }  }
4341    
4342    
# Line 3337  Undefine all the macros that were define Line 4349  Undefine all the macros that were define
4349  #ifdef NO_RECURSE  #ifdef NO_RECURSE
4350  #undef eptr  #undef eptr
4351  #undef ecode  #undef ecode
4352    #undef mstart
4353  #undef offset_top  #undef offset_top
4354  #undef ims  #undef ims
4355  #undef eptrb  #undef eptrb
# Line 3354  Undefine all the macros that were define Line 4367  Undefine all the macros that were define
4367    
4368  #undef cur_is_word  #undef cur_is_word
4369  #undef condition  #undef condition
 #undef minimize  
4370  #undef prev_is_word  #undef prev_is_word
4371    
4372  #undef original_ims  #undef original_ims
# Line 3410  Returns:          > 0 => success; value Line 4422  Returns:          > 0 => success; value
4422                   < -1 => some kind of unexpected problem                   < -1 => some kind of unexpected problem
4423  */  */
4424    
4425  PCRE_DATA_SCOPE int  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
4426  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
4427    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
4428    int offsetcount)    int offsetcount)
# Line 3419  int rc, resetcount, ocount; Line 4431  int rc, resetcount, ocount;
4431  int first_byte = -1;  int first_byte = -1;
4432  int req_byte = -1;  int req_byte = -1;
4433  int req_byte2 = -1;  int req_byte2 = -1;
4434  unsigned long int ims = 0;  int newline;
4435    unsigned long int ims;
4436  BOOL using_temporary_offsets = FALSE;  BOOL using_temporary_offsets = FALSE;
4437  BOOL anchored;  BOOL anchored;
4438  BOOL startline;  BOOL startline;
4439  BOOL firstline;  BOOL firstline;
4440  BOOL first_byte_caseless = FALSE;  BOOL first_byte_caseless = FALSE;
4441  BOOL req_byte_caseless = FALSE;  BOOL req_byte_caseless = FALSE;
4442    BOOL utf8;
4443  match_data match_block;  match_data match_block;
4444    match_data *md = &match_block;
4445  const uschar *tables;  const uschar *tables;
4446  const uschar *start_bits = NULL;  const uschar *start_bits = NULL;
4447  USPTR start_match = (USPTR)subject + start_offset;  USPTR start_match = (USPTR)subject + start_offset;
# Line 3451  if (offsetcount < 0) return PCRE_ERROR_B Line 4466  if (offsetcount < 0) return PCRE_ERROR_B
4466  the default values. */  the default values. */
4467    
4468  study = NULL;  study = NULL;
4469  match_block.match_limit = MATCH_LIMIT;  md->match_limit = MATCH_LIMIT;
4470  match_block.match_limit_recursion = MATCH_LIMIT_RECURSION;  md->match_limit_recursion = MATCH_LIMIT_RECURSION;
4471  match_block.callout_data = NULL;  md->callout_data = NULL;
4472    
4473  /* The table pointer is always in native byte order. */  /* The table pointer is always in native byte order. */
4474    
# Line 3465  if (extra_data != NULL) Line 4480  if (extra_data != NULL)
4480    if ((flags & PCRE_EXTRA_STUDY_DATA) != 0)    if ((flags & PCRE_EXTRA_STUDY_DATA) != 0)
4481      study = (const pcre_study_data *)extra_data->study_data;      study = (const pcre_study_data *)extra_data->study_data;
4482    if ((flags & PCRE_EXTRA_MATCH_LIMIT) != 0)    if ((flags & PCRE_EXTRA_MATCH_LIMIT) != 0)
4483      match_block.match_limit = extra_data->match_limit;      md->match_limit = extra_data->match_limit;
4484    if ((flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION) != 0)    if ((flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION) != 0)
4485      match_block.match_limit_recursion = extra_data->match_limit_recursion;      md->match_limit_recursion = extra_data->match_limit_recursion;
4486    if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0)    if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0)
4487      match_block.callout_data = extra_data->callout_data;      md->callout_data = extra_data->callout_data;
4488    if ((flags & PCRE_EXTRA_TABLES) != 0) tables = extra_data->tables;    if ((flags & PCRE_EXTRA_TABLES) != 0) tables = extra_data->tables;
4489    }    }
4490    
# Line 3494  if (re->magic_number != MAGIC_NUMBER) Line 4509  if (re->magic_number != MAGIC_NUMBER)
4509  /* Set up other data */  /* Set up other data */
4510    
4511  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;
4512  startline = (re->options & PCRE_STARTLINE) != 0;  startline = (re->flags & PCRE_STARTLINE) != 0;
4513  firstline = (re->options & PCRE_FIRSTLINE) != 0;  firstline = (re->options & PCRE_FIRSTLINE) != 0;
4514    
4515  /* The code starts after the real_pcre block and the capture name table. */  /* The code starts after the real_pcre block and the capture name table. */
4516    
4517  match_block.start_code = (const uschar *)external_re + re->name_table_offset +  md->start_code = (const uschar *)external_re + re->name_table_offset +
4518    re->name_count * re->name_entry_size;    re->name_count * re->name_entry_size;
4519    
4520  match_block.start_subject = (USPTR)subject;  md->start_subject = (USPTR)subject;
4521  match_block.start_offset = start_offset;  md->start_offset = start_offset;
4522  match_block.end_subject = match_block.start_subject + length;  md->end_subject = md->start_subject + length;
4523  end_subject = match_block.end_subject;  end_subject = md->end_subject;
4524    
4525  match_block.endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
4526  match_block.utf8 = (re->options & PCRE_UTF8) != 0;  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
4527    md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
4528  match_block.notbol = (options & PCRE_NOTBOL) != 0;  
4529  match_block.noteol = (options & PCRE_NOTEOL) != 0;  md->notbol = (options & PCRE_NOTBOL) != 0;
4530  match_block.notempty = (options & PCRE_NOTEMPTY) != 0;  md->noteol = (options & PCRE_NOTEOL) != 0;
4531  match_block.partial = (options & PCRE_PARTIAL) != 0;  md->notempty = (options & PCRE_NOTEMPTY) != 0;
4532  match_block.hitend = FALSE;  md->partial = (options & PCRE_PARTIAL) != 0;
4533    md->hitend = FALSE;
4534    
4535  match_block.recursive = NULL;                   /* No recursion at top level */  md->recursive = NULL;                   /* No recursion at top level */
4536    
4537  match_block.lcc = tables + lcc_offset;  md->lcc = tables + lcc_offset;
4538  match_block.ctypes = tables + ctypes_offset;  md->ctypes = tables + ctypes_offset;
4539    
4540    /* Handle different \R options. */
4541    
4542    switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
4543      {
4544      case 0:
4545      if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0)
4546        md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0;
4547      else
4548    #ifdef BSR_ANYCRLF
4549      md->bsr_anycrlf = TRUE;
4550    #else
4551      md->bsr_anycrlf = FALSE;
4552    #endif
4553      break;
4554    
4555      case PCRE_BSR_ANYCRLF:
4556      md->bsr_anycrlf = TRUE;
4557      break;
4558    
4559      case PCRE_BSR_UNICODE:
4560      md->bsr_anycrlf = FALSE;
4561      break;
4562    
4563      default: return PCRE_ERROR_BADNEWLINE;
4564      }
4565    
4566    /* Handle different types of newline. The three bits give eight cases. If
4567    nothing is set at run time, whatever was used at compile time applies. */
4568    
4569    switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options :
4570            (pcre_uint32)options) & PCRE_NEWLINE_BITS)
4571      {
4572      case 0: newline = NEWLINE; break;   /* Compile-time default */
4573      case PCRE_NEWLINE_CR: newline = CHAR_CR; break;
4574      case PCRE_NEWLINE_LF: newline = CHAR_NL; break;
4575      case PCRE_NEWLINE_CR+
4576           PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break;
4577      case PCRE_NEWLINE_ANY: newline = -1; break;
4578      case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
4579      default: return PCRE_ERROR_BADNEWLINE;
4580      }
4581    
4582    if (newline == -2)
4583      {
4584      md->nltype = NLTYPE_ANYCRLF;
4585      }
4586    else if (newline < 0)
4587      {
4588      md->nltype = NLTYPE_ANY;
4589      }
4590    else
4591      {
4592      md->nltype = NLTYPE_FIXED;
4593      if (newline > 255)
4594        {
4595        md->nllen = 2;
4596        md->nl[0] = (newline >> 8) & 255;
4597        md->nl[1] = newline & 255;
4598        }
4599      else
4600        {
4601        md->nllen = 1;
4602        md->nl[0] = newline;
4603        }
4604      }
4605    
4606  /* Partial matching is supported only for a restricted set of regexes at the  /* Partial matching is supported only for a restricted set of regexes at the
4607  moment. */  moment. */
4608    
4609  if (match_block.partial && (re->options & PCRE_NOPARTIAL) != 0)  if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
4610    return PCRE_ERROR_BADPARTIAL;    return PCRE_ERROR_BADPARTIAL;
4611    
4612  /* Check a UTF-8 string if required. Unfortunately there's no way of passing  /* Check a UTF-8 string if required. Unfortunately there's no way of passing
4613  back the character offset. */  back the character offset. */
4614    
4615  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
4616  if (match_block.utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
4617    {    {
4618    if (_pcre_valid_utf8((uschar *)subject, length) >= 0)    if (_pcre_valid_utf8((uschar *)subject, length) >= 0)
4619      return PCRE_ERROR_BADUTF8;      return PCRE_ERROR_BADUTF8;
# Line 3563  ocount = offsetcount - (offsetcount % 3) Line 4645  ocount = offsetcount - (offsetcount % 3)
4645  if (re->top_backref > 0 && re->top_backref >= ocount/3)  if (re->top_backref > 0 && re->top_backref >= ocount/3)
4646    {    {
4647    ocount = re->top_backref * 3 + 3;    ocount = re->top_backref * 3 + 3;
4648    match_block.offset_vector = (int *)(pcre_malloc)(ocount * sizeof(int));    md->offset_vector = (int *)(pcre_malloc)(ocount * sizeof(int));
4649    if (match_block.offset_vector == NULL) return PCRE_ERROR_NOMEMORY;    if (md->offset_vector == NULL) return PCRE_ERROR_NOMEMORY;
4650    using_temporary_offsets = TRUE;    using_temporary_offsets = TRUE;
4651    DPRINTF(("Got memory to hold back references\n"));    DPRINTF(("Got memory to hold back references\n"));
4652    }    }
4653  else match_block.offset_vector = offsets;  else md->offset_vector = offsets;
4654    
4655  match_block.offset_end = ocount;  md->offset_end = ocount;
4656  match_block.offset_max = (2*ocount)/3;  md->offset_max = (2*ocount)/3;
4657  match_block.offset_overflow = FALSE;  md->offset_overflow = FALSE;
4658  match_block.capture_last = -1;  md->capture_last = -1;
4659    
4660  /* Compute the minimum number of offsets that we need to reset each time. Doing  /* Compute the minimum number of offsets that we need to reset each time. Doing
4661  this makes a huge difference to execution time when there aren't many brackets  this makes a huge difference to execution time when there aren't many brackets
# Line 3586  if (resetcount > offsetcount) resetcount Line 4668  if (resetcount > offsetcount) resetcount
4668  never be used unless previously set, but they get saved and restored, and so we  never be used unless previously set, but they get saved and restored, and so we
4669  initialize them to avoid reading uninitialized locations. */  initialize them to avoid reading uninitialized locations. */
4670    
4671  if (match_block.offset_vector != NULL)  if (md->offset_vector != NULL)
4672    {    {
4673    register int *iptr = match_block.offset_vector + ocount;    register int *iptr = md->offset_vector + ocount;
4674    register int *iend = iptr - resetcount/2 + 1;    register int *iend = iptr - resetcount/2 + 1;
4675    while (--iptr >= iend) *iptr = -1;    while (--iptr >= iend) *iptr = -1;
4676    }    }
# Line 3601  studied, there may be a bitmap of possib Line 4683  studied, there may be a bitmap of possib
4683    
4684  if (!anchored)  if (!anchored)
4685    {    {
4686    if ((re->options & PCRE_FIRSTSET) != 0)    if ((re->flags & PCRE_FIRSTSET) != 0)
4687      {      {
4688      first_byte = re->first_byte & 255;      first_byte = re->first_byte & 255;
4689      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)
4690        first_byte = match_block.lcc[first_byte];        first_byte = md->lcc[first_byte];
4691      }      }
4692    else    else
4693      if (!startline && study != NULL &&      if (!startline && study != NULL &&
# Line 3616  if (!anchored) Line 4698  if (!anchored)
4698  /* For anchored or unanchored matches, there may be a "last known required  /* For anchored or unanchored matches, there may be a "last known required
4699  character" set. */  character" set. */
4700    
4701  if ((re->options & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
4702    {    {
4703    req_byte = re->req_byte & 255;    req_byte = re->req_byte & 255;
4704    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;
4705    req_byte2 = (tables + fcc_offset)[req_byte];  /* case flipped */    req_byte2 = (tables + fcc_offset)[req_byte];  /* case flipped */
4706    }    }
4707    
4708    
4709    /* ==========================================================================*/
4710    
4711  /* Loop for handling unanchored repeated matching attempts; for anchored regexs  /* Loop for handling unanchored repeated matching attempts; for anchored regexs
4712  the loop runs just once. */  the loop runs just once. */
4713    
4714  do  for(;;)
4715    {    {
4716    USPTR save_end_subject = end_subject;    USPTR save_end_subject = end_subject;
4717      USPTR new_start_match;
4718    
4719    /* Reset the maximum number of extractions we might see. */    /* Reset the maximum number of extractions we might see. */
4720    
4721    if (match_block.offset_vector != NULL)    if (md->offset_vector != NULL)
4722      {      {
4723      register int *iptr = match_block.offset_vector;      register int *iptr = md->offset_vector;
4724      register int *iend = iptr + resetcount;      register int *iend = iptr + resetcount;
4725      while (iptr < iend) *iptr++ = -1;      while (iptr < iend) *iptr++ = -1;
4726      }      }
4727    
4728    /* Advance to a unique first char if possible. If firstline is TRUE, the    /* If firstline is TRUE, the start of the match is constrained to the first
4729    start of the match is constrained to the first line of a multiline string.    line of a multiline string. That is, the match must be before or at the first
4730    Implement this by temporarily adjusting end_subject so that we stop scanning    newline. Implement this by temporarily adjusting end_subject so that we stop
4731    at a newline. If the match fails at the newline, later code breaks this loop.    scanning at a newline. If the match fails at the newline, later code breaks
4732    */    this loop. */
4733    
4734    if (firstline)    if (firstline)
4735      {      {
4736      USPTR t = start_match;      USPTR t = start_match;
4737      while (t < save_end_subject && *t != '\n') t++;  #ifdef SUPPORT_UTF8
4738        if (utf8)
4739          {
4740          while (t < md->end_subject && !IS_NEWLINE(t))
4741            {
4742            t++;
4743            while (t < end_subject && (*t & 0xc0) == 0x80) t++;
4744            }
4745          }
4746        else
4747    #endif
4748        while (t < md->end_subject && !IS_NEWLINE(t)) t++;
4749      end_subject = t;      end_subject = t;
4750      }      }
4751    
4752    /* Now test for a unique first byte */    /* There are some optimizations that avoid running the match if a known
4753      starting point is not found, or if a known later character is not present.
4754      However, there is an option that disables these, for testing and for ensuring
4755      that all callouts do actually occur. */
4756    
4757    if (first_byte >= 0)    if ((options & PCRE_NO_START_OPTIMIZE) == 0)
4758      {      {
4759      if (first_byte_caseless)      /* Advance to a unique first byte if there is one. */
       while (start_match < end_subject &&  
              match_block.lcc[*start_match] != first_byte)  
         start_match++;  
     else  
       while (start_match < end_subject && *start_match != first_byte)  
         start_match++;  
     }  
4760    
4761    /* Or to just after \n for a multiline match if possible */      if (first_byte >= 0)
4762          {
4763          if (first_byte_caseless)
4764            while (start_match < end_subject && md->lcc[*start_match] != first_byte)
4765              start_match++;
4766          else
4767            while (start_match < end_subject && *start_match != first_byte)
4768              start_match++;
4769          }
4770    
4771    else if (startline)      /* Or to just after a linebreak for a multiline match */
4772      {  
4773      if (start_match > match_block.start_subject + start_offset)      else if (startline)
4774        {        {
4775        while (start_match < end_subject && start_match[-1] != NEWLINE)        if (start_match > md->start_subject + start_offset)
4776          start_match++;          {
4777    #ifdef SUPPORT_UTF8
4778            if (utf8)
4779              {
4780              while (start_match < end_subject && !WAS_NEWLINE(start_match))
4781                {
4782                start_match++;
4783                while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
4784                  start_match++;
4785                }
4786              }
4787            else
4788    #endif
4789            while (start_match < end_subject && !WAS_NEWLINE(start_match))
4790              start_match++;
4791    
4792            /* If we have just passed a CR and the newline option is ANY or ANYCRLF,
4793            and we are now at a LF, advance the match position by one more character.
4794            */
4795    
4796            if (start_match[-1] == CHAR_CR &&
4797                 (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&
4798                 start_match < end_subject &&
4799                 *start_match == CHAR_NL)
4800              start_match++;
4801            }
4802        }        }
     }  
4803    
4804    /* Or to a non-unique first char after study */