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