ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/libio/string/pcre_internal.h
Revision: 59
Committed: Mon Oct 3 15:11:57 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-chdr
File size: 32953 byte(s)
Log Message:
- move non-irc related sources to /libio
- todo: make it independent of the rest of code

File Contents

# User Rev Content
1 adx 59 /* $Id: pcre_internal.h 33 2005-10-02 20:50:00Z knight $ */
2    
3     /*************************************************
4     * Perl-Compatible Regular Expressions *
5     *************************************************/
6    
7    
8     /* PCRE is a library of functions to support regular expressions whose syntax
9     and semantics are as close as possible to those of the Perl 5 language.
10    
11     Written by Philip Hazel
12     Copyright (c) 1997-2005 University of Cambridge
13    
14     -----------------------------------------------------------------------------
15     Redistribution and use in source and binary forms, with or without
16     modification, are permitted provided that the following conditions are met:
17    
18     * Redistributions of source code must retain the above copyright notice,
19     this list of conditions and the following disclaimer.
20    
21     * Redistributions in binary form must reproduce the above copyright
22     notice, this list of conditions and the following disclaimer in the
23     documentation and/or other materials provided with the distribution.
24    
25     * Neither the name of the University of Cambridge nor the names of its
26     contributors may be used to endorse or promote products derived from
27     this software without specific prior written permission.
28    
29     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30     AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32     ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
33     LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39     POSSIBILITY OF SUCH DAMAGE.
40     -----------------------------------------------------------------------------
41     */
42    
43     /* This header contains definitions that are shared between the different
44     modules, but which are not relevant to the exported API. This includes some
45     functions whose names all begin with "_pcre_". */
46    
47    
48     /* Define DEBUG to get debugging output on stdout. */
49    
50     /****
51     #define DEBUG
52     ****/
53    
54     /* Use a macro for debugging printing, 'cause that eliminates the use of #ifdef
55     inline, and there are *still* stupid compilers about that don't like indented
56     pre-processor statements, or at least there were when I first wrote this. After
57     all, it had only been about 10 years then... */
58    
59     #ifdef DEBUG
60     #define DPRINTF(p) printf p
61     #else
62     #define DPRINTF(p) /*nothing*/
63     #endif
64    
65    
66     /* Standard C headers plus the external interface definition. The only time
67     setjmp and stdarg are used is when NO_RECURSE is set. */
68    
69     #include <ctype.h>
70     #include <limits.h>
71     #include <setjmp.h>
72     #include <stdarg.h>
73     #include <stddef.h>
74     #include <stdio.h>
75     #include <stdlib.h>
76     #include <string.h>
77    
78     #ifndef PCRE_SPY
79     #define PCRE_DEFINITION /* Win32 __declspec(export) trigger for .dll */
80     #endif
81    
82     /* If you are compiling for a system that needs some magic to be inserted
83     before the definition of an exported function, define this macro to contain the
84     relevant magic. It apears at the start of every exported function. */
85    
86     #define EXPORT
87    
88     /* The value of NEWLINE determines the newline character. The default is to
89     leave it up to the compiler, but some sites want to force a particular value.
90     On Unix systems, "configure" can be used to override this default. */
91    
92     #ifndef NEWLINE
93     #define NEWLINE '\n'
94     #endif
95    
96     /* The value of LINK_SIZE determines the number of bytes used to store
97     links as offsets within the compiled regex. The default is 2, which allows for
98     compiled patterns up to 64K long. This covers the vast majority of cases.
99     However, PCRE can also be compiled to use 3 or 4 bytes instead. This allows for
100     longer patterns in extreme cases. On Unix systems, "configure" can be used to
101     override this default. */
102    
103     #ifndef LINK_SIZE
104     #define LINK_SIZE 2
105     #endif
106    
107     /* The value of MATCH_LIMIT determines the default number of times the match()
108     function can be called during a single execution of pcre_exec(). (There is a
109     runtime method of setting a different limit.) The limit exists in order to
110     catch runaway regular expressions that take for ever to determine that they do
111     not match. The default is set very large so that it does not accidentally catch
112     legitimate cases. On Unix systems, "configure" can be used to override this
113     default default. */
114    
115     #ifndef MATCH_LIMIT
116     #define MATCH_LIMIT 10000000
117     #endif
118    
119     /* PCRE uses recursive function calls to handle backtracking while matching.
120     This can sometimes be a problem on systems that have stacks of limited size.
121     Define NO_RECURSE to get a version that doesn't use recursion in the match()
122     function; instead it creates its own stack by steam using pcre_recurse_malloc
123     to get memory. For more detail, see comments and other stuff just above the
124     match() function. On Unix systems, "configure" can be used to set this in the
125     Makefile (use --disable-stack-for-recursion). */
126    
127     /* #define NO_RECURSE */
128    
129     /* We need to have types that specify unsigned 16-bit and 32-bit integers. We
130     cannot determine these outside the compilation (e.g. by running a program as
131     part of "configure") because PCRE is often cross-compiled for use on other
132     systems. Instead we make use of the maximum sizes that are available at
133     preprocessor time in standard C environments. */
134    
135     #if USHRT_MAX == 65535
136     typedef unsigned short pcre_uint16;
137     #elif UINT_MAX == 65535
138     typedef unsigned int pcre_uint16;
139     #else
140     #error Cannot determine a type for 16-bit unsigned integers
141     #endif
142    
143     #if UINT_MAX == 4294967295
144     typedef unsigned int pcre_uint32;
145     #elif ULONG_MAX == 4294967295
146     typedef unsigned long int pcre_uint32;
147     #else
148     #error Cannot determine a type for 32-bit unsigned integers
149     #endif
150    
151     /* All character handling must be done as unsigned characters. Otherwise there
152     are problems with top-bit-set characters and functions such as isspace().
153     However, we leave the interface to the outside world as char *, because that
154     should make things easier for callers. We define a short type for unsigned char
155     to save lots of typing. I tried "uchar", but it causes problems on Digital
156     Unix, where it is defined in sys/types, so use "uschar" instead. */
157    
158     typedef unsigned char uschar;
159    
160     /* Include the public PCRE header */
161    
162     #include "pcre.h"
163    
164     /* PCRE keeps offsets in its compiled code as 2-byte quantities (always stored
165     in big-endian order) by default. These are used, for example, to link from the
166     start of a subpattern to its alternatives and its end. The use of 2 bytes per
167     offset limits the size of the compiled regex to around 64K, which is big enough
168     for almost everybody. However, I received a request for an even bigger limit.
169     For this reason, and also to make the code easier to maintain, the storing and
170     loading of offsets from the byte string is now handled by the macros that are
171     defined here.
172    
173     The macros are controlled by the value of LINK_SIZE. This defaults to 2 in
174     the config.h file, but can be overridden by using -D on the command line. This
175     is automated on Unix systems via the "configure" command. */
176    
177     #if LINK_SIZE == 2
178    
179     #define PUT(a,n,d) \
180     (a[n] = (d) >> 8), \
181     (a[(n)+1] = (d) & 255)
182    
183     #define GET(a,n) \
184     (((a)[n] << 8) | (a)[(n)+1])
185    
186     #define MAX_PATTERN_SIZE (1 << 16)
187    
188    
189     #elif LINK_SIZE == 3
190    
191     #define PUT(a,n,d) \
192     (a[n] = (d) >> 16), \
193     (a[(n)+1] = (d) >> 8), \
194     (a[(n)+2] = (d) & 255)
195    
196     #define GET(a,n) \
197     (((a)[n] << 16) | ((a)[(n)+1] << 8) | (a)[(n)+2])
198    
199     #define MAX_PATTERN_SIZE (1 << 24)
200    
201    
202     #elif LINK_SIZE == 4
203    
204     #define PUT(a,n,d) \
205     (a[n] = (d) >> 24), \
206     (a[(n)+1] = (d) >> 16), \
207     (a[(n)+2] = (d) >> 8), \
208     (a[(n)+3] = (d) & 255)
209    
210     #define GET(a,n) \
211     (((a)[n] << 24) | ((a)[(n)+1] << 16) | ((a)[(n)+2] << 8) | (a)[(n)+3])
212    
213     #define MAX_PATTERN_SIZE (1 << 30) /* Keep it positive */
214    
215    
216     #else
217     #error LINK_SIZE must be either 2, 3, or 4
218     #endif
219    
220    
221     /* Convenience macro defined in terms of the others */
222    
223     #define PUTINC(a,n,d) PUT(a,n,d), a += LINK_SIZE
224    
225    
226     /* PCRE uses some other 2-byte quantities that do not change when the size of
227     offsets changes. There are used for repeat counts and for other things such as
228     capturing parenthesis numbers in back references. */
229    
230     #define PUT2(a,n,d) \
231     a[n] = (d) >> 8; \
232     a[(n)+1] = (d) & 255
233    
234     #define GET2(a,n) \
235     (((a)[n] << 8) | (a)[(n)+1])
236    
237     #define PUT2INC(a,n,d) PUT2(a,n,d), a += 2
238    
239    
240     /* When UTF-8 encoding is being used, a character is no longer just a single
241     byte. The macros for character handling generate simple sequences when used in
242     byte-mode, and more complicated ones for UTF-8 characters. */
243    
244     #define GETCHAR(c, eptr) c = *eptr;
245     #define GETCHARTEST(c, eptr) c = *eptr;
246     #define GETCHARINC(c, eptr) c = *eptr++;
247     #define GETCHARINCTEST(c, eptr) c = *eptr++;
248     #define GETCHARLEN(c, eptr, len) c = *eptr;
249     #define BACKCHAR(eptr)
250    
251    
252     /* These are the public options that can change during matching. */
253    
254     #define PCRE_IMS (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL)
255    
256     /* Private options flags start at the most significant end of the four bytes,
257     but skip the top bit so we can use ints for convenience without getting tangled
258     with negative values. The public options defined in pcre.h start at the least
259     significant end. Make sure they don't overlap! */
260    
261     #define PCRE_FIRSTSET 0x40000000 /* first_byte is set */
262     #define PCRE_REQCHSET 0x20000000 /* req_byte is set */
263     #define PCRE_STARTLINE 0x10000000 /* start after \n for multiline */
264     #define PCRE_ICHANGED 0x08000000 /* i option changes within regex */
265     #define PCRE_NOPARTIAL 0x04000000 /* can't use partial with this regex */
266    
267     /* Options for the "extra" block produced by pcre_study(). */
268    
269     #define PCRE_STUDY_MAPPED 0x01 /* a map of starting chars exists */
270    
271     /* Masks for identifying the public options that are permitted at compile
272     time, run time, or study time, respectively. */
273    
274     #define PUBLIC_OPTIONS \
275     (PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \
276     PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY|PCRE_UTF8| \
277     PCRE_NO_AUTO_CAPTURE|PCRE_NO_UTF8_CHECK|PCRE_AUTO_CALLOUT|PCRE_FIRSTLINE)
278    
279     #define PUBLIC_EXEC_OPTIONS \
280     (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK| \
281     PCRE_PARTIAL)
282    
283     #define PUBLIC_DFA_EXEC_OPTIONS \
284     (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY|PCRE_NO_UTF8_CHECK| \
285     PCRE_PARTIAL|PCRE_DFA_SHORTEST|PCRE_DFA_RESTART)
286    
287     #define PUBLIC_STUDY_OPTIONS 0 /* None defined */
288    
289     /* Magic number to provide a small check against being handed junk. Also used
290     to detect whether a pattern was compiled on a host of different endianness. */
291    
292     #define MAGIC_NUMBER 0x50435245UL /* 'PCRE' */
293    
294     /* Negative values for the firstchar and reqchar variables */
295    
296     #define REQ_UNSET (-2)
297     #define REQ_NONE (-1)
298    
299     /* The maximum remaining length of subject we are prepared to search for a
300     req_byte match. */
301    
302     #define REQ_BYTE_MAX 1000
303    
304     /* Flags added to firstbyte or reqbyte; a "non-literal" item is either a
305     variable-length repeat, or a anything other than literal characters. */
306    
307     #define REQ_CASELESS 0x0100 /* indicates caselessness */
308     #define REQ_VARY 0x0200 /* reqbyte followed non-literal item */
309    
310     /* Miscellaneous definitions */
311    
312     typedef int BOOL;
313    
314     #define FALSE 0
315     #define TRUE 1
316    
317     /* Escape items that are just an encoding of a particular data value. Note that
318     ESC_n is defined as yet another macro, which is set to either \n
319     (the default) or \r (which some people want). */
320    
321     #ifndef ESC_e
322     #define ESC_e 27
323     #endif
324    
325     #ifndef ESC_f
326     #define ESC_f '\f'
327     #endif
328    
329     #ifndef ESC_n
330     #define ESC_n NEWLINE
331     #endif
332    
333     #ifndef ESC_r
334     #define ESC_r '\r'
335     #endif
336    
337     /* We can't officially use ESC_t because it is a POSIX reserved identifier
338     (presumably because of all the others like size_t). */
339    
340     #ifndef ESC_tee
341     #define ESC_tee '\t'
342     #endif
343    
344     /* These are escaped items that aren't just an encoding of a particular data
345     value such as \n. They must have non-zero values, as check_escape() returns
346     their negation. Also, they must appear in the same order as in the opcode
347     definitions below, up to ESC_z. There's a dummy for OP_ANY because it
348     corresponds to "." rather than an escape sequence. The final one must be
349     ESC_REF as subsequent values are used for \1, \2, \3, etc. There is are two
350     tests in the code for an escape greater than ESC_b and less than ESC_Z to
351     detect the types that may be repeated. These are the types that consume
352     characters. If any new escapes are put in between that don't consume a
353     character, that code will have to change. */
354    
355     enum { ESC_A = 1, ESC_G, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s, ESC_W,
356     ESC_w, ESC_dum1, ESC_C, ESC_P, ESC_p, ESC_X, ESC_Z, ESC_z, ESC_E,
357     ESC_Q, ESC_REF };
358    
359     /* Flag bits and data types for the extended class (OP_XCLASS) for classes that
360     contain UTF-8 characters with values greater than 255. */
361    
362     #define XCL_NOT 0x01 /* Flag: this is a negative class */
363     #define XCL_MAP 0x02 /* Flag: a 32-byte map is present */
364    
365     #define XCL_END 0 /* Marks end of individual items */
366     #define XCL_SINGLE 1 /* Single item (one multibyte char) follows */
367     #define XCL_RANGE 2 /* A range (two multibyte chars) follows */
368     #define XCL_PROP 3 /* Unicode property (one property code) follows */
369     #define XCL_NOTPROP 4 /* Unicode inverted property (ditto) */
370    
371    
372     /* Opcode table: OP_BRA must be last, as all values >= it are used for brackets
373     that extract substrings. Starting from 1 (i.e. after OP_END), the values up to
374     OP_EOD must correspond in order to the list of escapes immediately above.
375     Note that whenever this list is updated, the two macro definitions that follow
376     must also be updated to match. */
377    
378     enum {
379     OP_END, /* 0 End of pattern */
380    
381     /* Values corresponding to backslashed metacharacters */
382    
383     OP_SOD, /* 1 Start of data: \A */
384     OP_SOM, /* 2 Start of match (subject + offset): \G */
385     OP_NOT_WORD_BOUNDARY, /* 3 \B */
386     OP_WORD_BOUNDARY, /* 4 \b */
387     OP_NOT_DIGIT, /* 5 \D */
388     OP_DIGIT, /* 6 \d */
389     OP_NOT_WHITESPACE, /* 7 \S */
390     OP_WHITESPACE, /* 8 \s */
391     OP_NOT_WORDCHAR, /* 9 \W */
392     OP_WORDCHAR, /* 10 \w */
393     OP_ANY, /* 11 Match any character */
394     OP_ANYBYTE, /* 12 Match any byte (\C); different to OP_ANY for UTF-8 */
395     OP_NOTPROP, /* 13 \P (not Unicode property) */
396     OP_PROP, /* 14 \p (Unicode property) */
397     OP_EXTUNI, /* 15 \X (extended Unicode sequence */
398     OP_EODN, /* 16 End of data or \n at end of data: \Z. */
399     OP_EOD, /* 17 End of data: \z */
400    
401     OP_OPT, /* 18 Set runtime options */
402     OP_CIRC, /* 19 Start of line - varies with multiline switch */
403     OP_DOLL, /* 20 End of line - varies with multiline switch */
404     OP_CHAR, /* 21 Match one character, casefully */
405     OP_CHARNC, /* 22 Match one character, caselessly */
406     OP_NOT, /* 23 Match anything but the following char */
407    
408     OP_STAR, /* 24 The maximizing and minimizing versions of */
409     OP_MINSTAR, /* 25 all these opcodes must come in pairs, with */
410     OP_PLUS, /* 26 the minimizing one second. */
411     OP_MINPLUS, /* 27 This first set applies to single characters */
412     OP_QUERY, /* 28 */
413     OP_MINQUERY, /* 29 */
414     OP_UPTO, /* 30 From 0 to n matches */
415     OP_MINUPTO, /* 31 */
416     OP_EXACT, /* 32 Exactly n matches */
417    
418     OP_NOTSTAR, /* 33 The maximizing and minimizing versions of */
419     OP_NOTMINSTAR, /* 34 all these opcodes must come in pairs, with */
420     OP_NOTPLUS, /* 35 the minimizing one second. */
421     OP_NOTMINPLUS, /* 36 This set applies to "not" single characters */
422     OP_NOTQUERY, /* 37 */
423     OP_NOTMINQUERY, /* 38 */
424     OP_NOTUPTO, /* 39 From 0 to n matches */
425     OP_NOTMINUPTO, /* 40 */
426     OP_NOTEXACT, /* 41 Exactly n matches */
427    
428     OP_TYPESTAR, /* 42 The maximizing and minimizing versions of */
429     OP_TYPEMINSTAR, /* 43 all these opcodes must come in pairs, with */
430     OP_TYPEPLUS, /* 44 the minimizing one second. These codes must */
431     OP_TYPEMINPLUS, /* 45 be in exactly the same order as those above. */
432     OP_TYPEQUERY, /* 46 This set applies to character types such as \d */
433     OP_TYPEMINQUERY, /* 47 */
434     OP_TYPEUPTO, /* 48 From 0 to n matches */
435     OP_TYPEMINUPTO, /* 49 */
436     OP_TYPEEXACT, /* 50 Exactly n matches */
437    
438     OP_CRSTAR, /* 51 The maximizing and minimizing versions of */
439     OP_CRMINSTAR, /* 52 all these opcodes must come in pairs, with */
440     OP_CRPLUS, /* 53 the minimizing one second. These codes must */
441     OP_CRMINPLUS, /* 54 be in exactly the same order as those above. */
442     OP_CRQUERY, /* 55 These are for character classes and back refs */
443     OP_CRMINQUERY, /* 56 */
444     OP_CRRANGE, /* 57 These are different to the three sets above. */
445     OP_CRMINRANGE, /* 58 */
446    
447     OP_CLASS, /* 59 Match a character class, chars < 256 only */
448     OP_NCLASS, /* 60 Same, but the bitmap was created from a negative
449     class - the difference is relevant only when a UTF-8
450     character > 255 is encountered. */
451    
452     OP_XCLASS, /* 61 Extended class for handling UTF-8 chars within the
453     class. This does both positive and negative. */
454    
455     OP_REF, /* 62 Match a back reference */
456     OP_RECURSE, /* 63 Match a numbered subpattern (possibly recursive) */
457     OP_CALLOUT, /* 64 Call out to external function if provided */
458    
459     OP_ALT, /* 65 Start of alternation */
460     OP_KET, /* 66 End of group that doesn't have an unbounded repeat */
461     OP_KETRMAX, /* 67 These two must remain together and in this */
462     OP_KETRMIN, /* 68 order. They are for groups the repeat for ever. */
463    
464     /* The assertions must come before ONCE and COND */
465    
466     OP_ASSERT, /* 69 Positive lookahead */
467     OP_ASSERT_NOT, /* 70 Negative lookahead */
468     OP_ASSERTBACK, /* 71 Positive lookbehind */
469     OP_ASSERTBACK_NOT, /* 72 Negative lookbehind */
470     OP_REVERSE, /* 73 Move pointer back - used in lookbehind assertions */
471    
472     /* ONCE and COND must come after the assertions, with ONCE first, as there's
473     a test for >= ONCE for a subpattern that isn't an assertion. */
474    
475     OP_ONCE, /* 74 Once matched, don't back up into the subpattern */
476     OP_COND, /* 75 Conditional group */
477     OP_CREF, /* 76 Used to hold an extraction string number (cond ref) */
478    
479     OP_BRAZERO, /* 77 These two must remain together and in this */
480     OP_BRAMINZERO, /* 78 order. */
481    
482     OP_BRANUMBER, /* 79 Used for extracting brackets whose number is greater
483     than can fit into an opcode. */
484    
485     OP_BRA /* 80 This and greater values are used for brackets that
486     extract substrings up to EXTRACT_BASIC_MAX. After
487     that, use is made of OP_BRANUMBER. */
488     };
489    
490     /* WARNING WARNING WARNING: There is an implicit assumption in pcre.c and
491     study.c that all opcodes are less than 128 in value. This makes handling UTF-8
492     character sequences easier. */
493    
494     /* The highest extraction number before we have to start using additional
495     bytes. (Originally PCRE didn't have support for extraction counts highter than
496     this number.) The value is limited by the number of opcodes left after OP_BRA,
497     i.e. 255 - OP_BRA. We actually set it a bit lower to leave room for additional
498     opcodes. */
499    
500     #define EXTRACT_BASIC_MAX 100
501    
502    
503     /* This macro defines the length of fixed length operations in the compiled
504     regex. The lengths are used when searching for specific things, and also in the
505     debugging printing of a compiled regex. We use a macro so that it can be
506     defined close to the definitions of the opcodes themselves.
507    
508     As things have been extended, some of these are no longer fixed lenths, but are
509     minima instead. For example, the length of a single-character repeat may vary
510     in UTF-8 mode. The code that uses this table must know about such things. */
511    
512     #define OP_LENGTHS \
513     1, /* End */ \
514     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* \A, \G, \B, \B, \D, \d, \S, \s, \W, \w */ \
515     1, 1, /* Any, Anybyte */ \
516     2, 2, 1, /* NOTPROP, PROP, EXTUNI */ \
517     1, 1, 2, 1, 1, /* \Z, \z, Opt, ^, $ */ \
518     2, /* Char - the minimum length */ \
519     2, /* Charnc - the minimum length */ \
520     2, /* not */ \
521     /* Positive single-char repeats ** These are */ \
522     2, 2, 2, 2, 2, 2, /* *, *?, +, +?, ?, ?? ** minima in */ \
523     4, 4, 4, /* upto, minupto, exact ** UTF-8 mode */ \
524     /* Negative single-char repeats - only for chars < 256 */ \
525     2, 2, 2, 2, 2, 2, /* NOT *, *?, +, +?, ?, ?? */ \
526     4, 4, 4, /* NOT upto, minupto, exact */ \
527     /* Positive type repeats */ \
528     2, 2, 2, 2, 2, 2, /* Type *, *?, +, +?, ?, ?? */ \
529     4, 4, 4, /* Type upto, minupto, exact */ \
530     /* Character class & ref repeats */ \
531     1, 1, 1, 1, 1, 1, /* *, *?, +, +?, ?, ?? */ \
532     5, 5, /* CRRANGE, CRMINRANGE */ \
533     33, /* CLASS */ \
534     33, /* NCLASS */ \
535     0, /* XCLASS - variable length */ \
536     3, /* REF */ \
537     1+LINK_SIZE, /* RECURSE */ \
538     2+2*LINK_SIZE, /* CALLOUT */ \
539     1+LINK_SIZE, /* Alt */ \
540     1+LINK_SIZE, /* Ket */ \
541     1+LINK_SIZE, /* KetRmax */ \
542     1+LINK_SIZE, /* KetRmin */ \
543     1+LINK_SIZE, /* Assert */ \
544     1+LINK_SIZE, /* Assert not */ \
545     1+LINK_SIZE, /* Assert behind */ \
546     1+LINK_SIZE, /* Assert behind not */ \
547     1+LINK_SIZE, /* Reverse */ \
548     1+LINK_SIZE, /* Once */ \
549     1+LINK_SIZE, /* COND */ \
550     3, /* CREF */ \
551     1, 1, /* BRAZERO, BRAMINZERO */ \
552     3, /* BRANUMBER */ \
553     1+LINK_SIZE /* BRA */ \
554    
555    
556     /* A magic value for OP_CREF to indicate the "in recursion" condition. */
557    
558     #define CREF_RECURSE 0xffff
559    
560     /* Error code numbers. They are given names so that they can more easily be
561     tracked. */
562    
563     enum { ERR0, ERR1, ERR2, ERR3, ERR4, ERR5, ERR6, ERR7, ERR8, ERR9,
564     ERR10, ERR11, ERR12, ERR13, ERR14, ERR15, ERR16, ERR17, ERR18, ERR19,
565     ERR20, ERR21, ERR22, ERR23, ERR24, ERR25, ERR26, ERR27, ERR28, ERR29,
566     ERR30, ERR31, ERR32, ERR33, ERR34, ERR35, ERR36, ERR37, ERR38, ERR39,
567     ERR40, ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47 };
568    
569     /* The real format of the start of the pcre block; the index of names and the
570     code vector run on as long as necessary after the end. We store an explicit
571     offset to the name table so that if a regex is compiled on one host, saved, and
572     then run on another where the size of pointers is different, all might still
573     be well. For the case of compiled-on-4 and run-on-8, we include an extra
574     pointer that is always NULL. For future-proofing, a few dummy fields were
575     originally included - even though you can never get this planning right - but
576     there is only one left now.
577    
578     NOTE NOTE NOTE:
579     Because people can now save and re-use compiled patterns, any additions to this
580     structure should be made at the end, and something earlier (e.g. a new
581     flag in the options or one of the dummy fields) should indicate that the new
582     fields are present. Currently PCRE always sets the dummy fields to zero.
583     NOTE NOTE NOTE:
584     */
585    
586     typedef struct real_pcre {
587     pcre_uint32 magic_number;
588     pcre_uint32 size; /* Total that was malloced */
589     pcre_uint32 options;
590     pcre_uint32 dummy1; /* For future use, maybe */
591    
592     pcre_uint16 top_bracket;
593     pcre_uint16 top_backref;
594     pcre_uint16 first_byte;
595     pcre_uint16 req_byte;
596     pcre_uint16 name_table_offset; /* Offset to name table that follows */
597     pcre_uint16 name_entry_size; /* Size of any name items */
598     pcre_uint16 name_count; /* Number of name items */
599     pcre_uint16 ref_count; /* Reference count */
600    
601     const unsigned char *tables; /* Pointer to tables or NULL for std */
602     const unsigned char *nullpad; /* NULL padding */
603     } real_pcre;
604    
605     /* The format of the block used to store data from pcre_study(). The same
606     remark (see NOTE above) about extending this structure applies. */
607    
608     typedef struct pcre_study_data {
609     pcre_uint32 size; /* Total that was malloced */
610     pcre_uint32 options;
611     uschar start_bits[32];
612     } pcre_study_data;
613    
614     /* Structure for passing "static" information around between the functions
615     doing the compiling, so that they are thread-safe. */
616    
617     typedef struct compile_data {
618     const uschar *lcc; /* Points to lower casing table */
619     const uschar *fcc; /* Points to case-flipping table */
620     const uschar *cbits; /* Points to character type table */
621     const uschar *ctypes; /* Points to table of type maps */
622     const uschar *start_code; /* The start of the compiled code */
623     const uschar *start_pattern; /* The start of the pattern */
624     uschar *name_table; /* The name/number table */
625     int names_found; /* Number of entries so far */
626     int name_entry_size; /* Size of each entry */
627     int top_backref; /* Maximum back reference */
628     unsigned int backref_map; /* Bitmap of low back refs */
629     int req_varyopt; /* "After variable item" flag for reqbyte */
630     BOOL nopartial; /* Set TRUE if partial won't work */
631     } compile_data;
632    
633     /* Structure for maintaining a chain of pointers to the currently incomplete
634     branches, for testing for left recursion. */
635    
636     typedef struct branch_chain {
637     struct branch_chain *outer;
638     uschar *current;
639     } branch_chain;
640    
641     /* Structure for items in a linked list that represents an explicit recursive
642     call within the pattern. */
643    
644     typedef struct recursion_info {
645     struct recursion_info *prevrec; /* Previous recursion record (or NULL) */
646     int group_num; /* Number of group that was called */
647     const uschar *after_call; /* "Return value": points after the call in the expr */
648     const uschar *save_start; /* Old value of md->start_match */
649     int *offset_save; /* Pointer to start of saved offsets */
650     int saved_max; /* Number of saved offsets */
651     } recursion_info;
652    
653     /* When compiling in a mode that doesn't use recursive calls to match(),
654     a structure is used to remember local variables on the heap. It is defined in
655     pcre.c, close to the match() function, so that it is easy to keep it in step
656     with any changes of local variable. However, the pointer to the current frame
657     must be saved in some "static" place over a longjmp(). We declare the
658     structure here so that we can put a pointer in the match_data structure.
659     NOTE: This isn't used for a "normal" compilation of pcre. */
660    
661     struct heapframe;
662    
663     /* Structure for passing "static" information around between the functions
664     doing traditional NFA matching, so that they are thread-safe. */
665    
666     typedef struct match_data {
667     unsigned long int match_call_count; /* As it says */
668     unsigned long int match_limit;/* As it says */
669     int *offset_vector; /* Offset vector */
670     int offset_end; /* One past the end */
671     int offset_max; /* The maximum usable for return data */
672     const uschar *lcc; /* Points to lower casing table */
673     const uschar *ctypes; /* Points to table of type maps */
674     BOOL offset_overflow; /* Set if too many extractions */
675     BOOL notbol; /* NOTBOL flag */
676     BOOL noteol; /* NOTEOL flag */
677     BOOL utf8; /* UTF8 flag */
678     BOOL endonly; /* Dollar not before final \n */
679     BOOL notempty; /* Empty string match not wanted */
680     BOOL partial; /* PARTIAL flag */
681     BOOL hitend; /* Hit the end of the subject at some point */
682     const uschar *start_code; /* For use when recursing */
683     const uschar *start_subject; /* Start of the subject string */
684     const uschar *end_subject; /* End of the subject string */
685     const uschar *start_match; /* Start of this match attempt */
686     const uschar *end_match_ptr; /* Subject position at end match */
687     int end_offset_top; /* Highwater mark at end of match */
688     int capture_last; /* Most recent capture number */
689     int start_offset; /* The start offset value */
690     recursion_info *recursive; /* Linked list of recursion data */
691     void *callout_data; /* To pass back to callouts */
692     struct heapframe *thisframe; /* Used only when compiling for no recursion */
693     } match_data;
694    
695     /* A similar structure is used for the same purpose by the DFA matching
696     functions. */
697    
698     typedef struct dfa_match_data {
699     const uschar *start_code; /* Start of the compiled pattern */
700     const uschar *start_subject; /* Start of the subject string */
701     const uschar *end_subject; /* End of subject string */
702     const uschar *tables; /* Character tables */
703     int moptions; /* Match options */
704     int poptions; /* Pattern options */
705     void *callout_data; /* To pass back to callouts */
706     } dfa_match_data;
707    
708     /* Bit definitions for entries in the pcre_ctypes table. */
709    
710     #define ctype_space 0x01
711     #define ctype_letter 0x02
712     #define ctype_digit 0x04
713     #define ctype_xdigit 0x08
714     #define ctype_word 0x10 /* alphameric or '_' */
715     #define ctype_meta 0x80 /* regexp meta char or zero (end pattern) */
716    
717     /* Offsets for the bitmap tables in pcre_cbits. Each table contains a set
718     of bits for a class map. Some classes are built by combining these tables. */
719    
720     #define cbit_space 0 /* [:space:] or \s */
721     #define cbit_xdigit 32 /* [:xdigit:] */
722     #define cbit_digit 64 /* [:digit:] or \d */
723     #define cbit_upper 96 /* [:upper:] */
724     #define cbit_lower 128 /* [:lower:] */
725     #define cbit_word 160 /* [:word:] or \w */
726     #define cbit_graph 192 /* [:graph:] */
727     #define cbit_print 224 /* [:print:] */
728     #define cbit_punct 256 /* [:punct:] */
729     #define cbit_cntrl 288 /* [:cntrl:] */
730     #define cbit_length 320 /* Length of the cbits table */
731    
732     /* Offsets of the various tables from the base tables pointer, and
733     total length. */
734    
735     #define lcc_offset 0
736     #define fcc_offset 256
737     #define cbits_offset 512
738     #define ctypes_offset (cbits_offset + cbit_length)
739     #define tables_length (ctypes_offset + 256)
740    
741     /* Layout of the UCP type table that translates property names into codes for
742     ucp_findchar(). */
743    
744     typedef struct {
745     const char *name;
746     int value;
747     } ucp_type_table;
748    
749    
750     /* Internal shared data tables. These are tables that are used by more than one
751     of the exported public functions. They have to be "external" in the C sense,
752     but are not part of the PCRE public API. The data for these tables is in the
753     pcre_tables.c module. */
754    
755     extern const uschar _pcre_default_tables[];
756    
757    
758     /* Internal shared functions. These are functions that are used by more than
759     one of the exported public functions. They have to be "external" in the C
760     sense, but are not part of the PCRE public API. */
761    
762     extern void _pcre_printint(pcre *, FILE *);
763     extern real_pcre * _pcre_try_flipped(const real_pcre *, real_pcre *,
764     const pcre_study_data *, pcre_study_data *);
765    
766     /* End of pcre_internal.h */

Properties

Name Value
svn:eol-style native
svn:keywords "Id Revision"