/[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 227 by ph10, Tue Aug 21 15:00:15 2007 UTC revision 402 by ph10, Sat Mar 21 17:26:03 2009 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2007 University of Cambridge             Copyright (c) 1997-2009 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 43  pattern matching using an NFA algorithm, Line 43  pattern matching using an NFA algorithm,
43  possible. There are also some static supporting functions. */  possible. There are also some static supporting functions. */
44    
45  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
46  #include <config.h>  #include "config.h"
47  #endif  #endif
48    
49  #define NLBLOCK md             /* Block containing newline information */  #define NLBLOCK md             /* Block containing newline information */
# Line 158  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 308  typedef struct heapframe { Line 334  typedef struct heapframe {
334    /* Function local variables */    /* Function local variables */
335    
336    const uschar *Xcallpat;    const uschar *Xcallpat;
337    #ifdef SUPPORT_UTF8
338    const uschar *Xcharptr;    const uschar *Xcharptr;
339    #endif
340    const uschar *Xdata;    const uschar *Xdata;
341    const uschar *Xnext;    const uschar *Xnext;
342    const uschar *Xpp;    const uschar *Xpp;
# Line 535  int oclength; Line 563  int oclength;
563  uschar occhars[8];  uschar occhars[8];
564  #endif  #endif
565    
566    int codelink;
567    int condcode;
568  int ctype;  int ctype;
569  int length;  int length;
570  int max;  int max;
# Line 609  for (;;) Line 639  for (;;)
639    {    {
640    minimize = possessive = FALSE;    minimize = possessive = FALSE;
641    op = *ecode;    op = *ecode;
642    
643    /* For partial matching, remember if we ever hit the end of the subject after    /* For partial matching, remember if we ever hit the end of the subject after
644    matching at least one subject character. */    matching at least one subject character. */
645    
# Line 761  for (;;) Line 791  for (;;)
791    
792      case OP_COND:      case OP_COND:
793      case OP_SCOND:      case OP_SCOND:
794      if (ecode[LINK_SIZE+1] == OP_RREF)         /* Recursion test */      codelink= GET(ecode, 1);
795    
796        /* Because of the way auto-callout works during compile, a callout item is
797        inserted between OP_COND and an assertion condition. */
798    
799        if (ecode[LINK_SIZE+1] == OP_CALLOUT)
800          {
801          if (pcre_callout != NULL)
802            {
803            pcre_callout_block cb;
804            cb.version          = 1;   /* Version 1 of the callout block */
805            cb.callout_number   = ecode[LINK_SIZE+2];
806            cb.offset_vector    = md->offset_vector;
807            cb.subject          = (PCRE_SPTR)md->start_subject;
808            cb.subject_length   = md->end_subject - md->start_subject;
809            cb.start_match      = mstart - md->start_subject;
810            cb.current_position = eptr - md->start_subject;
811            cb.pattern_position = GET(ecode, LINK_SIZE + 3);
812            cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
813            cb.capture_top      = offset_top/2;
814            cb.capture_last     = md->capture_last;
815            cb.callout_data     = md->callout_data;
816            if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);
817            if (rrc < 0) RRETURN(rrc);
818            }
819          ecode += _pcre_OP_lengths[OP_CALLOUT];
820          }
821    
822        condcode = ecode[LINK_SIZE+1];
823    
824        /* Now see what the actual condition is */
825    
826        if (condcode == OP_RREF)         /* Recursion test */
827        {        {
828        offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/        offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/
829        condition = md->recursive != NULL &&        condition = md->recursive != NULL &&
# Line 769  for (;;) Line 831  for (;;)
831        ecode += condition? 3 : GET(ecode, 1);        ecode += condition? 3 : GET(ecode, 1);
832        }        }
833    
834      else if (ecode[LINK_SIZE+1] == OP_CREF)    /* Group used test */      else if (condcode == OP_CREF)    /* Group used test */
835        {        {
836        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
837        condition = offset < offset_top && md->offset_vector[offset] >= 0;        condition = offset < offset_top && md->offset_vector[offset] >= 0;
838        ecode += condition? 3 : GET(ecode, 1);        ecode += condition? 3 : GET(ecode, 1);
839        }        }
840    
841      else if (ecode[LINK_SIZE+1] == OP_DEF)     /* DEFINE - always false */      else if (condcode == OP_DEF)     /* DEFINE - always false */
842        {        {
843        condition = FALSE;        condition = FALSE;
844        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
# Line 803  for (;;) Line 865  for (;;)
865        else        else
866          {          {
867          condition = FALSE;          condition = FALSE;
868          ecode += GET(ecode, 1);          ecode += codelink;
869          }          }
870        }        }
871    
# Line 826  for (;;) Line 888  for (;;)
888          goto TAIL_RECURSE;          goto TAIL_RECURSE;
889          }          }
890        }        }
891      else                         /* Condition false & no 2nd alternative */      else                         /* Condition false & no alternative */
892        {        {
893        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
894        }        }
# Line 1049  for (;;) Line 1111  for (;;)
1111          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1112            {            {
1113            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1114              if (new_recursive.offset_save != stacksave)
1115                (pcre_free)(new_recursive.offset_save);
1116            RRETURN(rrc);            RRETURN(rrc);
1117            }            }
1118    
# Line 1148  for (;;) Line 1212  for (;;)
1212      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1213      break;      break;
1214    
1215      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1216      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
1217      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
1218      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
1219      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1220    
1221      case OP_BRAZERO:      case OP_BRAZERO:
1222        {        {
# Line 1174  for (;;) Line 1238  for (;;)
1238        }        }
1239      break;      break;
1240    
1241        case OP_SKIPZERO:
1242          {
1243          next = ecode+1;
1244          do next += GET(next,1); while (*next == OP_ALT);
1245          ecode = next + 1 + LINK_SIZE;
1246          }
1247        break;
1248    
1249      /* End of a group, repeated or non-repeating. */      /* End of a group, repeated or non-repeating. */
1250    
1251      case OP_KET:      case OP_KET:
# Line 1421  for (;;) Line 1493  for (;;)
1493      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1494    
1495      case OP_ANY:      case OP_ANY:
1496      if ((ims & PCRE_DOTALL) == 0)      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
1497        {      /* Fall through */
1498        if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);  
1499        }      case OP_ALLANY:
1500      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);
1501      if (utf8)      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
       while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
