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

Diff of /code/trunk/internal.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 21 by nigel, Sat Feb 24 21:38:37 2007 UTC revision 39 by nigel, Sat Feb 24 21:39:13 2007 UTC
# Line 3  Line 3 
3  *************************************************/  *************************************************/
4    
5    
 #define PCRE_VERSION       "1.09 28-Apr-1998"  
   
   
6  /* This is a library of functions to support regular expressions whose syntax  /* 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  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.  the file Tech.Notes for some information on the internals.
9    
10  Written by: Philip Hazel <ph10@cam.ac.uk>  Written by: Philip Hazel <ph10@cam.ac.uk>
11    
12             Copyright (c) 1998 University of Cambridge             Copyright (c) 1997-1999 University of Cambridge
13    
14  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
15  Permission is granted to anyone to use this software for any purpose on any  Permission is granted to anyone to use this software for any purpose on any
# Line 28  restrictions: Line 25  restrictions:
25    
26  3. Altered versions must be plainly marked as such, and must not be  3. Altered versions must be plainly marked as such, and must not be
27     misrepresented as being the original software.     misrepresented as being the original software.
28    
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  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
33  */  */
34    
# Line 46  define a macro for memmove() if USE_BCOP Line 47  define a macro for memmove() if USE_BCOP
47    
48  #include <ctype.h>  #include <ctype.h>
49  #include <limits.h>  #include <limits.h>
 #include <setjmp.h>  
50  #include <stddef.h>  #include <stddef.h>
51  #include <stdio.h>  #include <stdio.h>
52  #include <stdlib.h>  #include <stdlib.h>
# Line 60  Standard C system should have one. */ Line 60  Standard C system should have one. */
60  #define offsetof(p_type,field) ((size_t)&(((p_type *)0)->field))  #define offsetof(p_type,field) ((size_t)&(((p_type *)0)->field))
61  #endif  #endif
62    
63  /* Private options flags start at the most significant end of the two bytes.  /* These are the public options that can change during matching. */
64  The public options defined in pcre.h start at the least significant end. Make  
65  sure they don't overlap! */  #define PCRE_IMS (PCRE_CASELESS|PCRE_MULTILINE|PCRE_DOTALL)
66    
67  #define PCRE_FIRSTSET           0x8000  /* first_char is set */  /* Private options flags start at the most significant end of the four bytes,
68  #define PCRE_STARTLINE          0x4000  /* start after \n for multiline */  but skip the top bit so we can use ints for convenience without getting tangled
69  #define PCRE_COMPILED_CASELESS  0x2000  /* like it says */  with negative values. The public options defined in pcre.h start at the least
70    significant end. Make sure they don't overlap, though now that we have expanded
71    to four bytes there is plenty of space. */
72    
73    #define PCRE_FIRSTSET      0x40000000  /* first_char is set */
74    #define PCRE_REQCHSET      0x20000000  /* req_char is set */
75    #define PCRE_STARTLINE     0x10000000  /* start after \n for multiline */
76    #define PCRE_INGROUP       0x08000000  /* compiling inside a group */
77    #define PCRE_ICHANGED      0x04000000  /* i option changes within regex */
78    
79  /* Options for the "extra" block produced by pcre_study(). */  /* Options for the "extra" block produced by pcre_study(). */
80    
81  #define PCRE_STUDY_CASELESS 0x01     /* study was caseless */  #define PCRE_STUDY_MAPPED   0x01     /* a map of starting chars exists */
 #define PCRE_STUDY_MAPPED   0x02     /* a map of starting chars exists */  
