--- code/trunk/pcretest.c 2007/04/02 10:08:14 143 +++ code/trunk/pcretest.c 2007/04/16 15:28:08 149 @@ -67,13 +67,16 @@ #endif -#define PCRE_SPY /* For Win32 build, import data, not export */ - -/* We include pcre_internal.h because we need the internal info for displaying -the results of pcre_study() and we also need to know about the internal -macros, structures, and other internal data values; pcretest has "inside -information" compared to a program that strictly follows the PCRE API. */ +/* We have to include pcre_internal.h because we need the internal info for +displaying the results of pcre_study() and we also need to know about the +internal macros, structures, and other internal data values; pcretest has +"inside information" compared to a program that strictly follows the PCRE API. + +Although pcre_internal.h does itself include pcre.h, we explicitly include it +here before pcre_internal.h so that the PCRE_EXP_xxx macros get set +appropriately for an application, not for building PCRE. */ +#include "pcre.h" #include "pcre_internal.h" /* We need access to the data tables that PCRE uses. So as not to have to keep @@ -660,7 +663,8 @@ *************************************************/ /* This is used both at compile and run-time to check for escapes, where -xxx is LF, CR, CRLF, or ANY. Print a message and return 0 if there is no match. +xxx is LF, CR, CRLF, ANYCRLF, or ANY. Print a message and return 0 if there is +no match. Arguments: p points after the leading '<' @@ -675,6 +679,7 @@ if (strncmp((char *)p, "cr>", 3) == 0) return PCRE_NEWLINE_CR; if (strncmp((char *)p, "lf>", 3) == 0) return PCRE_NEWLINE_LF; if (strncmp((char *)p, "crlf>", 5) == 0) return PCRE_NEWLINE_CRLF; +if (strncmp((char *)p, "anycrlf>", 8) == 0) return PCRE_NEWLINE_ANYCRLF; if (strncmp((char *)p, "any>", 4) == 0) return PCRE_NEWLINE_ANY; fprintf(f, "Unknown newline type at: <%s\n", p); return 0; @@ -847,6 +852,7 @@ (void)pcre_config(PCRE_CONFIG_NEWLINE, &rc); printf(" Newline sequence is %s\n", (rc == '\r')? "CR" : (rc == '\n')? "LF" : (rc == ('\r'<<8 | '\n'))? "CRLF" : + (rc == -2)? "ANYCRLF" : (rc == -1)? "ANY" : "???"); (void)pcre_config(PCRE_CONFIG_LINK_SIZE, &rc); printf(" Internal link size = %d\n", rc); @@ -1442,6 +1448,10 @@ fprintf(outfile, "Forced newline sequence: CRLF\n"); break; + case PCRE_NEWLINE_ANYCRLF: + fprintf(outfile, "Forced newline sequence: ANYCRLF\n"); + break; + case PCRE_NEWLINE_ANY: fprintf(outfile, "Forced newline sequence: ANY\n"); break; @@ -1591,7 +1601,7 @@ for (;;) { uschar *q; - uschar *bptr = dbuffer; + uschar *bptr; int *use_offsets = offsets; int use_size_offsets = size_offsets; int callout_data = 0; @@ -1647,7 +1657,7 @@ p = buffer; while (isspace(*p)) p++; - q = dbuffer; + bptr = q = dbuffer; while ((c = *p++) != 0) { int i = 0; @@ -2215,12 +2225,12 @@ to advance the start offset, and continue. We won't be at the end of the string - that was checked before setting g_notempty. - Complication arises in the case when the newline option is "any". - If the previous match was at the end of a line terminated by CRLF, an - advance of one character just passes the \r, whereas we should prefer the - longer newline sequence, as does the code in pcre_exec(). Fudge the - offset value to achieve this. - + Complication arises in the case when the newline option is "any" or + "anycrlf". If the previous match was at the end of a line terminated by + CRLF, an advance of one character just passes the \r, whereas we should + prefer the longer newline sequence, as does the code in pcre_exec(). + Fudge the offset value to achieve this. + Otherwise, in the case of UTF-8 matching, the advance must be one character, not one byte. */ @@ -2229,13 +2239,25 @@ if (g_notempty != 0) { int onechar = 1; + unsigned int obits = ((real_pcre *)re)->options; use_offsets[0] = start_offset; - if ((((real_pcre *)re)->options & PCRE_NEWLINE_BITS) == - PCRE_NEWLINE_ANY && + if ((obits & PCRE_NEWLINE_BITS) == 0) + { + int d; + (void)pcre_config(PCRE_CONFIG_NEWLINE, &d); + obits = (d == '\r')? PCRE_NEWLINE_CR : + (d == '\n')? PCRE_NEWLINE_LF : + (d == ('\r'<<8 | '\n'))? PCRE_NEWLINE_CRLF : + (d == -2)? PCRE_NEWLINE_ANYCRLF : + (d == -1)? PCRE_NEWLINE_ANY : 0; + } + if (((obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANY || + (obits & PCRE_NEWLINE_BITS) == PCRE_NEWLINE_ANYCRLF) + && start_offset < len - 1 && bptr[start_offset] == '\r' && bptr[start_offset+1] == '\n') - onechar++; + onechar++; else if (use_utf8) { while (start_offset + onechar < len)