]> git.ipfire.org Git - thirdparty/squid.git/blame - compat/GnuRegex.h
Real quiet cache.log when TPROXY and NAT both active
[thirdparty/squid.git] / compat / GnuRegex.h
CommitLineData
0e2cd867 1/*
262a0e14 2 * $Id$
0e2cd867 3 */
f04e1182
AJ
4#ifndef SQUID_CONFIG_H
5#include "config.h"
6#endif
7
b5638623 8#ifndef SQUID_REGEXP_LIBRARY_H
9#define SQUID_REGEXP_LIBRARY_H
10
f04e1182
AJ
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
26extern "C"
27{
28#endif
e1f7507e 29
090089c4 30/* Definitions for data structures and routines for the regular
b8d8561b 31 * expression library, version 0.12.
c5dd4956 32 *
b8d8561b 33 * Copyright (C) 1985, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
c5dd4956 34 *
b8d8561b 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)
38 * any later version.
c5dd4956 39 *
b8d8561b 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.
c5dd4956 44 *
b8d8561b 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
cbdec147 47 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. */
090089c4 48
090089c4 49/* POSIX says that <sys/types.h> must be included (by the caller) before
b8d8561b 50 * <regex.h>. */
090089c4 51
52#ifdef VMS
53/* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
b8d8561b 54 * should be there. */
090089c4 55#include <stddef.h>
56#endif
57
58
59/* The following bits are used to determine the regexp syntax we
b8d8561b 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. */
090089c4 64typedef unsigned reg_syntax_t;
65
66/* If this bit is not set, then \ inside a bracket expression is literal.
b8d8561b 67 * If set, then such a \ quotes the following character. */
090089c4 68#define RE_BACKSLASH_ESCAPE_IN_LISTS (1)
69
70/* If this bit is not set, then + and ? are operators, and \+ and \? are
c5dd4956 71 * literals.
b8d8561b 72 * If set, then \+ and \? are operators and + and ? are literals. */
090089c4 73#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
74
75/* If this bit is set, then character classes are supported. They are:
b8d8561b 76 * [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
77 * [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
78 * If not set, then character classes are not supported. */
090089c4 79#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
80
81/* If this bit is set, then ^ and $ are always anchors (outside bracket
b8d8561b 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
c5dd4956
AJ
87 * before a close-group or an alternation operator.
88 *
b8d8561b 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. */
090089c4 93#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
94
95/* If this bit is set, then special characters are always special
b8d8561b 96 * regardless of where they are in the pattern.
97 * If this bit is not set, then special characters are special only in
c5dd4956 98 * some contexts; otherwise they are ordinary. Specifically,
b8d8561b 99 * * + ? and intervals are only special when not after the beginning,
100 * open-group, or alternation operator. */
090089c4 101#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
102
103/* If this bit is set, then *, +, ?, and { cannot be first in an re or
b8d8561b 104 * immediately after an alternation or begin-group operator. */
090089c4 105#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
106
107/* If this bit is set, then . matches newline.
b8d8561b 108 * If not set, then it doesn't. */
090089c4 109#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
110
111/* If this bit is set, then . doesn't match NUL.
b8d8561b 112 * If not set, then it does. */
090089c4 113#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
114
115/* If this bit is set, nonmatching lists [^...] do not match newline.
b8d8561b 116 * If not set, they do. */
090089c4 117#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
118
119/* If this bit is set, either \{...\} or {...} defines an
c5dd4956 120 * interval, depending on RE_NO_BK_BRACES.
b8d8561b 121 * If not set, \{, \}, {, and } are literals. */
090089c4 122#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
123
124/* If this bit is set, +, ? and | aren't recognized as operators.
b8d8561b 125 * If not set, they are. */
090089c4 126#define RE_LIMITED_OPS (RE_INTERVALS << 1)
127
128/* If this bit is set, newline is an alternation operator.
b8d8561b 129 * If not set, newline is literal. */
090089c4 130#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
131
132/* If this bit is set, then `{...}' defines an interval, and \{ and \}
b8d8561b 133 * are literals.
134 * If not set, then `\{...\}' defines an interval. */
090089c4 135#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
136
137/* If this bit is set, (...) defines a group, and \( and \) are literals.
b8d8561b 138 * If not set, \(...\) defines a group, and ( and ) are literals. */
090089c4 139#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
140
141/* If this bit is set, then \<digit> matches <digit>.
b8d8561b 142 * If not set, then \<digit> is a back-reference. */
090089c4 143#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
144
c5dd4956 145/* If this bit is set, then | is an alternation operator, and \| is literal.
b8d8561b 146 * If not set, then \| is an alternation operator, and | is literal. */
090089c4 147#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
148
149/* If this bit is set, then an ending range point collating higher
b8d8561b 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. */
090089c4 153#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
154
155/* If this bit is set, then an unmatched ) is ordinary.
b8d8561b 156 * If not set, then an unmatched ) is invalid. */
090089c4 157#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
158
090089c4 159\f
160/* Define combinations of the above bits for the standard possibilities.
b8d8561b 161 * (The [[[ comments delimit what gets put into the Texinfo file, so
162 * don't delete them!) */
090089c4 163/* [[[begin syntaxes]]] */
164#define RE_SYNTAX_EMACS 0
165
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)
171
172#define RE_SYNTAX_POSIX_AWK \
173 (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS)
174
175#define RE_SYNTAX_GREP \
176 (RE_BK_PLUS_QM | RE_CHAR_CLASSES \
177 | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
178 | RE_NEWLINE_ALT)
179
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 \
184 | RE_NO_BK_VBAR)
185
186#define RE_SYNTAX_POSIX_EGREP \
187 (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES)
188
189/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
190#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
191
192#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
193
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)
198
199#define RE_SYNTAX_POSIX_BASIC \
200 (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
201
202/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
b8d8561b 203 * RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
204 * isn't minimal, since other operators, such as \`, aren't disabled. */
090089c4 205#define RE_SYNTAX_POSIX_MINIMAL_BASIC \
206 (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
207
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)
213
214/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS
b8d8561b 215 * replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added. */
090089c4 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]]] */
222\f
223/* Maximum number of duplicates an interval can allow. Some systems
b8d8561b 224 * (erroneously) define this in other header files, but we want our
225 * value, so remove any previous define. */
090089c4 226#ifdef RE_DUP_MAX
227#undef RE_DUP_MAX
228#endif
b8d8561b 229#define RE_DUP_MAX ((1 << 15) - 1)
090089c4 230
231
232/* POSIX `cflags' bits (i.e., information for `regcomp'). */
233
234/* If this bit is set, then use extended regular expression syntax.
b8d8561b 235 * If not set, then use basic regular expression syntax. */
090089c4 236#define REG_EXTENDED 1
237
238/* If this bit is set, then ignore case when matching.
b8d8561b 239 * If not set, then case is significant. */
090089c4 240#define REG_ICASE (REG_EXTENDED << 1)
b8d8561b 241
090089c4 242/* If this bit is set, then anchors do not match at newline
b8d8561b 243 * characters in the string.
244 * If not set, then anchors do match at newlines. */
090089c4 245#define REG_NEWLINE (REG_ICASE << 1)
246
247/* If this bit is set, then report only success or fail in regexec.
b8d8561b 248 * If not set, then returns differ between not matching and errors. */
090089c4 249#define REG_NOSUB (REG_NEWLINE << 1)
250
251
252/* POSIX `eflags' bits (i.e., information for regexec). */
253
254/* If this bit is set, then the beginning-of-line operator doesn't match
b8d8561b 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. */
090089c4 259#define REG_NOTBOL 1
260
261/* Like REG_NOTBOL, except for the end-of-line. */
262#define REG_NOTEOL (1 << 1)
263
264
265/* If any error codes are removed, changed, or added, update the
b8d8561b 266 * `re_error_msg' table in regex.c. */
267typedef enum {
268 REG_NOERROR = 0, /* Success. */
269 REG_NOMATCH, /* Didn't find a match (for regexec). */
270
271 /* POSIX regcomp return error codes. (In the order listed in the
272 * standard.) */
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. */
285
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. */
090089c4 290} reg_errcode_t;
291\f
292/* This data structure represents a compiled pattern. Before calling
b8d8561b 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. */
090089c4 297
b8d8561b 298struct re_pattern_buffer {
c5dd4956 299 /* [[[begin pattern_buffer]]] */
b8d8561b 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;
304
305 /* Number of bytes to which `buffer' points. */
306 unsigned long allocated;
307
308 /* Number of bytes actually used in `buffer'. */
309 unsigned long used;
310
311 /* Syntax setting with which the pattern was compiled. */
312 reg_syntax_t syntax;
313
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. */
317 char *fastmap;
318
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. */
323 char *translate;
324
325 /* Number of subexpressions found by the compiler. */
326 size_t re_nsub;
327
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;
334
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. */
090089c4 339#define REGS_UNALLOCATED 0
340#define REGS_REALLOCATE 1
341#define REGS_FIXED 2
b8d8561b 342 unsigned regs_allocated:2;
090089c4 343
b8d8561b 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;
090089c4 347
b8d8561b 348 /* If set, `re_match_2' does not return information about
349 * subexpressions. */
350 unsigned no_sub:1;
090089c4 351
b8d8561b 352 /* If set, a beginning-of-line anchor doesn't match at the
353 * beginning of the string. */
354 unsigned not_bol:1;
090089c4 355
b8d8561b 356 /* Similarly for an end-of-line anchor. */
357 unsigned not_eol:1;
090089c4 358
b8d8561b 359 /* If true, an anchor at a newline matches. */
360 unsigned newline_anchor:1;
090089c4 361
c5dd4956 362 /* [[[end pattern_buffer]]] */
090089c4 363};
364
365typedef struct re_pattern_buffer regex_t;
366
367
368/* search.c (search_buffer) in Emacs needs this one opcode value. It is
b8d8561b 369 * defined both in `regex.c' and here. */
090089c4 370#define RE_EXACTN_VALUE 1
371\f
372/* Type for byte offsets within the string. POSIX mandates this. */
373typedef int regoff_t;
374
375
376/* This is the structure we store register match data in. See
b8d8561b 377 * regex.texinfo for a full description of what registers match. */
378struct re_registers {
379 unsigned num_regs;
380 regoff_t *start;
381 regoff_t *end;
090089c4 382};
383
384
385/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
b8d8561b 386 * `re_match_2' returns information about at least this many registers
387 * the first time a `regs' structure is passed. */
090089c4 388#ifndef RE_NREGS
389#define RE_NREGS 30
390#endif
391
392
393/* POSIX specification for registers. Aside from the different names than
b8d8561b 394 * `re_registers', POSIX uses an array of structures, instead of a
395 * structure of arrays. */
396typedef struct {
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. */
090089c4 399} regmatch_t;
400\f
401/* Declarations for routines. */
402
403/* To avoid duplicating every routine declaration -- once with a
b8d8561b 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
407 * worth it. */
090089c4 408
6de2df60 409#if STDC_HEADERS
090089c4 410
411#define _RE_ARGS(args) args
412
413#else /* not __STDC__ */
414
415#define _RE_ARGS(args) ()
416
417#endif /* not __STDC__ */
418
090089c4 419/* POSIX compatibility. */
b8d8561b 420extern int regcomp _RE_ARGS((regex_t * preg, const char *pattern, int cflags));
090089c4 421extern int regexec
b8d8561b 422 _RE_ARGS((const regex_t * preg, const char *string, size_t nmatch,
c5dd4956 423 regmatch_t pmatch[], int eflags));
090089c4 424extern size_t regerror
c5dd4956
AJ
425 _RE_ARGS((int errcode, const regex_t * preg, char *errbuf,
426 size_t errbuf_size));
b8d8561b 427extern void regfree _RE_ARGS((regex_t * preg));
090089c4 428
f04e1182
AJ
429#ifdef __cplusplus
430}
431#endif
432
433#endif /* USE_GNUREGEX */
b5638623 434#endif /* SQUID_REGEXP_LIBRARY_H */
090089c4 435\f
436/*
b8d8561b 437 * Local variables:
438 * make-backup-files: t
439 * version-control: t
440 * trim-versions-without-asking: nil
441 * End:
442 */