/[pcre]/code/trunk/pcre_compile.c
ViewVC logotype

Diff of /code/trunk/pcre_compile.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 723 by ph10, Sat Oct 8 15:55:23 2011 UTC revision 762 by ph10, Tue Nov 22 13:36:51 2011 UTC
# Line 410  static const char error_texts[] = Line 410  static const char error_texts[] =
410    "this version of PCRE is not compiled with PCRE_UCP support\0"    "this version of PCRE is not compiled with PCRE_UCP support\0"
411    "\\c must be followed by an ASCII character\0"    "\\c must be followed by an ASCII character\0"
412    "\\k is not followed by a braced, angle-bracketed, or quoted name\0"    "\\k is not followed by a braced, angle-bracketed, or quoted name\0"
413      /* 70 */
414      "internal error: unknown opcode in find_fixedlength()\0"
415      "\\N is not supported in a class\0"
416      "too many forward references\0"
417    ;    ;
418    
419  /* Table to identify digits and hex digits. This is used when compiling  /* Table to identify digits and hex digits. This is used when compiling
# Line 676  else Line 680  else
680    
681      case CHAR_l:      case CHAR_l:
682      case CHAR_L:      case CHAR_L:
683        *errorcodeptr = ERR37;
684        break;
685    
686      case CHAR_u:      case CHAR_u:
687        if ((options & PCRE_JAVASCRIPT_COMPAT) != 0)
688          {
689          /* In JavaScript, \u must be followed by four hexadecimal numbers.
690          Otherwise it is a lowercase u letter. */
691          if ((digitab[ptr[1]] & ctype_xdigit) != 0 && (digitab[ptr[2]] & ctype_xdigit) != 0
692               && (digitab[ptr[3]] & ctype_xdigit) != 0 && (digitab[ptr[4]] & ctype_xdigit) != 0)
693            {
694            c = 0;
695            for (i = 0; i < 4; ++i)
696              {
697              register int cc = *(++ptr);
698    #ifndef EBCDIC  /* ASCII/UTF-8 coding */
699              if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
700              c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
701    #else           /* EBCDIC coding */
702              if (cc >= CHAR_a && cc <= CHAR_z) cc += 64;  /* Convert to upper case */
703              c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
704    #endif
705              }
706            }
707          }
708        else
709          *errorcodeptr = ERR37;
710        break;
711    
712      case CHAR_U:      case CHAR_U:
713      *errorcodeptr = ERR37;      /* In JavaScript, \U is an uppercase U letter. */
714        if ((options & PCRE_JAVASCRIPT_COMPAT) == 0) *errorcodeptr = ERR37;
715      break;      break;
716    
717      /* In a character class, \g is just a literal "g". Outside a character      /* In a character class, \g is just a literal "g". Outside a character
# Line 828  else Line 861  else
861      treated as a data character. */      treated as a data character. */
862    
863      case CHAR_x:      case CHAR_x:
864        if ((options & PCRE_JAVASCRIPT_COMPAT) != 0)
865          {
866          /* In JavaScript, \x must be followed by two hexadecimal numbers.
867          Otherwise it is a lowercase x letter. */
868          if ((digitab[ptr[1]] & ctype_xdigit) != 0 && (digitab[ptr[2]] & ctype_xdigit) != 0)
869            {
870            c = 0;
871            for (i = 0; i < 2; ++i)
872              {
873              register int cc = *(++ptr);
874    #ifndef EBCDIC  /* ASCII/UTF-8 coding */
875              if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
876              c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
877    #else           /* EBCDIC coding */
878              if (cc >= CHAR_a && cc <= CHAR_z) cc += 64;  /* Convert to upper case */
879              c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
880    #endif
881              }
882            }
883          break;
884          }
885    
886      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)
887        {        {
888        const uschar *pt = ptr + 2;        const uschar *pt = ptr + 2;
# Line 1475  Arguments: Line 1530  Arguments:
1530    
1531  Returns:   the fixed length,  Returns:   the fixed length,
1532               or -1 if there is no fixed length,               or -1 if there is no fixed length,
1533               or -2 if \C was encountered               or -2 if \C was encountered (in UTF-8 mode only)
1534               or -3 if an OP_RECURSE item was encountered and atend is FALSE               or -3 if an OP_RECURSE item was encountered and atend is FALSE
1535                 or -4 if an unknown opcode was encountered (internal error)
1536  */  */
1537    
1538  static int  static int
# Line 1500  for (;;) Line 1556  for (;;)
1556      /* We only need to continue for OP_CBRA (normal capturing bracket) and      /* We only need to continue for OP_CBRA (normal capturing bracket) and
1557      OP_BRA (normal non-capturing bracket) because the other variants of these      OP_BRA (normal non-capturing bracket) because the other variants of these
1558      opcodes are all concerned with unlimited repeated groups, which of course      opcodes are all concerned with unlimited repeated groups, which of course
1559      are not of fixed length. They will cause a -1 response from the default      are not of fixed length. */
     case of this switch. */  
1560    
1561      case OP_CBRA:      case OP_CBRA:
1562      case OP_BRA:      case OP_BRA:
1563      case OP_ONCE:      case OP_ONCE:
1564      case OP_ONCE_NC:      case OP_ONCE_NC:
1565      case OP_COND:      case OP_COND:
1566      d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), utf8, atend, cd);      d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), utf8, atend, cd);
1567      if (d < 0) return d;      if (d < 0) return d;
# Line 1515  for (;;) Line 1570  for (;;)
1570      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1571      break;      break;
1572    
1573      /* Reached end of a branch; if it's a ket it is the end of a nested      /* Reached end of a branch; if it's a ket it is the end of a nested call.
1574      call. If it's ALT it is an alternation in a nested call. If it is      If it's ALT it is an alternation in a nested call. An ACCEPT is effectively
1575      END it's the end of the outer call. All can be handled by the same code.      an ALT. If it is END it's the end of the outer call. All can be handled by
1576      Note that we must not include the OP_KETRxxx opcodes here, because they      the same code. Note that we must not include the OP_KETRxxx opcodes here,
1577      all imply an unlimited repeat. */      because they all imply an unlimited repeat. */
1578    
1579      case OP_ALT:      case OP_ALT:
1580      case OP_KET:      case OP_KET:
1581      case OP_END:      case OP_END:
1582        case OP_ACCEPT:
1583        case OP_ASSERT_ACCEPT:
1584      if (length < 0) length = branchlength;      if (length < 0) length = branchlength;
1585        else if (length != branchlength) return -1;        else if (length != branchlength) return -1;
1586      if (*cc != OP_ALT) return length;      if (*cc != OP_ALT) return length;
# Line 1557  for (;;) Line 1614  for (;;)
1614    
1615      /* Skip over things that don't match chars */      /* Skip over things that don't match chars */
1616    
1617      case OP_REVERSE:      case OP_MARK:
1618      case OP_CREF:      case OP_PRUNE_ARG:
1619      case OP_NCREF:      case OP_SKIP_ARG:
1620      case OP_RREF:      case OP_THEN_ARG:
1621      case OP_NRREF:      cc += cc[1] + _pcre_OP_lengths[*cc];
1622      case OP_DEF:      break;
1623    
1624      case OP_CALLOUT:      case OP_CALLOUT:
     case OP_SOD:  
     case OP_SOM:  
     case OP_SET_SOM:  
     case OP_EOD:  
     case OP_EODN:  