82    
83  /* Masks for identifying the public options: all permitted at compile time,  /* Masks for identifying the public options which are permitted at compile
84  only some permitted at run or study time. */  time, run time or study time, respectively. */
85    
86  #define PUBLIC_OPTIONS \  #define PUBLIC_OPTIONS \
87    (PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \    (PCRE_CASELESS|PCRE_EXTENDED|PCRE_ANCHORED|PCRE_MULTILINE| \
88     PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY)     PCRE_DOTALL|PCRE_DOLLAR_ENDONLY|PCRE_EXTRA|PCRE_UNGREEDY)
89    
90  #define PUBLIC_EXEC_OPTIONS \  #define PUBLIC_EXEC_OPTIONS \
91    (PCRE_CASELESS|PCRE_ANCHORED|PCRE_MULTILINE|PCRE_NOTBOL|PCRE_NOTEOL| \    (PCRE_ANCHORED|PCRE_NOTBOL|PCRE_NOTEOL|PCRE_NOTEMPTY)
    PCRE_DOTALL|PCRE_DOLLAR_ENDONLY)  
92    
93  #define PUBLIC_STUDY_OPTIONS (PCRE_CASELESS)  #define PUBLIC_STUDY_OPTIONS 0   /* None defined */
94    
95  /* Magic number to provide a small check against being handed junk. */  /* Magic number to provide a small check against being handed junk. */
96    
97  #define MAGIC_NUMBER  0x50435245   /* 'PCRE' */  #define MAGIC_NUMBER  0x50435245UL   /* 'PCRE' */
98    
99  /* Miscellaneous definitions */  /* Miscellaneous definitions */
100    
# Line 100  typedef int BOOL; Line 106  typedef int BOOL;
106  /* These are escaped items that aren't just an encoding of a particular data  /* These are escaped items that aren't just an encoding of a particular data
107  value such as \n. They must have non-zero values, as check_escape() returns  value such as \n. They must have non-zero values, as check_escape() returns
108  their negation. Also, they must appear in the same order as in the opcode  their negation. Also, they must appear in the same order as in the opcode
109  definitions below, up to ESC_Z. The final one must be ESC_REF as subsequent  definitions below, up to ESC_z. The final one must be ESC_REF as subsequent
110  values are used for \1, \2, \3, etc. There is a test in the code for an escape  values are used for \1, \2, \3, etc. There is a test in the code for an escape
111  greater than ESC_b and less than ESC_X to detect the types that may be  greater than ESC_b and less than ESC_X to detect the types that may be
112  repeated. If any new escapes are put in-between that don't consume a character,  repeated. If any new escapes are put in-between that don't consume a character,
113  that code will have to change. */  that code will have to change. */
114    
115  enum { ESC_A = 1, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s, ESC_W, ESC_w,  enum { ESC_A = 1, ESC_B, ESC_b, ESC_D, ESC_d, ESC_S, ESC_s, ESC_W, ESC_w,
116           ESC_Z, ESC_z, ESC_REF };
                     /* These are not Perl escapes, so can't appear in the */  
        ESC_X,       /* simple table-lookup because they must be conditional */  
                     /* on PCRE_EXTRA. */  
        ESC_Z,  
        ESC_REF };  
117    
118  /* Opcode table: OP_BRA must be last, as all values >= it are used for brackets  /* Opcode table: OP_BRA must be last, as all values >= it are used for brackets
119  that extract substrings. Starting from 1 (i.e. after OP_END), the values up to  that extract substrings. Starting from 1 (i.e. after OP_END), the values up to
# Line 132  enum { Line 133  enum {
133    OP_WHITESPACE,         /* \s */    OP_WHITESPACE,         /* \s */
134    OP_NOT_WORDCHAR,       /* \W */    OP_NOT_WORDCHAR,       /* \W */
135    OP_WORDCHAR,           /* \w */    OP_WORDCHAR,           /* \w */
136    OP_CUT,            /* The analogue of Prolog's "cut" operation (extension) */    OP_EODN,           /* End of data or \n at end of data: \Z. */
137    OP_EOD,            /* End of data: \Z. */    OP_EOD,            /* End of data: \z */
138    
139      OP_OPT,            /* Set runtime options */
140    OP_CIRC,           /* Start of line - varies with multiline switch */    OP_CIRC,           /* Start of line - varies with multiline switch */
141    OP_DOLL,           /* End of line - varies with multiline switch */    OP_DOLL,           /* End of line - varies with multiline switch */
142    OP_ANY,            /* Match any character */    OP_ANY,            /* Match any character */
# Line 181  enum { Line 183  enum {
183    OP_CRMINRANGE,    OP_CRMINRANGE,
184    
185    OP_CLASS,          /* Match a character class */    OP_CLASS,          /* Match a character class */
   OP_NEGCLASS,       /* Match a character class, specified negatively */  
