~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to compat/GnuRegex.h

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2010-05-04 11:15:49 UTC
  • mfrom: (1.3.1 upstream)
  • mto: (20.3.1 squeeze) (21.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20100504111549-1apjh2g5sndki4te
Tags: upstream-3.1.3
ImportĀ upstreamĀ versionĀ 3.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id$
 
3
 */
 
4
#ifndef SQUID_CONFIG_H
 
5
#include "config.h"
 
6
#endif
 
7
 
 
8
#ifndef SQUID_REGEXP_LIBRARY_H
 
9
#define SQUID_REGEXP_LIBRARY_H
 
10
 
 
11
#if !USE_GNUREGEX /* try the system one by default */
 
12
 
 
13
/* POSIX says that <sys/types.h> must be included (by the caller) before
 
14
 * <regex.h>.  */
 
15
#if HAVE_SYS_TYPES_H
 
16
#include <sys/types.h>
 
17
#endif
 
18
#if HAVE_REGEX_H
 
19
#include <regex.h>
 
20
#endif
 
21
 
 
22
 
 
23
#else  /* USE_GNUREGEX */
 
24
 
 
25
#ifdef __cplusplus
 
26
extern "C" {
 
27
#endif
 
28
 
 
29
    /* Definitions for data structures and routines for the regular
 
30
     * expression library, version 0.12.
 
31
     *
 
32
     * Copyright (C) 1985, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
 
33
     *
 
34
     * This program is free software; you can redistribute it and/or modify
 
35
     * it under the terms of the GNU General Public License as published by
 
36
     * the Free Software Foundation; either version 2, or (at your option)
 
37
     * any later version.
 
38
     *
 
39
     * This program is distributed in the hope that it will be useful,
 
40
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
41
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
42
     * GNU General Public License for more details.
 
43
     *
 
44
     * You should have received a copy of the GNU General Public License
 
45
     * along with this program; if not, write to the Free Software
 
46
     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.  */
 
47
 
 
48
    /* POSIX says that <sys/types.h> must be included (by the caller) before
 
49
     * <regex.h>.  */
 
50
 
 
51
#ifdef VMS
 
52
    /* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
 
53
     * should be there.  */
 
54
#include <stddef.h>
 
55
#endif
 
56
 
 
57
 
 
58
    /* The following bits are used to determine the regexp syntax we
 
59
     * recognize.  The set/not-set meanings are chosen so that Emacs syntax
 
60
     * remains the value 0.  The bits are given in alphabetical order, and
 
61
     * the definitions shifted by one from the previous bit; thus, when we
 
62
     * add or remove a bit, only one other definition need change.  */
 
63
    typedef unsigned reg_syntax_t;
 
64
 
 
65
    /* If this bit is not set, then \ inside a bracket expression is literal.
 
66
     * If set, then such a \ quotes the following character.  */
 
67
#define RE_BACKSLASH_ESCAPE_IN_LISTS (1)
 
68
 
 
69
    /* If this bit is not set, then + and ? are operators, and \+ and \? are
 
70
     * literals.
 
71
     * If set, then \+ and \? are operators and + and ? are literals.  */
 
72
#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
 
73
 
 
74
    /* If this bit is set, then character classes are supported.  They are:
 
75
     * [:alpha:], [:upper:], [:lower:],  [:digit:], [:alnum:], [:xdigit:],
 
76
     * [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
 
77
     * If not set, then character classes are not supported.  */
 
78
#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
 
79
 
 
80
    /* If this bit is set, then ^ and $ are always anchors (outside bracket
 
81
     * expressions, of course).
 
82
     * If this bit is not set, then it depends:
 
83
     * ^  is an anchor if it is at the beginning of a regular
 
84
     * expression or after an open-group or an alternation operator;
 
85
     * $  is an anchor if it is at the end of a regular expression, or
 
86
     * before a close-group or an alternation operator.
 
87
     *
 
88
     * This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
 
89
     * POSIX draft 11.2 says that * etc. in leading positions is undefined.
 
90
     * We already implemented a previous draft which made those constructs
 
91
     * invalid, though, so we haven't changed the code back.  */
 
92
#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
 
93
 
 
94
    /* If this bit is set, then special characters are always special
 
95
     * regardless of where they are in the pattern.
 
96
     * If this bit is not set, then special characters are special only in
 
97
     * some contexts; otherwise they are ordinary.  Specifically,
 
98
     * * + ? and intervals are only special when not after the beginning,
 
99
     * open-group, or alternation operator.  */
 
100
#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
 
101
 
 
102
    /* If this bit is set, then *, +, ?, and { cannot be first in an re or
 
103
     * immediately after an alternation or begin-group operator.  */
 
104
#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
 
105
 
 
106
    /* If this bit is set, then . matches newline.
 
107
     * If not set, then it doesn't.  */
 
108
#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
 
109
 
 
110
    /* If this bit is set, then . doesn't match NUL.
 
111
     * If not set, then it does.  */
 
112
#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
 
113
 
 
114
    /* If this bit is set, nonmatching lists [^...] do not match newline.
 
115
     * If not set, they do.  */
 
116
#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
 
117
 
 
118
    /* If this bit is set, either \{...\} or {...} defines an
 
119
     * interval, depending on RE_NO_BK_BRACES.
 
120
     * If not set, \{, \}, {, and } are literals.  */
 
121
#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
 
122
 
 
123
    /* If this bit is set, +, ? and | aren't recognized as operators.
 
124
     * If not set, they are.  */
 
125
#define RE_LIMITED_OPS (RE_INTERVALS << 1)
 
126
 
 
127
    /* If this bit is set, newline is an alternation operator.
 
128
     * If not set, newline is literal.  */
 
129
#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
 
130
 
 
131
    /* If this bit is set, then `{...}' defines an interval, and \{ and \}
 
132
     * are literals.
 
133
     * If not set, then `\{...\}' defines an interval.  */
 
134
#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
 
135
 
 
136
    /* If this bit is set, (...) defines a group, and \( and \) are literals.
 
137
     * If not set, \(...\) defines a group, and ( and ) are literals.  */
 
138
#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
 
139
 
 
140
    /* If this bit is set, then \<digit> matches <digit>.
 
141
     * If not set, then \<digit> is a back-reference.  */
 
142
#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
 
143
 
 
144
    /* If this bit is set, then | is an alternation operator, and \| is literal.
 
145
     * If not set, then \| is an alternation operator, and | is literal.  */
 
146
#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
 
147
 
 
148
    /* If this bit is set, then an ending range point collating higher
 
149
     * than the starting range point, as in [z-a], is invalid.
 
150
     * If not set, then when ending range point collates higher than the
 
151
     * starting range point, the range is ignored.  */
 
152
#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
 
153
 
 
154
    /* If this bit is set, then an unmatched ) is ordinary.
 
155
     * If not set, then an unmatched ) is invalid.  */
 
156
#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
 
157
 
 
158
    
 
159
    /* Define combinations of the above bits for the standard possibilities.
 
160
     * (The [[[ comments delimit what gets put into the Texinfo file, so
 
161
     * don't delete them!)  */
 
162
    /* [[[begin syntaxes]]] */
 
163
#define RE_SYNTAX_EMACS 0
 
164
 
 
165
#define RE_SYNTAX_AWK                                                   \
 
166
  (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL                       \
 
167
   | RE_NO_BK_PARENS            | RE_NO_BK_REFS                         \
 
168
   | RE_NO_BK_VBAR               | RE_NO_EMPTY_RANGES                   \
 
169
   | RE_UNMATCHED_RIGHT_PAREN_ORD)
 
170
 
 
171
#define RE_SYNTAX_POSIX_AWK                                             \
 
172
  (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS)
 
173
 
 
174
#define RE_SYNTAX_GREP                                                  \
 
175
  (RE_BK_PLUS_QM              | RE_CHAR_CLASSES                         \
 
176
   | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS                            \
 
177
   | RE_NEWLINE_ALT)
 
178
 
 
179
#define RE_SYNTAX_EGREP                                                 \
 
180
  (RE_CHAR_CLASSES        | RE_CONTEXT_INDEP_ANCHORS                    \
 
181
   | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE                    \
 
182
   | RE_NEWLINE_ALT       | RE_NO_BK_PARENS                             \
 
183
   | RE_NO_BK_VBAR)
 
184
 
 
185
#define RE_SYNTAX_POSIX_EGREP                                           \
 
186
  (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES)
 
187
 
 
188
    /* P1003.2/D11.2, section 4.20.7.1, lines 5078ff.  */
 
189
#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
 
190
 
 
191
#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
 
192
 
 
193
    /* Syntax bits common to both basic and extended POSIX regex syntax.  */
 
194
#define _RE_SYNTAX_POSIX_COMMON                                         \
 
195
  (RE_CHAR_CLASSES | RE_DOT_NEWLINE      | RE_DOT_NOT_NULL              \
 
196
   | RE_INTERVALS  | RE_NO_EMPTY_RANGES)
 
197
 
 
198
#define RE_SYNTAX_POSIX_BASIC                                           \
 
199
  (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
 
200
 
 
201
    /* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
 
202
     * RE_LIMITED_OPS, i.e., \? \+ \| are not recognized.  Actually, this
 
203
     * isn't minimal, since other operators, such as \`, aren't disabled.  */
 
204
#define RE_SYNTAX_POSIX_MINIMAL_BASIC                                   \
 
205
  (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
 
206
 
 
207
#define RE_SYNTAX_POSIX_EXTENDED                                        \
 
208
  (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS                   \
 
209
   | RE_CONTEXT_INDEP_OPS  | RE_NO_BK_BRACES                            \
 
210
   | RE_NO_BK_PARENS       | RE_NO_BK_VBAR                              \
 
211
   | RE_UNMATCHED_RIGHT_PAREN_ORD)
 
212
 
 
213
    /* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS
 
214
     * replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added.  */
 
215
#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED                                \
 
216
  (_RE_SYNTAX_POSIX_COMMON  | RE_CONTEXT_INDEP_ANCHORS                  \
 
217
   | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES                           \
 
218
   | RE_NO_BK_PARENS        | RE_NO_BK_REFS                             \
 
219
   | RE_NO_BK_VBAR          | RE_UNMATCHED_RIGHT_PAREN_ORD)
 
220
    /* [[[end syntaxes]]] */
 
221
    
 
222
    /* Maximum number of duplicates an interval can allow.  Some systems
 
223
     * (erroneously) define this in other header files, but we want our
 
224
     * value, so remove any previous define.  */
 
225
#ifdef RE_DUP_MAX
 
226
#undef RE_DUP_MAX
 
227
#endif
 
228
#define RE_DUP_MAX ((1 << 15) - 1)
 
229
 
 
230
 
 
231
    /* POSIX `cflags' bits (i.e., information for `regcomp').  */
 
232
 
 
233
    /* If this bit is set, then use extended regular expression syntax.
 
234
     * If not set, then use basic regular expression syntax.  */
 
235
#define REG_EXTENDED 1
 
236
 
 
237
    /* If this bit is set, then ignore case when matching.
 
238
     * If not set, then case is significant.  */
 
239
#define REG_ICASE (REG_EXTENDED << 1)
 
240
 
 
241
    /* If this bit is set, then anchors do not match at newline
 
242
     * characters in the string.
 
243
     * If not set, then anchors do match at newlines.  */
 
244
#define REG_NEWLINE (REG_ICASE << 1)
 
245
 
 
246
    /* If this bit is set, then report only success or fail in regexec.
 
247
     * If not set, then returns differ between not matching and errors.  */
 
248
#define REG_NOSUB (REG_NEWLINE << 1)
 
249
 
 
250
 
 
251
    /* POSIX `eflags' bits (i.e., information for regexec).  */
 
252
 
 
253
    /* If this bit is set, then the beginning-of-line operator doesn't match
 
254
     * the beginning of the string (presumably because it's not the
 
255
     * beginning of a line).
 
256
     * If not set, then the beginning-of-line operator does match the
 
257
     * beginning of the string.  */
 
258
#define REG_NOTBOL 1
 
259
 
 
260
    /* Like REG_NOTBOL, except for the end-of-line.  */
 
261
#define REG_NOTEOL (1 << 1)
 
262
 
 
263
 
 
264
    /* If any error codes are removed, changed, or added, update the
 
265
     * `re_error_msg' table in regex.c.  */
 
266
    typedef enum {
 
267
        REG_NOERROR = 0,                /* Success.  */
 
268
        REG_NOMATCH,            /* Didn't find a match (for regexec).  */
 
269
 
 
270
        /* POSIX regcomp return error codes.  (In the order listed in the
 
271
         * standard.)  */
 
272
        REG_BADPAT,                     /* Invalid pattern.  */
 
273
        REG_ECOLLATE,           /* Not implemented.  */
 
274
        REG_ECTYPE,                     /* Invalid character class name.  */
 
275
        REG_EESCAPE,            /* Trailing backslash.  */
 
276
        REG_ESUBREG,            /* Invalid back reference.  */
 
277
        REG_EBRACK,                     /* Unmatched left bracket.  */
 
278
        REG_EPAREN,                     /* Parenthesis imbalance.  */
 
279
        REG_EBRACE,                     /* Unmatched \{.  */
 
280
        REG_BADBR,                      /* Invalid contents of \{\}.  */
 
281
        REG_ERANGE,                     /* Invalid range end.  */
 
282
        REG_ESPACE,                     /* Ran out of memory.  */
 
283
        REG_BADRPT,                     /* No preceding re for repetition op.  */
 
284
 
 
285
        /* Error codes we've added.  */
 
286
        REG_EEND,                       /* Premature end.  */
 
287
        REG_ESIZE,                      /* Compiled pattern bigger than 2^16 bytes.  */
 
288
        REG_ERPAREN                     /* Unmatched ) or \); not returned from regcomp.  */
 
289
    } reg_errcode_t;
 
290
    
 
291
    /* This data structure represents a compiled pattern.  Before calling
 
292
     * the pattern compiler, the fields `buffer', `allocated', `fastmap',
 
293
     * `translate', and `no_sub' can be set.  After the pattern has been
 
294
     * compiled, the `re_nsub' field is available.  All other fields are
 
295
     * private to the regex routines.  */
 
296
 
 
297
    struct re_pattern_buffer {
 
298
        /* [[[begin pattern_buffer]]] */
 
299
        /* Space that holds the compiled pattern.  It is declared as
 
300
         * `unsigned char *' because its elements are
 
301
         * sometimes used as array indexes.  */
 
302
        unsigned char *buffer;
 
303
 
 
304
        /* Number of bytes to which `buffer' points.  */
 
305
        unsigned long allocated;
 
306
 
 
307
        /* Number of bytes actually used in `buffer'.  */
 
308
        unsigned long used;
 
309
 
 
310
        /* Syntax setting with which the pattern was compiled.  */
 
311
        reg_syntax_t syntax;
 
312
 
 
313
        /* Pointer to a fastmap, if any, otherwise zero.  re_search uses
 
314
         * the fastmap, if there is one, to skip over impossible
 
315
         * starting points for matches.  */
 
316
        char *fastmap;
 
317
 
 
318
        /* Either a translate table to apply to all characters before
 
319
         * comparing them, or zero for no translation.  The translation
 
320
         * is applied to a pattern when it is compiled and to a string
 
321
         * when it is matched.  */
 
322
        char *translate;
 
323
 
 
324
        /* Number of subexpressions found by the compiler.  */
 
325
        size_t re_nsub;
 
326
 
 
327
        /* Zero if this pattern cannot match the empty string, one else.
 
328
         * Well, in truth it's used only in `re_search_2', to see
 
329
         * whether or not we should use the fastmap, so we don't set
 
330
         * this absolutely perfectly; see `re_compile_fastmap' (the
 
331
         * `duplicate' case).  */
 
332
        unsigned can_be_null:1;
 
333
 
 
334
        /* If REGS_UNALLOCATED, allocate space in the `regs' structure
 
335
         * for `max (RE_NREGS, re_nsub + 1)' groups.
 
336
         * If REGS_REALLOCATE, reallocate space if necessary.
 
337
         * If REGS_FIXED, use what's there.  */
 
338
#define REGS_UNALLOCATED 0
 
339
#define REGS_REALLOCATE 1
 
340
#define REGS_FIXED 2
 
341
        unsigned regs_allocated:2;
 
342
 
 
343
        /* Set to zero when `regex_compile' compiles a pattern; set to one
 
344
         * by `re_compile_fastmap' if it updates the fastmap.  */
 
345
        unsigned fastmap_accurate:1;
 
346
 
 
347
        /* If set, `re_match_2' does not return information about
 
348
         * subexpressions.  */
 
349
        unsigned no_sub:1;
 
350
 
 
351
        /* If set, a beginning-of-line anchor doesn't match at the
 
352
         * beginning of the string.  */
 
353
        unsigned not_bol:1;
 
354
 
 
355
        /* Similarly for an end-of-line anchor.  */
 
356
        unsigned not_eol:1;
 
357
 
 
358
        /* If true, an anchor at a newline matches.  */
 
359
        unsigned newline_anchor:1;
 
360
 
 
361
        /* [[[end pattern_buffer]]] */
 
362
    };
 
363
 
 
364
    typedef struct re_pattern_buffer regex_t;
 
365
 
 
366
 
 
367
    /* search.c (search_buffer) in Emacs needs this one opcode value.  It is
 
368
     * defined both in `regex.c' and here.  */
 
369
#define RE_EXACTN_VALUE 1
 
370
    
 
371
    /* Type for byte offsets within the string.  POSIX mandates this.  */
 
372
    typedef int regoff_t;
 
373
 
 
374
 
 
375
    /* This is the structure we store register match data in.  See
 
376
     * regex.texinfo for a full description of what registers match.  */
 
377
    struct re_registers {
 
378
        unsigned num_regs;
 
379
        regoff_t *start;
 
380
        regoff_t *end;
 
381
    };
 
382
 
 
383
 
 
384
    /* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
 
385
     * `re_match_2' returns information about at least this many registers
 
386
     * the first time a `regs' structure is passed.  */
 
387
#ifndef RE_NREGS
 
388
#define RE_NREGS 30
 
389
#endif
 
390
 
 
391
 
 
392
    /* POSIX specification for registers.  Aside from the different names than
 
393
     * `re_registers', POSIX uses an array of structures, instead of a
 
394
     * structure of arrays.  */
 
395
    typedef struct {
 
396
        regoff_t rm_so;         /* Byte offset from string's start to substring's start.  */
 
397
        regoff_t rm_eo;         /* Byte offset from string's start to substring's end.  */
 
398
    } regmatch_t;
 
399
    
 
400
    /* Declarations for routines.  */
 
401
 
 
402
    /* To avoid duplicating every routine declaration -- once with a
 
403
     * prototype (if we are ANSI), and once without (if we aren't) -- we
 
404
     * use the following macro to declare argument types.  This
 
405
     * unfortunately clutters up the declarations a bit, but I think it's
 
406
     * worth it.  */
 
407
 
 
408
    /* POSIX compatibility.  */
 
409
    extern int regcomp(regex_t * preg, const char *pattern, int cflags);
 
410
    extern int regexec(const regex_t * preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags);
 
411
    extern size_t regerror(int errcode, const regex_t * preg, char *errbuf, size_t errbuf_size);
 
412
    extern void regfree(regex_t * preg);
 
413
 
 
414
#ifdef __cplusplus
 
415
}
 
416
#endif
 
417
 
 
418
#endif /* USE_GNUREGEX */
 
419
#endif /* SQUID_REGEXP_LIBRARY_H */
 
420
 
 
421
/*
 
422
 * Local variables:
 
423
 * make-backup-files: t
 
424
 * version-control: t
 
425
 * trim-versions-without-asking: nil
 
426
 * End:
 
427
 */