/[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 96 by nigel, Fri Mar 2 13:10:43 2007 UTC revision 149 by ph10, Mon Apr 16 15:28:08 2007 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-2006 University of Cambridge             Copyright (c) 1997-2007 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 48  possible. There are also some static sup Line 48  possible. There are also some static sup
48    
49  #include "pcre_internal.h"  #include "pcre_internal.h"
50    
51    /* Undefine some potentially clashing cpp symbols */
52    
53    #undef min
54    #undef max
55    
56  /* The chain of eptrblocks for tail recursions uses memory in stack workspace,  /* The chain of eptrblocks for tail recursions uses memory in stack workspace,
57  obtained at top level, the size of which is defined by EPTR_WORK_SIZE. */  obtained at top level, the size of which is defined by EPTR_WORK_SIZE. */
58    
# Line 299  typedef struct heapframe { Line 304  typedef struct heapframe {
304    int Xprop_category;    int Xprop_category;
305    int Xprop_chartype;    int Xprop_chartype;
306    int Xprop_script;    int Xprop_script;
307      int Xoclength;
308      uschar Xocchars[8];
309  #endif  #endif
310    
311    int Xctype;    int Xctype;
# Line 441  HEAP_RECURSE: Line 448  HEAP_RECURSE:
448  #define prop_category      frame->Xprop_category  #define prop_category      frame->Xprop_category
449  #define prop_chartype      frame->Xprop_chartype  #define prop_chartype      frame->Xprop_chartype
450  #define prop_script        frame->Xprop_script  #define prop_script        frame->Xprop_script
451    #define oclength           frame->Xoclength
452    #define occhars            frame->Xocchars
453  #endif  #endif
454    
455  #define ctype              frame->Xctype  #define ctype              frame->Xctype
# Line 494  int prop_fail_result; Line 503  int prop_fail_result;
503  int prop_category;  int prop_category;
504  int prop_chartype;  int prop_chartype;
505  int prop_script;  int prop_script;
506    int oclength;
507    uschar occhars[8];
508  #endif  #endif
509    
510  int ctype;  int ctype;
# Line 2045  for (;;) Line 2056  for (;;)
2056    
2057        if (length > 1)        if (length > 1)
2058          {          {
         int oclength = 0;  
         uschar occhars[8];  
   
2059  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2060          unsigned int othercase;          unsigned int othercase;
2061          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2062              (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR)              (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR)
2063            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2064            else oclength = 0;
2065  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2066    
2067          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2068            {            {
2069            if (memcmp(eptr, charptr, length) == 0) eptr += length;            if (memcmp(eptr, charptr, length) == 0) eptr += length;
2070    #ifdef SUPPORT_UCP
2071            /* Need braces because of following else */            /* Need braces because of following else */
2072            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }
2073            else            else
# Line 2065  for (;;) Line 2075  for (;;)
2075              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);
2076              eptr += oclength;              eptr += oclength;
2077              }              }
2078    #else   /* without SUPPORT_UCP */
2079              else { RRETURN(MATCH_NOMATCH); }
2080    #endif  /* SUPPORT_UCP */
2081            }            }
2082    
2083          if (min == max) continue;          if (min == max) continue;
# Line 2077  for (;;) Line 2090  for (;;)
2090              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2091              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
2092              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (memcmp(eptr, charptr, length) == 0) eptr += length;
2093    #ifdef SUPPORT_UCP
2094              /* Need braces because of following else */              /* Need braces because of following else */
2095              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }
2096              else              else
# Line 2084  for (;;) Line 2098  for (;;)
2098                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);
2099                eptr += oclength;                eptr += oclength;
2100                }                }
2101    #else   /* without SUPPORT_UCP */
2102                else { RRETURN (MATCH_NOMATCH); }
2103    #endif  /* SUPPORT_UCP */
2104              }              }
2105            /* Control never gets here */            /* Control never gets here */
2106            }            }
# Line 2095  for (;;) Line 2112  for (;;)
2112              {              {
2113              if (eptr > md->end_subject - length) break;              if (eptr > md->end_subject - length) break;
2114              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (memcmp(eptr, charptr, length) == 0) eptr += length;
2115    #ifdef SUPPORT_UCP
2116              else if (oclength == 0) break;              else if (oclength == 0) break;
2117              else              else
2118                {                {
2119                if (memcmp(eptr, occhars, oclength) != 0) break;                if (memcmp(eptr, occhars, oclength) != 0) break;
2120                eptr += oclength;                eptr += oclength;
2121                }                }
2122    #else   /* without SUPPORT_UCP */
2123                else break;
2124    #endif  /* SUPPORT_UCP */
2125              }              }
2126    
2127            if (possessive) continue;            if (possessive) continue;
2128            while (eptr >= pp)            for(;;)
2129             {             {
2130             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);
2131             if (rrc != MATCH_NOMATCH) RRETURN(rrc);             if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2132               if (eptr == pp) RRETURN(MATCH_NOMATCH);
2133    #ifdef SUPPORT_UCP
2134               eptr--;
2135               BACKCHAR(eptr);
2136    #else   /* without SUPPORT_UCP */
2137             eptr -= length;             eptr -= length;
2138    #endif  /* SUPPORT_UCP */
2139             }             }
           RRETURN(MATCH_NOMATCH);  
