/[pcre]/code/branches/pcre16/pcre_compile.c
ViewVC logotype

Diff of /code/branches/pcre16/pcre_compile.c

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

revision 654 by ph10, Tue Aug 2 11:00:40 2011 UTC revision 733 by ph10, Tue Oct 11 10:29:36 2011 UTC
# Line 1506  for (;;) Line 1506  for (;;)
1506      case OP_CBRA:      case OP_CBRA:
1507      case OP_BRA:      case OP_BRA:
1508      case OP_ONCE:      case OP_ONCE:
1509        case OP_ONCE_NC:
1510      case OP_COND:      case OP_COND:
1511      d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), utf8, atend, cd);      d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), utf8, atend, cd);
1512      if (d < 0) return d;      if (d < 0) return d;
# Line 1761  for (;;) Line 1762  for (;;)
1762        break;        break;
1763    
1764        case OP_THEN_ARG:        case OP_THEN_ARG:
1765        code += code[1+LINK_SIZE];        code += code[1];
1766        break;        break;
1767        }        }
1768    
# Line 1880  for (;;) Line 1881  for (;;)
1881        break;        break;
1882    
1883        case OP_THEN_ARG:        case OP_THEN_ARG:
1884        code += code[1+LINK_SIZE];        code += code[1];
1885        break;        break;
1886        }        }
1887    
# Line 2045  for (code = first_significant_code(code Line 2046  for (code = first_significant_code(code
2046    
2047    if (c == OP_BRA  || c == OP_BRAPOS ||    if (c == OP_BRA  || c == OP_BRAPOS ||
2048        c == OP_CBRA || c == OP_CBRAPOS ||        c == OP_CBRA || c == OP_CBRAPOS ||
2049        c == OP_ONCE || c == OP_COND)        c == OP_ONCE || c == OP_ONCE_NC ||
2050          c == OP_COND)
2051      {      {
2052      BOOL empty_branch;      BOOL empty_branch;
2053      if (GET(code, 1) == 0) return TRUE;    /* Hit unclosed bracket */      if (GET(code, 1) == 0) return TRUE;    /* Hit unclosed bracket */
# Line 2217  for (code = first_significant_code(code Line 2219  for (code = first_significant_code(code
2219      break;      break;
2220    
2221      case OP_THEN_ARG:      case OP_THEN_ARG:
2222      code += code[1+LINK_SIZE];      code += code[1];
2223      break;      break;
2224    
2225      /* None of the remaining opcodes are required to match a character. */      /* None of the remaining opcodes are required to match a character. */
# Line 2295  I think. Line 2297  I think.
2297  A user pointed out that PCRE was rejecting [:a[:digit:]] whereas Perl was not.  A user pointed out that PCRE was rejecting [:a[:digit:]] whereas Perl was not.
2298  It seems that the appearance of a nested POSIX class supersedes an apparent  It seems that the appearance of a nested POSIX class supersedes an apparent
2299  external class. For example, [:a[:digit:]b:] matches "a", "b", ":", or  external class. For example, [:a[:digit:]b:] matches "a", "b", ":", or
2300  a digit. Also, unescaped square brackets may also appear as part of class  a digit.
2301  names. For example, [:a[:abc]b:] gives unknown class "[:abc]b:]"in Perl.  
2302    In Perl, unescaped square brackets may also appear as part of class names. For
2303    example, [:a[:abc]b:] gives unknown POSIX class "[:abc]b:]". However, for
2304    [:a[:abc]b][b:] it gives unknown POSIX class "[:abc]b][b:]", which does not
2305    seem right at all. PCRE does not allow closing square brackets in POSIX class
2306    names.
2307    
2308  Arguments:  Arguments:
2309    ptr      pointer to the initial [    ptr      pointer to the initial [
# Line 2314  for (++ptr; *ptr != 0; ptr++) Line 2321  for (++ptr; *ptr != 0; ptr++)
2321    {    {
2322    if (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)    if (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)
2323      ptr++;      ptr++;
2324      else if (*ptr == CHAR_RIGHT_SQUARE_BRACKET) return FALSE;
2325    else    else
2326      {      {
2327      if (*ptr == terminator && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)      if (*ptr == terminator && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)
# Line 3086  uschar *class_utf8data_base; Line 3094  uschar *class_utf8data_base;
3094  uschar utf8_char[6];  uschar utf8_char[6];
3095  #else  #else
3096  BOOL utf8 = FALSE;  BOOL utf8 = FALSE;
 uschar *utf8_char = NULL;  
3097  #endif  #endif
3098    
3099  #ifdef PCRE_DEBUG  #ifdef PCRE_DEBUG
# Line 3137  for (;; ptr++) Line 3144  for (;; ptr++)
3144    int subfirstbyte;    int subfirstbyte;
3145    int terminator;    int terminator;
3146    int mclength;    int mclength;
3147      int tempbracount;
3148    uschar mcbuffer[8];    uschar mcbuffer[8];
3149    
3150    /* Get next byte in the pattern */    /* Get next byte in the pattern */
# Line 4835  for (;; ptr++) Line 4843  for (;; ptr++)
4843          uschar *ketcode = code - 1 - LINK_SIZE;          uschar *ketcode = code - 1 - LINK_SIZE;
4844          uschar *bracode = ketcode - GET(ketcode, 1);          uschar *bracode = ketcode - GET(ketcode, 1);
4845    
4846          if (*bracode == OP_ONCE && possessive_quantifier) *bracode = OP_BRA;          if ((*bracode == OP_ONCE || *bracode == OP_ONCE_NC) &&
4847          if (*bracode == OP_ONCE)              possessive_quantifier) *bracode = OP_BRA;
4848    
4849            if (*bracode == OP_ONCE || *bracode == OP_ONCE_NC)
4850            *ketcode = OP_KETRMAX + repeat_type;            *ketcode = OP_KETRMAX + repeat_type;
4851          else          else
4852            {            {
# Line 5040  for (;; ptr++) Line 5050  for (;; ptr++)
5050                PUT2INC(code, 0, oc->number);                PUT2INC(code, 0, oc->number);
5051                }                }
5052              *code++ = (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;              *code++ = (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;
5053    
5054                /* Do not set firstbyte after *ACCEPT */
5055                if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;
5056              }              }
5057    
5058            /* Handle other cases with/without an argument */            /* Handle other cases with/without an argument */
# Line 5052  for (;; ptr++) Line 5065  for (;; ptr++)
5065                goto FAILED;                goto FAILED;
5066                }                }
5067              *code = verbs[i].op;              *code = verbs[i].op;
5068              if (*code++ == OP_THEN)              if (*code++ == OP_THEN) cd->external_flags |= PCRE_HASTHEN;
               {  
               PUT(code, 0, code - bcptr->current_branch - 1);  
               code += LINK_SIZE;  
               }  
5069              }              }
5070    
5071            else            else
# Line 5067  for (;; ptr++) Line 5076  for (;; ptr++)
5076                goto FAILED;                goto FAILED;
5077                }                }
5078              *code = verbs[i].op_arg;              *code = verbs[i].op_arg;
5079              if (*code++ == OP_THEN_ARG)              if (*code++ == OP_THEN_ARG) cd->external_flags |= PCRE_HASTHEN;
               {  
               PUT(code, 0, code - bcptr->current_branch - 1);  
               code += LINK_SIZE;  
               }  
5080              *code++ = arglen;              *code++ = arglen;
5081              memcpy(code, arg, arglen);              memcpy(code, arg, arglen);
5082              code += arglen;              code += arglen;
# Line 5906  for (;; ptr++) Line 5911  for (;; ptr++)
5911      *code = bravalue;      *code = bravalue;
5912      tempcode = code;      tempcode = code;
5913      tempreqvary = cd->req_varyopt;        /* Save value before bracket */      tempreqvary = cd->req_varyopt;        /* Save value before bracket */
5914        tempbracount = cd->bracount;          /* Save value before bracket */
5915      length_prevgroup = 0;                 /* Initialize for pre-compile phase */      length_prevgroup = 0;                 /* Initialize for pre-compile phase */
5916    
5917      if (!compile_regex(      if (!compile_regex(
# Line 5928  for (;; ptr++) Line 5934  for (;; ptr++)
5934           ))           ))
5935        goto FAILED;        goto FAILED;
5936    
5937        /* If this was an atomic group and there are no capturing groups within it,
5938        generate OP_ONCE_NC instead of OP_ONCE. */
5939    
5940        if (bravalue == OP_ONCE && cd->bracount <= tempbracount)
5941          *code = OP_ONCE_NC;
5942    
5943      if (bravalue >= OP_ASSERT && bravalue <= OP_ASSERTBACK_NOT)      if (bravalue >= OP_ASSERT && bravalue <= OP_ASSERTBACK_NOT)
5944        cd->assert_depth -= 1;        cd->assert_depth -= 1;
5945    
5946      /* At the end of compiling, code is still pointing to the start of the      /* At the end of compiling, code is still pointing to the start of the
5947      group, while tempcode has been updated to point past the end of the group      group, while tempcode has been updated to point past the end of the group.
5948      and any option resetting that may follow it. The pattern pointer (ptr)      The pattern pointer (ptr) is on the bracket.
     is on the bracket. */  
5949    
5950      /* If this is a conditional bracket, check that there are no more than      If this is a conditional bracket, check that there are no more than
5951      two branches in the group, or just one if it's a DEFINE group. We do this      two branches in the group, or just one if it's a DEFINE group. We do this
5952      in the real compile phase, not in the pre-pass, where the whole group may      in the real compile phase, not in the pre-pass, where the whole group may
5953      not be available. */      not be available. */
# Line 6335  for (;; ptr++) Line 6346  for (;; ptr++)
6346        else firstbyte = reqbyte = REQ_NONE;        else firstbyte = reqbyte = REQ_NONE;
6347        }        }
6348    
6349      /* firstbyte was previously set; we can set reqbyte only the length is      /* firstbyte was previously set; we can set reqbyte only if the length is
6350      1 or the matching is caseful. */      1 or the matching is caseful. */
6351    
6352      else      else
# Line 6727  do { Line 6738  do {
6738    
6739     /* Other brackets */     /* Other brackets */
6740    
6741     else if (op == OP_ASSERT || op == OP_ONCE || op == OP_COND)     else if (op == OP_ASSERT || op == OP_ONCE || op == OP_ONCE_NC ||
6742                op == OP_COND)
6743       {       {
6744       if (!is_anchored(scode, bracket_map, backref_map)) return FALSE;       if (!is_anchored(scode, bracket_map, backref_map)) return FALSE;
6745       }       }
# Line 6831  do { Line 6843  do {
6843    
6844     /* Other brackets */     /* Other brackets */
6845    
6846     else if (op == OP_ASSERT || op == OP_ONCE)     else if (op == OP_ASSERT || op == OP_ONCE || op == OP_ONCE_NC)
6847       {       {
6848       if (!is_startline(scode, bracket_map, backref_map)) return FALSE;       if (!is_startline(scode, bracket_map, backref_map)) return FALSE;
6849       }       }
# Line 6901  do { Line 6913  do {
6913       case OP_SCBRAPOS:       case OP_SCBRAPOS:
6914       case OP_ASSERT:       case OP_ASSERT:
6915       case OP_ONCE:       case OP_ONCE:
6916         case OP_ONCE_NC:
6917       case OP_COND:       case OP_COND:
6918       if ((d = find_firstassertedchar(scode, op == OP_ASSERT)) < 0)       if ((d = find_firstassertedchar(scode, op == OP_ASSERT)) < 0)
6919         return -1;         return -1;
# Line 7282  re->top_bracket = cd->bracount; Line 7295  re->top_bracket = cd->bracount;
7295  re->top_backref = cd->top_backref;  re->top_backref = cd->top_backref;
7296  re->flags = cd->external_flags;  re->flags = cd->external_flags;
7297    
7298  if (cd->had_accept) reqbyte = -1;   /* Must disable after (*ACCEPT) */  if (cd->had_accept) reqbyte = REQ_NONE;   /* Must disable after (*ACCEPT) */
7299    
7300  /* 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. */
7301    

Legend:
Removed from v.654  
changed lines
  Added in v.733

  ViewVC Help
Powered by ViewVC 1.1.5