/[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 206 by ph10, Fri Aug 3 14:53:04 2007 UTC revision 213 by ph10, Wed Aug 15 11:34:14 2007 UTC
# Line 140  static const short int escapes[] = { Line 140  static const short int escapes[] = {
140  #endif  #endif
141    
142    
143    /* Table of special "verbs" like (*PRUNE) */
144    
145    typedef struct verbitem {
146      const char *name;
147      int   len;
148      int   op;
149    } verbitem;
150    
151    static verbitem verbs[] = {
152      { "ACCEPT", 6, OP_ACCEPT },
153      { "COMMIT", 6, OP_COMMIT },
154      { "F",      1, OP_FAIL },
155      { "FAIL",   4, OP_FAIL },
156      { "PRUNE",  5, OP_PRUNE },
157      { "SKIP",   4, OP_SKIP  },
158      { "THEN",   4, OP_THEN  }
159    };
160    
161    static int verbcount = sizeof(verbs)/sizeof(verbitem);
162    
163    
164  /* Tables of names of POSIX character classes and their lengths. The list is  /* Tables of names of POSIX character classes and their lengths. The list is
165  terminated by a zero length entry. The first three must be alpha, lower, upper,  terminated by a zero length entry. The first three must be alpha, lower, upper,
166  as this is assumed for handling case independence. */  as this is assumed for handling case independence. */
# Line 258  static const char *error_texts[] = { Line 279  static const char *error_texts[] = {
279    "repeating a DEFINE group is not allowed",    "repeating a DEFINE group is not allowed",
280    "inconsistent NEWLINE options",    "inconsistent NEWLINE options",
281    "\\g is not followed by a braced name or an optionally braced non-zero number",    "\\g is not followed by a braced name or an optionally braced non-zero number",
282    "(?+ or (?- or (?(+ or (?(- must be followed by a non-zero number"    "(?+ or (?- or (?(+ or (?(- must be followed by a non-zero number",
283      "(*VERB) with an argument is not supported",
284      /* 60 */
285      "(*VERB) not recognized",
286      "number is too big"
287  };  };
288    
289    
# Line 415  Arguments: Line 440  Arguments:
440    
441  Returns:         zero or positive => a data character  Returns:         zero or positive => a data character
442                   negative => a special escape sequence                   negative => a special escape sequence
443                   on error, errorptr is set                   on error, errorcodeptr is set
444  */  */
445    
446  static int  static int
# Line 499  else Line 524  else
524      c = 0;      c = 0;
525      while ((digitab[ptr[1]] & ctype_digit) != 0)      while ((digitab[ptr[1]] & ctype_digit) != 0)
526        c = c * 10 + *(++ptr) - '0';        c = c * 10 + *(++ptr) - '0';
527    
528        if (c < 0)
529          {
530          *errorcodeptr = ERR61;
531          break;
532          }
533    
534      if (c == 0 || (braced && *(++ptr) != '}'))      if (c == 0 || (braced && *(++ptr) != '}'))
535        {        {
536        *errorcodeptr = ERR57;        *errorcodeptr = ERR57;
537        return 0;        break;
538        }        }
539    
540      if (negated)      if (negated)
# Line 511  else Line 542  else
542        if (c > bracount)        if (c > bracount)
543          {          {
544          *errorcodeptr = ERR15;          *errorcodeptr = ERR15;
545          return 0;          break;
546          }          }
547        c = bracount - (c - 1);        c = bracount - (c - 1);
548        }        }
# Line 540  else Line 571  else
571        c -= '0';        c -= '0';
572        while ((digitab[ptr[1]] & ctype_digit) != 0)        while ((digitab[ptr[1]] & ctype_digit) != 0)
573          c = c * 10 + *(++ptr) - '0';          c = c * 10 + *(++ptr) - '0';
574          if (c < 0)
575            {
576            *errorcodeptr = ERR61;
577            break;
578            }
579        if (c < 10 || c <= bracount)        if (c < 10 || c <= bracount)
580          {          {
581          c = -(ESC_REF + c);          c = -(ESC_REF + c);
# Line 635  else Line 671  else
671      if (c == 0)      if (c == 0)
672        {        {
673        *errorcodeptr = ERR2;        *errorcodeptr = ERR2;
674        return 0;        break;
675        }        }
676    
677  #ifndef EBCDIC  /* ASCII coding */  #ifndef EBCDIC  /* ASCII coding */
# Line 941  for (; *ptr != 0; ptr++) Line 977  for (; *ptr != 0; ptr++)
977    /* An opening parens must now be a real metacharacter */    /* An opening parens must now be a real metacharacter */
978    
979    if (*ptr != '(') continue;    if (*ptr != '(') continue;
980    if (ptr[1] != '?')    if (ptr[1] != '?' && ptr[1] != '*')
981      {      {
982      count++;      count++;
983      if (name == NULL && count == lorn) return count;      if (name == NULL && count == lorn) return count;
# Line 2454  for (;; ptr++) Line 2490  for (;; ptr++)
2490        }        }
2491    
2492      /* If the first character is '^', set the negation flag and skip it. Also,      /* If the first character is '^', set the negation flag and skip it. Also,
2493      if the first few characters (either before or after ^) are \Q\E or \E we      if the first few characters (either before or after ^) are \Q\E or \E we
2494      skip them too. This makes for compatibility with Perl. */      skip them too. This makes for compatibility with Perl. */
2495    
2496      negate_class = FALSE;      negate_class = FALSE;
2497      for (;;)      for (;;)
2498        {        {
2499        c = *(++ptr);        c = *(++ptr);
2500        if (c == '\\')        if (c == '\\')
2501          {          {
2502          if (ptr[1] == 'E') ptr++;          if (ptr[1] == 'E') ptr++;
2503            else if (strncmp((const char *)ptr+1, "Q\\E", 3) == 0) ptr += 3;            else if (strncmp((const char *)ptr+1, "Q\\E", 3) == 0) ptr += 3;
2504              else break;              else break;
2505          }          }
2506        else if (!negate_class && c == '^')        else if (!negate_class && c == '^')
2507          negate_class = TRUE;          negate_class = TRUE;
2508        else break;        else break;
2509        }        }
2510    
2511      /* Keep a count of chars with values < 256 so that we can optimize the case      /* Keep a count of chars with values < 256 so that we can optimize the case
2512      of just a single character (as long as it's < 256). However, For higher      of just a single character (as long as it's < 256). However, For higher
# Line 3075  for (;; ptr++) Line 3111  for (;; ptr++)
3111        *errorcodeptr = ERR6;        *errorcodeptr = ERR6;
3112        goto FAILED;        goto FAILED;
3113        }        }
3114    
3115      /* If class_charcount is 1, we saw precisely one character whose value is      /* If class_charcount is 1, we saw precisely one character whose value is
3116      less than 256. In non-UTF-8 mode we can always optimize. In UTF-8 mode, we      less than 256. In non-UTF-8 mode we can always optimize. In UTF-8 mode, we
3117      can optimize the negative case only if there were no characters >= 128      can optimize the negative case only if there were no characters >= 128
# Line 3860  for (;; ptr++) Line 3896  for (;; ptr++)
3896      /* ===================================================================*/      /* ===================================================================*/
3897      /* Start of nested parenthesized sub-expression, or comment or lookahead or      /* Start of nested parenthesized sub-expression, or comment or lookahead or
3898      lookbehind or option setting or condition or all the other extended      lookbehind or option setting or condition or all the other extended
3899      parenthesis forms. First deal with the specials; all are introduced by ?,      parenthesis forms.  */
     and the appearance of any of them means that this is not a capturing  
     group. */  
3900    
3901      case '(':      case '(':
3902      newoptions = options;      newoptions = options;
# Line 3871  for (;; ptr++) Line 3905  for (;; ptr++)
3905      save_hwm = cd->hwm;      save_hwm = cd->hwm;
3906      reset_bracount = FALSE;      reset_bracount = FALSE;
3907    
3908      if (*(++ptr) == '?')      /* First deal with various "verbs" that can be introduced by '*'. */
3909    
3910        if (*(++ptr) == '*' && (cd->ctypes[ptr[1]] & ctype_letter) != 0)
3911          {
3912          int i, namelen;
3913          const uschar *name = ++ptr;
3914          previous = NULL;
3915          while ((cd->ctypes[*++ptr] & ctype_letter) != 0);
3916          if (*ptr == ':')
3917            {
3918            *errorcodeptr = ERR59;   /* Not supported */
3919            goto FAILED;
3920            }
3921          if (*ptr != ')')
3922            {
3923            *errorcodeptr = ERR60;
3924            goto FAILED;
3925            }
3926          namelen = ptr - name;
3927          for (i = 0; i < verbcount; i++)
3928            {
3929            if (namelen == verbs[i].len &&
3930                strncmp((char *)name, verbs[i].name, namelen) == 0)
3931              {
3932              *code = verbs[i].op;
3933              if (*code++ == OP_ACCEPT) cd->had_accept = TRUE;
3934              break;
3935              }
3936            }
3937          if (i < verbcount) continue;
3938          *errorcodeptr = ERR60;
3939          goto FAILED;
3940          }
3941    
3942        /* Deal with the extended parentheses; all are introduced by '?', and the
3943        appearance of any of them means that this is not a capturing group. */
3944    
3945        else if (*ptr == '?')
3946        {        {
3947        int i, set, unset, namelen;        int i, set, unset, namelen;
3948        int *optset;        int *optset;
# Line 4113  for (;; ptr++) Line 4184  for (;; ptr++)
4184    
4185          /* ------------------------------------------------------------ */          /* ------------------------------------------------------------ */
4186          case '!':                 /* Negative lookahead */          case '!':                 /* Negative lookahead */
         bravalue = OP_ASSERT_NOT;  
4187          ptr++;          ptr++;
4188            if (*ptr == ')')          /* Optimize (?!) */
4189              {
4190              *code++ = OP_FAIL;
4191              previous = NULL;
4192              continue;
4193              }
4194            bravalue = OP_ASSERT_NOT;
4195          break;          break;
4196    
4197    
# Line 5706  cd->start_code = codestart; Line 5783  cd->start_code = codestart;
5783  cd->hwm = cworkspace;  cd->hwm = cworkspace;
5784  cd->req_varyopt = 0;  cd->req_varyopt = 0;
5785  cd->nopartial = FALSE;  cd->nopartial = FALSE;
5786    cd->had_accept = FALSE;
5787    
5788  /* Set up a starting, non-extracting bracket, then compile the expression. On  /* Set up a starting, non-extracting bracket, then compile the expression. On
5789  error, errorcode will be set non-zero, so we don't need to look at the result  error, errorcode will be set non-zero, so we don't need to look at the result
# Line 5720  re->top_bracket = cd->bracount; Line 5798  re->top_bracket = cd->bracount;
5798  re->top_backref = cd->top_backref;  re->top_backref = cd->top_backref;
5799    
5800  if (cd->nopartial) re->options |= PCRE_NOPARTIAL;  if (cd->nopartial) re->options |= PCRE_NOPARTIAL;
5801    if (cd->had_accept) reqbyte = -1;   /* Must disable after (*ACCEPT) */
5802    
5803  /* If not reached end of pattern on success, there's an excess bracket. */  /* If not reached end of pattern on success, there's an excess bracket. */
5804    

Legend:
Removed from v.206  
changed lines
  Added in v.213

  ViewVC Help
Powered by ViewVC 1.1.5