1625      case OP_CIRC:      case OP_CIRC:
1626      case OP_CIRCM:      case OP_CIRCM:
1627        case OP_CLOSE:
1628        case OP_COMMIT:
1629        case OP_CREF:
1630        case OP_DEF:
1631      case OP_DOLL:      case OP_DOLL:
1632      case OP_DOLLM:      case OP_DOLLM:
1633        case OP_EOD:
1634        case OP_EODN:
1635        case OP_FAIL:
1636        case OP_NCREF:
1637        case OP_NRREF:
1638      case OP_NOT_WORD_BOUNDARY:      case OP_NOT_WORD_BOUNDARY:
1639        case OP_PRUNE:
1640        case OP_REVERSE:
1641        case OP_RREF:
1642        case OP_SET_SOM:
1643        case OP_SKIP:
1644        case OP_SOD:
1645        case OP_SOM:
1646        case OP_THEN:
1647      case OP_WORD_BOUNDARY:      case OP_WORD_BOUNDARY:
1648      cc += _pcre_OP_lengths[*cc];      cc += _pcre_OP_lengths[*cc];
1649      break;      break;
# Line 1595  for (;;) Line 1665  for (;;)
1665      need to skip over a multibyte character in UTF8 mode.  */      need to skip over a multibyte character in UTF8 mode.  */
1666    
1667      case OP_EXACT:      case OP_EXACT:
1668        case OP_EXACTI:
1669        case OP_NOTEXACT:
1670        case OP_NOTEXACTI:
1671      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
1672      cc += 4;      cc += 4;
1673  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1615  for (;;) Line 1688  for (;;)
1688      cc += 2;      cc += 2;
1689      /* Fall through */      /* Fall through */
1690    
1691        case OP_HSPACE:
1692        case OP_VSPACE:
1693        case OP_NOT_HSPACE:
1694        case OP_NOT_VSPACE:
1695      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
1696      case OP_DIGIT:      case OP_DIGIT:
1697      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
# Line 1627  for (;;) Line 1704  for (;;)
1704      cc++;      cc++;
1705      break;      break;
1706    
1707      /* The single-byte matcher isn't allowed */      /* The single-byte matcher isn't allowed. This only happens in UTF-8 mode;
1708        otherwise \C is coded as OP_ALLANY. */
1709    
1710      case OP_ANYBYTE:      case OP_ANYBYTE:
1711      return -2;      return -2;
# Line 1646  for (;;) Line 1724  for (;;)
1724    
1725      switch (*cc)      switch (*cc)
1726        {        {
1727          case OP_CRPLUS:
1728          case OP_CRMINPLUS:
1729        case OP_CRSTAR:        case OP_CRSTAR:
1730        case OP_CRMINSTAR:        case OP_CRMINSTAR:
1731        case OP_CRQUERY:        case OP_CRQUERY:
# Line 1666  for (;;) Line 1746  for (;;)
1746    
1747      /* Anything else is variable length */      /* Anything else is variable length */
1748    
1749      default:      case OP_ANYNL:
1750        case OP_BRAMINZERO:
1751        case OP_BRAPOS:
1752        case OP_BRAPOSZERO:
1753        case OP_BRAZERO:
1754        case OP_CBRAPOS:
1755        case OP_EXTUNI:
1756        case OP_KETRMAX:
1757        case OP_KETRMIN:
1758        case OP_KETRPOS:
1759        case OP_MINPLUS:
1760        case OP_MINPLUSI:
1761        case OP_MINQUERY:
1762        case OP_MINQUERYI:
1763        case OP_MINSTAR:
1764        case OP_MINSTARI:
1765        case OP_MINUPTO:
1766        case OP_MINUPTOI:
1767        case OP_NOTMINPLUS:
1768        case OP_NOTMINPLUSI:
1769        case OP_NOTMINQUERY:
1770        case OP_NOTMINQUERYI:
1771        case OP_NOTMINSTAR:
1772        case OP_NOTMINSTARI:
1773        case OP_NOTMINUPTO:
1774        case OP_NOTMINUPTOI:
1775        case OP_NOTPLUS:
1776        case OP_NOTPLUSI:
1777        case OP_NOTPOSPLUS:
1778        case OP_NOTPOSPLUSI:
1779        case OP_NOTPOSQUERY:
1780        case OP_NOTPOSQUERYI:
1781        case OP_NOTPOSSTAR:
1782        case OP_NOTPOSSTARI:
1783        case OP_NOTPOSUPTO:
1784        case OP_NOTPOSUPTOI:
1785        case OP_NOTQUERY:
1786        case OP_NOTQUERYI:
1787        case OP_NOTSTAR:
1788        case OP_NOTSTARI:
1789        case OP_NOTUPTO:
1790        case OP_NOTUPTOI:
1791        case OP_PLUS:
1792        case OP_PLUSI:
1793        case OP_POSPLUS:
1794        case OP_POSPLUSI:
1795        case OP_POSQUERY:
1796        case OP_POSQUERYI:
1797        case OP_POSSTAR:
1798        case OP_POSSTARI:
1799        case OP_POSUPTO:
1800        case OP_POSUPTOI:
1801        case OP_QUERY:
1802        case OP_QUERYI:
1803        case OP_REF:
1804        case OP_REFI:
1805        case OP_SBRA:
1806        case OP_SBRAPOS:
1807        case OP_SCBRA:
1808        case OP_SCBRAPOS:
1809        case OP_SCOND:
1810        case OP_SKIPZERO:
1811        case OP_STAR:
1812        case OP_STARI:
1813        case OP_TYPEMINPLUS:
1814        case OP_TYPEMINQUERY:
1815        case OP_TYPEMINSTAR:
1816        case OP_TYPEMINUPTO:
1817        case OP_TYPEPLUS:
1818        case OP_TYPEPOSPLUS:
1819        case OP_TYPEPOSQUERY:
1820        case OP_TYPEPOSSTAR:
1821        case OP_TYPEPOSUPTO:
1822        case OP_TYPEQUERY:
1823        case OP_TYPESTAR:
1824        case OP_TYPEUPTO:
1825        case OP_UPTO:
1826        case OP_UPTOI:
1827      return -1;      return -1;
1828    
1829        /* Catch unrecognized opcodes so that when new ones are added they
1830        are not forgotten, as has happened in the past. */
1831    
1832        default:
1833        return -4;
1834      }      }
1835    }    }
1836  /* Control never gets here */  /* Control never gets here */
# Line 3144  for (;; ptr++) Line 3307  for (;; ptr++)
3307    int subfirstbyte;    int subfirstbyte;
3308    int terminator;    int terminator;
3309    int mclength;    int mclength;
3310    int tempbracount;    int tempbracount;
3311    uschar mcbuffer[8];    uschar mcbuffer[8];
3312    
3313    /* Get next byte in the pattern */    /* Get next byte in the pattern */
# Line 3192  for (;; ptr++) Line 3355  for (;; ptr++)
3355        }        }
3356    
3357      *lengthptr += (int)(code - last_code);      *lengthptr += (int)(code - last_code);
3358      DPRINTF(("length=%d added %d c=%c\n", *lengthptr, code - last_code, c));      DPRINTF(("length=%d added %d c=%c\n", *lengthptr, (int)(code - last_code),
3359          c));
3360    
3361      /* If "previous" is set and it is not at the start of the work space, move      /* If "previous" is set and it is not at the start of the work space, move
3362      it back to there, in order to avoid filling up the work space. Otherwise,      it back to there, in order to avoid filling up the work space. Otherwise,
# Line 3608  for (;; ptr++) Line 3772  for (;; ptr++)
3772          if (*errorcodeptr != 0) goto FAILED;          if (*errorcodeptr != 0) goto FAILED;
3773    
3774          if (-c == ESC_b) c = CHAR_BS;    /* \b is backspace in a class */          if (-c == ESC_b) c = CHAR_BS;    /* \b is backspace in a class */
3775            else if (-c == ESC_N)            /* \N is not supported in a class */
3776              {
3777              *errorcodeptr = ERR71;
3778              goto FAILED;
3779              }
3780          else if (-c == ESC_Q)            /* Handle start of quoted string */          else if (-c == ESC_Q)            /* Handle start of quoted string */
3781            {            {
3782            if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)            if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)
# Line 4264  for (;; ptr++) Line 4433  for (;; ptr++)
4433      past, but it no longer happens for non-repeated recursions. In fact, the      past, but it no longer happens for non-repeated recursions. In fact, the
4434      repeated ones could be re-implemented independently so as not to need this,      repeated ones could be re-implemented independently so as not to need this,
4435      but for the moment we rely on the code for repeating groups. */      but for the moment we rely on the code for repeating groups. */
4436    
4437      if (*previous == OP_RECURSE)      if (*previous == OP_RECURSE)
4438        {        {
4439        memmove(previous + 1 + LINK_SIZE, previous, 1 + LINK_SIZE);        memmove(previous + 1 + LINK_SIZE, previous, 1 + LINK_SIZE);
# Line 4715  for (;; ptr++) Line 4884  for (;; ptr++)
4884              *lengthptr += delta;              *lengthptr += delta;
4885              }              }
4886    
4887            /* This is compiling for real */            /* This is compiling for real. If there is a set first byte for
4888              the group, and we have not yet set a "required byte", set it. */
4889    
4890            else            else
4891              {              {
# Line 4727  for (;; ptr++) Line 4897  for (;; ptr++)
4897                memcpy(code, previous, len);                memcpy(code, previous, len);
4898                for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)                for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)
4899                  {                  {
4900                    if (cd->hwm >= cd->start_workspace + WORK_SIZE_CHECK)
4901                      {
4902                      *errorcodeptr = ERR72;
4903                      goto FAILED;
4904                      }
4905                  PUT(cd->hwm, 0, GET(hc, 0) + len);                  PUT(cd->hwm, 0, GET(hc, 0) + len);
4906                  cd->hwm += LINK_SIZE;                  cd->hwm += LINK_SIZE;
4907                  }                  }
# Line 4754  for (;; ptr++) Line 4929  for (;; ptr++)
4929          add 2 + 2*LINKSIZE to allow for the nesting that occurs. Do some          add 2 + 2*LINKSIZE to allow for the nesting that occurs. Do some
4930          paranoid checks to avoid integer overflow. The INT64_OR_DOUBLE type is          paranoid checks to avoid integer overflow. The INT64_OR_DOUBLE type is
4931          a 64-bit integer type when available, otherwise double. */          a 64-bit integer type when available, otherwise double. */
4932    
4933          if (lengthptr != NULL && repeat_max > 0)          if (lengthptr != NULL && repeat_max > 0)
4934            {            {
4935            int delta = repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) -            int delta = repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) -
# Line 4794  for (;; ptr++) Line 4969  for (;; ptr++)
4969            memcpy(code, previous, len);            memcpy(code, previous, len);
4970            for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)            for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)
4971              {              {
4972                if (cd->hwm >= cd->start_workspace + WORK_SIZE_CHECK)
4973                  {
4974                  *errorcodeptr = ERR72;
4975                  goto FAILED;
4976                  }
4977              PUT(cd->hwm, 0, GET(hc, 0) + len + ((i != 0)? 2+LINK_SIZE : 1));              PUT(cd->hwm, 0, GET(hc, 0) + len + ((i != 0)? 2+LINK_SIZE : 1));
4978              cd->hwm += LINK_SIZE;              cd->hwm += LINK_SIZE;
4979              }              }
# Line 4822  for (;; ptr++) Line 5002  for (;; ptr++)
5002        ONCE brackets can be converted into non-capturing brackets, as the        ONCE brackets can be converted into non-capturing brackets, as the
5003        behaviour of (?:xx)++ is the same as (?>xx)++ and this saves having to        behaviour of (?:xx)++ is the same as (?>xx)++ and this saves having to
5004        deal with possessive ONCEs specially.        deal with possessive ONCEs specially.
5005    
5006        Otherwise, if the quantifier was possessive, we convert the BRA code to        Otherwise, when we are doing the actual compile phase, check to see
5007        the POS form, and the KET code to KETRPOS. (It turns out to be convenient        whether this group is one that could match an empty string. If so,
5008        at runtime to detect this kind of subpattern at both the start and at the        convert the initial operator to the S form (e.g. OP_BRA -> OP_SBRA) so
5009        end.) The use of special opcodes makes it possible to reduce greatly the        that runtime checking can be done. [This check is also applied to ONCE
5010        stack usage in pcre_exec(). If the group is preceded by OP_BRAZERO,        groups at runtime, but in a different way.]
5011        convert this to OP_BRAPOSZERO. Then cancel the possessive flag so that  
5012        the default action below, of wrapping everything inside atomic brackets,        Then, if the quantifier was possessive and the bracket is not a
5013        does not happen.        conditional, we convert the BRA code to the POS form, and the KET code to
5014          KETRPOS. (It turns out to be convenient at runtime to detect this kind of
5015        Then, when we are doing the actual compile phase, check to see whether        subpattern at both the start and at the end.) The use of special opcodes
5016        this group is one that could match an empty string. If so, convert the        makes it possible to reduce greatly the stack usage in pcre_exec(). If
5017        initial operator to the S form (e.g. OP_BRA -> OP_SBRA) so that runtime        the group is preceded by OP_BRAZERO, convert this to OP_BRAPOSZERO.
5018        checking can be done. [This check is also applied to ONCE groups at  
5019        runtime, but in a different way.] */        Then, if the minimum number of matches is 1 or 0, cancel the possessive
5020          flag so that the default action below, of wrapping everything inside
5021          atomic brackets, does not happen. When the minimum is greater than 1,
5022          there will be earlier copies of the group, and so we still have to wrap
5023          the whole thing. */
5024    
5025        else        else
5026          {          {
5027          uschar *ketcode = code - 1 - LINK_SIZE;          uschar *ketcode = code - 1 - LINK_SIZE;
5028          uschar *bracode = ketcode - GET(ketcode, 1);          uschar *bracode = ketcode - GET(ketcode, 1);
5029    
5030          if ((*bracode == OP_ONCE || *bracode == OP_ONCE_NC) &&          /* Convert possessive ONCE brackets to non-capturing */
5031    
5032            if ((*bracode == OP_ONCE || *bracode == OP_ONCE_NC) &&
5033              possessive_quantifier) *bracode = OP_BRA;              possessive_quantifier) *bracode = OP_BRA;
5034    
5035            /* For non-possessive ONCE brackets, all we need to do is to
5036            set the KET. */
5037    
5038          if (*bracode == OP_ONCE || *bracode == OP_ONCE_NC)          if (*bracode == OP_ONCE || *bracode == OP_ONCE_NC)
5039            *ketcode = OP_KETRMAX + repeat_type;            *ketcode = OP_KETRMAX + repeat_type;
5040    
5041            /* Handle non-ONCE brackets and possessive ONCEs (which have been
5042            converted to non-capturing above). */
5043    
5044          else          else
5045            {            {
5046            if (possessive_quantifier)            /* In the compile phase, check for empty string matching. */
5047              {  
             *bracode += 1;                   /* Switch to xxxPOS opcodes */  
             *ketcode = OP_KETRPOS;  
             if (brazeroptr != NULL) *brazeroptr = OP_BRAPOSZERO;  
             possessive_quantifier = FALSE;  
             }  
           else *ketcode = OP_KETRMAX + repeat_type;  
   
5048            if (lengthptr == NULL)            if (lengthptr == NULL)
5049              {              {
5050              uschar *scode = bracode;              uschar *scode = bracode;
# Line 4873  for (;; ptr++) Line 5059  for (;; ptr++)
5059                }                }
5060              while (*scode == OP_ALT);              while (*scode == OP_ALT);
5061              }              }
5062    
5063              /* Handle possessive quantifiers. */
5064    
5065              if (possessive_quantifier)
5066                {
5067                /* For COND brackets, we wrap the whole thing in a possessively
5068                repeated non-capturing bracket, because we have not invented POS
5069                versions of the COND opcodes. Because we are moving code along, we
5070                must ensure that any pending recursive references are updated. */
5071    
5072                if (*bracode == OP_COND || *bracode == OP_SCOND)
5073                  {
5074                  int nlen = (int)(code - bracode);
5075                  *code = OP_END;
5076                  adjust_recurse(bracode, 1 + LINK_SIZE, utf8, cd, save_hwm);
5077                  memmove(bracode + 1+LINK_SIZE, bracode, nlen);
5078                  code += 1 + LINK_SIZE;
5079                  nlen += 1 + LINK_SIZE;
5080                  *bracode = OP_BRAPOS;
5081                  *code++ = OP_KETRPOS;
5082                  PUTINC(code, 0, nlen);
5083                  PUT(bracode, 1, nlen);
5084                  }
5085    
5086                /* For non-COND brackets, we modify the BRA code and use KETRPOS. */
5087    
5088                else
5089                  {
5090                  *bracode += 1;              /* Switch to xxxPOS opcodes */
5091                  *ketcode = OP_KETRPOS;
5092                  }
5093    
5094                /* If the minimum is zero, mark it as possessive, then unset the
5095                possessive flag when the minimum is 0 or 1. */
5096    
5097                if (brazeroptr != NULL) *brazeroptr = OP_BRAPOSZERO;
5098                if (repeat_min < 2) possessive_quantifier = FALSE;
5099                }
5100    
5101              /* Non-possessive quantifier */
5102    
5103              else *ketcode = OP_KETRMAX + repeat_type;
5104            }            }
5105          }          }
5106        }        }
# Line 4899  for (;; ptr++) Line 5127  for (;; ptr++)
5127      notation is just syntactic sugar, taken from Sun's Java package, but the      notation is just syntactic sugar, taken from Sun's Java package, but the
5128      special opcodes can optimize it.      special opcodes can optimize it.
5129    
5130      Possessively repeated subpatterns have already been handled in the code      Some (but not all) possessively repeated subpatterns have already been
5131      just above, so possessive_quantifier is always FALSE for them at this      completely handled in the code just above. For them, possessive_quantifier
5132      stage.      is always FALSE at this stage.
5133    
5134      Note that the repeated item starts at tempcode, not at previous, which      Note that the repeated item starts at tempcode, not at previous, which
5135      might be the first part of a string whose (former) last char we repeated.      might be the first part of a string whose (former) last char we repeated.
# Line 5391  for (;; ptr++) Line 5619  for (;; ptr++)
5619    
5620          /* ------------------------------------------------------------ */          /* ------------------------------------------------------------ */
5621          case CHAR_C:                 /* Callout - may be followed by digits; */          case CHAR_C:                 /* Callout - may be followed by digits; */
5622          previous_callout = code;  /* Save for later completion */          previous_callout = code;     /* Save for later completion */
5623          after_manual_callout = 1; /* Skip one item before completing */          after_manual_callout = 1;    /* Skip one item before completing */
5624          *code++ = OP_CALLOUT;          *code++ = OP_CALLOUT;
5625            {            {
5626            int n = 0;            int n = 0;
# Line 5761  for (;; ptr++) Line 5989  for (;; ptr++)
5989                /* Fudge the value of "called" so that when it is inserted as an                /* Fudge the value of "called" so that when it is inserted as an
5990                offset below, what it actually inserted is the reference number                offset below, what it actually inserted is the reference number
5991                of the group. Then remember the forward reference. */                of the group. Then remember the forward reference. */
5992    
5993                called = cd->start_code + recno;                called = cd->start_code + recno;
5994                  if (cd->hwm >= cd->start_workspace + WORK_SIZE_CHECK)
5995                    {
5996                    *errorcodeptr = ERR72;
5997                    goto FAILED;
5998                    }
5999                PUTINC(cd->hwm, 0, (int)(code + 1 - cd->start_code));                PUTINC(cd->hwm, 0, (int)(code + 1 - cd->start_code));
6000                }                }
6001    
# Line 5783  for (;; ptr++) Line 6016  for (;; ptr++)
6016                }                }
6017              }              }
6018    
6019            /* Insert the recursion/subroutine item. */            /* Insert the recursion/subroutine item. It does not have a set first
6020              byte (relevant if it is repeated, because it will then be wrapped
6021              with ONCE brackets). */
6022    
6023            *code = OP_RECURSE;            *code = OP_RECURSE;
6024            PUT(code, 1, (int)(called - cd->start_code));            PUT(code, 1, (int)(called - cd->start_code));
6025            code += 1 + LINK_SIZE;            code += 1 + LINK_SIZE;
6026              groupsetfirstbyte = FALSE;
6027            }            }
6028    
6029          /* Can't determine a first byte now */          /* Can't determine a first byte now */
# Line 5933  for (;; ptr++) Line 6169  for (;; ptr++)
6169             &length_prevgroup              /* Pre-compile phase */             &length_prevgroup              /* Pre-compile phase */
6170           ))           ))
6171        goto FAILED;        goto FAILED;
6172    
6173      /* If this was an atomic group and there are no capturing groups within it,      /* If this was an atomic group and there are no capturing groups within it,
6174      generate OP_ONCE_NC instead of OP_ONCE. */      generate OP_ONCE_NC instead of OP_ONCE. */
6175    
6176      if (bravalue == OP_ONCE && cd->bracount <= tempbracount)      if (bravalue == OP_ONCE && cd->bracount <= tempbracount)
6177        *code = OP_ONCE_NC;        *code = OP_ONCE_NC;
6178    
6179      if (bravalue >= OP_ASSERT && bravalue <= OP_ASSERTBACK_NOT)      if (bravalue >= OP_ASSERT && bravalue <= OP_ASSERTBACK_NOT)
# Line 6269  for (;; ptr++) Line 6505  for (;; ptr++)
6505            }            }
6506          else          else
6507  #endif  #endif
6508            {          /* In non-UTF-8 mode, we turn \C into OP_ALLANY instead of OP_ANYBYTE
6509            so that it works in DFA mode and in lookbehinds. */
6510    
6511              {
6512            previous = (-c > ESC_b && -c < ESC_Z)? code : NULL;            previous = (-c > ESC_b && -c < ESC_Z)? code : NULL;
6513            *code++ = -c;            *code++ = (!utf8 && c == -ESC_C)? OP_ALLANY : -c;
6514            }            }
6515          }          }
6516        continue;        continue;
# Line 6563  for (;;) Line 6802  for (;;)
6802          }          }
6803        else if (fixed_length < 0)        else if (fixed_length < 0)
6804          {          {
6805          *errorcodeptr = (fixed_length == -2)? ERR36 : ERR25;          *errorcodeptr = (fixed_length == -2)? ERR36 :
6806                            (fixed_length == -4)? ERR70: ERR25;
6807          *ptrptr = ptr;          *ptrptr = ptr;
6808          return FALSE;          return FALSE;
6809          }          }
# Line 6913  do { Line 7153  do {
7153       case OP_SCBRAPOS:       case OP_SCBRAPOS:
7154       case OP_ASSERT:       case OP_ASSERT:
7155       case OP_ONCE:       case OP_ONCE:
7156       case OP_ONCE_NC:       case OP_ONCE_NC:
7157       case OP_COND:       case OP_COND:
7158       if ((d = find_firstassertedchar(scode, op == OP_ASSERT)) < 0)       if ((d = find_firstassertedchar(scode, op == OP_ASSERT)) < 0)
7159         return -1;         return -1;
# Line 7362  if (cd->check_lookbehind) Line 7602  if (cd->check_lookbehind)
7602        DPRINTF(("fixed length = %d\n", fixed_length));        DPRINTF(("fixed length = %d\n", fixed_length));
7603        if (fixed_length < 0)        if (fixed_length < 0)
7604          {          {
7605          errorcode = (fixed_length == -2)? ERR36 : ERR25;          errorcode = (fixed_length == -2)? ERR36 :
7606                        (fixed_length == -4)? ERR70 : ERR25;
7607          break;          break;
7608          }          }
7609        PUT(cc, 1, fixed_length);        PUT(cc, 1, fixed_length);

Legend:
Removed from v.723  
changed lines
  Added in v.762

  ViewVC Help
Powered by ViewVC 1.1.5