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