/[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 545 by ph10, Wed Jun 16 10:51:15 2010 UTC revision 556 by ph10, Tue Oct 26 11:06:44 2010 UTC
# Line 1110  Arguments: Line 1110  Arguments:
1110    name         name to seek, or NULL if seeking a numbered subpattern    name         name to seek, or NULL if seeking a numbered subpattern
1111    lorn         name length, or subpattern number if name is NULL    lorn         name length, or subpattern number if name is NULL
1112    xmode        TRUE if we are in /x mode    xmode        TRUE if we are in /x mode
1113      utf8         TRUE if we are in UTF-8 mode
1114    count        pointer to the current capturing subpattern number (updated)    count        pointer to the current capturing subpattern number (updated)
1115    
1116  Returns:       the number of the named subpattern, or -1 if not found  Returns:       the number of the named subpattern, or -1 if not found
# Line 1117  Returns:       the number of the named s Line 1118  Returns:       the number of the named s
1118    
1119  static int  static int
1120  find_parens_sub(uschar **ptrptr, compile_data *cd, const uschar *name, int lorn,  find_parens_sub(uschar **ptrptr, compile_data *cd, const uschar *name, int lorn,
1121    BOOL xmode, int *count)    BOOL xmode, BOOL utf8, int *count)
1122  {  {
1123  uschar *ptr = *ptrptr;  uschar *ptr = *ptrptr;
1124  int start_count = *count;  int start_count = *count;
# Line 1278  for (; *ptr != 0; ptr++) Line 1279  for (; *ptr != 0; ptr++)
1279    
1280    if (xmode && *ptr == CHAR_NUMBER_SIGN)    if (xmode && *ptr == CHAR_NUMBER_SIGN)
1281      {      {
1282      while (*(++ptr) != 0 && *ptr != CHAR_NL) {};      ptr++;
1283        while (*ptr != 0)
1284          {
1285          if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }
1286          ptr++;
1287    #ifdef SUPPORT_UTF8
1288          if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++;
1289    #endif
1290          }
1291      if (*ptr == 0) goto FAIL_EXIT;      if (*ptr == 0) goto FAIL_EXIT;
1292      continue;      continue;
1293      }      }
# Line 1287  for (; *ptr != 0; ptr++) Line 1296  for (; *ptr != 0; ptr++)
1296    
1297    if (*ptr == CHAR_LEFT_PARENTHESIS)    if (*ptr == CHAR_LEFT_PARENTHESIS)
1298      {      {
1299      int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, count);      int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf8, count);
1300      if (rc > 0) return rc;      if (rc > 0) return rc;
1301      if (*ptr == 0) goto FAIL_EXIT;      if (*ptr == 0) goto FAIL_EXIT;
1302      }      }
# Line 1333  Arguments: Line 1342  Arguments:
1342    name         name to seek, or NULL if seeking a numbered subpattern    name         name to seek, or NULL if seeking a numbered subpattern
1343    lorn         name length, or subpattern number if name is NULL    lorn         name length, or subpattern number if name is NULL
1344    xmode        TRUE if we are in /x mode    xmode        TRUE if we are in /x mode
1345      utf8         TRUE if we are in UTF-8 mode
1346    
1347  Returns:       the number of the found subpattern, or -1 if not found  Returns:       the number of the found subpattern, or -1 if not found
1348  */  */
1349    
1350  static int  static int
1351  find_parens(compile_data *cd, const uschar *name, int lorn, BOOL xmode)  find_parens(compile_data *cd, const uschar *name, int lorn, BOOL xmode,
1352      BOOL utf8)
1353  {  {
1354  uschar *ptr = (uschar *)cd->start_pattern;  uschar *ptr = (uschar *)cd->start_pattern;
1355  int count = 0;  int count = 0;
# Line 1351  matching closing parens. That is why we Line 1362  matching closing parens. That is why we
1362    
1363  for (;;)  for (;;)
1364    {    {
1365    rc = find_parens_sub(&ptr, cd, name, lorn, xmode, &count);    rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf8, &count);
1366    if (rc > 0 || *ptr++ == 0) break;    if (rc > 0 || *ptr++ == 0) break;
1367    }    }
1368    
# Line 1724  for (;;) Line 1735  for (;;)
1735        case OP_MARK:        case OP_MARK:
1736        case OP_PRUNE_ARG:        case OP_PRUNE_ARG:
1737        case OP_SKIP_ARG:        case OP_SKIP_ARG:
       case OP_THEN_ARG:  
1738        code += code[1];        code += code[1];
1739        break;        break;
1740    
1741          case OP_THEN_ARG:
1742          code += code[1+LINK_SIZE];
1743          break;
1744        }        }
1745    
1746      /* Add in the fixed length from the table */      /* Add in the fixed length from the table */
# Line 1827  for (;;) Line 1841  for (;;)
1841        case OP_MARK:        case OP_MARK:
1842        case OP_PRUNE_ARG:        case OP_PRUNE_ARG:
1843        case OP_SKIP_ARG:        case OP_SKIP_ARG:
       case OP_THEN_ARG:  
