Crazy Eddies GUI System: internal.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

# internal.h

    00001 /*************************************************
    00002 *      Perl-Compatible Regular Expressions       *
    00003 *************************************************/
    00004
    00005
    00006 /* This 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. See
    00008 the file doc/Tech.Notes for some information on the internals.
    00009
    00010 Written by: Philip Hazel <ph10@cam.ac.uk>
    00011
    00012            Copyright (c) 1997-2004 University of Cambridge
    00013
    00014 -----------------------------------------------------------------------------
    00015 Redistribution and use in source and binary forms, with or without
    00016 modification, are permitted provided that the following conditions are met:
    00017
    00018     * Redistributions of source code must retain the above copyright notice,
    00019       this list of conditions and the following disclaimer.
    00020
    00021     * Redistributions in binary form must reproduce the above copyright
    00022       notice, this list of conditions and the following disclaimer in the
    00023       documentation and/or other materials provided with the distribution.
    00024
    00025     * Neither the name of the University of Cambridge nor the names of its
    00026       contributors may be used to endorse or promote products derived from
    00027       this software without specific prior written permission.
    00028
    00029 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    00030 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    00031 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    00032 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    00033 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    00034 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    00035 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    00036 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    00037 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    00038 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    00039 POSSIBILITY OF SUCH DAMAGE.
    00040 -----------------------------------------------------------------------------
    00041 */
    00042
    00043 /* This header contains definitions that are shared between the different
    00044 modules, but which are not relevant to the outside. */
    00045
    00046 /* Get the definitions provided by running "configure" */
    00047
    00048 #include "pcreconfig.h"
    00049
    00050 /* Standard C headers plus the external interface definition. The only time
    00051 setjmp and stdarg are used is when NO_RECURSE is set. */
    00052
    00053 #include <ctype.h>
    00054 #include <limits.h>
    00055 #include <setjmp.h>
    00056 #include <stdarg.h>
    00057 #include <stddef.h>
    00058 #include <stdio.h>
    00059 #include <stdlib.h>
    00060 #include <string.h>
    00061
    00062 #ifndef PCRE_SPY
    00063 #define PCRE_DEFINITION       /* Win32 __declspec(export) trigger for .dll */
    00064 #endif
    00065
    00066 /* We need to have types that specify unsigned 16-bit and 32-bit integers. We
    00067 cannot determine these outside the compilation (e.g. by running a program as
    00068 part of "configure") because PCRE is often cross-compiled for use on other
    00069 systems. Instead we make use of the maximum sizes that are available at
    00070 preprocessor time in standard C environments. */
    00071
    00072 #if USHRT_MAX == 65535
    00073   typedef unsigned short pcre_uint16;
    00074 #elif UINT_MAX == 65535
    00075   typedef unsigned int pcre_uint16;
    00076 #else
    00077   #error Cannot determine a type for 16-bit unsigned integers
    00078 #endif
    00079
    00080 #if UINT_MAX == 4294967295
    00081   typedef unsigned int pcre_uint32;
    00082 #elif ULONG_MAX == 4294967295
    00083   typedef unsigned long int pcre_uint32;
    00084 #else
    00085   #error Cannot determine a type for 32-bit unsigned integers
    00086 #endif
    00087
    00088 /* All character handling must be done as unsigned characters. Otherwise there
    00089 are problems with top-bit-set characters and functions such as isspace().
    00090 However, we leave the interface to the outside world as char *, because that
    00091 should make things easier for callers. We define a short type for unsigned char
    00092 to save lots of typing. I tried "uchar", but it causes problems on Digital
    00093 Unix, where it is defined in sys/types, so use "uschar" instead. */
    00094
    00095 typedef unsigned char uschar;
    00096
    00097 /* Include the public PCRE header */
    00098
    00099 #include "pcre.h"
    00100
    00101 /* When compiling for use with the Virtual Pascal compiler, these functions
    00102 need to have their names changed. PCRE must be compiled with the -DVPCOMPAT
    00103 option on the command line. */
    00104
    00105 #ifdef VPCOMPAT
    00106 #define strncmp(s1,s2,m) _strncmp(s1,s2,m)
    00107 #define memcpy(d,s,n)    _memcpy(d,s,n)
    00108 #define memmove(d,s,n)   _memmove(d,s,n)
    00109 #define memset(s,c,n)    _memset(s,c,n)
    00110 #else  /* VPCOMPAT */
    00111
    00112 /* To cope with SunOS4 and other systems that lack memmove() but have bcopy(),
    00113 define a macro for memmove() if HAVE_MEMMOVE is false, provided that HAVE_BCOPY
    00114 is set. Otherwise, include an emulating function for those systems that have
    00115 neither (there some non-Unix environments where this is the case). This assumes
    00116 that all calls to memmove are moving strings upwards in store, which is the
    00117 case in PCRE. */
    00118
    00119 #if ! HAVE_MEMMOVE
    00120 #undef  memmove        /* some systems may have a macro */
    00121 #if HAVE_BCOPY
    00122 #define memmove(a, b, c) bcopy(b, a, c)
    00123 #else  /* HAVE_BCOPY */
    00124 void *
    00125 pcre_memmove(unsigned char *dest, const unsigned char *src, size_t n)
    00126 {
    00127 int i;
    00128 dest += n;
    00129 src += n;
    00130 for (i = 0; i < n; ++i) *(--dest) =  *(--src);
    00131 return dest;
    00132 }
    00133 #define memmove(a, b, c) pcre_memmove(a, b, c)
    00134 #endif   /* not HAVE_BCOPY */
    00135 #endif   /* not HAVE_MEMMOVE */
    00136 #endif   /* not VPCOMPAT */
    00137
    00138
    00139 /* PCRE keeps offsets in its compiled code as 2-byte quantities (always stored
    00140 in big-endian order) by default. These are used, for example, to link from the
    00141 start of a subpattern to its alternatives and its end. The use of 2 bytes per
    00142 offset limits the size of the compiled regex to around 64K, which is big enough
    00143 for almost everybody. However, I received a request for an even bigger limit.
    00144 For this reason, and also to make the code easier to maintain, the storing and
    00145 loading of offsets from the byte string is now handled by the macros that are
    00146 defined here.
    00147
    00148 The macros are controlled by the value of LINK_SIZE. This defaults to 2 in
    00149 the config.h file, but can be overridden by using -D on the command line. This
    00150 is automated on Unix systems via the "configure" command. */
    00151
    00152 #if LINK_SIZE == 2
    00153
    00154 #define PUT(a,n,d)   \
    00155   (a[n] = (d) >> 8), \
    00156   (a[(n)+1] = (d) & 255)
    00157
    00158 #define GET(a,n) \
    00159   (((a)[n] << 8) | (a)[(n)+1])
    00160
    00161 #define MAX_PATTERN_SIZE (1 << 16)
    00162
    00163
    00164 #elif LINK_SIZE == 3
    00165
    00166 #define PUT(a,n,d)       \
    00167   (a[n] = (d) >> 16),    \
    00168   (a[(n)+1] = (d) >> 8), \
    00169   (a[(n)+2] = (d) & 255)
    00170
    00171 #define GET(a,n) \
    00172   (((a)[n] << 16) | ((a)[(n)+1] << 8) | (a)[(n)+2])
    00173
    00174 #define MAX_PATTERN_SIZE (1 << 24)
    00175
    00176
    00177 #elif LINK_SIZE == 4
    00178
    00179 #define PUT(a,n,d)        \
    00180   (a[n] = (d) >> 24),     \
    00181   (a[(n)+1] = (d) >> 16), \
    00182   (a[(n)+2] = (d) >> 8),  \
    00183   (a[(n)+3] = (d) & 255)
    00184
    00185 #define GET(a,n) \
    00186   (((a)[n] << 24) | ((a)[(n)+1] << 16) | ((a)[(n)+2] << 8) | (a)[(n)+3])
    00187
    00188 #define MAX_PATTERN_SIZE (1 << 30)   /* Keep it positive */
    00189
    00190
    00191 #else
    00192 #error LINK_SIZE must be either 2, 3, or 4
    00193 #endif
    00194
    00195
    00196 /* Convenience macro defined in terms of the others */
    00197
    00198 #define PUTINC(a,n,d)   PUT(a,n,d), a += LINK_SIZE
    00199
    00200
    00201 /* PCRE uses some other 2-byte quantities that do not change when the size of
    00202 offsets changes. There are used for repeat counts and for other things such as
    00203 capturing parenthesis numbers in back references. */
    00204
    00205 #define PUT2(a,n,d)   \
    00206   a[n] = (d) >> 8; \
    00207   a[(n)+1] = (d) & 255
    00208
    00209 #define GET2(a,n) \
    00210   (((a)[n] << 8) | (a)[(n)+1])
    00211
    00212 #define PUT2INC(a,n,d)  PUT2(a,n,d), a += 2
    00213
    00214
    00215 /* In case there is no definition of offsetof() provided - though any proper
    00216 Standard C system should have one. */
    00217
    00218 #ifndef offsetof
    00219 #define offsetof(p_type,field) ((size_t)&(((p_type *)0)->field))
    00220 #endif
    00221
    00222
    00223 /* These are the public options that can change during matching. */
    00224
    00225 #define PCRE_IMS (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL)
    00226
    00227 /* Private options flags start at the most significant end of the four bytes,
    00228 but skip the top bit so we can use ints for convenience without getting tangled
    00229 with negative values. The public options defined in pcre.h start at the least
    00230 significant end. Make sure they don't overlap, though now that we have expanded
    00231 to four bytes, there is plenty of space. */
    00232
    00233 #define PCRE_FIRSTSET      0x40000000  /* first_byte is set */
    00234 #define PCRE_REQCHSET      0x20000000  /* req_byte is set */
    00235 #define PCRE_STARTLINE     0x10000000  /* start after \n for multiline */
    00236 #define PCRE_ICHANGED      0x08000000  /* i option changes within regex */
    00237 #define PCRE_NOPARTIAL     0x04000000  /* can't use partial with this regex */
    00238
    00239 /* Options for the "extra" block produced by pcre_study(). */
    00240
    00241 #define PCRE_STUDY_MAPPED   0x01     /* a map of starting chars exists */
    00242
    00243 /* Masks for identifying the public options which are permitted at compile
    00244 time, run time or study time, respectively. */
    00245
    00246 #define PUBLIC_OPTIONS \
    00247   (PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \
    00248    PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY|PCRE_UTF8| \
    00249    PCRE_NO_AUTO_CAPTURE|PCRE_NO_UTF8_CHECK|PCRE_AUTO_CALLOUT)
    00250
    00251 #define PUBLIC_EXEC_OPTIONS \
    00252   (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK| \
    00253    PCRE_PARTIAL)
    00254
    00255 #define PUBLIC_STUDY_OPTIONS 0   /* None defined */
    00256
    00257 /* Magic number to provide a small check against being handed junk. */
    00258
    00259 #define MAGIC_NUMBER  0x50435245UL   /* 'PCRE' */
    00260
    00261 /* Negative values for the firstchar and reqchar variables */
    00262
    00263 #define REQ_UNSET (-2)
    00264 #define REQ_NONE  (-1)
    00265
    00266 /* Flags added to firstbyte or reqbyte; a "non-literal" item is either a
    00267 variable-length repeat, or a anything other than literal characters. */
    00268
    00269 #define REQ_CASELESS 0x0100    /* indicates caselessness */
    00270 #define REQ_VARY     0x0200    /* reqbyte followed non-literal item */
    00271
    00272 /* Miscellaneous definitions */
    00273
    00274 typedef int BOOL;
    00275
    00276 #define FALSE   0
    00277 #define TRUE    1
    00278
    00279 /* Escape items that are just an encoding of a particular data value. Note that
    00280 ESC_n is defined as yet another macro, which is set in config.h to either \n
    00281 (the default) or \r (which some people want). */
    00282
    00283 #ifndef ESC_e
    00284 #define ESC_e 27
    00285 #endif
    00286
    00287 #ifndef ESC_f
    00288 #define ESC_f '\f'
    00289 #endif
    00290
    00291 #ifndef ESC_n
    00292 #define ESC_n NEWLINE
    00293 #endif
    00294
    00295 #ifndef ESC_r
    00296 #define ESC_r '\r'
    00297 #endif
    00298
    00299 /* We can't officially use ESC_t because it is a POSIX reserved identifier
    00300 (presumably because of all the others like size_t). */
    00301
    00302 #ifndef ESC_tee
    00303 #define ESC_tee '\t'
    00304 #endif
    00305
    00306 /* These are escaped items that aren't just an encoding of a particular data
    00307 value such as \n. They must have non-zero values, as check_escape() returns
    00308 their negation. Also, they must appear in the same order as in the opcode
    00309 definitions below, up to ESC_z. There's a dummy for OP_ANY because it
    00310 corresponds to "." rather than an escape sequence. The final one must be
    00311 ESC_REF as subsequent values are used for \1, \2, \3, etc. There is are two
    00312 tests in the code for an escape greater than ESC_b and less than ESC_Z to
    00313 detect the types that may be repeated. These are the types that consume
    00314 characters. If any new escapes are put in between that don't consume a
    00315 character, that code will have to change. */
    00316
    00317 enum { ESC_A = 1, ESC_G, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s, ESC_W,
    00318        ESC_w, ESC_dum1, ESC_C, ESC_P, ESC_p, ESC_X, ESC_Z, ESC_z, ESC_E,
    00319        ESC_Q, ESC_REF };
    00320
    00321 /* Flag bits and data types for the extended class (OP_XCLASS) for classes that
    00322 contain UTF-8 characters with values greater than 255. */
    00323
    00324 #define XCL_NOT    0x01    /* Flag: this is a negative class */
    00325 #define XCL_MAP    0x02    /* Flag: a 32-byte map is present */
    00326
    00327 #define XCL_END       0    /* Marks end of individual items */
    00328 #define XCL_SINGLE    1    /* Single item (one multibyte char) follows */
    00329 #define XCL_RANGE     2    /* A range (two multibyte chars) follows */
    00330 #define XCL_PROP      3    /* Unicode property (one property code) follows */
    00331 #define XCL_NOTPROP   4    /* Unicode inverted property (ditto) */
    00332
    00333
    00334 /* Opcode table: OP_BRA must be last, as all values >= it are used for brackets
    00335 that extract substrings. Starting from 1 (i.e. after OP_END), the values up to
    00336 OP_EOD must correspond in order to the list of escapes immediately above.
    00337 Note that whenever this list is updated, the two macro definitions that follow
    00338 must also be updated to match. */
    00339
    00340 enum {
    00341   OP_END,            /* 0 End of pattern */
    00342
    00343   /* Values corresponding to backslashed metacharacters */
    00344
    00345   OP_SOD,            /* 1 Start of data: \A */
    00346   OP_SOM,            /* 2 Start of match (subject + offset): \G */
    00347   OP_NOT_WORD_BOUNDARY,  /*  3 \B */
    00348   OP_WORD_BOUNDARY,      /*  4 \b */
    00349   OP_NOT_DIGIT,          /*  5 \D */
    00350   OP_DIGIT,              /*  6 \d */
    00351   OP_NOT_WHITESPACE,     /*  7 \S */
    00352   OP_WHITESPACE,         /*  8 \s */
    00353   OP_NOT_WORDCHAR,       /*  9 \W */
    00354   OP_WORDCHAR,           /* 10 \w */
    00355   OP_ANY,            /* 11 Match any character */
    00356   OP_ANYBYTE,        /* 12 Match any byte (\C); different to OP_ANY for UTF-8 */
    00357   OP_NOTPROP,        /* 13 \P (not Unicode property) */
    00358   OP_PROP,           /* 14 \p (Unicode property) */
    00359   OP_EXTUNI,         /* 15 \X (extended Unicode sequence */
    00360   OP_EODN,           /* 16 End of data or \n at end of data: \Z. */
    00361   OP_EOD,            /* 17 End of data: \z */
    00362
    00363   OP_OPT,            /* 18 Set runtime options */
    00364   OP_CIRC,           /* 19 Start of line - varies with multiline switch */
    00365   OP_DOLL,           /* 20 End of line - varies with multiline switch */
    00366   OP_CHAR,           /* 21 Match one character, casefully */
    00367   OP_CHARNC,         /* 22 Match one character, caselessly */
    00368   OP_NOT,            /* 23 Match anything but the following char */
    00369
    00370   OP_STAR,           /* 24 The maximizing and minimizing versions of */
    00371   OP_MINSTAR,        /* 25 all these opcodes must come in pairs, with */
    00372   OP_PLUS,           /* 26 the minimizing one second. */
    00373   OP_MINPLUS,        /* 27 This first set applies to single characters */
    00374   OP_QUERY,          /* 28 */
    00375   OP_MINQUERY,       /* 29 */
    00376   OP_UPTO,           /* 30 From 0 to n matches */
    00377   OP_MINUPTO,        /* 31 */
    00378   OP_EXACT,          /* 32 Exactly n matches */
    00379
    00380   OP_NOTSTAR,        /* 33 The maximizing and minimizing versions of */
    00381   OP_NOTMINSTAR,     /* 34 all these opcodes must come in pairs, with */
    00382   OP_NOTPLUS,        /* 35 the minimizing one second. */
    00383   OP_NOTMINPLUS,     /* 36 This set applies to "not" single characters */
    00384   OP_NOTQUERY,       /* 37 */
    00385   OP_NOTMINQUERY,    /* 38 */
    00386   OP_NOTUPTO,        /* 39 From 0 to n matches */
    00387   OP_NOTMINUPTO,     /* 40 */
    00388   OP_NOTEXACT,       /* 41 Exactly n matches */
    00389
    00390   OP_TYPESTAR,       /* 42 The maximizing and minimizing versions of */
    00391   OP_TYPEMINSTAR,    /* 43 all these opcodes must come in pairs, with */
    00392   OP_TYPEPLUS,       /* 44 the minimizing one second. These codes must */
    00393   OP_TYPEMINPLUS,    /* 45 be in exactly the same order as those above. */
    00394   OP_TYPEQUERY,      /* 46 This set applies to character types such as \d */
    00395   OP_TYPEMINQUERY,   /* 47 */
    00396   OP_TYPEUPTO,       /* 48 From 0 to n matches */
    00397   OP_TYPEMINUPTO,    /* 49 */
    00398   OP_TYPEEXACT,      /* 50 Exactly n matches */
    00399
    00400   OP_CRSTAR,         /* 51 The maximizing and minimizing versions of */
    00401   OP_CRMINSTAR,      /* 52 all these opcodes must come in pairs, with */
    00402   OP_CRPLUS,         /* 53 the minimizing one second. These codes must */
    00403   OP_CRMINPLUS,      /* 54 be in exactly the same order as those above. */
    00404   OP_CRQUERY,        /* 55 These are for character classes and back refs */
    00405   OP_CRMINQUERY,     /* 56 */
    00406   OP_CRRANGE,        /* 57 These are different to the three sets above. */
    00407   OP_CRMINRANGE,     /* 58 */
    00408
    00409   OP_CLASS,          /* 59 Match a character class, chars < 256 only */
    00410   OP_NCLASS,         /* 60 Same, but the bitmap was created from a negative
    00411                            class - the difference is relevant only when a UTF-8
    00412                            character > 255 is encountered. */
    00413
    00414   OP_XCLASS,         /* 61 Extended class for handling UTF-8 chars within the
    00415                            class. This does both positive and negative. */
    00416
    00417   OP_REF,            /* 62 Match a back reference */
    00418   OP_RECURSE,        /* 63 Match a numbered subpattern (possibly recursive) */
    00419   OP_CALLOUT,        /* 64 Call out to external function if provided */
    00420
    00421   OP_ALT,            /* 65 Start of alternation */
    00422   OP_KET,            /* 66 End of group that doesn't have an unbounded repeat */
    00423   OP_KETRMAX,        /* 67 These two must remain together and in this */
    00424   OP_KETRMIN,        /* 68 order. They are for groups the repeat for ever. */
    00425
    00426   /* The assertions must come before ONCE and COND */
    00427
    00428   OP_ASSERT,         /* 69 Positive lookahead */
    00429   OP_ASSERT_NOT,     /* 70 Negative lookahead */
    00430   OP_ASSERTBACK,     /* 71 Positive lookbehind */
    00431   OP_ASSERTBACK_NOT, /* 72 Negative lookbehind */
    00432   OP_REVERSE,        /* 73 Move pointer back - used in lookbehind assertions */
    00433
    00434   /* ONCE and COND must come after the assertions, with ONCE first, as there's
    00435   a test for >= ONCE for a subpattern that isn't an assertion. */
    00436
    00437   OP_ONCE,           /* 74 Once matched, don't back up into the subpattern */
    00438   OP_COND,           /* 75 Conditional group */
    00439   OP_CREF,           /* 76 Used to hold an extraction string number (cond ref) */
    00440
    00441   OP_BRAZERO,        /* 77 These two must remain together and in this */
    00442   OP_BRAMINZERO,     /* 78 order. */
    00443
    00444   OP_BRANUMBER,      /* 79 Used for extracting brackets whose number is greater
    00445                            than can fit into an opcode. */
    00446
    00447   OP_BRA             /* 80 This and greater values are used for brackets that
    00448                            extract substrings up to EXTRACT_BASIC_MAX. After
    00449                            that, use is made of OP_BRANUMBER. */
    00450 };
    00451
    00452 /* WARNING WARNING WARNING: There is an implicit assumption in pcre.c and
    00453 study.c that all opcodes are less than 128 in value. This makes handling UTF-8
    00454 character sequences easier. */
    00455
    00456 /* The highest extraction number before we have to start using additional
    00457 bytes. (Originally PCRE didn't have support for extraction counts highter than
    00458 this number.) The value is limited by the number of opcodes left after OP_BRA,
    00459 i.e. 255 - OP_BRA. We actually set it a bit lower to leave room for additional
    00460 opcodes. */
    00461
    00462 #define EXTRACT_BASIC_MAX  100
    00463
    00464
    00465 /* This macro defines textual names for all the opcodes. There are used only
    00466 for debugging, in pcre.c when DEBUG is defined, and also in pcretest.c. The
    00467 macro is referenced only in printint.c. */
    00468
    00469 #define OP_NAME_LIST \
    00470   "End", "\\A", "\\G", "\\B", "\\b", "\\D", "\\d",                \
    00471   "\\S", "\\s", "\\W", "\\w", "Any", "Anybyte",                   \
    00472   "notprop", "prop", "extuni",                                    \
    00473   "\\Z", "\\z",                                                   \
    00474   "Opt", "^", "$", "char", "charnc", "not",                       \
    00475   "*", "*?", "+", "+?", "?", "??", "{", "{", "{",                 \
    00476   "*", "*?", "+", "+?", "?", "??", "{", "{", "{",                 \
    00477   "*", "*?", "+", "+?", "?", "??", "{", "{", "{",                 \
    00478   "*", "*?", "+", "+?", "?", "??", "{", "{",                      \
    00479   "class", "nclass", "xclass", "Ref", "Recurse", "Callout",       \
    00480   "Alt", "Ket", "KetRmax", "KetRmin", "Assert", "Assert not",     \
    00481   "AssertB", "AssertB not", "Reverse", "Once", "Cond", "Cond ref",\
    00482   "Brazero", "Braminzero", "Branumber", "Bra"
    00483
    00484
    00485 /* This macro defines the length of fixed length operations in the compiled
    00486 regex. The lengths are used when searching for specific things, and also in the
    00487 debugging printing of a compiled regex. We use a macro so that it can be
    00488 incorporated both into pcre.c and pcretest.c without being publicly exposed.
    00489
    00490 As things have been extended, some of these are no longer fixed lenths, but are
    00491 minima instead. For example, the length of a single-character repeat may vary
    00492 in UTF-8 mode. The code that uses this table must know about such things. */
    00493
    00494 #define OP_LENGTHS \
    00495   1,                             /* End                                    */ \
    00496   1, 1, 1, 1, 1, 1, 1, 1, 1, 1,  /* \A, \G, \B, \B, \D, \d, \S, \s, \W, \w */ \
    00497   1, 1,                          /* Any, Anybyte                           */ \
    00498   2, 2, 1,                       /* NOTPROP, PROP, EXTUNI                  */ \
    00499   1, 1, 2, 1, 1,                 /* \Z, \z, Opt, ^, $                      */ \
    00500   2,                             /* Char  - the minimum length             */ \
    00501   2,                             /* Charnc  - the minimum length           */ \
    00502   2,                             /* not                                    */ \
    00503   /* Positive single-char repeats                            ** These are  */ \
    00504   2, 2, 2, 2, 2, 2,              /* *, *?, +, +?, ?, ??      ** minima in  */ \
    00505   4, 4, 4,                       /* upto, minupto, exact     ** UTF-8 mode */ \
    00506   /* Negative single-char repeats - only for chars < 256                   */ \
    00507   2, 2, 2, 2, 2, 2,              /* NOT *, *?, +, +?, ?, ??                */ \
    00508   4, 4, 4,                       /* NOT upto, minupto, exact               */ \
    00509   /* Positive type repeats                                                 */ \
    00510   2, 2, 2, 2, 2, 2,              /* Type *, *?, +, +?, ?, ??               */ \
    00511   4, 4, 4,                       /* Type upto, minupto, exact              */ \
    00512   /* Character class & ref repeats                                         */ \
    00513   1, 1, 1, 1, 1, 1,              /* *, *?, +, +?, ?, ??                    */ \
    00514   5, 5,                          /* CRRANGE, CRMINRANGE                    */ \
    00515  33,                             /* CLASS                                  */ \
    00516  33,                             /* NCLASS                                 */ \
    00517   0,                             /* XCLASS - variable length               */ \
    00518   3,                             /* REF                                    */ \
    00519   1+LINK_SIZE,                   /* RECURSE                                */ \
    00520   2+2*LINK_SIZE,                 /* CALLOUT                                */ \
    00521   1+LINK_SIZE,                   /* Alt                                    */ \
    00522   1+LINK_SIZE,                   /* Ket                                    */ \
    00523   1+LINK_SIZE,                   /* KetRmax                                */ \
    00524   1+LINK_SIZE,                   /* KetRmin                                */ \
    00525   1+LINK_SIZE,                   /* Assert                                 */ \
    00526   1+LINK_SIZE,                   /* Assert not                             */ \
    00527   1+LINK_SIZE,                   /* Assert behind                          */ \
    00528   1+LINK_SIZE,                   /* Assert behind not                      */ \
    00529   1+LINK_SIZE,                   /* Reverse                                */ \
    00530   1+LINK_SIZE,                   /* Once                                   */ \
    00531   1+LINK_SIZE,                   /* COND                                   */ \
    00532   3,                             /* CREF                                   */ \
    00533   1, 1,                          /* BRAZERO, BRAMINZERO                    */ \
    00534   3,                             /* BRANUMBER                              */ \
    00535   1+LINK_SIZE                    /* BRA                                    */ \
    00536
    00537
    00538 /* A magic value for OP_CREF to indicate the "in recursion" condition. */
    00539
    00540 #define CREF_RECURSE  0xffff
    00541
    00542 /* The texts of compile-time error messages are defined as macros here so that
    00543 they can be accessed by the POSIX wrapper and converted into error codes.  Yes,
    00544 I could have used error codes in the first place, but didn't feel like changing
    00545 just to accommodate the POSIX wrapper. */
    00546
    00547 #define ERR1  "\\ at end of pattern"
    00548 #define ERR2  "\\c at end of pattern"
    00549 #define ERR3  "unrecognized character follows \\"
    00550 #define ERR4  "numbers out of order in {} quantifier"
    00551 #define ERR5  "number too big in {} quantifier"
    00552 #define ERR6  "missing terminating ] for character class"
    00553 #define ERR7  "invalid escape sequence in character class"
    00554 #define ERR8  "range out of order in character class"
    00555 #define ERR9  "nothing to repeat"
    00556 #define ERR10 "operand of unlimited repeat could match the empty string"
    00557 #define ERR11 "internal error: unexpected repeat"
    00558 #define ERR12 "unrecognized character after (?"
    00559 #define ERR13 "POSIX named classes are supported only within a class"
    00560 #define ERR14 "missing )"
    00561 #define ERR15 "reference to non-existent subpattern"
    00562 #define ERR16 "erroffset passed as NULL"
    00563 #define ERR17 "unknown option bit(s) set"
    00564 #define ERR18 "missing ) after comment"
    00565 #define ERR19 "parentheses nested too deeply"
    00566 #define ERR20 "regular expression too large"
    00567 #define ERR21 "failed to get memory"
    00568 #define ERR22 "unmatched parentheses"
    00569 #define ERR23 "internal error: code overflow"
    00570 #define ERR24 "unrecognized character after (?<"
    00571 #define ERR25 "lookbehind assertion is not fixed length"
    00572 #define ERR26 "malformed number after (?("
    00573 #define ERR27 "conditional group contains more than two branches"
    00574 #define ERR28 "assertion expected after (?("
    00575 #define ERR29 "(?R or (?digits must be followed by )"
    00576 #define ERR30 "unknown POSIX class name"
    00577 #define ERR31 "POSIX collating elements are not supported"
    00578 #define ERR32 "this version of PCRE is not compiled with PCRE_UTF8 support"
    00579 #define ERR33 "spare error"
    00580 #define ERR34 "character value in \\x{...} sequence is too large"
    00581 #define ERR35 "invalid condition (?(0)"
    00582 #define ERR36 "\\C not allowed in lookbehind assertion"
    00583 #define ERR37 "PCRE does not support \\L, \\l, \\N, \\U, or \\u"
    00584 #define ERR38 "number after (?C is > 255"
    00585 #define ERR39 "closing ) for (?C expected"
    00586 #define ERR40 "recursive call could loop indefinitely"
    00587 #define ERR41 "unrecognized character after (?P"
    00588 #define ERR42 "syntax error after (?P"
    00589 #define ERR43 "two named groups have the same name"
    00590 #define ERR44 "invalid UTF-8 string"
    00591 #define ERR45 "support for \\P, \\p, and \\X has not been compiled"
    00592 #define ERR46 "malformed \\P or \\p sequence"
    00593 #define ERR47 "unknown property name after \\P or \\p"
    00594
    00595 /* The real format of the start of the pcre block; the index of names and the
    00596 code vector run on as long as necessary after the end. We store an explicit
    00597 offset to the name table so that if a regex is compiled on one host, saved, and
    00598 then run on another where the size of pointers is different, all might still
    00599 be well. For the case of compiled-on-4 and run-on-8, we include an extra
    00600 pointer that is always NULL. For future-proofing, we also include a few dummy
    00601 fields - even though you can never get this planning right!
    00602
    00603 NOTE NOTE NOTE:
    00604 Because people can now save and re-use compiled patterns, any additions to this
    00605 structure should be made at the end, and something earlier (e.g. a new
    00606 flag in the options or one of the dummy fields) should indicate that the new
    00607 fields are present. Currently PCRE always sets the dummy fields to zero.
    00608 NOTE NOTE NOTE:
    00609 */
    00610
    00611 typedef struct real_pcre {
    00612   pcre_uint32 magic_number;
    00613   pcre_uint32 size;               /* Total that was malloced */
    00614   pcre_uint32 options;
    00615   pcre_uint32 dummy1;             /* For future use, maybe */
    00616
    00617   pcre_uint16 top_bracket;
    00618   pcre_uint16 top_backref;
    00619   pcre_uint16 first_byte;
    00620   pcre_uint16 req_byte;
    00621   pcre_uint16 name_table_offset;  /* Offset to name table that follows */
    00622   pcre_uint16 name_entry_size;    /* Size of any name items */
    00623   pcre_uint16 name_count;         /* Number of name items */
    00624   pcre_uint16 dummy2;             /* For future use, maybe */
    00625
    00626   const unsigned char *tables;    /* Pointer to tables or NULL for std */
    00627   const unsigned char *nullpad;   /* NULL padding */
    00628 } real_pcre;
    00629
    00630 /* The format of the block used to store data from pcre_study(). The same
    00631 remark (see NOTE above) about extending this structure applies. */
    00632
    00633 typedef struct pcre_study_data {
    00634   pcre_uint32 size;               /* Total that was malloced */
    00635   pcre_uint32 options;
    00636   uschar start_bits[32];
    00637 } pcre_study_data;
    00638
    00639 /* Structure for passing "static" information around between the functions
    00640 doing the compiling, so that they are thread-safe. */
    00641
    00642 typedef struct compile_data {
    00643   const uschar *lcc;            /* Points to lower casing table */
    00644   const uschar *fcc;            /* Points to case-flipping table */
    00645   const uschar *cbits;          /* Points to character type table */
    00646   const uschar *ctypes;         /* Points to table of type maps */
    00647   const uschar *start_code;     /* The start of the compiled code */
    00648   const uschar *start_pattern;  /* The start of the pattern */
    00649   uschar *name_table;           /* The name/number table */
    00650   int  names_found;             /* Number of entries so far */
    00651   int  name_entry_size;         /* Size of each entry */
    00652   int  top_backref;             /* Maximum back reference */
    00653   unsigned int backref_map;     /* Bitmap of low back refs */
    00654   int  req_varyopt;             /* "After variable item" flag for reqbyte */
    00655   BOOL nopartial;               /* Set TRUE if partial won't work */
    00656 } compile_data;
    00657
    00658 /* Structure for maintaining a chain of pointers to the currently incomplete
    00659 branches, for testing for left recursion. */
    00660
    00661 typedef struct branch_chain {
    00662   struct branch_chain *outer;
    00663   uschar *current;
    00664 } branch_chain;
    00665
    00666 /* Structure for items in a linked list that represents an explicit recursive
    00667 call within the pattern. */
    00668
    00669 typedef struct recursion_info {
    00670   struct recursion_info *prevrec; /* Previous recursion record (or NULL) */
    00671   int group_num;                /* Number of group that was called */
    00672   const uschar *after_call;     /* "Return value": points after the call in the expr */
    00673   const uschar *save_start;     /* Old value of md->start_match */
    00674   int *offset_save;             /* Pointer to start of saved offsets */
    00675   int saved_max;                /* Number of saved offsets */
    00676 } recursion_info;
    00677
    00678 /* When compiling in a mode that doesn't use recursive calls to match(),
    00679 a structure is used to remember local variables on the heap. It is defined in
    00680 pcre.c, close to the match() function, so that it is easy to keep it in step
    00681 with any changes of local variable. However, the pointer to the current frame
    00682 must be saved in some "static" place over a longjmp(). We declare the
    00683 structure here so that we can put a pointer in the match_data structure.
    00684 NOTE: This isn't used for a "normal" compilation of pcre. */
    00685
    00686 struct heapframe;
    00687
    00688 /* Structure for passing "static" information around between the functions
    00689 doing the matching, so that they are thread-safe. */
    00690
    00691 typedef struct match_data {
    00692   unsigned long int match_call_count; /* As it says */
    00693   unsigned long int match_limit;/* As it says */
    00694   int   *offset_vector;         /* Offset vector */
    00695   int    offset_end;            /* One past the end */
    00696   int    offset_max;            /* The maximum usable for return data */
    00697   const uschar *lcc;            /* Points to lower casing table */
    00698   const uschar *ctypes;         /* Points to table of type maps */
    00699   BOOL   offset_overflow;       /* Set if too many extractions */
    00700   BOOL   notbol;                /* NOTBOL flag */
    00701   BOOL   noteol;                /* NOTEOL flag */
    00702   BOOL   utf8;                  /* UTF8 flag */
    00703   BOOL   endonly;               /* Dollar not before final \n */
    00704   BOOL   notempty;              /* Empty string match not wanted */
    00705   BOOL   partial;               /* PARTIAL flag */
    00706   BOOL   hitend;                /* Hit the end of the subject at some point */
    00707   const uschar *start_code;     /* For use when recursing */
    00708   const uschar *start_subject;  /* Start of the subject string */
    00709   const uschar *end_subject;    /* End of the subject string */
    00710   const uschar *start_match;    /* Start of this match attempt */
    00711   const uschar *end_match_ptr;  /* Subject position at end match */
    00712   int    end_offset_top;        /* Highwater mark at end of match */
    00713   int    capture_last;          /* Most recent capture number */
    00714   int    start_offset;          /* The start offset value */
    00715   recursion_info *recursive;    /* Linked list of recursion data */
    00716   void  *callout_data;          /* To pass back to callouts */
    00717   struct heapframe *thisframe;  /* Used only when compiling for no recursion */
    00718 } match_data;
    00719
    00720 /* Bit definitions for entries in the pcre_ctypes table. */
    00721
    00722 #define ctype_space   0x01
    00723 #define ctype_letter  0x02
    00724 #define ctype_digit   0x04
    00725 #define ctype_xdigit  0x08
    00726 #define ctype_word    0x10   /* alphameric or '_' */
    00727 #define ctype_meta    0x80   /* regexp meta char or zero (end pattern) */
    00728
    00729 /* Offsets for the bitmap tables in pcre_cbits. Each table contains a set
    00730 of bits for a class map. Some classes are built by combining these tables. */
    00731
    00732 #define cbit_space     0      /* [:space:] or \s */
    00733 #define cbit_xdigit   32      /* [:xdigit:] */
    00734 #define cbit_digit    64      /* [:digit:] or \d */
    00735 #define cbit_upper    96      /* [:upper:] */
    00736 #define cbit_lower   128      /* [:lower:] */
    00737 #define cbit_word    160      /* [:word:] or \w */
    00738 #define cbit_graph   192      /* [:graph:] */
    00739 #define cbit_print   224      /* [:print:] */
    00740 #define cbit_punct   256      /* [:punct:] */
    00741 #define cbit_cntrl   288      /* [:cntrl:] */
    00742 #define cbit_length  320      /* Length of the cbits table */
    00743
    00744 /* Offsets of the various tables from the base tables pointer, and
    00745 total length. */
    00746
    00747 #define lcc_offset      0
    00748 #define fcc_offset    256
    00749 #define cbits_offset  512
    00750 #define ctypes_offset (cbits_offset + cbit_length)
    00751 #define tables_length (ctypes_offset + 256)
    00752
    00753 /* End of internal.h */