source: trunk/essentials/app-arch/tar/lib/regex.h

Last change on this file was 3342, checked in by bird, 18 years ago

tar 1.16.1

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