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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (show annotations) (download)
Sat Feb 24 21:38:41 2007 UTC (7 years, 6 months ago) by nigel
Original Path: code/trunk/internal.h
File MIME type: text/plain
File size: 11598 byte(s)
Load pcre-2.00 into code/trunk.

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

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12