186    OP_REF,            /* Match a back reference */    OP_REF,            /* Match a back reference */
187    
188    OP_ALT,            /* Start of alternation */    OP_ALT,            /* Start of alternation */
# Line 189  enum { Line 190  enum {
190    OP_KETRMAX,        /* These two must remain together and in this */    OP_KETRMAX,        /* These two must remain together and in this */
191    OP_KETRMIN,        /* order. They are for groups the repeat for ever. */    OP_KETRMIN,        /* order. They are for groups the repeat for ever. */
192    
193    OP_ASSERT,    /* The assertions must come before ONCE and COND */
194    OP_ASSERT_NOT,  
195      OP_ASSERT,         /* Positive lookahead */
196      OP_ASSERT_NOT,     /* Negative lookahead */
197      OP_ASSERTBACK,     /* Positive lookbehind */
198      OP_ASSERTBACK_NOT, /* Negative lookbehind */
199      OP_REVERSE,        /* Move pointer back - used in lookbehind assertions */
200    
201      /* ONCE and COND must come after the assertions, with ONCE first, as there's
202      a test for >= ONCE for a subpattern that isn't an assertion. */
203    
204    OP_ONCE,           /* Once matched, don't back up into the subpattern */    OP_ONCE,           /* Once matched, don't back up into the subpattern */
205      OP_COND,           /* Conditional group */
206      OP_CREF,           /* Used to hold an extraction string number */
207    
208    OP_BRAZERO,        /* These two must remain together and in this */    OP_BRAZERO,        /* These two must remain together and in this */
209    OP_BRAMINZERO,     /* order. */    OP_BRAMINZERO,     /* order. */
# Line 231  just to accommodate the POSIX wrapper. * Line 243  just to accommodate the POSIX wrapper. *
243  #define ERR19 "too many sets of parentheses"  #define ERR19 "too many sets of parentheses"
244  #define ERR20 "regular expression too large"  #define ERR20 "regular expression too large"
245  #define ERR21 "failed to get memory"  #define ERR21 "failed to get memory"
246  #define ERR22 "unmatched brackets"  #define ERR22 "unmatched parentheses"
247  #define ERR23 "internal error: code overflow"  #define ERR23 "internal error: code overflow"
248    #define ERR24 "unrecognized character after (?<"
249    #define ERR25 "lookbehind assertion is not fixed length"
250    #define ERR26 "malformed number after (?("
251    #define ERR27 "conditional group contains more than two branches"
252    #define ERR28 "assertion expected after (?("
253    
254  /* All character handling must be done as unsigned characters. Otherwise there  /* All character handling must be done as unsigned characters. Otherwise there
255  are problems with top-bit-set characters and functions such as isspace().  are problems with top-bit-set characters and functions such as isspace().
# Line 247  typedef unsigned char uschar; Line 264  typedef unsigned char uschar;
264  runs on as long as necessary after the end. */  runs on as long as necessary after the end. */
265    
266  typedef struct real_pcre {  typedef struct real_pcre {
267    unsigned int  magic_number;    unsigned long int magic_number;
268    unsigned short int options;    const unsigned char *tables;
269    unsigned char top_bracket;    unsigned long int options;
270    unsigned char top_backref;    uschar top_bracket;
271    unsigned char first_char;    uschar top_backref;
272    unsigned char code[1];    uschar first_char;
273      uschar req_char;
274      uschar code[1];
275  } real_pcre;  } real_pcre;
276    
277  /* The real format of the extra block returned by pcre_study(). */  /* The real format of the extra block returned by pcre_study(). */
278    
279  typedef struct real_pcre_extra {  typedef struct real_pcre_extra {
280    unsigned char options;    uschar options;
281    unsigned char start_bits[32];    uschar start_bits[32];
282  } real_pcre_extra;  } real_pcre_extra;
283    
 /* Global tables from chartables.c */  
