internal.h

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

Generated on Wed May 31 18:19:48 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6