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