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