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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (hide annotations) (download)
Sat Feb 24 21:38:17 2007 UTC (7 years, 8 months ago) by nigel
Original Path: code/trunk/internal.h
File MIME type: text/plain
File size: 10943 byte(s)
Load pcre-1.04 into code/trunk.

1 nigel 3 /*************************************************
2     * Perl-Compatible Regular Expressions *
3     *************************************************/
4    
5    
6 nigel 11 #define PCRE_VERSION "1.04 22-Dec-1997"
7 nigel 3
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) 1997 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 nigel 9 #undef memmove /* some systems may have a macro */
42 nigel 3 #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 nigel 9 /* In case there is no definition of offsetof() provided - though any proper
57     Standard C system should have one. */
58    
59     #ifndef offsetof
60 nigel 11 #define offsetof(p_type,field) ((size_t)&(((p_type *)0)->field))
61 nigel 9 #endif
62    
63 nigel 3 /* 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 nigel 7 OP_EOD must correspond in order to the list of escapes immediately above. */
120 nigel 3
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 nigel 7 OP_EOD, /* End of data: \Z. */
137 nigel 3
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_REF, /* Match a back reference */
185    
186     OP_ALT, /* Start of alternation */
187     OP_KET, /* End of group that doesn't have an unbounded repeat */
188     OP_KETRMAX, /* These two must remain together and in this */
189     OP_KETRMIN, /* order. They are for groups the repeat for ever. */
190    
191     OP_ASSERT,
192     OP_ASSERT_NOT,
193     OP_ONCE, /* Once matched, don't back up into the subpattern */
194    
195     OP_BRAZERO, /* These two must remain together and in this */
196     OP_BRAMINZERO, /* order. */
197    
198     OP_BRA /* This and greater values are used for brackets that
199     extract substrings. */
200     };
201    
202     /* The highest extraction number. This is limited by the number of opcodes
203     left after OP_BRA, i.e. 255 - OP_BRA. We actually set it somewhat lower. */
204    
205     #define EXTRACT_MAX 99
206    
207     /* The texts of compile-time error messages are defined as macros here so that
208     they can be accessed by the POSIX wrapper and converted into error codes. Yes,
209     I could have used error codes in the first place, but didn't feel like changing
210     just to accommodate the POSIX wrapper. */
211    
212     #define ERR1 "\\ at end of pattern"
213     #define ERR2 "\\c at end of pattern"
214     #define ERR3 "unrecognized character follows \\"
215     #define ERR4 "numbers out of order in {} quantifier"
216     #define ERR5 "number too big in {} quantifier"
217     #define ERR6 "missing terminating ] for character class"
218     #define ERR7 "invalid escape sequence in character class"
219     #define ERR8 "range out of order in character class"
220     #define ERR9 "nothing to repeat"
221     #define ERR10 "operand of unlimited repeat could match the empty string"
222     #define ERR11 "internal error: unexpected repeat"
223     #define ERR12 "unrecognized character after (?"
224     #define ERR13 "too many capturing parenthesized sub-patterns"
225     #define ERR14 "missing )"
226     #define ERR15 "back reference to non-existent subpattern"
227     #define ERR16 "erroffset passed as NULL"
228     #define ERR17 "unknown option bit(s) set"
229     #define ERR18 "missing ) after comment"
230     #define ERR19 "too many sets of parentheses"
231     #define ERR20 "regular expression too large"
232     #define ERR21 "failed to get memory"
233     #define ERR22 "unmatched brackets"
234     #define ERR23 "internal error: code overflow"
235    
236     /* All character handling must be done as unsigned characters. Otherwise there
237     are problems with top-bit-set characters and functions such as isspace().
238     However, we leave the interface to the outside world as char *, because that
239     should make things easier for callers. We define a short type for unsigned char
240     to save lots of typing. I tried "uchar", but it causes problems on Digital
241     Unix, where it is defined in sys/types, so use "uschar" instead. */
242    
243     typedef unsigned char uschar;
244    
245     /* The real format of the start of the pcre block; the actual code vector
246     runs on as long as necessary after the end. */
247    
248     typedef struct real_pcre {
249     unsigned int magic_number;
250     unsigned short int options;
251     unsigned char top_bracket;
252     unsigned char top_backref;
253     unsigned char first_char;
254     unsigned char code[1];
255     } real_pcre;
256    
257     /* The real format of the extra block returned by pcre_study(). */
258    
259     typedef struct real_pcre_extra {
260     unsigned char options;
261     unsigned char start_bits[32];
262     } real_pcre_extra;
263    
264     /* Global tables from chartables.c */
265    
266     extern uschar pcre_lcc[];
267     extern uschar pcre_fcc[];
268     extern uschar pcre_cbits[];
269     extern uschar pcre_ctypes[];
270    
271     /* Bit definitions for entries in pcre_ctypes[]. */
272    
273     #define ctype_space 0x01
274     #define ctype_letter 0x02
275     #define ctype_digit 0x04
276     #define ctype_xdigit 0x08
277     #define ctype_word 0x10 /* alphameric or '_' */
278     #define ctype_meta 0x80 /* regexp meta char or zero (end pattern) */
279    
280     /* Offsets for the bitmap tables */
281    
282     #define cbit_digit 0
283     #define cbit_letter 32
284     #define cbit_word 64
285     #define cbit_space 96
286     #define cbit_length 128 /* Length of the cbits table */
287    
288     /* End of internal.h */

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12