Back to index

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