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