/[pcre]/code/tags/pcre-4.3/internal.h
ViewVC logotype

Contents of /code/tags/pcre-4.3/internal.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 43 - (hide annotations) (download)
Sat Feb 24 21:39:21 2007 UTC (7 years, 9 months ago) by nigel
Original Path: code/trunk/internal.h
File MIME type: text/plain
File size: 14693 byte(s)
Load pcre-3.0 into code/trunk.

1 nigel 3 /*************************************************
2     * Perl-Compatible Regular Expressions *
3     *************************************************/
4    
5    
6     /* 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
8     the file Tech.Notes for some information on the internals.
9    
10     Written by: Philip Hazel <ph10@cam.ac.uk>
11    
12 nigel 43 Copyright (c) 1997-2000 University of Cambridge
13 nigel 3
14     -----------------------------------------------------------------------------
15     Permission is granted to anyone to use this software for any purpose on any
16     computer system, and to redistribute it freely, subject to the following
17     restrictions:
18    
19     1. This software is distributed in the hope that it will be useful,
20     but WITHOUT ANY WARRANTY; without even the implied warranty of
21     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22    
23     2. The origin of this software must not be misrepresented, either by
24     explicit claim or by omission.
25    
26     3. Altered versions must be plainly marked as such, and must not be
27     misrepresented as being the original software.
28 nigel 29
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 nigel 3 -----------------------------------------------------------------------------
33     */
34    
35     /* This header contains definitions that are shared between the different
36     modules, but which are not relevant to the outside. */
37    
38 nigel 41 /* Get the definitions provided by running "configure" */
39    
40     #include "config.h"
41    
42 nigel 3 /* To cope with SunOS4 and other systems that lack memmove() but have bcopy(),
43 nigel 43 define a macro for memmove() if HAVE_MEMMOVE is false. */
44 nigel 3
45 nigel 43 #if ! HAVE_MEMMOVE
46 nigel 9 #undef memmove /* some systems may have a macro */
47 nigel 3 #define memmove(a, b, c) bcopy(b, a, c)
48     #endif
49    
50     /* Standard C headers plus the external interface definition */
51    
52     #include <ctype.h>
53     #include <limits.h>
54     #include <stddef.h>
55     #include <stdio.h>
56     #include <stdlib.h>
57     #include <string.h>
58     #include "pcre.h"
59    
60 nigel 9 /* In case there is no definition of offsetof() provided - though any proper
61     Standard C system should have one. */
62    
63     #ifndef offsetof
64 nigel 11 #define offsetof(p_type,field) ((size_t)&(((p_type *)0)->field))
65 nigel 9 #endif
66    
67 nigel 23 /* These are the public options that can change during matching. */
68    
69     #define PCRE_IMS (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL)
70    
71 nigel 37 /* Private options flags start at the most significant end of the four bytes,
72     but skip the top bit so we can use ints for convenience without getting tangled
73     with negative values. The public options defined in pcre.h start at the least
74     significant end. Make sure they don't overlap, though now that we have expanded
75     to four bytes there is plenty of space. */
76 nigel 3
77 nigel 37 #define PCRE_FIRSTSET 0x40000000 /* first_char is set */
78     #define PCRE_REQCHSET 0x20000000 /* req_char is set */
79     #define PCRE_STARTLINE 0x10000000 /* start after \n for multiline */
80     #define PCRE_INGROUP 0x08000000 /* compiling inside a group */
81     #define PCRE_ICHANGED 0x04000000 /* i option changes within regex */
82 nigel 3
83     /* Options for the "extra" block produced by pcre_study(). */
84    
85 nigel 23 #define PCRE_STUDY_MAPPED 0x01 /* a map of starting chars exists */
86 nigel 3
87 nigel 23 /* Masks for identifying the public options which are permitted at compile
88     time, run time or study time, respectively. */
89 nigel 3
90     #define PUBLIC_OPTIONS \
91     (PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \
92 nigel 19 PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY)
93 nigel 3
94 nigel 37 #define PUBLIC_EXEC_OPTIONS \
95     (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY)
96 nigel 3
97 nigel 23 #define PUBLIC_STUDY_OPTIONS 0 /* None defined */
98 nigel 3
99     /* Magic number to provide a small check against being handed junk. */
100    
101 nigel 33 #define MAGIC_NUMBER 0x50435245UL /* 'PCRE' */
102 nigel 3
103     /* Miscellaneous definitions */
104    
105     typedef int BOOL;
106    
107     #define FALSE 0
108     #define TRUE 1
109    
110     /* These are escaped items that aren't just an encoding of a particular data
111     value such as \n. They must have non-zero values, as check_escape() returns
112     their negation. Also, they must appear in the same order as in the opcode
113 nigel 23 definitions below, up to ESC_z. The final one must be ESC_REF as subsequent
114 nigel 3 values are used for \1, \2, \3, etc. There is a test in the code for an escape
115     greater than ESC_b and less than ESC_X to detect the types that may be
116     repeated. If any new escapes are put in-between that don't consume a character,
117     that code will have to change. */
118    
119     enum { ESC_A = 1, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s, ESC_W, ESC_w,
120 nigel 23 ESC_Z, ESC_z, ESC_REF };
121 nigel 3
122     /* Opcode table: OP_BRA must be last, as all values >= it are used for brackets
123     that extract substrings. Starting from 1 (i.e. after OP_END), the values up to
124 nigel 7 OP_EOD must correspond in order to the list of escapes immediately above. */
125 nigel 3
126     enum {
127     OP_END, /* End of pattern */
128    
129     /* Values corresponding to backslashed metacharacters */
130    
131     OP_SOD, /* Start of data: \A */
132     OP_NOT_WORD_BOUNDARY, /* \B */
133     OP_WORD_BOUNDARY, /* \b */
134     OP_NOT_DIGIT, /* \D */
135     OP_DIGIT, /* \d */
136     OP_NOT_WHITESPACE, /* \S */
137     OP_WHITESPACE, /* \s */
138     OP_NOT_WORDCHAR, /* \W */
139     OP_WORDCHAR, /* \w */
140 nigel 23 OP_EODN, /* End of data or \n at end of data: \Z. */
141     OP_EOD, /* End of data: \z */
142 nigel 3
143 nigel 23 OP_OPT, /* Set runtime options */
144 nigel 3 OP_CIRC, /* Start of line - varies with multiline switch */
145     OP_DOLL, /* End of line - varies with multiline switch */
146     OP_ANY, /* Match any character */
147     OP_CHARS, /* Match string of characters */
148     OP_NOT, /* Match anything but the following char */
149    
150     OP_STAR, /* The maximizing and minimizing versions of */
151     OP_MINSTAR, /* all these opcodes must come in pairs, with */
152     OP_PLUS, /* the minimizing one second. */
153     OP_MINPLUS, /* This first set applies to single characters */
154     OP_QUERY,
155     OP_MINQUERY,
156     OP_UPTO, /* From 0 to n matches */
157     OP_MINUPTO,
158     OP_EXACT, /* Exactly n matches */
159    
160     OP_NOTSTAR, /* The maximizing and minimizing versions of */
161     OP_NOTMINSTAR, /* all these opcodes must come in pairs, with */
162     OP_NOTPLUS, /* the minimizing one second. */
163     OP_NOTMINPLUS, /* This first set applies to "not" single characters */
164     OP_NOTQUERY,
165     OP_NOTMINQUERY,
166     OP_NOTUPTO, /* From 0 to n matches */
167     OP_NOTMINUPTO,
168     OP_NOTEXACT, /* Exactly n matches */
169    
170     OP_TYPESTAR, /* The maximizing and minimizing versions of */
171     OP_TYPEMINSTAR, /* all these opcodes must come in pairs, with */
172     OP_TYPEPLUS, /* the minimizing one second. These codes must */
173     OP_TYPEMINPLUS, /* be in exactly the same order as those above. */
174     OP_TYPEQUERY, /* This set applies to character types such as \d */
175     OP_TYPEMINQUERY,
176     OP_TYPEUPTO, /* From 0 to n matches */
177     OP_TYPEMINUPTO,
178     OP_TYPEEXACT, /* Exactly n matches */
179    
180     OP_CRSTAR, /* The maximizing and minimizing versions of */
181     OP_CRMINSTAR, /* all these opcodes must come in pairs, with */
182     OP_CRPLUS, /* the minimizing one second. These codes must */
183     OP_CRMINPLUS, /* be in exactly the same order as those above. */
184     OP_CRQUERY, /* These are for character classes and back refs */
185     OP_CRMINQUERY,
186     OP_CRRANGE, /* These are different to the three seta above. */
187     OP_CRMINRANGE,
188    
189     OP_CLASS, /* Match a character class */
190     OP_REF, /* Match a back reference */
191 nigel 43 OP_RECURSE, /* Match this pattern recursively */
192 nigel 3
193     OP_ALT, /* Start of alternation */
194     OP_KET, /* End of group that doesn't have an unbounded repeat */
195     OP_KETRMAX, /* These two must remain together and in this */
196     OP_KETRMIN, /* order. They are for groups the repeat for ever. */
197    
198 nigel 23 /* The assertions must come before ONCE and COND */
199    
200     OP_ASSERT, /* Positive lookahead */
201     OP_ASSERT_NOT, /* Negative lookahead */
202     OP_ASSERTBACK, /* Positive lookbehind */
203     OP_ASSERTBACK_NOT, /* Negative lookbehind */
204     OP_REVERSE, /* Move pointer back - used in lookbehind assertions */
205    
206     /* ONCE and COND must come after the assertions, with ONCE first, as there's
207     a test for >= ONCE for a subpattern that isn't an assertion. */
208    
209 nigel 3 OP_ONCE, /* Once matched, don't back up into the subpattern */
210 nigel 23 OP_COND, /* Conditional group */
211     OP_CREF, /* Used to hold an extraction string number */
212 nigel 3
213     OP_BRAZERO, /* These two must remain together and in this */
214     OP_BRAMINZERO, /* order. */
215    
216     OP_BRA /* This and greater values are used for brackets that
217     extract substrings. */
218     };
219    
220     /* The highest extraction number. This is limited by the number of opcodes
221     left after OP_BRA, i.e. 255 - OP_BRA. We actually set it somewhat lower. */
222    
223     #define EXTRACT_MAX 99
224    
225     /* The texts of compile-time error messages are defined as macros here so that
226     they can be accessed by the POSIX wrapper and converted into error codes. Yes,
227     I could have used error codes in the first place, but didn't feel like changing
228     just to accommodate the POSIX wrapper. */
229    
230     #define ERR1 "\\ at end of pattern"
231     #define ERR2 "\\c at end of pattern"
232     #define ERR3 "unrecognized character follows \\"
233     #define ERR4 "numbers out of order in {} quantifier"
234     #define ERR5 "number too big in {} quantifier"
235     #define ERR6 "missing terminating ] for character class"
236     #define ERR7 "invalid escape sequence in character class"
237     #define ERR8 "range out of order in character class"
238     #define ERR9 "nothing to repeat"
239     #define ERR10 "operand of unlimited repeat could match the empty string"
240     #define ERR11 "internal error: unexpected repeat"
241     #define ERR12 "unrecognized character after (?"
242     #define ERR13 "too many capturing parenthesized sub-patterns"
243     #define ERR14 "missing )"
244     #define ERR15 "back reference to non-existent subpattern"
245     #define ERR16 "erroffset passed as NULL"
246     #define ERR17 "unknown option bit(s) set"
247     #define ERR18 "missing ) after comment"
248     #define ERR19 "too many sets of parentheses"
249     #define ERR20 "regular expression too large"
250     #define ERR21 "failed to get memory"
251 nigel 23 #define ERR22 "unmatched parentheses"
252 nigel 3 #define ERR23 "internal error: code overflow"
253 nigel 23 #define ERR24 "unrecognized character after (?<"
254     #define ERR25 "lookbehind assertion is not fixed length"
255     #define ERR26 "malformed number after (?("
256     #define ERR27 "conditional group contains more than two branches"
257     #define ERR28 "assertion expected after (?("
258 nigel 43 #define ERR29 "(?p must be followed by )"
259     #define ERR30 "unknown POSIX class name"
260     #define ERR31 "POSIX collating elements are not supported"
261 nigel 3
262     /* All character handling must be done as unsigned characters. Otherwise there
263     are problems with top-bit-set characters and functions such as isspace().
264     However, we leave the interface to the outside world as char *, because that
265     should make things easier for callers. We define a short type for unsigned char
266     to save lots of typing. I tried "uchar", but it causes problems on Digital
267     Unix, where it is defined in sys/types, so use "uschar" instead. */
268    
269     typedef unsigned char uschar;
270    
271     /* The real format of the start of the pcre block; the actual code vector
272     runs on as long as necessary after the end. */
273    
274     typedef struct real_pcre {
275 nigel 33 unsigned long int magic_number;
276 nigel 43 size_t size;
277 nigel 25 const unsigned char *tables;
278 nigel 37 unsigned long int options;
279     uschar top_bracket;
280     uschar top_backref;
281     uschar first_char;
282     uschar req_char;
283     uschar code[1];
284 nigel 3 } real_pcre;
285    
286     /* The real format of the extra block returned by pcre_study(). */
287    
288     typedef struct real_pcre_extra {
289 nigel 37 uschar options;
290     uschar start_bits[32];
291 nigel 3 } real_pcre_extra;
292    
293    
294 nigel 25 /* Structure for passing "static" information around between the functions
295     doing the compiling, so that they are thread-safe. */
296 nigel 3
297 nigel 25 typedef struct compile_data {
298     const uschar *lcc; /* Points to lower casing table */
299 nigel 37 const uschar *fcc; /* Points to case-flipping table */
300 nigel 25 const uschar *cbits; /* Points to character type table */
301     const uschar *ctypes; /* Points to table of type maps */
302     } compile_data;
303 nigel 3
304 nigel 25 /* Structure for passing "static" information around between the functions
305     doing the matching, so that they are thread-safe. */
306    
307     typedef struct match_data {
308     int errorcode; /* As it says */
309     int *offset_vector; /* Offset vector */
310     int offset_end; /* One past the end */
311     int offset_max; /* The maximum usable for return data */
312     const uschar *lcc; /* Points to lower casing table */
313     const uschar *ctypes; /* Points to table of type maps */
314     BOOL offset_overflow; /* Set if too many extractions */
315     BOOL notbol; /* NOTBOL flag */
316     BOOL noteol; /* NOTEOL flag */
317     BOOL endonly; /* Dollar not before final \n */
318 nigel 37 BOOL notempty; /* Empty string match not wanted */
319 nigel 43 const uschar *start_pattern; /* For use when recursing */
320 nigel 25 const uschar *start_subject; /* Start of the subject string */
321     const uschar *end_subject; /* End of the subject string */
322 nigel 37 const uschar *start_match; /* Start of this match attempt */
323 nigel 25 const uschar *end_match_ptr; /* Subject position at end match */
324 nigel 43 int end_offset_top; /* Highwater mark at end of match */
325 nigel 25 } match_data;
326    
327     /* Bit definitions for entries in the pcre_ctypes table. */
328    
329 nigel 3 #define ctype_space 0x01
330     #define ctype_letter 0x02
331     #define ctype_digit 0x04
332     #define ctype_xdigit 0x08
333     #define ctype_word 0x10 /* alphameric or '_' */
334     #define ctype_meta 0x80 /* regexp meta char or zero (end pattern) */
335    
336 nigel 25 /* Offsets for the bitmap tables in pcre_cbits. Each table contains a set
337 nigel 43 of bits for a class map. Some classes are built by combining these tables. */
338 nigel 3
339 nigel 43 #define cbit_space 0 /* [:space:] or \s */
340     #define cbit_xdigit 32 /* [:xdigit:] */
341     #define cbit_digit 64 /* [:digit:] or \d */
342     #define cbit_upper 96 /* [:upper:] */
343     #define cbit_lower 128 /* [:lower:] */
344     #define cbit_word 160 /* [:word:] or \w */
345     #define cbit_graph 192 /* [:graph:] */
346     #define cbit_print 224 /* [:print:] */
347     #define cbit_punct 256 /* [:punct:] */
348     #define cbit_cntrl 288 /* [:cntrl:] */
349     #define cbit_length 320 /* Length of the cbits table */
350 nigel 3
351 nigel 25 /* Offsets of the various tables from the base tables pointer, and
352     total length. */
353    
354     #define lcc_offset 0
355     #define fcc_offset 256
356     #define cbits_offset 512
357     #define ctypes_offset (cbits_offset + cbit_length)
358     #define tables_length (ctypes_offset + 256)
359    
360 nigel 3 /* End of internal.h */

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12