/[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 227 by ph10, Tue Aug 21 15:00:15 2007 UTC revision 236 by ph10, Tue Sep 11 12:57:06 2007 UTC
# Line 43  supporting internal functions that are n Line 43  supporting internal functions that are n
43    
44    
45  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
46  #include <config.h>  #include "config.h"
47  #endif  #endif
48    
49  #define NLBLOCK cd             /* Block containing newline information */  #define NLBLOCK cd             /* Block containing newline information */
# Line 2976  for (;; ptr++) Line 2976  for (;; ptr++)
2976    
2977        oldptr = ptr;        oldptr = ptr;
2978    
2979          /* Remember \r or \n */
2980    
2981          if (c == '\r' || c == '\n') cd->external_flags |= PCRE_HASCRORLF;
2982    
2983          /* Check for range */
2984    
2985        if (!inescq && ptr[1] == '-')        if (!inescq && ptr[1] == '-')
2986          {          {
2987          int d;          int d;
# Line 3043  for (;; ptr++) Line 3049  for (;; ptr++)
3049    
3050          if (d == c) goto LONE_SINGLE_CHARACTER;  /* A few lines below */          if (d == c) goto LONE_SINGLE_CHARACTER;  /* A few lines below */
3051    
3052            /* Remember \r or \n */
3053    
3054            if (d == '\r' || d == '\n') cd->external_flags |= PCRE_HASCRORLF;
3055    
3056          /* In UTF-8 mode, if the upper limit is > 255, or > 127 for caseless          /* In UTF-8 mode, if the upper limit is > 255, or > 127 for caseless
3057          matching, we have to use an XCLASS with extra data items. Caseless          matching, we have to use an XCLASS with extra data items. Caseless
3058          matching for characters > 127 is available only if UCP support is          matching for characters > 127 is available only if UCP support is
# Line 3196  for (;; ptr++) Line 3206  for (;; ptr++)
3206        goto FAILED;        goto FAILED;
3207        }        }
3208    
3209    
3210    /* This code has been disabled because it would mean that \s counts as
3211    an explicit \r or \n reference, and that's not really what is wanted. Now
3212    we set the flag only if there is a literal "\r" or "\n" in the class. */
3213    
3214    #if 0
3215      /* Remember whether \r or \n are in this class */      /* Remember whether \r or \n are in this class */
3216    
3217      if (negate_class)      if (negate_class)
3218        {        {
3219        if ((classbits[1] & 0x24) != 0x24) cd->external_options |= PCRE_HASCRORLF;        if ((classbits[1] & 0x24) != 0x24) cd->external_flags |= PCRE_HASCRORLF;
3220        }        }
3221      else      else
3222        {        {
3223        if ((classbits[1] & 0x24) != 0) cd->external_options |= PCRE_HASCRORLF;        if ((classbits[1] & 0x24) != 0) cd->external_flags |= PCRE_HASCRORLF;
3224        }        }
3225    #endif
3226    
3227    
3228      /* If class_charcount is 1, we saw precisely one character whose value is      /* If class_charcount is 1, we saw precisely one character whose value is
3229      less than 256. As long as there were no characters >= 128 and there was no      less than 256. As long as there were no characters >= 128 and there was no
# Line 3498  for (;; ptr++) Line 3516  for (;; ptr++)
3516        /* All real repeats make it impossible to handle partial matching (maybe        /* All real repeats make it impossible to handle partial matching (maybe
3517        one day we will be able to remove this restriction). */        one day we will be able to remove this restriction). */
3518    
3519        if (repeat_max != 1) cd->nopartial = TRUE;        if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL;
3520    
3521        /* Combine the op_type with the repeat_type */        /* Combine the op_type with the repeat_type */
3522    
# Line 3648  for (;; ptr++) Line 3666  for (;; ptr++)
3666        /* All real repeats make it impossible to handle partial matching (maybe        /* All real repeats make it impossible to handle partial matching (maybe
3667        one day we will be able to remove this restriction). */        one day we will be able to remove this restriction). */
3668    
3669        if (repeat_max != 1) cd->nopartial = TRUE;        if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL;
3670    
3671        if (repeat_min == 0 && repeat_max == -1)        if (repeat_min == 0 && repeat_max == -1)
3672          *code++ = OP_CRSTAR + repeat_type;          *code++ = OP_CRSTAR + repeat_type;
# Line 4645  for (;; ptr++) Line 4663  for (;; ptr++)
4663    
4664              case 'J':    /* Record that it changed in the external options */              case 'J':    /* Record that it changed in the external options */
4665              *optset |= PCRE_DUPNAMES;              *optset |= PCRE_DUPNAMES;
4666              cd->external_options |= PCRE_JCHANGED;              cd->external_flags |= PCRE_JCHANGED;
4667              break;              break;
4668    
4669              case 'i': *optset |= PCRE_CASELESS; break;              case 'i': *optset |= PCRE_CASELESS; break;
# Line 5065  for (;; ptr++) Line 5083  for (;; ptr++)
5083      /* Remember if \r or \n were seen */      /* Remember if \r or \n were seen */
5084    
5085      if (mcbuffer[0] == '\r' || mcbuffer[0] == '\n')      if (mcbuffer[0] == '\r' || mcbuffer[0] == '\n')
5086        cd->external_options |= PCRE_HASCRORLF;        cd->external_flags |= PCRE_HASCRORLF;
5087    
5088      /* Set the first and required bytes appropriately. If no previous first      /* Set the first and required bytes appropriately. If no previous first
5089      byte, set it from this character, but revert to none on a zero repeat.      byte, set it from this character, but revert to none on a zero repeat.
# Line 5745  cd->fcc = tables + fcc_offset; Line 5763  cd->fcc = tables + fcc_offset;
5763  cd->cbits = tables + cbits_offset;  cd->cbits = tables + cbits_offset;
5764  cd->ctypes = tables + ctypes_offset;  cd->ctypes = tables + ctypes_offset;
5765    
5766  /* Check for newline settings at the start of the pattern, and remember the  /* Check for global one-time settings at the start of the pattern, and remember
5767  offset for later. */  the offset for later. */
5768    
5769  if (ptr[0] == '(' && ptr[1] == '*')  while (ptr[skipatstart] == '(' && ptr[skipatstart+1] == '*')
5770    {    {
5771    int newnl = 0;    int newnl = 0;
5772    if (strncmp((char *)(ptr+2), "CR)", 3) == 0)    int newbsr = 0;
5773      { skipatstart = 5; newnl = PCRE_NEWLINE_CR; }  
5774    else if (strncmp((char *)(ptr+2), "LF)", 3)  == 0)    if (strncmp((char *)(ptr+skipatstart+2), "CR)", 3) == 0)
5775      { skipatstart = 5; newnl = PCRE_NEWLINE_LF; }      { skipatstart += 5; newnl = PCRE_NEWLINE_CR; }
5776    else if (strncmp((char *)(ptr+2), "CRLF)", 5)  == 0)    else if (strncmp((char *)(ptr+skipatstart+2), "LF)", 3)  == 0)
5777      { skipatstart = 7; newnl = PCRE_NEWLINE_CR + PCRE_NEWLINE_LF; }      { skipatstart += 5; newnl = PCRE_NEWLINE_LF; }
5778    else if (strncmp((char *)(ptr+2), "ANY)", 4) == 0)    else if (strncmp((char *)(ptr+skipatstart+2), "CRLF)", 5)  == 0)
5779      { skipatstart = 6; newnl = PCRE_NEWLINE_ANY; }      { skipatstart += 7; newnl = PCRE_NEWLINE_CR + PCRE_NEWLINE_LF; }
5780    else if (strncmp((char *)(ptr+2), "ANYCRLF)", 8)  == 0)    else if (strncmp((char *)(ptr+skipatstart+2), "ANY)", 4) == 0)
5781      { skipatstart = 10; newnl = PCRE_NEWLINE_ANYCRLF; }      { skipatstart += 6; newnl = PCRE_NEWLINE_ANY; }
5782    if (skipatstart > 0)    else if (strncmp((char *)(ptr+skipatstart+2), "ANYCRLF)", 8)  == 0)
5783        { skipatstart += 10; newnl = PCRE_NEWLINE_ANYCRLF; }
5784    
5785      else if (strncmp((char *)(ptr+skipatstart+2), "BSR_ANYCRLF)", 12) == 0)
5786        { skipatstart += 14; newbsr = PCRE_BSR_ANYCRLF; }
5787      else if (strncmp((char *)(ptr+skipatstart+2), "BSR_UNICODE)", 12) == 0)
5788        { skipatstart += 14; newbsr = PCRE_BSR_UNICODE; }
5789    
5790      if (newnl != 0)
5791      options = (options & ~PCRE_NEWLINE_BITS) | newnl;      options = (options & ~PCRE_NEWLINE_BITS) | newnl;
5792      else if (newbsr != 0)
5793        options = (options & ~(PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) | newbsr;
5794      else break;
5795      }
5796    
5797    /* Check validity of \R options. */
5798    
5799    switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
5800      {
5801      case 0:
5802      case PCRE_BSR_ANYCRLF:
5803      case PCRE_BSR_UNICODE:
5804      break;
5805      default: errorcode = ERR56; goto PCRE_EARLY_ERROR_RETURN;
5806    }    }
5807    
5808  /* Handle different types of newline. The three bits give seven cases. The  /* Handle different types of newline. The three bits give seven cases. The
# Line 5834  cd->hwm = cworkspace; Line 5874  cd->hwm = cworkspace;
5874  cd->start_pattern = (const uschar *)pattern;  cd->start_pattern = (const uschar *)pattern;
5875  cd->end_pattern = (const uschar *)(pattern + strlen(pattern));  cd->end_pattern = (const uschar *)(pattern + strlen(pattern));
5876  cd->req_varyopt = 0;  cd->req_varyopt = 0;
 cd->nopartial = FALSE;  
5877  cd->external_options = options;  cd->external_options = options;
5878    cd->external_flags = 0;
5879    
5880  /* 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
5881  don't need to look at the result of the function here. The initial options have  don't need to look at the result of the function here. The initial options have
# Line 5874  if (re == NULL) Line 5914  if (re == NULL)
5914    goto PCRE_EARLY_ERROR_RETURN;    goto PCRE_EARLY_ERROR_RETURN;
5915    }    }
5916    
5917  /* Put in the magic number, and save the sizes, initial options, and character  /* Put in the magic number, and save the sizes, initial options, internal
5918  table pointer. NULL is used for the default character tables. The nullpad field  flags, and character table pointer. NULL is used for the default character
5919  is at the end; it's there to help in the case when a regex compiled on a system  tables. The nullpad field is at the end; it's there to help in the case when a
5920  with 4-byte pointers is run on another with 8-byte pointers. */  regex compiled on a system with 4-byte pointers is run on another with 8-byte
5921    pointers. */
5922    
5923  re->magic_number = MAGIC_NUMBER;  re->magic_number = MAGIC_NUMBER;
5924  re->size = size;  re->size = size;
5925  re->options = cd->external_options;  re->options = cd->external_options;
5926    re->flags = cd->external_flags;
5927  re->dummy1 = 0;  re->dummy1 = 0;
5928  re->first_byte = 0;  re->first_byte = 0;
5929  re->req_byte = 0;  re->req_byte = 0;
# Line 5906  codestart = cd->name_table + re->name_en Line 5948  codestart = cd->name_table + re->name_en
5948  cd->start_code = codestart;  cd->start_code = codestart;
5949  cd->hwm = cworkspace;  cd->hwm = cworkspace;
5950  cd->req_varyopt = 0;  cd->req_varyopt = 0;
 cd->nopartial = FALSE;  
5951  cd->had_accept = FALSE;  cd->had_accept = FALSE;
5952    
5953  /* Set up a starting, non-extracting bracket, then compile the expression. On  /* Set up a starting, non-extracting bracket, then compile the expression. On
# Line 5920  code = (uschar *)codestart; Line 5961  code = (uschar *)codestart;
5961    &errorcode, FALSE, FALSE, 0, &firstbyte, &reqbyte, NULL, cd, NULL);    &errorcode, FALSE, FALSE, 0, &firstbyte, &reqbyte, NULL, cd, NULL);
5962  re->top_bracket = cd->bracount;  re->top_bracket = cd->bracount;
5963  re->top_backref = cd->top_backref;  re->top_backref = cd->top_backref;
5964    re->flags = cd->external_flags;
5965    
 if (cd->nopartial) re->options |= PCRE_NOPARTIAL;  
5966  if (cd->had_accept) reqbyte = -1;   /* Must disable after (*ACCEPT) */  if (cd->had_accept) reqbyte = -1;   /* Must disable after (*ACCEPT) */
5967    
5968  /* If not reached end of pattern on success, there's an excess bracket. */  /* If not reached end of pattern on success, there's an excess bracket. */
# Line 5993  if ((re->options & PCRE_ANCHORED) == 0) Line 6034  if ((re->options & PCRE_ANCHORED) == 0)
6034        int ch = firstbyte & 255;        int ch = firstbyte & 255;
6035        re->first_byte = ((firstbyte & REQ_CASELESS) != 0 &&        re->first_byte = ((firstbyte & REQ_CASELESS) != 0 &&
6036           cd->fcc[ch] == ch)? ch : firstbyte;           cd->fcc[ch] == ch)? ch : firstbyte;
6037        re->options |= PCRE_FIRSTSET;        re->flags |= PCRE_FIRSTSET;
6038        }        }
6039      else if (is_startline(codestart, 0, cd->backref_map))      else if (is_startline(codestart, 0, cd->backref_map))
6040        re->options |= PCRE_STARTLINE;        re->flags |= PCRE_STARTLINE;
6041      }      }
6042    }    }
6043    
# Line 6010  if (reqbyte >= 0 && Line 6051  if (reqbyte >= 0 &&
6051    int ch = reqbyte & 255;    int ch = reqbyte & 255;
6052    re->req_byte = ((reqbyte & REQ_CASELESS) != 0 &&    re->req_byte = ((reqbyte & REQ_CASELESS) != 0 &&
6053      cd->fcc[ch] == ch)? (reqbyte & ~REQ_CASELESS) : reqbyte;      cd->fcc[ch] == ch)? (reqbyte & ~REQ_CASELESS) : reqbyte;
6054    re->options |= PCRE_REQCHSET;    re->flags |= PCRE_REQCHSET;
6055    }    }
6056    
6057  /* Print out the compiled data if debugging is enabled. This is never the  /* Print out the compiled data if debugging is enabled. This is never the
# Line 6023  printf("Length = %d top_bracket = %d top Line 6064  printf("Length = %d top_bracket = %d top
6064    
6065  printf("Options=%08x\n", re->options);  printf("Options=%08x\n", re->options);
6066    
6067  if ((re->options & PCRE_FIRSTSET) != 0)  if ((re->flags & PCRE_FIRSTSET) != 0)
6068    {    {
6069    int ch = re->first_byte & 255;    int ch = re->first_byte & 255;
6070    const char *caseless = ((re->first_byte & REQ_CASELESS) == 0)?    const char *caseless = ((re->first_byte & REQ_CASELESS) == 0)?
# Line 6032  if ((re->options & PCRE_FIRSTSET) != 0) Line 6073  if ((re->options & PCRE_FIRSTSET) != 0)
6073      else printf("First char = \\x%02x%s\n", ch, caseless);      else printf("First char = \\x%02x%s\n", ch, caseless);
6074    }    }
6075    
6076  if ((re->options & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
6077    {    {
6078    int ch = re->req_byte & 255;    int ch = re->req_byte & 255;
6079    const char *caseless = ((re->req_byte & REQ_CASELESS) == 0)?    const char *caseless = ((re->req_byte & REQ_CASELESS) == 0)?

Legend:
Removed from v.227  
changed lines
  Added in v.236

  ViewVC Help
Powered by ViewVC 1.1.5