• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

src/pcre/pcre_internal.h

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-2009 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 /* We do not support both EBCDIC and UTF-8 at the same time. The "configure"
00055 script prevents both being selected, but not everybody uses "configure". */
00056 
00057 #if defined EBCDIC && defined SUPPORT_UTF8
00058 #error The use of both EBCDIC and SUPPORT_UTF8 is not supported.
00059 #endif
00060 
00061 /* If SUPPORT_UCP is defined, SUPPORT_UTF8 must also be defined. The
00062 "configure" script ensures this, but not everybody uses "configure". */
00063 
00064 #if defined SUPPORT_UCP && !defined SUPPORT_UTF8
00065 #define SUPPORT_UTF8 1
00066 #endif
00067 
00068 /* Use a macro for debugging printing, 'cause that eliminates the use of #ifdef
00069 inline, and there are *still* stupid compilers about that don't like indented
00070 pre-processor statements, or at least there were when I first wrote this. After
00071 all, it had only been about 10 years then...
00072 
00073 It turns out that the Mac Debugging.h header also defines the macro DPRINTF, so
00074 be absolutely sure we get our version. */
00075 
00076 #undef DPRINTF
00077 #ifdef DEBUG_PCRE
00078 #define DPRINTF(p) printf p
00079 #else
00080 #define DPRINTF(p) /* Nothing */
00081 #endif
00082 
00083 
00084 /* Standard C headers plus the external interface definition. The only time
00085 setjmp and stdarg are used is when NO_RECURSE is set. */
00086 
00087 #include <ctype.h>
00088 #include <limits.h>
00089 #include <setjmp.h>
00090 #include <stdarg.h>
00091 #include <stddef.h>
00092 #include <stdio.h>
00093 #include <stdlib.h>
00094 #include <string.h>
00095 
00096 /* When compiling a DLL for Windows, the exported symbols have to be declared
00097 using some MS magic. I found some useful information on this web page:
00098 http://msdn2.microsoft.com/en-us/library/y4h7bcy6(VS.80).aspx. According to the
00099 information there, using __declspec(dllexport) without "extern" we have a
00100 definition; with "extern" we have a declaration. The settings here override the
00101 setting in pcre.h (which is included below); it defines only PCRE_EXP_DECL,
00102 which is all that is needed for applications (they just import the symbols). We
00103 use:
00104 
00105   PCRE_EXP_DECL       for declarations
00106   PCRE_EXP_DEFN       for definitions of exported functions
00107   PCRE_EXP_DATA_DEFN  for definitions of exported variables
00108 
00109 The reason for the two DEFN macros is that in non-Windows environments, one
00110 does not want to have "extern" before variable definitions because it leads to
00111 compiler warnings. So we distinguish between functions and variables. In
00112 Windows, the two should always be the same.
00113 
00114 The reason for wrapping this in #ifndef PCRE_EXP_DECL is so that pcretest,
00115 which is an application, but needs to import this file in order to "peek" at
00116 internals, can #include pcre.h first to get an application's-eye view.
00117 
00118 In principle, people compiling for non-Windows, non-Unix-like (i.e. uncommon,
00119 special-purpose environments) might want to stick other stuff in front of
00120 exported symbols. That's why, in the non-Windows case, we set PCRE_EXP_DEFN and
00121 PCRE_EXP_DATA_DEFN only if they are not already set. */
00122 
00123 #ifndef PCRE_EXP_DECL
00124 //#  ifdef _WIN32
00125 //#    ifndef PCRE_STATIC
00126 //#      define PCRE_EXP_DECL       extern __declspec(dllexport)
00127 //#      define PCRE_EXP_DEFN       __declspec(dllexport)
00128 //#      define PCRE_EXP_DATA_DEFN  __declspec(dllexport)
00129 //#    else
00130 //#      define PCRE_EXP_DECL       extern
00131 //#      define PCRE_EXP_DEFN
00132 //#      define PCRE_EXP_DATA_DEFN
00133 //#    endif
00134 //#  else
00135 #    ifdef __cplusplus
00136 #      define PCRE_EXP_DECL       extern "C"
00137 #    else
00138 #      define PCRE_EXP_DECL       extern
00139 #    endif
00140 #    ifndef PCRE_EXP_DEFN
00141 #      define PCRE_EXP_DEFN       PCRE_EXP_DECL
00142 #    endif
00143 #    ifndef PCRE_EXP_DATA_DEFN
00144 #      define PCRE_EXP_DATA_DEFN
00145 #    endif
00146 //#  endif
00147 #endif
00148 
00149 /* When compiling with the MSVC compiler, it is sometimes necessary to include
00150 a "calling convention" before exported function names. (This is secondhand
00151 information; I know nothing about MSVC myself). For example, something like
00152 
00153   void __cdecl function(....)
00154 
00155 might be needed. In order so make this easy, all the exported functions have
00156 PCRE_CALL_CONVENTION just before their names. It is rarely needed; if not
00157 set, we ensure here that it has no effect. */
00158 
00159 #ifndef PCRE_CALL_CONVENTION
00160 #define PCRE_CALL_CONVENTION
00161 #endif
00162 
00163 /* We need to have types that specify unsigned 16-bit and 32-bit integers. We
00164 cannot determine these outside the compilation (e.g. by running a program as
00165 part of "configure") because PCRE is often cross-compiled for use on other
00166 systems. Instead we make use of the maximum sizes that are available at
00167 preprocessor time in standard C environments. */
00168 
00169 #if USHRT_MAX == 65535
00170   typedef unsigned short pcre_uint16;
00171   typedef short pcre_int16;
00172 #elif UINT_MAX == 65535
00173   typedef unsigned int pcre_uint16;
00174   typedef int pcre_int16;
00175 #else
00176   #error Cannot determine a type for 16-bit unsigned integers
00177 #endif
00178 
00179 #if UINT_MAX == 4294967295
00180   typedef unsigned int pcre_uint32;
00181   typedef int pcre_int32;
00182 #elif ULONG_MAX == 4294967295
00183   typedef unsigned long int pcre_uint32;
00184   typedef long int pcre_int32;
00185 #else
00186   #error Cannot determine a type for 32-bit unsigned integers
00187 #endif
00188 
00189 /* All character handling must be done as unsigned characters. Otherwise there
00190 are problems with top-bit-set characters and functions such as isspace().
00191 However, we leave the interface to the outside world as char *, because that
00192 should make things easier for callers. We define a short type for unsigned char
00193 to save lots of typing. I tried "uchar", but it causes problems on Digital
00194 Unix, where it is defined in sys/types, so use "uschar" instead. */
00195 
00196 typedef unsigned char uschar;
00197 
00198 /* This is an unsigned int value that no character can ever have. UTF-8
00199 characters only go up to 0x7fffffff (though Unicode doesn't go beyond
00200 0x0010ffff). */
00201 
00202 #define NOTACHAR 0xffffffff
00203 
00204 /* PCRE is able to support several different kinds of newline (CR, LF, CRLF,
00205 "any" and "anycrlf" at present). The following macros are used to package up
00206 testing for newlines. NLBLOCK, PSSTART, and PSEND are defined in the various
00207 modules to indicate in which datablock the parameters exist, and what the
00208 start/end of string field names are. */
00209 
00210 #define NLTYPE_FIXED    0     /* Newline is a fixed length string */
00211 #define NLTYPE_ANY      1     /* Newline is any Unicode line ending */
00212 #define NLTYPE_ANYCRLF  2     /* Newline is CR, LF, or CRLF */
00213 
00214 /* This macro checks for a newline at the given position */
00215 
00216 #define IS_NEWLINE(p) \
00217   ((NLBLOCK->nltype != NLTYPE_FIXED)? \
00218     ((p) < NLBLOCK->PSEND && \
00219      _pcre_is_newline((p), NLBLOCK->nltype, NLBLOCK->PSEND, &(NLBLOCK->nllen),\
00220        utf8)) \
00221     : \
00222     ((p) <= NLBLOCK->PSEND - NLBLOCK->nllen && \
00223      (p)[0] == NLBLOCK->nl[0] && \
00224      (NLBLOCK->nllen == 1 || (p)[1] == NLBLOCK->nl[1]) \
00225     ) \
00226   )
00227 
00228 /* This macro checks for a newline immediately preceding the given position */
00229 
00230 #define WAS_NEWLINE(p) \
00231   ((NLBLOCK->nltype != NLTYPE_FIXED)? \
00232     ((p) > NLBLOCK->PSSTART && \
00233      _pcre_was_newline((p), NLBLOCK->nltype, NLBLOCK->PSSTART, \
00234        &(NLBLOCK->nllen), utf8)) \
00235     : \
00236     ((p) >= NLBLOCK->PSSTART + NLBLOCK->nllen && \
00237      (p)[-NLBLOCK->nllen] == NLBLOCK->nl[0] && \
00238      (NLBLOCK->nllen == 1 || (p)[-NLBLOCK->nllen+1] == NLBLOCK->nl[1]) \
00239     ) \
00240   )
00241 
00242 /* When PCRE is compiled as a C++ library, the subject pointer can be replaced
00243 with a custom type. This makes it possible, for example, to allow pcre_exec()
00244 to process subject strings that are discontinuous by using a smart pointer
00245 class. It must always be possible to inspect all of the subject string in
00246 pcre_exec() because of the way it backtracks. Two macros are required in the
00247 normal case, for sign-unspecified and unsigned char pointers. The former is
00248 used for the external interface and appears in pcre.h, which is why its name
00249 must begin with PCRE_. */
00250 
00251 #ifdef CUSTOM_SUBJECT_PTR
00252 #define PCRE_SPTR CUSTOM_SUBJECT_PTR
00253 #define USPTR CUSTOM_SUBJECT_PTR
00254 #else
00255 #define PCRE_SPTR const char *
00256 #define USPTR const unsigned char *
00257 #endif
00258 
00259 
00260 
00261 /* Include the public PCRE header and the definitions of UCP character property
00262 values. */
00263 
00264 #include "pcre.h"
00265 #include "ucp.h"
00266 
00267 /* When compiling for use with the Virtual Pascal compiler, these functions
00268 need to have their names changed. PCRE must be compiled with the -DVPCOMPAT
00269 option on the command line. */
00270 
00271 #ifdef VPCOMPAT
00272 #define strlen(s)        _strlen(s)
00273 #define strncmp(s1,s2,m) _strncmp(s1,s2,m)
00274 #define memcmp(s,c,n)    _memcmp(s,c,n)
00275 #define memcpy(d,s,n)    _memcpy(d,s,n)
00276 #define memmove(d,s,n)   _memmove(d,s,n)
00277 #define memset(s,c,n)    _memset(s,c,n)
00278 #else  /* VPCOMPAT */
00279 
00280 /* To cope with SunOS4 and other systems that lack memmove() but have bcopy(),
00281 define a macro for memmove() if HAVE_MEMMOVE is false, provided that HAVE_BCOPY
00282 is set. Otherwise, include an emulating function for those systems that have
00283 neither (there some non-Unix environments where this is the case). */
00284 
00285 #ifndef HAVE_MEMMOVE
00286 #undef  memmove        /* some systems may have a macro */
00287 #ifdef HAVE_BCOPY
00288 #define memmove(a, b, c) bcopy(b, a, c)
00289 #else  /* HAVE_BCOPY */
00290 static void *
00291 pcre_memmove(void *d, const void *s, size_t n)
00292 {
00293 size_t i;
00294 unsigned char *dest = (unsigned char *)d;
00295 const unsigned char *src = (const unsigned char *)s;
00296 if (dest > src)
00297   {
00298   dest += n;
00299   src += n;
00300   for (i = 0; i < n; ++i) *(--dest) = *(--src);
00301   return (void *)dest;
00302   }
00303 else
00304   {
00305   for (i = 0; i < n; ++i) *dest++ = *src++;
00306   return (void *)(dest - n);
00307   }
00308 }
00309 #define memmove(a, b, c) pcre_memmove(a, b, c)
00310 #endif   /* not HAVE_BCOPY */
00311 #endif   /* not HAVE_MEMMOVE */
00312 #endif   /* not VPCOMPAT */
00313 
00314 
00315 /* PCRE keeps offsets in its compiled code as 2-byte quantities (always stored
00316 in big-endian order) by default. These are used, for example, to link from the
00317 start of a subpattern to its alternatives and its end. The use of 2 bytes per
00318 offset limits the size of the compiled regex to around 64K, which is big enough
00319 for almost everybody. However, I received a request for an even bigger limit.
00320 For this reason, and also to make the code easier to maintain, the storing and
00321 loading of offsets from the byte string is now handled by the macros that are
00322 defined here.
00323 
00324 The macros are controlled by the value of LINK_SIZE. This defaults to 2 in
00325 the config.h file, but can be overridden by using -D on the command line. This
00326 is automated on Unix systems via the "configure" command. */
00327 
00328 #if LINK_SIZE == 2
00329 
00330 #define PUT(a,n,d)   \
00331   (a[n] = (d) >> 8), \
00332   (a[(n)+1] = (d) & 255)
00333 
00334 #define GET(a,n) \
00335   (((a)[n] << 8) | (a)[(n)+1])
00336 
00337 #define MAX_PATTERN_SIZE (1 << 16)
00338 
00339 
00340 #elif LINK_SIZE == 3
00341 
00342 #define PUT(a,n,d)       \
00343   (a[n] = (d) >> 16),    \
00344   (a[(n)+1] = (d) >> 8), \
00345   (a[(n)+2] = (d) & 255)
00346 
00347 #define GET(a,n) \
00348   (((a)[n] << 16) | ((a)[(n)+1] << 8) | (a)[(n)+2])
00349 
00350 #define MAX_PATTERN_SIZE (1 << 24)
00351 
00352 
00353 #elif LINK_SIZE == 4
00354 
00355 #define PUT(a,n,d)        \
00356   (a[n] = (d) >> 24),     \
00357   (a[(n)+1] = (d) >> 16), \
00358   (a[(n)+2] = (d) >> 8),  \
00359   (a[(n)+3] = (d) & 255)
00360 
00361 #define GET(a,n) \
00362   (((a)[n] << 24) | ((a)[(n)+1] << 16) | ((a)[(n)+2] << 8) | (a)[(n)+3])
00363 
00364 #define MAX_PATTERN_SIZE (1 << 30)   /* Keep it positive */
00365 
00366 
00367 #else
00368 #error LINK_SIZE must be either 2, 3, or 4
00369 #endif
00370 
00371 
00372 /* Convenience macro defined in terms of the others */
00373 
00374 #define PUTINC(a,n,d)   PUT(a,n,d), a += LINK_SIZE
00375 
00376 
00377 /* PCRE uses some other 2-byte quantities that do not change when the size of
00378 offsets changes. There are used for repeat counts and for other things such as
00379 capturing parenthesis numbers in back references. */
00380 
00381 #define PUT2(a,n,d)   \
00382   a[n] = (d) >> 8; \
00383   a[(n)+1] = (d) & 255
00384 
00385 #define GET2(a,n) \
00386   (((a)[n] << 8) | (a)[(n)+1])
00387 
00388 #define PUT2INC(a,n,d)  PUT2(a,n,d), a += 2
00389 
00390 
00391 /* When UTF-8 encoding is being used, a character is no longer just a single
00392 byte. The macros for character handling generate simple sequences when used in
00393 byte-mode, and more complicated ones for UTF-8 characters. BACKCHAR should
00394 never be called in byte mode. To make sure it can never even appear when UTF-8
00395 support is omitted, we don't even define it. */
00396 
00397 #ifndef SUPPORT_UTF8
00398 #define GETCHAR(c, eptr) c = *eptr;
00399 #define GETCHARTEST(c, eptr) c = *eptr;
00400 #define GETCHARINC(c, eptr) c = *eptr++;
00401 #define GETCHARINCTEST(c, eptr) c = *eptr++;
00402 #define GETCHARLEN(c, eptr, len) c = *eptr;
00403 /* #define BACKCHAR(eptr) */
00404 
00405 #else   /* SUPPORT_UTF8 */
00406 
00407 /* Get the next UTF-8 character, not advancing the pointer. This is called when
00408 we know we are in UTF-8 mode. */
00409 
00410 #define GETCHAR(c, eptr) \
00411   c = *eptr; \
00412   if (c >= 0xc0) \
00413     { \
00414     int gcii; \
00415     int gcaa = _pcre_utf8_table4[c & 0x3f];  /* Number of additional bytes */ \
00416     int gcss = 6*gcaa; \
00417     c = (c & _pcre_utf8_table3[gcaa]) << gcss; \
00418     for (gcii = 1; gcii <= gcaa; gcii++) \
00419       { \
00420       gcss -= 6; \
00421       c |= (eptr[gcii] & 0x3f) << gcss; \
00422       } \
00423     }
00424 
00425 /* Get the next UTF-8 character, testing for UTF-8 mode, and not advancing the
00426 pointer. */
00427 
00428 #define GETCHARTEST(c, eptr) \
00429   c = *eptr; \
00430   if (utf8 && c >= 0xc0) \
00431     { \
00432     int gcii; \
00433     int gcaa = _pcre_utf8_table4[c & 0x3f];  /* Number of additional bytes */ \
00434     int gcss = 6*gcaa; \
00435     c = (c & _pcre_utf8_table3[gcaa]) << gcss; \
00436     for (gcii = 1; gcii <= gcaa; gcii++) \
00437       { \
00438       gcss -= 6; \
00439       c |= (eptr[gcii] & 0x3f) << gcss; \
00440       } \
00441     }
00442 
00443 /* Get the next UTF-8 character, advancing the pointer. This is called when we
00444 know we are in UTF-8 mode. */
00445 
00446 #define GETCHARINC(c, eptr) \
00447   c = *eptr++; \
00448   if (c >= 0xc0) \
00449     { \
00450     int gcaa = _pcre_utf8_table4[c & 0x3f];  /* Number of additional bytes */ \
00451     int gcss = 6*gcaa; \
00452     c = (c & _pcre_utf8_table3[gcaa]) << gcss; \
00453     while (gcaa-- > 0) \
00454       { \
00455       gcss -= 6; \
00456       c |= (*eptr++ & 0x3f) << gcss; \
00457       } \
00458     }
00459 
00460 /* Get the next character, testing for UTF-8 mode, and advancing the pointer */
00461 
00462 #define GETCHARINCTEST(c, eptr) \
00463   c = *eptr++; \
00464   if (utf8 && c >= 0xc0) \
00465     { \
00466     int gcaa = _pcre_utf8_table4[c & 0x3f];  /* Number of additional bytes */ \
00467     int gcss = 6*gcaa; \
00468     c = (c & _pcre_utf8_table3[gcaa]) << gcss; \
00469     while (gcaa-- > 0) \
00470       { \
00471       gcss -= 6; \
00472       c |= (*eptr++ & 0x3f) << gcss; \
00473       } \
00474     }
00475 
00476 /* Get the next UTF-8 character, not advancing the pointer, incrementing length
00477 if there are extra bytes. This is called when we know we are in UTF-8 mode. */
00478 
00479 #define GETCHARLEN(c, eptr, len) \
00480   c = *eptr; \
00481   if (c >= 0xc0) \
00482     { \
00483     int gcii; \
00484     int gcaa = _pcre_utf8_table4[c & 0x3f];  /* Number of additional bytes */ \
00485     int gcss = 6*gcaa; \
00486     c = (c & _pcre_utf8_table3[gcaa]) << gcss; \
00487     for (gcii = 1; gcii <= gcaa; gcii++) \
00488       { \
00489       gcss -= 6; \
00490       c |= (eptr[gcii] & 0x3f) << gcss; \
00491       } \
00492     len += gcaa; \
00493     }
00494 
00495 /* Get the next UTF-8 character, testing for UTF-8 mode, not advancing the
00496 pointer, incrementing length if there are extra bytes. This is called when we
00497 know we are in UTF-8 mode. */
00498 
00499 #define GETCHARLENTEST(c, eptr, len) \
00500   c = *eptr; \
00501   if (utf8 && c >= 0xc0) \
00502     { \
00503     int gcii; \
00504     int gcaa = _pcre_utf8_table4[c & 0x3f];  /* Number of additional bytes */ \
00505     int gcss = 6*gcaa; \
00506     c = (c & _pcre_utf8_table3[gcaa]) << gcss; \
00507     for (gcii = 1; gcii <= gcaa; gcii++) \
00508       { \
00509       gcss -= 6; \
00510       c |= (eptr[gcii] & 0x3f) << gcss; \
00511       } \
00512     len += gcaa; \
00513     }
00514 
00515 /* If the pointer is not at the start of a character, move it back until
00516 it is. This is called only in UTF-8 mode - we don't put a test within the macro
00517 because almost all calls are already within a block of UTF-8 only code. */
00518 
00519 #define BACKCHAR(eptr) while((*eptr & 0xc0) == 0x80) eptr--
00520 
00521 #endif
00522 
00523 
00524 /* In case there is no definition of offsetof() provided - though any proper
00525 Standard C system should have one. */
00526 
00527 #ifndef offsetof
00528 #define offsetof(p_type,field) ((size_t)&(((p_type *)0)->field))
00529 #endif
00530 
00531 
00532 /* These are the public options that can change during matching. */
00533 
00534 #define PCRE_IMS (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL)
00535 
00536 /* Private flags containing information about the compiled regex. They used to
00537 live at the top end of the options word, but that got almost full, so now they
00538 are in a 16-bit flags word. From release 8.00, PCRE_NOPARTIAL is unused, as
00539 the restrictions on partial matching have been lifted. It remains for backwards
00540 compatibility. */
00541 
00542 #define PCRE_NOPARTIAL     0x0001  /* can't use partial with this regex */
00543 #define PCRE_FIRSTSET      0x0002  /* first_byte is set */
00544 #define PCRE_REQCHSET      0x0004  /* req_byte is set */
00545 #define PCRE_STARTLINE     0x0008  /* start after \n for multiline */
00546 #define PCRE_JCHANGED      0x0010  /* j option used in regex */
00547 #define PCRE_HASCRORLF     0x0020  /* explicit \r or \n in pattern */
00548 
00549 /* Options for the "extra" block produced by pcre_study(). */
00550 
00551 #define PCRE_STUDY_MAPPED   0x01     /* a map of starting chars exists */
00552 #define PCRE_STUDY_MINLEN   0x02     /* a minimum length field exists */
00553 
00554 /* Masks for identifying the public options that are permitted at compile
00555 time, run time, or study time, respectively. */
00556 
00557 #define PCRE_NEWLINE_BITS (PCRE_NEWLINE_CR|PCRE_NEWLINE_LF|PCRE_NEWLINE_ANY| \
00558                            PCRE_NEWLINE_ANYCRLF)
00559 
00560 #define PUBLIC_COMPILE_OPTIONS \
00561   (PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \
00562    PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY|PCRE_UTF8| \
00563    PCRE_NO_AUTO_CAPTURE|PCRE_NO_UTF8_CHECK|PCRE_AUTO_CALLOUT|PCRE_FIRSTLINE| \
00564    PCRE_DUPNAMES|PCRE_NEWLINE_BITS|PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE| \
00565    PCRE_JAVASCRIPT_COMPAT)
00566 
00567 #define PUBLIC_EXEC_OPTIONS \
00568   (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NOTEMPTY_ATSTART| \
00569    PCRE_NO_UTF8_CHECK|PCRE_PARTIAL_HARD|PCRE_PARTIAL_SOFT|PCRE_NEWLINE_BITS| \
00570    PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE|PCRE_NO_START_OPTIMIZE)
00571 
00572 #define PUBLIC_DFA_EXEC_OPTIONS \
00573   (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NOTEMPTY_ATSTART| \
00574    PCRE_NO_UTF8_CHECK|PCRE_PARTIAL_HARD|PCRE_PARTIAL_SOFT|PCRE_DFA_SHORTEST| \
00575    PCRE_DFA_RESTART|PCRE_NEWLINE_BITS|PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE| \
00576    PCRE_NO_START_OPTIMIZE)
00577 
00578 #define PUBLIC_STUDY_OPTIONS 0   /* None defined */
00579 
00580 /* Magic number to provide a small check against being handed junk. Also used
00581 to detect whether a pattern was compiled on a host of different endianness. */
00582 
00583 #define MAGIC_NUMBER  0x50435245UL   /* 'PCRE' */
00584 
00585 /* Negative values for the firstchar and reqchar variables */
00586 
00587 #define REQ_UNSET (-2)
00588 #define REQ_NONE  (-1)
00589 
00590 /* The maximum remaining length of subject we are prepared to search for a
00591 req_byte match. */
00592 
00593 #define REQ_BYTE_MAX 1000
00594 
00595 /* Flags added to firstbyte or reqbyte; a "non-literal" item is either a
00596 variable-length repeat, or a anything other than literal characters. */
00597 
00598 #define REQ_CASELESS 0x0100    /* indicates caselessness */
00599 #define REQ_VARY     0x0200    /* reqbyte followed non-literal item */
00600 
00601 /* Miscellaneous definitions. The #ifndef is to pacify compiler warnings in
00602 environments where these macros are defined elsewhere. Unfortunately, there
00603 is no way to do the same for the typedef. */
00604 
00605 typedef int BOOL;
00606 
00607 #ifndef FALSE
00608 #define FALSE   0
00609 #define TRUE    1
00610 #endif
00611 
00612 /* If PCRE is to support UTF-8 on EBCDIC platforms, we cannot use normal
00613 character constants like '*' because the compiler would emit their EBCDIC code,
00614 which is different from their ASCII/UTF-8 code. Instead we define macros for
00615 the characters so that they always use the ASCII/UTF-8 code when UTF-8 support
00616 is enabled. When UTF-8 support is not enabled, the definitions use character
00617 literals. Both character and string versions of each character are needed, and
00618 there are some longer strings as well.
00619 
00620 This means that, on EBCDIC platforms, the PCRE library can handle either
00621 EBCDIC, or UTF-8, but not both. To support both in the same compiled library
00622 would need different lookups depending on whether PCRE_UTF8 was set or not.
00623 This would make it impossible to use characters in switch/case statements,
00624 which would reduce performance. For a theoretical use (which nobody has asked
00625 for) in a minority area (EBCDIC platforms), this is not sensible. Any
00626 application that did need both could compile two versions of the library, using
00627 macros to give the functions distinct names. */
00628 
00629 #ifndef SUPPORT_UTF8
00630 
00631 /* UTF-8 support is not enabled; use the platform-dependent character literals
00632 so that PCRE works on both ASCII and EBCDIC platforms, in non-UTF-mode only. */
00633 
00634 #define CHAR_HT                     '\t'
00635 #define CHAR_VT                     '\v'
00636 #define CHAR_FF                     '\f'
00637 #define CHAR_CR                     '\r'
00638 #define CHAR_NL                     '\n'
00639 #define CHAR_BS                     '\b'
00640 #define CHAR_BEL                    '\a'
00641 #ifdef EBCDIC
00642 #define CHAR_ESC                    '\047'
00643 #define CHAR_DEL                    '\007'
00644 #else
00645 #define CHAR_ESC                    '\033'
00646 #define CHAR_DEL                    '\177'
00647 #endif
00648 
00649 #define CHAR_SPACE                  ' '
00650 #define CHAR_EXCLAMATION_MARK       '!'
00651 #define CHAR_QUOTATION_MARK         '"'
00652 #define CHAR_NUMBER_SIGN            '#'
00653 #define CHAR_DOLLAR_SIGN            '$'
00654 #define CHAR_PERCENT_SIGN           '%'
00655 #define CHAR_AMPERSAND              '&'
00656 #define CHAR_APOSTROPHE             '\''
00657 #define CHAR_LEFT_PARENTHESIS       '('
00658 #define CHAR_RIGHT_PARENTHESIS      ')'
00659 #define CHAR_ASTERISK               '*'
00660 #define CHAR_PLUS                   '+'
00661 #define CHAR_COMMA                  ','
00662 #define CHAR_MINUS                  '-'
00663 #define CHAR_DOT                    '.'
00664 #define CHAR_SLASH                  '/'
00665 #define CHAR_0                      '0'
00666 #define CHAR_1                      '1'
00667 #define CHAR_2                      '2'
00668 #define CHAR_3                      '3'
00669 #define CHAR_4                      '4'
00670 #define CHAR_5                      '5'
00671 #define CHAR_6                      '6'
00672 #define CHAR_7                      '7'
00673 #define CHAR_8                      '8'
00674 #define CHAR_9                      '9'
00675 #define CHAR_COLON                  ':'
00676 #define CHAR_SEMICOLON              ';'
00677 #define CHAR_LESS_THAN_SIGN         '<'
00678 #define CHAR_EQUALS_SIGN            '='
00679 #define CHAR_GREATER_THAN_SIGN      '>'
00680 #define CHAR_QUESTION_MARK          '?'
00681 #define CHAR_COMMERCIAL_AT          '@'
00682 #define CHAR_A                      'A'
00683 #define CHAR_B                      'B'
00684 #define CHAR_C                      'C'
00685 #define CHAR_D                      'D'
00686 #define CHAR_E                      'E'
00687 #define CHAR_F                      'F'
00688 #define CHAR_G                      'G'
00689 #define CHAR_H                      'H'
00690 #define CHAR_I                      'I'
00691 #define CHAR_J                      'J'
00692 #define CHAR_K                      'K'
00693 #define CHAR_L                      'L'
00694 #define CHAR_M                      'M'
00695 #define CHAR_N                      'N'
00696 #define CHAR_O                      'O'
00697 #define CHAR_P                      'P'
00698 #define CHAR_Q                      'Q'
00699 #define CHAR_R                      'R'
00700 #define CHAR_S                      'S'
00701 #define CHAR_T                      'T'
00702 #define CHAR_U                      'U'
00703 #define CHAR_V                      'V'
00704 #define CHAR_W                      'W'
00705 #define CHAR_X                      'X'
00706 #define CHAR_Y                      'Y'
00707 #define CHAR_Z                      'Z'
00708 #define CHAR_LEFT_SQUARE_BRACKET    '['
00709 #define CHAR_BACKSLASH              '\\'
00710 #define CHAR_RIGHT_SQUARE_BRACKET   ']'
00711 #define CHAR_CIRCUMFLEX_ACCENT      '^'
00712 #define CHAR_UNDERSCORE             '_'
00713 #define CHAR_GRAVE_ACCENT           '`'
00714 #define CHAR_a                      'a'
00715 #define CHAR_b                      'b'
00716 #define CHAR_c                      'c'
00717 #define CHAR_d                      'd'
00718 #define CHAR_e                      'e'
00719 #define CHAR_f                      'f'
00720 #define CHAR_g                      'g'
00721 #define CHAR_h                      'h'
00722 #define CHAR_i                      'i'
00723 #define CHAR_j                      'j'
00724 #define CHAR_k                      'k'
00725 #define CHAR_l                      'l'
00726 #define CHAR_m                      'm'
00727 #define CHAR_n                      'n'
00728 #define CHAR_o                      'o'
00729 #define CHAR_p                      'p'
00730 #define CHAR_q                      'q'
00731 #define CHAR_r                      'r'
00732 #define CHAR_s                      's'
00733 #define CHAR_t                      't'
00734 #define CHAR_u                      'u'
00735 #define CHAR_v                      'v'
00736 #define CHAR_w                      'w'
00737 #define CHAR_x                      'x'
00738 #define CHAR_y                      'y'
00739 #define CHAR_z                      'z'
00740 #define CHAR_LEFT_CURLY_BRACKET     '{'
00741 #define CHAR_VERTICAL_LINE          '|'
00742 #define CHAR_RIGHT_CURLY_BRACKET    '}'
00743 #define CHAR_TILDE                  '~'
00744 
00745 #define STR_HT                      "\t"
00746 #define STR_VT                      "\v"
00747 #define STR_FF                      "\f"
00748 #define STR_CR                      "\r"
00749 #define STR_NL                      "\n"
00750 #define STR_BS                      "\b"
00751 #define STR_BEL                     "\a"
00752 #ifdef EBCDIC
00753 #define STR_ESC                     "\047"
00754 #define STR_DEL                     "\007"
00755 #else
00756 #define STR_ESC                     "\033"
00757 #define STR_DEL                     "\177"
00758 #endif
00759 
00760 #define STR_SPACE                   " "
00761 #define STR_EXCLAMATION_MARK        "!"
00762 #define STR_QUOTATION_MARK          "\""
00763 #define STR_NUMBER_SIGN             "#"
00764 #define STR_DOLLAR_SIGN             "$"
00765 #define STR_PERCENT_SIGN            "%"
00766 #define STR_AMPERSAND               "&"
00767 #define STR_APOSTROPHE              "'"
00768 #define STR_LEFT_PARENTHESIS        "("
00769 #define STR_RIGHT_PARENTHESIS       ")"
00770 #define STR_ASTERISK                "*"
00771 #define STR_PLUS                    "+"
00772 #define STR_COMMA                   ","
00773 #define STR_MINUS                   "-"
00774 #define STR_DOT                     "."
00775 #define STR_SLASH                   "/"
00776 #define STR_0                       "0"
00777 #define STR_1                       "1"
00778 #define STR_2                       "2"
00779 #define STR_3                       "3"
00780 #define STR_4                       "4"
00781 #define STR_5                       "5"
00782 #define STR_6                       "6"
00783 #define STR_7                       "7"
00784 #define STR_8                       "8"
00785 #define STR_9                       "9"
00786 #define STR_COLON                   ":"
00787 #define STR_SEMICOLON               ";"
00788 #define STR_LESS_THAN_SIGN          "<"
00789 #define STR_EQUALS_SIGN             "="
00790 #define STR_GREATER_THAN_SIGN       ">"
00791 #define STR_QUESTION_MARK           "?"
00792 #define STR_COMMERCIAL_AT           "@"
00793 #define STR_A                       "A"
00794 #define STR_B                       "B"
00795 #define STR_C                       "C"
00796 #define STR_D                       "D"
00797 #define STR_E                       "E"
00798 #define STR_F                       "F"
00799 #define STR_G                       "G"
00800 #define STR_H                       "H"
00801 #define STR_I                       "I"
00802 #define STR_J                       "J"
00803 #define STR_K                       "K"
00804 #define STR_L                       "L"
00805 #define STR_M                       "M"
00806 #define STR_N                       "N"
00807 #define STR_O                       "O"
00808 #define STR_P                       "P"
00809 #define STR_Q                       "Q"
00810 #define STR_R                       "R"
00811 #define STR_S                       "S"
00812 #define STR_T                       "T"
00813 #define STR_U                       "U"
00814 #define STR_V                       "V"
00815 #define STR_W                       "W"
00816 #define STR_X                       "X"
00817 #define STR_Y                       "Y"
00818 #define STR_Z                       "Z"
00819 #define STR_LEFT_SQUARE_BRACKET     "["
00820 #define STR_BACKSLASH               "\\"
00821 #define STR_RIGHT_SQUARE_BRACKET    "]"
00822 #define STR_CIRCUMFLEX_ACCENT       "^"
00823 #define STR_UNDERSCORE              "_"
00824 #define STR_GRAVE_ACCENT            "`"
00825 #define STR_a                       "a"
00826 #define STR_b                       "b"
00827 #define STR_c                       "c"
00828 #define STR_d                       "d"
00829 #define STR_e                       "e"
00830 #define STR_f                       "f"
00831 #define STR_g                       "g"
00832 #define STR_h                       "h"
00833 #define STR_i                       "i"
00834 #define STR_j                       "j"
00835 #define STR_k                       "k"
00836 #define STR_l                       "l"
00837 #define STR_m                       "m"
00838 #define STR_n                       "n"
00839 #define STR_o                       "o"
00840 #define STR_p                       "p"
00841 #define STR_q                       "q"
00842 #define STR_r                       "r"
00843 #define STR_s                       "s"
00844 #define STR_t                       "t"
00845 #define STR_u                       "u"
00846 #define STR_v                       "v"
00847 #define STR_w                       "w"
00848 #define STR_x                       "x"
00849 #define STR_y                       "y"
00850 #define STR_z                       "z"
00851 #define STR_LEFT_CURLY_BRACKET      "{"
00852 #define STR_VERTICAL_LINE           "|"
00853 #define STR_RIGHT_CURLY_BRACKET     "}"
00854 #define STR_TILDE                   "~"
00855 
00856 #define STRING_ACCEPT0              "ACCEPT\0"
00857 #define STRING_COMMIT0              "COMMIT\0"
00858 #define STRING_F0                   "F\0"
00859 #define STRING_FAIL0                "FAIL\0"
00860 #define STRING_PRUNE0               "PRUNE\0"
00861 #define STRING_SKIP0                "SKIP\0"
00862 #define STRING_THEN                 "THEN"
00863 
00864 #define STRING_alpha0               "alpha\0"
00865 #define STRING_lower0               "lower\0"
00866 #define STRING_upper0               "upper\0"
00867 #define STRING_alnum0               "alnum\0"
00868 #define STRING_ascii0               "ascii\0"
00869 #define STRING_blank0               "blank\0"
00870 #define STRING_cntrl0               "cntrl\0"
00871 #define STRING_digit0               "digit\0"
00872 #define STRING_graph0               "graph\0"
00873 #define STRING_print0               "print\0"
00874 #define STRING_punct0               "punct\0"
00875 #define STRING_space0               "space\0"
00876 #define STRING_word0                "word\0"
00877 #define STRING_xdigit               "xdigit"
00878 
00879 #define STRING_DEFINE               "DEFINE"
00880 
00881 #define STRING_CR_RIGHTPAR          "CR)"
00882 #define STRING_LF_RIGHTPAR          "LF)"
00883 #define STRING_CRLF_RIGHTPAR        "CRLF)"
00884 #define STRING_ANY_RIGHTPAR         "ANY)"
00885 #define STRING_ANYCRLF_RIGHTPAR     "ANYCRLF)"
00886 #define STRING_BSR_ANYCRLF_RIGHTPAR "BSR_ANYCRLF)"
00887 #define STRING_BSR_UNICODE_RIGHTPAR "BSR_UNICODE)"
00888 #define STRING_UTF8_RIGHTPAR        "UTF8)"
00889 
00890 #else  /* SUPPORT_UTF8 */
00891 
00892 /* UTF-8 support is enabled; always use UTF-8 (=ASCII) character codes. This
00893 works in both modes non-EBCDIC platforms, and on EBCDIC platforms in UTF-8 mode
00894 only. */
00895 
00896 #define CHAR_HT                     '\011'
00897 #define CHAR_VT                     '\013'
00898 #define CHAR_FF                     '\014'
00899 #define CHAR_CR                     '\015'
00900 #define CHAR_NL                     '\012'
00901 #define CHAR_BS                     '\010'
00902 #define CHAR_BEL                    '\007'
00903 #define CHAR_ESC                    '\033'
00904 #define CHAR_DEL                    '\177'
00905 
00906 #define CHAR_SPACE                  '\040'
00907 #define CHAR_EXCLAMATION_MARK       '\041'
00908 #define CHAR_QUOTATION_MARK         '\042'
00909 #define CHAR_NUMBER_SIGN            '\043'
00910 #define CHAR_DOLLAR_SIGN            '\044'
00911 #define CHAR_PERCENT_SIGN           '\045'
00912 #define CHAR_AMPERSAND              '\046'
00913 #define CHAR_APOSTROPHE             '\047'
00914 #define CHAR_LEFT_PARENTHESIS       '\050'
00915 #define CHAR_RIGHT_PARENTHESIS      '\051'
00916 #define CHAR_ASTERISK               '\052'
00917 #define CHAR_PLUS                   '\053'
00918 #define CHAR_COMMA                  '\054'
00919 #define CHAR_MINUS                  '\055'
00920 #define CHAR_DOT                    '\056'
00921 #define CHAR_SLASH                  '\057'
00922 #define CHAR_0                      '\060'
00923 #define CHAR_1                      '\061'
00924 #define CHAR_2                      '\062'
00925 #define CHAR_3                      '\063'
00926 #define CHAR_4                      '\064'
00927 #define CHAR_5                      '\065'
00928 #define CHAR_6                      '\066'
00929 #define CHAR_7                      '\067'
00930 #define CHAR_8                      '\070'
00931 #define CHAR_9                      '\071'
00932 #define CHAR_COLON                  '\072'
00933 #define CHAR_SEMICOLON              '\073'
00934 #define CHAR_LESS_THAN_SIGN         '\074'
00935 #define CHAR_EQUALS_SIGN            '\075'
00936 #define CHAR_GREATER_THAN_SIGN      '\076'
00937 #define CHAR_QUESTION_MARK          '\077'
00938 #define CHAR_COMMERCIAL_AT          '\100'
00939 #define CHAR_A                      '\101'
00940 #define CHAR_B                      '\102'
00941 #define CHAR_C                      '\103'
00942 #define CHAR_D                      '\104'
00943 #define CHAR_E                      '\105'
00944 #define CHAR_F                      '\106'
00945 #define CHAR_G                      '\107'
00946 #define CHAR_H                      '\110'
00947 #define CHAR_I                      '\111'
00948 #define CHAR_J                      '\112'
00949 #define CHAR_K                      '\113'
00950 #define CHAR_L                      '\114'
00951 #define CHAR_M                      '\115'
00952 #define CHAR_N                      '\116'
00953 #define CHAR_O                      '\117'
00954 #define CHAR_P                      '\120'
00955 #define CHAR_Q                      '\121'
00956 #define CHAR_R                      '\122'
00957 #define CHAR_S                      '\123'
00958 #define CHAR_T                      '\124'
00959 #define CHAR_U                      '\125'
00960 #define CHAR_V                      '\126'
00961 #define CHAR_W                      '\127'
00962 #define CHAR_X                      '\130'
00963 #define CHAR_Y                      '\131'
00964 #define CHAR_Z                      '\132'
00965 #define CHAR_LEFT_SQUARE_BRACKET    '\133'
00966 #define CHAR_BACKSLASH              '\134'
00967 #define CHAR_RIGHT_SQUARE_BRACKET   '\135'
00968 #define CHAR_CIRCUMFLEX_ACCENT      '\136'
00969 #define CHAR_UNDERSCORE             '\137'
00970 #define CHAR_GRAVE_ACCENT           '\140'
00971 #define CHAR_a                      '\141'
00972 #define CHAR_b                      '\142'
00973 #define CHAR_c                      '\143'
00974 #define CHAR_d                      '\144'
00975 #define CHAR_e                      '\145'
00976 #define CHAR_f                      '\146'
00977 #define CHAR_g                      '\147'
00978 #define CHAR_h                      '\150'
00979 #define CHAR_i                      '\151'
00980 #define CHAR_j                      '\152'
00981 #define CHAR_k                      '\153'
00982 #define CHAR_l                      '\154'
00983 #define CHAR_m                      '\155'
00984 #define CHAR_n                      '\156'
00985 #define CHAR_o                      '\157'
00986 #define CHAR_p                      '\160'
00987 #define CHAR_q                      '\161'
00988 #define CHAR_r                      '\162'
00989 #define CHAR_s                      '\163'
00990 #define CHAR_t                      '\164'
00991 #define CHAR_u                      '\165'
00992 #define CHAR_v                      '\166'
00993 #define CHAR_w                      '\167'
00994 #define CHAR_x                      '\170'
00995 #define CHAR_y                      '\171'
00996 #define CHAR_z                      '\172'
00997 #define CHAR_LEFT_CURLY_BRACKET     '\173'
00998 #define CHAR_VERTICAL_LINE          '\174'
00999 #define CHAR_RIGHT_CURLY_BRACKET    '\175'
01000 #define CHAR_TILDE                  '\176'
01001 
01002 #define STR_HT                      "\011"
01003 #define STR_VT                      "\013"
01004 #define STR_FF                      "\014"
01005 #define STR_CR                      "\015"
01006 #define STR_NL                      "\012"
01007 #define STR_BS                      "\010"
01008 #define STR_BEL                     "\007"
01009 #define STR_ESC                     "\033"
01010 #define STR_DEL                     "\177"
01011 
01012 #define STR_SPACE                   "\040"
01013 #define STR_EXCLAMATION_MARK        "\041"
01014 #define STR_QUOTATION_MARK          "\042"
01015 #define STR_NUMBER_SIGN             "\043"
01016 #define STR_DOLLAR_SIGN             "\044"
01017 #define STR_PERCENT_SIGN            "\045"
01018 #define STR_AMPERSAND               "\046"
01019 #define STR_APOSTROPHE              "\047"
01020 #define STR_LEFT_PARENTHESIS        "\050"
01021 #define STR_RIGHT_PARENTHESIS       "\051"
01022 #define STR_ASTERISK                "\052"
01023 #define STR_PLUS                    "\053"
01024 #define STR_COMMA                   "\054"
01025 #define STR_MINUS                   "\055"
01026 #define STR_DOT                     "\056"
01027 #define STR_SLASH                   "\057"
01028 #define STR_0                       "\060"
01029 #define STR_1                       "\061"
01030 #define STR_2                       "\062"
01031 #define STR_3                       "\063"
01032 #define STR_4                       "\064"
01033 #define STR_5                       "\065"
01034 #define STR_6                       "\066"
01035 #define STR_7                       "\067"
01036 #define STR_8                       "\070"
01037 #define STR_9                       "\071"
01038 #define STR_COLON                   "\072"
01039 #define STR_SEMICOLON               "\073"
01040 #define STR_LESS_THAN_SIGN          "\074"
01041 #define STR_EQUALS_SIGN             "\075"
01042 #define STR_GREATER_THAN_SIGN       "\076"
01043 #define STR_QUESTION_MARK           "\077"
01044 #define STR_COMMERCIAL_AT           "\100"
01045 #define STR_A                       "\101"
01046 #define STR_B                       "\102"
01047 #define STR_C                       "\103"
01048 #define STR_D                       "\104"
01049 #define STR_E                       "\105"
01050 #define STR_F                       "\106"
01051 #define STR_G                       "\107"
01052 #define STR_H                       "\110"
01053 #define STR_I                       "\111"
01054 #define STR_J                       "\112"
01055 #define STR_K                       "\113"
01056 #define STR_L                       "\114"
01057 #define STR_M                       "\115"
01058 #define STR_N                       "\116"
01059 #define STR_O                       "\117"
01060 #define STR_P                       "\120"
01061 #define STR_Q                       "\121"
01062 #define STR_R                       "\122"
01063 #define STR_S                       "\123"
01064 #define STR_T                       "\124"
01065 #define STR_U                       "\125"
01066 #define STR_V                       "\126"
01067 #define STR_W                       "\127"
01068 #define STR_X                       "\130"
01069 #define STR_Y                       "\131"
01070 #define STR_Z                       "\132"
01071 #define STR_LEFT_SQUARE_BRACKET     "\133"
01072 #define STR_BACKSLASH               "\134"
01073 #define STR_RIGHT_SQUARE_BRACKET    "\135"
01074 #define STR_CIRCUMFLEX_ACCENT       "\136"
01075 #define STR_UNDERSCORE              "\137"
01076 #define STR_GRAVE_ACCENT            "\140"
01077 #define STR_a                       "\141"
01078 #define STR_b                       "\142"
01079 #define STR_c                       "\143"
01080 #define STR_d                       "\144"
01081 #define STR_e                       "\145"
01082 #define STR_f                       "\146"
01083 #define STR_g                       "\147"
01084 #define STR_h                       "\150"
01085 #define STR_i                       "\151"
01086 #define STR_j                       "\152"
01087 #define STR_k                       "\153"
01088 #define STR_l                       "\154"
01089 #define STR_m                       "\155"
01090 #define STR_n                       "\156"
01091 #define STR_o                       "\157"
01092 #define STR_p                       "\160"
01093 #define STR_q                       "\161"
01094 #define STR_r                       "\162"
01095 #define STR_s                       "\163"
01096 #define STR_t                       "\164"
01097 #define STR_u                       "\165"
01098 #define STR_v                       "\166"
01099 #define STR_w                       "\167"
01100 #define STR_x                       "\170"
01101 #define STR_y                       "\171"
01102 #define STR_z                       "\172"
01103 #define STR_LEFT_CURLY_BRACKET      "\173"
01104 #define STR_VERTICAL_LINE           "\174"
01105 #define STR_RIGHT_CURLY_BRACKET     "\175"
01106 #define STR_TILDE                   "\176"
01107 
01108 #define STRING_ACCEPT0              STR_A STR_C STR_C STR_E STR_P STR_T "\0"
01109 #define STRING_COMMIT0              STR_C STR_O STR_M STR_M STR_I STR_T "\0"
01110 #define STRING_F0                   STR_F "\0"
01111 #define STRING_FAIL0                STR_F STR_A STR_I STR_L "\0"
01112 #define STRING_PRUNE0               STR_P STR_R STR_U STR_N STR_E "\0"
01113 #define STRING_SKIP0                STR_S STR_K STR_I STR_P "\0"
01114 #define STRING_THEN                 STR_T STR_H STR_E STR_N
01115 
01116 #define STRING_alpha0               STR_a STR_l STR_p STR_h STR_a "\0"
01117 #define STRING_lower0               STR_l STR_o STR_w STR_e STR_r "\0"
01118 #define STRING_upper0               STR_u STR_p STR_p STR_e STR_r "\0"
01119 #define STRING_alnum0               STR_a STR_l STR_n STR_u STR_m "\0"
01120 #define STRING_ascii0               STR_a STR_s STR_c STR_i STR_i "\0"
01121 #define STRING_blank0               STR_b STR_l STR_a STR_n STR_k "\0"
01122 #define STRING_cntrl0               STR_c STR_n STR_t STR_r STR_l "\0"
01123 #define STRING_digit0               STR_d STR_i STR_g STR_i STR_t "\0"
01124 #define STRING_graph0               STR_g STR_r STR_a STR_p STR_h "\0"
01125 #define STRING_print0               STR_p STR_r STR_i STR_n STR_t "\0"
01126 #define STRING_punct0               STR_p STR_u STR_n STR_c STR_t "\0"
01127 #define STRING_space0               STR_s STR_p STR_a STR_c STR_e "\0"
01128 #define STRING_word0                STR_w STR_o STR_r STR_d       "\0"
01129 #define STRING_xdigit               STR_x STR_d STR_i STR_g STR_i STR_t
01130 
01131 #define STRING_DEFINE               STR_D STR_E STR_F STR_I STR_N STR_E
01132 
01133 #define STRING_CR_RIGHTPAR          STR_C STR_R STR_RIGHT_PARENTHESIS
01134 #define STRING_LF_RIGHTPAR          STR_L STR_F STR_RIGHT_PARENTHESIS
01135 #define STRING_CRLF_RIGHTPAR        STR_C STR_R STR_L STR_F STR_RIGHT_PARENTHESIS
01136 #define STRING_ANY_RIGHTPAR         STR_A STR_N STR_Y STR_RIGHT_PARENTHESIS
01137 #define STRING_ANYCRLF_RIGHTPAR     STR_A STR_N STR_Y STR_C STR_R STR_L STR_F STR_RIGHT_PARENTHESIS
01138 #define STRING_BSR_ANYCRLF_RIGHTPAR STR_B STR_S STR_R STR_UNDERSCORE STR_A STR_N STR_Y STR_C STR_R STR_L STR_F STR_RIGHT_PARENTHESIS
01139 #define STRING_BSR_UNICODE_RIGHTPAR STR_B STR_S STR_R STR_UNDERSCORE STR_U STR_N STR_I STR_C STR_O STR_D STR_E STR_RIGHT_PARENTHESIS
01140 #define STRING_UTF8_RIGHTPAR        STR_U STR_T STR_F STR_8 STR_RIGHT_PARENTHESIS
01141 
01142 #endif  /* SUPPORT_UTF8 */
01143 
01144 /* Escape items that are just an encoding of a particular data value. */
01145 
01146 #ifndef ESC_e
01147 #define ESC_e CHAR_ESC
01148 #endif
01149 
01150 #ifndef ESC_f
01151 #define ESC_f CHAR_FF
01152 #endif
01153 
01154 #ifndef ESC_n
01155 #define ESC_n CHAR_NL
01156 #endif
01157 
01158 #ifndef ESC_r
01159 #define ESC_r CHAR_CR
01160 #endif
01161 
01162 /* We can't officially use ESC_t because it is a POSIX reserved identifier
01163 (presumably because of all the others like size_t). */
01164 
01165 #ifndef ESC_tee
01166 #define ESC_tee CHAR_HT
01167 #endif
01168 
01169 /* Codes for different types of Unicode property */
01170 
01171 #define PT_ANY        0    /* Any property - matches all chars */
01172 #define PT_LAMP       1    /* L& - the union of Lu, Ll, Lt */
01173 #define PT_GC         2    /* General characteristic (e.g. L) */
01174 #define PT_PC         3    /* Particular characteristic (e.g. Lu) */
01175 #define PT_SC         4    /* Script (e.g. Han) */
01176 
01177 /* Flag bits and data types for the extended class (OP_XCLASS) for classes that
01178 contain UTF-8 characters with values greater than 255. */
01179 
01180 #define XCL_NOT    0x01    /* Flag: this is a negative class */
01181 #define XCL_MAP    0x02    /* Flag: a 32-byte map is present */
01182 
01183 #define XCL_END       0    /* Marks end of individual items */
01184 #define XCL_SINGLE    1    /* Single item (one multibyte char) follows */
01185 #define XCL_RANGE     2    /* A range (two multibyte chars) follows */
01186 #define XCL_PROP      3    /* Unicode property (2-byte property code follows) */
01187 #define XCL_NOTPROP   4    /* Unicode inverted property (ditto) */
01188 
01189 /* These are escaped items that aren't just an encoding of a particular data
01190 value such as \n. They must have non-zero values, as check_escape() returns
01191 their negation. Also, they must appear in the same order as in the opcode
01192 definitions below, up to ESC_z. There's a dummy for OP_ANY because it
01193 corresponds to "." rather than an escape sequence, and another for OP_ALLANY
01194 (which is used for [^] in JavaScript compatibility mode).
01195 
01196 The final escape must be ESC_REF as subsequent values are used for
01197 backreferences (\1, \2, \3, etc). There are two tests in the code for an escape
01198 greater than ESC_b and less than ESC_Z to detect the types that may be
01199 repeated. These are the types that consume characters. If any new escapes are
01200 put in between that don't consume a character, that code will have to change.
01201 */
01202 
01203 enum { ESC_A = 1, ESC_G, ESC_K, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s,
01204        ESC_W, ESC_w, ESC_dum1, ESC_dum2, ESC_C, ESC_P, ESC_p, ESC_R, ESC_H,
01205        ESC_h, ESC_V, ESC_v, ESC_X, ESC_Z, ESC_z, ESC_E, ESC_Q, ESC_g, ESC_k,
01206        ESC_REF };
01207 
01208 
01209 /* Opcode table: Starting from 1 (i.e. after OP_END), the values up to
01210 OP_EOD must correspond in order to the list of escapes immediately above.
01211 
01212 *** NOTE NOTE NOTE *** Whenever this list is updated, the two macro definitions
01213 that follow must also be updated to match. There are also tables called
01214 "coptable" and "poptable" in pcre_dfa_exec.c that must be updated. */
01215 
01216 enum {
01217   OP_END,            /* 0 End of pattern */
01218 
01219   /* Values corresponding to backslashed metacharacters */
01220 
01221   OP_SOD,            /* 1 Start of data: \A */
01222   OP_SOM,            /* 2 Start of match (subject + offset): \G */
01223   OP_SET_SOM,        /* 3 Set start of match (\K) */
01224   OP_NOT_WORD_BOUNDARY,  /*  4 \B */
01225   OP_WORD_BOUNDARY,      /*  5 \b */
01226   OP_NOT_DIGIT,          /*  6 \D */
01227   OP_DIGIT,              /*  7 \d */
01228   OP_NOT_WHITESPACE,     /*  8 \S */
01229   OP_WHITESPACE,         /*  9 \s */
01230   OP_NOT_WORDCHAR,       /* 10 \W */
01231   OP_WORDCHAR,           /* 11 \w */
01232   OP_ANY,            /* 12 Match any character (subject to DOTALL) */
01233   OP_ALLANY,         /* 13 Match any character (not subject to DOTALL) */
01234   OP_ANYBYTE,        /* 14 Match any byte (\C); different to OP_ANY for UTF-8 */
01235   OP_NOTPROP,        /* 15 \P (not Unicode property) */
01236   OP_PROP,           /* 16 \p (Unicode property) */
01237   OP_ANYNL,          /* 17 \R (any newline sequence) */
01238   OP_NOT_HSPACE,     /* 18 \H (not horizontal whitespace) */
01239   OP_HSPACE,         /* 19 \h (horizontal whitespace) */
01240   OP_NOT_VSPACE,     /* 20 \V (not vertical whitespace) */
01241   OP_VSPACE,         /* 21 \v (vertical whitespace) */
01242   OP_EXTUNI,         /* 22 \X (extended Unicode sequence */
01243   OP_EODN,           /* 23 End of data or \n at end of data: \Z. */
01244   OP_EOD,            /* 24 End of data: \z */
01245 
01246   OP_OPT,            /* 25 Set runtime options */
01247   OP_CIRC,           /* 26 Start of line - varies with multiline switch */
01248   OP_DOLL,           /* 27 End of line - varies with multiline switch */
01249   OP_CHAR,           /* 28 Match one character, casefully */
01250   OP_CHARNC,         /* 29 Match one character, caselessly */
01251   OP_NOT,            /* 30 Match one character, not the following one */
01252 
01253   OP_STAR,           /* 31 The maximizing and minimizing versions of */
01254   OP_MINSTAR,        /* 32 these six opcodes must come in pairs, with */
01255   OP_PLUS,           /* 33 the minimizing one second. */
01256   OP_MINPLUS,        /* 34 This first set applies to single characters.*/
01257   OP_QUERY,          /* 35 */
01258   OP_MINQUERY,       /* 36 */
01259 
01260   OP_UPTO,           /* 37 From 0 to n matches */
01261   OP_MINUPTO,        /* 38 */
01262   OP_EXACT,          /* 39 Exactly n matches */
01263 
01264   OP_POSSTAR,        /* 40 Possessified star */
01265   OP_POSPLUS,        /* 41 Possessified plus */
01266   OP_POSQUERY,       /* 42 Posesssified query */
01267   OP_POSUPTO,        /* 43 Possessified upto */
01268 
01269   OP_NOTSTAR,        /* 44 The maximizing and minimizing versions of */
01270   OP_NOTMINSTAR,     /* 45 these six opcodes must come in pairs, with */
01271   OP_NOTPLUS,        /* 46 the minimizing one second. They must be in */
01272   OP_NOTMINPLUS,     /* 47 exactly the same order as those above. */
01273   OP_NOTQUERY,       /* 48 This set applies to "not" single characters. */
01274   OP_NOTMINQUERY,    /* 49 */
01275 
01276   OP_NOTUPTO,        /* 50 From 0 to n matches */
01277   OP_NOTMINUPTO,     /* 51 */
01278   OP_NOTEXACT,       /* 52 Exactly n matches */
01279 
01280   OP_NOTPOSSTAR,     /* 53 Possessified versions */
01281   OP_NOTPOSPLUS,     /* 54 */
01282   OP_NOTPOSQUERY,    /* 55 */
01283   OP_NOTPOSUPTO,     /* 56 */
01284 
01285   OP_TYPESTAR,       /* 57 The maximizing and minimizing versions of */
01286   OP_TYPEMINSTAR,    /* 58 these six opcodes must come in pairs, with */
01287   OP_TYPEPLUS,       /* 59 the minimizing one second. These codes must */
01288   OP_TYPEMINPLUS,    /* 60 be in exactly the same order as those above. */
01289   OP_TYPEQUERY,      /* 61 This set applies to character types such as \d */
01290   OP_TYPEMINQUERY,   /* 62 */
01291 
01292   OP_TYPEUPTO,       /* 63 From 0 to n matches */
01293   OP_TYPEMINUPTO,    /* 64 */
01294   OP_TYPEEXACT,      /* 65 Exactly n matches */
01295 
01296   OP_TYPEPOSSTAR,    /* 66 Possessified versions */
01297   OP_TYPEPOSPLUS,    /* 67 */
01298   OP_TYPEPOSQUERY,   /* 68 */
01299   OP_TYPEPOSUPTO,    /* 69 */
01300 
01301   OP_CRSTAR,         /* 70 The maximizing and minimizing versions of */
01302   OP_CRMINSTAR,      /* 71 all these opcodes must come in pairs, with */
01303   OP_CRPLUS,         /* 72 the minimizing one second. These codes must */
01304   OP_CRMINPLUS,      /* 73 be in exactly the same order as those above. */
01305   OP_CRQUERY,        /* 74 These are for character classes and back refs */
01306   OP_CRMINQUERY,     /* 75 */
01307   OP_CRRANGE,        /* 76 These are different to the three sets above. */
01308   OP_CRMINRANGE,     /* 77 */
01309 
01310   OP_CLASS,          /* 78 Match a character class, chars < 256 only */
01311   OP_NCLASS,         /* 79 Same, but the bitmap was created from a negative
01312                            class - the difference is relevant only when a UTF-8
01313                            character > 255 is encountered. */
01314 
01315   OP_XCLASS,         /* 80 Extended class for handling UTF-8 chars within the
01316                            class. This does both positive and negative. */
01317 
01318   OP_REF,            /* 81 Match a back reference */
01319   OP_RECURSE,        /* 82 Match a numbered subpattern (possibly recursive) */
01320   OP_CALLOUT,        /* 83 Call out to external function if provided */
01321 
01322   OP_ALT,            /* 84 Start of alternation */
01323   OP_KET,            /* 85 End of group that doesn't have an unbounded repeat */
01324   OP_KETRMAX,        /* 86 These two must remain together and in this */
01325   OP_KETRMIN,        /* 87 order. They are for groups the repeat for ever. */
01326 
01327   /* The assertions must come before BRA, CBRA, ONCE, and COND.*/
01328 
01329   OP_ASSERT,         /* 88 Positive lookahead */
01330   OP_ASSERT_NOT,     /* 89 Negative lookahead */
01331   OP_ASSERTBACK,     /* 90 Positive lookbehind */
01332   OP_ASSERTBACK_NOT, /* 91 Negative lookbehind */
01333   OP_REVERSE,        /* 92 Move pointer back - used in lookbehind assertions */
01334 
01335   /* ONCE, BRA, CBRA, and COND must come after the assertions, with ONCE first,
01336   as there's a test for >= ONCE for a subpattern that isn't an assertion. */
01337 
01338   OP_ONCE,           /* 93 Atomic group */
01339   OP_BRA,            /* 94 Start of non-capturing bracket */
01340   OP_CBRA,           /* 95 Start of capturing bracket */
01341   OP_COND,           /* 96 Conditional group */
01342 
01343   /* These three must follow the previous three, in the same order. There's a
01344   check for >= SBRA to distinguish the two sets. */
01345 
01346   OP_SBRA,           /* 97 Start of non-capturing bracket, check empty  */
01347   OP_SCBRA,          /* 98 Start of capturing bracket, check empty */
01348   OP_SCOND,          /* 99 Conditional group, check empty */
01349 
01350   /* The next two pairs must (respectively) be kept together. */
01351 
01352   OP_CREF,           /* 100 Used to hold a capture number as condition */
01353   OP_NCREF,          /* 101 Same, but generaged by a name reference*/
01354   OP_RREF,           /* 102 Used to hold a recursion number as condition */
01355   OP_NRREF,          /* 103 Same, but generaged by a name reference*/
01356   OP_DEF,            /* 104 The DEFINE condition */
01357 
01358   OP_BRAZERO,        /* 105 These two must remain together and in this */
01359   OP_BRAMINZERO,     /* 106 order. */
01360 
01361   /* These are backtracking control verbs */
01362 
01363   OP_PRUNE,          /* 107 */
01364   OP_SKIP,           /* 108 */
01365   OP_THEN,           /* 109 */
01366   OP_COMMIT,         /* 110 */
01367 
01368   /* These are forced failure and success verbs */
01369 
01370   OP_FAIL,           /* 111 */
01371   OP_ACCEPT,         /* 112 */
01372   OP_CLOSE,          /* 113 Used before OP_ACCEPT to close open captures */
01373 
01374   /* This is used to skip a subpattern with a {0} quantifier */
01375 
01376   OP_SKIPZERO        /* 114 */
01377 };
01378 
01379 /* *** NOTE NOTE NOTE *** Whenever the list above is updated, the two macro
01380 definitions that follow must also be updated to match. There are also tables
01381 called "coptable" cna "poptable" in pcre_dfa_exec.c that must be updated. */
01382 
01383 
01384 /* This macro defines textual names for all the opcodes. These are used only
01385 for debugging. The macro is referenced only in pcre_printint.c. */
01386 
01387 #define OP_NAME_LIST \
01388   "End", "\\A", "\\G", "\\K", "\\B", "\\b", "\\D", "\\d",         \
01389   "\\S", "\\s", "\\W", "\\w", "Any", "AllAny", "Anybyte",         \
01390   "notprop", "prop", "\\R", "\\H", "\\h", "\\V", "\\v",           \
01391   "extuni",  "\\Z", "\\z",                                        \
01392   "Opt", "^", "$", "char", "charnc", "not",                       \
01393   "*", "*?", "+", "+?", "?", "??", "{", "{", "{",                 \
01394   "*+","++", "?+", "{",                                           \
01395   "*", "*?", "+", "+?", "?", "??", "{", "{", "{",                 \
01396   "*+","++", "?+", "{",                                           \
01397   "*", "*?", "+", "+?", "?", "??", "{", "{", "{",                 \
01398   "*+","++", "?+", "{",                                           \
01399   "*", "*?", "+", "+?", "?", "??", "{", "{",                      \
01400   "class", "nclass", "xclass", "Ref", "Recurse", "Callout",       \
01401   "Alt", "Ket", "KetRmax", "KetRmin", "Assert", "Assert not",     \
01402   "AssertB", "AssertB not", "Reverse",                            \
01403   "Once", "Bra", "CBra", "Cond", "SBra", "SCBra", "SCond",        \
01404   "Cond ref", "Cond nref", "Cond rec", "Cond nrec", "Cond def",   \
01405   "Brazero", "Braminzero",                                        \
01406   "*PRUNE", "*SKIP", "*THEN", "*COMMIT", "*FAIL", "*ACCEPT",      \
01407   "Close", "Skip zero"
01408 
01409 
01410 /* This macro defines the length of fixed length operations in the compiled
01411 regex. The lengths are used when searching for specific things, and also in the
01412 debugging printing of a compiled regex. We use a macro so that it can be
01413 defined close to the definitions of the opcodes themselves.
01414 
01415 As things have been extended, some of these are no longer fixed lenths, but are
01416 minima instead. For example, the length of a single-character repeat may vary
01417 in UTF-8 mode. The code that uses this table must know about such things. */
01418 
01419 #define OP_LENGTHS \
01420   1,                             /* End                                    */ \
01421   1, 1, 1, 1, 1,                 /* \A, \G, \K, \B, \b                     */ \
01422   1, 1, 1, 1, 1, 1,              /* \D, \d, \S, \s, \W, \w                 */ \
01423   1, 1, 1,                       /* Any, AllAny, Anybyte                   */ \
01424   3, 3, 1,                       /* NOTPROP, PROP, EXTUNI                  */ \
01425   1, 1, 1, 1, 1,                 /* \R, \H, \h, \V, \v                     */ \
01426   1, 1, 2, 1, 1,                 /* \Z, \z, Opt, ^, $                      */ \
01427   2,                             /* Char  - the minimum length             */ \
01428   2,                             /* Charnc  - the minimum length           */ \
01429   2,                             /* not                                    */ \
01430   /* Positive single-char repeats                            ** These are  */ \
01431   2, 2, 2, 2, 2, 2,              /* *, *?, +, +?, ?, ??      ** minima in  */ \
01432   4, 4, 4,                       /* upto, minupto, exact     ** UTF-8 mode */ \
01433   2, 2, 2, 4,                    /* *+, ++, ?+, upto+                      */ \
01434   /* Negative single-char repeats - only for chars < 256                   */ \
01435   2, 2, 2, 2, 2, 2,              /* NOT *, *?, +, +?, ?, ??                */ \
01436   4, 4, 4,                       /* NOT upto, minupto, exact               */ \
01437   2, 2, 2, 4,                    /* Possessive *, +, ?, upto               */ \
01438   /* Positive type repeats                                                 */ \
01439   2, 2, 2, 2, 2, 2,              /* Type *, *?, +, +?, ?, ??               */ \
01440   4, 4, 4,                       /* Type upto, minupto, exact              */ \
01441   2, 2, 2, 4,                    /* Possessive *+, ++, ?+, upto+           */ \
01442   /* Character class & ref repeats                                         */ \
01443   1, 1, 1, 1, 1, 1,              /* *, *?, +, +?, ?, ??                    */ \
01444   5, 5,                          /* CRRANGE, CRMINRANGE                    */ \
01445  33,                             /* CLASS                                  */ \
01446  33,                             /* NCLASS                                 */ \
01447   0,                             /* XCLASS - variable length               */ \
01448   3,                             /* REF                                    */ \
01449   1+LINK_SIZE,                   /* RECURSE                                */ \
01450   2+2*LINK_SIZE,                 /* CALLOUT                                */ \
01451   1+LINK_SIZE,                   /* Alt                                    */ \
01452   1+LINK_SIZE,                   /* Ket                                    */ \
01453   1+LINK_SIZE,                   /* KetRmax                                */ \
01454   1+LINK_SIZE,                   /* KetRmin                                */ \
01455   1+LINK_SIZE,                   /* Assert                                 */ \
01456   1+LINK_SIZE,                   /* Assert not                             */ \
01457   1+LINK_SIZE,                   /* Assert behind                          */ \
01458   1+LINK_SIZE,                   /* Assert behind not                      */ \
01459   1+LINK_SIZE,                   /* Reverse                                */ \
01460   1+LINK_SIZE,                   /* ONCE                                   */ \
01461   1+LINK_SIZE,                   /* BRA                                    */ \
01462   3+LINK_SIZE,                   /* CBRA                                   */ \
01463   1+LINK_SIZE,                   /* COND                                   */ \
01464   1+LINK_SIZE,                   /* SBRA                                   */ \
01465   3+LINK_SIZE,                   /* SCBRA                                  */ \
01466   1+LINK_SIZE,                   /* SCOND                                  */ \
01467   3, 3,                          /* CREF, NCREF                            */ \
01468   3, 3,                          /* RREF, NRREF                            */ \
01469   1,                             /* DEF                                    */ \
01470   1, 1,                          /* BRAZERO, BRAMINZERO                    */ \
01471   1, 1, 1, 1,                    /* PRUNE, SKIP, THEN, COMMIT,             */ \
01472   1, 1, 3, 1                     /* FAIL, ACCEPT, CLOSE, SKIPZERO          */
01473 
01474 
01475 /* A magic value for OP_RREF and OP_NRREF to indicate the "any recursion"
01476 condition. */
01477 
01478 #define RREF_ANY  0xffff
01479 
01480 /* Error code numbers. They are given names so that they can more easily be
01481 tracked. */
01482 
01483 enum { ERR0,  ERR1,  ERR2,  ERR3,  ERR4,  ERR5,  ERR6,  ERR7,  ERR8,  ERR9,
01484        ERR10, ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19,
01485        ERR20, ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR28, ERR29,
01486        ERR30, ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39,
01487        ERR40, ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49,
01488        ERR50, ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58, ERR59,
01489        ERR60, ERR61, ERR62, ERR63, ERR64, ERR65 };
01490 
01491 /* The real format of the start of the pcre block; the index of names and the
01492 code vector run on as long as necessary after the end. We store an explicit
01493 offset to the name table so that if a regex is compiled on one host, saved, and
01494 then run on another where the size of pointers is different, all might still
01495 be well. For the case of compiled-on-4 and run-on-8, we include an extra
01496 pointer that is always NULL. For future-proofing, a few dummy fields were
01497 originally included - even though you can never get this planning right - but
01498 there is only one left now.
01499 
01500 NOTE NOTE NOTE:
01501 Because people can now save and re-use compiled patterns, any additions to this
01502 structure should be made at the end, and something earlier (e.g. a new
01503 flag in the options or one of the dummy fields) should indicate that the new
01504 fields are present. Currently PCRE always sets the dummy fields to zero.
01505 NOTE NOTE NOTE
01506 */
01507 
01508 typedef struct real_pcre {
01509   pcre_uint32 magic_number;
01510   pcre_uint32 size;               /* Total that was malloced */
01511   pcre_uint32 options;            /* Public options */
01512   pcre_uint16 flags;              /* Private flags */
01513   pcre_uint16 dummy1;             /* For future use */
01514   pcre_uint16 top_bracket;
01515   pcre_uint16 top_backref;
01516   pcre_uint16 first_byte;
01517   pcre_uint16 req_byte;
01518   pcre_uint16 name_table_offset;  /* Offset to name table that follows */
01519   pcre_uint16 name_entry_size;    /* Size of any name items */
01520   pcre_uint16 name_count;         /* Number of name items */
01521   pcre_uint16 ref_count;          /* Reference count */
01522 
01523   const unsigned char *tables;    /* Pointer to tables or NULL for std */
01524   const unsigned char *nullpad;   /* NULL padding */
01525 } real_pcre;
01526 
01527 /* The format of the block used to store data from pcre_study(). The same
01528 remark (see NOTE above) about extending this structure applies. */
01529 
01530 typedef struct pcre_study_data {
01531   pcre_uint32 size;               /* Total that was malloced */
01532   pcre_uint32 flags;              /* Private flags */
01533   uschar start_bits[32];          /* Starting char bits */
01534   pcre_uint32 minlength;          /* Minimum subject length */
01535 } pcre_study_data;
01536 
01537 /* Structure for building a chain of open capturing subpatterns during
01538 compiling, so that instructions to close them can be compiled when (*ACCEPT) is
01539 encountered. */
01540 
01541 typedef struct open_capitem {
01542   struct open_capitem *next;    /* Chain link */
01543   pcre_uint16 number;           /* Capture number */
01544 } open_capitem;
01545 
01546 /* Structure for passing "static" information around between the functions
01547 doing the compiling, so that they are thread-safe. */
01548 
01549 typedef struct compile_data {
01550   const uschar *lcc;            /* Points to lower casing table */
01551   const uschar *fcc;            /* Points to case-flipping table */
01552   const uschar *cbits;          /* Points to character type table */
01553   const uschar *ctypes;         /* Points to table of type maps */
01554   const uschar *start_workspace;/* The start of working space */
01555   const uschar *start_code;     /* The start of the compiled code */
01556   const uschar *start_pattern;  /* The start of the pattern */
01557   const uschar *end_pattern;    /* The end of the pattern */
01558   open_capitem *open_caps;      /* Chain of open capture items */
01559   uschar *hwm;                  /* High watermark of workspace */
01560   uschar *name_table;           /* The name/number table */
01561   int  names_found;             /* Number of entries so far */
01562   int  name_entry_size;         /* Size of each entry */
01563   int  bracount;                /* Count of capturing parens as we compile */
01564   int  final_bracount;          /* Saved value after first pass */
01565   int  top_backref;             /* Maximum back reference */
01566   unsigned int backref_map;     /* Bitmap of low back refs */
01567   int  external_options;        /* External (initial) options */
01568   int  external_flags;          /* External flag bits to be set */
01569   int  req_varyopt;             /* "After variable item" flag for reqbyte */
01570   BOOL had_accept;              /* (*ACCEPT) encountered */
01571   BOOL check_lookbehind;        /* Lookbehinds need later checking */
01572   int  nltype;                  /* Newline type */
01573   int  nllen;                   /* Newline string length */
01574   uschar nl[4];                 /* Newline string when fixed length */
01575 } compile_data;
01576 
01577 /* Structure for maintaining a chain of pointers to the currently incomplete
01578 branches, for testing for left recursion. */
01579 
01580 typedef struct branch_chain {
01581   struct branch_chain *outer;
01582   uschar *current;
01583 } branch_chain;
01584 
01585 /* Structure for items in a linked list that represents an explicit recursive
01586 call within the pattern. */
01587 
01588 typedef struct recursion_info {
01589   struct recursion_info *prevrec; /* Previous recursion record (or NULL) */
01590   int group_num;                /* Number of group that was called */
01591   const uschar *after_call;     /* "Return value": points after the call in the expr */
01592   USPTR save_start;             /* Old value of mstart */
01593   int *offset_save;             /* Pointer to start of saved offsets */
01594   int saved_max;                /* Number of saved offsets */
01595   int save_offset_top;          /* Current value of offset_top */
01596 } recursion_info;
01597 
01598 /* Structure for building a chain of data for holding the values of the subject
01599 pointer at the start of each subpattern, so as to detect when an empty string
01600 has been matched by a subpattern - to break infinite loops. */
01601 
01602 typedef struct eptrblock {
01603   struct eptrblock *epb_prev;
01604   USPTR epb_saved_eptr;
01605 } eptrblock;
01606 
01607 
01608 /* Structure for passing "static" information around between the functions
01609 doing traditional NFA matching, so that they are thread-safe. */
01610 
01611 typedef struct match_data {
01612   unsigned long int match_call_count;      /* As it says */
01613   unsigned long int match_limit;           /* As it says */
01614   unsigned long int match_limit_recursion; /* As it says */
01615   int   *offset_vector;         /* Offset vector */
01616   int    offset_end;            /* One past the end */
01617   int    offset_max;            /* The maximum usable for return data */
01618   int    nltype;                /* Newline type */
01619   int    nllen;                 /* Newline string length */
01620   int    name_count;            /* Number of names in name table */
01621   int    name_entry_size;       /* Size of entry in names table */
01622   uschar *name_table;           /* Table of names */
01623   uschar nl[4];                 /* Newline string when fixed */
01624   const uschar *lcc;            /* Points to lower casing table */
01625   const uschar *ctypes;         /* Points to table of type maps */
01626   BOOL   offset_overflow;       /* Set if too many extractions */
01627   BOOL   notbol;                /* NOTBOL flag */
01628   BOOL   noteol;                /* NOTEOL flag */
01629   BOOL   utf8;                  /* UTF8 flag */
01630   BOOL   jscript_compat;        /* JAVASCRIPT_COMPAT flag */
01631   BOOL   endonly;               /* Dollar not before final \n */
01632   BOOL   notempty;              /* Empty string match not wanted */
01633   BOOL   notempty_atstart;      /* Empty string match at start not wanted */
01634   BOOL   hitend;                /* Hit the end of the subject at some point */
01635   BOOL   bsr_anycrlf;           /* \R is just any CRLF, not full Unicode */
01636   const uschar *start_code;     /* For use when recursing */
01637   USPTR  start_subject;         /* Start of the subject string */
01638   USPTR  end_subject;           /* End of the subject string */
01639   USPTR  start_match_ptr;       /* Start of matched string */
01640   USPTR  end_match_ptr;         /* Subject position at end match */
01641   USPTR  start_used_ptr;        /* Earliest consulted character */
01642   int    partial;               /* PARTIAL options */
01643   int    end_offset_top;        /* Highwater mark at end of match */
01644   int    capture_last;          /* Most recent capture number */
01645   int    start_offset;          /* The start offset value */
01646   eptrblock *eptrchain;         /* Chain of eptrblocks for tail recursions */
01647   int    eptrn;                 /* Next free eptrblock */
01648   recursion_info *recursive;    /* Linked list of recursion data */
01649   void  *callout_data;          /* To pass back to callouts */
01650 } match_data;
01651 
01652 /* A similar structure is used for the same purpose by the DFA matching
01653 functions. */
01654 
01655 typedef struct dfa_match_data {
01656   const uschar *start_code;     /* Start of the compiled pattern */
01657   const uschar *start_subject;  /* Start of the subject string */
01658   const uschar *end_subject;    /* End of subject string */
01659   const uschar *start_used_ptr; /* Earliest consulted character */
01660   const uschar *tables;         /* Character tables */
01661   int   start_offset;           /* The start offset value */
01662   int   moptions;               /* Match options */
01663   int   poptions;               /* Pattern options */
01664   int    nltype;                /* Newline type */
01665   int    nllen;                 /* Newline string length */
01666   uschar nl[4];                 /* Newline string when fixed */
01667   void  *callout_data;          /* To pass back to callouts */
01668 } dfa_match_data;
01669 
01670 /* Bit definitions for entries in the pcre_ctypes table. */
01671 
01672 #define ctype_space   0x01
01673 #define ctype_letter  0x02
01674 #define ctype_digit   0x04
01675 #define ctype_xdigit  0x08
01676 #define ctype_word    0x10   /* alphanumeric or '_' */
01677 #define ctype_meta    0x80   /* regexp meta char or zero (end pattern) */
01678 
01679 /* Offsets for the bitmap tables in pcre_cbits. Each table contains a set
01680 of bits for a class map. Some classes are built by combining these tables. */
01681 
01682 #define cbit_space     0      /* [:space:] or \s */
01683 #define cbit_xdigit   32      /* [:xdigit:] */
01684 #define cbit_digit    64      /* [:digit:] or \d */
01685 #define cbit_upper    96      /* [:upper:] */
01686 #define cbit_lower   128      /* [:lower:] */
01687 #define cbit_word    160      /* [:word:] or \w */
01688 #define cbit_graph   192      /* [:graph:] */
01689 #define cbit_print   224      /* [:print:] */
01690 #define cbit_punct   256      /* [:punct:] */
01691 #define cbit_cntrl   288      /* [:cntrl:] */
01692 #define cbit_length  320      /* Length of the cbits table */
01693 
01694 /* Offsets of the various tables from the base tables pointer, and
01695 total length. */
01696 
01697 #define lcc_offset      0
01698 #define fcc_offset    256
01699 #define cbits_offset  512
01700 #define ctypes_offset (cbits_offset + cbit_length)
01701 #define tables_length (ctypes_offset + 256)
01702 
01703 /* Layout of the UCP type table that translates property names into types and
01704 codes. Each entry used to point directly to a name, but to reduce the number of
01705 relocations in shared libraries, it now has an offset into a single string
01706 instead. */
01707 
01708 typedef struct {
01709   pcre_uint16 name_offset;
01710   pcre_uint16 type;
01711   pcre_uint16 value;
01712 } ucp_type_table;
01713 
01714 
01715 /* Internal shared data tables. These are tables that are used by more than one
01716 of the exported public functions. They have to be "external" in the C sense,
01717 but are not part of the PCRE public API. The data for these tables is in the
01718 pcre_tables.c module. */
01719 
01720 extern const int    _pcre_utf8_table1[];
01721 extern const int    _pcre_utf8_table2[];
01722 extern const int    _pcre_utf8_table3[];
01723 extern const uschar _pcre_utf8_table4[];
01724 
01725 extern const int    _pcre_utf8_table1_size;
01726 
01727 extern const char   _pcre_utt_names[];
01728 extern const ucp_type_table _pcre_utt[];
01729 extern const int _pcre_utt_size;
01730 
01731 extern const uschar _pcre_default_tables[];
01732 
01733 extern const uschar _pcre_OP_lengths[];
01734 
01735 
01736 /* Internal shared functions. These are functions that are used by more than
01737 one of the exported public functions. They have to be "external" in the C
01738 sense, but are not part of the PCRE public API. */
01739 
01740 extern const uschar *_pcre_find_bracket(const uschar *, BOOL, int);
01741 extern BOOL          _pcre_is_newline(const uschar *, int, const uschar *,
01742                        int *, BOOL);
01743 extern int           _pcre_ord2utf8(int, uschar *);
01744 extern real_pcre    *_pcre_try_flipped(const real_pcre *, real_pcre *,
01745                        const pcre_study_data *, pcre_study_data *);
01746 extern int           _pcre_valid_utf8(const uschar *, int);
01747 extern BOOL          _pcre_was_newline(const uschar *, int, const uschar *,
01748                        int *, BOOL);
01749 extern BOOL          _pcre_xclass(int, const uschar *);
01750 
01751 
01752 /* Unicode character database (UCD) */
01753 
01754 typedef struct {
01755   uschar script;
01756   uschar chartype;
01757   pcre_int32 other_case;
01758 } ucd_record;
01759 
01760 extern const ucd_record  _pcre_ucd_records[];
01761 extern const uschar      _pcre_ucd_stage1[];
01762 extern const pcre_uint16 _pcre_ucd_stage2[];
01763 extern const int         _pcre_ucp_gentype[];
01764 
01765 
01766 /* UCD access macros */
01767 
01768 #define UCD_BLOCK_SIZE 128
01769 #define GET_UCD(ch) (_pcre_ucd_records + \
01770         _pcre_ucd_stage2[_pcre_ucd_stage1[(ch) / UCD_BLOCK_SIZE] * \
01771         UCD_BLOCK_SIZE + ch % UCD_BLOCK_SIZE])
01772 
01773 #define UCD_CHARTYPE(ch)  GET_UCD(ch)->chartype
01774 #define UCD_SCRIPT(ch)    GET_UCD(ch)->script
01775 #define UCD_CATEGORY(ch)  _pcre_ucp_gentype[UCD_CHARTYPE(ch)]
01776 #define UCD_OTHERCASE(ch) (ch + GET_UCD(ch)->other_case)
01777 
01778 #endif
01779 
01780 /* End of pcre_internal.h */