/[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 1270 by ph10, Sun Mar 3 10:42:46 2013 UTC revision 1271 by ph10, Wed Mar 6 16:50:38 2013 UTC
# 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 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];        codelink -= PRIV(OP_lengths)[OP_CALLOUT];
1326        }        }
1327    
1328      condcode = ecode[LINK_SIZE+1];      condcode = ecode[LINK_SIZE+1];
# Line 1738  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 1785  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 1822  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 1839  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 2634  for (;;)
2634              { if (op == OP_PROP) break; else { RRETURN(MATCH_NOMATCH); } }              { if (op == OP_PROP) break; else { RRETURN(MATCH_NOMATCH); } }
2635            }            }
2636          break;          break;
2637    
2638          case PT_UCNC:          case PT_UCNC:
2639          if ((c == CHAR_DOLLAR_SIGN || c == CHAR_COMMERCIAL_AT ||          if ((c == CHAR_DOLLAR_SIGN || c == CHAR_COMMERCIAL_AT ||
2640               c == CHAR_GRAVE_ACCENT || (c >= 0xa0 && c <= 0xd7ff) ||               c == CHAR_GRAVE_ACCENT || (c >= 0xa0 && c <= 0xd7ff) ||
2641               c >= 0xe000) == (op == OP_NOTPROP))               c >= 0xe000) == (op == OP_NOTPROP))
2642            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2643          break;          break;
2644    
2645          /* This should never occur */          /* This should never occur */
2646    
# Line 4254  for (;;) Line 4259  for (;;)
4259                }                }
4260              }              }
4261            break;            break;
4262    
4263            case PT_UCNC:            case PT_UCNC:
4264            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
4265              {              {
# Line 4268  for (;;) Line 4273  for (;;)
4273                   c == CHAR_GRAVE_ACCENT || (c >= 0xa0 && c <= 0xd7ff) ||                   c == CHAR_GRAVE_ACCENT || (c >= 0xa0 && c <= 0xd7ff) ||
4274                   c >= 0xe000) == prop_fail_result)                   c >= 0xe000) == prop_fail_result)
4275                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4276              }              }
4277            break;            break;
4278    
4279            /* This should not occur */            /* This should not occur */
4280    
# Line 5016  for (;;) Line 5021  for (;;)
5021                }                }
5022              }              }
5023            /* Control never gets here */            /* Control never gets here */
5024    
5025            case PT_UCNC:            case PT_UCNC:
5026            for (fi = min;; fi++)            for (fi = min;; fi++)
5027              {              {
# Line 5032  for (;;) Line 5037  for (;;)
5037              if ((c == CHAR_DOLLAR_SIGN || c == CHAR_COMMERCIAL_AT ||              if ((c == CHAR_DOLLAR_SIGN || c == CHAR_COMMERCIAL_AT ||
5038                   c == CHAR_GRAVE_ACCENT || (c >= 0xa0 && c <= 0xd7ff) ||                   c == CHAR_GRAVE_ACCENT || (c >= 0xa0 && c <= 0xd7ff) ||
5039                   c >= 0xe000) == prop_fail_result)                   c >= 0xe000) == prop_fail_result)
5040                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
5041              }              }
5042            /* Control never gets here */            /* Control never gets here */
5043    
5044            /* This should never occur */            /* This should never occur */
# Line 5545  for (;;) Line 5550  for (;;)
5550                   c >= 0xe000) == prop_fail_result)                   c >= 0xe000) == prop_fail_result)
5551                break;                break;
5552              eptr += len;              eptr += len;
5553              }              }
5554            break;            break;
5555    
5556            default:            default:
# Line 6894  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)    if (md->hitend && start_partial == NULL)
6903      {      {
6904      start_partial = md->start_used_ptr;      start_partial = md->start_used_ptr;
6905      match_partial = start_match;      match_partial = start_match;
6906      }      }
6907    
6908    switch(rc)    switch(rc)
6909      {      {
# Line 7032  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 7106  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)      if (offsetcount > 2)
7115        offsets[2] = (int)(match_partial - (PCRE_PUCHAR)subject);        offsets[2] = (int)(match_partial - (PCRE_PUCHAR)subject);
7116      }      }
7117    rc = PCRE_ERROR_PARTIAL;    rc = PCRE_ERROR_PARTIAL;

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

  ViewVC Help
Powered by ViewVC 1.1.5