3 |
*************************************************/ |
*************************************************/ |
4 |
|
|
5 |
|
|
|
#define PCRE_VERSION "2.01 21-Oct-1998" |
|
|
|
|
|
|
|
6 |
/* This is a library of functions to support regular expressions whose syntax |
/* This is a library of functions to support regular expressions whose syntax |
7 |
and semantics are as close as possible to those of the Perl 5 language. See |
and semantics are as close as possible to those of the Perl 5 language. See |
8 |
the file Tech.Notes for some information on the internals. |
the file Tech.Notes for some information on the internals. |
9 |
|
|
10 |
Written by: Philip Hazel <ph10@cam.ac.uk> |
Written by: Philip Hazel <ph10@cam.ac.uk> |
11 |
|
|
12 |
Copyright (c) 1998 University of Cambridge |
Copyright (c) 1997-2000 University of Cambridge |
13 |
|
|
14 |
----------------------------------------------------------------------------- |
----------------------------------------------------------------------------- |
15 |
Permission is granted to anyone to use this software for any purpose on any |
Permission is granted to anyone to use this software for any purpose on any |
25 |
|
|
26 |
3. Altered versions must be plainly marked as such, and must not be |
3. Altered versions must be plainly marked as such, and must not be |
27 |
misrepresented as being the original software. |
misrepresented as being the original software. |
28 |
|
|
29 |
|
4. If PCRE is embedded in any software that is released under the GNU |
30 |
|
General Purpose Licence (GPL), then the terms of that licence shall |
31 |
|
supersede any condition above with which it is incompatible. |
32 |
----------------------------------------------------------------------------- |
----------------------------------------------------------------------------- |
33 |
*/ |
*/ |
34 |
|
|
35 |
/* This header contains definitions that are shared between the different |
/* This header contains definitions that are shared between the different |
36 |
modules, but which are not relevant to the outside. */ |
modules, but which are not relevant to the outside. */ |
37 |
|
|
38 |
|
/* Get the definitions provided by running "configure" */ |
39 |
|
|
40 |
|
#include "config.h" |
41 |
|
|
42 |
/* To cope with SunOS4 and other systems that lack memmove() but have bcopy(), |
/* To cope with SunOS4 and other systems that lack memmove() but have bcopy(), |
43 |
define a macro for memmove() if USE_BCOPY is defined. */ |
define a macro for memmove() if HAVE_MEMMOVE is false, provided that HAVE_BCOPY |
44 |
|
is set. Otherwise, include an emulating function for those systems that have |
45 |
|
neither (there some non-Unix environments where this is the case). This assumes |
46 |
|
that all calls to memmove are moving strings upwards in store, which is the |
47 |
|
case in PCRE. */ |
48 |
|
|
49 |
#ifdef USE_BCOPY |
#if ! HAVE_MEMMOVE |
50 |
#undef memmove /* some systems may have a macro */ |
#undef memmove /* some systems may have a macro */ |
51 |
|
#if HAVE_BCOPY |
52 |
#define memmove(a, b, c) bcopy(b, a, c) |
#define memmove(a, b, c) bcopy(b, a, c) |
53 |
|
#else |
54 |
|
void * |
55 |
|
pcre_memmove(unsigned char *dest, const unsigned char *src, size_t n) |
56 |
|
{ |
57 |
|
int i; |
58 |
|
dest += n; |
59 |
|
src += n; |
60 |
|
for (i = 0; i < n; ++i) *(--dest) = *(--src); |
61 |
|
} |
62 |
|
#define memmove(a, b, c) pcre_memmove(a, b, c) |
63 |
|
#endif |
64 |
#endif |
#endif |
65 |
|
|
66 |
/* Standard C headers plus the external interface definition */ |
/* Standard C headers plus the external interface definition */ |
84 |
|
|
85 |
#define PCRE_IMS (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL) |
#define PCRE_IMS (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL) |
86 |
|
|
87 |
/* Private options flags start at the most significant end of the two bytes. |
/* Private options flags start at the most significant end of the four bytes, |
88 |
The public options defined in pcre.h start at the least significant end. Make |
but skip the top bit so we can use ints for convenience without getting tangled |
89 |
sure they don't overlap! */ |
with negative values. The public options defined in pcre.h start at the least |
90 |
|
significant end. Make sure they don't overlap, though now that we have expanded |
91 |
#define PCRE_FIRSTSET 0x8000 /* first_char is set */ |
to four bytes there is plenty of space. */ |
92 |
#define PCRE_STARTLINE 0x4000 /* start after \n for multiline */ |
|
93 |
#define PCRE_INGROUP 0x2000 /* compiling inside a group */ |
#define PCRE_FIRSTSET 0x40000000 /* first_char is set */ |
94 |
|
#define PCRE_REQCHSET 0x20000000 /* req_char is set */ |
95 |
|
#define PCRE_STARTLINE 0x10000000 /* start after \n for multiline */ |
96 |
|
#define PCRE_INGROUP 0x08000000 /* compiling inside a group */ |
97 |
|
#define PCRE_ICHANGED 0x04000000 /* i option changes within regex */ |
98 |
|
|
99 |
/* Options for the "extra" block produced by pcre_study(). */ |
/* Options for the "extra" block produced by pcre_study(). */ |
100 |
|
|
105 |
|
|
106 |
#define PUBLIC_OPTIONS \ |
#define PUBLIC_OPTIONS \ |
107 |
(PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \ |
(PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \ |
108 |
PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY) |
PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY|PCRE_UTF8) |
109 |
|
|
110 |
#define PUBLIC_EXEC_OPTIONS (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL) |
#define PUBLIC_EXEC_OPTIONS \ |
111 |
|
(PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY) |
112 |
|
|
113 |
#define PUBLIC_STUDY_OPTIONS 0 /* None defined */ |
#define PUBLIC_STUDY_OPTIONS 0 /* None defined */ |
114 |
|
|
115 |
/* Magic number to provide a small check against being handed junk. */ |
/* Magic number to provide a small check against being handed junk. */ |
116 |
|
|
117 |
#define MAGIC_NUMBER 0x50435245 /* 'PCRE' */ |
#define MAGIC_NUMBER 0x50435245UL /* 'PCRE' */ |
118 |
|
|
119 |
/* Miscellaneous definitions */ |
/* Miscellaneous definitions */ |
120 |
|
|
204 |
|
|
205 |
OP_CLASS, /* Match a character class */ |
OP_CLASS, /* Match a character class */ |
206 |
OP_REF, /* Match a back reference */ |
OP_REF, /* Match a back reference */ |
207 |
|
OP_RECURSE, /* Match this pattern recursively */ |
208 |
|
|
209 |
OP_ALT, /* Start of alternation */ |
OP_ALT, /* Start of alternation */ |
210 |
OP_KET, /* End of group that doesn't have an unbounded repeat */ |
OP_KET, /* End of group that doesn't have an unbounded repeat */ |
271 |
#define ERR26 "malformed number after (?(" |
#define ERR26 "malformed number after (?(" |
272 |
#define ERR27 "conditional group contains more than two branches" |
#define ERR27 "conditional group contains more than two branches" |
273 |
#define ERR28 "assertion expected after (?(" |
#define ERR28 "assertion expected after (?(" |
274 |
|
#define ERR29 "(?p must be followed by )" |
275 |
|
#define ERR30 "unknown POSIX class name" |
276 |
|
#define ERR31 "POSIX collating elements are not supported" |
277 |
|
#define ERR32 "this version of PCRE is not compiled with PCRE_UTF8 support" |
278 |
|
#define ERR33 "characters with values > 255 are not yet supported in classes" |
279 |
|
#define ERR34 "character value in \\x{...} sequence is too large" |
280 |
|
|
281 |
/* All character handling must be done as unsigned characters. Otherwise there |
/* All character handling must be done as unsigned characters. Otherwise there |
282 |
are problems with top-bit-set characters and functions such as isspace(). |
are problems with top-bit-set characters and functions such as isspace(). |
291 |
runs on as long as necessary after the end. */ |
runs on as long as necessary after the end. */ |
292 |
|
|
293 |
typedef struct real_pcre { |
typedef struct real_pcre { |
294 |
unsigned int magic_number; |
unsigned long int magic_number; |
295 |
|
size_t size; |
296 |
const unsigned char *tables; |
const unsigned char *tables; |
297 |
unsigned short int options; |
unsigned long int options; |
298 |
unsigned char top_bracket; |
uschar top_bracket; |
299 |
unsigned char top_backref; |
uschar top_backref; |
300 |
unsigned char first_char; |
uschar first_char; |
301 |
unsigned char code[1]; |
uschar req_char; |
302 |
|
uschar code[1]; |
303 |
} real_pcre; |
} real_pcre; |
304 |
|
|
305 |
/* The real format of the extra block returned by pcre_study(). */ |
/* The real format of the extra block returned by pcre_study(). */ |
306 |
|
|
307 |
typedef struct real_pcre_extra { |
typedef struct real_pcre_extra { |
308 |
unsigned char options; |
uschar options; |
309 |
unsigned char start_bits[32]; |
uschar start_bits[32]; |
310 |
} real_pcre_extra; |
} real_pcre_extra; |
311 |
|
|
312 |
|
|
315 |
|
|
316 |
typedef struct compile_data { |
typedef struct compile_data { |
317 |
const uschar *lcc; /* Points to lower casing table */ |
const uschar *lcc; /* Points to lower casing table */ |
318 |
const uschar *fcc; /* Points to case-flippint table */ |
const uschar *fcc; /* Points to case-flipping table */ |
319 |
const uschar *cbits; /* Points to character type table */ |
const uschar *cbits; /* Points to character type table */ |
320 |
const uschar *ctypes; /* Points to table of type maps */ |
const uschar *ctypes; /* Points to table of type maps */ |
321 |
} compile_data; |
} compile_data; |
333 |
BOOL offset_overflow; /* Set if too many extractions */ |
BOOL offset_overflow; /* Set if too many extractions */ |
334 |
BOOL notbol; /* NOTBOL flag */ |
BOOL notbol; /* NOTBOL flag */ |
335 |
BOOL noteol; /* NOTEOL flag */ |
BOOL noteol; /* NOTEOL flag */ |
336 |
|
BOOL utf8; /* UTF8 flag */ |
337 |
BOOL endonly; /* Dollar not before final \n */ |
BOOL endonly; /* Dollar not before final \n */ |
338 |
|
BOOL notempty; /* Empty string match not wanted */ |
339 |
|
const uschar *start_pattern; /* For use when recursing */ |
340 |
const uschar *start_subject; /* Start of the subject string */ |
const uschar *start_subject; /* Start of the subject string */ |
341 |
const uschar *end_subject; /* End of the subject string */ |
const uschar *end_subject; /* End of the subject string */ |
342 |
|
const uschar *start_match; /* Start of this match attempt */ |
343 |
const uschar *end_match_ptr; /* Subject position at end match */ |
const uschar *end_match_ptr; /* Subject position at end match */ |
344 |
int end_offset_top; /* Highwater mark at end of match */ |
int end_offset_top; /* Highwater mark at end of match */ |
345 |
} match_data; |
} match_data; |
346 |
|
|
347 |
/* Bit definitions for entries in the pcre_ctypes table. */ |
/* Bit definitions for entries in the pcre_ctypes table. */ |
354 |
#define ctype_meta 0x80 /* regexp meta char or zero (end pattern) */ |
#define ctype_meta 0x80 /* regexp meta char or zero (end pattern) */ |
355 |
|
|
356 |
/* Offsets for the bitmap tables in pcre_cbits. Each table contains a set |
/* Offsets for the bitmap tables in pcre_cbits. Each table contains a set |
357 |
of bits for a class map. */ |
of bits for a class map. Some classes are built by combining these tables. */ |
358 |
|
|
359 |
#define cbit_digit 0 /* for \d */ |
#define cbit_space 0 /* [:space:] or \s */ |
360 |
#define cbit_word 32 /* for \w */ |
#define cbit_xdigit 32 /* [:xdigit:] */ |
361 |
#define cbit_space 64 /* for \s */ |
#define cbit_digit 64 /* [:digit:] or \d */ |
362 |
#define cbit_length 96 /* Length of the cbits table */ |
#define cbit_upper 96 /* [:upper:] */ |
363 |
|
#define cbit_lower 128 /* [:lower:] */ |
364 |
|
#define cbit_word 160 /* [:word:] or \w */ |
365 |
|
#define cbit_graph 192 /* [:graph:] */ |
366 |
|
#define cbit_print 224 /* [:print:] */ |
367 |
|
#define cbit_punct 256 /* [:punct:] */ |
368 |
|
#define cbit_cntrl 288 /* [:cntrl:] */ |
369 |
|
#define cbit_length 320 /* Length of the cbits table */ |
370 |
|
|
371 |
/* Offsets of the various tables from the base tables pointer, and |
/* Offsets of the various tables from the base tables pointer, and |
372 |
total length. */ |
total length. */ |