]> git.proxmox.com Git - mirror_smartmontools-debian.git/blame - regex/regex.h
import smartmontools 7.0
[mirror_smartmontools-debian.git] / regex / regex.h
CommitLineData
832b75ed
GG
1/* Definitions for data structures and routines for the regular
2 expression library.
ff28b140 3 Copyright (C) 1985, 1989-2018 Free Software Foundation, Inc.
832b75ed
GG
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
ff28b140
TL
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
832b75ed
GG
19
20#ifndef _REGEX_H
21#define _REGEX_H 1
22
ff28b140
TL
23#include <sys/types.h>
24
832b75ed
GG
25/* Allow the use in C++ code. */
26#ifdef __cplusplus
27extern "C" {
28#endif
29
ff28b140
TL
30/* Define __USE_GNU to declare GNU extensions that violate the
31 POSIX name space rules. */
32#if defined(_GNU_SOURCE) || defined(_REGEX_STANDALONE)
33# define __USE_GNU 1
34#endif
35
36#ifdef _REGEX_LARGE_OFFSETS
37
38/* Use types and values that are wide enough to represent signed and
39 unsigned byte offsets in memory. This currently works only when
40 the regex code is used outside of the GNU C library; it is not yet
41 supported within glibc itself, and glibc users should not define
42 _REGEX_LARGE_OFFSETS. */
43
44/* The type of object sizes. */
45typedef size_t __re_size_t;
46
47/* The type of object sizes, in places where the traditional code
48 uses unsigned long int. */
49typedef size_t __re_long_size_t;
50
51#else
52
53/* The traditional GNU regex implementation mishandles strings longer
54 than INT_MAX. */
55typedef unsigned int __re_size_t;
56typedef unsigned long int __re_long_size_t;
832b75ed 57
832b75ed
GG
58#endif
59
60/* The following two types have to be signed and unsigned integer type
61 wide enough to hold a value of a pointer. For most ANSI compilers
62 ptrdiff_t and size_t should be likely OK. Still size of these two
63 types is 2 for Microsoft C. Ugh... */
64typedef long int s_reg_t;
65typedef unsigned long int active_reg_t;
66
67/* The following bits are used to determine the regexp syntax we
68 recognize. The set/not-set meanings are chosen so that Emacs syntax
69 remains the value 0. The bits are given in alphabetical order, and
70 the definitions shifted by one from the previous bit; thus, when we
71 add or remove a bit, only one other definition need change. */
72typedef unsigned long int reg_syntax_t;
73
ff28b140 74#ifdef __USE_GNU
832b75ed
GG
75/* If this bit is not set, then \ inside a bracket expression is literal.
76 If set, then such a \ quotes the following character. */
ff28b140 77# define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1)
832b75ed
GG
78
79/* If this bit is not set, then + and ? are operators, and \+ and \? are
80 literals.
81 If set, then \+ and \? are operators and + and ? are literals. */
ff28b140 82# define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
832b75ed
GG
83
84/* If this bit is set, then character classes are supported. They are:
85 [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
86 [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
87 If not set, then character classes are not supported. */
ff28b140 88# define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
832b75ed
GG
89
90/* If this bit is set, then ^ and $ are always anchors (outside bracket
91 expressions, of course).
92 If this bit is not set, then it depends:
ff28b140
TL
93 ^ is an anchor if it is at the beginning of a regular
94 expression or after an open-group or an alternation operator;
95 $ is an anchor if it is at the end of a regular expression, or
96 before a close-group or an alternation operator.
832b75ed
GG
97
98 This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
99 POSIX draft 11.2 says that * etc. in leading positions is undefined.
100 We already implemented a previous draft which made those constructs
101 invalid, though, so we haven't changed the code back. */
ff28b140 102# define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
832b75ed
GG
103
104/* If this bit is set, then special characters are always special
105 regardless of where they are in the pattern.
106 If this bit is not set, then special characters are special only in
107 some contexts; otherwise they are ordinary. Specifically,
108 * + ? and intervals are only special when not after the beginning,
109 open-group, or alternation operator. */
ff28b140 110# define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
832b75ed
GG
111
112/* If this bit is set, then *, +, ?, and { cannot be first in an re or
113 immediately after an alternation or begin-group operator. */
ff28b140 114# define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
832b75ed
GG
115
116/* If this bit is set, then . matches newline.
117 If not set, then it doesn't. */
ff28b140 118# define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
832b75ed
GG
119
120/* If this bit is set, then . doesn't match NUL.
121 If not set, then it does. */
ff28b140 122# define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
832b75ed
GG
123
124/* If this bit is set, nonmatching lists [^...] do not match newline.
125 If not set, they do. */
ff28b140 126# define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
832b75ed
GG
127
128/* If this bit is set, either \{...\} or {...} defines an
129 interval, depending on RE_NO_BK_BRACES.
130 If not set, \{, \}, {, and } are literals. */
ff28b140 131# define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
832b75ed
GG
132
133/* If this bit is set, +, ? and | aren't recognized as operators.
134 If not set, they are. */
ff28b140 135# define RE_LIMITED_OPS (RE_INTERVALS << 1)
832b75ed
GG
136
137/* If this bit is set, newline is an alternation operator.
138 If not set, newline is literal. */
ff28b140 139# define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
832b75ed 140
ff28b140 141/* If this bit is set, then '{...}' defines an interval, and \{ and \}
832b75ed 142 are literals.
ff28b140
TL
143 If not set, then '\{...\}' defines an interval. */
144# define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
832b75ed
GG
145
146/* If this bit is set, (...) defines a group, and \( and \) are literals.
147 If not set, \(...\) defines a group, and ( and ) are literals. */
ff28b140 148# define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
832b75ed
GG
149
150/* If this bit is set, then \<digit> matches <digit>.
151 If not set, then \<digit> is a back-reference. */
ff28b140 152# define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
832b75ed
GG
153
154/* If this bit is set, then | is an alternation operator, and \| is literal.
155 If not set, then \| is an alternation operator, and | is literal. */
ff28b140 156# define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
832b75ed
GG
157
158/* If this bit is set, then an ending range point collating higher
159 than the starting range point, as in [z-a], is invalid.
160 If not set, then when ending range point collates higher than the
161 starting range point, the range is ignored. */
ff28b140 162# define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
832b75ed
GG
163
164/* If this bit is set, then an unmatched ) is ordinary.
165 If not set, then an unmatched ) is invalid. */
ff28b140 166# define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
832b75ed
GG
167
168/* If this bit is set, succeed as soon as we match the whole pattern,
169 without further backtracking. */
ff28b140 170# define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
832b75ed
GG
171
172/* If this bit is set, do not process the GNU regex operators.
173 If not set, then the GNU regex operators are recognized. */
ff28b140 174# define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1)
832b75ed
GG
175
176/* If this bit is set, turn on internal regex debugging.
177 If not set, and debugging was on, turn it off.
178 This only works if regex.c is compiled -DDEBUG.
179 We define this bit always, so that all that's needed to turn on
180 debugging is to recompile regex.c; the calling code can always have
181 this bit set, and it won't affect anything in the normal case. */
ff28b140 182# define RE_DEBUG (RE_NO_GNU_OPS << 1)
832b75ed
GG
183
184/* If this bit is set, a syntactically invalid interval is treated as
185 a string of ordinary characters. For example, the ERE 'a{1' is
186 treated as 'a\{1'. */
ff28b140 187# define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1)
832b75ed
GG
188
189/* If this bit is set, then ignore case when matching.
190 If not set, then case is significant. */
ff28b140
TL
191# define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1)
192
193/* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only
194 for ^, because it is difficult to scan the regex backwards to find
195 whether ^ should be special. */
196# define RE_CARET_ANCHORS_HERE (RE_ICASE << 1)
197
198/* If this bit is set, then \{ cannot be first in a regex or
199 immediately after an alternation, open-group or \} operator. */
200# define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1)
201
202/* If this bit is set, then no_sub will be set to 1 during
203 re_compile_pattern. */
204# define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1)
205#endif
832b75ed
GG
206
207/* This global variable defines the particular regexp syntax to use (for
208 some interfaces). When a regexp is compiled, the syntax used is
209 stored in the pattern buffer, so changing this does not affect
210 already-compiled regexps. */
211extern reg_syntax_t re_syntax_options;
212\f
ff28b140 213#ifdef __USE_GNU
832b75ed
GG
214/* Define combinations of the above bits for the standard possibilities.
215 (The [[[ comments delimit what gets put into the Texinfo file, so
216 don't delete them!) */
217/* [[[begin syntaxes]]] */
ff28b140 218# define RE_SYNTAX_EMACS 0
832b75ed 219
ff28b140 220# define RE_SYNTAX_AWK \
832b75ed
GG
221 (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
222 | RE_NO_BK_PARENS | RE_NO_BK_REFS \
223 | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
224 | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \
ff28b140 225 | RE_CHAR_CLASSES \
832b75ed
GG
226 | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS)
227
ff28b140
TL
228# define RE_SYNTAX_GNU_AWK \
229 ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \
230 | RE_INVALID_INTERVAL_ORD) \
231 & ~(RE_DOT_NOT_NULL | RE_CONTEXT_INDEP_OPS \
232 | RE_CONTEXT_INVALID_OPS ))
832b75ed 233
ff28b140 234# define RE_SYNTAX_POSIX_AWK \
832b75ed 235 (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \
ff28b140
TL
236 | RE_INTERVALS | RE_NO_GNU_OPS \
237 | RE_INVALID_INTERVAL_ORD)
832b75ed 238
ff28b140
TL
239# define RE_SYNTAX_GREP \
240 ((RE_SYNTAX_POSIX_BASIC | RE_NEWLINE_ALT) \
241 & ~(RE_CONTEXT_INVALID_DUP | RE_DOT_NOT_NULL))
832b75ed 242
ff28b140
TL
243# define RE_SYNTAX_EGREP \
244 ((RE_SYNTAX_POSIX_EXTENDED | RE_INVALID_INTERVAL_ORD | RE_NEWLINE_ALT) \
245 & ~(RE_CONTEXT_INVALID_OPS | RE_DOT_NOT_NULL))
832b75ed 246
ff28b140
TL
247/* POSIX grep -E behavior is no longer incompatible with GNU. */
248# define RE_SYNTAX_POSIX_EGREP \
249 RE_SYNTAX_EGREP
832b75ed
GG
250
251/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
ff28b140 252# define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
832b75ed 253
ff28b140 254# define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
832b75ed
GG
255
256/* Syntax bits common to both basic and extended POSIX regex syntax. */
ff28b140 257# define _RE_SYNTAX_POSIX_COMMON \
832b75ed
GG
258 (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
259 | RE_INTERVALS | RE_NO_EMPTY_RANGES)
260
ff28b140
TL
261# define RE_SYNTAX_POSIX_BASIC \
262 (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP)
832b75ed
GG
263
264/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
265 RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
266 isn't minimal, since other operators, such as \`, aren't disabled. */
ff28b140 267# define RE_SYNTAX_POSIX_MINIMAL_BASIC \
832b75ed
GG
268 (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
269
ff28b140 270# define RE_SYNTAX_POSIX_EXTENDED \
832b75ed
GG
271 (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
272 | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
273 | RE_NO_BK_PARENS | RE_NO_BK_VBAR \
274 | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD)
275
276/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is
277 removed and RE_NO_BK_REFS is added. */
ff28b140 278# define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
832b75ed
GG
279 (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
280 | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
281 | RE_NO_BK_PARENS | RE_NO_BK_REFS \
282 | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
283/* [[[end syntaxes]]] */
ff28b140
TL
284
285/* Maximum number of duplicates an interval can allow. POSIX-conforming
286 systems might define this in <limits.h>, but we want our
832b75ed 287 value, so remove any previous define. */
ff28b140
TL
288# ifdef _REGEX_INCLUDE_LIMITS_H
289# include <limits.h>
290# endif
291# ifdef RE_DUP_MAX
292# undef RE_DUP_MAX
293# endif
294
295/* RE_DUP_MAX is 2**15 - 1 because an earlier implementation stored
296 the counter as a 2-byte signed integer. This is no longer true, so
297 RE_DUP_MAX could be increased to (INT_MAX / 10 - 1), or to
298 ((SIZE_MAX - 9) / 10) if _REGEX_LARGE_OFFSETS is defined.
299 However, there would be a huge performance problem if someone
300 actually used a pattern like a\{214748363\}, so RE_DUP_MAX retains
301 its historical value. */
302# define RE_DUP_MAX (0x7fff)
832b75ed 303#endif
832b75ed
GG
304
305
ff28b140 306/* POSIX 'cflags' bits (i.e., information for 'regcomp'). */
832b75ed
GG
307
308/* If this bit is set, then use extended regular expression syntax.
309 If not set, then use basic regular expression syntax. */
310#define REG_EXTENDED 1
311
312/* If this bit is set, then ignore case when matching.
313 If not set, then case is significant. */
ff28b140 314#define REG_ICASE (1 << 1)
832b75ed
GG
315
316/* If this bit is set, then anchors do not match at newline
317 characters in the string.
318 If not set, then anchors do match at newlines. */
ff28b140 319#define REG_NEWLINE (1 << 2)
832b75ed
GG
320
321/* If this bit is set, then report only success or fail in regexec.
322 If not set, then returns differ between not matching and errors. */
ff28b140 323#define REG_NOSUB (1 << 3)
832b75ed
GG
324
325
ff28b140 326/* POSIX 'eflags' bits (i.e., information for regexec). */
832b75ed
GG
327
328/* If this bit is set, then the beginning-of-line operator doesn't match
329 the beginning of the string (presumably because it's not the
330 beginning of a line).
331 If not set, then the beginning-of-line operator does match the
332 beginning of the string. */
333#define REG_NOTBOL 1
334
335/* Like REG_NOTBOL, except for the end-of-line. */
336#define REG_NOTEOL (1 << 1)
337
ff28b140
TL
338/* Use PMATCH[0] to delimit the start and end of the search in the
339 buffer. */
340#define REG_STARTEND (1 << 2)
341
832b75ed
GG
342
343/* If any error codes are removed, changed, or added, update the
ff28b140
TL
344 '__re_error_msgid' table in regcomp.c. */
345
832b75ed
GG
346typedef enum
347{
ff28b140
TL
348 _REG_ENOSYS = -1, /* This will never happen for this implementation. */
349 _REG_NOERROR = 0, /* Success. */
350 _REG_NOMATCH, /* Didn't find a match (for regexec). */
832b75ed
GG
351
352 /* POSIX regcomp return error codes. (In the order listed in the
353 standard.) */
ff28b140
TL
354 _REG_BADPAT, /* Invalid pattern. */
355 _REG_ECOLLATE, /* Invalid collating element. */
356 _REG_ECTYPE, /* Invalid character class name. */
357 _REG_EESCAPE, /* Trailing backslash. */
358 _REG_ESUBREG, /* Invalid back reference. */
359 _REG_EBRACK, /* Unmatched left bracket. */
360 _REG_EPAREN, /* Parenthesis imbalance. */
361 _REG_EBRACE, /* Unmatched \{. */
362 _REG_BADBR, /* Invalid contents of \{\}. */
363 _REG_ERANGE, /* Invalid range end. */
364 _REG_ESPACE, /* Ran out of memory. */
365 _REG_BADRPT, /* No preceding re for repetition op. */
832b75ed
GG
366
367 /* Error codes we've added. */
ff28b140
TL
368 _REG_EEND, /* Premature end. */
369 _REG_ESIZE, /* Too large (e.g., repeat count too large). */
370 _REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
832b75ed 371} reg_errcode_t;
ff28b140
TL
372
373#if defined _XOPEN_SOURCE || defined __USE_XOPEN2K
374# define REG_ENOSYS _REG_ENOSYS
375#endif
376#define REG_NOERROR _REG_NOERROR
377#define REG_NOMATCH _REG_NOMATCH
378#define REG_BADPAT _REG_BADPAT
379#define REG_ECOLLATE _REG_ECOLLATE
380#define REG_ECTYPE _REG_ECTYPE
381#define REG_EESCAPE _REG_EESCAPE
382#define REG_ESUBREG _REG_ESUBREG
383#define REG_EBRACK _REG_EBRACK
384#define REG_EPAREN _REG_EPAREN
385#define REG_EBRACE _REG_EBRACE
386#define REG_BADBR _REG_BADBR
387#define REG_ERANGE _REG_ERANGE
388#define REG_ESPACE _REG_ESPACE
389#define REG_BADRPT _REG_BADRPT
390#define REG_EEND _REG_EEND
391#define REG_ESIZE _REG_ESIZE
392#define REG_ERPAREN _REG_ERPAREN
832b75ed
GG
393\f
394/* This data structure represents a compiled pattern. Before calling
ff28b140
TL
395 the pattern compiler, the fields 'buffer', 'allocated', 'fastmap',
396 and 'translate' can be set. After the pattern has been compiled,
397 the fields 're_nsub', 'not_bol' and 'not_eol' are available. All
398 other fields are private to the regex routines. */
832b75ed
GG
399
400#ifndef RE_TRANSLATE_TYPE
ff28b140
TL
401# define __RE_TRANSLATE_TYPE unsigned char *
402# ifdef __USE_GNU
403# define RE_TRANSLATE_TYPE __RE_TRANSLATE_TYPE
404# endif
405#endif
406
407#ifdef __USE_GNU
408# define __REPB_PREFIX(name) name
409#else
410# define __REPB_PREFIX(name) __##name
832b75ed
GG
411#endif
412
413struct re_pattern_buffer
414{
ff28b140
TL
415 /* Space that holds the compiled pattern. The type
416 'struct re_dfa_t' is private and is not declared here. */
417 struct re_dfa_t *__REPB_PREFIX(buffer);
832b75ed 418
ff28b140
TL
419 /* Number of bytes to which 'buffer' points. */
420 __re_long_size_t __REPB_PREFIX(allocated);
832b75ed 421
ff28b140
TL
422 /* Number of bytes actually used in 'buffer'. */
423 __re_long_size_t __REPB_PREFIX(used);
832b75ed 424
ff28b140
TL
425 /* Syntax setting with which the pattern was compiled. */
426 reg_syntax_t __REPB_PREFIX(syntax);
832b75ed 427
ff28b140
TL
428 /* Pointer to a fastmap, if any, otherwise zero. re_search uses the
429 fastmap, if there is one, to skip over impossible starting points
430 for matches. */
431 char *__REPB_PREFIX(fastmap);
832b75ed 432
ff28b140
TL
433 /* Either a translate table to apply to all characters before
434 comparing them, or zero for no translation. The translation is
435 applied to a pattern when it is compiled and to a string when it
436 is matched. */
437 __RE_TRANSLATE_TYPE __REPB_PREFIX(translate);
832b75ed 438
ff28b140 439 /* Number of subexpressions found by the compiler. */
832b75ed
GG
440 size_t re_nsub;
441
ff28b140
TL
442 /* Zero if this pattern cannot match the empty string, one else.
443 Well, in truth it's used only in 're_search_2', to see whether or
444 not we should use the fastmap, so we don't set this absolutely
445 perfectly; see 're_compile_fastmap' (the "duplicate" case). */
446 unsigned __REPB_PREFIX(can_be_null) : 1;
447
448 /* If REGS_UNALLOCATED, allocate space in the 'regs' structure
449 for 'max (RE_NREGS, re_nsub + 1)' groups.
450 If REGS_REALLOCATE, reallocate space if necessary.
451 If REGS_FIXED, use what's there. */
452#ifdef __USE_GNU
453# define REGS_UNALLOCATED 0
454# define REGS_REALLOCATE 1
455# define REGS_FIXED 2
456#endif
457 unsigned __REPB_PREFIX(regs_allocated) : 2;
458
459 /* Set to zero when 're_compile_pattern' compiles a pattern; set to
460 one by 're_compile_fastmap' if it updates the fastmap. */
461 unsigned __REPB_PREFIX(fastmap_accurate) : 1;
462
463 /* If set, 're_match_2' does not return information about
464 subexpressions. */
465 unsigned __REPB_PREFIX(no_sub) : 1;
466
467 /* If set, a beginning-of-line anchor doesn't match at the beginning
468 of the string. */
469 unsigned __REPB_PREFIX(not_bol) : 1;
470
471 /* Similarly for an end-of-line anchor. */
472 unsigned __REPB_PREFIX(not_eol) : 1;
473
474 /* If true, an anchor at a newline matches. */
475 unsigned __REPB_PREFIX(newline_anchor) : 1;
832b75ed
GG
476};
477
478typedef struct re_pattern_buffer regex_t;
479\f
480/* Type for byte offsets within the string. POSIX mandates this. */
ff28b140
TL
481#ifdef _REGEX_LARGE_OFFSETS
482/* POSIX 1003.1-2008 requires that regoff_t be at least as wide as
483 ptrdiff_t and ssize_t. We don't know of any hosts where ptrdiff_t
484 is wider than ssize_t, so ssize_t is safe. ptrdiff_t is not
485 visible here, so use ssize_t. */
486typedef ssize_t regoff_t;
487#else
488/* The traditional GNU regex implementation mishandles strings longer
489 than INT_MAX. */
832b75ed 490typedef int regoff_t;
ff28b140 491#endif
832b75ed
GG
492
493
ff28b140 494#ifdef __USE_GNU
832b75ed
GG
495/* This is the structure we store register match data in. See
496 regex.texinfo for a full description of what registers match. */
497struct re_registers
498{
ff28b140 499 __re_size_t num_regs;
832b75ed
GG
500 regoff_t *start;
501 regoff_t *end;
502};
503
504
ff28b140
TL
505/* If 'regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
506 're_match_2' returns information about at least this many registers
507 the first time a 'regs' structure is passed. */
508# ifndef RE_NREGS
509# define RE_NREGS 30
510# endif
832b75ed
GG
511#endif
512
513
514/* POSIX specification for registers. Aside from the different names than
ff28b140 515 're_registers', POSIX uses an array of structures, instead of a
832b75ed
GG
516 structure of arrays. */
517typedef struct
518{
519 regoff_t rm_so; /* Byte offset from string's start to substring's start. */
520 regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
521} regmatch_t;
522\f
523/* Declarations for routines. */
524
ff28b140 525#ifdef __USE_GNU
832b75ed 526/* Sets the current default syntax to SYNTAX, and return the old syntax.
ff28b140
TL
527 You can also simply assign to the 're_syntax_options' variable. */
528extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax);
832b75ed
GG
529
530/* Compile the regular expression PATTERN, with length LENGTH
ff28b140
TL
531 and syntax given by the global 're_syntax_options', into the buffer
532 BUFFER. Return NULL if successful, and an error string if not.
533
534 To free the allocated storage, you must call 'regfree' on BUFFER.
535 Note that the translate table must either have been initialized by
536 'regcomp', with a malloc'ed value, or set to NULL before calling
537 'regfree'. */
538extern const char *re_compile_pattern (const char *__pattern, size_t __length,
539 struct re_pattern_buffer *__buffer);
832b75ed
GG
540
541
542/* Compile a fastmap for the compiled pattern in BUFFER; used to
543 accelerate searches. Return 0 if successful and -2 if was an
544 internal error. */
ff28b140 545extern int re_compile_fastmap (struct re_pattern_buffer *__buffer);
832b75ed
GG
546
547
548/* Search in the string STRING (with length LENGTH) for the pattern
549 compiled into BUFFER. Start searching at position START, for RANGE
550 characters. Return the starting position of the match, -1 for no
551 match, or -2 for an internal error. Also return register
552 information in REGS (if REGS and BUFFER->no_sub are nonzero). */
ff28b140
TL
553extern regoff_t re_search (struct re_pattern_buffer *__buffer,
554 const char *__String, regoff_t __length,
555 regoff_t __start, regoff_t __range,
556 struct re_registers *__regs);
832b75ed
GG
557
558
ff28b140 559/* Like 're_search', but search in the concatenation of STRING1 and
832b75ed 560 STRING2. Also, stop searching at index START + STOP. */
ff28b140
TL
561extern regoff_t re_search_2 (struct re_pattern_buffer *__buffer,
562 const char *__string1, regoff_t __length1,
563 const char *__string2, regoff_t __length2,
564 regoff_t __start, regoff_t __range,
565 struct re_registers *__regs,
566 regoff_t __stop);
832b75ed
GG
567
568
ff28b140 569/* Like 're_search', but return how many characters in STRING the regexp
832b75ed 570 in BUFFER matched, starting at position START. */
ff28b140
TL
571extern regoff_t re_match (struct re_pattern_buffer *__buffer,
572 const char *__String, regoff_t __length,
573 regoff_t __start, struct re_registers *__regs);
832b75ed
GG
574
575
ff28b140
TL
576/* Relates to 're_match' as 're_search_2' relates to 're_search'. */
577extern regoff_t re_match_2 (struct re_pattern_buffer *__buffer,
578 const char *__string1, regoff_t __length1,
579 const char *__string2, regoff_t __length2,
580 regoff_t __start, struct re_registers *__regs,
581 regoff_t __stop);
832b75ed
GG
582
583
584/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
585 ENDS. Subsequent matches using BUFFER and REGS will use this memory
586 for recording register information. STARTS and ENDS must be
ff28b140 587 allocated with malloc, and must each be at least 'NUM_REGS * sizeof
832b75ed
GG
588 (regoff_t)' bytes long.
589
590 If NUM_REGS == 0, then subsequent matches should allocate their own
591 register data.
592
593 Unless this function is called, the first search or match using
ff28b140 594 BUFFER will allocate its own register data, without
832b75ed 595 freeing the old data. */
ff28b140
TL
596extern void re_set_registers (struct re_pattern_buffer *__buffer,
597 struct re_registers *__regs,
598 __re_size_t __num_regs,
599 regoff_t *__starts, regoff_t *__ends);
600#endif /* Use GNU */
832b75ed 601
ff28b140 602#if defined _REGEX_RE_COMP || (defined _LIBC && defined __USE_MISC)
832b75ed
GG
603# ifndef _CRAY
604/* 4.2 bsd compatibility. */
ff28b140
TL
605extern char *re_comp (const char *);
606extern int re_exec (const char *);
832b75ed
GG
607# endif
608#endif
609
ff28b140
TL
610/* For plain 'restrict', use glibc's __restrict if defined.
611 Otherwise, GCC 2.95 and later have "__restrict"; C99 compilers have
612 "restrict", and "configure" may have defined "restrict".
613 Other compilers use __restrict, __restrict__, and _Restrict, and
614 'configure' might #define 'restrict' to those words, so pick a
615 different name. */
616#ifndef _Restrict_
617# if defined __restrict || 2 < __GNUC__ + (95 <= __GNUC_MINOR__)
618# define _Restrict_ __restrict
619# elif 199901L <= __STDC_VERSION__ || defined restrict
620# define _Restrict_ restrict
621# else
622# define _Restrict_
832b75ed
GG
623# endif
624#endif
ff28b140
TL
625/* For [restrict], use glibc's __restrict_arr if available.
626 Otherwise, GCC 3.1 (not in C++ mode) and C99 support [restrict]. */
627#ifndef _Restrict_arr_
628# ifdef __restrict_arr
629# define _Restrict_arr_ __restrict_arr
630# elif ((199901L <= __STDC_VERSION__ || 3 < __GNUC__ + (1 <= __GNUC_MINOR__)) \
631 && !defined __GNUG__)
632# define _Restrict_arr_ _Restrict_
832b75ed 633# else
ff28b140 634# define _Restrict_arr_
832b75ed
GG
635# endif
636#endif
637
638/* POSIX compatibility. */
ff28b140
TL
639extern int regcomp (regex_t *_Restrict_ __preg,
640 const char *_Restrict_ __pattern,
641 int __cflags);
832b75ed 642
ff28b140
TL
643extern int regexec (const regex_t *_Restrict_ __preg,
644 const char *_Restrict_ __String, size_t __nmatch,
645 regmatch_t __pmatch[_Restrict_arr_],
646 int __eflags);
832b75ed 647
ff28b140
TL
648extern size_t regerror (int __errcode, const regex_t *_Restrict_ __preg,
649 char *_Restrict_ __errbuf, size_t __errbuf_size);
832b75ed 650
ff28b140 651extern void regfree (regex_t *__preg);
832b75ed
GG
652
653
654#ifdef __cplusplus
655}
656#endif /* C++ */
657
658#endif /* regex.h */