/[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 150 by ph10, Tue Apr 17 08:22:40 2007 UTC revision 371 by ph10, Mon Aug 25 18:28:05 2008 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-2007 University of Cambridge             Copyright (c) 1997-2008 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 */  #define NLBLOCK md             /* Block containing newline information */
50  #define PSSTART start_subject  /* Field containing processed string start */  #define PSSTART start_subject  /* Field containing processed string start */
51  #define PSEND   end_subject    /* Field containing processed string end */  #define PSEND   end_subject    /* Field containing processed string end */
# Line 53  possible. There are also some static sup Line 57  possible. There are also some static sup
57  #undef min  #undef min
58  #undef max  #undef max
59    
 /* The chain of eptrblocks for tail recursions uses memory in stack workspace,  
 obtained at top level, the size of which is defined by EPTR_WORK_SIZE. */  
   
 #define EPTR_WORK_SIZE (1000)  
   
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_cbegroup       0x02  /* Could-be-empty unlimited repeat group */  #define match_cbegroup       0x02  /* Could-be-empty unlimited repeat group */
 #define match_tail_recursed  0x04  /* Tail recursive call */  
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 70  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 152  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 188  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 210  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 256  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 273  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;
# Line 323  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 354  made performance worse. Line 405  made performance worse.
405  Arguments:  Arguments:
406     eptr        pointer to current character in subject     eptr        pointer to current character in subject
407     ecode       pointer to current position in compiled 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 363  Arguments: Line 416  Arguments:
416                   match_condassert - this is an assertion condition                   match_condassert - this is an assertion condition
417                   match_cbegroup - this is the start of an unlimited repeat                   match_cbegroup - this is the start of an unlimited repeat
418                     group that can match an empty string                     group that can match an empty string
                  match_tail_recursed - this is a tail_recursed group  
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 373  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, unsigned int rdepth)    int flags, unsigned int rdepth)
431  {  {
# Line 401  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 415  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 545  defined). However, RMATCH isn't like a f Line 599  defined). However, RMATCH isn't like a f
599  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,
600  however, impact performance when true recursion is being used. */  however, impact performance when true recursion is being used. */
601    
602    #ifdef SUPPORT_UTF8
603    utf8 = md->utf8;       /* Local copy of the flag */
604    #else
605    utf8 = FALSE;
606    #endif
607    
608  /* 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
609  haven't exceeded the recursive call limit. */  haven't exceeded the recursive call limit. */
610    
# Line 553  if (rdepth >= md->match_limit_recursion) Line 613  if (rdepth >= md->match_limit_recursion)
613    
614  original_ims = ims;    /* Save for resetting on ')' */  original_ims = ims;    /* Save for resetting on ')' */
615    
 #ifdef SUPPORT_UTF8  
 utf8 = md->utf8;       /* Local copy of the flag */  
 #else  
 utf8 = FALSE;  
 #endif  
   
616  /* At the start of a group with an unlimited repeat that may match an empty  /* At the start of a group with an unlimited repeat that may match an empty
617  string, the match_cbegroup flag is set. When this is the case, add the current  string, the match_cbegroup flag is set. When this is the case, add the current
618  subject pointer to the chain of such remembered pointers, to be checked when we  subject pointer to the chain of such remembered pointers, to be checked when we
619  hit the closing ket, in order to break infinite loops that match no characters.  hit the closing ket, in order to break infinite loops that match no characters.
620  When match() is called in other circumstances, don't add to the chain. If this  When match() is called in other circumstances, don't add to the chain. The
621  is a tail recursion, use a block from the workspace, as the one on the stack is  match_cbegroup flag must NOT be used with tail recursion, because the memory
622  already used. */  block that is used is on the stack, so a new one may be required for each
623    match(). */
624    
625  if ((flags & match_cbegroup) != 0)  if ((flags & match_cbegroup) != 0)
626    {    {
627    eptrblock *p;    newptrb.epb_saved_eptr = eptr;
628    if ((flags & match_tail_recursed) != 0)    newptrb.epb_prev = eptrb;
629      {    eptrb = &newptrb;
     if (md->eptrn >= EPTR_WORK_SIZE) RRETURN(PCRE_ERROR_NULLWSLIMIT);  
     p = md->eptrchain + md->eptrn++;  
     }  
   else p = &newptrb;  
   p->epb_saved_eptr = eptr;  
   p->epb_prev = eptrb;  
   eptrb = p;  
630    }    }
631    
632  /* Now start processing the opcodes. */  /* Now start processing the opcodes. */
# Line 593  for (;;) Line 641  for (;;)
641    
642    if (md->partial &&    if (md->partial &&
643        eptr >= md->end_subject &&        eptr >= md->end_subject &&
644        eptr > md->start_match)        eptr > mstart)
645      md->hitend = TRUE;      md->hitend = TRUE;
646    
647    switch(op)    switch(op)
648      {      {
649        case OP_FAIL:
650        RRETURN(MATCH_NOMATCH);
651    
652        case OP_PRUNE:
653        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
654          ims, eptrb, flags, RM51);
655        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
656        RRETURN(MATCH_PRUNE);
657    
658        case OP_COMMIT:
659        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
660          ims, eptrb, flags, RM52);
661        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
662        RRETURN(MATCH_COMMIT);
663    
664        case OP_SKIP:
665        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
666          ims, eptrb, flags, RM53);
667        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
668        md->start_match_ptr = eptr;   /* Pass back current position */
669        RRETURN(MATCH_SKIP);
670    
671        case OP_THEN:
672        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
673          ims, eptrb, flags, RM54);
674        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
675        RRETURN(MATCH_THEN);
676    
677      /* Handle a capturing bracket. If there is space in the offset vector, save      /* Handle a capturing bracket. If there is space in the offset vector, save
678      the current subject position in the working slot at the top of the vector.      the current subject position in the working slot at the top of the vector.
679      We mustn't change the current values of the data slot, because they may be      We mustn't change the current values of the data slot, because they may be
# Line 637  for (;;) Line 713  for (;;)
713        flags = (op == OP_SCBRA)? match_cbegroup : 0;        flags = (op == OP_SCBRA)? match_cbegroup : 0;
714        do        do
715          {          {
716          RMATCH(rrc, eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
717            ims, eptrb, flags);            ims, eptrb, flags, RM1);
718          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
719          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
720          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
721          }          }
# Line 654  for (;;) Line 730  for (;;)
730        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
731        }        }
732    
733      /* Insufficient room for saving captured contents. Treat as a non-capturing      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
734      bracket. */      as a non-capturing bracket. */
735    
736        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
737        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
738    
739      DPRINTF(("insufficient capture room: treat as non-capturing\n"));      DPRINTF(("insufficient capture room: treat as non-capturing\n"));
740    
741        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
742        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
743    
744      /* Non-capturing bracket. Loop for all the alternatives. When we get to the      /* Non-capturing bracket. Loop for all the alternatives. When we get to the
745      final alternative within the brackets, we would return the result of a      final alternative within the brackets, we would return the result of a
746      recursive call to match() whatever happened. We can reduce stack usage by      recursive call to match() whatever happened. We can reduce stack usage by
747      turning this into a tail recursion. */      turning this into a tail recursion, except in the case when match_cbegroup
748        is set.*/
749    
750      case OP_BRA:      case OP_BRA:
751      case OP_SBRA:      case OP_SBRA:
# Line 670  for (;;) Line 753  for (;;)
753      flags = (op >= OP_SBRA)? match_cbegroup : 0;      flags = (op >= OP_SBRA)? match_cbegroup : 0;
754      for (;;)      for (;;)
755        {        {
756        if (ecode[GET(ecode, 1)] != OP_ALT)        if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */
757          {          {
758          ecode += _pcre_OP_lengths[*ecode];          if (flags == 0)    /* Not a possibly empty group */
759          flags |= match_tail_recursed;            {
760          DPRINTF(("bracket 0 tail recursion\n"));            ecode += _pcre_OP_lengths[*ecode];
761          goto TAIL_RECURSE;            DPRINTF(("bracket 0 tail recursion\n"));
762              goto TAIL_RECURSE;
763              }
764    
765            /* Possibly empty group; can't use tail recursion. */
766    
767            RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
768              eptrb, flags, RM48);
769            RRETURN(rrc);
770          }          }
771    
772        /* For non-final alternatives, continue the loop for a NOMATCH result;        /* For non-final alternatives, continue the loop for a NOMATCH result;
773        otherwise return. */        otherwise return. */
774    
775        RMATCH(rrc, eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
776          eptrb, flags);          eptrb, flags, RM2);
777        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
778        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
779        }        }
780      /* Control never reaches here. */      /* Control never reaches here. */
# Line 723  for (;;) Line 814  for (;;)
814    
815      else      else
816        {        {
817        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
818            match_condassert);            match_condassert, RM3);
819        if (rrc == MATCH_MATCH)        if (rrc == MATCH_MATCH)
820          {          {
821          condition = TRUE;          condition = TRUE;
822          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
823          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
824          }          }
825        else if (rrc != MATCH_NOMATCH)        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
826          {          {
827          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
828          }          }
# Line 743  for (;;) Line 834  for (;;)
834        }        }
835    
836      /* We are now at the branch that is to be obeyed. As there is only one,      /* We are now at the branch that is to be obeyed. As there is only one,
837      we can use tail recursion to avoid using another stack frame. If the second      we can use tail recursion to avoid using another stack frame, except when
838      alternative doesn't exist, we can just plough on. */      match_cbegroup is required for an unlimited repeat of a possibly empty
839        group. If the second alternative doesn't exist, we can just plough on. */
840    
841      if (condition || *ecode == OP_ALT)      if (condition || *ecode == OP_ALT)
842        {        {
843        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
844        flags = match_tail_recursed | ((op == OP_SCOND)? match_cbegroup : 0);        if (op == OP_SCOND)        /* Possibly empty group */
845        goto TAIL_RECURSE;          {
846            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
847            RRETURN(rrc);
848            }
849          else                       /* Group must match something */
850            {
851            flags = 0;
852            goto TAIL_RECURSE;
853            }
854        }        }
855      else      else                         /* Condition false & no 2nd alternative */
856        {        {
857        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
858        }        }
859      break;      break;
860    
861    
862      /* End of the pattern. If we are in a top-level recursion, we should      /* End of the pattern, either real or forced. If we are in a top-level
863      restore the offsets appropriately and continue from after the call. */      recursion, we should restore the offsets appropriately and continue from
864        after the call. */
865    
866        case OP_ACCEPT:
867      case OP_END:      case OP_END:
868      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL && md->recursive->group_num == 0)
869        {        {
# Line 770  for (;;) Line 872  for (;;)
872        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
873        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
874          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
875        md->start_match = rec->save_start;        mstart = rec->save_start;
876        ims = original_ims;        ims = original_ims;
877        ecode = rec->after_call;        ecode = rec->after_call;
878        break;        break;
# Line 779  for (;;) Line 881  for (;;)
881      /* 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
882      string - backtracking will then try other alternatives, if any. */      string - backtracking will then try other alternatives, if any. */
883    
884      if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH);      if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);
885      md->end_match_ptr = eptr;          /* Record where we ended */      md->end_match_ptr = eptr;           /* Record where we ended */
886      md->end_offset_top = offset_top;   /* and how many extracts were taken */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
887        md->start_match_ptr = mstart;       /* and the start (\K can modify) */
888      RRETURN(MATCH_MATCH);      RRETURN(MATCH_MATCH);
889    
890      /* Change option settings */      /* Change option settings */
# Line 802  for (;;) Line 905  for (;;)
905      case OP_ASSERTBACK:      case OP_ASSERTBACK:
906      do      do
907        {        {
908        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
909            RM4);
910        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
911        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
912        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
913        }        }
914      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 828  for (;;) Line 932  for (;;)
932      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
933      do      do
934        {        {
935        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
936            RM5);
937        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
938        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
939        ecode += GET(ecode,1);        ecode += GET(ecode,1);
940        }        }
941      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 854  for (;;) Line 959  for (;;)
959          {          {
960          eptr--;          eptr--;
961          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
962          BACKCHAR(eptr)          BACKCHAR(eptr);
963          }          }
964        }        }
965      else      else
# Line 885  for (;;) Line 990  for (;;)
990        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
991        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
992        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = md->end_subject - md->start_subject;
993        cb.start_match      = md->start_match - md->start_subject;        cb.start_match      = mstart - md->start_subject;
994        cb.current_position = eptr - md->start_subject;        cb.current_position = eptr - md->start_subject;
995        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
996        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
# Line 947  for (;;) Line 1052  for (;;)
1052    
1053        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1054              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1055        new_recursive.save_start = md->start_match;        new_recursive.save_start = mstart;
1056        md->start_match = eptr;        mstart = eptr;
1057    
1058        /* 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
1059        restore the offset and recursion data. */        restore the offset and recursion data. */
# Line 957  for (;;) Line 1062  for (;;)
1062        flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;        flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
1063        do        do
1064          {          {
1065          RMATCH(rrc, eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1066            md, ims, eptrb, flags);            md, ims, eptrb, flags, RM6);
1067          if (rrc == MATCH_MATCH)          if (rrc == MATCH_MATCH)
1068            {            {
1069            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
# Line 967  for (;;) Line 1072  for (;;)
1072              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1073            RRETURN(MATCH_MATCH);            RRETURN(MATCH_MATCH);
1074            }            }
1075          else if (rrc != MATCH_NOMATCH)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1076            {            {
1077            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1078            RRETURN(rrc);            RRETURN(rrc);
# Line 1001  for (;;) Line 1106  for (;;)
1106    
1107      do      do
1108        {        {
1109        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
         eptrb, 0);  
1110        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
1111        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1112        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1113        }        }
1114      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 1047  for (;;) Line 1151  for (;;)
1151    
1152      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1153        {        {
1154        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);
1155        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1156        ecode = prev;        ecode = prev;
1157        flags = match_tail_recursed;        flags = 0;
1158        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1159        }        }
1160      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1161        {        {
1162        RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_cbegroup);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
1163        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1164        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1165        flags = match_tail_recursed;        flags = 0;
1166        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1167        }        }
1168      /* Control never gets here */      /* Control never gets here */
# Line 1070  for (;;) Line 1174  for (;;)
1174      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1175      break;      break;
1176    
1177      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1178      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
1179      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
1180      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
1181      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1182    
1183      case OP_BRAZERO:      case OP_BRAZERO:
1184        {        {
1185        next = ecode+1;        next = ecode+1;
1186        RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, 0);        RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
1187        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1188        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next,1); while (*next == OP_ALT);
1189        ecode = next + 1 + LINK_SIZE;        ecode = next + 1 + LINK_SIZE;
# Line 1090  for (;;) Line 1194  for (;;)
1194        {        {
1195        next = ecode+1;        next = ecode+1;
1196        do next += GET(next, 1); while (*next == OP_ALT);        do next += GET(next, 1); while (*next == OP_ALT);
1197        RMATCH(rrc, eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);        RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11);
1198        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1199        ecode++;        ecode++;
1200        }        }
1201      break;      break;
1202    
1203        case OP_SKIPZERO:
1204          {
1205          next = ecode+1;
1206          do next += GET(next,1); while (*next == OP_ALT);
1207          ecode = next + 1 + LINK_SIZE;
1208          }
1209        break;
1210    
1211      /* End of a group, repeated or non-repeating. */      /* End of a group, repeated or non-repeating. */
1212    
1213      case OP_KET:      case OP_KET:
# Line 1160  for (;;) Line 1272  for (;;)
1272          recursion_info *rec = md->recursive;          recursion_info *rec = md->recursive;
1273          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1274          md->recursive = rec->prevrec;          md->recursive = rec->prevrec;
1275          md->start_match = rec->save_start;          mstart = rec->save_start;
1276          memcpy(md->offset_vector, rec->offset_save,          memcpy(md->offset_vector, rec->offset_save,
1277            rec->saved_max * sizeof(int));            rec->saved_max * sizeof(int));
1278          ecode = rec->after_call;          ecode = rec->after_call;
# Line 1189  for (;;) Line 1301  for (;;)
1301    
1302      /* 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
1303      preceding bracket, in the appropriate order. In the second case, we can use      preceding bracket, in the appropriate order. In the second case, we can use
1304      tail recursion to avoid using another stack frame. */      tail recursion to avoid using another stack frame, unless we have an
1305        unlimited repeat of a group that can match an empty string. */
1306    
1307      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
1308    
1309      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1310        {        {
1311        RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);
1312        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1313          if (flags != 0)    /* Could match an empty string */
1314            {
1315            RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
1316            RRETURN(rrc);
1317            }
1318        ecode = prev;        ecode = prev;
       flags |= match_tail_recursed;  
1319        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1320        }        }
1321      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1322        {        {
1323        RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, flags);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
1324        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1325        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1326        flags = match_tail_recursed;        flags = 0;
1327        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1328        }        }
1329      /* Control never gets here */      /* Control never gets here */
# Line 1239  for (;;) Line 1356  for (;;)
1356      ecode++;      ecode++;
1357      break;      break;
1358    
1359        /* Reset the start of match point */
1360    
1361        case OP_SET_SOM:
1362        mstart = eptr;
1363        ecode++;
1364        break;
1365    
1366      /* Assert before internal newline if multiline, or before a terminating      /* Assert before internal newline if multiline, or before a terminating
1367      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. */
1368    
# Line 1331  for (;;) Line 1455  for (;;)
1455      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1456    
1457      case OP_ANY:      case OP_ANY:
1458      if ((ims & PCRE_DOTALL) == 0)      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
1459        {      /* Fall through */
1460        if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);  
1461        }      case OP_ALLANY:
1462      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);
1463      if (utf8)      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
       while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