1502      ecode++;      ecode++;
1503      break;      break;
1504    
# Line 1526  for (;;) Line 1597  for (;;)
1597        case 0x000d:        case 0x000d:
1598        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1599        break;        break;
1600    
1601        case 0x000a:        case 0x000a:
1602          break;
1603    
1604        case 0x000b:        case 0x000b:
1605        case 0x000c:        case 0x000c:
1606        case 0x0085:        case 0x0085:
1607        case 0x2028:        case 0x2028:
1608        case 0x2029:        case 0x2029:
1609          if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
1610        break;        break;
1611        }        }
1612      ecode++;      ecode++;
# Line 1642  for (;;) Line 1717  for (;;)
1717      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1718      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1719        {        {
1720        int chartype, script;        const ucd_record *prop = GET_UCD(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1721    
1722        switch(ecode[1])        switch(ecode[1])
1723          {          {
# Line 1652  for (;;) Line 1726  for (;;)
1726          break;          break;
1727    
1728          case PT_LAMP:          case PT_LAMP:
1729          if ((chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
1730               chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
1731               chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
1732            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1733           break;           break;
1734    
1735          case PT_GC:          case PT_GC:
1736          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
1737            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1738          break;          break;
1739    
1740          case PT_PC:          case PT_PC:
1741          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
1742            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1743          break;          break;
1744    
1745          case PT_SC:          case PT_SC:
1746          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
1747            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1748          break;          break;
1749    
# Line 1688  for (;;) Line 1762  for (;;)
1762      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1763      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1764        {        {
1765        int chartype, script;        int category = UCD_CATEGORY(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1766        if (category == ucp_M) RRETURN(MATCH_NOMATCH);        if (category == ucp_M) RRETURN(MATCH_NOMATCH);
1767        while (eptr < md->end_subject)        while (eptr < md->end_subject)
1768          {          {
# Line 1698  for (;;) Line 1771  for (;;)
1771            {            {
1772            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
1773            }            }
1774          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
1775          if (category != ucp_M) break;          if (category != ucp_M) break;
1776          eptr += len;          eptr += len;
1777          }          }
# Line 1719  for (;;) Line 1792  for (;;)
1792      case OP_REF:      case OP_REF:
1793        {        {
1794        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
1795        ecode += 3;                                 /* Advance past item */        ecode += 3;
1796    
1797        /* If the reference is unset, set the length to be longer than the amount        /* If the reference is unset, there are two possibilities:
1798        of subject left; this ensures that every attempt at a match fails. We  
1799        can't just fail here, because of the possibility of quantifiers with zero        (a) In the default, Perl-compatible state, set the length to be longer
1800        minima. */        than the amount of subject left; this ensures that every attempt at a
1801          match fails. We can't just fail here, because of the possibility of
1802        length = (offset >= offset_top || md->offset_vector[offset] < 0)?        quantifiers with zero minima.
1803          md->end_subject - eptr + 1 :  
1804          md->offset_vector[offset+1] - md->offset_vector[offset];        (b) If the JavaScript compatibility flag is set, set the length to zero
1805          so that the back reference matches an empty string.
1806    
1807          Otherwise, set the length to the length of what was matched by the
1808          referenced subpattern. */
1809    
1810          if (offset >= offset_top || md->offset_vector[offset] < 0)
1811            length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
1812          else
1813            length = md->offset_vector[offset+1] - md->offset_vector[offset];
1814    
1815        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
1816    
# Line 2003  for (;;) Line 2085  for (;;)
2085    
2086    
2087      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2088      in UTF-8 mode, because that's the only time it is compiled. */      when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8
2089        mode, because Unicode properties are supported in non-UTF-8 mode. */
2090    
2091  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2092      case OP_XCLASS:      case OP_XCLASS:
# Line 2045  for (;;) Line 2128  for (;;)
2128        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2129          {          {
2130          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2131          GETCHARINC(c, eptr);          GETCHARINCTEST(c, eptr);
2132          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2133          }          }
2134    
# Line 2064  for (;;) Line 2147  for (;;)
2147            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2148            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2149            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2150            GETCHARINC(c, eptr);            GETCHARINCTEST(c, eptr);
2151            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2152            }            }
2153          /* Control never gets here */          /* Control never gets here */
# Line 2079  for (;;) Line 2162  for (;;)
2162            {            {
2163            int len = 1;            int len = 1;
2164            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
2165            GETCHARLEN(c, eptr, len);            GETCHARLENTEST(c, eptr, len);
2166            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2167            eptr += len;            eptr += len;
2168            }            }
# Line 2154  for (;;) Line 2237  for (;;)
2237          if (fc != dc)          if (fc != dc)
2238            {            {
2239  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2240            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2241  #endif  #endif
2242              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2243            }            }
# Line 2245  for (;;) Line 2328  for (;;)
2328  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2329          unsigned int othercase;          unsigned int othercase;
2330          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2331              (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR)              (othercase = UCD_OTHERCASE(fc)) != fc)
2332            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2333          else oclength = 0;          else oclength = 0;
2334  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
# Line 2565  for (;;) Line 2648  for (;;)
2648              {              {
2649              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
2650              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2651                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2652              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2653              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
2654              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
2655                RRETURN(MATCH_NOMATCH);  
2656              }              }
2657            }            }
2658          else          else
# Line 2674  for (;;) Line 2758  for (;;)
2758              {              {
2759              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
2760              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2761                if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2762              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2763              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
2764              }              }
2765            }            }
2766          else          else
# Line 2850  for (;;) Line 2934  for (;;)
2934              {              {
2935              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2936              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
2937              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
2938              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
2939                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
2940                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2863  for (;;) Line 2947  for (;;)
2947              {              {
2948              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2949              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
2950              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
2951              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
2952                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2953              }              }
# Line 2874  for (;;) Line 2958  for (;;)
2958              {              {
2959              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2960              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
2961              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
2962              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
2963                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2964              }              }
# Line 2885  for (;;) Line 2969  for (;;)
2969              {              {
2970              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2971              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
2972              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
2973              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
2974                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2975              }              }
# Line 2904  for (;;) Line 2988  for (;;)
2988          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2989            {            {
2990            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
2991            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
2992            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
2993            while (eptr < md->end_subject)            while (eptr < md->end_subject)
2994              {              {
# Line 2913  for (;;) Line 2997  for (;;)
2997                {                {
2998                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
2999                }                }
3000              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3001              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3002              eptr += len;              eptr += len;
3003              }              }
# Line 2931  for (;;) Line 3015  for (;;)
3015          case OP_ANY:          case OP_ANY:
3016          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3017            {            {
3018            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject || IS_NEWLINE(eptr))
                ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))  
3019              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3020            eptr++;            eptr++;
3021            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3022            }            }
3023          break;          break;
3024    
3025            case OP_ALLANY:
3026            for (i = 1; i <= min; i++)
3027              {
3028              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3029              eptr++;
3030              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3031              }
3032            break;
3033    
3034          case OP_ANYBYTE:          case OP_ANYBYTE:
3035          eptr += min;          eptr += min;
3036          break;          break;
# Line 2954  for (;;) Line 3046  for (;;)
3046              case 0x000d:              case 0x000d:
3047              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3048              break;              break;
3049    
3050              case 0x000a:              case 0x000a:
3051                break;
3052    
3053              case 0x000b:              case 0x000b:
3054              case 0x000c:              case 0x000c:
3055              case 0x0085:              case 0x0085:
3056              case 0x2028:              case 0x2028:
3057              case 0x2029:              case 0x2029:
3058                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3059              break;              break;
3060              }              }
3061            }            }
# Line 3143  for (;;) Line 3239  for (;;)
3239        switch(ctype)        switch(ctype)
3240          {          {
3241          case OP_ANY:          case OP_ANY:
3242          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3243            {            {
3244            for (i = 1; i <= min; i++)            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3245              {            eptr++;
             if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);  
             eptr++;  
             }  
3246            }            }
3247          else eptr += min;          break;
3248    
3249            case OP_ALLANY:
3250            eptr += min;
3251          break;          break;
3252    
3253          case OP_ANYBYTE:          case OP_ANYBYTE:
# Line 3172  for (;;) Line 3268  for (;;)
3268              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3269              break;              break;
3270              case 0x000a:              case 0x000a:
3271                break;
3272    
3273              case 0x000b:              case 0x000b:
3274              case 0x000c:              case 0x000c:
3275              case 0x0085:              case 0x0085:
3276                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3277              break;              break;
3278              }              }
3279            }            }
# Line 3314  for (;;) Line 3413  for (;;)
3413              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3414              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3415              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3416              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3417              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3418                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3419                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 3329  for (;;) Line 3428  for (;;)
3428              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3429              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3430              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3431              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3432              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3433                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3434              }              }
# Line 3342  for (;;) Line 3441  for (;;)
3441              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3442              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3443              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3444              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3445              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3446                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3447              }              }
# Line 3355  for (;;) Line 3454  for (;;)
3454              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3455              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3456              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3457              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3458              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3459                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3460              }              }
# Line 3377  for (;;) Line 3476  for (;;)
3476            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3477            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
3478            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3479            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3480            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3481            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3482              {              {
# Line 3386  for (;;) Line 3485  for (;;)
3485                {                {
3486                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3487                }                }
3488              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3489              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3490              eptr += len;              eptr += len;
3491              }              }
# Line 3405  for (;;) Line 3504  for (;;)
3504            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
3505            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3506            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max || eptr >= md->end_subject ||
3507                 (ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 &&                 (ctype == OP_ANY && IS_NEWLINE(eptr)))
                 IS_NEWLINE(eptr)))  
