8
#ifndef SQUID_REGEXP_LIBRARY_H
9
#define SQUID_REGEXP_LIBRARY_H
11
#if !USE_GNUREGEX /* try the system one by default */
13
/* POSIX says that <sys/types.h> must be included (by the caller) before
16
#include <sys/types.h>
23
#else /* USE_GNUREGEX */
29
/* Definitions for data structures and routines for the regular
30
* expression library, version 0.12.
32
* Copyright (C) 1985, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
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)
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.
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. */
48
/* POSIX says that <sys/types.h> must be included (by the caller) before
52
/* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
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;
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)
69
/* If this bit is not set, then + and ? are operators, and \+ and \? are
71
* If set, then \+ and \? are operators and + and ? are literals. */
72
#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
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)
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.
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)
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)
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)
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)
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)
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)
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)
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)
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)
131
/* If this bit is set, then `{...}' defines an interval, and \{ and \}
133
* If not set, then `\{...\}' defines an interval. */
134
#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
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)
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)
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)
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)
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)
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
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)
171
#define RE_SYNTAX_POSIX_AWK \
172
(RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS)
174
#define RE_SYNTAX_GREP \
175
(RE_BK_PLUS_QM | RE_CHAR_CLASSES \
176
| RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
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 \
185
#define RE_SYNTAX_POSIX_EGREP \
186
(RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES)
188
/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
189
#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
191
#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
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)
198
#define RE_SYNTAX_POSIX_BASIC \
199
(_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
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)
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)
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]]] */
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. */
228
#define RE_DUP_MAX ((1 << 15) - 1)
231
/* POSIX `cflags' bits (i.e., information for `regcomp'). */
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
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)
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)
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)
251
/* POSIX `eflags' bits (i.e., information for regexec). */
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. */
260
/* Like REG_NOTBOL, except for the end-of-line. */
261
#define REG_NOTEOL (1 << 1)
264
/* If any error codes are removed, changed, or added, update the
265
* `re_error_msg' table in regex.c. */
267
REG_NOERROR = 0, /* Success. */
268
REG_NOMATCH, /* Didn't find a match (for regexec). */
270
/* POSIX regcomp return error codes. (In the order listed in the
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. */
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. */
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. */
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;
304
/* Number of bytes to which `buffer' points. */
305
unsigned long allocated;
307
/* Number of bytes actually used in `buffer'. */
310
/* Syntax setting with which the pattern was compiled. */
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. */
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. */
324
/* Number of subexpressions found by the compiler. */
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;
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
341
unsigned regs_allocated:2;
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;
347
/* If set, `re_match_2' does not return information about
351
/* If set, a beginning-of-line anchor doesn't match at the
352
* beginning of the string. */
355
/* Similarly for an end-of-line anchor. */
358
/* If true, an anchor at a newline matches. */
359
unsigned newline_anchor:1;
361
/* [[[end pattern_buffer]]] */
364
typedef struct re_pattern_buffer regex_t;
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
371
/* Type for byte offsets within the string. POSIX mandates this. */
372
typedef int regoff_t;
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 {
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. */
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. */
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. */
400
/* Declarations for routines. */
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
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);
418
#endif /* USE_GNUREGEX */
419
#endif /* SQUID_REGEXP_LIBRARY_H */
423
* make-backup-files: t
425
* trim-versions-without-asking: nil