--- code/trunk/internal.h 2007/02/24 21:38:21 13 +++ code/trunk/internal.h 2007/02/24 21:39:01 33 @@ -3,7 +3,7 @@ *************************************************/ -#define PCRE_VERSION "1.05 23-Dec-1997" +#define PCRE_VERSION "2.05 21-Apr-1999" /* This is a library of functions to support regular expressions whose syntax @@ -12,7 +12,7 @@ Written by: Philip Hazel - Copyright (c) 1997 University of Cambridge + Copyright (c) 1997-1999 University of Cambridge ----------------------------------------------------------------------------- Permission is granted to anyone to use this software for any purpose on any @@ -28,6 +28,10 @@ 3. Altered versions must be plainly marked as such, and must not be misrepresented as being the original software. + +4. If PCRE is embedded in any software that is released under the GNU + General Purpose Licence (GPL), then the terms of that licence shall + supersede any condition above with which it is incompatible. ----------------------------------------------------------------------------- */ @@ -46,7 +50,6 @@ #include #include -#include #include #include #include @@ -60,35 +63,36 @@ #define offsetof(p_type,field) ((size_t)&(((p_type *)0)->field)) #endif +/* These are the public options that can change during matching. */ + +#define PCRE_IMS (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL) + /* Private options flags start at the most significant end of the two bytes. The public options defined in pcre.h start at the least significant end. Make sure they don't overlap! */ #define PCRE_FIRSTSET 0x8000 /* first_char is set */ #define PCRE_STARTLINE 0x4000 /* start after \n for multiline */ -#define PCRE_COMPILED_CASELESS 0x2000 /* like it says */ +#define PCRE_INGROUP 0x2000 /* compiling inside a group */ /* Options for the "extra" block produced by pcre_study(). */ -#define PCRE_STUDY_CASELESS 0x01 /* study was caseless */ -#define PCRE_STUDY_MAPPED 0x02 /* a map of starting chars exists */ +#define PCRE_STUDY_MAPPED 0x01 /* a map of starting chars exists */ -/* Masks for identifying the public options: all permitted at compile time, -only some permitted at run or study time. */ +/* Masks for identifying the public options which are permitted at compile +time, run time or study time, respectively. */ #define PUBLIC_OPTIONS \ (PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \ - PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA) + PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY) -#define PUBLIC_EXEC_OPTIONS \ - (PCRE_CASELESS|PCRE_ANCHORED|PCRE_MULTILINE|PCRE_NOTBOL|PCRE_NOTEOL| \ - PCRE_DOTALL|PCRE_DOLLAR_ENDONLY) +#define PUBLIC_EXEC_OPTIONS (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL) -#define PUBLIC_STUDY_OPTIONS (PCRE_CASELESS) +#define PUBLIC_STUDY_OPTIONS 0 /* None defined */ /* Magic number to provide a small check against being handed junk. */ -#define MAGIC_NUMBER 0x50435245 /* 'PCRE' */ +#define MAGIC_NUMBER 0x50435245UL /* 'PCRE' */ /* Miscellaneous definitions */ @@ -100,19 +104,14 @@ /* These are escaped items that aren't just an encoding of a particular data value such as \n. They must have non-zero values, as check_escape() returns their negation. Also, they must appear in the same order as in the opcode -definitions below, up to ESC_Z. The final one must be ESC_REF as subsequent +definitions below, up to ESC_z. The final one must be ESC_REF as subsequent values are used for \1, \2, \3, etc. There is a test in the code for an escape greater than ESC_b and less than ESC_X to detect the types that may be repeated. If any new escapes are put in-between that don't consume a character, that code will have to change. */ enum { ESC_A = 1, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s, ESC_W, ESC_w, - - /* These are not Perl escapes, so can't appear in the */ - ESC_X, /* simple table-lookup because they must be conditional */ - /* on PCRE_EXTRA. */ - ESC_Z, - ESC_REF }; + ESC_Z, ESC_z, ESC_REF }; /* Opcode table: OP_BRA must be last, as all values >= it are used for brackets that extract substrings. Starting from 1 (i.e. after OP_END), the values up to @@ -132,9 +131,10 @@ OP_WHITESPACE, /* \s */ OP_NOT_WORDCHAR, /* \W */ OP_WORDCHAR, /* \w */ - OP_CUT, /* The analogue of Prolog's "cut" operation (extension) */ - OP_EOD, /* End of data: \Z. */ + OP_EODN, /* End of data or \n at end of data: \Z. */ + OP_EOD, /* End of data: \z */ + OP_OPT, /* Set runtime options */ OP_CIRC, /* Start of line - varies with multiline switch */ OP_DOLL, /* End of line - varies with multiline switch */ OP_ANY, /* Match any character */ @@ -181,7 +181,6 @@ OP_CRMINRANGE, OP_CLASS, /* Match a character class */ - OP_NEGCLASS, /* Match a character class, specified negatively */ OP_REF, /* Match a back reference */ OP_ALT, /* Start of alternation */ @@ -189,9 +188,20 @@ OP_KETRMAX, /* These two must remain together and in this */ OP_KETRMIN, /* order. They are for groups the repeat for ever. */ - OP_ASSERT, - OP_ASSERT_NOT, + /* The assertions must come before ONCE and COND */ + + OP_ASSERT, /* Positive lookahead */ + OP_ASSERT_NOT, /* Negative lookahead */ + OP_ASSERTBACK, /* Positive lookbehind */ + OP_ASSERTBACK_NOT, /* Negative lookbehind */ + OP_REVERSE, /* Move pointer back - used in lookbehind assertions */ + + /* ONCE and COND must come after the assertions, with ONCE first, as there's + a test for >= ONCE for a subpattern that isn't an assertion. */ + OP_ONCE, /* Once matched, don't back up into the subpattern */ + OP_COND, /* Conditional group */ + OP_CREF, /* Used to hold an extraction string number */ OP_BRAZERO, /* These two must remain together and in this */ OP_BRAMINZERO, /* order. */ @@ -231,8 +241,13 @@ #define ERR19 "too many sets of parentheses" #define ERR20 "regular expression too large" #define ERR21 "failed to get memory" -#define ERR22 "unmatched brackets" +#define ERR22 "unmatched parentheses" #define ERR23 "internal error: code overflow" +#define ERR24 "unrecognized character after (?<" +#define ERR25 "lookbehind assertion is not fixed length" +#define ERR26 "malformed number after (?(" +#define ERR27 "conditional group contains more than two branches" +#define ERR28 "assertion expected after (?(" /* All character handling must be done as unsigned characters. Otherwise there are problems with top-bit-set characters and functions such as isspace(). @@ -247,7 +262,8 @@ runs on as long as necessary after the end. */ typedef struct real_pcre { - unsigned int magic_number; + unsigned long int magic_number; + const unsigned char *tables; unsigned short int options; unsigned char top_bracket; unsigned char top_backref; @@ -262,14 +278,38 @@ unsigned char start_bits[32]; } real_pcre_extra; -/* Global tables from chartables.c */ -extern uschar pcre_lcc[]; -extern uschar pcre_fcc[]; -extern uschar pcre_cbits[]; -extern uschar pcre_ctypes[]; +/* Structure for passing "static" information around between the functions +doing the compiling, so that they are thread-safe. */ + +typedef struct compile_data { + const uschar *lcc; /* Points to lower casing table */ + const uschar *fcc; /* Points to case-flippint table */ + const uschar *cbits; /* Points to character type table */ + const uschar *ctypes; /* Points to table of type maps */ +} compile_data; + +/* Structure for passing "static" information around between the functions +doing the matching, so that they are thread-safe. */ + +typedef struct match_data { + int errorcode; /* As it says */ + int *offset_vector; /* Offset vector */ + int offset_end; /* One past the end */ + int offset_max; /* The maximum usable for return data */ + const uschar *lcc; /* Points to lower casing table */ + const uschar *ctypes; /* Points to table of type maps */ + BOOL offset_overflow; /* Set if too many extractions */ + BOOL notbol; /* NOTBOL flag */ + BOOL noteol; /* NOTEOL flag */ + BOOL endonly; /* Dollar not before final \n */ + const uschar *start_subject; /* Start of the subject string */ + const uschar *end_subject; /* End of the subject string */ + const uschar *end_match_ptr; /* Subject position at end match */ + int end_offset_top; /* Highwater mark at end of match */ +} match_data; -/* Bit definitions for entries in pcre_ctypes[]. */ +/* Bit definitions for entries in the pcre_ctypes table. */ #define ctype_space 0x01 #define ctype_letter 0x02 @@ -278,12 +318,21 @@ #define ctype_word 0x10 /* alphameric or '_' */ #define ctype_meta 0x80 /* regexp meta char or zero (end pattern) */ -/* Offsets for the bitmap tables */ +/* Offsets for the bitmap tables in pcre_cbits. Each table contains a set +of bits for a class map. */ -#define cbit_digit 0 -#define cbit_letter 32 -#define cbit_word 64 -#define cbit_space 96 -#define cbit_length 128 /* Length of the cbits table */ +#define cbit_digit 0 /* for \d */ +#define cbit_word 32 /* for \w */ +#define cbit_space 64 /* for \s */ +#define cbit_length 96 /* Length of the cbits table */ + +/* Offsets of the various tables from the base tables pointer, and +total length. */ + +#define lcc_offset 0 +#define fcc_offset 256 +#define cbits_offset 512 +#define ctypes_offset (cbits_offset + cbit_length) +#define tables_length (ctypes_offset + 256) /* End of internal.h */