00001 /************************************************* 00002 * Perl-Compatible Regular Expressions * 00003 *************************************************/ 00004 00005 00006 /* PCRE is a library of functions to support regular expressions whose syntax 00007 and semantics are as close as possible to those of the Perl 5 language. 00008 00009 Written by Philip Hazel 00010 Copyright (c) 1997-2008 University of Cambridge 00011 00012 ----------------------------------------------------------------------------- 00013 Redistribution and use in source and binary forms, with or without 00014 modification, are permitted provided that the following conditions are met: 00015 00016 * Redistributions of source code must retain the above copyright notice, 00017 this list of conditions and the following disclaimer. 00018 00019 * Redistributions in binary form must reproduce the above copyright 00020 notice, this list of conditions and the following disclaimer in the 00021 documentation and/or other materials provided with the distribution. 00022 00023 * Neither the name of the University of Cambridge nor the names of its 00024 contributors may be used to endorse or promote products derived from 00025 this software without specific prior written permission. 00026 00027 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00028 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00029 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00030 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00031 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00032 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00033 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00034 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00035 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00036 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00037 POSSIBILITY OF SUCH DAMAGE. 00038 ----------------------------------------------------------------------------- 00039 */ 00040 00041 /* This header contains definitions that are shared between the different 00042 modules, but which are not relevant to the exported API. This includes some 00043 functions whose names all begin with "_pcre_". */ 00044 00045 #ifndef PCRE_INTERNAL_H 00046 #define PCRE_INTERNAL_H 00047 00048 /* Define DEBUG to get debugging output on stdout. */ 00049 00050 #if 0 00051 #define DEBUG 00052 #endif 00053 00054 /* Use a macro for debugging printing, 'cause that eliminates the use of #ifdef 00055 inline, and there are *still* stupid compilers about that don't like indented 00056 pre-processor statements, or at least there were when I first wrote this. After 00057 all, it had only been about 10 years then... 00058 00059 It turns out that the Mac Debugging.h header also defines the macro DPRINTF, so 00060 be absolutely sure we get our version. */ 00061 00062 #undef DPRINTF 00063 #ifdef DEBUG 00064 #define DPRINTF(p) printf p 00065 #else 00066 #define DPRINTF(p) /* Nothing */ 00067 #endif 00068 00069 00070 /* Standard C headers plus the external interface definition. The only time 00071 setjmp and stdarg are used is when NO_RECURSE is set. */ 00072 00073 #include <ctype.h> 00074 #include <limits.h> 00075 #include <setjmp.h> 00076 #include <stdarg.h> 00077 #include <stddef.h> 00078 #include <stdio.h> 00079 #include <stdlib.h> 00080 #include <string.h> 00081 00082 /* When compiling a DLL for Windows, the exported symbols have to be declared 00083 using some MS magic. I found some useful information on this web page: 00084 http://msdn2.microsoft.com/en-us/library/y4h7bcy6(VS.80).aspx. According to the 00085 information there, using __declspec(dllexport) without "extern" we have a 00086 definition; with "extern" we have a declaration. The settings here override the 00087 setting in pcre.h (which is included below); it defines only PCRE_EXP_DECL, 00088 which is all that is needed for applications (they just import the symbols). We 00089 use: 00090 00091 PCRE_EXP_DECL for declarations 00092 PCRE_EXP_DEFN for definitions of exported functions 00093 PCRE_EXP_DATA_DEFN for definitions of exported variables 00094 00095 The reason for the two DEFN macros is that in non-Windows environments, one 00096 does not want to have "extern" before variable definitions because it leads to 00097 compiler warnings. So we distinguish between functions and variables. In 00098 Windows, the two should always be the same. 00099 00100 The reason for wrapping this in #ifndef PCRE_EXP_DECL is so that pcretest, 00101 which is an application, but needs to import this file in order to "peek" at 00102 internals, can #include pcre.h first to get an application's-eye view. 00103 00104 In principle, people compiling for non-Windows, non-Unix-like (i.e. uncommon, 00105 special-purpose environments) might want to stick other stuff in front of 00106 exported symbols. That's why, in the non-Windows case, we set PCRE_EXP_DEFN and 00107 PCRE_EXP_DATA_DEFN only if they are not already set. */ 00108 00109 #ifndef PCRE_EXP_DECL 00110 # ifdef _WIN32 00111 # ifndef PCRE_STATIC 00112 # define PCRE_EXP_DECL extern __declspec(dllexport) 00113 # define PCRE_EXP_DEFN __declspec(dllexport) 00114 # define PCRE_EXP_DATA_DEFN __declspec(dllexport) 00115 # else 00116 # define PCRE_EXP_DECL extern 00117 # define PCRE_EXP_DEFN 00118 # define PCRE_EXP_DATA_DEFN 00119 # endif 00120 # else 00121 # ifdef __cplusplus 00122 # define PCRE_EXP_DECL extern "C" 00123 # else 00124 # define PCRE_EXP_DECL extern 00125 # endif 00126 # ifndef PCRE_EXP_DEFN 00127 # define PCRE_EXP_DEFN PCRE_EXP_DECL 00128 # endif 00129 # ifndef PCRE_EXP_DATA_DEFN 00130 # define PCRE_EXP_DATA_DEFN 00131 # endif 00132 # endif 00133 #endif 00134 00135 /* When compiling with the MSVC compiler, it is sometimes necessary to include 00136 a "calling convention" before exported function names. (This is secondhand 00137 information; I know nothing about MSVC myself). For example, something like 00138 00139 void __cdecl function(....) 00140 00141 might be needed. In order so make this easy, all the exported functions have 00142 PCRE_CALL_CONVENTION just before their names. It is rarely needed; if not 00143 set, we ensure here that it has no effect. */ 00144 00145 #ifndef PCRE_CALL_CONVENTION 00146 #define PCRE_CALL_CONVENTION 00147 #endif 00148 00149 /* We need to have types that specify unsigned 16-bit and 32-bit integers. We 00150 cannot determine these outside the compilation (e.g. by running a program as 00151 part of "configure") because PCRE is often cross-compiled for use on other 00152 systems. Instead we make use of the maximum sizes that are available at 00153 preprocessor time in standard C environments. */ 00154 00155 #if USHRT_MAX == 65535 00156 typedef unsigned short pcre_uint16; 00157 typedef short pcre_int16; 00158 #elif UINT_MAX == 65535 00159 typedef unsigned int pcre_uint16; 00160 typedef int pcre_int16; 00161 #else 00162 #error Cannot determine a type for 16-bit unsigned integers 00163 #endif 00164 00165 #if UINT_MAX == 4294967295 00166 typedef unsigned int pcre_uint32; 00167 typedef int pcre_int32; 00168 #elif ULONG_MAX == 4294967295 00169 typedef unsigned long int pcre_uint32; 00170 typedef long int pcre_int32; 00171 #else 00172 #error Cannot determine a type for 32-bit unsigned integers 00173 #endif 00174 00175 /* All character handling must be done as unsigned characters. Otherwise there 00176 are problems with top-bit-set characters and functions such as isspace(). 00177 However, we leave the interface to the outside world as char *, because that 00178 should make things easier for callers. We define a short type for unsigned char 00179 to save lots of typing. I tried "uchar", but it causes problems on Digital 00180 Unix, where it is defined in sys/types, so use "uschar" instead. */ 00181 00182 typedef unsigned char uschar; 00183 00184 /* This is an unsigned int value that no character can ever have. UTF-8 00185 characters only go up to 0x7fffffff (though Unicode doesn't go beyond 00186 0x0010ffff). */ 00187 00188 #define NOTACHAR 0xffffffff 00189 00190 /* PCRE is able to support several different kinds of newline (CR, LF, CRLF, 00191 "any" and "anycrlf" at present). The following macros are used to package up 00192 testing for newlines. NLBLOCK, PSSTART, and PSEND are defined in the various 00193 modules to indicate in which datablock the parameters exist, and what the 00194 start/end of string field names are. */ 00195 00196 #define NLTYPE_FIXED 0 /* Newline is a fixed length string */ 00197 #define NLTYPE_ANY 1 /* Newline is any Unicode line ending */ 00198 #define NLTYPE_ANYCRLF 2 /* Newline is CR, LF, or CRLF */ 00199 00200 /* This macro checks for a newline at the given position */ 00201 00202 #define IS_NEWLINE(p) \ 00203 ((NLBLOCK->nltype != NLTYPE_FIXED)? \ 00204 ((p) < NLBLOCK->PSEND && \ 00205 _pcre_is_newline((p), NLBLOCK->nltype, NLBLOCK->PSEND, &(NLBLOCK->nllen),\ 00206 utf8)) \ 00207 : \ 00208 ((p) <= NLBLOCK->PSEND - NLBLOCK->nllen && \ 00209 (p)[0] == NLBLOCK->nl[0] && \ 00210 (NLBLOCK->nllen == 1 || (p)[1] == NLBLOCK->nl[1]) \ 00211 ) \ 00212 ) 00213 00214 /* This macro checks for a newline immediately preceding the given position */ 00215 00216 #define WAS_NEWLINE(p) \ 00217 ((NLBLOCK->nltype != NLTYPE_FIXED)? \ 00218 ((p) > NLBLOCK->PSSTART && \ 00219 _pcre_was_newline((p), NLBLOCK->nltype, NLBLOCK->PSSTART, \ 00220 &(NLBLOCK->nllen), utf8)) \ 00221 : \ 00222 ((p) >= NLBLOCK->PSSTART + NLBLOCK->nllen && \ 00223 (p)[-NLBLOCK->nllen] == NLBLOCK->nl[0] && \ 00224 (NLBLOCK->nllen == 1 || (p)[-NLBLOCK->nllen+1] == NLBLOCK->nl[1]) \ 00225 ) \ 00226 ) 00227 00228 /* When PCRE is compiled as a C++ library, the subject pointer can be replaced 00229 with a custom type. This makes it possible, for example, to allow pcre_exec() 00230 to process subject strings that are discontinuous by using a smart pointer 00231 class. It must always be possible to inspect all of the subject string in 00232 pcre_exec() because of the way it backtracks. Two macros are required in the 00233 normal case, for sign-unspecified and unsigned char pointers. The former is 00234 used for the external interface and appears in pcre.h, which is why its name 00235 must begin with PCRE_. */ 00236 00237 #ifdef CUSTOM_SUBJECT_PTR 00238 #define PCRE_SPTR CUSTOM_SUBJECT_PTR 00239 #define USPTR CUSTOM_SUBJECT_PTR 00240 #else 00241 #define PCRE_SPTR const char * 00242 #define USPTR const unsigned char * 00243 #endif 00244 00245 00246 00247 /* Include the public PCRE header and the definitions of UCP character property 00248 values. */ 00249 00250 #include "pcre.h" 00251 #include "ucp.h" 00252 00253 /* When compiling for use with the Virtual Pascal compiler, these functions 00254 need to have their names changed. PCRE must be compiled with the -DVPCOMPAT 00255 option on the command line. */ 00256 00257 #ifdef VPCOMPAT 00258 #define strlen(s) _strlen(s) 00259 #define strncmp(s1,s2,m) _strncmp(s1,s2,m) 00260 #define memcmp(s,c,n) _memcmp(s,c,n) 00261 #define memcpy(d,s,n) _memcpy(d,s,n) 00262 #define memmove(d,s,n) _memmove(d,s,n) 00263 #define memset(s,c,n) _memset(s,c,n) 00264 #else /* VPCOMPAT */ 00265 00266 /* To cope with SunOS4 and other systems that lack memmove() but have bcopy(), 00267 define a macro for memmove() if HAVE_MEMMOVE is false, provided that HAVE_BCOPY 00268 is set. Otherwise, include an emulating function for those systems that have 00269 neither (there some non-Unix environments where this is the case). */ 00270 00271 #ifndef HAVE_MEMMOVE 00272 #undef memmove /* some systems may have a macro */ 00273 #ifdef HAVE_BCOPY 00274 #define memmove(a, b, c) bcopy(b, a, c) 00275 #else /* HAVE_BCOPY */ 00276 static void * 00277 pcre_memmove(void *d, const void *s, size_t n) 00278 { 00279 size_t i; 00280 unsigned char *dest = (unsigned char *)d; 00281 const unsigned char *src = (const unsigned char *)s; 00282 if (dest > src) 00283 { 00284 dest += n; 00285 src += n; 00286 for (i = 0; i < n; ++i) *(--dest) = *(--src); 00287 return (void *)dest; 00288 } 00289 else 00290 { 00291 for (i = 0; i < n; ++i) *dest++ = *src++; 00292 return (void *)(dest - n); 00293 } 00294 } 00295 #define memmove(a, b, c) pcre_memmove(a, b, c) 00296 #endif /* not HAVE_BCOPY */ 00297 #endif /* not HAVE_MEMMOVE */ 00298 #endif /* not VPCOMPAT */ 00299 00300 00301 /* PCRE keeps offsets in its compiled code as 2-byte quantities (always stored 00302 in big-endian order) by default. These are used, for example, to link from the 00303 start of a subpattern to its alternatives and its end. The use of 2 bytes per 00304 offset limits the size of the compiled regex to around 64K, which is big enough 00305 for almost everybody. However, I received a request for an even bigger limit. 00306 For this reason, and also to make the code easier to maintain, the storing and 00307 loading of offsets from the byte string is now handled by the macros that are 00308 defined here. 00309 00310 The macros are controlled by the value of LINK_SIZE. This defaults to 2 in 00311 the config.h file, but can be overridden by using -D on the command line. This 00312 is automated on Unix systems via the "configure" command. */ 00313 00314 #if LINK_SIZE == 2 00315 00316 #define PUT(a,n,d) \ 00317 (a[n] = (d) >> 8), \ 00318 (a[(n)+1] = (d) & 255) 00319 00320 #define GET(a,n) \ 00321 (((a)[n] << 8) | (a)[(n)+1]) 00322 00323 #define MAX_PATTERN_SIZE (1 << 16) 00324 00325 00326 #elif LINK_SIZE == 3 00327 00328 #define PUT(a,n,d) \ 00329 (a[n] = (d) >> 16), \ 00330 (a[(n)+1] = (d) >> 8), \ 00331 (a[(n)+2] = (d) & 255) 00332 00333 #define GET(a,n) \ 00334 (((a)[n] << 16) | ((a)[(n)+1] << 8) | (a)[(n)+2]) 00335 00336 #define MAX_PATTERN_SIZE (1 << 24) 00337 00338 00339 #elif LINK_SIZE == 4 00340 00341 #define PUT(a,n,d) \ 00342 (a[n] = (d) >> 24), \ 00343 (a[(n)+1] = (d) >> 16), \ 00344 (a[(n)+2] = (d) >> 8), \ 00345 (a[(n)+3] = (d) & 255) 00346 00347 #define GET(a,n) \ 00348 (((a)[n] << 24) | ((a)[(n)+1] << 16) | ((a)[(n)+2] << 8) | (a)[(n)+3]) 00349 00350 #define MAX_PATTERN_SIZE (1 << 30) /* Keep it positive */ 00351 00352 00353 #else 00354 #error LINK_SIZE must be either 2, 3, or 4 00355 #endif 00356 00357 00358 /* Convenience macro defined in terms of the others */ 00359 00360 #define PUTINC(a,n,d) PUT(a,n,d), a += LINK_SIZE 00361 00362 00363 /* PCRE uses some other 2-byte quantities that do not change when the size of 00364 offsets changes. There are used for repeat counts and for other things such as 00365 capturing parenthesis numbers in back references. */ 00366 00367 #define PUT2(a,n,d) \ 00368 a[n] = (d) >> 8; \ 00369 a[(n)+1] = (d) & 255 00370 00371 #define GET2(a,n) \ 00372 (((a)[n] << 8) | (a)[(n)+1]) 00373 00374 #define PUT2INC(a,n,d) PUT2(a,n,d), a += 2 00375 00376 00377 /* When UTF-8 encoding is being used, a character is no longer just a single 00378 byte. The macros for character handling generate simple sequences when used in 00379 byte-mode, and more complicated ones for UTF-8 characters. BACKCHAR should 00380 never be called in byte mode. To make sure it can never even appear when UTF-8 00381 support is omitted, we don't even define it. */ 00382 00383 #ifndef SUPPORT_UTF8 00384 #define GETCHAR(c, eptr) c = *eptr; 00385 #define GETCHARTEST(c, eptr) c = *eptr; 00386 #define GETCHARINC(c, eptr) c = *eptr++; 00387 #define GETCHARINCTEST(c, eptr) c = *eptr++; 00388 #define GETCHARLEN(c, eptr, len) c = *eptr; 00389 /* #define BACKCHAR(eptr) */ 00390 00391 #else /* SUPPORT_UTF8 */ 00392 00393 /* Get the next UTF-8 character, not advancing the pointer. This is called when 00394 we know we are in UTF-8 mode. */ 00395 00396 #define GETCHAR(c, eptr) \ 00397 c = *eptr; \ 00398 if (c >= 0xc0) \ 00399 { \ 00400 int gcii; \ 00401 int gcaa = _pcre_utf8_table4[c & 0x3f]; /* Number of additional bytes */ \ 00402 int gcss = 6*gcaa; \ 00403 c = (c & _pcre_utf8_table3[gcaa]) << gcss; \ 00404 for (gcii = 1; gcii <= gcaa; gcii++) \ 00405 { \ 00406 gcss -= 6; \ 00407 c |= (eptr[gcii] & 0x3f) << gcss; \ 00408 } \ 00409 } 00410 00411 /* Get the next UTF-8 character, testing for UTF-8 mode, and not advancing the 00412 pointer. */ 00413 00414 #define GETCHARTEST(c, eptr) \ 00415 c = *eptr; \ 00416 if (utf8 && c >= 0xc0) \ 00417 { \ 00418 int gcii; \ 00419 int gcaa = _pcre_utf8_table4[c & 0x3f]; /* Number of additional bytes */ \ 00420 int gcss = 6*gcaa; \ 00421 c = (c & _pcre_utf8_table3[gcaa]) << gcss; \ 00422 for (gcii = 1; gcii <= gcaa; gcii++) \ 00423 { \ 00424 gcss -= 6; \ 00425 c |= (eptr[gcii] & 0x3f) << gcss; \ 00426 } \ 00427 } 00428 00429 /* Get the next UTF-8 character, advancing the pointer. This is called when we 00430 know we are in UTF-8 mode. */ 00431 00432 #define GETCHARINC(c, eptr) \ 00433 c = *eptr++; \ 00434 if (c >= 0xc0) \ 00435 { \ 00436 int gcaa = _pcre_utf8_table4[c & 0x3f]; /* Number of additional bytes */ \ 00437 int gcss = 6*gcaa; \ 00438 c = (c & _pcre_utf8_table3[gcaa]) << gcss; \ 00439 while (gcaa-- > 0) \ 00440 { \ 00441 gcss -= 6; \ 00442 c |= (*eptr++ & 0x3f) << gcss; \ 00443 } \ 00444 } 00445 00446 /* Get the next character, testing for UTF-8 mode, and advancing the pointer */ 00447 00448 #define GETCHARINCTEST(c, eptr) \ 00449 c = *eptr++; \ 00450 if (utf8 && c >= 0xc0) \ 00451 { \ 00452 int gcaa = _pcre_utf8_table4[c & 0x3f]; /* Number of additional bytes */ \ 00453 int gcss = 6*gcaa; \ 00454 c = (c & _pcre_utf8_table3[gcaa]) << gcss; \ 00455 while (gcaa-- > 0) \ 00456 { \ 00457 gcss -= 6; \ 00458 c |= (*eptr++ & 0x3f) << gcss; \ 00459 } \ 00460 } 00461 00462 /* Get the next UTF-8 character, not advancing the pointer, incrementing length 00463 if there are extra bytes. This is called when we know we are in UTF-8 mode. */ 00464 00465 #define GETCHARLEN(c, eptr, len) \ 00466 c = *eptr; \ 00467 if (c >= 0xc0) \ 00468 { \ 00469 int gcii; \ 00470 int gcaa = _pcre_utf8_table4[c & 0x3f]; /* Number of additional bytes */ \ 00471 int gcss = 6*gcaa; \ 00472 c = (c & _pcre_utf8_table3[gcaa]) << gcss; \ 00473 for (gcii = 1; gcii <= gcaa; gcii++) \ 00474 { \ 00475 gcss -= 6; \ 00476 c |= (eptr[gcii] & 0x3f) << gcss; \ 00477 } \ 00478 len += gcaa; \ 00479 } 00480 00481 /* If the pointer is not at the start of a character, move it back until 00482 it is. This is called only in UTF-8 mode - we don't put a test within the macro 00483 because almost all calls are already within a block of UTF-8 only code. */ 00484 00485 #define BACKCHAR(eptr) while((*eptr & 0xc0) == 0x80) eptr-- 00486 00487 #endif 00488 00489 00490 /* In case there is no definition of offsetof() provided - though any proper 00491 Standard C system should have one. */ 00492 00493 #ifndef offsetof 00494 #define offsetof(p_type,field) ((size_t)&(((p_type *)0)->field)) 00495 #endif 00496 00497 00498 /* These are the public options that can change during matching. */ 00499 00500 #define PCRE_IMS (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL) 00501 00502 /* Private flags containing information about the compiled regex. They used to 00503 live at the top end of the options word, but that got almost full, so now they 00504 are in a 16-bit flags word. */ 00505 00506 #define PCRE_NOPARTIAL 0x0001 /* can't use partial with this regex */ 00507 #define PCRE_FIRSTSET 0x0002 /* first_byte is set */ 00508 #define PCRE_REQCHSET 0x0004 /* req_byte is set */ 00509 #define PCRE_STARTLINE 0x0008 /* start after \n for multiline */ 00510 #define PCRE_JCHANGED 0x0010 /* j option used in regex */ 00511 #define PCRE_HASCRORLF 0x0020 /* explicit \r or \n in pattern */ 00512 00513 /* Options for the "extra" block produced by pcre_study(). */ 00514 00515 #define PCRE_STUDY_MAPPED 0x01 /* a map of starting chars exists */ 00516 00517 /* Masks for identifying the public options that are permitted at compile 00518 time, run time, or study time, respectively. */ 00519 00520 #define PCRE_NEWLINE_BITS (PCRE_NEWLINE_CR|PCRE_NEWLINE_LF|PCRE_NEWLINE_ANY| \ 00521 PCRE_NEWLINE_ANYCRLF) 00522 00523 #define PUBLIC_OPTIONS \ 00524 (PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \ 00525 PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY|PCRE_UTF8| \ 00526 PCRE_NO_AUTO_CAPTURE|PCRE_NO_UTF8_CHECK|PCRE_AUTO_CALLOUT|PCRE_FIRSTLINE| \ 00527 PCRE_DUPNAMES|PCRE_NEWLINE_BITS|PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE| \ 00528 PCRE_JAVASCRIPT_COMPAT) 00529 00530 #define PUBLIC_EXEC_OPTIONS \ 00531 (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK| \ 00532 PCRE_PARTIAL|PCRE_NEWLINE_BITS|PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE) 00533 00534 #define PUBLIC_DFA_EXEC_OPTIONS \ 00535 (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK| \ 00536 PCRE_PARTIAL|PCRE_DFA_SHORTEST|PCRE_DFA_RESTART|PCRE_NEWLINE_BITS| \ 00537 PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE) 00538 00539 #define PUBLIC_STUDY_OPTIONS 0 /* None defined */ 00540 00541 /* Magic number to provide a small check against being handed junk. Also used 00542 to detect whether a pattern was compiled on a host of different endianness. */ 00543 00544 #define MAGIC_NUMBER 0x50435245UL /* 'PCRE' */ 00545 00546 /* Negative values for the firstchar and reqchar variables */ 00547 00548 #define REQ_UNSET (-2) 00549 #define REQ_NONE (-1) 00550 00551 /* The maximum remaining length of subject we are prepared to search for a 00552 req_byte match. */ 00553 00554 #define REQ_BYTE_MAX 1000 00555 00556 /* Flags added to firstbyte or reqbyte; a "non-literal" item is either a 00557 variable-length repeat, or a anything other than literal characters. */ 00558 00559 #define REQ_CASELESS 0x0100 /* indicates caselessness */ 00560 #define REQ_VARY 0x0200 /* reqbyte followed non-literal item */ 00561 00562 /* Miscellaneous definitions. The #ifndef is to pacify compiler warnings in 00563 environments where these macros are defined elsewhere. */ 00564 00565 #ifndef FALSE 00566 typedef int BOOL; 00567 00568 #define FALSE 0 00569 #define TRUE 1 00570 #endif 00571 00572 /* Escape items that are just an encoding of a particular data value. */ 00573 00574 #ifndef ESC_e 00575 #define ESC_e 27 00576 #endif 00577 00578 #ifndef ESC_f 00579 #define ESC_f '\f' 00580 #endif 00581 00582 #ifndef ESC_n 00583 #define ESC_n '\n' 00584 #endif 00585 00586 #ifndef ESC_r 00587 #define ESC_r '\r' 00588 #endif 00589 00590 /* We can't officially use ESC_t because it is a POSIX reserved identifier 00591 (presumably because of all the others like size_t). */ 00592 00593 #ifndef ESC_tee 00594 #define ESC_tee '\t' 00595 #endif 00596 00597 /* Codes for different types of Unicode property */ 00598 00599 #define PT_ANY 0 /* Any property - matches all chars */ 00600 #define PT_LAMP 1 /* L& - the union of Lu, Ll, Lt */ 00601 #define PT_GC 2 /* General characteristic (e.g. L) */ 00602 #define PT_PC 3 /* Particular characteristic (e.g. Lu) */ 00603 #define PT_SC 4 /* Script (e.g. Han) */ 00604 00605 /* Flag bits and data types for the extended class (OP_XCLASS) for classes that 00606 contain UTF-8 characters with values greater than 255. */ 00607 00608 #define XCL_NOT 0x01 /* Flag: this is a negative class */ 00609 #define XCL_MAP 0x02 /* Flag: a 32-byte map is present */ 00610 00611 #define XCL_END 0 /* Marks end of individual items */ 00612 #define XCL_SINGLE 1 /* Single item (one multibyte char) follows */ 00613 #define XCL_RANGE 2 /* A range (two multibyte chars) follows */ 00614 #define XCL_PROP 3 /* Unicode property (2-byte property code follows) */ 00615 #define XCL_NOTPROP 4 /* Unicode inverted property (ditto) */ 00616 00617 /* These are escaped items that aren't just an encoding of a particular data 00618 value such as \n. They must have non-zero values, as check_escape() returns 00619 their negation. Also, they must appear in the same order as in the opcode 00620 definitions below, up to ESC_z. There's a dummy for OP_ANY because it 00621 corresponds to "." rather than an escape sequence, and another for OP_ALLANY 00622 (which is used for [^] in JavaScript compatibility mode). 00623 00624 The final escape must be ESC_REF as subsequent values are used for 00625 backreferences (\1, \2, \3, etc). There are two tests in the code for an escape 00626 greater than ESC_b and less than ESC_Z to detect the types that may be 00627 repeated. These are the types that consume characters. If any new escapes are 00628 put in between that don't consume a character, that code will have to change. 00629 */ 00630 00631 enum { ESC_A = 1, ESC_G, ESC_K, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s, 00632 ESC_W, ESC_w, ESC_dum1, ESC_dum2, ESC_C, ESC_P, ESC_p, ESC_R, ESC_H, 00633 ESC_h, ESC_V, ESC_v, ESC_X, ESC_Z, ESC_z, ESC_E, ESC_Q, ESC_g, ESC_k, 00634 ESC_REF }; 00635 00636 00637 /* Opcode table: Starting from 1 (i.e. after OP_END), the values up to 00638 OP_EOD must correspond in order to the list of escapes immediately above. 00639 00640 *** NOTE NOTE NOTE *** Whenever this list is updated, the two macro definitions 00641 that follow must also be updated to match. There is also a table called 00642 "coptable" in pcre_dfa_exec.c that must be updated. */ 00643 00644 enum { 00645 OP_END, /* 0 End of pattern */ 00646 00647 /* Values corresponding to backslashed metacharacters */ 00648 00649 OP_SOD, /* 1 Start of data: \A */ 00650 OP_SOM, /* 2 Start of match (subject + offset): \G */ 00651 OP_SET_SOM, /* 3 Set start of match (\K) */ 00652 OP_NOT_WORD_BOUNDARY, /* 4 \B */ 00653 OP_WORD_BOUNDARY, /* 5 \b */ 00654 OP_NOT_DIGIT, /* 6 \D */ 00655 OP_DIGIT, /* 7 \d */ 00656 OP_NOT_WHITESPACE, /* 8 \S */ 00657 OP_WHITESPACE, /* 9 \s */ 00658 OP_NOT_WORDCHAR, /* 10 \W */ 00659 OP_WORDCHAR, /* 11 \w */ 00660 OP_ANY, /* 12 Match any character (subject to DOTALL) */ 00661 OP_ALLANY, /* 13 Match any character (not subject to DOTALL) */ 00662 OP_ANYBYTE, /* 14 Match any byte (\C); different to OP_ANY for UTF-8 */ 00663 OP_NOTPROP, /* 15 \P (not Unicode property) */ 00664 OP_PROP, /* 16 \p (Unicode property) */ 00665 OP_ANYNL, /* 17 \R (any newline sequence) */ 00666 OP_NOT_HSPACE, /* 18 \H (not horizontal whitespace) */ 00667 OP_HSPACE, /* 19 \h (horizontal whitespace) */ 00668 OP_NOT_VSPACE, /* 20 \V (not vertical whitespace) */ 00669 OP_VSPACE, /* 21 \v (vertical whitespace) */ 00670 OP_EXTUNI, /* 22 \X (extended Unicode sequence */ 00671 OP_EODN, /* 23 End of data or \n at end of data: \Z. */ 00672 OP_EOD, /* 24 End of data: \z */ 00673 00674 OP_OPT, /* 25 Set runtime options */ 00675 OP_CIRC, /* 26 Start of line - varies with multiline switch */ 00676 OP_DOLL, /* 27 End of line - varies with multiline switch */ 00677 OP_CHAR, /* 28 Match one character, casefully */ 00678 OP_CHARNC, /* 29 Match one character, caselessly */ 00679 OP_NOT, /* 30 Match one character, not the following one */ 00680 00681 OP_STAR, /* 31 The maximizing and minimizing versions of */ 00682 OP_MINSTAR, /* 32 these six opcodes must come in pairs, with */ 00683 OP_PLUS, /* 33 the minimizing one second. */ 00684 OP_MINPLUS, /* 34 This first set applies to single characters.*/ 00685 OP_QUERY, /* 35 */ 00686 OP_MINQUERY, /* 36 */ 00687 00688 OP_UPTO, /* 37 From 0 to n matches */ 00689 OP_MINUPTO, /* 38 */ 00690 OP_EXACT, /* 39 Exactly n matches */ 00691 00692 OP_POSSTAR, /* 40 Possessified star */ 00693 OP_POSPLUS, /* 41 Possessified plus */ 00694 OP_POSQUERY, /* 42 Posesssified query */ 00695 OP_POSUPTO, /* 43 Possessified upto */ 00696 00697 OP_NOTSTAR, /* 44 The maximizing and minimizing versions of */ 00698 OP_NOTMINSTAR, /* 45 these six opcodes must come in pairs, with */ 00699 OP_NOTPLUS, /* 46 the minimizing one second. They must be in */ 00700 OP_NOTMINPLUS, /* 47 exactly the same order as those above. */ 00701 OP_NOTQUERY, /* 48 This set applies to "not" single characters. */ 00702 OP_NOTMINQUERY, /* 49 */ 00703 00704 OP_NOTUPTO, /* 50 From 0 to n matches */ 00705 OP_NOTMINUPTO, /* 51 */ 00706 OP_NOTEXACT, /* 52 Exactly n matches */ 00707 00708 OP_NOTPOSSTAR, /* 53 Possessified versions */ 00709 OP_NOTPOSPLUS, /* 54 */ 00710 OP_NOTPOSQUERY, /* 55 */ 00711 OP_NOTPOSUPTO, /* 56 */ 00712 00713 OP_TYPESTAR, /* 57 The maximizing and minimizing versions of */ 00714 OP_TYPEMINSTAR, /* 58 these six opcodes must come in pairs, with */ 00715 OP_TYPEPLUS, /* 59 the minimizing one second. These codes must */ 00716 OP_TYPEMINPLUS, /* 60 be in exactly the same order as those above. */ 00717 OP_TYPEQUERY, /* 61 This set applies to character types such as \d */ 00718 OP_TYPEMINQUERY, /* 62 */ 00719 00720 OP_TYPEUPTO, /* 63 From 0 to n matches */ 00721 OP_TYPEMINUPTO, /* 64 */ 00722 OP_TYPEEXACT, /* 65 Exactly n matches */ 00723 00724 OP_TYPEPOSSTAR, /* 66 Possessified versions */ 00725 OP_TYPEPOSPLUS, /* 67 */ 00726 OP_TYPEPOSQUERY, /* 68 */ 00727 OP_TYPEPOSUPTO, /* 69 */ 00728 00729 OP_CRSTAR, /* 70 The maximizing and minimizing versions of */ 00730 OP_CRMINSTAR, /* 71 all these opcodes must come in pairs, with */ 00731 OP_CRPLUS, /* 72 the minimizing one second. These codes must */ 00732 OP_CRMINPLUS, /* 73 be in exactly the same order as those above. */ 00733 OP_CRQUERY, /* 74 These are for character classes and back refs */ 00734 OP_CRMINQUERY, /* 75 */ 00735 OP_CRRANGE, /* 76 These are different to the three sets above. */ 00736 OP_CRMINRANGE, /* 77 */ 00737 00738 OP_CLASS, /* 78 Match a character class, chars < 256 only */ 00739 OP_NCLASS, /* 79 Same, but the bitmap was created from a negative 00740 class - the difference is relevant only when a UTF-8 00741 character > 255 is encountered. */ 00742 00743 OP_XCLASS, /* 80 Extended class for handling UTF-8 chars within the 00744 class. This does both positive and negative. */ 00745 00746 OP_REF, /* 81 Match a back reference */ 00747 OP_RECURSE, /* 82 Match a numbered subpattern (possibly recursive) */ 00748 OP_CALLOUT, /* 83 Call out to external function if provided */ 00749 00750 OP_ALT, /* 84 Start of alternation */ 00751 OP_KET, /* 85 End of group that doesn't have an unbounded repeat */ 00752 OP_KETRMAX, /* 86 These two must remain together and in this */ 00753 OP_KETRMIN, /* 87 order. They are for groups the repeat for ever. */ 00754 00755 /* The assertions must come before BRA, CBRA, ONCE, and COND.*/ 00756 00757 OP_ASSERT, /* 88 Positive lookahead */ 00758 OP_ASSERT_NOT, /* 89 Negative lookahead */ 00759 OP_ASSERTBACK, /* 90 Positive lookbehind */ 00760 OP_ASSERTBACK_NOT, /* 91 Negative lookbehind */ 00761 OP_REVERSE, /* 92 Move pointer back - used in lookbehind assertions */ 00762 00763 /* ONCE, BRA, CBRA, and COND must come after the assertions, with ONCE first, 00764 as there's a test for >= ONCE for a subpattern that isn't an assertion. */ 00765 00766 OP_ONCE, /* 93 Atomic group */ 00767 OP_BRA, /* 94 Start of non-capturing bracket */ 00768 OP_CBRA, /* 95 Start of capturing bracket */ 00769 OP_COND, /* 96 Conditional group */ 00770 00771 /* These three must follow the previous three, in the same order. There's a 00772 check for >= SBRA to distinguish the two sets. */ 00773 00774 OP_SBRA, /* 97 Start of non-capturing bracket, check empty */ 00775 OP_SCBRA, /* 98 Start of capturing bracket, check empty */ 00776 OP_SCOND, /* 99 Conditional group, check empty */ 00777 00778 OP_CREF, /* 100 Used to hold a capture number as condition */ 00779 OP_RREF, /* 101 Used to hold a recursion number as condition */ 00780 OP_DEF, /* 102 The DEFINE condition */ 00781 00782 OP_BRAZERO, /* 103 These two must remain together and in this */ 00783 OP_BRAMINZERO, /* 104 order. */ 00784 00785 /* These are backtracking control verbs */ 00786 00787 OP_PRUNE, /* 105 */ 00788 OP_SKIP, /* 106 */ 00789 OP_THEN, /* 107 */ 00790 OP_COMMIT, /* 108 */ 00791 00792 /* These are forced failure and success verbs */ 00793 00794 OP_FAIL, /* 109 */ 00795 OP_ACCEPT, /* 110 */ 00796 00797 /* This is used to skip a subpattern with a {0} quantifier */ 00798 00799 OP_SKIPZERO /* 111 */ 00800 }; 00801 00802 00803 /* This macro defines textual names for all the opcodes. These are used only 00804 for debugging. The macro is referenced only in pcre_printint.c. */ 00805 00806 #define OP_NAME_LIST \ 00807 "End", "\\A", "\\G", "\\K", "\\B", "\\b", "\\D", "\\d", \ 00808 "\\S", "\\s", "\\W", "\\w", "Any", "AllAny", "Anybyte", \ 00809 "notprop", "prop", "\\R", "\\H", "\\h", "\\V", "\\v", \ 00810 "extuni", "\\Z", "\\z", \ 00811 "Opt", "^", "$", "char", "charnc", "not", \ 00812 "*", "*?", "+", "+?", "?", "??", "{", "{", "{", \ 00813 "*+","++", "?+", "{", \ 00814 "*", "*?", "+", "+?", "?", "??", "{", "{", "{", \ 00815 "*+","++", "?+", "{", \ 00816 "*", "*?", "+", "+?", "?", "??", "{", "{", "{", \ 00817 "*+","++", "?+", "{", \ 00818 "*", "*?", "+", "+?", "?", "??", "{", "{", \ 00819 "class", "nclass", "xclass", "Ref", "Recurse", "Callout", \ 00820 "Alt", "Ket", "KetRmax", "KetRmin", "Assert", "Assert not", \ 00821 "AssertB", "AssertB not", "Reverse", \ 00822 "Once", "Bra", "CBra", "Cond", "SBra", "SCBra", "SCond", \ 00823 "Cond ref", "Cond rec", "Cond def", "Brazero", "Braminzero", \ 00824 "*PRUNE", "*SKIP", "*THEN", "*COMMIT", "*FAIL", "*ACCEPT", \ 00825 "Skip zero" 00826 00827 00828 /* This macro defines the length of fixed length operations in the compiled 00829 regex. The lengths are used when searching for specific things, and also in the 00830 debugging printing of a compiled regex. We use a macro so that it can be 00831 defined close to the definitions of the opcodes themselves. 00832 00833 As things have been extended, some of these are no longer fixed lenths, but are 00834 minima instead. For example, the length of a single-character repeat may vary 00835 in UTF-8 mode. The code that uses this table must know about such things. */ 00836 00837 #define OP_LENGTHS \ 00838 1, /* End */ \ 00839 1, 1, 1, 1, 1, /* \A, \G, \K, \B, \b */ \ 00840 1, 1, 1, 1, 1, 1, /* \D, \d, \S, \s, \W, \w */ \ 00841 1, 1, 1, /* Any, AllAny, Anybyte */ \ 00842 3, 3, 1, /* NOTPROP, PROP, EXTUNI */ \ 00843 1, 1, 1, 1, 1, /* \R, \H, \h, \V, \v */ \ 00844 1, 1, 2, 1, 1, /* \Z, \z, Opt, ^, $ */ \ 00845 2, /* Char - the minimum length */ \ 00846 2, /* Charnc - the minimum length */ \ 00847 2, /* not */ \ 00848 /* Positive single-char repeats ** These are */ \ 00849 2, 2, 2, 2, 2, 2, /* *, *?, +, +?, ?, ?? ** minima in */ \ 00850 4, 4, 4, /* upto, minupto, exact ** UTF-8 mode */ \ 00851 2, 2, 2, 4, /* *+, ++, ?+, upto+ */ \ 00852 /* Negative single-char repeats - only for chars < 256 */ \ 00853 2, 2, 2, 2, 2, 2, /* NOT *, *?, +, +?, ?, ?? */ \ 00854 4, 4, 4, /* NOT upto, minupto, exact */ \ 00855 2, 2, 2, 4, /* Possessive *, +, ?, upto */ \ 00856 /* Positive type repeats */ \ 00857 2, 2, 2, 2, 2, 2, /* Type *, *?, +, +?, ?, ?? */ \ 00858 4, 4, 4, /* Type upto, minupto, exact */ \ 00859 2, 2, 2, 4, /* Possessive *+, ++, ?+, upto+ */ \ 00860 /* Character class & ref repeats */ \ 00861 1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */ \ 00862 5, 5, /* CRRANGE, CRMINRANGE */ \ 00863 33, /* CLASS */ \ 00864 33, /* NCLASS */ \ 00865 0, /* XCLASS - variable length */ \ 00866 3, /* REF */ \ 00867 1+LINK_SIZE, /* RECURSE */ \ 00868 2+2*LINK_SIZE, /* CALLOUT */ \ 00869 1+LINK_SIZE, /* Alt */ \ 00870 1+LINK_SIZE, /* Ket */ \ 00871 1+LINK_SIZE, /* KetRmax */ \ 00872 1+LINK_SIZE, /* KetRmin */ \ 00873 1+LINK_SIZE, /* Assert */ \ 00874 1+LINK_SIZE, /* Assert not */ \ 00875 1+LINK_SIZE, /* Assert behind */ \ 00876 1+LINK_SIZE, /* Assert behind not */ \ 00877 1+LINK_SIZE, /* Reverse */ \ 00878 1+LINK_SIZE, /* ONCE */ \ 00879 1+LINK_SIZE, /* BRA */ \ 00880 3+LINK_SIZE, /* CBRA */ \ 00881 1+LINK_SIZE, /* COND */ \ 00882 1+LINK_SIZE, /* SBRA */ \ 00883 3+LINK_SIZE, /* SCBRA */ \ 00884 1+LINK_SIZE, /* SCOND */ \ 00885 3, /* CREF */ \ 00886 3, /* RREF */ \ 00887 1, /* DEF */ \ 00888 1, 1, /* BRAZERO, BRAMINZERO */ \ 00889 1, 1, 1, 1, /* PRUNE, SKIP, THEN, COMMIT, */ \ 00890 1, 1, 1 /* FAIL, ACCEPT, SKIPZERO */ 00891 00892 00893 /* A magic value for OP_RREF to indicate the "any recursion" condition. */ 00894 00895 #define RREF_ANY 0xffff 00896 00897 /* Error code numbers. They are given names so that they can more easily be 00898 tracked. */ 00899 00900 enum { ERR0, ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9, 00901 ERR10, ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19, 00902 ERR20, ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR28, ERR29, 00903 ERR30, ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39, 00904 ERR40, ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49, 00905 ERR50, ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58, ERR59, 00906 ERR60, ERR61, ERR62, ERR63, ERR64 }; 00907 00908 /* The real format of the start of the pcre block; the index of names and the 00909 code vector run on as long as necessary after the end. We store an explicit 00910 offset to the name table so that if a regex is compiled on one host, saved, and 00911 then run on another where the size of pointers is different, all might still 00912 be well. For the case of compiled-on-4 and run-on-8, we include an extra 00913 pointer that is always NULL. For future-proofing, a few dummy fields were 00914 originally included - even though you can never get this planning right - but 00915 there is only one left now. 00916 00917 NOTE NOTE NOTE: 00918 Because people can now save and re-use compiled patterns, any additions to this 00919 structure should be made at the end, and something earlier (e.g. a new 00920 flag in the options or one of the dummy fields) should indicate that the new 00921 fields are present. Currently PCRE always sets the dummy fields to zero. 00922 NOTE NOTE NOTE: 00923 */ 00924 00925 typedef struct real_pcre { 00926 pcre_uint32 magic_number; 00927 pcre_uint32 size; /* Total that was malloced */ 00928 pcre_uint32 options; /* Public options */ 00929 pcre_uint16 flags; /* Private flags */ 00930 pcre_uint16 dummy1; /* For future use */ 00931 pcre_uint16 top_bracket; 00932 pcre_uint16 top_backref; 00933 pcre_uint16 first_byte; 00934 pcre_uint16 req_byte; 00935 pcre_uint16 name_table_offset; /* Offset to name table that follows */ 00936 pcre_uint16 name_entry_size; /* Size of any name items */ 00937 pcre_uint16 name_count; /* Number of name items */ 00938 pcre_uint16 ref_count; /* Reference count */ 00939 00940 const unsigned char *tables; /* Pointer to tables or NULL for std */ 00941 const unsigned char *nullpad; /* NULL padding */ 00942 } real_pcre; 00943 00944 /* The format of the block used to store data from pcre_study(). The same 00945 remark (see NOTE above) about extending this structure applies. */ 00946 00947 typedef struct pcre_study_data { 00948 pcre_uint32 size; /* Total that was malloced */ 00949 pcre_uint32 options; 00950 uschar start_bits[32]; 00951 } pcre_study_data; 00952 00953 /* Structure for passing "static" information around between the functions 00954 doing the compiling, so that they are thread-safe. */ 00955 00956 typedef struct compile_data { 00957 const uschar *lcc; /* Points to lower casing table */ 00958 const uschar *fcc; /* Points to case-flipping table */ 00959 const uschar *cbits; /* Points to character type table */ 00960 const uschar *ctypes; /* Points to table of type maps */ 00961 const uschar *start_workspace;/* The start of working space */ 00962 const uschar *start_code; /* The start of the compiled code */ 00963 const uschar *start_pattern; /* The start of the pattern */ 00964 const uschar *end_pattern; /* The end of the pattern */ 00965 uschar *hwm; /* High watermark of workspace */ 00966 uschar *name_table; /* The name/number table */ 00967 int names_found; /* Number of entries so far */ 00968 int name_entry_size; /* Size of each entry */ 00969 int bracount; /* Count of capturing parens as we compile */ 00970 int final_bracount; /* Saved value after first pass */ 00971 int top_backref; /* Maximum back reference */ 00972 unsigned int backref_map; /* Bitmap of low back refs */ 00973 int external_options; /* External (initial) options */ 00974 int external_flags; /* External flag bits to be set */ 00975 int req_varyopt; /* "After variable item" flag for reqbyte */ 00976 BOOL had_accept; /* (*ACCEPT) encountered */ 00977 int nltype; /* Newline type */ 00978 int nllen; /* Newline string length */ 00979 uschar nl[4]; /* Newline string when fixed length */ 00980 } compile_data; 00981 00982 /* Structure for maintaining a chain of pointers to the currently incomplete 00983 branches, for testing for left recursion. */ 00984 00985 typedef struct branch_chain { 00986 struct branch_chain *outer; 00987 uschar *current; 00988 } branch_chain; 00989 00990 /* Structure for items in a linked list that represents an explicit recursive 00991 call within the pattern. */ 00992 00993 typedef struct recursion_info { 00994 struct recursion_info *prevrec; /* Previous recursion record (or NULL) */ 00995 int group_num; /* Number of group that was called */ 00996 const uschar *after_call; /* "Return value": points after the call in the expr */ 00997 USPTR save_start; /* Old value of mstart */ 00998 int *offset_save; /* Pointer to start of saved offsets */ 00999 int saved_max; /* Number of saved offsets */ 01000 } recursion_info; 01001 01002 /* Structure for building a chain of data for holding the values of the subject 01003 pointer at the start of each subpattern, so as to detect when an empty string 01004 has been matched by a subpattern - to break infinite loops. */ 01005 01006 typedef struct eptrblock { 01007 struct eptrblock *epb_prev; 01008 USPTR epb_saved_eptr; 01009 } eptrblock; 01010 01011 01012 /* Structure for passing "static" information around between the functions 01013 doing traditional NFA matching, so that they are thread-safe. */ 01014 01015 typedef struct match_data { 01016 unsigned long int match_call_count; /* As it says */ 01017 unsigned long int match_limit; /* As it says */ 01018 unsigned long int match_limit_recursion; /* As it says */ 01019 int *offset_vector; /* Offset vector */ 01020 int offset_end; /* One past the end */ 01021 int offset_max; /* The maximum usable for return data */ 01022 int nltype; /* Newline type */ 01023 int nllen; /* Newline string length */ 01024 uschar nl[4]; /* Newline string when fixed */ 01025 const uschar *lcc; /* Points to lower casing table */ 01026 const uschar *ctypes; /* Points to table of type maps */ 01027 BOOL offset_overflow; /* Set if too many extractions */ 01028 BOOL notbol; /* NOTBOL flag */ 01029 BOOL noteol; /* NOTEOL flag */ 01030 BOOL utf8; /* UTF8 flag */ 01031 BOOL jscript_compat; /* JAVASCRIPT_COMPAT flag */ 01032 BOOL endonly; /* Dollar not before final \n */ 01033 BOOL notempty; /* Empty string match not wanted */ 01034 BOOL partial; /* PARTIAL flag */ 01035 BOOL hitend; /* Hit the end of the subject at some point */ 01036 BOOL bsr_anycrlf; /* \R is just any CRLF, not full Unicode */ 01037 const uschar *start_code; /* For use when recursing */ 01038 USPTR start_subject; /* Start of the subject string */ 01039 USPTR end_subject; /* End of the subject string */ 01040 USPTR start_match_ptr; /* Start of matched string */ 01041 USPTR end_match_ptr; /* Subject position at end match */ 01042 int end_offset_top; /* Highwater mark at end of match */ 01043 int capture_last; /* Most recent capture number */ 01044 int start_offset; /* The start offset value */ 01045 eptrblock *eptrchain; /* Chain of eptrblocks for tail recursions */ 01046 int eptrn; /* Next free eptrblock */ 01047 recursion_info *recursive; /* Linked list of recursion data */ 01048 void *callout_data; /* To pass back to callouts */ 01049 } match_data; 01050 01051 /* A similar structure is used for the same purpose by the DFA matching 01052 functions. */ 01053 01054 typedef struct dfa_match_data { 01055 const uschar *start_code; /* Start of the compiled pattern */ 01056 const uschar *start_subject; /* Start of the subject string */ 01057 const uschar *end_subject; /* End of subject string */ 01058 const uschar *tables; /* Character tables */ 01059 int moptions; /* Match options */ 01060 int poptions; /* Pattern options */ 01061 int nltype; /* Newline type */ 01062 int nllen; /* Newline string length */ 01063 uschar nl[4]; /* Newline string when fixed */ 01064 void *callout_data; /* To pass back to callouts */ 01065 } dfa_match_data; 01066 01067 /* Bit definitions for entries in the pcre_ctypes table. */ 01068 01069 #define ctype_space 0x01 01070 #define ctype_letter 0x02 01071 #define ctype_digit 0x04 01072 #define ctype_xdigit 0x08 01073 #define ctype_word 0x10 /* alphanumeric or '_' */ 01074 #define ctype_meta 0x80 /* regexp meta char or zero (end pattern) */ 01075 01076 /* Offsets for the bitmap tables in pcre_cbits. Each table contains a set 01077 of bits for a class map. Some classes are built by combining these tables. */ 01078 01079 #define cbit_space 0 /* [:space:] or \s */ 01080 #define cbit_xdigit 32 /* [:xdigit:] */ 01081 #define cbit_digit 64 /* [:digit:] or \d */ 01082 #define cbit_upper 96 /* [:upper:] */ 01083 #define cbit_lower 128 /* [:lower:] */ 01084 #define cbit_word 160 /* [:word:] or \w */ 01085 #define cbit_graph 192 /* [:graph:] */ 01086 #define cbit_print 224 /* [:print:] */ 01087 #define cbit_punct 256 /* [:punct:] */ 01088 #define cbit_cntrl 288 /* [:cntrl:] */ 01089 #define cbit_length 320 /* Length of the cbits table */ 01090 01091 /* Offsets of the various tables from the base tables pointer, and 01092 total length. */ 01093 01094 #define lcc_offset 0 01095 #define fcc_offset 256 01096 #define cbits_offset 512 01097 #define ctypes_offset (cbits_offset + cbit_length) 01098 #define tables_length (ctypes_offset + 256) 01099 01100 /* Layout of the UCP type table that translates property names into types and 01101 codes. Each entry used to point directly to a name, but to reduce the number of 01102 relocations in shared libraries, it now has an offset into a single string 01103 instead. */ 01104 01105 typedef struct { 01106 pcre_uint16 name_offset; 01107 pcre_uint16 type; 01108 pcre_uint16 value; 01109 } ucp_type_table; 01110 01111 01112 /* Internal shared data tables. These are tables that are used by more than one 01113 of the exported public functions. They have to be "external" in the C sense, 01114 but are not part of the PCRE public API. The data for these tables is in the 01115 pcre_tables.c module. */ 01116 01117 extern const int _pcre_utf8_table1[]; 01118 extern const int _pcre_utf8_table2[]; 01119 extern const int _pcre_utf8_table3[]; 01120 extern const uschar _pcre_utf8_table4[]; 01121 01122 extern const int _pcre_utf8_table1_size; 01123 01124 extern const char _pcre_utt_names[]; 01125 extern const ucp_type_table _pcre_utt[]; 01126 extern const int _pcre_utt_size; 01127 01128 extern const uschar _pcre_default_tables[]; 01129 01130 extern const uschar _pcre_OP_lengths[]; 01131 01132 01133 /* Internal shared functions. These are functions that are used by more than 01134 one of the exported public functions. They have to be "external" in the C 01135 sense, but are not part of the PCRE public API. */ 01136 01137 extern BOOL _pcre_is_newline(const uschar *, int, const uschar *, 01138 int *, BOOL); 01139 extern int _pcre_ord2utf8(int, uschar *); 01140 extern real_pcre *_pcre_try_flipped(const real_pcre *, real_pcre *, 01141 const pcre_study_data *, pcre_study_data *); 01142 extern int _pcre_valid_utf8(const uschar *, int); 01143 extern BOOL _pcre_was_newline(const uschar *, int, const uschar *, 01144 int *, BOOL); 01145 extern BOOL _pcre_xclass(int, const uschar *); 01146 01147 01148 /* Unicode character database (UCD) */ 01149 01150 typedef struct { 01151 uschar script; 01152 uschar chartype; 01153 pcre_int32 other_case; 01154 } ucd_record; 01155 01156 extern const ucd_record _pcre_ucd_records[]; 01157 extern const uschar _pcre_ucd_stage1[]; 01158 extern const pcre_uint16 _pcre_ucd_stage2[]; 01159 extern const int _pcre_ucp_gentype[]; 01160 01161 01162 /* UCD access macros */ 01163 01164 #define UCD_BLOCK_SIZE 128 01165 #define GET_UCD(ch) (_pcre_ucd_records + \ 01166 _pcre_ucd_stage2[_pcre_ucd_stage1[(ch) / UCD_BLOCK_SIZE] * \ 01167 UCD_BLOCK_SIZE + ch % UCD_BLOCK_SIZE]) 01168 01169 #define UCD_CHARTYPE(ch) GET_UCD(ch)->chartype 01170 #define UCD_SCRIPT(ch) GET_UCD(ch)->script 01171 #define UCD_CATEGORY(ch) _pcre_ucp_gentype[UCD_CHARTYPE(ch)] 01172 #define UCD_OTHERCASE(ch) (ch + GET_UCD(ch)->other_case) 01173 01174 #endif 01175 01176 /* End of pcre_internal.h */