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