1844        code += code[1];        code += code[1];
1845        break;        break;
1846    
1847          case OP_THEN_ARG:
1848          code += code[1+LINK_SIZE];
1849          break;
1850        }        }
1851    
1852      /* Add in the fixed length from the table */      /* Add in the fixed length from the table */
# Line 2105  for (code = first_significant_code(code Line 2122  for (code = first_significant_code(code
2122      case OP_MARK:      case OP_MARK:
2123      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
2124      case OP_SKIP_ARG:      case OP_SKIP_ARG:
     case OP_THEN_ARG:  
2125      code += code[1];      code += code[1];
2126      break;      break;
2127    
2128        case OP_THEN_ARG:
2129        code += code[1+LINK_SIZE];
2130        break;
2131    
2132      /* None of the remaining opcodes are required to match a character. */      /* None of the remaining opcodes are required to match a character. */
2133    
2134      default:      default:
# Line 2506  if ((options & PCRE_EXTENDED) != 0) Line 2526  if ((options & PCRE_EXTENDED) != 0)
2526      while ((cd->ctypes[*ptr] & ctype_space) != 0) ptr++;      while ((cd->ctypes[*ptr] & ctype_space) != 0) ptr++;
2527      if (*ptr == CHAR_NUMBER_SIGN)      if (*ptr == CHAR_NUMBER_SIGN)
2528        {        {
2529        while (*(++ptr) != 0)        ptr++;
2530          while (*ptr != 0)
2531            {
2532          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }
2533            ptr++;
2534    #ifdef SUPPORT_UTF8
2535            if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++;
2536    #endif
2537            }
2538        }        }
2539      else break;      else break;
2540      }      }
# Line 2543  if ((options & PCRE_EXTENDED) != 0) Line 2570  if ((options & PCRE_EXTENDED) != 0)
2570      while ((cd->ctypes[*ptr] & ctype_space) != 0) ptr++;      while ((cd->ctypes[*ptr] & ctype_space) != 0) ptr++;
2571      if (*ptr == CHAR_NUMBER_SIGN)      if (*ptr == CHAR_NUMBER_SIGN)
2572        {        {
2573        while (*(++ptr) != 0)        ptr++;
2574          while (*ptr != 0)
2575            {
2576          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }
2577            ptr++;
2578    #ifdef SUPPORT_UTF8
2579            if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++;
2580    #endif
2581            }
2582        }        }
2583      else break;      else break;
2584      }      }
# Line 3117  for (;; ptr++) Line 3151  for (;; ptr++)
3151      if ((cd->ctypes[c] & ctype_space) != 0) continue;      if ((cd->ctypes[c] & ctype_space) != 0) continue;
3152      if (c == CHAR_NUMBER_SIGN)      if (c == CHAR_NUMBER_SIGN)
3153        {        {
3154        while (*(++ptr) != 0)        ptr++;
3155          while (*ptr != 0)
3156          {          {
3157          if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }
3158            ptr++;
3159    #ifdef SUPPORT_UTF8
3160            if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++;
3161    #endif
3162          }          }
3163        if (*ptr != 0) continue;        if (*ptr != 0) continue;
3164    
# Line 3494  for (;; ptr++) Line 3533  for (;; ptr++)
3533              for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_word];              for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_word];
3534              continue;              continue;
3535    
3536                /* Perl 5.004 onwards omits VT from \s, but we must preserve it
3537                if it was previously set by something earlier in the character
3538                class. */
3539    
3540              case ESC_s:              case ESC_s:
3541              for (c = 0; c < 32; c++) classbits[c] |= cbits[c+cbit_space];              classbits[0] |= cbits[cbit_space];
3542              classbits[1] &= ~0x08;   /* Perl 5.004 onwards omits VT from \s */              classbits[1] |= cbits[cbit_space+1] & ~0x08;
3543                for (c = 2; c < 32; c++) classbits[c] |= cbits[c+cbit_space];
3544              continue;              continue;
3545    
3546              case ESC_S:              case ESC_S:
# Line 4808  for (;; ptr++) Line 4852  for (;; ptr++)
4852                *errorcodeptr = ERR66;                *errorcodeptr = ERR66;
4853                goto FAILED;                goto FAILED;
4854                }                }
4855              *code++ = verbs[i].op;              *code = verbs[i].op;
4856                if (*code++ == OP_THEN)
4857                  {
4858                  PUT(code, 0, code - bcptr->current_branch - 1);
4859                  code += LINK_SIZE;
4860                  }
4861              }              }
4862    
4863            else            else
# Line 4818  for (;; ptr++) Line 4867  for (;; ptr++)
4867                *errorcodeptr = ERR59;                *errorcodeptr = ERR59;
4868                goto FAILED;                goto FAILED;
4869                }                }
4870              *code++ = verbs[i].op_arg;              *code = verbs[i].op_arg;
4871                if (*code++ == OP_THEN_ARG)
4872                  {
4873                  PUT(code, 0, code - bcptr->current_branch - 1);
4874                  code += LINK_SIZE;
4875                  }
4876              *code++ = arglen;              *code++ = arglen;
4877              memcpy(code, arg, arglen);              memcpy(code, arg, arglen);
4878              code += arglen;              code += arglen;
# Line 5012  for (;; ptr++) Line 5066  for (;; ptr++)
5066          /* Search the pattern for a forward reference */          /* Search the pattern for a forward reference */
5067    
5068          else if ((i = find_parens(cd, name, namelen,          else if ((i = find_parens(cd, name, namelen,
5069                          (options & PCRE_EXTENDED) != 0)) > 0)                          (options & PCRE_EXTENDED) != 0, utf8)) > 0)
5070            {            {
5071            PUT2(code, 2+LINK_SIZE, i);            PUT2(code, 2+LINK_SIZE, i);
5072            code[1+LINK_SIZE]++;            code[1+LINK_SIZE]++;
# Line 5358  for (;; ptr++) Line 5412  for (;; ptr++)
5412              }              }
5413            else if ((recno =                /* Forward back reference */            else if ((recno =                /* Forward back reference */
5414                      find_parens(cd, name, namelen,                      find_parens(cd, name, namelen,
5415                        (options & PCRE_EXTENDED) != 0)) <= 0)                        (options & PCRE_EXTENDED) != 0, utf8)) <= 0)
5416              {              {
5417              *errorcodeptr = ERR15;              *errorcodeptr = ERR15;
5418              goto FAILED;              goto FAILED;
# Line 5469  for (;; ptr++) Line 5523  for (;; ptr++)
5523              if (called == NULL)              if (called == NULL)
5524                {                {
5525                if (find_parens(cd, NULL, recno,                if (find_parens(cd, NULL, recno,
5526                      (options & PCRE_EXTENDED) != 0) < 0)                      (options & PCRE_EXTENDED) != 0, utf8) < 0)
5527                  {                  {
5528                  *errorcodeptr = ERR15;                  *errorcodeptr = ERR15;
5529                  goto FAILED;                  goto FAILED;

Legend:
Removed from v.545  
changed lines
  Added in v.556

  ViewVC Help
Powered by ViewVC 1.1.5