# # # add_file "pcre/pcre_newline.c" # content [52667cdf33813f8c161638c91b14813f0aceeb21] # # add_file "pcre/pcre_ord2utf8.c" # content [e2da5e11be19beab7cbe98fc4f1200438a4612f2] # # add_file "pcre/pcre_ucp_searchfuncs.c" # content [bd92f7801af94ebe492b49be93a02fa992de0fdf] # # add_file "pcre/pcre_valid_utf8.c" # content [c587b5e870e25985bca0d58a189d7d5fca4a4a29] # # add_file "pcre/pcrepattern.texi" # content [10041ae21b3ce5f6971aca811ce57abc0827da8b] # # add_file "pcre/pcresyntax.texi" # content [a5c795d675697cc91f001cc242cb717e34bcbcac] # # add_file "pcre/ucp.h" # content [858221df2d7d0d08b5b88749f94746bb77d2d472] # # add_file "pcre/ucpinternal.h" # content [56fe522a5a3d12d4736430a563d22abb8864050f] # # add_file "pcre/ucptable.h" # content [665475a65598de16193f595e4ec78d84b9059662] # # patch "Makefile.am" # from [302a257f3be89ef313e76dda8a3e62e0a1afe5fe] # to [239a18937d9d8775848b95358b2f8421258f8067] # # patch "monotone.texi" # from [11dbcb7685ca2369e9131eb7a4c2194f6b5619ae] # to [ba3e94933926c735fe99c81024701beaaef7203a] # # patch "pcre/README" # from [d83b21c4e1e1332190090230099bccd633988985] # to [420b5f8ab281ef77f9caa6cde682d24ea5f68322] # # patch "pcre/pcre.h" # from [845646297e364447eb985e62d9b838c4e26fdbc2] # to [3d50cb3220621ae4952c574e5f6970a2f6bda6fd] # # patch "pcre/pcre_chartables.c" # from [aa6b49b4d832ffdad9d5ca3fd8013ec371fc417a] # to [d9401a46b0d13b36b344c6a96580da7b5a8fb7b8] # # patch "pcre/pcre_compile.c" # from [2a7d0d4b9860bb85f50197170d47926a8526269b] # to [7e46181d93904b1c2030713b028b75f5588b303f] # # patch "pcre/pcre_config.c" # from [3197ae2ed4c54cc20c770044d842038ba7e9f2b5] # to [9e873bc83d131086cab79a943b783ea9367222e4] # # patch "pcre/pcre_config.h" # from [cdd4d95dc55d8f805da3888d61eb630148b39eaf] # to [e2de114bbc6648e9d5f961c63729069b64733f67] # # patch "pcre/pcre_dfa_exec.c" # from [e47bdb1351432a867879ff71b5439285458202b6] # to [54e1c705cf360ac00f188006e24f1faa813c8508] # # patch "pcre/pcre_exec.c" # from [67b6e933c1bf48822748163ca104e433a79208b5] # to [15e9af69dc4d3e1a33cf3b7b8a2906d6ca426dc9] # # patch "pcre/pcre_fullinfo.c" # from [65c02930182c0ca0a12b7a2cd46cce76a0f89457] # to [3596c951b0cc5bb905d8ca91cba96161f39bb607] # # patch "pcre/pcre_get.c" # from [4dd0a6df9fa0c3a4fb9a3356ad2b9623d9febf57] # to [8e8c912b9d50848a74761991314b6ea326b2464a] # # patch "pcre/pcre_globals.c" # from [4a27067a587c5cd92ad9671107a3541f6429082c] # to [3cf49201069daca47dc593a2ef160fbb13610a69] # # patch "pcre/pcre_info.c" # from [14399144255ceaa0d09a0d16ef030e3dc91cff5b] # to [004e534421480865060b938b75561b8e523beb2b] # # patch "pcre/pcre_internal.h" # from [d6b78d25230e9f7d3cdf183f2fb45b6de45dc062] # to [787e957bffa8995e75e15a2a1c17befc5d570cdc] # # patch "pcre/pcre_maketables.c" # from [03f5e59dd47ef2874398251712ff6ee454d76d13] # to [a5231ea973f291c3fe8f7f44534028794a3bb1da] # # patch "pcre/pcre_refcount.c" # from [ebd0c3dfce2e8dc81a179e2b033364fcec82f55b] # to [84e42bff9f54245918ff28b8e8fb23dc53fb0db9] # # patch "pcre/pcre_study.c" # from [9a88f30ab85c1a4df719efb21352da8ec0ff0a60] # to [29605e98e732f8139fd1fedc6a5d7de268add456] # # patch "pcre/pcre_tables.c" # from [f504519f4ad83001af74dca4ada66d1fe68f64aa] # to [43b929d5086b991efc569e2d3fe2924fde8e7009] # # patch "pcre/pcre_try_flipped.c" # from [4d22ad726b0e1decb6c0ebaecd607b7def17d642] # to [2d7f11db16127e769a87613dbb38ba1959a89c5c] # # patch "pcre/pcre_version.c" # from [0e4d6ac360d5acfba16e4d071b69d954488e7a5f] # to [97e12b4b30fc68214564f746963f1701528925a7] # # patch "pcre/pcre_xclass.c" # from [d672ac5b6a31841662bca6917df7d31537ae7f22] # to [b9a3ce19007386f9fb242cd8396ca94efaa29b5d] # # patch "tests/syntax_errors_in_.mtn-ignore/stderr-ref" # from [81aae288f36ab9e7e65cc454878447c7ce9ad945] # to [e5393b2dd883f02f0f5bbe8a97aec42304c69f0e] # ============================================================ --- pcre/pcre_newline.c 52667cdf33813f8c161638c91b14813f0aceeb21 +++ pcre/pcre_newline.c 52667cdf33813f8c161638c91b14813f0aceeb21 @@ -0,0 +1,162 @@ +/************************************************* +* Perl-Compatible Regular Expressions * +*************************************************/ + +/* PCRE is a library of functions to support regular expressions whose syntax +and semantics are as close as possible to those of the Perl 5 language. + + Written by Philip Hazel + Copyright (c) 1997-2007 University of Cambridge + +----------------------------------------------------------------------------- +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of the University of Cambridge nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +----------------------------------------------------------------------------- +*/ + + +/* This module contains internal functions for testing newlines when more than +one kind of newline is to be recognized. When a newline is found, its length is +returned. In principle, we could implement several newline "types", each +referring to a different set of newline characters. At present, PCRE supports +only NLTYPE_FIXED, which gets handled without these functions, NLTYPE_ANYCRLF, +and NLTYPE_ANY. The full list of Unicode newline characters is taken from +http://unicode.org/unicode/reports/tr18/. */ + + +#include "pcre_config.h" + +#include "pcre_internal.h" + + + +/************************************************* +* Check for newline at given position * +*************************************************/ + +/* It is guaranteed that the initial value of ptr is less than the end of the +string that is being processed. + +Arguments: + ptr pointer to possible newline + type the newline type + endptr pointer to the end of the string + lenptr where to return the length + utf8 TRUE if in utf8 mode + +Returns: TRUE or FALSE +*/ + +BOOL +_pcre_is_newline(const uschar *ptr, int type, const uschar *endptr, + int *lenptr, BOOL utf8) +{ +int c; +if (utf8) { GETCHAR(c, ptr); } else c = *ptr; + +if (type == NLTYPE_ANYCRLF) switch(c) + { + case 0x000a: *lenptr = 1; return TRUE; /* LF */ + case 0x000d: *lenptr = (ptr < endptr - 1 && ptr[1] == 0x0a)? 2 : 1; + return TRUE; /* CR */ + default: return FALSE; + } + +/* NLTYPE_ANY */ + +else switch(c) + { + case 0x000a: /* LF */ + case 0x000b: /* VT */ + case 0x000c: *lenptr = 1; return TRUE; /* FF */ + case 0x000d: *lenptr = (ptr < endptr - 1 && ptr[1] == 0x0a)? 2 : 1; + return TRUE; /* CR */ + case 0x0085: *lenptr = utf8? 2 : 1; return TRUE; /* NEL */ + case 0x2028: /* LS */ + case 0x2029: *lenptr = 3; return TRUE; /* PS */ + default: return FALSE; + } +} + + + +/************************************************* +* Check for newline at previous position * +*************************************************/ + +/* It is guaranteed that the initial value of ptr is greater than the start of +the string that is being processed. + +Arguments: + ptr pointer to possible newline + type the newline type + startptr pointer to the start of the string + lenptr where to return the length + utf8 TRUE if in utf8 mode + +Returns: TRUE or FALSE +*/ + +BOOL +_pcre_was_newline(const uschar *ptr, int type, const uschar *startptr, + int *lenptr, BOOL utf8) +{ +int c; +ptr--; +#ifdef SUPPORT_UTF8 +if (utf8) + { + BACKCHAR(ptr); + GETCHAR(c, ptr); + } +else c = *ptr; +#else /* no UTF-8 support */ +c = *ptr; +#endif /* SUPPORT_UTF8 */ + +if (type == NLTYPE_ANYCRLF) switch(c) + { + case 0x000a: *lenptr = (ptr > startptr && ptr[-1] == 0x0d)? 2 : 1; + return TRUE; /* LF */ + case 0x000d: *lenptr = 1; return TRUE; /* CR */ + default: return FALSE; + } + +else switch(c) + { + case 0x000a: *lenptr = (ptr > startptr && ptr[-1] == 0x0d)? 2 : 1; + return TRUE; /* LF */ + case 0x000b: /* VT */ + case 0x000c: /* FF */ + case 0x000d: *lenptr = 1; return TRUE; /* CR */ + case 0x0085: *lenptr = utf8? 2 : 1; return TRUE; /* NEL */ + case 0x2028: /* LS */ + case 0x2029: *lenptr = 3; return TRUE; /* PS */ + default: return FALSE; + } +} + +/* End of pcre_newline.c */ ============================================================ --- pcre/pcre_ord2utf8.c e2da5e11be19beab7cbe98fc4f1200438a4612f2 +++ pcre/pcre_ord2utf8.c e2da5e11be19beab7cbe98fc4f1200438a4612f2 @@ -0,0 +1,83 @@ +/************************************************* +* Perl-Compatible Regular Expressions * +*************************************************/ + +/* PCRE is a library of functions to support regular expressions whose syntax +and semantics are as close as possible to those of the Perl 5 language. + + Written by Philip Hazel + Copyright (c) 1997-2007 University of Cambridge + +----------------------------------------------------------------------------- +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of the University of Cambridge nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +----------------------------------------------------------------------------- +*/ + + +/* This file contains a private PCRE function that converts an ordinal +character value into a UTF8 string. */ + +#include "pcre_config.h" + +#include "pcre_internal.h" + + +/************************************************* +* Convert character value to UTF-8 * +*************************************************/ + +/* This function takes an integer value in the range 0 - 0x7fffffff +and encodes it as a UTF-8 character in 0 to 6 bytes. + +Arguments: + cvalue the character value + buffer pointer to buffer for result - at least 6 bytes long + +Returns: number of characters placed in the buffer +*/ + +int +_pcre_ord2utf8(int cvalue, uschar *buffer) +{ +#ifdef SUPPORT_UTF8 +register int i, j; +for (i = 0; i < _pcre_utf8_table1_size; i++) + if (cvalue <= _pcre_utf8_table1[i]) break; +buffer += i; +for (j = i; j > 0; j--) + { + *buffer-- = 0x80 | (cvalue & 0x3f); + cvalue >>= 6; + } +*buffer = _pcre_utf8_table2[i] | cvalue; +return i + 1; +#else +return 0; /* Keep compiler happy; this function won't ever be */ +#endif /* called when SUPPORT_UTF8 is not defined. */ +} + +/* End of pcre_ord2utf8.c */ ============================================================ --- pcre/pcre_ucp_searchfuncs.c bd92f7801af94ebe492b49be93a02fa992de0fdf +++ pcre/pcre_ucp_searchfuncs.c bd92f7801af94ebe492b49be93a02fa992de0fdf @@ -0,0 +1,177 @@ +/************************************************* +* Perl-Compatible Regular Expressions * +*************************************************/ + +/* PCRE is a library of functions to support regular expressions whose syntax +and semantics are as close as possible to those of the Perl 5 language. + + Written by Philip Hazel + Copyright (c) 1997-2007 University of Cambridge + +----------------------------------------------------------------------------- +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of the University of Cambridge nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +----------------------------------------------------------------------------- +*/ + + +/* This module contains code for searching the table of Unicode character +properties. */ + +#include "pcre_config.h" + +#include "pcre_internal.h" + +#include "ucp.h" /* Category definitions */ +#include "ucpinternal.h" /* Internal table details */ +#include "ucptable.h" /* The table itself */ + + +/* Table to translate from particular type value to the general value. */ + +static const int ucp_gentype[] = { + ucp_C, ucp_C, ucp_C, ucp_C, ucp_C, /* Cc, Cf, Cn, Co, Cs */ + ucp_L, ucp_L, ucp_L, ucp_L, ucp_L, /* Ll, Lu, Lm, Lo, Lt */ + ucp_M, ucp_M, ucp_M, /* Mc, Me, Mn */ + ucp_N, ucp_N, ucp_N, /* Nd, Nl, No */ + ucp_P, ucp_P, ucp_P, ucp_P, ucp_P, /* Pc, Pd, Pe, Pf, Pi */ + ucp_P, ucp_P, /* Ps, Po */ + ucp_S, ucp_S, ucp_S, ucp_S, /* Sc, Sk, Sm, So */ + ucp_Z, ucp_Z, ucp_Z /* Zl, Zp, Zs */ +}; + + + +/************************************************* +* Search table and return type * +*************************************************/ + +/* Three values are returned: the category is ucp_C, ucp_L, etc. The detailed +character type is ucp_Lu, ucp_Nd, etc. The script is ucp_Latin, etc. + +Arguments: + c the character value + type_ptr the detailed character type is returned here + script_ptr the script is returned here + +Returns: the character type category +*/ + +int +_pcre_ucp_findprop(const unsigned int c, int *type_ptr, int *script_ptr) +{ +int bot = 0; +int top = sizeof(ucp_table)/sizeof(cnode); +int mid; + +/* The table is searched using a binary chop. You might think that using +intermediate variables to hold some of the common expressions would speed +things up, but tests with gcc 3.4.4 on Linux showed that, on the contrary, it +makes things a lot slower. */ + +for (;;) + { + if (top <= bot) + { + *type_ptr = ucp_Cn; + *script_ptr = ucp_Common; + return ucp_C; + } + mid = (bot + top) >> 1; + if (c == (ucp_table[mid].f0 & f0_charmask)) break; + if (c < (ucp_table[mid].f0 & f0_charmask)) top = mid; + else + { + if ((ucp_table[mid].f0 & f0_rangeflag) != 0 && + c <= (ucp_table[mid].f0 & f0_charmask) + + (ucp_table[mid].f1 & f1_rangemask)) break; + bot = mid + 1; + } + } + +/* Found an entry in the table. Set the script and detailed type values, and +return the general type. */ + +*script_ptr = (ucp_table[mid].f0 & f0_scriptmask) >> f0_scriptshift; +*type_ptr = (ucp_table[mid].f1 & f1_typemask) >> f1_typeshift; + +return ucp_gentype[*type_ptr]; +} + + + +/************************************************* +* Search table and return other case * +*************************************************/ + +/* If the given character is a letter, and there is another case for the +letter, return the other case. Otherwise, return -1. + +Arguments: + c the character value + +Returns: the other case or NOTACHAR if none +*/ + +unsigned int +_pcre_ucp_othercase(const unsigned int c) +{ +int bot = 0; +int top = sizeof(ucp_table)/sizeof(cnode); +int mid, offset; + +/* The table is searched using a binary chop. You might think that using +intermediate variables to hold some of the common expressions would speed +things up, but tests with gcc 3.4.4 on Linux showed that, on the contrary, it +makes things a lot slower. */ + +for (;;) + { + if (top <= bot) return -1; + mid = (bot + top) >> 1; + if (c == (ucp_table[mid].f0 & f0_charmask)) break; + if (c < (ucp_table[mid].f0 & f0_charmask)) top = mid; + else + { + if ((ucp_table[mid].f0 & f0_rangeflag) != 0 && + c <= (ucp_table[mid].f0 & f0_charmask) + + (ucp_table[mid].f1 & f1_rangemask)) break; + bot = mid + 1; + } + } + +/* Found an entry in the table. Return NOTACHAR for a range entry. Otherwise +return the other case if there is one, else NOTACHAR. */ + +if ((ucp_table[mid].f0 & f0_rangeflag) != 0) return NOTACHAR; + +offset = ucp_table[mid].f1 & f1_casemask; +if ((offset & f1_caseneg) != 0) offset |= f1_caseneg; +return (offset == 0)? NOTACHAR : c + offset; +} + + +/* End of pcre_ucp_searchfuncs.c */ ============================================================ --- pcre/pcre_valid_utf8.c c587b5e870e25985bca0d58a189d7d5fca4a4a29 +++ pcre/pcre_valid_utf8.c c587b5e870e25985bca0d58a189d7d5fca4a4a29 @@ -0,0 +1,160 @@ +/************************************************* +* Perl-Compatible Regular Expressions * +*************************************************/ + +/* PCRE is a library of functions to support regular expressions whose syntax +and semantics are as close as possible to those of the Perl 5 language. + + Written by Philip Hazel + Copyright (c) 1997-2007 University of Cambridge + +----------------------------------------------------------------------------- +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of the University of Cambridge nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +----------------------------------------------------------------------------- +*/ + + +/* This module contains an internal function for validating UTF-8 character +strings. */ + + +#include "pcre_config.h" + +#include "pcre_internal.h" + + +/************************************************* +* Validate a UTF-8 string * +*************************************************/ + +/* This function is called (optionally) at the start of compile or match, to +validate that a supposed UTF-8 string is actually valid. The early check means +that subsequent code can assume it is dealing with a valid string. The check +can be turned off for maximum performance, but the consequences of supplying +an invalid string are then undefined. + +Originally, this function checked according to RFC 2279, allowing for values in +the range 0 to 0x7fffffff, up to 6 bytes long, but ensuring that they were in +the canonical format. Once somebody had pointed out RFC 3629 to me (it +obsoletes 2279), additional restrictions were applies. The values are now +limited to be between 0 and 0x0010ffff, no more than 4 bytes long, and the +subrange 0xd000 to 0xdfff is excluded. + +Arguments: + string points to the string + length length of string, or -1 if the string is zero-terminated + +Returns: < 0 if the string is a valid UTF-8 string + >= 0 otherwise; the value is the offset of the bad byte +*/ + +int +_pcre_valid_utf8(const uschar *string, int length) +{ +#ifdef SUPPORT_UTF8 +register const uschar *p; + +if (length < 0) + { + for (p = string; *p != 0; p++); + length = p - string; + } + +for (p = string; length-- > 0; p++) + { + register int ab; + register int c = *p; + if (c < 128) continue; + if (c < 0xc0) return p - string; + ab = _pcre_utf8_table4[c & 0x3f]; /* Number of additional bytes */ + if (length < ab || ab > 3) return p - string; + length -= ab; + + /* Check top bits in the second byte */ + if ((*(++p) & 0xc0) != 0x80) return p - string; + + /* Check for overlong sequences for each different length, and for the + excluded range 0xd000 to 0xdfff. */ + + switch (ab) + { + /* Check for xx00 000x (overlong sequence) */ + + case 1: + if ((c & 0x3e) == 0) return p - string; + continue; /* We know there aren't any more bytes to check */ + + /* Check for 1110 0000, xx0x xxxx (overlong sequence) or + 1110 1101, 1010 xxxx (0xd000 - 0xdfff) */ + + case 2: + if ((c == 0xe0 && (*p & 0x20) == 0) || + (c == 0xed && *p >= 0xa0)) + return p - string; + break; + + /* Check for 1111 0000, xx00 xxxx (overlong sequence) or + greater than 0x0010ffff (f4 8f bf bf) */ + + case 3: + if ((c == 0xf0 && (*p & 0x30) == 0) || + (c > 0xf4 ) || + (c == 0xf4 && *p > 0x8f)) + return p - string; + break; + +#if 0 + /* These cases can no longer occur, as we restrict to a maximum of four + bytes nowadays. Leave the code here in case we ever want to add an option + for longer sequences. */ + + /* Check for 1111 1000, xx00 0xxx */ + case 4: + if (c == 0xf8 && (*p & 0x38) == 0) return p - string; + break; + + /* Check for leading 0xfe or 0xff, and then for 1111 1100, xx00 00xx */ + case 5: + if (c == 0xfe || c == 0xff || + (c == 0xfc && (*p & 0x3c) == 0)) return p - string; + break; +#endif + + } + + /* Check for valid bytes after the 2nd, if any; all must start 10 */ + while (--ab > 0) + { + if ((*(++p) & 0xc0) != 0x80) return p - string; + } + } +#endif + +return -1; +} + +/* End of pcre_valid_utf8.c */ ============================================================ --- pcre/pcrepattern.texi 10041ae21b3ce5f6971aca811ce57abc0827da8b +++ pcre/pcrepattern.texi 10041ae21b3ce5f6971aca811ce57abc0827da8b @@ -0,0 +1,2405 @@ address@hidden This file was hand-translated to Texinfo from the upstream PCRE address@hidden documentation file pcrepattern.3, whose copyright notice is: address@hidden address@hidden Author: Philip Hazel, University Computing Service address@hidden Cambridge CB2 3QH, England address@hidden Last updated: 17 September 2007 address@hidden Copyright (c) 1997-2007 University of Cambridge. address@hidden address@hidden Redistribution and use in source and binary forms, with or without address@hidden modification, are permitted provided that the following conditions are met: address@hidden address@hidden * Redistributions of source code must retain the above copyright notice, address@hidden this list of conditions and the following disclaimer. address@hidden address@hidden * Redistributions in binary form must reproduce the above copyright address@hidden notice, this list of conditions and the following disclaimer in the address@hidden documentation and/or other materials provided with the distribution. address@hidden address@hidden * Neither the name of the University of Cambridge nor the names of its address@hidden contributors may be used to endorse or promote products derived from address@hidden this software without specific prior written permission. address@hidden address@hidden THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" address@hidden AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE address@hidden IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE address@hidden ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE address@hidden LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR address@hidden CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF address@hidden SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS address@hidden INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN address@hidden CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) address@hidden ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE address@hidden POSSIBILITY OF SUCH DAMAGE. address@hidden address@hidden Apart from markup translation, all mention of callouts has been address@hidden removed, and confusing references to PCRE itself, its configuration address@hidden options and library API, or to specific programming environments address@hidden have been removed or clarified. + address@hidden Regexp Details address@hidden Regexp Details + +The syntax and semantics of PCRE regular expressions, as used in +Monotone, are described in detail below. Regular expressions in +general are covered in a number of books, some of which have copious +examples. Jeffrey Friedl's ``Mastering Regular Expressions,'' +published by O'Reilly, covers regular expressions in great detail. +This description is intended as reference material. + address@hidden Characters and Metacharacters + +A regular expression is a pattern that is matched against a subject +string from left to right. Most characters stand for themselves in a +pattern, and match the corresponding characters in the subject. As a +trivial example, the pattern + address@hidden + The quick brown fox address@hidden verbatim + address@hidden +matches a portion of a subject string that is identical to +itself. When caseless matching is specified, letters are matched +independently of case. + +The power of regular expressions comes from the ability to include +alternatives and repetitions in the pattern. These are encoded in the +pattern by the use of @dfn{metacharacters}, which do not stand for +themselves but instead are interpreted in some special way. + +There are two different sets of metacharacters: those that are +recognized anywhere in the pattern except within square brackets, and +those that are recognized within square brackets. Outside square +brackets, the metacharacters are as follows: + address@hidden @code address@hidden \ +general escape character with several uses address@hidden ^ +assert start of string (or line, in multiline mode) address@hidden $ +assert end of string (or line, in multiline mode) address@hidden . +match any character except newline (by default) address@hidden [ +start character class definition address@hidden | +start of alternative branch address@hidden ( +start subpattern address@hidden ) +end subpattern address@hidden ? +extends the meaning of @samp{(} + also 0 or 1 quantifier + also quantifier minimizer address@hidden * +0 or more quantifier address@hidden + +1 or more quantifier + also ``possessive quantifier'' address@hidden @{ +start min/max quantifier address@hidden table + address@hidden +Part of a pattern that is in square brackets is called a "character +class". In a character class the only metacharacters are: + address@hidden @code address@hidden \ +general escape character address@hidden ^ +negate the class, but only if the first character address@hidden - +indicates character range address@hidden [ +POSIX character class (only if followed by POSIX + syntax) address@hidden ] +terminates the character class address@hidden table + address@hidden +The following sections describe the use of each of the metacharacters. + address@hidden Backslash + +The backslash character has several uses. Firstly, if it is followed +by a non-alphanumeric character, it takes away any special meaning +that character may have. This use of backslash as an escape character +applies both inside and outside character classes. + +For example, if you want to match a @samp{*} character, you write address@hidden in the pattern. This escaping action applies whether or not +the following character would otherwise be interpreted as a +metacharacter, so it is always safe to precede a non-alphanumeric with +backslash to specify that it stands for itself. In particular, if you +want to match a backslash, you write @samp{\\}. + +If a pattern is compiled with the @samp{(?x)} option, whitespace in +the pattern (other than in a character class) and characters between a address@hidden outside a character class and the next newline are +ignored. An escaping backslash can be used to include a whitespace or address@hidden character as part of the pattern. + +If you want to remove the special meaning from a sequence of +characters, you can do so by putting them between @samp{\Q} and address@hidden The @samp{\Q...\E} sequence is recognized both inside and +outside character classes. + address@hidden Non-printing Characters + +A second use of backslash provides a way of encoding non-printing characters +in patterns in a visible manner. There is no restriction on the appearance of +non-printing characters, apart from the binary zero that terminates a pattern, +but when a pattern is being prepared by text editing, it is usually easier to +use one of the following escape sequences than the binary character it +represents: + address@hidden @code address@hidden \a +alarm, that is, the BEL character (hex 07) address@hidden address@hidden +"address@hidden", where @var{x} is any character address@hidden \e +escape (hex 1B) address@hidden \f +formfeed (hex 0C) address@hidden \n +linefeed (hex 0A) address@hidden \r +carriage return (hex 0D) address@hidden \t +tab (hex 09) address@hidden address@hidden +character with octal code @var{ddd}, or backreference address@hidden address@hidden +character with hex code @var{hh} address@hidden address@hidden@address@hidden +character with hex code @var{hhh...} address@hidden table + +The precise effect of @address@hidden is as follows: if @var{x} is a lower +case letter, it is converted to upper case. Then bit 6 of the +character (hex 40) is inverted. Thus @samp{\cz} becomes hex 1A (the address@hidden control character, in ASCII), but @address@hidden becomes hex 3B +(@samp{;}), and @samp{\c;} becomes hex 7B (@address@hidden). + address@hidden the math in the next paragraph is not done with @math because address@hidden ``2**31'' is a much nicer thing to have in the Info file than ``2^{31}''. + +After @samp{\x}, from zero to two hexadecimal digits are read (letters +can be in upper or lower case). Any number of hexadecimal digits may +appear between @address@hidden and @address@hidden, but the value of the +character code must be less than 256 in non-UTF-8 mode, and less than address@hidden +$2^{31}$ address@hidden tex address@hidden +231 address@hidden html address@hidden address@hidden +2**31 address@hidden ifnothtml address@hidden ifnottex +in UTF-8 mode. That is, the maximum value in hexadecimal is +7FFFFFFF. Note that this is bigger than the largest Unicode code +point, which is 10FFFF. + +If characters other than hexadecimal digits appear between @address@hidden +and @address@hidden, or if there is no terminating @address@hidden, this form of +escape is not recognized. Instead, the initial @samp{\x} will be +interpreted as a basic hexadecimal escape, with no following digits, +giving a character whose value is zero. + +Characters whose value is less than 256 can be defined by either of +the two syntaxes for @samp{\x}. There is no difference in the way they +are handled. For example, @samp{\xdc} is exactly the same as address@hidden@address@hidden + +After @samp{\0} up to two further octal digits are read. If there are +fewer than two digits, just those that are present are used. Thus the +sequence @samp{\0\x\07} specifies two binary zeros followed by a address@hidden character (octal 007). Make sure you supply two digits after +the initial zero if the pattern character that follows is itself an +octal digit. + +The handling of a backslash followed by a digit other than 0 is +complicated. Outside a character class, PCRE reads it and any +following digits as a decimal number. If the number is less than 10, +or if there have been at least that many previous capturing left +parentheses in the expression, the entire sequence is taken as a address@hidden reference}. A description of how this works is given later, +following the discussion of parenthesized subpatterns. + +Inside a character class, or if the decimal number is greater than 9 +and there have not been that many capturing subpatterns, PCRE re-reads +up to three octal digits following the backslash, and uses them to +generate a data character. Any subsequent digits stand for +themselves. In non-UTF-8 mode, the value of a character specified in +octal must be less than @samp{\400}. In UTF-8 mode, values up to address@hidden are permitted. For example: + address@hidden @code address@hidden \040 +is another way of writing a space address@hidden \40 +is the same, provided there are fewer than 40 + previous capturing subpatterns address@hidden \7 +is always a back reference address@hidden \11 +might be a back reference, or another way of + writing a tab address@hidden \011 +is always a tab address@hidden \0113 +is a tab followed by the character @samp{3} address@hidden \113 +might be a back reference, otherwise the + character with octal code 113 address@hidden \377 +might be a back reference, otherwise + the byte consisting entirely of 1 bits address@hidden \81 +is either a back reference, or a binary zero + followed by the two characters @samp{8} and @samp{1} address@hidden table + +Note that octal values of 100 or greater must not be introduced by a +leading zero, because no more than three octal digits are ever read. + +All the sequences that define a single character value can be used +both inside and outside character classes. In addition, inside a +character class, the sequence @samp{\b} is interpreted as the @key{BS} +character (hex 08), and the sequences @samp{\R} and @samp{\X} are +interpreted as the characters @samp{R} and @samp{X}, +respectively. Outside a character class, these sequences have +different meanings (see below). + address@hidden Absolute and Relative Back References + +The sequence @samp{\g} followed by an unsigned or a negative number, +optionally enclosed in braces, is an absolute or relative back +reference. A named back reference can be coded as address@hidden@address@hidden Back references are discussed later, following the +discussion of parenthesized subpatterns. + address@hidden Generic character types + +Another use of backslash is for specifying generic character types. The +following are always recognized: + address@hidden @code address@hidden \d +any decimal digit address@hidden \D +any character that is not a decimal digit address@hidden \h +any horizontal whitespace character address@hidden \H +any character that is not a horizontal whitespace character address@hidden \s +any whitespace character address@hidden \S +any character that is not a whitespace character address@hidden \v +any vertical whitespace character address@hidden \V +any character that is not a vertical whitespace character address@hidden \w +any ``word'' character address@hidden \W +any ``non-word'' character address@hidden table + +Each pair of escape sequences partitions the complete set of +characters into two disjoint sets. Any given character matches one, +and only one, of each pair. + +These character type sequences can appear both inside and outside +character classes. They each match one character of the appropriate +type. If the current matching point is at the end of the subject +string, all of them fail, since there is no character to match. + +For compatibility with Perl, @samp{\s} does not match the @key{VT} +character (code 11). This makes it different from the the POSIX +``space'' class. The @samp{\s} characters are @key{TAB} (9), @key{LF} +(10), @key{FF} (12), @key{CR} (13), and @key{SPACE} (32). + +In UTF-8 mode, characters with values greater than 128 never match address@hidden, @samp{\s}, or @samp{\w}, and always match @samp{\D}, address@hidden, and @samp{\W}. These sequences retain their original +meanings from before UTF-8 support was available, mainly for +efficiency reasons. + +The sequences @samp{\h}, @samp{\H}, @samp{\v}, and @samp{\V} are Perl +5.10 features. In contrast to the other sequences, these do match +certain high-valued codepoints in UTF-8 mode. The horizontal space +characters are: + address@hidden @code address@hidden U+0009 +Horizontal tab address@hidden U+0020 +Space address@hidden U+00A0 +Non-break space address@hidden U+1680 +Ogham space mark address@hidden U+180E +Mongolian vowel separator address@hidden U+2000 +En quad address@hidden U+2001 +Em quad address@hidden U+2002 +En space address@hidden U+2003 +Em space address@hidden U+2004 +Three-per-em space address@hidden U+2005 +Four-per-em space address@hidden U+2006 +Six-per-em space address@hidden U+2007 +Figure space address@hidden U+2008 +Punctuation space address@hidden U+2009 +Thin space address@hidden U+200A +Hair space address@hidden U+202F +Narrow no-break space address@hidden U+205F +Medium mathematical space address@hidden U+3000 +Ideographic space address@hidden table + address@hidden +The vertical space characters are: + address@hidden @code address@hidden U+000A +Linefeed address@hidden U+000B +Vertical tab address@hidden U+000C +Formfeed address@hidden U+000D +Carriage return address@hidden U+0085 +Next line address@hidden U+2028 +Line separator address@hidden U+2029 +Paragraph separator address@hidden table + address@hidden +A ``word'' character is an underscore or any character less than 256 +that is a letter or digit. The definition of letters and digits is +that used for the ``C'' locale. + address@hidden Newline Conventions + +PCRE supports five different conventions for indicating line breaks in +strings: a single CR (carriage return) character, a single LF +(linefeed) character, the two-character sequence CRLF, any of the +three preceding, or any Unicode newline sequence. The default is to +match any Unicode newline sequence. It is possible to override the +default newline convention by starting a pattern string with one of +the following five sequences: + address@hidden @code address@hidden (*CR) + carriage return address@hidden (*LF) + linefeed address@hidden (*CRLF) + carriage return, followed by linefeed address@hidden (*ANYCRLF) + any of the three above address@hidden (*ANY) + all Unicode newline sequences address@hidden table + +For example, the pattern + address@hidden + (*CR)a.b address@hidden verbatim + address@hidden +changes the convention to CR. That pattern matches @samp{a\nb} because +LF is no longer a newline. Note that these special settings, which are +not Perl-compatible, are recognized only at the very start of a +pattern, and that they must be in upper case. If more than one of them +is present, the last one is used. + +The newline convention does not affect what the @samp{\R} escape +sequence matches. By default, this is any Unicode newline sequence, +for Perl compatibility. However, this can be changed; see the +description of @samp{\R} below. A change of @samp{\R} setting can be +combined with a change of newline convention. + address@hidden Newline Sequences + +Outside a character class, by default, the escape sequence @samp{\R} matches +any Unicode newline sequence. This is a Perl 5.10 feature. In +non-UTF-8 mode @samp{\R} is equivalent to the following: + address@hidden + (?>\r\n|\n|\x0b|\f|\r|\x85) address@hidden verbatim + +This is an example of an "atomic group", details of which are given +below. This particular group matches either the two-character +sequence @key{CR} followed by @key{LF}, or one of the single +characters @key{LF} (linefeed, @code{U+000A}), @key{VT} (vertical tab, address@hidden), @key{FF} (formfeed, @code{U+000C}), @key{CR} (carriage +return, @code{U+000D}), or @key{NEL} (next line, @code{U+0085}). The +two-character sequence is treated as a single unit that cannot be +split. In UTF-8 mode, two additional characters whose codepoints are +greater than 255 are added: @key{LS} (line separator, @code{U+2028}) +and @key{PS} (paragraph separator, @code{U+2029}). + +It is possible to change the meaning of @samp{\R} by starting a +pattern string with one of the following sequences: + address@hidden @code address@hidden (*BSR_ANYCRLF) address@hidden, @key{LF}, or @address@hidden only address@hidden (*BSR_UNICODE) +any Unicode newline sequence (the default) address@hidden table + +Note that these special settings, which are not Perl-compatible, are +recognized only at the very start of a pattern, and that they must be +in upper case. If more than one of them is present, the last one is +used. They can be combined with a change of newline convention, for +example, a pattern can start with: + address@hidden + (*ANY)(*BSR_ANYCRLF) address@hidden verbatim + address@hidden +Inside a character class, @samp{\R} matches the letter @samp{R}. + address@hidden Unicode Character Properties + +Three additional escape sequences match characters with specific +Unicode properties. When not in UTF-8 mode, these sequences are of +course limited to testing characters whose codepoints are less than +256, but they do work in this mode. The extra escape sequences are: + address@hidden @code address@hidden address@hidden@address@hidden +a character with the @var{xx} property address@hidden address@hidden@address@hidden +a character without the @var{xx} property address@hidden \X +an extended Unicode sequence address@hidden table + +The property names represented by @var{xx} above are limited to the +Unicode script names, the general category properties, and @samp{Any}, +which matches any character (including newline). Other properties such +as @samp{InMusicalSymbols} are not currently supported by PCRE. Note +that @address@hidden@}} does not match any characters, so always causes +a match failure. + +Sets of Unicode characters are defined as belonging to certain +scripts. A character from one of these sets can be matched using a +script name. For example: + address@hidden + \p{Greek} + \P{Han} address@hidden verbatim + address@hidden +Those that are not part of an identified script are lumped together as +``Common.'' The current list of scripts is: + +Arabic, +Armenian, +Balinese, +Bengali, +Bopomofo, +Braille, +Buginese, +Buhid, +Canadian_Aboriginal, +Cherokee, +Common, +Coptic, +Cuneiform, +Cypriot, +Cyrillic, +Deseret, +Devanagari, +Ethiopic, +Georgian, +Glagolitic, +Gothic, +Greek, +Gujarati, +Gurmukhi, +Han, +Hangul, +Hanunoo, +Hebrew, +Hiragana, +Inherited, +Kannada, +Katakana, +Kharoshthi, +Khmer, +Lao, +Latin, +Limbu, +Linear_B, +Malayalam, +Mongolian, +Myanmar, +New_Tai_Lue, +Nko, +Ogham, +Old_Italic, +Old_Persian, +Oriya, +Osmanya, +Phags_Pa, +Phoenician, +Runic, +Shavian, +Sinhala, +Syloti_Nagri, +Syriac, +Tagalog, +Tagbanwa, +Tai_Le, +Tamil, +Telugu, +Thaana, +Thai, +Tibetan, +Tifinagh, +Ugaritic, +Yi. + +Each character has exactly one general category property, specified by a +two-letter abbreviation. For compatibility with Perl, negation can be specified +by including a circumflex between the opening brace and the property name. For +example, @address@hidden@}} is the same as @address@hidden@}}. + +If only one letter is specified with @samp{\p} or @samp{\P}, it +includes all the general category properties that start with that +letter. In this case, in the absence of negation, the curly brackets +in the escape sequence are optional; these two examples have the same +effect: + address@hidden + \p{L} + \pL address@hidden verbatim + address@hidden +The following general category property codes are supported: + address@hidden @code address@hidden C +Other address@hidden Cc +Control address@hidden Cf +Format address@hidden Cn +Unassigned address@hidden Co +Private use address@hidden Cs +Surrogate + address@hidden L +Letter address@hidden Ll +Lower case letter address@hidden Lm +Modifier letter address@hidden Lo +Other letter address@hidden Lt +Title case letter address@hidden Lu +Upper case letter + address@hidden M +Mark address@hidden Mc +Spacing mark address@hidden Me +Enclosing mark address@hidden Mn +Non-spacing mark + address@hidden N +Number address@hidden Nd +Decimal number address@hidden Nl +Letter number address@hidden No +Other number + address@hidden P +Punctuation address@hidden Pc +Connector punctuation address@hidden Pd +Dash punctuation address@hidden Pe +Close punctuation address@hidden Pf +Final punctuation address@hidden Pi +Initial punctuation address@hidden Po +Other punctuation address@hidden Ps +Open punctuation + address@hidden S +Symbol address@hidden Sc +Currency symbol address@hidden Sk +Modifier symbol address@hidden Sm +Mathematical symbol address@hidden So +Other symbol + address@hidden Z +Separator address@hidden Zl +Line separator address@hidden Zp +Paragraph separator address@hidden Zs +Space separator address@hidden table + +The special property @samp{L&} is also supported: it matches a +character that has the @samp{Lu}, @samp{Ll}, or @samp{Lt} property, in +other words, a letter that is not classified as a modifier or +``other.'' + +The @samp{Cs} (Surrogate) property applies only to characters in the +range @code{U+D800} to @code{U+DFFF}. Such characters are not valid in +UTF-8 strings (see RFC 3629) and so cannot be tested by PCRE. + +The long synonyms for these properties that Perl supports (such as address@hidden@address@hidden) are not supported by PCRE, nor is it permitted to +prefix any of these properties with @samp{Is}. + +No character that is in the Unicode table has the @samp{Cn} +(unassigned) property. Instead, this property is assumed for any code +point that is not in the Unicode table. + +Specifying caseless matching does not affect these escape sequences. For +example, @address@hidden@}} always matches only upper case letters. + +The @samp{\X} escape matches any number of Unicode characters that +form an extended Unicode sequence. @samp{\X} is equivalent to + address@hidden + (?>\PM\pM*) address@hidden verbatim + +That is, it matches a character without the ``mark'' property, +followed by zero or more characters with the ``mark'' property, and +treats the sequence as an atomic group (see below). Characters with +the ``mark'' property are typically accents that affect the preceding +character. None of them have codepoints less than 256, so in non-UTF-8 +mode @samp{\X} matches any one character. + +Matching characters by Unicode property is not fast, because PCRE has +to search a structure that contains data for over fifteen thousand +characters. That is why the traditional escape sequences such as address@hidden and @samp{\w} do not use Unicode properties in PCRE. + address@hidden Resetting the Match Start + +The escape sequence @samp{\K}, which is a Perl 5.10 feature, causes +any previously matched characters not to be included in the final +matched sequence. For example, the pattern: + address@hidden + foo\Kbar address@hidden verbatim + address@hidden +matches @samp{foobar}, but reports that it has matched address@hidden This feature is similar to a lookbehind assertion +(described below). However, in this case, the part of the subject +before the real match does not have to be of fixed length, as +lookbehind assertions do. The use of @samp{\K} does not interfere with the +setting of captured substrings. For example, when the pattern + address@hidden + (foo)\Kbar address@hidden verbatim + address@hidden +matches @samp{foobar}, the first substring is still set to @samp{foo}. + address@hidden Simple assertions + +The final use of backslash is for certain simple assertions. An +assertion specifies a condition that has to be met at a particular +point in a match, without consuming any characters from the subject +string. The use of subpatterns for more complicated assertions is +described below. The backslashed assertions are: + address@hidden @code address@hidden \b +matches at a word boundary address@hidden \B +matches when not at a word boundary address@hidden \A +matches at the start of the subject address@hidden \Z +matches at the end of the subject + also matches before a newline at the end of the subject address@hidden \z +matches only at the end of the subject address@hidden \G +matches at the first matching position in the subject address@hidden table + address@hidden +These assertions may not appear in character classes (but note that address@hidden has a different meaning, namely the backspace character, +inside a character class). + +A word boundary is a position in the subject string where the current +character and the previous character do not both match @samp{\w} or address@hidden (i.e.@: one matches @samp{\w} and the other matches address@hidden), or the start or end of the string if the first or last +character matches @samp{\w}, respectively. + +The @samp{\A}, @samp{\Z}, and @samp{\z} assertions differ from the +traditional circumflex and dollar (described in the next section) in +that they only ever match at the very start and end of the subject +string, whatever options are set. Thus, they are independent of +multiline mode. The difference between @samp{\Z} and @samp{\z} is that address@hidden matches before a newline at the end of the string as well as +at the very end, whereas @samp{\z} matches only at the end. + +The @samp{\G} assertion is true only when the current matching +position is at the start point of the match. As used in Monotone, address@hidden is always equal to @samp{\A}. + address@hidden Circumflex and Dollar + +Outside a character class, in the default matching mode, the +circumflex character, @samp{^}, is an assertion that is true only if +the current matching point is at the start of the subject string. +Inside a character class, circumflex has an entirely different meaning +(see below). + +Circumflex need not be the first character of the pattern if a number +of alternatives are involved, but it should be the first thing in each +alternative in which it appears if the pattern is ever to match that +branch. If all possible alternatives start with a circumflex, that is, +if the pattern is constrained to match only at the start of the +subject, it is said to be an ``anchored'' pattern. (There are also +other constructs that can cause a pattern to be anchored.) + +A dollar character, @samp{$}, is an assertion that is true only if the +current matching point is at the end of the subject string, or +immediately before a newline at the end of the string (by +default). Dollar need not be the last character of the pattern if a +number of alternatives are involved, but it should be the last item in +any branch in which it appears. Dollar has no special meaning in a +character class. + +The meanings of the circumflex and dollar characters are changed if +the @samp{(?m)} option is set. When this is the case, a circumflex +matches immediately after internal newlines as well as at the start of +the subject string. It does not match after a newline that ends the +string. A dollar matches before any newlines in the string, as well as +at the very end, when @samp{(?m)} is set. When newline is specified as +the two-character sequence @address@hidden, isolated @key{CR} and address@hidden characters do not indicate newlines. + +For example, the pattern @samp{^abc$} matches the subject string address@hidden (where @samp{\n} represents a newline) in multiline +mode, but not otherwise. Consequently, patterns that are anchored in +single line mode because all branches start with ^ are not anchored in +multiline mode. + +Note that the sequences @samp{\A}, @samp{\Z}, and @samp{\z} can be +used to match the start and end of the subject in both modes, and if +all branches of a pattern start with @samp{\A} it is always anchored. + address@hidden Full Stop (Period, Dot) + +Outside a character class, a dot in the pattern matches any one +character in the subject string except (by default) a character that +signifies the end of a line. In UTF-8 mode, the matched character may +be more than one byte long. + +When a line ending is defined as a single character, dot never matches +that character; when the two-character sequence @address@hidden is +used, dot does not match @key{CR} if it is immediately followed by address@hidden, but otherwise it matches all characters (including isolated address@hidden and @key{LF}s). When any Unicode line endings are being +recognized, dot does not match @key{CR} or @key{LF} or any of the +other line ending characters. + +The behaviour of dot with regard to newlines can be changed. If the address@hidden(?s)} option is set, a dot matches any one character, without +exception. If the two-character sequence @address@hidden is present +in the subject string, it takes two dots to match it. + +The handling of dot is entirely independent of the handling of circumflex and +dollar, the only relationship being that they both involve newlines. Dot has no +special meaning in a character class. + address@hidden Matching a Single Byte + +Outside a character class, the escape sequence @samp{\C} matches any +one byte, both in and out of UTF-8 mode. Unlike a dot, it always +matches any line-ending characters. The feature is provided in Perl in +order to match individual bytes in UTF-8 mode. Because it breaks up +UTF-8 characters into individual bytes, what remains in the string may +be a malformed UTF-8 string. For this reason, the @samp{\C} escape +sequence is best avoided. + +PCRE does not allow @samp{\C} to appear in lookbehind assertions +(described below), because in UTF-8 mode this would make it impossible +to calculate the length of the lookbehind. + address@hidden Square Brackets and Character Classes + +An opening square bracket introduces a character class, terminated by +a closing square bracket. A closing square bracket on its own is not +special. If a closing square bracket is required as a member of the +class, it should be the first data character in the class (after an +initial circumflex, if present) or escaped with a backslash. + +A character class matches a single character in the subject. In UTF-8 +mode, the character may occupy more than one byte. A matched character +must be in the set of characters defined by the class, unless the +first character in the class definition is a circumflex, in which case +the subject character must not be in the set defined by the class. If +a circumflex is actually required as a member of the class, ensure it +is not the first character, or escape it with a backslash. + +For example, the character class @samp{[aeiou]} matches any lower case +vowel, while @samp{[^aeiou]} matches any character that is not a lower +case vowel. Note that a circumflex is just a convenient notation for +specifying the characters that are in the class by enumerating those +that are not. A class that starts with a circumflex is not an +assertion: it still consumes a character from the subject string, and +therefore it fails if the current pointer is at the end of the string. + +In UTF-8 mode, characters with values greater than 255 can be included +in a class as a literal string of bytes, or by using the @address@hidden +escaping mechanism. + +When caseless matching is set, any letters in a class represent both +their upper case and lower case versions, so for example, a caseless address@hidden matches @samp{A} as well as @samp{a}, and a caseless [^aeiou] +does not match @samp{A}, whereas a caseful version would. In UTF-8 mode, +PCRE always understands the concept of case for characters whose +values are less than 128, so caseless matching is always possible. For +characters with higher values, the concept of case is supported if +PCRE is compiled with Unicode property support, but not otherwise. If +you want to use caseless matching for characters 128 and above, you +must ensure that PCRE is compiled with Unicode property support as +well as with UTF-8 support. + +Characters that might indicate line breaks are never treated in any +special way when matching character classes, whatever line-ending +sequence is in use, and whatever setting of the @samp{(?s)} and address@hidden(?m)} options is used. A class such as @samp{[^a]} always +matches one of these characters. + +The minus (hyphen) character can be used to specify a range of +characters in a character class. For example, @samp{[d-m]} matches any +letter between @samp{d} and @samp{m}, inclusive. If a minus character +is required in a class, it must be escaped with a backslash or appear +in a position where it cannot be interpreted as indicating a range, +typically as the first or last character in the class. + +It is not possible to have the literal character @samp{]} as the end +character of a range. A pattern such as @samp{[W-]46]} is interpreted +as a class of two characters (@samp{W} and @samp{-}) followed by a +literal string @samp{46]}, so it would match @samp{W46]} or address@hidden However, if the @samp{]} is escaped with a backslash it +is interpreted as the end of range, so @samp{[W-\]46]} is interpreted +as a class containing a range followed by two other characters. The +octal or hexadecimal representation of @samp{]} can also be used to +end a range. + +Ranges operate in the collating sequence of character values. They can +also be used for characters specified numerically, for example address@hidden In UTF-8 mode, ranges can include characters whose +values are greater than 255, for example @address@hidden@address@hidden@}]}. + +If a range that includes letters is used when caseless matching is +set, it matches the letters in either case. For example, @samp{[W-c]} +is equivalent to @samp{[][\\^_`wxyzabc]}, matched caselessly. + +The character types @samp{\d}, @samp{\D}, @samp{\p}, @samp{\P}, address@hidden, @samp{\S}, @samp{\w}, and @samp{\W} may also appear in a +character class, and add the characters that they match to the +class. For example, @samp{[\dABCDEF]} matches any hexadecimal digit. A +circumflex can conveniently be used with the upper case character +types to specify a more restricted set of characters than the matching +lower case type. For example, the class @samp{[^\W_]} matches any +letter or digit, but not underscore. + +The only metacharacters that are recognized in character classes are +backslash, hyphen (only where it can be interpreted as specifying a +range), circumflex (only at the start), opening square bracket (only +when it can be interpreted as introducing a POSIX class name---see the +next section), and the terminating closing square bracket. However, +escaping other non-alphanumeric characters does no harm. + address@hidden POSIX Character Classes + +Perl supports the POSIX notation for character classes. This uses +names enclosed by @samp{[:} and @samp{:]} within the enclosing square +brackets. PCRE also supports this notation. For example, + address@hidden + [01[:alpha:]%] address@hidden verbatim + address@hidden +matches @samp{0}, @samp{1}, any alphabetic character, or @samp{%}. The +supported class names are + address@hidden @code address@hidden alnum +letters and digits address@hidden alpha +letters address@hidden ascii +character codes 0 -- 127 address@hidden blank +space or tab only address@hidden cntrl +control characters address@hidden digit +decimal digits (same as @samp{\d}) address@hidden graph +printing characters, excluding space address@hidden lower +lower case letters address@hidden print +printing characters, including space address@hidden punct +printing characters, excluding letters and digits address@hidden space +white space (not quite the same as @samp{\s}) address@hidden upper +upper case letters address@hidden word +``word'' characters (same as @samp{\w}) address@hidden xdigit +hexadecimal digits address@hidden table + +The ``space'' characters are @key{HT} (9), @key{LF} (10), @key{VT} +(11), @key{FF} (12), @key{CR} (13), and space (32). Notice that this +list includes the @key{VT} character (code 11). This makes "space" +different to @samp{\s}, which does not include @key{VT} (for Perl +compatibility). + +The name ``word'' is a Perl extension, and ``blank'' is a GNU +extension from Perl 5.8. Another Perl extension is negation, which is +indicated by a @samp{^} character after the colon. For example, + address@hidden + [12[:^digit:]] address@hidden verbatim + address@hidden +matches @samp{1}, @samp{2}, or any non-digit. PCRE (and Perl) also +recognize the POSIX syntax @address@hidden and @address@hidden +where @var{ch} is a ``collating element,'' but these are not +supported, and an error is given if they are encountered. + +In UTF-8 mode, characters with values greater than 128 do not match +any of the POSIX character classes. + address@hidden Vertical Bar + +Vertical bar characters are used to separate alternative patterns. For +example, the pattern + address@hidden + gilbert|sullivan address@hidden verbatim + address@hidden +matches either @samp{gilbert} or @samp{sullivan}. Any number of +alternatives may appear, and an empty alternative is permitted +(matching the empty string). The matching process tries each +alternative in turn, from left to right, and the first one that +succeeds is used. If the alternatives are within a subpattern (defined +below), "succeeds" means matching the rest of the main pattern as well +as the alternative in the subpattern. + address@hidden Internal Option Setting + +The behavior of the matching engine can be adjusted from within the +pattern by a sequence of option letters enclosed between @samp{(?} and address@hidden)}. The option letters are + address@hidden @code address@hidden i +Caseless: characters in one case match the corresponding + characters in other cases as well. address@hidden m +Multiline: @samp{^} and @samp{$} match at newlines + as well as at beginning and end of string. address@hidden s +Dotall: dot matches any character, including newline characters. address@hidden x +Extended syntax: unescaped white space is ignored and embedded + comments are possible. address@hidden J +Dupnames: names for capturing subpattern need not be unique. address@hidden U +Ungreedy: quantifiers match as few times as possible by default. address@hidden X +Extra: for forward compatibility, give an error if any escape sequence +with no defined meaning appears. address@hidden table + +For example, @samp{(?im)} sets caseless, multiline matching. It is +also possible to unset these options by preceding the letters with a +hyphen, and a combined setting and unsetting such as @samp{(?im-sx)} +is also permitted. (This would set the caseless and multiline options +while unsetting the dotall and extended-syntax options.) If a letter +appears both before and after the hyphen, the option is unset. The +lowercase option letters are Perl-compatible; the uppercase ones are +PCRE only. + +When an option change occurs at top level (that is, not inside +subpattern parentheses), the change applies to the remainder of the +pattern that follows. An option change within a subpattern (see below +for a description of subpatterns) affects only that part of the +current pattern that follows it, so + address@hidden + (a(?i)b)c address@hidden verbatim + address@hidden +matches @samp{abc} and @samp{aBc} and no other strings. By this +means, options can be made to have different settings in different +parts of the pattern. Any changes made in one alternative do carry on +into subsequent branches within the same subpattern. For example, + address@hidden + (a(?i)b|c) address@hidden verbatim + address@hidden +matches @samp{ab}, @samp{aB}, @samp{c}, and @samp{C}, even though when +matching @samp{C} the first branch is abandoned before the option +setting. This is because the effects of option settings happen when +the pattern is parsed. There would be some very weird behaviour +otherwise. + address@hidden:} Unlike these options, the similar, PCRE-specific option +sequences that start with @samp{(*} may appear only at the very +beginning of the pattern. Details of these sequences are given in the +section entitled ``Newline sequences,'' above. + address@hidden Subpatterns + +Subpatterns are delimited by parentheses (round brackets), which can +be nested. Turning part of a pattern into a subpattern does two +things: + address@hidden address@hidden +It localizes a set of alternatives. For example, the pattern + address@hidden + cat(aract|erpillar|) address@hidden verbatim + address@hidden +matches one of the words @samp{cat}, @samp{cataract}, or address@hidden Without the parentheses, it would match address@hidden, @samp{erpillar} or an empty string. + address@hidden +It sets up the subpattern as a capturing subpattern. As used in +Monotone this only means that during matching, the portion of the +subject string that matched the subpattern is available for back +references. Captured subpatterns are, for instance, not available to +callers of @code{regex.search}. Opening parentheses are counted from +left to right (starting from 1) to obtain numbers for the capturing +subpatterns. + +For example, if the string @samp{the red king} is matched against the pattern + address@hidden + the ((red|white) (king|queen)) address@hidden verbatim + +the captured substrings are @samp{red king}, @samp{red}, and address@hidden, and are numbered 1, 2, and 3, respectively. address@hidden enumerate + +The fact that plain parentheses fulfil two functions is not always +helpful. There are often times when a grouping subpattern is required +without a capturing requirement. If an opening parenthesis is followed +by a question mark and a colon, the subpattern does not do any +capturing, and is not counted when computing the number of any +subsequent capturing subpatterns. For example, if the string @samp{the +white queen} is matched against the pattern + address@hidden + the ((?:red|white) (king|queen)) address@hidden verbatim + address@hidden +the captured substrings are @samp{white queen} and @samp{queen}, and +are numbered 1 and 2. The maximum number of capturing subpatterns is +65535. + +As a convenient shorthand, if any option settings are required at the +start of a non-capturing subpattern, the option letters may appear +between the @samp{?} and the @samp{:}. Thus the two patterns + address@hidden + (?i:saturday|sunday) + (?:(?i)saturday|sunday) address@hidden verbatim + address@hidden +match exactly the same set of strings. Because alternative branches +are tried from left to right, and options are not reset until the end +of the subpattern is reached, an option setting in one branch does +affect subsequent branches, so the above patterns match @samp{SUNDAY} +as well as @samp{Saturday}. + address@hidden Duplicate Subpattern Numbers + +Perl 5.10 introduced a feature whereby each alternative in a +subpattern uses the same numbers for its capturing parentheses. Such a +subpattern starts with @samp{(?|} and is itself a non-capturing +subpattern. For example, consider this pattern: + address@hidden + (?|(Sat)ur|(Sun))day address@hidden verbatim + address@hidden +Because the two alternatives are inside a @samp{(?|} group, both sets +of capturing parentheses are numbered one. Thus, when the pattern +matches, you can look at captured substring number one, whichever +alternative matched. This construct is useful when you want to capture +part, but not all, of one of a number of alternatives. Inside a address@hidden(?|} group, parentheses are numbered as usual, but the number is +reset at the start of each branch. The numbers of any capturing +buffers that follow the subpattern start after the highest number used +in any branch. The following example is taken from the Perl +documentation. The numbers underneath show in which buffer the +captured content will be stored. + address@hidden + # before ---------------branch-reset----------- after + / ( a ) (?| x ( y ) z | (p (q) r) | (t) u (v) ) ( z ) /x + # 1 2 2 3 2 3 4 address@hidden verbatim + address@hidden +A backreference or a recursive call to a numbered subpattern always +refers to the first one in the pattern with the given number. + +An alternative approach to using this ``branch reset'' feature is to +use duplicate named subpatterns, as described in the next section. + address@hidden Named Subpatterns + +Identifying capturing parentheses by number is simple, but it can be +very hard to keep track of the numbers in complicated regular +expressions. Furthermore, if an expression is modified, the numbers +may change. To help with this difficulty, PCRE supports the naming of +subpatterns. This feature was not added to Perl until release +5.10. Python had the feature earlier, and PCRE introduced it at +release 4.0, using the Python syntax. PCRE now supports both the Perl +and the Python syntax. + +In PCRE, a subpattern can be named in one of three ways: address@hidden(?<@var{name}>...)} or @samp{(?'@var{name}'...)} as in Perl, or address@hidden(?P<@var{name}>...)} as in Python. References to capturing +parentheses from other parts of the pattern, such as backreferences, +recursion, and conditions, can be made by name as well as by number. + +Names consist of up to 32 alphanumeric characters and +underscores. Named capturing parentheses are still allocated numbers +as well as names, exactly as if the names were not present. + +By default, a name must be unique within a pattern, but it is possible +to relax this constraint by setting the @samp{(?J)} option. This can +be useful for patterns where only one instance of the named +parentheses can match. Suppose you want to match the name of a +weekday, either as a 3-letter abbreviation or as the full name, and in +both cases you want to extract the abbreviation. This pattern +(ignoring the line breaks) does the job: + address@hidden + (?Jx) + (?Mon|Fri|Sun)(?:day)?| + (?Tue)(?:sday)?| + (?Wed)(?:nesday)?| + (?Thu)(?:rsday)?| + (?Sat)(?:urday)? address@hidden verbatim + address@hidden +There are five capturing substrings, but only one is ever set after a +match. (An alternative way of solving this problem is to use a +``branch reset'' subpattern, as described in the previous section.) + address@hidden Repetition + +Repetition is specified by @dfn{quantifiers}, which can follow any of +the following items: + address@hidden @bullet address@hidden + a literal data character address@hidden + the dot metacharacter address@hidden + the @samp{\C} escape sequence address@hidden + the @samp{\X} escape sequence (in UTF-8 mode with Unicode properties) address@hidden + the @samp{\R} escape sequence address@hidden + an escape such as @samp{\d} that matches a single character address@hidden + a character class address@hidden + a back reference (see next section) address@hidden + a parenthesized subpattern (unless it is an assertion) address@hidden itemize + +The general repetition quantifier specifies a minimum and maximum +number of permitted matches, by giving the two numbers in curly +brackets (braces), separated by a comma. The numbers must be less than +65536, and the first must be less than or equal to the second. For +example: + address@hidden + z{2,4} address@hidden verbatim + address@hidden +matches @samp{zz}, @samp{zzz}, or @samp{zzzz}. A closing brace on its +own is not a special character. If the second number is omitted, but +the comma is present, there is no upper limit; if the second number +and the comma are both omitted, the quantifier specifies an exact +number of required matches. Thus + address@hidden + [aeiou]{3,} address@hidden verbatim + address@hidden +matches at least 3 successive vowels, but may match many more, while + address@hidden + \d{8} address@hidden verbatim + address@hidden +matches exactly 8 digits. An opening curly bracket that appears in a +position where a quantifier is not allowed, or one that does not match +the syntax of a quantifier, is taken as a literal character. For +example, @address@hidden,address@hidden is not a quantifier, but a literal string of four +characters. + +In UTF-8 mode, quantifiers apply to UTF-8 characters rather than to +individual bytes. Thus, for example, @address@hidden@address@hidden@}} matches two +UTF-8 characters, each of which is represented by a two-byte +sequence. Similarly, @address@hidden@}} matches three Unicode extended +sequences, each of which may be several bytes long (and they may be of +different lengths). + +The quantifier @address@hidden@}} is permitted, causing the expression to +behave as if the previous item and the quantifier were not present. + +For convenience, the three most common quantifiers have +single-character abbreviations: + address@hidden @code address@hidden * +is equivalent to @{0,@} address@hidden + +is equivalent to @{1,@} address@hidden ? +is equivalent to @{0,address@hidden address@hidden table + +It is possible to construct infinite loops by following a subpattern that can +match no characters with a quantifier that has no upper limit, for example: + address@hidden + (a?)* address@hidden verbatim + address@hidden +Earlier versions of Perl and PCRE used to give an error at compile +time for such patterns. However, because there are cases where this +can be useful, such patterns are now accepted, but if any repetition +of the subpattern does in fact match no characters, the loop is +forcibly broken. + +By default, the quantifiers are @dfn{greedy}, that is, they match as +much as possible (up to the maximum number of permitted times), +without causing the rest of the pattern to fail. The classic example +of where this gives problems is in trying to match comments in C +programs. These appear between @samp{/*} and @samp{*/}, and within the +comment, individual @samp{*} and @samp{/} characters may appear. An +attempt to match C comments by applying the pattern + address@hidden + /\*.*\*/ address@hidden verbatim + address@hidden +to the string + address@hidden + /* first comment */ not comment /* second comment */ address@hidden verbatim + address@hidden +fails, because it matches the entire string owing to the greediness of +the @samp{.*} item. + +However, if a quantifier is followed by a question mark, it ceases to +be greedy, and instead matches the minimum number of times possible, +so the pattern + address@hidden + /\*.*?\*/ address@hidden verbatim + address@hidden +does the right thing with the C comments. The meaning of the various +quantifiers is not otherwise changed, just the preferred number of +matches. Do not confuse this use of question mark with its use as a +quantifier in its own right. Because it has two uses, it can sometimes +appear doubled, as in + address@hidden + \d??\d address@hidden verbatim + address@hidden +which matches one digit by preference, but can match two if that is the only +way the rest of the pattern matches. + +If the @samp{(?U)} option is set (an option that is not available in +Perl), the quantifiers are not greedy by default, but individual ones +can be made greedy by following them with a question mark. In other +words, it inverts the default behaviour. + +When a parenthesized subpattern is quantified with a minimum repeat count that +is greater than 1 or with a limited maximum, more memory is required for the +compiled pattern, in proportion to the size of the minimum or maximum. + +If a pattern starts with @samp{.*} or @address@hidden,@}} and the address@hidden(?s)} option is set, thus allowing the dot to match newlines, +the pattern is implicitly anchored, because whatever follows will be +tried against every character position in the subject string, so there +is no point in retrying the overall match at any position after the +first. PCRE normally treats such a pattern as though it were preceded +by @samp{\A}. + +In cases where it is known that the subject string contains no +newlines, it is worth setting @samp{(?s)} in order to obtain this +optimization, or alternatively using @samp{^} or @samp{\A} to indicate +anchoring explicitly. + +However, there is one situation where the optimization cannot be +used. When .* is inside capturing parentheses that are the subject of +a backreference elsewhere in the pattern, a match at the start may +fail where a later one succeeds. Consider, for example: + address@hidden + (.*)abc\1 address@hidden verbatim + address@hidden +If the subject is @samp{xyz123abc123} the match point is the fourth +character. For this reason, such a pattern is not implicitly anchored. + +When a capturing subpattern is repeated, the value captured is the +substring that matched the final iteration. For example, after + address@hidden + (tweedle[dume]{3}\s*)+ address@hidden verbatim + address@hidden +has matched @samp{tweedledum tweedledee} the value of the captured +substring is @samp{tweedledee}. However, if there are nested capturing +subpatterns, the corresponding captured values may have been set in +previous iterations. For example, after + address@hidden + (a|(b))+ address@hidden verbatim + address@hidden +matches @samp{aba} the value of the second captured substring is @samp{b}. + address@hidden Atomic Grouping and Possessive Quantifiers + +With both maximizing (@dfn{greedy}) and minimizing (@dfn{ungreedy} or address@hidden) repetition, failure of what follows normally causes the +repeated item to be re-evaluated to see if a different number of +repeats allows the rest of the pattern to match. Sometimes it is +useful to prevent this, either to change the nature of the match, or +to cause it fail earlier than it otherwise might, when the author of +the pattern knows there is no point in carrying on. + +Consider, for example, the pattern @samp{\d+foo} when applied to the +subject line + address@hidden + 123456bar address@hidden verbatim + +After matching all 6 digits and then failing to match @samp{foo}, the +normal action of the matcher is to try again with only 5 digits +matching the @samp{\d+} item, and then with 4, and so on, before +ultimately failing. @dfn{Atomic grouping} (a term taken from Jeffrey +Friedl's book) provides the means for specifying that once a +subpattern has matched, it is not to be re-evaluated in this way. + +If we use atomic grouping for the previous example, the matcher gives +up immediately on failing to match @samp{foo} the first time. The +notation is a kind of special parenthesis, starting with @samp{(?>} as in +this example: + address@hidden + (?>\d+)foo address@hidden verbatim + address@hidden +This kind of parenthesis ``locks up'' the part of the pattern it +contains once it has matched, and a failure further into the pattern +is prevented from backtracking into it. Backtracking past it to +previous items, however, works as normal. Atomic grouping subpatterns +are not capturing subpatterns. + +An alternative description is that a subpattern of this type matches +the string of characters that an identical standalone pattern would +match, if anchored at the current point in the subject string. + +Simple cases such as the above example can be thought of as a +maximizing repeat that must swallow everything it can. So, while both address@hidden and @samp{\d+?} are prepared to adjust the number of digits +they match in order to make the rest of the pattern match, address@hidden(?>\d+)} can only match an entire sequence of digits. + +Atomic groups in general can of course contain arbitrarily complicated +subpatterns, and can be nested. However, when the subpattern for an +atomic group is just a single repeated item, as in the example above, +a simpler notation, called a @dfn{possessive quantifier}, can be +used. This consists of an additional @samp{+} character following a +quantifier. Using this notation, the previous example can be rewritten +as + address@hidden + \d++foo address@hidden verbatim + address@hidden +Note that a possessive quantifier can be used with an entire group, for +example: + address@hidden + (abc|xyz){2,3}+ address@hidden verbatim + address@hidden +Possessive quantifiers are always greedy; the setting of the address@hidden(?U)} option is ignored. They are a convenient notation for the +simpler forms of atomic group. However, there is no difference in the +meaning of a possessive quantifier and the equivalent atomic group, +though there may be a performance difference; possessive quantifiers +should be slightly faster. + +The possessive quantifier syntax is an extension to the Perl 5.8 +syntax. Jeffrey Friedl originated the idea (and the name) in the +first edition of his book. Mike McCloskey liked it, so implemented it +when he built Sun's Java package, and PCRE copied it from there. It +ultimately found its way into Perl at release 5.10. + +PCRE has an optimization that automatically ``possessifies'' certain +simple pattern constructs. For example, the sequence @samp{A+B} is +treated as @samp{A++B} because there is no point in backtracking into +a sequence of @samp{A}s when @samp{B} must follow. + +When a pattern contains an unlimited repeat inside a subpattern that +can itself be repeated an unlimited number of times, the use of an +atomic group is the only way to avoid some failing matches taking a +very long time indeed. The pattern + address@hidden + (\D+|<\d+>)*[!?] address@hidden verbatim + address@hidden +matches an unlimited number of substrings that either consist of +non-digits, or digits enclosed in @samp{<>}, followed by either address@hidden or @samp{?}. When it matches, it runs quickly. However, if it +is applied to + address@hidden + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa address@hidden verbatim + address@hidden +it takes a long time before reporting failure. This is because the +string can be divided between the internal @samp{\D+} repeat and the +external @samp{*} repeat in a large number of ways, and all have to be +tried. (The example uses @samp{[!?]} rather than a single character at +the end, because both PCRE and Perl have an optimization that allows +for fast failure when a single character is used. They remember the +last single character that is required for a match, and fail early if +it is not present in the string.) If the pattern is changed so that it +uses an atomic group, like this: + address@hidden + ((?>\D+)|<\d+>)*[!?] address@hidden verbatim + address@hidden +sequences of non-digits cannot be broken, and failure happens quickly. + address@hidden Back References + +Outside a character class, a backslash followed by a digit greater +than 0 (and possibly further digits) is a back reference to a +capturing subpattern earlier (that is, to its left) in the pattern, +provided there have been that many previous capturing left +parentheses. + +However, if the decimal number following the backslash is less than +10, it is always taken as a back reference, and causes an error only +if there are not that many capturing left parentheses in the entire +pattern. In other words, the parentheses that are referenced need not +be to the left of the reference for numbers less than 10. A ``forward +back reference'' of this type can make sense when a repetition is +involved and the subpattern to the right has participated in an +earlier iteration. + +It is not possible to have a numerical ``forward back reference'' to a +subpattern whose number is 10 or more using this syntax because a +sequence such as @samp{\50} is interpreted as a character defined in +octal. See the subsection entitled ``Non-printing characters'' above +for further details of the handling of digits following a +backslash. There is no such problem when named parentheses are used. A +back reference to any subpattern is possible using named parentheses +(see below). + +Another way of avoiding the ambiguity inherent in the use of digits +following a backslash is to use the @samp{\g} escape sequence, which +is a feature introduced in Perl 5.10. This escape must be followed by +an unsigned number or a negative number, optionally enclosed in +braces. These examples are all identical: + address@hidden + (ring), \1 + (ring), \g1 + (ring), \g{1} address@hidden verbatim + +An unsigned number specifies an absolute reference without the +ambiguity that is present in the older syntax. It is also useful when +literal digits follow the reference. A negative number is a relative +reference. Consider this example: + address@hidden + (abc(def)ghi)\g{-1} address@hidden verbatim + address@hidden +The sequence @address@hidden@}} is a reference to the most recently +started capturing subpattern before @samp{\g}, that is, is it +equivalent to @samp{\2}. Similarly, @address@hidden@}} would be +equivalent to @samp{\1}. The use of relative references can be helpful +in long patterns, and also in patterns that are created by joining +together fragments that contain references within themselves. + +A back reference matches whatever actually matched the capturing +subpattern in the current subject string, rather than anything +matching the subpattern itself (see ``Subpatterns as subroutines'' below +for a way of doing that). So the pattern + address@hidden + (sens|respons)e and \1ibility address@hidden verbatim + address@hidden +matches @samp{sense and sensibility} and @samp{response and +responsibility}, but not @samp{sense and responsibility}. If caseful +matching is in force at the time of the back reference, the case of +letters is relevant. For example, + address@hidden + ((?i)rah)\s+\1 address@hidden verbatim + address@hidden +matches @samp{rah rah} and @samp{RAH RAH}, but not @samp{RAH rah}, +even though the original capturing subpattern is matched caselessly. + +There are several different ways of writing back references to named +subpatterns. The .NET syntax @address@hidden@}} and the Perl syntax address@hidden} or @samp{\k'name'} are supported, as is the Python +syntax (?P=name). Perl 5.10's unified back reference syntax, in which address@hidden can be used for both numeric and named references, is also +supported. We could rewrite the above example in any of the following +ways: + address@hidden + (?(?i)rah)\s+\k + (?'p1'(?i)rah)\s+\k{p1} + (?P(?i)rah)\s+(?P=p1) + (?(?i)rah)\s+\g{p1} address@hidden verbatim + address@hidden +A subpattern that is referenced by name may appear in the pattern +before or after the reference. + +There may be more than one back reference to the same subpattern. If a +subpattern has not actually been used in a particular match, any back +references to it always fail. For example, the pattern + address@hidden + (a|(bc))\2 address@hidden verbatim + address@hidden +always fails if it starts to match @samp{a} rather than address@hidden Because there may be many capturing parentheses in a +pattern, all digits following the backslash are taken as part of a +potential back reference number. If the pattern continues with a digit +character, some delimiter must be used to terminate the back +reference. If the @samp{(?x)} option is set, this can be whitespace. +Otherwise an empty comment (see ``Comments'' below) can be used. + +A back reference that occurs inside the parentheses to which it refers +fails when the subpattern is first used, so, for example, @samp{(a\1)} +never matches. However, such references can be useful inside repeated +subpatterns. For example, the pattern + address@hidden + (a|b\1)+ address@hidden verbatim + address@hidden +matches any number of @samp{a}s and also @samp{aba}, @samp{ababbaa} +etc. At each iteration of the subpattern, the back reference matches +the character string corresponding to the previous iteration. In order +for this to work, the pattern must be such that the first iteration +does not need to match the back reference. This can be done using +alternation, as in the example above, or by a quantifier with a +minimum of zero. + address@hidden Assertions + +An assertion is a test on the characters following or preceding the +current matching point that does not actually consume any +characters. The simple assertions coded as @samp{\b}, @samp{\B}, address@hidden, @samp{\G}, @samp{\Z}, @samp{\z}, @samp{^} and @samp{$} are +described above. + +More complicated assertions are coded as subpatterns. There are two +kinds: those that look ahead of the current position in the subject +string, and those that look behind it. An assertion subpattern is +matched in the normal way, except that it does not cause the current +matching position to be changed. + +Assertion subpatterns are not capturing subpatterns, and may not be +repeated, because it makes no sense to assert the same thing several +times. If any kind of assertion contains capturing subpatterns within +it, these are counted for the purposes of numbering the capturing +subpatterns in the whole pattern. However, substring capturing is +carried out only for positive assertions, because it does not make +sense for negative assertions. + address@hidden Lookahead Assertions + +Lookahead assertions start with @samp{(?=} for positive assertions and address@hidden(?!} for negative assertions. For example, + address@hidden + \w+(?=;) address@hidden verbatim + address@hidden +matches a word followed by a semicolon, but does not include the semicolon in +the match, and + address@hidden + foo(?!bar) address@hidden verbatim + address@hidden +matches any occurrence of @samp{foo} that is not followed by address@hidden Note that the apparently similar pattern + address@hidden + (?!foo)bar address@hidden verbatim + address@hidden +does not find an occurrence of @samp{bar} that is preceded by +something other than @samp{foo}; it finds any occurrence of @samp{bar} +whatsoever, because the assertion @samp{(?!foo)} is always true when +the next three characters are @samp{bar}. A lookbehind assertion is +needed to achieve the other effect. + +If you want to force a matching failure at some point in a pattern, +the most convenient way to do it is with @samp{(?!)} because an empty +string always matches, so an assertion that requires there not to be +an empty string must always fail. + address@hidden Lookbehind Assertions + +Lookbehind assertions start with @samp{(?<=} for positive assertions +and @samp{(?)...)} or @samp{(?('name')...)} to +test for a used subpattern by name. For compatibility with earlier +versions of PCRE, which had this facility before Perl, the syntax address@hidden(?(name)...)} is also recognized. However, there is a possible +ambiguity with this syntax, because subpattern names may consist +entirely of digits. PCRE looks first for a named subpattern; if it +cannot find one and the name consists entirely of digits, PCRE looks +for a subpattern of that number, which must be greater than +zero. Using subpattern names that consist entirely of digits is not +recommended. + +Rewriting the above example to use a named subpattern gives this: + address@hidden + (? \( )? [^()]+ (?() \) ) address@hidden verbatim + address@hidden Checking for pattern recursion + +If the condition is the string @samp{(R)}, and there is no subpattern +with the name @samp{R}, the condition is true if a recursive call to +the whole pattern or any subpattern has been made. If digits or a name +preceded by ampersand follow the letter @samp{R}, for example: + address@hidden + (?(R3)...) or (?(R&name)...) address@hidden verbatim + address@hidden +the condition is true if the most recent recursion is into the +subpattern whose number or name is given. This condition does not +check the entire recursion stack. + +At ``top level,'' all these recursion test conditions are false. Recursive +patterns are described below. + address@hidden Defining subpatterns for use by reference only + +If the condition is the string @samp{(DEFINE)}, and there is no +subpattern with the name @samp{DEFINE}, the condition is always +false. In this case, there may be only one alternative in the +subpattern. It is always skipped if control reaches this point in the +pattern; the idea of DEFINE is that it can be used to define address@hidden that can be referenced from elsewhere. (The use of +subroutines is described below.) For example, a pattern to match an +IPv4 address could be written like this (ignore whitespace and line +breaks): + address@hidden + (?(DEFINE) (? 2[0-4]\d | 25[0-5] | 1\d\d | [1-9]?\d) ) + \b (?&byte) (\.(?&byte)){3} \b address@hidden verbatim + +The first part of the pattern is a DEFINE group inside which a another +group named "byte" is defined. This matches an individual component of +an IPv4 address (a number less than 256). When matching takes place, +this part of the pattern is skipped because DEFINE acts like a false +condition. + +The rest of the pattern uses references to the named group to match +the four dot-separated components of an IPv4 address, insisting on a +word boundary at each end. + address@hidden Assertion conditions + +If the condition is not in any of the above formats, it must be an +assertion. This may be a positive or negative lookahead or lookbehind +assertion. Consider this pattern, again containing non-significant +white space, and with the two alternatives on the second line: + address@hidden + (?(?=[^a-z]*[a-z]) + \d{2}-[a-z]{3}-\d{2} | \d{2}-\d{2}-\d{2} ) address@hidden verbatim + +The condition is a positive lookahead assertion that matches an +optional sequence of non-letters followed by a letter. In other words, +it tests for the presence of at least one letter in the subject. If a +letter is found, the subject is matched against the first alternative; +otherwise it is matched against the second. This pattern matches +strings in one of the two forms @address@hidden@address@hidden or address@hidden@address@hidden@var{dd}}, where @var{aaa} are letters and address@hidden are digits. + address@hidden Comments + +The sequence @samp{(?#} marks the start of a comment that continues up +to the next closing parenthesis. Nested parentheses are not +permitted. The characters that make up a comment play no part in the +pattern matching at all. + +If the @samp{(?x)} option is set, an unescaped @samp{#} character +outside a character class introduces a comment that continues to +immediately after the next newline in the pattern. + address@hidden Recursive Patterns + +Consider the problem of matching a string in parentheses, allowing for +unlimited nested parentheses. Without the use of recursion, the best +that can be done is to use a pattern that matches up to some fixed +depth of nesting. It is not possible to handle an arbitrary nesting +depth. + +PCRE supports special syntax for recursion of the entire pattern, and +also for individual subpattern recursion. After its introduction in +PCRE and Python, this kind of recursion was introduced into Perl at +release 5.10. + +A special item that consists of @samp{(?} followed by a number greater +than zero and a closing parenthesis is a recursive call of the +subpattern of the given number, provided that it occurs inside that +subpattern. (If not, it is a subroutine call, which is described in +the next section.) The special item @samp{(?R)} or @samp{(?0)} is a +recursive call of the entire regular expression. + +In PCRE (like Python, but unlike Perl), a recursive subpattern call is +always treated as an atomic group. That is, once it has matched some +of the subject string, it is never re-entered, even if it contains +untried alternatives and there is a subsequent matching failure. + +This PCRE pattern solves the nested parentheses problem (whitespace is +insignificant): + address@hidden + \( ( (?>[^()]+) | (?R) )* \) address@hidden verbatim + +First it matches an opening parenthesis. Then it matches any number of +substrings which can either be a sequence of non-parentheses, or a +recursive match of the pattern itself (that is, a correctly +parenthesized substring). Finally there is a closing parenthesis. + +If this were part of a larger pattern, you would not want to recurse +the entire pattern, so instead you could use this: + address@hidden + ( \( ( (?>[^()]+) | (?1) )* \) ) address@hidden verbatim + address@hidden +We have put the pattern into parentheses, and caused the recursion to +refer to them instead of the whole pattern. + +In a larger pattern, keeping track of parenthesis numbers can be +tricky. This is made easier by the use of relative references. (A Perl +5.10 feature.) Instead of @samp{(?1)} in the pattern above you can +write @samp{(?-2)} to refer to the second most recently opened +parentheses preceding the recursion. In other words, a negative number +counts capturing parentheses leftwards from the point at which it is +encountered. + +It is also possible to refer to subsequently opened parentheses, by +writing references such as @samp{(?+2)}. However, these cannot be +recursive because the reference is not inside the parentheses that are +referenced. They are always subroutine calls, as described in the next +section. + +An alternative approach is to use named parentheses instead. The Perl +syntax for this is @samp{(?&name)}; PCRE's earlier syntax address@hidden(?P>name)} is also supported. We could rewrite the above example +as follows: + address@hidden + (? \( ( (?>[^()]+) | (?&pn) )* \) ) address@hidden verbatim + address@hidden +If there is more than one subpattern with the same name, the earliest +one is used. + +This particular example pattern that we have been looking at contains +nested unlimited repeats, and so the use of atomic grouping for +matching strings of non-parentheses is important when applying the +pattern to strings that do not match. For example, when this pattern +is applied to + address@hidden + (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() address@hidden verbatim + address@hidden +it fails quickly. However, if atomic grouping is not used, the match +runs for a very long time indeed because there are so many different +ways the @samp{+} and @samp{*} repeats can carve up the subject, and +all have to be tested before failure can be reported. + +At the end of a match, the values set for any capturing subpatterns +are those from the outermost level of the recursion at which the +subpattern value is set. If the pattern above is matched against + address@hidden + (ab(cd)ef) address@hidden verbatim + address@hidden +the value for the capturing parentheses is @samp{ef}, which is the +last value taken on at the top level. If additional parentheses are +added, giving + address@hidden + \( ( ( (?>[^()]+) | (?R) )* ) \) + ^ ^ address@hidden example + address@hidden +the string they capture is @samp{ab(cd)ef}, the contents of the top +level parentheses. + +Do not confuse the @samp{(?R)} item with the condition @samp{(?(R)}, +which tests for recursion. Consider this pattern, which matches text +in angle brackets, allowing for arbitrary nesting. Only digits are +allowed in nested brackets (that is, when recursing), whereas any +characters are permitted at the outer level. + address@hidden + < (?: (?(R) \d++ | [^<>]*+) | (?R)) * > address@hidden verbatim + address@hidden +In this pattern, @samp{(?(R)} is the start of a conditional +subpattern, with two different alternatives for the recursive and +non-recursive cases. The @samp{(?R)} item is the actual recursive +call. + address@hidden Subpatterns as Subroutines + +If the syntax for a recursive subpattern reference (either by number +or by name) is used outside the parentheses to which it refers, it +operates like a subroutine in a programming language. The called +subpattern may be defined before or after the reference. A numbered +reference can be absolute or relative, as in these examples: + address@hidden + (...(absolute)...)...(?2)... + (...(relative)...)...(?-1)... + (...(?+1)...(relative)... address@hidden verbatim + +An earlier example pointed out that the pattern + address@hidden + (sens|respons)e and \1ibility address@hidden verbatim + address@hidden +matches @samp{sense and sensibility} and @samp{response and +responsibility}, but not @samp{sense and responsibility}. If instead +the pattern + address@hidden + (sens|respons)e and (?1)ibility address@hidden verbatim + address@hidden +is used, it does match @samp{sense and responsibility} as well as the +other two strings. Another example is given in the discussion of +DEFINE above. + +Like recursive subpatterns, a subroutine call is always treated as an +atomic group. That is, once it has matched some of the subject string, +it is never re-entered, even if it contains untried alternatives and +there is a subsequent matching failure. + +When a subpattern is used as a subroutine, processing options such as +case-independence are fixed when the subpattern is defined. They +cannot be changed for different calls. For example, consider this +pattern: + address@hidden + (abc)(?i:(?-1)) address@hidden verbatim + +It matches @samp{abcabc}. It does not match @samp{abcABC} because the +change of processing option does not affect the called subpattern. + address@hidden Backtracking Control + +Perl 5.10 introduced a number of special @dfn{backtracking control +verbs}, which are described in the Perl documentation as +``experimental and subject to change or removal in a future version of +Perl.'' It goes on to say: ``Their usage in production code should be +noted to avoid problems during upgrades.'' The same remarks apply to +the PCRE features described in this section. + +The new verbs make use of what was previously invalid syntax: an +opening parenthesis followed by an asterisk. In Perl, they are +generally of the form @samp{(*VERB:ARG)} but PCRE does not support the +use of arguments, so its general form is just @samp{(*VERB)}. Any +number of these verbs may occur in a pattern. There are two kinds: + address@hidden Verbs that act immediately + +The following verbs act as soon as they are encountered: + address@hidden @code address@hidden (*ACCEPT) + +This verb causes the match to end successfully, skipping the remainder +of the pattern. When inside a recursion, only the innermost pattern is +ended immediately. PCRE differs from Perl in what happens if the address@hidden(*ACCEPT)} is inside capturing parentheses. In Perl, the data so +far is captured: in PCRE no data is captured. For example: + address@hidden + A(A|B(*ACCEPT)|C)D address@hidden verbatim + +This matches @samp{AB}, @samp{AAD}, or @samp{ACD}, but when it matches address@hidden, no data is captured. + address@hidden (*FAIL) @r{or} (*F) + +This verb causes the match to fail, forcing backtracking to occur. It +is equivalent to @samp{(?!)} but easier to read. It is not clear +whether there is any use for this without the ability to execute code +in the middle of the pattern (which Perl has but PCRE in Monotone does +not). address@hidden table + address@hidden Verbs that act after backtracking + +The following verbs do nothing when they are encountered. Matching +continues with what follows, but if there is no subsequent match, a +failure is forced. The verbs differ in exactly what kind of failure +occurs. + address@hidden @code address@hidden (*COMMIT) + +This verb causes the whole match to fail outright if the rest of the +pattern does not match. Even if the pattern is unanchored, no further +attempts to find a match by advancing the start point take place. Once address@hidden(*COMMIT)} has been passed, the regular expression engine is +committed to finding a match at the current starting point, or not at +all. For example: + address@hidden + a+(*COMMIT)b address@hidden verbatim + +This matches @samp{xxaab} but not @samp{aacaab}. It can be thought of +as a kind of dynamic anchor, or ``I've started, so I must finish.'' + address@hidden (*PRUNE) + +This verb causes the match to fail at the current position if the rest +of the pattern does not match. If the pattern is unanchored, the +normal ``bump-along'' advance to the next starting character then +happens. Backtracking can occur as usual to the left of address@hidden(*PRUNE)}, or when matching to the right of @code{(*PRUNE)}, but +if there is no match to the right, backtracking cannot cross address@hidden(*PRUNE)}. In simple cases, the use of @code{(*PRUNE)} is just +an alternative to an atomic group or possessive quantifier, but there +are some uses of @code{(*PRUNE)} that cannot be expressed in any other +way. + address@hidden (*SKIP) + +This verb is like @code{(*PRUNE)}, except that if the pattern is +unanchored, the "bumpalong" advance is not to the next character, but +to the position in the subject where @code{(*SKIP)} was +encountered. @code{(*SKIP)} signifies that whatever text was matched +leading up to it cannot be part of a successful match. Consider: + address@hidden + a+(*SKIP)b address@hidden verbatim + +If the subject is @samp{aaaac...}, after the first match attempt fails +(starting at the first character in the string), the starting point +skips on to start the next attempt at @samp{c}. Note that a possessive +quantifer does not have the same effect in this example; although it +would suppress backtracking during the first match attempt, the second +attempt would start at the second character instead of skipping on to address@hidden + address@hidden (*THEN) + +This verb causes a skip to the next alternation if the rest of the +pattern does not match. That is, it cancels pending backtracking, but +only within the current alternation. Its name comes from the +observation that it can be used for a pattern-based if-then-else +block: + address@hidden + ( COND1 (*THEN) FOO + | COND2 (*THEN) BAR + | COND3 (*THEN) BAZ ) ... address@hidden verbatim + +If the @samp{COND1} pattern matches, @samp{FOO} is tried (and possibly +further items after the end of the group if @samp{FOO} succeeds); on +failure the matcher skips to the second alternative and tries address@hidden, without backtracking into COND1. If @code{(*THEN)} is used +outside of any alternation, it acts exactly like @code{(*PRUNE)}. address@hidden table ============================================================ --- pcre/pcresyntax.texi a5c795d675697cc91f001cc242cb717e34bcbcac +++ pcre/pcresyntax.texi a5c795d675697cc91f001cc242cb717e34bcbcac @@ -0,0 +1,583 @@ address@hidden This file was hand-translated to Texinfo from the upstream PCRE address@hidden documentation file pcresyntax.3, whose copyright notice is: address@hidden address@hidden Author: Philip Hazel, University Computing Service address@hidden Cambridge CB2 3QH, England address@hidden Last updated: 21 September 2007 address@hidden Copyright (c) 1997-2007 University of Cambridge. address@hidden address@hidden Redistribution and use in source and binary forms, with or without address@hidden modification, are permitted provided that the following conditions are met: address@hidden address@hidden * Redistributions of source code must retain the above copyright notice, address@hidden this list of conditions and the following disclaimer. address@hidden address@hidden * Redistributions in binary form must reproduce the above copyright address@hidden notice, this list of conditions and the following disclaimer in the address@hidden documentation and/or other materials provided with the distribution. address@hidden address@hidden * Neither the name of the University of Cambridge nor the names of its address@hidden contributors may be used to endorse or promote products derived from address@hidden this software without specific prior written permission. address@hidden address@hidden THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" address@hidden AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE address@hidden IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE address@hidden ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE address@hidden LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR address@hidden CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF address@hidden SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS address@hidden INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN address@hidden CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) address@hidden ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE address@hidden POSSIBILITY OF SUCH DAMAGE. address@hidden address@hidden Apart from markup translation, all mention of callouts has been address@hidden removed, and a few confusing references to PCRE itself or to address@hidden specific programming environments have been removed or clarified. + address@hidden Regexp Summary address@hidden Regexp Syntax Summary + +This is a quick-reference summary of the regular expression syntax +used in Monotone. + address@hidden Quoting + address@hidden @code address@hidden address@hidden + where @var{x} is non-alphanumeric is a literal @var{x} address@hidden \Q...\E + treat enclosed characters as literal address@hidden table + address@hidden Characters + address@hidden @code address@hidden \a + alarm, that is, the BEL character (hex 07) address@hidden address@hidden + address@hidden'', where @var{x} is any character address@hidden \e + escape (hex 1B) address@hidden \f + formfeed (hex 0C) address@hidden \n + newline (hex 0A) address@hidden \r + carriage return (hex 0D) address@hidden \t + tab (hex 09) address@hidden address@hidden + character with octal code @var{ddd}, or backreference address@hidden address@hidden + character with hex code @var{hh} address@hidden address@hidden@address@hidden + character with hex code @var{hhh...} address@hidden table + address@hidden Character Types + address@hidden @code address@hidden . + any character except newline; + in dotall mode, any character whatsoever address@hidden \C + one byte, even in UTF-8 mode (best avoided) address@hidden \d + a decimal digit address@hidden \D + a character that is not a decimal digit address@hidden \h + a horizontal whitespace character address@hidden \H + a character that is not a horizontal whitespace character address@hidden address@hidden@address@hidden + a character with the @var{xx} property address@hidden address@hidden@address@hidden + a character without the @var{xx} property address@hidden \R + a newline sequence address@hidden \s + a whitespace character address@hidden \S + a character that is not a whitespace character address@hidden \v + a vertical whitespace character address@hidden \V + a character that is not a vertical whitespace character address@hidden \w + a ``word'' character address@hidden \W + a ``non-word'' character address@hidden \X + an extended Unicode sequence address@hidden table + address@hidden address@hidden, @samp{\D}, @samp{\s}, @samp{\S}, @samp{\w}, and @samp{\W} +recognize only ASCII characters. + address@hidden General category property codes for @samp{\p} and @samp{\P} + address@hidden @code address@hidden C + Other address@hidden Cc + Control address@hidden Cf + Format address@hidden Cn + Unassigned address@hidden Co + Private use address@hidden Cs + Surrogate + address@hidden L + Letter address@hidden Ll + Lower case letter address@hidden Lm + Modifier letter address@hidden Lo + Other letter address@hidden Lt + Title case letter address@hidden Lu + Upper case letter address@hidden L& + Ll, Lu, or Lt + address@hidden M + Mark address@hidden Mc + Spacing mark address@hidden Me + Enclosing mark address@hidden Mn + Non-spacing mark + address@hidden N + Number address@hidden Nd + Decimal number address@hidden Nl + Letter number address@hidden No + Other number + address@hidden P + Punctuation address@hidden Pc + Connector punctuation address@hidden Pd + Dash punctuation address@hidden Pe + Close punctuation address@hidden Pf + Final punctuation address@hidden Pi + Initial punctuation address@hidden Po + Other punctuation address@hidden Ps + Open punctuation + address@hidden S + Symbol address@hidden Sc + Currency symbol address@hidden Sk + Modifier symbol address@hidden Sm + Mathematical symbol address@hidden So + Other symbol + address@hidden Z + Separator address@hidden Zl + Line separator address@hidden Zp + Paragraph separator address@hidden Zs + Space separator address@hidden table + address@hidden Script names for @samp{\p} and @samp{\P} + +Arabic, +Armenian, +Balinese, +Bengali, +Bopomofo, +Braille, +Buginese, +Buhid, +Canadian_Aboriginal, +Cherokee, +Common, +Coptic, +Cuneiform, +Cypriot, +Cyrillic, +Deseret, +Devanagari, +Ethiopic, +Georgian, +Glagolitic, +Gothic, +Greek, +Gujarati, +Gurmukhi, +Han, +Hangul, +Hanunoo, +Hebrew, +Hiragana, +Inherited, +Kannada, +Katakana, +Kharoshthi, +Khmer, +Lao, +Latin, +Limbu, +Linear_B, +Malayalam, +Mongolian, +Myanmar, +New_Tai_Lue, +Nko, +Ogham, +Old_Italic, +Old_Persian, +Oriya, +Osmanya, +Phags_Pa, +Phoenician, +Runic, +Shavian, +Sinhala, +Syloti_Nagri, +Syriac, +Tagalog, +Tagbanwa, +Tai_Le, +Tamil, +Telugu, +Thaana, +Thai, +Tibetan, +Tifinagh, +Ugaritic, +Yi. + address@hidden Character Classes + address@hidden @code address@hidden [...] + positive character class address@hidden [^...] + negative character class address@hidden address@hidden@var{y}] + range (can be used for hex characters) address@hidden [[:@var{xxx}:]] + positive POSIX named set address@hidden [[^:@var{xxx}:]] + negative POSIX named set + address@hidden alnum + alphanumeric address@hidden alpha + alphabetic address@hidden ascii + 0-127 address@hidden blank + space or tab address@hidden cntrl + control character address@hidden digit + decimal digit address@hidden graph + printing, excluding space address@hidden lower + lower case letter address@hidden print + printing, including space address@hidden punct + printing, excluding alphanumeric address@hidden space + whitespace address@hidden upper + upper case letter address@hidden word + same as @samp{\w} address@hidden xdigit + hexadecimal digit address@hidden table + +In PCRE, POSIX character set names recognize only ASCII +characters. You can use @samp{\Q...\E} inside a character class. + address@hidden Quantifiers + address@hidden @code address@hidden ? + 0 or 1, greedy address@hidden ?+ + 0 or 1, possessive address@hidden ?? + 0 or 1, lazy address@hidden * + 0 or more, greedy address@hidden *+ + 0 or more, possessive address@hidden *? + 0 or more, lazy address@hidden + + 1 or more, greedy address@hidden ++ + 1 or more, possessive address@hidden +? + 1 or more, lazy address@hidden @address@hidden@} + exactly @var{n} address@hidden @address@hidden,@address@hidden + at least @var{n}, no more than @var{m}, greedy address@hidden @address@hidden,@address@hidden + at least @var{n}, no more than @var{m}, possessive address@hidden @address@hidden,@address@hidden + at least @var{n}, no more than @var{m}, lazy address@hidden @address@hidden,@} + @var{n} or more, greedy address@hidden @address@hidden,@}+ + @var{n} or more, possessive address@hidden @address@hidden,@}? + @var{n} or more, lazy address@hidden table + address@hidden Anchors and Simple Assertions + address@hidden @code address@hidden \b + word boundary address@hidden \B + not a word boundary address@hidden ^ + start of subject + also after internal newline in multiline mode address@hidden \A + start of subject address@hidden $ + end of subject + also before newline at end of subject + also before internal newline in multiline mode address@hidden \Z + end of subject + also before newline at end of subject address@hidden \z + end of subject address@hidden \G + first matching position in subject address@hidden table + address@hidden Match Point Reset + address@hidden @code address@hidden \K + reset start of match address@hidden table + address@hidden Alternation + address@hidden @code address@hidden @var{expr}|@var{expr}|@var{expr}... address@hidden table + address@hidden Capturing + address@hidden @code address@hidden (...) + capturing group address@hidden (?<@var{name}>...) + named capturing group (like Perl) address@hidden (?'@var{name}'...) + named capturing group (like Perl) address@hidden (?P<@var{name}>...) + named capturing group (like Python) address@hidden (?:...) + non-capturing group address@hidden (?|...) + non-capturing group; reset group numbers for + capturing groups in each alternative address@hidden table + address@hidden Atomic Groups + address@hidden @code address@hidden (?>...) + atomic, non-capturing group address@hidden table + address@hidden Comment + address@hidden @code address@hidden (?#....) + comment (not nestable) address@hidden table + address@hidden Option Setting + address@hidden @code address@hidden (?i) + caseless address@hidden (?J) + allow duplicate names address@hidden (?m) + multiline address@hidden (?s) + single line (dotall) address@hidden (?U) + default ungreedy (lazy) address@hidden (?x) + extended (ignore white space) address@hidden (?-...) + unset option(s) address@hidden table + address@hidden Lookahead and Lookbehind Assertions + address@hidden @code address@hidden (?=...) + positive look ahead address@hidden (?!...) + negative look ahead address@hidden (?<=...) + positive look behind address@hidden (? + reference by name (like Perl) address@hidden \k'@var{name}' + reference by name (like Perl) address@hidden address@hidden@address@hidden + reference by name (like Perl) address@hidden address@hidden@address@hidden + reference by name (like .NET) address@hidden (address@hidden) + reference by name (like Python) address@hidden table + address@hidden Subroutine References (possibly recursive) + address@hidden @code address@hidden (?R) + recurse whole pattern address@hidden (address@hidden) + call subpattern by absolute number address@hidden (address@hidden) + call subpattern by relative number address@hidden (address@hidden) + call subpattern by relative number address@hidden (?&@var{name}) + call subpattern by name (like Perl) address@hidden (?P>@var{name}) + call subpattern by name (like Python) address@hidden table + address@hidden Conditional Patterns + address@hidden @code address@hidden (?(@var{condition})@var{yes-pattern}) address@hidden (?(@var{condition})@var{yes-pattern}|@var{no-pattern}) + address@hidden (?(@var{n})... + absolute reference condition address@hidden (?(address@hidden)... + relative reference condition address@hidden (?(address@hidden)... + relative reference condition address@hidden (?(<@var{name}>)... + named reference condition (like Perl) address@hidden (?('@var{name}')... + named reference condition (like Perl) address@hidden (?(@var{name})... + named reference condition (PCRE only) address@hidden (?(R)... + overall recursion condition address@hidden (?(address@hidden)... + specific group recursion condition address@hidden (?(R&@var{name})... + specific recursion condition address@hidden (?(DEFINE)... + define subpattern for reference address@hidden (?(assert)... + assertion condition address@hidden table + address@hidden Backtracking Control + +The following act immediately they are reached: + address@hidden @code address@hidden (*ACCEPT) + force successful match address@hidden (*FAIL) + force backtrack; synonym @samp{(*F)} address@hidden table + +The following act only when a subsequent match failure causes a backtrack to +reach them. They all force a match failure, but they differ in what happens +afterwards. Those that advance the start-of-match point do so only if the +pattern is not anchored. + address@hidden @code address@hidden (*COMMIT) + overall failure, no advance of starting point address@hidden (*PRUNE) + advance to next starting character address@hidden (*SKIP) + advance start to current matching position address@hidden (*THEN) + local failure, backtrack to next alternation address@hidden table + address@hidden Newline Conventions + +These are recognized only at the very start of the pattern or after a address@hidden(*BSR_...)} option. + address@hidden @code address@hidden (*CR) address@hidden (*LF) address@hidden (*CRLF) address@hidden (*ANYCRLF) address@hidden (*ANY) address@hidden table + address@hidden What @samp{\R} Matches + +These are recognized only at the very start of the pattern or after a address@hidden(*...)} option that sets the newline convention. + address@hidden @code address@hidden (*BSR_ANYCRLF) address@hidden (*BSR_UNICODE) address@hidden table ============================================================ --- pcre/ucp.h 858221df2d7d0d08b5b88749f94746bb77d2d472 +++ pcre/ucp.h 858221df2d7d0d08b5b88749f94746bb77d2d472 @@ -0,0 +1,133 @@ +/************************************************* +* Unicode Property Table handler * +*************************************************/ + +#ifndef _UCP_H +#define _UCP_H + +/* This file contains definitions of the property values that are returned by +the function _pcre_ucp_findprop(). New values that are added for new releases +of Unicode should always be at the end of each enum, for backwards +compatibility. */ + +/* These are the general character categories. */ + +enum { + ucp_C, /* Other */ + ucp_L, /* Letter */ + ucp_M, /* Mark */ + ucp_N, /* Number */ + ucp_P, /* Punctuation */ + ucp_S, /* Symbol */ + ucp_Z /* Separator */ +}; + +/* These are the particular character types. */ + +enum { + ucp_Cc, /* Control */ + ucp_Cf, /* Format */ + ucp_Cn, /* Unassigned */ + ucp_Co, /* Private use */ + ucp_Cs, /* Surrogate */ + ucp_Ll, /* Lower case letter */ + ucp_Lm, /* Modifier letter */ + ucp_Lo, /* Other letter */ + ucp_Lt, /* Title case letter */ + ucp_Lu, /* Upper case letter */ + ucp_Mc, /* Spacing mark */ + ucp_Me, /* Enclosing mark */ + ucp_Mn, /* Non-spacing mark */ + ucp_Nd, /* Decimal number */ + ucp_Nl, /* Letter number */ + ucp_No, /* Other number */ + ucp_Pc, /* Connector punctuation */ + ucp_Pd, /* Dash punctuation */ + ucp_Pe, /* Close punctuation */ + ucp_Pf, /* Final punctuation */ + ucp_Pi, /* Initial punctuation */ + ucp_Po, /* Other punctuation */ + ucp_Ps, /* Open punctuation */ + ucp_Sc, /* Currency symbol */ + ucp_Sk, /* Modifier symbol */ + ucp_Sm, /* Mathematical symbol */ + ucp_So, /* Other symbol */ + ucp_Zl, /* Line separator */ + ucp_Zp, /* Paragraph separator */ + ucp_Zs /* Space separator */ +}; + +/* These are the script identifications. */ + +enum { + ucp_Arabic, + ucp_Armenian, + ucp_Bengali, + ucp_Bopomofo, + ucp_Braille, + ucp_Buginese, + ucp_Buhid, + ucp_Canadian_Aboriginal, + ucp_Cherokee, + ucp_Common, + ucp_Coptic, + ucp_Cypriot, + ucp_Cyrillic, + ucp_Deseret, + ucp_Devanagari, + ucp_Ethiopic, + ucp_Georgian, + ucp_Glagolitic, + ucp_Gothic, + ucp_Greek, + ucp_Gujarati, + ucp_Gurmukhi, + ucp_Han, + ucp_Hangul, + ucp_Hanunoo, + ucp_Hebrew, + ucp_Hiragana, + ucp_Inherited, + ucp_Kannada, + ucp_Katakana, + ucp_Kharoshthi, + ucp_Khmer, + ucp_Lao, + ucp_Latin, + ucp_Limbu, + ucp_Linear_B, + ucp_Malayalam, + ucp_Mongolian, + ucp_Myanmar, + ucp_New_Tai_Lue, + ucp_Ogham, + ucp_Old_Italic, + ucp_Old_Persian, + ucp_Oriya, + ucp_Osmanya, + ucp_Runic, + ucp_Shavian, + ucp_Sinhala, + ucp_Syloti_Nagri, + ucp_Syriac, + ucp_Tagalog, + ucp_Tagbanwa, + ucp_Tai_Le, + ucp_Tamil, + ucp_Telugu, + ucp_Thaana, + ucp_Thai, + ucp_Tibetan, + ucp_Tifinagh, + ucp_Ugaritic, + ucp_Yi, + ucp_Balinese, /* New for Unicode 5.0.0 */ + ucp_Cuneiform, /* New for Unicode 5.0.0 */ + ucp_Nko, /* New for Unicode 5.0.0 */ + ucp_Phags_Pa, /* New for Unicode 5.0.0 */ + ucp_Phoenician /* New for Unicode 5.0.0 */ +}; + +#endif + +/* End of ucp.h */ ============================================================ --- pcre/ucpinternal.h 56fe522a5a3d12d4736430a563d22abb8864050f +++ pcre/ucpinternal.h 56fe522a5a3d12d4736430a563d22abb8864050f @@ -0,0 +1,92 @@ +/************************************************* +* Unicode Property Table handler * +*************************************************/ + +#ifndef _UCPINTERNAL_H +#define _UCPINTERNAL_H + +/* Internal header file defining the layout of the bits in each pair of 32-bit +words that form a data item in the table. */ + +typedef struct cnode { + pcre_uint32 f0; + pcre_uint32 f1; +} cnode; + +/* Things for the f0 field */ + +#define f0_scriptmask 0xff000000 /* Mask for script field */ +#define f0_scriptshift 24 /* Shift for script value */ +#define f0_rangeflag 0x00f00000 /* Flag for a range item */ +#define f0_charmask 0x001fffff /* Mask for code point value */ + +/* Things for the f1 field */ + +#define f1_typemask 0xfc000000 /* Mask for char type field */ +#define f1_typeshift 26 /* Shift for the type field */ +#define f1_rangemask 0x0000ffff /* Mask for a range offset */ +#define f1_casemask 0x0000ffff /* Mask for a case offset */ +#define f1_caseneg 0xffff8000 /* Bits for negation */ + +/* The data consists of a vector of structures of type cnode. The two unsigned +32-bit integers are used as follows: + +(f0) (1) The most significant byte holds the script number. The numbers are + defined by the enum in ucp.h. + + (2) The 0x00800000 bit is set if this entry defines a range of characters. + It is not set if this entry defines a single character + + (3) The 0x00600000 bits are spare. + + (4) The 0x001fffff bits contain the code point. No Unicode code point will + ever be greater than 0x0010ffff, so this should be OK for ever. + +(f1) (1) The 0xfc000000 bits contain the character type number. The numbers are + defined by an enum in ucp.h. + + (2) The 0x03ff0000 bits are spare. + + (3) The 0x0000ffff bits contain EITHER the unsigned offset to the top of + range if this entry defines a range, OR the *signed* offset to the + character's "other case" partner if this entry defines a single + character. There is no partner if the value is zero. + +------------------------------------------------------------------------------- +| script (8) |.|.|.| codepoint (21) || type (6) |.|.| spare (8) | offset (16) | +------------------------------------------------------------------------------- + | | | | | + | | |-> spare | |-> spare + | | | + | |-> spare |-> spare + | + |-> range flag + +The upper/lower casing information is set only for characters that come in +pairs. The non-one-to-one mappings in the Unicode data are ignored. + +When searching the data, proceed as follows: + +(1) Set up for a binary chop search. + +(2) If the top is not greater than the bottom, the character is not in the + table. Its type must therefore be "Cn" ("Undefined"). + +(3) Find the middle vector element. + +(4) Extract the code point and compare. If equal, we are done. + +(5) If the test character is smaller, set the top to the current point, and + goto (2). + +(6) If the current entry defines a range, compute the last character by adding + the offset, and see if the test character is within the range. If it is, + we are done. + +(7) Otherwise, set the bottom to one element past the current point and goto + (2). +*/ + +#endif /* _UCPINTERNAL_H */ + +/* End of ucpinternal.h */ ============================================================ --- pcre/ucptable.h 665475a65598de16193f595e4ec78d84b9059662 +++ pcre/ucptable.h 665475a65598de16193f595e4ec78d84b9059662 @@ -0,0 +1,3068 @@ +/* This source module is automatically generated from the Unicode +property table. See ucpinternal.h for a description of the layout. +This version was made from the Unicode 5.0.0 tables. */ + +static const cnode ucp_table[] = { + { 0x09800000, 0x0000001f }, + { 0x09000020, 0x74000000 }, + { 0x09800021, 0x54000002 }, + { 0x09000024, 0x5c000000 }, + { 0x09800025, 0x54000002 }, + { 0x09000028, 0x58000000 }, + { 0x09000029, 0x48000000 }, + { 0x0900002a, 0x54000000 }, + { 0x0900002b, 0x64000000 }, + { 0x0900002c, 0x54000000 }, + { 0x0900002d, 0x44000000 }, + { 0x0980002e, 0x54000001 }, + { 0x09800030, 0x34000009 }, + { 0x0980003a, 0x54000001 }, + { 0x0980003c, 0x64000002 }, + { 0x0980003f, 0x54000001 }, + { 0x21000041, 0x24000020 }, + { 0x21000042, 0x24000020 }, + { 0x21000043, 0x24000020 }, + { 0x21000044, 0x24000020 }, + { 0x21000045, 0x24000020 }, + { 0x21000046, 0x24000020 }, + { 0x21000047, 0x24000020 }, + { 0x21000048, 0x24000020 }, + { 0x21000049, 0x24000020 }, + { 0x2100004a, 0x24000020 }, + { 0x2100004b, 0x24000020 }, + { 0x2100004c, 0x24000020 }, + { 0x2100004d, 0x24000020 }, + { 0x2100004e, 0x24000020 }, + { 0x2100004f, 0x24000020 }, + { 0x21000050, 0x24000020 }, + { 0x21000051, 0x24000020 }, + { 0x21000052, 0x24000020 }, + { 0x21000053, 0x24000020 }, + { 0x21000054, 0x24000020 }, + { 0x21000055, 0x24000020 }, + { 0x21000056, 0x24000020 }, + { 0x21000057, 0x24000020 }, + { 0x21000058, 0x24000020 }, + { 0x21000059, 0x24000020 }, + { 0x2100005a, 0x24000020 }, + { 0x0900005b, 0x58000000 }, + { 0x0900005c, 0x54000000 }, + { 0x0900005d, 0x48000000 }, + { 0x0900005e, 0x60000000 }, + { 0x0900005f, 0x40000000 }, + { 0x09000060, 0x60000000 }, + { 0x21000061, 0x1400ffe0 }, + { 0x21000062, 0x1400ffe0 }, + { 0x21000063, 0x1400ffe0 }, + { 0x21000064, 0x1400ffe0 }, + { 0x21000065, 0x1400ffe0 }, + { 0x21000066, 0x1400ffe0 }, + { 0x21000067, 0x1400ffe0 }, + { 0x21000068, 0x1400ffe0 }, + { 0x21000069, 0x1400ffe0 }, + { 0x2100006a, 0x1400ffe0 }, + { 0x2100006b, 0x1400ffe0 }, + { 0x2100006c, 0x1400ffe0 }, + { 0x2100006d, 0x1400ffe0 }, + { 0x2100006e, 0x1400ffe0 }, + { 0x2100006f, 0x1400ffe0 }, + { 0x21000070, 0x1400ffe0 }, + { 0x21000071, 0x1400ffe0 }, + { 0x21000072, 0x1400ffe0 }, + { 0x21000073, 0x1400ffe0 }, + { 0x21000074, 0x1400ffe0 }, + { 0x21000075, 0x1400ffe0 }, + { 0x21000076, 0x1400ffe0 }, + { 0x21000077, 0x1400ffe0 }, + { 0x21000078, 0x1400ffe0 }, + { 0x21000079, 0x1400ffe0 }, + { 0x2100007a, 0x1400ffe0 }, + { 0x0900007b, 0x58000000 }, + { 0x0900007c, 0x64000000 }, + { 0x0900007d, 0x48000000 }, + { 0x0900007e, 0x64000000 }, + { 0x0980007f, 0x00000020 }, + { 0x090000a0, 0x74000000 }, + { 0x090000a1, 0x54000000 }, + { 0x098000a2, 0x5c000003 }, + { 0x098000a6, 0x68000001 }, + { 0x090000a8, 0x60000000 }, + { 0x090000a9, 0x68000000 }, + { 0x210000aa, 0x14000000 }, + { 0x090000ab, 0x50000000 }, + { 0x090000ac, 0x64000000 }, + { 0x090000ad, 0x04000000 }, + { 0x090000ae, 0x68000000 }, + { 0x090000af, 0x60000000 }, + { 0x090000b0, 0x68000000 }, + { 0x090000b1, 0x64000000 }, + { 0x098000b2, 0x3c000001 }, + { 0x090000b4, 0x60000000 }, + { 0x090000b5, 0x140002e7 }, + { 0x090000b6, 0x68000000 }, + { 0x090000b7, 0x54000000 }, + { 0x090000b8, 0x60000000 }, + { 0x090000b9, 0x3c000000 }, + { 0x210000ba, 0x14000000 }, + { 0x090000bb, 0x4c000000 }, + { 0x098000bc, 0x3c000002 }, + { 0x090000bf, 0x54000000 }, + { 0x210000c0, 0x24000020 }, + { 0x210000c1, 0x24000020 }, + { 0x210000c2, 0x24000020 }, + { 0x210000c3, 0x24000020 }, + { 0x210000c4, 0x24000020 }, + { 0x210000c5, 0x24000020 }, + { 0x210000c6, 0x24000020 }, + { 0x210000c7, 0x24000020 }, + { 0x210000c8, 0x24000020 }, + { 0x210000c9, 0x24000020 }, + { 0x210000ca, 0x24000020 }, + { 0x210000cb, 0x24000020 }, + { 0x210000cc, 0x24000020 }, + { 0x210000cd, 0x24000020 }, + { 0x210000ce, 0x24000020 }, + { 0x210000cf, 0x24000020 }, + { 0x210000d0, 0x24000020 }, + { 0x210000d1, 0x24000020 }, + { 0x210000d2, 0x24000020 }, + { 0x210000d3, 0x24000020 }, + { 0x210000d4, 0x24000020 }, + { 0x210000d5, 0x24000020 }, + { 0x210000d6, 0x24000020 }, + { 0x090000d7, 0x64000000 }, + { 0x210000d8, 0x24000020 }, + { 0x210000d9, 0x24000020 }, + { 0x210000da, 0x24000020 }, + { 0x210000db, 0x24000020 }, + { 0x210000dc, 0x24000020 }, + { 0x210000dd, 0x24000020 }, + { 0x210000de, 0x24000020 }, + { 0x210000df, 0x14000000 }, + { 0x210000e0, 0x1400ffe0 }, + { 0x210000e1, 0x1400ffe0 }, + { 0x210000e2, 0x1400ffe0 }, + { 0x210000e3, 0x1400ffe0 }, + { 0x210000e4, 0x1400ffe0 }, + { 0x210000e5, 0x1400ffe0 }, + { 0x210000e6, 0x1400ffe0 }, + { 0x210000e7, 0x1400ffe0 }, + { 0x210000e8, 0x1400ffe0 }, + { 0x210000e9, 0x1400ffe0 }, + { 0x210000ea, 0x1400ffe0 }, + { 0x210000eb, 0x1400ffe0 }, + { 0x210000ec, 0x1400ffe0 }, + { 0x210000ed, 0x1400ffe0 }, + { 0x210000ee, 0x1400ffe0 }, + { 0x210000ef, 0x1400ffe0 }, + { 0x210000f0, 0x1400ffe0 }, + { 0x210000f1, 0x1400ffe0 }, + { 0x210000f2, 0x1400ffe0 }, + { 0x210000f3, 0x1400ffe0 }, + { 0x210000f4, 0x1400ffe0 }, + { 0x210000f5, 0x1400ffe0 }, + { 0x210000f6, 0x1400ffe0 }, + { 0x090000f7, 0x64000000 }, + { 0x210000f8, 0x1400ffe0 }, + { 0x210000f9, 0x1400ffe0 }, + { 0x210000fa, 0x1400ffe0 }, + { 0x210000fb, 0x1400ffe0 }, + { 0x210000fc, 0x1400ffe0 }, + { 0x210000fd, 0x1400ffe0 }, + { 0x210000fe, 0x1400ffe0 }, + { 0x210000ff, 0x14000079 }, + { 0x21000100, 0x24000001 }, + { 0x21000101, 0x1400ffff }, + { 0x21000102, 0x24000001 }, + { 0x21000103, 0x1400ffff }, + { 0x21000104, 0x24000001 }, + { 0x21000105, 0x1400ffff }, + { 0x21000106, 0x24000001 }, + { 0x21000107, 0x1400ffff }, + { 0x21000108, 0x24000001 }, + { 0x21000109, 0x1400ffff }, + { 0x2100010a, 0x24000001 }, + { 0x2100010b, 0x1400ffff }, + { 0x2100010c, 0x24000001 }, + { 0x2100010d, 0x1400ffff }, + { 0x2100010e, 0x24000001 }, + { 0x2100010f, 0x1400ffff }, + { 0x21000110, 0x24000001 }, + { 0x21000111, 0x1400ffff }, + { 0x21000112, 0x24000001 }, + { 0x21000113, 0x1400ffff }, + { 0x21000114, 0x24000001 }, + { 0x21000115, 0x1400ffff }, + { 0x21000116, 0x24000001 }, + { 0x21000117, 0x1400ffff }, + { 0x21000118, 0x24000001 }, + { 0x21000119, 0x1400ffff }, + { 0x2100011a, 0x24000001 }, + { 0x2100011b, 0x1400ffff }, + { 0x2100011c, 0x24000001 }, + { 0x2100011d, 0x1400ffff }, + { 0x2100011e, 0x24000001 }, + { 0x2100011f, 0x1400ffff }, + { 0x21000120, 0x24000001 }, + { 0x21000121, 0x1400ffff }, + { 0x21000122, 0x24000001 }, + { 0x21000123, 0x1400ffff }, + { 0x21000124, 0x24000001 }, + { 0x21000125, 0x1400ffff }, + { 0x21000126, 0x24000001 }, + { 0x21000127, 0x1400ffff }, + { 0x21000128, 0x24000001 }, + { 0x21000129, 0x1400ffff }, + { 0x2100012a, 0x24000001 }, + { 0x2100012b, 0x1400ffff }, + { 0x2100012c, 0x24000001 }, + { 0x2100012d, 0x1400ffff }, + { 0x2100012e, 0x24000001 }, + { 0x2100012f, 0x1400ffff }, + { 0x21000130, 0x2400ff39 }, + { 0x21000131, 0x1400ff18 }, + { 0x21000132, 0x24000001 }, + { 0x21000133, 0x1400ffff }, + { 0x21000134, 0x24000001 }, + { 0x21000135, 0x1400ffff }, + { 0x21000136, 0x24000001 }, + { 0x21000137, 0x1400ffff }, + { 0x21000138, 0x14000000 }, + { 0x21000139, 0x24000001 }, + { 0x2100013a, 0x1400ffff }, + { 0x2100013b, 0x24000001 }, + { 0x2100013c, 0x1400ffff }, + { 0x2100013d, 0x24000001 }, + { 0x2100013e, 0x1400ffff }, + { 0x2100013f, 0x24000001 }, + { 0x21000140, 0x1400ffff }, + { 0x21000141, 0x24000001 }, + { 0x21000142, 0x1400ffff }, + { 0x21000143, 0x24000001 }, + { 0x21000144, 0x1400ffff }, + { 0x21000145, 0x24000001 }, + { 0x21000146, 0x1400ffff }, + { 0x21000147, 0x24000001 }, + { 0x21000148, 0x1400ffff }, + { 0x21000149, 0x14000000 }, + { 0x2100014a, 0x24000001 }, + { 0x2100014b, 0x1400ffff }, + { 0x2100014c, 0x24000001 }, + { 0x2100014d, 0x1400ffff }, + { 0x2100014e, 0x24000001 }, + { 0x2100014f, 0x1400ffff }, + { 0x21000150, 0x24000001 }, + { 0x21000151, 0x1400ffff }, + { 0x21000152, 0x24000001 }, + { 0x21000153, 0x1400ffff }, + { 0x21000154, 0x24000001 }, + { 0x21000155, 0x1400ffff }, + { 0x21000156, 0x24000001 }, + { 0x21000157, 0x1400ffff }, + { 0x21000158, 0x24000001 }, + { 0x21000159, 0x1400ffff }, + { 0x2100015a, 0x24000001 }, + { 0x2100015b, 0x1400ffff }, + { 0x2100015c, 0x24000001 }, + { 0x2100015d, 0x1400ffff }, + { 0x2100015e, 0x24000001 }, + { 0x2100015f, 0x1400ffff }, + { 0x21000160, 0x24000001 }, + { 0x21000161, 0x1400ffff }, + { 0x21000162, 0x24000001 }, + { 0x21000163, 0x1400ffff }, + { 0x21000164, 0x24000001 }, + { 0x21000165, 0x1400ffff }, + { 0x21000166, 0x24000001 }, + { 0x21000167, 0x1400ffff }, + { 0x21000168, 0x24000001 }, + { 0x21000169, 0x1400ffff }, + { 0x2100016a, 0x24000001 }, + { 0x2100016b, 0x1400ffff }, + { 0x2100016c, 0x24000001 }, + { 0x2100016d, 0x1400ffff }, + { 0x2100016e, 0x24000001 }, + { 0x2100016f, 0x1400ffff }, + { 0x21000170, 0x24000001 }, + { 0x21000171, 0x1400ffff }, + { 0x21000172, 0x24000001 }, + { 0x21000173, 0x1400ffff }, + { 0x21000174, 0x24000001 }, + { 0x21000175, 0x1400ffff }, + { 0x21000176, 0x24000001 }, + { 0x21000177, 0x1400ffff }, + { 0x21000178, 0x2400ff87 }, + { 0x21000179, 0x24000001 }, + { 0x2100017a, 0x1400ffff }, + { 0x2100017b, 0x24000001 }, + { 0x2100017c, 0x1400ffff }, + { 0x2100017d, 0x24000001 }, + { 0x2100017e, 0x1400ffff }, + { 0x2100017f, 0x1400fed4 }, + { 0x21000180, 0x140000c3 }, + { 0x21000181, 0x240000d2 }, + { 0x21000182, 0x24000001 }, + { 0x21000183, 0x1400ffff }, + { 0x21000184, 0x24000001 }, + { 0x21000185, 0x1400ffff }, + { 0x21000186, 0x240000ce }, + { 0x21000187, 0x24000001 }, + { 0x21000188, 0x1400ffff }, + { 0x21000189, 0x240000cd }, + { 0x2100018a, 0x240000cd }, + { 0x2100018b, 0x24000001 }, + { 0x2100018c, 0x1400ffff }, + { 0x2100018d, 0x14000000 }, + { 0x2100018e, 0x2400004f }, + { 0x2100018f, 0x240000ca }, + { 0x21000190, 0x240000cb }, + { 0x21000191, 0x24000001 }, + { 0x21000192, 0x1400ffff }, + { 0x21000193, 0x240000cd }, + { 0x21000194, 0x240000cf }, + { 0x21000195, 0x14000061 }, + { 0x21000196, 0x240000d3 }, + { 0x21000197, 0x240000d1 }, + { 0x21000198, 0x24000001 }, + { 0x21000199, 0x1400ffff }, + { 0x2100019a, 0x140000a3 }, + { 0x2100019b, 0x14000000 }, + { 0x2100019c, 0x240000d3 }, + { 0x2100019d, 0x240000d5 }, + { 0x2100019e, 0x14000082 }, + { 0x2100019f, 0x240000d6 }, + { 0x210001a0, 0x24000001 }, + { 0x210001a1, 0x1400ffff }, + { 0x210001a2, 0x24000001 }, + { 0x210001a3, 0x1400ffff }, + { 0x210001a4, 0x24000001 }, + { 0x210001a5, 0x1400ffff }, + { 0x210001a6, 0x240000da }, + { 0x210001a7, 0x24000001 }, + { 0x210001a8, 0x1400ffff }, + { 0x210001a9, 0x240000da }, + { 0x218001aa, 0x14000001 }, + { 0x210001ac, 0x24000001 }, + { 0x210001ad, 0x1400ffff }, + { 0x210001ae, 0x240000da }, + { 0x210001af, 0x24000001 }, + { 0x210001b0, 0x1400ffff }, + { 0x210001b1, 0x240000d9 }, + { 0x210001b2, 0x240000d9 }, + { 0x210001b3, 0x24000001 }, + { 0x210001b4, 0x1400ffff }, + { 0x210001b5, 0x24000001 }, + { 0x210001b6, 0x1400ffff }, + { 0x210001b7, 0x240000db }, + { 0x210001b8, 0x24000001 }, + { 0x210001b9, 0x1400ffff }, + { 0x210001ba, 0x14000000 }, + { 0x210001bb, 0x1c000000 }, + { 0x210001bc, 0x24000001 }, + { 0x210001bd, 0x1400ffff }, + { 0x210001be, 0x14000000 }, + { 0x210001bf, 0x14000038 }, + { 0x218001c0, 0x1c000003 }, + { 0x210001c4, 0x24000002 }, + { 0x210001c5, 0x2000ffff }, + { 0x210001c6, 0x1400fffe }, + { 0x210001c7, 0x24000002 }, + { 0x210001c8, 0x2000ffff }, + { 0x210001c9, 0x1400fffe }, + { 0x210001ca, 0x24000002 }, + { 0x210001cb, 0x2000ffff }, + { 0x210001cc, 0x1400fffe }, + { 0x210001cd, 0x24000001 }, + { 0x210001ce, 0x1400ffff }, + { 0x210001cf, 0x24000001 }, + { 0x210001d0, 0x1400ffff }, + { 0x210001d1, 0x24000001 }, + { 0x210001d2, 0x1400ffff }, + { 0x210001d3, 0x24000001 }, + { 0x210001d4, 0x1400ffff }, + { 0x210001d5, 0x24000001 }, + { 0x210001d6, 0x1400ffff }, + { 0x210001d7, 0x24000001 }, + { 0x210001d8, 0x1400ffff }, + { 0x210001d9, 0x24000001 }, + { 0x210001da, 0x1400ffff }, + { 0x210001db, 0x24000001 }, + { 0x210001dc, 0x1400ffff }, + { 0x210001dd, 0x1400ffb1 }, + { 0x210001de, 0x24000001 }, + { 0x210001df, 0x1400ffff }, + { 0x210001e0, 0x24000001 }, + { 0x210001e1, 0x1400ffff }, + { 0x210001e2, 0x24000001 }, + { 0x210001e3, 0x1400ffff }, + { 0x210001e4, 0x24000001 }, + { 0x210001e5, 0x1400ffff }, + { 0x210001e6, 0x24000001 }, + { 0x210001e7, 0x1400ffff }, + { 0x210001e8, 0x24000001 }, + { 0x210001e9, 0x1400ffff }, + { 0x210001ea, 0x24000001 }, + { 0x210001eb, 0x1400ffff }, + { 0x210001ec, 0x24000001 }, + { 0x210001ed, 0x1400ffff }, + { 0x210001ee, 0x24000001 }, + { 0x210001ef, 0x1400ffff }, + { 0x210001f0, 0x14000000 }, + { 0x210001f1, 0x24000002 }, + { 0x210001f2, 0x2000ffff }, + { 0x210001f3, 0x1400fffe }, + { 0x210001f4, 0x24000001 }, + { 0x210001f5, 0x1400ffff }, + { 0x210001f6, 0x2400ff9f }, + { 0x210001f7, 0x2400ffc8 }, + { 0x210001f8, 0x24000001 }, + { 0x210001f9, 0x1400ffff }, + { 0x210001fa, 0x24000001 }, + { 0x210001fb, 0x1400ffff }, + { 0x210001fc, 0x24000001 }, + { 0x210001fd, 0x1400ffff }, + { 0x210001fe, 0x24000001 }, + { 0x210001ff, 0x1400ffff }, + { 0x21000200, 0x24000001 }, + { 0x21000201, 0x1400ffff }, + { 0x21000202, 0x24000001 }, + { 0x21000203, 0x1400ffff }, + { 0x21000204, 0x24000001 }, + { 0x21000205, 0x1400ffff }, + { 0x21000206, 0x24000001 }, + { 0x21000207, 0x1400ffff }, + { 0x21000208, 0x24000001 }, + { 0x21000209, 0x1400ffff }, + { 0x2100020a, 0x24000001 }, + { 0x2100020b, 0x1400ffff }, + { 0x2100020c, 0x24000001 }, + { 0x2100020d, 0x1400ffff }, + { 0x2100020e, 0x24000001 }, + { 0x2100020f, 0x1400ffff }, + { 0x21000210, 0x24000001 }, + { 0x21000211, 0x1400ffff }, + { 0x21000212, 0x24000001 }, + { 0x21000213, 0x1400ffff }, + { 0x21000214, 0x24000001 }, + { 0x21000215, 0x1400ffff }, + { 0x21000216, 0x24000001 }, + { 0x21000217, 0x1400ffff }, + { 0x21000218, 0x24000001 }, + { 0x21000219, 0x1400ffff }, + { 0x2100021a, 0x24000001 }, + { 0x2100021b, 0x1400ffff }, + { 0x2100021c, 0x24000001 }, + { 0x2100021d, 0x1400ffff }, + { 0x2100021e, 0x24000001 }, + { 0x2100021f, 0x1400ffff }, + { 0x21000220, 0x2400ff7e }, + { 0x21000221, 0x14000000 }, + { 0x21000222, 0x24000001 }, + { 0x21000223, 0x1400ffff }, + { 0x21000224, 0x24000001 }, + { 0x21000225, 0x1400ffff }, + { 0x21000226, 0x24000001 }, + { 0x21000227, 0x1400ffff }, + { 0x21000228, 0x24000001 }, + { 0x21000229, 0x1400ffff }, + { 0x2100022a, 0x24000001 }, + { 0x2100022b, 0x1400ffff }, + { 0x2100022c, 0x24000001 }, + { 0x2100022d, 0x1400ffff }, + { 0x2100022e, 0x24000001 }, + { 0x2100022f, 0x1400ffff }, + { 0x21000230, 0x24000001 }, + { 0x21000231, 0x1400ffff }, + { 0x21000232, 0x24000001 }, + { 0x21000233, 0x1400ffff }, + { 0x21800234, 0x14000005 }, + { 0x2100023a, 0x24002a2b }, + { 0x2100023b, 0x24000001 }, + { 0x2100023c, 0x1400ffff }, + { 0x2100023d, 0x2400ff5d }, + { 0x2100023e, 0x24002a28 }, + { 0x2180023f, 0x14000001 }, + { 0x21000241, 0x24000001 }, + { 0x21000242, 0x1400ffff }, + { 0x21000243, 0x2400ff3d }, + { 0x21000244, 0x24000045 }, + { 0x21000245, 0x24000047 }, + { 0x21000246, 0x24000001 }, + { 0x21000247, 0x1400ffff }, + { 0x21000248, 0x24000001 }, + { 0x21000249, 0x1400ffff }, + { 0x2100024a, 0x24000001 }, + { 0x2100024b, 0x1400ffff }, + { 0x2100024c, 0x24000001 }, + { 0x2100024d, 0x1400ffff }, + { 0x2100024e, 0x24000001 }, + { 0x2100024f, 0x1400ffff }, + { 0x21800250, 0x14000002 }, + { 0x21000253, 0x1400ff2e }, + { 0x21000254, 0x1400ff32 }, + { 0x21000255, 0x14000000 }, + { 0x21000256, 0x1400ff33 }, + { 0x21000257, 0x1400ff33 }, + { 0x21000258, 0x14000000 }, + { 0x21000259, 0x1400ff36 }, + { 0x2100025a, 0x14000000 }, + { 0x2100025b, 0x1400ff35 }, + { 0x2180025c, 0x14000003 }, + { 0x21000260, 0x1400ff33 }, + { 0x21800261, 0x14000001 }, + { 0x21000263, 0x1400ff31 }, + { 0x21800264, 0x14000003 }, + { 0x21000268, 0x1400ff2f }, + { 0x21000269, 0x1400ff2d }, + { 0x2100026a, 0x14000000 }, + { 0x2100026b, 0x140029f7 }, + { 0x2180026c, 0x14000002 }, + { 0x2100026f, 0x1400ff2d }, + { 0x21800270, 0x14000001 }, + { 0x21000272, 0x1400ff2b }, + { 0x21800273, 0x14000001 }, + { 0x21000275, 0x1400ff2a }, + { 0x21800276, 0x14000006 }, + { 0x2100027d, 0x140029e7 }, + { 0x2180027e, 0x14000001 }, + { 0x21000280, 0x1400ff26 }, + { 0x21800281, 0x14000001 }, + { 0x21000283, 0x1400ff26 }, + { 0x21800284, 0x14000003 }, + { 0x21000288, 0x1400ff26 }, + { 0x21000289, 0x1400ffbb }, + { 0x2100028a, 0x1400ff27 }, + { 0x2100028b, 0x1400ff27 }, + { 0x2100028c, 0x1400ffb9 }, + { 0x2180028d, 0x14000004 }, + { 0x21000292, 0x1400ff25 }, + { 0x21000293, 0x14000000 }, + { 0x21000294, 0x1c000000 }, + { 0x21800295, 0x1400001a }, + { 0x218002b0, 0x18000011 }, + { 0x098002c2, 0x60000003 }, + { 0x098002c6, 0x1800000b }, + { 0x098002d2, 0x6000000d }, + { 0x218002e0, 0x18000004 }, + { 0x098002e5, 0x60000008 }, + { 0x090002ee, 0x18000000 }, + { 0x098002ef, 0x60000010 }, + { 0x1b800300, 0x30000044 }, + { 0x1b000345, 0x30000054 }, + { 0x1b800346, 0x30000029 }, + { 0x13800374, 0x60000001 }, + { 0x1300037a, 0x18000000 }, + { 0x1300037b, 0x14000082 }, + { 0x1300037c, 0x14000082 }, + { 0x1300037d, 0x14000082 }, + { 0x0900037e, 0x54000000 }, + { 0x13800384, 0x60000001 }, + { 0x13000386, 0x24000026 }, + { 0x09000387, 0x54000000 }, + { 0x13000388, 0x24000025 }, + { 0x13000389, 0x24000025 }, + { 0x1300038a, 0x24000025 }, + { 0x1300038c, 0x24000040 }, + { 0x1300038e, 0x2400003f }, + { 0x1300038f, 0x2400003f }, + { 0x13000390, 0x14000000 }, + { 0x13000391, 0x24000020 }, + { 0x13000392, 0x24000020 }, + { 0x13000393, 0x24000020 }, + { 0x13000394, 0x24000020 }, + { 0x13000395, 0x24000020 }, + { 0x13000396, 0x24000020 }, + { 0x13000397, 0x24000020 }, + { 0x13000398, 0x24000020 }, + { 0x13000399, 0x24000020 }, + { 0x1300039a, 0x24000020 }, + { 0x1300039b, 0x24000020 }, + { 0x1300039c, 0x24000020 }, + { 0x1300039d, 0x24000020 }, + { 0x1300039e, 0x24000020 }, + { 0x1300039f, 0x24000020 }, + { 0x130003a0, 0x24000020 }, + { 0x130003a1, 0x24000020 }, + { 0x130003a3, 0x24000020 }, + { 0x130003a4, 0x24000020 }, + { 0x130003a5, 0x24000020 }, + { 0x130003a6, 0x24000020 }, + { 0x130003a7, 0x24000020 }, + { 0x130003a8, 0x24000020 }, + { 0x130003a9, 0x24000020 }, + { 0x130003aa, 0x24000020 }, + { 0x130003ab, 0x24000020 }, + { 0x130003ac, 0x1400ffda }, + { 0x130003ad, 0x1400ffdb }, + { 0x130003ae, 0x1400ffdb }, + { 0x130003af, 0x1400ffdb }, + { 0x130003b0, 0x14000000 }, + { 0x130003b1, 0x1400ffe0 }, + { 0x130003b2, 0x1400ffe0 }, + { 0x130003b3, 0x1400ffe0 }, + { 0x130003b4, 0x1400ffe0 }, + { 0x130003b5, 0x1400ffe0 }, + { 0x130003b6, 0x1400ffe0 }, + { 0x130003b7, 0x1400ffe0 }, + { 0x130003b8, 0x1400ffe0 }, + { 0x130003b9, 0x1400ffe0 }, + { 0x130003ba, 0x1400ffe0 }, + { 0x130003bb, 0x1400ffe0 }, + { 0x130003bc, 0x1400ffe0 }, + { 0x130003bd, 0x1400ffe0 }, + { 0x130003be, 0x1400ffe0 }, + { 0x130003bf, 0x1400ffe0 }, + { 0x130003c0, 0x1400ffe0 }, + { 0x130003c1, 0x1400ffe0 }, + { 0x130003c2, 0x1400ffe1 }, + { 0x130003c3, 0x1400ffe0 }, + { 0x130003c4, 0x1400ffe0 }, + { 0x130003c5, 0x1400ffe0 }, + { 0x130003c6, 0x1400ffe0 }, + { 0x130003c7, 0x1400ffe0 }, + { 0x130003c8, 0x1400ffe0 }, + { 0x130003c9, 0x1400ffe0 }, + { 0x130003ca, 0x1400ffe0 }, + { 0x130003cb, 0x1400ffe0 }, + { 0x130003cc, 0x1400ffc0 }, + { 0x130003cd, 0x1400ffc1 }, + { 0x130003ce, 0x1400ffc1 }, + { 0x130003d0, 0x1400ffc2 }, + { 0x130003d1, 0x1400ffc7 }, + { 0x138003d2, 0x24000002 }, + { 0x130003d5, 0x1400ffd1 }, + { 0x130003d6, 0x1400ffca }, + { 0x130003d7, 0x14000000 }, + { 0x130003d8, 0x24000001 }, + { 0x130003d9, 0x1400ffff }, + { 0x130003da, 0x24000001 }, + { 0x130003db, 0x1400ffff }, + { 0x130003dc, 0x24000001 }, + { 0x130003dd, 0x1400ffff }, + { 0x130003de, 0x24000001 }, + { 0x130003df, 0x1400ffff }, + { 0x130003e0, 0x24000001 }, + { 0x130003e1, 0x1400ffff }, + { 0x0a0003e2, 0x24000001 }, + { 0x0a0003e3, 0x1400ffff }, + { 0x0a0003e4, 0x24000001 }, + { 0x0a0003e5, 0x1400ffff }, + { 0x0a0003e6, 0x24000001 }, + { 0x0a0003e7, 0x1400ffff }, + { 0x0a0003e8, 0x24000001 }, + { 0x0a0003e9, 0x1400ffff }, + { 0x0a0003ea, 0x24000001 }, + { 0x0a0003eb, 0x1400ffff }, + { 0x0a0003ec, 0x24000001 }, + { 0x0a0003ed, 0x1400ffff }, + { 0x0a0003ee, 0x24000001 }, + { 0x0a0003ef, 0x1400ffff }, + { 0x130003f0, 0x1400ffaa }, + { 0x130003f1, 0x1400ffb0 }, + { 0x130003f2, 0x14000007 }, + { 0x130003f3, 0x14000000 }, + { 0x130003f4, 0x2400ffc4 }, + { 0x130003f5, 0x1400ffa0 }, + { 0x130003f6, 0x64000000 }, + { 0x130003f7, 0x24000001 }, + { 0x130003f8, 0x1400ffff }, + { 0x130003f9, 0x2400fff9 }, + { 0x130003fa, 0x24000001 }, + { 0x130003fb, 0x1400ffff }, + { 0x130003fc, 0x14000000 }, + { 0x130003fd, 0x2400ff7e }, + { 0x130003fe, 0x2400ff7e }, + { 0x130003ff, 0x2400ff7e }, + { 0x0c000400, 0x24000050 }, + { 0x0c000401, 0x24000050 }, + { 0x0c000402, 0x24000050 }, + { 0x0c000403, 0x24000050 }, + { 0x0c000404, 0x24000050 }, + { 0x0c000405, 0x24000050 }, + { 0x0c000406, 0x24000050 }, + { 0x0c000407, 0x24000050 }, + { 0x0c000408, 0x24000050 }, + { 0x0c000409, 0x24000050 }, + { 0x0c00040a, 0x24000050 }, + { 0x0c00040b, 0x24000050 }, + { 0x0c00040c, 0x24000050 }, + { 0x0c00040d, 0x24000050 }, + { 0x0c00040e, 0x24000050 }, + { 0x0c00040f, 0x24000050 }, + { 0x0c000410, 0x24000020 }, + { 0x0c000411, 0x24000020 }, + { 0x0c000412, 0x24000020 }, + { 0x0c000413, 0x24000020 }, + { 0x0c000414, 0x24000020 }, + { 0x0c000415, 0x24000020 }, + { 0x0c000416, 0x24000020 }, + { 0x0c000417, 0x24000020 }, + { 0x0c000418, 0x24000020 }, + { 0x0c000419, 0x24000020 }, + { 0x0c00041a, 0x24000020 }, + { 0x0c00041b, 0x24000020 }, + { 0x0c00041c, 0x24000020 }, + { 0x0c00041d, 0x24000020 }, + { 0x0c00041e, 0x24000020 }, + { 0x0c00041f, 0x24000020 }, + { 0x0c000420, 0x24000020 }, + { 0x0c000421, 0x24000020 }, + { 0x0c000422, 0x24000020 }, + { 0x0c000423, 0x24000020 }, + { 0x0c000424, 0x24000020 }, + { 0x0c000425, 0x24000020 }, + { 0x0c000426, 0x24000020 }, + { 0x0c000427, 0x24000020 }, + { 0x0c000428, 0x24000020 }, + { 0x0c000429, 0x24000020 }, + { 0x0c00042a, 0x24000020 }, + { 0x0c00042b, 0x24000020 }, + { 0x0c00042c, 0x24000020 }, + { 0x0c00042d, 0x24000020 }, + { 0x0c00042e, 0x24000020 }, + { 0x0c00042f, 0x24000020 }, + { 0x0c000430, 0x1400ffe0 }, + { 0x0c000431, 0x1400ffe0 }, + { 0x0c000432, 0x1400ffe0 }, + { 0x0c000433, 0x1400ffe0 }, + { 0x0c000434, 0x1400ffe0 }, + { 0x0c000435, 0x1400ffe0 }, + { 0x0c000436, 0x1400ffe0 }, + { 0x0c000437, 0x1400ffe0 }, + { 0x0c000438, 0x1400ffe0 }, + { 0x0c000439, 0x1400ffe0 }, + { 0x0c00043a, 0x1400ffe0 }, + { 0x0c00043b, 0x1400ffe0 }, + { 0x0c00043c, 0x1400ffe0 }, + { 0x0c00043d, 0x1400ffe0 }, + { 0x0c00043e, 0x1400ffe0 }, + { 0x0c00043f, 0x1400ffe0 }, + { 0x0c000440, 0x1400ffe0 }, + { 0x0c000441, 0x1400ffe0 }, + { 0x0c000442, 0x1400ffe0 }, + { 0x0c000443, 0x1400ffe0 }, + { 0x0c000444, 0x1400ffe0 }, + { 0x0c000445, 0x1400ffe0 }, + { 0x0c000446, 0x1400ffe0 }, + { 0x0c000447, 0x1400ffe0 }, + { 0x0c000448, 0x1400ffe0 }, + { 0x0c000449, 0x1400ffe0 }, + { 0x0c00044a, 0x1400ffe0 }, + { 0x0c00044b, 0x1400ffe0 }, + { 0x0c00044c, 0x1400ffe0 }, + { 0x0c00044d, 0x1400ffe0 }, + { 0x0c00044e, 0x1400ffe0 }, + { 0x0c00044f, 0x1400ffe0 }, + { 0x0c000450, 0x1400ffb0 }, + { 0x0c000451, 0x1400ffb0 }, + { 0x0c000452, 0x1400ffb0 }, + { 0x0c000453, 0x1400ffb0 }, + { 0x0c000454, 0x1400ffb0 }, + { 0x0c000455, 0x1400ffb0 }, + { 0x0c000456, 0x1400ffb0 }, + { 0x0c000457, 0x1400ffb0 }, + { 0x0c000458, 0x1400ffb0 }, + { 0x0c000459, 0x1400ffb0 }, + { 0x0c00045a, 0x1400ffb0 }, + { 0x0c00045b, 0x1400ffb0 }, + { 0x0c00045c, 0x1400ffb0 }, + { 0x0c00045d, 0x1400ffb0 }, + { 0x0c00045e, 0x1400ffb0 }, + { 0x0c00045f, 0x1400ffb0 }, + { 0x0c000460, 0x24000001 }, + { 0x0c000461, 0x1400ffff }, + { 0x0c000462, 0x24000001 }, + { 0x0c000463, 0x1400ffff }, + { 0x0c000464, 0x24000001 }, + { 0x0c000465, 0x1400ffff }, + { 0x0c000466, 0x24000001 }, + { 0x0c000467, 0x1400ffff }, + { 0x0c000468, 0x24000001 }, + { 0x0c000469, 0x1400ffff }, + { 0x0c00046a, 0x24000001 }, + { 0x0c00046b, 0x1400ffff }, + { 0x0c00046c, 0x24000001 }, + { 0x0c00046d, 0x1400ffff }, + { 0x0c00046e, 0x24000001 }, + { 0x0c00046f, 0x1400ffff }, + { 0x0c000470, 0x24000001 }, + { 0x0c000471, 0x1400ffff }, + { 0x0c000472, 0x24000001 }, + { 0x0c000473, 0x1400ffff }, + { 0x0c000474, 0x24000001 }, + { 0x0c000475, 0x1400ffff }, + { 0x0c000476, 0x24000001 }, + { 0x0c000477, 0x1400ffff }, + { 0x0c000478, 0x24000001 }, + { 0x0c000479, 0x1400ffff }, + { 0x0c00047a, 0x24000001 }, + { 0x0c00047b, 0x1400ffff }, + { 0x0c00047c, 0x24000001 }, + { 0x0c00047d, 0x1400ffff }, + { 0x0c00047e, 0x24000001 }, + { 0x0c00047f, 0x1400ffff }, + { 0x0c000480, 0x24000001 }, + { 0x0c000481, 0x1400ffff }, + { 0x0c000482, 0x68000000 }, + { 0x0c800483, 0x30000003 }, + { 0x0c800488, 0x2c000001 }, + { 0x0c00048a, 0x24000001 }, + { 0x0c00048b, 0x1400ffff }, + { 0x0c00048c, 0x24000001 }, + { 0x0c00048d, 0x1400ffff }, + { 0x0c00048e, 0x24000001 }, + { 0x0c00048f, 0x1400ffff }, + { 0x0c000490, 0x24000001 }, + { 0x0c000491, 0x1400ffff }, + { 0x0c000492, 0x24000001 }, + { 0x0c000493, 0x1400ffff }, + { 0x0c000494, 0x24000001 }, + { 0x0c000495, 0x1400ffff }, + { 0x0c000496, 0x24000001 }, + { 0x0c000497, 0x1400ffff }, + { 0x0c000498, 0x24000001 }, + { 0x0c000499, 0x1400ffff }, + { 0x0c00049a, 0x24000001 }, + { 0x0c00049b, 0x1400ffff }, + { 0x0c00049c, 0x24000001 }, + { 0x0c00049d, 0x1400ffff }, + { 0x0c00049e, 0x24000001 }, + { 0x0c00049f, 0x1400ffff }, + { 0x0c0004a0, 0x24000001 }, + { 0x0c0004a1, 0x1400ffff }, + { 0x0c0004a2, 0x24000001 }, + { 0x0c0004a3, 0x1400ffff }, + { 0x0c0004a4, 0x24000001 }, + { 0x0c0004a5, 0x1400ffff }, + { 0x0c0004a6, 0x24000001 }, + { 0x0c0004a7, 0x1400ffff }, + { 0x0c0004a8, 0x24000001 }, + { 0x0c0004a9, 0x1400ffff }, + { 0x0c0004aa, 0x24000001 }, + { 0x0c0004ab, 0x1400ffff }, + { 0x0c0004ac, 0x24000001 }, + { 0x0c0004ad, 0x1400ffff }, + { 0x0c0004ae, 0x24000001 }, + { 0x0c0004af, 0x1400ffff }, + { 0x0c0004b0, 0x24000001 }, + { 0x0c0004b1, 0x1400ffff }, + { 0x0c0004b2, 0x24000001 }, + { 0x0c0004b3, 0x1400ffff }, + { 0x0c0004b4, 0x24000001 }, + { 0x0c0004b5, 0x1400ffff }, + { 0x0c0004b6, 0x24000001 }, + { 0x0c0004b7, 0x1400ffff }, + { 0x0c0004b8, 0x24000001 }, + { 0x0c0004b9, 0x1400ffff }, + { 0x0c0004ba, 0x24000001 }, + { 0x0c0004bb, 0x1400ffff }, + { 0x0c0004bc, 0x24000001 }, + { 0x0c0004bd, 0x1400ffff }, + { 0x0c0004be, 0x24000001 }, + { 0x0c0004bf, 0x1400ffff }, + { 0x0c0004c0, 0x2400000f }, + { 0x0c0004c1, 0x24000001 }, + { 0x0c0004c2, 0x1400ffff }, + { 0x0c0004c3, 0x24000001 }, + { 0x0c0004c4, 0x1400ffff }, + { 0x0c0004c5, 0x24000001 }, + { 0x0c0004c6, 0x1400ffff }, + { 0x0c0004c7, 0x24000001 }, + { 0x0c0004c8, 0x1400ffff }, + { 0x0c0004c9, 0x24000001 }, + { 0x0c0004ca, 0x1400ffff }, + { 0x0c0004cb, 0x24000001 }, + { 0x0c0004cc, 0x1400ffff }, + { 0x0c0004cd, 0x24000001 }, + { 0x0c0004ce, 0x1400ffff }, + { 0x0c0004cf, 0x1400fff1 }, + { 0x0c0004d0, 0x24000001 }, + { 0x0c0004d1, 0x1400ffff }, + { 0x0c0004d2, 0x24000001 }, + { 0x0c0004d3, 0x1400ffff }, + { 0x0c0004d4, 0x24000001 }, + { 0x0c0004d5, 0x1400ffff }, + { 0x0c0004d6, 0x24000001 }, + { 0x0c0004d7, 0x1400ffff }, + { 0x0c0004d8, 0x24000001 }, + { 0x0c0004d9, 0x1400ffff }, + { 0x0c0004da, 0x24000001 }, + { 0x0c0004db, 0x1400ffff }, + { 0x0c0004dc, 0x24000001 }, + { 0x0c0004dd, 0x1400ffff }, + { 0x0c0004de, 0x24000001 }, + { 0x0c0004df, 0x1400ffff }, + { 0x0c0004e0, 0x24000001 }, + { 0x0c0004e1, 0x1400ffff }, + { 0x0c0004e2, 0x24000001 }, + { 0x0c0004e3, 0x1400ffff }, + { 0x0c0004e4, 0x24000001 }, + { 0x0c0004e5, 0x1400ffff }, + { 0x0c0004e6, 0x24000001 }, + { 0x0c0004e7, 0x1400ffff }, + { 0x0c0004e8, 0x24000001 }, + { 0x0c0004e9, 0x1400ffff }, + { 0x0c0004ea, 0x24000001 }, + { 0x0c0004eb, 0x1400ffff }, + { 0x0c0004ec, 0x24000001 }, + { 0x0c0004ed, 0x1400ffff }, + { 0x0c0004ee, 0x24000001 }, + { 0x0c0004ef, 0x1400ffff }, + { 0x0c0004f0, 0x24000001 }, + { 0x0c0004f1, 0x1400ffff }, + { 0x0c0004f2, 0x24000001 }, + { 0x0c0004f3, 0x1400ffff }, + { 0x0c0004f4, 0x24000001 }, + { 0x0c0004f5, 0x1400ffff }, + { 0x0c0004f6, 0x24000001 }, + { 0x0c0004f7, 0x1400ffff }, + { 0x0c0004f8, 0x24000001 }, + { 0x0c0004f9, 0x1400ffff }, + { 0x0c0004fa, 0x24000001 }, + { 0x0c0004fb, 0x1400ffff }, + { 0x0c0004fc, 0x24000001 }, + { 0x0c0004fd, 0x1400ffff }, + { 0x0c0004fe, 0x24000001 }, + { 0x0c0004ff, 0x1400ffff }, + { 0x0c000500, 0x24000001 }, + { 0x0c000501, 0x1400ffff }, + { 0x0c000502, 0x24000001 }, + { 0x0c000503, 0x1400ffff }, + { 0x0c000504, 0x24000001 }, + { 0x0c000505, 0x1400ffff }, + { 0x0c000506, 0x24000001 }, + { 0x0c000507, 0x1400ffff }, + { 0x0c000508, 0x24000001 }, + { 0x0c000509, 0x1400ffff }, + { 0x0c00050a, 0x24000001 }, + { 0x0c00050b, 0x1400ffff }, + { 0x0c00050c, 0x24000001 }, + { 0x0c00050d, 0x1400ffff }, + { 0x0c00050e, 0x24000001 }, + { 0x0c00050f, 0x1400ffff }, + { 0x0c000510, 0x24000001 }, + { 0x0c000511, 0x1400ffff }, + { 0x0c000512, 0x24000001 }, + { 0x0c000513, 0x1400ffff }, + { 0x01000531, 0x24000030 }, + { 0x01000532, 0x24000030 }, + { 0x01000533, 0x24000030 }, + { 0x01000534, 0x24000030 }, + { 0x01000535, 0x24000030 }, + { 0x01000536, 0x24000030 }, + { 0x01000537, 0x24000030 }, + { 0x01000538, 0x24000030 }, + { 0x01000539, 0x24000030 }, + { 0x0100053a, 0x24000030 }, + { 0x0100053b, 0x24000030 }, + { 0x0100053c, 0x24000030 }, + { 0x0100053d, 0x24000030 }, + { 0x0100053e, 0x24000030 }, + { 0x0100053f, 0x24000030 }, + { 0x01000540, 0x24000030 }, + { 0x01000541, 0x24000030 }, + { 0x01000542, 0x24000030 }, + { 0x01000543, 0x24000030 }, + { 0x01000544, 0x24000030 }, + { 0x01000545, 0x24000030 }, + { 0x01000546, 0x24000030 }, + { 0x01000547, 0x24000030 }, + { 0x01000548, 0x24000030 }, + { 0x01000549, 0x24000030 }, + { 0x0100054a, 0x24000030 }, + { 0x0100054b, 0x24000030 }, + { 0x0100054c, 0x24000030 }, + { 0x0100054d, 0x24000030 }, + { 0x0100054e, 0x24000030 }, + { 0x0100054f, 0x24000030 }, + { 0x01000550, 0x24000030 }, + { 0x01000551, 0x24000030 }, + { 0x01000552, 0x24000030 }, + { 0x01000553, 0x24000030 }, + { 0x01000554, 0x24000030 }, + { 0x01000555, 0x24000030 }, + { 0x01000556, 0x24000030 }, + { 0x01000559, 0x18000000 }, + { 0x0180055a, 0x54000005 }, + { 0x01000561, 0x1400ffd0 }, + { 0x01000562, 0x1400ffd0 }, + { 0x01000563, 0x1400ffd0 }, + { 0x01000564, 0x1400ffd0 }, + { 0x01000565, 0x1400ffd0 }, + { 0x01000566, 0x1400ffd0 }, + { 0x01000567, 0x1400ffd0 }, + { 0x01000568, 0x1400ffd0 }, + { 0x01000569, 0x1400ffd0 }, + { 0x0100056a, 0x1400ffd0 }, + { 0x0100056b, 0x1400ffd0 }, + { 0x0100056c, 0x1400ffd0 }, + { 0x0100056d, 0x1400ffd0 }, + { 0x0100056e, 0x1400ffd0 }, + { 0x0100056f, 0x1400ffd0 }, + { 0x01000570, 0x1400ffd0 }, + { 0x01000571, 0x1400ffd0 }, + { 0x01000572, 0x1400ffd0 }, + { 0x01000573, 0x1400ffd0 }, + { 0x01000574, 0x1400ffd0 }, + { 0x01000575, 0x1400ffd0 }, + { 0x01000576, 0x1400ffd0 }, + { 0x01000577, 0x1400ffd0 }, + { 0x01000578, 0x1400ffd0 }, + { 0x01000579, 0x1400ffd0 }, + { 0x0100057a, 0x1400ffd0 }, + { 0x0100057b, 0x1400ffd0 }, + { 0x0100057c, 0x1400ffd0 }, + { 0x0100057d, 0x1400ffd0 }, + { 0x0100057e, 0x1400ffd0 }, + { 0x0100057f, 0x1400ffd0 }, + { 0x01000580, 0x1400ffd0 }, + { 0x01000581, 0x1400ffd0 }, + { 0x01000582, 0x1400ffd0 }, + { 0x01000583, 0x1400ffd0 }, + { 0x01000584, 0x1400ffd0 }, + { 0x01000585, 0x1400ffd0 }, + { 0x01000586, 0x1400ffd0 }, + { 0x01000587, 0x14000000 }, + { 0x09000589, 0x54000000 }, + { 0x0100058a, 0x44000000 }, + { 0x19800591, 0x3000002c }, + { 0x190005be, 0x54000000 }, + { 0x190005bf, 0x30000000 }, + { 0x190005c0, 0x54000000 }, + { 0x198005c1, 0x30000001 }, + { 0x190005c3, 0x54000000 }, + { 0x198005c4, 0x30000001 }, + { 0x190005c6, 0x54000000 }, + { 0x190005c7, 0x30000000 }, + { 0x198005d0, 0x1c00001a }, + { 0x198005f0, 0x1c000002 }, + { 0x198005f3, 0x54000001 }, + { 0x09800600, 0x04000003 }, + { 0x0000060b, 0x5c000000 }, + { 0x0980060c, 0x54000001 }, + { 0x0080060e, 0x68000001 }, + { 0x00800610, 0x30000005 }, + { 0x0900061b, 0x54000000 }, + { 0x0080061e, 0x54000001 }, + { 0x00800621, 0x1c000019 }, + { 0x09000640, 0x18000000 }, + { 0x00800641, 0x1c000009 }, + { 0x1b80064b, 0x30000013 }, + { 0x09800660, 0x34000009 }, + { 0x0080066a, 0x54000003 }, + { 0x0080066e, 0x1c000001 }, + { 0x1b000670, 0x30000000 }, + { 0x00800671, 0x1c000062 }, + { 0x000006d4, 0x54000000 }, + { 0x000006d5, 0x1c000000 }, + { 0x008006d6, 0x30000006 }, + { 0x090006dd, 0x04000000 }, + { 0x000006de, 0x2c000000 }, + { 0x008006df, 0x30000005 }, + { 0x008006e5, 0x18000001 }, + { 0x008006e7, 0x30000001 }, + { 0x000006e9, 0x68000000 }, + { 0x008006ea, 0x30000003 }, + { 0x008006ee, 0x1c000001 }, + { 0x008006f0, 0x34000009 }, + { 0x008006fa, 0x1c000002 }, + { 0x008006fd, 0x68000001 }, + { 0x000006ff, 0x1c000000 }, + { 0x31800700, 0x5400000d }, + { 0x3100070f, 0x04000000 }, + { 0x31000710, 0x1c000000 }, + { 0x31000711, 0x30000000 }, + { 0x31800712, 0x1c00001d }, + { 0x31800730, 0x3000001a }, + { 0x3180074d, 0x1c000020 }, + { 0x37800780, 0x1c000025 }, + { 0x378007a6, 0x3000000a }, + { 0x370007b1, 0x1c000000 }, + { 0x3f8007c0, 0x34000009 }, + { 0x3f8007ca, 0x1c000020 }, + { 0x3f8007eb, 0x30000008 }, + { 0x3f8007f4, 0x18000001 }, + { 0x3f0007f6, 0x68000000 }, + { 0x3f8007f7, 0x54000002 }, + { 0x3f0007fa, 0x18000000 }, + { 0x0e800901, 0x30000001 }, + { 0x0e000903, 0x28000000 }, + { 0x0e800904, 0x1c000035 }, + { 0x0e00093c, 0x30000000 }, + { 0x0e00093d, 0x1c000000 }, + { 0x0e80093e, 0x28000002 }, + { 0x0e800941, 0x30000007 }, + { 0x0e800949, 0x28000003 }, + { 0x0e00094d, 0x30000000 }, + { 0x0e000950, 0x1c000000 }, + { 0x0e800951, 0x30000003 }, + { 0x0e800958, 0x1c000009 }, + { 0x0e800962, 0x30000001 }, + { 0x09800964, 0x54000001 }, + { 0x0e800966, 0x34000009 }, + { 0x09000970, 0x54000000 }, + { 0x0e80097b, 0x1c000004 }, + { 0x02000981, 0x30000000 }, + { 0x02800982, 0x28000001 }, + { 0x02800985, 0x1c000007 }, + { 0x0280098f, 0x1c000001 }, + { 0x02800993, 0x1c000015 }, + { 0x028009aa, 0x1c000006 }, + { 0x020009b2, 0x1c000000 }, + { 0x028009b6, 0x1c000003 }, + { 0x020009bc, 0x30000000 }, + { 0x020009bd, 0x1c000000 }, + { 0x028009be, 0x28000002 }, + { 0x028009c1, 0x30000003 }, + { 0x028009c7, 0x28000001 }, + { 0x028009cb, 0x28000001 }, + { 0x020009cd, 0x30000000 }, + { 0x020009ce, 0x1c000000 }, + { 0x020009d7, 0x28000000 }, + { 0x028009dc, 0x1c000001 }, + { 0x028009df, 0x1c000002 }, + { 0x028009e2, 0x30000001 }, + { 0x028009e6, 0x34000009 }, + { 0x028009f0, 0x1c000001 }, + { 0x028009f2, 0x5c000001 }, + { 0x028009f4, 0x3c000005 }, + { 0x020009fa, 0x68000000 }, + { 0x15800a01, 0x30000001 }, + { 0x15000a03, 0x28000000 }, + { 0x15800a05, 0x1c000005 }, + { 0x15800a0f, 0x1c000001 }, + { 0x15800a13, 0x1c000015 }, + { 0x15800a2a, 0x1c000006 }, + { 0x15800a32, 0x1c000001 }, + { 0x15800a35, 0x1c000001 }, + { 0x15800a38, 0x1c000001 }, + { 0x15000a3c, 0x30000000 }, + { 0x15800a3e, 0x28000002 }, + { 0x15800a41, 0x30000001 }, + { 0x15800a47, 0x30000001 }, + { 0x15800a4b, 0x30000002 }, + { 0x15800a59, 0x1c000003 }, + { 0x15000a5e, 0x1c000000 }, + { 0x15800a66, 0x34000009 }, + { 0x15800a70, 0x30000001 }, + { 0x15800a72, 0x1c000002 }, + { 0x14800a81, 0x30000001 }, + { 0x14000a83, 0x28000000 }, + { 0x14800a85, 0x1c000008 }, + { 0x14800a8f, 0x1c000002 }, + { 0x14800a93, 0x1c000015 }, + { 0x14800aaa, 0x1c000006 }, + { 0x14800ab2, 0x1c000001 }, + { 0x14800ab5, 0x1c000004 }, + { 0x14000abc, 0x30000000 }, + { 0x14000abd, 0x1c000000 }, + { 0x14800abe, 0x28000002 }, + { 0x14800ac1, 0x30000004 }, + { 0x14800ac7, 0x30000001 }, + { 0x14000ac9, 0x28000000 }, + { 0x14800acb, 0x28000001 }, + { 0x14000acd, 0x30000000 }, + { 0x14000ad0, 0x1c000000 }, + { 0x14800ae0, 0x1c000001 }, + { 0x14800ae2, 0x30000001 }, + { 0x14800ae6, 0x34000009 }, + { 0x14000af1, 0x5c000000 }, + { 0x2b000b01, 0x30000000 }, + { 0x2b800b02, 0x28000001 }, + { 0x2b800b05, 0x1c000007 }, + { 0x2b800b0f, 0x1c000001 }, + { 0x2b800b13, 0x1c000015 }, + { 0x2b800b2a, 0x1c000006 }, + { 0x2b800b32, 0x1c000001 }, + { 0x2b800b35, 0x1c000004 }, + { 0x2b000b3c, 0x30000000 }, + { 0x2b000b3d, 0x1c000000 }, + { 0x2b000b3e, 0x28000000 }, + { 0x2b000b3f, 0x30000000 }, + { 0x2b000b40, 0x28000000 }, + { 0x2b800b41, 0x30000002 }, + { 0x2b800b47, 0x28000001 }, + { 0x2b800b4b, 0x28000001 }, + { 0x2b000b4d, 0x30000000 }, + { 0x2b000b56, 0x30000000 }, + { 0x2b000b57, 0x28000000 }, + { 0x2b800b5c, 0x1c000001 }, + { 0x2b800b5f, 0x1c000002 }, + { 0x2b800b66, 0x34000009 }, + { 0x2b000b70, 0x68000000 }, + { 0x2b000b71, 0x1c000000 }, + { 0x35000b82, 0x30000000 }, + { 0x35000b83, 0x1c000000 }, + { 0x35800b85, 0x1c000005 }, + { 0x35800b8e, 0x1c000002 }, + { 0x35800b92, 0x1c000003 }, + { 0x35800b99, 0x1c000001 }, + { 0x35000b9c, 0x1c000000 }, + { 0x35800b9e, 0x1c000001 }, + { 0x35800ba3, 0x1c000001 }, + { 0x35800ba8, 0x1c000002 }, + { 0x35800bae, 0x1c00000b }, + { 0x35800bbe, 0x28000001 }, + { 0x35000bc0, 0x30000000 }, + { 0x35800bc1, 0x28000001 }, + { 0x35800bc6, 0x28000002 }, + { 0x35800bca, 0x28000002 }, + { 0x35000bcd, 0x30000000 }, + { 0x35000bd7, 0x28000000 }, + { 0x35800be6, 0x34000009 }, + { 0x35800bf0, 0x3c000002 }, + { 0x35800bf3, 0x68000005 }, + { 0x35000bf9, 0x5c000000 }, + { 0x35000bfa, 0x68000000 }, + { 0x36800c01, 0x28000002 }, + { 0x36800c05, 0x1c000007 }, + { 0x36800c0e, 0x1c000002 }, + { 0x36800c12, 0x1c000016 }, + { 0x36800c2a, 0x1c000009 }, + { 0x36800c35, 0x1c000004 }, + { 0x36800c3e, 0x30000002 }, + { 0x36800c41, 0x28000003 }, + { 0x36800c46, 0x30000002 }, + { 0x36800c4a, 0x30000003 }, + { 0x36800c55, 0x30000001 }, + { 0x36800c60, 0x1c000001 }, + { 0x36800c66, 0x34000009 }, + { 0x1c800c82, 0x28000001 }, + { 0x1c800c85, 0x1c000007 }, + { 0x1c800c8e, 0x1c000002 }, + { 0x1c800c92, 0x1c000016 }, + { 0x1c800caa, 0x1c000009 }, + { 0x1c800cb5, 0x1c000004 }, + { 0x1c000cbc, 0x30000000 }, + { 0x1c000cbd, 0x1c000000 }, + { 0x1c000cbe, 0x28000000 }, + { 0x1c000cbf, 0x30000000 }, + { 0x1c800cc0, 0x28000004 }, + { 0x1c000cc6, 0x30000000 }, + { 0x1c800cc7, 0x28000001 }, + { 0x1c800cca, 0x28000001 }, + { 0x1c800ccc, 0x30000001 }, + { 0x1c800cd5, 0x28000001 }, + { 0x1c000cde, 0x1c000000 }, + { 0x1c800ce0, 0x1c000001 }, + { 0x1c800ce2, 0x30000001 }, + { 0x1c800ce6, 0x34000009 }, + { 0x1c800cf1, 0x68000001 }, + { 0x24800d02, 0x28000001 }, + { 0x24800d05, 0x1c000007 }, + { 0x24800d0e, 0x1c000002 }, + { 0x24800d12, 0x1c000016 }, + { 0x24800d2a, 0x1c00000f }, + { 0x24800d3e, 0x28000002 }, + { 0x24800d41, 0x30000002 }, + { 0x24800d46, 0x28000002 }, + { 0x24800d4a, 0x28000002 }, + { 0x24000d4d, 0x30000000 }, + { 0x24000d57, 0x28000000 }, + { 0x24800d60, 0x1c000001 }, + { 0x24800d66, 0x34000009 }, + { 0x2f800d82, 0x28000001 }, + { 0x2f800d85, 0x1c000011 }, + { 0x2f800d9a, 0x1c000017 }, + { 0x2f800db3, 0x1c000008 }, + { 0x2f000dbd, 0x1c000000 }, + { 0x2f800dc0, 0x1c000006 }, + { 0x2f000dca, 0x30000000 }, + { 0x2f800dcf, 0x28000002 }, + { 0x2f800dd2, 0x30000002 }, + { 0x2f000dd6, 0x30000000 }, + { 0x2f800dd8, 0x28000007 }, + { 0x2f800df2, 0x28000001 }, + { 0x2f000df4, 0x54000000 }, + { 0x38800e01, 0x1c00002f }, + { 0x38000e31, 0x30000000 }, + { 0x38800e32, 0x1c000001 }, + { 0x38800e34, 0x30000006 }, + { 0x09000e3f, 0x5c000000 }, + { 0x38800e40, 0x1c000005 }, + { 0x38000e46, 0x18000000 }, + { 0x38800e47, 0x30000007 }, + { 0x38000e4f, 0x54000000 }, + { 0x38800e50, 0x34000009 }, + { 0x38800e5a, 0x54000001 }, + { 0x20800e81, 0x1c000001 }, + { 0x20000e84, 0x1c000000 }, + { 0x20800e87, 0x1c000001 }, + { 0x20000e8a, 0x1c000000 }, + { 0x20000e8d, 0x1c000000 }, + { 0x20800e94, 0x1c000003 }, + { 0x20800e99, 0x1c000006 }, + { 0x20800ea1, 0x1c000002 }, + { 0x20000ea5, 0x1c000000 }, + { 0x20000ea7, 0x1c000000 }, + { 0x20800eaa, 0x1c000001 }, + { 0x20800ead, 0x1c000003 }, + { 0x20000eb1, 0x30000000 }, + { 0x20800eb2, 0x1c000001 }, + { 0x20800eb4, 0x30000005 }, + { 0x20800ebb, 0x30000001 }, + { 0x20000ebd, 0x1c000000 }, + { 0x20800ec0, 0x1c000004 }, + { 0x20000ec6, 0x18000000 }, + { 0x20800ec8, 0x30000005 }, + { 0x20800ed0, 0x34000009 }, + { 0x20800edc, 0x1c000001 }, + { 0x39000f00, 0x1c000000 }, + { 0x39800f01, 0x68000002 }, + { 0x39800f04, 0x5400000e }, + { 0x39800f13, 0x68000004 }, + { 0x39800f18, 0x30000001 }, + { 0x39800f1a, 0x68000005 }, + { 0x39800f20, 0x34000009 }, + { 0x39800f2a, 0x3c000009 }, + { 0x39000f34, 0x68000000 }, + { 0x39000f35, 0x30000000 }, + { 0x39000f36, 0x68000000 }, + { 0x39000f37, 0x30000000 }, + { 0x39000f38, 0x68000000 }, + { 0x39000f39, 0x30000000 }, + { 0x39000f3a, 0x58000000 }, + { 0x39000f3b, 0x48000000 }, + { 0x39000f3c, 0x58000000 }, + { 0x39000f3d, 0x48000000 }, + { 0x39800f3e, 0x28000001 }, + { 0x39800f40, 0x1c000007 }, + { 0x39800f49, 0x1c000021 }, + { 0x39800f71, 0x3000000d }, + { 0x39000f7f, 0x28000000 }, + { 0x39800f80, 0x30000004 }, + { 0x39000f85, 0x54000000 }, + { 0x39800f86, 0x30000001 }, + { 0x39800f88, 0x1c000003 }, + { 0x39800f90, 0x30000007 }, + { 0x39800f99, 0x30000023 }, + { 0x39800fbe, 0x68000007 }, + { 0x39000fc6, 0x30000000 }, + { 0x39800fc7, 0x68000005 }, + { 0x39000fcf, 0x68000000 }, + { 0x39800fd0, 0x54000001 }, + { 0x26801000, 0x1c000021 }, + { 0x26801023, 0x1c000004 }, + { 0x26801029, 0x1c000001 }, + { 0x2600102c, 0x28000000 }, + { 0x2680102d, 0x30000003 }, + { 0x26001031, 0x28000000 }, + { 0x26001032, 0x30000000 }, + { 0x26801036, 0x30000001 }, + { 0x26001038, 0x28000000 }, + { 0x26001039, 0x30000000 }, + { 0x26801040, 0x34000009 }, + { 0x2680104a, 0x54000005 }, + { 0x26801050, 0x1c000005 }, + { 0x26801056, 0x28000001 }, + { 0x26801058, 0x30000001 }, + { 0x100010a0, 0x24001c60 }, + { 0x100010a1, 0x24001c60 }, + { 0x100010a2, 0x24001c60 }, + { 0x100010a3, 0x24001c60 }, + { 0x100010a4, 0x24001c60 }, + { 0x100010a5, 0x24001c60 }, + { 0x100010a6, 0x24001c60 }, + { 0x100010a7, 0x24001c60 }, + { 0x100010a8, 0x24001c60 }, + { 0x100010a9, 0x24001c60 }, + { 0x100010aa, 0x24001c60 }, + { 0x100010ab, 0x24001c60 }, + { 0x100010ac, 0x24001c60 }, + { 0x100010ad, 0x24001c60 }, + { 0x100010ae, 0x24001c60 }, + { 0x100010af, 0x24001c60 }, + { 0x100010b0, 0x24001c60 }, + { 0x100010b1, 0x24001c60 }, + { 0x100010b2, 0x24001c60 }, + { 0x100010b3, 0x24001c60 }, + { 0x100010b4, 0x24001c60 }, + { 0x100010b5, 0x24001c60 }, + { 0x100010b6, 0x24001c60 }, + { 0x100010b7, 0x24001c60 }, + { 0x100010b8, 0x24001c60 }, + { 0x100010b9, 0x24001c60 }, + { 0x100010ba, 0x24001c60 }, + { 0x100010bb, 0x24001c60 }, + { 0x100010bc, 0x24001c60 }, + { 0x100010bd, 0x24001c60 }, + { 0x100010be, 0x24001c60 }, + { 0x100010bf, 0x24001c60 }, + { 0x100010c0, 0x24001c60 }, + { 0x100010c1, 0x24001c60 }, + { 0x100010c2, 0x24001c60 }, + { 0x100010c3, 0x24001c60 }, + { 0x100010c4, 0x24001c60 }, + { 0x100010c5, 0x24001c60 }, + { 0x108010d0, 0x1c00002a }, + { 0x090010fb, 0x54000000 }, + { 0x100010fc, 0x18000000 }, + { 0x17801100, 0x1c000059 }, + { 0x1780115f, 0x1c000043 }, + { 0x178011a8, 0x1c000051 }, + { 0x0f801200, 0x1c000048 }, + { 0x0f80124a, 0x1c000003 }, + { 0x0f801250, 0x1c000006 }, + { 0x0f001258, 0x1c000000 }, + { 0x0f80125a, 0x1c000003 }, + { 0x0f801260, 0x1c000028 }, + { 0x0f80128a, 0x1c000003 }, + { 0x0f801290, 0x1c000020 }, + { 0x0f8012b2, 0x1c000003 }, + { 0x0f8012b8, 0x1c000006 }, + { 0x0f0012c0, 0x1c000000 }, + { 0x0f8012c2, 0x1c000003 }, + { 0x0f8012c8, 0x1c00000e }, + { 0x0f8012d8, 0x1c000038 }, + { 0x0f801312, 0x1c000003 }, + { 0x0f801318, 0x1c000042 }, + { 0x0f00135f, 0x30000000 }, + { 0x0f001360, 0x68000000 }, + { 0x0f801361, 0x54000007 }, + { 0x0f801369, 0x3c000013 }, + { 0x0f801380, 0x1c00000f }, + { 0x0f801390, 0x68000009 }, + { 0x088013a0, 0x1c000054 }, + { 0x07801401, 0x1c00026b }, + { 0x0780166d, 0x54000001 }, + { 0x0780166f, 0x1c000007 }, + { 0x28001680, 0x74000000 }, + { 0x28801681, 0x1c000019 }, + { 0x2800169b, 0x58000000 }, + { 0x2800169c, 0x48000000 }, + { 0x2d8016a0, 0x1c00004a }, + { 0x098016eb, 0x54000002 }, + { 0x2d8016ee, 0x38000002 }, + { 0x32801700, 0x1c00000c }, + { 0x3280170e, 0x1c000003 }, + { 0x32801712, 0x30000002 }, + { 0x18801720, 0x1c000011 }, + { 0x18801732, 0x30000002 }, + { 0x09801735, 0x54000001 }, + { 0x06801740, 0x1c000011 }, + { 0x06801752, 0x30000001 }, + { 0x33801760, 0x1c00000c }, + { 0x3380176e, 0x1c000002 }, + { 0x33801772, 0x30000001 }, + { 0x1f801780, 0x1c000033 }, + { 0x1f8017b4, 0x04000001 }, + { 0x1f0017b6, 0x28000000 }, + { 0x1f8017b7, 0x30000006 }, + { 0x1f8017be, 0x28000007 }, + { 0x1f0017c6, 0x30000000 }, + { 0x1f8017c7, 0x28000001 }, + { 0x1f8017c9, 0x3000000a }, + { 0x1f8017d4, 0x54000002 }, + { 0x1f0017d7, 0x18000000 }, + { 0x1f8017d8, 0x54000002 }, + { 0x1f0017db, 0x5c000000 }, + { 0x1f0017dc, 0x1c000000 }, + { 0x1f0017dd, 0x30000000 }, + { 0x1f8017e0, 0x34000009 }, + { 0x1f8017f0, 0x3c000009 }, + { 0x25801800, 0x54000005 }, + { 0x25001806, 0x44000000 }, + { 0x25801807, 0x54000003 }, + { 0x2580180b, 0x30000002 }, + { 0x2500180e, 0x74000000 }, + { 0x25801810, 0x34000009 }, + { 0x25801820, 0x1c000022 }, + { 0x25001843, 0x18000000 }, + { 0x25801844, 0x1c000033 }, + { 0x25801880, 0x1c000028 }, + { 0x250018a9, 0x30000000 }, + { 0x22801900, 0x1c00001c }, + { 0x22801920, 0x30000002 }, + { 0x22801923, 0x28000003 }, + { 0x22801927, 0x30000001 }, + { 0x22801929, 0x28000002 }, + { 0x22801930, 0x28000001 }, + { 0x22001932, 0x30000000 }, + { 0x22801933, 0x28000005 }, + { 0x22801939, 0x30000002 }, + { 0x22001940, 0x68000000 }, + { 0x22801944, 0x54000001 }, + { 0x22801946, 0x34000009 }, + { 0x34801950, 0x1c00001d }, + { 0x34801970, 0x1c000004 }, + { 0x27801980, 0x1c000029 }, + { 0x278019b0, 0x28000010 }, + { 0x278019c1, 0x1c000006 }, + { 0x278019c8, 0x28000001 }, + { 0x278019d0, 0x34000009 }, + { 0x278019de, 0x54000001 }, + { 0x1f8019e0, 0x6800001f }, + { 0x05801a00, 0x1c000016 }, + { 0x05801a17, 0x30000001 }, + { 0x05801a19, 0x28000002 }, + { 0x05801a1e, 0x54000001 }, + { 0x3d801b00, 0x30000003 }, + { 0x3d001b04, 0x28000000 }, + { 0x3d801b05, 0x1c00002e }, + { 0x3d001b34, 0x30000000 }, + { 0x3d001b35, 0x28000000 }, + { 0x3d801b36, 0x30000004 }, + { 0x3d001b3b, 0x28000000 }, + { 0x3d001b3c, 0x30000000 }, + { 0x3d801b3d, 0x28000004 }, + { 0x3d001b42, 0x30000000 }, + { 0x3d801b43, 0x28000001 }, + { 0x3d801b45, 0x1c000006 }, + { 0x3d801b50, 0x34000009 }, + { 0x3d801b5a, 0x54000006 }, + { 0x3d801b61, 0x68000009 }, + { 0x3d801b6b, 0x30000008 }, + { 0x3d801b74, 0x68000008 }, + { 0x21801d00, 0x1400002b }, + { 0x21801d2c, 0x18000035 }, + { 0x21801d62, 0x14000015 }, + { 0x0c001d78, 0x18000000 }, + { 0x21801d79, 0x14000003 }, + { 0x21001d7d, 0x14000ee6 }, + { 0x21801d7e, 0x1400001c }, + { 0x21801d9b, 0x18000024 }, + { 0x1b801dc0, 0x3000000a }, + { 0x1b801dfe, 0x30000001 }, + { 0x21001e00, 0x24000001 }, + { 0x21001e01, 0x1400ffff }, + { 0x21001e02, 0x24000001 }, + { 0x21001e03, 0x1400ffff }, + { 0x21001e04, 0x24000001 }, + { 0x21001e05, 0x1400ffff }, + { 0x21001e06, 0x24000001 }, + { 0x21001e07, 0x1400ffff }, + { 0x21001e08, 0x24000001 }, + { 0x21001e09, 0x1400ffff }, + { 0x21001e0a, 0x24000001 }, + { 0x21001e0b, 0x1400ffff }, + { 0x21001e0c, 0x24000001 }, + { 0x21001e0d, 0x1400ffff }, + { 0x21001e0e, 0x24000001 }, + { 0x21001e0f, 0x1400ffff }, + { 0x21001e10, 0x24000001 }, + { 0x21001e11, 0x1400ffff }, + { 0x21001e12, 0x24000001 }, + { 0x21001e13, 0x1400ffff }, + { 0x21001e14, 0x24000001 }, + { 0x21001e15, 0x1400ffff }, + { 0x21001e16, 0x24000001 }, + { 0x21001e17, 0x1400ffff }, + { 0x21001e18, 0x24000001 }, + { 0x21001e19, 0x1400ffff }, + { 0x21001e1a, 0x24000001 }, + { 0x21001e1b, 0x1400ffff }, + { 0x21001e1c, 0x24000001 }, + { 0x21001e1d, 0x1400ffff }, + { 0x21001e1e, 0x24000001 }, + { 0x21001e1f, 0x1400ffff }, + { 0x21001e20, 0x24000001 }, + { 0x21001e21, 0x1400ffff }, + { 0x21001e22, 0x24000001 }, + { 0x21001e23, 0x1400ffff }, + { 0x21001e24, 0x24000001 }, + { 0x21001e25, 0x1400ffff }, + { 0x21001e26, 0x24000001 }, + { 0x21001e27, 0x1400ffff }, + { 0x21001e28, 0x24000001 }, + { 0x21001e29, 0x1400ffff }, + { 0x21001e2a, 0x24000001 }, + { 0x21001e2b, 0x1400ffff }, + { 0x21001e2c, 0x24000001 }, + { 0x21001e2d, 0x1400ffff }, + { 0x21001e2e, 0x24000001 }, + { 0x21001e2f, 0x1400ffff }, + { 0x21001e30, 0x24000001 }, + { 0x21001e31, 0x1400ffff }, + { 0x21001e32, 0x24000001 }, + { 0x21001e33, 0x1400ffff }, + { 0x21001e34, 0x24000001 }, + { 0x21001e35, 0x1400ffff }, + { 0x21001e36, 0x24000001 }, + { 0x21001e37, 0x1400ffff }, + { 0x21001e38, 0x24000001 }, + { 0x21001e39, 0x1400ffff }, + { 0x21001e3a, 0x24000001 }, + { 0x21001e3b, 0x1400ffff }, + { 0x21001e3c, 0x24000001 }, + { 0x21001e3d, 0x1400ffff }, + { 0x21001e3e, 0x24000001 }, + { 0x21001e3f, 0x1400ffff }, + { 0x21001e40, 0x24000001 }, + { 0x21001e41, 0x1400ffff }, + { 0x21001e42, 0x24000001 }, + { 0x21001e43, 0x1400ffff }, + { 0x21001e44, 0x24000001 }, + { 0x21001e45, 0x1400ffff }, + { 0x21001e46, 0x24000001 }, + { 0x21001e47, 0x1400ffff }, + { 0x21001e48, 0x24000001 }, + { 0x21001e49, 0x1400ffff }, + { 0x21001e4a, 0x24000001 }, + { 0x21001e4b, 0x1400ffff }, + { 0x21001e4c, 0x24000001 }, + { 0x21001e4d, 0x1400ffff }, + { 0x21001e4e, 0x24000001 }, + { 0x21001e4f, 0x1400ffff }, + { 0x21001e50, 0x24000001 }, + { 0x21001e51, 0x1400ffff }, + { 0x21001e52, 0x24000001 }, + { 0x21001e53, 0x1400ffff }, + { 0x21001e54, 0x24000001 }, + { 0x21001e55, 0x1400ffff }, + { 0x21001e56, 0x24000001 }, + { 0x21001e57, 0x1400ffff }, + { 0x21001e58, 0x24000001 }, + { 0x21001e59, 0x1400ffff }, + { 0x21001e5a, 0x24000001 }, + { 0x21001e5b, 0x1400ffff }, + { 0x21001e5c, 0x24000001 }, + { 0x21001e5d, 0x1400ffff }, + { 0x21001e5e, 0x24000001 }, + { 0x21001e5f, 0x1400ffff }, + { 0x21001e60, 0x24000001 }, + { 0x21001e61, 0x1400ffff }, + { 0x21001e62, 0x24000001 }, + { 0x21001e63, 0x1400ffff }, + { 0x21001e64, 0x24000001 }, + { 0x21001e65, 0x1400ffff }, + { 0x21001e66, 0x24000001 }, + { 0x21001e67, 0x1400ffff }, + { 0x21001e68, 0x24000001 }, + { 0x21001e69, 0x1400ffff }, + { 0x21001e6a, 0x24000001 }, + { 0x21001e6b, 0x1400ffff }, + { 0x21001e6c, 0x24000001 }, + { 0x21001e6d, 0x1400ffff }, + { 0x21001e6e, 0x24000001 }, + { 0x21001e6f, 0x1400ffff }, + { 0x21001e70, 0x24000001 }, + { 0x21001e71, 0x1400ffff }, + { 0x21001e72, 0x24000001 }, + { 0x21001e73, 0x1400ffff }, + { 0x21001e74, 0x24000001 }, + { 0x21001e75, 0x1400ffff }, + { 0x21001e76, 0x24000001 }, + { 0x21001e77, 0x1400ffff }, + { 0x21001e78, 0x24000001 }, + { 0x21001e79, 0x1400ffff }, + { 0x21001e7a, 0x24000001 }, + { 0x21001e7b, 0x1400ffff }, + { 0x21001e7c, 0x24000001 }, + { 0x21001e7d, 0x1400ffff }, + { 0x21001e7e, 0x24000001 }, + { 0x21001e7f, 0x1400ffff }, + { 0x21001e80, 0x24000001 }, + { 0x21001e81, 0x1400ffff }, + { 0x21001e82, 0x24000001 }, + { 0x21001e83, 0x1400ffff }, + { 0x21001e84, 0x24000001 }, + { 0x21001e85, 0x1400ffff }, + { 0x21001e86, 0x24000001 }, + { 0x21001e87, 0x1400ffff }, + { 0x21001e88, 0x24000001 }, + { 0x21001e89, 0x1400ffff }, + { 0x21001e8a, 0x24000001 }, + { 0x21001e8b, 0x1400ffff }, + { 0x21001e8c, 0x24000001 }, + { 0x21001e8d, 0x1400ffff }, + { 0x21001e8e, 0x24000001 }, + { 0x21001e8f, 0x1400ffff }, + { 0x21001e90, 0x24000001 }, + { 0x21001e91, 0x1400ffff }, + { 0x21001e92, 0x24000001 }, + { 0x21001e93, 0x1400ffff }, + { 0x21001e94, 0x24000001 }, + { 0x21001e95, 0x1400ffff }, + { 0x21801e96, 0x14000004 }, + { 0x21001e9b, 0x1400ffc5 }, + { 0x21001ea0, 0x24000001 }, + { 0x21001ea1, 0x1400ffff }, + { 0x21001ea2, 0x24000001 }, + { 0x21001ea3, 0x1400ffff }, + { 0x21001ea4, 0x24000001 }, + { 0x21001ea5, 0x1400ffff }, + { 0x21001ea6, 0x24000001 }, + { 0x21001ea7, 0x1400ffff }, + { 0x21001ea8, 0x24000001 }, + { 0x21001ea9, 0x1400ffff }, + { 0x21001eaa, 0x24000001 }, + { 0x21001eab, 0x1400ffff }, + { 0x21001eac, 0x24000001 }, + { 0x21001ead, 0x1400ffff }, + { 0x21001eae, 0x24000001 }, + { 0x21001eaf, 0x1400ffff }, + { 0x21001eb0, 0x24000001 }, + { 0x21001eb1, 0x1400ffff }, + { 0x21001eb2, 0x24000001 }, + { 0x21001eb3, 0x1400ffff }, + { 0x21001eb4, 0x24000001 }, + { 0x21001eb5, 0x1400ffff }, + { 0x21001eb6, 0x24000001 }, + { 0x21001eb7, 0x1400ffff }, + { 0x21001eb8, 0x24000001 }, + { 0x21001eb9, 0x1400ffff }, + { 0x21001eba, 0x24000001 }, + { 0x21001ebb, 0x1400ffff }, + { 0x21001ebc, 0x24000001 }, + { 0x21001ebd, 0x1400ffff }, + { 0x21001ebe, 0x24000001 }, + { 0x21001ebf, 0x1400ffff }, + { 0x21001ec0, 0x24000001 }, + { 0x21001ec1, 0x1400ffff }, + { 0x21001ec2, 0x24000001 }, + { 0x21001ec3, 0x1400ffff }, + { 0x21001ec4, 0x24000001 }, + { 0x21001ec5, 0x1400ffff }, + { 0x21001ec6, 0x24000001 }, + { 0x21001ec7, 0x1400ffff }, + { 0x21001ec8, 0x24000001 }, + { 0x21001ec9, 0x1400ffff }, + { 0x21001eca, 0x24000001 }, + { 0x21001ecb, 0x1400ffff }, + { 0x21001ecc, 0x24000001 }, + { 0x21001ecd, 0x1400ffff }, + { 0x21001ece, 0x24000001 }, + { 0x21001ecf, 0x1400ffff }, + { 0x21001ed0, 0x24000001 }, + { 0x21001ed1, 0x1400ffff }, + { 0x21001ed2, 0x24000001 }, + { 0x21001ed3, 0x1400ffff }, + { 0x21001ed4, 0x24000001 }, + { 0x21001ed5, 0x1400ffff }, + { 0x21001ed6, 0x24000001 }, + { 0x21001ed7, 0x1400ffff }, + { 0x21001ed8, 0x24000001 }, + { 0x21001ed9, 0x1400ffff }, + { 0x21001eda, 0x24000001 }, + { 0x21001edb, 0x1400ffff }, + { 0x21001edc, 0x24000001 }, + { 0x21001edd, 0x1400ffff }, + { 0x21001ede, 0x24000001 }, + { 0x21001edf, 0x1400ffff }, + { 0x21001ee0, 0x24000001 }, + { 0x21001ee1, 0x1400ffff }, + { 0x21001ee2, 0x24000001 }, + { 0x21001ee3, 0x1400ffff }, + { 0x21001ee4, 0x24000001 }, + { 0x21001ee5, 0x1400ffff }, + { 0x21001ee6, 0x24000001 }, + { 0x21001ee7, 0x1400ffff }, + { 0x21001ee8, 0x24000001 }, + { 0x21001ee9, 0x1400ffff }, + { 0x21001eea, 0x24000001 }, + { 0x21001eeb, 0x1400ffff }, + { 0x21001eec, 0x24000001 }, + { 0x21001eed, 0x1400ffff }, + { 0x21001eee, 0x24000001 }, + { 0x21001eef, 0x1400ffff }, + { 0x21001ef0, 0x24000001 }, + { 0x21001ef1, 0x1400ffff }, + { 0x21001ef2, 0x24000001 }, + { 0x21001ef3, 0x1400ffff }, + { 0x21001ef4, 0x24000001 }, + { 0x21001ef5, 0x1400ffff }, + { 0x21001ef6, 0x24000001 }, + { 0x21001ef7, 0x1400ffff }, + { 0x21001ef8, 0x24000001 }, + { 0x21001ef9, 0x1400ffff }, + { 0x13001f00, 0x14000008 }, + { 0x13001f01, 0x14000008 }, + { 0x13001f02, 0x14000008 }, + { 0x13001f03, 0x14000008 }, + { 0x13001f04, 0x14000008 }, + { 0x13001f05, 0x14000008 }, + { 0x13001f06, 0x14000008 }, + { 0x13001f07, 0x14000008 }, + { 0x13001f08, 0x2400fff8 }, + { 0x13001f09, 0x2400fff8 }, + { 0x13001f0a, 0x2400fff8 }, + { 0x13001f0b, 0x2400fff8 }, + { 0x13001f0c, 0x2400fff8 }, + { 0x13001f0d, 0x2400fff8 }, + { 0x13001f0e, 0x2400fff8 }, + { 0x13001f0f, 0x2400fff8 }, + { 0x13001f10, 0x14000008 }, + { 0x13001f11, 0x14000008 }, + { 0x13001f12, 0x14000008 }, + { 0x13001f13, 0x14000008 }, + { 0x13001f14, 0x14000008 }, + { 0x13001f15, 0x14000008 }, + { 0x13001f18, 0x2400fff8 }, + { 0x13001f19, 0x2400fff8 }, + { 0x13001f1a, 0x2400fff8 }, + { 0x13001f1b, 0x2400fff8 }, + { 0x13001f1c, 0x2400fff8 }, + { 0x13001f1d, 0x2400fff8 }, + { 0x13001f20, 0x14000008 }, + { 0x13001f21, 0x14000008 }, + { 0x13001f22, 0x14000008 }, + { 0x13001f23, 0x14000008 }, + { 0x13001f24, 0x14000008 }, + { 0x13001f25, 0x14000008 }, + { 0x13001f26, 0x14000008 }, + { 0x13001f27, 0x14000008 }, + { 0x13001f28, 0x2400fff8 }, + { 0x13001f29, 0x2400fff8 }, + { 0x13001f2a, 0x2400fff8 }, + { 0x13001f2b, 0x2400fff8 }, + { 0x13001f2c, 0x2400fff8 }, + { 0x13001f2d, 0x2400fff8 }, + { 0x13001f2e, 0x2400fff8 }, + { 0x13001f2f, 0x2400fff8 }, + { 0x13001f30, 0x14000008 }, + { 0x13001f31, 0x14000008 }, + { 0x13001f32, 0x14000008 }, + { 0x13001f33, 0x14000008 }, + { 0x13001f34, 0x14000008 }, + { 0x13001f35, 0x14000008 }, + { 0x13001f36, 0x14000008 }, + { 0x13001f37, 0x14000008 }, + { 0x13001f38, 0x2400fff8 }, + { 0x13001f39, 0x2400fff8 }, + { 0x13001f3a, 0x2400fff8 }, + { 0x13001f3b, 0x2400fff8 }, + { 0x13001f3c, 0x2400fff8 }, + { 0x13001f3d, 0x2400fff8 }, + { 0x13001f3e, 0x2400fff8 }, + { 0x13001f3f, 0x2400fff8 }, + { 0x13001f40, 0x14000008 }, + { 0x13001f41, 0x14000008 }, + { 0x13001f42, 0x14000008 }, + { 0x13001f43, 0x14000008 }, + { 0x13001f44, 0x14000008 }, + { 0x13001f45, 0x14000008 }, + { 0x13001f48, 0x2400fff8 }, + { 0x13001f49, 0x2400fff8 }, + { 0x13001f4a, 0x2400fff8 }, + { 0x13001f4b, 0x2400fff8 }, + { 0x13001f4c, 0x2400fff8 }, + { 0x13001f4d, 0x2400fff8 }, + { 0x13001f50, 0x14000000 }, + { 0x13001f51, 0x14000008 }, + { 0x13001f52, 0x14000000 }, + { 0x13001f53, 0x14000008 }, + { 0x13001f54, 0x14000000 }, + { 0x13001f55, 0x14000008 }, + { 0x13001f56, 0x14000000 }, + { 0x13001f57, 0x14000008 }, + { 0x13001f59, 0x2400fff8 }, + { 0x13001f5b, 0x2400fff8 }, + { 0x13001f5d, 0x2400fff8 }, + { 0x13001f5f, 0x2400fff8 }, + { 0x13001f60, 0x14000008 }, + { 0x13001f61, 0x14000008 }, + { 0x13001f62, 0x14000008 }, + { 0x13001f63, 0x14000008 }, + { 0x13001f64, 0x14000008 }, + { 0x13001f65, 0x14000008 }, + { 0x13001f66, 0x14000008 }, + { 0x13001f67, 0x14000008 }, + { 0x13001f68, 0x2400fff8 }, + { 0x13001f69, 0x2400fff8 }, + { 0x13001f6a, 0x2400fff8 }, + { 0x13001f6b, 0x2400fff8 }, + { 0x13001f6c, 0x2400fff8 }, + { 0x13001f6d, 0x2400fff8 }, + { 0x13001f6e, 0x2400fff8 }, + { 0x13001f6f, 0x2400fff8 }, + { 0x13001f70, 0x1400004a }, + { 0x13001f71, 0x1400004a }, + { 0x13001f72, 0x14000056 }, + { 0x13001f73, 0x14000056 }, + { 0x13001f74, 0x14000056 }, + { 0x13001f75, 0x14000056 }, + { 0x13001f76, 0x14000064 }, + { 0x13001f77, 0x14000064 }, + { 0x13001f78, 0x14000080 }, + { 0x13001f79, 0x14000080 }, + { 0x13001f7a, 0x14000070 }, + { 0x13001f7b, 0x14000070 }, + { 0x13001f7c, 0x1400007e }, + { 0x13001f7d, 0x1400007e }, + { 0x13001f80, 0x14000008 }, + { 0x13001f81, 0x14000008 }, + { 0x13001f82, 0x14000008 }, + { 0x13001f83, 0x14000008 }, + { 0x13001f84, 0x14000008 }, + { 0x13001f85, 0x14000008 }, + { 0x13001f86, 0x14000008 }, + { 0x13001f87, 0x14000008 }, + { 0x13001f88, 0x2000fff8 }, + { 0x13001f89, 0x2000fff8 }, + { 0x13001f8a, 0x2000fff8 }, + { 0x13001f8b, 0x2000fff8 }, + { 0x13001f8c, 0x2000fff8 }, + { 0x13001f8d, 0x2000fff8 }, + { 0x13001f8e, 0x2000fff8 }, + { 0x13001f8f, 0x2000fff8 }, + { 0x13001f90, 0x14000008 }, + { 0x13001f91, 0x14000008 }, + { 0x13001f92, 0x14000008 }, + { 0x13001f93, 0x14000008 }, + { 0x13001f94, 0x14000008 }, + { 0x13001f95, 0x14000008 }, + { 0x13001f96, 0x14000008 }, + { 0x13001f97, 0x14000008 }, + { 0x13001f98, 0x2000fff8 }, + { 0x13001f99, 0x2000fff8 }, + { 0x13001f9a, 0x2000fff8 }, + { 0x13001f9b, 0x2000fff8 }, + { 0x13001f9c, 0x2000fff8 }, + { 0x13001f9d, 0x2000fff8 }, + { 0x13001f9e, 0x2000fff8 }, + { 0x13001f9f, 0x2000fff8 }, + { 0x13001fa0, 0x14000008 }, + { 0x13001fa1, 0x14000008 }, + { 0x13001fa2, 0x14000008 }, + { 0x13001fa3, 0x14000008 }, + { 0x13001fa4, 0x14000008 }, + { 0x13001fa5, 0x14000008 }, + { 0x13001fa6, 0x14000008 }, + { 0x13001fa7, 0x14000008 }, + { 0x13001fa8, 0x2000fff8 }, + { 0x13001fa9, 0x2000fff8 }, + { 0x13001faa, 0x2000fff8 }, + { 0x13001fab, 0x2000fff8 }, + { 0x13001fac, 0x2000fff8 }, + { 0x13001fad, 0x2000fff8 }, + { 0x13001fae, 0x2000fff8 }, + { 0x13001faf, 0x2000fff8 }, + { 0x13001fb0, 0x14000008 }, + { 0x13001fb1, 0x14000008 }, + { 0x13001fb2, 0x14000000 }, + { 0x13001fb3, 0x14000009 }, + { 0x13001fb4, 0x14000000 }, + { 0x13801fb6, 0x14000001 }, + { 0x13001fb8, 0x2400fff8 }, + { 0x13001fb9, 0x2400fff8 }, + { 0x13001fba, 0x2400ffb6 }, + { 0x13001fbb, 0x2400ffb6 }, + { 0x13001fbc, 0x2000fff7 }, + { 0x13001fbd, 0x60000000 }, + { 0x13001fbe, 0x1400e3db }, + { 0x13801fbf, 0x60000002 }, + { 0x13001fc2, 0x14000000 }, + { 0x13001fc3, 0x14000009 }, + { 0x13001fc4, 0x14000000 }, + { 0x13801fc6, 0x14000001 }, + { 0x13001fc8, 0x2400ffaa }, + { 0x13001fc9, 0x2400ffaa }, + { 0x13001fca, 0x2400ffaa }, + { 0x13001fcb, 0x2400ffaa }, + { 0x13001fcc, 0x2000fff7 }, + { 0x13801fcd, 0x60000002 }, + { 0x13001fd0, 0x14000008 }, + { 0x13001fd1, 0x14000008 }, + { 0x13801fd2, 0x14000001 }, + { 0x13801fd6, 0x14000001 }, + { 0x13001fd8, 0x2400fff8 }, + { 0x13001fd9, 0x2400fff8 }, + { 0x13001fda, 0x2400ff9c }, + { 0x13001fdb, 0x2400ff9c }, + { 0x13801fdd, 0x60000002 }, + { 0x13001fe0, 0x14000008 }, + { 0x13001fe1, 0x14000008 }, + { 0x13801fe2, 0x14000002 }, + { 0x13001fe5, 0x14000007 }, + { 0x13801fe6, 0x14000001 }, + { 0x13001fe8, 0x2400fff8 }, + { 0x13001fe9, 0x2400fff8 }, + { 0x13001fea, 0x2400ff90 }, + { 0x13001feb, 0x2400ff90 }, + { 0x13001fec, 0x2400fff9 }, + { 0x13801fed, 0x60000002 }, + { 0x13001ff2, 0x14000000 }, + { 0x13001ff3, 0x14000009 }, + { 0x13001ff4, 0x14000000 }, + { 0x13801ff6, 0x14000001 }, + { 0x13001ff8, 0x2400ff80 }, + { 0x13001ff9, 0x2400ff80 }, + { 0x13001ffa, 0x2400ff82 }, + { 0x13001ffb, 0x2400ff82 }, + { 0x13001ffc, 0x2000fff7 }, + { 0x13801ffd, 0x60000001 }, + { 0x09802000, 0x7400000a }, + { 0x0980200b, 0x04000004 }, + { 0x09802010, 0x44000005 }, + { 0x09802016, 0x54000001 }, + { 0x09002018, 0x50000000 }, + { 0x09002019, 0x4c000000 }, + { 0x0900201a, 0x58000000 }, + { 0x0980201b, 0x50000001 }, + { 0x0900201d, 0x4c000000 }, + { 0x0900201e, 0x58000000 }, + { 0x0900201f, 0x50000000 }, + { 0x09802020, 0x54000007 }, + { 0x09002028, 0x6c000000 }, + { 0x09002029, 0x70000000 }, + { 0x0980202a, 0x04000004 }, + { 0x0900202f, 0x74000000 }, + { 0x09802030, 0x54000008 }, + { 0x09002039, 0x50000000 }, + { 0x0900203a, 0x4c000000 }, + { 0x0980203b, 0x54000003 }, + { 0x0980203f, 0x40000001 }, + { 0x09802041, 0x54000002 }, + { 0x09002044, 0x64000000 }, + { 0x09002045, 0x58000000 }, + { 0x09002046, 0x48000000 }, + { 0x09802047, 0x5400000a }, + { 0x09002052, 0x64000000 }, + { 0x09002053, 0x54000000 }, + { 0x09002054, 0x40000000 }, + { 0x09802055, 0x54000009 }, + { 0x0900205f, 0x74000000 }, + { 0x09802060, 0x04000003 }, + { 0x0980206a, 0x04000005 }, + { 0x09002070, 0x3c000000 }, + { 0x21002071, 0x14000000 }, + { 0x09802074, 0x3c000005 }, + { 0x0980207a, 0x64000002 }, + { 0x0900207d, 0x58000000 }, + { 0x0900207e, 0x48000000 }, + { 0x2100207f, 0x14000000 }, + { 0x09802080, 0x3c000009 }, + { 0x0980208a, 0x64000002 }, + { 0x0900208d, 0x58000000 }, + { 0x0900208e, 0x48000000 }, + { 0x21802090, 0x18000004 }, + { 0x098020a0, 0x5c000015 }, + { 0x1b8020d0, 0x3000000c }, + { 0x1b8020dd, 0x2c000003 }, + { 0x1b0020e1, 0x30000000 }, + { 0x1b8020e2, 0x2c000002 }, + { 0x1b8020e5, 0x3000000a }, + { 0x09802100, 0x68000001 }, + { 0x09002102, 0x24000000 }, + { 0x09802103, 0x68000003 }, + { 0x09002107, 0x24000000 }, + { 0x09802108, 0x68000001 }, + { 0x0900210a, 0x14000000 }, + { 0x0980210b, 0x24000002 }, + { 0x0980210e, 0x14000001 }, + { 0x09802110, 0x24000002 }, + { 0x09002113, 0x14000000 }, + { 0x09002114, 0x68000000 }, + { 0x09002115, 0x24000000 }, + { 0x09802116, 0x68000002 }, + { 0x09802119, 0x24000004 }, + { 0x0980211e, 0x68000005 }, + { 0x09002124, 0x24000000 }, + { 0x09002125, 0x68000000 }, + { 0x13002126, 0x2400e2a3 }, + { 0x09002127, 0x68000000 }, + { 0x09002128, 0x24000000 }, + { 0x09002129, 0x68000000 }, + { 0x2100212a, 0x2400df41 }, + { 0x2100212b, 0x2400dfba }, + { 0x0980212c, 0x24000001 }, + { 0x0900212e, 0x68000000 }, + { 0x0900212f, 0x14000000 }, + { 0x09802130, 0x24000001 }, + { 0x21002132, 0x2400001c }, + { 0x09002133, 0x24000000 }, + { 0x09002134, 0x14000000 }, + { 0x09802135, 0x1c000003 }, + { 0x09002139, 0x14000000 }, + { 0x0980213a, 0x68000001 }, + { 0x0980213c, 0x14000001 }, + { 0x0980213e, 0x24000001 }, + { 0x09802140, 0x64000004 }, + { 0x09002145, 0x24000000 }, + { 0x09802146, 0x14000003 }, + { 0x0900214a, 0x68000000 }, + { 0x0900214b, 0x64000000 }, + { 0x0980214c, 0x68000001 }, + { 0x2100214e, 0x1400ffe4 }, + { 0x09802153, 0x3c00000c }, + { 0x09002160, 0x38000010 }, + { 0x09002161, 0x38000010 }, + { 0x09002162, 0x38000010 }, + { 0x09002163, 0x38000010 }, + { 0x09002164, 0x38000010 }, + { 0x09002165, 0x38000010 }, + { 0x09002166, 0x38000010 }, + { 0x09002167, 0x38000010 }, + { 0x09002168, 0x38000010 }, + { 0x09002169, 0x38000010 }, + { 0x0900216a, 0x38000010 }, + { 0x0900216b, 0x38000010 }, + { 0x0900216c, 0x38000010 }, + { 0x0900216d, 0x38000010 }, + { 0x0900216e, 0x38000010 }, + { 0x0900216f, 0x38000010 }, + { 0x09002170, 0x3800fff0 }, + { 0x09002171, 0x3800fff0 }, + { 0x09002172, 0x3800fff0 }, + { 0x09002173, 0x3800fff0 }, + { 0x09002174, 0x3800fff0 }, + { 0x09002175, 0x3800fff0 }, + { 0x09002176, 0x3800fff0 }, + { 0x09002177, 0x3800fff0 }, + { 0x09002178, 0x3800fff0 }, + { 0x09002179, 0x3800fff0 }, + { 0x0900217a, 0x3800fff0 }, + { 0x0900217b, 0x3800fff0 }, + { 0x0900217c, 0x3800fff0 }, + { 0x0900217d, 0x3800fff0 }, + { 0x0900217e, 0x3800fff0 }, + { 0x0900217f, 0x3800fff0 }, + { 0x09802180, 0x38000002 }, + { 0x09002183, 0x24000001 }, + { 0x21002184, 0x1400ffff }, + { 0x09802190, 0x64000004 }, + { 0x09802195, 0x68000004 }, + { 0x0980219a, 0x64000001 }, + { 0x0980219c, 0x68000003 }, + { 0x090021a0, 0x64000000 }, + { 0x098021a1, 0x68000001 }, + { 0x090021a3, 0x64000000 }, + { 0x098021a4, 0x68000001 }, + { 0x090021a6, 0x64000000 }, + { 0x098021a7, 0x68000006 }, + { 0x090021ae, 0x64000000 }, + { 0x098021af, 0x6800001e }, + { 0x098021ce, 0x64000001 }, + { 0x098021d0, 0x68000001 }, + { 0x090021d2, 0x64000000 }, + { 0x090021d3, 0x68000000 }, + { 0x090021d4, 0x64000000 }, + { 0x098021d5, 0x6800001e }, + { 0x098021f4, 0x6400010b }, + { 0x09802300, 0x68000007 }, + { 0x09802308, 0x64000003 }, + { 0x0980230c, 0x68000013 }, + { 0x09802320, 0x64000001 }, + { 0x09802322, 0x68000006 }, + { 0x09002329, 0x58000000 }, + { 0x0900232a, 0x48000000 }, + { 0x0980232b, 0x68000050 }, + { 0x0900237c, 0x64000000 }, + { 0x0980237d, 0x6800001d }, + { 0x0980239b, 0x64000018 }, + { 0x098023b4, 0x68000027 }, + { 0x098023dc, 0x64000005 }, + { 0x098023e2, 0x68000005 }, + { 0x09802400, 0x68000026 }, + { 0x09802440, 0x6800000a }, + { 0x09802460, 0x3c00003b }, + { 0x0980249c, 0x68000019 }, + { 0x090024b6, 0x6800001a }, + { 0x090024b7, 0x6800001a }, + { 0x090024b8, 0x6800001a }, + { 0x090024b9, 0x6800001a }, + { 0x090024ba, 0x6800001a }, + { 0x090024bb, 0x6800001a }, + { 0x090024bc, 0x6800001a }, + { 0x090024bd, 0x6800001a }, + { 0x090024be, 0x6800001a }, + { 0x090024bf, 0x6800001a }, + { 0x090024c0, 0x6800001a }, + { 0x090024c1, 0x6800001a }, + { 0x090024c2, 0x6800001a }, + { 0x090024c3, 0x6800001a }, + { 0x090024c4, 0x6800001a }, + { 0x090024c5, 0x6800001a }, + { 0x090024c6, 0x6800001a }, + { 0x090024c7, 0x6800001a }, + { 0x090024c8, 0x6800001a }, + { 0x090024c9, 0x6800001a }, + { 0x090024ca, 0x6800001a }, + { 0x090024cb, 0x6800001a }, + { 0x090024cc, 0x6800001a }, + { 0x090024cd, 0x6800001a }, + { 0x090024ce, 0x6800001a }, + { 0x090024cf, 0x6800001a }, + { 0x090024d0, 0x6800ffe6 }, + { 0x090024d1, 0x6800ffe6 }, + { 0x090024d2, 0x6800ffe6 }, + { 0x090024d3, 0x6800ffe6 }, + { 0x090024d4, 0x6800ffe6 }, + { 0x090024d5, 0x6800ffe6 }, + { 0x090024d6, 0x6800ffe6 }, + { 0x090024d7, 0x6800ffe6 }, + { 0x090024d8, 0x6800ffe6 }, + { 0x090024d9, 0x6800ffe6 }, + { 0x090024da, 0x6800ffe6 }, + { 0x090024db, 0x6800ffe6 }, + { 0x090024dc, 0x6800ffe6 }, + { 0x090024dd, 0x6800ffe6 }, + { 0x090024de, 0x6800ffe6 }, + { 0x090024df, 0x6800ffe6 }, + { 0x090024e0, 0x6800ffe6 }, + { 0x090024e1, 0x6800ffe6 }, + { 0x090024e2, 0x6800ffe6 }, + { 0x090024e3, 0x6800ffe6 }, + { 0x090024e4, 0x6800ffe6 }, + { 0x090024e5, 0x6800ffe6 }, + { 0x090024e6, 0x6800ffe6 }, + { 0x090024e7, 0x6800ffe6 }, + { 0x090024e8, 0x6800ffe6 }, + { 0x090024e9, 0x6800ffe6 }, + { 0x098024ea, 0x3c000015 }, + { 0x09802500, 0x680000b6 }, + { 0x090025b7, 0x64000000 }, + { 0x098025b8, 0x68000008 }, + { 0x090025c1, 0x64000000 }, + { 0x098025c2, 0x68000035 }, + { 0x098025f8, 0x64000007 }, + { 0x09802600, 0x6800006e }, + { 0x0900266f, 0x64000000 }, + { 0x09802670, 0x6800002c }, + { 0x098026a0, 0x68000012 }, + { 0x09802701, 0x68000003 }, + { 0x09802706, 0x68000003 }, + { 0x0980270c, 0x6800001b }, + { 0x09802729, 0x68000022 }, + { 0x0900274d, 0x68000000 }, + { 0x0980274f, 0x68000003 }, + { 0x09002756, 0x68000000 }, + { 0x09802758, 0x68000006 }, + { 0x09802761, 0x68000006 }, + { 0x09002768, 0x58000000 }, + { 0x09002769, 0x48000000 }, + { 0x0900276a, 0x58000000 }, + { 0x0900276b, 0x48000000 }, + { 0x0900276c, 0x58000000 }, + { 0x0900276d, 0x48000000 }, + { 0x0900276e, 0x58000000 }, + { 0x0900276f, 0x48000000 }, + { 0x09002770, 0x58000000 }, + { 0x09002771, 0x48000000 }, + { 0x09002772, 0x58000000 }, + { 0x09002773, 0x48000000 }, + { 0x09002774, 0x58000000 }, + { 0x09002775, 0x48000000 }, + { 0x09802776, 0x3c00001d }, + { 0x09002794, 0x68000000 }, + { 0x09802798, 0x68000017 }, + { 0x098027b1, 0x6800000d }, + { 0x098027c0, 0x64000004 }, + { 0x090027c5, 0x58000000 }, + { 0x090027c6, 0x48000000 }, + { 0x098027c7, 0x64000003 }, + { 0x098027d0, 0x64000015 }, + { 0x090027e6, 0x58000000 }, + { 0x090027e7, 0x48000000 }, + { 0x090027e8, 0x58000000 }, + { 0x090027e9, 0x48000000 }, + { 0x090027ea, 0x58000000 }, + { 0x090027eb, 0x48000000 }, + { 0x098027f0, 0x6400000f }, + { 0x04802800, 0x680000ff }, + { 0x09802900, 0x64000082 }, + { 0x09002983, 0x58000000 }, + { 0x09002984, 0x48000000 }, + { 0x09002985, 0x58000000 }, + { 0x09002986, 0x48000000 }, + { 0x09002987, 0x58000000 }, + { 0x09002988, 0x48000000 }, + { 0x09002989, 0x58000000 }, + { 0x0900298a, 0x48000000 }, + { 0x0900298b, 0x58000000 }, + { 0x0900298c, 0x48000000 }, + { 0x0900298d, 0x58000000 }, + { 0x0900298e, 0x48000000 }, + { 0x0900298f, 0x58000000 }, + { 0x09002990, 0x48000000 }, + { 0x09002991, 0x58000000 }, + { 0x09002992, 0x48000000 }, + { 0x09002993, 0x58000000 }, + { 0x09002994, 0x48000000 }, + { 0x09002995, 0x58000000 }, + { 0x09002996, 0x48000000 }, + { 0x09002997, 0x58000000 }, + { 0x09002998, 0x48000000 }, + { 0x09802999, 0x6400003e }, + { 0x090029d8, 0x58000000 }, + { 0x090029d9, 0x48000000 }, + { 0x090029da, 0x58000000 }, + { 0x090029db, 0x48000000 }, + { 0x098029dc, 0x6400001f }, + { 0x090029fc, 0x58000000 }, + { 0x090029fd, 0x48000000 }, + { 0x098029fe, 0x64000101 }, + { 0x09802b00, 0x6800001a }, + { 0x09802b20, 0x68000003 }, + { 0x11002c00, 0x24000030 }, + { 0x11002c01, 0x24000030 }, + { 0x11002c02, 0x24000030 }, + { 0x11002c03, 0x24000030 }, + { 0x11002c04, 0x24000030 }, + { 0x11002c05, 0x24000030 }, + { 0x11002c06, 0x24000030 }, + { 0x11002c07, 0x24000030 }, + { 0x11002c08, 0x24000030 }, + { 0x11002c09, 0x24000030 }, + { 0x11002c0a, 0x24000030 }, + { 0x11002c0b, 0x24000030 }, + { 0x11002c0c, 0x24000030 }, + { 0x11002c0d, 0x24000030 }, + { 0x11002c0e, 0x24000030 }, + { 0x11002c0f, 0x24000030 }, + { 0x11002c10, 0x24000030 }, + { 0x11002c11, 0x24000030 }, + { 0x11002c12, 0x24000030 }, + { 0x11002c13, 0x24000030 }, + { 0x11002c14, 0x24000030 }, + { 0x11002c15, 0x24000030 }, + { 0x11002c16, 0x24000030 }, + { 0x11002c17, 0x24000030 }, + { 0x11002c18, 0x24000030 }, + { 0x11002c19, 0x24000030 }, + { 0x11002c1a, 0x24000030 }, + { 0x11002c1b, 0x24000030 }, + { 0x11002c1c, 0x24000030 }, + { 0x11002c1d, 0x24000030 }, + { 0x11002c1e, 0x24000030 }, + { 0x11002c1f, 0x24000030 }, + { 0x11002c20, 0x24000030 }, + { 0x11002c21, 0x24000030 }, + { 0x11002c22, 0x24000030 }, + { 0x11002c23, 0x24000030 }, + { 0x11002c24, 0x24000030 }, + { 0x11002c25, 0x24000030 }, + { 0x11002c26, 0x24000030 }, + { 0x11002c27, 0x24000030 }, + { 0x11002c28, 0x24000030 }, + { 0x11002c29, 0x24000030 }, + { 0x11002c2a, 0x24000030 }, + { 0x11002c2b, 0x24000030 }, + { 0x11002c2c, 0x24000030 }, + { 0x11002c2d, 0x24000030 }, + { 0x11002c2e, 0x24000030 }, + { 0x11002c30, 0x1400ffd0 }, + { 0x11002c31, 0x1400ffd0 }, + { 0x11002c32, 0x1400ffd0 }, + { 0x11002c33, 0x1400ffd0 }, + { 0x11002c34, 0x1400ffd0 }, + { 0x11002c35, 0x1400ffd0 }, + { 0x11002c36, 0x1400ffd0 }, + { 0x11002c37, 0x1400ffd0 }, + { 0x11002c38, 0x1400ffd0 }, + { 0x11002c39, 0x1400ffd0 }, + { 0x11002c3a, 0x1400ffd0 }, + { 0x11002c3b, 0x1400ffd0 }, + { 0x11002c3c, 0x1400ffd0 }, + { 0x11002c3d, 0x1400ffd0 }, + { 0x11002c3e, 0x1400ffd0 }, + { 0x11002c3f, 0x1400ffd0 }, + { 0x11002c40, 0x1400ffd0 }, + { 0x11002c41, 0x1400ffd0 }, + { 0x11002c42, 0x1400ffd0 }, + { 0x11002c43, 0x1400ffd0 }, + { 0x11002c44, 0x1400ffd0 }, + { 0x11002c45, 0x1400ffd0 }, + { 0x11002c46, 0x1400ffd0 }, + { 0x11002c47, 0x1400ffd0 }, + { 0x11002c48, 0x1400ffd0 }, + { 0x11002c49, 0x1400ffd0 }, + { 0x11002c4a, 0x1400ffd0 }, + { 0x11002c4b, 0x1400ffd0 }, + { 0x11002c4c, 0x1400ffd0 }, + { 0x11002c4d, 0x1400ffd0 }, + { 0x11002c4e, 0x1400ffd0 }, + { 0x11002c4f, 0x1400ffd0 }, + { 0x11002c50, 0x1400ffd0 }, + { 0x11002c51, 0x1400ffd0 }, + { 0x11002c52, 0x1400ffd0 }, + { 0x11002c53, 0x1400ffd0 }, + { 0x11002c54, 0x1400ffd0 }, + { 0x11002c55, 0x1400ffd0 }, + { 0x11002c56, 0x1400ffd0 }, + { 0x11002c57, 0x1400ffd0 }, + { 0x11002c58, 0x1400ffd0 }, + { 0x11002c59, 0x1400ffd0 }, + { 0x11002c5a, 0x1400ffd0 }, + { 0x11002c5b, 0x1400ffd0 }, + { 0x11002c5c, 0x1400ffd0 }, + { 0x11002c5d, 0x1400ffd0 }, + { 0x11002c5e, 0x1400ffd0 }, + { 0x21002c60, 0x24000001 }, + { 0x21002c61, 0x1400ffff }, + { 0x21002c62, 0x2400d609 }, + { 0x21002c63, 0x2400f11a }, + { 0x21002c64, 0x2400d619 }, + { 0x21002c65, 0x1400d5d5 }, + { 0x21002c66, 0x1400d5d8 }, + { 0x21002c67, 0x24000001 }, + { 0x21002c68, 0x1400ffff }, + { 0x21002c69, 0x24000001 }, + { 0x21002c6a, 0x1400ffff }, + { 0x21002c6b, 0x24000001 }, + { 0x21002c6c, 0x1400ffff }, + { 0x21002c74, 0x14000000 }, + { 0x21002c75, 0x24000001 }, + { 0x21002c76, 0x1400ffff }, + { 0x21002c77, 0x14000000 }, + { 0x0a002c80, 0x24000001 }, + { 0x0a002c81, 0x1400ffff }, + { 0x0a002c82, 0x24000001 }, + { 0x0a002c83, 0x1400ffff }, + { 0x0a002c84, 0x24000001 }, + { 0x0a002c85, 0x1400ffff }, + { 0x0a002c86, 0x24000001 }, + { 0x0a002c87, 0x1400ffff }, + { 0x0a002c88, 0x24000001 }, + { 0x0a002c89, 0x1400ffff }, + { 0x0a002c8a, 0x24000001 }, + { 0x0a002c8b, 0x1400ffff }, + { 0x0a002c8c, 0x24000001 }, + { 0x0a002c8d, 0x1400ffff }, + { 0x0a002c8e, 0x24000001 }, + { 0x0a002c8f, 0x1400ffff }, + { 0x0a002c90, 0x24000001 }, + { 0x0a002c91, 0x1400ffff }, + { 0x0a002c92, 0x24000001 }, + { 0x0a002c93, 0x1400ffff }, + { 0x0a002c94, 0x24000001 }, + { 0x0a002c95, 0x1400ffff }, + { 0x0a002c96, 0x24000001 }, + { 0x0a002c97, 0x1400ffff }, + { 0x0a002c98, 0x24000001 }, + { 0x0a002c99, 0x1400ffff }, + { 0x0a002c9a, 0x24000001 }, + { 0x0a002c9b, 0x1400ffff }, + { 0x0a002c9c, 0x24000001 }, + { 0x0a002c9d, 0x1400ffff }, + { 0x0a002c9e, 0x24000001 }, + { 0x0a002c9f, 0x1400ffff }, + { 0x0a002ca0, 0x24000001 }, + { 0x0a002ca1, 0x1400ffff }, + { 0x0a002ca2, 0x24000001 }, + { 0x0a002ca3, 0x1400ffff }, + { 0x0a002ca4, 0x24000001 }, + { 0x0a002ca5, 0x1400ffff }, + { 0x0a002ca6, 0x24000001 }, + { 0x0a002ca7, 0x1400ffff }, + { 0x0a002ca8, 0x24000001 }, + { 0x0a002ca9, 0x1400ffff }, + { 0x0a002caa, 0x24000001 }, + { 0x0a002cab, 0x1400ffff }, + { 0x0a002cac, 0x24000001 }, + { 0x0a002cad, 0x1400ffff }, + { 0x0a002cae, 0x24000001 }, + { 0x0a002caf, 0x1400ffff }, + { 0x0a002cb0, 0x24000001 }, + { 0x0a002cb1, 0x1400ffff }, + { 0x0a002cb2, 0x24000001 }, + { 0x0a002cb3, 0x1400ffff }, + { 0x0a002cb4, 0x24000001 }, + { 0x0a002cb5, 0x1400ffff }, + { 0x0a002cb6, 0x24000001 }, + { 0x0a002cb7, 0x1400ffff }, + { 0x0a002cb8, 0x24000001 }, + { 0x0a002cb9, 0x1400ffff }, + { 0x0a002cba, 0x24000001 }, + { 0x0a002cbb, 0x1400ffff }, + { 0x0a002cbc, 0x24000001 }, + { 0x0a002cbd, 0x1400ffff }, + { 0x0a002cbe, 0x24000001 }, + { 0x0a002cbf, 0x1400ffff }, + { 0x0a002cc0, 0x24000001 }, + { 0x0a002cc1, 0x1400ffff }, + { 0x0a002cc2, 0x24000001 }, + { 0x0a002cc3, 0x1400ffff }, + { 0x0a002cc4, 0x24000001 }, + { 0x0a002cc5, 0x1400ffff }, + { 0x0a002cc6, 0x24000001 }, + { 0x0a002cc7, 0x1400ffff }, + { 0x0a002cc8, 0x24000001 }, + { 0x0a002cc9, 0x1400ffff }, + { 0x0a002cca, 0x24000001 }, + { 0x0a002ccb, 0x1400ffff }, + { 0x0a002ccc, 0x24000001 }, + { 0x0a002ccd, 0x1400ffff }, + { 0x0a002cce, 0x24000001 }, + { 0x0a002ccf, 0x1400ffff }, + { 0x0a002cd0, 0x24000001 }, + { 0x0a002cd1, 0x1400ffff }, + { 0x0a002cd2, 0x24000001 }, + { 0x0a002cd3, 0x1400ffff }, + { 0x0a002cd4, 0x24000001 }, + { 0x0a002cd5, 0x1400ffff }, + { 0x0a002cd6, 0x24000001 }, + { 0x0a002cd7, 0x1400ffff }, + { 0x0a002cd8, 0x24000001 }, + { 0x0a002cd9, 0x1400ffff }, + { 0x0a002cda, 0x24000001 }, + { 0x0a002cdb, 0x1400ffff }, + { 0x0a002cdc, 0x24000001 }, + { 0x0a002cdd, 0x1400ffff }, + { 0x0a002cde, 0x24000001 }, + { 0x0a002cdf, 0x1400ffff }, + { 0x0a002ce0, 0x24000001 }, + { 0x0a002ce1, 0x1400ffff }, + { 0x0a002ce2, 0x24000001 }, + { 0x0a002ce3, 0x1400ffff }, + { 0x0a002ce4, 0x14000000 }, + { 0x0a802ce5, 0x68000005 }, + { 0x0a802cf9, 0x54000003 }, + { 0x0a002cfd, 0x3c000000 }, + { 0x0a802cfe, 0x54000001 }, + { 0x10002d00, 0x1400e3a0 }, + { 0x10002d01, 0x1400e3a0 }, + { 0x10002d02, 0x1400e3a0 }, + { 0x10002d03, 0x1400e3a0 }, + { 0x10002d04, 0x1400e3a0 }, + { 0x10002d05, 0x1400e3a0 }, + { 0x10002d06, 0x1400e3a0 }, + { 0x10002d07, 0x1400e3a0 }, + { 0x10002d08, 0x1400e3a0 }, + { 0x10002d09, 0x1400e3a0 }, + { 0x10002d0a, 0x1400e3a0 }, + { 0x10002d0b, 0x1400e3a0 }, + { 0x10002d0c, 0x1400e3a0 }, + { 0x10002d0d, 0x1400e3a0 }, + { 0x10002d0e, 0x1400e3a0 }, + { 0x10002d0f, 0x1400e3a0 }, + { 0x10002d10, 0x1400e3a0 }, + { 0x10002d11, 0x1400e3a0 }, + { 0x10002d12, 0x1400e3a0 }, + { 0x10002d13, 0x1400e3a0 }, + { 0x10002d14, 0x1400e3a0 }, + { 0x10002d15, 0x1400e3a0 }, + { 0x10002d16, 0x1400e3a0 }, + { 0x10002d17, 0x1400e3a0 }, + { 0x10002d18, 0x1400e3a0 }, + { 0x10002d19, 0x1400e3a0 }, + { 0x10002d1a, 0x1400e3a0 }, + { 0x10002d1b, 0x1400e3a0 }, + { 0x10002d1c, 0x1400e3a0 }, + { 0x10002d1d, 0x1400e3a0 }, + { 0x10002d1e, 0x1400e3a0 }, + { 0x10002d1f, 0x1400e3a0 }, + { 0x10002d20, 0x1400e3a0 }, + { 0x10002d21, 0x1400e3a0 }, + { 0x10002d22, 0x1400e3a0 }, + { 0x10002d23, 0x1400e3a0 }, + { 0x10002d24, 0x1400e3a0 }, + { 0x10002d25, 0x1400e3a0 }, + { 0x3a802d30, 0x1c000035 }, + { 0x3a002d6f, 0x18000000 }, + { 0x0f802d80, 0x1c000016 }, + { 0x0f802da0, 0x1c000006 }, + { 0x0f802da8, 0x1c000006 }, + { 0x0f802db0, 0x1c000006 }, + { 0x0f802db8, 0x1c000006 }, + { 0x0f802dc0, 0x1c000006 }, + { 0x0f802dc8, 0x1c000006 }, + { 0x0f802dd0, 0x1c000006 }, + { 0x0f802dd8, 0x1c000006 }, + { 0x09802e00, 0x54000001 }, + { 0x09002e02, 0x50000000 }, + { 0x09002e03, 0x4c000000 }, + { 0x09002e04, 0x50000000 }, + { 0x09002e05, 0x4c000000 }, + { 0x09802e06, 0x54000002 }, + { 0x09002e09, 0x50000000 }, + { 0x09002e0a, 0x4c000000 }, + { 0x09002e0b, 0x54000000 }, + { 0x09002e0c, 0x50000000 }, + { 0x09002e0d, 0x4c000000 }, + { 0x09802e0e, 0x54000008 }, + { 0x09002e17, 0x44000000 }, + { 0x09002e1c, 0x50000000 }, + { 0x09002e1d, 0x4c000000 }, + { 0x16802e80, 0x68000019 }, + { 0x16802e9b, 0x68000058 }, + { 0x16802f00, 0x680000d5 }, + { 0x09802ff0, 0x6800000b }, + { 0x09003000, 0x74000000 }, + { 0x09803001, 0x54000002 }, + { 0x09003004, 0x68000000 }, + { 0x16003005, 0x18000000 }, + { 0x09003006, 0x1c000000 }, + { 0x16003007, 0x38000000 }, + { 0x09003008, 0x58000000 }, + { 0x09003009, 0x48000000 }, + { 0x0900300a, 0x58000000 }, + { 0x0900300b, 0x48000000 }, + { 0x0900300c, 0x58000000 }, + { 0x0900300d, 0x48000000 }, + { 0x0900300e, 0x58000000 }, + { 0x0900300f, 0x48000000 }, + { 0x09003010, 0x58000000 }, + { 0x09003011, 0x48000000 }, + { 0x09803012, 0x68000001 }, + { 0x09003014, 0x58000000 }, + { 0x09003015, 0x48000000 }, + { 0x09003016, 0x58000000 }, + { 0x09003017, 0x48000000 }, + { 0x09003018, 0x58000000 }, + { 0x09003019, 0x48000000 }, + { 0x0900301a, 0x58000000 }, + { 0x0900301b, 0x48000000 }, + { 0x0900301c, 0x44000000 }, + { 0x0900301d, 0x58000000 }, + { 0x0980301e, 0x48000001 }, + { 0x09003020, 0x68000000 }, + { 0x16803021, 0x38000008 }, + { 0x1b80302a, 0x30000005 }, + { 0x09003030, 0x44000000 }, + { 0x09803031, 0x18000004 }, + { 0x09803036, 0x68000001 }, + { 0x16803038, 0x38000002 }, + { 0x1600303b, 0x18000000 }, + { 0x0900303c, 0x1c000000 }, + { 0x0900303d, 0x54000000 }, + { 0x0980303e, 0x68000001 }, + { 0x1a803041, 0x1c000055 }, + { 0x1b803099, 0x30000001 }, + { 0x0980309b, 0x60000001 }, + { 0x1a80309d, 0x18000001 }, + { 0x1a00309f, 0x1c000000 }, + { 0x090030a0, 0x44000000 }, + { 0x1d8030a1, 0x1c000059 }, + { 0x090030fb, 0x54000000 }, + { 0x098030fc, 0x18000002 }, + { 0x1d0030ff, 0x1c000000 }, + { 0x03803105, 0x1c000027 }, + { 0x17803131, 0x1c00005d }, + { 0x09803190, 0x68000001 }, + { 0x09803192, 0x3c000003 }, + { 0x09803196, 0x68000009 }, + { 0x038031a0, 0x1c000017 }, + { 0x098031c0, 0x6800000f }, + { 0x1d8031f0, 0x1c00000f }, + { 0x17803200, 0x6800001e }, + { 0x09803220, 0x3c000009 }, + { 0x0980322a, 0x68000019 }, + { 0x09003250, 0x68000000 }, + { 0x09803251, 0x3c00000e }, + { 0x17803260, 0x6800001f }, + { 0x09803280, 0x3c000009 }, + { 0x0980328a, 0x68000026 }, + { 0x098032b1, 0x3c00000e }, + { 0x098032c0, 0x6800003e }, + { 0x09803300, 0x680000ff }, + { 0x16803400, 0x1c0019b5 }, + { 0x09804dc0, 0x6800003f }, + { 0x16804e00, 0x1c0051bb }, + { 0x3c80a000, 0x1c000014 }, + { 0x3c00a015, 0x18000000 }, + { 0x3c80a016, 0x1c000476 }, + { 0x3c80a490, 0x68000036 }, + { 0x0980a700, 0x60000016 }, + { 0x0980a717, 0x18000003 }, + { 0x0980a720, 0x60000001 }, + { 0x3080a800, 0x1c000001 }, + { 0x3000a802, 0x28000000 }, + { 0x3080a803, 0x1c000002 }, + { 0x3000a806, 0x30000000 }, + { 0x3080a807, 0x1c000003 }, + { 0x3000a80b, 0x30000000 }, + { 0x3080a80c, 0x1c000016 }, + { 0x3080a823, 0x28000001 }, + { 0x3080a825, 0x30000001 }, + { 0x3000a827, 0x28000000 }, + { 0x3080a828, 0x68000003 }, + { 0x4080a840, 0x1c000033 }, + { 0x4080a874, 0x54000003 }, + { 0x1780ac00, 0x1c002ba3 }, + { 0x0980d800, 0x1000037f }, + { 0x0980db80, 0x1000007f }, + { 0x0980dc00, 0x100003ff }, + { 0x0980e000, 0x0c0018ff }, + { 0x1680f900, 0x1c00012d }, + { 0x1680fa30, 0x1c00003a }, + { 0x1680fa70, 0x1c000069 }, + { 0x2180fb00, 0x14000006 }, + { 0x0180fb13, 0x14000004 }, + { 0x1900fb1d, 0x1c000000 }, + { 0x1900fb1e, 0x30000000 }, + { 0x1980fb1f, 0x1c000009 }, + { 0x1900fb29, 0x64000000 }, + { 0x1980fb2a, 0x1c00000c }, + { 0x1980fb38, 0x1c000004 }, + { 0x1900fb3e, 0x1c000000 }, + { 0x1980fb40, 0x1c000001 }, + { 0x1980fb43, 0x1c000001 }, + { 0x1980fb46, 0x1c00006b }, + { 0x0080fbd3, 0x1c00016a }, + { 0x0900fd3e, 0x58000000 }, + { 0x0900fd3f, 0x48000000 }, + { 0x0080fd50, 0x1c00003f }, + { 0x0080fd92, 0x1c000035 }, + { 0x0080fdf0, 0x1c00000b }, + { 0x0000fdfc, 0x5c000000 }, + { 0x0900fdfd, 0x68000000 }, + { 0x1b80fe00, 0x3000000f }, + { 0x0980fe10, 0x54000006 }, + { 0x0900fe17, 0x58000000 }, + { 0x0900fe18, 0x48000000 }, + { 0x0900fe19, 0x54000000 }, + { 0x1b80fe20, 0x30000003 }, + { 0x0900fe30, 0x54000000 }, + { 0x0980fe31, 0x44000001 }, + { 0x0980fe33, 0x40000001 }, + { 0x0900fe35, 0x58000000 }, + { 0x0900fe36, 0x48000000 }, + { 0x0900fe37, 0x58000000 }, + { 0x0900fe38, 0x48000000 }, + { 0x0900fe39, 0x58000000 }, + { 0x0900fe3a, 0x48000000 }, + { 0x0900fe3b, 0x58000000 }, + { 0x0900fe3c, 0x48000000 }, + { 0x0900fe3d, 0x58000000 }, + { 0x0900fe3e, 0x48000000 }, + { 0x0900fe3f, 0x58000000 }, + { 0x0900fe40, 0x48000000 }, + { 0x0900fe41, 0x58000000 }, + { 0x0900fe42, 0x48000000 }, + { 0x0900fe43, 0x58000000 }, + { 0x0900fe44, 0x48000000 }, + { 0x0980fe45, 0x54000001 }, + { 0x0900fe47, 0x58000000 }, + { 0x0900fe48, 0x48000000 }, + { 0x0980fe49, 0x54000003 }, + { 0x0980fe4d, 0x40000002 }, + { 0x0980fe50, 0x54000002 }, + { 0x0980fe54, 0x54000003 }, + { 0x0900fe58, 0x44000000 }, + { 0x0900fe59, 0x58000000 }, + { 0x0900fe5a, 0x48000000 }, + { 0x0900fe5b, 0x58000000 }, + { 0x0900fe5c, 0x48000000 }, + { 0x0900fe5d, 0x58000000 }, + { 0x0900fe5e, 0x48000000 }, + { 0x0980fe5f, 0x54000002 }, + { 0x0900fe62, 0x64000000 }, + { 0x0900fe63, 0x44000000 }, + { 0x0980fe64, 0x64000002 }, + { 0x0900fe68, 0x54000000 }, + { 0x0900fe69, 0x5c000000 }, + { 0x0980fe6a, 0x54000001 }, + { 0x0080fe70, 0x1c000004 }, + { 0x0080fe76, 0x1c000086 }, + { 0x0900feff, 0x04000000 }, + { 0x0980ff01, 0x54000002 }, + { 0x0900ff04, 0x5c000000 }, + { 0x0980ff05, 0x54000002 }, + { 0x0900ff08, 0x58000000 }, + { 0x0900ff09, 0x48000000 }, + { 0x0900ff0a, 0x54000000 }, + { 0x0900ff0b, 0x64000000 }, + { 0x0900ff0c, 0x54000000 }, + { 0x0900ff0d, 0x44000000 }, + { 0x0980ff0e, 0x54000001 }, + { 0x0980ff10, 0x34000009 }, + { 0x0980ff1a, 0x54000001 }, + { 0x0980ff1c, 0x64000002 }, + { 0x0980ff1f, 0x54000001 }, + { 0x2100ff21, 0x24000020 }, + { 0x2100ff22, 0x24000020 }, + { 0x2100ff23, 0x24000020 }, + { 0x2100ff24, 0x24000020 }, + { 0x2100ff25, 0x24000020 }, + { 0x2100ff26, 0x24000020 }, + { 0x2100ff27, 0x24000020 }, + { 0x2100ff28, 0x24000020 }, + { 0x2100ff29, 0x24000020 }, + { 0x2100ff2a, 0x24000020 }, + { 0x2100ff2b, 0x24000020 }, + { 0x2100ff2c, 0x24000020 }, + { 0x2100ff2d, 0x24000020 }, + { 0x2100ff2e, 0x24000020 }, + { 0x2100ff2f, 0x24000020 }, + { 0x2100ff30, 0x24000020 }, + { 0x2100ff31, 0x24000020 }, + { 0x2100ff32, 0x24000020 }, + { 0x2100ff33, 0x24000020 }, + { 0x2100ff34, 0x24000020 }, + { 0x2100ff35, 0x24000020 }, + { 0x2100ff36, 0x24000020 }, + { 0x2100ff37, 0x24000020 }, + { 0x2100ff38, 0x24000020 }, + { 0x2100ff39, 0x24000020 }, + { 0x2100ff3a, 0x24000020 }, + { 0x0900ff3b, 0x58000000 }, + { 0x0900ff3c, 0x54000000 }, + { 0x0900ff3d, 0x48000000 }, + { 0x0900ff3e, 0x60000000 }, + { 0x0900ff3f, 0x40000000 }, + { 0x0900ff40, 0x60000000 }, + { 0x2100ff41, 0x1400ffe0 }, + { 0x2100ff42, 0x1400ffe0 }, + { 0x2100ff43, 0x1400ffe0 }, + { 0x2100ff44, 0x1400ffe0 }, + { 0x2100ff45, 0x1400ffe0 }, + { 0x2100ff46, 0x1400ffe0 }, + { 0x2100ff47, 0x1400ffe0 }, + { 0x2100ff48, 0x1400ffe0 }, + { 0x2100ff49, 0x1400ffe0 }, + { 0x2100ff4a, 0x1400ffe0 }, + { 0x2100ff4b, 0x1400ffe0 }, + { 0x2100ff4c, 0x1400ffe0 }, + { 0x2100ff4d, 0x1400ffe0 }, + { 0x2100ff4e, 0x1400ffe0 }, + { 0x2100ff4f, 0x1400ffe0 }, + { 0x2100ff50, 0x1400ffe0 }, + { 0x2100ff51, 0x1400ffe0 }, + { 0x2100ff52, 0x1400ffe0 }, + { 0x2100ff53, 0x1400ffe0 }, + { 0x2100ff54, 0x1400ffe0 }, + { 0x2100ff55, 0x1400ffe0 }, + { 0x2100ff56, 0x1400ffe0 }, + { 0x2100ff57, 0x1400ffe0 }, + { 0x2100ff58, 0x1400ffe0 }, + { 0x2100ff59, 0x1400ffe0 }, + { 0x2100ff5a, 0x1400ffe0 }, + { 0x0900ff5b, 0x58000000 }, + { 0x0900ff5c, 0x64000000 }, + { 0x0900ff5d, 0x48000000 }, + { 0x0900ff5e, 0x64000000 }, + { 0x0900ff5f, 0x58000000 }, + { 0x0900ff60, 0x48000000 }, + { 0x0900ff61, 0x54000000 }, + { 0x0900ff62, 0x58000000 }, + { 0x0900ff63, 0x48000000 }, + { 0x0980ff64, 0x54000001 }, + { 0x1d80ff66, 0x1c000009 }, + { 0x0900ff70, 0x18000000 }, + { 0x1d80ff71, 0x1c00002c }, + { 0x0980ff9e, 0x18000001 }, + { 0x1780ffa0, 0x1c00001e }, + { 0x1780ffc2, 0x1c000005 }, + { 0x1780ffca, 0x1c000005 }, + { 0x1780ffd2, 0x1c000005 }, + { 0x1780ffda, 0x1c000002 }, + { 0x0980ffe0, 0x5c000001 }, + { 0x0900ffe2, 0x64000000 }, + { 0x0900ffe3, 0x60000000 }, + { 0x0900ffe4, 0x68000000 }, + { 0x0980ffe5, 0x5c000001 }, + { 0x0900ffe8, 0x68000000 }, + { 0x0980ffe9, 0x64000003 }, + { 0x0980ffed, 0x68000001 }, + { 0x0980fff9, 0x04000002 }, + { 0x0980fffc, 0x68000001 }, + { 0x23810000, 0x1c00000b }, + { 0x2381000d, 0x1c000019 }, + { 0x23810028, 0x1c000012 }, + { 0x2381003c, 0x1c000001 }, + { 0x2381003f, 0x1c00000e }, + { 0x23810050, 0x1c00000d }, + { 0x23810080, 0x1c00007a }, + { 0x09810100, 0x54000001 }, + { 0x09010102, 0x68000000 }, + { 0x09810107, 0x3c00002c }, + { 0x09810137, 0x68000008 }, + { 0x13810140, 0x38000034 }, + { 0x13810175, 0x3c000003 }, + { 0x13810179, 0x68000010 }, + { 0x1301018a, 0x3c000000 }, + { 0x29810300, 0x1c00001e }, + { 0x29810320, 0x3c000003 }, + { 0x12810330, 0x1c000010 }, + { 0x12010341, 0x38000000 }, + { 0x12810342, 0x1c000007 }, + { 0x1201034a, 0x38000000 }, + { 0x3b810380, 0x1c00001d }, + { 0x3b01039f, 0x54000000 }, + { 0x2a8103a0, 0x1c000023 }, + { 0x2a8103c8, 0x1c000007 }, + { 0x2a0103d0, 0x54000000 }, + { 0x2a8103d1, 0x38000004 }, + { 0x0d010400, 0x24000028 }, + { 0x0d010401, 0x24000028 }, + { 0x0d010402, 0x24000028 }, + { 0x0d010403, 0x24000028 }, + { 0x0d010404, 0x24000028 }, + { 0x0d010405, 0x24000028 }, + { 0x0d010406, 0x24000028 }, + { 0x0d010407, 0x24000028 }, + { 0x0d010408, 0x24000028 }, + { 0x0d010409, 0x24000028 }, + { 0x0d01040a, 0x24000028 }, + { 0x0d01040b, 0x24000028 }, + { 0x0d01040c, 0x24000028 }, + { 0x0d01040d, 0x24000028 }, + { 0x0d01040e, 0x24000028 }, + { 0x0d01040f, 0x24000028 }, + { 0x0d010410, 0x24000028 }, + { 0x0d010411, 0x24000028 }, + { 0x0d010412, 0x24000028 }, + { 0x0d010413, 0x24000028 }, + { 0x0d010414, 0x24000028 }, + { 0x0d010415, 0x24000028 }, + { 0x0d010416, 0x24000028 }, + { 0x0d010417, 0x24000028 }, + { 0x0d010418, 0x24000028 }, + { 0x0d010419, 0x24000028 }, + { 0x0d01041a, 0x24000028 }, + { 0x0d01041b, 0x24000028 }, + { 0x0d01041c, 0x24000028 }, + { 0x0d01041d, 0x24000028 }, + { 0x0d01041e, 0x24000028 }, + { 0x0d01041f, 0x24000028 }, + { 0x0d010420, 0x24000028 }, + { 0x0d010421, 0x24000028 }, + { 0x0d010422, 0x24000028 }, + { 0x0d010423, 0x24000028 }, + { 0x0d010424, 0x24000028 }, + { 0x0d010425, 0x24000028 }, + { 0x0d010426, 0x24000028 }, + { 0x0d010427, 0x24000028 }, + { 0x0d010428, 0x1400ffd8 }, + { 0x0d010429, 0x1400ffd8 }, + { 0x0d01042a, 0x1400ffd8 }, + { 0x0d01042b, 0x1400ffd8 }, + { 0x0d01042c, 0x1400ffd8 }, + { 0x0d01042d, 0x1400ffd8 }, + { 0x0d01042e, 0x1400ffd8 }, + { 0x0d01042f, 0x1400ffd8 }, + { 0x0d010430, 0x1400ffd8 }, + { 0x0d010431, 0x1400ffd8 }, + { 0x0d010432, 0x1400ffd8 }, + { 0x0d010433, 0x1400ffd8 }, + { 0x0d010434, 0x1400ffd8 }, + { 0x0d010435, 0x1400ffd8 }, + { 0x0d010436, 0x1400ffd8 }, + { 0x0d010437, 0x1400ffd8 }, + { 0x0d010438, 0x1400ffd8 }, + { 0x0d010439, 0x1400ffd8 }, + { 0x0d01043a, 0x1400ffd8 }, + { 0x0d01043b, 0x1400ffd8 }, + { 0x0d01043c, 0x1400ffd8 }, + { 0x0d01043d, 0x1400ffd8 }, + { 0x0d01043e, 0x1400ffd8 }, + { 0x0d01043f, 0x1400ffd8 }, + { 0x0d010440, 0x1400ffd8 }, + { 0x0d010441, 0x1400ffd8 }, + { 0x0d010442, 0x1400ffd8 }, + { 0x0d010443, 0x1400ffd8 }, + { 0x0d010444, 0x1400ffd8 }, + { 0x0d010445, 0x1400ffd8 }, + { 0x0d010446, 0x1400ffd8 }, + { 0x0d010447, 0x1400ffd8 }, + { 0x0d010448, 0x1400ffd8 }, + { 0x0d010449, 0x1400ffd8 }, + { 0x0d01044a, 0x1400ffd8 }, + { 0x0d01044b, 0x1400ffd8 }, + { 0x0d01044c, 0x1400ffd8 }, + { 0x0d01044d, 0x1400ffd8 }, + { 0x0d01044e, 0x1400ffd8 }, + { 0x0d01044f, 0x1400ffd8 }, + { 0x2e810450, 0x1c00004d }, + { 0x2c8104a0, 0x34000009 }, + { 0x0b810800, 0x1c000005 }, + { 0x0b010808, 0x1c000000 }, + { 0x0b81080a, 0x1c00002b }, + { 0x0b810837, 0x1c000001 }, + { 0x0b01083c, 0x1c000000 }, + { 0x0b01083f, 0x1c000000 }, + { 0x41810900, 0x1c000015 }, + { 0x41810916, 0x3c000003 }, + { 0x4101091f, 0x54000000 }, + { 0x1e010a00, 0x1c000000 }, + { 0x1e810a01, 0x30000002 }, + { 0x1e810a05, 0x30000001 }, + { 0x1e810a0c, 0x30000003 }, + { 0x1e810a10, 0x1c000003 }, + { 0x1e810a15, 0x1c000002 }, + { 0x1e810a19, 0x1c00001a }, + { 0x1e810a38, 0x30000002 }, + { 0x1e010a3f, 0x30000000 }, + { 0x1e810a40, 0x3c000007 }, + { 0x1e810a50, 0x54000008 }, + { 0x3e812000, 0x1c00036e }, + { 0x3e812400, 0x38000062 }, + { 0x3e812470, 0x54000003 }, + { 0x0981d000, 0x680000f5 }, + { 0x0981d100, 0x68000026 }, + { 0x0981d12a, 0x6800003a }, + { 0x0981d165, 0x28000001 }, + { 0x1b81d167, 0x30000002 }, + { 0x0981d16a, 0x68000002 }, + { 0x0981d16d, 0x28000005 }, + { 0x0981d173, 0x04000007 }, + { 0x1b81d17b, 0x30000007 }, + { 0x0981d183, 0x68000001 }, + { 0x1b81d185, 0x30000006 }, + { 0x0981d18c, 0x6800001d }, + { 0x1b81d1aa, 0x30000003 }, + { 0x0981d1ae, 0x6800002f }, + { 0x1381d200, 0x68000041 }, + { 0x1381d242, 0x30000002 }, + { 0x1301d245, 0x68000000 }, + { 0x0981d300, 0x68000056 }, + { 0x0981d360, 0x3c000011 }, + { 0x0981d400, 0x24000019 }, + { 0x0981d41a, 0x14000019 }, + { 0x0981d434, 0x24000019 }, + { 0x0981d44e, 0x14000006 }, + { 0x0981d456, 0x14000011 }, + { 0x0981d468, 0x24000019 }, + { 0x0981d482, 0x14000019 }, + { 0x0901d49c, 0x24000000 }, + { 0x0981d49e, 0x24000001 }, + { 0x0901d4a2, 0x24000000 }, + { 0x0981d4a5, 0x24000001 }, + { 0x0981d4a9, 0x24000003 }, + { 0x0981d4ae, 0x24000007 }, + { 0x0981d4b6, 0x14000003 }, + { 0x0901d4bb, 0x14000000 }, + { 0x0981d4bd, 0x14000006 }, + { 0x0981d4c5, 0x1400000a }, + { 0x0981d4d0, 0x24000019 }, + { 0x0981d4ea, 0x14000019 }, + { 0x0981d504, 0x24000001 }, + { 0x0981d507, 0x24000003 }, + { 0x0981d50d, 0x24000007 }, + { 0x0981d516, 0x24000006 }, + { 0x0981d51e, 0x14000019 }, + { 0x0981d538, 0x24000001 }, + { 0x0981d53b, 0x24000003 }, + { 0x0981d540, 0x24000004 }, + { 0x0901d546, 0x24000000 }, + { 0x0981d54a, 0x24000006 }, + { 0x0981d552, 0x14000019 }, + { 0x0981d56c, 0x24000019 }, + { 0x0981d586, 0x14000019 }, + { 0x0981d5a0, 0x24000019 }, + { 0x0981d5ba, 0x14000019 }, + { 0x0981d5d4, 0x24000019 }, + { 0x0981d5ee, 0x14000019 }, + { 0x0981d608, 0x24000019 }, + { 0x0981d622, 0x14000019 }, + { 0x0981d63c, 0x24000019 }, + { 0x0981d656, 0x14000019 }, + { 0x0981d670, 0x24000019 }, + { 0x0981d68a, 0x1400001b }, + { 0x0981d6a8, 0x24000018 }, + { 0x0901d6c1, 0x64000000 }, + { 0x0981d6c2, 0x14000018 }, + { 0x0901d6db, 0x64000000 }, + { 0x0981d6dc, 0x14000005 }, + { 0x0981d6e2, 0x24000018 }, + { 0x0901d6fb, 0x64000000 }, + { 0x0981d6fc, 0x14000018 }, + { 0x0901d715, 0x64000000 }, + { 0x0981d716, 0x14000005 }, + { 0x0981d71c, 0x24000018 }, + { 0x0901d735, 0x64000000 }, + { 0x0981d736, 0x14000018 }, + { 0x0901d74f, 0x64000000 }, + { 0x0981d750, 0x14000005 }, + { 0x0981d756, 0x24000018 }, + { 0x0901d76f, 0x64000000 }, + { 0x0981d770, 0x14000018 }, + { 0x0901d789, 0x64000000 }, + { 0x0981d78a, 0x14000005 }, + { 0x0981d790, 0x24000018 }, + { 0x0901d7a9, 0x64000000 }, + { 0x0981d7aa, 0x14000018 }, + { 0x0901d7c3, 0x64000000 }, + { 0x0981d7c4, 0x14000005 }, + { 0x0901d7ca, 0x24000000 }, + { 0x0901d7cb, 0x14000000 }, + { 0x0981d7ce, 0x34000031 }, + { 0x16820000, 0x1c00a6d6 }, + { 0x1682f800, 0x1c00021d }, + { 0x090e0001, 0x04000000 }, + { 0x098e0020, 0x0400005f }, + { 0x1b8e0100, 0x300000ef }, + { 0x098f0000, 0x0c00fffd }, + { 0x09900000, 0x0c00fffd }, +}; ============================================================ --- Makefile.am 302a257f3be89ef313e76dda8a3e62e0a1afe5fe +++ Makefile.am 239a18937d9d8775848b95358b2f8421258f8067 @@ -275,12 +275,15 @@ PCRE_SOURCES = \ PCRE_SOURCES = \ pcre/pcre_chartables.c pcre/pcre_compile.c pcre/pcre_config.c \ - pcre/pcre_config.h pcre/pcre_dfa_exec.c pcre/pcre_exec.c \ - pcre/pcre_fullinfo.c pcre/pcre_get.c pcre/pcre_globals.c \ - pcre/pcre.h pcre/pcre_info.c pcre/pcre_internal.h \ - pcre/pcre_maketables.c pcre/pcre_refcount.c pcre/pcre_study.c \ - pcre/pcre_tables.c pcre/pcre_try_flipped.c pcre/pcre_version.c \ - pcre/pcre_xclass.c + pcre/pcre_dfa_exec.c pcre/pcre_exec.c pcre/pcre_fullinfo.c \ + pcre/pcre_get.c pcre/pcre_globals.c pcre/pcre_info.c \ + pcre/pcre_maketables.c pcre/pcre_newline.c \ + pcre/pcre_ord2utf8.c pcre/pcre_refcount.c pcre/pcre_study.c \ + pcre/pcre_tables.c pcre/pcre_try_flipped.c \ + pcre/pcre_ucp_searchfuncs.c pcre/pcre_valid_utf8.c \ + pcre/pcre_version.c pcre/pcre_xclass.c pcre/pcre_config.h \ + pcre/pcre.h pcre/pcre_internal.h pcre/ucp.h pcre/ucpinternal.h \ + pcre/ucptable.h UNIX_PLATFORM_SOURCES = \ unix/read_password.cc unix/get_system_flavour.cc \ @@ -493,6 +496,7 @@ EPS_FIGURES=$(addprefix $(top_builddir)/ PNG_FIGURES=$(addprefix $(top_builddir)/figures/,$(notdir $(PDF_FIGURES:.pdf=.png))) EPS_FIGURES=$(addprefix $(top_builddir)/figures/,$(notdir $(PDF_FIGURES:.pdf=.eps))) +TEXI_FRAGMENTS = pcre/pcrepattern.texi pcre/pcresyntax.texi info_TEXINFOS = monotone.texi EXTRA_DIST = $(PDF_FIGURES) $(PNG_FIGURES) INSTALL README.changesets \ @@ -512,15 +516,18 @@ EXTRA_DIST = $(PDF_FIGURES) $(PNG_FIGURE $(wildcard $(srcdir)/examples/*) \ win32/monotone.iss win32/modpath.iss $(wildcard \ $(srcdir)/debian/*) mac/monotone-pkg-logo.gif \ - mac/monotone.pmproj mac/package-intro.rtf audit-includes + mac/monotone.pmproj mac/package-intro.rtf audit-includes \ + $(TEXI_FRAGMENTS) MAKEINFOFLAGS=-I $(top_builddir) -monotone.info: monotone.texi version.texi std_hooks.lua +monotone.info: monotone.texi version.texi std_hooks.lua $(TEXI_FRAGMENTS) -monotone.pdf: monotone.texi version.texi std_hooks.lua $(PDF_FIGURES) +monotone.pdf: monotone.texi version.texi std_hooks.lua $(TEXI_FRAGMENTS) \ + $(PDF_FIGURES) -monotone.dvi: monotone.texi version.texi std_hooks.lua $(EPS_FIGURES) +monotone.dvi: monotone.texi version.texi std_hooks.lua $(TEXI_FRAGMENTS) \ + $(EPS_FIGURES) #%.eps: %.epsi # mv -f $< $@ @@ -801,7 +808,8 @@ apidocs: apidocs: doxygen doxygen.cfg -monotone.html: monotone.texi version.texi std_hooks.lua texinfo.css +monotone.html: monotone.texi version.texi $(TEXI_FRAGMENTS) \ + std_hooks.lua texinfo.css if $(CHECK_SRCDIR_EQ_BUILDDIR); then :; else \ cp -r $(srcdir)/figures .; \ cp $(srcdir)/texinfo.css .; \ ============================================================ --- monotone.texi 11dbcb7685ca2369e9131eb7a4c2194f6b5619ae +++ monotone.texi ba3e94933926c735fe99c81024701beaaef7203a @@ -3264,7 +3264,8 @@ @heading Existing control files @table @file @item .mtn-ignore Contains a list of regular expression patterns, one per line. If it exists, -any file with a name matching one of these patterns is ignored. +any file with a name matching one of these patterns is +ignored. @xref{Regexps}, for the syntax of these regular expressions. @item _MTN/wanted-testresults Contains a list of testresult key names, one per line. If it exists, update will only select revisions that do not have regressions according to the given @@ -4920,9 +4921,9 @@ @section Informative hunk for a line that matches a regular expression. The default regular expression is correct for many programming languages. You can adjust the expression used with the Lua hook address@hidden; @ref{Hooks}. address@hidden; @ref{Hooks}. For the regular expression +syntax, @xref{Regexps}. - @option{--unified} requests the ``unified diff'' format, the default. @option{--context} requests the ``context diff'' format (analogous to running the program @command{diff @option{-c}}). Both of these formats are @@ -8748,7 +8749,8 @@ @subsection External Diff Tools regular expressions that match their particular syntax. If you have a better regular expression for some language, you can add it to this hook; and if you send it to the monotone developers, we will likely -make it to the default for that language. +make it the default for that language. @xref{Regexps}, for the +regular expression syntax. @item external_diff (@var{file_path}, @var{old_data}, @var{new_data}, @var{is_binary}, @var{diff_args}, @var{old_rev}, @var{new_rev}) @@ -9110,7 +9112,7 @@ @section Additional Lua Functions @item regex.search(@var{regexp}, @var{string}) Returns true if a match for @var{regexp} is found in @var{str}, return -false otherwise. +false otherwise. @xref{Regexps}, for the syntax of @var{regexp}. @item register_command(@var{name}, @var{abstract}, @var{description}, @var{function}) @@ -9180,6 +9182,8 @@ @chapter Special Topics * Hash Integrity:: Notes on probability and failure. * Rebuilding ancestry:: In case of corruption. * Mark-Merge:: The merging algorithm used by Monotone. +* Regexps:: The syntax of regular expressions + used by Monotone. @end menu @page @@ -10508,6 +10512,25 @@ @subheading More on "mark-merge" Replies and further discussion concerning this email can be found in the @uref{http://thread.gmane.org/gmane.comp.version-control.revctrl/92, monotone-devel archives}. address@hidden Regexps address@hidden Regular Expression Syntax + +Monotone expects user-provided regular expressions in address@hidden files and as the result of the address@hidden Lua hook (for the @option{--show-encloser} +option to @command{diff}). User-written Lua hooks may also use the +function @code{regex.search} as they see fit. All these regular +expressions should be written with the same syntax, which is that +expected by the Perl-Compatible Regular Expression library (PCRE). + address@hidden +* Regexp Summary:: Quick reference to regular expression syntax. +* Regexp Details:: Details of regular expression syntax and semantics. address@hidden menu + address@hidden pcre/pcresyntax.texi address@hidden pcre/pcrepattern.texi + @node Default hooks @appendix Default hooks ============================================================ --- pcre/README d83b21c4e1e1332190090230099bccd633988985 +++ pcre/README 420b5f8ab281ef77f9caa6cde682d24ea5f68322 @@ -1,8 +1,10 @@ -This is most of pcre 6.7. Configuration settings have been HARDWIRED. -(pcre does not have any portability constraints that we need to worry -about.) Unicode support has been removed, and the "dftables.c" -program has been run and its result checked in. pcre_internal.h has -been modified to include pcre_config.h instead of bare config.h. Some -#ifdefs have been added to pcre_tables.c, pcre_internal.h, and -pcre_dfa_exec.c to dike out Unicode more thoroughly. - +This is the library component of pcre 7.4, downloaded from +. The only +modification made to the code is that each .c file has been changed to +#include "pcre_config.h" unconditionally, instead of "config.h" only when +HAVE_CONFIG_H is defined. The file pcre_config.h is an appropriately +customized version of pcre's config.h.in. (This is done so that we +don't clutter monotone's own config.h with pcre's settings.) The files +pcresyntax.texi and pcrepattern.texi are translations to Texinfo of the +upstream documentation files pcresyntax.3 and pcrepattern.3, which were +in manpage format. ============================================================ --- pcre/pcre.h 845646297e364447eb985e62d9b838c4e26fdbc2 +++ pcre/pcre.h 3d50cb3220621ae4952c574e5f6970a2f6bda6fd @@ -5,7 +5,7 @@ applications that call the PCRE function /* This is the public header file for the PCRE library, to be #included by applications that call the PCRE functions. - Copyright (c) 1997-2005 University of Cambridge + Copyright (c) 1997-2007 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -41,47 +41,49 @@ POSSIBILITY OF SUCH DAMAGE. /* The current PCRE version information. */ -/* NOTES FOR FUTURE MAINTAINERS: Do not use numbers with leading zeros, because -they may be treated as octal constants. The PCRE_PRERELEASE feature is for -identifying release candidates. It might be defined as -RC2, for example. In -real releases, it should be defined empty. Do not change the alignment of these -statments. The code in ./configure greps out the version numbers by using "cut" -to get values from column 29 onwards. These are substituted into pcre-config -and libpcre.pc. The values are not put into configure.ac and substituted here -(which would simplify this issue) because that makes life harder for those who -cannot run ./configure. As it now stands, this file need not be edited in that -circumstance. */ +#define PCRE_MAJOR 7 +#define PCRE_MINOR 4 +#define PCRE_PRERELEASE +#define PCRE_DATE 2007-09-21 -#define PCRE_MAJOR 6 -#define PCRE_MINOR 7 -#define PCRE_PRERELEASE -#define PCRE_DATE 04-Jul-2006 +/* When an application links to a PCRE DLL in Windows, the symbols that are +imported have to be identified as such. When building PCRE, the appropriate +export setting is defined in pcre_internal.h, which includes this file. So we +don't change existing definitions of PCRE_EXP_DECL and PCRECPP_EXP_DECL. */ -/* Win32 uses DLL by default; it needs special stuff for exported functions -when building PCRE. */ - -#ifdef _WIN32 -# ifdef PCRE_DEFINITION -# ifdef DLL_EXPORT -# define PCRE_DATA_SCOPE __declspec(dllexport) +#if defined(_WIN32) && !defined(PCRE_STATIC) +# ifndef PCRE_EXP_DECL +# define PCRE_EXP_DECL extern __declspec(dllimport) +# endif +# ifdef __cplusplus +# ifndef PCRECPP_EXP_DECL +# define PCRECPP_EXP_DECL extern __declspec(dllimport) # endif -# else -# ifndef PCRE_STATIC -# define PCRE_DATA_SCOPE extern __declspec(dllimport) +# ifndef PCRECPP_EXP_DEFN +# define PCRECPP_EXP_DEFN __declspec(dllimport) # endif # endif #endif -/* Otherwise, we use the standard "extern". */ +/* By default, we use the standard "extern" declarations. */ -#ifndef PCRE_DATA_SCOPE +#ifndef PCRE_EXP_DECL # ifdef __cplusplus -# define PCRE_DATA_SCOPE extern "C" +# define PCRE_EXP_DECL extern "C" # else -# define PCRE_DATA_SCOPE extern +# define PCRE_EXP_DECL extern # endif #endif +#ifdef __cplusplus +# ifndef PCRECPP_EXP_DECL +# define PCRECPP_EXP_DECL extern +# endif +# ifndef PCRECPP_EXP_DEFN +# define PCRECPP_EXP_DEFN +# endif +#endif + /* Have to include stdlib.h in order to ensure that size_t is defined; it is needed here for malloc. */ @@ -118,6 +120,10 @@ extern "C" { #define PCRE_NEWLINE_CR 0x00100000 #define PCRE_NEWLINE_LF 0x00200000 #define PCRE_NEWLINE_CRLF 0x00300000 +#define PCRE_NEWLINE_ANY 0x00400000 +#define PCRE_NEWLINE_ANYCRLF 0x00500000 +#define PCRE_BSR_ANYCRLF 0x00800000 +#define PCRE_BSR_UNICODE 0x01000000 /* Exec-time and get/set-time error codes */ @@ -125,7 +131,8 @@ extern "C" { #define PCRE_ERROR_NULL (-2) #define PCRE_ERROR_BADOPTION (-3) #define PCRE_ERROR_BADMAGIC (-4) -#define PCRE_ERROR_UNKNOWN_NODE (-5) +#define PCRE_ERROR_UNKNOWN_OPCODE (-5) +#define PCRE_ERROR_UNKNOWN_NODE (-5) /* For backward compatibility */ #define PCRE_ERROR_NOMEMORY (-6) #define PCRE_ERROR_NOSUBSTRING (-7) #define PCRE_ERROR_MATCHLIMIT (-8) @@ -142,6 +149,8 @@ extern "C" { #define PCRE_ERROR_DFA_WSSIZE (-19) #define PCRE_ERROR_DFA_RECURSE (-20) #define PCRE_ERROR_RECURSIONLIMIT (-21) +#define PCRE_ERROR_NULLWSLIMIT (-22) /* No longer actually used */ +#define PCRE_ERROR_BADNEWLINE (-23) /* Request types for pcre_fullinfo() */ @@ -158,6 +167,9 @@ extern "C" { #define PCRE_INFO_NAMETABLE 9 #define PCRE_INFO_STUDYSIZE 10 #define PCRE_INFO_DEFAULT_TABLES 11 +#define PCRE_INFO_OKPARTIAL 12 +#define PCRE_INFO_JCHANGED 13 +#define PCRE_INFO_HASCRORLF 14 /* Request types for pcre_config(). Do not re-arrange, in order to remain compatible. */ @@ -170,6 +182,7 @@ compatible. */ #define PCRE_CONFIG_STACKRECURSE 5 #define PCRE_CONFIG_UNICODE_PROPERTIES 6 #define PCRE_CONFIG_MATCH_LIMIT_RECURSION 7 +#define PCRE_CONFIG_BSR 8 /* Bit flags for the pcre_extra structure. Do not re-arrange or redefine these bits, just add new ones on the end, in order to remain compatible. */ @@ -236,52 +249,52 @@ have to take another form. */ have to take another form. */ #ifndef VPCOMPAT -PCRE_DATA_SCOPE void *(*pcre_malloc)(size_t); -PCRE_DATA_SCOPE void (*pcre_free)(void *); -PCRE_DATA_SCOPE void *(*pcre_stack_malloc)(size_t); -PCRE_DATA_SCOPE void (*pcre_stack_free)(void *); -PCRE_DATA_SCOPE int (*pcre_callout)(pcre_callout_block *); +PCRE_EXP_DECL void *(*pcre_malloc)(size_t); +PCRE_EXP_DECL void (*pcre_free)(void *); +PCRE_EXP_DECL void *(*pcre_stack_malloc)(size_t); +PCRE_EXP_DECL void (*pcre_stack_free)(void *); +PCRE_EXP_DECL int (*pcre_callout)(pcre_callout_block *); #else /* VPCOMPAT */ -PCRE_DATA_SCOPE void *pcre_malloc(size_t); -PCRE_DATA_SCOPE void pcre_free(void *); -PCRE_DATA_SCOPE void *pcre_stack_malloc(size_t); -PCRE_DATA_SCOPE void pcre_stack_free(void *); -PCRE_DATA_SCOPE int pcre_callout(pcre_callout_block *); +PCRE_EXP_DECL void *pcre_malloc(size_t); +PCRE_EXP_DECL void pcre_free(void *); +PCRE_EXP_DECL void *pcre_stack_malloc(size_t); +PCRE_EXP_DECL void pcre_stack_free(void *); +PCRE_EXP_DECL int pcre_callout(pcre_callout_block *); #endif /* VPCOMPAT */ /* Exported PCRE functions */ -PCRE_DATA_SCOPE pcre *pcre_compile(const char *, int, const char **, int *, +PCRE_EXP_DECL pcre *pcre_compile(const char *, int, const char **, int *, const unsigned char *); -PCRE_DATA_SCOPE pcre *pcre_compile2(const char *, int, int *, const char **, +PCRE_EXP_DECL pcre *pcre_compile2(const char *, int, int *, const char **, int *, const unsigned char *); -PCRE_DATA_SCOPE int pcre_config(int, void *); -PCRE_DATA_SCOPE int pcre_copy_named_substring(const pcre *, const char *, +PCRE_EXP_DECL int pcre_config(int, void *); +PCRE_EXP_DECL int pcre_copy_named_substring(const pcre *, const char *, int *, int, const char *, char *, int); -PCRE_DATA_SCOPE int pcre_copy_substring(const char *, int *, int, int, char *, +PCRE_EXP_DECL int pcre_copy_substring(const char *, int *, int, int, char *, int); -PCRE_DATA_SCOPE int pcre_dfa_exec(const pcre *, const pcre_extra *, +PCRE_EXP_DECL int pcre_dfa_exec(const pcre *, const pcre_extra *, const char *, int, int, int, int *, int , int *, int); -PCRE_DATA_SCOPE int pcre_exec(const pcre *, const pcre_extra *, PCRE_SPTR, +PCRE_EXP_DECL int pcre_exec(const pcre *, const pcre_extra *, PCRE_SPTR, int, int, int, int *, int); -PCRE_DATA_SCOPE void pcre_free_substring(const char *); -PCRE_DATA_SCOPE void pcre_free_substring_list(const char **); -PCRE_DATA_SCOPE int pcre_fullinfo(const pcre *, const pcre_extra *, int, +PCRE_EXP_DECL void pcre_free_substring(const char *); +PCRE_EXP_DECL void pcre_free_substring_list(const char **); +PCRE_EXP_DECL int pcre_fullinfo(const pcre *, const pcre_extra *, int, void *); -PCRE_DATA_SCOPE int pcre_get_named_substring(const pcre *, const char *, +PCRE_EXP_DECL int pcre_get_named_substring(const pcre *, const char *, int *, int, const char *, const char **); -PCRE_DATA_SCOPE int pcre_get_stringnumber(const pcre *, const char *); -PCRE_DATA_SCOPE int pcre_get_stringtable_entries(const pcre *, const char *, +PCRE_EXP_DECL int pcre_get_stringnumber(const pcre *, const char *); +PCRE_EXP_DECL int pcre_get_stringtable_entries(const pcre *, const char *, char **, char **); -PCRE_DATA_SCOPE int pcre_get_substring(const char *, int *, int, int, +PCRE_EXP_DECL int pcre_get_substring(const char *, int *, int, int, const char **); -PCRE_DATA_SCOPE int pcre_get_substring_list(const char *, int *, int, +PCRE_EXP_DECL int pcre_get_substring_list(const char *, int *, int, const char ***); -PCRE_DATA_SCOPE int pcre_info(const pcre *, int *, int *); -PCRE_DATA_SCOPE const unsigned char *pcre_maketables(void); -PCRE_DATA_SCOPE int pcre_refcount(pcre *, int); -PCRE_DATA_SCOPE pcre_extra *pcre_study(const pcre *, int, const char **); -PCRE_DATA_SCOPE const char *pcre_version(void); +PCRE_EXP_DECL int pcre_info(const pcre *, int *, int *); +PCRE_EXP_DECL const unsigned char *pcre_maketables(void); +PCRE_EXP_DECL int pcre_refcount(pcre *, int); +PCRE_EXP_DECL pcre_extra *pcre_study(const pcre *, int, const char **); +PCRE_EXP_DECL const char *pcre_version(void); #ifdef __cplusplus } /* extern "C" */ ============================================================ --- pcre/pcre_chartables.c aa6b49b4d832ffdad9d5ca3fd8013ec371fc417a +++ pcre/pcre_chartables.c d9401a46b0d13b36b344c6a96580da7b5a8fb7b8 @@ -1,15 +1,29 @@ /************************************************* * Perl-Compatible Regular Expressions * *************************************************/ -/* This file is automatically written by the dftables auxiliary -program. If you edit it by hand, you might like to edit the Makefile to -prevent its ever being regenerated. +/* This file contains character tables that are used when no external tables +are passed to PCRE by the application that calls it. The tables are used only +for characters whose code values are less than 256. -This file contains the default tables for characters with codes less than -128 (ASCII characters). These tables are used when no external tables are -passed to PCRE. */ +This is a default version of the tables that assumes ASCII encoding. A program +called dftables (which is distributed with PCRE) can be used to build +alternative versions of this file. This is necessary if you are running in an +EBCDIC environment, or if you want to default to a different encoding, for +example ISO-8859-1. When dftables is run, it creates these tables in the +current locale. If PCRE is configured with --enable-rebuild-chartables, this +happens automatically. +The following #includes are present because without the gcc 4.x may remove the +array definition from the final binary if PCRE is built into a static library +and dead code stripping is activated. This leads to link errors. Pulling in the +header ensures that the array gets flagged as "someone outside this compilation +unit might reference this" and so it will always be supplied to the linker. */ + +#include "pcre_config.h" + +#include "pcre_internal.h" + const unsigned char _pcre_default_tables[] = { /* This table is a lower casing table. */ @@ -82,11 +96,10 @@ const unsigned char _pcre_default_tables 240,241,242,243,244,245,246,247, 248,249,250,251,252,253,254,255, -/* This table contains bit maps for various character classes. -Each map is 32 bytes long and the bits run from the least -significant end of each byte. The classes that have their own -maps are: space, xdigit, digit, upper, lower, word, graph -print, punct, and cntrl. Other classes are built from combinations. */ +/* This table contains bit maps for various character classes. Each map is 32 +bytes long and the bits run from the least significant end of each byte. The +classes that have their own maps are: space, xdigit, digit, upper, lower, word, +graph, print, punct, and cntrl. Other classes are built from combinations. */ 0x00,0x3e,0x00,0x00,0x01,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, @@ -158,7 +171,7 @@ print, punct, and cntrl. Other classes a 0x00,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x12, /* @ - G */ 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* H - O */ 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* P - W */ - 0x12,0x12,0x12,0x80,0x00,0x00,0x80,0x10, /* X - _ */ + 0x12,0x12,0x12,0x80,0x80,0x00,0x80,0x10, /* X - _ */ 0x00,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x12, /* ` - g */ 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* h - o */ 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* p - w */ @@ -180,4 +193,4 @@ print, punct, and cntrl. Other classes a 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 240-247 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/* 248-255 */ +/* End of pcre_chartables.c */ -/* End of chartables.c */ ============================================================ --- pcre/pcre_compile.c 2a7d0d4b9860bb85f50197170d47926a8526269b +++ pcre/pcre_compile.c 7e46181d93904b1c2030713b028b75f5588b303f @@ -6,7 +6,7 @@ and semantics are as close as possible t and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel - Copyright (c) 1997-2006 University of Cambridge + Copyright (c) 1997-2007 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -42,7 +42,12 @@ supporting internal functions that are n supporting internal functions that are not used by other modules. */ -#define NLBLOCK cd /* The block containing newline information */ +#include "pcre_config.h" + +#define NLBLOCK cd /* Block containing newline information */ +#define PSSTART start_pattern /* Field containing processed string start */ +#define PSEND end_pattern /* Field containing processed string end */ + #include "pcre_internal.h" @@ -54,40 +59,57 @@ used by pcretest. DEBUG is not defined w #endif +/* Macro for setting individual bits in class bitmaps. */ +#define SETBIT(a,b) a[b/8] |= (1 << (b%8)) + +/* Maximum length value to check against when making sure that the integer that +holds the compiled pattern length does not overflow. We make it a bit less than +INT_MAX to allow for adding in group terminating bytes, so that we don't have +to check them every time. */ + +#define OFLOW_MAX (INT_MAX - 20) + + /************************************************* * Code parameters and static tables * *************************************************/ -/* Maximum number of items on the nested bracket stacks at compile time. This -applies to the nesting of all kinds of parentheses. It does not limit -un-nested, non-capturing parentheses. This number can be made bigger if -necessary - it is used to dimension one int and one unsigned char vector at -compile time. */ +/* This value specifies the size of stack workspace that is used during the +first pre-compile phase that determines how much memory is required. The regex +is partly compiled into this space, but the compiled parts are discarded as +soon as they can be, so that hopefully there will never be an overrun. The code +does, however, check for an overrun. The largest amount I've seen used is 218, +so this number is very generous. -#define BRASTACK_SIZE 200 +The same workspace is used during the second, actual compile phase for +remembering forward references to groups so that they can be filled in at the +end. Each entry in this list occupies LINK_SIZE bytes, so even when LINK_SIZE +is 4 there is plenty of room. */ +#define COMPILE_WORK_SIZE (4096) + /* Table for handling escaped characters in the range '0'-'z'. Positive returns are simple data values; negative values are for special things like \d and so on. Zero means further processing is needed (for things like \x), or the escape is invalid. */ -#if !EBCDIC /* This is the "normal" table for ASCII systems */ +#ifndef EBCDIC /* This is the "normal" table for ASCII systems */ static const short int escapes[] = { 0, 0, 0, 0, 0, 0, 0, 0, /* 0 - 7 */ 0, 0, ':', ';', '<', '=', '>', '?', /* 8 - ? */ '@', -ESC_A, -ESC_B, -ESC_C, -ESC_D, -ESC_E, 0, -ESC_G, /* @ - G */ - 0, 0, 0, 0, 0, 0, 0, 0, /* H - O */ --ESC_P, -ESC_Q, 0, -ESC_S, 0, 0, 0, -ESC_W, /* P - W */ +-ESC_H, 0, 0, -ESC_K, 0, 0, 0, 0, /* H - O */ +-ESC_P, -ESC_Q, -ESC_R, -ESC_S, 0, 0, -ESC_V, -ESC_W, /* P - W */ -ESC_X, 0, -ESC_Z, '[', '\\', ']', '^', '_', /* X - _ */ '`', 7, -ESC_b, 0, -ESC_d, ESC_e, ESC_f, 0, /* ` - g */ - 0, 0, 0, 0, 0, 0, ESC_n, 0, /* h - o */ --ESC_p, 0, ESC_r, -ESC_s, ESC_tee, 0, 0, -ESC_w, /* p - w */ +-ESC_h, 0, 0, -ESC_k, 0, 0, ESC_n, 0, /* h - o */ +-ESC_p, 0, ESC_r, -ESC_s, ESC_tee, 0, -ESC_v, -ESC_w, /* p - w */ 0, 0, -ESC_z /* x - z */ }; -#else /* This is the "abnormal" table for EBCDIC systems */ +#else /* This is the "abnormal" table for EBCDIC systems */ static const short int escapes[] = { /* 48 */ 0, 0, 0, '.', '<', '(', '+', '|', /* 50 */ '&', 0, 0, 0, 0, 0, 0, 0, @@ -97,18 +119,18 @@ static const short int escapes[] = { /* 70 */ 0, 0, 0, 0, 0, 0, 0, 0, /* 78 */ 0, '`', ':', '#', '@', '\'', '=', '"', /* 80 */ 0, 7, -ESC_b, 0, -ESC_d, ESC_e, ESC_f, 0, -/* 88 */ 0, 0, 0, '{', 0, 0, 0, 0, -/* 90 */ 0, 0, 0, 'l', 0, ESC_n, 0, -ESC_p, +/* 88 */-ESC_h, 0, 0, '{', 0, 0, 0, 0, +/* 90 */ 0, 0, -ESC_k, 'l', 0, ESC_n, 0, -ESC_p, /* 98 */ 0, ESC_r, 0, '}', 0, 0, 0, 0, -/* A0 */ 0, '~', -ESC_s, ESC_tee, 0, 0, -ESC_w, 0, +/* A0 */ 0, '~', -ESC_s, ESC_tee, 0,-ESC_v, -ESC_w, 0, /* A8 */ 0,-ESC_z, 0, 0, 0, '[', 0, 0, /* B0 */ 0, 0, 0, 0, 0, 0, 0, 0, /* B8 */ 0, 0, 0, 0, 0, ']', '=', '-', /* C0 */ '{',-ESC_A, -ESC_B, -ESC_C, -ESC_D,-ESC_E, 0, -ESC_G, -/* C8 */ 0, 0, 0, 0, 0, 0, 0, 0, -/* D0 */ '}', 0, 0, 0, 0, 0, 0, -ESC_P, -/* D8 */-ESC_Q, 0, 0, 0, 0, 0, 0, 0, -/* E0 */ '\\', 0, -ESC_S, 0, 0, 0, -ESC_W, -ESC_X, +/* C8 */-ESC_H, 0, 0, 0, 0, 0, 0, 0, +/* D0 */ '}', 0, -ESC_K, 0, 0, 0, 0, -ESC_P, +/* D8 */-ESC_Q,-ESC_R, 0, 0, 0, 0, 0, 0, +/* E0 */ '\\', 0, -ESC_S, 0, 0,-ESC_V, -ESC_W, -ESC_X, /* E8 */ 0,-ESC_Z, 0, 0, 0, 0, 0, 0, /* F0 */ 0, 0, 0, 0, 0, 0, 0, 0, /* F8 */ 0, 0, 0, 0, 0, 0, 0, 0 @@ -116,15 +138,48 @@ static const short int escapes[] = { #endif -/* Tables of names of POSIX character classes and their lengths. The list is -terminated by a zero length entry. The first three must be alpha, lower, upper, -as this is assumed for handling case independence. */ +/* Table of special "verbs" like (*PRUNE). This is a short table, so it is +searched linearly. Put all the names into a single string, in order to reduce +the number of relocations when a shared library is dynamically linked. */ -static const char *const posix_names[] = { - "alpha", "lower", "upper", - "alnum", "ascii", "blank", "cntrl", "digit", "graph", - "print", "punct", "space", "word", "xdigit" }; +typedef struct verbitem { + int len; + int op; +} verbitem; +static const char verbnames[] = + "ACCEPT\0" + "COMMIT\0" + "F\0" + "FAIL\0" + "PRUNE\0" + "SKIP\0" + "THEN"; + +static verbitem verbs[] = { + { 6, OP_ACCEPT }, + { 6, OP_COMMIT }, + { 1, OP_FAIL }, + { 4, OP_FAIL }, + { 5, OP_PRUNE }, + { 4, OP_SKIP }, + { 4, OP_THEN } +}; + +static int verbcount = sizeof(verbs)/sizeof(verbitem); + + +/* Tables of names of POSIX character classes and their lengths. The names are +now all in a single string, to reduce the number of relocations when a shared +library is dynamically loaded. The list of lengths is terminated by a zero +length entry. The first three must be alpha, lower, upper, as this is assumed +for handling case independence. */ + +static const char posix_names[] = + "alpha\0" "lower\0" "upper\0" "alnum\0" "ascii\0" "blank\0" + "cntrl\0" "digit\0" "graph\0" "print\0" "punct\0" "space\0" + "word\0" "xdigit"; + static const uschar posix_name_lengths[] = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 6, 0 }; @@ -156,73 +211,94 @@ static const int posix_class_maps[] = { }; +#define STRING(a) # a +#define XSTRING(s) STRING(s) + /* The texts of compile-time error messages. These are "char *" because they -are passed to the outside world. */ +are passed to the outside world. Do not ever re-use any error number, because +they are documented. Always add a new error instead. Messages marked DEAD below +are no longer used. This used to be a table of strings, but in order to reduce +the number of relocations needed when a shared library is loaded dynamically, +it is now one long string. We cannot use a table of offsets, because the +lengths of inserts such as XSTRING(MAX_NAME_SIZE) are not known. Instead, we +simply count through to the one we want - this isn't a performance issue +because these strings are used only when there is a compilation error. */ -static const char *error_texts[] = { - "no error", - "\\ at end of pattern", - "\\c at end of pattern", - "unrecognized character follows \\", - "numbers out of order in {} quantifier", +static const char error_texts[] = + "no error\0" + "\\ at end of pattern\0" + "\\c at end of pattern\0" + "unrecognized character follows \\\0" + "numbers out of order in {} quantifier\0" /* 5 */ - "number too big in {} quantifier", - "missing terminating ] for character class", - "invalid escape sequence in character class", - "range out of order in character class", - "nothing to repeat", + "number too big in {} quantifier\0" + "missing terminating ] for character class\0" + "invalid escape sequence in character class\0" + "range out of order in character class\0" + "nothing to repeat\0" /* 10 */ - "operand of unlimited repeat could match the empty string", - "internal error: unexpected repeat", - "unrecognized character after (?", - "POSIX named classes are supported only within a class", - "missing )", + "operand of unlimited repeat could match the empty string\0" /** DEAD **/ + "internal error: unexpected repeat\0" + "unrecognized character after (?\0" + "POSIX named classes are supported only within a class\0" + "missing )\0" /* 15 */ - "reference to non-existent subpattern", - "erroffset passed as NULL", - "unknown option bit(s) set", - "missing ) after comment", - "parentheses nested too deeply", + "reference to non-existent subpattern\0" + "erroffset passed as NULL\0" + "unknown option bit(s) set\0" + "missing ) after comment\0" + "parentheses nested too deeply\0" /** DEAD **/ /* 20 */ - "regular expression too large", - "failed to get memory", - "unmatched parentheses", - "internal error: code overflow", - "unrecognized character after (?<", + "regular expression is too large\0" + "failed to get memory\0" + "unmatched parentheses\0" + "internal error: code overflow\0" + "unrecognized character after (?<\0" /* 25 */ - "lookbehind assertion is not fixed length", - "malformed number or name after (?(", - "conditional group contains more than two branches", - "assertion expected after (?(", - "(?R or (?digits must be followed by )", + "lookbehind assertion is not fixed length\0" + "malformed number or name after (?(\0" + "conditional group contains more than two branches\0" + "assertion expected after (?(\0" + "(?R or (?[+-]digits must be followed by )\0" /* 30 */ - "unknown POSIX class name", - "POSIX collating elements are not supported", - "this version of PCRE is not compiled with PCRE_UTF8 support", - "spare error", - "character value in \\x{...} sequence is too large", + "unknown POSIX class name\0" + "POSIX collating elements are not supported\0" + "this version of PCRE is not compiled with PCRE_UTF8 support\0" + "spare error\0" /** DEAD **/ + "character value in \\x{...} sequence is too large\0" /* 35 */ - "invalid condition (?(0)", - "\\C not allowed in lookbehind assertion", - "PCRE does not support \\L, \\l, \\N, \\U, or \\u", - "number after (?C is > 255", - "closing ) for (?C expected", + "invalid condition (?(0)\0" + "\\C not allowed in lookbehind assertion\0" + "PCRE does not support \\L, \\l, \\N, \\U, or \\u\0" + "number after (?C is > 255\0" + "closing ) for (?C expected\0" /* 40 */ - "recursive call could loop indefinitely", - "unrecognized character after (?P", - "syntax error after (?P", - "two named subpatterns have the same name", - "invalid UTF-8 string", + "recursive call could loop indefinitely\0" + "unrecognized character after (?P\0" + "syntax error in subpattern name (missing terminator)\0" + "two named subpatterns have the same name\0" + "invalid UTF-8 string\0" /* 45 */ - "support for \\P, \\p, and \\X has not been compiled", - "malformed \\P or \\p sequence", - "unknown property name after \\P or \\p", - "subpattern name is too long (maximum 32 characters)", - "too many named subpatterns (maximum 10,000)", + "support for \\P, \\p, and \\X has not been compiled\0" + "malformed \\P or \\p sequence\0" + "unknown property name after \\P or \\p\0" + "subpattern name is too long (maximum " XSTRING(MAX_NAME_SIZE) " characters)\0" + "too many named subpatterns (maximum " XSTRING(MAX_NAME_COUNT) ")\0" /* 50 */ - "repeated subpattern is too long", - "octal value is greater than \\377 (not in UTF-8 mode)" -}; + "repeated subpattern is too long\0" /** DEAD **/ + "octal value is greater than \\377 (not in UTF-8 mode)\0" + "internal error: overran compiling workspace\0" + "internal error: previously-checked referenced subpattern not found\0" + "DEFINE group contains more than one branch\0" + /* 55 */ + "repeating a DEFINE group is not allowed\0" + "inconsistent NEWLINE options\0" + "\\g is not followed by a braced name or an optionally braced non-zero number\0" + "(?+ or (?- or (?(+ or (?(- must be followed by a non-zero number\0" + "(*VERB) with an argument is not supported\0" + /* 60 */ + "(*VERB) not recognized\0" + "number is too big"; /* Table to identify digits and hex digits. This is used when compiling @@ -241,7 +317,7 @@ Then we can use ctype_digit and ctype_xd Then we can use ctype_digit and ctype_xdigit in the code. */ -#if !EBCDIC /* This is the "normal" case, for ASCII systems */ +#ifndef EBCDIC /* This is the "normal" case, for ASCII systems */ static const unsigned char digitab[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 0- 7 */ @@ -277,7 +353,7 @@ static const unsigned char digitab[] = 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 240-247 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/* 248-255 */ -#else /* This is the "abnormal" case, for EBCDIC systems */ +#else /* This is the "abnormal" case, for EBCDIC systems */ static const unsigned char digitab[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 0- 7 0 */ @@ -291,7 +367,7 @@ static const unsigned char digitab[] = 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* - 71 40 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 72- | */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* & - 87 50 */ - 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 88- ¬ */ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 88- 95 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* - -103 60 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 104- ? */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 112-119 70 */ @@ -325,7 +401,7 @@ static const unsigned char ebcdic_charta 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* - 71 */ 0x00,0x00,0x00,0x80,0x00,0x80,0x80,0x80, /* 72- | */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* & - 87 */ - 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00, /* 88- ¬ */ + 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00, /* 88- 95 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* - -103 */ 0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x80, /* 104- ? */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 112-119 */ @@ -352,20 +428,44 @@ static BOOL /* Definition to allow mutual recursion */ static BOOL - compile_regex(int, int, int *, uschar **, const uschar **, int *, BOOL, int, - int *, int *, branch_chain *, compile_data *); + compile_regex(int, int, uschar **, const uschar **, int *, BOOL, BOOL, int, + int *, int *, branch_chain *, compile_data *, int *); /************************************************* +* Find an error text * +*************************************************/ + +/* The error texts are now all in one long string, to save on relocations. As +some of the text is of unknown length, we can't use a table of offsets. +Instead, just count through the strings. This is not a performance issue +because it happens only when there has been a compilation error. + +Argument: the error number +Returns: pointer to the error string +*/ + +static const char * +find_error_text(int n) +{ +const char *s = error_texts; +for (; n > 0; n--) while (*s++ != 0); +return s; +} + + +/************************************************* * Handle escapes * *************************************************/ /* This function is called when a \ has been encountered. It either returns a positive value for a simple escape such as \n, or a negative value which -encodes one of the more complicated things such as \d. When UTF-8 is enabled, -a positive value greater than 255 may be returned. On entry, ptr is pointing at -the \. On exit, it is on the final character of the escape sequence. +encodes one of the more complicated things such as \d. A backreference to group +n is returned as -(ESC_REF + n); ESC_REF is the highest ESC_xxx macro. When +UTF-8 is enabled, a positive value greater than 255 may be returned. On entry, +ptr is pointing at the \. On exit, it is on the final character of the escape +sequence. Arguments: ptrptr points to the pattern position pointer @@ -376,7 +476,7 @@ Returns: zero or positive => a d Returns: zero or positive => a data character negative => a special escape sequence - on error, errorptr is set + on error, errorcodeptr is set */ static int @@ -398,11 +498,11 @@ Otherwise further processing may be requ a table. A non-zero result is something that can be returned immediately. Otherwise further processing may be required. */ -#if !EBCDIC /* ASCII coding */ +#ifndef EBCDIC /* ASCII coding */ else if (c < '0' || c > 'z') {} /* Not alphameric */ else if ((i = escapes[c - '0']) != 0) c = i; -#else /* EBCDIC coding */ +#else /* EBCDIC coding */ else if (c < 'a' || (ebcdic_chartab[c] & 0x0E) == 0) {} /* Not alphameric */ else if ((i = escapes[c - 0x48]) != 0) c = i; #endif @@ -412,6 +512,8 @@ else else { const uschar *oldptr; + BOOL braced, negated; + switch (c) { /* A number of Perl escapes are not handled by PCRE. We give an explicit @@ -425,6 +527,65 @@ else *errorcodeptr = ERR37; break; + /* \g must be followed by a number, either plain or braced. If positive, it + is an absolute backreference. If negative, it is a relative backreference. + This is a Perl 5.10 feature. Perl 5.10 also supports \g{name} as a + reference to a named group. This is part of Perl's movement towards a + unified syntax for back references. As this is synonymous with \k{name}, we + fudge it up by pretending it really was \k. */ + + case 'g': + if (ptr[1] == '{') + { + const uschar *p; + for (p = ptr+2; *p != 0 && *p != '}'; p++) + if (*p != '-' && (digitab[*p] & ctype_digit) == 0) break; + if (*p != 0 && *p != '}') + { + c = -ESC_k; + break; + } + braced = TRUE; + ptr++; + } + else braced = FALSE; + + if (ptr[1] == '-') + { + negated = TRUE; + ptr++; + } + else negated = FALSE; + + c = 0; + while ((digitab[ptr[1]] & ctype_digit) != 0) + c = c * 10 + *(++ptr) - '0'; + + if (c < 0) + { + *errorcodeptr = ERR61; + break; + } + + if (c == 0 || (braced && *(++ptr) != '}')) + { + *errorcodeptr = ERR57; + break; + } + + if (negated) + { + if (c > bracount) + { + *errorcodeptr = ERR15; + break; + } + c = bracount - (c - 1); + } + + c = -(ESC_REF + c); + break; + /* The handling of escape sequences consisting of a string of digits starting with one that is not zero is not straightforward. By experiment, the way Perl works seems to be as follows: @@ -446,6 +607,11 @@ else c -= '0'; while ((digitab[ptr[1]] & ctype_digit) != 0) c = c * 10 + *(++ptr) - '0'; + if (c < 0) + { + *errorcodeptr = ERR61; + break; + } if (c < 10 || c <= bracount) { c = -(ESC_REF + c); @@ -495,10 +661,10 @@ else if (c == 0 && cc == '0') continue; /* Leading zeroes */ count++; -#if !EBCDIC /* ASCII coding */ +#ifndef EBCDIC /* ASCII coding */ if (cc >= 'a') cc -= 32; /* Convert to upper case */ c = (c << 4) + cc - ((cc < 'A')? '0' : ('A' - 10)); -#else /* EBCDIC coding */ +#else /* EBCDIC coding */ if (cc >= 'a' && cc <= 'z') cc += 64; /* Convert to upper case */ c = (c << 4) + cc - ((cc >= '0')? '0' : ('A' - 10)); #endif @@ -522,34 +688,32 @@ else { int cc; /* Some compilers don't like ++ */ cc = *(++ptr); /* in initializers */ -#if !EBCDIC /* ASCII coding */ +#ifndef EBCDIC /* ASCII coding */ if (cc >= 'a') cc -= 32; /* Convert to upper case */ c = c * 16 + cc - ((cc < 'A')? '0' : ('A' - 10)); -#else /* EBCDIC coding */ +#else /* EBCDIC coding */ if (cc <= 'z') cc += 64; /* Convert to upper case */ c = c * 16 + cc - ((cc >= '0')? '0' : ('A' - 10)); #endif } break; - /* Other special escapes not starting with a digit are straightforward */ + /* For \c, a following letter is upper-cased; then the 0x40 bit is flipped. + This coding is ASCII-specific, but then the whole concept of \cx is + ASCII-specific. (However, an EBCDIC equivalent has now been added.) */ case 'c': c = *(++ptr); if (c == 0) { *errorcodeptr = ERR2; - return 0; + break; } - /* A letter is upper-cased; then the 0x40 bit is flipped. This coding - is ASCII-specific, but then the whole concept of \cx is ASCII-specific. - (However, an EBCDIC equivalent has now been added.) */ - -#if !EBCDIC /* ASCII coding */ +#ifndef EBCDIC /* ASCII coding */ if (c >= 'a' && c <= 'z') c -= 32; c ^= 0x40; -#else /* EBCDIC coding */ +#else /* EBCDIC coding */ if (c >= 'a' && c <= 'z') c += 64; c ^= 0xC0; #endif @@ -619,7 +783,7 @@ if (c == '{') *negptr = TRUE; ptr++; } - for (i = 0; i < sizeof(name) - 1; i++) + for (i = 0; i < (int)sizeof(name) - 1; i++) { c = *(++ptr); if (c == 0) goto ERROR_RETURN; @@ -648,7 +812,7 @@ while (bot < top) while (bot < top) { i = (bot + top) >> 1; - c = strcmp(name, _pcre_utt[i].name); + c = strcmp(name, _pcre_utt_names + _pcre_utt[i].name_offset); if (c == 0) { *dptr = _pcre_utt[i].value; @@ -772,42 +936,112 @@ return p; /************************************************* -* Find forward referenced named subpattern * +* Find forward referenced subpattern * *************************************************/ -/* This function scans along a pattern looking for capturing subpatterns, and -counting them. If it finds a named pattern that matches the name it is given, -it returns its number. This is used for forward references to named -subpatterns. We know that if (?P< is encountered, the name will be terminated -by '>' because that is checked in the first pass. +/* This function scans along a pattern's text looking for capturing +subpatterns, and counting them. If it finds a named pattern that matches the +name it is given, it returns its number. Alternatively, if the name is NULL, it +returns when it reaches a given numbered subpattern. This is used for forward +references to subpatterns. We know that if (?P< is encountered, the name will +be terminated by '>' because that is checked in the first pass. Arguments: - pointer current position in the pattern - count current count of capturing parens - name name to seek - namelen name length + ptr current position in the pattern + count current count of capturing parens so far encountered + name name to seek, or NULL if seeking a numbered subpattern + lorn name length, or subpattern number if name is NULL + xmode TRUE if we are in /x mode Returns: the number of the named subpattern, or -1 if not found */ static int -find_named_parens(const uschar *ptr, int count, const uschar *name, int namelen) +find_parens(const uschar *ptr, int count, const uschar *name, int lorn, + BOOL xmode) { const uschar *thisname; + for (; *ptr != 0; ptr++) { - if (*ptr == '\\' && ptr[1] != 0) { ptr++; continue; } + int term; + + /* Skip over backslashed characters and also entire \Q...\E */ + + if (*ptr == '\\') + { + if (*(++ptr) == 0) return -1; + if (*ptr == 'Q') for (;;) + { + while (*(++ptr) != 0 && *ptr != '\\'); + if (*ptr == 0) return -1; + if (*(++ptr) == 'E') break; + } + continue; + } + + /* Skip over character classes */ + + if (*ptr == '[') + { + while (*(++ptr) != ']') + { + if (*ptr == 0) return -1; + if (*ptr == '\\') + { + if (*(++ptr) == 0) return -1; + if (*ptr == 'Q') for (;;) + { + while (*(++ptr) != 0 && *ptr != '\\'); + if (*ptr == 0) return -1; + if (*(++ptr) == 'E') break; + } + continue; + } + } + continue; + } + + /* Skip comments in /x mode */ + + if (xmode && *ptr == '#') + { + while (*(++ptr) != 0 && *ptr != '\n'); + if (*ptr == 0) return -1; + continue; + } + + /* An opening parens must now be a real metacharacter */ + if (*ptr != '(') continue; - if (ptr[1] != '?') { count++; continue; } - if (ptr[2] == '(') { ptr += 2; continue; } - if (ptr[2] != 'P' || ptr[3] != '<') continue; + if (ptr[1] != '?' && ptr[1] != '*') + { + count++; + if (name == NULL && count == lorn) return count; + continue; + } + + ptr += 2; + if (*ptr == 'P') ptr++; /* Allow optional P */ + + /* We have to disambiguate (? */ + + if ((*ptr != '<' || ptr[1] == '!' || ptr[1] == '=') && + *ptr != '\'') + continue; + count++; - ptr += 4; + + if (name == NULL && count == lorn) return count; + term = *ptr++; + if (term == '<') term = '>'; thisname = ptr; - while (*ptr != '>') ptr++; - if (namelen == ptr - thisname && strncmp(name, thisname, namelen) == 0) + while (*ptr != term) ptr++; + if (name != NULL && lorn == ptr - thisname && + strncmp((const char *)name, (const char *)thisname, lorn) == 0) return count; } + return -1; } @@ -862,7 +1096,8 @@ for (;;) case OP_CALLOUT: case OP_CREF: - case OP_BRANUMBER: + case OP_RREF: + case OP_DEF: code += _pcre_OP_lengths[*code]; break; @@ -907,14 +1142,13 @@ for (;;) { int d; register int op = *cc; - if (op >= OP_BRA) op = OP_BRA; - switch (op) { + case OP_CBRA: case OP_BRA: case OP_ONCE: case OP_COND: - d = find_fixedlength(cc, options); + d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), options); if (d < 0) return d; branchlength += d; do cc += GET(cc, 1); while (*cc == OP_ALT); @@ -949,8 +1183,9 @@ for (;;) /* Skip over things that don't match chars */ case OP_REVERSE: - case OP_BRANUMBER: case OP_CREF: + case OP_RREF: + case OP_DEF: case OP_OPT: case OP_CALLOUT: case OP_SOD: @@ -995,6 +1230,7 @@ for (;;) case OP_TYPEEXACT: branchlength += GET2(cc,1); + if (cc[3] == OP_PROP || cc[3] == OP_NOTPROP) cc += 2; cc += 4; break; @@ -1094,25 +1330,52 @@ for (;;) if (c == OP_XCLASS) code += GET(code, 1); - /* Handle bracketed group */ + /* Handle capturing bracket */ - else if (c > OP_BRA) + else if (c == OP_CBRA) { - int n = c - OP_BRA; - if (n > EXTRACT_BASIC_MAX) n = GET2(code, 2+LINK_SIZE); + int n = GET2(code, 1+LINK_SIZE); if (n == number) return (uschar *)code; - code += _pcre_OP_lengths[OP_BRA]; + code += _pcre_OP_lengths[c]; } - /* Otherwise, we get the item's length from the table. In UTF-8 mode, opcodes - that are followed by a character may be followed by a multi-byte character. - The length in the table is a minimum, so we have to scan along to skip the - extra bytes. All opcodes are less than 128, so we can use relatively - efficient code. */ + /* Otherwise, we can get the item's length from the table, except that for + repeated character types, we have to test for \p and \P, which have an extra + two bytes of parameters. */ else { + switch(c) + { + case OP_TYPESTAR: + case OP_TYPEMINSTAR: + case OP_TYPEPLUS: + case OP_TYPEMINPLUS: + case OP_TYPEQUERY: + case OP_TYPEMINQUERY: + case OP_TYPEPOSSTAR: + case OP_TYPEPOSPLUS: + case OP_TYPEPOSQUERY: + if (code[1] == OP_PROP || code[1] == OP_NOTPROP) code += 2; + break; + + case OP_TYPEUPTO: + case OP_TYPEMINUPTO: + case OP_TYPEEXACT: + case OP_TYPEPOSUPTO: + if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2; + break; + } + + /* Add in the fixed length from the table */ + code += _pcre_OP_lengths[c]; + + /* In UTF-8 mode, opcodes that are followed by a character may be followed by + a multi-byte character. The length in the table is a minimum, so we have to + arrange to skip the extra bytes. */ + +#ifdef SUPPORT_UTF8 if (utf8) switch(c) { case OP_CHAR: @@ -1120,15 +1383,20 @@ for (;;) case OP_EXACT: case OP_UPTO: case OP_MINUPTO: + case OP_POSUPTO: case OP_STAR: case OP_MINSTAR: + case OP_POSSTAR: case OP_PLUS: case OP_MINPLUS: + case OP_POSPLUS: case OP_QUERY: case OP_MINQUERY: - while ((*code & 0xc0) == 0x80) code++; + case OP_POSQUERY: + if (code[-1] >= 0xc0) code += _pcre_utf8_table4[code[-1] & 0x3f]; break; } +#endif } } } @@ -1164,22 +1432,43 @@ for (;;) if (c == OP_XCLASS) code += GET(code, 1); - /* All bracketed groups have the same length. */ + /* Otherwise, we can get the item's length from the table, except that for + repeated character types, we have to test for \p and \P, which have an extra + two bytes of parameters. */ - else if (c > OP_BRA) + else { - code += _pcre_OP_lengths[OP_BRA]; - } + switch(c) + { + case OP_TYPESTAR: + case OP_TYPEMINSTAR: + case OP_TYPEPLUS: + case OP_TYPEMINPLUS: + case OP_TYPEQUERY: + case OP_TYPEMINQUERY: + case OP_TYPEPOSSTAR: + case OP_TYPEPOSPLUS: + case OP_TYPEPOSQUERY: + if (code[1] == OP_PROP || code[1] == OP_NOTPROP) code += 2; + break; - /* Otherwise, we get the item's length from the table. In UTF-8 mode, opcodes - that are followed by a character may be followed by a multi-byte character. - The length in the table is a minimum, so we have to scan along to skip the - extra bytes. All opcodes are less than 128, so we can use relatively - efficient code. */ + case OP_TYPEPOSUPTO: + case OP_TYPEUPTO: + case OP_TYPEMINUPTO: + case OP_TYPEEXACT: + if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2; + break; + } - else - { + /* Add in the fixed length from the table */ + code += _pcre_OP_lengths[c]; + + /* In UTF-8 mode, opcodes that are followed by a character may be followed + by a multi-byte character. The length in the table is a minimum, so we have + to arrange to skip the extra bytes. */ + +#ifdef SUPPORT_UTF8 if (utf8) switch(c) { case OP_CHAR: @@ -1187,15 +1476,20 @@ for (;;) case OP_EXACT: case OP_UPTO: case OP_MINUPTO: + case OP_POSUPTO: case OP_STAR: case OP_MINSTAR: + case OP_POSSTAR: case OP_PLUS: case OP_MINPLUS: + case OP_POSPLUS: case OP_QUERY: case OP_MINQUERY: - while ((*code & 0xc0) == 0x80) code++; + case OP_POSQUERY: + if (code[-1] >= 0xc0) code += _pcre_utf8_table4[code[-1] & 0x3f]; break; } +#endif } } } @@ -1207,10 +1501,11 @@ for (;;) *************************************************/ /* This function scans through a branch of a compiled pattern to see whether it -can match the empty string or not. It is called only from could_be_empty() -below. Note that first_significant_code() skips over assertions. If we hit an -unclosed bracket, we return "empty" - this means we've struck an inner bracket -whose current branch will already have been scanned. +can match the empty string or not. It is called from could_be_empty() +below and from compile_branch() when checking for an unlimited repeat of a +group that can match nothing. Note that first_significant_code() skips over +assertions. If we hit an unclosed bracket, we return "empty" - this means we've +struck an inner bracket whose current branch will already have been scanned. Arguments: code points to start of search @@ -1224,7 +1519,7 @@ register int c; could_be_empty_branch(const uschar *code, const uschar *endcode, BOOL utf8) { register int c; -for (code = first_significant_code(code + 1 + LINK_SIZE, NULL, 0, TRUE); +for (code = first_significant_code(code + _pcre_OP_lengths[*code], NULL, 0, TRUE); code < endcode; code = first_significant_code(code + _pcre_OP_lengths[c], NULL, 0, TRUE)) { @@ -1232,8 +1527,20 @@ for (code = first_significant_code(code c = *code; - if (c >= OP_BRA) + /* Groups with zero repeats can of course be empty; skip them. */ + + if (c == OP_BRAZERO || c == OP_BRAMINZERO) { + code += _pcre_OP_lengths[c]; + do code += GET(code, 1); while (*code == OP_ALT); + c = *code; + continue; + } + + /* For other groups, scan the branches. */ + + if (c == OP_BRA || c == OP_CBRA || c == OP_ONCE || c == OP_COND) + { BOOL empty_branch; if (GET(code, 1) == 0) return TRUE; /* Hit unclosed bracket */ @@ -1248,17 +1555,23 @@ for (code = first_significant_code(code } while (*code == OP_ALT); if (!empty_branch) return FALSE; /* All branches are non-empty */ - code += 1 + LINK_SIZE; c = *code; + continue; } - else switch (c) + /* Handle the other opcodes */ + + switch (c) { - /* Check for quantifiers after a class */ + /* Check for quantifiers after a class. XCLASS is used for classes that + cannot be represented just by a bit map. This includes negated single + high-valued characters. The length in _pcre_OP_lengths[] is zero; the + actual length is stored in the compiled code, so we must update "code" + here. */ #ifdef SUPPORT_UTF8 case OP_XCLASS: - ccode = code + GET(code, 1); + ccode = code += GET(code, 1); goto CHECK_CLASS_REPEAT; #endif @@ -1308,15 +1621,38 @@ for (code = first_significant_code(code case OP_NOT: case OP_PLUS: case OP_MINPLUS: + case OP_POSPLUS: case OP_EXACT: case OP_NOTPLUS: case OP_NOTMINPLUS: + case OP_NOTPOSPLUS: case OP_NOTEXACT: case OP_TYPEPLUS: case OP_TYPEMINPLUS: + case OP_TYPEPOSPLUS: case OP_TYPEEXACT: return FALSE; + /* These are going to continue, as they may be empty, but we have to + fudge the length for the \p and \P cases. */ + + case OP_TYPESTAR: + case OP_TYPEMINSTAR: + case OP_TYPEPOSSTAR: + case OP_TYPEQUERY: + case OP_TYPEMINQUERY: + case OP_TYPEPOSQUERY: + if (code[1] == OP_PROP || code[1] == OP_NOTPROP) code += 2; + break; + + /* Same for these */ + + case OP_TYPEUPTO: + case OP_TYPEMINUPTO: + case OP_TYPEPOSUPTO: + if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2; + break; + /* End of branch */ case OP_KET: @@ -1325,16 +1661,19 @@ for (code = first_significant_code(code case OP_ALT: return TRUE; - /* In UTF-8 mode, STAR, MINSTAR, QUERY, MINQUERY, UPTO, and MINUPTO may be - followed by a multibyte character */ + /* In UTF-8 mode, STAR, MINSTAR, POSSTAR, QUERY, MINQUERY, POSQUERY, UPTO, + MINUPTO, and POSUPTO may be followed by a multibyte character */ #ifdef SUPPORT_UTF8 case OP_STAR: case OP_MINSTAR: + case OP_POSSTAR: case OP_QUERY: case OP_MINQUERY: + case OP_POSQUERY: case OP_UPTO: case OP_MINUPTO: + case OP_POSUPTO: if (utf8) while ((code[2] & 0xc0) == 0x80) code++; break; #endif @@ -1430,11 +1769,13 @@ check_posix_name(const uschar *ptr, int static int check_posix_name(const uschar *ptr, int len) { +const char *pn = posix_names; register int yield = 0; while (posix_name_lengths[yield] != 0) { if (len == posix_name_lengths[yield] && - strncmp((const char *)ptr, posix_names[yield], len) == 0) return yield; + strncmp((const char *)ptr, pn, len) == 0) return yield; + pn += posix_name_lengths[yield] + 1; yield++; } return -1; @@ -1452,26 +1793,58 @@ that refer to the group itself or any co optional (i.e. the minimum quantifier is zero), OP_BRAZERO is inserted before it, after it has been compiled. This means that any OP_RECURSE items within it that refer to the group itself or any contained groups have to have their -offsets adjusted. That is the job of this function. Before it is called, the -partially compiled regex must be temporarily terminated with OP_END. +offsets adjusted. That one of the jobs of this function. Before it is called, +the partially compiled regex must be temporarily terminated with OP_END. +This function has been extended with the possibility of forward references for +recursions and subroutine calls. It must also check the list of such references +for the group we are dealing with. If it finds that one of the recursions in +the current group is on this list, it adjusts the offset in the list, not the +value in the reference (which is a group number). + Arguments: group points to the start of the group adjust the amount by which the group is to be moved utf8 TRUE in UTF-8 mode cd contains pointers to tables etc. + save_hwm the hwm forward reference pointer at the start of the group Returns: nothing */ static void -adjust_recurse(uschar *group, int adjust, BOOL utf8, compile_data *cd) +adjust_recurse(uschar *group, int adjust, BOOL utf8, compile_data *cd, + uschar *save_hwm) { uschar *ptr = group; + while ((ptr = (uschar *)find_recurse(ptr, utf8)) != NULL) { - int offset = GET(ptr, 1); - if (cd->start_code + offset >= group) PUT(ptr, 1, offset + adjust); + int offset; + uschar *hc; + + /* See if this recursion is on the forward reference list. If so, adjust the + reference. */ + + for (hc = save_hwm; hc < cd->hwm; hc += LINK_SIZE) + { + offset = GET(hc, 0); + if (cd->start_code + offset == ptr + 1) + { + PUT(hc, 0, offset + adjust); + break; + } + } + + /* Otherwise, adjust the recursion offset if it's after the start of this + group. */ + + if (hc >= cd->hwm) + { + offset = GET(ptr, 1); + if (cd->start_code + offset >= group) PUT(ptr, 1, offset + adjust); + } + ptr += 1 + LINK_SIZE; } } @@ -1550,12 +1923,13 @@ static BOOL */ static BOOL -get_othercase_range(int *cptr, int d, int *ocptr, int *odptr) +get_othercase_range(unsigned int *cptr, unsigned int d, unsigned int *ocptr, + unsigned int *odptr) { -int c, othercase, next; +unsigned int c, othercase, next; for (c = *cptr; c <= d; c++) - { if ((othercase = _pcre_ucp_othercase(c)) >= 0) break; } + { if ((othercase = _pcre_ucp_othercase(c)) != NOTACHAR) break; } if (c > d) return FALSE; @@ -1576,17 +1950,351 @@ return TRUE; #endif /* SUPPORT_UCP */ + /************************************************* +* Check if auto-possessifying is possible * +*************************************************/ + +/* This function is called for unlimited repeats of certain items, to see +whether the next thing could possibly match the repeated item. If not, it makes +sense to automatically possessify the repeated item. + +Arguments: + op_code the repeated op code + this data for this item, depends on the opcode + utf8 TRUE in UTF-8 mode + utf8_char used for utf8 character bytes, NULL if not relevant + ptr next character in pattern + options options bits + cd contains pointers to tables etc. + +Returns: TRUE if possessifying is wanted +*/ + +static BOOL +check_auto_possessive(int op_code, int item, BOOL utf8, uschar *utf8_char, + const uschar *ptr, int options, compile_data *cd) +{ +int next; + +/* Skip whitespace and comments in extended mode */ + +if ((options & PCRE_EXTENDED) != 0) + { + for (;;) + { + while ((cd->ctypes[*ptr] & ctype_space) != 0) ptr++; + if (*ptr == '#') + { + while (*(++ptr) != 0) + if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; } + } + else break; + } + } + +/* If the next item is one that we can handle, get its value. A non-negative +value is a character, a negative value is an escape value. */ + +if (*ptr == '\\') + { + int temperrorcode = 0; + next = check_escape(&ptr, &temperrorcode, cd->bracount, options, FALSE); + if (temperrorcode != 0) return FALSE; + ptr++; /* Point after the escape sequence */ + } + +else if ((cd->ctypes[*ptr] & ctype_meta) == 0) + { +#ifdef SUPPORT_UTF8 + if (utf8) { GETCHARINC(next, ptr); } else +#endif + next = *ptr++; + } + +else return FALSE; + +/* Skip whitespace and comments in extended mode */ + +if ((options & PCRE_EXTENDED) != 0) + { + for (;;) + { + while ((cd->ctypes[*ptr] & ctype_space) != 0) ptr++; + if (*ptr == '#') + { + while (*(++ptr) != 0) + if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; } + } + else break; + } + } + +/* If the next thing is itself optional, we have to give up. */ + +if (*ptr == '*' || *ptr == '?' || strncmp((char *)ptr, "{0,", 3) == 0) + return FALSE; + +/* Now compare the next item with the previous opcode. If the previous is a +positive single character match, "item" either contains the character or, if +"item" is greater than 127 in utf8 mode, the character's bytes are in +utf8_char. */ + + +/* Handle cases when the next item is a character. */ + +if (next >= 0) switch(op_code) + { + case OP_CHAR: +#ifdef SUPPORT_UTF8 + if (utf8 && item > 127) { GETCHAR(item, utf8_char); } +#endif + return item != next; + + /* For CHARNC (caseless character) we must check the other case. If we have + Unicode property support, we can use it to test the other case of + high-valued characters. */ + + case OP_CHARNC: +#ifdef SUPPORT_UTF8 + if (utf8 && item > 127) { GETCHAR(item, utf8_char); } +#endif + if (item == next) return FALSE; +#ifdef SUPPORT_UTF8 + if (utf8) + { + unsigned int othercase; + if (next < 128) othercase = cd->fcc[next]; else +#ifdef SUPPORT_UCP + othercase = _pcre_ucp_othercase((unsigned int)next); +#else + othercase = NOTACHAR; +#endif + return (unsigned int)item != othercase; + } + else +#endif /* SUPPORT_UTF8 */ + return (item != cd->fcc[next]); /* Non-UTF-8 mode */ + + /* For OP_NOT, "item" must be a single-byte character. */ + + case OP_NOT: + if (next < 0) return FALSE; /* Not a character */ + if (item == next) return TRUE; + if ((options & PCRE_CASELESS) == 0) return FALSE; +#ifdef SUPPORT_UTF8 + if (utf8) + { + unsigned int othercase; + if (next < 128) othercase = cd->fcc[next]; else +#ifdef SUPPORT_UCP + othercase = _pcre_ucp_othercase(next); +#else + othercase = NOTACHAR; +#endif + return (unsigned int)item == othercase; + } + else +#endif /* SUPPORT_UTF8 */ + return (item == cd->fcc[next]); /* Non-UTF-8 mode */ + + case OP_DIGIT: + return next > 127 || (cd->ctypes[next] & ctype_digit) == 0; + + case OP_NOT_DIGIT: + return next <= 127 && (cd->ctypes[next] & ctype_digit) != 0; + + case OP_WHITESPACE: + return next > 127 || (cd->ctypes[next] & ctype_space) == 0; + + case OP_NOT_WHITESPACE: + return next <= 127 && (cd->ctypes[next] & ctype_space) != 0; + + case OP_WORDCHAR: + return next > 127 || (cd->ctypes[next] & ctype_word) == 0; + + case OP_NOT_WORDCHAR: + return next <= 127 && (cd->ctypes[next] & ctype_word) != 0; + + case OP_HSPACE: + case OP_NOT_HSPACE: + switch(next) + { + case 0x09: + case 0x20: + case 0xa0: + case 0x1680: + case 0x180e: + case 0x2000: + case 0x2001: + case 0x2002: + case 0x2003: + case 0x2004: + case 0x2005: + case 0x2006: + case 0x2007: + case 0x2008: + case 0x2009: + case 0x200A: + case 0x202f: + case 0x205f: + case 0x3000: + return op_code != OP_HSPACE; + default: + return op_code == OP_HSPACE; + } + + case OP_VSPACE: + case OP_NOT_VSPACE: + switch(next) + { + case 0x0a: + case 0x0b: + case 0x0c: + case 0x0d: + case 0x85: + case 0x2028: + case 0x2029: + return op_code != OP_VSPACE; + default: + return op_code == OP_VSPACE; + } + + default: + return FALSE; + } + + +/* Handle the case when the next item is \d, \s, etc. */ + +switch(op_code) + { + case OP_CHAR: + case OP_CHARNC: +#ifdef SUPPORT_UTF8 + if (utf8 && item > 127) { GETCHAR(item, utf8_char); } +#endif + switch(-next) + { + case ESC_d: + return item > 127 || (cd->ctypes[item] & ctype_digit) == 0; + + case ESC_D: + return item <= 127 && (cd->ctypes[item] & ctype_digit) != 0; + + case ESC_s: + return item > 127 || (cd->ctypes[item] & ctype_space) == 0; + + case ESC_S: + return item <= 127 && (cd->ctypes[item] & ctype_space) != 0; + + case ESC_w: + return item > 127 || (cd->ctypes[item] & ctype_word) == 0; + + case ESC_W: + return item <= 127 && (cd->ctypes[item] & ctype_word) != 0; + + case ESC_h: + case ESC_H: + switch(item) + { + case 0x09: + case 0x20: + case 0xa0: + case 0x1680: + case 0x180e: + case 0x2000: + case 0x2001: + case 0x2002: + case 0x2003: + case 0x2004: + case 0x2005: + case 0x2006: + case 0x2007: + case 0x2008: + case 0x2009: + case 0x200A: + case 0x202f: + case 0x205f: + case 0x3000: + return -next != ESC_h; + default: + return -next == ESC_h; + } + + case ESC_v: + case ESC_V: + switch(item) + { + case 0x0a: + case 0x0b: + case 0x0c: + case 0x0d: + case 0x85: + case 0x2028: + case 0x2029: + return -next != ESC_v; + default: + return -next == ESC_v; + } + + default: + return FALSE; + } + + case OP_DIGIT: + return next == -ESC_D || next == -ESC_s || next == -ESC_W || + next == -ESC_h || next == -ESC_v; + + case OP_NOT_DIGIT: + return next == -ESC_d; + + case OP_WHITESPACE: + return next == -ESC_S || next == -ESC_d || next == -ESC_w; + + case OP_NOT_WHITESPACE: + return next == -ESC_s || next == -ESC_h || next == -ESC_v; + + case OP_HSPACE: + return next == -ESC_S || next == -ESC_H || next == -ESC_d || next == -ESC_w; + + case OP_NOT_HSPACE: + return next == -ESC_h; + + /* Can't have \S in here because VT matches \S (Perl anomaly) */ + case OP_VSPACE: + return next == -ESC_V || next == -ESC_d || next == -ESC_w; + + case OP_NOT_VSPACE: + return next == -ESC_v; + + case OP_WORDCHAR: + return next == -ESC_W || next == -ESC_s || next == -ESC_h || next == -ESC_v; + + case OP_NOT_WORDCHAR: + return next == -ESC_w || next == -ESC_d; + + default: + return FALSE; + } + +/* Control does not reach here */ +} + + + +/************************************************* * Compile one branch * *************************************************/ -/* Scan the pattern, compiling it into the code vector. If the options are +/* Scan the pattern, compiling it into the a vector. If the options are changed during the branch, the pointer is used to change the external options -bits. +bits. This function is used during the pre-compile phase when we are trying +to find out the amount of memory needed, as well as during the real compile +phase. The value of lengthptr distinguishes the two phases. Arguments: optionsptr pointer to the option bits - brackets points to number of extracting brackets used codeptr points to the pointer to the current code point ptrptr points to the current pattern pointer errorcodeptr points to error code variable @@ -1594,15 +2302,17 @@ Arguments: reqbyteptr set to the last literal character required, else < 0 bcptr points to current branch chain cd contains pointers to tables etc. + lengthptr NULL during the real compile phase + points to length accumulator during pre-compile phase Returns: TRUE on success FALSE, with *errorcodeptr set non-zero on error */ static BOOL -compile_branch(int *optionsptr, int *brackets, uschar **codeptr, - const uschar **ptrptr, int *errorcodeptr, int *firstbyteptr, - int *reqbyteptr, branch_chain *bcptr, compile_data *cd) +compile_branch(int *optionsptr, uschar **codeptr, const uschar **ptrptr, + int *errorcodeptr, int *firstbyteptr, int *reqbyteptr, branch_chain *bcptr, + compile_data *cd, int *lengthptr) { int repeat_type, op_type; int repeat_min = 0, repeat_max = 0; /* To please picky compilers */ @@ -1613,8 +2323,11 @@ int after_manual_callout = 0; int req_caseopt, reqvary, tempreqvary; int options = *optionsptr; int after_manual_callout = 0; +int length_prevgroup = 0; register int c; register uschar *code = *codeptr; +uschar *last_code = code; +uschar *orig_code = code; uschar *tempcode; BOOL inescq = FALSE; BOOL groupsetfirstbyte = FALSE; @@ -1622,6 +2335,7 @@ uschar *previous_callout = NULL; const uschar *tempptr; uschar *previous = NULL; uschar *previous_callout = NULL; +uschar *save_hwm = NULL; uschar classbits[32]; #ifdef SUPPORT_UTF8 @@ -1631,8 +2345,13 @@ BOOL utf8 = FALSE; uschar utf8_char[6]; #else BOOL utf8 = FALSE; +uschar *utf8_char = NULL; #endif +#ifdef DEBUG +if (lengthptr != NULL) DPRINTF((">> start branch\n")); +#endif + /* Set up the default and non-default settings for greediness */ greedy_default = ((options & PCRE_UNGREEDY) != 0); @@ -1664,20 +2383,87 @@ for (;; ptr++) BOOL negate_class; BOOL possessive_quantifier; BOOL is_quantifier; + BOOL is_recurse; + BOOL reset_bracount; int class_charcount; int class_lastchar; int newoptions; int recno; + int refsign; int skipbytes; int subreqbyte; int subfirstbyte; + int terminator; int mclength; uschar mcbuffer[8]; - /* Next byte in the pattern */ + /* Get next byte in the pattern */ c = *ptr; + /* If we are in the pre-compile phase, accumulate the length used for the + previous cycle of this loop. */ + + if (lengthptr != NULL) + { +#ifdef DEBUG + if (code > cd->hwm) cd->hwm = code; /* High water info */ +#endif + if (code > cd->start_workspace + COMPILE_WORK_SIZE) /* Check for overrun */ + { + *errorcodeptr = ERR52; + goto FAILED; + } + + /* There is at least one situation where code goes backwards: this is the + case of a zero quantifier after a class (e.g. [ab]{0}). At compile time, + the class is simply eliminated. However, it is created first, so we have to + allow memory for it. Therefore, don't ever reduce the length at this point. + */ + + if (code < last_code) code = last_code; + + /* Paranoid check for integer overflow */ + + if (OFLOW_MAX - *lengthptr < code - last_code) + { + *errorcodeptr = ERR20; + goto FAILED; + } + + *lengthptr += code - last_code; + DPRINTF(("length=%d added %d c=%c\n", *lengthptr, code - last_code, c)); + + /* If "previous" is set and it is not at the start of the work space, move + it back to there, in order to avoid filling up the work space. Otherwise, + if "previous" is NULL, reset the current code pointer to the start. */ + + if (previous != NULL) + { + if (previous > orig_code) + { + memmove(orig_code, previous, code - previous); + code -= previous - orig_code; + previous = orig_code; + } + } + else code = orig_code; + + /* Remember where this code item starts so we can pick up the length + next time round. */ + + last_code = code; + } + + /* In the real compile phase, just check the workspace used by the forward + reference list. */ + + else if (cd->hwm > cd->start_workspace + COMPILE_WORK_SIZE) + { + *errorcodeptr = ERR52; + goto FAILED; + } + /* If in \Q...\E, check for the end; if not, we have a literal */ if (inescq && c != 0) @@ -1692,7 +2478,8 @@ for (;; ptr++) { if (previous_callout != NULL) { - complete_callout(previous_callout, ptr, cd); + if (lengthptr == NULL) /* Don't attempt in pre-compile phase */ + complete_callout(previous_callout, ptr, cd); previous_callout = NULL; } if ((options & PCRE_AUTO_CALLOUT) != 0) @@ -1713,7 +2500,8 @@ for (;; ptr++) if (!is_quantifier && previous_callout != NULL && after_manual_callout-- <= 0) { - complete_callout(previous_callout, ptr, cd); + if (lengthptr == NULL) /* Don't attempt in pre-compile phase */ + complete_callout(previous_callout, ptr, cd); previous_callout = NULL; } @@ -1724,12 +2512,12 @@ for (;; ptr++) if ((cd->ctypes[c] & ctype_space) != 0) continue; if (c == '#') { - while (*(++ptr) != 0) if (IS_NEWLINE(ptr)) break; - if (*ptr != 0) + while (*(++ptr) != 0) { - ptr += cd->nllen - 1; - continue; + if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; } } + if (*ptr != 0) continue; + /* Else fall through to handle end of string */ c = 0; } @@ -1745,17 +2533,28 @@ for (;; ptr++) switch(c) { - /* The branch terminates at end of string, |, or ). */ - - case 0: - case '|': + /* ===================================================================*/ + case 0: /* The branch terminates at string end */ + case '|': /* or | or ) */ case ')': *firstbyteptr = firstbyte; *reqbyteptr = reqbyte; *codeptr = code; *ptrptr = ptr; + if (lengthptr != NULL) + { + if (OFLOW_MAX - *lengthptr < code - last_code) + { + *errorcodeptr = ERR20; + goto FAILED; + } + *lengthptr += code - last_code; /* To include callout length */ + DPRINTF((">> end branch\n")); + } return TRUE; + + /* ===================================================================*/ /* Handle single-character metacharacters. In multiline mode, ^ disables the setting of any following char as a first character. */ @@ -1784,6 +2583,8 @@ for (;; ptr++) *code++ = OP_ANY; break; + + /* ===================================================================*/ /* Character classes. If the included characters are all < 256, we build a 32-byte bitmap of the permitted characters, except in the special case where there is only one such character. For negated classes, we build the @@ -1809,45 +2610,52 @@ for (;; ptr++) goto FAILED; } - /* If the first character is '^', set the negation flag and skip it. */ + /* If the first character is '^', set the negation flag and skip it. Also, + if the first few characters (either before or after ^) are \Q\E or \E we + skip them too. This makes for compatibility with Perl. */ - if ((c = *(++ptr)) == '^') + negate_class = FALSE; + for (;;) { - negate_class = TRUE; c = *(++ptr); + if (c == '\\') + { + if (ptr[1] == 'E') ptr++; + else if (strncmp((const char *)ptr+1, "Q\\E", 3) == 0) ptr += 3; + else break; + } + else if (!negate_class && c == '^') + negate_class = TRUE; + else break; } - else - { - negate_class = FALSE; - } /* Keep a count of chars with values < 256 so that we can optimize the case - of just a single character (as long as it's < 256). For higher valued UTF-8 - characters, we don't yet do any optimization. */ + of just a single character (as long as it's < 256). However, For higher + valued UTF-8 characters, we don't yet do any optimization. */ class_charcount = 0; class_lastchar = -1; + /* Initialize the 32-char bit map to all zeros. We build the map in a + temporary bit of memory, in case the class contains only 1 character (less + than 256), because in that case the compiled code doesn't use the bit map. + */ + + memset(classbits, 0, 32 * sizeof(uschar)); + #ifdef SUPPORT_UTF8 class_utf8 = FALSE; /* No chars >= 256 */ - class_utf8data = code + LINK_SIZE + 34; /* For UTF-8 items */ + class_utf8data = code + LINK_SIZE + 2; /* For UTF-8 items */ #endif - /* Initialize the 32-char bit map to all zeros. We have to build the - map in a temporary bit of store, in case the class contains only 1 - character (< 256), because in that case the compiled code doesn't use the - bit map. */ - - memset(classbits, 0, 32 * sizeof(uschar)); - /* Process characters until ] is reached. By writing this as a "do" it - means that an initial ] is taken as a data character. The first pass - through the regex checked the overall syntax, so we don't need to be very - strict here. At the start of the loop, c contains the first byte of the - character. */ + means that an initial ] is taken as a data character. At the start of the + loop, c contains the first byte of the character. */ - do + if (c != 0) do { + const uschar *oldptr; + #ifdef SUPPORT_UTF8 if (utf8 && c > 127) { /* Braces are required because the */ @@ -1859,13 +2667,13 @@ for (;; ptr++) if (inescq) { - if (c == '\\' && ptr[1] == 'E') + if (c == '\\' && ptr[1] == 'E') /* If we are at \E */ { - inescq = FALSE; - ptr++; - continue; + inescq = FALSE; /* Reset literal state */ + ptr++; /* Skip the 'E' */ + continue; /* Carry on with next */ } - else goto LONE_SINGLE_CHARACTER; + goto CHECK_RANGE; /* Could be range if \E follows */ } /* Handle POSIX class names. Perl allows a negation extension of the @@ -1956,19 +2764,20 @@ for (;; ptr++) } /* Backslash may introduce a single character, or it may introduce one - of the specials, which just set a flag. Escaped items are checked for - validity in the pre-compiling pass. The sequence \b is a special case. - Inside a class (and only there) it is treated as backspace. Elsewhere - it marks a word boundary. Other escapes have preset maps ready to - or into the one we are building. We assume they have more than one + of the specials, which just set a flag. The sequence \b is a special + case. Inside a class (and only there) it is treated as backspace. + Elsewhere it marks a word boundary. Other escapes have preset maps ready + to 'or' into the one we are building. We assume they have more than one character in them, so set class_charcount bigger than one. */ if (c == '\\') { - c = check_escape(&ptr, errorcodeptr, *brackets, options, TRUE); + c = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE); + if (*errorcodeptr != 0) goto FAILED; if (-c == ESC_b) c = '\b'; /* \b is backslash in a class */ else if (-c == ESC_X) c = 'X'; /* \X is literal X in a class */ + else if (-c == ESC_R) c = 'R'; /* \R is literal R in a class */ else if (-c == ESC_Q) /* Handle start of quoted string */ { if (ptr[1] == '\\' && ptr[2] == 'E') @@ -1978,12 +2787,16 @@ for (;; ptr++) else inescq = TRUE; continue; } + else if (-c == ESC_E) continue; /* Ignore orphan \E */ if (c < 0) { register const uschar *cbits = cd->cbits; class_charcount += 2; /* Greater than 1 is what matters */ - switch (-c) + + /* Save time by not doing this in the pre-compile phase. */ + + if (lengthptr == NULL) switch (-c) { case ESC_d: for (c = 0; c < 32; c++) classbits[c] |= cbits[c+cbit_digit]; @@ -2011,53 +2824,225 @@ for (;; ptr++) classbits[1] |= 0x08; /* Perl 5.004 onwards omits VT from \s */ continue; -#ifdef SUPPORT_UCP - case ESC_p: - case ESC_P: + case ESC_E: /* Perl ignores an orphan \E */ + continue; + + default: /* Not recognized; fall through */ + break; /* Need "default" setting to stop compiler warning. */ + } + + /* In the pre-compile phase, just do the recognition. */ + + else if (c == -ESC_d || c == -ESC_D || c == -ESC_w || + c == -ESC_W || c == -ESC_s || c == -ESC_S) continue; + + /* We need to deal with \H, \h, \V, and \v in both phases because + they use extra memory. */ + + if (-c == ESC_h) + { + SETBIT(classbits, 0x09); /* VT */ + SETBIT(classbits, 0x20); /* SPACE */ + SETBIT(classbits, 0xa0); /* NSBP */ +#ifdef SUPPORT_UTF8 + if (utf8) { - BOOL negated; - int pdata; - int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr); - if (ptype < 0) goto FAILED; class_utf8 = TRUE; - *class_utf8data++ = ((-c == ESC_p) != negated)? - XCL_PROP : XCL_NOTPROP; - *class_utf8data++ = ptype; - *class_utf8data++ = pdata; - class_charcount -= 2; /* Not a < 256 character */ + *class_utf8data++ = XCL_SINGLE; + class_utf8data += _pcre_ord2utf8(0x1680, class_utf8data); + *class_utf8data++ = XCL_SINGLE; + class_utf8data += _pcre_ord2utf8(0x180e, class_utf8data); + *class_utf8data++ = XCL_RANGE; + class_utf8data += _pcre_ord2utf8(0x2000, class_utf8data); + class_utf8data += _pcre_ord2utf8(0x200A, class_utf8data); + *class_utf8data++ = XCL_SINGLE; + class_utf8data += _pcre_ord2utf8(0x202f, class_utf8data); + *class_utf8data++ = XCL_SINGLE; + class_utf8data += _pcre_ord2utf8(0x205f, class_utf8data); + *class_utf8data++ = XCL_SINGLE; + class_utf8data += _pcre_ord2utf8(0x3000, class_utf8data); } +#endif continue; + } + + if (-c == ESC_H) + { + for (c = 0; c < 32; c++) + { + int x = 0xff; + switch (c) + { + case 0x09/8: x ^= 1 << (0x09%8); break; + case 0x20/8: x ^= 1 << (0x20%8); break; + case 0xa0/8: x ^= 1 << (0xa0%8); break; + default: break; + } + classbits[c] |= x; + } + +#ifdef SUPPORT_UTF8 + if (utf8) + { + class_utf8 = TRUE; + *class_utf8data++ = XCL_RANGE; + class_utf8data += _pcre_ord2utf8(0x0100, class_utf8data); + class_utf8data += _pcre_ord2utf8(0x167f, class_utf8data); + *class_utf8data++ = XCL_RANGE; + class_utf8data += _pcre_ord2utf8(0x1681, class_utf8data); + class_utf8data += _pcre_ord2utf8(0x180d, class_utf8data); + *class_utf8data++ = XCL_RANGE; + class_utf8data += _pcre_ord2utf8(0x180f, class_utf8data); + class_utf8data += _pcre_ord2utf8(0x1fff, class_utf8data); + *class_utf8data++ = XCL_RANGE; + class_utf8data += _pcre_ord2utf8(0x200B, class_utf8data); + class_utf8data += _pcre_ord2utf8(0x202e, class_utf8data); + *class_utf8data++ = XCL_RANGE; + class_utf8data += _pcre_ord2utf8(0x2030, class_utf8data); + class_utf8data += _pcre_ord2utf8(0x205e, class_utf8data); + *class_utf8data++ = XCL_RANGE; + class_utf8data += _pcre_ord2utf8(0x2060, class_utf8data); + class_utf8data += _pcre_ord2utf8(0x2fff, class_utf8data); + *class_utf8data++ = XCL_RANGE; + class_utf8data += _pcre_ord2utf8(0x3001, class_utf8data); + class_utf8data += _pcre_ord2utf8(0x7fffffff, class_utf8data); + } #endif + continue; + } - /* Unrecognized escapes are faulted if PCRE is running in its - strict mode. By default, for compatibility with Perl, they are - treated as literals. */ + if (-c == ESC_v) + { + SETBIT(classbits, 0x0a); /* LF */ + SETBIT(classbits, 0x0b); /* VT */ + SETBIT(classbits, 0x0c); /* FF */ + SETBIT(classbits, 0x0d); /* CR */ + SETBIT(classbits, 0x85); /* NEL */ +#ifdef SUPPORT_UTF8 + if (utf8) + { + class_utf8 = TRUE; + *class_utf8data++ = XCL_RANGE; + class_utf8data += _pcre_ord2utf8(0x2028, class_utf8data); + class_utf8data += _pcre_ord2utf8(0x2029, class_utf8data); + } +#endif + continue; + } - default: - if ((options & PCRE_EXTRA) != 0) + if (-c == ESC_V) + { + for (c = 0; c < 32; c++) { - *errorcodeptr = ERR7; - goto FAILED; + int x = 0xff; + switch (c) + { + case 0x0a/8: x ^= 1 << (0x0a%8); + x ^= 1 << (0x0b%8); + x ^= 1 << (0x0c%8); + x ^= 1 << (0x0d%8); + break; + case 0x85/8: x ^= 1 << (0x85%8); break; + default: break; + } + classbits[c] |= x; } - c = *ptr; /* The final character */ - class_charcount -= 2; /* Undo the default count from above */ + +#ifdef SUPPORT_UTF8 + if (utf8) + { + class_utf8 = TRUE; + *class_utf8data++ = XCL_RANGE; + class_utf8data += _pcre_ord2utf8(0x0100, class_utf8data); + class_utf8data += _pcre_ord2utf8(0x2027, class_utf8data); + *class_utf8data++ = XCL_RANGE; + class_utf8data += _pcre_ord2utf8(0x2029, class_utf8data); + class_utf8data += _pcre_ord2utf8(0x7fffffff, class_utf8data); + } +#endif + continue; } + + /* We need to deal with \P and \p in both phases. */ + +#ifdef SUPPORT_UCP + if (-c == ESC_p || -c == ESC_P) + { + BOOL negated; + int pdata; + int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr); + if (ptype < 0) goto FAILED; + class_utf8 = TRUE; + *class_utf8data++ = ((-c == ESC_p) != negated)? + XCL_PROP : XCL_NOTPROP; + *class_utf8data++ = ptype; + *class_utf8data++ = pdata; + class_charcount -= 2; /* Not a < 256 character */ + continue; + } +#endif + /* Unrecognized escapes are faulted if PCRE is running in its + strict mode. By default, for compatibility with Perl, they are + treated as literals. */ + + if ((options & PCRE_EXTRA) != 0) + { + *errorcodeptr = ERR7; + goto FAILED; + } + + class_charcount -= 2; /* Undo the default count from above */ + c = *ptr; /* Get the final character and fall through */ } /* Fall through if we have a single character (c >= 0). This may be - > 256 in UTF-8 mode. */ + greater than 256 in UTF-8 mode. */ } /* End of backslash handling */ /* A single character may be followed by '-' to form a range. However, Perl does not permit ']' to be the end of the range. A '-' character - here is treated as a literal. */ + at the end is treated as a literal. Perl ignores orphaned \E sequences + entirely. The code for handling \Q and \E is messy. */ - if (ptr[1] == '-' && ptr[2] != ']') + CHECK_RANGE: + while (ptr[1] == '\\' && ptr[2] == 'E') { + inescq = FALSE; + ptr += 2; + } + + oldptr = ptr; + + /* Remember \r or \n */ + + if (c == '\r' || c == '\n') cd->external_flags |= PCRE_HASCRORLF; + + /* Check for range */ + + if (!inescq && ptr[1] == '-') + { int d; ptr += 2; + while (*ptr == '\\' && ptr[1] == 'E') ptr += 2; + /* If we hit \Q (not followed by \E) at this point, go into escaped + mode. */ + + while (*ptr == '\\' && ptr[1] == 'Q') + { + ptr += 2; + if (*ptr == '\\' && ptr[1] == 'E') { ptr += 2; continue; } + inescq = TRUE; + break; + } + + if (*ptr == 0 || (!inescq && *ptr == ']')) + { + ptr = oldptr; + goto LONE_SINGLE_CHARACTER; + } + #ifdef SUPPORT_UTF8 if (utf8) { /* Braces are required because the */ @@ -2071,30 +3056,41 @@ for (;; ptr++) not any of the other escapes. Perl 5.6 treats a hyphen as a literal in such circumstances. */ - if (d == '\\') + if (!inescq && d == '\\') { - const uschar *oldptr = ptr; - d = check_escape(&ptr, errorcodeptr, *brackets, options, TRUE); + d = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE); + if (*errorcodeptr != 0) goto FAILED; - /* \b is backslash; \X is literal X; any other special means the '-' - was literal */ + /* \b is backslash; \X is literal X; \R is literal R; any other + special means the '-' was literal */ if (d < 0) { if (d == -ESC_b) d = '\b'; - else if (d == -ESC_X) d = 'X'; else + else if (d == -ESC_X) d = 'X'; + else if (d == -ESC_R) d = 'R'; else { - ptr = oldptr - 2; + ptr = oldptr; goto LONE_SINGLE_CHARACTER; /* A few lines below */ } } } - /* The check that the two values are in the correct order happens in - the pre-pass. Optimize one-character ranges */ + /* Check that the two values are in the correct order. Optimize + one-character ranges */ + if (d < c) + { + *errorcodeptr = ERR8; + goto FAILED; + } + if (d == c) goto LONE_SINGLE_CHARACTER; /* A few lines below */ + /* Remember \r or \n */ + + if (d == '\r' || d == '\n') cd->external_flags |= PCRE_HASCRORLF; + /* In UTF-8 mode, if the upper limit is > 255, or > 127 for caseless matching, we have to use an XCLASS with extra data items. Caseless matching for characters > 127 is available only if UCP support is @@ -2112,19 +3108,23 @@ for (;; ptr++) #ifdef SUPPORT_UCP if ((options & PCRE_CASELESS) != 0) { - int occ, ocd; - int cc = c; - int origd = d; + unsigned int occ, ocd; + unsigned int cc = c; + unsigned int origd = d; while (get_othercase_range(&cc, origd, &occ, &ocd)) { - if (occ >= c && ocd <= d) continue; /* Skip embedded ranges */ + if (occ >= (unsigned int)c && + ocd <= (unsigned int)d) + continue; /* Skip embedded ranges */ - if (occ < c && ocd >= c - 1) /* Extend the basic range */ + if (occ < (unsigned int)c && + ocd >= (unsigned int)c - 1) /* Extend the basic range */ { /* if there is overlap, */ c = occ; /* noting that if occ < c */ continue; /* we can't have ocd > d */ } /* because a subrange is */ - if (ocd > d && occ <= d + 1) /* always shorter than */ + if (ocd > (unsigned int)d && + occ <= (unsigned int)d + 1) /* always shorter than */ { /* the basic range. */ d = ocd; continue; @@ -2172,7 +3172,12 @@ for (;; ptr++) ranges that lie entirely within 0-127 when there is UCP support; else for partial ranges without UCP support. */ - for (; c <= d; c++) + class_charcount += d - c + 1; + class_lastchar = d; + + /* We can save a bit of time by skipping this in the pre-compile. */ + + if (lengthptr == NULL) for (; c <= d; c++) { classbits[c/8] |= (1 << (c&7)); if ((options & PCRE_CASELESS) != 0) @@ -2180,8 +3185,6 @@ for (;; ptr++) int uc = cd->fcc[c]; /* flip case */ classbits[uc/8] |= (1 << (uc&7)); } - class_charcount++; /* in case a one-char range */ - class_lastchar = c; } continue; /* Go get the next char in the class */ @@ -2205,8 +3208,8 @@ for (;; ptr++) #ifdef SUPPORT_UCP if ((options & PCRE_CASELESS) != 0) { - int othercase; - if ((othercase = _pcre_ucp_othercase(c)) >= 0) + unsigned int othercase; + if ((othercase = _pcre_ucp_othercase(c)) != NOTACHAR) { *class_utf8data++ = XCL_SINGLE; class_utf8data += _pcre_ord2utf8(othercase, class_utf8data); @@ -2231,18 +3234,45 @@ for (;; ptr++) } } - /* Loop until ']' reached; the check for end of string happens inside the - loop. This "while" is the end of the "do" above. */ + /* Loop until ']' reached. This "while" is the end of the "do" above. */ - while ((c = *(++ptr)) != ']' || inescq); + while ((c = *(++ptr)) != 0 && (c != ']' || inescq)); + if (c == 0) /* Missing terminating ']' */ + { + *errorcodeptr = ERR6; + goto FAILED; + } + + +/* This code has been disabled because it would mean that \s counts as +an explicit \r or \n reference, and that's not really what is wanted. Now +we set the flag only if there is a literal "\r" or "\n" in the class. */ + +#if 0 + /* Remember whether \r or \n are in this class */ + + if (negate_class) + { + if ((classbits[1] & 0x24) != 0x24) cd->external_flags |= PCRE_HASCRORLF; + } + else + { + if ((classbits[1] & 0x24) != 0) cd->external_flags |= PCRE_HASCRORLF; + } +#endif + + /* If class_charcount is 1, we saw precisely one character whose value is - less than 256. In non-UTF-8 mode we can always optimize. In UTF-8 mode, we - can optimize the negative case only if there were no characters >= 128 - because OP_NOT and the related opcodes like OP_NOTSTAR operate on - single-bytes only. This is an historical hangover. Maybe one day we can - tidy these opcodes to handle multi-byte characters. + less than 256. As long as there were no characters >= 128 and there was no + use of \p or \P, in other words, no use of any XCLASS features, we can + optimize. + In UTF-8 mode, we can optimize the negative case only if there were no + characters >= 128 because OP_NOT and the related opcodes like OP_NOTSTAR + operate on single-bytes only. This is an historical hangover. Maybe one day + we can tidy these opcodes to handle multi-byte characters. + The optimization throws away the bit map. We turn the item into a 1-character OP_CHAR[NC] if it's positive, or OP_NOT if it's negative. Note that OP_NOT does not support multibyte characters. In the positive case, it @@ -2251,10 +3281,8 @@ for (;; ptr++) reqbyte, save the previous value for reinstating. */ #ifdef SUPPORT_UTF8 - if (class_charcount == 1 && - (!utf8 || - (!class_utf8 && (!negate_class || class_lastchar < 128)))) - + if (class_charcount == 1 && !class_utf8 && + (!utf8 || !negate_class || class_lastchar < 128)) #else if (class_charcount == 1) #endif @@ -2298,7 +3326,7 @@ for (;; ptr++) /* If there are characters with values > 255, we have to compile an extended class, with its own opcode. If there are no characters < 256, - we can omit the bitmap. */ + we can omit the bitmap in the actual compiled code. */ #ifdef SUPPORT_UTF8 if (class_utf8) @@ -2308,25 +3336,18 @@ for (;; ptr++) code += LINK_SIZE; *code = negate_class? XCL_NOT : 0; - /* If the map is required, install it, and move on to the end of - the extra data */ + /* If the map is required, move up the extra data to make room for it; + otherwise just move the code pointer to the end of the extra data. */ if (class_charcount > 0) { *code++ |= XCL_MAP; + memmove(code + 32, code, class_utf8data - code); memcpy(code, classbits, 32); - code = class_utf8data; + code = class_utf8data + 32; } + else code = class_utf8data; - /* If the map is not required, slide down the extra data. */ - - else - { - int len = class_utf8data - (code + 33); - memmove(code + 1, code + 33, len); - code += len + 1; - } - /* Now fill in the complete length of the item */ PUT(previous, 1, code - previous); @@ -2342,7 +3363,8 @@ for (;; ptr++) if (negate_class) { *code++ = OP_NCLASS; - for (c = 0; c < 32; c++) code[c] = ~classbits[c]; + if (lengthptr == NULL) /* Save time in the pre-compile phase */ + for (c = 0; c < 32; c++) code[c] = ~classbits[c]; } else { @@ -2352,6 +3374,8 @@ for (;; ptr++) code += 32; break; + + /* ===================================================================*/ /* Various kinds of repeat; '{' is not necessarily a quantifier, but this has been tested above. */ @@ -2419,20 +3443,6 @@ for (;; ptr++) } else repeat_type = greedy_default; - /* If previous was a recursion, we need to wrap it inside brackets so that - it can be replicated if necessary. */ - - if (*previous == OP_RECURSE) - { - memmove(previous + 1 + LINK_SIZE, previous, 1 + LINK_SIZE); - code += 1 + LINK_SIZE; - *previous = OP_BRA; - PUT(previous, 1, code - previous); - *code = OP_KET; - PUT(code, 1, code - previous); - code += 1 + LINK_SIZE; - } - /* If previous was a character match, abolish the item and generate a repeat item instead. If a char item has a minumum of more than one, ensure that it is set in reqbyte - it might not be if a sequence such as x{3} is @@ -2466,18 +3476,40 @@ for (;; ptr++) if (repeat_min > 1) reqbyte = c | req_caseopt | cd->req_varyopt; } + /* If the repetition is unlimited, it pays to see if the next thing on + the line is something that cannot possibly match this character. If so, + automatically possessifying this item gains some performance in the case + where the match fails. */ + + if (!possessive_quantifier && + repeat_max < 0 && + check_auto_possessive(*previous, c, utf8, utf8_char, ptr + 1, + options, cd)) + { + repeat_type = 0; /* Force greedy */ + possessive_quantifier = TRUE; + } + goto OUTPUT_SINGLE_REPEAT; /* Code shared with single character types */ } /* If previous was a single negated character ([^a] or similar), we use one of the special opcodes, replacing it. The code is shared with single- character repeats by setting opt_type to add a suitable offset into - repeat_type. OP_NOT is currently used only for single-byte chars. */ + repeat_type. We can also test for auto-possessification. OP_NOT is + currently used only for single-byte chars. */ else if (*previous == OP_NOT) { op_type = OP_NOTSTAR - OP_STAR; /* Use "not" opcodes */ c = previous[1]; + if (!possessive_quantifier && + repeat_max < 0 && + check_auto_possessive(OP_NOT, c, utf8, NULL, ptr + 1, options, cd)) + { + repeat_type = 0; /* Force greedy */ + possessive_quantifier = TRUE; + } goto OUTPUT_SINGLE_REPEAT; } @@ -2495,6 +3527,14 @@ for (;; ptr++) op_type = OP_TYPESTAR - OP_STAR; /* Use type opcodes */ c = *previous; + if (!possessive_quantifier && + repeat_max < 0 && + check_auto_possessive(c, 0, utf8, NULL, ptr + 1, options, cd)) + { + repeat_type = 0; /* Force greedy */ + possessive_quantifier = TRUE; + } + OUTPUT_SINGLE_REPEAT: if (*previous == OP_PROP || *previous == OP_NOTPROP) { @@ -2514,7 +3554,7 @@ for (;; ptr++) /* All real repeats make it impossible to handle partial matching (maybe one day we will be able to remove this restriction). */ - if (repeat_max != 1) cd->nopartial = TRUE; + if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; /* Combine the op_type with the repeat_type */ @@ -2535,7 +3575,7 @@ for (;; ptr++) } /* A repeat minimum of 1 is optimized into some special cases. If the - maximum is unlimited, we use OP_PLUS. Otherwise, the original item it + maximum is unlimited, we use OP_PLUS. Otherwise, the original item is left in place and, if the maximum is greater than 1, we use OP_UPTO with one less than the maximum. */ @@ -2588,7 +3628,8 @@ for (;; ptr++) } /* Else insert an UPTO if the max is greater than the min, again - preceded by the character, for the previously inserted code. */ + preceded by the character, for the previously inserted code. If the + UPTO is just for 1 instance, we can use QUERY instead. */ else if (repeat_max != repeat_min) { @@ -2607,8 +3648,16 @@ for (;; ptr++) *code++ = prop_value; } repeat_max -= repeat_min; - *code++ = OP_UPTO + repeat_type; - PUT2INC(code, 0, repeat_max); + + if (repeat_max == 1) + { + *code++ = OP_QUERY + repeat_type; + } + else + { + *code++ = OP_UPTO + repeat_type; + PUT2INC(code, 0, repeat_max); + } } } @@ -2655,7 +3704,7 @@ for (;; ptr++) /* All real repeats make it impossible to handle partial matching (maybe one day we will be able to remove this restriction). */ - if (repeat_max != 1) cd->nopartial = TRUE; + if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; if (repeat_min == 0 && repeat_max == -1) *code++ = OP_CRSTAR + repeat_type; @@ -2675,14 +3724,22 @@ for (;; ptr++) /* If previous was a bracket group, we may have to replicate it in certain cases. */ - else if (*previous >= OP_BRA || *previous == OP_ONCE || - *previous == OP_COND) + else if (*previous == OP_BRA || *previous == OP_CBRA || + *previous == OP_ONCE || *previous == OP_COND) { register int i; int ketoffset = 0; int len = code - previous; uschar *bralink = NULL; + /* Repeating a DEFINE group is pointless */ + + if (*previous == OP_COND && previous[LINK_SIZE+1] == OP_DEF) + { + *errorcodeptr = ERR55; + goto FAILED; + } + /* If the maximum repeat count is unlimited, find the end of the bracket by scanning through from the start, and compute the offset back to it from the current code pointer. There may be an OP_OPT setting following @@ -2717,13 +3774,14 @@ for (;; ptr++) /* If the maximum is 1 or unlimited, we just have to stick in the BRAZERO and do no more at this point. However, we do need to adjust any OP_RECURSE calls inside the group that refer to the group itself or - any internal group, because the offset is from the start of the whole - regex. Temporarily terminate the pattern while doing this. */ + any internal or forward referenced group, because the offset is from + the start of the whole regex. Temporarily terminate the pattern while + doing this. */ if (repeat_max <= 1) { *code = OP_END; - adjust_recurse(previous, 1, utf8, cd); + adjust_recurse(previous, 1, utf8, cd, save_hwm); memmove(previous+1, previous, len); code++; *previous++ = OP_BRAZERO + repeat_type; @@ -2741,7 +3799,7 @@ for (;; ptr++) { int offset; *code = OP_END; - adjust_recurse(previous, 2 + LINK_SIZE, utf8, cd); + adjust_recurse(previous, 2 + LINK_SIZE, utf8, cd, save_hwm); memmove(previous + 2 + LINK_SIZE, previous, len); code += 2 + LINK_SIZE; *previous++ = OP_BRAZERO + repeat_type; @@ -2761,19 +3819,52 @@ for (;; ptr++) /* If the minimum is greater than zero, replicate the group as many times as necessary, and adjust the maximum to the number of subsequent copies that we need. If we set a first char from the group, and didn't - set a required char, copy the latter from the former. */ + set a required char, copy the latter from the former. If there are any + forward reference subroutine calls in the group, there will be entries on + the workspace list; replicate these with an appropriate increment. */ else { if (repeat_min > 1) { - if (groupsetfirstbyte && reqbyte < 0) reqbyte = firstbyte; - for (i = 1; i < repeat_min; i++) + /* In the pre-compile phase, we don't actually do the replication. We + just adjust the length as if we had. Do some paranoid checks for + potential integer overflow. */ + + if (lengthptr != NULL) { - memcpy(code, previous, len); - code += len; + int delta = (repeat_min - 1)*length_prevgroup; + if ((double)(repeat_min - 1)*(double)length_prevgroup > + (double)INT_MAX || + OFLOW_MAX - *lengthptr < delta) + { + *errorcodeptr = ERR20; + goto FAILED; + } + *lengthptr += delta; } + + /* This is compiling for real */ + + else + { + if (groupsetfirstbyte && reqbyte < 0) reqbyte = firstbyte; + for (i = 1; i < repeat_min; i++) + { + uschar *hc; + uschar *this_hwm = cd->hwm; + memcpy(code, previous, len); + for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE) + { + PUT(cd->hwm, 0, GET(hc, 0) + len); + cd->hwm += LINK_SIZE; + } + save_hwm = this_hwm; + code += len; + } + } } + if (repeat_max > 0) repeat_max -= repeat_min; } @@ -2781,12 +3872,39 @@ for (;; ptr++) the maximum is limited, it replicates the group in a nested fashion, remembering the bracket starts on a stack. In the case of a zero minimum, the first one was set up above. In all cases the repeat_max now specifies - the number of additional copies needed. */ + the number of additional copies needed. Again, we must remember to + replicate entries on the forward reference list. */ if (repeat_max >= 0) { - for (i = repeat_max - 1; i >= 0; i--) + /* In the pre-compile phase, we don't actually do the replication. We + just adjust the length as if we had. For each repetition we must add 1 + to the length for BRAZERO and for all but the last repetition we must + add 2 + 2*LINKSIZE to allow for the nesting that occurs. Do some + paranoid checks to avoid integer overflow. */ + + if (lengthptr != NULL && repeat_max > 0) { + int delta = repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) - + 2 - 2*LINK_SIZE; /* Last one doesn't nest */ + if ((double)repeat_max * + (double)(length_prevgroup + 1 + 2 + 2*LINK_SIZE) + > (double)INT_MAX || + OFLOW_MAX - *lengthptr < delta) + { + *errorcodeptr = ERR20; + goto FAILED; + } + *lengthptr += delta; + } + + /* This is compiling for real */ + + else for (i = repeat_max - 1; i >= 0; i--) + { + uschar *hc; + uschar *this_hwm = cd->hwm; + *code++ = OP_BRAZERO + repeat_type; /* All but the final copy start a new nesting, maintaining the @@ -2802,6 +3920,12 @@ for (;; ptr++) } memcpy(code, previous, len); + for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE) + { + PUT(cd->hwm, 0, GET(hc, 0) + len + ((i != 0)? 2+LINK_SIZE : 1)); + cd->hwm += LINK_SIZE; + } + save_hwm = this_hwm; code += len; } @@ -2824,9 +3948,34 @@ for (;; ptr++) /* If the maximum is unlimited, set a repeater in the final copy. We can't just offset backwards from the current code point, because we don't know if there's been an options resetting after the ket. The - correct offset was computed above. */ + correct offset was computed above. - else code[-ketoffset] = OP_KETRMAX + repeat_type; + Then, when we are doing the actual compile phase, check to see whether + this group is a non-atomic one that could match an empty string. If so, + convert the initial operator to the S form (e.g. OP_BRA -> OP_SBRA) so + that runtime checking can be done. [This check is also applied to + atomic groups at runtime, but in a different way.] */ + + else + { + uschar *ketcode = code - ketoffset; + uschar *bracode = ketcode - GET(ketcode, 1); + *ketcode = OP_KETRMAX + repeat_type; + if (lengthptr == NULL && *bracode != OP_ONCE) + { + uschar *scode = bracode; + do + { + if (could_be_empty_branch(scode, ketcode, utf8)) + { + *bracode += OP_SBRA - OP_BRA; + break; + } + scode += GET(scode, 1); + } + while (*scode == OP_ALT); + } + } } /* Else there's some kind of shambles */ @@ -2837,22 +3986,53 @@ for (;; ptr++) goto FAILED; } - /* If the character following a repeat is '+', we wrap the entire repeated - item inside OP_ONCE brackets. This is just syntactic sugar, taken from - Sun's Java package. The repeated item starts at tempcode, not at previous, - which might be the first part of a string whose (former) last char we - repeated. However, we don't support '+' after a greediness '?'. */ + /* If the character following a repeat is '+', or if certain optimization + tests above succeeded, possessive_quantifier is TRUE. For some of the + simpler opcodes, there is an special alternative opcode for this. For + anything else, we wrap the entire repeated item inside OP_ONCE brackets. + The '+' notation is just syntactic sugar, taken from Sun's Java package, + but the special opcodes can optimize it a bit. The repeated item starts at + tempcode, not at previous, which might be the first part of a string whose + (former) last char we repeated. + Possessifying an 'exact' quantifier has no effect, so we can ignore it. But + an 'upto' may follow. We skip over an 'exact' item, and then test the + length of what remains before proceeding. */ + if (possessive_quantifier) { - int len = code - tempcode; - memmove(tempcode + 1+LINK_SIZE, tempcode, len); - code += 1 + LINK_SIZE; - len += 1 + LINK_SIZE; - tempcode[0] = OP_ONCE; - *code++ = OP_KET; - PUTINC(code, 0, len); - PUT(tempcode, 1, len); + int len; + if (*tempcode == OP_EXACT || *tempcode == OP_TYPEEXACT || + *tempcode == OP_NOTEXACT) + tempcode += _pcre_OP_lengths[*tempcode]; + len = code - tempcode; + if (len > 0) switch (*tempcode) + { + case OP_STAR: *tempcode = OP_POSSTAR; break; + case OP_PLUS: *tempcode = OP_POSPLUS; break; + case OP_QUERY: *tempcode = OP_POSQUERY; break; + case OP_UPTO: *tempcode = OP_POSUPTO; break; + + case OP_TYPESTAR: *tempcode = OP_TYPEPOSSTAR; break; + case OP_TYPEPLUS: *tempcode = OP_TYPEPOSPLUS; break; + case OP_TYPEQUERY: *tempcode = OP_TYPEPOSQUERY; break; + case OP_TYPEUPTO: *tempcode = OP_TYPEPOSUPTO; break; + + case OP_NOTSTAR: *tempcode = OP_NOTPOSSTAR; break; + case OP_NOTPLUS: *tempcode = OP_NOTPOSPLUS; break; + case OP_NOTQUERY: *tempcode = OP_NOTPOSQUERY; break; + case OP_NOTUPTO: *tempcode = OP_NOTPOSUPTO; break; + + default: + memmove(tempcode + 1+LINK_SIZE, tempcode, len); + code += 1 + LINK_SIZE; + len += 1 + LINK_SIZE; + tempcode[0] = OP_ONCE; + *code++ = OP_KET; + PUTINC(code, 0, len); + PUT(tempcode, 1, len); + break; + } } /* In all case we no longer have a previous item. We also set the @@ -2865,162 +4045,354 @@ for (;; ptr++) break; - /* Start of nested bracket sub-expression, or comment or lookahead or - lookbehind or option setting or condition. First deal with special things - that can come after a bracket; all are introduced by ?, and the appearance - of any of them means that this is not a referencing group. They were - checked for validity in the first pass over the string, so we don't have to - check for syntax errors here. */ + /* ===================================================================*/ + /* Start of nested parenthesized sub-expression, or comment or lookahead or + lookbehind or option setting or condition or all the other extended + parenthesis forms. */ case '(': newoptions = options; skipbytes = 0; + bravalue = OP_CBRA; + save_hwm = cd->hwm; + reset_bracount = FALSE; - if (*(++ptr) == '?') + /* First deal with various "verbs" that can be introduced by '*'. */ + + if (*(++ptr) == '*' && (cd->ctypes[ptr[1]] & ctype_letter) != 0) { - int set, unset; + int i, namelen; + const char *vn = verbnames; + const uschar *name = ++ptr; + previous = NULL; + while ((cd->ctypes[*++ptr] & ctype_letter) != 0); + if (*ptr == ':') + { + *errorcodeptr = ERR59; /* Not supported */ + goto FAILED; + } + if (*ptr != ')') + { + *errorcodeptr = ERR60; + goto FAILED; + } + namelen = ptr - name; + for (i = 0; i < verbcount; i++) + { + if (namelen == verbs[i].len && + strncmp((char *)name, vn, namelen) == 0) + { + *code = verbs[i].op; + if (*code++ == OP_ACCEPT) cd->had_accept = TRUE; + break; + } + vn += verbs[i].len + 1; + } + if (i < verbcount) continue; + *errorcodeptr = ERR60; + goto FAILED; + } + + /* Deal with the extended parentheses; all are introduced by '?', and the + appearance of any of them means that this is not a capturing group. */ + + else if (*ptr == '?') + { + int i, set, unset, namelen; int *optset; + const uschar *name; + uschar *slot; switch (*(++ptr)) { case '#': /* Comment; skip to ket */ ptr++; - while (*ptr != ')') ptr++; + while (*ptr != 0 && *ptr != ')') ptr++; + if (*ptr == 0) + { + *errorcodeptr = ERR18; + goto FAILED; + } continue; - case ':': /* Non-extracting bracket */ + + /* ------------------------------------------------------------ */ + case '|': /* Reset capture count for each branch */ + reset_bracount = TRUE; + /* Fall through */ + + /* ------------------------------------------------------------ */ + case ':': /* Non-capturing bracket */ bravalue = OP_BRA; ptr++; break; + + /* ------------------------------------------------------------ */ case '(': bravalue = OP_COND; /* Conditional group */ - /* A condition can be a number, referring to a numbered group, a name, - referring to a named group, 'R', referring to recursion, or an - assertion. There are two unfortunate ambiguities, caused by history. - (a) 'R' can be the recursive thing or the name 'R', and (b) a number - could be a name that consists of digits. In both cases, we look for a - name first; if not found, we try the other cases. If the first - character after (?( is a word character, we know the rest up to ) will - also be word characters because the syntax was checked in the first - pass. */ + /* A condition can be an assertion, a number (referring to a numbered + group), a name (referring to a named group), or 'R', referring to + recursion. R and R&name are also permitted for recursion tests. - if ((cd->ctypes[ptr[1]] & ctype_word) != 0) + There are several syntaxes for testing a named group: (?(name)) is used + by Python; Perl 5.10 onwards uses (?() or (?('name')). + + There are two unfortunate ambiguities, caused by history. (a) 'R' can + be the recursive thing or the name 'R' (and similarly for 'R' followed + by digits), and (b) a number could be a name that consists of digits. + In both cases, we look for a name first; if not found, we try the other + cases. */ + + /* For conditions that are assertions, check the syntax, and then exit + the switch. This will take control down to where bracketed groups, + including assertions, are processed. */ + + if (ptr[1] == '?' && (ptr[2] == '=' || ptr[2] == '!' || ptr[2] == '<')) + break; + + /* Most other conditions use OP_CREF (a couple change to OP_RREF + below), and all need to skip 3 bytes at the start of the group. */ + + code[1+LINK_SIZE] = OP_CREF; + skipbytes = 3; + refsign = -1; + + /* Check for a test for recursion in a named group. */ + + if (ptr[1] == 'R' && ptr[2] == '&') { - int i, namelen; - int condref = 0; - const uschar *name; - uschar *slot = cd->name_table; + terminator = -1; + ptr += 2; + code[1+LINK_SIZE] = OP_RREF; /* Change the type of test */ + } - /* This is needed for all successful cases. */ + /* Check for a test for a named group's having been set, using the Perl + syntax (?() or (?('name') */ - skipbytes = 3; + else if (ptr[1] == '<') + { + terminator = '>'; + ptr++; + } + else if (ptr[1] == '\'') + { + terminator = '\''; + ptr++; + } + else + { + terminator = 0; + if (ptr[1] == '-' || ptr[1] == '+') refsign = *(++ptr); + } - /* Read the name, but also get it as a number if it's all digits */ + /* We now expect to read a name; any thing else is an error */ - name = ++ptr; - while (*ptr != ')') - { - if (condref >= 0) - condref = ((digitab[*ptr] & ctype_digit) != 0)? - condref * 10 + *ptr - '0' : -1; - ptr++; - } - namelen = ptr - name; + if ((cd->ctypes[ptr[1]] & ctype_word) == 0) + { + ptr += 1; /* To get the right offset */ + *errorcodeptr = ERR28; + goto FAILED; + } + + /* Read the name, but also get it as a number if it's all digits */ + + recno = 0; + name = ++ptr; + while ((cd->ctypes[*ptr] & ctype_word) != 0) + { + if (recno >= 0) + recno = ((digitab[*ptr] & ctype_digit) != 0)? + recno * 10 + *ptr - '0' : -1; ptr++; + } + namelen = ptr - name; - for (i = 0; i < cd->names_found; i++) - { - if (strncmp((char *)name, (char *)slot+2, namelen) == 0) break; - slot += cd->name_entry_size; - } + if ((terminator > 0 && *ptr++ != terminator) || *ptr++ != ')') + { + ptr--; /* Error offset */ + *errorcodeptr = ERR26; + goto FAILED; + } - /* Found a previous named subpattern */ + /* Do no further checking in the pre-compile phase. */ - if (i < cd->names_found) + if (lengthptr != NULL) break; + + /* In the real compile we do the work of looking for the actual + reference. If the string started with "+" or "-" we require the rest to + be digits, in which case recno will be set. */ + + if (refsign > 0) + { + if (recno <= 0) { - condref = GET2(slot, 0); - code[1+LINK_SIZE] = OP_CREF; - PUT2(code, 2+LINK_SIZE, condref); + *errorcodeptr = ERR58; + goto FAILED; } + if (refsign == '-') + { + recno = cd->bracount - recno + 1; + if (recno <= 0) + { + *errorcodeptr = ERR15; + goto FAILED; + } + } + else recno += cd->bracount; + PUT2(code, 2+LINK_SIZE, recno); + break; + } - /* Search the pattern for a forward reference */ + /* Otherwise (did not start with "+" or "-"), start by looking for the + name. */ - else if ((i = find_named_parens(ptr, *brackets, name, namelen)) > 0) - { - code[1+LINK_SIZE] = OP_CREF; - PUT2(code, 2+LINK_SIZE, i); - } + slot = cd->name_table; + for (i = 0; i < cd->names_found; i++) + { + if (strncmp((char *)name, (char *)slot+2, namelen) == 0) break; + slot += cd->name_entry_size; + } - /* Check for 'R' for recursion */ + /* Found a previous named subpattern */ - else if (namelen == 1 && *name == 'R') - { - code[1+LINK_SIZE] = OP_CREF; - PUT2(code, 2+LINK_SIZE, CREF_RECURSE); - } + if (i < cd->names_found) + { + recno = GET2(slot, 0); + PUT2(code, 2+LINK_SIZE, recno); + } - /* Check for a subpattern number */ + /* Search the pattern for a forward reference */ - else if (condref > 0) + else if ((i = find_parens(ptr, cd->bracount, name, namelen, + (options & PCRE_EXTENDED) != 0)) > 0) + { + PUT2(code, 2+LINK_SIZE, i); + } + + /* If terminator == 0 it means that the name followed directly after + the opening parenthesis [e.g. (?(abc)...] and in this case there are + some further alternatives to try. For the cases where terminator != 0 + [things like (?(... or (?('name')... or (?(R&name)... ] we have + now checked all the possibilities, so give an error. */ + + else if (terminator != 0) + { + *errorcodeptr = ERR15; + goto FAILED; + } + + /* Check for (?(R) for recursion. Allow digits after R to specify a + specific group number. */ + + else if (*name == 'R') + { + recno = 0; + for (i = 1; i < namelen; i++) { - code[1+LINK_SIZE] = OP_CREF; - PUT2(code, 2+LINK_SIZE, condref); + if ((digitab[name[i]] & ctype_digit) == 0) + { + *errorcodeptr = ERR15; + goto FAILED; + } + recno = recno * 10 + name[i] - '0'; } + if (recno == 0) recno = RREF_ANY; + code[1+LINK_SIZE] = OP_RREF; /* Change test type */ + PUT2(code, 2+LINK_SIZE, recno); + } - /* Either an unidentified subpattern, or a reference to (?(0) */ + /* Similarly, check for the (?(DEFINE) "condition", which is always + false. */ - else - { - *errorcodeptr = (condref == 0)? ERR35: ERR15; - goto FAILED; - } + else if (namelen == 6 && strncmp((char *)name, "DEFINE", 6) == 0) + { + code[1+LINK_SIZE] = OP_DEF; + skipbytes = 1; } - /* For conditions that are assertions, we just fall through, having - set bravalue above. */ + /* Check for the "name" actually being a subpattern number. */ + else if (recno > 0) + { + PUT2(code, 2+LINK_SIZE, recno); + } + + /* Either an unidentified subpattern, or a reference to (?(0) */ + + else + { + *errorcodeptr = (recno == 0)? ERR35: ERR15; + goto FAILED; + } break; + + /* ------------------------------------------------------------ */ case '=': /* Positive lookahead */ bravalue = OP_ASSERT; ptr++; break; + + /* ------------------------------------------------------------ */ case '!': /* Negative lookahead */ - bravalue = OP_ASSERT_NOT; ptr++; + if (*ptr == ')') /* Optimize (?!) */ + { + *code++ = OP_FAIL; + previous = NULL; + continue; + } + bravalue = OP_ASSERT_NOT; break; - case '<': /* Lookbehinds */ - switch (*(++ptr)) + + /* ------------------------------------------------------------ */ + case '<': /* Lookbehind or named define */ + switch (ptr[1]) { case '=': /* Positive lookbehind */ bravalue = OP_ASSERTBACK; - ptr++; + ptr += 2; break; case '!': /* Negative lookbehind */ bravalue = OP_ASSERTBACK_NOT; - ptr++; + ptr += 2; break; + + default: /* Could be name define, else bad */ + if ((cd->ctypes[ptr[1]] & ctype_word) != 0) goto DEFINE_NAME; + ptr++; /* Correct offset for error */ + *errorcodeptr = ERR24; + goto FAILED; } break; + + /* ------------------------------------------------------------ */ case '>': /* One-time brackets */ bravalue = OP_ONCE; ptr++; break; + + /* ------------------------------------------------------------ */ case 'C': /* Callout - may be followed by digits; */ previous_callout = code; /* Save for later completion */ after_manual_callout = 1; /* Skip one item before completing */ - *code++ = OP_CALLOUT; /* Already checked that the terminating */ - { /* closing parenthesis is present. */ + *code++ = OP_CALLOUT; + { int n = 0; while ((digitab[*(++ptr)] & ctype_digit) != 0) n = n * 10 + *ptr - '0'; + if (*ptr != ')') + { + *errorcodeptr = ERR39; + goto FAILED; + } if (n > 255) { *errorcodeptr = ERR38; @@ -3034,58 +4406,138 @@ for (;; ptr++) previous = NULL; continue; - case 'P': /* Named subpattern handling */ - if (*(++ptr) == '<') /* Definition */ + + /* ------------------------------------------------------------ */ + case 'P': /* Python-style named subpattern handling */ + if (*(++ptr) == '=' || *ptr == '>') /* Reference or recursion */ { - int i, namelen; - uschar *slot = cd->name_table; - const uschar *name; /* Don't amalgamate; some compilers */ - name = ++ptr; /* grumble at autoincrement in declaration */ + is_recurse = *ptr == '>'; + terminator = ')'; + goto NAMED_REF_OR_RECURSE; + } + else if (*ptr != '<') /* Test for Python-style definition */ + { + *errorcodeptr = ERR41; + goto FAILED; + } + /* Fall through to handle (?P< as (?< is handled */ - while (*ptr++ != '>'); - namelen = ptr - name - 1; - for (i = 0; i < cd->names_found; i++) + /* ------------------------------------------------------------ */ + DEFINE_NAME: /* Come here from (?< handling */ + case '\'': + { + terminator = (*ptr == '<')? '>' : '\''; + name = ++ptr; + + while ((cd->ctypes[*ptr] & ctype_word) != 0) ptr++; + namelen = ptr - name; + + /* In the pre-compile phase, just do a syntax check. */ + + if (lengthptr != NULL) { - int crc = memcmp(name, slot+2, namelen); - if (crc == 0) + if (*ptr != terminator) { - if (slot[2+namelen] == 0) + *errorcodeptr = ERR42; + goto FAILED; + } + if (cd->names_found >= MAX_NAME_COUNT) + { + *errorcodeptr = ERR49; + goto FAILED; + } + if (namelen + 3 > cd->name_entry_size) + { + cd->name_entry_size = namelen + 3; + if (namelen > MAX_NAME_SIZE) { - if ((options & PCRE_DUPNAMES) == 0) + *errorcodeptr = ERR48; + goto FAILED; + } + } + } + + /* In the real compile, create the entry in the table */ + + else + { + slot = cd->name_table; + for (i = 0; i < cd->names_found; i++) + { + int crc = memcmp(name, slot+2, namelen); + if (crc == 0) + { + if (slot[2+namelen] == 0) { - *errorcodeptr = ERR43; - goto FAILED; + if ((options & PCRE_DUPNAMES) == 0) + { + *errorcodeptr = ERR43; + goto FAILED; + } } + else crc = -1; /* Current name is substring */ } - else crc = -1; /* Current name is substring */ + if (crc < 0) + { + memmove(slot + cd->name_entry_size, slot, + (cd->names_found - i) * cd->name_entry_size); + break; + } + slot += cd->name_entry_size; } - if (crc < 0) - { - memmove(slot + cd->name_entry_size, slot, - (cd->names_found - i) * cd->name_entry_size); - break; - } - slot += cd->name_entry_size; + + PUT2(slot, 0, cd->bracount + 1); + memcpy(slot + 2, name, namelen); + slot[2+namelen] = 0; } + } - PUT2(slot, 0, *brackets + 1); - memcpy(slot + 2, name, namelen); - slot[2+namelen] = 0; - cd->names_found++; - goto NUMBERED_GROUP; - } + /* In both cases, count the number of names we've encountered. */ - if (*ptr == '=' || *ptr == '>') /* Reference or recursion */ + ptr++; /* Move past > or ' */ + cd->names_found++; + goto NUMBERED_GROUP; + + + /* ------------------------------------------------------------ */ + case '&': /* Perl recursion/subroutine syntax */ + terminator = ')'; + is_recurse = TRUE; + /* Fall through */ + + /* We come here from the Python syntax above that handles both + references (?P=name) and recursion (?P>name), as well as falling + through from the Perl recursion syntax (?&name). */ + + NAMED_REF_OR_RECURSE: + name = ++ptr; + while ((cd->ctypes[*ptr] & ctype_word) != 0) ptr++; + namelen = ptr - name; + + /* In the pre-compile phase, do a syntax check and set a dummy + reference number. */ + + if (lengthptr != NULL) { - int i, namelen; - int type = *ptr++; - const uschar *name = ptr; - uschar *slot = cd->name_table; + if (*ptr != terminator) + { + *errorcodeptr = ERR42; + goto FAILED; + } + if (namelen > MAX_NAME_SIZE) + { + *errorcodeptr = ERR48; + goto FAILED; + } + recno = 0; + } - while (*ptr != ')') ptr++; - namelen = ptr - name; + /* In the real compile, seek the name in the table */ + else + { + slot = cd->name_table; for (i = 0; i < cd->names_found; i++) { if (strncmp((char *)name, (char *)slot+2, namelen) == 0) break; @@ -3097,71 +4549,124 @@ for (;; ptr++) recno = GET2(slot, 0); } else if ((recno = /* Forward back reference */ - find_named_parens(ptr, *brackets, name, namelen)) <= 0) + find_parens(ptr, cd->bracount, name, namelen, + (options & PCRE_EXTENDED) != 0)) <= 0) { *errorcodeptr = ERR15; goto FAILED; } + } - if (type == '>') goto HANDLE_RECURSION; /* A few lines below */ + /* In both phases, we can now go to the code than handles numerical + recursion or backreferences. */ - /* Back reference */ + if (is_recurse) goto HANDLE_RECURSION; + else goto HANDLE_REFERENCE; - previous = code; - *code++ = OP_REF; - PUT2INC(code, 0, recno); - cd->backref_map |= (recno < 32)? (1 << recno) : 1; - if (recno > cd->top_backref) cd->top_backref = recno; - continue; - } - /* Should never happen */ - break; - - case 'R': /* Pattern recursion */ + /* ------------------------------------------------------------ */ + case 'R': /* Recursion */ ptr++; /* Same as (?0) */ /* Fall through */ - /* Recursion or "subroutine" call */ - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': + /* ------------------------------------------------------------ */ + case '-': case '+': + case '0': case '1': case '2': case '3': case '4': /* Recursion or */ + case '5': case '6': case '7': case '8': case '9': /* subroutine */ { const uschar *called; + + if ((refsign = *ptr) == '+') ptr++; + else if (refsign == '-') + { + if ((digitab[ptr[1]] & ctype_digit) == 0) + goto OTHER_CHAR_AFTER_QUERY; + ptr++; + } + recno = 0; while((digitab[*ptr] & ctype_digit) != 0) recno = recno * 10 + *ptr++ - '0'; + if (*ptr != ')') + { + *errorcodeptr = ERR29; + goto FAILED; + } + + if (refsign == '-') + { + if (recno == 0) + { + *errorcodeptr = ERR58; + goto FAILED; + } + recno = cd->bracount - recno + 1; + if (recno <= 0) + { + *errorcodeptr = ERR15; + goto FAILED; + } + } + else if (refsign == '+') + { + if (recno == 0) + { + *errorcodeptr = ERR58; + goto FAILED; + } + recno += cd->bracount; + } + /* Come here from code above that handles a named recursion */ HANDLE_RECURSION: previous = code; + called = cd->start_code; - /* Find the bracket that is being referenced. Temporarily end the - regex in case it doesn't exist. */ + /* When we are actually compiling, find the bracket that is being + referenced. Temporarily end the regex in case it doesn't exist before + this point. If we end up with a forward reference, first check that + the bracket does occur later so we can give the error (and position) + now. Then remember this forward reference in the workspace so it can + be filled in at the end. */ - *code = OP_END; - called = (recno == 0)? cd->start_code : - find_bracket(cd->start_code, utf8, recno); - if (called == NULL) + if (lengthptr == NULL) { - *errorcodeptr = ERR15; - goto FAILED; - } + *code = OP_END; + if (recno != 0) called = find_bracket(cd->start_code, utf8, recno); - /* If the subpattern is still open, this is a recursive call. We - check to see if this is a left recursion that could loop for ever, - and diagnose that case. */ + /* Forward reference */ - if (GET(called, 1) == 0 && could_be_empty(called, code, bcptr, utf8)) - { - *errorcodeptr = ERR40; - goto FAILED; + if (called == NULL) + { + if (find_parens(ptr, cd->bracount, NULL, recno, + (options & PCRE_EXTENDED) != 0) < 0) + { + *errorcodeptr = ERR15; + goto FAILED; + } + called = cd->start_code + recno; + PUTINC(cd->hwm, 0, code + 2 + LINK_SIZE - cd->start_code); + } + + /* If not a forward reference, and the subpattern is still open, + this is a recursive call. We check to see if this is a left + recursion that could loop for ever, and diagnose that case. */ + + else if (GET(called, 1) == 0 && + could_be_empty(called, code, bcptr, utf8)) + { + *errorcodeptr = ERR40; + goto FAILED; + } } /* Insert the recursion/subroutine item, automatically wrapped inside - "once" brackets. */ + "once" brackets. Set up a "previous group" length so that a + subsequent quantifier will work. */ *code = OP_ONCE; PUT(code, 1, 2 + 2*LINK_SIZE); @@ -3174,12 +4679,19 @@ for (;; ptr++) *code = OP_KET; PUT(code, 1, 2 + 2*LINK_SIZE); code += 1 + LINK_SIZE; + + length_prevgroup = 3 + 3*LINK_SIZE; } + + /* Can't determine a first byte now */ + + if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE; continue; - /* Character after (? not specially recognized */ - default: /* Option setting */ + /* ------------------------------------------------------------ */ + default: /* Other characters: check option setting */ + OTHER_CHAR_AFTER_QUERY: set = unset = 0; optset = &set; @@ -3189,13 +4701,21 @@ for (;; ptr++) { case '-': optset = &unset; break; + case 'J': /* Record that it changed in the external options */ + *optset |= PCRE_DUPNAMES; + cd->external_flags |= PCRE_JCHANGED; + break; + case 'i': *optset |= PCRE_CASELESS; break; - case 'J': *optset |= PCRE_DUPNAMES; break; case 'm': *optset |= PCRE_MULTILINE; break; case 's': *optset |= PCRE_DOTALL; break; case 'x': *optset |= PCRE_EXTENDED; break; case 'U': *optset |= PCRE_UNGREEDY; break; case 'X': *optset |= PCRE_EXTRA; break; + + default: *errorcodeptr = ERR12; + ptr--; /* Correct the offset */ + goto FAILED; } } @@ -3204,32 +4724,54 @@ for (;; ptr++) newoptions = (options | set) & (~unset); /* If the options ended with ')' this is not the start of a nested - group with option changes, so the options change at this level. Compile - code to change the ims options if this setting actually changes any of - them. We also pass the new setting back so that it can be put at the - start of any following branches, and when this group ends (if we are in - a group), a resetting item can be compiled. + group with option changes, so the options change at this level. If this + item is right at the start of the pattern, the options can be + abstracted and made external in the pre-compile phase, and ignored in + the compile phase. This can be helpful when matching -- for instance in + caseless checking of required bytes. - Note that if this item is right at the start of the pattern, the - options will have been abstracted and made global, so there will be no - change to compile. */ + If the code pointer is not (cd->start_code + 1 + LINK_SIZE), we are + definitely *not* at the start of the pattern because something has been + compiled. In the pre-compile phase, however, the code pointer can have + that value after the start, because it gets reset as code is discarded + during the pre-compile. However, this can happen only at top level - if + we are within parentheses, the starting BRA will still be present. At + any parenthesis level, the length value can be used to test if anything + has been compiled at that level. Thus, a test for both these conditions + is necessary to ensure we correctly detect the start of the pattern in + both phases. + If we are not at the pattern start, compile code to change the ims + options if this setting actually changes any of them. We also pass the + new setting back so that it can be put at the start of any following + branches, and when this group ends (if we are in a group), a resetting + item can be compiled. */ + if (*ptr == ')') { - if ((options & PCRE_IMS) != (newoptions & PCRE_IMS)) + if (code == cd->start_code + 1 + LINK_SIZE && + (lengthptr == NULL || *lengthptr == 2 + 2*LINK_SIZE)) { - *code++ = OP_OPT; - *code++ = newoptions & PCRE_IMS; + cd->external_options = newoptions; + options = newoptions; } + else + { + if ((options & PCRE_IMS) != (newoptions & PCRE_IMS)) + { + *code++ = OP_OPT; + *code++ = newoptions & PCRE_IMS; + } - /* Change options at this level, and pass them back for use - in subsequent branches. Reset the greedy defaults and the case - value for firstbyte and reqbyte. */ + /* Change options at this level, and pass them back for use + in subsequent branches. Reset the greedy defaults and the case + value for firstbyte and reqbyte. */ - *optionsptr = options = newoptions; - greedy_default = ((newoptions & PCRE_UNGREEDY) != 0); - greedy_non_default = greedy_default ^ 1; - req_caseopt = ((options & PCRE_CASELESS) != 0)? REQ_CASELESS : 0; + *optionsptr = options = newoptions; + greedy_default = ((newoptions & PCRE_UNGREEDY) != 0); + greedy_non_default = greedy_default ^ 1; + req_caseopt = ((options & PCRE_CASELESS) != 0)? REQ_CASELESS : 0; + } previous = NULL; /* This item can't be repeated */ continue; /* It is complete */ @@ -3242,58 +4784,57 @@ for (;; ptr++) bravalue = OP_BRA; ptr++; - } - } + } /* End of switch for character following (? */ + } /* End of (? handling */ - /* If PCRE_NO_AUTO_CAPTURE is set, all unadorned brackets become - non-capturing and behave like (?:...) brackets */ + /* Opening parenthesis not followed by '?'. If PCRE_NO_AUTO_CAPTURE is set, + all unadorned brackets become non-capturing and behave like (?:...) + brackets. */ else if ((options & PCRE_NO_AUTO_CAPTURE) != 0) { bravalue = OP_BRA; } - /* Else we have a referencing group; adjust the opcode. If the bracket - number is greater than EXTRACT_BASIC_MAX, we set the opcode one higher, and - arrange for the true number to follow later, in an OP_BRANUMBER item. */ + /* Else we have a capturing group. */ else { NUMBERED_GROUP: - if (++(*brackets) > EXTRACT_BASIC_MAX) - { - bravalue = OP_BRA + EXTRACT_BASIC_MAX + 1; - code[1+LINK_SIZE] = OP_BRANUMBER; - PUT2(code, 2+LINK_SIZE, *brackets); - skipbytes = 3; - } - else bravalue = OP_BRA + *brackets; + cd->bracount += 1; + PUT2(code, 1+LINK_SIZE, cd->bracount); + skipbytes = 2; } - /* Process nested bracketed re. Assertions may not be repeated, but other - kinds can be. We copy code into a non-register variable in order to be able - to pass its address because some compilers complain otherwise. Pass in a - new setting for the ims options if they have changed. */ + /* Process nested bracketed regex. Assertions may not be repeated, but + other kinds can be. All their opcodes are >= OP_ONCE. We copy code into a + non-register variable in order to be able to pass its address because some + compilers complain otherwise. Pass in a new setting for the ims options if + they have changed. */ previous = (bravalue >= OP_ONCE)? code : NULL; *code = bravalue; tempcode = code; tempreqvary = cd->req_varyopt; /* Save value before bracket */ + length_prevgroup = 0; /* Initialize for pre-compile phase */ if (!compile_regex( newoptions, /* The complete new option state */ options & PCRE_IMS, /* The previous ims option state */ - brackets, /* Extracting bracket count */ &tempcode, /* Where to put code (updated) */ &ptr, /* Input pointer (updated) */ errorcodeptr, /* Where to put an error message */ (bravalue == OP_ASSERTBACK || bravalue == OP_ASSERTBACK_NOT), /* TRUE if back assert */ - skipbytes, /* Skip over OP_COND/OP_BRANUMBER */ + reset_bracount, /* True if (?| group */ + skipbytes, /* Skip over bracket number */ &subfirstbyte, /* For possible first char */ &subreqbyte, /* For possible last char */ bcptr, /* Current branch chain */ - cd)) /* Tables block */ + cd, /* Tables block */ + (lengthptr == NULL)? NULL : /* Actual compile phase */ + &length_prevgroup /* Pre-compile phase */ + )) goto FAILED; /* At the end of compiling, code is still pointing to the start of the @@ -3302,9 +4843,11 @@ for (;; ptr++) is on the bracket. */ /* If this is a conditional bracket, check that there are no more than - two branches in the group. */ + two branches in the group, or just one if it's a DEFINE group. We do this + in the real compile phase, not in the pre-pass, where the whole group may + not be available. */ - else if (bravalue == OP_COND) + if (bravalue == OP_COND && lengthptr == NULL) { uschar *tc = code; int condcount = 0; @@ -3315,29 +4858,83 @@ for (;; ptr++) } while (*tc != OP_KET); - if (condcount > 2) + /* A DEFINE group is never obeyed inline (the "condition" is always + false). It must have only one branch. */ + + if (code[LINK_SIZE+1] == OP_DEF) { - *errorcodeptr = ERR27; - goto FAILED; + if (condcount > 1) + { + *errorcodeptr = ERR54; + goto FAILED; + } + bravalue = OP_DEF; /* Just a flag to suppress char handling below */ } - /* If there is just one branch, we must not make use of its firstbyte or - reqbyte, because this is equivalent to an empty second branch. */ + /* A "normal" conditional group. If there is just one branch, we must not + make use of its firstbyte or reqbyte, because this is equivalent to an + empty second branch. */ - if (condcount == 1) subfirstbyte = subreqbyte = REQ_NONE; + else + { + if (condcount > 2) + { + *errorcodeptr = ERR27; + goto FAILED; + } + if (condcount == 1) subfirstbyte = subreqbyte = REQ_NONE; + } } - /* Handle updating of the required and first characters. Update for normal - brackets of all kinds, and conditions with two branches (see code above). - If the bracket is followed by a quantifier with zero repeat, we have to - back off. Hence the definition of zeroreqbyte and zerofirstbyte outside the - main loop so that they can be accessed for the back off. */ + /* Error if hit end of pattern */ + if (*ptr != ')') + { + *errorcodeptr = ERR14; + goto FAILED; + } + + /* In the pre-compile phase, update the length by the length of the group, + less the brackets at either end. Then reduce the compiled code to just a + set of non-capturing brackets so that it doesn't use much memory if it is + duplicated by a quantifier.*/ + + if (lengthptr != NULL) + { + if (OFLOW_MAX - *lengthptr < length_prevgroup - 2 - 2*LINK_SIZE) + { + *errorcodeptr = ERR20; + goto FAILED; + } + *lengthptr += length_prevgroup - 2 - 2*LINK_SIZE; + *code++ = OP_BRA; + PUTINC(code, 0, 1 + LINK_SIZE); + *code++ = OP_KET; + PUTINC(code, 0, 1 + LINK_SIZE); + break; /* No need to waste time with special character handling */ + } + + /* Otherwise update the main code pointer to the end of the group. */ + + code = tempcode; + + /* For a DEFINE group, required and first character settings are not + relevant. */ + + if (bravalue == OP_DEF) break; + + /* Handle updating of the required and first characters for other types of + group. Update for normal brackets of all kinds, and conditions with two + branches (see code above). If the bracket is followed by a quantifier with + zero repeat, we have to back off. Hence the definition of zeroreqbyte and + zerofirstbyte outside the main loop so that they can be accessed for the + back off. */ + zeroreqbyte = reqbyte; zerofirstbyte = firstbyte; groupsetfirstbyte = FALSE; - if (bravalue >= OP_BRA || bravalue == OP_ONCE || bravalue == OP_COND) + if (bravalue >= OP_ONCE) { /* If we have not yet set a firstbyte in this branch, take it from the subpattern, remembering that it was set here so that a repeat of more @@ -3378,35 +4975,22 @@ for (;; ptr++) firstbyte, looking for an asserted first char. */ else if (bravalue == OP_ASSERT && subreqbyte >= 0) reqbyte = subreqbyte; + break; /* End of processing '(' */ - /* Now update the main code pointer to the end of the group. */ - code = tempcode; - - /* Error if hit end of pattern */ - - if (*ptr != ')') - { - *errorcodeptr = ERR14; - goto FAILED; - } - break; - - /* Check \ for being a real metacharacter; if not, fall through and handle - it as a data character at the start of a string. Escape items are checked - for validity in the pre-compiling pass. */ - - case '\\': - tempptr = ptr; - c = check_escape(&ptr, errorcodeptr, *brackets, options, FALSE); - - /* Handle metacharacters introduced by \. For ones like \d, the ESC_ values + /* ===================================================================*/ + /* Handle metasequences introduced by \. For ones like \d, the ESC_ values are arranged to be the negation of the corresponding OP_values. For the back references, the values are ESC_REF plus the reference number. Only back references and those types that consume a character may be repeated. We can test for values between ESC_b and ESC_Z for the latter; this may have to change if any new ones are ever created. */ + case '\\': + tempptr = ptr; + c = check_escape(&ptr, errorcodeptr, cd->bracount, options, FALSE); + if (*errorcodeptr != 0) goto FAILED; + if (c < 0) { if (-c == ESC_Q) /* Handle start of quoted string */ @@ -3416,6 +5000,8 @@ for (;; ptr++) continue; } + if (-c == ESC_E) continue; /* Perl ignores an orphan \E */ + /* For metasequences that actually match a character, we disable the setting of a first character if it hasn't already been set. */ @@ -3427,18 +5013,34 @@ for (;; ptr++) zerofirstbyte = firstbyte; zeroreqbyte = reqbyte; - /* Back references are handled specially */ + /* \k or \k'name' is a back reference by name (Perl syntax). + We also support \k{name} (.NET syntax) */ + if (-c == ESC_k && (ptr[1] == '<' || ptr[1] == '\'' || ptr[1] == '{')) + { + is_recurse = FALSE; + terminator = (*(++ptr) == '<')? '>' : (*ptr == '\'')? '\'' : '}'; + goto NAMED_REF_OR_RECURSE; + } + + /* Back references are handled specially; must disable firstbyte if + not set to cope with cases like (?=(\w+))\1: which would otherwise set + ':' later. */ + if (-c >= ESC_REF) { - int number = -c - ESC_REF; + recno = -c - ESC_REF; + + HANDLE_REFERENCE: /* Come here from named backref handling */ + if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE; previous = code; *code++ = OP_REF; - PUT2INC(code, 0, number); + PUT2INC(code, 0, recno); + cd->backref_map |= (recno < 32)? (1 << recno) : 1; + if (recno > cd->top_backref) cd->top_backref = recno; } - /* So are Unicode property matches, if supported. We know that get_ucp - won't fail because it was tested in the pre-pass. */ + /* So are Unicode property matches, if supported. */ #ifdef SUPPORT_UCP else if (-c == ESC_P || -c == ESC_p) @@ -3446,15 +5048,26 @@ for (;; ptr++) BOOL negated; int pdata; int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr); + if (ptype < 0) goto FAILED; previous = code; *code++ = ((-c == ESC_p) != negated)? OP_PROP : OP_NOTPROP; *code++ = ptype; *code++ = pdata; } +#else + + /* If Unicode properties are not supported, \X, \P, and \p are not + allowed. */ + + else if (-c == ESC_X || -c == ESC_P || -c == ESC_p) + { + *errorcodeptr = ERR45; + goto FAILED; + } #endif - /* For the rest, we can obtain the OP value by negating the escape - value */ + /* For the rest (including \X when Unicode properties are supported), we + can obtain the OP value by negating the escape value. */ else { @@ -3478,9 +5091,10 @@ for (;; ptr++) mcbuffer[0] = c; mclength = 1; } + goto ONE_CHAR; - goto ONE_CHAR; + /* ===================================================================*/ /* Handle a literal character. It is guaranteed not to be whitespace or # when the extended flag is set. If we are in UTF-8 mode, it may be a multi-byte literal character. */ @@ -3491,7 +5105,7 @@ for (;; ptr++) mcbuffer[0] = c; #ifdef SUPPORT_UTF8 - if (utf8 && (c & 0xc0) == 0xc0) + if (utf8 && c >= 0xc0) { while ((ptr[1] & 0xc0) == 0x80) mcbuffer[mclength++] = *(++ptr); @@ -3506,6 +5120,11 @@ for (;; ptr++) *code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARNC : OP_CHAR; for (c = 0; c < mclength; c++) *code++ = mcbuffer[c]; + /* Remember if \r or \n were seen */ + + if (mcbuffer[0] == '\r' || mcbuffer[0] == '\n') + cd->external_flags |= PCRE_HASCRORLF; + /* Set the first and required bytes appropriately. If no previous first byte, set it from this character, but revert to none on a zero repeat. Otherwise, leave the firstbyte value alone, and don't change it on a zero @@ -3542,6 +5161,7 @@ for (;; ptr++) } } /* end of big loop */ + /* Control never reaches here by falling through, only by a goto for all the error states. Pass back the position in the pattern so that it can be displayed to the user for diagnosing the error. */ @@ -3558,35 +5178,42 @@ return FALSE; * Compile sequence of alternatives * *************************************************/ -/* On entry, ptr is pointing past the bracket character, but on return -it points to the closing bracket, or vertical bar, or end of string. -The code variable is pointing at the byte into which the BRA operator has been -stored. If the ims options are changed at the start (for a (?ims: group) or -during any branch, we need to insert an OP_OPT item at the start of every -following branch to ensure they get set correctly at run time, and also pass -the new options into every subsequent branch compile. +/* On entry, ptr is pointing past the bracket character, but on return it +points to the closing bracket, or vertical bar, or end of string. The code +variable is pointing at the byte into which the BRA operator has been stored. +If the ims options are changed at the start (for a (?ims: group) or during any +branch, we need to insert an OP_OPT item at the start of every following branch +to ensure they get set correctly at run time, and also pass the new options +into every subsequent branch compile. -Argument: +This function is used during the pre-compile phase when we are trying to find +out the amount of memory needed, as well as during the real compile phase. The +value of lengthptr distinguishes the two phases. + +Arguments: options option bits, including any changes for this subpattern oldims previous settings of ims option bits - brackets -> int containing the number of extracting brackets used codeptr -> the address of the current code pointer ptrptr -> the address of the current pattern pointer errorcodeptr -> pointer to error code variable lookbehind TRUE if this is a lookbehind assertion - skipbytes skip this many bytes at start (for OP_COND, OP_BRANUMBER) + reset_bracount TRUE to reset the count for each branch + skipbytes skip this many bytes at start (for brackets and OP_COND) firstbyteptr place to put the first required character, or a negative number reqbyteptr place to put the last required character, or a negative number bcptr pointer to the chain of currently open branches cd points to the data block with tables pointers etc. + lengthptr NULL during the real compile phase + points to length accumulator during pre-compile phase -Returns: TRUE on success +Returns: TRUE on success */ static BOOL -compile_regex(int options, int oldims, int *brackets, uschar **codeptr, - const uschar **ptrptr, int *errorcodeptr, BOOL lookbehind, int skipbytes, - int *firstbyteptr, int *reqbyteptr, branch_chain *bcptr, compile_data *cd) +compile_regex(int options, int oldims, uschar **codeptr, const uschar **ptrptr, + int *errorcodeptr, BOOL lookbehind, BOOL reset_bracount, int skipbytes, + int *firstbyteptr, int *reqbyteptr, branch_chain *bcptr, compile_data *cd, + int *lengthptr) { const uschar *ptr = *ptrptr; uschar *code = *codeptr; @@ -3595,6 +5222,9 @@ int branchfirstbyte, branchreqbyte; uschar *reverse_count = NULL; int firstbyte, reqbyte; int branchfirstbyte, branchreqbyte; +int length; +int orig_bracount; +int max_bracount; branch_chain bc; bc.outer = bcptr; @@ -3602,6 +5232,20 @@ firstbyte = reqbyte = REQ_UNSET; firstbyte = reqbyte = REQ_UNSET; +/* Accumulate the length for use in the pre-compile phase. Start with the +length of the BRA and KET and any extra bytes that are required at the +beginning. We accumulate in a local variable to save frequent testing of +lenthptr for NULL. We cannot do this by looking at the value of code at the +start and end of each alternative, because compiled items are discarded during +the pre-compile phase so that the work space is not exceeded. */ + +length = 2 + 2*LINK_SIZE + skipbytes; + +/* WARNING: If the above line is changed for any reason, you must also change +the code that abstracts option settings at the start of the pattern and makes +them global. It tests the value of length for (2 + 2*LINK_SIZE) in the +pre-compile phase to find out whether anything has yet been compiled or not. */ + /* Offset is set zero to mark that this bracket is still open */ PUT(code, 1, 0); @@ -3609,14 +5253,21 @@ code += 1 + LINK_SIZE + skipbytes; /* Loop for each alternative branch */ +orig_bracount = max_bracount = cd->bracount; for (;;) { + /* For a (?| group, reset the capturing bracket count so that each branch + uses the same numbers. */ + + if (reset_bracount) cd->bracount = orig_bracount; + /* Handle a change of ims options at the start of the branch */ if ((options & PCRE_IMS) != oldims) { *code++ = OP_OPT; *code++ = options & PCRE_IMS; + length += 2; } /* Set up dummy OP_REVERSE if lookbehind assertion */ @@ -3626,95 +5277,110 @@ for (;;) *code++ = OP_REVERSE; reverse_count = code; PUTINC(code, 0, 0); + length += 1 + LINK_SIZE; } - /* Now compile the branch */ + /* Now compile the branch; in the pre-compile phase its length gets added + into the length. */ - if (!compile_branch(&options, brackets, &code, &ptr, errorcodeptr, - &branchfirstbyte, &branchreqbyte, &bc, cd)) + if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstbyte, + &branchreqbyte, &bc, cd, (lengthptr == NULL)? NULL : &length)) { *ptrptr = ptr; return FALSE; } - /* If this is the first branch, the firstbyte and reqbyte values for the - branch become the values for the regex. */ + /* Keep the highest bracket count in case (?| was used and some branch + has fewer than the rest. */ - if (*last_branch != OP_ALT) - { - firstbyte = branchfirstbyte; - reqbyte = branchreqbyte; - } + if (cd->bracount > max_bracount) max_bracount = cd->bracount; - /* If this is not the first branch, the first char and reqbyte have to - match the values from all the previous branches, except that if the previous - value for reqbyte didn't have REQ_VARY set, it can still match, and we set - REQ_VARY for the regex. */ + /* In the real compile phase, there is some post-processing to be done. */ - else + if (lengthptr == NULL) { - /* If we previously had a firstbyte, but it doesn't match the new branch, - we have to abandon the firstbyte for the regex, but if there was previously - no reqbyte, it takes on the value of the old firstbyte. */ + /* If this is the first branch, the firstbyte and reqbyte values for the + branch become the values for the regex. */ - if (firstbyte >= 0 && firstbyte != branchfirstbyte) + if (*last_branch != OP_ALT) { - if (reqbyte < 0) reqbyte = firstbyte; - firstbyte = REQ_NONE; + firstbyte = branchfirstbyte; + reqbyte = branchreqbyte; } - /* If we (now or from before) have no firstbyte, a firstbyte from the - branch becomes a reqbyte if there isn't a branch reqbyte. */ + /* If this is not the first branch, the first char and reqbyte have to + match the values from all the previous branches, except that if the + previous value for reqbyte didn't have REQ_VARY set, it can still match, + and we set REQ_VARY for the regex. */ - if (firstbyte < 0 && branchfirstbyte >= 0 && branchreqbyte < 0) - branchreqbyte = branchfirstbyte; + else + { + /* If we previously had a firstbyte, but it doesn't match the new branch, + we have to abandon the firstbyte for the regex, but if there was + previously no reqbyte, it takes on the value of the old firstbyte. */ - /* Now ensure that the reqbytes match */ + if (firstbyte >= 0 && firstbyte != branchfirstbyte) + { + if (reqbyte < 0) reqbyte = firstbyte; + firstbyte = REQ_NONE; + } - if ((reqbyte & ~REQ_VARY) != (branchreqbyte & ~REQ_VARY)) - reqbyte = REQ_NONE; - else reqbyte |= branchreqbyte; /* To "or" REQ_VARY */ - } + /* If we (now or from before) have no firstbyte, a firstbyte from the + branch becomes a reqbyte if there isn't a branch reqbyte. */ - /* If lookbehind, check that this branch matches a fixed-length string, - and put the length into the OP_REVERSE item. Temporarily mark the end of - the branch with OP_END. */ + if (firstbyte < 0 && branchfirstbyte >= 0 && branchreqbyte < 0) + branchreqbyte = branchfirstbyte; - if (lookbehind) - { - int length; - *code = OP_END; - length = find_fixedlength(last_branch, options); - DPRINTF(("fixed length = %d\n", length)); - if (length < 0) + /* Now ensure that the reqbytes match */ + + if ((reqbyte & ~REQ_VARY) != (branchreqbyte & ~REQ_VARY)) + reqbyte = REQ_NONE; + else reqbyte |= branchreqbyte; /* To "or" REQ_VARY */ + } + + /* If lookbehind, check that this branch matches a fixed-length string, and + put the length into the OP_REVERSE item. Temporarily mark the end of the + branch with OP_END. */ + + if (lookbehind) { - *errorcodeptr = (length == -2)? ERR36 : ERR25; - *ptrptr = ptr; - return FALSE; + int fixed_length; + *code = OP_END; + fixed_length = find_fixedlength(last_branch, options); + DPRINTF(("fixed length = %d\n", fixed_length)); + if (fixed_length < 0) + { + *errorcodeptr = (fixed_length == -2)? ERR36 : ERR25; + *ptrptr = ptr; + return FALSE; + } + PUT(reverse_count, 0, fixed_length); } - PUT(reverse_count, 0, length); } - /* Reached end of expression, either ')' or end of pattern. Go back through - the alternative branches and reverse the chain of offsets, with the field in - the BRA item now becoming an offset to the first alternative. If there are - no alternatives, it points to the end of the group. The length in the - terminating ket is always the length of the whole bracketed item. If any of - the ims options were changed inside the group, compile a resetting op-code - following, except at the very end of the pattern. Return leaving the pointer - at the terminating char. */ + /* Reached end of expression, either ')' or end of pattern. In the real + compile phase, go back through the alternative branches and reverse the chain + of offsets, with the field in the BRA item now becoming an offset to the + first alternative. If there are no alternatives, it points to the end of the + group. The length in the terminating ket is always the length of the whole + bracketed item. If any of the ims options were changed inside the group, + compile a resetting op-code following, except at the very end of the pattern. + Return leaving the pointer at the terminating char. */ if (*ptr != '|') { - int length = code - last_branch; - do + if (lengthptr == NULL) { - int prev_length = GET(last_branch, 1); - PUT(last_branch, 1, length); - length = prev_length; - last_branch -= length; + int branch_length = code - last_branch; + do + { + int prev_length = GET(last_branch, 1); + PUT(last_branch, 1, branch_length); + branch_length = prev_length; + last_branch -= branch_length; + } + while (branch_length > 0); } - while (length > 0); /* Fill in the ket */ @@ -3728,26 +5394,53 @@ for (;;) { *code++ = OP_OPT; *code++ = oldims; + length += 2; } + /* Retain the highest bracket number, in case resetting was used. */ + + cd->bracount = max_bracount; + /* Set values to pass back */ *codeptr = code; *ptrptr = ptr; *firstbyteptr = firstbyte; *reqbyteptr = reqbyte; + if (lengthptr != NULL) + { + if (OFLOW_MAX - *lengthptr < length) + { + *errorcodeptr = ERR20; + return FALSE; + } + *lengthptr += length; + } return TRUE; } - /* Another branch follows; insert an "or" node. Its length field points back + /* Another branch follows. In the pre-compile phase, we can move the code + pointer back to where it was for the start of the first branch. (That is, + pretend that each branch is the only one.) + + In the real compile phase, insert an ALT node. Its length field points back to the previous branch while the bracket remains open. At the end the chain is reversed. It's done like this so that the start of the bracket has a zero offset until it is closed, making it possible to detect recursion. */ - *code = OP_ALT; - PUT(code, 1, code - last_branch); - bc.current = last_branch = code; - code += 1 + LINK_SIZE; + if (lengthptr != NULL) + { + code = *codeptr + 1 + LINK_SIZE + skipbytes; + length += 1 + LINK_SIZE; + } + else + { + *code = OP_ALT; + PUT(code, 1, code - last_branch); + bc.current = last_branch = code; + code += 1 + LINK_SIZE; + } + ptr++; } /* Control never reaches here */ @@ -3799,24 +5492,29 @@ do { unsigned int backref_map) { do { - const uschar *scode = - first_significant_code(code + 1+LINK_SIZE, options, PCRE_MULTILINE, FALSE); + const uschar *scode = first_significant_code(code + _pcre_OP_lengths[*code], + options, PCRE_MULTILINE, FALSE); register int op = *scode; + /* Non-capturing brackets */ + + if (op == OP_BRA) + { + if (!is_anchored(scode, options, bracket_map, backref_map)) return FALSE; + } + /* Capturing brackets */ - if (op > OP_BRA) + else if (op == OP_CBRA) { - int new_map; - op -= OP_BRA; - if (op > EXTRACT_BASIC_MAX) op = GET2(scode, 2+LINK_SIZE); - new_map = bracket_map | ((op < 32)? (1 << op) : 1); + int n = GET2(scode, 1+LINK_SIZE); + int new_map = bracket_map | ((n < 32)? (1 << n) : 1); if (!is_anchored(scode, options, new_map, backref_map)) return FALSE; } /* Other brackets */ - else if (op == OP_BRA || op == OP_ASSERT || op == OP_ONCE || op == OP_COND) + else if (op == OP_ASSERT || op == OP_ONCE || op == OP_COND) { if (!is_anchored(scode, options, bracket_map, backref_map)) return FALSE; } @@ -3824,7 +5522,8 @@ do { /* .* is not anchored unless DOTALL is set and it isn't in brackets that are or may be referenced. */ - else if ((op == OP_TYPESTAR || op == OP_TYPEMINSTAR) && + else if ((op == OP_TYPESTAR || op == OP_TYPEMINSTAR || + op == OP_TYPEPOSSTAR) && (*options & PCRE_DOTALL) != 0) { if (scode[1] != OP_ANY || (bracket_map & backref_map) != 0) return FALSE; @@ -3869,30 +5568,35 @@ do { unsigned int backref_map) { do { - const uschar *scode = first_significant_code(code + 1+LINK_SIZE, NULL, 0, - FALSE); + const uschar *scode = first_significant_code(code + _pcre_OP_lengths[*code], + NULL, 0, FALSE); register int op = *scode; + /* Non-capturing brackets */ + + if (op == OP_BRA) + { + if (!is_startline(scode, bracket_map, backref_map)) return FALSE; + } + /* Capturing brackets */ - if (op > OP_BRA) + else if (op == OP_CBRA) { - int new_map; - op -= OP_BRA; - if (op > EXTRACT_BASIC_MAX) op = GET2(scode, 2+LINK_SIZE); - new_map = bracket_map | ((op < 32)? (1 << op) : 1); + int n = GET2(scode, 1+LINK_SIZE); + int new_map = bracket_map | ((n < 32)? (1 << n) : 1); if (!is_startline(scode, new_map, backref_map)) return FALSE; } /* Other brackets */ - else if (op == OP_BRA || op == OP_ASSERT || op == OP_ONCE || op == OP_COND) + else if (op == OP_ASSERT || op == OP_ONCE || op == OP_COND) { if (!is_startline(scode, bracket_map, backref_map)) return FALSE; } /* .* means "start at start or after \n" if it isn't in brackets that may be referenced. */ - else if (op == OP_TYPESTAR || op == OP_TYPEMINSTAR) + else if (op == OP_TYPESTAR || op == OP_TYPEMINSTAR || op == OP_TYPEPOSSTAR) { if (scode[1] != OP_ANY || (bracket_map & backref_map) != 0) return FALSE; } @@ -3941,14 +5645,13 @@ do { first_significant_code(code + 1+LINK_SIZE, options, PCRE_CASELESS, TRUE); register int op = *scode; - if (op >= OP_BRA) op = OP_BRA; - switch(op) { default: return -1; case OP_BRA: + case OP_CBRA: case OP_ASSERT: case OP_ONCE: case OP_COND: @@ -3964,6 +5667,7 @@ do { case OP_CHARNC: case OP_PLUS: case OP_MINPLUS: + case OP_POSPLUS: if (!inassert) return -1; if (c < 0) { @@ -4004,7 +5708,7 @@ Returns: pointer to compiled data with errorptr and erroroffset set */ -PCRE_DATA_SCOPE pcre * +PCRE_EXP_DEFN pcre * pcre_compile(const char *pattern, int options, const char **errorptr, int *erroroffset, const unsigned char *tables) { @@ -4012,38 +5716,38 @@ return pcre_compile2(pattern, options, N } - -PCRE_DATA_SCOPE pcre * +PCRE_EXP_DEFN pcre * pcre_compile2(const char *pattern, int options, int *errorcodeptr, const char **errorptr, int *erroroffset, const unsigned char *tables) { real_pcre *re; -int length = 1 + LINK_SIZE; /* For initial BRA plus length */ -int c, firstbyte, reqbyte, newline; -int bracount = 0; -int branch_extra = 0; -int branch_newextra; -int item_count = -1; -int name_count = 0; -int max_name_size = 0; -int lastitemlength = 0; +int length = 1; /* For final END opcode */ +int firstbyte, reqbyte, newline; int errorcode = 0; +int skipatstart = 0; #ifdef SUPPORT_UTF8 BOOL utf8; -BOOL class_utf8; #endif -BOOL inescq = FALSE; -BOOL capturing; -unsigned int brastackptr = 0; size_t size; uschar *code; const uschar *codestart; const uschar *ptr; compile_data compile_block; compile_data *cd = &compile_block; -int brastack[BRASTACK_SIZE]; -uschar bralenstack[BRASTACK_SIZE]; +/* This space is used for "compiling" into during the first phase, when we are +computing the amount of memory that is needed. Compiled items are thrown away +as soon as possible, so that a fairly large buffer should be sufficient for +this purpose. The same space is used in the second phase for remembering where +to fill in forward references to subpatterns. */ + +uschar cworkspace[COMPILE_WORK_SIZE]; + + +/* Set this early so that early errors get offset 0. */ + +ptr = (const uschar *)pattern; + /* We can't pass back an error message if errorptr is NULL; I guess the best we can do is just return NULL, but we can set a code value if there is a code pointer. */ @@ -4062,7 +5766,7 @@ if (erroroffset == NULL) if (erroroffset == NULL) { errorcode = ERR16; - goto PCRE_EARLY_ERROR_RETURN; + goto PCRE_EARLY_ERROR_RETURN2; } *erroroffset = 0; @@ -4075,7 +5779,7 @@ if (utf8 && (options & PCRE_NO_UTF8_CHEC (*erroroffset = _pcre_valid_utf8((uschar *)pattern, -1)) >= 0) { errorcode = ERR44; - goto PCRE_EARLY_ERROR_RETURN; + goto PCRE_EARLY_ERROR_RETURN2; } #else if ((options & PCRE_UTF8) != 0) @@ -4099,34 +5803,91 @@ cd->ctypes = tables + ctypes_offset; cd->cbits = tables + cbits_offset; cd->ctypes = tables + ctypes_offset; -/* Handle different types of newline. The two bits give four cases. The current -code allows for one- or two-byte sequences. */ +/* Check for global one-time settings at the start of the pattern, and remember +the offset for later. */ -switch (options & PCRE_NEWLINE_CRLF) +while (ptr[skipatstart] == '(' && ptr[skipatstart+1] == '*') { - default: newline = NEWLINE; break; /* Compile-time default */ + int newnl = 0; + int newbsr = 0; + + if (strncmp((char *)(ptr+skipatstart+2), "CR)", 3) == 0) + { skipatstart += 5; newnl = PCRE_NEWLINE_CR; } + else if (strncmp((char *)(ptr+skipatstart+2), "LF)", 3) == 0) + { skipatstart += 5; newnl = PCRE_NEWLINE_LF; } + else if (strncmp((char *)(ptr+skipatstart+2), "CRLF)", 5) == 0) + { skipatstart += 7; newnl = PCRE_NEWLINE_CR + PCRE_NEWLINE_LF; } + else if (strncmp((char *)(ptr+skipatstart+2), "ANY)", 4) == 0) + { skipatstart += 6; newnl = PCRE_NEWLINE_ANY; } + else if (strncmp((char *)(ptr+skipatstart+2), "ANYCRLF)", 8) == 0) + { skipatstart += 10; newnl = PCRE_NEWLINE_ANYCRLF; } + + else if (strncmp((char *)(ptr+skipatstart+2), "BSR_ANYCRLF)", 12) == 0) + { skipatstart += 14; newbsr = PCRE_BSR_ANYCRLF; } + else if (strncmp((char *)(ptr+skipatstart+2), "BSR_UNICODE)", 12) == 0) + { skipatstart += 14; newbsr = PCRE_BSR_UNICODE; } + + if (newnl != 0) + options = (options & ~PCRE_NEWLINE_BITS) | newnl; + else if (newbsr != 0) + options = (options & ~(PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) | newbsr; + else break; + } + +/* Check validity of \R options. */ + +switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) + { + case 0: + case PCRE_BSR_ANYCRLF: + case PCRE_BSR_UNICODE: + break; + default: errorcode = ERR56; goto PCRE_EARLY_ERROR_RETURN; + } + +/* Handle different types of newline. The three bits give seven cases. The +current code allows for fixed one- or two-byte sequences, plus "any" and +"anycrlf". */ + +switch (options & PCRE_NEWLINE_BITS) + { + case 0: newline = NEWLINE; break; /* Build-time default */ case PCRE_NEWLINE_CR: newline = '\r'; break; case PCRE_NEWLINE_LF: newline = '\n'; break; 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: errorcode = ERR56; goto PCRE_EARLY_ERROR_RETURN; } -if (newline > 255) +if (newline == -2) { - cd->nllen = 2; - cd->nl[0] = (newline >> 8) & 255; - cd->nl[1] = newline & 255; + cd->nltype = NLTYPE_ANYCRLF; } +else if (newline < 0) + { + cd->nltype = NLTYPE_ANY; + } else { - cd->nllen = 1; - cd->nl[0] = newline; + cd->nltype = NLTYPE_FIXED; + if (newline > 255) + { + cd->nllen = 2; + cd->nl[0] = (newline >> 8) & 255; + cd->nl[1] = newline & 255; + } + else + { + cd->nllen = 1; + cd->nl[0] = newline; + } } -/* Maximum back reference and backref bitmap. This is updated for numeric -references during the first pass, but for named references during the actual -compile pass. The bitmap records up to 31 back references to help in deciding -whether (.*) can be treated as anchored or not. */ +/* Maximum back reference and backref bitmap. The bitmap records up to 31 back +references to help in deciding whether (.*) can be treated as anchored or not. +*/ cd->top_backref = 0; cd->backref_map = 0; @@ -4136,953 +5897,43 @@ DPRINTF(("%s\n", pattern)); DPRINTF(("------------------------------------------------------------------\n")); DPRINTF(("%s\n", pattern)); -/* The first thing to do is to make a pass over the pattern to compute the -amount of store required to hold the compiled code. This does not have to be -perfect as long as errors are overestimates. At the same time we can detect any -flag settings right at the start, and extract them. Make an attempt to correct -for any counted white space if an "extended" flag setting appears late in the -pattern. We can't be so clever for #-comments. */ +/* Pretend to compile the pattern while actually just accumulating the length +of memory required. This behaviour is triggered by passing a non-NULL final +argument to compile_regex(). We pass a block of workspace (cworkspace) for it +to compile parts of the pattern into; the compiled code is discarded when it is +no longer needed, so hopefully this workspace will never overflow, though there +is a test for its doing so. */ -ptr = (const uschar *)(pattern - 1); -while ((c = *(++ptr)) != 0) - { - int min, max; - int class_optcount; - int bracket_length; - int duplength; +cd->bracount = 0; +cd->names_found = 0; +cd->name_entry_size = 0; +cd->name_table = NULL; +cd->start_workspace = cworkspace; +cd->start_code = cworkspace; +cd->hwm = cworkspace; +cd->start_pattern = (const uschar *)pattern; +cd->end_pattern = (const uschar *)(pattern + strlen(pattern)); +cd->req_varyopt = 0; +cd->external_options = options; +cd->external_flags = 0; - /* If we are inside a \Q...\E sequence, all chars are literal */ +/* Now do the pre-compile. On error, errorcode will be set non-zero, so we +don't need to look at the result of the function here. The initial options have +been put into the cd block so that they can be changed if an option setting is +found within the regex right at the beginning. Bringing initial option settings +outside can help speed up starting point checks. */ - if (inescq) - { - if ((options & PCRE_AUTO_CALLOUT) != 0) length += 2 + 2*LINK_SIZE; - goto NORMAL_CHAR; - } +ptr += skipatstart; +code = cworkspace; +*code = OP_BRA; +(void)compile_regex(cd->external_options, cd->external_options & PCRE_IMS, + &code, &ptr, &errorcode, FALSE, FALSE, 0, &firstbyte, &reqbyte, NULL, cd, + &length); +if (errorcode != 0) goto PCRE_EARLY_ERROR_RETURN; - /* Otherwise, first check for ignored whitespace and comments */ +DPRINTF(("end pre-compile: length=%d workspace=%d\n", length, + cd->hwm - cworkspace)); - if ((options & PCRE_EXTENDED) != 0) - { - if ((cd->ctypes[c] & ctype_space) != 0) continue; - if (c == '#') - { - while (*(++ptr) != 0) if (IS_NEWLINE(ptr)) break; - if (*ptr != 0) - { - ptr += cd->nllen - 1; - continue; - } - break; /* End loop at end of pattern */ - } - } - - item_count++; /* Is zero for the first non-comment item */ - - /* Allow space for auto callout before every item except quantifiers. */ - - if ((options & PCRE_AUTO_CALLOUT) != 0 && - c != '*' && c != '+' && c != '?' && - (c != '{' || !is_counted_repeat(ptr + 1))) - length += 2 + 2*LINK_SIZE; - - switch(c) - { - /* A backslashed item may be an escaped data character or it may be a - character type. */ - - case '\\': - c = check_escape(&ptr, &errorcode, bracount, options, FALSE); - if (errorcode != 0) goto PCRE_ERROR_RETURN; - - lastitemlength = 1; /* Default length of last item for repeats */ - - if (c >= 0) /* Data character */ - { - length += 2; /* For a one-byte character */ - -#ifdef SUPPORT_UTF8 - if (utf8 && c > 127) - { - int i; - for (i = 0; i < _pcre_utf8_table1_size; i++) - if (c <= _pcre_utf8_table1[i]) break; - length += i; - lastitemlength += i; - } -#endif - - continue; - } - - /* If \Q, enter "literal" mode */ - - if (-c == ESC_Q) - { - inescq = TRUE; - continue; - } - - /* \X is supported only if Unicode property support is compiled */ - -#ifndef SUPPORT_UCP - if (-c == ESC_X) - { - errorcode = ERR45; - goto PCRE_ERROR_RETURN; - } -#endif - - /* \P and \p are for Unicode properties, but only when the support has - been compiled. Each item needs 3 bytes. */ - - else if (-c == ESC_P || -c == ESC_p) - { -#ifdef SUPPORT_UCP - BOOL negated; - BOOL pdata; - length += 3; - lastitemlength = 3; - if (get_ucp(&ptr, &negated, &pdata, &errorcode) < 0) - goto PCRE_ERROR_RETURN; - continue; -#else - errorcode = ERR45; - goto PCRE_ERROR_RETURN; -#endif - } - - /* Other escapes need one byte */ - - length++; - - /* A back reference needs an additional 2 bytes, plus either one or 5 - bytes for a repeat. We also need to keep the value of the highest - back reference. */ - - if (c <= -ESC_REF) - { - int refnum = -c - ESC_REF; - cd->backref_map |= (refnum < 32)? (1 << refnum) : 1; - if (refnum > cd->top_backref) - cd->top_backref = refnum; - length += 2; /* For single back reference */ - if (ptr[1] == '{' && is_counted_repeat(ptr+2)) - { - ptr = read_repeat_counts(ptr+2, &min, &max, &errorcode); - if (errorcode != 0) goto PCRE_ERROR_RETURN; - if ((min == 0 && (max == 1 || max == -1)) || - (min == 1 && max == -1)) - length++; - else length += 5; - if (ptr[1] == '?') ptr++; - } - } - continue; - - case '^': /* Single-byte metacharacters */ - case '.': - case '$': - length++; - lastitemlength = 1; - continue; - - case '*': /* These repeats won't be after brackets; */ - case '+': /* those are handled separately */ - case '?': - length++; - goto POSESSIVE; /* A few lines below */ - - /* This covers the cases of braced repeats after a single char, metachar, - class, or back reference. */ - - case '{': - if (!is_counted_repeat(ptr+1)) goto NORMAL_CHAR; - ptr = read_repeat_counts(ptr+1, &min, &max, &errorcode); - if (errorcode != 0) goto PCRE_ERROR_RETURN; - - /* These special cases just insert one extra opcode */ - - if ((min == 0 && (max == 1 || max == -1)) || - (min == 1 && max == -1)) - length++; - - /* These cases might insert additional copies of a preceding character. */ - - else - { - if (min != 1) - { - length -= lastitemlength; /* Uncount the original char or metachar */ - if (min > 0) length += 3 + lastitemlength; - } - length += lastitemlength + ((max > 0)? 3 : 1); - } - - if (ptr[1] == '?') ptr++; /* Needs no extra length */ - - POSESSIVE: /* Test for possessive quantifier */ - if (ptr[1] == '+') - { - ptr++; - length += 2 + 2*LINK_SIZE; /* Allow for atomic brackets */ - } - continue; - - /* An alternation contains an offset to the next branch or ket. If any ims - options changed in the previous branch(es), and/or if we are in a - lookbehind assertion, extra space will be needed at the start of the - branch. This is handled by branch_extra. */ - - case '|': - length += 1 + LINK_SIZE + branch_extra; - continue; - - /* A character class uses 33 characters provided that all the character - values are less than 256. Otherwise, it uses a bit map for low valued - characters, and individual items for others. Don't worry about character - types that aren't allowed in classes - they'll get picked up during the - compile. A character class that contains only one single-byte character - uses 2 or 3 bytes, depending on whether it is negated or not. Notice this - where we can. (In UTF-8 mode we can do this only for chars < 128.) */ - - case '[': - if (*(++ptr) == '^') - { - class_optcount = 10; /* Greater than one */ - ptr++; - } - else class_optcount = 0; - -#ifdef SUPPORT_UTF8 - class_utf8 = FALSE; -#endif - - /* Written as a "do" so that an initial ']' is taken as data */ - - if (*ptr != 0) do - { - /* Inside \Q...\E everything is literal except \E */ - - if (inescq) - { - if (*ptr != '\\' || ptr[1] != 'E') goto GET_ONE_CHARACTER; - inescq = FALSE; - ptr += 1; - continue; - } - - /* Outside \Q...\E, check for escapes */ - - if (*ptr == '\\') - { - c = check_escape(&ptr, &errorcode, bracount, options, TRUE); - if (errorcode != 0) goto PCRE_ERROR_RETURN; - - /* \b is backspace inside a class; \X is literal */ - - if (-c == ESC_b) c = '\b'; - else if (-c == ESC_X) c = 'X'; - - /* \Q enters quoting mode */ - - else if (-c == ESC_Q) - { - inescq = TRUE; - continue; - } - - /* Handle escapes that turn into characters */ - - if (c >= 0) goto NON_SPECIAL_CHARACTER; - - /* Escapes that are meta-things. The normal ones just affect the - bit map, but Unicode properties require an XCLASS extended item. */ - - else - { - class_optcount = 10; /* \d, \s etc; make sure > 1 */ -#ifdef SUPPORT_UTF8 - if (-c == ESC_p || -c == ESC_P) - { - if (!class_utf8) - { - class_utf8 = TRUE; - length += LINK_SIZE + 2; - } - length += 3; - } -#endif - } - } - - /* Check the syntax for POSIX stuff. The bits we actually handle are - checked during the real compile phase. */ - - else if (*ptr == '[' && - (ptr[1] == ':' || ptr[1] == '.' || ptr[1] == '=') && - check_posix_syntax(ptr, &ptr, cd)) - { - ptr++; - class_optcount = 10; /* Make sure > 1 */ - } - - /* Anything else increments the possible optimization count. We have to - detect ranges here so that we can compute the number of extra ranges for - caseless wide characters when UCP support is available. If there are wide - characters, we are going to have to use an XCLASS, even for single - characters. */ - - else - { - int d; - - GET_ONE_CHARACTER: - -#ifdef SUPPORT_UTF8 - if (utf8) - { - int extra = 0; - GETCHARLEN(c, ptr, extra); - ptr += extra; - } - else c = *ptr; -#else - c = *ptr; -#endif - - /* Come here from handling \ above when it escapes to a char value */ - - NON_SPECIAL_CHARACTER: - class_optcount++; - - d = -1; - if (ptr[1] == '-') - { - uschar const *hyptr = ptr++; - if (ptr[1] == '\\') - { - ptr++; - d = check_escape(&ptr, &errorcode, bracount, options, TRUE); - if (errorcode != 0) goto PCRE_ERROR_RETURN; - if (-d == ESC_b) d = '\b'; /* backspace */ - else if (-d == ESC_X) d = 'X'; /* literal X in a class */ - } - else if (ptr[1] != 0 && ptr[1] != ']') - { - ptr++; -#ifdef SUPPORT_UTF8 - if (utf8) - { - int extra = 0; - GETCHARLEN(d, ptr, extra); - ptr += extra; - } - else -#endif - d = *ptr; - } - if (d < 0) ptr = hyptr; /* go back to hyphen as data */ - } - - /* If d >= 0 we have a range. In UTF-8 mode, if the end is > 255, or > - 127 for caseless matching, we will need to use an XCLASS. */ - - if (d >= 0) - { - class_optcount = 10; /* Ensure > 1 */ - if (d < c) - { - errorcode = ERR8; - goto PCRE_ERROR_RETURN; - } - -#ifdef SUPPORT_UTF8 - if (utf8 && (d > 255 || ((options & PCRE_CASELESS) != 0 && d > 127))) - { - uschar buffer[6]; - if (!class_utf8) /* Allow for XCLASS overhead */ - { - class_utf8 = TRUE; - length += LINK_SIZE + 2; - } - -#ifdef SUPPORT_UCP - /* If we have UCP support, find out how many extra ranges are - needed to map the other case of characters within this range. We - have to mimic the range optimization here, because extending the - range upwards might push d over a boundary that makes is use - another byte in the UTF-8 representation. */ - - if ((options & PCRE_CASELESS) != 0) - { - int occ, ocd; - int cc = c; - int origd = d; - while (get_othercase_range(&cc, origd, &occ, &ocd)) - { - if (occ >= c && ocd <= d) continue; /* Skip embedded */ - - if (occ < c && ocd >= c - 1) /* Extend the basic range */ - { /* if there is overlap, */ - c = occ; /* noting that if occ < c */ - continue; /* we can't have ocd > d */ - } /* because a subrange is */ - if (ocd > d && occ <= d + 1) /* always shorter than */ - { /* the basic range. */ - d = ocd; - continue; - } - - /* An extra item is needed */ - - length += 1 + _pcre_ord2utf8(occ, buffer) + - ((occ == ocd)? 0 : _pcre_ord2utf8(ocd, buffer)); - } - } -#endif /* SUPPORT_UCP */ - - /* The length of the (possibly extended) range */ - - length += 1 + _pcre_ord2utf8(c, buffer) + _pcre_ord2utf8(d, buffer); - } -#endif /* SUPPORT_UTF8 */ - - } - - /* We have a single character. There is nothing to be done unless we - are in UTF-8 mode. If the char is > 255, or 127 when caseless, we must - allow for an XCL_SINGLE item, doubled for caselessness if there is UCP - support. */ - - else - { -#ifdef SUPPORT_UTF8 - if (utf8 && (c > 255 || ((options & PCRE_CASELESS) != 0 && c > 127))) - { - uschar buffer[6]; - class_optcount = 10; /* Ensure > 1 */ - if (!class_utf8) /* Allow for XCLASS overhead */ - { - class_utf8 = TRUE; - length += LINK_SIZE + 2; - } -#ifdef SUPPORT_UCP - length += (((options & PCRE_CASELESS) != 0)? 2 : 1) * - (1 + _pcre_ord2utf8(c, buffer)); -#else /* SUPPORT_UCP */ - length += 1 + _pcre_ord2utf8(c, buffer); -#endif /* SUPPORT_UCP */ - } -#endif /* SUPPORT_UTF8 */ - } - } - } - while (*(++ptr) != 0 && (inescq || *ptr != ']')); /* Concludes "do" above */ - - if (*ptr == 0) /* Missing terminating ']' */ - { - errorcode = ERR6; - goto PCRE_ERROR_RETURN; - } - - /* We can optimize when there was only one optimizable character. Repeats - for positive and negated single one-byte chars are handled by the general - code. Here, we handle repeats for the class opcodes. */ - - if (class_optcount == 1) length += 3; else - { - length += 33; - - /* A repeat needs either 1 or 5 bytes. If it is a possessive quantifier, - we also need extra for wrapping the whole thing in a sub-pattern. */ - - if (*ptr != 0 && ptr[1] == '{' && is_counted_repeat(ptr+2)) - { - ptr = read_repeat_counts(ptr+2, &min, &max, &errorcode); - if (errorcode != 0) goto PCRE_ERROR_RETURN; - if ((min == 0 && (max == 1 || max == -1)) || - (min == 1 && max == -1)) - length++; - else length += 5; - if (ptr[1] == '+') - { - ptr++; - length += 2 + 2*LINK_SIZE; - } - else if (ptr[1] == '?') ptr++; - } - } - continue; - - /* Brackets may be genuine groups or special things */ - - case '(': - branch_newextra = 0; - bracket_length = 1 + LINK_SIZE; - capturing = FALSE; - - /* Handle special forms of bracket, which all start (? */ - - if (ptr[1] == '?') - { - int set, unset; - int *optset; - - switch (c = ptr[2]) - { - /* Skip over comments entirely */ - case '#': - ptr += 3; - while (*ptr != 0 && *ptr != ')') ptr++; - if (*ptr == 0) - { - errorcode = ERR18; - goto PCRE_ERROR_RETURN; - } - continue; - - /* Non-referencing groups and lookaheads just move the pointer on, and - then behave like a non-special bracket, except that they don't increment - the count of extracting brackets. Ditto for the "once only" bracket, - which is in Perl from version 5.005. */ - - case ':': - case '=': - case '!': - case '>': - ptr += 2; - break; - - /* Named subpatterns are an extension copied from Python */ - - case 'P': - ptr += 3; - - /* Handle the definition of a named subpattern */ - - if (*ptr == '<') - { - const uschar *p; /* Don't amalgamate; some compilers */ - p = ++ptr; /* grumble at autoincrement in declaration */ - while ((cd->ctypes[*ptr] & ctype_word) != 0) ptr++; - if (*ptr != '>') - { - errorcode = ERR42; - goto PCRE_ERROR_RETURN; - } - name_count++; - if (name_count > MAX_NAME_COUNT) - { - errorcode = ERR49; - goto PCRE_ERROR_RETURN; - } - if (ptr - p > max_name_size) - { - max_name_size = (ptr - p); - if (max_name_size > MAX_NAME_SIZE) - { - errorcode = ERR48; - goto PCRE_ERROR_RETURN; - } - } - capturing = TRUE; /* Named parentheses are always capturing */ - break; /* Go handle capturing parentheses */ - } - - /* Handle back references and recursive calls to named subpatterns */ - - if (*ptr == '=' || *ptr == '>') - { - length += 3 + 3*LINK_SIZE; /* Allow for the automatic "once" */ - while ((cd->ctypes[*(++ptr)] & ctype_word) != 0); - if (*ptr != ')') - { - errorcode = ERR42; - goto PCRE_ERROR_RETURN; - } - goto RECURSE_CHECK_QUANTIFIED; - } - - /* Unknown character after (?P */ - - errorcode = ERR41; - goto PCRE_ERROR_RETURN; - - /* (?R) specifies a recursive call to the regex, which is an extension - to provide the facility which can be obtained by (?p{perl-code}) in - Perl 5.6. In Perl 5.8 this has become (??{perl-code}). - - From PCRE 4.00, items such as (?3) specify subroutine-like "calls" to - the appropriate numbered brackets. This includes both recursive and - non-recursive calls. (?R) is now synonymous with (?0). */ - - case 'R': - ptr++; - - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - ptr += 2; - if (c != 'R') - while ((digitab[*(++ptr)] & ctype_digit) != 0); - if (*ptr != ')') - { - errorcode = ERR29; - goto PCRE_ERROR_RETURN; - } - length += 3 + 3*LINK_SIZE; /* Allows for the automatic "once" */ - - /* If this item is quantified, it will get wrapped inside brackets so - as to use the code for quantified brackets. We jump down and use the - code that handles this for real brackets. Come here from code for - named recursions/subroutines. */ - - RECURSE_CHECK_QUANTIFIED: - if (ptr[1] == '+' || ptr[1] == '*' || ptr[1] == '?' || ptr[1] == '{') - { - length += 2 + 2 * LINK_SIZE; /* to make bracketed */ - duplength = 5 + 3 * LINK_SIZE; - goto HANDLE_QUANTIFIED_BRACKETS; - } - continue; - - /* (?C) is an extension which provides "callout" - to provide a bit of - the functionality of the Perl (?{...}) feature. An optional number may - follow (default is zero). */ - - case 'C': - ptr += 2; - while ((digitab[*(++ptr)] & ctype_digit) != 0); - if (*ptr != ')') - { - errorcode = ERR39; - goto PCRE_ERROR_RETURN; - } - length += 2 + 2*LINK_SIZE; - continue; - - /* Lookbehinds are in Perl from version 5.005 */ - - case '<': - ptr += 3; - if (*ptr == '=' || *ptr == '!') - { - branch_newextra = 1 + LINK_SIZE; - length += 1 + LINK_SIZE; /* For the first branch */ - break; - } - errorcode = ERR24; - goto PCRE_ERROR_RETURN; - - /* Conditionals are in Perl from version 5.005. The bracket must either - be followed by a number (for bracket reference) or by an assertion - group. PCRE extends this by allowing a name to reference a named group; - unfortunately, previously 'R' was implemented for a recursion test. - When this is compiled, we look for the named group 'R' first. At this - point we just do a basic syntax check. */ - - case '(': - if ((cd->ctypes[ptr[3]] & ctype_word) != 0) - { - ptr += 4; - length += 3; - while ((cd->ctypes[*ptr] & ctype_word) != 0) ptr++; - if (*ptr != ')') - { - errorcode = ERR26; - goto PCRE_ERROR_RETURN; - } - } - else /* An assertion must follow */ - { - ptr++; /* Can treat like ':' as far as spacing is concerned */ - if (ptr[2] != '?' || - (ptr[3] != '=' && ptr[3] != '!' && ptr[3] != '<') ) - { - ptr += 2; /* To get right offset in message */ - errorcode = ERR28; - goto PCRE_ERROR_RETURN; - } - } - break; - - /* Else loop checking valid options until ) is met. Anything else is an - error. If we are without any brackets, i.e. at top level, the settings - act as if specified in the options, so massage the options immediately. - This is for backward compatibility with Perl 5.004. */ - - default: - set = unset = 0; - optset = &set; - ptr += 2; - - for (;; ptr++) - { - c = *ptr; - switch (c) - { - case 'i': - *optset |= PCRE_CASELESS; - continue; - - case 'J': - *optset |= PCRE_DUPNAMES; - options |= PCRE_JCHANGED; /* Record that it changed */ - continue; - - case 'm': - *optset |= PCRE_MULTILINE; - continue; - - case 's': - *optset |= PCRE_DOTALL; - continue; - - case 'x': - *optset |= PCRE_EXTENDED; - continue; - - case 'X': - *optset |= PCRE_EXTRA; - continue; - - case 'U': - *optset |= PCRE_UNGREEDY; - continue; - - case '-': - optset = &unset; - continue; - - /* A termination by ')' indicates an options-setting-only item; if - this is at the very start of the pattern (indicated by item_count - being zero), we use it to set the global options. This is helpful - when analyzing the pattern for first characters, etc. Otherwise - nothing is done here and it is handled during the compiling - process. - - We allow for more than one options setting at the start. If such - settings do not change the existing options, nothing is compiled. - However, we must leave space just in case something is compiled. - This can happen for pathological sequences such as (?i)(?-i) - because the global options will end up with -i set. The space is - small and not significant. (Before I did this there was a reported - bug with (?i)(?-i) in a machine-generated pattern.) - - [Historical note: Up to Perl 5.8, options settings at top level - were always global settings, wherever they appeared in the pattern. - That is, they were equivalent to an external setting. From 5.8 - onwards, they apply only to what follows (which is what you might - expect).] */ - - case ')': - if (item_count == 0) - { - options = (options | set) & (~unset); - set = unset = 0; /* To save length */ - item_count--; /* To allow for several */ - length += 2; - } - - /* Fall through */ - - /* A termination by ':' indicates the start of a nested group with - the given options set. This is again handled at compile time, but - we must allow for compiled space if any of the ims options are - set. We also have to allow for resetting space at the end of - the group, which is why 4 is added to the length and not just 2. - If there are several changes of options within the same group, this - will lead to an over-estimate on the length, but this shouldn't - matter very much. We also have to allow for resetting options at - the start of any alternations, which we do by setting - branch_newextra to 2. */ - - case ':': - if (((set|unset) & PCRE_IMS) != 0) - { - length += 4; - branch_newextra = 2; - } - goto END_OPTIONS; - - /* Unrecognized option character */ - - default: - errorcode = ERR12; - goto PCRE_ERROR_RETURN; - } - } - - /* If we hit a closing bracket, that's it - this is a freestanding - option-setting. We need to ensure that branch_extra is updated if - necessary. The only values branch_newextra can have here are 0 or 2. - If the value is 2, then branch_extra must either be 2 or 5, depending - on whether this is a lookbehind group or not. */ - - END_OPTIONS: - if (c == ')') - { - if (branch_newextra == 2 && - (branch_extra == 0 || branch_extra == 1+LINK_SIZE)) - branch_extra += branch_newextra; - continue; - } - - /* If options were terminated by ':' control comes here. This is a - non-capturing group with an options change. There is nothing more that - needs to be done because "capturing" is already set FALSE by default; - we can just fall through. */ - - } - } - - /* Ordinary parentheses, not followed by '?', are capturing unless - PCRE_NO_AUTO_CAPTURE is set. */ - - else capturing = (options & PCRE_NO_AUTO_CAPTURE) == 0; - - /* Capturing brackets must be counted so we can process escapes in a - Perlish way. If the number exceeds EXTRACT_BASIC_MAX we are going to need - an additional 3 bytes of memory per capturing bracket. */ - - if (capturing) - { - bracount++; - if (bracount > EXTRACT_BASIC_MAX) bracket_length += 3; - } - - /* Save length for computing whole length at end if there's a repeat that - requires duplication of the group. Also save the current value of - branch_extra, and start the new group with the new value. If non-zero, this - will either be 2 for a (?imsx: group, or 3 for a lookbehind assertion. */ - - if (brastackptr >= sizeof(brastack)/sizeof(int)) - { - errorcode = ERR19; - goto PCRE_ERROR_RETURN; - } - - bralenstack[brastackptr] = branch_extra; - branch_extra = branch_newextra; - - brastack[brastackptr++] = length; - length += bracket_length; - continue; - - /* Handle ket. Look for subsequent max/min; for certain sets of values we - have to replicate this bracket up to that many times. If brastackptr is - 0 this is an unmatched bracket which will generate an error, but take care - not to try to access brastack[-1] when computing the length and restoring - the branch_extra value. */ - - case ')': - length += 1 + LINK_SIZE; - if (brastackptr > 0) - { - duplength = length - brastack[--brastackptr]; - branch_extra = bralenstack[brastackptr]; - /* This is a paranoid check to stop integer overflow later on */ - if (duplength > MAX_DUPLENGTH) - { - errorcode = ERR50; - goto PCRE_ERROR_RETURN; - } - } - else duplength = 0; - - /* The following code is also used when a recursion such as (?3) is - followed by a quantifier, because in that case, it has to be wrapped inside - brackets so that the quantifier works. The value of duplength must be - set before arrival. */ - - HANDLE_QUANTIFIED_BRACKETS: - - /* Leave ptr at the final char; for read_repeat_counts this happens - automatically; for the others we need an increment. */ - - if ((c = ptr[1]) == '{' && is_counted_repeat(ptr+2)) - { - ptr = read_repeat_counts(ptr+2, &min, &max, &errorcode); - if (errorcode != 0) goto PCRE_ERROR_RETURN; - } - else if (c == '*') { min = 0; max = -1; ptr++; } - else if (c == '+') { min = 1; max = -1; ptr++; } - else if (c == '?') { min = 0; max = 1; ptr++; } - else { min = 1; max = 1; } - - /* If the minimum is zero, we have to allow for an OP_BRAZERO before the - group, and if the maximum is greater than zero, we have to replicate - maxval-1 times; each replication acquires an OP_BRAZERO plus a nesting - bracket set. */ - - if (min == 0) - { - length++; - if (max > 0) length += (max - 1) * (duplength + 3 + 2*LINK_SIZE); - } - - /* When the minimum is greater than zero, we have to replicate up to - minval-1 times, with no additions required in the copies. Then, if there - is a limited maximum we have to replicate up to maxval-1 times allowing - for a BRAZERO item before each optional copy and nesting brackets for all - but one of the optional copies. */ - - else - { - length += (min - 1) * duplength; - if (max > min) /* Need this test as max=-1 means no limit */ - length += (max - min) * (duplength + 3 + 2*LINK_SIZE) - - (2 + 2*LINK_SIZE); - } - - /* Allow space for once brackets for "possessive quantifier" */ - - if (ptr[1] == '+') - { - ptr++; - length += 2 + 2*LINK_SIZE; - } - continue; - - /* Non-special character. It won't be space or # in extended mode, so it is - always a genuine character. If we are in a \Q...\E sequence, check for the - end; if not, we have a literal. */ - - default: - NORMAL_CHAR: - - if (inescq && c == '\\' && ptr[1] == 'E') - { - inescq = FALSE; - ptr++; - continue; - } - - length += 2; /* For a one-byte character */ - lastitemlength = 1; /* Default length of last item for repeats */ - - /* In UTF-8 mode, check for additional bytes. */ - -#ifdef SUPPORT_UTF8 - if (utf8 && (c & 0xc0) == 0xc0) - { - while ((ptr[1] & 0xc0) == 0x80) /* Can't flow over the end */ - { /* because the end is marked */ - lastitemlength++; /* by a zero byte. */ - length++; - ptr++; - } - } -#endif - - continue; - } - } - -length += 2 + LINK_SIZE; /* For final KET and END */ - -if ((options & PCRE_AUTO_CALLOUT) != 0) - length += 2 + 2*LINK_SIZE; /* For final callout */ - if (length > MAX_PATTERN_SIZE) { errorcode = ERR20; @@ -5091,9 +5942,10 @@ externally provided function. Integer ov /* Compute the size of data block needed and get it, either from malloc or externally provided function. Integer overflow should no longer be possible -because nowadays we limit the maximum value of name_count and max_name size. */ +because nowadays we limit the maximum value of cd->names_found and +cd->name_entry_size. */ -size = length + sizeof(real_pcre) + name_count * (max_name_size + 3); +size = length + sizeof(real_pcre) + cd->names_found * (cd->name_entry_size + 3); re = (real_pcre *)(pcre_malloc)(size); if (re == NULL) @@ -5102,48 +5954,56 @@ if (re == NULL) goto PCRE_EARLY_ERROR_RETURN; } -/* Put in the magic number, and save the sizes, options, and character table -pointer. NULL is used for the default character tables. The nullpad field is at -the end; it's there to help in the case when a regex compiled on a system with -4-byte pointers is run on another with 8-byte pointers. */ +/* Put in the magic number, and save the sizes, initial options, internal +flags, and character table pointer. NULL is used for the default character +tables. The nullpad field is at the end; it's there to help in the case when a +regex compiled on a system with 4-byte pointers is run on another with 8-byte +pointers. */ re->magic_number = MAGIC_NUMBER; re->size = size; -re->options = options; +re->options = cd->external_options; +re->flags = cd->external_flags; re->dummy1 = 0; +re->first_byte = 0; +re->req_byte = 0; re->name_table_offset = sizeof(real_pcre); -re->name_entry_size = max_name_size + 3; -re->name_count = name_count; +re->name_entry_size = cd->name_entry_size; +re->name_count = cd->names_found; re->ref_count = 0; re->tables = (tables == _pcre_default_tables)? NULL : tables; re->nullpad = NULL; /* The starting points of the name/number translation table and of the code are -passed around in the compile data block. */ +passed around in the compile data block. The start/end pattern and initial +options are already set from the pre-compile phase, as is the name_entry_size +field. Reset the bracket count and the names_found field. Also reset the hwm +field; this time it's used for remembering forward references to subpatterns. +*/ +cd->bracount = 0; cd->names_found = 0; -cd->name_entry_size = max_name_size + 3; cd->name_table = (uschar *)re + re->name_table_offset; codestart = cd->name_table + re->name_entry_size * re->name_count; cd->start_code = codestart; -cd->start_pattern = (const uschar *)pattern; +cd->hwm = cworkspace; cd->req_varyopt = 0; -cd->nopartial = FALSE; +cd->had_accept = FALSE; /* Set up a starting, non-extracting bracket, then compile the expression. On error, errorcode will be set non-zero, so we don't need to look at the result of the function here. */ -ptr = (const uschar *)pattern; +ptr = (const uschar *)pattern + skipatstart; code = (uschar *)codestart; *code = OP_BRA; -bracount = 0; -(void)compile_regex(options, options & PCRE_IMS, &bracount, &code, &ptr, - &errorcode, FALSE, 0, &firstbyte, &reqbyte, NULL, cd); -re->top_bracket = bracount; +(void)compile_regex(re->options, re->options & PCRE_IMS, &code, &ptr, + &errorcode, FALSE, FALSE, 0, &firstbyte, &reqbyte, NULL, cd, NULL); +re->top_bracket = cd->bracount; re->top_backref = cd->top_backref; +re->flags = cd->external_flags; -if (cd->nopartial) re->options |= PCRE_NOPARTIAL; +if (cd->had_accept) reqbyte = -1; /* Must disable after (*ACCEPT) */ /* If not reached end of pattern on success, there's an excess bracket. */ @@ -5158,20 +6018,34 @@ if (code - codestart > length) errorcode if (code - codestart > length) errorcode = ERR23; #endif +/* Fill in any forward references that are required. */ + +while (errorcode == 0 && cd->hwm > cworkspace) + { + int offset, recno; + const uschar *groupptr; + cd->hwm -= LINK_SIZE; + offset = GET(cd->hwm, 0); + recno = GET(codestart, offset); + groupptr = find_bracket(codestart, (re->options & PCRE_UTF8) != 0, recno); + if (groupptr == NULL) errorcode = ERR53; + else PUT(((uschar *)codestart), offset, groupptr - codestart); + } + /* Give an error if there's back reference to a non-existent capturing subpattern. */ -if (re->top_backref > re->top_bracket) errorcode = ERR15; +if (errorcode == 0 && re->top_backref > re->top_bracket) errorcode = ERR15; /* Failed to compile, or error while post-processing */ if (errorcode != 0) { (pcre_free)(re); - PCRE_ERROR_RETURN: - *erroroffset = ptr - (const uschar *)pattern; PCRE_EARLY_ERROR_RETURN: - *errorptr = error_texts[errorcode]; + *erroroffset = ptr - (const uschar *)pattern; + PCRE_EARLY_ERROR_RETURN2: + *errorptr = find_error_text(errorcode); if (errorcodeptr != NULL) *errorcodeptr = errorcode; return NULL; } @@ -5180,15 +6054,15 @@ as starting with .* when DOTALL is set). the pattern is anchored by virtue of ^ characters or \A or anything else (such as starting with .* when DOTALL is set). -Otherwise, if we know what the first character has to be, save it, because that +Otherwise, if we know what the first byte has to be, save it, because that speeds up unanchored matches no end. If not, see if we can set the PCRE_STARTLINE flag. This is helpful for multiline matches when all branches start with ^. and also when all branches start with .* for non-DOTALL matches. */ -if ((options & PCRE_ANCHORED) == 0) +if ((re->options & PCRE_ANCHORED) == 0) { - int temp_options = options; + int temp_options = re->options; /* May get changed during these scans */ if (is_anchored(codestart, &temp_options, 0, cd->backref_map)) re->options |= PCRE_ANCHORED; else @@ -5200,10 +6074,10 @@ if ((options & PCRE_ANCHORED) == 0) int ch = firstbyte & 255; re->first_byte = ((firstbyte & REQ_CASELESS) != 0 && cd->fcc[ch] == ch)? ch : firstbyte; - re->options |= PCRE_FIRSTSET; + re->flags |= PCRE_FIRSTSET; } else if (is_startline(codestart, 0, cd->backref_map)) - re->options |= PCRE_STARTLINE; + re->flags |= PCRE_STARTLINE; } } @@ -5217,7 +6091,7 @@ if (reqbyte >= 0 && int ch = reqbyte & 255; re->req_byte = ((reqbyte & REQ_CASELESS) != 0 && cd->fcc[ch] == ch)? (reqbyte & ~REQ_CASELESS) : reqbyte; - re->options |= PCRE_REQCHSET; + re->flags |= PCRE_REQCHSET; } /* Print out the compiled data if debugging is enabled. This is never the @@ -5228,21 +6102,9 @@ printf("Length = %d top_bracket = %d top printf("Length = %d top_bracket = %d top_backref = %d\n", length, re->top_bracket, re->top_backref); -if (re->options != 0) - { - printf("%s%s%s%s%s%s%s%s%s\n", - ((re->options & PCRE_NOPARTIAL) != 0)? "nopartial " : "", - ((re->options & PCRE_ANCHORED) != 0)? "anchored " : "", - ((re->options & PCRE_CASELESS) != 0)? "caseless " : "", - ((re->options & PCRE_EXTENDED) != 0)? "extended " : "", - ((re->options & PCRE_MULTILINE) != 0)? "multiline " : "", - ((re->options & PCRE_DOTALL) != 0)? "dotall " : "", - ((re->options & PCRE_DOLLAR_ENDONLY) != 0)? "endonly " : "", - ((re->options & PCRE_EXTRA) != 0)? "extra " : "", - ((re->options & PCRE_UNGREEDY) != 0)? "ungreedy " : ""); - } +printf("Options=%08x\n", re->options); -if ((re->options & PCRE_FIRSTSET) != 0) +if ((re->flags & PCRE_FIRSTSET) != 0) { int ch = re->first_byte & 255; const char *caseless = ((re->first_byte & REQ_CASELESS) == 0)? @@ -5251,7 +6113,7 @@ if ((re->options & PCRE_FIRSTSET) != 0) else printf("First char = \\x%02x%s\n", ch, caseless); } -if ((re->options & PCRE_REQCHSET) != 0) +if ((re->flags & PCRE_REQCHSET) != 0) { int ch = re->req_byte & 255; const char *caseless = ((re->req_byte & REQ_CASELESS) == 0)? @@ -5260,7 +6122,7 @@ if ((re->options & PCRE_REQCHSET) != 0) else printf("Req char = \\x%02x%s\n", ch, caseless); } -pcre_printint(re, stdout); +pcre_printint(re, stdout, TRUE); /* This check is done here in the debugging case so that the code that was compiled can be seen. */ @@ -5268,12 +6130,12 @@ if (code - codestart > length) if (code - codestart > length) { (pcre_free)(re); - *errorptr = error_texts[ERR23]; + *errorptr = find_error_text(ERR23); *erroroffset = ptr - (uschar *)pattern; if (errorcodeptr != NULL) *errorcodeptr = ERR23; return NULL; } -#endif +#endif /* DEBUG */ return (pcre *)re; } ============================================================ --- pcre/pcre_config.c 3197ae2ed4c54cc20c770044d842038ba7e9f2b5 +++ pcre/pcre_config.c 9e873bc83d131086cab79a943b783ea9367222e4 @@ -6,7 +6,7 @@ and semantics are as close as possible t and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel - Copyright (c) 1997-2006 University of Cambridge + Copyright (c) 1997-2007 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -41,6 +41,8 @@ POSSIBILITY OF SUCH DAMAGE. /* This module contains the external function pcre_config(). */ +#include "pcre_config.h" + #include "pcre_internal.h" @@ -58,7 +60,7 @@ Returns: 0 if data returned, n Returns: 0 if data returned, negative on error */ -PCRE_DATA_SCOPE int +PCRE_EXP_DEFN int pcre_config(int what, void *where) { switch (what) @@ -83,6 +85,14 @@ switch (what) *((int *)where) = NEWLINE; break; + case PCRE_CONFIG_BSR: +#ifdef BSR_ANYCRLF + *((int *)where) = 1; +#else + *((int *)where) = 0; +#endif + break; + case PCRE_CONFIG_LINK_SIZE: *((int *)where) = LINK_SIZE; break; ============================================================ --- pcre/pcre_config.h cdd4d95dc55d8f805da3888d61eb630148b39eaf +++ pcre/pcre_config.h e2de114bbc6648e9d5f961c63729069b64733f67 @@ -1,152 +1,115 @@ -/* Formerly libpcre config.h.in. We do not need to worry about most of the - portability issues that upstream libpcre's build system concerns itself - with, so we make no attempt to wire this up to monotone's configure. */ +/* Formerly pcre-7.4/config.h.in. Only those macros used by the + library proper, not the test programs, have been preserved. As + monotone assumes all the facilities of C90 exist, we hardwire the + C90 setting of the configuration macro for the few places where + PCRE doesn't make that assumption. For values set from configure + command line switches in PCRE upstream, we hardwire selections that + are appropriate for monotone (mostly the upstream defaults). */ -/* Make sure these options are disabled, as we did not import all of their - support code. */ -#undef SUPPORT_UTF8 -#undef SUPPORT_UCP -#undef DEBUG +/* By default, the \R escape sequence matches any Unicode line ending + character or sequence of characters. If BSR_ANYCRLF is defined, this is + changed so that backslash-R matches only CR, LF, or CRLF. The build- time + default can be overridden by the user of PCRE at runtime. On systems that + support it, "configure" can be used to override the default. */ +/* #undef BSR_ANYCRLF */ -/* On Unix-like systems config.in is converted by "configure" into config.h. -Some other environments also support the use of "configure". PCRE is written in -Standard C, but there are a few non-standard things it can cope with, allowing -it to run on SunOS4 and other "close to standard" systems. - -On a non-Unix-like system you should just copy this file into config.h, and set -up the macros the way you need them. You should normally change the definitions -of HAVE_STRERROR and HAVE_MEMMOVE to 1. Unfortunately, because of the way -autoconf works, these cannot be made the defaults. If your system has bcopy() -and not memmove(), change the definition of HAVE_BCOPY instead of HAVE_MEMMOVE. -If your system has neither bcopy() nor memmove(), leave them both as 0; an -emulation function will be used. */ - /* If you are compiling for a system that uses EBCDIC instead of ASCII -character codes, define this macro as 1. On systems that can use "configure", -this can be done via --enable-ebcdic. */ + character codes, define this macro as 1. On systems that can use + "configure", this can be done via --enable-ebcdic. */ +/* #undef EBCDIC */ -#ifndef EBCDIC -#define EBCDIC 0 -#endif +/* Define to 1 if you have the `bcopy' function. */ +/* #undef HAVE_BCOPY */ -/* If you are compiling for a system other than a Unix-like system or Win32, -and it needs some magic to be inserted before the definition of a function that -is exported by the library, define this macro to contain the relevant magic. If -you do not define this macro, it defaults to "extern" for a C compiler and -"extern C" for a C++ compiler on non-Win32 systems. This macro apears at the -start of every exported function that is part of the external API. It does not -appear on functions that are "external" in the C sense, but which are internal -to the library. */ +/* Define to 1 if you have the `memmove' function. */ +#define HAVE_MEMMOVE 1 -/* #define PCRE_DATA_SCOPE */ +/* The value of LINK_SIZE determines the number of bytes used to store links + as offsets within the compiled regex. The default is 2, which allows for + compiled patterns up to 64K long. This covers the vast majority of cases. + However, PCRE can also be compiled to use 3 or 4 bytes instead. This allows + for longer patterns in extreme cases. On systems that support it, + "configure" can be used to override this default. */ +#define LINK_SIZE 2 -/* Define the following macro to empty if the "const" keyword does not work. */ +/* The value of MATCH_LIMIT determines the default number of times the + internal match() function can be called during a single execution of + pcre_exec(). There is a runtime interface for setting a different limit. + The limit exists in order to catch runaway regular expressions that take + for ever to determine that they do not match. The default is set very large + so that it does not accidentally catch legitimate cases. On systems that + support it, "configure" can be used to override this default default. */ +#define MATCH_LIMIT 10000000 -#undef const +/* The above limit applies to all calls of match(), whether or not they + increase the recursion depth. In some environments it is desirable to limit + the depth of recursive calls of match() more strictly, in order to restrict + the maximum amount of stack (or heap, if NO_RECURSE is defined) that is + used. The value of MATCH_LIMIT_RECURSION applies only to recursive calls of + match(). To have any useful effect, it must be less than the value of + MATCH_LIMIT. The default is to use the same value as MATCH_LIMIT. There is + a runtime method for setting a different limit. On systems that support it, + "configure" can be used to override the default. */ +#define MATCH_LIMIT_RECURSION MATCH_LIMIT -/* Define the following macro to "unsigned" if does not define -size_t. */ +/* This limit is parameterized just in case anybody ever wants to change it. + Care must be taken if it is increased, because it guards against integer + overflow caused by enormously large patterns. */ +#define MAX_NAME_COUNT 10000 -#undef size_t +/* This limit is parameterized just in case anybody ever wants to change it. + Care must be taken if it is increased, because it guards against integer + overflow caused by enormously large patterns. */ +#define MAX_NAME_SIZE 32 -/* The following two definitions are mainly for the benefit of SunOS4, which -does not have the strerror() or memmove() functions that should be present in -all Standard C libraries. The macros HAVE_STRERROR and HAVE_MEMMOVE should -normally be defined with the value 1 for other systems, but unfortunately we -cannot make this the default because "configure" files generated by autoconf -will only change 0 to 1; they won't change 1 to 0 if the functions are not -found. */ +/* The value of NEWLINE determines the newline character sequence. On systems + that support it, "configure" can be used to override the default, which is + 10. The possible values are 10 (LF), 13 (CR), 3338 (CRLF), -1 (ANY), or -2 + (ANYCRLF). */ +#define NEWLINE -1 -#define HAVE_STRERROR 1 -#define HAVE_MEMMOVE 1 +/* PCRE uses recursive function calls to handle backtracking while matching. + This can sometimes be a problem on systems that have stacks of limited + size. Define NO_RECURSE to get a version that doesn't use recursion in the + match() function; instead it creates its own stack by steam using + pcre_recurse_malloc() to obtain memory from the heap. For more detail, see + the comments and other stuff just above the match() function. On systems + that support it, "configure" can be used to set this in the Makefile (use + --disable-stack-for-recursion). */ +/* #undef NO_RECURSE */ -/* There are some non-Unix-like systems that don't even have bcopy(). If this -macro is false, an emulation is used. If HAVE_MEMMOVE is set to 1, the value of -HAVE_BCOPY is not relevant. */ +/* If you are compiling for a system other than a Unix-like system or + Win32, and it needs some magic to be inserted before the definition + of a function that is exported by the library, define this macro to + contain the relevant magic. If you do not define this macro, it + defaults to "extern" for a C compiler and "extern C" for a C++ + compiler on non-Win32 systems. This macro apears at the start of + every exported function that is part of the external API. It does + not appear on functions that are "external" in the C sense, but + which are internal to the library. */ +/* #undef PCRE_EXP_DEFN */ -#define HAVE_BCOPY 0 +/* Define if linking statically (TODO: make nice with Libtool) */ +#define PCRE_STATIC 1 -/* The value of NEWLINE determines the newline character. The default is to -leave it up to the compiler, but some sites want to force a particular value. -On Unix-like systems, "configure" can be used to override this default. */ - -#ifndef NEWLINE -#define NEWLINE '\n' -#endif - -/* The value of LINK_SIZE determines the number of bytes used to store links as -offsets within the compiled regex. The default is 2, which allows for compiled -patterns up to 64K long. This covers the vast majority of cases. However, PCRE -can also be compiled to use 3 or 4 bytes instead. This allows for longer -patterns in extreme cases. On systems that support it, "configure" can be used -to override this default. */ - -#ifndef LINK_SIZE -#define LINK_SIZE 2 -#endif - /* When calling PCRE via the POSIX interface, additional working storage is -required for holding the pointers to capturing substrings because PCRE requires -three integers per substring, whereas the POSIX interface provides only two. If -the number of expected substrings is small, the wrapper function uses space on -the stack, because this is faster than using malloc() for each call. The -threshold above which the stack is no longer used is defined by POSIX_MALLOC_ -THRESHOLD. On systems that support it, "configure" can be used to override this -default. */ - -#ifndef POSIX_MALLOC_THRESHOLD + required for holding the pointers to capturing substrings because PCRE + requires three integers per substring, whereas the POSIX interface provides + only two. If the number of expected substrings is small, the wrapper + function uses space on the stack, because this is faster than using + malloc() for each call. The threshold above which the stack is no longer + used is defined by POSIX_MALLOC_THRESHOLD. On systems that support it, + "configure" can be used to override this default. */ #define POSIX_MALLOC_THRESHOLD 10 -#endif -/* PCRE uses recursive function calls to handle backtracking while matching. -This can sometimes be a problem on systems that have stacks of limited size. -Define NO_RECURSE to get a version that doesn't use recursion in the match() -function; instead it creates its own stack by steam using pcre_recurse_malloc() -to obtain memory from the heap. For more detail, see the comments and other -stuff just above the match() function. On systems that support it, "configure" -can be used to set this in the Makefile (use --disable-stack-for-recursion). */ +/* Define to enable support for Unicode properties */ +#define SUPPORT_UCP 1 -/* #define NO_RECURSE */ +/* Define to enable support for the UTF-8 Unicode encoding. */ +#define SUPPORT_UTF8 1 -/* The value of MATCH_LIMIT determines the default number of times the internal -match() function can be called during a single execution of pcre_exec(). There -is a runtime interface for setting a different limit. The limit exists in order -to catch runaway regular expressions that take for ever to determine that they -do not match. The default is set very large so that it does not accidentally -catch legitimate cases. On systems that support it, "configure" can be used to -override this default default. */ +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ -#ifndef MATCH_LIMIT -#define MATCH_LIMIT 10000000 -#endif - -/* The above limit applies to all calls of match(), whether or not they -increase the recursion depth. In some environments it is desirable to limit the -depth of recursive calls of match() more strictly, in order to restrict the -maximum amount of stack (or heap, if NO_RECURSE is defined) that is used. The -value of MATCH_LIMIT_RECURSION applies only to recursive calls of match(). To -have any useful effect, it must be less than the value of MATCH_LIMIT. There is -a runtime method for setting a different limit. On systems that support it, -"configure" can be used to override this default default. */ - -#ifndef MATCH_LIMIT_RECURSION -#define MATCH_LIMIT_RECURSION MATCH_LIMIT -#endif - -/* These three limits are parameterized just in case anybody ever wants to -change them. Care must be taken if they are increased, because they guard -against integer overflow caused by enormously large patterns. */ - -#ifndef MAX_NAME_SIZE -#define MAX_NAME_SIZE 32 -#endif - -#ifndef MAX_NAME_COUNT -#define MAX_NAME_COUNT 10000 -#endif - -#ifndef MAX_DUPLENGTH -#define MAX_DUPLENGTH 30000 -#endif - -/* End */ ============================================================ --- pcre/pcre_dfa_exec.c e47bdb1351432a867879ff71b5439285458202b6 +++ pcre/pcre_dfa_exec.c 54e1c705cf360ac00f188006e24f1faa813c8508 @@ -6,7 +6,7 @@ and semantics are as close as possible t and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel - Copyright (c) 1997-2006 University of Cambridge + Copyright (c) 1997-2007 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -39,11 +39,17 @@ POSSIBILITY OF SUCH DAMAGE. /* This module contains the external function pcre_dfa_exec(), which is an -alternative matching function that uses a DFA algorithm. This is NOT Perl- -compatible, but it has advantages in certain applications. */ +alternative matching function that uses a sort of DFA algorithm (not a true +FSM). This is NOT Perl- compatible, but it has advantages in certain +applications. */ -#define NLBLOCK md /* The block containing newline information */ +#include "pcre_config.h" + +#define NLBLOCK md /* Block containing newline information */ +#define PSSTART start_subject /* Field containing processed string start */ +#define PSEND end_subject /* Field containing processed string end */ + #include "pcre_internal.h" @@ -58,24 +64,31 @@ compatible, but it has advantages in cer *************************************************/ /* These are offsets that are used to turn the OP_TYPESTAR and friends opcodes -into others, under special conditions. A gap of 10 between the blocks should be -enough. */ +into others, under special conditions. A gap of 20 between the blocks should be +enough. The resulting opcodes don't have to be less than 256 because they are +never stored, so we push them well clear of the normal opcodes. */ -#define OP_PROP_EXTRA (EXTRACT_BASIC_MAX+1) -#define OP_EXTUNI_EXTRA (EXTRACT_BASIC_MAX+11) +#define OP_PROP_EXTRA 300 +#define OP_EXTUNI_EXTRA 320 +#define OP_ANYNL_EXTRA 340 +#define OP_HSPACE_EXTRA 360 +#define OP_VSPACE_EXTRA 380 /* This table identifies those opcodes that are followed immediately by a character that is to be tested in some way. This makes is possible to centralize the loading of these characters. In the case of Type * etc, the "character" is the opcode for \D, \d, \S, \s, \W, or \w, which will always be a -small value. */ +small value. ***NOTE*** If the start of this table is modified, the two tables +that follow must also be modified. */ static uschar coptable[] = { 0, /* End */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* \A, \G, \B, \b, \D, \d, \S, \s, \W, \w */ + 0, 0, 0, 0, 0, /* \A, \G, \K, \B, \b */ + 0, 0, 0, 0, 0, 0, /* \D, \d, \S, \s, \W, \w */ 0, 0, /* Any, Anybyte */ 0, 0, 0, /* NOTPROP, PROP, EXTUNI */ + 0, 0, 0, 0, 0, /* \R, \H, \h, \V, \v */ 0, 0, 0, 0, 0, /* \Z, \z, Opt, ^, $ */ 1, /* Char */ 1, /* Charnc */ @@ -83,12 +96,15 @@ static uschar coptable[] = { /* Positive single-char repeats */ 1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */ 3, 3, 3, /* upto, minupto, exact */ + 1, 1, 1, 3, /* *+, ++, ?+, upto+ */ /* Negative single-char repeats - only for chars < 256 */ 1, 1, 1, 1, 1, 1, /* NOT *, *?, +, +?, ?, ?? */ 3, 3, 3, /* NOT upto, minupto, exact */ + 1, 1, 1, 3, /* NOT *+, ++, ?+, updo+ */ /* Positive type repeats */ 1, 1, 1, 1, 1, 1, /* Type *, *?, +, +?, ?, ?? */ 3, 3, 3, /* Type upto, minupto, exact */ + 1, 1, 1, 3, /* Type *+, ++, ?+, upto+ */ /* Character class & ref repeats */ 0, 0, 0, 0, 0, 0, /* *, *?, +, +?, ?, ?? */ 0, 0, /* CRRANGE, CRMINRANGE */ @@ -107,19 +123,21 @@ static uschar coptable[] = { 0, /* Assert behind */ 0, /* Assert behind not */ 0, /* Reverse */ - 0, /* Once */ - 0, /* COND */ + 0, 0, 0, 0, /* ONCE, BRA, CBRA, COND */ + 0, 0, 0, /* SBRA, SCBRA, SCOND */ 0, /* CREF */ + 0, /* RREF */ + 0, /* DEF */ 0, 0, /* BRAZERO, BRAMINZERO */ - 0, /* BRANUMBER */ - 0 /* BRA */ + 0, 0, 0, 0, /* PRUNE, SKIP, THEN, COMMIT */ + 0, 0 /* FAIL, ACCEPT */ }; /* These 2 tables allow for compact code for testing for \D, \d, \S, \s, \W, and \w */ static uschar toptable1[] = { - 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, ctype_digit, ctype_digit, ctype_space, ctype_space, ctype_word, ctype_word, @@ -127,7 +145,7 @@ static uschar toptable2[] = { }; static uschar toptable2[] = { - 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, ctype_digit, 0, ctype_space, 0, ctype_word, 0, @@ -278,7 +296,7 @@ const uschar *ptr; const uschar *ctypes, *lcc, *fcc; const uschar *ptr; -const uschar *end_code; +const uschar *end_code, *first_op; int active_count, new_count, match_count; @@ -291,6 +309,8 @@ BOOL utf8 = (md->poptions & PCRE_UTF8) ! #ifdef SUPPORT_UTF8 BOOL utf8 = (md->poptions & PCRE_UTF8) != 0; +#else +BOOL utf8 = FALSE; #endif rlevel++; @@ -314,6 +334,9 @@ new_count = 0; next_new_state = new_states = active_states + wscount; new_count = 0; +first_op = this_start_code + 1 + LINK_SIZE + + ((*this_start_code == OP_CBRA || *this_start_code == OP_SCBRA)? 2:0); + /* The first thing in any (sub) pattern is a bracket of some sort. Push all the alternative states onto the list, and find out where the end is. This makes is possible to use this function recursively, when we want to stop at a @@ -323,7 +346,7 @@ move back, and set up each alternative a a backward assertion. In that case, we have to find out the maximum amount to move back, and set up each alternative appropriately. */ -if (this_start_code[1+LINK_SIZE] == OP_REVERSE) +if (*first_op == OP_REVERSE) { int max_back = 0; int gone_back; @@ -405,10 +428,13 @@ else else { + int length = 1 + LINK_SIZE + + ((*this_start_code == OP_CBRA || *this_start_code == OP_SCBRA)? 2:0); do { - ADD_NEW(end_code - start_code + 1 + LINK_SIZE, 0); + ADD_NEW(end_code - start_code + length, 0); end_code += GET(end_code, 1); + length = 1 + LINK_SIZE; } while (*end_code == OP_ALT); } @@ -461,7 +487,7 @@ for (;;) if (ptr < end_subject) { - clen = 1; + clen = 1; /* Number of bytes in the character */ #ifdef SUPPORT_UTF8 if (utf8) { GETCHARLEN(c, ptr, clen); } else #endif /* SUPPORT_UTF8 */ @@ -469,8 +495,8 @@ for (;;) } else { - clen = 0; /* At end subject */ - c = -1; + clen = 0; /* This indicates the end of the subject */ + c = NOTACHAR; /* This value should never actually be used */ } /* Scan up the active states and act on each one. The result of an action @@ -484,11 +510,13 @@ for (;;) const uschar *code; int state_offset = current_state->offset; int count, codevalue; +#ifdef SUPPORT_UCP int chartype, script; +#endif #ifdef DEBUG printf ("%.*sProcessing state %d c=", rlevel*2-2, SP, state_offset); - if (c < 0) printf("-1\n"); + if (clen == 0) printf("EOL\n"); else if (c > 32 && c < 127) printf("'%c'\n", c); else printf("0x%02x\n", c); #endif @@ -532,7 +560,6 @@ for (;;) code = start_code + state_offset; codevalue = *code; - if (codevalue >= OP_BRA) codevalue = OP_BRA; /* All brackets are equal */ /* If this opcode is followed by an inline character, load it. It is tempting to test for the presence of a subject character here, but that @@ -540,10 +567,10 @@ for (;;) permitted. We also use this mechanism for opcodes such as OP_TYPEPLUS that take an - argument that is not a data character - but is always one byte long. - Unfortunately, we have to take special action to deal with \P, \p, and - \X in this case. To keep the other cases fast, convert these ones to new - opcodes. */ + argument that is not a data character - but is always one byte long. We + have to take special action to deal with \P, \p, \H, \h, \V, \v and \X in + this case. To keep the other cases fast, convert these ones to new opcodes. + */ if (coptable[codevalue] > 0) { @@ -554,15 +581,25 @@ for (;;) d = code[coptable[codevalue]]; if (codevalue >= OP_TYPESTAR) { - if (d == OP_ANYBYTE) return PCRE_ERROR_DFA_UITEM; - if (d >= OP_NOTPROP) - codevalue += (d == OP_EXTUNI)? OP_EXTUNI_EXTRA : OP_PROP_EXTRA; + switch(d) + { + case OP_ANYBYTE: return PCRE_ERROR_DFA_UITEM; + case OP_NOTPROP: + case OP_PROP: codevalue += OP_PROP_EXTRA; break; + case OP_ANYNL: codevalue += OP_ANYNL_EXTRA; break; + case OP_EXTUNI: codevalue += OP_EXTUNI_EXTRA; break; + case OP_NOT_HSPACE: + case OP_HSPACE: codevalue += OP_HSPACE_EXTRA; break; + case OP_NOT_VSPACE: + case OP_VSPACE: codevalue += OP_VSPACE_EXTRA; break; + default: break; + } } } else { dlen = 0; /* Not strictly necessary, but compilers moan */ - d = -1; /* if these variables are not set. */ + d = NOTACHAR; /* if these variables are not set. */ } @@ -624,6 +661,7 @@ for (;;) /*-----------------------------------------------------------------*/ case OP_BRA: + case OP_SBRA: do { ADD_ACTIVE(code - start_code + 1 + LINK_SIZE, 0); @@ -633,6 +671,18 @@ for (;;) break; /*-----------------------------------------------------------------*/ + case OP_CBRA: + case OP_SCBRA: + ADD_ACTIVE(code - start_code + 3 + LINK_SIZE, 0); + code += GET(code, 1); + while (*code == OP_ALT) + { + ADD_ACTIVE(code - start_code + 1 + LINK_SIZE, 0); + code += GET(code, 1); + } + break; + + /*-----------------------------------------------------------------*/ case OP_BRAZERO: case OP_BRAMINZERO: ADD_ACTIVE(state_offset + 1, 0); @@ -642,17 +692,11 @@ for (;;) break; /*-----------------------------------------------------------------*/ - case OP_BRANUMBER: - ADD_ACTIVE(state_offset + 1 + LINK_SIZE, 0); - break; - - /*-----------------------------------------------------------------*/ case OP_CIRC: if ((ptr == start_subject && (md->moptions & PCRE_NOTBOL) == 0) || ((ims & PCRE_MULTILINE) != 0 && - ptr >= start_subject + md->nllen && ptr != end_subject && - IS_NEWLINE(ptr - md->nllen))) + WAS_NEWLINE(ptr))) { ADD_ACTIVE(state_offset + 1, 0); } break; @@ -686,16 +730,13 @@ for (;;) /*-----------------------------------------------------------------*/ case OP_ANY: - if (clen > 0 && ((ims & PCRE_DOTALL) != 0 || - ptr > end_subject - md->nllen || - !IS_NEWLINE(ptr))) + if (clen > 0 && ((ims & PCRE_DOTALL) != 0 || !IS_NEWLINE(ptr))) { ADD_NEW(state_offset + 1, 0); } break; /*-----------------------------------------------------------------*/ case OP_EODN: - if (clen == 0 || - (ptr == end_subject - md->nllen && IS_NEWLINE(ptr))) + if (clen == 0 || (IS_NEWLINE(ptr) && ptr == end_subject - md->nllen)) { ADD_ACTIVE(state_offset + 1, 0); } break; @@ -704,13 +745,12 @@ for (;;) if ((md->moptions & PCRE_NOTEOL) == 0) { if (clen == 0 || - (ptr <= end_subject - md->nllen && IS_NEWLINE(ptr) && + (IS_NEWLINE(ptr) && ((ims & PCRE_MULTILINE) != 0 || ptr == end_subject - md->nllen) )) { ADD_ACTIVE(state_offset + 1, 0); } } - else if ((ims & PCRE_MULTILINE) != 0 && - ptr <= end_subject - md->nllen && IS_NEWLINE(ptr)) + else if ((ims & PCRE_MULTILINE) != 0 && IS_NEWLINE(ptr)) { ADD_ACTIVE(state_offset + 1, 0); } break; @@ -759,13 +799,12 @@ for (;;) break; -#ifdef SUPPORT_UCP - /*-----------------------------------------------------------------*/ /* Check the next character by Unicode property. We will get here only if the support is in the binary; otherwise a compile-time error occurs. */ +#ifdef SUPPORT_UCP case OP_PROP: case OP_NOTPROP: if (clen > 0) @@ -816,6 +855,7 @@ for (;;) case OP_TYPEPLUS: case OP_TYPEMINPLUS: + case OP_TYPEPOSPLUS: count = current_state->count; /* Already matched */ if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); } if (clen > 0) @@ -824,11 +864,15 @@ for (;;) (c < 256 && (d != OP_ANY || (ims & PCRE_DOTALL) != 0 || - ptr > end_subject - md->nllen || !IS_NEWLINE(ptr) ) && ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) { + if (count > 0 && codevalue == OP_TYPEPOSPLUS) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } count++; ADD_NEW(state_offset, count); } @@ -838,6 +882,7 @@ for (;;) /*-----------------------------------------------------------------*/ case OP_TYPEQUERY: case OP_TYPEMINQUERY: + case OP_TYPEPOSQUERY: ADD_ACTIVE(state_offset + 2, 0); if (clen > 0) { @@ -845,11 +890,15 @@ for (;;) (c < 256 && (d != OP_ANY || (ims & PCRE_DOTALL) != 0 || - ptr > end_subject - md->nllen || !IS_NEWLINE(ptr) ) && ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) { + if (codevalue == OP_TYPEPOSQUERY) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } ADD_NEW(state_offset + 2, 0); } } @@ -858,6 +907,7 @@ for (;;) /*-----------------------------------------------------------------*/ case OP_TYPESTAR: case OP_TYPEMINSTAR: + case OP_TYPEPOSSTAR: ADD_ACTIVE(state_offset + 2, 0); if (clen > 0) { @@ -865,11 +915,15 @@ for (;;) (c < 256 && (d != OP_ANY || (ims & PCRE_DOTALL) != 0 || - ptr > end_subject - md->nllen || !IS_NEWLINE(ptr) ) && ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) { + if (codevalue == OP_TYPEPOSSTAR) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } ADD_NEW(state_offset, 0); } } @@ -877,10 +931,30 @@ for (;;) /*-----------------------------------------------------------------*/ case OP_TYPEEXACT: + count = current_state->count; /* Number already matched */ + if (clen > 0) + { + if ((c >= 256 && d != OP_DIGIT && d != OP_WHITESPACE && d != OP_WORDCHAR) || + (c < 256 && + (d != OP_ANY || + (ims & PCRE_DOTALL) != 0 || + !IS_NEWLINE(ptr) + ) && + ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) + { + if (++count >= GET2(code, 1)) + { ADD_NEW(state_offset + 4, 0); } + else + { ADD_NEW(state_offset, count); } + } + } + break; + + /*-----------------------------------------------------------------*/ case OP_TYPEUPTO: case OP_TYPEMINUPTO: - if (codevalue != OP_TYPEEXACT) - { ADD_ACTIVE(state_offset + 4, 0); } + case OP_TYPEPOSUPTO: + ADD_ACTIVE(state_offset + 4, 0); count = current_state->count; /* Number already matched */ if (clen > 0) { @@ -888,11 +962,15 @@ for (;;) (c < 256 && (d != OP_ANY || (ims & PCRE_DOTALL) != 0 || - ptr > end_subject - md->nllen || !IS_NEWLINE(ptr) ) && ((ctypes[c] & toptable1[d]) ^ toptable2[d]) != 0)) { + if (codevalue == OP_TYPEPOSUPTO) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } if (++count >= GET2(code, 1)) { ADD_NEW(state_offset + 4, 0); } else @@ -903,13 +981,14 @@ for (;;) /* ========================================================================== */ /* These are virtual opcodes that are used when something like - OP_TYPEPLUS has OP_PROP, OP_NOTPROP, or OP_EXTUNI as its argument. It - keeps the code above fast for the other cases. The argument is in the - d variable. */ + OP_TYPEPLUS has OP_PROP, OP_NOTPROP, OP_ANYNL, or OP_EXTUNI as its + argument. It keeps the code above fast for the other cases. The argument + is in the d variable. */ #ifdef SUPPORT_UCP case OP_PROP_EXTRA + OP_TYPEPLUS: case OP_PROP_EXTRA + OP_TYPEMINPLUS: + case OP_PROP_EXTRA + OP_TYPEPOSPLUS: count = current_state->count; /* Already matched */ if (count > 0) { ADD_ACTIVE(state_offset + 4, 0); } if (clen > 0) @@ -945,19 +1024,34 @@ for (;;) break; } - if (OK == (d == OP_PROP)) { count++; ADD_NEW(state_offset, count); } + if (OK == (d == OP_PROP)) + { + if (count > 0 && codevalue == OP_PROP_EXTRA + OP_TYPEPOSPLUS) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } + count++; + ADD_NEW(state_offset, count); + } } break; /*-----------------------------------------------------------------*/ case OP_EXTUNI_EXTRA + OP_TYPEPLUS: case OP_EXTUNI_EXTRA + OP_TYPEMINPLUS: + case OP_EXTUNI_EXTRA + OP_TYPEPOSPLUS: count = current_state->count; /* Already matched */ if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); } if (clen > 0 && _pcre_ucp_findprop(c, &chartype, &script) != ucp_M) { const uschar *nptr = ptr + clen; int ncount = 0; + if (count > 0 && codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSPLUS) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } while (nptr < end_subject) { int nd; @@ -971,15 +1065,149 @@ for (;;) ADD_NEW_DATA(-state_offset, count, ncount); } break; +#endif /*-----------------------------------------------------------------*/ + case OP_ANYNL_EXTRA + OP_TYPEPLUS: + case OP_ANYNL_EXTRA + OP_TYPEMINPLUS: + case OP_ANYNL_EXTRA + OP_TYPEPOSPLUS: + count = current_state->count; /* Already matched */ + if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); } + if (clen > 0) + { + int ncount = 0; + switch (c) + { + case 0x000b: + case 0x000c: + case 0x0085: + case 0x2028: + case 0x2029: + if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break; + goto ANYNL01; + + case 0x000d: + if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1; + /* Fall through */ + + ANYNL01: + case 0x000a: + if (count > 0 && codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSPLUS) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } + count++; + ADD_NEW_DATA(-state_offset, count, ncount); + break; + + default: + break; + } + } + break; + + /*-----------------------------------------------------------------*/ + case OP_VSPACE_EXTRA + OP_TYPEPLUS: + case OP_VSPACE_EXTRA + OP_TYPEMINPLUS: + case OP_VSPACE_EXTRA + OP_TYPEPOSPLUS: + count = current_state->count; /* Already matched */ + if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); } + if (clen > 0) + { + BOOL OK; + switch (c) + { + case 0x000a: + case 0x000b: + case 0x000c: + case 0x000d: + case 0x0085: + case 0x2028: + case 0x2029: + OK = TRUE; + break; + + default: + OK = FALSE; + break; + } + + if (OK == (d == OP_VSPACE)) + { + if (count > 0 && codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSPLUS) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } + count++; + ADD_NEW_DATA(-state_offset, count, 0); + } + } + break; + + /*-----------------------------------------------------------------*/ + case OP_HSPACE_EXTRA + OP_TYPEPLUS: + case OP_HSPACE_EXTRA + OP_TYPEMINPLUS: + case OP_HSPACE_EXTRA + OP_TYPEPOSPLUS: + count = current_state->count; /* Already matched */ + if (count > 0) { ADD_ACTIVE(state_offset + 2, 0); } + if (clen > 0) + { + BOOL OK; + switch (c) + { + case 0x09: /* HT */ + case 0x20: /* SPACE */ + case 0xa0: /* NBSP */ + case 0x1680: /* OGHAM SPACE MARK */ + case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ + case 0x2000: /* EN QUAD */ + case 0x2001: /* EM QUAD */ + case 0x2002: /* EN SPACE */ + case 0x2003: /* EM SPACE */ + case 0x2004: /* THREE-PER-EM SPACE */ + case 0x2005: /* FOUR-PER-EM SPACE */ + case 0x2006: /* SIX-PER-EM SPACE */ + case 0x2007: /* FIGURE SPACE */ + case 0x2008: /* PUNCTUATION SPACE */ + case 0x2009: /* THIN SPACE */ + case 0x200A: /* HAIR SPACE */ + case 0x202f: /* NARROW NO-BREAK SPACE */ + case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ + case 0x3000: /* IDEOGRAPHIC SPACE */ + OK = TRUE; + break; + + default: + OK = FALSE; + break; + } + + if (OK == (d == OP_HSPACE)) + { + if (count > 0 && codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSPLUS) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } + count++; + ADD_NEW_DATA(-state_offset, count, 0); + } + } + break; + + /*-----------------------------------------------------------------*/ +#ifdef SUPPORT_UCP case OP_PROP_EXTRA + OP_TYPEQUERY: case OP_PROP_EXTRA + OP_TYPEMINQUERY: + case OP_PROP_EXTRA + OP_TYPEPOSQUERY: count = 4; goto QS1; case OP_PROP_EXTRA + OP_TYPESTAR: case OP_PROP_EXTRA + OP_TYPEMINSTAR: + case OP_PROP_EXTRA + OP_TYPEPOSSTAR: count = 0; QS1: @@ -1018,18 +1246,29 @@ for (;;) break; } - if (OK == (d == OP_PROP)) { ADD_NEW(state_offset + count, 0); } + if (OK == (d == OP_PROP)) + { + if (codevalue == OP_PROP_EXTRA + OP_TYPEPOSSTAR || + codevalue == OP_PROP_EXTRA + OP_TYPEPOSQUERY) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } + ADD_NEW(state_offset + count, 0); + } } break; /*-----------------------------------------------------------------*/ case OP_EXTUNI_EXTRA + OP_TYPEQUERY: case OP_EXTUNI_EXTRA + OP_TYPEMINQUERY: + case OP_EXTUNI_EXTRA + OP_TYPEPOSQUERY: count = 2; goto QS2; case OP_EXTUNI_EXTRA + OP_TYPESTAR: case OP_EXTUNI_EXTRA + OP_TYPEMINSTAR: + case OP_EXTUNI_EXTRA + OP_TYPEPOSSTAR: count = 0; QS2: @@ -1039,6 +1278,12 @@ for (;;) { const uschar *nptr = ptr + clen; int ncount = 0; + if (codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSSTAR || + codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSQUERY) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } while (nptr < end_subject) { int nd; @@ -1051,11 +1296,167 @@ for (;;) ADD_NEW_DATA(-(state_offset + count), 0, ncount); } break; +#endif /*-----------------------------------------------------------------*/ + case OP_ANYNL_EXTRA + OP_TYPEQUERY: + case OP_ANYNL_EXTRA + OP_TYPEMINQUERY: + case OP_ANYNL_EXTRA + OP_TYPEPOSQUERY: + count = 2; + goto QS3; + + case OP_ANYNL_EXTRA + OP_TYPESTAR: + case OP_ANYNL_EXTRA + OP_TYPEMINSTAR: + case OP_ANYNL_EXTRA + OP_TYPEPOSSTAR: + count = 0; + + QS3: + ADD_ACTIVE(state_offset + 2, 0); + if (clen > 0) + { + int ncount = 0; + switch (c) + { + case 0x000b: + case 0x000c: + case 0x0085: + case 0x2028: + case 0x2029: + if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break; + goto ANYNL02; + + case 0x000d: + if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1; + /* Fall through */ + + ANYNL02: + case 0x000a: + if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSSTAR || + codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSQUERY) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } + ADD_NEW_DATA(-(state_offset + count), 0, ncount); + break; + + default: + break; + } + } + break; + + /*-----------------------------------------------------------------*/ + case OP_VSPACE_EXTRA + OP_TYPEQUERY: + case OP_VSPACE_EXTRA + OP_TYPEMINQUERY: + case OP_VSPACE_EXTRA + OP_TYPEPOSQUERY: + count = 2; + goto QS4; + + case OP_VSPACE_EXTRA + OP_TYPESTAR: + case OP_VSPACE_EXTRA + OP_TYPEMINSTAR: + case OP_VSPACE_EXTRA + OP_TYPEPOSSTAR: + count = 0; + + QS4: + ADD_ACTIVE(state_offset + 2, 0); + if (clen > 0) + { + BOOL OK; + switch (c) + { + case 0x000a: + case 0x000b: + case 0x000c: + case 0x000d: + case 0x0085: + case 0x2028: + case 0x2029: + OK = TRUE; + break; + + default: + OK = FALSE; + break; + } + if (OK == (d == OP_VSPACE)) + { + if (codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSSTAR || + codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSQUERY) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } + ADD_NEW_DATA(-(state_offset + count), 0, 0); + } + } + break; + + /*-----------------------------------------------------------------*/ + case OP_HSPACE_EXTRA + OP_TYPEQUERY: + case OP_HSPACE_EXTRA + OP_TYPEMINQUERY: + case OP_HSPACE_EXTRA + OP_TYPEPOSQUERY: + count = 2; + goto QS5; + + case OP_HSPACE_EXTRA + OP_TYPESTAR: + case OP_HSPACE_EXTRA + OP_TYPEMINSTAR: + case OP_HSPACE_EXTRA + OP_TYPEPOSSTAR: + count = 0; + + QS5: + ADD_ACTIVE(state_offset + 2, 0); + if (clen > 0) + { + BOOL OK; + switch (c) + { + case 0x09: /* HT */ + case 0x20: /* SPACE */ + case 0xa0: /* NBSP */ + case 0x1680: /* OGHAM SPACE MARK */ + case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ + case 0x2000: /* EN QUAD */ + case 0x2001: /* EM QUAD */ + case 0x2002: /* EN SPACE */ + case 0x2003: /* EM SPACE */ + case 0x2004: /* THREE-PER-EM SPACE */ + case 0x2005: /* FOUR-PER-EM SPACE */ + case 0x2006: /* SIX-PER-EM SPACE */ + case 0x2007: /* FIGURE SPACE */ + case 0x2008: /* PUNCTUATION SPACE */ + case 0x2009: /* THIN SPACE */ + case 0x200A: /* HAIR SPACE */ + case 0x202f: /* NARROW NO-BREAK SPACE */ + case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ + case 0x3000: /* IDEOGRAPHIC SPACE */ + OK = TRUE; + break; + + default: + OK = FALSE; + break; + } + + if (OK == (d == OP_HSPACE)) + { + if (codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSSTAR || + codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSQUERY) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } + ADD_NEW_DATA(-(state_offset + count), 0, 0); + } + } + break; + + /*-----------------------------------------------------------------*/ +#ifdef SUPPORT_UCP case OP_PROP_EXTRA + OP_TYPEEXACT: case OP_PROP_EXTRA + OP_TYPEUPTO: case OP_PROP_EXTRA + OP_TYPEMINUPTO: + case OP_PROP_EXTRA + OP_TYPEPOSUPTO: if (codevalue != OP_PROP_EXTRA + OP_TYPEEXACT) { ADD_ACTIVE(state_offset + 6, 0); } count = current_state->count; /* Number already matched */ @@ -1094,6 +1495,11 @@ for (;;) if (OK == (d == OP_PROP)) { + if (codevalue == OP_PROP_EXTRA + OP_TYPEPOSUPTO) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } if (++count >= GET2(code, 1)) { ADD_NEW(state_offset + 6, 0); } else @@ -1106,6 +1512,7 @@ for (;;) case OP_EXTUNI_EXTRA + OP_TYPEEXACT: case OP_EXTUNI_EXTRA + OP_TYPEUPTO: case OP_EXTUNI_EXTRA + OP_TYPEMINUPTO: + case OP_EXTUNI_EXTRA + OP_TYPEPOSUPTO: if (codevalue != OP_EXTUNI_EXTRA + OP_TYPEEXACT) { ADD_ACTIVE(state_offset + 4, 0); } count = current_state->count; /* Number already matched */ @@ -1113,6 +1520,11 @@ for (;;) { const uschar *nptr = ptr + clen; int ncount = 0; + if (codevalue == OP_EXTUNI_EXTRA + OP_TYPEPOSUPTO) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } while (nptr < end_subject) { int nd; @@ -1130,6 +1542,147 @@ for (;;) break; #endif + /*-----------------------------------------------------------------*/ + case OP_ANYNL_EXTRA + OP_TYPEEXACT: + case OP_ANYNL_EXTRA + OP_TYPEUPTO: + case OP_ANYNL_EXTRA + OP_TYPEMINUPTO: + case OP_ANYNL_EXTRA + OP_TYPEPOSUPTO: + if (codevalue != OP_ANYNL_EXTRA + OP_TYPEEXACT) + { ADD_ACTIVE(state_offset + 4, 0); } + count = current_state->count; /* Number already matched */ + if (clen > 0) + { + int ncount = 0; + switch (c) + { + case 0x000b: + case 0x000c: + case 0x0085: + case 0x2028: + case 0x2029: + if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break; + goto ANYNL03; + + case 0x000d: + if (ptr + 1 < end_subject && ptr[1] == 0x0a) ncount = 1; + /* Fall through */ + + ANYNL03: + case 0x000a: + if (codevalue == OP_ANYNL_EXTRA + OP_TYPEPOSUPTO) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } + if (++count >= GET2(code, 1)) + { ADD_NEW_DATA(-(state_offset + 4), 0, ncount); } + else + { ADD_NEW_DATA(-state_offset, count, ncount); } + break; + + default: + break; + } + } + break; + + /*-----------------------------------------------------------------*/ + case OP_VSPACE_EXTRA + OP_TYPEEXACT: + case OP_VSPACE_EXTRA + OP_TYPEUPTO: + case OP_VSPACE_EXTRA + OP_TYPEMINUPTO: + case OP_VSPACE_EXTRA + OP_TYPEPOSUPTO: + if (codevalue != OP_VSPACE_EXTRA + OP_TYPEEXACT) + { ADD_ACTIVE(state_offset + 4, 0); } + count = current_state->count; /* Number already matched */ + if (clen > 0) + { + BOOL OK; + switch (c) + { + case 0x000a: + case 0x000b: + case 0x000c: + case 0x000d: + case 0x0085: + case 0x2028: + case 0x2029: + OK = TRUE; + break; + + default: + OK = FALSE; + } + + if (OK == (d == OP_VSPACE)) + { + if (codevalue == OP_VSPACE_EXTRA + OP_TYPEPOSUPTO) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } + if (++count >= GET2(code, 1)) + { ADD_NEW_DATA(-(state_offset + 4), 0, 0); } + else + { ADD_NEW_DATA(-state_offset, count, 0); } + } + } + break; + + /*-----------------------------------------------------------------*/ + case OP_HSPACE_EXTRA + OP_TYPEEXACT: + case OP_HSPACE_EXTRA + OP_TYPEUPTO: + case OP_HSPACE_EXTRA + OP_TYPEMINUPTO: + case OP_HSPACE_EXTRA + OP_TYPEPOSUPTO: + if (codevalue != OP_HSPACE_EXTRA + OP_TYPEEXACT) + { ADD_ACTIVE(state_offset + 4, 0); } + count = current_state->count; /* Number already matched */ + if (clen > 0) + { + BOOL OK; + switch (c) + { + case 0x09: /* HT */ + case 0x20: /* SPACE */ + case 0xa0: /* NBSP */ + case 0x1680: /* OGHAM SPACE MARK */ + case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ + case 0x2000: /* EN QUAD */ + case 0x2001: /* EM QUAD */ + case 0x2002: /* EN SPACE */ + case 0x2003: /* EM SPACE */ + case 0x2004: /* THREE-PER-EM SPACE */ + case 0x2005: /* FOUR-PER-EM SPACE */ + case 0x2006: /* SIX-PER-EM SPACE */ + case 0x2007: /* FIGURE SPACE */ + case 0x2008: /* PUNCTUATION SPACE */ + case 0x2009: /* THIN SPACE */ + case 0x200A: /* HAIR SPACE */ + case 0x202f: /* NARROW NO-BREAK SPACE */ + case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ + case 0x3000: /* IDEOGRAPHIC SPACE */ + OK = TRUE; + break; + + default: + OK = FALSE; + break; + } + + if (OK == (d == OP_HSPACE)) + { + if (codevalue == OP_HSPACE_EXTRA + OP_TYPEPOSUPTO) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } + if (++count >= GET2(code, 1)) + { ADD_NEW_DATA(-(state_offset + 4), 0, 0); } + else + { ADD_NEW_DATA(-state_offset, count, 0); } + } + } + break; + /* ========================================================================== */ /* These opcodes are followed by a character that is usually compared to the current subject character; it is loaded into d. We still get @@ -1150,7 +1703,7 @@ for (;;) { if (c == d) { ADD_NEW(state_offset + dlen + 1, 0); } else { - int othercase; + unsigned int othercase; if (c < 128) othercase = fcc[c]; else /* If we have Unicode property support, we can use it to test the @@ -1159,7 +1712,7 @@ for (;;) #ifdef SUPPORT_UCP othercase = _pcre_ucp_othercase(c); #else - othercase = -1; + othercase = NOTACHAR; #endif if (d == othercase) { ADD_NEW(state_offset + dlen + 1, 0); } @@ -1200,6 +1753,134 @@ for (;;) #endif /*-----------------------------------------------------------------*/ + /* This is a tricky like EXTUNI because it too can match more than one + character (when CR is followed by LF). In this case, set up a negative + state to wait for one character to pass before continuing. */ + + case OP_ANYNL: + if (clen > 0) switch(c) + { + case 0x000b: + case 0x000c: + case 0x0085: + case 0x2028: + case 0x2029: + if ((md->moptions & PCRE_BSR_ANYCRLF) != 0) break; + + case 0x000a: + ADD_NEW(state_offset + 1, 0); + break; + + case 0x000d: + if (ptr + 1 < end_subject && ptr[1] == 0x0a) + { + ADD_NEW_DATA(-(state_offset + 1), 0, 1); + } + else + { + ADD_NEW(state_offset + 1, 0); + } + break; + } + break; + + /*-----------------------------------------------------------------*/ + case OP_NOT_VSPACE: + if (clen > 0) switch(c) + { + case 0x000a: + case 0x000b: + case 0x000c: + case 0x000d: + case 0x0085: + case 0x2028: + case 0x2029: + break; + + default: + ADD_NEW(state_offset + 1, 0); + break; + } + break; + + /*-----------------------------------------------------------------*/ + case OP_VSPACE: + if (clen > 0) switch(c) + { + case 0x000a: + case 0x000b: + case 0x000c: + case 0x000d: + case 0x0085: + case 0x2028: + case 0x2029: + ADD_NEW(state_offset + 1, 0); + break; + + default: break; + } + break; + + /*-----------------------------------------------------------------*/ + case OP_NOT_HSPACE: + if (clen > 0) switch(c) + { + case 0x09: /* HT */ + case 0x20: /* SPACE */ + case 0xa0: /* NBSP */ + case 0x1680: /* OGHAM SPACE MARK */ + case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ + case 0x2000: /* EN QUAD */ + case 0x2001: /* EM QUAD */ + case 0x2002: /* EN SPACE */ + case 0x2003: /* EM SPACE */ + case 0x2004: /* THREE-PER-EM SPACE */ + case 0x2005: /* FOUR-PER-EM SPACE */ + case 0x2006: /* SIX-PER-EM SPACE */ + case 0x2007: /* FIGURE SPACE */ + case 0x2008: /* PUNCTUATION SPACE */ + case 0x2009: /* THIN SPACE */ + case 0x200A: /* HAIR SPACE */ + case 0x202f: /* NARROW NO-BREAK SPACE */ + case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ + case 0x3000: /* IDEOGRAPHIC SPACE */ + break; + + default: + ADD_NEW(state_offset + 1, 0); + break; + } + break; + + /*-----------------------------------------------------------------*/ + case OP_HSPACE: + if (clen > 0) switch(c) + { + case 0x09: /* HT */ + case 0x20: /* SPACE */ + case 0xa0: /* NBSP */ + case 0x1680: /* OGHAM SPACE MARK */ + case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ + case 0x2000: /* EN QUAD */ + case 0x2001: /* EM QUAD */ + case 0x2002: /* EN SPACE */ + case 0x2003: /* EM SPACE */ + case 0x2004: /* THREE-PER-EM SPACE */ + case 0x2005: /* FOUR-PER-EM SPACE */ + case 0x2006: /* SIX-PER-EM SPACE */ + case 0x2007: /* FIGURE SPACE */ + case 0x2008: /* PUNCTUATION SPACE */ + case 0x2009: /* THIN SPACE */ + case 0x200A: /* HAIR SPACE */ + case 0x202f: /* NARROW NO-BREAK SPACE */ + case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ + case 0x3000: /* IDEOGRAPHIC SPACE */ + ADD_NEW(state_offset + 1, 0); + break; + } + break; + + /*-----------------------------------------------------------------*/ /* Match a negated single character. This is only used for one-byte characters, that is, we know that d < 256. The character we are checking (c) can be multibyte. */ @@ -1207,7 +1888,7 @@ for (;;) case OP_NOT: if (clen > 0) { - int otherd = ((ims & PCRE_CASELESS) != 0)? fcc[d] : d; + unsigned int otherd = ((ims & PCRE_CASELESS) != 0)? fcc[d] : d; if (c != d && c != otherd) { ADD_NEW(state_offset + dlen + 1, 0); } } break; @@ -1215,13 +1896,15 @@ for (;;) /*-----------------------------------------------------------------*/ case OP_PLUS: case OP_MINPLUS: + case OP_POSPLUS: case OP_NOTPLUS: case OP_NOTMINPLUS: + case OP_NOTPOSPLUS: count = current_state->count; /* Already matched */ if (count > 0) { ADD_ACTIVE(state_offset + dlen + 1, 0); } if (clen > 0) { - int otherd = -1; + unsigned int otherd = NOTACHAR; if ((ims & PCRE_CASELESS) != 0) { #ifdef SUPPORT_UTF8 @@ -1236,19 +1919,30 @@ for (;;) otherd = fcc[d]; } if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR)) - { count++; ADD_NEW(state_offset, count); } + { + if (count > 0 && + (codevalue == OP_POSPLUS || codevalue == OP_NOTPOSPLUS)) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } + count++; + ADD_NEW(state_offset, count); + } } break; /*-----------------------------------------------------------------*/ case OP_QUERY: case OP_MINQUERY: + case OP_POSQUERY: case OP_NOTQUERY: case OP_NOTMINQUERY: + case OP_NOTPOSQUERY: ADD_ACTIVE(state_offset + dlen + 1, 0); if (clen > 0) { - int otherd = -1; + unsigned int otherd = NOTACHAR; if ((ims & PCRE_CASELESS) != 0) { #ifdef SUPPORT_UTF8 @@ -1263,19 +1957,28 @@ for (;;) otherd = fcc[d]; } if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR)) - { ADD_NEW(state_offset + dlen + 1, 0); } + { + if (codevalue == OP_POSQUERY || codevalue == OP_NOTPOSQUERY) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } + ADD_NEW(state_offset + dlen + 1, 0); + } } break; /*-----------------------------------------------------------------*/ case OP_STAR: case OP_MINSTAR: + case OP_POSSTAR: case OP_NOTSTAR: case OP_NOTMINSTAR: + case OP_NOTPOSSTAR: ADD_ACTIVE(state_offset + dlen + 1, 0); if (clen > 0) { - int otherd = -1; + unsigned int otherd = NOTACHAR; if ((ims & PCRE_CASELESS) != 0) { #ifdef SUPPORT_UTF8 @@ -1290,23 +1993,59 @@ for (;;) otherd = fcc[d]; } if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR)) - { ADD_NEW(state_offset, 0); } + { + if (codevalue == OP_POSSTAR || codevalue == OP_NOTPOSSTAR) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } + ADD_NEW(state_offset, 0); + } } break; /*-----------------------------------------------------------------*/ case OP_EXACT: + case OP_NOTEXACT: + count = current_state->count; /* Number already matched */ + if (clen > 0) + { + unsigned int otherd = NOTACHAR; + if ((ims & PCRE_CASELESS) != 0) + { +#ifdef SUPPORT_UTF8 + if (utf8 && d >= 128) + { +#ifdef SUPPORT_UCP + otherd = _pcre_ucp_othercase(d); +#endif /* SUPPORT_UCP */ + } + else +#endif /* SUPPORT_UTF8 */ + otherd = fcc[d]; + } + if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR)) + { + if (++count >= GET2(code, 1)) + { ADD_NEW(state_offset + dlen + 3, 0); } + else + { ADD_NEW(state_offset, count); } + } + } + break; + + /*-----------------------------------------------------------------*/ case OP_UPTO: case OP_MINUPTO: - case OP_NOTEXACT: + case OP_POSUPTO: case OP_NOTUPTO: case OP_NOTMINUPTO: - if (codevalue != OP_EXACT && codevalue != OP_NOTEXACT) - { ADD_ACTIVE(state_offset + dlen + 3, 0); } + case OP_NOTPOSUPTO: + ADD_ACTIVE(state_offset + dlen + 3, 0); count = current_state->count; /* Number already matched */ if (clen > 0) { - int otherd = -1; + unsigned int otherd = NOTACHAR; if ((ims & PCRE_CASELESS) != 0) { #ifdef SUPPORT_UTF8 @@ -1322,6 +2061,11 @@ for (;;) } if ((c == d || c == otherd) == (codevalue < OP_NOTSTAR)) { + if (codevalue == OP_POSUPTO || codevalue == OP_NOTPOSUPTO) + { + active_count--; /* Remove non-match possibility */ + next_active_state--; + } if (++count >= GET2(code, 1)) { ADD_NEW(state_offset + dlen + 3, 0); } else @@ -1450,18 +2194,31 @@ for (;;) /*-----------------------------------------------------------------*/ case OP_COND: + case OP_SCOND: { int local_offsets[1000]; int local_workspace[1000]; int condcode = code[LINK_SIZE+1]; - /* The only supported version of OP_CREF is for the value 0xffff, which - means "test if in a recursion". */ + /* Back reference conditions are not supported */ - if (condcode == OP_CREF) + if (condcode == OP_CREF) return PCRE_ERROR_DFA_UCOND; + + /* The DEFINE condition is always false */ + + if (condcode == OP_DEF) { + ADD_ACTIVE(state_offset + GET(code, 1) + LINK_SIZE + 1, 0); + } + + /* The only supported version of OP_RREF is for the value RREF_ANY, + which means "test if in any recursion". We can't test for specifically + recursed groups. */ + + else if (condcode == OP_RREF) + { int value = GET2(code, LINK_SIZE+2); - if (value != 0xffff) return PCRE_ERROR_DFA_UCOND; + if (value != RREF_ANY) return PCRE_ERROR_DFA_UCOND; if (recursing > 0) { ADD_ACTIVE(state_offset + LINK_SIZE + 4, 0); } else { ADD_ACTIVE(state_offset + GET(code, 1) + LINK_SIZE + 1, 0); } } @@ -1730,7 +2487,7 @@ Arguments: Arguments: argument_re points to the compiled expression - extra_data points to extra data or is NULL (not currently used) + extra_data points to extra data or is NULL subject points to the subject string length length of subject string (may contain binary zeros) start_offset where to start in the subject string @@ -1746,7 +2503,7 @@ Returns: > 0 => number of match < -1 => some kind of unexpected problem */ -PCRE_DATA_SCOPE int +PCRE_EXP_DEFN int pcre_dfa_exec(const pcre *argument_re, const pcre_extra *extra_data, const char *subject, int length, int start_offset, int options, int *offsets, int offsetcount, int *workspace, int wscount) @@ -1836,29 +2593,56 @@ md->poptions = re->options; md->moptions = options; md->poptions = re->options; -/* Handle different types of newline. The two bits give four cases. If nothing -is set at run time, whatever was used at compile time applies. */ +/* If the BSR option is not set at match time, copy what was set +at compile time. */ -switch ((((options & PCRE_NEWLINE_CRLF) == 0)? re->options : options) & - PCRE_NEWLINE_CRLF) +if ((md->moptions & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) == 0) { - default: newline = NEWLINE; break; /* Compile-time default */ + if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0) + md->moptions |= re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE); +#ifdef BSR_ANYCRLF + else md->moptions |= PCRE_BSR_ANYCRLF; +#endif + } + +/* 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 : (pcre_uint32)options) & + PCRE_NEWLINE_BITS) + { + case 0: newline = NEWLINE; break; /* Compile-time default */ case PCRE_NEWLINE_CR: newline = '\r'; break; case PCRE_NEWLINE_LF: newline = '\n'; break; 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 > 255) +if (newline == -2) { - md->nllen = 2; - md->nl[0] = (newline >> 8) & 255; - md->nl[1] = newline & 255; + md->nltype = NLTYPE_ANYCRLF; } +else if (newline < 0) + { + md->nltype = NLTYPE_ANY; + } else { - md->nllen = 1; - md->nl[0] = newline; + md->nltype = NLTYPE_FIXED; + if (newline > 255) + { + md->nllen = 2; + md->nl[0] = (newline >> 8) & 255; + md->nl[1] = newline & 255; + } + else + { + md->nllen = 1; + md->nl[0] = newline; + } } /* Check a UTF-8 string if required. Unfortunately there's no way of passing @@ -1891,7 +2675,7 @@ lcc = md->tables + lcc_offset; used in a loop when finding where to start. */ lcc = md->tables + lcc_offset; -startline = (re->options & PCRE_STARTLINE) != 0; +startline = (re->flags & PCRE_STARTLINE) != 0; firstline = (re->options & PCRE_FIRSTLINE) != 0; /* Set up the first character to match, if available. The first_byte value is @@ -1902,7 +2686,7 @@ if (!anchored) if (!anchored) { - if ((re->options & PCRE_FIRSTSET) != 0) + if ((re->flags & PCRE_FIRSTSET) != 0) { first_byte = re->first_byte & 255; if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE) @@ -1919,7 +2703,7 @@ character" set. */ /* For anchored or unanchored matches, there may be a "last known required character" set. */ -if ((re->options & PCRE_REQCHSET) != 0) +if ((re->flags & PCRE_REQCHSET) != 0) { req_byte = re->req_byte & 255; req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0; @@ -1948,7 +2732,7 @@ for (;;) if (firstline) { const uschar *t = current_subject; - while (t <= save_end_subject - md->nllen && !IS_NEWLINE(t)) t++; + while (t < md->end_subject && !IS_NEWLINE(t)) t++; end_subject = t; } @@ -1967,12 +2751,20 @@ for (;;) else if (startline) { - if (current_subject > md->start_subject + md->nllen + - start_offset) + if (current_subject > md->start_subject + start_offset) { - while (current_subject <= end_subject && - !IS_NEWLINE(current_subject - md->nllen)) + while (current_subject <= end_subject && !WAS_NEWLINE(current_subject)) current_subject++; + + /* 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 (current_subject[-1] == '\r' && + (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) && + current_subject < end_subject && + *current_subject == '\n') + current_subject++; } } @@ -2072,9 +2864,7 @@ for (;;) /* Advance to the next subject character unless we are at the end of a line and firstline is set. */ - if (firstline && - current_subject <= end_subject - md->nllen && - IS_NEWLINE(current_subject)) break; + if (firstline && IS_NEWLINE(current_subject)) break; current_subject++; if (utf8) { @@ -2082,8 +2872,22 @@ for (;;) current_subject++; } if (current_subject > end_subject) break; - } + /* If we have just passed a CR and we are now at a LF, and the pattern does + not contain any explicit matches for \r or \n, and the newline option is CRLF + or ANY or ANYCRLF, advance the match position by one more character. */ + + if (current_subject[-1] == '\r' && + current_subject < end_subject && + *current_subject == '\n' && + (re->flags & PCRE_HASCRORLF) == 0 && + (md->nltype == NLTYPE_ANY || + md->nltype == NLTYPE_ANYCRLF || + md->nllen == 2)) + current_subject++; + + } /* "Bumpalong" loop */ + return PCRE_ERROR_NOMATCH; } ============================================================ --- pcre/pcre_exec.c 67b6e933c1bf48822748163ca104e433a79208b5 +++ pcre/pcre_exec.c 15e9af69dc4d3e1a33cf3b7b8a2906d6ca426dc9 @@ -6,7 +6,7 @@ and semantics are as close as possible t and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel - Copyright (c) 1997-2006 University of Cambridge + Copyright (c) 1997-2007 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -42,25 +42,23 @@ possible. There are also some static sup pattern matching using an NFA algorithm, trying to mimic Perl as closely as possible. There are also some static supporting functions. */ -#define NLBLOCK md /* The block containing newline information */ +#include "pcre_config.h" + +#define NLBLOCK md /* Block containing newline information */ +#define PSSTART start_subject /* Field containing processed string start */ +#define PSEND end_subject /* Field containing processed string end */ + #include "pcre_internal.h" +/* Undefine some potentially clashing cpp symbols */ -/* Structure for building a chain of data that actually lives on the -stack, for holding the values of the subject pointer at the start of each -subpattern, so as to detect when an empty string has been matched by a -subpattern - to break infinite loops. When NO_RECURSE is set, these blocks -are on the heap, not on the stack. */ +#undef min +#undef max -typedef struct eptrblock { - struct eptrblock *epb_prev; - USPTR epb_saved_eptr; -} eptrblock; - /* Flag bits for the match() function */ -#define match_condassert 0x01 /* Called to check a condition assertion */ -#define match_isgroup 0x02 /* Set if start of bracketed group */ +#define match_condassert 0x01 /* Called to check a condition assertion */ +#define match_cbegroup 0x02 /* Could-be-empty unlimited repeat group */ /* Non-error returns from the match() function. Error returns are externally defined PCRE_ERROR_xxx codes, which are all negative. */ @@ -68,6 +66,14 @@ defined PCRE_ERROR_xxx codes, which are #define MATCH_MATCH 1 #define MATCH_NOMATCH 0 +/* Special internal returns from the match() function. Make them sufficiently +negative to avoid the external error codes. */ + +#define MATCH_COMMIT (-999) +#define MATCH_PRUNE (-998) +#define MATCH_SKIP (-997) +#define MATCH_THEN (-996) + /* Maximum number of ints of offset to save on the stack for recursive calls. If the offset vector is bigger, malloc is used. This should be a multiple of 3, because the offset vector is always a multiple of 3 long. */ @@ -101,7 +107,7 @@ pchars(const uschar *p, int length, BOOL static void pchars(const uschar *p, int length, BOOL is_subject, match_data *md) { -int c; +unsigned int c; if (is_subject && length > md->end_subject - p) length = md->end_subject - p; while (length-- > 0) if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c); @@ -186,20 +192,45 @@ always used to. obtained from malloc() instead instead of on the stack. Macros are used to achieve this so that the actual code doesn't look very different to what it always used to. + +The original heap-recursive code used longjmp(). However, it seems that this +can be very slow on some operating systems. Following a suggestion from Stan +Switzer, the use of longjmp() has been abolished, at the cost of having to +provide a unique number for each call to RMATCH. There is no way of generating +a sequence of numbers at compile time in C. I have given them names, to make +them stand out more clearly. + +Crude tests on x86 Linux show a small speedup of around 5-8%. However, on +FreeBSD, avoiding longjmp() more than halves the time taken to run the standard +tests. Furthermore, not using longjmp() means that local dynamic variables +don't have indeterminate values; this has meant that the frame size can be +reduced because the result can be "passed back" by straight setting of the +variable instead of being passed in the frame. **************************************************************************** ***************************************************************************/ +/* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN +below must be updated in sync. */ +enum { RM1=1, RM2, RM3, RM4, RM5, RM6, RM7, RM8, RM9, RM10, + RM11, RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20, + RM21, RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30, + RM31, RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40, + RM41, RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50, + RM51, RM52, RM53, RM54 }; + /* These versions of the macros use the stack, as normal. There are debugging -versions and production versions. */ +versions and production versions. Note that the "rw" argument of RMATCH isn't +actuall used in this definition. */ #ifndef NO_RECURSE #define REGISTER register + #ifdef DEBUG -#define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \ +#define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \ { \ printf("match() called in line %d\n", __LINE__); \ - rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1); \ + rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1); \ printf("to line %d\n", __LINE__); \ } #define RRETURN(ra) \ @@ -208,43 +239,38 @@ versions and production versions. */ return ra; \ } #else -#define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \ - rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1) +#define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \ + rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1) #define RRETURN(ra) return ra #endif #else -/* These versions of the macros manage a private stack on the heap. Note -that the rd argument of RMATCH isn't actually used. It's the md argument of -match(), which never changes. */ +/* These versions of the macros manage a private stack on the heap. Note that +the "rd" argument of RMATCH isn't actually used in this definition. It's the md +argument of match(), which never changes. */ #define REGISTER -#define RMATCH(rx,ra,rb,rc,rd,re,rf,rg)\ +#define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\ {\ heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\ - if (setjmp(frame->Xwhere) == 0)\ - {\ - newframe->Xeptr = ra;\ - newframe->Xecode = rb;\ - newframe->Xoffset_top = rc;\ - newframe->Xims = re;\ - newframe->Xeptrb = rf;\ - newframe->Xflags = rg;\ - newframe->Xrdepth = frame->Xrdepth + 1;\ - newframe->Xprevframe = frame;\ - frame = newframe;\ - DPRINTF(("restarting from line %d\n", __LINE__));\ - goto HEAP_RECURSE;\ - }\ - else\ - {\ - DPRINTF(("longjumped back to line %d\n", __LINE__));\ - frame = md->thisframe;\ - rx = frame->Xresult;\ - }\ + frame->Xwhere = rw; \ + newframe->Xeptr = ra;\ + newframe->Xecode = rb;\ + newframe->Xmstart = mstart;\ + newframe->Xoffset_top = rc;\ + newframe->Xims = re;\ + newframe->Xeptrb = rf;\ + newframe->Xflags = rg;\ + newframe->Xrdepth = frame->Xrdepth + 1;\ + newframe->Xprevframe = frame;\ + frame = newframe;\ + DPRINTF(("restarting from line %d\n", __LINE__));\ + goto HEAP_RECURSE;\ + L_##rw:\ + DPRINTF(("jumped back to line %d\n", __LINE__));\ } #define RRETURN(ra)\ @@ -254,9 +280,8 @@ match(), which never changes. */ (pcre_stack_free)(newframe);\ if (frame != NULL)\ {\ - frame->Xresult = ra;\ - md->thisframe = frame;\ - longjmp(frame->Xwhere, 1);\ + rrc = ra;\ + goto HEAP_RETURN;\ }\ return ra;\ } @@ -271,6 +296,7 @@ typedef struct heapframe { const uschar *Xeptr; const uschar *Xecode; + const uschar *Xmstart; int Xoffset_top; long int Xims; eptrblock *Xeptrb; @@ -291,7 +317,6 @@ typedef struct heapframe { BOOL Xcur_is_word; BOOL Xcondition; - BOOL Xminimize; BOOL Xprev_is_word; unsigned long int Xoriginal_ims; @@ -303,11 +328,12 @@ typedef struct heapframe { int Xprop_category; int Xprop_chartype; int Xprop_script; - int *Xprop_test_variable; + int Xoclength; + uschar Xocchars[8]; #endif int Xctype; - int Xfc; + unsigned int Xfc; int Xfi; int Xlength; int Xmax; @@ -321,10 +347,9 @@ typedef struct heapframe { eptrblock Xnewptrb; - /* Place to pass back result, and where to jump back to */ + /* Where to jump back to */ - int Xresult; - jmp_buf Xwhere; + int Xwhere; } heapframe; @@ -340,10 +365,7 @@ typedef struct heapframe { * Match from current position * *************************************************/ -/* On entry ecode points to the first opcode, and eptr to the first character -in the subject string, while eptrb holds the value of eptr at the start of the -last bracketed group - used for breaking infinite loops matching zero-length -strings. This function is called recursively in many circumstances. Whenever it +/* This function is called recursively in many circumstances. Whenever it returns a negative (error) response, the outer incarnation must also return the same response. @@ -353,8 +375,10 @@ Arguments: made performance worse. Arguments: - eptr pointer in subject - ecode position in code + eptr pointer to current character in subject + ecode pointer to current position in compiled code + mstart pointer to the current match start position (can be modified + by encountering \K) offset_top current top pointer md pointer to "static" info for the match ims current /i, /m, and /s options @@ -362,7 +386,8 @@ Arguments: brackets - for testing for empty matches flags can contain match_condassert - this is an assertion condition - match_isgroup - this is the start of a bracketed group + match_cbegroup - this is the start of an unlimited repeat + group that can match an empty string rdepth the recursion depth Returns: MATCH_MATCH if matched ) these values are >= 0 @@ -372,19 +397,21 @@ static int */ static int -match(REGISTER USPTR eptr, REGISTER const uschar *ecode, +match(REGISTER USPTR eptr, REGISTER const uschar *ecode, const uschar *mstart, int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb, int flags, unsigned int rdepth) { /* These variables do not need to be preserved over recursion in this function, -so they can be ordinary variables in all cases. Mark them with "register" -because they are used a lot in loops. */ +so they can be ordinary variables in all cases. Mark some of them with +"register" because they are used a lot in loops. */ register int rrc; /* Returns from recursive calls */ register int i; /* Used for loops not involving calls to RMATCH() */ -register unsigned int c; /* Character values not kept over RMATCH() calls */ +register unsigned int c; /* Character values not kept over RMATCH() calls */ register BOOL utf8; /* Local copy of UTF-8 flag for speed */ +BOOL minimize, possessive; /* Quantifier options */ + /* When recursion is not being used, all "local" variables that have to be preserved over calls to RMATCH() are part of a "frame" which is obtained from heap storage. Set up the top-level frame here; others are obtained from the @@ -398,6 +425,7 @@ frame->Xecode = ecode; frame->Xeptr = eptr; frame->Xecode = ecode; +frame->Xmstart = mstart; frame->Xoffset_top = offset_top; frame->Xims = ims; frame->Xeptrb = eptrb; @@ -412,6 +440,7 @@ HEAP_RECURSE: #define eptr frame->Xeptr #define ecode frame->Xecode +#define mstart frame->Xmstart #define offset_top frame->Xoffset_top #define ims frame->Xims #define eptrb frame->Xeptrb @@ -434,7 +463,6 @@ HEAP_RECURSE: #define cur_is_word frame->Xcur_is_word #define condition frame->Xcondition -#define minimize frame->Xminimize #define prev_is_word frame->Xprev_is_word #define original_ims frame->Xoriginal_ims @@ -446,7 +474,8 @@ HEAP_RECURSE: #define prop_category frame->Xprop_category #define prop_chartype frame->Xprop_chartype #define prop_script frame->Xprop_script -#define prop_test_variable frame->Xprop_test_variable +#define oclength frame->Xoclength +#define occhars frame->Xocchars #endif #define ctype frame->Xctype @@ -470,7 +499,7 @@ i, and fc and c, can be the same variabl get preserved during recursion in the normal way. In this environment, fi and i, and fc and c, can be the same variables. */ -#else +#else /* NO_RECURSE not defined */ #define fi i #define fc c @@ -489,7 +518,6 @@ BOOL condition; /* that do not have to be preserved over */ BOOL cur_is_word; /* a recursive call to RMATCH(). */ BOOL condition; -BOOL minimize; BOOL prev_is_word; unsigned long int original_ims; @@ -501,7 +529,8 @@ int prop_script; int prop_category; int prop_chartype; int prop_script; -int *prop_test_variable; +int oclength; +uschar occhars[8]; #endif int ctype; @@ -516,7 +545,7 @@ eptrblock newptrb; int stacksave[REC_STACK_SAVE_MAX]; eptrblock newptrb; -#endif +#endif /* NO_RECURSE */ /* These statements are here to stop the compiler complaining about unitialized variables. */ @@ -524,9 +553,9 @@ prop_fail_result = 0; #ifdef SUPPORT_UCP prop_value = 0; prop_fail_result = 0; -prop_test_variable = NULL; #endif + /* This label is used for tail recursion, which is used in a few cases even when NO_RECURSE is not defined, in order to reduce the amount of stack that is used. Thanks to Ian Taylor for noticing this possibility and sending the @@ -542,6 +571,12 @@ however, impact performance when true re complicated macro. It has to be used in one particular way. This shouldn't, however, impact performance when true recursion is being used. */ +#ifdef SUPPORT_UTF8 +utf8 = md->utf8; /* Local copy of the flag */ +#else +utf8 = FALSE; +#endif + /* First check that we haven't called match() too many times, or that we haven't exceeded the recursive call limit. */ @@ -550,66 +585,89 @@ original_ims = ims; /* Save for reset original_ims = ims; /* Save for resetting on ')' */ -#ifdef SUPPORT_UTF8 -utf8 = md->utf8; /* Local copy of the flag */ -#else -utf8 = FALSE; -#endif +/* At the start of a group with an unlimited repeat that may match an empty +string, the match_cbegroup flag is set. When this is the case, add the current +subject pointer to the chain of such remembered pointers, to be checked when we +hit the closing ket, in order to break infinite loops that match no characters. +When match() is called in other circumstances, don't add to the chain. The +match_cbegroup flag must NOT be used with tail recursion, because the memory +block that is used is on the stack, so a new one may be required for each +match(). */ -/* At the start of a bracketed group, add the current subject pointer to the -stack of such pointers, to be re-instated at the end of the group when we hit -the closing ket. When match() is called in other circumstances, we don't add to -this stack. */ - -if ((flags & match_isgroup) != 0) +if ((flags & match_cbegroup) != 0) { + newptrb.epb_saved_eptr = eptr; newptrb.epb_prev = eptrb; - newptrb.epb_saved_eptr = eptr; eptrb = &newptrb; } -/* Now start processing the operations. */ +/* Now start processing the opcodes. */ for (;;) { + minimize = possessive = FALSE; op = *ecode; - minimize = FALSE; /* For partial matching, remember if we ever hit the end of the subject after matching at least one subject character. */ if (md->partial && eptr >= md->end_subject && - eptr > md->start_match) + eptr > mstart) md->hitend = TRUE; - /* Opening capturing bracket. If there is space in the offset vector, save - the current subject position in the working slot at the top of the vector. We - mustn't change the current values of the data slot, because they may be set - from a previous iteration of this group, and be referred to by a reference - inside the group. + switch(op) + { + case OP_FAIL: + RRETURN(MATCH_NOMATCH); - If the bracket fails to match, we need to restore this value and also the - values of the final offsets, in case they were set by a previous iteration of - the same bracket. + case OP_PRUNE: + RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, + ims, eptrb, flags, RM51); + if (rrc != MATCH_NOMATCH) RRETURN(rrc); + RRETURN(MATCH_PRUNE); - If there isn't enough space in the offset vector, treat this as if it were a - non-capturing bracket. Don't worry about setting the flag for the error case - here; that is handled in the code for KET. */ + case OP_COMMIT: + RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, + ims, eptrb, flags, RM52); + if (rrc != MATCH_NOMATCH) RRETURN(rrc); + RRETURN(MATCH_COMMIT); - if (op > OP_BRA) - { - number = op - OP_BRA; + case OP_SKIP: + RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, + ims, eptrb, flags, RM53); + if (rrc != MATCH_NOMATCH) RRETURN(rrc); + md->start_match_ptr = eptr; /* Pass back current position */ + RRETURN(MATCH_SKIP); - /* For extended extraction brackets (large number), we have to fish out the - number from a dummy opcode at the start. */ + case OP_THEN: + RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, + ims, eptrb, flags, RM54); + if (rrc != MATCH_NOMATCH) RRETURN(rrc); + RRETURN(MATCH_THEN); - if (number > EXTRACT_BASIC_MAX) - number = GET2(ecode, 2+LINK_SIZE); + /* Handle a capturing bracket. If there is space in the offset vector, save + the current subject position in the working slot at the top of the vector. + We mustn't change the current values of the data slot, because they may be + set from a previous iteration of this group, and be referred to by a + reference inside the group. + + If the bracket fails to match, we need to restore this value and also the + values of the final offsets, in case they were set by a previous iteration + of the same bracket. + + If there isn't enough space in the offset vector, treat this as if it were + a non-capturing bracket. Don't worry about setting the flag for the error + case here; that is handled in the code for KET. */ + + case OP_CBRA: + case OP_SCBRA: + number = GET2(ecode, 1+LINK_SIZE); offset = number << 1; #ifdef DEBUG - printf("start bracket %d subject=", number); + printf("start bracket %d\n", number); + printf("subject="); pchars(eptr, 16, TRUE, md); printf("\n"); #endif @@ -624,11 +682,12 @@ for (;;) DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3)); md->offset_vector[md->offset_end - number] = eptr - md->start_subject; + flags = (op == OP_SCBRA)? match_cbegroup : 0; do { - RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, - match_isgroup); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); + RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, + ims, eptrb, flags, RM1); + if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); md->capture_last = save_capture_last; ecode += GET(ecode, 1); } @@ -643,40 +702,51 @@ for (;;) RRETURN(MATCH_NOMATCH); } - /* Insufficient room for saving captured contents */ + /* FALL THROUGH ... Insufficient room for saving captured contents. Treat + as a non-capturing bracket. */ - else op = OP_BRA; - } + /* VVVVVVVVVVVVVVVVVVVVVVVVV */ + /* VVVVVVVVVVVVVVVVVVVVVVVVV */ - /* Other types of node can be handled by a switch */ + DPRINTF(("insufficient capture room: treat as non-capturing\n")); - switch(op) - { - case OP_BRA: /* Non-capturing bracket: optimized */ - DPRINTF(("start bracket 0\n")); + /* VVVVVVVVVVVVVVVVVVVVVVVVV */ + /* VVVVVVVVVVVVVVVVVVVVVVVVV */ - /* Loop for all the alternatives */ + /* Non-capturing bracket. Loop for all the alternatives. When we get to the + final alternative within the brackets, we would return the result of a + recursive call to match() whatever happened. We can reduce stack usage by + turning this into a tail recursion, except in the case when match_cbegroup + is set.*/ + case OP_BRA: + case OP_SBRA: + DPRINTF(("start non-capturing bracket\n")); + flags = (op >= OP_SBRA)? match_cbegroup : 0; for (;;) { - /* When we get to the final alternative within the brackets, we would - return the result of a recursive call to match() whatever happened. We - can reduce stack usage by turning this into a tail recursion. */ + if (ecode[GET(ecode, 1)] != OP_ALT) /* Final alternative */ + { + if (flags == 0) /* Not a possibly empty group */ + { + ecode += _pcre_OP_lengths[*ecode]; + DPRINTF(("bracket 0 tail recursion\n")); + goto TAIL_RECURSE; + } - if (ecode[GET(ecode, 1)] != OP_ALT) - { - ecode += 1 + LINK_SIZE; - flags = match_isgroup; - DPRINTF(("bracket 0 tail recursion\n")); - goto TAIL_RECURSE; - } + /* Possibly empty group; can't use tail recursion. */ + RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims, + eptrb, flags, RM48); + RRETURN(rrc); + } + /* For non-final alternatives, continue the loop for a NOMATCH result; otherwise return. */ - RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, - match_isgroup); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); + RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims, + eptrb, flags, RM2); + if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); ecode += GET(ecode, 1); } /* Control never reaches here. */ @@ -688,55 +758,84 @@ for (;;) obeyed, we can use tail recursion to avoid using another stack frame. */ case OP_COND: - if (ecode[LINK_SIZE+1] == OP_CREF) /* Condition extract or recurse test */ + case OP_SCOND: + if (ecode[LINK_SIZE+1] == OP_RREF) /* Recursion test */ { + offset = GET2(ecode, LINK_SIZE + 2); /* Recursion group number*/ + condition = md->recursive != NULL && + (offset == RREF_ANY || offset == md->recursive->group_num); + ecode += condition? 3 : GET(ecode, 1); + } + + else if (ecode[LINK_SIZE+1] == OP_CREF) /* Group used test */ + { offset = GET2(ecode, LINK_SIZE+2) << 1; /* Doubled ref number */ - condition = (offset == CREF_RECURSE * 2)? - (md->recursive != NULL) : - (offset < offset_top && md->offset_vector[offset] >= 0); - ecode += condition? (LINK_SIZE + 4) : (LINK_SIZE + 1 + GET(ecode, 1)); - flags = match_isgroup; - goto TAIL_RECURSE; + condition = offset < offset_top && md->offset_vector[offset] >= 0; + ecode += condition? 3 : GET(ecode, 1); } + else if (ecode[LINK_SIZE+1] == OP_DEF) /* DEFINE - always false */ + { + condition = FALSE; + ecode += GET(ecode, 1); + } + /* The condition is an assertion. Call match() to evaluate it - setting - the final argument TRUE causes it to stop at the end of an assertion. */ + the final argument match_condassert causes it to stop at the end of an + assertion. */ else { - RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, - match_condassert | match_isgroup); + RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, + match_condassert, RM3); if (rrc == MATCH_MATCH) { - ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE+2); + condition = TRUE; + ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2); while (*ecode == OP_ALT) ecode += GET(ecode, 1); } - else if (rrc != MATCH_NOMATCH) + else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) { RRETURN(rrc); /* Need braces because of following else */ } - else ecode += GET(ecode, 1); + else + { + condition = FALSE; + ecode += GET(ecode, 1); + } + } - /* We are now at the branch that is to be obeyed. As there is only one, - we can use tail recursion to avoid using another stack frame. */ + /* We are now at the branch that is to be obeyed. As there is only one, + we can use tail recursion to avoid using another stack frame, except when + match_cbegroup is required for an unlimited repeat of a possibly empty + group. If the second alternative doesn't exist, we can just plough on. */ + if (condition || *ecode == OP_ALT) + { ecode += 1 + LINK_SIZE; - flags = match_isgroup; - goto TAIL_RECURSE; + if (op == OP_SCOND) /* Possibly empty group */ + { + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49); + RRETURN(rrc); + } + else /* Group must match something */ + { + flags = 0; + goto TAIL_RECURSE; + } } - /* Control never reaches here */ + else /* Condition false & no 2nd alternative */ + { + ecode += 1 + LINK_SIZE; + } + break; - /* Skip over conditional reference or large extraction number data if - encountered. */ - case OP_CREF: - case OP_BRANUMBER: - ecode += 3; - break; + /* End of the pattern, either real or forced. If we are in a top-level + recursion, we should restore the offsets appropriately and continue from + after the call. */ - /* End of the pattern. If we are in a recursion, we should restore the - offsets appropriately and continue from after the call. */ - + case OP_ACCEPT: case OP_END: if (md->recursive != NULL && md->recursive->group_num == 0) { @@ -745,7 +844,7 @@ for (;;) md->recursive = rec->prevrec; memmove(md->offset_vector, rec->offset_save, rec->saved_max * sizeof(int)); - md->start_match = rec->save_start; + mstart = rec->save_start; ims = original_ims; ecode = rec->after_call; break; @@ -754,9 +853,10 @@ for (;;) /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty string - backtracking will then try other alternatives, if any. */ - if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH); - md->end_match_ptr = eptr; /* Record where we ended */ - md->end_offset_top = offset_top; /* and how many extracts were taken */ + if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH); + md->end_match_ptr = eptr; /* Record where we ended */ + md->end_offset_top = offset_top; /* and how many extracts were taken */ + md->start_match_ptr = mstart; /* and the start (\K can modify) */ RRETURN(MATCH_MATCH); /* Change option settings */ @@ -777,10 +877,10 @@ for (;;) case OP_ASSERTBACK: do { - RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, - match_isgroup); + RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0, + RM4); if (rrc == MATCH_MATCH) break; - if (rrc != MATCH_NOMATCH) RRETURN(rrc); + if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); ecode += GET(ecode, 1); } while (*ecode == OP_ALT); @@ -804,10 +904,10 @@ for (;;) case OP_ASSERTBACK_NOT: do { - RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, - match_isgroup); + RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0, + RM5); if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH); - if (rrc != MATCH_NOMATCH) RRETURN(rrc); + if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); ecode += GET(ecode,1); } while (*ecode == OP_ALT); @@ -826,12 +926,12 @@ for (;;) #ifdef SUPPORT_UTF8 if (utf8) { - c = GET(ecode,1); - for (i = 0; i < c; i++) + i = GET(ecode, 1); + while (i-- > 0) { eptr--; if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); - BACKCHAR(eptr) + BACKCHAR(eptr); } } else @@ -840,7 +940,7 @@ for (;;) /* No UTF-8 support, or not in UTF-8 mode: count is byte count */ { - eptr -= GET(ecode,1); + eptr -= GET(ecode, 1); if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH); } @@ -862,7 +962,7 @@ for (;;) cb.offset_vector = md->offset_vector; cb.subject = (PCRE_SPTR)md->start_subject; cb.subject_length = md->end_subject - md->start_subject; - cb.start_match = md->start_match - md->start_subject; + cb.start_match = mstart - md->start_subject; cb.current_position = eptr - md->start_subject; cb.pattern_position = GET(ecode, 2); cb.next_item_length = GET(ecode, 2 + LINK_SIZE); @@ -897,14 +997,9 @@ for (;;) case OP_RECURSE: { callpat = md->start_code + GET(ecode, 1); - new_recursive.group_num = *callpat - OP_BRA; + new_recursive.group_num = (callpat == md->start_code)? 0 : + GET2(callpat, 1 + LINK_SIZE); - /* For extended extraction brackets (large number), we have to fish out - the number from a dummy opcode at the start. */ - - if (new_recursive.group_num > EXTRACT_BASIC_MAX) - new_recursive.group_num = GET2(callpat, 2+LINK_SIZE); - /* Add to "recursing stack" */ new_recursive.prevrec = md->recursive; @@ -929,17 +1024,18 @@ for (;;) memcpy(new_recursive.offset_save, md->offset_vector, new_recursive.saved_max * sizeof(int)); - new_recursive.save_start = md->start_match; - md->start_match = eptr; + new_recursive.save_start = mstart; + mstart = eptr; /* OK, now we can do the recursion. For each top-level alternative we restore the offset and recursion data. */ DPRINTF(("Recursing into group %d\n", new_recursive.group_num)); + flags = (*callpat >= OP_SBRA)? match_cbegroup : 0; do { - RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims, - eptrb, match_isgroup); + RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top, + md, ims, eptrb, flags, RM6); if (rrc == MATCH_MATCH) { DPRINTF(("Recursion matched\n")); @@ -948,7 +1044,7 @@ for (;;) (pcre_free)(new_recursive.offset_save); RRETURN(MATCH_MATCH); } - else if (rrc != MATCH_NOMATCH) + else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) { DPRINTF(("Recursion gave error %d\n", rrc)); RRETURN(rrc); @@ -982,10 +1078,9 @@ for (;;) do { - RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, - eptrb, match_isgroup); + RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7); if (rrc == MATCH_MATCH) break; - if (rrc != MATCH_NOMATCH) RRETURN(rrc); + if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc); ecode += GET(ecode,1); } while (*ecode == OP_ALT); @@ -997,7 +1092,7 @@ for (;;) /* Continue as from after the assertion, updating the offsets high water mark, since extracts may have been taken. */ - do ecode += GET(ecode,1); while (*ecode == OP_ALT); + do ecode += GET(ecode, 1); while (*ecode == OP_ALT); offset_top = md->end_offset_top; eptr = md->end_match_ptr; @@ -1028,15 +1123,15 @@ for (;;) if (*ecode == OP_KETRMIN) { - RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8); if (rrc != MATCH_NOMATCH) RRETURN(rrc); ecode = prev; - flags = match_isgroup; + flags = 0; goto TAIL_RECURSE; } else /* OP_KETRMAX */ { - RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); + RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9); if (rrc != MATCH_NOMATCH) RRETURN(rrc); ecode += 1 + LINK_SIZE; flags = 0; @@ -1060,39 +1155,45 @@ for (;;) case OP_BRAZERO: { next = ecode+1; - RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup); + RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10); if (rrc != MATCH_NOMATCH) RRETURN(rrc); do next += GET(next,1); while (*next == OP_ALT); - ecode = next + 1+LINK_SIZE; + ecode = next + 1 + LINK_SIZE; } break; case OP_BRAMINZERO: { next = ecode+1; - do next += GET(next,1); while (*next == OP_ALT); - RMATCH(rrc, eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, - match_isgroup); + do next += GET(next, 1); while (*next == OP_ALT); + RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11); if (rrc != MATCH_NOMATCH) RRETURN(rrc); ecode++; } break; - /* End of a group, repeated or non-repeating. If we are at the end of - an assertion "group", stop matching and return MATCH_MATCH, but record the - current high water mark for use by positive assertions. Do this also - for the "once" (not-backup up) groups. */ + /* End of a group, repeated or non-repeating. */ case OP_KET: case OP_KETRMIN: case OP_KETRMAX: prev = ecode - GET(ecode, 1); - saved_eptr = eptrb->epb_saved_eptr; - /* Back up the stack of bracket start pointers. */ + /* If this was a group that remembered the subject start, in order to break + infinite repeats of empty string matches, retrieve the subject start from + the chain. Otherwise, set it NULL. */ - eptrb = eptrb->epb_prev; + if (*prev >= OP_SBRA) + { + saved_eptr = eptrb->epb_saved_eptr; /* Value at start of group */ + eptrb = eptrb->epb_prev; /* Backup to previous group */ + } + else saved_eptr = NULL; + /* If we are at the end of an assertion group, stop matching and return + MATCH_MATCH, but record the current high water mark for use by positive + assertions. Do this also for the "once" (atomic) groups. */ + if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT || *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT || *prev == OP_ONCE) @@ -1102,18 +1203,15 @@ for (;;) RRETURN(MATCH_MATCH); } - /* In all other cases except a conditional group we have to check the - group number back at the start and if necessary complete handling an - extraction by setting the offsets and bumping the high water mark. */ + /* For capturing groups we have to check the group number back at the start + and if necessary complete handling an extraction by setting the offsets and + bumping the high water mark. Note that whole-pattern recursion is coded as + a recurse into group 0, so it won't be picked up here. Instead, we catch it + when the OP_END is reached. Other recursion is handled here. */ - if (*prev != OP_COND) + if (*prev == OP_CBRA || *prev == OP_SCBRA) { - number = *prev - OP_BRA; - - /* For extended extraction brackets (large number), we have to fish out - the number from a dummy opcode at the start. */ - - if (number > EXTRACT_BASIC_MAX) number = GET2(prev, 2+LINK_SIZE); + number = GET2(prev, 1+LINK_SIZE); offset = number << 1; #ifdef DEBUG @@ -1121,42 +1219,34 @@ for (;;) printf("\n"); #endif - /* Test for a numbered group. This includes groups called as a result - of recursion. Note that whole-pattern recursion is coded as a recurse - into group 0, so it won't be picked up here. Instead, we catch it when - the OP_END is reached. */ - - if (number > 0) + md->capture_last = number; + if (offset >= md->offset_max) md->offset_overflow = TRUE; else { - md->capture_last = number; - if (offset >= md->offset_max) md->offset_overflow = TRUE; else - { - md->offset_vector[offset] = - md->offset_vector[md->offset_end - number]; - md->offset_vector[offset+1] = eptr - md->start_subject; - if (offset_top <= offset) offset_top = offset + 2; - } + md->offset_vector[offset] = + md->offset_vector[md->offset_end - number]; + md->offset_vector[offset+1] = eptr - md->start_subject; + if (offset_top <= offset) offset_top = offset + 2; + } - /* Handle a recursively called group. Restore the offsets - appropriately and continue from after the call. */ + /* Handle a recursively called group. Restore the offsets + appropriately and continue from after the call. */ - if (md->recursive != NULL && md->recursive->group_num == number) - { - recursion_info *rec = md->recursive; - DPRINTF(("Recursion (%d) succeeded - continuing\n", number)); - md->recursive = rec->prevrec; - md->start_match = rec->save_start; - memcpy(md->offset_vector, rec->offset_save, - rec->saved_max * sizeof(int)); - ecode = rec->after_call; - ims = original_ims; - break; - } + if (md->recursive != NULL && md->recursive->group_num == number) + { + recursion_info *rec = md->recursive; + DPRINTF(("Recursion (%d) succeeded - continuing\n", number)); + md->recursive = rec->prevrec; + mstart = rec->save_start; + memcpy(md->offset_vector, rec->offset_save, + rec->saved_max * sizeof(int)); + ecode = rec->after_call; + ims = original_ims; + break; } } - /* Reset the value of the ims flags, in case they got changed during - the group. */ + /* For both capturing and non-capturing groups, reset the value of the ims + flags, in case they got changed during the group. */ ims = original_ims; DPRINTF(("ims reset to %02lx\n", ims)); @@ -1175,19 +1265,26 @@ for (;;) /* The repeating kets try the rest of the pattern or restart from the preceding bracket, in the appropriate order. In the second case, we can use - tail recursion to avoid using another stack frame. */ + tail recursion to avoid using another stack frame, unless we have an + unlimited repeat of a group that can match an empty string. */ + flags = (*prev >= OP_SBRA)? match_cbegroup : 0; + if (*ecode == OP_KETRMIN) { - RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12); if (rrc != MATCH_NOMATCH) RRETURN(rrc); + if (flags != 0) /* Could match an empty string */ + { + RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50); + RRETURN(rrc); + } ecode = prev; - flags = match_isgroup; goto TAIL_RECURSE; } else /* OP_KETRMAX */ { - RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup); + RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13); if (rrc != MATCH_NOMATCH) RRETURN(rrc); ecode += 1 + LINK_SIZE; flags = 0; @@ -1202,9 +1299,7 @@ for (;;) if ((ims & PCRE_MULTILINE) != 0) { if (eptr != md->start_subject && - (eptr == md->end_subject || - eptr < md->start_subject + md->nllen || - !IS_NEWLINE(eptr - md->nllen))) + (eptr == md->end_subject || !WAS_NEWLINE(eptr))) RRETURN(MATCH_NOMATCH); ecode++; break; @@ -1225,6 +1320,13 @@ for (;;) ecode++; break; + /* Reset the start of match point */ + + case OP_SET_SOM: + mstart = eptr; + ecode++; + break; + /* Assert before internal newline if multiline, or before a terminating newline unless endonly is set, else end of subject unless noteol is set. */ @@ -1244,7 +1346,7 @@ for (;;) if (!md->endonly) { if (eptr != md->end_subject && - (eptr != md->end_subject - md->nllen || !IS_NEWLINE(eptr))) + (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen)) RRETURN(MATCH_NOMATCH); ecode++; break; @@ -1263,7 +1365,7 @@ for (;;) case OP_EODN: if (eptr != md->end_subject && - (eptr != md->end_subject - md->nllen || !IS_NEWLINE(eptr))) + (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen)) RRETURN(MATCH_NOMATCH); ecode++; break; @@ -1319,8 +1421,7 @@ for (;;) case OP_ANY: if ((ims & PCRE_DOTALL) == 0) { - if (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr)) - RRETURN(MATCH_NOMATCH); + if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); } if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH); if (utf8) @@ -1414,6 +1515,126 @@ for (;;) ecode++; break; + case OP_ANYNL: + if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); + GETCHARINCTEST(c, eptr); + switch(c) + { + default: RRETURN(MATCH_NOMATCH); + case 0x000d: + if (eptr < md->end_subject && *eptr == 0x0a) eptr++; + break; + + case 0x000a: + break; + + case 0x000b: + case 0x000c: + case 0x0085: + case 0x2028: + case 0x2029: + if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); + break; + } + ecode++; + break; + + case OP_NOT_HSPACE: + if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); + GETCHARINCTEST(c, eptr); + switch(c) + { + default: break; + case 0x09: /* HT */ + case 0x20: /* SPACE */ + case 0xa0: /* NBSP */ + case 0x1680: /* OGHAM SPACE MARK */ + case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ + case 0x2000: /* EN QUAD */ + case 0x2001: /* EM QUAD */ + case 0x2002: /* EN SPACE */ + case 0x2003: /* EM SPACE */ + case 0x2004: /* THREE-PER-EM SPACE */ + case 0x2005: /* FOUR-PER-EM SPACE */ + case 0x2006: /* SIX-PER-EM SPACE */ + case 0x2007: /* FIGURE SPACE */ + case 0x2008: /* PUNCTUATION SPACE */ + case 0x2009: /* THIN SPACE */ + case 0x200A: /* HAIR SPACE */ + case 0x202f: /* NARROW NO-BREAK SPACE */ + case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ + case 0x3000: /* IDEOGRAPHIC SPACE */ + RRETURN(MATCH_NOMATCH); + } + ecode++; + break; + + case OP_HSPACE: + if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); + GETCHARINCTEST(c, eptr); + switch(c) + { + default: RRETURN(MATCH_NOMATCH); + case 0x09: /* HT */ + case 0x20: /* SPACE */ + case 0xa0: /* NBSP */ + case 0x1680: /* OGHAM SPACE MARK */ + case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ + case 0x2000: /* EN QUAD */ + case 0x2001: /* EM QUAD */ + case 0x2002: /* EN SPACE */ + case 0x2003: /* EM SPACE */ + case 0x2004: /* THREE-PER-EM SPACE */ + case 0x2005: /* FOUR-PER-EM SPACE */ + case 0x2006: /* SIX-PER-EM SPACE */ + case 0x2007: /* FIGURE SPACE */ + case 0x2008: /* PUNCTUATION SPACE */ + case 0x2009: /* THIN SPACE */ + case 0x200A: /* HAIR SPACE */ + case 0x202f: /* NARROW NO-BREAK SPACE */ + case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ + case 0x3000: /* IDEOGRAPHIC SPACE */ + break; + } + ecode++; + break; + + case OP_NOT_VSPACE: + if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); + GETCHARINCTEST(c, eptr); + switch(c) + { + default: break; + case 0x0a: /* LF */ + case 0x0b: /* VT */ + case 0x0c: /* FF */ + case 0x0d: /* CR */ + case 0x85: /* NEL */ + case 0x2028: /* LINE SEPARATOR */ + case 0x2029: /* PARAGRAPH SEPARATOR */ + RRETURN(MATCH_NOMATCH); + } + ecode++; + break; + + case OP_VSPACE: + if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); + GETCHARINCTEST(c, eptr); + switch(c) + { + default: RRETURN(MATCH_NOMATCH); + case 0x0a: /* LF */ + case 0x0b: /* VT */ + case 0x0c: /* FF */ + case 0x0d: /* CR */ + case 0x85: /* NEL */ + case 0x2028: /* LINE SEPARATOR */ + case 0x2029: /* PARAGRAPH SEPARATOR */ + break; + } + ecode++; + break; + #ifdef SUPPORT_UCP /* Check the next character by Unicode property. We will get here only if the support is in the binary; otherwise a compile-time error occurs. */ @@ -1456,7 +1677,6 @@ for (;;) default: RRETURN(PCRE_ERROR_INTERNAL); - break; } ecode += 3; @@ -1570,7 +1790,7 @@ for (;;) { for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (fi >= max || !match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH); @@ -1591,7 +1811,7 @@ for (;;) } while (eptr >= pp) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15); if (rrc != MATCH_NOMATCH) RRETURN(rrc); eptr -= length; } @@ -1696,7 +1916,7 @@ for (;;) { for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); GETCHARINC(c, eptr); @@ -1716,7 +1936,7 @@ for (;;) { for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); c = *eptr++; @@ -1753,7 +1973,7 @@ for (;;) } for (;;) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (eptr-- == pp) break; /* Stop if tried at original pos */ BACKCHAR(eptr); @@ -1772,7 +1992,7 @@ for (;;) } while (eptr >= pp) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19); if (rrc != MATCH_NOMATCH) RRETURN(rrc); eptr--; } @@ -1843,7 +2063,7 @@ for (;;) { for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); GETCHARINC(c, eptr); @@ -1867,10 +2087,10 @@ for (;;) } for(;;) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (eptr-- == pp) break; /* Stop if tried at original pos */ - BACKCHAR(eptr) + if (utf8) BACKCHAR(eptr); } RRETURN(MATCH_NOMATCH); } @@ -1926,7 +2146,7 @@ for (;;) else { - int dc; + unsigned int dc; GETCHARINC(dc, eptr); ecode += length; @@ -1953,13 +2173,17 @@ for (;;) } break; - /* Match a single character repeatedly; different opcodes share code. */ + /* Match a single character repeatedly. */ case OP_EXACT: min = max = GET2(ecode, 1); ecode += 3; goto REPEATCHAR; + case OP_POSUPTO: + possessive = TRUE; + /* Fall through */ + case OP_UPTO: case OP_MINUPTO: min = 0; @@ -1968,6 +2192,27 @@ for (;;) ecode += 3; goto REPEATCHAR; + case OP_POSSTAR: + possessive = TRUE; + min = 0; + max = INT_MAX; + ecode++; + goto REPEATCHAR; + + case OP_POSPLUS: + possessive = TRUE; + min = 1; + max = INT_MAX; + ecode++; + goto REPEATCHAR; + + case OP_POSQUERY: + possessive = TRUE; + min = 0; + max = 1; + ecode++; + goto REPEATCHAR; + case OP_STAR: case OP_MINSTAR: case OP_PLUS: @@ -1999,20 +2244,18 @@ for (;;) if (length > 1) { - int oclength = 0; - uschar occhars[8]; - #ifdef SUPPORT_UCP - int othercase; + unsigned int othercase; if ((ims & PCRE_CASELESS) != 0 && - (othercase = _pcre_ucp_othercase(fc)) >= 0 && - othercase >= 0) + (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR) oclength = _pcre_ord2utf8(othercase, occhars); + else oclength = 0; #endif /* SUPPORT_UCP */ for (i = 1; i <= min; i++) { if (memcmp(eptr, charptr, length) == 0) eptr += length; +#ifdef SUPPORT_UCP /* Need braces because of following else */ else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } else @@ -2020,6 +2263,9 @@ for (;;) if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH); eptr += oclength; } +#else /* without SUPPORT_UCP */ + else { RRETURN(MATCH_NOMATCH); } +#endif /* SUPPORT_UCP */ } if (min == max) continue; @@ -2028,10 +2274,11 @@ for (;;) { for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22); 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 /* Need braces because of following else */ else if (oclength == 0) { RRETURN(MATCH_NOMATCH); } else @@ -2039,30 +2286,45 @@ for (;;) if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH); eptr += oclength; } +#else /* without SUPPORT_UCP */ + else { RRETURN (MATCH_NOMATCH); } +#endif /* SUPPORT_UCP */ } /* Control never gets here */ } - else + + else /* Maximize */ { pp = eptr; for (i = min; i < max; i++) { if (eptr > md->end_subject - length) break; if (memcmp(eptr, charptr, length) == 0) eptr += length; +#ifdef SUPPORT_UCP else if (oclength == 0) break; else { if (memcmp(eptr, occhars, oclength) != 0) break; eptr += oclength; } +#else /* without SUPPORT_UCP */ + else break; +#endif /* SUPPORT_UCP */ } - while (eptr >= pp) + + if (possessive) continue; + for(;;) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23); if (rrc != MATCH_NOMATCH) RRETURN(rrc); + if (eptr == pp) RRETURN(MATCH_NOMATCH); +#ifdef SUPPORT_UCP + eptr--; + BACKCHAR(eptr); +#else /* without SUPPORT_UCP */ eptr -= length; +#endif /* SUPPORT_UCP */ } - RRETURN(MATCH_NOMATCH); } /* Control never gets here */ } @@ -2102,7 +2364,7 @@ for (;;) { for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (fi >= max || eptr >= md->end_subject || fc != md->lcc[*eptr++]) @@ -2110,7 +2372,7 @@ for (;;) } /* Control never gets here */ } - else + else /* Maximize */ { pp = eptr; for (i = min; i < max; i++) @@ -2118,9 +2380,10 @@ for (;;) if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break; eptr++; } + if (possessive) continue; while (eptr >= pp) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25); eptr--; if (rrc != MATCH_NOMATCH) RRETURN(rrc); } @@ -2139,14 +2402,14 @@ for (;;) { for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (fi >= max || eptr >= md->end_subject || fc != *eptr++) RRETURN(MATCH_NOMATCH); } /* Control never gets here */ } - else + else /* Maximize */ { pp = eptr; for (i = min; i < max; i++) @@ -2154,9 +2417,10 @@ for (;;) if (eptr >= md->end_subject || fc != *eptr) break; eptr++; } + if (possessive) continue; while (eptr >= pp) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27); eptr--; if (rrc != MATCH_NOMATCH) RRETURN(rrc); } @@ -2206,6 +2470,34 @@ for (;;) ecode += 3; goto REPEATNOTCHAR; + case OP_NOTPOSSTAR: + possessive = TRUE; + min = 0; + max = INT_MAX; + ecode++; + goto REPEATNOTCHAR; + + case OP_NOTPOSPLUS: + possessive = TRUE; + min = 1; + max = INT_MAX; + ecode++; + goto REPEATNOTCHAR; + + case OP_NOTPOSQUERY: + possessive = TRUE; + min = 0; + max = 1; + ecode++; + goto REPEATNOTCHAR; + + case OP_NOTPOSUPTO: + possessive = TRUE; + min = 0; + max = GET2(ecode, 1); + ecode += 3; + goto REPEATNOTCHAR; + case OP_NOTSTAR: case OP_NOTMINSTAR: case OP_NOTPLUS: @@ -2245,7 +2537,7 @@ for (;;) /* UTF-8 mode */ if (utf8) { - register int d; + register unsigned int d; for (i = 1; i <= min; i++) { GETCHARINC(d, eptr); @@ -2270,10 +2562,10 @@ for (;;) /* UTF-8 mode */ if (utf8) { - register int d; + register unsigned int d; for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28); if (rrc != MATCH_NOMATCH) RRETURN(rrc); GETCHARINC(d, eptr); if (d < 256) d = md->lcc[d]; @@ -2287,7 +2579,7 @@ for (;;) { for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH); @@ -2306,7 +2598,7 @@ for (;;) /* UTF-8 mode */ if (utf8) { - register int d; + register unsigned int d; for (i = min; i < max; i++) { int len = 1; @@ -2316,9 +2608,10 @@ for (;;) if (fc == d) break; eptr += len; } - for(;;) + if (possessive) continue; + for(;;) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (eptr-- == pp) break; /* Stop if tried at original pos */ BACKCHAR(eptr); @@ -2333,9 +2626,10 @@ for (;;) if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break; eptr++; } + if (possessive) continue; while (eptr >= pp) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31); if (rrc != MATCH_NOMATCH) RRETURN(rrc); eptr--; } @@ -2354,7 +2648,7 @@ for (;;) /* UTF-8 mode */ if (utf8) { - register int d; + register unsigned int d; for (i = 1; i <= min; i++) { GETCHARINC(d, eptr); @@ -2377,10 +2671,10 @@ for (;;) /* UTF-8 mode */ if (utf8) { - register int d; + register unsigned int d; for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32); if (rrc != MATCH_NOMATCH) RRETURN(rrc); GETCHARINC(d, eptr); if (fi >= max || eptr >= md->end_subject || fc == d) @@ -2393,7 +2687,7 @@ for (;;) { for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (fi >= max || eptr >= md->end_subject || fc == *eptr++) RRETURN(MATCH_NOMATCH); @@ -2412,7 +2706,7 @@ for (;;) /* UTF-8 mode */ if (utf8) { - register int d; + register unsigned int d; for (i = min; i < max; i++) { int len = 1; @@ -2421,9 +2715,10 @@ for (;;) if (fc == d) break; eptr += len; } + if (possessive) continue; for(;;) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (eptr-- == pp) break; /* Stop if tried at original pos */ BACKCHAR(eptr); @@ -2438,9 +2733,10 @@ for (;;) if (eptr >= md->end_subject || fc == *eptr) break; eptr++; } + if (possessive) continue; while (eptr >= pp) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35); if (rrc != MATCH_NOMATCH) RRETURN(rrc); eptr--; } @@ -2469,6 +2765,34 @@ for (;;) ecode += 3; goto REPEATTYPE; + case OP_TYPEPOSSTAR: + possessive = TRUE; + min = 0; + max = INT_MAX; + ecode++; + goto REPEATTYPE; + + case OP_TYPEPOSPLUS: + possessive = TRUE; + min = 1; + max = INT_MAX; + ecode++; + goto REPEATTYPE; + + case OP_TYPEPOSQUERY: + possessive = TRUE; + min = 0; + max = 1; + ecode++; + goto REPEATTYPE; + + case OP_TYPEPOSUPTO: + possessive = TRUE; + min = 0; + max = GET2(ecode, 1); + ecode += 3; + goto REPEATTYPE; + case OP_TYPESTAR: case OP_TYPEMINSTAR: case OP_TYPEPLUS: @@ -2519,7 +2843,7 @@ for (;;) for (i = 1; i <= min; i++) { if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); - GETCHARINC(c, eptr); + GETCHARINCTEST(c, eptr); } break; @@ -2527,7 +2851,7 @@ for (;;) for (i = 1; i <= min; i++) { if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); - GETCHARINC(c, eptr); + GETCHARINCTEST(c, eptr); prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); if ((prop_chartype == ucp_Lu || prop_chartype == ucp_Ll || @@ -2540,7 +2864,7 @@ for (;;) for (i = 1; i <= min; i++) { if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); - GETCHARINC(c, eptr); + GETCHARINCTEST(c, eptr); prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); if ((prop_category == prop_value) == prop_fail_result) RRETURN(MATCH_NOMATCH); @@ -2551,7 +2875,7 @@ for (;;) for (i = 1; i <= min; i++) { if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); - GETCHARINC(c, eptr); + GETCHARINCTEST(c, eptr); prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); if ((prop_chartype == prop_value) == prop_fail_result) RRETURN(MATCH_NOMATCH); @@ -2562,7 +2886,7 @@ for (;;) for (i = 1; i <= min; i++) { if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); - GETCHARINC(c, eptr); + GETCHARINCTEST(c, eptr); prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); if ((prop_script == prop_value) == prop_fail_result) RRETURN(MATCH_NOMATCH); @@ -2571,7 +2895,6 @@ for (;;) default: RRETURN(PCRE_ERROR_INTERNAL); - break; } } @@ -2611,9 +2934,7 @@ for (;;) for (i = 1; i <= min; i++) { if (eptr >= md->end_subject || - ((ims & PCRE_DOTALL) == 0 && - eptr <= md->end_subject - md->nllen && - IS_NEWLINE(eptr))) + ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr))) RRETURN(MATCH_NOMATCH); eptr++; while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; @@ -2624,6 +2945,136 @@ for (;;) eptr += min; break; + case OP_ANYNL: + for (i = 1; i <= min; i++) + { + if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); + GETCHARINC(c, eptr); + switch(c) + { + default: RRETURN(MATCH_NOMATCH); + case 0x000d: + if (eptr < md->end_subject && *eptr == 0x0a) eptr++; + break; + + case 0x000a: + break; + + case 0x000b: + case 0x000c: + case 0x0085: + case 0x2028: + case 0x2029: + if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); + break; + } + } + break; + + case OP_NOT_HSPACE: + for (i = 1; i <= min; i++) + { + if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); + GETCHARINC(c, eptr); + switch(c) + { + default: break; + case 0x09: /* HT */ + case 0x20: /* SPACE */ + case 0xa0: /* NBSP */ + case 0x1680: /* OGHAM SPACE MARK */ + case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ + case 0x2000: /* EN QUAD */ + case 0x2001: /* EM QUAD */ + case 0x2002: /* EN SPACE */ + case 0x2003: /* EM SPACE */ + case 0x2004: /* THREE-PER-EM SPACE */ + case 0x2005: /* FOUR-PER-EM SPACE */ + case 0x2006: /* SIX-PER-EM SPACE */ + case 0x2007: /* FIGURE SPACE */ + case 0x2008: /* PUNCTUATION SPACE */ + case 0x2009: /* THIN SPACE */ + case 0x200A: /* HAIR SPACE */ + case 0x202f: /* NARROW NO-BREAK SPACE */ + case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ + case 0x3000: /* IDEOGRAPHIC SPACE */ + RRETURN(MATCH_NOMATCH); + } + } + break; + + case OP_HSPACE: + for (i = 1; i <= min; i++) + { + if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); + GETCHARINC(c, eptr); + switch(c) + { + default: RRETURN(MATCH_NOMATCH); + case 0x09: /* HT */ + case 0x20: /* SPACE */ + case 0xa0: /* NBSP */ + case 0x1680: /* OGHAM SPACE MARK */ + case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ + case 0x2000: /* EN QUAD */ + case 0x2001: /* EM QUAD */ + case 0x2002: /* EN SPACE */ + case 0x2003: /* EM SPACE */ + case 0x2004: /* THREE-PER-EM SPACE */ + case 0x2005: /* FOUR-PER-EM SPACE */ + case 0x2006: /* SIX-PER-EM SPACE */ + case 0x2007: /* FIGURE SPACE */ + case 0x2008: /* PUNCTUATION SPACE */ + case 0x2009: /* THIN SPACE */ + case 0x200A: /* HAIR SPACE */ + case 0x202f: /* NARROW NO-BREAK SPACE */ + case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ + case 0x3000: /* IDEOGRAPHIC SPACE */ + break; + } + } + break; + + case OP_NOT_VSPACE: + for (i = 1; i <= min; i++) + { + if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); + GETCHARINC(c, eptr); + switch(c) + { + default: break; + case 0x0a: /* LF */ + case 0x0b: /* VT */ + case 0x0c: /* FF */ + case 0x0d: /* CR */ + case 0x85: /* NEL */ + case 0x2028: /* LINE SEPARATOR */ + case 0x2029: /* PARAGRAPH SEPARATOR */ + RRETURN(MATCH_NOMATCH); + } + } + break; + + case OP_VSPACE: + for (i = 1; i <= min; i++) + { + if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); + GETCHARINC(c, eptr); + switch(c) + { + default: RRETURN(MATCH_NOMATCH); + case 0x0a: /* LF */ + case 0x0b: /* VT */ + case 0x0c: /* FF */ + case 0x0d: /* CR */ + case 0x85: /* NEL */ + case 0x2028: /* LINE SEPARATOR */ + case 0x2029: /* PARAGRAPH SEPARATOR */ + break; + } + } + break; + case OP_NOT_DIGIT: for (i = 1; i <= min; i++) { @@ -2648,9 +3099,9 @@ for (;;) for (i = 1; i <= min; i++) { if (eptr >= md->end_subject || - (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0)) + (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)) RRETURN(MATCH_NOMATCH); - while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; + while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80); } break; @@ -2668,9 +3119,9 @@ for (;;) for (i = 1; i <= min; i++) { if (eptr >= md->end_subject || - (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0)) + (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)) RRETURN(MATCH_NOMATCH); - while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; + while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80); } break; @@ -2692,7 +3143,8 @@ for (;;) #endif /* SUPPORT_UTF8 */ /* Code for the non-UTF-8 case for minimum matching of operators other - than OP_PROP and OP_NOTPROP. */ + than OP_PROP and OP_NOTPROP. We can assume that there are the minimum + number of bytes present, as this was tested above. */ switch(ctype) { @@ -2701,8 +3153,7 @@ for (;;) { for (i = 1; i <= min; i++) { - if (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr)) - RRETURN(MATCH_NOMATCH); + if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); eptr++; } } @@ -2713,6 +3164,95 @@ for (;;) eptr += min; break; + /* Because of the CRLF case, we can't assume the minimum number of + bytes are present in this case. */ + + case OP_ANYNL: + for (i = 1; i <= min; i++) + { + if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); + switch(*eptr++) + { + default: RRETURN(MATCH_NOMATCH); + case 0x000d: + if (eptr < md->end_subject && *eptr == 0x0a) eptr++; + break; + case 0x000a: + break; + + case 0x000b: + case 0x000c: + case 0x0085: + if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); + break; + } + } + break; + + case OP_NOT_HSPACE: + for (i = 1; i <= min; i++) + { + if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); + switch(*eptr++) + { + default: break; + case 0x09: /* HT */ + case 0x20: /* SPACE */ + case 0xa0: /* NBSP */ + RRETURN(MATCH_NOMATCH); + } + } + break; + + case OP_HSPACE: + for (i = 1; i <= min; i++) + { + if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); + switch(*eptr++) + { + default: RRETURN(MATCH_NOMATCH); + case 0x09: /* HT */ + case 0x20: /* SPACE */ + case 0xa0: /* NBSP */ + break; + } + } + break; + + case OP_NOT_VSPACE: + for (i = 1; i <= min; i++) + { + if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); + switch(*eptr++) + { + default: break; + case 0x0a: /* LF */ + case 0x0b: /* VT */ + case 0x0c: /* FF */ + case 0x0d: /* CR */ + case 0x85: /* NEL */ + RRETURN(MATCH_NOMATCH); + } + } + break; + + case OP_VSPACE: + for (i = 1; i <= min; i++) + { + if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); + switch(*eptr++) + { + default: RRETURN(MATCH_NOMATCH); + case 0x0a: /* LF */ + case 0x0b: /* VT */ + case 0x0c: /* FF */ + case 0x0d: /* CR */ + case 0x85: /* NEL */ + break; + } + } + break; + case OP_NOT_DIGIT: for (i = 1; i <= min; i++) if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH); @@ -2768,18 +3308,18 @@ for (;;) case PT_ANY: for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); GETCHARINC(c, eptr); if (prop_fail_result) RRETURN(MATCH_NOMATCH); } - break; + /* Control never gets here */ case PT_LAMP: for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); GETCHARINC(c, eptr); @@ -2789,12 +3329,12 @@ for (;;) prop_chartype == ucp_Lt) == prop_fail_result) RRETURN(MATCH_NOMATCH); } - break; + /* Control never gets here */ case PT_GC: for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); GETCHARINC(c, eptr); @@ -2802,12 +3342,12 @@ for (;;) if ((prop_category == prop_value) == prop_fail_result) RRETURN(MATCH_NOMATCH); } - break; + /* Control never gets here */ case PT_PC: for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); GETCHARINC(c, eptr); @@ -2815,12 +3355,12 @@ for (;;) if ((prop_chartype == prop_value) == prop_fail_result) RRETURN(MATCH_NOMATCH); } - break; + /* Control never gets here */ case PT_SC: for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); GETCHARINC(c, eptr); @@ -2828,11 +3368,10 @@ for (;;) if ((prop_script == prop_value) == prop_fail_result) RRETURN(MATCH_NOMATCH); } - break; + /* Control never gets here */ default: RRETURN(PCRE_ERROR_INTERNAL); - break; } } @@ -2843,7 +3382,7 @@ for (;;) { for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH); GETCHARINCTEST(c, eptr); @@ -2872,11 +3411,11 @@ for (;;) { for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (fi >= max || eptr >= md->end_subject || (ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 && - eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))) + IS_NEWLINE(eptr))) RRETURN(MATCH_NOMATCH); GETCHARINC(c, eptr); @@ -2888,6 +3427,110 @@ for (;;) case OP_ANYBYTE: break; + case OP_ANYNL: + switch(c) + { + default: RRETURN(MATCH_NOMATCH); + case 0x000d: + if (eptr < md->end_subject && *eptr == 0x0a) eptr++; + break; + case 0x000a: + break; + + case 0x000b: + case 0x000c: + case 0x0085: + case 0x2028: + case 0x2029: + if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); + break; + } + break; + + case OP_NOT_HSPACE: + switch(c) + { + default: break; + case 0x09: /* HT */ + case 0x20: /* SPACE */ + case 0xa0: /* NBSP */ + case 0x1680: /* OGHAM SPACE MARK */ + case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ + case 0x2000: /* EN QUAD */ + case 0x2001: /* EM QUAD */ + case 0x2002: /* EN SPACE */ + case 0x2003: /* EM SPACE */ + case 0x2004: /* THREE-PER-EM SPACE */ + case 0x2005: /* FOUR-PER-EM SPACE */ + case 0x2006: /* SIX-PER-EM SPACE */ + case 0x2007: /* FIGURE SPACE */ + case 0x2008: /* PUNCTUATION SPACE */ + case 0x2009: /* THIN SPACE */ + case 0x200A: /* HAIR SPACE */ + case 0x202f: /* NARROW NO-BREAK SPACE */ + case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ + case 0x3000: /* IDEOGRAPHIC SPACE */ + RRETURN(MATCH_NOMATCH); + } + break; + + case OP_HSPACE: + switch(c) + { + default: RRETURN(MATCH_NOMATCH); + case 0x09: /* HT */ + case 0x20: /* SPACE */ + case 0xa0: /* NBSP */ + case 0x1680: /* OGHAM SPACE MARK */ + case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ + case 0x2000: /* EN QUAD */ + case 0x2001: /* EM QUAD */ + case 0x2002: /* EN SPACE */ + case 0x2003: /* EM SPACE */ + case 0x2004: /* THREE-PER-EM SPACE */ + case 0x2005: /* FOUR-PER-EM SPACE */ + case 0x2006: /* SIX-PER-EM SPACE */ + case 0x2007: /* FIGURE SPACE */ + case 0x2008: /* PUNCTUATION SPACE */ + case 0x2009: /* THIN SPACE */ + case 0x200A: /* HAIR SPACE */ + case 0x202f: /* NARROW NO-BREAK SPACE */ + case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ + case 0x3000: /* IDEOGRAPHIC SPACE */ + break; + } + break; + + case OP_NOT_VSPACE: + switch(c) + { + default: break; + case 0x0a: /* LF */ + case 0x0b: /* VT */ + case 0x0c: /* FF */ + case 0x0d: /* CR */ + case 0x85: /* NEL */ + case 0x2028: /* LINE SEPARATOR */ + case 0x2029: /* PARAGRAPH SEPARATOR */ + RRETURN(MATCH_NOMATCH); + } + break; + + case OP_VSPACE: + switch(c) + { + default: RRETURN(MATCH_NOMATCH); + case 0x0a: /* LF */ + case 0x0b: /* VT */ + case 0x0c: /* FF */ + case 0x0d: /* CR */ + case 0x85: /* NEL */ + case 0x2028: /* LINE SEPARATOR */ + case 0x2029: /* PARAGRAPH SEPARATOR */ + break; + } + break; + case OP_NOT_DIGIT: if (c < 256 && (md->ctypes[c] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH); @@ -2929,11 +3572,10 @@ for (;;) { for (fi = min;; fi++) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (fi >= max || eptr >= md->end_subject || - ((ims & PCRE_DOTALL) == 0 && - eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))) + ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr))) RRETURN(MATCH_NOMATCH); c = *eptr++; @@ -2945,6 +3587,73 @@ for (;;) case OP_ANYBYTE: break; + case OP_ANYNL: + switch(c) + { + default: RRETURN(MATCH_NOMATCH); + case 0x000d: + if (eptr < md->end_subject && *eptr == 0x0a) eptr++; + break; + + case 0x000a: + break; + + case 0x000b: + case 0x000c: + case 0x0085: + if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH); + break; + } + break; + + case OP_NOT_HSPACE: + switch(c) + { + default: break; + case 0x09: /* HT */ + case 0x20: /* SPACE */ + case 0xa0: /* NBSP */ + RRETURN(MATCH_NOMATCH); + } + break; + + case OP_HSPACE: + switch(c) + { + default: RRETURN(MATCH_NOMATCH); + case 0x09: /* HT */ + case 0x20: /* SPACE */ + case 0xa0: /* NBSP */ + break; + } + break; + + case OP_NOT_VSPACE: + switch(c) + { + default: break; + case 0x0a: /* LF */ + case 0x0b: /* VT */ + case 0x0c: /* FF */ + case 0x0d: /* CR */ + case 0x85: /* NEL */ + RRETURN(MATCH_NOMATCH); + } + break; + + case OP_VSPACE: + switch(c) + { + default: RRETURN(MATCH_NOMATCH); + case 0x0a: /* LF */ + case 0x0b: /* VT */ + case 0x0c: /* FF */ + case 0x0d: /* CR */ + case 0x85: /* NEL */ + break; + } + break; + case OP_NOT_DIGIT: if ((md->ctypes[c] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH); break; @@ -2977,7 +3686,7 @@ for (;;) /* Control never gets here */ } - /* If maximizing it is worth using inline code for speed, doing the type + /* If maximizing, it is worth using inline code for speed, doing the type test once at the start (i.e. keep it out of the loop). Again, keep the UTF-8 and UCP stuff separate. */ @@ -3058,12 +3767,13 @@ for (;;) /* eptr is now past the end of the maximum run */ + if (possessive) continue; for(;;) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (eptr-- == pp) break; /* Stop if tried at original pos */ - BACKCHAR(eptr); + if (utf8) BACKCHAR(eptr); } } @@ -3093,17 +3803,18 @@ for (;;) /* eptr is now past the end of the maximum run */ + if (possessive) continue; for(;;) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (eptr-- == pp) break; /* Stop if tried at original pos */ for (;;) /* Move back over one extended */ { int len = 1; - BACKCHAR(eptr); if (!utf8) c = *eptr; else { + BACKCHAR(eptr); GETCHARLEN(c, eptr, len); } prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script); @@ -3124,20 +3835,13 @@ for (;;) switch(ctype) { case OP_ANY: - - /* Special code is required for UTF8, but when the maximum is - unlimited we don't need it, so we repeat the non-UTF8 code. This is - probably worth it, because .* is quite a common idiom. */ - if (max < INT_MAX) { if ((ims & PCRE_DOTALL) == 0) { for (i = min; i < max; i++) { - if (eptr >= md->end_subject || - (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))) - break; + if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break; eptr++; while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; } @@ -3161,18 +3865,14 @@ for (;;) { for (i = min; i < max; i++) { - if (eptr >= md->end_subject || - (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))) - break; + if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break; eptr++; + while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++; } - break; } else { - c = max - min; - if (c > md->end_subject - eptr) c = md->end_subject - eptr; - eptr += c; + eptr = md->end_subject; } } break; @@ -3181,10 +3881,98 @@ for (;;) case OP_ANYBYTE: c = max - min; - if (c > md->end_subject - eptr) c = md->end_subject - eptr; + if (c > (unsigned int)(md->end_subject - eptr)) + c = md->end_subject - eptr; eptr += c; break; + case OP_ANYNL: + for (i = min; i < max; i++) + { + int len = 1; + if (eptr >= md->end_subject) break; + GETCHARLEN(c, eptr, len); + if (c == 0x000d) + { + if (++eptr >= md->end_subject) break; + if (*eptr == 0x000a) eptr++; + } + else + { + if (c != 0x000a && + (md->bsr_anycrlf || + (c != 0x000b && c != 0x000c && + c != 0x0085 && c != 0x2028 && c != 0x2029))) + break; + eptr += len; + } + } + break; + + case OP_NOT_HSPACE: + case OP_HSPACE: + for (i = min; i < max; i++) + { + BOOL gotspace; + int len = 1; + if (eptr >= md->end_subject) break; + GETCHARLEN(c, eptr, len); + switch(c) + { + default: gotspace = FALSE; break; + case 0x09: /* HT */ + case 0x20: /* SPACE */ + case 0xa0: /* NBSP */ + case 0x1680: /* OGHAM SPACE MARK */ + case 0x180e: /* MONGOLIAN VOWEL SEPARATOR */ + case 0x2000: /* EN QUAD */ + case 0x2001: /* EM QUAD */ + case 0x2002: /* EN SPACE */ + case 0x2003: /* EM SPACE */ + case 0x2004: /* THREE-PER-EM SPACE */ + case 0x2005: /* FOUR-PER-EM SPACE */ + case 0x2006: /* SIX-PER-EM SPACE */ + case 0x2007: /* FIGURE SPACE */ + case 0x2008: /* PUNCTUATION SPACE */ + case 0x2009: /* THIN SPACE */ + case 0x200A: /* HAIR SPACE */ + case 0x202f: /* NARROW NO-BREAK SPACE */ + case 0x205f: /* MEDIUM MATHEMATICAL SPACE */ + case 0x3000: /* IDEOGRAPHIC SPACE */ + gotspace = TRUE; + break; + } + if (gotspace == (ctype == OP_NOT_HSPACE)) break; + eptr += len; + } + break; + + case OP_NOT_VSPACE: + case OP_VSPACE: + for (i = min; i < max; i++) + { + BOOL gotspace; + int len = 1; + if (eptr >= md->end_subject) break; + GETCHARLEN(c, eptr, len); + switch(c) + { + default: gotspace = FALSE; break; + case 0x0a: /* LF */ + case 0x0b: /* VT */ + case 0x0c: /* FF */ + case 0x0d: /* CR */ + case 0x85: /* NEL */ + case 0x2028: /* LINE SEPARATOR */ + case 0x2029: /* PARAGRAPH SEPARATOR */ + gotspace = TRUE; + break; + } + if (gotspace == (ctype == OP_NOT_VSPACE)) break; + eptr += len; + } + break; + case OP_NOT_DIGIT: for (i = min; i < max; i++) { @@ -3257,16 +4045,17 @@ for (;;) /* eptr is now past the end of the maximum run */ + if (possessive) continue; for(;;) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM46); if (rrc != MATCH_NOMATCH) RRETURN(rrc); if (eptr-- == pp) break; /* Stop if tried at original pos */ BACKCHAR(eptr); } } else -#endif +#endif /* SUPPORT_UTF8 */ /* Not UTF-8 mode */ { @@ -3277,9 +4066,7 @@ for (;;) { for (i = min; i < max; i++) { - if (eptr >= md->end_subject || - (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))) - break; + if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break; eptr++; } break; @@ -3288,10 +4075,74 @@ for (;;) case OP_ANYBYTE: c = max - min; - if (c > md->end_subject - eptr) c = md->end_subject - eptr; + if (c > (unsigned int)(md->end_subject - eptr)) + c = md->end_subject - eptr; eptr += c; break; + case OP_ANYNL: + for (i = min; i < max; i++) + { + if (eptr >= md->end_subject) break; + c = *eptr; + if (c == 0x000d) + { + if (++eptr >= md->end_subject) break; + if (*eptr == 0x000a) eptr++; + } + else + { + if (c != 0x000a && + (md->bsr_anycrlf || + (c != 0x000b && c != 0x000c && c != 0x0085))) + break; + eptr++; + } + } + break; + + case OP_NOT_HSPACE: + for (i = min; i < max; i++) + { + if (eptr >= md->end_subject) break; + c = *eptr; + if (c == 0x09 || c == 0x20 || c == 0xa0) break; + eptr++; + } + break; + + case OP_HSPACE: + for (i = min; i < max; i++) + { + if (eptr >= md->end_subject) break; + c = *eptr; + if (c != 0x09 && c != 0x20 && c != 0xa0) break; + eptr++; + } + break; + + case OP_NOT_VSPACE: + for (i = min; i < max; i++) + { + if (eptr >= md->end_subject) break; + c = *eptr; + if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85) + break; + eptr++; + } + break; + + case OP_VSPACE: + for (i = min; i < max; i++) + { + if (eptr >= md->end_subject) break; + c = *eptr; + if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85) + break; + eptr++; + } + break; + case OP_NOT_DIGIT: for (i = min; i < max; i++) { @@ -3352,9 +4203,10 @@ for (;;) /* eptr is now past the end of the maximum run */ + if (possessive) continue; while (eptr >= pp) { - RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0); + RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM47); eptr--; if (rrc != MATCH_NOMATCH) RRETURN(rrc); } @@ -3366,14 +4218,12 @@ for (;;) } /* Control never gets here */ - /* There's been some horrible disaster. Since all codes > OP_BRA are - for capturing brackets, and there shouldn't be any gaps between 0 and - OP_BRA, arrival here can only mean there is something seriously wrong - in the code above or the OP_xxx definitions. */ + /* There's been some horrible disaster. Arrival here can only mean there is + something seriously wrong in the code above or the OP_xxx definitions. */ default: DPRINTF(("Unknown opcode %d\n", *ecode)); - RRETURN(PCRE_ERROR_UNKNOWN_NODE); + RRETURN(PCRE_ERROR_UNKNOWN_OPCODE); } /* Do not stick any code in here without much thought; it is assumed @@ -3382,6 +4232,35 @@ for (;;) } /* End of main loop */ /* Control never reaches here */ + + +/* When compiling to use the heap rather than the stack for recursive calls to +match(), the RRETURN() macro jumps here. The number that is saved in +frame->Xwhere indicates which label we actually want to return to. */ + +#ifdef NO_RECURSE +#define LBL(val) case val: goto L_RM##val; +HEAP_RETURN: +switch (frame->Xwhere) + { + LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8) + LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17) + LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33) + LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52) + LBL(53) LBL(54) +#ifdef SUPPORT_UTF8 + LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30) + LBL(32) LBL(34) LBL(42) LBL(46) +#ifdef SUPPORT_UCP + LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45) +#endif /* SUPPORT_UCP */ +#endif /* SUPPORT_UTF8 */ + default: + DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere)); + return PCRE_ERROR_INTERNAL; + } +#undef LBL +#endif /* NO_RECURSE */ } @@ -3394,6 +4273,7 @@ Undefine all the macros that were define #ifdef NO_RECURSE #undef eptr #undef ecode +#undef mstart #undef offset_top #undef ims #undef eptrb @@ -3411,7 +4291,6 @@ Undefine all the macros that were define #undef cur_is_word #undef condition -#undef minimize #undef prev_is_word #undef original_ims @@ -3467,7 +4346,7 @@ Returns: > 0 => success; value < -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) @@ -3484,6 +4363,7 @@ BOOL req_byte_caseless = FALSE; BOOL firstline; BOOL first_byte_caseless = FALSE; BOOL req_byte_caseless = FALSE; +BOOL utf8; match_data match_block; match_data *md = &match_block; const uschar *tables; @@ -3553,7 +4433,7 @@ anchored = ((re->options | options) & PC /* Set up other data */ anchored = ((re->options | options) & PCRE_ANCHORED) != 0; -startline = (re->options & PCRE_STARTLINE) != 0; +startline = (re->flags & PCRE_STARTLINE) != 0; firstline = (re->options & PCRE_FIRSTLINE) != 0; /* The code starts after the real_pcre block and the capture name table. */ @@ -3567,7 +4447,7 @@ md->endonly = (re->options & PCRE_DOLLAR end_subject = md->end_subject; md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0; -md->utf8 = (re->options & PCRE_UTF8) != 0; +utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0; md->notbol = (options & PCRE_NOTBOL) != 0; md->noteol = (options & PCRE_NOTEOL) != 0; @@ -3580,42 +4460,83 @@ md->ctypes = tables + ctypes_offset; md->lcc = tables + lcc_offset; md->ctypes = tables + ctypes_offset; -/* Handle different types of newline. The two bits give four cases. If nothing -is set at run time, whatever was used at compile time applies. */ +/* Handle different \R options. */ -switch ((((options & PCRE_NEWLINE_CRLF) == 0)? re->options : options) & - PCRE_NEWLINE_CRLF) +switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) { - default: newline = NEWLINE; break; /* Compile-time default */ + case 0: + if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0) + md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0; + else +#ifdef BSR_ANYCRLF + md->bsr_anycrlf = TRUE; +#else + md->bsr_anycrlf = FALSE; +#endif + break; + + case PCRE_BSR_ANYCRLF: + md->bsr_anycrlf = TRUE; + break; + + case PCRE_BSR_UNICODE: + md->bsr_anycrlf = FALSE; + break; + + default: return PCRE_ERROR_BADNEWLINE; + } + +/* 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 : + (pcre_uint32)options) & PCRE_NEWLINE_BITS) + { + case 0: newline = NEWLINE; break; /* Compile-time default */ case PCRE_NEWLINE_CR: newline = '\r'; break; case PCRE_NEWLINE_LF: newline = '\n'; break; 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 > 255) +if (newline == -2) { - md->nllen = 2; - md->nl[0] = (newline >> 8) & 255; - md->nl[1] = newline & 255; + md->nltype = NLTYPE_ANYCRLF; } +else if (newline < 0) + { + md->nltype = NLTYPE_ANY; + } else { - md->nllen = 1; - md->nl[0] = newline; + md->nltype = NLTYPE_FIXED; + if (newline > 255) + { + md->nllen = 2; + md->nl[0] = (newline >> 8) & 255; + md->nl[1] = newline & 255; + } + else + { + md->nllen = 1; + md->nl[0] = newline; + } } /* Partial matching is supported only for a restricted set of regexes at the moment. */ -if (md->partial && (re->options & PCRE_NOPARTIAL) != 0) +if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0) return PCRE_ERROR_BADPARTIAL; /* Check a UTF-8 string if required. Unfortunately there's no way of passing back the character offset. */ #ifdef SUPPORT_UTF8 -if (md->utf8 && (options & PCRE_NO_UTF8_CHECK) == 0) +if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0) { if (_pcre_valid_utf8((uschar *)subject, length) >= 0) return PCRE_ERROR_BADUTF8; @@ -3685,7 +4606,7 @@ if (!anchored) if (!anchored) { - if ((re->options & PCRE_FIRSTSET) != 0) + if ((re->flags & PCRE_FIRSTSET) != 0) { first_byte = re->first_byte & 255; if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE) @@ -3700,19 +4621,23 @@ character" set. */ /* For anchored or unanchored matches, there may be a "last known required character" set. */ -if ((re->options & PCRE_REQCHSET) != 0) +if ((re->flags & PCRE_REQCHSET) != 0) { req_byte = re->req_byte & 255; req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0; req_byte2 = (tables + fcc_offset)[req_byte]; /* case flipped */ } + +/* ==========================================================================*/ + /* Loop for handling unanchored repeated matching attempts; for anchored regexs the loop runs just once. */ -do +for(;;) { USPTR save_end_subject = end_subject; + USPTR new_start_match; /* Reset the maximum number of extractions we might see. */ @@ -3725,14 +4650,14 @@ do /* Advance to a unique first char if possible. If firstline is TRUE, the start of the match is constrained to the first line of a multiline string. - Implement this by temporarily adjusting end_subject so that we stop scanning - at a newline. If the match fails at the newline, later code breaks this loop. - */ + That is, the match must be before or at the first newline. Implement this by + temporarily adjusting end_subject so that we stop scanning at a newline. If + the match fails at the newline, later code breaks this loop. */ if (firstline) { USPTR t = start_match; - while (t <= save_end_subject - md->nllen && !IS_NEWLINE(t)) t++; + while (t < md->end_subject && !IS_NEWLINE(t)) t++; end_subject = t; } @@ -3753,12 +4678,20 @@ do else if (startline) { - if (start_match >= md->start_subject + md->nllen + - start_offset) + if (start_match > md->start_subject + start_offset) { - while (start_match <= end_subject && - !IS_NEWLINE(start_match - md->nllen)) + 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++; } } @@ -3793,8 +4726,8 @@ do HOWEVER: when the subject string is very, very long, searching to its end can take a long time, and give bad performance on quite ordinary patterns. This - showed up when somebody was matching /^C/ on a 32-megabyte string... so we - don't do this when the string is sufficiently long. + showed up when somebody was matching something like /^\d+C/ on a 32-megabyte + string... so we don't do this when the string is sufficiently long. ALSO: this processing is disabled when partial matching is requested. */ @@ -3826,9 +4759,14 @@ do } } - /* If we can't find the required character, break the matching loop */ + /* If we can't find the required character, break the matching loop, + forcing a match failure. */ - if (p >= end_subject) break; + if (p >= end_subject) + { + rc = MATCH_NOMATCH; + break; + } /* If we have found the required character, save the point where we found it, so that we don't search again next time round the loop if @@ -3838,49 +4776,105 @@ do } } - /* When a match occurs, substrings will be set for all internal extractions; - we just need to set up the whole thing as substring 0 before returning. If - there were too many extractions, set the return code to zero. In the case - where we had to get some local store to hold offsets for backreferences, copy - those back references that we can. In this case there need not be overflow - if certain parts of the pattern were not used. */ + /* OK, we can now run the match. */ - md->start_match = start_match; + md->start_match_ptr = start_match; md->match_call_count = 0; + rc = match(start_match, md->start_code, start_match, 2, md, ims, NULL, 0, 0); - rc = match(start_match, md->start_code, 2, md, ims, NULL, match_isgroup, 0); + switch(rc) + { + /* NOMATCH and PRUNE advance by one character. THEN at this level acts + exactly like PRUNE. */ - /* When the result is no match, if the subject's first character was a - newline and the PCRE_FIRSTLINE option is set, break (which will return - PCRE_ERROR_NOMATCH). The option requests that a match occur before the first - newline in the subject. Otherwise, advance the pointer to the next character - and continue - but the continuation will actually happen only when the - pattern is not anchored. */ - - if (rc == MATCH_NOMATCH) - { - if (firstline && - start_match <= md->end_subject - md->nllen && - IS_NEWLINE(start_match)) - break; - start_match++; + case MATCH_NOMATCH: + case MATCH_PRUNE: + case MATCH_THEN: + new_start_match = start_match + 1; #ifdef SUPPORT_UTF8 - if (md->utf8) - while(start_match < end_subject && (*start_match & 0xc0) == 0x80) - start_match++; + if (utf8) + while(new_start_match < end_subject && (*new_start_match & 0xc0) == 0x80) + new_start_match++; #endif - continue; + break; + + /* SKIP passes back the next starting point explicitly. */ + + case MATCH_SKIP: + new_start_match = md->start_match_ptr; + break; + + /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */ + + case MATCH_COMMIT: + rc = MATCH_NOMATCH; + goto ENDLOOP; + + /* Any other return is some kind of error. */ + + default: + goto ENDLOOP; } - if (rc != MATCH_MATCH) - { - DPRINTF((">>>> error: returning %d\n", rc)); - return rc; - } + /* Control reaches here for the various types of "no match at this point" + result. Reset the code to MATCH_NOMATCH for subsequent checking. */ - /* We have a match! Copy the offset information from temporary store if - necessary */ + rc = MATCH_NOMATCH; + /* If PCRE_FIRSTLINE is set, the match must happen before or at the first + newline in the subject (though it may continue over the newline). Therefore, + if we have just failed to match, starting at a newline, do not continue. */ + + if (firstline && IS_NEWLINE(start_match)) break; + + /* Advance to new matching position */ + + start_match = new_start_match; + + /* Break the loop if the pattern is anchored or if we have passed the end of + the subject. */ + + if (anchored || start_match > end_subject) break; + + /* If we have just passed a CR and we are now at a LF, and the pattern does + not contain any explicit matches for \r or \n, and the newline option is CRLF + or ANY or ANYCRLF, advance the match position by one more character. */ + + if (start_match[-1] == '\r' && + start_match < end_subject && + *start_match == '\n' && + (re->flags & PCRE_HASCRORLF) == 0 && + (md->nltype == NLTYPE_ANY || + md->nltype == NLTYPE_ANYCRLF || + md->nllen == 2)) + start_match++; + + } /* End of for(;;) "bumpalong" loop */ + +/* ==========================================================================*/ + +/* We reach here when rc is not MATCH_NOMATCH, or if one of the stopping +conditions is true: + +(1) The pattern is anchored or the match was failed by (*COMMIT); + +(2) We are past the end of the subject; + +(3) PCRE_FIRSTLINE is set and we have failed to match at a newline, because + this option requests that a match occur at or before the first newline in + the subject. + +When we have a match and the offset vector is big enough to deal with any +backreferences, captured substring offsets will already be set up. In the case +where we had to get some local store to hold offsets for backreference +processing, copy those that we can. In this case there need not be overflow if +certain parts of the pattern were not used, even though there are more +capturing parentheses than vector slots. */ + +ENDLOOP: + +if (rc == MATCH_MATCH) + { if (using_temporary_offsets) { if (offsetcount >= 4) @@ -3889,18 +4883,23 @@ do (offsetcount - 2) * sizeof(int)); DPRINTF(("Copied offsets from temporary memory\n")); } - if (md->end_offset_top > offsetcount) - md->offset_overflow = TRUE; - + if (md->end_offset_top > offsetcount) md->offset_overflow = TRUE; DPRINTF(("Freeing temporary memory\n")); (pcre_free)(md->offset_vector); } + /* Set the return code to the number of captured strings, or 0 if there are + too many to fit into the vector. */ + rc = md->offset_overflow? 0 : md->end_offset_top/2; + /* If there is space, set up the whole thing as substring 0. The value of + md->start_match_ptr might be modified if \K was encountered on the success + matching path. */ + if (offsetcount < 2) rc = 0; else { - offsets[0] = start_match - md->start_subject; + offsets[0] = md->start_match_ptr - md->start_subject; offsets[1] = md->end_match_ptr - md->start_subject; } @@ -3908,18 +4907,22 @@ do return rc; } -/* This "while" is the end of the "do" above */ +/* Control gets here if there has been an error, or if the overall match +attempt has failed at all permitted starting positions. */ -while (!anchored && start_match <= end_subject); - if (using_temporary_offsets) { DPRINTF(("Freeing temporary memory\n")); (pcre_free)(md->offset_vector); } -if (md->partial && md->hitend) +if (rc != MATCH_NOMATCH) { + DPRINTF((">>>> error: returning %d\n", rc)); + return rc; + } +else if (md->partial && md->hitend) + { DPRINTF((">>>> returning PCRE_ERROR_PARTIAL\n")); return PCRE_ERROR_PARTIAL; } ============================================================ --- pcre/pcre_fullinfo.c 65c02930182c0ca0a12b7a2cd46cce76a0f89457 +++ pcre/pcre_fullinfo.c 3596c951b0cc5bb905d8ca91cba96161f39bb607 @@ -6,7 +6,7 @@ and semantics are as close as possible t and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel - Copyright (c) 1997-2006 University of Cambridge + Copyright (c) 1997-2007 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -42,6 +42,8 @@ information about a compiled pattern. */ information about a compiled pattern. */ +#include "pcre_config.h" + #include "pcre_internal.h" @@ -61,7 +63,7 @@ Returns: 0 if data returned, n Returns: 0 if data returned, negative on error */ -PCRE_DATA_SCOPE int +PCRE_EXP_DEFN int pcre_fullinfo(const pcre *argument_re, const pcre_extra *extra_data, int what, void *where) { @@ -106,8 +108,8 @@ switch (what) case PCRE_INFO_FIRSTBYTE: *((int *)where) = - ((re->options & PCRE_FIRSTSET) != 0)? re->first_byte : - ((re->options & PCRE_STARTLINE) != 0)? -1 : -2; + ((re->flags & PCRE_FIRSTSET) != 0)? re->first_byte : + ((re->flags & PCRE_STARTLINE) != 0)? -1 : -2; break; /* Make sure we pass back the pointer to the bit vector in the external @@ -121,7 +123,7 @@ switch (what) case PCRE_INFO_LASTLITERAL: *((int *)where) = - ((re->options & PCRE_REQCHSET) != 0)? re->req_byte : -1; + ((re->flags & PCRE_REQCHSET) != 0)? re->req_byte : -1; break; case PCRE_INFO_NAMEENTRYSIZE: @@ -140,6 +142,18 @@ switch (what) *((const uschar **)where) = (const uschar *)(_pcre_default_tables); break; + case PCRE_INFO_OKPARTIAL: + *((int *)where) = (re->flags & PCRE_NOPARTIAL) == 0; + break; + + case PCRE_INFO_JCHANGED: + *((int *)where) = (re->flags & PCRE_JCHANGED) != 0; + break; + + case PCRE_INFO_HASCRORLF: + *((int *)where) = (re->flags & PCRE_HASCRORLF) != 0; + break; + default: return PCRE_ERROR_BADOPTION; } ============================================================ --- pcre/pcre_get.c 4dd0a6df9fa0c3a4fb9a3356ad2b9623d9febf57 +++ pcre/pcre_get.c 8e8c912b9d50848a74761991314b6ea326b2464a @@ -6,7 +6,7 @@ and semantics are as close as possible t and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel - Copyright (c) 1997-2006 University of Cambridge + Copyright (c) 1997-2007 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -43,6 +43,8 @@ for these functions came from Scott Wime for these functions came from Scott Wimer. */ +#include "pcre_config.h" + #include "pcre_internal.h" @@ -185,7 +187,7 @@ uschar *entry; int entrysize; char *first, *last; uschar *entry; -if ((re->options & (PCRE_DUPNAMES | PCRE_JCHANGED)) == 0) +if ((re->options & PCRE_DUPNAMES) == 0 && (re->flags & PCRE_JCHANGED) == 0) return pcre_get_stringnumber(code, stringname); entrysize = pcre_get_stringtable_entries(code, stringname, &first, &last); if (entrysize <= 0) return entrysize; @@ -436,7 +438,6 @@ return pcre_get_substring(subject, ovect int n = get_first_set(code, stringname, ovector); if (n <= 0) return n; return pcre_get_substring(subject, ovector, stringcount, n, stringptr); - } ============================================================ --- pcre/pcre_globals.c 4a27067a587c5cd92ad9671107a3541f6429082c +++ pcre/pcre_globals.c 3cf49201069daca47dc593a2ef160fbb13610a69 @@ -6,7 +6,7 @@ and semantics are as close as possible t and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel - Copyright (c) 1997-2006 University of Cambridge + Copyright (c) 1997-2007 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -46,24 +46,16 @@ differently, and global variables are no all threads. However, when compiling for Virtual Pascal, things are done differently, and global variables are not used (see pcre.in). */ +#include "pcre_config.h" #include "pcre_internal.h" - #ifndef VPCOMPAT -#ifdef __cplusplus -extern "C" void *(*pcre_malloc)(size_t) = malloc; -extern "C" void (*pcre_free)(void *) = free; -extern "C" void *(*pcre_stack_malloc)(size_t) = malloc; -extern "C" void (*pcre_stack_free)(void *) = free; -extern "C" int (*pcre_callout)(pcre_callout_block *) = NULL; -#else -void *(*pcre_malloc)(size_t) = malloc; -void (*pcre_free)(void *) = free; -void *(*pcre_stack_malloc)(size_t) = malloc; -void (*pcre_stack_free)(void *) = free; -int (*pcre_callout)(pcre_callout_block *) = NULL; +PCRE_EXP_DATA_DEFN void *(*pcre_malloc)(size_t) = malloc; +PCRE_EXP_DATA_DEFN void (*pcre_free)(void *) = free; +PCRE_EXP_DATA_DEFN void *(*pcre_stack_malloc)(size_t) = malloc; +PCRE_EXP_DATA_DEFN void (*pcre_stack_free)(void *) = free; +PCRE_EXP_DATA_DEFN int (*pcre_callout)(pcre_callout_block *) = NULL; #endif -#endif /* End of pcre_globals.c */ ============================================================ --- pcre/pcre_info.c 14399144255ceaa0d09a0d16ef030e3dc91cff5b +++ pcre/pcre_info.c 004e534421480865060b938b75561b8e523beb2b @@ -6,7 +6,7 @@ and semantics are as close as possible t and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel - Copyright (c) 1997-2006 University of Cambridge + Copyright (c) 1997-2007 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -43,6 +43,8 @@ deprecated, as it has been superseded by deprecated, as it has been superseded by pcre_fullinfo(). */ +#include "pcre_config.h" + #include "pcre_internal.h" @@ -68,7 +70,7 @@ Returns: number of capturing subp or negative values on error */ -PCRE_DATA_SCOPE int +PCRE_EXP_DEFN int pcre_info(const pcre *argument_re, int *optptr, int *first_byte) { real_pcre internal_re; @@ -81,8 +83,8 @@ if (first_byte != NULL) } if (optptr != NULL) *optptr = (int)(re->options & PUBLIC_OPTIONS); if (first_byte != NULL) - *first_byte = ((re->options & PCRE_FIRSTSET) != 0)? re->first_byte : - ((re->options & PCRE_STARTLINE) != 0)? -1 : -2; + *first_byte = ((re->flags & PCRE_FIRSTSET) != 0)? re->first_byte : + ((re->flags & PCRE_STARTLINE) != 0)? -1 : -2; return re->top_bracket; } ============================================================ --- pcre/pcre_internal.h d6b78d25230e9f7d3cdf183f2fb45b6de45dc062 +++ pcre/pcre_internal.h 787e957bffa8995e75e15a2a1c17befc5d570cdc @@ -7,7 +7,7 @@ and semantics are as close as possible t and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel - Copyright (c) 1997-2006 University of Cambridge + Copyright (c) 1997-2007 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -54,19 +54,19 @@ pre-processor statements, or at least th /* Use a macro for debugging printing, 'cause that eliminates the use of #ifdef inline, and there are *still* stupid compilers about that don't like indented pre-processor statements, or at least there were when I first wrote this. After -all, it had only been about 10 years then... */ +all, it had only been about 10 years then... +It turns out that the Mac Debugging.h header also defines the macro DPRINTF, so +be absolutely sure we get our version. */ + +#undef DPRINTF #ifdef DEBUG #define DPRINTF(p) printf p #else -#define DPRINTF(p) /*nothing*/ +#define DPRINTF(p) /* Nothing */ #endif -/* Get the definitions provided by running "configure" */ - -#include "pcre_config.h" - /* Standard C headers plus the external interface definition. The only time setjmp and stdarg are used is when NO_RECURSE is set. */ @@ -79,8 +79,57 @@ setjmp and stdarg are used is when NO_RE #include #include -#ifndef PCRE_SPY -#define PCRE_DEFINITION /* Win32 __declspec(export) trigger for .dll */ +/* When compiling a DLL for Windows, the exported symbols have to be declared +using some MS magic. I found some useful information on this web page: +http://msdn2.microsoft.com/en-us/library/y4h7bcy6(VS.80).aspx. According to the +information there, using __declspec(dllexport) without "extern" we have a +definition; with "extern" we have a declaration. The settings here override the +setting in pcre.h (which is included below); it defines only PCRE_EXP_DECL, +which is all that is needed for applications (they just import the symbols). We +use: + + PCRE_EXP_DECL for declarations + PCRE_EXP_DEFN for definitions of exported functions + PCRE_EXP_DATA_DEFN for definitions of exported variables + +The reason for the two DEFN macros is that in non-Windows environments, one +does not want to have "extern" before variable definitions because it leads to +compiler warnings. So we distinguish between functions and variables. In +Windows, the two should always be the same. + +The reason for wrapping this in #ifndef PCRE_EXP_DECL is so that pcretest, +which is an application, but needs to import this file in order to "peek" at +internals, can #include pcre.h first to get an application's-eye view. + +In principle, people compiling for non-Windows, non-Unix-like (i.e. uncommon, +special-purpose environments) might want to stick other stuff in front of +exported symbols. That's why, in the non-Windows case, we set PCRE_EXP_DEFN and +PCRE_EXP_DATA_DEFN only if they are not already set. */ + +#ifndef PCRE_EXP_DECL +# ifdef _WIN32 +# ifndef PCRE_STATIC +# define PCRE_EXP_DECL extern __declspec(dllexport) +# define PCRE_EXP_DEFN __declspec(dllexport) +# define PCRE_EXP_DATA_DEFN __declspec(dllexport) +# else +# define PCRE_EXP_DECL extern +# define PCRE_EXP_DEFN +# define PCRE_EXP_DATA_DEFN +# endif +# else +# ifdef __cplusplus +# define PCRE_EXP_DECL extern "C" +# else +# define PCRE_EXP_DECL extern +# endif +# ifndef PCRE_EXP_DEFN +# define PCRE_EXP_DEFN PCRE_EXP_DECL +# endif +# ifndef PCRE_EXP_DATA_DEFN +# define PCRE_EXP_DATA_DEFN +# endif +# endif #endif /* We need to have types that specify unsigned 16-bit and 32-bit integers. We @@ -114,14 +163,50 @@ typedef unsigned char uschar; typedef unsigned char uschar; -/* PCRE is able to support 3 different kinds of newline (CR, LF, CRLF). The -following macro is used to package up testing for newlines. NLBLOCK is defined -in the various modules to indicate in which datablock the parameters exist. */ +/* This is an unsigned int value that no character can ever have. UTF-8 +characters only go up to 0x7fffffff (though Unicode doesn't go beyond +0x0010ffff). */ +#define NOTACHAR 0xffffffff + +/* PCRE is able to support several different kinds of newline (CR, LF, CRLF, +"any" and "anycrlf" at present). The following macros are used to package up +testing for newlines. NLBLOCK, PSSTART, and PSEND are defined in the various +modules to indicate in which datablock the parameters exist, and what the +start/end of string field names are. */ + +#define NLTYPE_FIXED 0 /* Newline is a fixed length string */ +#define NLTYPE_ANY 1 /* Newline is any Unicode line ending */ +#define NLTYPE_ANYCRLF 2 /* Newline is CR, LF, or CRLF */ + +/* This macro checks for a newline at the given position */ + #define IS_NEWLINE(p) \ - ((p)[0] == NLBLOCK->nl[0] && \ - (NLBLOCK->nllen == 1 || (p)[1] == NLBLOCK->nl[1])) + ((NLBLOCK->nltype != NLTYPE_FIXED)? \ + ((p) < NLBLOCK->PSEND && \ + _pcre_is_newline((p), NLBLOCK->nltype, NLBLOCK->PSEND, &(NLBLOCK->nllen),\ + utf8)) \ + : \ + ((p) <= NLBLOCK->PSEND - NLBLOCK->nllen && \ + (p)[0] == NLBLOCK->nl[0] && \ + (NLBLOCK->nllen == 1 || (p)[1] == NLBLOCK->nl[1]) \ + ) \ + ) +/* This macro checks for a newline immediately preceding the given position */ + +#define WAS_NEWLINE(p) \ + ((NLBLOCK->nltype != NLTYPE_FIXED)? \ + ((p) > NLBLOCK->PSSTART && \ + _pcre_was_newline((p), NLBLOCK->nltype, NLBLOCK->PSSTART, \ + &(NLBLOCK->nllen), utf8)) \ + : \ + ((p) >= NLBLOCK->PSSTART + NLBLOCK->nllen && \ + (p)[-NLBLOCK->nllen] == NLBLOCK->nl[0] && \ + (NLBLOCK->nllen == 1 || (p)[-NLBLOCK->nllen+1] == NLBLOCK->nl[1]) \ + ) \ + ) + /* When PCRE is compiled as a C++ library, the subject pointer can be replaced with a custom type. This makes it possible, for example, to allow pcre_exec() to process subject strings that are discontinuous by using a smart pointer @@ -139,20 +224,22 @@ must begin with PCRE_. */ #define USPTR const unsigned char * #endif + + /* Include the public PCRE header and the definitions of UCP character property values. */ #include "pcre.h" -#ifdef SUPPORT_UCP #include "ucp.h" -#endif /* When compiling for use with the Virtual Pascal compiler, these functions need to have their names changed. PCRE must be compiled with the -DVPCOMPAT option on the command line. */ #ifdef VPCOMPAT +#define strlen(s) _strlen(s) #define strncmp(s1,s2,m) _strncmp(s1,s2,m) +#define memcmp(s,c,n) _memcmp(s,c,n) #define memcpy(d,s,n) _memcpy(d,s,n) #define memmove(d,s,n) _memmove(d,s,n) #define memset(s,c,n) _memset(s,c,n) @@ -161,23 +248,31 @@ is set. Otherwise, include an emulating /* To cope with SunOS4 and other systems that lack memmove() but have bcopy(), define a macro for memmove() if HAVE_MEMMOVE is false, provided that HAVE_BCOPY is set. Otherwise, include an emulating function for those systems that have -neither (there some non-Unix environments where this is the case). This assumes -that all calls to memmove are moving strings upwards in store, which is the -case in PCRE. */ +neither (there some non-Unix environments where this is the case). */ -#if ! HAVE_MEMMOVE +#ifndef HAVE_MEMMOVE #undef memmove /* some systems may have a macro */ -#if HAVE_BCOPY +#ifdef HAVE_BCOPY #define memmove(a, b, c) bcopy(b, a, c) #else /* HAVE_BCOPY */ static void * -pcre_memmove(unsigned char *dest, const unsigned char *src, size_t n) +pcre_memmove(void *d, const void *s, size_t n) { size_t i; -dest += n; -src += n; -for (i = 0; i < n; ++i) *(--dest) = *(--src); -return dest; +unsigned char *dest = (unsigned char *)d; +const unsigned char *src = (const unsigned char *)s; +if (dest > src) + { + dest += n; + src += n; + for (i = 0; i < n; ++i) *(--dest) = *(--src); + return (void *)dest; + } +else + { + for (i = 0; i < n; ++i) *dest++ = *src++; + return (void *)(dest - n); + } } #define memmove(a, b, c) pcre_memmove(a, b, c) #endif /* not HAVE_BCOPY */ @@ -263,7 +358,9 @@ byte. The macros for character handling /* When UTF-8 encoding is being used, a character is no longer just a single byte. The macros for character handling generate simple sequences when used in -byte-mode, and more complicated ones for UTF-8 characters. */ +byte-mode, and more complicated ones for UTF-8 characters. BACKCHAR should +never be called in byte mode. To make sure it can never even appear when UTF-8 +support is omitted, we don't even define it. */ #ifndef SUPPORT_UTF8 #define GETCHAR(c, eptr) c = *eptr; @@ -271,7 +368,7 @@ byte-mode, and more complicated ones for #define GETCHARINC(c, eptr) c = *eptr++; #define GETCHARINCTEST(c, eptr) c = *eptr++; #define GETCHARLEN(c, eptr, len) c = *eptr; -#define BACKCHAR(eptr) +/* #define BACKCHAR(eptr) */ #else /* SUPPORT_UTF8 */ @@ -280,7 +377,7 @@ we know we are in UTF-8 mode. */ #define GETCHAR(c, eptr) \ c = *eptr; \ - if ((c & 0xc0) == 0xc0) \ + if (c >= 0xc0) \ { \ int gcii; \ int gcaa = _pcre_utf8_table4[c & 0x3f]; /* Number of additional bytes */ \ @@ -298,7 +395,7 @@ pointer. */ #define GETCHARTEST(c, eptr) \ c = *eptr; \ - if (utf8 && (c & 0xc0) == 0xc0) \ + if (utf8 && c >= 0xc0) \ { \ int gcii; \ int gcaa = _pcre_utf8_table4[c & 0x3f]; /* Number of additional bytes */ \ @@ -316,7 +413,7 @@ know we are in UTF-8 mode. */ #define GETCHARINC(c, eptr) \ c = *eptr++; \ - if ((c & 0xc0) == 0xc0) \ + if (c >= 0xc0) \ { \ int gcaa = _pcre_utf8_table4[c & 0x3f]; /* Number of additional bytes */ \ int gcss = 6*gcaa; \ @@ -332,7 +429,7 @@ know we are in UTF-8 mode. */ #define GETCHARINCTEST(c, eptr) \ c = *eptr++; \ - if (utf8 && (c & 0xc0) == 0xc0) \ + if (utf8 && c >= 0xc0) \ { \ int gcaa = _pcre_utf8_table4[c & 0x3f]; /* Number of additional bytes */ \ int gcss = 6*gcaa; \ @@ -349,7 +446,7 @@ if there are extra bytes. This is called #define GETCHARLEN(c, eptr, len) \ c = *eptr; \ - if ((c & 0xc0) == 0xc0) \ + if (c >= 0xc0) \ { \ int gcii; \ int gcaa = _pcre_utf8_table4[c & 0x3f]; /* Number of additional bytes */ \ @@ -364,9 +461,10 @@ if there are extra bytes. This is called } /* If the pointer is not at the start of a character, move it back until -it is. Called only in UTF-8 mode. */ +it is. This is called only in UTF-8 mode - we don't put a test within the macro +because almost all calls are already within a block of UTF-8 only code. */ -#define BACKCHAR(eptr) while((*eptr & 0xc0) == 0x80) eptr--; +#define BACKCHAR(eptr) while((*eptr & 0xc0) == 0x80) eptr-- #endif @@ -383,17 +481,16 @@ Standard C system should have one. */ #define PCRE_IMS (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL) -/* Private options flags start at the most significant end of the four bytes. -The public options defined in pcre.h start at the least significant end. Make -sure they don't overlap! The bits are getting a bit scarce now -- when we run -out, there is a dummy word in the structure that could be used for the private -bits. */ +/* Private flags containing information about the compiled regex. They used to +live at the top end of the options word, but that got almost full, so now they +are in a 16-bit flags word. */ -#define PCRE_NOPARTIAL 0x80000000 /* can't use partial with this regex */ -#define PCRE_FIRSTSET 0x40000000 /* first_byte is set */ -#define PCRE_REQCHSET 0x20000000 /* req_byte is set */ -#define PCRE_STARTLINE 0x10000000 /* start after \n for multiline */ -#define PCRE_JCHANGED 0x08000000 /* j option changes within regex */ +#define PCRE_NOPARTIAL 0x0001 /* can't use partial with this regex */ +#define PCRE_FIRSTSET 0x0002 /* first_byte is set */ +#define PCRE_REQCHSET 0x0004 /* req_byte is set */ +#define PCRE_STARTLINE 0x0008 /* start after \n for multiline */ +#define PCRE_JCHANGED 0x0010 /* j option used in regex */ +#define PCRE_HASCRORLF 0x0020 /* explicit \r or \n in pattern */ /* Options for the "extra" block produced by pcre_study(). */ @@ -402,20 +499,23 @@ time, run time, or study time, respectiv /* Masks for identifying the public options that are permitted at compile time, run time, or study time, respectively. */ +#define PCRE_NEWLINE_BITS (PCRE_NEWLINE_CR|PCRE_NEWLINE_LF|PCRE_NEWLINE_ANY| \ + PCRE_NEWLINE_ANYCRLF) + #define PUBLIC_OPTIONS \ (PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \ PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY|PCRE_UTF8| \ PCRE_NO_AUTO_CAPTURE|PCRE_NO_UTF8_CHECK|PCRE_AUTO_CALLOUT|PCRE_FIRSTLINE| \ - PCRE_DUPNAMES|PCRE_NEWLINE_CR|PCRE_NEWLINE_LF) + PCRE_DUPNAMES|PCRE_NEWLINE_BITS|PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE) #define PUBLIC_EXEC_OPTIONS \ (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK| \ - PCRE_PARTIAL|PCRE_NEWLINE_CR|PCRE_NEWLINE_LF) + PCRE_PARTIAL|PCRE_NEWLINE_BITS|PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE) #define PUBLIC_DFA_EXEC_OPTIONS \ (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK| \ - PCRE_PARTIAL|PCRE_DFA_SHORTEST|PCRE_DFA_RESTART|PCRE_NEWLINE_CR| \ - PCRE_NEWLINE_LF) + PCRE_PARTIAL|PCRE_DFA_SHORTEST|PCRE_DFA_RESTART|PCRE_NEWLINE_BITS| \ + PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE) #define PUBLIC_STUDY_OPTIONS 0 /* None defined */ @@ -447,9 +547,7 @@ typedef int BOOL; #define FALSE 0 #define TRUE 1 -/* Escape items that are just an encoding of a particular data value. Note that -ESC_n is defined as yet another macro, which is set in config.h to either \n -(the default) or \r (which some people want). */ +/* Escape items that are just an encoding of a particular data value. */ #ifndef ESC_e #define ESC_e 27 @@ -460,7 +558,7 @@ ESC_n is defined as yet another macro, w #endif #ifndef ESC_n -#define ESC_n NEWLINE +#define ESC_n '\n' #endif #ifndef ESC_r @@ -499,22 +597,24 @@ corresponds to "." rather than an escape their negation. Also, they must appear in the same order as in the opcode definitions below, up to ESC_z. There's a dummy for OP_ANY because it corresponds to "." rather than an escape sequence. The final one must be -ESC_REF as subsequent values are used for \1, \2, \3, etc. There is are two -tests in the code for an escape greater than ESC_b and less than ESC_Z to -detect the types that may be repeated. These are the types that consume -characters. If any new escapes are put in between that don't consume a +ESC_REF as subsequent values are used for backreferences (\1, \2, \3, etc). +There are two tests in the code for an escape greater than ESC_b and less than +ESC_Z to detect the types that may be repeated. These are the types that +consume characters. If any new escapes are put in between that don't consume a character, that code will have to change. */ -enum { ESC_A = 1, ESC_G, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s, ESC_W, - ESC_w, ESC_dum1, ESC_C, ESC_P, ESC_p, ESC_X, ESC_Z, ESC_z, ESC_E, - ESC_Q, ESC_REF }; +enum { ESC_A = 1, ESC_G, ESC_K, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s, + ESC_W, ESC_w, ESC_dum1, ESC_C, ESC_P, ESC_p, ESC_R, ESC_H, ESC_h, + ESC_V, ESC_v, ESC_X, ESC_Z, ESC_z, ESC_E, ESC_Q, ESC_k, ESC_REF }; -/* Opcode table: OP_BRA must be last, as all values >= it are used for brackets -that extract substrings. Starting from 1 (i.e. after OP_END), the values up to + +/* Opcode table: Starting from 1 (i.e. after OP_END), the values up to OP_EOD must correspond in order to the list of escapes immediately above. -Note that whenever this list is updated, the two macro definitions that follow -must also be updated to match. */ +*** NOTE NOTE NOTE *** Whenever this list is updated, the two macro definitions +that follow must also be updated to match. There is also a table called +"coptable" in pcre_dfa_exec.c that must be updated. */ + enum { OP_END, /* 0 End of pattern */ @@ -522,141 +622,175 @@ enum { OP_SOD, /* 1 Start of data: \A */ OP_SOM, /* 2 Start of match (subject + offset): \G */ - OP_NOT_WORD_BOUNDARY, /* 3 \B */ - OP_WORD_BOUNDARY, /* 4 \b */ - OP_NOT_DIGIT, /* 5 \D */ - OP_DIGIT, /* 6 \d */ - OP_NOT_WHITESPACE, /* 7 \S */ - OP_WHITESPACE, /* 8 \s */ - OP_NOT_WORDCHAR, /* 9 \W */ - OP_WORDCHAR, /* 10 \w */ - OP_ANY, /* 11 Match any character */ - OP_ANYBYTE, /* 12 Match any byte (\C); different to OP_ANY for UTF-8 */ - OP_NOTPROP, /* 13 \P (not Unicode property) */ - OP_PROP, /* 14 \p (Unicode property) */ - OP_EXTUNI, /* 15 \X (extended Unicode sequence */ - OP_EODN, /* 16 End of data or \n at end of data: \Z. */ - OP_EOD, /* 17 End of data: \z */ + OP_SET_SOM, /* 3 Set start of match (\K) */ + OP_NOT_WORD_BOUNDARY, /* 4 \B */ + OP_WORD_BOUNDARY, /* 5 \b */ + OP_NOT_DIGIT, /* 6 \D */ + OP_DIGIT, /* 7 \d */ + OP_NOT_WHITESPACE, /* 8 \S */ + OP_WHITESPACE, /* 9 \s */ + OP_NOT_WORDCHAR, /* 10 \W */ + OP_WORDCHAR, /* 11 \w */ + OP_ANY, /* 12 Match any character */ + OP_ANYBYTE, /* 13 Match any byte (\C); different to OP_ANY for UTF-8 */ + OP_NOTPROP, /* 14 \P (not Unicode property) */ + OP_PROP, /* 15 \p (Unicode property) */ + OP_ANYNL, /* 16 \R (any newline sequence) */ + OP_NOT_HSPACE, /* 17 \H (not horizontal whitespace) */ + OP_HSPACE, /* 18 \h (horizontal whitespace) */ + OP_NOT_VSPACE, /* 19 \V (not vertical whitespace) */ + OP_VSPACE, /* 20 \v (vertical whitespace) */ + OP_EXTUNI, /* 21 \X (extended Unicode sequence */ + OP_EODN, /* 22 End of data or \n at end of data: \Z. */ + OP_EOD, /* 23 End of data: \z */ - OP_OPT, /* 18 Set runtime options */ - OP_CIRC, /* 19 Start of line - varies with multiline switch */ - OP_DOLL, /* 20 End of line - varies with multiline switch */ - OP_CHAR, /* 21 Match one character, casefully */ - OP_CHARNC, /* 22 Match one character, caselessly */ - OP_NOT, /* 23 Match one character, not the following one */ + OP_OPT, /* 24 Set runtime options */ + OP_CIRC, /* 25 Start of line - varies with multiline switch */ + OP_DOLL, /* 26 End of line - varies with multiline switch */ + OP_CHAR, /* 27 Match one character, casefully */ + OP_CHARNC, /* 28 Match one character, caselessly */ + OP_NOT, /* 29 Match one character, not the following one */ - OP_STAR, /* 24 The maximizing and minimizing versions of */ - OP_MINSTAR, /* 25 all these opcodes must come in pairs, with */ - OP_PLUS, /* 26 the minimizing one second. */ - OP_MINPLUS, /* 27 This first set applies to single characters */ - OP_QUERY, /* 28 */ - OP_MINQUERY, /* 29 */ - OP_UPTO, /* 30 From 0 to n matches */ - OP_MINUPTO, /* 31 */ - OP_EXACT, /* 32 Exactly n matches */ + OP_STAR, /* 30 The maximizing and minimizing versions of */ + OP_MINSTAR, /* 31 these six opcodes must come in pairs, with */ + OP_PLUS, /* 32 the minimizing one second. */ + OP_MINPLUS, /* 33 This first set applies to single characters.*/ + OP_QUERY, /* 34 */ + OP_MINQUERY, /* 35 */ - OP_NOTSTAR, /* 33 The maximizing and minimizing versions of */ - OP_NOTMINSTAR, /* 34 all these opcodes must come in pairs, with */ - OP_NOTPLUS, /* 35 the minimizing one second. */ - OP_NOTMINPLUS, /* 36 This set applies to "not" single characters */ - OP_NOTQUERY, /* 37 */ - OP_NOTMINQUERY, /* 38 */ - OP_NOTUPTO, /* 39 From 0 to n matches */ - OP_NOTMINUPTO, /* 40 */ - OP_NOTEXACT, /* 41 Exactly n matches */ + OP_UPTO, /* 36 From 0 to n matches */ + OP_MINUPTO, /* 37 */ + OP_EXACT, /* 38 Exactly n matches */ - OP_TYPESTAR, /* 42 The maximizing and minimizing versions of */ - OP_TYPEMINSTAR, /* 43 all these opcodes must come in pairs, with */ - OP_TYPEPLUS, /* 44 the minimizing one second. These codes must */ - OP_TYPEMINPLUS, /* 45 be in exactly the same order as those above. */ - OP_TYPEQUERY, /* 46 This set applies to character types such as \d */ - OP_TYPEMINQUERY, /* 47 */ - OP_TYPEUPTO, /* 48 From 0 to n matches */ - OP_TYPEMINUPTO, /* 49 */ - OP_TYPEEXACT, /* 50 Exactly n matches */ + OP_POSSTAR, /* 39 Possessified star */ + OP_POSPLUS, /* 40 Possessified plus */ + OP_POSQUERY, /* 41 Posesssified query */ + OP_POSUPTO, /* 42 Possessified upto */ - OP_CRSTAR, /* 51 The maximizing and minimizing versions of */ - OP_CRMINSTAR, /* 52 all these opcodes must come in pairs, with */ - OP_CRPLUS, /* 53 the minimizing one second. These codes must */ - OP_CRMINPLUS, /* 54 be in exactly the same order as those above. */ - OP_CRQUERY, /* 55 These are for character classes and back refs */ - OP_CRMINQUERY, /* 56 */ - OP_CRRANGE, /* 57 These are different to the three sets above. */ - OP_CRMINRANGE, /* 58 */ + OP_NOTSTAR, /* 43 The maximizing and minimizing versions of */ + OP_NOTMINSTAR, /* 44 these six opcodes must come in pairs, with */ + OP_NOTPLUS, /* 45 the minimizing one second. They must be in */ + OP_NOTMINPLUS, /* 46 exactly the same order as those above. */ + OP_NOTQUERY, /* 47 This set applies to "not" single characters. */ + OP_NOTMINQUERY, /* 48 */ - OP_CLASS, /* 59 Match a character class, chars < 256 only */ - OP_NCLASS, /* 60 Same, but the bitmap was created from a negative + OP_NOTUPTO, /* 49 From 0 to n matches */ + OP_NOTMINUPTO, /* 50 */ + OP_NOTEXACT, /* 51 Exactly n matches */ + + OP_NOTPOSSTAR, /* 52 Possessified versions */ + OP_NOTPOSPLUS, /* 53 */ + OP_NOTPOSQUERY, /* 54 */ + OP_NOTPOSUPTO, /* 55 */ + + OP_TYPESTAR, /* 56 The maximizing and minimizing versions of */ + OP_TYPEMINSTAR, /* 57 these six opcodes must come in pairs, with */ + OP_TYPEPLUS, /* 58 the minimizing one second. These codes must */ + OP_TYPEMINPLUS, /* 59 be in exactly the same order as those above. */ + OP_TYPEQUERY, /* 60 This set applies to character types such as \d */ + OP_TYPEMINQUERY, /* 61 */ + + OP_TYPEUPTO, /* 62 From 0 to n matches */ + OP_TYPEMINUPTO, /* 63 */ + OP_TYPEEXACT, /* 64 Exactly n matches */ + + OP_TYPEPOSSTAR, /* 65 Possessified versions */ + OP_TYPEPOSPLUS, /* 66 */ + OP_TYPEPOSQUERY, /* 67 */ + OP_TYPEPOSUPTO, /* 68 */ + + OP_CRSTAR, /* 69 The maximizing and minimizing versions of */ + OP_CRMINSTAR, /* 70 all these opcodes must come in pairs, with */ + OP_CRPLUS, /* 71 the minimizing one second. These codes must */ + OP_CRMINPLUS, /* 72 be in exactly the same order as those above. */ + OP_CRQUERY, /* 73 These are for character classes and back refs */ + OP_CRMINQUERY, /* 74 */ + OP_CRRANGE, /* 75 These are different to the three sets above. */ + OP_CRMINRANGE, /* 76 */ + + OP_CLASS, /* 77 Match a character class, chars < 256 only */ + OP_NCLASS, /* 78 Same, but the bitmap was created from a negative class - the difference is relevant only when a UTF-8 character > 255 is encountered. */ - OP_XCLASS, /* 61 Extended class for handling UTF-8 chars within the + OP_XCLASS, /* 79 Extended class for handling UTF-8 chars within the class. This does both positive and negative. */ - OP_REF, /* 62 Match a back reference */ - OP_RECURSE, /* 63 Match a numbered subpattern (possibly recursive) */ - OP_CALLOUT, /* 64 Call out to external function if provided */ + OP_REF, /* 80 Match a back reference */ + OP_RECURSE, /* 81 Match a numbered subpattern (possibly recursive) */ + OP_CALLOUT, /* 82 Call out to external function if provided */ - OP_ALT, /* 65 Start of alternation */ - OP_KET, /* 66 End of group that doesn't have an unbounded repeat */ - OP_KETRMAX, /* 67 These two must remain together and in this */ - OP_KETRMIN, /* 68 order. They are for groups the repeat for ever. */ + OP_ALT, /* 83 Start of alternation */ + OP_KET, /* 84 End of group that doesn't have an unbounded repeat */ + OP_KETRMAX, /* 85 These two must remain together and in this */ + OP_KETRMIN, /* 86 order. They are for groups the repeat for ever. */ - /* The assertions must come before ONCE and COND */ + /* The assertions must come before BRA, CBRA, ONCE, and COND.*/ - OP_ASSERT, /* 69 Positive lookahead */ - OP_ASSERT_NOT, /* 70 Negative lookahead */ - OP_ASSERTBACK, /* 71 Positive lookbehind */ - OP_ASSERTBACK_NOT, /* 72 Negative lookbehind */ - OP_REVERSE, /* 73 Move pointer back - used in lookbehind assertions */ + OP_ASSERT, /* 87 Positive lookahead */ + OP_ASSERT_NOT, /* 88 Negative lookahead */ + OP_ASSERTBACK, /* 89 Positive lookbehind */ + OP_ASSERTBACK_NOT, /* 90 Negative lookbehind */ + OP_REVERSE, /* 91 Move pointer back - used in lookbehind assertions */ - /* ONCE and COND must come after the assertions, with ONCE first, as there's - a test for >= ONCE for a subpattern that isn't an assertion. */ + /* ONCE, BRA, CBRA, and COND must come after the assertions, with ONCE first, + as there's a test for >= ONCE for a subpattern that isn't an assertion. */ - OP_ONCE, /* 74 Once matched, don't back up into the subpattern */ - OP_COND, /* 75 Conditional group */ - OP_CREF, /* 76 Used to hold an extraction string number (cond ref) */ + OP_ONCE, /* 92 Atomic group */ + OP_BRA, /* 93 Start of non-capturing bracket */ + OP_CBRA, /* 94 Start of capturing bracket */ + OP_COND, /* 95 Conditional group */ - OP_BRAZERO, /* 77 These two must remain together and in this */ - OP_BRAMINZERO, /* 78 order. */ + /* These three must follow the previous three, in the same order. There's a + check for >= SBRA to distinguish the two sets. */ - OP_BRANUMBER, /* 79 Used for extracting brackets whose number is greater - than can fit into an opcode. */ + OP_SBRA, /* 96 Start of non-capturing bracket, check empty */ + OP_SCBRA, /* 97 Start of capturing bracket, check empty */ + OP_SCOND, /* 98 Conditional group, check empty */ - OP_BRA /* 80 This and greater values are used for brackets that - extract substrings up to EXTRACT_BASIC_MAX. After - that, use is made of OP_BRANUMBER. */ -}; + OP_CREF, /* 99 Used to hold a capture number as condition */ + OP_RREF, /* 100 Used to hold a recursion number as condition */ + OP_DEF, /* 101 The DEFINE condition */ -/* WARNING WARNING WARNING: There is an implicit assumption in pcre.c and -study.c that all opcodes are less than 128 in value. This makes handling UTF-8 -character sequences easier. */ + OP_BRAZERO, /* 102 These two must remain together and in this */ + OP_BRAMINZERO, /* 103 order. */ -/* The highest extraction number before we have to start using additional -bytes. (Originally PCRE didn't have support for extraction counts highter than -this number.) The value is limited by the number of opcodes left after OP_BRA, -i.e. 255 - OP_BRA. We actually set it a bit lower to leave room for additional -opcodes. */ + /* These are backtracking control verbs */ -#define EXTRACT_BASIC_MAX 100 + OP_PRUNE, /* 104 */ + OP_SKIP, /* 105 */ + OP_THEN, /* 106 */ + OP_COMMIT, /* 107 */ + /* These are forced failure and success verbs */ + OP_FAIL, /* 108 */ + OP_ACCEPT /* 109 */ +}; + + /* This macro defines textual names for all the opcodes. These are used only for debugging. The macro is referenced only in pcre_printint.c. */ #define OP_NAME_LIST \ - "End", "\\A", "\\G", "\\B", "\\b", "\\D", "\\d", \ + "End", "\\A", "\\G", "\\K", "\\B", "\\b", "\\D", "\\d", \ "\\S", "\\s", "\\W", "\\w", "Any", "Anybyte", \ - "notprop", "prop", "extuni", \ - "\\Z", "\\z", \ + "notprop", "prop", "\\R", "\\H", "\\h", "\\V", "\\v", \ + "extuni", "\\Z", "\\z", \ "Opt", "^", "$", "char", "charnc", "not", \ "*", "*?", "+", "+?", "?", "??", "{", "{", "{", \ + "*+","++", "?+", "{", \ "*", "*?", "+", "+?", "?", "??", "{", "{", "{", \ + "*+","++", "?+", "{", \ "*", "*?", "+", "+?", "?", "??", "{", "{", "{", \ + "*+","++", "?+", "{", \ "*", "*?", "+", "+?", "?", "??", "{", "{", \ "class", "nclass", "xclass", "Ref", "Recurse", "Callout", \ "Alt", "Ket", "KetRmax", "KetRmin", "Assert", "Assert not", \ - "AssertB", "AssertB not", "Reverse", "Once", "Cond", "Cond ref",\ - "Brazero", "Braminzero", "Branumber", "Bra" + "AssertB", "AssertB not", "Reverse", \ + "Once", "Bra", "CBra", "Cond", "SBra", "SCBra", "SCond", \ + "Cond ref", "Cond rec", "Cond def", "Brazero", "Braminzero", \ + "*PRUNE", "*SKIP", "*THEN", "*COMMIT", "*FAIL", "*ACCEPT" /* This macro defines the length of fixed length operations in the compiled @@ -670,9 +804,11 @@ in UTF-8 mode. The code that uses this t #define OP_LENGTHS \ 1, /* End */ \ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* \A, \G, \B, \B, \D, \d, \S, \s, \W, \w */ \ + 1, 1, 1, 1, 1, /* \A, \G, \K, \B, \b */ \ + 1, 1, 1, 1, 1, 1, /* \D, \d, \S, \s, \W, \w */ \ 1, 1, /* Any, Anybyte */ \ 3, 3, 1, /* NOTPROP, PROP, EXTUNI */ \ + 1, 1, 1, 1, 1, /* \R, \H, \h, \V, \v */ \ 1, 1, 2, 1, 1, /* \Z, \z, Opt, ^, $ */ \ 2, /* Char - the minimum length */ \ 2, /* Charnc - the minimum length */ \ @@ -680,12 +816,15 @@ in UTF-8 mode. The code that uses this t /* Positive single-char repeats ** These are */ \ 2, 2, 2, 2, 2, 2, /* *, *?, +, +?, ?, ?? ** minima in */ \ 4, 4, 4, /* upto, minupto, exact ** UTF-8 mode */ \ + 2, 2, 2, 4, /* *+, ++, ?+, upto+ */ \ /* Negative single-char repeats - only for chars < 256 */ \ 2, 2, 2, 2, 2, 2, /* NOT *, *?, +, +?, ?, ?? */ \ 4, 4, 4, /* NOT upto, minupto, exact */ \ + 2, 2, 2, 4, /* Possessive *, +, ?, upto */ \ /* Positive type repeats */ \ 2, 2, 2, 2, 2, 2, /* Type *, *?, +, +?, ?, ?? */ \ 4, 4, 4, /* Type upto, minupto, exact */ \ + 2, 2, 2, 4, /* Possessive *+, ++, ?+, upto+ */ \ /* Character class & ref repeats */ \ 1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */ \ 5, 5, /* CRRANGE, CRMINRANGE */ \ @@ -704,17 +843,24 @@ in UTF-8 mode. The code that uses this t 1+LINK_SIZE, /* Assert behind */ \ 1+LINK_SIZE, /* Assert behind not */ \ 1+LINK_SIZE, /* Reverse */ \ - 1+LINK_SIZE, /* Once */ \ + 1+LINK_SIZE, /* ONCE */ \ + 1+LINK_SIZE, /* BRA */ \ + 3+LINK_SIZE, /* CBRA */ \ 1+LINK_SIZE, /* COND */ \ + 1+LINK_SIZE, /* SBRA */ \ + 3+LINK_SIZE, /* SCBRA */ \ + 1+LINK_SIZE, /* SCOND */ \ 3, /* CREF */ \ + 3, /* RREF */ \ + 1, /* DEF */ \ 1, 1, /* BRAZERO, BRAMINZERO */ \ - 3, /* BRANUMBER */ \ - 1+LINK_SIZE /* BRA */ \ + 1, 1, 1, 1, /* PRUNE, SKIP, THEN, COMMIT, */ \ + 1, 1 /* FAIL, ACCEPT */ -/* A magic value for OP_CREF to indicate the "in recursion" condition. */ +/* A magic value for OP_RREF to indicate the "any recursion" condition. */ -#define CREF_RECURSE 0xffff +#define RREF_ANY 0xffff /* Error code numbers. They are given names so that they can more easily be tracked. */ @@ -724,7 +870,8 @@ enum { ERR0, ERR1, ERR2, ERR3, ERR4, ERR20, ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR28, ERR29, ERR30, ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39, ERR40, ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49, - ERR50, ERR51 }; + ERR50, ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58, ERR59, + ERR60, ERR61 }; /* The real format of the start of the pcre block; the index of names and the code vector run on as long as necessary after the end. We store an explicit @@ -746,9 +893,9 @@ typedef struct real_pcre { typedef struct real_pcre { pcre_uint32 magic_number; pcre_uint32 size; /* Total that was malloced */ - pcre_uint32 options; - pcre_uint32 dummy1; /* For future use, maybe */ - + pcre_uint32 options; /* Public options */ + pcre_uint16 flags; /* Private flags */ + pcre_uint16 dummy1; /* For future use */ pcre_uint16 top_bracket; pcre_uint16 top_backref; pcre_uint16 first_byte; @@ -779,17 +926,24 @@ typedef struct compile_data { const uschar *fcc; /* Points to case-flipping table */ const uschar *cbits; /* Points to character type table */ const uschar *ctypes; /* Points to table of type maps */ + const uschar *start_workspace;/* The start of working space */ const uschar *start_code; /* The start of the compiled code */ const uschar *start_pattern; /* The start of the pattern */ + const uschar *end_pattern; /* The end of the pattern */ + uschar *hwm; /* High watermark of workspace */ uschar *name_table; /* The name/number table */ int names_found; /* Number of entries so far */ int name_entry_size; /* Size of each entry */ + int bracount; /* Count of capturing parens */ int top_backref; /* Maximum back reference */ unsigned int backref_map; /* Bitmap of low back refs */ + int external_options; /* External (initial) options */ + int external_flags; /* External flag bits to be set */ int req_varyopt; /* "After variable item" flag for reqbyte */ - BOOL nopartial; /* Set TRUE if partial won't work */ - int nllen; /* 1 or 2 for newline string length */ - uschar nl[4]; /* Newline string */ + BOOL had_accept; /* (*ACCEPT) encountered */ + int nltype; /* Newline type */ + int nllen; /* Newline string length */ + uschar nl[4]; /* Newline string when fixed length */ } compile_data; /* Structure for maintaining a chain of pointers to the currently incomplete @@ -807,21 +961,21 @@ typedef struct recursion_info { struct recursion_info *prevrec; /* Previous recursion record (or NULL) */ int group_num; /* Number of group that was called */ const uschar *after_call; /* "Return value": points after the call in the expr */ - USPTR save_start; /* Old value of md->start_match */ + USPTR save_start; /* Old value of mstart */ int *offset_save; /* Pointer to start of saved offsets */ int saved_max; /* Number of saved offsets */ } recursion_info; -/* When compiling in a mode that doesn't use recursive calls to match(), -a structure is used to remember local variables on the heap. It is defined in -pcre_exec.c, close to the match() function, so that it is easy to keep it in -step with any changes of local variable. However, the pointer to the current -frame must be saved in some "static" place over a longjmp(). We declare the -structure here so that we can put a pointer in the match_data structure. NOTE: -This isn't used for a "normal" compilation of pcre. */ +/* Structure for building a chain of data for holding the values of the subject +pointer at the start of each subpattern, so as to detect when an empty string +has been matched by a subpattern - to break infinite loops. */ -struct heapframe; +typedef struct eptrblock { + struct eptrblock *epb_prev; + USPTR epb_saved_eptr; +} eptrblock; + /* Structure for passing "static" information around between the functions doing traditional NFA matching, so that they are thread-safe. */ @@ -832,8 +986,9 @@ typedef struct match_data { int *offset_vector; /* Offset vector */ int offset_end; /* One past the end */ int offset_max; /* The maximum usable for return data */ - int nllen; /* 1 or 2 for newline string length */ - uschar nl[4]; /* Newline string */ + int nltype; /* Newline type */ + int nllen; /* Newline string length */ + uschar nl[4]; /* Newline string when fixed */ const uschar *lcc; /* Points to lower casing table */ const uschar *ctypes; /* Points to table of type maps */ BOOL offset_overflow; /* Set if too many extractions */ @@ -844,17 +999,19 @@ typedef struct match_data { BOOL notempty; /* Empty string match not wanted */ BOOL partial; /* PARTIAL flag */ BOOL hitend; /* Hit the end of the subject at some point */ + BOOL bsr_anycrlf; /* \R is just any CRLF, not full Unicode */ const uschar *start_code; /* For use when recursing */ USPTR start_subject; /* Start of the subject string */ USPTR end_subject; /* End of the subject string */ - USPTR start_match; /* Start of this match attempt */ + USPTR start_match_ptr; /* Start of matched string */ USPTR end_match_ptr; /* Subject position at end match */ int end_offset_top; /* Highwater mark at end of match */ int capture_last; /* Most recent capture number */ int start_offset; /* The start offset value */ + eptrblock *eptrchain; /* Chain of eptrblocks for tail recursions */ + int eptrn; /* Next free eptrblock */ recursion_info *recursive; /* Linked list of recursion data */ void *callout_data; /* To pass back to callouts */ - struct heapframe *thisframe; /* Used only when compiling for no recursion */ } match_data; /* A similar structure is used for the same purpose by the DFA matching @@ -867,8 +1024,9 @@ typedef struct dfa_match_data { const uschar *tables; /* Character tables */ int moptions; /* Match options */ int poptions; /* Pattern options */ - int nllen; /* 1 or 2 for newline string length */ - uschar nl[4]; /* Newline string */ + int nltype; /* Newline type */ + int nllen; /* Newline string length */ + uschar nl[4]; /* Newline string when fixed */ void *callout_data; /* To pass back to callouts */ } dfa_match_data; @@ -906,10 +1064,12 @@ total length. */ #define tables_length (ctypes_offset + 256) /* Layout of the UCP type table that translates property names into types and -codes. */ +codes. Each entry used to point directly to a name, but to reduce the number of +relocations in shared libraries, it now has an offset into a single string +instead. */ typedef struct { - const char *name; + pcre_uint16 name_offset; pcre_uint16 type; pcre_uint16 value; } ucp_type_table; @@ -927,6 +1087,7 @@ extern const int _pcre_utf8_table1_si extern const int _pcre_utf8_table1_size; +extern const char _pcre_utt_names[]; extern const ucp_type_table _pcre_utt[]; extern const int _pcre_utt_size; @@ -939,13 +1100,17 @@ sense, but are not part of the PCRE publ one of the exported public functions. They have to be "external" in the C sense, but are not part of the PCRE public API. */ -extern int _pcre_ord2utf8(int, uschar *); -extern real_pcre * _pcre_try_flipped(const real_pcre *, real_pcre *, - const pcre_study_data *, pcre_study_data *); -extern int _pcre_ucp_findprop(const unsigned int, int *, int *); -extern int _pcre_ucp_othercase(const int); -extern int _pcre_valid_utf8(const uschar *, int); -extern BOOL _pcre_xclass(int, const uschar *); +extern BOOL _pcre_is_newline(const uschar *, int, const uschar *, + int *, BOOL); +extern int _pcre_ord2utf8(int, uschar *); +extern real_pcre *_pcre_try_flipped(const real_pcre *, real_pcre *, + const pcre_study_data *, pcre_study_data *); +extern int _pcre_ucp_findprop(const unsigned int, int *, int *); +extern unsigned int _pcre_ucp_othercase(const unsigned int); +extern int _pcre_valid_utf8(const uschar *, int); +extern BOOL _pcre_was_newline(const uschar *, int, const uschar *, + int *, BOOL); +extern BOOL _pcre_xclass(int, const uschar *); #endif ============================================================ --- pcre/pcre_maketables.c 03f5e59dd47ef2874398251712ff6ee454d76d13 +++ pcre/pcre_maketables.c a5231ea973f291c3fe8f7f44534028794a3bb1da @@ -6,7 +6,7 @@ and semantics are as close as possible t and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel - Copyright (c) 1997-2006 University of Cambridge + Copyright (c) 1997-2007 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -45,7 +45,8 @@ compilation of dftables.c, in which case #ifndef DFTABLES -#include "pcre_internal.h" +# include "pcre_config.h" +# include "pcre_internal.h" #endif @@ -130,7 +131,7 @@ for (i = 0; i < 256; i++) meta-character, which in this sense is any character that terminates a run of data characters. */ - if (strchr("*+?{^.$|()[", i) != 0) x += ctype_meta; + if (strchr("\\*+?{^.$|()[", i) != 0) x += ctype_meta; *p++ = x; } ============================================================ --- pcre/pcre_refcount.c ebd0c3dfce2e8dc81a179e2b033364fcec82f55b +++ pcre/pcre_refcount.c 84e42bff9f54245918ff28b8e8fb23dc53fb0db9 @@ -6,7 +6,7 @@ and semantics are as close as possible t and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel - Copyright (c) 1997-2006 University of Cambridge + Copyright (c) 1997-2007 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -43,6 +43,9 @@ shared by different users. */ pattern data block. This might be helpful in applications where the block is shared by different users. */ + +#include "pcre_config.h" + #include "pcre_internal.h" @@ -63,7 +66,7 @@ Returns: the (possibly updated) c a negative error number */ -PCRE_DATA_SCOPE int +PCRE_EXP_DEFN int pcre_refcount(pcre *argument_re, int adjust) { real_pcre *re = (real_pcre *)argument_re; ============================================================ --- pcre/pcre_study.c 9a88f30ab85c1a4df719efb21352da8ec0ff0a60 +++ pcre/pcre_study.c 29605e98e732f8139fd1fedc6a5d7de268add456 @@ -6,7 +6,7 @@ and semantics are as close as possible t and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel - Copyright (c) 1997-2006 University of Cambridge + Copyright (c) 1997-2007 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -42,9 +42,16 @@ supporting functions. */ supporting functions. */ +#include "pcre_config.h" + #include "pcre_internal.h" +/* Returns from set_start_bits() */ + +enum { SSB_FAIL, SSB_DONE, SSB_CONTINUE }; + + /************************************************* * Set a bit and maybe its alternate case * *************************************************/ @@ -72,12 +79,16 @@ if (caseless && (cd->ctypes[c] & ctype_l /************************************************* -* Create bitmap of starting chars * +* Create bitmap of starting bytes * *************************************************/ -/* This function scans a compiled unanchored expression and attempts to build a -bitmap of the set of initial characters. If it can't, it returns FALSE. As time -goes by, we may be able to get more clever at doing this. +/* This function scans a compiled unanchored expression recursively and +attempts to build a bitmap of the set of possible starting bytes. As time goes +by, we may be able to get more clever at doing this. The SSB_CONTINUE return is +useful for parenthesized groups in patterns such as (a*)b where the group +provides some optional starting bytes but scanning must continue at the outer +level to find at least one mandatory byte. At the outermost level, this +function fails unless the result is SSB_DONE. Arguments: code points to an expression @@ -86,14 +97,17 @@ Arguments: utf8 TRUE if in UTF-8 mode cd the block with char table pointers -Returns: TRUE if table built, FALSE otherwise +Returns: SSB_FAIL => Failed to find any starting bytes + SSB_DONE => Found mandatory starting bytes + SSB_CONTINUE => Found optional starting bytes */ -static BOOL +static int set_start_bits(const uschar *code, uschar *start_bits, BOOL caseless, BOOL utf8, compile_data *cd) { register int c; +int yield = SSB_DONE; #if 0 /* ========================================================================= */ @@ -114,45 +128,69 @@ do do { - const uschar *tcode = code + 1 + LINK_SIZE; + const uschar *tcode = code + (((int)*code == OP_CBRA)? 3:1) + LINK_SIZE; BOOL try_next = TRUE; - while (try_next) + while (try_next) /* Loop for items in this branch */ { - /* If a branch starts with a bracket or a positive lookahead assertion, - recurse to set bits from within them. That's all for this branch. */ - - if ((int)*tcode >= OP_BRA || *tcode == OP_ASSERT) + int rc; + switch(*tcode) { - if (!set_start_bits(tcode, start_bits, caseless, utf8, cd)) - return FALSE; - try_next = FALSE; - } + /* Fail if we reach something we don't understand */ - else switch(*tcode) - { default: - return FALSE; + return SSB_FAIL; - /* Skip over callout */ + /* If we hit a bracket or a positive lookahead assertion, recurse to set + bits from within the subpattern. If it can't find anything, we have to + give up. If it finds some mandatory character(s), we are done for this + branch. Otherwise, carry on scanning after the subpattern. */ - case OP_CALLOUT: - tcode += 2 + 2*LINK_SIZE; + case OP_BRA: + case OP_SBRA: + case OP_CBRA: + case OP_SCBRA: + case OP_ONCE: + case OP_ASSERT: + rc = set_start_bits(tcode, start_bits, caseless, utf8, cd); + if (rc == SSB_FAIL) return SSB_FAIL; + if (rc == SSB_DONE) try_next = FALSE; else + { + do tcode += GET(tcode, 1); while (*tcode == OP_ALT); + tcode += 1 + LINK_SIZE; + } break; - /* Skip over extended extraction bracket number */ + /* If we hit ALT or KET, it means we haven't found anything mandatory in + this branch, though we might have found something optional. For ALT, we + continue with the next alternative, but we have to arrange that the final + result from subpattern is SSB_CONTINUE rather than SSB_DONE. For KET, + return SSB_CONTINUE: if this is the top level, that indicates failure, + but after a nested subpattern, it causes scanning to continue. */ - case OP_BRANUMBER: - tcode += 3; + case OP_ALT: + yield = SSB_CONTINUE; + try_next = FALSE; break; + case OP_KET: + case OP_KETRMAX: + case OP_KETRMIN: + return SSB_CONTINUE; + + /* Skip over callout */ + + case OP_CALLOUT: + tcode += 2 + 2*LINK_SIZE; + break; + /* Skip over lookbehind and negative lookahead assertions */ case OP_ASSERT_NOT: case OP_ASSERTBACK: case OP_ASSERTBACK_NOT: do tcode += GET(tcode, 1); while (*tcode == OP_ALT); - tcode += 1+LINK_SIZE; + tcode += 1 + LINK_SIZE; break; /* Skip over an option setting, changing the caseless flag */ @@ -166,27 +204,30 @@ do case OP_BRAZERO: case OP_BRAMINZERO: - if (!set_start_bits(++tcode, start_bits, caseless, utf8, cd)) - return FALSE; + if (set_start_bits(++tcode, start_bits, caseless, utf8, cd) == SSB_FAIL) + return SSB_FAIL; /* ========================================================================= See the comment at the head of this function concerning the next line, which was an old fudge for the benefit of OS/2. dummy = 1; ========================================================================= */ do tcode += GET(tcode,1); while (*tcode == OP_ALT); - tcode += 1+LINK_SIZE; + tcode += 1 + LINK_SIZE; break; /* Single-char * or ? sets the bit and tries the next item */ case OP_STAR: case OP_MINSTAR: + case OP_POSSTAR: case OP_QUERY: case OP_MINQUERY: + case OP_POSQUERY: set_bit(start_bits, tcode[1], caseless, cd); tcode += 2; #ifdef SUPPORT_UTF8 - if (utf8) while ((*tcode & 0xc0) == 0x80) tcode++; + if (utf8 && tcode[-1] >= 0xc0) + tcode += _pcre_utf8_table4[tcode[-1] & 0x3f]; #endif break; @@ -194,10 +235,12 @@ do case OP_UPTO: case OP_MINUPTO: + case OP_POSUPTO: set_bit(start_bits, tcode[3], caseless, cd); tcode += 4; #ifdef SUPPORT_UTF8 - if (utf8) while ((*tcode & 0xc0) == 0x80) tcode++; + if (utf8 && tcode[-1] >= 0xc0) + tcode += _pcre_utf8_table4[tcode[-1] & 0x3f]; #endif break; @@ -210,6 +253,7 @@ do case OP_CHARNC: case OP_PLUS: case OP_MINPLUS: + case OP_POSPLUS: set_bit(start_bits, tcode[1], caseless, cd); try_next = FALSE; break; @@ -283,16 +327,19 @@ do case OP_TYPEUPTO: case OP_TYPEMINUPTO: + case OP_TYPEPOSUPTO: tcode += 2; /* Fall through */ case OP_TYPESTAR: case OP_TYPEMINSTAR: + case OP_TYPEPOSSTAR: case OP_TYPEQUERY: case OP_TYPEMINQUERY: + case OP_TYPEPOSQUERY: switch(tcode[1]) { case OP_ANY: - return FALSE; + return SSB_FAIL; case OP_NOT_DIGIT: for (c = 0; c < 32; c++) @@ -349,11 +396,13 @@ do character with a value > 255. */ case OP_NCLASS: +#ifdef SUPPORT_UTF8 if (utf8) { start_bits[24] |= 0xf0; /* Bits for 0xc4 - 0xc8 */ memset(start_bits+25, 0xff, 7); /* Bits for 0xc9 - 0xff */ } +#endif /* Fall through */ case OP_CLASS: @@ -366,6 +415,7 @@ do value is > 127. In fact, there are only two possible starting bytes for characters in the range 128 - 255. */ +#ifdef SUPPORT_UTF8 if (utf8) { for (c = 0; c < 16; c++) start_bits[c] |= tcode[c]; @@ -383,6 +433,7 @@ do /* In non-UTF-8 mode, the two bit maps are completely compatible. */ else +#endif { for (c = 0; c < 32; c++) start_bits[c] |= tcode[c]; } @@ -418,7 +469,7 @@ while (*code == OP_ALT); code += GET(code, 1); /* Advance to next branch */ } while (*code == OP_ALT); -return TRUE; +return yield; } @@ -442,7 +493,7 @@ Returns: pointer to a pcre_extra bloc NULL on error or if no optimization possible */ -PCRE_DATA_SCOPE pcre_extra * +PCRE_EXP_DEFN pcre_extra * pcre_study(const pcre *external_re, int options, const char **errorptr) { uschar start_bits[32]; @@ -474,7 +525,8 @@ at present. */ a multiline pattern that matches only at "line starts", no further processing at present. */ -if ((re->options & (PCRE_ANCHORED|PCRE_FIRSTSET|PCRE_STARTLINE)) != 0) +if ((re->options & PCRE_ANCHORED) != 0 || + (re->flags & (PCRE_FIRSTSET|PCRE_STARTLINE)) != 0) return NULL; /* Set the character tables in the block that is passed around */ @@ -492,8 +544,8 @@ memset(start_bits, 0, 32 * sizeof(uschar /* See if we can find a fixed set of initial characters for the pattern. */ memset(start_bits, 0, 32 * sizeof(uschar)); -if (!set_start_bits(code, start_bits, (re->options & PCRE_CASELESS) != 0, - (re->options & PCRE_UTF8) != 0, &compile_block)) return NULL; +if (set_start_bits(code, start_bits, (re->options & PCRE_CASELESS) != 0, + (re->options & PCRE_UTF8) != 0, &compile_block) != SSB_DONE) return NULL; /* Get a pcre_extra block and a pcre_study_data block. The study data is put in the latter, which is pointed to by the former, which may also get additional ============================================================ --- pcre/pcre_tables.c f504519f4ad83001af74dca4ada66d1fe68f64aa +++ pcre/pcre_tables.c 43b929d5086b991efc569e2d3fe2924fde8e7009 @@ -6,7 +6,7 @@ and semantics are as close as possible t and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel - Copyright (c) 1997-2006 University of Cambridge + Copyright (c) 1997-2007 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -44,6 +44,8 @@ clashes with the library. */ clashes with the library. */ +#include "pcre_config.h" + #include "pcre_internal.h" @@ -58,10 +60,11 @@ const uschar _pcre_OP_lengths[] = { OP_L * Tables for UTF-8 support * *************************************************/ -#ifdef SUPPORT_UTF8 /* These are the breakpoints for different numbers of bytes in a UTF-8 character. */ +#ifdef SUPPORT_UTF8 + const int _pcre_utf8_table1[] = { 0x7f, 0x7ff, 0xffff, 0x1fffff, 0x3ffffff, 0x7fffffff}; @@ -73,126 +76,241 @@ const int _pcre_utf8_table3[] = { 0xff, const int _pcre_utf8_table2[] = { 0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc}; const int _pcre_utf8_table3[] = { 0xff, 0x1f, 0x0f, 0x07, 0x03, 0x01}; -/* Table of the number of extra characters, indexed by the first character -masked with 0x3f. The highest number for a valid UTF-8 character is in fact -0x3d. */ +/* Table of the number of extra bytes, indexed by the first byte masked with +0x3f. The highest number for a valid UTF-8 first byte is in fact 0x3d. */ const uschar _pcre_utf8_table4[] = { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5 }; -#endif -#ifdef SUPPORT_UCP +/* The pcre_utt[] table below translates Unicode property names into type and +code values. It is searched by binary chop, so must be in collating sequence of +name. Originally, the table contained pointers to the name strings in the first +field of each entry. However, that leads to a large number of relocations when +a shared library is dynamically loaded. A significant reduction is made by +putting all the names into a single, large string and then using offsets in the +table itself. Maintenance is more error-prone, but frequent changes to this +data is unlikely. */ -/* This table translates Unicode property names into type and code values. It -is searched by binary chop, so must be in collating sequence of name. */ +const char _pcre_utt_names[] = + "Any\0" + "Arabic\0" + "Armenian\0" + "Balinese\0" + "Bengali\0" + "Bopomofo\0" + "Braille\0" + "Buginese\0" + "Buhid\0" + "C\0" + "Canadian_Aboriginal\0" + "Cc\0" + "Cf\0" + "Cherokee\0" + "Cn\0" + "Co\0" + "Common\0" + "Coptic\0" + "Cs\0" + "Cuneiform\0" + "Cypriot\0" + "Cyrillic\0" + "Deseret\0" + "Devanagari\0" + "Ethiopic\0" + "Georgian\0" + "Glagolitic\0" + "Gothic\0" + "Greek\0" + "Gujarati\0" + "Gurmukhi\0" + "Han\0" + "Hangul\0" + "Hanunoo\0" + "Hebrew\0" + "Hiragana\0" + "Inherited\0" + "Kannada\0" + "Katakana\0" + "Kharoshthi\0" + "Khmer\0" + "L\0" + "L&\0" + "Lao\0" + "Latin\0" + "Limbu\0" + "Linear_B\0" + "Ll\0" + "Lm\0" + "Lo\0" + "Lt\0" + "Lu\0" + "M\0" + "Malayalam\0" + "Mc\0" + "Me\0" + "Mn\0" + "Mongolian\0" + "Myanmar\0" + "N\0" + "Nd\0" + "New_Tai_Lue\0" + "Nko\0" + "Nl\0" + "No\0" + "Ogham\0" + "Old_Italic\0" + "Old_Persian\0" + "Oriya\0" + "Osmanya\0" + "P\0" + "Pc\0" + "Pd\0" + "Pe\0" + "Pf\0" + "Phags_Pa\0" + "Phoenician\0" + "Pi\0" + "Po\0" + "Ps\0" + "Runic\0" + "S\0" + "Sc\0" + "Shavian\0" + "Sinhala\0" + "Sk\0" + "Sm\0" + "So\0" + "Syloti_Nagri\0" + "Syriac\0" + "Tagalog\0" + "Tagbanwa\0" + "Tai_Le\0" + "Tamil\0" + "Telugu\0" + "Thaana\0" + "Thai\0" + "Tibetan\0" + "Tifinagh\0" + "Ugaritic\0" + "Yi\0" + "Z\0" + "Zl\0" + "Zp\0" + "Zs\0"; const ucp_type_table _pcre_utt[] = { - { "Any", PT_ANY, 0 }, - { "Arabic", PT_SC, ucp_Arabic }, - { "Armenian", PT_SC, ucp_Armenian }, - { "Bengali", PT_SC, ucp_Bengali }, - { "Bopomofo", PT_SC, ucp_Bopomofo }, - { "Braille", PT_SC, ucp_Braille }, - { "Buginese", PT_SC, ucp_Buginese }, - { "Buhid", PT_SC, ucp_Buhid }, - { "C", PT_GC, ucp_C }, - { "Canadian_Aboriginal", PT_SC, ucp_Canadian_Aboriginal }, - { "Cc", PT_PC, ucp_Cc }, - { "Cf", PT_PC, ucp_Cf }, - { "Cherokee", PT_SC, ucp_Cherokee }, - { "Cn", PT_PC, ucp_Cn }, - { "Co", PT_PC, ucp_Co }, - { "Common", PT_SC, ucp_Common }, - { "Coptic", PT_SC, ucp_Coptic }, - { "Cs", PT_PC, ucp_Cs }, - { "Cypriot", PT_SC, ucp_Cypriot }, - { "Cyrillic", PT_SC, ucp_Cyrillic }, - { "Deseret", PT_SC, ucp_Deseret }, - { "Devanagari", PT_SC, ucp_Devanagari }, - { "Ethiopic", PT_SC, ucp_Ethiopic }, - { "Georgian", PT_SC, ucp_Georgian }, - { "Glagolitic", PT_SC, ucp_Glagolitic }, - { "Gothic", PT_SC, ucp_Gothic }, - { "Greek", PT_SC, ucp_Greek }, - { "Gujarati", PT_SC, ucp_Gujarati }, - { "Gurmukhi", PT_SC, ucp_Gurmukhi }, - { "Han", PT_SC, ucp_Han }, - { "Hangul", PT_SC, ucp_Hangul }, - { "Hanunoo", PT_SC, ucp_Hanunoo }, - { "Hebrew", PT_SC, ucp_Hebrew }, - { "Hiragana", PT_SC, ucp_Hiragana }, - { "Inherited", PT_SC, ucp_Inherited }, - { "Kannada", PT_SC, ucp_Kannada }, - { "Katakana", PT_SC, ucp_Katakana }, - { "Kharoshthi", PT_SC, ucp_Kharoshthi }, - { "Khmer", PT_SC, ucp_Khmer }, - { "L", PT_GC, ucp_L }, - { "L&", PT_LAMP, 0 }, - { "Lao", PT_SC, ucp_Lao }, - { "Latin", PT_SC, ucp_Latin }, - { "Limbu", PT_SC, ucp_Limbu }, - { "Linear_B", PT_SC, ucp_Linear_B }, - { "Ll", PT_PC, ucp_Ll }, - { "Lm", PT_PC, ucp_Lm }, - { "Lo", PT_PC, ucp_Lo }, - { "Lt", PT_PC, ucp_Lt }, - { "Lu", PT_PC, ucp_Lu }, - { "M", PT_GC, ucp_M }, - { "Malayalam", PT_SC, ucp_Malayalam }, - { "Mc", PT_PC, ucp_Mc }, - { "Me", PT_PC, ucp_Me }, - { "Mn", PT_PC, ucp_Mn }, - { "Mongolian", PT_SC, ucp_Mongolian }, - { "Myanmar", PT_SC, ucp_Myanmar }, - { "N", PT_GC, ucp_N }, - { "Nd", PT_PC, ucp_Nd }, - { "New_Tai_Lue", PT_SC, ucp_New_Tai_Lue }, - { "Nl", PT_PC, ucp_Nl }, - { "No", PT_PC, ucp_No }, - { "Ogham", PT_SC, ucp_Ogham }, - { "Old_Italic", PT_SC, ucp_Old_Italic }, - { "Old_Persian", PT_SC, ucp_Old_Persian }, - { "Oriya", PT_SC, ucp_Oriya }, - { "Osmanya", PT_SC, ucp_Osmanya }, - { "P", PT_GC, ucp_P }, - { "Pc", PT_PC, ucp_Pc }, - { "Pd", PT_PC, ucp_Pd }, - { "Pe", PT_PC, ucp_Pe }, - { "Pf", PT_PC, ucp_Pf }, - { "Pi", PT_PC, ucp_Pi }, - { "Po", PT_PC, ucp_Po }, - { "Ps", PT_PC, ucp_Ps }, - { "Runic", PT_SC, ucp_Runic }, - { "S", PT_GC, ucp_S }, - { "Sc", PT_PC, ucp_Sc }, - { "Shavian", PT_SC, ucp_Shavian }, - { "Sinhala", PT_SC, ucp_Sinhala }, - { "Sk", PT_PC, ucp_Sk }, - { "Sm", PT_PC, ucp_Sm }, - { "So", PT_PC, ucp_So }, - { "Syloti_Nagri", PT_SC, ucp_Syloti_Nagri }, - { "Syriac", PT_SC, ucp_Syriac }, - { "Tagalog", PT_SC, ucp_Tagalog }, - { "Tagbanwa", PT_SC, ucp_Tagbanwa }, - { "Tai_Le", PT_SC, ucp_Tai_Le }, - { "Tamil", PT_SC, ucp_Tamil }, - { "Telugu", PT_SC, ucp_Telugu }, - { "Thaana", PT_SC, ucp_Thaana }, - { "Thai", PT_SC, ucp_Thai }, - { "Tibetan", PT_SC, ucp_Tibetan }, - { "Tifinagh", PT_SC, ucp_Tifinagh }, - { "Ugaritic", PT_SC, ucp_Ugaritic }, - { "Yi", PT_SC, ucp_Yi }, - { "Z", PT_GC, ucp_Z }, - { "Zl", PT_PC, ucp_Zl }, - { "Zp", PT_PC, ucp_Zp }, - { "Zs", PT_PC, ucp_Zs } + { 0, PT_ANY, 0 }, + { 4, PT_SC, ucp_Arabic }, + { 11, PT_SC, ucp_Armenian }, + { 20, PT_SC, ucp_Balinese }, + { 29, PT_SC, ucp_Bengali }, + { 37, PT_SC, ucp_Bopomofo }, + { 46, PT_SC, ucp_Braille }, + { 54, PT_SC, ucp_Buginese }, + { 63, PT_SC, ucp_Buhid }, + { 69, PT_GC, ucp_C }, + { 71, PT_SC, ucp_Canadian_Aboriginal }, + { 91, PT_PC, ucp_Cc }, + { 94, PT_PC, ucp_Cf }, + { 97, PT_SC, ucp_Cherokee }, + { 106, PT_PC, ucp_Cn }, + { 109, PT_PC, ucp_Co }, + { 112, PT_SC, ucp_Common }, + { 119, PT_SC, ucp_Coptic }, + { 126, PT_PC, ucp_Cs }, + { 129, PT_SC, ucp_Cuneiform }, + { 139, PT_SC, ucp_Cypriot }, + { 147, PT_SC, ucp_Cyrillic }, + { 156, PT_SC, ucp_Deseret }, + { 164, PT_SC, ucp_Devanagari }, + { 175, PT_SC, ucp_Ethiopic }, + { 184, PT_SC, ucp_Georgian }, + { 193, PT_SC, ucp_Glagolitic }, + { 204, PT_SC, ucp_Gothic }, + { 211, PT_SC, ucp_Greek }, + { 217, PT_SC, ucp_Gujarati }, + { 226, PT_SC, ucp_Gurmukhi }, + { 235, PT_SC, ucp_Han }, + { 239, PT_SC, ucp_Hangul }, + { 246, PT_SC, ucp_Hanunoo }, + { 254, PT_SC, ucp_Hebrew }, + { 261, PT_SC, ucp_Hiragana }, + { 270, PT_SC, ucp_Inherited }, + { 280, PT_SC, ucp_Kannada }, + { 288, PT_SC, ucp_Katakana }, + { 297, PT_SC, ucp_Kharoshthi }, + { 308, PT_SC, ucp_Khmer }, + { 314, PT_GC, ucp_L }, + { 316, PT_LAMP, 0 }, + { 319, PT_SC, ucp_Lao }, + { 323, PT_SC, ucp_Latin }, + { 329, PT_SC, ucp_Limbu }, + { 335, PT_SC, ucp_Linear_B }, + { 344, PT_PC, ucp_Ll }, + { 347, PT_PC, ucp_Lm }, + { 350, PT_PC, ucp_Lo }, + { 353, PT_PC, ucp_Lt }, + { 356, PT_PC, ucp_Lu }, + { 359, PT_GC, ucp_M }, + { 361, PT_SC, ucp_Malayalam }, + { 371, PT_PC, ucp_Mc }, + { 374, PT_PC, ucp_Me }, + { 377, PT_PC, ucp_Mn }, + { 380, PT_SC, ucp_Mongolian }, + { 390, PT_SC, ucp_Myanmar }, + { 398, PT_GC, ucp_N }, + { 400, PT_PC, ucp_Nd }, + { 403, PT_SC, ucp_New_Tai_Lue }, + { 415, PT_SC, ucp_Nko }, + { 419, PT_PC, ucp_Nl }, + { 422, PT_PC, ucp_No }, + { 425, PT_SC, ucp_Ogham }, + { 431, PT_SC, ucp_Old_Italic }, + { 442, PT_SC, ucp_Old_Persian }, + { 454, PT_SC, ucp_Oriya }, + { 460, PT_SC, ucp_Osmanya }, + { 468, PT_GC, ucp_P }, + { 470, PT_PC, ucp_Pc }, + { 473, PT_PC, ucp_Pd }, + { 476, PT_PC, ucp_Pe }, + { 479, PT_PC, ucp_Pf }, + { 482, PT_SC, ucp_Phags_Pa }, + { 491, PT_SC, ucp_Phoenician }, + { 502, PT_PC, ucp_Pi }, + { 505, PT_PC, ucp_Po }, + { 508, PT_PC, ucp_Ps }, + { 511, PT_SC, ucp_Runic }, + { 517, PT_GC, ucp_S }, + { 519, PT_PC, ucp_Sc }, + { 522, PT_SC, ucp_Shavian }, + { 530, PT_SC, ucp_Sinhala }, + { 538, PT_PC, ucp_Sk }, + { 541, PT_PC, ucp_Sm }, + { 544, PT_PC, ucp_So }, + { 547, PT_SC, ucp_Syloti_Nagri }, + { 560, PT_SC, ucp_Syriac }, + { 567, PT_SC, ucp_Tagalog }, + { 575, PT_SC, ucp_Tagbanwa }, + { 584, PT_SC, ucp_Tai_Le }, + { 591, PT_SC, ucp_Tamil }, + { 597, PT_SC, ucp_Telugu }, + { 604, PT_SC, ucp_Thaana }, + { 611, PT_SC, ucp_Thai }, + { 616, PT_SC, ucp_Tibetan }, + { 624, PT_SC, ucp_Tifinagh }, + { 633, PT_SC, ucp_Ugaritic }, + { 642, PT_SC, ucp_Yi }, + { 645, PT_GC, ucp_Z }, + { 647, PT_PC, ucp_Zl }, + { 650, PT_PC, ucp_Zp }, + { 653, PT_PC, ucp_Zs } }; const int _pcre_utt_size = sizeof(_pcre_utt)/sizeof(ucp_type_table); -#endif +#endif /* SUPPORT_UTF8 */ + /* End of pcre_tables.c */ ============================================================ --- pcre/pcre_try_flipped.c 4d22ad726b0e1decb6c0ebaecd607b7def17d642 +++ pcre/pcre_try_flipped.c 2d7f11db16127e769a87613dbb38ba1959a89c5c @@ -6,7 +6,7 @@ and semantics are as close as possible t and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel - Copyright (c) 1997-2006 University of Cambridge + Copyright (c) 1997-2007 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -43,6 +43,8 @@ auxiliary local function to flip the app auxiliary local function to flip the appropriate bytes. */ +#include "pcre_config.h" + #include "pcre_internal.h" @@ -104,6 +106,7 @@ internal_re->options = byteflip(re->opti *internal_re = *re; /* To copy other fields */ internal_re->size = byteflip(re->size, sizeof(re->size)); internal_re->options = byteflip(re->options, sizeof(re->options)); +internal_re->flags = (pcre_uint16)byteflip(re->flags, sizeof(re->flags)); internal_re->top_bracket = (pcre_uint16)byteflip(re->top_bracket, sizeof(re->top_bracket)); internal_re->top_backref = ============================================================ --- pcre/pcre_version.c 0e4d6ac360d5acfba16e4d071b69d954488e7a5f +++ pcre/pcre_version.c 97e12b4b30fc68214564f746963f1701528925a7 @@ -6,7 +6,7 @@ and semantics are as close as possible t and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel - Copyright (c) 1997-2006 University of Cambridge + Copyright (c) 1997-2007 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -42,6 +42,8 @@ string that identifies the PCRE version string that identifies the PCRE version that is in use. */ +#include "pcre_config.h" + #include "pcre_internal.h" @@ -49,16 +51,38 @@ string that identifies the PCRE version * Return version string * *************************************************/ +/* These macros are the standard way of turning unquoted text into C strings. +They allow macros like PCRE_MAJOR to be defined without quotes, which is +convenient for user programs that want to test its value. */ + #define STRING(a) # a #define XSTRING(s) STRING(s) -PCRE_DATA_SCOPE const char * +/* A problem turned up with PCRE_PRERELEASE, which is defined empty for +production releases. Originally, it was used naively in this code: + + return XSTRING(PCRE_MAJOR) + "." XSTRING(PCRE_MINOR) + XSTRING(PCRE_PRERELEASE) + " " XSTRING(PCRE_DATE); + +However, when PCRE_PRERELEASE is empty, this leads to an attempted expansion of +STRING(). The C standard states: "If (before argument substitution) any +argument consists of no preprocessing tokens, the behavior is undefined." It +turns out the gcc treats this case as a single empty string - which is what we +really want - but Visual C grumbles about the lack of an argument for the +macro. Unfortunately, both are within their rights. To cope with both ways of +handling this, I had resort to some messy hackery that does a test at run time. +I could find no way of detecting that a macro is defined as an empty string at +pre-processor time. This hack uses a standard trick for avoiding calling +the STRING macro with an empty argument when doing the test. */ + +PCRE_EXP_DEFN const char * pcre_version(void) { -return XSTRING(PCRE_MAJOR) - "." XSTRING(PCRE_MINOR) - XSTRING(PCRE_PRERELEASE) - " " XSTRING(PCRE_DATE); +return (XSTRING(Z PCRE_PRERELEASE)[1] == 0)? + XSTRING(PCRE_MAJOR.PCRE_MINOR PCRE_DATE) : + XSTRING(PCRE_MAJOR.PCRE_MINOR) XSTRING(PCRE_PRERELEASE PCRE_DATE); } /* End of pcre_version.c */ ============================================================ --- pcre/pcre_xclass.c d672ac5b6a31841662bca6917df7d31537ae7f22 +++ pcre/pcre_xclass.c b9a3ce19007386f9fb242cd8396ca94efaa29b5d @@ -6,7 +6,7 @@ and semantics are as close as possible t and semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel - Copyright (c) 1997-2006 University of Cambridge + Copyright (c) 1997-2007 University of Cambridge ----------------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without @@ -43,6 +43,8 @@ pcre_exec() and pcre_def_exec(). */ pcre_exec() and pcre_def_exec(). */ +#include "pcre_config.h" + #include "pcre_internal.h" ============================================================ --- tests/syntax_errors_in_.mtn-ignore/stderr-ref 81aae288f36ab9e7e65cc454878447c7ce9ad945 +++ tests/syntax_errors_in_.mtn-ignore/stderr-ref e5393b2dd883f02f0f5bbe8a97aec42304c69f0e @@ -1,7 +1,7 @@ mtn: warning: while matching file 'ts-st mtn: warning: while matching file 'ts-stdin': .mtn-ignore:1: warning: error near char 2 of regex "\": \ at end of pattern - skipping this regex for all remaining files. -.mtn-ignore:2: warning: error near char 1 of regex "\c": \c at end of pattern +.mtn-ignore:2: warning: error near char 3 of regex "\c": \c at end of pattern - skipping this regex for all remaining files. .mtn-ignore:3: warning: error near char 6 of regex "x{3,1}": numbers out of order in {} quantifier - skipping this regex for all remaining files. @@ -25,7 +25,7 @@ mtn: warning: while matching file 'ts-st - skipping this regex for all remaining files. .mtn-ignore:13: warning: error near char 1 of regex ")": unmatched parentheses - skipping this regex for all remaining files. -.mtn-ignore:14: warning: error near char 4 of regex "(?x)": syntax error after (?P +.mtn-ignore:29: warning: error near char 5 of regex "(?P<*>x)": syntax error in subpattern name (missing terminator) - skipping this regex for all remaining files. .mtn-ignore:30: warning: error near char 38 of regex "(?P)": subpattern name is too long (maximum 32 characters) - skipping this regex for all remaining files.