3508              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3509    
3510            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3511            switch(ctype)            switch(ctype)
3512              {              {
3513              case OP_ANY:        /* This is the DOTALL case */              case OP_ANY:        /* This is the non-NL case */
3514              break;              case OP_ALLANY:
   
3515              case OP_ANYBYTE:              case OP_ANYBYTE:
3516              break;              break;
3517    
# Line 3426  for (;;) Line 3523  for (;;)
3523                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3524                break;                break;
3525                case 0x000a:                case 0x000a:
3526                  break;
3527    
3528                case 0x000b:                case 0x000b:
3529                case 0x000c:                case 0x000c:
3530                case 0x0085:                case 0x0085:
3531                case 0x2028:                case 0x2028:
3532                case 0x2029:                case 0x2029:
3533                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3534                break;                break;
3535                }                }
3536              break;              break;
# Line 3563  for (;;) Line 3663  for (;;)
3663            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
3664            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3665            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max || eptr >= md->end_subject ||
3666                 ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))                 (ctype == OP_ANY && IS_NEWLINE(eptr)))
3667              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3668    
3669            c = *eptr++;            c = *eptr++;
3670            switch(ctype)            switch(ctype)
3671              {              {
3672              case OP_ANY:   /* This is the DOTALL case */              case OP_ANY:     /* This is the non-NL case */
3673              break;              case OP_ALLANY:
   
3674              case OP_ANYBYTE:              case OP_ANYBYTE:
3675              break;              break;
3676    
# Line 3582  for (;;) Line 3681  for (;;)
3681                case 0x000d:                case 0x000d:
3682                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3683                break;                break;
3684    
3685                case 0x000a:                case 0x000a:
3686                  break;
3687    
3688                case 0x000b:                case 0x000b:
3689                case 0x000c:                case 0x000c:
3690                case 0x0085:                case 0x0085:
3691                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3692                break;                break;
3693                }                }
3694              break;              break;
# Line 3700  for (;;) Line 3803  for (;;)
3803              int len = 1;              int len = 1;
3804              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3805              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3806              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3807              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3808                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3809                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 3715  for (;;) Line 3818  for (;;)
3818              int len = 1;              int len = 1;
3819              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3820              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3821              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3822              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3823                break;                break;
3824              eptr+= len;              eptr+= len;
# Line 3728  for (;;) Line 3831  for (;;)
3831              int len = 1;              int len = 1;
3832              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3833              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3834              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3835              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3836                break;                break;
3837              eptr+= len;              eptr+= len;
# Line 3741  for (;;) Line 3844  for (;;)
3844              int len = 1;              int len = 1;
3845              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
3846              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
3847              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3848              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3849                break;                break;
3850              eptr+= len;              eptr+= len;
# Line 3770  for (;;) Line 3873  for (;;)
3873            {            {
3874            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
3875            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3876            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3877            if (prop_category == ucp_M) break;            if (prop_category == ucp_M) break;
3878            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3879              {              {
# Line 3779  for (;;) Line 3882  for (;;)
3882                {                {
3883                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3884                }                }
3885              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3886              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3887              eptr += len;              eptr += len;
3888              }              }
# Line 3801  for (;;) Line 3904  for (;;)
3904                BACKCHAR(eptr);                BACKCHAR(eptr);
3905                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
3906                }                }
3907              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3908              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3909              eptr--;              eptr--;
3910              }              }
# Line 3821  for (;;) Line 3924  for (;;)
3924            case OP_ANY:            case OP_ANY:
3925            if (max < INT_MAX)            if (max < INT_MAX)
3926              {              {
3927              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  
3928                {                {
3929                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
3930                  {                eptr++;
3931                  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++;  
                 }  
3932                }                }
3933              }              }
3934    
# Line 3845  for (;;) Line 3936  for (;;)
3936    
3937            else            else
3938              {              {
3939              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
3940                {                {
3941                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
3942                  {                eptr++;
3943                  if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 eptr++;  
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
3944                }                }
3945              else              }
3946              break;
3947    
3948              case OP_ALLANY:
3949              if (max < INT_MAX)
3950                {
3951                for (i = min; i < max; i++)
3952                {                {
3953                eptr = md->end_subject;                if (eptr >= md->end_subject) break;
3954                  eptr++;
3955                  while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3956                }                }
3957              }              }
3958              else eptr = md->end_subject;   /* Unlimited UTF-8 repeat */
3959            break;            break;
3960    
3961            /* The byte case is the same as non-UTF8 */            /* The byte case is the same as non-UTF8 */
# Line 3883  for (;;) Line 3980  for (;;)
3980                }                }
3981              else              else
3982                {                {
3983                if (c != 0x000a && c != 0x000b && c != 0x000c &&                if (c != 0x000a &&
3984                    c != 0x0085 && c != 0x2028 && c != 0x2029)                    (md->bsr_anycrlf ||
3985                       (c != 0x000b && c != 0x000c &&
3986                        c != 0x0085 && c != 0x2028 && c != 0x2029)))
3987                  break;                  break;
3988                eptr += len;                eptr += len;
3989                }                }
# Line 4044  for (;;) Line 4143  for (;;)
4143          switch(ctype)          switch(ctype)
4144            {            {
4145            case OP_ANY:            case OP_ANY:
4146            if ((ims & PCRE_DOTALL) == 0)            for (i = min; i < max; i++)
4147              {              {
4148              for (i = min; i < max; i++)              if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
4149                {              eptr++;
               if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;  
               eptr++;  
               }  
             break;  
4150              }              }
4151            /* For DOTALL case, fall through and treat as \C */            break;
4152    
4153              case OP_ALLANY:
4154            case OP_ANYBYTE:            case OP_ANYBYTE:
4155            c = max - min;            c = max - min;
4156            if (c > (unsigned int)(md->end_subject - eptr))            if (c > (unsigned int)(md->end_subject - eptr))
# Line 4074  for (;;) Line 4170  for (;;)
4170                }                }
4171              else              else
4172                {                {
4173                if (c != 0x000a && c != 0x000b && c != 0x000c && c != 0x0085)                if (c != 0x000a &&
4174                      (md->bsr_anycrlf ||
4175                        (c != 0x000b && c != 0x000c && c != 0x0085)))
4176                  break;                  break;
4177                eptr++;                eptr++;
4178                }                }
# Line 4224  HEAP_RETURN: Line 4322  HEAP_RETURN:
4322  switch (frame->Xwhere)  switch (frame->Xwhere)
4323    {    {
4324    LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)    LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)
4325    LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(16)    LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)
4326    LBL(17) LBL(18) LBL(19) LBL(20) LBL(21) LBL(22) LBL(23) LBL(24)    LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)
4327    LBL(25) LBL(26) LBL(27) LBL(28) LBL(29) LBL(30) LBL(31) LBL(32)    LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
4328    LBL(33) LBL(34) LBL(35) LBL(36) LBL(37) LBL(38) LBL(39) LBL(40)    LBL(53) LBL(54)
4329    LBL(41) LBL(42) LBL(43) LBL(44) LBL(45) LBL(46) LBL(47) LBL(48)  #ifdef SUPPORT_UTF8
4330    LBL(49) LBL(50) LBL(51) LBL(52) LBL(53) LBL(54)    LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)
4331      LBL(32) LBL(34) LBL(42) LBL(46)
4332    #ifdef SUPPORT_UCP
4333      LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
4334    #endif  /* SUPPORT_UCP */
4335    #endif  /* SUPPORT_UTF8 */
4336    default:    default:
4337    DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));    DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));
4338    return PCRE_ERROR_INTERNAL;    return PCRE_ERROR_INTERNAL;
# Line 4321  Returns:          > 0 => success; value Line 4424  Returns:          > 0 => success; value
4424                   < -1 => some kind of unexpected problem                   < -1 => some kind of unexpected problem
4425  */  */
4426    
4427  PCRE_EXP_DEFN int  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
4428  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
4429    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
4430    int offsetcount)    int offsetcount)
# Line 4408  if (re->magic_number != MAGIC_NUMBER) Line 4511  if (re->magic_number != MAGIC_NUMBER)
4511  /* Set up other data */  /* Set up other data */
4512    
4513  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;
4514  startline = (re->options & PCRE_STARTLINE) != 0;  startline = (re->flags & PCRE_STARTLINE) != 0;
4515  firstline = (re->options & PCRE_FIRSTLINE) != 0;  firstline = (re->options & PCRE_FIRSTLINE) != 0;
4516    
4517  /* 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 4423  end_subject = md->end_subject; Line 4526  end_subject = md->end_subject;
4526    
4527  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
4528  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
4529    md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
4530    
4531  md->notbol = (options & PCRE_NOTBOL) != 0;  md->notbol = (options & PCRE_NOTBOL) != 0;
4532  md->noteol = (options & PCRE_NOTEOL) != 0;  md->noteol = (options & PCRE_NOTEOL) != 0;
# Line 4435  md->recursive = NULL; Line 4539  md->recursive = NULL;
4539  md->lcc = tables + lcc_offset;  md->lcc = tables + lcc_offset;
4540  md->ctypes = tables + ctypes_offset;  md->ctypes = tables + ctypes_offset;
4541    
4542    /* Handle different \R options. */
4543    
4544    switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
4545      {
4546      case 0:
4547      if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0)
4548        md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0;
4549      else
4550    #ifdef BSR_ANYCRLF
4551      md->bsr_anycrlf = TRUE;
4552    #else
4553      md->bsr_anycrlf = FALSE;
4554    #endif
4555      break;
4556    
4557      case PCRE_BSR_ANYCRLF:
4558      md->bsr_anycrlf = TRUE;
4559      break;
4560    
4561      case PCRE_BSR_UNICODE:
4562      md->bsr_anycrlf = FALSE;
4563      break;
4564    
4565      default: return PCRE_ERROR_BADNEWLINE;
4566      }
4567    
4568  /* Handle different types of newline. The three bits give eight cases. If  /* Handle different types of newline. The three bits give eight cases. If
4569  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. */
4570    
4571  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : (pcre_uint32)options) &  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options :
4572         PCRE_NEWLINE_BITS)          (pcre_uint32)options) & PCRE_NEWLINE_BITS)
4573    {    {
4574    case 0: newline = NEWLINE; break;   /* Compile-time default */    case 0: newline = NEWLINE; break;   /* Compile-time default */
4575    case PCRE_NEWLINE_CR: newline = '\r'; break;    case PCRE_NEWLINE_CR: newline = CHAR_CR; break;
4576    case PCRE_NEWLINE_LF: newline = '\n'; break;    case PCRE_NEWLINE_LF: newline = CHAR_NL; break;
4577    case PCRE_NEWLINE_CR+    case PCRE_NEWLINE_CR+
4578         PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;         PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break;
4579    case PCRE_NEWLINE_ANY: newline = -1; break;    case PCRE_NEWLINE_ANY: newline = -1; break;
4580    case PCRE_NEWLINE_ANYCRLF: newline = -2; break;    case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
4581    default: return PCRE_ERROR_BADNEWLINE;    default: return PCRE_ERROR_BADNEWLINE;
# Line 4478  else Line 4608  else
4608  /* 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
4609  moment. */  moment. */
4610    
4611  if (md->partial && (re->options & PCRE_NOPARTIAL) != 0)  if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
4612    return PCRE_ERROR_BADPARTIAL;    return PCRE_ERROR_BADPARTIAL;
4613    
4614  /* 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 4555  studied, there may be a bitmap of possib Line 4685  studied, there may be a bitmap of possib
4685    
4686  if (!anchored)  if (!anchored)
4687    {    {
4688    if ((re->options & PCRE_FIRSTSET) != 0)    if ((re->flags & PCRE_FIRSTSET) != 0)
4689      {      {
4690      first_byte = re->first_byte & 255;      first_byte = re->first_byte & 255;
4691      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)
# Line 4570  if (!anchored) Line 4700  if (!anchored)
4700  /* For anchored or unanchored matches, there may be a "last known required  /* For anchored or unanchored matches, there may be a "last known required
4701  character" set. */  character" set. */
4702    
4703  if ((re->options & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
4704    {    {
4705    req_byte = re->req_byte & 255;    req_byte = re->req_byte & 255;
4706    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;
# Line 4597  for(;;) Line 4727  for(;;)
4727      while (iptr < iend) *iptr++ = -1;      while (iptr < iend) *iptr++ = -1;
4728      }      }
4729    
4730    /* Advance to a unique first char if possible. If firstline is TRUE, the    /* If firstline is TRUE, the start of the match is constrained to the first
4731    start of the match is constrained to the first line of a multiline string.    line of a multiline string. That is, the match must be before or at the first
4732    That is, the match must be before or at the first newline. Implement this by    newline. Implement this by temporarily adjusting end_subject so that we stop
4733    temporarily adjusting end_subject so that we stop scanning at a newline. If    scanning at a newline. If the match fails at the newline, later code breaks
4734    the match fails at the newline, later code breaks this loop. */    this loop. */
4735    
4736    if (firstline)    if (firstline)
4737      {      {
4738      USPTR t = start_match;      USPTR t = start_match;
4739    #ifdef SUPPORT_UTF8
4740        if (utf8)
4741          {
4742          while (t < md->end_subject && !IS_NEWLINE(t))
4743            {
4744            t++;
4745            while (t < end_subject && (*t & 0xc0) == 0x80) t++;
4746            }
4747          }
4748        else
4749    #endif
4750      while (t < md->end_subject && !IS_NEWLINE(t)) t++;      while (t < md->end_subject && !IS_NEWLINE(t)) t++;
4751      end_subject = t;      end_subject = t;
4752      }      }
4753    
4754    /* Now test for a unique first byte */    /* There are some optimizations that avoid running the match if a known
4755      starting point is not found, or if a known later character is not present.
4756      However, there is an option that disables these, for testing and for ensuring
4757      that all callouts do actually occur. */
4758    
4759    if (first_byte >= 0)    if ((options & PCRE_NO_START_OPTIMIZE) == 0)
4760      {      {
4761      if (first_byte_caseless)      /* Advance to a unique first byte if there is one. */
       while (start_match < end_subject &&  
              md->lcc[*start_match] != first_byte)  
         start_match++;  
     else  
       while (start_match < end_subject && *start_match != first_byte)  
         start_match++;  
     }  
4762    
4763    /* Or to just after a linebreak for a multiline match if possible */      if (first_byte >= 0)
4764          {
4765          if (first_byte_caseless)
4766            while (start_match < end_subject && md->lcc[*start_match] != first_byte)
4767              start_match++;
4768          else
4769            while (start_match < end_subject && *start_match != first_byte)
4770              start_match++;
4771          }
4772    
4773    else if (startline)      /* Or to just after a linebreak for a multiline match */
4774      {  
4775      if (start_match > md->start_subject + start_offset)      else if (startline)
4776        {        {
4777        while (start_match <= end_subject && !WAS_NEWLINE(start_match))        if (start_match > md->start_subject + start_offset)
4778          start_match++;          {
4779    #ifdef SUPPORT_UTF8
4780            if (utf8)
4781              {
4782              while (start_match < end_subject && !WAS_NEWLINE(start_match))
4783                {
4784                start_match++;
4785                while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
4786                  start_match++;
4787                }
4788              }
4789            else
4790    #endif
4791            while (start_match < end_subject && !WAS_NEWLINE(start_match))
4792              start_match++;
4793    
4794            /* If we have just passed a CR and the newline option is ANY or ANYCRLF,
4795            and we are now at a LF, advance the match position by one more character.
4796            */
4797    
4798        /* If we have just passed a CR and the newline option is ANY or ANYCRLF,          if (start_match[-1] == CHAR_CR &&
4799        and we are now at a LF, advance the match position by one more character.               (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&
4800        */               start_match < end_subject &&
4801                 *start_match == CHAR_NL)
4802        if (start_match[-1] == '\r' &&            start_match++;
4803             (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&          }
            start_match < end_subject &&  
            *start_match == '\n')  
         start_match++;  
4804        }        }
     }  
4805    
4806    /* Or to a non-unique first char after study */      /* Or to a non-unique first byte after study */
4807    
4808    else if (start_bits != NULL)      else if (start_bits != NULL)
     {  
     while (start_match < end_subject)  
4809        {        {
4810        register unsigned int c = *start_match;        while (start_match < end_subject)
4811        if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++; else break;          {
4812            register unsigned int c = *start_match;
4813            if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++;
4814              else break;
4815            }
4816        }        }
4817      }      }   /* Starting optimizations */
4818    
4819    /* Restore fudged end_subject */    /* Restore fudged end_subject */
4820    
# Line 4665  for(;;) Line 4826  for(;;)
4826    printf("\n");    printf("\n");
4827  #endif  #endif
4828    
4829    /* If req_byte is set, we know that that character must appear in the subject    /* If req_byte is set, we know that that character must appear in the
4830    for the match to succeed. If the first character is set, req_byte must be    subject for the match to succeed. If the first character is set, req_byte
4831    later in the subject; otherwise the test starts at the match point. This    must be later in the subject; otherwise the test starts at the match point.
4832    optimization can save a huge amount of backtracking in patterns with nested    This optimization can save a huge amount of backtracking in patterns with
4833    unlimited repeats that aren't going to match. Writing separate code for    nested unlimited repeats that aren't going to match. Writing separate code
4834    cased/caseless versions makes it go faster, as does using an autoincrement    for cased/caseless versions makes it go faster, as does using an
4835    and backing off on a match.    autoincrement and backing off on a match.
4836    
4837    HOWEVER: when the subject string is very, very long, searching to its end can    HOWEVER: when the subject string is very, very long, searching to its end
4838    take a long time, and give bad performance on quite ordinary patterns. This    can take a long time, and give bad performance on quite ordinary patterns.
4839    showed up when somebody was matching something like /^\d+C/ on a 32-megabyte    This showed up when somebody was matching something like /^\d+C/ on a
4840    string... so we don't do this when the string is sufficiently long.    32-megabyte string... so we don't do this when the string is sufficiently
4841      long.
4842    
4843    ALSO: this processing is disabled when partial matching is requested.    ALSO: this processing is disabled when partial matching is requested, or if
4844    */    disabling is explicitly requested. */
4845    
4846    if (req_byte >= 0 &&    if ((options & PCRE_NO_START_OPTIMIZE) == 0 &&
4847          req_byte >= 0 &&
4848        end_subject - start_match < REQ_BYTE_MAX &&        end_subject - start_match < REQ_BYTE_MAX &&
4849        !md->partial)        !md->partial)
4850      {      {
# Line 4789  for(;;) Line 4952  for(;;)
4952    not contain any explicit matches for \r or \n, and the newline option is CRLF    not contain any explicit matches for \r or \n, and the newline option is CRLF
4953    or ANY or ANYCRLF, advance the match position by one more character. */    or ANY or ANYCRLF, advance the match position by one more character. */
4954    
4955    if (start_match[-1] == '\r' &&    if (start_match[-1] == CHAR_CR &&
4956        start_match < end_subject &&        start_match < end_subject &&
4957        *start_match == '\n' &&        *start_match == CHAR_NL &&
4958        (re->options & PCRE_HASCRORLF) == 0 &&        (re->flags & PCRE_HASCRORLF) == 0 &&
4959          (md->nltype == NLTYPE_ANY ||          (md->nltype == NLTYPE_ANY ||
4960           md->nltype == NLTYPE_ANYCRLF ||           md->nltype == NLTYPE_ANYCRLF ||
4961           md->nllen == 2))           md->nllen == 2))

Legend:
Removed from v.227  
changed lines
  Added in v.402

  ViewVC Help
Powered by ViewVC 1.1.5