1 |
/* Definitions for data structures and routines for the regular |
/* Definitions for data structures and routines for the regular |
2 |
expression library. |
expression library. |
3 |
Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003 |
Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003,2005 |
4 |
Free Software Foundation, Inc. |
Free Software Foundation, Inc. |
5 |
This file is part of the GNU C Library. |
This file is part of the GNU C Library. |
6 |
|
|
28 |
extern "C" { |
extern "C" { |
29 |
#endif |
#endif |
30 |
|
|
31 |
/* POSIX says that <sys/types.h> must be included (by the caller) before |
/* Define _REGEX_SOURCE to get definitions that are incompatible with |
32 |
<regex.h>. */ |
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 _POSIX_C_SOURCE && !defined _POSIX_SOURCE && defined VMS |
#if defined _REGEX_SOURCE && defined VMS |
41 |
/* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it |
/* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it |
42 |
should be there. */ |
should be there. */ |
43 |
# include <stddef.h> |
# include <stddef.h> |
44 |
#endif |
#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. */ |
60 |
|
typedef 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. */ |
65 |
|
typedef size_t __re_idx_t; |
66 |
|
|
67 |
|
/* The type of object sizes. */ |
68 |
|
typedef size_t __re_size_t; |
69 |
|
|
70 |
|
/* The type of object sizes, in places where the traditional code |
71 |
|
uses unsigned long int. */ |
72 |
|
typedef 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 |
|
|
79 |
|
typedef int regoff_t; |
80 |
|
typedef int __re_idx_t; |
81 |
|
typedef unsigned int __re_size_t; |
82 |
|
typedef unsigned long int __re_long_size_t; |
83 |
|
|
84 |
|
#endif |
85 |
|
|
86 |
/* The following two types have to be signed and unsigned integer type |
/* 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 |
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 |
ptrdiff_t and size_t should be likely OK. Still size of these two |
99 |
|
|
100 |
/* If this bit is not set, then \ inside a bracket expression is literal. |
/* If this bit is not set, then \ inside a bracket expression is literal. |
101 |
If set, then such a \ quotes the following character. */ |
If set, then such a \ quotes the following character. */ |
102 |
#define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1) |
#define REG_BACKSLASH_ESCAPE_IN_LISTS 1ul |
103 |
|
|
104 |
/* If this bit is not set, then + and ? are operators, and \+ and \? are |
/* If this bit is not set, then + and ? are operators, and \+ and \? are |
105 |
literals. |
literals. |
106 |
If set, then \+ and \? are operators and + and ? are literals. */ |
If set, then \+ and \? are operators and + and ? are literals. */ |
107 |
#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1) |
#define REG_BK_PLUS_QM (1ul << 1) |
108 |
|
|
109 |
/* If this bit is set, then character classes are supported. They are: |
/* If this bit is set, then character classes are supported. They are: |
110 |
[:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], |
[:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], |
111 |
[:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. |
[:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. |
112 |
If not set, then character classes are not supported. */ |
If not set, then character classes are not supported. */ |
113 |
#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1) |
#define REG_CHAR_CLASSES (1ul << 2) |
114 |
|
|
115 |
/* If this bit is set, then ^ and $ are always anchors (outside bracket |
/* If this bit is set, then ^ and $ are always anchors (outside bracket |
116 |
expressions, of course). |
expressions, of course). |
120 |
$ is an anchor if it is at the end of a regular expression, or |
$ is an anchor if it is at the end of a regular expression, or |
121 |
before a close-group or an alternation operator. |
before a close-group or an alternation operator. |
122 |
|
|
123 |
This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because |
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. |
POSIX draft 11.2 says that * etc. in leading positions is undefined. |
125 |
We already implemented a previous draft which made those constructs |
We already implemented a previous draft which made those constructs |
126 |
invalid, though, so we haven't changed the code back. */ |
invalid, though, so we haven't changed the code back. */ |
127 |
#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1) |
#define REG_CONTEXT_INDEP_ANCHORS (1ul << 3) |
128 |
|
|
129 |
/* If this bit is set, then special characters are always special |
/* If this bit is set, then special characters are always special |
130 |
regardless of where they are in the pattern. |
regardless of where they are in the pattern. |
132 |
some contexts; otherwise they are ordinary. Specifically, |
some contexts; otherwise they are ordinary. Specifically, |
133 |
* + ? and intervals are only special when not after the beginning, |
* + ? and intervals are only special when not after the beginning, |
134 |
open-group, or alternation operator. */ |
open-group, or alternation operator. */ |
135 |
#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1) |
#define REG_CONTEXT_INDEP_OPS (1ul << 4) |
136 |
|
|
137 |
/* If this bit is set, then *, +, ?, and { cannot be first in an re or |
/* If this bit is set, then *, +, ?, and { cannot be first in an re or |
138 |
immediately after an alternation or begin-group operator. */ |
immediately after an alternation or begin-group operator. */ |
139 |
#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1) |
#define REG_CONTEXT_INVALID_OPS (1ul << 5) |
140 |
|
|
141 |
/* If this bit is set, then . matches newline. |
/* If this bit is set, then . matches newline. |
142 |
If not set, then it doesn't. */ |
If not set, then it doesn't. */ |
143 |
#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1) |
#define REG_DOT_NEWLINE (1ul << 6) |
144 |
|
|
145 |
/* If this bit is set, then . doesn't match NUL. |
/* If this bit is set, then . doesn't match NUL. |
146 |
If not set, then it does. */ |
If not set, then it does. */ |
147 |
#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1) |
#define REG_DOT_NOT_NULL (1ul << 7) |
148 |
|
|
149 |
/* If this bit is set, nonmatching lists [^...] do not match newline. |
/* If this bit is set, nonmatching lists [^...] do not match newline. |
150 |
If not set, they do. */ |
If not set, they do. */ |
151 |
#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1) |
#define REG_HAT_LISTS_NOT_NEWLINE (1ul << 8) |
152 |
|
|
153 |
/* If this bit is set, either \{...\} or {...} defines an |
/* If this bit is set, either \{...\} or {...} defines an |
154 |
interval, depending on RE_NO_BK_BRACES. |
interval, depending on REG_NO_BK_BRACES. |
155 |
If not set, \{, \}, {, and } are literals. */ |
If not set, \{, \}, {, and } are literals. */ |
156 |
#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1) |
#define REG_INTERVALS (1ul << 9) |
157 |
|
|
158 |
/* If this bit is set, +, ? and | aren't recognized as operators. |
/* If this bit is set, +, ? and | aren't recognized as operators. |
159 |
If not set, they are. */ |
If not set, they are. */ |
160 |
#define RE_LIMITED_OPS (RE_INTERVALS << 1) |
#define REG_LIMITED_OPS (1ul << 10) |
161 |
|
|
162 |
/* If this bit is set, newline is an alternation operator. |
/* If this bit is set, newline is an alternation operator. |
163 |
If not set, newline is literal. */ |
If not set, newline is literal. */ |
164 |
#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1) |
#define REG_NEWLINE_ALT (1ul << 11) |
165 |
|
|
166 |
/* If this bit is set, then `{...}' defines an interval, and \{ and \} |
/* If this bit is set, then `{...}' defines an interval, and \{ and \} |
167 |
are literals. |
are literals. |
168 |
If not set, then `\{...\}' defines an interval. */ |
If not set, then `\{...\}' defines an interval. */ |
169 |
#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1) |
#define REG_NO_BK_BRACES (1ul << 12) |
170 |
|
|
171 |
/* If this bit is set, (...) defines a group, and \( and \) are literals. |
/* If this bit is set, (...) defines a group, and \( and \) are literals. |
172 |
If not set, \(...\) defines a group, and ( and ) are literals. */ |
If not set, \(...\) defines a group, and ( and ) are literals. */ |
173 |
#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1) |
#define REG_NO_BK_PARENS (1ul << 13) |
174 |
|
|
175 |
/* If this bit is set, then \<digit> matches <digit>. |
/* If this bit is set, then \<digit> matches <digit>. |
176 |
If not set, then \<digit> is a back-reference. */ |
If not set, then \<digit> is a back-reference. */ |
177 |
#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1) |
#define REG_NO_BK_REFS (1ul << 14) |
178 |
|
|
179 |
/* If this bit is set, then | is an alternation operator, and \| is literal. |
/* 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. */ |
If not set, then \| is an alternation operator, and | is literal. */ |
181 |
#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1) |
#define REG_NO_BK_VBAR (1ul << 15) |
182 |
|
|
183 |
/* If this bit is set, then an ending range point collating higher |
/* If this bit is set, then an ending range point collating higher |
184 |
than the starting range point, as in [z-a], is invalid. |
than the starting range point, as in [z-a], is invalid. |
185 |
If not set, then when ending range point collates higher than the |
If not set, the containing range is empty and does not match any string. */ |
186 |
starting range point, the range is ignored. */ |
#define REG_NO_EMPTY_RANGES (1ul << 16) |
|
#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1) |
|
187 |
|
|
188 |
/* If this bit is set, then an unmatched ) is ordinary. |
/* If this bit is set, then an unmatched ) is ordinary. |
189 |
If not set, then an unmatched ) is invalid. */ |
If not set, then an unmatched ) is invalid. */ |
190 |
#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1) |
#define REG_UNMATCHED_RIGHT_PAREN_ORD (1ul << 17) |
191 |
|
|
192 |
/* If this bit is set, succeed as soon as we match the whole pattern, |
/* If this bit is set, succeed as soon as we match the whole pattern, |
193 |
without further backtracking. */ |
without further backtracking. */ |
194 |
#define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1) |
#define REG_NO_POSIX_BACKTRACKING (1ul << 18) |
195 |
|
|
196 |
/* If this bit is set, do not process the GNU regex operators. |
/* If this bit is set, do not process the GNU regex operators. |
197 |
If not set, then the GNU regex operators are recognized. */ |
If not set, then the GNU regex operators are recognized. */ |
198 |
#define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1) |
#define REG_NO_GNU_OPS (1ul << 19) |
199 |
|
|
200 |
/* If this bit is set, turn on internal regex debugging. |
/* If this bit is set, turn on internal regex debugging. |
201 |
If not set, and debugging was on, turn it off. |
If not set, and debugging was on, turn it off. |
203 |
We define this bit always, so that all that's needed to turn on |
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 |
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. */ |
this bit set, and it won't affect anything in the normal case. */ |
206 |
#define RE_DEBUG (RE_NO_GNU_OPS << 1) |
#define REG_DEBUG (1ul << 20) |
207 |
|
|
208 |
/* If this bit is set, a syntactically invalid interval is treated as |
/* 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 |
a string of ordinary characters. For example, the ERE 'a{1' is |
210 |
treated as 'a\{1'. */ |
treated as 'a\{1'. */ |
211 |
#define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1) |
#define REG_INVALID_INTERVAL_ORD (1ul << 21) |
212 |
|
|
213 |
/* If this bit is set, then ignore case when matching. |
/* If this bit is set, then ignore case when matching. |
214 |
If not set, then case is significant. */ |
If not set, then case is significant. */ |
215 |
#define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1) |
#define REG_IGNORE_CASE (1ul << 22) |
216 |
|
|
217 |
/* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only |
/* 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 |
for ^, because it is difficult to scan the regex backwards to find |
219 |
whether ^ should be special. */ |
whether ^ should be special. */ |
220 |
#define RE_CARET_ANCHORS_HERE (RE_ICASE << 1) |
#define REG_CARET_ANCHORS_HERE (1ul << 23) |
221 |
|
|
222 |
/* If this bit is set, then \{ cannot be first in an bre or |
/* If this bit is set, then \{ cannot be first in an bre or |
223 |
immediately after an alternation or begin-group operator. */ |
immediately after an alternation or begin-group operator. */ |
224 |
#define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1) |
#define REG_CONTEXT_INVALID_DUP (1ul << 24) |
225 |
|
|
226 |
/* If this bit is set, then no_sub will be set to 1 during |
/* If this bit is set, then no_sub will be set to 1 during |
227 |
re_compile_pattern. */ |
re_compile_pattern. */ |
228 |
#define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1) |
#define REG_NO_SUB (1ul << 25) |
229 |
|
|
230 |
/* This global variable defines the particular regexp syntax to use (for |
/* This global variable defines the particular regexp syntax to use (for |
231 |
some interfaces). When a regexp is compiled, the syntax used is |
some interfaces). When a regexp is compiled, the syntax used is |
237 |
(The [[[ comments delimit what gets put into the Texinfo file, so |
(The [[[ comments delimit what gets put into the Texinfo file, so |
238 |
don't delete them!) */ |
don't delete them!) */ |
239 |
/* [[[begin syntaxes]]] */ |
/* [[[begin syntaxes]]] */ |
240 |
#define RE_SYNTAX_EMACS 0 |
#define REG_SYNTAX_EMACS 0 |
241 |
|
|
242 |
#define RE_SYNTAX_AWK \ |
#define REG_SYNTAX_AWK \ |
243 |
(RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ |
(REG_BACKSLASH_ESCAPE_IN_LISTS | REG_DOT_NOT_NULL \ |
244 |
| RE_NO_BK_PARENS | RE_NO_BK_REFS \ |
| REG_NO_BK_PARENS | REG_NO_BK_REFS \ |
245 |
| RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ |
| REG_NO_BK_VBAR | REG_NO_EMPTY_RANGES \ |
246 |
| RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \ |
| REG_DOT_NEWLINE | REG_CONTEXT_INDEP_ANCHORS \ |
247 |
| RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS) |
| REG_UNMATCHED_RIGHT_PAREN_ORD | REG_NO_GNU_OPS) |
248 |
|
|
249 |
#define RE_SYNTAX_GNU_AWK \ |
#define REG_SYNTAX_GNU_AWK \ |
250 |
((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG) \ |
((REG_SYNTAX_POSIX_EXTENDED | REG_BACKSLASH_ESCAPE_IN_LISTS \ |
251 |
& ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS \ |
| REG_DEBUG) \ |
252 |
| RE_CONTEXT_INVALID_OPS )) |
& ~(REG_DOT_NOT_NULL | REG_INTERVALS | REG_CONTEXT_INDEP_OPS \ |
253 |
|
| REG_CONTEXT_INVALID_OPS )) |
254 |
#define RE_SYNTAX_POSIX_AWK \ |
|
255 |
(RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ |
#define REG_SYNTAX_POSIX_AWK \ |
256 |
| RE_INTERVALS | RE_NO_GNU_OPS) |
(REG_SYNTAX_POSIX_EXTENDED | REG_BACKSLASH_ESCAPE_IN_LISTS \ |
257 |
|
| REG_INTERVALS | REG_NO_GNU_OPS) |
258 |
#define RE_SYNTAX_GREP \ |
|
259 |
(RE_BK_PLUS_QM | RE_CHAR_CLASSES \ |
#define REG_SYNTAX_GREP \ |
260 |
| RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \ |
(REG_BK_PLUS_QM | REG_CHAR_CLASSES \ |
261 |
| RE_NEWLINE_ALT) |
| REG_HAT_LISTS_NOT_NEWLINE | REG_INTERVALS \ |
262 |
|
| REG_NEWLINE_ALT) |
263 |
#define RE_SYNTAX_EGREP \ |
|
264 |
(RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ |
#define REG_SYNTAX_EGREP \ |
265 |
| RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \ |
(REG_CHAR_CLASSES | REG_CONTEXT_INDEP_ANCHORS \ |
266 |
| RE_NEWLINE_ALT | RE_NO_BK_PARENS \ |
| REG_CONTEXT_INDEP_OPS | REG_HAT_LISTS_NOT_NEWLINE \ |
267 |
| RE_NO_BK_VBAR) |
| REG_NEWLINE_ALT | REG_NO_BK_PARENS \ |
268 |
|
| REG_NO_BK_VBAR) |
269 |
#define RE_SYNTAX_POSIX_EGREP \ |
|
270 |
(RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \ |
#define REG_SYNTAX_POSIX_EGREP \ |
271 |
| RE_INVALID_INTERVAL_ORD) |
(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. */ |
/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ |
275 |
#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC |
#define REG_SYNTAX_ED REG_SYNTAX_POSIX_BASIC |
276 |
|
|
277 |
#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC |
#define REG_SYNTAX_SED REG_SYNTAX_POSIX_BASIC |
278 |
|
|
279 |
/* Syntax bits common to both basic and extended POSIX regex syntax. */ |
/* Syntax bits common to both basic and extended POSIX regex syntax. */ |
280 |
#define _RE_SYNTAX_POSIX_COMMON \ |
#define _REG_SYNTAX_POSIX_COMMON \ |
281 |
(RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ |
(REG_CHAR_CLASSES | REG_DOT_NEWLINE | REG_DOT_NOT_NULL \ |
282 |
| RE_INTERVALS | RE_NO_EMPTY_RANGES) |
| REG_INTERVALS | REG_NO_EMPTY_RANGES) |
283 |
|
|
284 |
#define RE_SYNTAX_POSIX_BASIC \ |
#define REG_SYNTAX_POSIX_BASIC \ |
285 |
(_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP) |
(_REG_SYNTAX_POSIX_COMMON | REG_BK_PLUS_QM | REG_CONTEXT_INVALID_DUP) |
286 |
|
|
287 |
/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes |
/* Differs from ..._POSIX_BASIC only in that REG_BK_PLUS_QM becomes |
288 |
RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this |
REG_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this |
289 |
isn't minimal, since other operators, such as \`, aren't disabled. */ |
isn't minimal, since other operators, such as \`, aren't disabled. */ |
290 |
#define RE_SYNTAX_POSIX_MINIMAL_BASIC \ |
#define REG_SYNTAX_POSIX_MINIMAL_BASIC \ |
291 |
(_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) |
(_REG_SYNTAX_POSIX_COMMON | REG_LIMITED_OPS) |
292 |
|
|
293 |
#define RE_SYNTAX_POSIX_EXTENDED \ |
#define REG_SYNTAX_POSIX_EXTENDED \ |
294 |
(_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ |
(_REG_SYNTAX_POSIX_COMMON | REG_CONTEXT_INDEP_ANCHORS \ |
295 |
| RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ |
| REG_CONTEXT_INDEP_OPS | REG_NO_BK_BRACES \ |
296 |
| RE_NO_BK_PARENS | RE_NO_BK_VBAR \ |
| REG_NO_BK_PARENS | REG_NO_BK_VBAR \ |
297 |
| RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD) |
| REG_CONTEXT_INVALID_OPS | REG_UNMATCHED_RIGHT_PAREN_ORD) |
298 |
|
|
299 |
/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is |
/* Differs from ..._POSIX_EXTENDED in that REG_CONTEXT_INDEP_OPS is |
300 |
removed and RE_NO_BK_REFS is added. */ |
removed and REG_NO_BK_REFS is added. */ |
301 |
#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ |
#define REG_SYNTAX_POSIX_MINIMAL_EXTENDED \ |
302 |
(_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ |
(_REG_SYNTAX_POSIX_COMMON | REG_CONTEXT_INDEP_ANCHORS \ |
303 |
| RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ |
| REG_CONTEXT_INVALID_OPS | REG_NO_BK_BRACES \ |
304 |
| RE_NO_BK_PARENS | RE_NO_BK_REFS \ |
| REG_NO_BK_PARENS | REG_NO_BK_REFS \ |
305 |
| RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) |
| REG_NO_BK_VBAR | REG_UNMATCHED_RIGHT_PAREN_ORD) |
306 |
/* [[[end syntaxes]]] */ |
/* [[[end syntaxes]]] */ |
307 |
|
|
308 |
/* Maximum number of duplicates an interval can allow. Some systems |
/* Maximum number of duplicates an interval can allow. This is |
309 |
(erroneously) define this in other header files, but we want our |
distinct from RE_DUP_MAX, to conform to POSIX name space rules and |
310 |
value, so remove any previous define. */ |
to avoid collisions with <limits.h>. */ |
311 |
#ifdef RE_DUP_MAX |
#define REG_DUP_MAX 32767 |
|
# undef RE_DUP_MAX |
|
|
#endif |
|
|
/* If sizeof(int) == 2, then ((1 << 15) - 1) overflows. */ |
|
|
#define RE_DUP_MAX (0x7fff) |
|
312 |
|
|
313 |
|
|
314 |
/* POSIX `cflags' bits (i.e., information for `regcomp'). */ |
/* POSIX `cflags' bits (i.e., information for `regcomp'). */ |
319 |
|
|
320 |
/* If this bit is set, then ignore case when matching. |
/* If this bit is set, then ignore case when matching. |
321 |
If not set, then case is significant. */ |
If not set, then case is significant. */ |
322 |
#define REG_ICASE (REG_EXTENDED << 1) |
#define REG_ICASE (1 << 1) |
323 |
|
|
324 |
/* If this bit is set, then anchors do not match at newline |
/* If this bit is set, then anchors do not match at newline |
325 |
characters in the string. |
characters in the string. |
326 |
If not set, then anchors do match at newlines. */ |
If not set, then anchors do match at newlines. */ |
327 |
#define REG_NEWLINE (REG_ICASE << 1) |
#define REG_NEWLINE (1 << 2) |
328 |
|
|
329 |
/* If this bit is set, then report only success or fail in regexec. |
/* 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. */ |
If not set, then returns differ between not matching and errors. */ |
331 |
#define REG_NOSUB (REG_NEWLINE << 1) |
#define REG_NOSUB (1 << 3) |
332 |
|
|
333 |
|
|
334 |
/* POSIX `eflags' bits (i.e., information for regexec). */ |
/* POSIX `eflags' bits (i.e., information for regexec). */ |
349 |
|
|
350 |
|
|
351 |
/* If any error codes are removed, changed, or added, update the |
/* If any error codes are removed, changed, or added, update the |
352 |
`re_error_msg' table in regex.c. */ |
`__re_error_msgid' table in regcomp.c. */ |
353 |
|
|
354 |
typedef enum |
typedef enum |
355 |
{ |
{ |
356 |
#ifdef _XOPEN_SOURCE |
_REG_ENOSYS = -1, /* This will never happen for this implementation. */ |
357 |
REG_ENOSYS = -1, /* This will never happen for this implementation. */ |
#define REG_ENOSYS _REG_ENOSYS |
|
#endif |
|
358 |
|
|
359 |
REG_NOERROR = 0, /* Success. */ |
_REG_NOERROR, /* Success. */ |
360 |
REG_NOMATCH, /* Didn't find a match (for regexec). */ |
#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 |
/* POSIX regcomp return error codes. (In the order listed in the |
366 |
standard.) */ |
standard.) */ |
367 |
REG_BADPAT, /* Invalid pattern. */ |
|
368 |
REG_ECOLLATE, /* Inalid collating element. */ |
_REG_BADPAT, /* Invalid pattern. */ |
369 |
REG_ECTYPE, /* Invalid character class name. */ |
#define REG_BADPAT _REG_BADPAT |
370 |
REG_EESCAPE, /* Trailing backslash. */ |
|
371 |
REG_ESUBREG, /* Invalid back reference. */ |
_REG_ECOLLATE, /* Inalid collating element. */ |
372 |
REG_EBRACK, /* Unmatched left bracket. */ |
#define REG_ECOLLATE _REG_ECOLLATE |
373 |
REG_EPAREN, /* Parenthesis imbalance. */ |
|
374 |
REG_EBRACE, /* Unmatched \{. */ |
_REG_ECTYPE, /* Invalid character class name. */ |
375 |
REG_BADBR, /* Invalid contents of \{\}. */ |
#define REG_ECTYPE _REG_ECTYPE |
376 |
REG_ERANGE, /* Invalid range end. */ |
|
377 |
REG_ESPACE, /* Ran out of memory. */ |
_REG_EESCAPE, /* Trailing backslash. */ |
378 |
REG_BADRPT, /* No preceding re for repetition op. */ |
#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. */ |
/* Error codes we've added. */ |
405 |
REG_EEND, /* Premature end. */ |
|
406 |
REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ |
_REG_EEND, /* Premature end. */ |
407 |
REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ |
#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; |
} 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 |
/* This data structure represents a compiled pattern. Before calling |
445 |
the pattern compiler, the fields `buffer', `allocated', `fastmap', |
the pattern compiler), the fields `re_buffer', `re_allocated', `re_fastmap', |
446 |
`translate', and `no_sub' can be set. After the pattern has been |
`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 |
compiled, the `re_nsub' field is available. All other fields are |
448 |
private to the regex routines. */ |
private to the regex routines. */ |
449 |
|
|
|
#ifndef RE_TRANSLATE_TYPE |
|
|
# define RE_TRANSLATE_TYPE char * |
|
|
#endif |
|
|
|
|
450 |
struct re_pattern_buffer |
struct re_pattern_buffer |
451 |
{ |
{ |
452 |
/* [[[begin pattern_buffer]]] */ |
/* [[[begin pattern_buffer]]] */ |
453 |
/* Space that holds the compiled pattern. It is declared as |
/* Space that holds the compiled pattern. It is declared as |
454 |
`unsigned char *' because its elements are |
`unsigned char *' because its elements are |
455 |
sometimes used as array indexes. */ |
sometimes used as array indexes. */ |
456 |
unsigned char *buffer; |
unsigned char *_REG_RE_NAME (buffer); |
457 |
|
|
458 |
/* Number of bytes to which `buffer' points. */ |
/* Number of bytes to which `re_buffer' points. */ |
459 |
unsigned long int allocated; |
__re_long_size_t _REG_RE_NAME (allocated); |
460 |
|
|
461 |
/* Number of bytes actually used in `buffer'. */ |
/* Number of bytes actually used in `re_buffer'. */ |
462 |
unsigned long int used; |
__re_long_size_t _REG_RE_NAME (used); |
463 |
|
|
464 |
/* Syntax setting with which the pattern was compiled. */ |
/* Syntax setting with which the pattern was compiled. */ |
465 |
reg_syntax_t syntax; |
reg_syntax_t _REG_RE_NAME (syntax); |
466 |
|
|
467 |
/* Pointer to a fastmap, if any, otherwise zero. re_search uses |
/* Pointer to a fastmap, if any, otherwise zero. re_search uses |
468 |
the fastmap, if there is one, to skip over impossible |
the fastmap, if there is one, to skip over impossible |
469 |
starting points for matches. */ |
starting points for matches. */ |
470 |
char *fastmap; |
char *_REG_RE_NAME (fastmap); |
471 |
|
|
472 |
/* Either a translate table to apply to all characters before |
/* Either a translate table to apply to all characters before |
473 |
comparing them, or zero for no translation. The translation |
comparing them, or zero for no translation. The translation |
474 |
is applied to a pattern when it is compiled and to a string |
is applied to a pattern when it is compiled and to a string |
475 |
when it is matched. */ |
when it is matched. */ |
476 |
RE_TRANSLATE_TYPE translate; |
REG_TRANSLATE_TYPE _REG_RE_NAME (translate); |
477 |
|
|
478 |
/* Number of subexpressions found by the compiler. */ |
/* Number of subexpressions found by the compiler. */ |
479 |
size_t re_nsub; |
size_t re_nsub; |
483 |
whether or not we should use the fastmap, so we don't set |
whether or not we should use the fastmap, so we don't set |
484 |
this absolutely perfectly; see `re_compile_fastmap' (the |
this absolutely perfectly; see `re_compile_fastmap' (the |
485 |
`duplicate' case). */ |
`duplicate' case). */ |
486 |
unsigned can_be_null : 1; |
unsigned int _REG_RE_NAME (can_be_null) : 1; |
487 |
|
|
488 |
/* If REGS_UNALLOCATED, allocate space in the `regs' structure |
/* If REG_UNALLOCATED, allocate space in the `regs' structure |
489 |
for `max (RE_NREGS, re_nsub + 1)' groups. |
for `max (REG_NREGS, re_nsub + 1)' groups. |
490 |
If REGS_REALLOCATE, reallocate space if necessary. |
If REG_REALLOCATE, reallocate space if necessary. |
491 |
If REGS_FIXED, use what's there. */ |
If REG_FIXED, use what's there. */ |
492 |
#define REGS_UNALLOCATED 0 |
#define REG_UNALLOCATED 0 |
493 |
#define REGS_REALLOCATE 1 |
#define REG_REALLOCATE 1 |
494 |
#define REGS_FIXED 2 |
#define REG_FIXED 2 |
495 |
unsigned regs_allocated : 2; |
unsigned int _REG_RE_NAME (regs_allocated) : 2; |
496 |
|
|
497 |
/* Set to zero when `regex_compile' compiles a pattern; set to one |
/* Set to zero when `regex_compile' compiles a pattern; set to one |
498 |
by `re_compile_fastmap' if it updates the fastmap. */ |
by `re_compile_fastmap' if it updates the fastmap. */ |
499 |
unsigned fastmap_accurate : 1; |
unsigned int _REG_RE_NAME (fastmap_accurate) : 1; |
500 |
|
|
501 |
/* If set, `re_match_2' does not return information about |
/* If set, `re_match_2' does not return information about |
502 |
subexpressions. */ |
subexpressions. */ |
503 |
unsigned no_sub : 1; |
unsigned int _REG_RE_NAME (no_sub) : 1; |
504 |
|
|
505 |
/* If set, a beginning-of-line anchor doesn't match at the |
/* If set, a beginning-of-line anchor doesn't match at the |
506 |
beginning of the string. */ |
beginning of the string. */ |
507 |
unsigned not_bol : 1; |
unsigned int _REG_RE_NAME (not_bol) : 1; |
508 |
|
|
509 |
/* Similarly for an end-of-line anchor. */ |
/* Similarly for an end-of-line anchor. */ |
510 |
unsigned not_eol : 1; |
unsigned int _REG_RE_NAME (not_eol) : 1; |
511 |
|
|
512 |
/* If true, an anchor at a newline matches. */ |
/* If true, an anchor at a newline matches. */ |
513 |
unsigned newline_anchor : 1; |
unsigned int _REG_RE_NAME (newline_anchor) : 1; |
514 |
|
|
515 |
/* [[[end pattern_buffer]]] */ |
/* [[[end pattern_buffer]]] */ |
516 |
}; |
}; |
517 |
|
|
518 |
typedef struct re_pattern_buffer regex_t; |
typedef struct re_pattern_buffer regex_t; |
519 |
|
|
|
/* Type for byte offsets within the string. POSIX mandates this. */ |
|
|
typedef int regoff_t; |
|
|
|
|
|
|
|
520 |
/* This is the structure we store register match data in. See |
/* This is the structure we store register match data in. See |
521 |
regex.texinfo for a full description of what registers match. */ |
regex.texinfo for a full description of what registers match. */ |
522 |
struct re_registers |
struct re_registers |
523 |
{ |
{ |
524 |
unsigned num_regs; |
__re_size_t _REG_RM_NAME (num_regs); |
525 |
regoff_t *start; |
regoff_t *_REG_RM_NAME (start); |
526 |
regoff_t *end; |
regoff_t *_REG_RM_NAME (end); |
527 |
}; |
}; |
528 |
|
|
529 |
|
|
530 |
/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer, |
/* If `regs_allocated' is REG_UNALLOCATED in the pattern buffer, |
531 |
`re_match_2' returns information about at least this many registers |
`re_match_2' returns information about at least this many registers |
532 |
the first time a `regs' structure is passed. */ |
the first time a `regs' structure is passed. */ |
533 |
#ifndef RE_NREGS |
#ifndef REG_NREGS |
534 |
# define RE_NREGS 30 |
# define REG_NREGS 30 |
535 |
#endif |
#endif |
536 |
|
|
537 |
|
|
546 |
|
|
547 |
/* Declarations for routines. */ |
/* Declarations for routines. */ |
548 |
|
|
|
/* To avoid duplicating every routine declaration -- once with a |
|
|
prototype (if we are ANSI), and once without (if we aren't) -- we |
|
|
use the following macro to declare argument types. This |
|
|
unfortunately clutters up the declarations a bit, but I think it's |
|
|
worth it. */ |
|
|
|
|
|
#if __STDC__ |
|
|
|
|
|
# define _RE_ARGS(args) args |
|
|
|
|
|
#else /* not __STDC__ */ |
|
|
|
|
|
# define _RE_ARGS(args) () |
|
|
|
|
|
#endif /* not __STDC__ */ |
|
|
|
|
549 |
/* Sets the current default syntax to SYNTAX, and return the old syntax. |
/* Sets the current default syntax to SYNTAX, and return the old syntax. |
550 |
You can also simply assign to the `re_syntax_options' variable. */ |
You can also simply assign to the `re_syntax_options' variable. */ |
551 |
extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax)); |
extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax); |
552 |
|
|
553 |
/* Compile the regular expression PATTERN, with length LENGTH |
/* Compile the regular expression PATTERN, with length LENGTH |
554 |
and syntax given by the global `re_syntax_options', into the buffer |
and syntax given by the global `re_syntax_options', into the buffer |
555 |
BUFFER. Return NULL if successful, and an error string if not. */ |
BUFFER. Return NULL if successful, and an error string if not. */ |
556 |
extern const char *re_compile_pattern |
extern const char *re_compile_pattern (const char *__pattern, size_t __length, |
557 |
_RE_ARGS ((const char *pattern, size_t length, |
struct re_pattern_buffer *__buffer); |
|
struct re_pattern_buffer *buffer)); |
|
558 |
|
|
559 |
|
|
560 |
/* Compile a fastmap for the compiled pattern in BUFFER; used to |
/* Compile a fastmap for the compiled pattern in BUFFER; used to |
561 |
accelerate searches. Return 0 if successful and -2 if was an |
accelerate searches. Return 0 if successful and -2 if was an |
562 |
internal error. */ |
internal error. */ |
563 |
extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer)); |
extern int re_compile_fastmap (struct re_pattern_buffer *__buffer); |
564 |
|
|
565 |
|
|
566 |
/* Search in the string STRING (with length LENGTH) for the pattern |
/* Search in the string STRING (with length LENGTH) for the pattern |
567 |
compiled into BUFFER. Start searching at position START, for RANGE |
compiled into BUFFER. Start searching at position START, for RANGE |
568 |
characters. Return the starting position of the match, -1 for no |
characters. Return the starting position of the match, -1 for no |
569 |
match, or -2 for an internal error. Also return register |
match, or -2 for an internal error. Also return register |
570 |
information in REGS (if REGS and BUFFER->no_sub are nonzero). */ |
information in REGS (if REGS and BUFFER->re_no_sub are nonzero). */ |
571 |
extern int re_search |
extern regoff_t re_search (struct re_pattern_buffer *__buffer, |
572 |
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, |
const char *__string, __re_idx_t __length, |
573 |
int length, int start, int range, struct re_registers *regs)); |
__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 |
/* Like `re_search', but search in the concatenation of STRING1 and |
578 |
STRING2. Also, stop searching at index START + STOP. */ |
STRING2. Also, stop searching at index START + STOP. */ |
579 |
extern int re_search_2 |
extern regoff_t re_search_2 (struct re_pattern_buffer *__buffer, |
580 |
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, |
const char *__string1, __re_idx_t __length1, |
581 |
int length1, const char *string2, int length2, |
const char *__string2, __re_idx_t __length2, |
582 |
int start, int range, struct re_registers *regs, int stop)); |
__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 |
/* Like `re_search', but return how many characters in STRING the regexp |
588 |
in BUFFER matched, starting at position START. */ |
in BUFFER matched, starting at position START. */ |
589 |
extern int re_match |
extern regoff_t re_match (struct re_pattern_buffer *__buffer, |
590 |
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, |
const char *__string, __re_idx_t __length, |
591 |
int length, int start, struct re_registers *regs)); |
__re_idx_t __start, struct re_registers *__regs); |
592 |
|
|
593 |
|
|
594 |
/* Relates to `re_match' as `re_search_2' relates to `re_search'. */ |
/* Relates to `re_match' as `re_search_2' relates to `re_search'. */ |
595 |
extern int re_match_2 |
extern regoff_t re_match_2 (struct re_pattern_buffer *__buffer, |
596 |
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, |
const char *__string1, __re_idx_t __length1, |
597 |
int length1, const char *string2, int length2, |
const char *__string2, __re_idx_t __length2, |
598 |
int start, struct re_registers *regs, int stop)); |
__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 |
/* Set REGS to hold NUM_REGS registers, storing them in STARTS and |
611 |
Unless this function is called, the first search or match using |
Unless this function is called, the first search or match using |
612 |
PATTERN_BUFFER will allocate its own register data, without |
PATTERN_BUFFER will allocate its own register data, without |
613 |
freeing the old data. */ |
freeing the old data. */ |
614 |
extern void re_set_registers |
extern void re_set_registers (struct re_pattern_buffer *__buffer, |
615 |
_RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs, |
struct re_registers *__regs, |
616 |
unsigned num_regs, regoff_t *starts, regoff_t *ends)); |
__re_size_t __num_regs, |
617 |
|
regoff_t *__starts, regoff_t *__ends); |
618 |
|
|
619 |
#if defined _REGEX_RE_COMP || defined _LIBC |
#if defined _REGEX_RE_COMP || defined _LIBC |
620 |
# ifndef _CRAY |
# ifndef _CRAY |
621 |
/* 4.2 bsd compatibility. */ |
/* 4.2 bsd compatibility. */ |
622 |
extern char *re_comp _RE_ARGS ((const char *)); |
extern char *re_comp (const char *); |
623 |
extern int re_exec _RE_ARGS ((const char *)); |
extern int re_exec (const char *); |
624 |
# endif |
# endif |
625 |
#endif |
#endif |
626 |
|
|
635 |
# endif |
# endif |
636 |
# endif |
# endif |
637 |
#endif |
#endif |
638 |
/* gcc 3.1 and up support the [restrict] syntax. */ |
/* gcc 3.1 and up support the [restrict] syntax, but g++ doesn't. */ |
639 |
#ifndef __restrict_arr |
#ifndef __restrict_arr |
640 |
# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) |
# if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) && !defined __cplusplus |
641 |
# define __restrict_arr __restrict |
# define __restrict_arr __restrict |
642 |
# else |
# else |
643 |
# define __restrict_arr |
# define __restrict_arr |
645 |
#endif |
#endif |
646 |
|
|
647 |
/* POSIX compatibility. */ |
/* POSIX compatibility. */ |
648 |
extern int regcomp _RE_ARGS ((regex_t *__restrict __preg, |
extern int regcomp (regex_t *__restrict __preg, |
649 |
const char *__restrict __pattern, |
const char *__restrict __pattern, |
650 |
int __cflags)); |
int __cflags); |
651 |
|
|
652 |
extern int regexec _RE_ARGS ((const regex_t *__restrict __preg, |
extern int regexec (const regex_t *__restrict __preg, |
653 |
const char *__restrict __string, size_t __nmatch, |
const char *__restrict __string, size_t __nmatch, |
654 |
regmatch_t __pmatch[__restrict_arr], |
regmatch_t __pmatch[__restrict_arr], |
655 |
int __eflags)); |
int __eflags); |
656 |
|
|
657 |
|
extern size_t regerror (int __errcode, const regex_t *__restrict __preg, |
658 |
|
char *__restrict __errbuf, size_t __errbuf_size); |
659 |
|
|
660 |
|
extern 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 |
extern size_t regerror _RE_ARGS ((int __errcode, const regex_t *__preg, |
# undef RE_DUP_MAX |
702 |
char *__errbuf, size_t __errbuf_size)); |
# define RE_DUP_MAX (0x7fff) |
703 |
|
|
704 |
extern void regfree _RE_ARGS ((regex_t *__preg)); |
/* 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 |
#ifdef __cplusplus |
758 |
} |
} |