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