/[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 1312 by ph10, Fri Apr 5 15:35:59 2013 UTC revision 1313 by ph10, Wed Apr 24 12:07:09 2013 UTC
# Line 487  static const char error_texts[] = Line 487  static const char error_texts[] =
487    "a numbered reference must not be zero\0"    "a numbered reference must not be zero\0"
488    "an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)\0"    "an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)\0"
489    /* 60 */    /* 60 */
490    "(*VERB) not recognized\0"    "(*VERB) not recognized or malformed\0"
491    "number is too big\0"    "number is too big\0"
492    "subpattern name expected\0"    "subpattern name expected\0"
493    "digit expected after (?+\0"    "digit expected after (?+\0"
# Line 798  Otherwise further processing may be requ Line 798  Otherwise further processing may be requ
798  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
799  /* Not alphanumeric */  /* Not alphanumeric */
800  else if (c < CHAR_0 || c > CHAR_z) {}  else if (c < CHAR_0 || c > CHAR_z) {}
801  else if ((i = escapes[c - CHAR_0]) != 0)  else if ((i = escapes[c - CHAR_0]) != 0)
802    { if (i > 0) c = (pcre_uint32)i; else escape = -i; }    { if (i > 0) c = (pcre_uint32)i; else escape = -i; }
803    
804  #else           /* EBCDIC coding */  #else           /* EBCDIC coding */
# Line 1410  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1410  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1410    {    {
1411    /* Handle specials such as (*SKIP) or (*UTF8) etc. */    /* Handle specials such as (*SKIP) or (*UTF8) etc. */
1412    
1413    if (ptr[1] == CHAR_ASTERISK)    if (ptr[1] == CHAR_ASTERISK)
1414      {      {
1415      ptr += 2;      ptr += 2;
1416      while (ptr < cd->end_pattern && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;      while (ptr < cd->end_pattern && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
1417      }      }
1418    
1419    /* Handle a normal, unnamed capturing parenthesis. */    /* Handle a normal, unnamed capturing parenthesis. */
1420    
# Line 3091  value is a character, a negative value i Line 3091  value is a character, a negative value i
3091  if (*ptr == CHAR_BACKSLASH)  if (*ptr == CHAR_BACKSLASH)
3092    {    {
3093    int temperrorcode = 0;    int temperrorcode = 0;
3094    escape = check_escape(&ptr, &next, &temperrorcode, cd->bracount, options,    escape = check_escape(&ptr, &next, &temperrorcode, cd->bracount, options,
3095      FALSE);      FALSE);
3096    if (temperrorcode != 0) return FALSE;    if (temperrorcode != 0) return FALSE;
3097    ptr++;    /* Point after the escape sequence */    ptr++;    /* Point after the escape sequence */
# Line 4275  for (;; ptr++) Line 4275  for (;; ptr++)
4275    
4276        if (c == CHAR_BACKSLASH)        if (c == CHAR_BACKSLASH)
4277          {          {
4278          escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options,          escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options,
4279            TRUE);            TRUE);
4280          if (*errorcodeptr != 0) goto FAILED;          if (*errorcodeptr != 0) goto FAILED;
4281          if (escape == 0) c = ec;          if (escape == 0) c = ec;
# Line 5725  for (;; ptr++) Line 5725  for (;; ptr++)
5725          /* ------------------------------------------------------------ */          /* ------------------------------------------------------------ */
5726          case CHAR_LEFT_PARENTHESIS:          case CHAR_LEFT_PARENTHESIS:
5727          bravalue = OP_COND;       /* Conditional group */          bravalue = OP_COND;       /* Conditional group */
5728          tempptr = ptr;          tempptr = ptr;
5729    
5730          /* A condition can be an assertion, a number (referring to a numbered          /* A condition can be an assertion, a number (referring to a numbered
5731          group), a name (referring to a named group), or 'R', referring to          group), a name (referring to a named group), or 'R', referring to
# Line 5739  for (;; ptr++) Line 5739  for (;; ptr++)
5739          by digits), and (b) a number could be a name that consists of digits.          by digits), and (b) a number could be a name that consists of digits.
5740          In both cases, we look for a name first; if not found, we try the other          In both cases, we look for a name first; if not found, we try the other
5741          cases.          cases.
5742    
5743          For compatibility with auto-callouts, we allow a callout to be          For compatibility with auto-callouts, we allow a callout to be
5744          specified before a condition that is an assertion. First, check for the          specified before a condition that is an assertion. First, check for the
5745          syntax of a callout; if found, adjust the temporary pointer that is          syntax of a callout; if found, adjust the temporary pointer that is
5746          used to check for an assertion condition. That's all that is needed! */          used to check for an assertion condition. That's all that is needed! */
5747    
5748          if (ptr[1] == CHAR_QUESTION_MARK && ptr[2] == CHAR_C)          if (ptr[1] == CHAR_QUESTION_MARK && ptr[2] == CHAR_C)
5749            {            {
5750            for (i = 3;; i++) if (!IS_DIGIT(ptr[i])) break;            for (i = 3;; i++) if (!IS_DIGIT(ptr[i])) break;
5751            if (ptr[i] == CHAR_RIGHT_PARENTHESIS)            if (ptr[i] == CHAR_RIGHT_PARENTHESIS)
5752              tempptr += i + 1;              tempptr += i + 1;
5753            }            }
5754    
5755          /* For conditions that are assertions, check the syntax, and then exit          /* For conditions that are assertions, check the syntax, and then exit
5756          the switch. This will take control down to where bracketed groups,          the switch. This will take control down to where bracketed groups,
5757          including assertions, are processed. */          including assertions, are processed. */
5758    
5759          if (tempptr[1] == CHAR_QUESTION_MARK &&          if (tempptr[1] == CHAR_QUESTION_MARK &&
5760                (tempptr[2] == CHAR_EQUALS_SIGN ||                (tempptr[2] == CHAR_EQUALS_SIGN ||
5761                 tempptr[2] == CHAR_EXCLAMATION_MARK ||                 tempptr[2] == CHAR_EXCLAMATION_MARK ||
5762                 tempptr[2] == CHAR_LESS_THAN_SIGN))                 tempptr[2] == CHAR_LESS_THAN_SIGN))
5763            break;            break;
5764    
# Line 6901  for (;; ptr++) Line 6901  for (;; ptr++)
6901    
6902        else        else
6903          {          {
6904          if ((escape == ESC_b || escape == ESC_B || escape == ESC_A) &&          if ((escape == ESC_b || escape == ESC_B || escape == ESC_A) &&
6905               cd->max_lookbehind == 0)               cd->max_lookbehind == 0)
6906            cd->max_lookbehind = 1;            cd->max_lookbehind = 1;
6907  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 7766  pcre32_compile2(PCRE_SPTR32 pattern, int Line 7766  pcre32_compile2(PCRE_SPTR32 pattern, int
7766  {  {
7767  REAL_PCRE *re;  REAL_PCRE *re;
7768  int length = 1;  /* For final END opcode */  int length = 1;  /* For final END opcode */
 pcre_uint32 firstchar, reqchar;  
7769  pcre_int32 firstcharflags, reqcharflags;  pcre_int32 firstcharflags, reqcharflags;
7770    pcre_uint32 firstchar, reqchar;
7771    pcre_uint32 limit_match = PCRE_UINT32_MAX;
7772    pcre_uint32 limit_recursion = PCRE_UINT32_MAX;
7773  int newline;  int newline;
7774  int errorcode = 0;  int errorcode = 0;
7775  int skipatstart = 0;  int skipatstart = 0;
# Line 7831  if ((options & ~PUBLIC_COMPILE_OPTIONS) Line 7833  if ((options & ~PUBLIC_COMPILE_OPTIONS)
7833    errorcode = ERR17;    errorcode = ERR17;
7834    goto PCRE_EARLY_ERROR_RETURN;    goto PCRE_EARLY_ERROR_RETURN;
7835    }    }
7836    
7837  /* If PCRE_NEVER_UTF is set, remember it. As this option steals a bit that is  /* If PCRE_NEVER_UTF is set, remember it. */
7838  also used for execution options, flatten it just in case. */  
7839    if ((options & PCRE_NEVER_UTF) != 0) never_utf = TRUE;
 if ((options & PCRE_NEVER_UTF) != 0)  
   {  
   never_utf = TRUE;  
   options &= ~PCRE_NEVER_UTF;  
   }  
7840    
7841  /* Check for global one-time settings at the start of the pattern, and remember  /* Check for global one-time settings at the start of the pattern, and remember
7842  the offset for later. */  the offset for later. */
7843    
7844    cd->external_flags = 0;   /* Initialize here for LIMIT_MATCH/RECURSION */
7845    
7846  while (ptr[skipatstart] == CHAR_LEFT_PARENTHESIS &&  while (ptr[skipatstart] == CHAR_LEFT_PARENTHESIS &&
7847         ptr[skipatstart+1] == CHAR_ASTERISK)         ptr[skipatstart+1] == CHAR_ASTERISK)
7848    {    {
# Line 7874  PCRE_UTF8 == PCRE_UTF16 == PCRE_UTF32. * Line 7873  PCRE_UTF8 == PCRE_UTF16 == PCRE_UTF32. *
7873    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_NO_START_OPT_RIGHTPAR, 13) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_NO_START_OPT_RIGHTPAR, 13) == 0)
7874      { skipatstart += 15; options |= PCRE_NO_START_OPTIMIZE; continue; }      { skipatstart += 15; options |= PCRE_NO_START_OPTIMIZE; continue; }
7875    
7876      else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_LIMIT_MATCH_EQ, 12) == 0)
7877        {
7878        pcre_uint32 c = 0;
7879        int p = skipatstart + 14;
7880        while (isdigit(ptr[p]))
7881          {
7882          if (c > PCRE_UINT32_MAX / 10 - 1) break;   /* Integer overflow */
7883          c = c*10 + ptr[p++] - CHAR_0;
7884          }
7885        if (ptr[p++] != CHAR_RIGHT_PARENTHESIS) break;
7886        if (c < limit_match)
7887          {
7888          limit_match = c;
7889          cd->external_flags |= PCRE_MLSET;
7890          }
7891        skipatstart = p;
7892        continue;
7893        }
7894    
7895      else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_LIMIT_RECURSION_EQ, 16) == 0)
7896        {
7897        pcre_uint32 c = 0;
7898        int p = skipatstart + 18;
7899        while (isdigit(ptr[p]))
7900          {
7901          if (c > PCRE_UINT32_MAX / 10 - 1) break;   /* Integer overflow check */
7902          c = c*10 + ptr[p++] - CHAR_0;
7903          }
7904        if (ptr[p++] != CHAR_RIGHT_PARENTHESIS) break;
7905        if (c < limit_recursion)
7906          {
7907          limit_recursion = c;
7908          cd->external_flags |= PCRE_RLSET;
7909          }
7910        skipatstart = p;
7911        continue;
7912        }
7913    
7914    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_CR_RIGHTPAR, 3) == 0)    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_CR_RIGHTPAR, 3) == 0)
7915      { skipatstart += 5; newnl = PCRE_NEWLINE_CR; }      { skipatstart += 5; newnl = PCRE_NEWLINE_CR; }
7916    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_LF_RIGHTPAR, 3)  == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_LF_RIGHTPAR, 3)  == 0)
# Line 7896  PCRE_UTF8 == PCRE_UTF16 == PCRE_UTF32. * Line 7933  PCRE_UTF8 == PCRE_UTF16 == PCRE_UTF32. *
7933      options = (options & ~(PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) | newbsr;      options = (options & ~(PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) | newbsr;
7934    else break;    else break;
7935    }    }
7936    
7937  /* PCRE_UTF(16|32) have the same value as PCRE_UTF8. */  /* PCRE_UTF(16|32) have the same value as PCRE_UTF8. */
7938  utf = (options & PCRE_UTF8) != 0;  utf = (options & PCRE_UTF8) != 0;
7939  if (utf && never_utf)  if (utf && never_utf)
7940    {    {
7941    errorcode = ERR78;    errorcode = ERR78;
7942    goto PCRE_EARLY_ERROR_RETURN2;    goto PCRE_EARLY_ERROR_RETURN2;
7943    }    }
7944    
7945  /* Can't support UTF unless PCRE has been compiled to include the code. The  /* Can't support UTF unless PCRE has been compiled to include the code. The
7946  return of an error code from PRIV(valid_utf)() is a new feature, introduced in  return of an error code from PRIV(valid_utf)() is a new feature, introduced in
# Line 8026  cd->req_varyopt = 0; Line 8063  cd->req_varyopt = 0;
8063  cd->assert_depth = 0;  cd->assert_depth = 0;
8064  cd->max_lookbehind = 0;  cd->max_lookbehind = 0;
8065  cd->external_options = options;  cd->external_options = options;
 cd->external_flags = 0;  
8066  cd->open_caps = NULL;  cd->open_caps = NULL;
8067    
8068  /* Now do the pre-compile. On error, errorcode will be set non-zero, so we  /* Now do the pre-compile. On error, errorcode will be set non-zero, so we
# Line 8076  re->magic_number = MAGIC_NUMBER; Line 8112  re->magic_number = MAGIC_NUMBER;
8112  re->size = (int)size;  re->size = (int)size;
8113  re->options = cd->external_options;  re->options = cd->external_options;
8114  re->flags = cd->external_flags;  re->flags = cd->external_flags;
8115    re->limit_match = limit_match;
8116    re->limit_recursion = limit_recursion;
8117  re->first_char = 0;  re->first_char = 0;
8118  re->req_char = 0;  re->req_char = 0;
8119  re->name_table_offset = sizeof(REAL_PCRE) / sizeof(pcre_uchar);  re->name_table_offset = sizeof(REAL_PCRE) / sizeof(pcre_uchar);
# Line 8085  re->ref_count = 0; Line 8123  re->ref_count = 0;
8123  re->tables = (tables == PRIV(default_tables))? NULL : tables;  re->tables = (tables == PRIV(default_tables))? NULL : tables;
8124  re->nullpad = NULL;  re->nullpad = NULL;
8125  #ifdef COMPILE_PCRE32  #ifdef COMPILE_PCRE32
8126  re->dummy1 = re->dummy2 = 0;  re->dummy = 0;
8127    #else
8128    re->dummy1 = re->dummy2 = re->dummy3 = 0;
8129  #endif  #endif
8130    
8131  /* The starting points of the name/number translation table and of the code are  /* The starting points of the name/number translation table and of the code are

Legend:
Removed from v.1312  
changed lines
  Added in v.1313

  ViewVC Help
Powered by ViewVC 1.1.5