/[pcre]/code/trunk/internal.h
ViewVC logotype

Contents of /code/trunk/internal.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 15 - (show annotations) (download)
Sat Feb 24 21:38:25 2007 UTC (7 years, 6 months ago) by nigel
File MIME type: text/plain
File size: 11016 byte(s)
Load pcre-1.06 into code/trunk.

1 /*************************************************
2 * Perl-Compatible Regular Expressions *
3 *************************************************/
4
5
6 #define PCRE_VERSION "1.06 23-Jan-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 <setjmp.h>
50 #include <stddef.h>
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <string.h>
54 #include "pcre.h"
55
56 /* In case there is no definition of offsetof() provided - though any proper
57 Standard C system should have one. */
58
59 #ifndef offsetof
60 #define offsetof(p_type,field) ((size_t)&(((p_type *)0)->field))
61 #endif
62
63 /* Private options flags start at the most significant end of the two bytes.
64 The public options defined in pcre.h start at the least significant end. Make
65 sure they don't overlap! */
66
67 #define PCRE_FIRSTSET 0x8000 /* first_char is set */
68 #define PCRE_STARTLINE 0x4000 /* start after \n for multiline */
69 #define PCRE_COMPILED_CASELESS 0x2000 /* like it says */
70
71 /* Options for the "extra" block produced by pcre_study(). */
72
73 #define PCRE_STUDY_CASELESS 0x01 /* study was caseless */
74 #define PCRE_STUDY_MAPPED 0x02 /* a map of starting chars exists */
75
76 /* Masks for identifying the public options: all permitted at compile time,
77 only some permitted at run or study time. */
78
79 #define PUBLIC_OPTIONS \
80 (PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \
81 PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA)
82
83 #define PUBLIC_EXEC_OPTIONS \
84 (PCRE_CASELESS|PCRE_ANCHORED|PCRE_MULTILINE|PCRE_NOTBOL|PCRE_NOTEOL| \
85 PCRE_DOTALL|PCRE_DOLLAR_ENDONLY)
86
87 #define PUBLIC_STUDY_OPTIONS (PCRE_CASELESS)
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
111 /* These are not Perl escapes, so can't appear in the */
112 ESC_X, /* simple table-lookup because they must be conditional */
113 /* on PCRE_EXTRA. */
114 ESC_Z,
115 ESC_REF };
116
117 /* Opcode table: OP_BRA must be last, as all values >= it are used for brackets
118 that extract substrings. Starting from 1 (i.e. after OP_END), the values up to
119 OP_EOD must correspond in order to the list of escapes immediately above. */
120
121 enum {
122 OP_END, /* End of pattern */
123
124 /* Values corresponding to backslashed metacharacters */
125
126 OP_SOD, /* Start of data: \A */
127 OP_NOT_WORD_BOUNDARY, /* \B */
128 OP_WORD_BOUNDARY, /* \b */
129 OP_NOT_DIGIT, /* \D */
130 OP_DIGIT, /* \d */
131 OP_NOT_WHITESPACE, /* \S */
132 OP_WHITESPACE, /* \s */
133 OP_NOT_WORDCHAR, /* \W */
134 OP_WORDCHAR, /* \w */
135 OP_CUT, /* The analogue of Prolog's "cut" operation (extension) */
136 OP_EOD, /* End of data: \Z. */
137
138 OP_CIRC, /* Start of line - varies with multiline switch */
139 OP_DOLL, /* End of line - varies with multiline switch */
140 OP_ANY, /* Match any character */
141 OP_CHARS, /* Match string of characters */
142 OP_NOT, /* Match anything but the following char */
143
144 OP_STAR, /* The maximizing and minimizing versions of */
145 OP_MINSTAR, /* all these opcodes must come in pairs, with */
146 OP_PLUS, /* the minimizing one second. */
147 OP_MINPLUS, /* This first set applies to single characters */
148 OP_QUERY,
149 OP_MINQUERY,
150 OP_UPTO, /* From 0 to n matches */
151 OP_MINUPTO,
152 OP_EXACT, /* Exactly n matches */
153
154 OP_NOTSTAR, /* The maximizing and minimizing versions of */
155 OP_NOTMINSTAR, /* all these opcodes must come in pairs, with */
156 OP_NOTPLUS, /* the minimizing one second. */
157 OP_NOTMINPLUS, /* This first set applies to "not" single characters */
158 OP_NOTQUERY,
159 OP_NOTMINQUERY,
160 OP_NOTUPTO, /* From 0 to n matches */
161 OP_NOTMINUPTO,
162 OP_NOTEXACT, /* Exactly n matches */
163
164 OP_TYPESTAR, /* The maximizing and minimizing versions of */
165 OP_TYPEMINSTAR, /* all these opcodes must come in pairs, with */
166 OP_TYPEPLUS, /* the minimizing one second. These codes must */
167 OP_TYPEMINPLUS, /* be in exactly the same order as those above. */
168 OP_TYPEQUERY, /* This set applies to character types such as \d */
169 OP_TYPEMINQUERY,
170 OP_TYPEUPTO, /* From 0 to n matches */
171 OP_TYPEMINUPTO,
172 OP_TYPEEXACT, /* Exactly n matches */
173
174 OP_CRSTAR, /* The maximizing and minimizing versions of */
175 OP_CRMINSTAR, /* all these opcodes must come in pairs, with */
176 OP_CRPLUS, /* the minimizing one second. These codes must */
177 OP_CRMINPLUS, /* be in exactly the same order as those above. */
178 OP_CRQUERY, /* These are for character classes and back refs */
179 OP_CRMINQUERY,
180 OP_CRRANGE, /* These are different to the three seta above. */
181 OP_CRMINRANGE,
182
183 OP_CLASS, /* Match a character class */
184 OP_NEGCLASS, /* Match a character class, specified negatively */
185 OP_REF, /* Match a back reference */
186
187 OP_ALT, /* Start of alternation */
188 OP_KET, /* End of group that doesn't have an unbounded repeat */
189 OP_KETRMAX, /* These two must remain together and in this */
190 OP_KETRMIN, /* order. They are for groups the repeat for ever. */
191
192 OP_ASSERT,
193 OP_ASSERT_NOT,
194 OP_ONCE, /* Once matched, don't back up into the subpattern */
195
196 OP_BRAZERO, /* These two must remain together and in this */
197 OP_BRAMINZERO, /* order. */
198
199 OP_BRA /* This and greater values are used for brackets that
200 extract substrings. */
201 };
202
203 /* The highest extraction number. This is limited by the number of opcodes
204 left after OP_BRA, i.e. 255 - OP_BRA. We actually set it somewhat lower. */
205
206 #define EXTRACT_MAX 99
207
208 /* The texts of compile-time error messages are defined as macros here so that
209 they can be accessed by the POSIX wrapper and converted into error codes. Yes,
210 I could have used error codes in the first place, but didn't feel like changing
211 just to accommodate the POSIX wrapper. */
212
213 #define ERR1 "\\ at end of pattern"
214 #define ERR2 "\\c at end of pattern"
215 #define ERR3 "unrecognized character follows \\"
216 #define ERR4 "numbers out of order in {} quantifier"
217 #define ERR5 "number too big in {} quantifier"
218 #define ERR6 "missing terminating ] for character class"
219 #define ERR7 "invalid escape sequence in character class"
220 #define ERR8 "range out of order in character class"
221 #define ERR9 "nothing to repeat"
222 #define ERR10 "operand of unlimited repeat could match the empty string"
223 #define ERR11 "internal error: unexpected repeat"
224 #define ERR12 "unrecognized character after (?"
225 #define ERR13 "too many capturing parenthesized sub-patterns"
226 #define ERR14 "missing )"
227 #define ERR15 "back reference to non-existent subpattern"
228 #define ERR16 "erroffset passed as NULL"
229 #define ERR17 "unknown option bit(s) set"
230 #define ERR18 "missing ) after comment"
231 #define ERR19 "too many sets of parentheses"
232 #define ERR20 "regular expression too large"
233 #define ERR21 "failed to get memory"
234 #define ERR22 "unmatched brackets"
235 #define ERR23 "internal error: code overflow"
236
237 /* All character handling must be done as unsigned characters. Otherwise there
238 are problems with top-bit-set characters and functions such as isspace().
239 However, we leave the interface to the outside world as char *, because that
240 should make things easier for callers. We define a short type for unsigned char
241 to save lots of typing. I tried "uchar", but it causes problems on Digital
242 Unix, where it is defined in sys/types, so use "uschar" instead. */
243
244 typedef unsigned char uschar;
245
246 /* The real format of the start of the pcre block; the actual code vector
247 runs on as long as necessary after the end. */
248
249 typedef struct real_pcre {
250 unsigned int magic_number;
251 unsigned short int options;
252 unsigned char top_bracket;
253 unsigned char top_backref;
254 unsigned char first_char;
255 unsigned char code[1];
256 } real_pcre;
257
258 /* The real format of the extra block returned by pcre_study(). */
259
260 typedef struct real_pcre_extra {
261 unsigned char options;
262 unsigned char start_bits[32];
263 } real_pcre_extra;
264
265 /* Global tables from chartables.c */
266
267 extern uschar pcre_lcc[];
268 extern uschar pcre_fcc[];
269 extern uschar pcre_cbits[];
270 extern uschar pcre_ctypes[];
271
272 /* Bit definitions for entries in pcre_ctypes[]. */
273
274 #define ctype_space 0x01
275 #define ctype_letter 0x02
276 #define ctype_digit 0x04
277 #define ctype_xdigit 0x08
278 #define ctype_word 0x10 /* alphameric or '_' */
279 #define ctype_meta 0x80 /* regexp meta char or zero (end pattern) */
280
281 /* Offsets for the bitmap tables */
282
283 #define cbit_digit 0
284 #define cbit_letter 32
285 #define cbit_word 64
286 #define cbit_space 96
287 #define cbit_length 128 /* Length of the cbits table */
288
289 /* End of internal.h */

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12