2140            }            }
2141          /* Control never gets here */          /* Control never gets here */
2142          }          }
# Line 3686  Returns: > 0 => success; value Line 3712  Returns: > 0 => success; value
3712                   < -1 => some kind of unexpected problem                   < -1 => some kind of unexpected problem
3713  */  */
3714    
3715  PCRE_DATA_SCOPE int  PCRE_EXP_DEFN int
3716  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
3717    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
3718    int offsetcount)    int offsetcount)
# Line 3802  md->eptrchain = eptrchain; Line 3828  md->eptrchain = eptrchain;
3828  md->lcc = tables + lcc_offset;  md->lcc = tables + lcc_offset;
3829  md->ctypes = tables + ctypes_offset;  md->ctypes = tables + ctypes_offset;
3830    
3831  /* Handle different types of newline. The two bits give four cases. If nothing  /* Handle different types of newline. The three bits give eight cases. If
3832  is set at run time, whatever was used at compile time applies. */  nothing is set at run time, whatever was used at compile time applies. */
3833    
3834  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : options) &  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : (pcre_uint32)options) &
3835         PCRE_NEWLINE_BITS)         PCRE_NEWLINE_BITS)
3836    {    {
3837    case 0: newline = NEWLINE; break;   /* Compile-time default */    case 0: newline = NEWLINE; break;   /* Compile-time default */
# Line 3814  switch ((((options & PCRE_NEWLINE_BITS) Line 3840  switch ((((options & PCRE_NEWLINE_BITS)
3840    case PCRE_NEWLINE_CR+    case PCRE_NEWLINE_CR+
3841         PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;         PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;
3842    case PCRE_NEWLINE_ANY: newline = -1; break;    case PCRE_NEWLINE_ANY: newline = -1; break;
3843      case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
3844    default: return PCRE_ERROR_BADNEWLINE;    default: return PCRE_ERROR_BADNEWLINE;
3845    }    }
3846    
3847  if (newline < 0)  if (newline == -2)
3848      {
3849      md->nltype = NLTYPE_ANYCRLF;
3850      }
3851    else if (newline < 0)
3852    {    {
3853    md->nltype = NLTYPE_ANY;    md->nltype = NLTYPE_ANY;
3854    }    }
# Line 3992  for(;;) Line 4023  for(;;)
4023        {        {
4024        while (start_match <= end_subject && !WAS_NEWLINE(start_match))        while (start_match <= end_subject && !WAS_NEWLINE(start_match))
4025          start_match++;          start_match++;
4026    
4027          /* If we have just passed a CR and the newline option is ANY or ANYCRLF,
4028          and we are now at a LF, advance the match position by one more character.
4029          */
4030    
4031          if (start_match[-1] == '\r' &&
4032               (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&
4033               start_match < end_subject &&
4034               *start_match == '\n')
4035            start_match++;
4036        }        }
4037      }      }
4038    
# Line 4107  for(;;) Line 4148  for(;;)
4148    
4149    if (anchored || start_match > end_subject) break;    if (anchored || start_match > end_subject) break;
4150    
4151    /* If we have just passed a CR and the newline option is CRLF or ANY, and we    /* If we have just passed a CR and the newline option is CRLF or ANY or
4152    are now at a LF, advance the match position by one more character. */    ANYCRLF, and we are now at a LF, advance the match position by one more
4153      character. */
4154    
4155    if (start_match[-1] == '\r' &&    if (start_match[-1] == '\r' &&
4156         (md->nltype == NLTYPE_ANY || md->nllen == 2) &&         (md->nltype == NLTYPE_ANY ||
4157            md->nltype == NLTYPE_ANYCRLF ||
4158            md->nllen == 2) &&
4159         start_match < end_subject &&         start_match < end_subject &&
4160         *start_match == '\n')         *start_match == '\n')
4161      start_match++;      start_match++;

Legend:
Removed from v.96  
changed lines
  Added in v.149

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12