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

Diff of /code/trunk/pcre.c

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

revision 17 by nigel, Sat Feb 24 21:38:29 2007 UTC revision 21 by nigel, Sat Feb 24 21:38:37 2007 UTC
# Line 623  compile_branch(int options, int *bracket Line 623  compile_branch(int options, int *bracket
623  int repeat_type, op_type;  int repeat_type, op_type;
624  int repeat_min, repeat_max;  int repeat_min, repeat_max;
625  int bravalue, length;  int bravalue, length;
626    int greedy_default, greedy_non_default;
627  register int c;  register int c;
628  register uschar *code = *codeptr;  register uschar *code = *codeptr;
629  const uschar *ptr = *ptrptr;  const uschar *ptr = *ptrptr;
# Line 630  const uschar *oldptr; Line 631  const uschar *oldptr;
631  uschar *previous = NULL;  uschar *previous = NULL;
632  uschar class[32];  uschar class[32];
633    
634    /* Set up the default and non-default settings for greediness */
635    
636    greedy_default = ((options & PCRE_UNGREEDY) != 0);
637    greedy_non_default = greedy_default ^ 1;
638    
639  /* Switch on next character until the end of the branch */  /* Switch on next character until the end of the branch */
640    
641  for (;; ptr++)  for (;; ptr++)
# Line 907  for (;; ptr++) Line 913  for (;; ptr++)
913        goto FAILED;        goto FAILED;
914        }        }
915    
916      /* If the next character is '?' this is a minimizing repeat. Advance to the      /* If the next character is '?' this is a minimizing repeat, by default,
917        but if PCRE_UNGREEDY is set, it works the other way round. Advance to the
918      next character. */      next character. */
919    
920      if (ptr[1] == '?') { repeat_type = 1; ptr++; } else repeat_type = 0;      if (ptr[1] == '?')
921          { repeat_type = greedy_non_default; ptr++; }
922        else repeat_type = greedy_default;
923    
924      /* If the maximum is zero then the minimum must also be zero; Perl allows      /* If the maximum is zero then the minimum must also be zero; Perl allows
925      this case, so we do too - by simply omitting the item altogether. */      this case, so we do too - by simply omitting the item altogether. */
# Line 999  for (;; ptr++) Line 1008  for (;; ptr++)
1008          /* If the mininum is 1 and the previous item was a character string,          /* If the mininum is 1 and the previous item was a character string,
1009          we either have to put back the item that got cancelled if the string          we either have to put back the item that got cancelled if the string
1010          length was 1, or add the character back onto the end of a longer          length was 1, or add the character back onto the end of a longer
1011          string. For a character type nothing need be done; it will just get put          string. For a character type nothing need be done; it will just get
1012          back naturally. */          put back naturally. Note that the final character is always going to
1013            get added below. */
1014    
1015          else if (*previous == OP_CHARS)          else if (*previous == OP_CHARS)
1016            {            {
1017            if (code == previous) code += 2; else previous[1]++;            if (code == previous) code += 2; else previous[1]++;
1018            }            }
1019    
1020            /*  For a single negated character we also have to put back the
1021            item that got cancelled. */
1022    
1023            else if (*previous == OP_NOT) code++;
1024    
1025          /* If the maximum is unlimited, insert an OP_STAR. */          /* If the maximum is unlimited, insert an OP_STAR. */
1026    
1027          if (repeat_max < 0)          if (repeat_max < 0)
# Line 1149  for (;; ptr++) Line 1164  for (;; ptr++)
1164          case 'm':          case 'm':
1165          case 's':          case 's':
1166          case 'x':          case 'x':
1167            case 'U':
1168            case 'X':
1169          ptr++;          ptr++;
1170          while (*ptr != ')') ptr++;          while (*ptr != ')') ptr++;
1171          previous = NULL;          previous = NULL;
# Line 1752  while ((c = *(++ptr)) != 0) Line 1769  while ((c = *(++ptr)) != 0)
1769          ptr += 2;          ptr += 2;
1770          break;          break;
1771          }          }
1772        /* Else fall thourh */        /* Else fall through */
1773    
1774        /* Else loop setting valid options until ) is met. Anything else is an        /* Else loop setting valid options until ) is met. Anything else is an
1775        error. */        error. */
# Line 1782  while ((c = *(++ptr)) != 0) Line 1799  while ((c = *(++ptr)) != 0)
1799            length -= spaces;          /* Already counted spaces */            length -= spaces;          /* Already counted spaces */
1800            continue;            continue;
1801            }            }
1802            else if (c == 'X')
1803              {
1804              options |= PCRE_EXTRA;
1805              continue;
1806              }
1807            else if (c == 'U')
1808              {
1809              options |= PCRE_UNGREEDY;
1810              continue;
1811              }
1812          else if (c == ')') break;          else if (c == ')') break;
1813    
1814          *errorptr = ERR12;          *errorptr = ERR12;
# Line 1987  printf("Length = %d top_bracket = %d top Line 2014  printf("Length = %d top_bracket = %d top
2014    
2015  if (re->options != 0)  if (re->options != 0)
2016    {    {
2017    printf("%s%s%s%s%s%s%s\n",    printf("%s%s%s%s%s%s%s%s\n",
2018      ((re->options & PCRE_ANCHORED) != 0)? "anchored " : "",      ((re->options & PCRE_ANCHORED) != 0)? "anchored " : "",
2019      ((re->options & PCRE_CASELESS) != 0)? "caseless " : "",      ((re->options & PCRE_CASELESS) != 0)? "caseless " : "",
2020      ((re->options & PCRE_EXTENDED) != 0)? "extended " : "",      ((re->options & PCRE_EXTENDED) != 0)? "extended " : "",
2021      ((re->options & PCRE_MULTILINE) != 0)? "multiline " : "",      ((re->options & PCRE_MULTILINE) != 0)? "multiline " : "",
2022      ((re->options & PCRE_DOTALL) != 0)? "dotall " : "",      ((re->options & PCRE_DOTALL) != 0)? "dotall " : "",
2023      ((re->options & PCRE_DOLLAR_ENDONLY) != 0)? "endonly " : "",      ((re->options & PCRE_DOLLAR_ENDONLY) != 0)? "endonly " : "",
2024      ((re->options & PCRE_EXTRA) != 0)? "extra " : "");      ((re->options & PCRE_EXTRA) != 0)? "extra " : "",
2025        ((re->options & PCRE_UNGREEDY) != 0)? "ungreedy " : "");
2026    }    }
2027    
2028  if ((re->options & PCRE_FIRSTSET) != 0)  if ((re->options & PCRE_FIRSTSET) != 0)

Legend:
Removed from v.17  
changed lines
  Added in v.21

  ViewVC Help
Powered by ViewVC 1.1.5