1464      ecode++;      ecode++;
1465      break;      break;
1466    
# Line 1436  for (;;) Line 1559  for (;;)
1559        case 0x000d:        case 0x000d:
1560        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1561        break;        break;
1562    
1563        case 0x000a:        case 0x000a:
1564          break;
1565    
1566        case 0x000b:        case 0x000b:
1567        case 0x000c:        case 0x000c:
1568        case 0x0085:        case 0x0085:
1569        case 0x2028:        case 0x2028:
1570        case 0x2029:        case 0x2029:
1571          if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
1572          break;
1573          }
1574        ecode++;
1575        break;
1576    
1577        case OP_NOT_HSPACE:
1578        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1579        GETCHARINCTEST(c, eptr);
1580        switch(c)
1581          {
1582          default: break;
1583          case 0x09:      /* HT */
1584          case 0x20:      /* SPACE */
1585          case 0xa0:      /* NBSP */
1586          case 0x1680:    /* OGHAM SPACE MARK */
1587          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1588          case 0x2000:    /* EN QUAD */
1589          case 0x2001:    /* EM QUAD */
1590          case 0x2002:    /* EN SPACE */
1591          case 0x2003:    /* EM SPACE */
1592          case 0x2004:    /* THREE-PER-EM SPACE */
1593          case 0x2005:    /* FOUR-PER-EM SPACE */
1594          case 0x2006:    /* SIX-PER-EM SPACE */
1595          case 0x2007:    /* FIGURE SPACE */
1596          case 0x2008:    /* PUNCTUATION SPACE */
1597          case 0x2009:    /* THIN SPACE */
1598          case 0x200A:    /* HAIR SPACE */
1599          case 0x202f:    /* NARROW NO-BREAK SPACE */
1600          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1601          case 0x3000:    /* IDEOGRAPHIC SPACE */
1602          RRETURN(MATCH_NOMATCH);
1603          }
1604        ecode++;
1605        break;
1606    
1607        case OP_HSPACE:
1608        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1609        GETCHARINCTEST(c, eptr);
1610        switch(c)
1611          {
1612          default: RRETURN(MATCH_NOMATCH);
1613          case 0x09:      /* HT */
1614          case 0x20:      /* SPACE */
1615          case 0xa0:      /* NBSP */
1616          case 0x1680:    /* OGHAM SPACE MARK */
1617          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1618          case 0x2000:    /* EN QUAD */
1619          case 0x2001:    /* EM QUAD */
1620          case 0x2002:    /* EN SPACE */
1621          case 0x2003:    /* EM SPACE */
1622          case 0x2004:    /* THREE-PER-EM SPACE */
1623          case 0x2005:    /* FOUR-PER-EM SPACE */
1624          case 0x2006:    /* SIX-PER-EM SPACE */
1625          case 0x2007:    /* FIGURE SPACE */
1626          case 0x2008:    /* PUNCTUATION SPACE */
1627          case 0x2009:    /* THIN SPACE */
1628          case 0x200A:    /* HAIR SPACE */
1629          case 0x202f:    /* NARROW NO-BREAK SPACE */
1630          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1631          case 0x3000:    /* IDEOGRAPHIC SPACE */
1632          break;
1633          }
1634        ecode++;
1635        break;
1636    
1637        case OP_NOT_VSPACE:
1638        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1639        GETCHARINCTEST(c, eptr);
1640        switch(c)
1641          {
1642          default: break;
1643          case 0x0a:      /* LF */
1644          case 0x0b:      /* VT */
1645          case 0x0c:      /* FF */
1646          case 0x0d:      /* CR */
1647          case 0x85:      /* NEL */
1648          case 0x2028:    /* LINE SEPARATOR */
1649          case 0x2029:    /* PARAGRAPH SEPARATOR */
1650          RRETURN(MATCH_NOMATCH);
1651          }
1652        ecode++;
1653        break;
1654    
1655        case OP_VSPACE:
1656        if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1657        GETCHARINCTEST(c, eptr);
1658        switch(c)
1659          {
1660          default: RRETURN(MATCH_NOMATCH);
1661          case 0x0a:      /* LF */
1662          case 0x0b:      /* VT */
1663          case 0x0c:      /* FF */
1664          case 0x0d:      /* CR */
1665          case 0x85:      /* NEL */
1666          case 0x2028:    /* LINE SEPARATOR */
1667          case 0x2029:    /* PARAGRAPH SEPARATOR */
1668        break;        break;
1669        }        }
1670      ecode++;      ecode++;
# Line 1456  for (;;) Line 1679  for (;;)
1679      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1680      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1681        {        {
1682        int chartype, script;        const ucd_record * prop = GET_UCD(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1683    
1684        switch(ecode[1])        switch(ecode[1])
1685          {          {
# Line 1466  for (;;) Line 1688  for (;;)
1688          break;          break;
1689    
1690          case PT_LAMP:          case PT_LAMP:
1691          if ((chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
1692               chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
1693               chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
1694            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1695           break;           break;
1696    
1697          case PT_GC:          case PT_GC:
1698          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
1699            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1700          break;          break;
1701    
1702          case PT_PC:          case PT_PC:
1703          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
1704            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1705          break;          break;
1706    
1707          case PT_SC:          case PT_SC:
1708          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
1709            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1710          break;          break;
1711    
# Line 1502  for (;;) Line 1724  for (;;)
1724      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1725      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1726        {        {
1727        int chartype, script;        int category = UCD_CATEGORY(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1728        if (category == ucp_M) RRETURN(MATCH_NOMATCH);        if (category == ucp_M) RRETURN(MATCH_NOMATCH);
1729        while (eptr < md->end_subject)        while (eptr < md->end_subject)
1730          {          {
# Line 1512  for (;;) Line 1733  for (;;)
1733            {            {
1734            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
1735            }            }
1736          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
1737          if (category != ucp_M) break;          if (category != ucp_M) break;
1738          eptr += len;          eptr += len;
1739          }          }
# Line 1533  for (;;) Line 1754  for (;;)
1754      case OP_REF:      case OP_REF:
1755        {        {
1756        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
1757        ecode += 3;                                 /* Advance past item */        ecode += 3;
1758    
1759          /* If the reference is unset, there are two possibilities:
1760    
1761          (a) In the default, Perl-compatible state, set the length to be longer
1762          than the amount of subject left; this ensures that every attempt at a
1763          match fails. We can't just fail here, because of the possibility of
1764          quantifiers with zero minima.
1765    
1766          (b) If the JavaScript compatibility flag is set, set the length to zero
1767          so that the back reference matches an empty string.
1768    
1769        /* If the reference is unset, set the length to be longer than the amount        Otherwise, set the length to the length of what was matched by the
1770        of subject left; this ensures that every attempt at a match fails. We        referenced subpattern. */
1771        can't just fail here, because of the possibility of quantifiers with zero  
1772        minima. */        if (offset >= offset_top || md->offset_vector[offset] < 0)
1773            length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
1774        length = (offset >= offset_top || md->offset_vector[offset] < 0)?        else
1775          md->end_subject - eptr + 1 :          length = md->offset_vector[offset+1] - md->offset_vector[offset];
         md->offset_vector[offset+1] - md->offset_vector[offset];  
1776    
1777        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
1778    
# Line 1602  for (;;) Line 1832  for (;;)
1832          {          {
1833          for (fi = min;; fi++)          for (fi = min;; fi++)
1834            {            {
1835            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
1836            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1837            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max || !match_ref(offset, eptr, length, md, ims))
1838              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
# Line 1623  for (;;) Line 1853  for (;;)
1853            }            }
1854          while (eptr >= pp)          while (eptr >= pp)
1855            {            {
1856            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
1857            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1858            eptr -= length;            eptr -= length;
1859            }            }
# Line 1728  for (;;) Line 1958  for (;;)
1958            {            {
1959            for (fi = min;; fi++)            for (fi = min;; fi++)
1960              {              {
1961              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
1962              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1963              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1964              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
# Line 1748  for (;;) Line 1978  for (;;)
1978            {            {
1979            for (fi = min;; fi++)            for (fi = min;; fi++)
1980              {              {
1981              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
1982              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1983              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1984              c = *eptr++;              c = *eptr++;
# Line 1785  for (;;) Line 2015  for (;;)
2015              }              }
2016            for (;;)            for (;;)
2017              {              {
2018              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
2019              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2020              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2021              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 1804  for (;;) Line 2034  for (;;)
2034              }              }
2035            while (eptr >= pp)            while (eptr >= pp)
2036              {              {
2037              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
2038              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2039              eptr--;              eptr--;
2040              }              }
# Line 1875  for (;;) Line 2105  for (;;)
2105          {          {
2106          for (fi = min;; fi++)          for (fi = min;; fi++)
2107            {            {
2108            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2109            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2110            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2111            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
# Line 1899  for (;;) Line 2129  for (;;)
2129            }            }
2130          for(;;)          for(;;)
2131            {            {
2132            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2133            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2134            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2135            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2136            }            }
2137          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2138          }          }
# Line 1968  for (;;) Line 2198  for (;;)
2198          if (fc != dc)          if (fc != dc)
2199            {            {
2200  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2201            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2202  #endif  #endif
2203              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2204            }            }
# Line 2059  for (;;) Line 2289  for (;;)
2289  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2290          unsigned int othercase;          unsigned int othercase;
2291          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2292              (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR)              (othercase = UCD_OTHERCASE(fc)) != fc)
2293            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2294          else oclength = 0;          else oclength = 0;
2295  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
# Line 2086  for (;;) Line 2316  for (;;)
2316            {            {
2317            for (fi = min;; fi++)            for (fi = min;; fi++)
2318              {              {
2319              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2320              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2321              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2322              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (memcmp(eptr, charptr, length) == 0) eptr += length;
# Line 2127  for (;;) Line 2357  for (;;)
2357            if (possessive) continue;            if (possessive) continue;
2358            for(;;)            for(;;)
2359             {             {
2360             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2361             if (rrc != MATCH_NOMATCH) RRETURN(rrc);             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2362             if (eptr == pp) RRETURN(MATCH_NOMATCH);             if (eptr == pp) RRETURN(MATCH_NOMATCH);
2363  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2176  for (;;) Line 2406  for (;;)
2406          {          {
2407          for (fi = min;; fi++)          for (fi = min;; fi++)
2408            {            {
2409            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2410            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2411            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max || eptr >= md->end_subject ||
2412                fc != md->lcc[*eptr++])                fc != md->lcc[*eptr++])
# Line 2195  for (;;) Line 2425  for (;;)
2425          if (possessive) continue;          if (possessive) continue;
2426          while (eptr >= pp)          while (eptr >= pp)
2427            {            {
2428            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
2429            eptr--;            eptr--;
2430            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2431            }            }
# Line 2214  for (;;) Line 2444  for (;;)
2444          {          {
2445          for (fi = min;; fi++)          for (fi = min;; fi++)
2446            {            {
2447            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
2448            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2449            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)
2450              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
# Line 2232  for (;;) Line 2462  for (;;)
2462          if (possessive) continue;          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, RM27);
2466            eptr--;            eptr--;
2467            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2468            }            }
# Line 2377  for (;;) Line 2607  for (;;)
2607            register unsigned int d;            register unsigned int d;
2608            for (fi = min;; fi++)            for (fi = min;; fi++)
2609              {              {
2610              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
2611              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2612                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2613              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2614              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
2615              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
2616                RRETURN(MATCH_NOMATCH);  
2617              }              }
2618            }            }
2619          else          else
# Line 2391  for (;;) Line 2622  for (;;)
2622            {            {
2623            for (fi = min;; fi++)            for (fi = min;; fi++)
2624              {              {
2625              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
2626              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2627              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])
2628                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
# Line 2423  for (;;) Line 2654  for (;;)
2654          if (possessive) continue;          if (possessive) continue;
2655          for(;;)          for(;;)
2656              {              {
2657              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
2658              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2659              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2660              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2441  for (;;) Line 2672  for (;;)
2672            if (possessive) continue;            if (possessive) continue;
2673            while (eptr >= pp)            while (eptr >= pp)
2674              {              {
2675              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
2676              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2677              eptr--;              eptr--;
2678              }              }
# Line 2486  for (;;) Line 2717  for (;;)
2717            register unsigned int d;            register unsigned int d;
2718            for (fi = min;; fi++)            for (fi = min;; fi++)
2719              {              {
2720              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
2721              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2722                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2723              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2724              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
2725              }              }
2726            }            }
2727          else          else
# Line 2499  for (;;) Line 2730  for (;;)
2730            {            {
2731            for (fi = min;; fi++)            for (fi = min;; fi++)
2732              {              {
2733              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
2734              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2735              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)
2736                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
# Line 2530  for (;;) Line 2761  for (;;)
2761            if (possessive) continue;            if (possessive) continue;
2762            for(;;)            for(;;)
2763              {              {
2764              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
2765              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2766              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2767              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2548  for (;;) Line 2779  for (;;)
2779            if (possessive) continue;            if (possessive) continue;
2780            while (eptr >= pp)            while (eptr >= pp)
2781              {              {
2782              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
2783              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2784              eptr--;              eptr--;
2785              }              }
# Line 2655  for (;;) Line 2886  for (;;)
2886            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2887              {              {
2888              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2889              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2890              }              }
2891            break;            break;
2892    
# Line 2663  for (;;) Line 2894  for (;;)
2894            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2895              {              {
2896              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2897              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2898              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
2899              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
2900                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
2901                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2676  for (;;) Line 2907  for (;;)
2907            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2908              {              {
2909              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2910              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2911              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
2912              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
2913                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2914              }              }
# Line 2687  for (;;) Line 2918  for (;;)
2918            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2919              {              {
2920              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2921              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2922              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
2923              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
2924                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2925              }              }
# Line 2698  for (;;) Line 2929  for (;;)
2929            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
2930              {              {
2931              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2932              GETCHARINC(c, eptr);              GETCHARINCTEST(c, eptr);
2933              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
2934              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
2935                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2936              }              }
# Line 2718  for (;;) Line 2949  for (;;)
2949          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2950            {            {
2951            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
2952            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
2953            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
2954            while (eptr < md->end_subject)            while (eptr < md->end_subject)
2955              {              {
# Line 2727  for (;;) Line 2958  for (;;)
2958                {                {
2959                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
2960                }                }
2961              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
2962              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
2963              eptr += len;              eptr += len;
2964              }              }
# Line 2745  for (;;) Line 2976  for (;;)
2976          case OP_ANY:          case OP_ANY:
2977          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2978            {            {
2979            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject || IS_NEWLINE(eptr))
                ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))  
2980              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2981            eptr++;            eptr++;
2982            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
2983            }            }
2984          break;          break;
2985    
2986            case OP_ALLANY:
2987            for (i = 1; i <= min; i++)
2988              {
2989              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2990              eptr++;
2991              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
2992              }
2993            break;
2994    
2995          case OP_ANYBYTE:          case OP_ANYBYTE:
2996          eptr += min;          eptr += min;
2997          break;          break;
# Line 2768  for (;;) Line 3007  for (;;)
3007              case 0x000d:              case 0x000d:
3008              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3009              break;              break;
3010    
3011              case 0x000a:              case 0x000a:
3012                break;
3013    
3014              case 0x000b:              case 0x000b:
3015              case 0x000c:              case 0x000c:
3016              case 0x0085:              case 0x0085:
3017              case 0x2028:              case 0x2028:
3018              case 0x2029:              case 0x2029:
3019                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3020                break;
3021                }
3022              }
3023            break;
3024    
3025            case OP_NOT_HSPACE:
3026            for (i = 1; i <= min; i++)
3027              {
3028              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3029              GETCHARINC(c, eptr);
3030              switch(c)
3031                {
3032                default: break;
3033                case 0x09:      /* HT */
3034                case 0x20:      /* SPACE */
3035                case 0xa0:      /* NBSP */
3036                case 0x1680:    /* OGHAM SPACE MARK */
3037                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3038                case 0x2000:    /* EN QUAD */
3039                case 0x2001:    /* EM QUAD */
3040                case 0x2002:    /* EN SPACE */
3041                case 0x2003:    /* EM SPACE */
3042                case 0x2004:    /* THREE-PER-EM SPACE */
3043                case 0x2005:    /* FOUR-PER-EM SPACE */
3044                case 0x2006:    /* SIX-PER-EM SPACE */
3045                case 0x2007:    /* FIGURE SPACE */
3046                case 0x2008:    /* PUNCTUATION SPACE */
3047                case 0x2009:    /* THIN SPACE */
3048                case 0x200A:    /* HAIR SPACE */
3049                case 0x202f:    /* NARROW NO-BREAK SPACE */
3050                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3051                case 0x3000:    /* IDEOGRAPHIC SPACE */
3052                RRETURN(MATCH_NOMATCH);
3053                }
3054              }
3055            break;
3056    
3057            case OP_HSPACE:
3058            for (i = 1; i <= min; i++)
3059              {
3060              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3061              GETCHARINC(c, eptr);
3062              switch(c)
3063                {
3064                default: RRETURN(MATCH_NOMATCH);
3065                case 0x09:      /* HT */
3066                case 0x20:      /* SPACE */
3067                case 0xa0:      /* NBSP */
3068                case 0x1680:    /* OGHAM SPACE MARK */
3069                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3070                case 0x2000:    /* EN QUAD */
3071                case 0x2001:    /* EM QUAD */
3072                case 0x2002:    /* EN SPACE */
3073                case 0x2003:    /* EM SPACE */
3074                case 0x2004:    /* THREE-PER-EM SPACE */
3075                case 0x2005:    /* FOUR-PER-EM SPACE */
3076                case 0x2006:    /* SIX-PER-EM SPACE */
3077                case 0x2007:    /* FIGURE SPACE */
3078                case 0x2008:    /* PUNCTUATION SPACE */
3079                case 0x2009:    /* THIN SPACE */
3080                case 0x200A:    /* HAIR SPACE */
3081                case 0x202f:    /* NARROW NO-BREAK SPACE */
3082                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3083                case 0x3000:    /* IDEOGRAPHIC SPACE */
3084                break;
3085                }
3086              }
3087            break;
3088    
3089            case OP_NOT_VSPACE:
3090            for (i = 1; i <= min; i++)
3091              {
3092              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3093              GETCHARINC(c, eptr);
3094              switch(c)
3095                {
3096                default: break;
3097                case 0x0a:      /* LF */
3098                case 0x0b:      /* VT */
3099                case 0x0c:      /* FF */
3100                case 0x0d:      /* CR */
3101                case 0x85:      /* NEL */
3102                case 0x2028:    /* LINE SEPARATOR */
3103                case 0x2029:    /* PARAGRAPH SEPARATOR */
3104                RRETURN(MATCH_NOMATCH);
3105                }
3106              }
3107            break;
3108    
3109            case OP_VSPACE:
3110            for (i = 1; i <= min; i++)
3111              {
3112              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3113              GETCHARINC(c, eptr);
3114              switch(c)
3115                {
3116                default: RRETURN(MATCH_NOMATCH);
3117                case 0x0a:      /* LF */
3118                case 0x0b:      /* VT */
3119                case 0x0c:      /* FF */
3120                case 0x0d:      /* CR */
3121                case 0x85:      /* NEL */
3122                case 0x2028:    /* LINE SEPARATOR */
3123                case 0x2029:    /* PARAGRAPH SEPARATOR */
3124              break;              break;
3125              }              }
3126            }            }
# Line 2803  for (;;) Line 3150  for (;;)
3150          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3151            {            {
3152            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3153               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0))
3154              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3155            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3156            }            }
3157          break;          break;
3158    
# Line 2823  for (;;) Line 3170  for (;;)
3170          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3171            {            {
3172            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3173               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))
3174              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3175            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3176            }            }
3177          break;          break;
3178    
# Line 2853  for (;;) Line 3200  for (;;)
3200        switch(ctype)        switch(ctype)
3201          {          {
3202          case OP_ANY:          case OP_ANY:
3203          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3204            {            {
3205            for (i = 1; i <= min; i++)            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3206              {            eptr++;
             if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);  
             eptr++;  
             }  
3207            }            }
3208          else eptr += min;          break;
3209    
3210            case OP_ALLANY:
3211            eptr += min;
3212          break;          break;
3213    
3214          case OP_ANYBYTE:          case OP_ANYBYTE:
# Line 2882  for (;;) Line 3229  for (;;)
3229              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3230              break;              break;
3231              case 0x000a:              case 0x000a:
3232                break;
3233    
3234              case 0x000b:              case 0x000b:
3235              case 0x000c:              case 0x000c:
3236              case 0x0085:              case 0x0085:
3237                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3238                break;
3239                }
3240              }
3241            break;
3242    
3243            case OP_NOT_HSPACE:
3244            for (i = 1; i <= min; i++)
3245              {
3246              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3247              switch(*eptr++)
3248                {
3249                default: break;
3250                case 0x09:      /* HT */
3251                case 0x20:      /* SPACE */
3252                case 0xa0:      /* NBSP */
3253                RRETURN(MATCH_NOMATCH);
3254                }
3255              }
3256            break;
3257    
3258            case OP_HSPACE:
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 0x09:      /* HT */
3266                case 0x20:      /* SPACE */
3267                case 0xa0:      /* NBSP */
3268                break;
3269                }
3270              }
3271            break;
3272    
3273            case OP_NOT_VSPACE:
3274            for (i = 1; i <= min; i++)
3275              {
3276              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3277              switch(*eptr++)
3278                {
3279                default: break;
3280                case 0x0a:      /* LF */
3281                case 0x0b:      /* VT */
3282                case 0x0c:      /* FF */
3283                case 0x0d:      /* CR */
3284                case 0x85:      /* NEL */
3285                RRETURN(MATCH_NOMATCH);
3286                }
3287              }
3288            break;
3289    
3290            case OP_VSPACE:
3291            for (i = 1; i <= min; i++)
3292              {
3293              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3294              switch(*eptr++)
3295                {
3296                default: RRETURN(MATCH_NOMATCH);
3297                case 0x0a:      /* LF */
3298                case 0x0b:      /* VT */
3299                case 0x0c:      /* FF */
3300                case 0x0d:      /* CR */
3301                case 0x85:      /* NEL */
3302              break;              break;
3303              }              }
3304            }            }
# Line 2945  for (;;) Line 3359  for (;;)
3359            case PT_ANY:            case PT_ANY:
3360            for (fi = min;; fi++)            for (fi = min;; fi++)
3361              {              {
3362              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
3363              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3364              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3365              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
# Line 2956  for (;;) Line 3370  for (;;)
3370            case PT_LAMP:            case PT_LAMP:
3371            for (fi = min;; fi++)            for (fi = min;; fi++)
3372              {              {
3373              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
3374              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3375              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3376              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3377              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3378              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3379                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3380                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2971  for (;;) Line 3385  for (;;)
3385            case PT_GC:            case PT_GC:
3386            for (fi = min;; fi++)            for (fi = min;; fi++)
3387              {              {
3388              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
3389              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3390              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3391              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3392              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3393              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3394                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3395              }              }
# Line 2984  for (;;) Line 3398  for (;;)
3398            case PT_PC:            case PT_PC:
3399            for (fi = min;; fi++)            for (fi = min;; fi++)
3400              {              {
3401              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
3402              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3403              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3404              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3405              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3406              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3407                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3408              }              }
# Line 2997  for (;;) Line 3411  for (;;)
3411            case PT_SC:            case PT_SC:
3412            for (fi = min;; fi++)            for (fi = min;; fi++)
3413              {              {
3414              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
3415              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3416              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3417              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3418              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3419              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3420                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3421              }              }
# Line 3019  for (;;) Line 3433  for (;;)
3433          {          {
3434          for (fi = min;; fi++)          for (fi = min;; fi++)
3435            {            {
3436            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
3437            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3438            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3439            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3440            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3441            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3442            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3443              {              {
# Line 3032  for (;;) Line 3446  for (;;)
3446                {                {
3447                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3448                }                }
3449              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3450              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3451              eptr += len;              eptr += len;
3452              }              }
# Line 3048  for (;;) Line 3462  for (;;)
3462          {          {
3463          for (fi = min;; fi++)          for (fi = min;; fi++)
3464            {            {
3465            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
3466            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3467            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max || eptr >= md->end_subject ||
3468                 (ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 &&                 (ctype == OP_ANY && IS_NEWLINE(eptr)))
                 IS_NEWLINE(eptr)))  
3469              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3470    
3471            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3472            switch(ctype)            switch(ctype)
3473              {              {
3474              case OP_ANY:        /* This is the DOTALL case */              case OP_ANY:        /* This is the non-NL case */
3475              break;              case OP_ALLANY:
   
3476              case OP_ANYBYTE:              case OP_ANYBYTE:
3477              break;              break;
3478    
# Line 3072  for (;;) Line 3484  for (;;)
3484                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3485                break;                break;
3486                case 0x000a:                case 0x000a:
3487                  break;
3488    
3489                case 0x000b:                case 0x000b:
3490                case 0x000c:                case 0x000c:
3491                case 0x0085:                case 0x0085:
3492                case 0x2028:                case 0x2028:
3493                case 0x2029:                case 0x2029:
3494                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3495                  break;
3496                  }
3497                break;
3498    
3499                case OP_NOT_HSPACE:
3500                switch(c)
3501                  {
3502                  default: break;
3503                  case 0x09:      /* HT */
3504                  case 0x20:      /* SPACE */
3505                  case 0xa0:      /* NBSP */
3506                  case 0x1680:    /* OGHAM SPACE MARK */
3507                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3508                  case 0x2000:    /* EN QUAD */
3509                  case 0x2001:    /* EM QUAD */
3510                  case 0x2002:    /* EN SPACE */
3511                  case 0x2003:    /* EM SPACE */
3512                  case 0x2004:    /* THREE-PER-EM SPACE */
3513                  case 0x2005:    /* FOUR-PER-EM SPACE */
3514                  case 0x2006:    /* SIX-PER-EM SPACE */
3515                  case 0x2007:    /* FIGURE SPACE */
3516                  case 0x2008:    /* PUNCTUATION SPACE */
3517                  case 0x2009:    /* THIN SPACE */
3518                  case 0x200A:    /* HAIR SPACE */
3519                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3520                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3521                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3522                  RRETURN(MATCH_NOMATCH);
3523                  }
3524                break;
3525    
3526                case OP_HSPACE:
3527                switch(c)
3528                  {
3529                  default: RRETURN(MATCH_NOMATCH);
3530                  case 0x09:      /* HT */
3531                  case 0x20:      /* SPACE */
3532                  case 0xa0:      /* NBSP */
3533                  case 0x1680:    /* OGHAM SPACE MARK */
3534                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3535                  case 0x2000:    /* EN QUAD */
3536                  case 0x2001:    /* EM QUAD */
3537                  case 0x2002:    /* EN SPACE */
3538                  case 0x2003:    /* EM SPACE */
3539                  case 0x2004:    /* THREE-PER-EM SPACE */
3540                  case 0x2005:    /* FOUR-PER-EM SPACE */
3541                  case 0x2006:    /* SIX-PER-EM SPACE */
3542                  case 0x2007:    /* FIGURE SPACE */
3543                  case 0x2008:    /* PUNCTUATION SPACE */
3544                  case 0x2009:    /* THIN SPACE */
3545                  case 0x200A:    /* HAIR SPACE */
3546                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3547                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3548                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3549                  break;
3550                  }
3551                break;
3552    
3553                case OP_NOT_VSPACE:
3554                switch(c)
3555                  {
3556                  default: break;
3557                  case 0x0a:      /* LF */
3558                  case 0x0b:      /* VT */
3559                  case 0x0c:      /* FF */
3560                  case 0x0d:      /* CR */
3561                  case 0x85:      /* NEL */
3562                  case 0x2028:    /* LINE SEPARATOR */
3563                  case 0x2029:    /* PARAGRAPH SEPARATOR */
3564                  RRETURN(MATCH_NOMATCH);
3565                  }
3566                break;
3567    
3568                case OP_VSPACE:
3569                switch(c)
3570                  {
3571                  default: RRETURN(MATCH_NOMATCH);
3572                  case 0x0a:      /* LF */
3573                  case 0x0b:      /* VT */
3574                  case 0x0c:      /* FF */
3575                  case 0x0d:      /* CR */
3576                  case 0x85:      /* NEL */
3577                  case 0x2028:    /* LINE SEPARATOR */
3578                  case 0x2029:    /* PARAGRAPH SEPARATOR */
3579                break;                break;
3580                }                }
3581              break;              break;
# Line 3122  for (;;) Line 3621  for (;;)
3621          {          {
3622          for (fi = min;; fi++)          for (fi = min;; fi++)
3623            {            {
3624            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
3625            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3626            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max || eptr >= md->end_subject ||
3627                 ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))                 (ctype == OP_ANY && IS_NEWLINE(eptr)))
3628              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3629    
3630            c = *eptr++;            c = *eptr++;
3631            switch(ctype)            switch(ctype)
3632              {              {
3633              case OP_ANY:   /* This is the DOTALL case */              case OP_ANY:     /* This is the non-NL case */
3634              break;              case OP_ALLANY:
   
3635              case OP_ANYBYTE:              case OP_ANYBYTE:
3636              break;              break;
3637    
# Line 3144  for (;;) Line 3642  for (;;)
3642                case 0x000d:                case 0x000d:
3643                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3644                break;                break;
3645    
3646                case 0x000a:                case 0x000a:
3647                  break;
3648    
3649                case 0x000b:                case 0x000b:
3650                case 0x000c:                case 0x000c:
3651                case 0x0085:                case 0x0085:
3652                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3653                  break;
3654                  }
3655                break;
3656    
3657                case OP_NOT_HSPACE:
3658                switch(c)
3659                  {
3660                  default: break;
3661                  case 0x09:      /* HT */
3662                  case 0x20:      /* SPACE */
3663                  case 0xa0:      /* NBSP */
3664                  RRETURN(MATCH_NOMATCH);
3665                  }
3666                break;
3667    
3668                case OP_HSPACE:
3669                switch(c)
3670                  {
3671                  default: RRETURN(MATCH_NOMATCH);
3672                  case 0x09:      /* HT */
3673                  case 0x20:      /* SPACE */
3674                  case 0xa0:      /* NBSP */
3675                  break;
3676                  }
3677                break;
3678    
3679                case OP_NOT_VSPACE:
3680                switch(c)
3681                  {
3682                  default: break;
3683                  case 0x0a:      /* LF */
3684                  case 0x0b:      /* VT */
3685                  case 0x0c:      /* FF */
3686                  case 0x0d:      /* CR */
3687                  case 0x85:      /* NEL */
3688                  RRETURN(MATCH_NOMATCH);
3689                  }
3690                break;
3691    
3692                case OP_VSPACE:
3693                switch(c)
3694                  {
3695                  default: RRETURN(MATCH_NOMATCH);
3696                  case 0x0a:      /* LF */
3697                  case 0x0b:      /* VT */
3698                  case 0x0c:      /* FF */
3699                  case 0x0d:      /* CR */
3700                  case 0x85:      /* NEL */
3701                break;                break;
3702                }                }
3703              break;              break;
# Line 3214  for (;;) Line 3764  for (;;)
3764              int len = 1;              int len = 1;
3765              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3766              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3767              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3768              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3769                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3770                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 3229  for (;;) Line 3779  for (;;)
3779              int len = 1;              int len = 1;
3780              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3781              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3782              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3783              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3784                break;                break;
3785              eptr+= len;              eptr+= len;
# Line 3242  for (;;) Line 3792  for (;;)
3792              int len = 1;              int len = 1;
3793              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3794              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3795              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3796              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3797                break;                break;
3798              eptr+= len;              eptr+= len;
# Line 3255  for (;;) Line 3805  for (;;)
3805              int len = 1;              int len = 1;
3806              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3807              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3808              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3809              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3810                break;                break;
3811              eptr+= len;              eptr+= len;
# Line 3268  for (;;) Line 3818  for (;;)
3818          if (possessive) continue;          if (possessive) continue;
3819          for(;;)          for(;;)
3820            {            {
3821            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);
3822            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3823            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
3824            BACKCHAR(eptr);            if (utf8) BACKCHAR(eptr);
3825            }            }
3826          }          }
3827    
# Line 3284  for (;;) Line 3834  for (;;)
3834            {            {
3835            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
3836            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3837            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3838            if (prop_category == ucp_M) break;            if (prop_category == ucp_M) break;
3839            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3840              {              {
# Line 3293  for (;;) Line 3843  for (;;)
3843                {                {
3844                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3845                }                }
3846              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3847              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3848              eptr += len;              eptr += len;
3849              }              }
# Line 3304  for (;;) Line 3854  for (;;)
3854          if (possessive) continue;          if (possessive) continue;
3855          for(;;)          for(;;)
3856            {            {
3857            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);
3858            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3859            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
3860            for (;;)                        /* Move back over one extended */            for (;;)                        /* Move back over one extended */
3861              {              {
3862              int len = 1;              int len = 1;
             BACKCHAR(eptr);  
3863              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr; else
3864                {                {
3865                  BACKCHAR(eptr);
3866                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3867                }                }
3868              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3869              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3870              eptr--;              eptr--;
3871              }              }
# Line 3333  for (;;) Line 3883  for (;;)
3883          switch(ctype)          switch(ctype)
3884            {            {
3885            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. */  
   
3886            if (max < INT_MAX)            if (max < INT_MAX)
3887              {              {
3888              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
               {  
               for (i = min; i < max; i++)  
                 {  
                 if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;  
                 eptr++;  
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
               }  
             else  
3889                {                {
3890                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
3891                  {                eptr++;
3892                  if (eptr >= md->end_subject) break;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 eptr++;  
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
3893                }                }
3894              }              }
3895    
# Line 3364  for (;;) Line 3897  for (;;)
3897    
3898            else            else
3899              {              {
3900              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
3901                {                {
3902                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
3903                  {                eptr++;
3904                  if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 eptr++;  
                 }  
               break;  
3905                }                }
3906              else              }
3907              break;
3908    
3909              case OP_ALLANY:
3910              if (max < INT_MAX)
3911                {
3912                for (i = min; i < max; i++)
3913                {                {
3914                c = max - min;                if (eptr >= md->end_subject) break;
3915                if (c > (unsigned int)(md->end_subject - eptr))                eptr++;
3916                  c = md->end_subject - eptr;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
               eptr += c;  
3917                }                }
3918              }              }
3919              else eptr = md->end_subject;   /* Unlimited UTF-8 repeat */
3920            break;            break;
3921    
3922            /* The byte case is the same as non-UTF8 */            /* The byte case is the same as non-UTF8 */
# Line 3405  for (;;) Line 3941  for (;;)
3941                }                }
3942              else              else
3943                {                {
3944                if (c != 0x000a && c != 0x000b && c != 0x000c &&                if (c != 0x000a &&
3945                    c != 0x0085 && c != 0x2028 && c != 0x2029)                    (md->bsr_anycrlf ||
3946                       (c != 0x000b && c != 0x000c &&
3947                        c != 0x0085 && c != 0x2028 && c != 0x2029)))
3948                  break;                  break;
3949                eptr += len;                eptr += len;
3950                }                }
3951              }              }
3952            break;            break;
3953    
3954              case OP_NOT_HSPACE:
3955              case OP_HSPACE:
3956              for (i = min; i < max; i++)
3957                {
3958                BOOL gotspace;
3959                int len = 1;
3960                if (eptr >= md->end_subject) break;
3961                GETCHARLEN(c, eptr, len);
3962                switch(c)
3963                  {
3964                  default: gotspace = FALSE; break;
3965                  case 0x09:      /* HT */
3966                  case 0x20:      /* SPACE */
3967                  case 0xa0:      /* NBSP */
3968                  case 0x1680:    /* OGHAM SPACE MARK */
3969                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3970                  case 0x2000:    /* EN QUAD */
3971                  case 0x2001:    /* EM QUAD */
3972                  case 0x2002:    /* EN SPACE */
3973                  case 0x2003:    /* EM SPACE */
3974                  case 0x2004:    /* THREE-PER-EM SPACE */
3975                  case 0x2005:    /* FOUR-PER-EM SPACE */
3976                  case 0x2006:    /* SIX-PER-EM SPACE */
3977                  case 0x2007:    /* FIGURE SPACE */
3978                  case 0x2008:    /* PUNCTUATION SPACE */
3979                  case 0x2009:    /* THIN SPACE */
3980                  case 0x200A:    /* HAIR SPACE */
3981                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3982                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3983                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3984                  gotspace = TRUE;
3985                  break;
3986                  }
3987                if (gotspace == (ctype == OP_NOT_HSPACE)) break;
3988                eptr += len;
3989                }
3990              break;
3991    
3992              case OP_NOT_VSPACE:
3993              case OP_VSPACE:
3994              for (i = min; i < max; i++)
3995                {
3996                BOOL gotspace;
3997                int len = 1;
3998                if (eptr >= md->end_subject) break;
3999                GETCHARLEN(c, eptr, len);
4000                switch(c)
4001                  {
4002                  default: gotspace = FALSE; break;
4003                  case 0x0a:      /* LF */
4004                  case 0x0b:      /* VT */
4005                  case 0x0c:      /* FF */
4006                  case 0x0d:      /* CR */
4007                  case 0x85:      /* NEL */
4008                  case 0x2028:    /* LINE SEPARATOR */
4009                  case 0x2029:    /* PARAGRAPH SEPARATOR */
4010                  gotspace = TRUE;
4011                  break;
4012                  }
4013                if (gotspace == (ctype == OP_NOT_VSPACE)) break;
4014                eptr += len;
4015                }
4016              break;
4017    
4018            case OP_NOT_DIGIT:            case OP_NOT_DIGIT:
4019            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4020              {              {
# Line 3488  for (;;) Line 4090  for (;;)
4090          if (possessive) continue;          if (possessive) continue;
4091          for(;;)          for(;;)
4092            {            {
4093            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM46);
4094            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4095            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
4096            BACKCHAR(eptr);            BACKCHAR(eptr);
4097            }            }
4098          }          }
4099        else        else
4100  #endif  #endif  /* SUPPORT_UTF8 */
4101    
4102        /* Not UTF-8 mode */        /* Not UTF-8 mode */
4103          {          {
4104          switch(ctype)          switch(ctype)
4105            {            {
4106            case OP_ANY:            case OP_ANY:
4107            if ((ims & PCRE_DOTALL) == 0)            for (i = min; i < max; i++)
4108              {              {
4109              for (i = min; i < max; i++)              if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
4110                {              eptr++;
               if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;  
               eptr++;  
               }  
             break;  
4111              }              }
4112            /* For DOTALL case, fall through and treat as \C */            break;
4113    
4114              case OP_ALLANY:
4115            case OP_ANYBYTE:            case OP_ANYBYTE:
4116            c = max - min;            c = max - min;
4117            if (c > (unsigned int)(md->end_subject - eptr))            if (c > (unsigned int)(md->end_subject - eptr))
# Line 3532  for (;;) Line 4131  for (;;)
4131                }                }
4132              else              else
4133                {                {
4134                if (c != 0x000a && c != 0x000b && c != 0x000c && c != 0x0085)                if (c != 0x000a &&
4135                      (md->bsr_anycrlf ||
4136                        (c != 0x000b && c != 0x000c && c != 0x0085)))
4137                  break;                  break;
4138                eptr++;                eptr++;
4139                }                }
4140              }              }
4141            break;            break;
4142    
4143              case OP_NOT_HSPACE:
4144              for (i = min; i < max; i++)
4145                {
4146                if (eptr >= md->end_subject) break;
4147                c = *eptr;
4148                if (c == 0x09 || c == 0x20 || c == 0xa0) break;
4149                eptr++;
4150                }
4151              break;
4152    
4153              case OP_HSPACE:
4154              for (i = min; i < max; i++)
4155                {
4156                if (eptr >= md->end_subject) break;
4157                c = *eptr;
4158                if (c != 0x09 && c != 0x20 && c != 0xa0) break;
4159                eptr++;
4160                }
4161              break;
4162    
4163              case OP_NOT_VSPACE:
4164              for (i = min; i < max; i++)
4165                {
4166                if (eptr >= md->end_subject) break;
4167                c = *eptr;
4168                if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)
4169                  break;
4170                eptr++;
4171                }
4172              break;
4173    
4174              case OP_VSPACE:
4175              for (i = min; i < max; i++)
4176                {
4177                if (eptr >= md->end_subject) break;
4178                c = *eptr;
4179                if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85)
4180                  break;
4181                eptr++;
4182                }
4183              break;
4184    
4185            case OP_NOT_DIGIT:            case OP_NOT_DIGIT:
4186            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4187              {              {
# Line 3602  for (;;) Line 4245  for (;;)
4245          if (possessive) continue;          if (possessive) continue;
4246          while (eptr >= pp)          while (eptr >= pp)
4247            {            {
4248            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM47);
4249            eptr--;            eptr--;
4250            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4251            }            }
# Line 3628  for (;;) Line 4271  for (;;)
4271    
4272    }             /* End of main loop */    }             /* End of main loop */
4273  /* Control never reaches here */  /* Control never reaches here */
4274    
4275    
4276    /* When compiling to use the heap rather than the stack for recursive calls to
4277    match(), the RRETURN() macro jumps here. The number that is saved in
4278    frame->Xwhere indicates which label we actually want to return to. */
4279    
4280    #ifdef NO_RECURSE
4281    #define LBL(val) case val: goto L_RM##val;
4282    HEAP_RETURN:
4283    switch (frame->Xwhere)
4284      {
4285      LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)
4286      LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)
4287      LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)
4288      LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
4289      LBL(53) LBL(54)
4290    #ifdef SUPPORT_UTF8
4291      LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)
4292      LBL(32) LBL(34) LBL(42) LBL(46)
4293    #ifdef SUPPORT_UCP
4294      LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
4295    #endif  /* SUPPORT_UCP */
4296    #endif  /* SUPPORT_UTF8 */
4297      default:
4298      DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));
4299      return PCRE_ERROR_INTERNAL;
4300      }
4301    #undef LBL
4302    #endif  /* NO_RECURSE */
4303  }  }
4304    
4305    
# Line 3640  Undefine all the macros that were define Line 4312  Undefine all the macros that were define
4312  #ifdef NO_RECURSE  #ifdef NO_RECURSE
4313  #undef eptr  #undef eptr
4314  #undef ecode  #undef ecode
4315    #undef mstart
4316  #undef offset_top  #undef offset_top
4317  #undef ims  #undef ims
4318  #undef eptrb  #undef eptrb
# Line 3712  Returns:          > 0 => success; value Line 4385  Returns:          > 0 => success; value
4385                   < -1 => some kind of unexpected problem                   < -1 => some kind of unexpected problem
4386  */  */
4387    
4388  PCRE_EXP_DEFN int  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
4389  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
4390    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
4391    int offsetcount)    int offsetcount)
# Line 3737  const uschar *start_bits = NULL; Line 4410  const uschar *start_bits = NULL;
4410  USPTR start_match = (USPTR)subject + start_offset;  USPTR start_match = (USPTR)subject + start_offset;
4411  USPTR end_subject;  USPTR end_subject;
4412  USPTR req_byte_ptr = start_match - 1;  USPTR req_byte_ptr = start_match - 1;
 eptrblock eptrchain[EPTR_WORK_SIZE];  
4413    
4414  pcre_study_data internal_study;  pcre_study_data internal_study;
4415  const pcre_study_data *study;  const pcre_study_data *study;
# Line 3800  if (re->magic_number != MAGIC_NUMBER) Line 4472  if (re->magic_number != MAGIC_NUMBER)
4472  /* Set up other data */  /* Set up other data */
4473    
4474  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;
4475  startline = (re->options & PCRE_STARTLINE) != 0;  startline = (re->flags & PCRE_STARTLINE) != 0;
4476  firstline = (re->options & PCRE_FIRSTLINE) != 0;  firstline = (re->options & PCRE_FIRSTLINE) != 0;
4477    
4478  /* 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. */
# Line 3815  end_subject = md->end_subject; Line 4487  end_subject = md->end_subject;
4487    
4488  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
4489  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
4490    md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
4491    
4492  md->notbol = (options & PCRE_NOTBOL) != 0;  md->notbol = (options & PCRE_NOTBOL) != 0;
4493  md->noteol = (options & PCRE_NOTEOL) != 0;  md->noteol = (options & PCRE_NOTEOL) != 0;
# Line 3823  md->partial = (options & PCRE_PARTIAL) ! Line 4496  md->partial = (options & PCRE_PARTIAL) !
4496  md->hitend = FALSE;  md->hitend = FALSE;
4497    
4498  md->recursive = NULL;                   /* No recursion at top level */  md->recursive = NULL;                   /* No recursion at top level */
 md->eptrchain = eptrchain;              /* Make workspace generally available */  
4499    
4500  md->lcc = tables + lcc_offset;  md->lcc = tables + lcc_offset;
4501  md->ctypes = tables + ctypes_offset;  md->ctypes = tables + ctypes_offset;
4502    
4503    /* Handle different \R options. */
4504    
4505    switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
4506      {
4507      case 0:
4508      if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0)
4509        md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0;
4510      else
4511    #ifdef BSR_ANYCRLF
4512      md->bsr_anycrlf = TRUE;
4513    #else
4514      md->bsr_anycrlf = FALSE;
4515    #endif
4516      break;
4517    
4518      case PCRE_BSR_ANYCRLF:
4519      md->bsr_anycrlf = TRUE;
4520      break;
4521    
4522      case PCRE_BSR_UNICODE:
4523      md->bsr_anycrlf = FALSE;
4524      break;
4525    
4526      default: return PCRE_ERROR_BADNEWLINE;
4527      }
4528    
4529  /* Handle different types of newline. The three bits give eight cases. If  /* Handle different types of newline. The three bits give eight cases. If
4530  nothing is set at run time, whatever was used at compile time applies. */  nothing is set at run time, whatever was used at compile time applies. */
4531    
4532  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : (pcre_uint32)options) &  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options :
4533         PCRE_NEWLINE_BITS)          (pcre_uint32)options) & PCRE_NEWLINE_BITS)
4534    {    {
4535    case 0: newline = NEWLINE; break;   /* Compile-time default */    case 0: newline = NEWLINE; break;   /* Compile-time default */
4536    case PCRE_NEWLINE_CR: newline = '\r'; break;    case PCRE_NEWLINE_CR: newline = '\r'; break;
# Line 3871  else Line 4569  else
4569  /* 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
4570  moment. */  moment. */
4571    
4572  if (md->partial && (re->options & PCRE_NOPARTIAL) != 0)  if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
4573    return PCRE_ERROR_BADPARTIAL;    return PCRE_ERROR_BADPARTIAL;
4574    
4575  /* 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
# Line 3948  studied, there may be a bitmap of possib Line 4646  studied, there may be a bitmap of possib
4646    
4647  if (!anchored)  if (!anchored)
4648    {    {
4649    if ((re->options & PCRE_FIRSTSET) != 0)    if ((re->flags & PCRE_FIRSTSET) != 0)
4650      {      {
4651      first_byte = re->first_byte & 255;      first_byte = re->first_byte & 255;
4652      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)
# Line 3963  if (!anchored) Line 4661  if (!anchored)
4661  /* For anchored or unanchored matches, there may be a "last known required  /* For anchored or unanchored matches, there may be a "last known required
4662  character" set. */  character" set. */
4663    
4664  if ((re->options & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
4665    {    {
4666    req_byte = re->req_byte & 255;    req_byte = re->req_byte & 255;
4667    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;
# Line 3979  the loop runs just once. */ Line 4677  the loop runs just once. */
4677  for(;;)  for(;;)
4678    {    {
4679    USPTR save_end_subject = end_subject;    USPTR save_end_subject = end_subject;
4680      USPTR new_start_match;
4681    
4682    /* Reset the maximum number of extractions we might see. */    /* Reset the maximum number of extractions we might see. */
4683    
# Line 3998  for(;;) Line 4697  for(;;)
4697    if (firstline)    if (firstline)
4698      {      {
4699      USPTR t = start_match;      USPTR t = start_match;
4700    #ifdef SUPPORT_UTF8
4701        if (utf8)
4702          {
4703          while (t < md->end_subject && !IS_NEWLINE(t))
4704            {
4705            t++;
4706            while (t < end_subject && (*t & 0xc0) == 0x80) t++;
4707            }
4708          }
4709        else
4710    #endif
4711      while (t < md->end_subject && !IS_NEWLINE(t)) t++;      while (t < md->end_subject && !IS_NEWLINE(t)) t++;
4712      end_subject = t;      end_subject = t;
4713      }      }
4714    
4715    /* Now test for a unique first byte */    /* Now advance to a unique first byte if there is one. */
4716    
4717    if (first_byte >= 0)    if (first_byte >= 0)
4718      {      {
4719      if (first_byte_caseless)      if (first_byte_caseless)
4720        while (start_match < end_subject &&        while (start_match < end_subject && md->lcc[*start_match] != first_byte)
              md->lcc[*start_match] != first_byte)  
4721          start_match++;          start_match++;
4722      else      else
4723        while (start_match < end_subject && *start_match != first_byte)        while (start_match < end_subject && *start_match != first_byte)
4724          start_match++;          start_match++;
4725      }      }
4726    
4727    /* Or to just after a linebreak for a multiline match if possible */    /* Or to just after a linebreak for a multiline match */
4728    
4729    else if (startline)    else if (startline)
4730      {      {
4731      if (start_match > md->start_subject + start_offset)      if (start_match > md->start_subject + start_offset)
4732        {        {
4733        while (start_match <= end_subject && !WAS_NEWLINE(start_match))  #ifdef SUPPORT_UTF8
4734          if (utf8)
4735            {
4736            while (start_match < end_subject && !WAS_NEWLINE(start_match))
4737              {
4738              start_match++;
4739              while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
4740                start_match++;
4741              }
4742            }
4743          else
4744    #endif
4745          while (start_match < end_subject && !WAS_NEWLINE(start_match))
4746          start_match++;          start_match++;
4747    
4748        /* If we have just passed a CR and the newline option is ANY or ANYCRLF,        /* If we have just passed a CR and the newline option is ANY or ANYCRLF,
# Line 4036  for(;;) Line 4757  for(;;)
4757        }        }
4758      }      }
4759    
4760    /* Or to a non-unique first char after study */    /* Or to a non-unique first byte after study */
4761    
4762    else if (start_bits != NULL)    else if (start_bits != NULL)
4763      {      {
4764      while (start_match < end_subject)      while (start_match < end_subject)
4765        {        {
4766        register unsigned int c = *start_match;        register unsigned int c = *start_match;
4767        if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++; else break;        if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++;
4768            else break;
4769        }        }
4770      }      }
4771    
# Line 4119  for(;;) Line 4841  for(;;)
4841    
4842    /* OK, we can now run the match. */    /* OK, we can now run the match. */
4843    
4844    md->start_match = start_match;    md->start_match_ptr = start_match;
4845    md->match_call_count = 0;    md->match_call_count = 0;
4846    md->eptrn = 0;                          /* Next free eptrchain slot */    rc = match(start_match, md->start_code, start_match, 2, md, ims, NULL, 0, 0);
4847    rc = match(start_match, md->start_code, 2, md, ims, NULL, 0, 0);  
4848      switch(rc)
4849        {
4850        /* NOMATCH and PRUNE advance by one character. THEN at this level acts
4851        exactly like PRUNE. */
4852    
4853        case MATCH_NOMATCH:
4854        case MATCH_PRUNE:
4855        case MATCH_THEN:
4856        new_start_match = start_match + 1;
4857    #ifdef SUPPORT_UTF8
4858        if (utf8)
4859          while(new_start_match < end_subject && (*new_start_match & 0xc0) == 0x80)
4860            new_start_match++;
4861    #endif
4862        break;
4863    
4864        /* SKIP passes back the next starting point explicitly. */
4865    
4866        case MATCH_SKIP:
4867        new_start_match = md->start_match_ptr;
4868        break;
4869    
4870        /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */
4871    
4872        case MATCH_COMMIT:
4873        rc = MATCH_NOMATCH;
4874        goto ENDLOOP;
4875    
4876    /* Any return other than MATCH_NOMATCH breaks the loop. */      /* Any other return is some kind of error. */
4877    
4878    if (rc != MATCH_NOMATCH) break;      default:
4879        goto ENDLOOP;
4880        }
4881    
4882      /* Control reaches here for the various types of "no match at this point"
4883      result. Reset the code to MATCH_NOMATCH for subsequent checking. */
4884    
4885      rc = MATCH_NOMATCH;
4886    
4887    /* If PCRE_FIRSTLINE is set, the match must happen before or at the first    /* If PCRE_FIRSTLINE is set, the match must happen before or at the first
4888    newline in the subject (though it may continue over the newline). Therefore,    newline in the subject (though it may continue over the newline). Therefore,
# Line 4134  for(;;) Line 4890  for(;;)
4890    
4891    if (firstline && IS_NEWLINE(start_match)) break;    if (firstline && IS_NEWLINE(start_match)) break;
4892    
4893    /* Advance the match position by one character. */    /* Advance to new matching position */
4894    
4895    start_match++;    start_match = new_start_match;
 #ifdef SUPPORT_UTF8  
   if (utf8)  
     while(start_match < end_subject && (*start_match & 0xc0) == 0x80)  
       start_match++;  
 #endif  
4896    
4897    /* Break the loop if the pattern is anchored or if we have passed the end of    /* Break the loop if the pattern is anchored or if we have passed the end of
4898    the subject. */    the subject. */
4899    
4900    if (anchored || start_match > end_subject) break;    if (anchored || start_match > end_subject) break;
4901    
4902    /* If we have just passed a CR and the newline option is CRLF or ANY or    /* If we have just passed a CR and we are now at a LF, and the pattern does
4903    ANYCRLF, and we are now at a LF, advance the match position by one more    not contain any explicit matches for \r or \n, and the newline option is CRLF
4904    character. */    or ANY or ANYCRLF, advance the match position by one more character. */
4905    
4906    if (start_match[-1] == '\r' &&    if (start_match[-1] == '\r' &&
4907         (md->nltype == NLTYPE_ANY ||        start_match < end_subject &&
4908          md->nltype == NLTYPE_ANYCRLF ||        *start_match == '\n' &&
4909          md->nllen == 2) &&        (re->flags & PCRE_HASCRORLF) == 0 &&
4910         start_match < end_subject &&          (md->nltype == NLTYPE_ANY ||
4911         *start_match == '\n')           md->nltype == NLTYPE_ANYCRLF ||
4912             md->nllen == 2))
4913      start_match++;      start_match++;
4914    
4915    }   /* End of for(;;) "bumpalong" loop */    }   /* End of for(;;) "bumpalong" loop */
# Line 4167  for(;;) Line 4919  for(;;)
4919  /* We reach here when rc is not MATCH_NOMATCH, or if one of the stopping  /* We reach here when rc is not MATCH_NOMATCH, or if one of the stopping
4920  conditions is true:  conditions is true:
4921    
4922  (1) The pattern is anchored;  (1) The pattern is anchored or the match was failed by (*COMMIT);
4923    
4924  (2) We are past the end of the subject;  (2) We are past the end of the subject;
4925    
# Line 4182  processing, copy those that we can. In t Line 4934  processing, copy those that we can. In t
4934  certain parts of the pattern were not used, even though there are more  certain parts of the pattern were not used, even though there are more
4935  capturing parentheses than vector slots. */  capturing parentheses than vector slots. */
4936    
4937    ENDLOOP:
4938    
4939  if (rc == MATCH_MATCH)  if (rc == MATCH_MATCH)
4940    {    {
4941    if (using_temporary_offsets)    if (using_temporary_offsets)
# Line 4202  if (rc == MATCH_MATCH) Line 4956  if (rc == MATCH_MATCH)
4956    
4957    rc = md->offset_overflow? 0 : md->end_offset_top/2;    rc = md->offset_overflow? 0 : md->end_offset_top/2;
4958    
4959    /* If there is space, set up the whole thing as substring 0. */    /* If there is space, set up the whole thing as substring 0. The value of
4960      md->start_match_ptr might be modified if \K was encountered on the success
4961      matching path. */
4962    
4963    if (offsetcount < 2) rc = 0; else    if (offsetcount < 2) rc = 0; else
4964      {      {
4965      offsets[0] = start_match - md->start_subject;      offsets[0] = md->start_match_ptr - md->start_subject;
4966      offsets[1] = md->end_match_ptr - md->start_subject;      offsets[1] = md->end_match_ptr - md->start_subject;
4967      }      }
4968    

Legend:
Removed from v.150  
changed lines
  Added in v.371

  ViewVC Help
Powered by ViewVC 1.1.5