284    
285  extern uschar pcre_lcc[];  /* Structure for passing "static" information around between the functions
286  extern uschar pcre_fcc[];  doing the compiling, so that they are thread-safe. */
287  extern uschar pcre_cbits[];  
288  extern uschar pcre_ctypes[];  typedef struct compile_data {
289      const uschar *lcc;            /* Points to lower casing table */
290      const uschar *fcc;            /* Points to case-flipping table */
291      const uschar *cbits;          /* Points to character type table */
292      const uschar *ctypes;         /* Points to table of type maps */
293    } compile_data;
294    
295    /* Structure for passing "static" information around between the functions
296    doing the matching, so that they are thread-safe. */
297    
298    typedef struct match_data {
299      int    errorcode;             /* As it says */
300      int   *offset_vector;         /* Offset vector */
301      int    offset_end;            /* One past the end */
302      int    offset_max;            /* The maximum usable for return data */
303      const uschar *lcc;            /* Points to lower casing table */
304      const uschar *ctypes;         /* Points to table of type maps */
305      BOOL   offset_overflow;       /* Set if too many extractions */
306      BOOL   notbol;                /* NOTBOL flag */
307      BOOL   noteol;                /* NOTEOL flag */
308      BOOL   endonly;               /* Dollar not before final \n */
309      BOOL   notempty;              /* Empty string match not wanted */
310      const uschar *start_subject;  /* Start of the subject string */
311      const uschar *end_subject;    /* End of the subject string */
312      const uschar *start_match;    /* Start of this match attempt */
313      const uschar *end_match_ptr;  /* Subject position at end match */
314      int     end_offset_top;       /* Highwater mark at end of match */
315    } match_data;
316    
317  /* Bit definitions for entries in pcre_ctypes[]. */  /* Bit definitions for entries in the pcre_ctypes table. */
318    
319  #define ctype_space   0x01  #define ctype_space   0x01
320  #define ctype_letter  0x02  #define ctype_letter  0x02
# Line 278  extern uschar pcre_ctypes[]; Line 323  extern uschar pcre_ctypes[];
323  #define ctype_word    0x10   /* alphameric or '_' */  #define ctype_word    0x10   /* alphameric or '_' */
324  #define ctype_meta    0x80   /* regexp meta char or zero (end pattern) */  #define ctype_meta    0x80   /* regexp meta char or zero (end pattern) */
325    
326  /* Offsets for the bitmap tables */  /* Offsets for the bitmap tables in pcre_cbits. Each table contains a set
327    of bits for a class map. */
328    
329  #define cbit_digit    0  #define cbit_digit    0      /* for \d */
330  #define cbit_letter  32  #define cbit_word    32      /* for \w */
331  #define cbit_word    64  #define cbit_space   64      /* for \s */
332  #define cbit_space   96  #define cbit_length  96      /* Length of the cbits table */
333  #define cbit_length 128      /* Length of the cbits table */  
334    /* Offsets of the various tables from the base tables pointer, and
335    total length. */
336    
337    #define lcc_offset      0
338    #define fcc_offset    256
339    #define cbits_offset  512
340    #define ctypes_offset (cbits_offset + cbit_length)
341    #define tables_length (ctypes_offset + 256)
342    
343  /* End of internal.h */  /* End of internal.h */

Legend:
Removed from v.21  
changed lines
  Added in v.39

  ViewVC Help
Powered by ViewVC 1.1.5