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

Diff of /code/trunk/pcre_exec.c

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

revision 1248 by ph10, Wed Feb 13 17:36:38 2013 UTC revision 1271 by ph10, Wed Mar 6 16:50:38 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 56  possible. There are also some static sup Line 56  possible. There are also some static sup
56  #undef min  #undef min
57  #undef max  #undef max
58    
59  /* The md->capture_last field uses the lower 16 bits for the last captured  /* The md->capture_last field uses the lower 16 bits for the last captured
60  substring (which can never be greater than 65535) and a bit in the top half  substring (which can never be greater than 65535) and a bit in the top half
61  to mean "capture vector overflowed". This odd way of doing things was  to mean "capture vector overflowed". This odd way of doing things was
62  implemented when it was realized that preserving and restoring the overflow bit  implemented when it was realized that preserving and restoring the overflow bit
63  whenever the last capture number was saved/restored made for a neater  whenever the last capture number was saved/restored made for a neater
64  interface, and doing it this way saved on (a) another variable, which would  interface, and doing it this way saved on (a) another variable, which would
65  have increased the stack frame size (a big NO-NO in PCRE) and (b) another  have increased the stack frame size (a big NO-NO in PCRE) and (b) another
66  separate set of save/restore instructions. The following defines are used in  separate set of save/restore instructions. The following defines are used in
67  implementing this. */  implementing this. */
68    
69  #define CAPLMASK    0x0000ffff    /* The bits used for last_capture */  #define CAPLMASK    0x0000ffff    /* The bits used for last_capture */
# Line 87  defined PCRE_ERROR_xxx codes, which are Line 87  defined PCRE_ERROR_xxx codes, which are
87  negative to avoid the external error codes. */  negative to avoid the external error codes. */
88    
89  #define MATCH_ACCEPT       (-999)  #define MATCH_ACCEPT       (-999)
90  #define MATCH_COMMIT       (-998)  #define MATCH_KETRPOS      (-998)
91  #define MATCH_KETRPOS      (-997)  #define MATCH_ONCE         (-997)
92  #define MATCH_ONCE         (-996)  /* The next 5 must be kept together and in sequence so that a test that checks
93    for any one of them can use a range. */
94    #define MATCH_COMMIT       (-996)
95  #define MATCH_PRUNE        (-995)  #define MATCH_PRUNE        (-995)
96  #define MATCH_SKIP         (-994)  #define MATCH_SKIP         (-994)
97  #define MATCH_SKIP_ARG     (-993)  #define MATCH_SKIP_ARG     (-993)
98  #define MATCH_THEN         (-992)  #define MATCH_THEN         (-992)
99    #define MATCH_BACKTRACK_MAX MATCH_THEN
100    #define MATCH_BACKTRACK_MIN MATCH_COMMIT
101    
102  /* Maximum number of ints of offset to save on the stack for recursive calls.  /* Maximum number of ints of offset to save on the stack for recursive calls.
103  If the offset vector is bigger, malloc is used. This should be a multiple of 3,  If the offset vector is bigger, malloc is used. This should be a multiple of 3,
# Line 233  if (caseless) Line 237  if (caseless)
237      {      {
238      while (length-- > 0)      while (length-- > 0)
239        {        {
240        pcre_uchar cc, cp;        pcre_uint32 cc, cp;
241        if (eptr >= md->end_subject) return -2;   /* Partial match */        if (eptr >= md->end_subject) return -2;   /* Partial match */
242        cc = RAWUCHARTEST(eptr);        cc = RAWUCHARTEST(eptr);
243        cp = RAWUCHARTEST(p);        cp = RAWUCHARTEST(p);
# Line 308  enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM Line 312  enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM
312         RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,         RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
313         RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,         RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
314         RM51,  RM52, RM53, RM54, RM55, RM56, RM57, RM58, RM59, RM60,         RM51,  RM52, RM53, RM54, RM55, RM56, RM57, RM58, RM59, RM60,
315         RM61,  RM62, RM63, RM64, RM65, RM66, RM67 };         RM61,  RM62, RM63, RM64, RM65, RM66, RM67, RM68 };
316    
317  /* These versions of the macros use the stack, as normal. There are debugging  /* These versions of the macros use the stack, as normal. There are debugging
318  versions and production versions. Note that the "rw" argument of RMATCH isn't  versions and production versions. Note that the "rw" argument of RMATCH isn't
# Line 1310  for (;;) Line 1314  for (;;)
1314          cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);          cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
1315          cb.capture_top      = offset_top/2;          cb.capture_top      = offset_top/2;
1316          cb.capture_last     = md->capture_last & CAPLMASK;          cb.capture_last     = md->capture_last & CAPLMASK;
1317          /* Internal change requires this for API compatibility. */          /* Internal change requires this for API compatibility. */
1318          if (cb.capture_last == 0) cb.capture_last = -1;          if (cb.capture_last == 0) cb.capture_last = -1;
1319          cb.callout_data     = md->callout_data;          cb.callout_data     = md->callout_data;
1320          cb.mark             = md->nomatch_mark;          cb.mark             = md->nomatch_mark;
1321          if ((rrc = (*PUBL(callout))(&cb)) > 0) RRETURN(MATCH_NOMATCH);          if ((rrc = (*PUBL(callout))(&cb)) > 0) RRETURN(MATCH_NOMATCH);
1322          if (rrc < 0) RRETURN(rrc);          if (rrc < 0) RRETURN(rrc);
1323          }          }
1324        ecode += PRIV(OP_lengths)[OP_CALLOUT];        ecode += PRIV(OP_lengths)[OP_CALLOUT];
1325          codelink -= PRIV(OP_lengths)[OP_CALLOUT];
1326        }        }
1327    
1328      condcode = ecode[LINK_SIZE+1];      condcode = ecode[LINK_SIZE+1];
# Line 1737  for (;;) Line 1742  for (;;)
1742        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
1743        cb.capture_top      = offset_top/2;        cb.capture_top      = offset_top/2;
1744        cb.capture_last     = md->capture_last & CAPLMASK;        cb.capture_last     = md->capture_last & CAPLMASK;
1745        /* Internal change requires this for API compatibility. */        /* Internal change requires this for API compatibility. */
1746        if (cb.capture_last == 0) cb.capture_last = -1;        if (cb.capture_last == 0) cb.capture_last = -1;
1747        cb.callout_data     = md->callout_data;        cb.callout_data     = md->callout_data;
1748        cb.mark             = md->nomatch_mark;        cb.mark             = md->nomatch_mark;
1749        if ((rrc = (*PUBL(callout))(&cb)) > 0) RRETURN(MATCH_NOMATCH);        if ((rrc = (*PUBL(callout))(&cb)) > 0) RRETURN(MATCH_NOMATCH);
# Line 1784  for (;;) Line 1789  for (;;)
1789        /* Add to "recursing stack" */        /* Add to "recursing stack" */
1790    
1791        new_recursive.group_num = recno;        new_recursive.group_num = recno;
1792        new_recursive.saved_capture_last = md->capture_last;        new_recursive.saved_capture_last = md->capture_last;
1793        new_recursive.subject_position = eptr;        new_recursive.subject_position = eptr;
1794        new_recursive.prevrec = md->recursive;        new_recursive.prevrec = md->recursive;
1795        md->recursive = &new_recursive;        md->recursive = &new_recursive;
# Line 1821  for (;;) Line 1826  for (;;)
1826            md, eptrb, RM6);            md, eptrb, RM6);
1827          memcpy(md->offset_vector, new_recursive.offset_save,          memcpy(md->offset_vector, new_recursive.offset_save,
1828              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1829          md->capture_last = new_recursive.saved_capture_last;          md->capture_last = new_recursive.saved_capture_last;
1830          md->recursive = new_recursive.prevrec;          md->recursive = new_recursive.prevrec;
1831          if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)          if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
1832            {            {
# Line 1838  for (;;) Line 1843  for (;;)
1843            goto RECURSION_MATCHED;        /* Exit loop; end processing */            goto RECURSION_MATCHED;        /* Exit loop; end processing */
1844            }            }
1845    
1846          /* PCRE does not allow THEN or COMMIT to escape beyond a recursion; it          /* PCRE does not allow THEN, SKIP, PRUNE or COMMIT to escape beyond a
1847          is treated as NOMATCH. */          recursion; they are treated as NOMATCH. These codes are defined in a
1848            range that can be tested for. Any other return code is an error. */
1849    
1850          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN &&          else if (rrc != MATCH_NOMATCH &&
1851                   rrc != MATCH_COMMIT)                   (rrc < MATCH_BACKTRACK_MIN || rrc > MATCH_BACKTRACK_MAX))
1852            {            {
1853            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1854            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
# Line 2629  for (;;) Line 2635  for (;;)
2635            }            }
2636          break;          break;
2637    
2638            case PT_UCNC:
2639            if ((c == CHAR_DOLLAR_SIGN || c == CHAR_COMMERCIAL_AT ||
2640                 c == CHAR_GRAVE_ACCENT || (c >= 0xa0 && c <= 0xd7ff) ||
2641                 c >= 0xe000) == (op == OP_NOTPROP))
2642              RRETURN(MATCH_NOMATCH);
2643            break;
2644    
2645          /* This should never occur */          /* This should never occur */
2646    
2647          default:          default:
# Line 3215  for (;;) Line 3228  for (;;)
3228    
3229        if (fc < 128)        if (fc < 128)
3230          {          {
3231          pcre_uchar cc = RAWUCHAR(eptr);          pcre_uint32 cc = RAWUCHAR(eptr);
3232          if (md->lcc[fc] != TABLE_GET(cc, md->lcc, cc)) RRETURN(MATCH_NOMATCH);          if (md->lcc[fc] != TABLE_GET(cc, md->lcc, cc)) RRETURN(MATCH_NOMATCH);
3233          ecode++;          ecode++;
3234          eptr++;          eptr++;
# Line 4247  for (;;) Line 4260  for (;;)
4260              }              }
4261            break;            break;
4262    
4263              case PT_UCNC:
4264              for (i = 1; i <= min; i++)
4265                {
4266                if (eptr >= md->end_subject)
4267                  {
4268                  SCHECK_PARTIAL();
4269                  RRETURN(MATCH_NOMATCH);
4270                  }
4271                GETCHARINCTEST(c, eptr);
4272                if ((c == CHAR_DOLLAR_SIGN || c == CHAR_COMMERCIAL_AT ||
4273                     c == CHAR_GRAVE_ACCENT || (c >= 0xa0 && c <= 0xd7ff) ||
4274                     c >= 0xe000) == prop_fail_result)
4275                  RRETURN(MATCH_NOMATCH);
4276                }
4277              break;
4278    
4279            /* This should not occur */            /* This should not occur */
4280    
4281            default:            default:
# Line 4452  for (;;) Line 4481  for (;;)
4481          case OP_DIGIT:          case OP_DIGIT:
4482          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4483            {            {
4484            pcre_uchar cc;            pcre_uint32 cc;
   
4485            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4486              {              {
4487              SCHECK_PARTIAL();              SCHECK_PARTIAL();
# Line 4470  for (;;) Line 4498  for (;;)
4498          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
4499          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4500            {            {
4501            pcre_uchar cc;            pcre_uint32 cc;
   
4502            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4503              {              {
4504              SCHECK_PARTIAL();              SCHECK_PARTIAL();
# Line 4488  for (;;) Line 4515  for (;;)
4515          case OP_WHITESPACE:          case OP_WHITESPACE:
4516          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4517            {            {
4518            pcre_uchar cc;            pcre_uint32 cc;
   
4519            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4520              {              {
4521              SCHECK_PARTIAL();              SCHECK_PARTIAL();
# Line 4506  for (;;) Line 4532  for (;;)
4532          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
4533          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4534            {            {
4535            pcre_uchar cc;            pcre_uint32 cc;
   
4536            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4537              {              {
4538              SCHECK_PARTIAL();              SCHECK_PARTIAL();
# Line 4524  for (;;) Line 4549  for (;;)
4549          case OP_WORDCHAR:          case OP_WORDCHAR:
4550          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4551            {            {
4552            pcre_uchar cc;            pcre_uint32 cc;
   
4553            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4554              {              {
4555              SCHECK_PARTIAL();              SCHECK_PARTIAL();
# Line 4998  for (;;) Line 5022  for (;;)
5022              }              }
5023            /* Control never gets here */            /* Control never gets here */
5024    
5025              case PT_UCNC:
5026              for (fi = min;; fi++)
5027                {
5028                RMATCH(eptr, ecode, offset_top, md, eptrb, RM68);
5029                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5030                if (fi >= max) RRETURN(MATCH_NOMATCH);
5031                if (eptr >= md->end_subject)
5032                  {
5033                  SCHECK_PARTIAL();
5034                  RRETURN(MATCH_NOMATCH);
5035                  }
5036                GETCHARINCTEST(c, eptr);
5037                if ((c == CHAR_DOLLAR_SIGN || c == CHAR_COMMERCIAL_AT ||
5038                     c == CHAR_GRAVE_ACCENT || (c >= 0xa0 && c <= 0xd7ff) ||
5039                     c >= 0xe000) == prop_fail_result)
5040                  RRETURN(MATCH_NOMATCH);
5041                }
5042              /* Control never gets here */
5043    
5044            /* This should never occur */            /* This should never occur */
5045            default:            default:
5046            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
# Line 5492  for (;;) Line 5535  for (;;)
5535            GOT_MAX:            GOT_MAX:
5536            break;            break;
5537    
5538              case PT_UCNC:
5539              for (i = min; i < max; i++)
5540                {
5541                int len = 1;
5542                if (eptr >= md->end_subject)
5543                  {
5544                  SCHECK_PARTIAL();
5545                  break;
5546                  }
5547                GETCHARLENTEST(c, eptr, len);
5548                if ((c == CHAR_DOLLAR_SIGN || c == CHAR_COMMERCIAL_AT ||
5549                     c == CHAR_GRAVE_ACCENT || (c >= 0xa0 && c <= 0xd7ff) ||
5550                     c >= 0xe000) == prop_fail_result)
5551                  break;
5552                eptr += len;
5553                }
5554              break;
5555    
5556            default:            default:
5557            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
5558            }            }
# Line 6133  switch (frame->Xwhere) Line 6194  switch (frame->Xwhere)
6194    LBL(32) LBL(34) LBL(42) LBL(46)    LBL(32) LBL(34) LBL(42) LBL(46)
6195  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6196    LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)    LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
6197    LBL(59) LBL(60) LBL(61) LBL(62) LBL(67)    LBL(59) LBL(60) LBL(61) LBL(62) LBL(67) LBL(68)
6198  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
6199  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
6200    default:    default:
# Line 6286  const pcre_uint8 *start_bits = NULL; Line 6347  const pcre_uint8 *start_bits = NULL;
6347  PCRE_PUCHAR start_match = (PCRE_PUCHAR)subject + start_offset;  PCRE_PUCHAR start_match = (PCRE_PUCHAR)subject + start_offset;
6348  PCRE_PUCHAR end_subject;  PCRE_PUCHAR end_subject;
6349  PCRE_PUCHAR start_partial = NULL;  PCRE_PUCHAR start_partial = NULL;
6350    PCRE_PUCHAR match_partial;
6351  PCRE_PUCHAR req_char_ptr = start_match - 1;  PCRE_PUCHAR req_char_ptr = start_match - 1;
6352    
6353  const pcre_study_data *study;  const pcre_study_data *study;
# Line 6837  for(;;) Line 6899  for(;;)
6899    md->match_function_type = 0;    md->match_function_type = 0;
6900    md->end_offset_top = 0;    md->end_offset_top = 0;
6901    rc = match(start_match, md->start_code, start_match, 2, md, NULL, 0);    rc = match(start_match, md->start_code, start_match, 2, md, NULL, 0);
6902    if (md->hitend && start_partial == NULL) start_partial = md->start_used_ptr;    if (md->hitend && start_partial == NULL)
6903        {
6904        start_partial = md->start_used_ptr;
6905        match_partial = start_match;
6906        }
6907    
6908    switch(rc)    switch(rc)
6909      {      {
# Line 6971  if (rc == MATCH_MATCH || rc == MATCH_ACC Line 7037  if (rc == MATCH_MATCH || rc == MATCH_ACC
7037    /* Set the return code to the number of captured strings, or 0 if there were    /* Set the return code to the number of captured strings, or 0 if there were
7038    too many to fit into the vector. */    too many to fit into the vector. */
7039    
7040    rc = ((md->capture_last & OVFLBIT) != 0 &&    rc = ((md->capture_last & OVFLBIT) != 0 &&
7041           md->end_offset_top >= arg_offset_max)?           md->end_offset_top >= arg_offset_max)?
7042      0 : md->end_offset_top/2;      0 : md->end_offset_top/2;
7043    
# Line 7045  if (start_partial != NULL) Line 7111  if (start_partial != NULL)
7111      {      {
7112      offsets[0] = (int)(start_partial - (PCRE_PUCHAR)subject);      offsets[0] = (int)(start_partial - (PCRE_PUCHAR)subject);
7113      offsets[1] = (int)(end_subject - (PCRE_PUCHAR)subject);      offsets[1] = (int)(end_subject - (PCRE_PUCHAR)subject);
7114        if (offsetcount > 2)
7115          offsets[2] = (int)(match_partial - (PCRE_PUCHAR)subject);
7116      }      }
7117    rc = PCRE_ERROR_PARTIAL;    rc = PCRE_ERROR_PARTIAL;
7118    }    }

Legend:
Removed from v.1248  
changed lines
  Added in v.1271

  ViewVC Help
Powered by ViewVC 1.1.5