--- code/trunk/pcre_exec.c 2007/03/09 15:59:06 117 +++ code/trunk/pcre_exec.c 2007/04/16 15:28:08 149 @@ -48,6 +48,11 @@ #include "pcre_internal.h" +/* Undefine some potentially clashing cpp symbols */ + +#undef min +#undef max + /* The chain of eptrblocks for tail recursions uses memory in stack workspace, obtained at top level, the size of which is defined by EPTR_WORK_SIZE. */ @@ -299,8 +304,8 @@ int Xprop_category; int Xprop_chartype; int Xprop_script; - int Xoclength; - uschar Xocchars[8]; + int Xoclength; + uschar Xocchars[8]; #endif int Xctype; @@ -2062,7 +2067,7 @@ for (i = 1; i <= min; i++) { if (memcmp(eptr, charptr, length) == 0) eptr += length; -#ifdef SUPPORT_UCP +#ifdef SUPPORT_UCP /* Need braces because of following else */ else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } else @@ -2072,7 +2077,7 @@ } #else /* without SUPPORT_UCP */ else { RRETURN(MATCH_NOMATCH); } -#endif /* SUPPORT_UCP */ +#endif /* SUPPORT_UCP */ } if (min == max) continue; @@ -2085,7 +2090,7 @@ if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); if (memcmp(eptr, charptr, length) == 0) eptr += length; -#ifdef SUPPORT_UCP +#ifdef SUPPORT_UCP /* Need braces because of following else */ else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } else @@ -2107,7 +2112,7 @@ { if (eptr > md->end_subject - length) break; if (memcmp(eptr, charptr, length) == 0) eptr += length; -#ifdef SUPPORT_UCP +#ifdef SUPPORT_UCP else if (oclength == 0) break; else { @@ -2116,22 +2121,22 @@ } #else /* without SUPPORT_UCP */ else break; -#endif /* SUPPORT_UCP */ +#endif /* SUPPORT_UCP */ } if (possessive) continue; - while (eptr >= pp) + for(;;) { RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); if (rrc != MATCH_NOMATCH) RRETURN(rrc); + if (eptr == pp) RRETURN(MATCH_NOMATCH); #ifdef SUPPORT_UCP eptr--; BACKCHAR(eptr); -#else /* without SUPPORT_UCP */ +#else /* without SUPPORT_UCP */ eptr -= length; -#endif /* SUPPORT_UCP */ +#endif /* SUPPORT_UCP */ } - RRETURN(MATCH_NOMATCH); } /* Control never gets here */ } @@ -3707,7 +3712,7 @@ < -1 => some kind of unexpected problem */ -PCRE_DATA_SCOPE int +PCRE_EXP_DEFN int pcre_exec(const pcre *argument_re, const pcre_extra *extra_data, PCRE_SPTR subject, int length, int start_offset, int options, int *offsets, int offsetcount) @@ -3826,7 +3831,7 @@ /* Handle different types of newline. The three bits give eight cases. If nothing is set at run time, whatever was used at compile time applies. */ -switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : options) & +switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : (pcre_uint32)options) & PCRE_NEWLINE_BITS) { case 0: newline = NEWLINE; break; /* Compile-time default */ @@ -3835,10 +3840,15 @@ case PCRE_NEWLINE_CR+ PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break; case PCRE_NEWLINE_ANY: newline = -1; break; + case PCRE_NEWLINE_ANYCRLF: newline = -2; break; default: return PCRE_ERROR_BADNEWLINE; } -if (newline < 0) +if (newline == -2) + { + md->nltype = NLTYPE_ANYCRLF; + } +else if (newline < 0) { md->nltype = NLTYPE_ANY; } @@ -4013,6 +4023,16 @@ { while (start_match <= end_subject && !WAS_NEWLINE(start_match)) start_match++; + + /* If we have just passed a CR and the newline option is ANY or ANYCRLF, + and we are now at a LF, advance the match position by one more character. + */ + + if (start_match[-1] == '\r' && + (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) && + start_match < end_subject && + *start_match == '\n') + start_match++; } } @@ -4128,11 +4148,14 @@ if (anchored || start_match > end_subject) break; - /* If we have just passed a CR and the newline option is CRLF or ANY, and we - are now at a LF, advance the match position by one more character. */ + /* If we have just passed a CR and the newline option is CRLF or ANY or + ANYCRLF, and we are now at a LF, advance the match position by one more + character. */ if (start_match[-1] == '\r' && - (md->nltype == NLTYPE_ANY || md->nllen == 2) && + (md->nltype == NLTYPE_ANY || + md->nltype == NLTYPE_ANYCRLF || + md->nllen == 2) && start_match < end_subject && *start_match == '\n') start_match++;