428
|
1 /* Definitions for data structures and routines for the regular
|
|
2 expression library, version 0.12.
|
|
3
|
|
4 Copyright (C) 1985, 89, 90, 91, 92, 93, 95 Free Software Foundation, Inc.
|
826
|
5 Copyright (C) 2002 Ben Wing.
|
428
|
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
|
|
18 along with this program; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: FSF 19.29. */
|
|
23
|
440
|
24 #ifndef INCLUDED_regex_h_
|
|
25 #define INCLUDED_regex_h_
|
428
|
26
|
446
|
27 #ifdef emacs
|
|
28 #define RE_TRANSLATE_TYPE Lisp_Object
|
2333
|
29 #define RE_LISP_SHORT_CONTEXT_ARGS_DECL , Lisp_Object UNUSED (lispobj), struct buffer *UNUSED (lispbuf)
|
826
|
30 #define RE_LISP_SHORT_CONTEXT_ARGS , lispobj, lispbuf
|
|
31 #define RE_LISP_CONTEXT_ARGS_DECL , Lisp_Object lispobj, struct buffer *lispbuf, struct syntax_cache *scache
|
2333
|
32 #define RE_LISP_CONTEXT_ARGS_MULE_DECL , Lisp_Object lispobj, struct buffer *USED_IF_MULE (lispbuf), struct syntax_cache *scache
|
826
|
33 #define RE_LISP_CONTEXT_ARGS , lispobj, lispbuf, scache
|
446
|
34 #else
|
|
35 #define RE_TRANSLATE_TYPE char *
|
826
|
36 #define RE_LISP_SHORT_CONTEXT_ARGS_DECL
|
|
37 #define RE_LISP_SHORT_CONTEXT_ARGS
|
|
38 #define RE_LISP_CONTEXT_ARGS_DECL
|
2333
|
39 #define RE_LISP_CONTEXT_ARGS_MULE_DECL
|
826
|
40 #define RE_LISP_CONTEXT_ARGS
|
665
|
41 #define Elemcount ssize_t
|
|
42 #define Bytecount ssize_t
|
446
|
43 #endif /* emacs */
|
|
44
|
428
|
45 /* POSIX says that <sys/types.h> must be included (by the caller) before
|
|
46 <regex.h>. */
|
|
47
|
|
48
|
|
49 /* The following bits are used to determine the regexp syntax we
|
|
50 recognize. The not-set meaning typically corresponds to the syntax
|
|
51 used by Emacs (the exception is RE_INTERVAL, made for historical
|
|
52 reasons). The bits are given in alphabetical order, and the
|
|
53 definitions shifted by one from the previous bit; thus, when we add or
|
|
54 remove a bit, only one other definition need change. */
|
|
55 typedef unsigned reg_syntax_t;
|
|
56
|
|
57 /* If this bit is not set, then \ inside a bracket expression is literal.
|
|
58 If set, then such a \ quotes the following character. */
|
|
59 #define RE_BACKSLASH_ESCAPE_IN_LISTS (1)
|
|
60
|
|
61 /* If this bit is not set, then + and ? are operators, and \+ and \? are
|
|
62 literals.
|
|
63 If set, then \+ and \? are operators and + and ? are literals. */
|
|
64 #define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
|
|
65
|
|
66 /* If this bit is set, then character classes are supported. They are:
|
|
67 [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
|
|
68 [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
|
|
69 If not set, then character classes are not supported. */
|
|
70 #define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
|
|
71
|
|
72 /* If this bit is set, then ^ and $ are always anchors (outside bracket
|
|
73 expressions, of course).
|
|
74 If this bit is not set, then it depends:
|
|
75 ^ is an anchor if it is at the beginning of a regular
|
|
76 expression or after an open-group or an alternation operator;
|
|
77 $ is an anchor if it is at the end of a regular expression, or
|
|
78 before a close-group or an alternation operator.
|
|
79
|
|
80 This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
|
|
81 POSIX draft 11.2 says that * etc. in leading positions is undefined.
|
|
82 We already implemented a previous draft which made those constructs
|
|
83 invalid, though, so we haven't changed the code back. */
|
|
84 #define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
|
|
85
|
|
86 /* If this bit is set, then special characters are always special
|
|
87 regardless of where they are in the pattern.
|
|
88 If this bit is not set, then special characters are special only in
|
|
89 some contexts; otherwise they are ordinary. Specifically,
|
|
90 * + ? and intervals are only special when not after the beginning,
|
|
91 open-group, or alternation operator. */
|
|
92 #define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
|
|
93
|
|
94 /* If this bit is set, then *, +, ?, and { cannot be first in an re or
|
|
95 immediately after an alternation or begin-group operator. */
|
|
96 #define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
|
|
97
|
|
98 /* If this bit is set, then . matches newline.
|
|
99 If not set, then it doesn't. */
|
|
100 #define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
|
|
101
|
|
102 /* If this bit is set, then . doesn't match NUL.
|
|
103 If not set, then it does. */
|
|
104 #define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
|
|
105
|
|
106 /* If this bit is set, nonmatching lists [^...] do not match newline.
|
|
107 If not set, they do. */
|
|
108 #define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
|
|
109
|
|
110 /* If this bit is set, either \{...\} or {...} defines an
|
|
111 interval, depending on RE_NO_BK_BRACES.
|
|
112 If not set, \{, \}, {, and } are literals. */
|
|
113 #define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
|
|
114
|
|
115 /* If this bit is set, +, ? and | aren't recognized as operators.
|
|
116 If not set, they are. */
|
|
117 #define RE_LIMITED_OPS (RE_INTERVALS << 1)
|
|
118
|
|
119 /* If this bit is set, newline is an alternation operator.
|
|
120 If not set, newline is literal. */
|
|
121 #define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
|
|
122
|
|
123 /* If this bit is set, then `{...}' defines an interval, and \{ and \}
|
|
124 are literals.
|
|
125 If not set, then `\{...\}' defines an interval. */
|
|
126 #define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
|
|
127
|
|
128 /* If this bit is set, (...) defines a group, and \( and \) are literals.
|
|
129 If not set, \(...\) defines a group, and ( and ) are literals. */
|
|
130 #define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
|
|
131
|
|
132 /* If this bit is set, then \<digit> matches <digit>.
|
|
133 If not set, then \<digit> is a back-reference. */
|
|
134 #define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
|
|
135
|
|
136 /* If this bit is set, then | is an alternation operator, and \| is literal.
|
|
137 If not set, then \| is an alternation operator, and | is literal. */
|
|
138 #define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
|
|
139
|
|
140 /* If this bit is set, then an ending range point collating higher
|
|
141 than the starting range point, as in [z-a], is invalid.
|
|
142 If not set, then when ending range point collates higher than the
|
|
143 starting range point, the range is ignored. */
|
|
144 #define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
|
|
145
|
|
146 /* If this bit is not set, allow minimal matching:
|
|
147 - a*? and a+? and a?? perform shortest-possible matching (compare with a*
|
|
148 and a+ and a?, respectively, which perform longest-possible matching)
|
|
149 - other juxtaposing of * + and ? is rejected.
|
|
150 If this bit is set, consecutive * + and ?'s are collapsed in a logical
|
|
151 manner:
|
|
152 - a*? and a+? are the same as a*
|
|
153 - a?? is the same as a?
|
|
154 */
|
|
155 #define RE_NO_MINIMAL_MATCHING (RE_NO_EMPTY_RANGES << 1)
|
|
156
|
|
157 /* If this bit is set, succeed as soon as we match the whole pattern,
|
|
158 without further backtracking. */
|
|
159 #define RE_NO_POSIX_BACKTRACKING (RE_NO_MINIMAL_MATCHING << 1)
|
|
160
|
|
161 /* If this bit is not set, (?:re) behaves like (re) (or \(?:re\) behaves like
|
|
162 \(re\)) except that the matched string is not registered. */
|
|
163 #define RE_NO_SHY_GROUPS (RE_NO_POSIX_BACKTRACKING << 1)
|
|
164
|
|
165 /* If this bit is set, then an unmatched ) is ordinary.
|
|
166 If not set, then an unmatched ) is invalid. */
|
|
167 #define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_SHY_GROUPS << 1)
|
|
168
|
502
|
169 /* If this bit is set, then \22 will read as a back reference,
|
|
170 provided at least 22 non-shy groups have been seen so far. In all
|
|
171 other cases (bit not set, not 22 non-shy groups seen so far), it
|
|
172 reads as a back reference \2 followed by a digit 2. */
|
|
173 #define RE_NO_MULTI_DIGIT_BK_REFS (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
|
|
174
|
428
|
175 /* This global variable defines the particular regexp syntax to use (for
|
|
176 some interfaces). When a regexp is compiled, the syntax used is
|
|
177 stored in the pattern buffer, so changing this does not affect
|
|
178 already-compiled regexps. */
|
|
179 extern reg_syntax_t re_syntax_options;
|
|
180
|
|
181 /* Define combinations of the above bits for the standard possibilities.
|
|
182 (The [[[ comments delimit what gets put into the Texinfo file, so
|
|
183 don't delete them!) */
|
|
184 /* [[[begin syntaxes]]] */
|
|
185 #define RE_SYNTAX_EMACS RE_INTERVALS
|
|
186
|
|
187 #define RE_SYNTAX_AWK \
|
|
188 (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
|
|
189 | RE_NO_BK_PARENS | RE_NO_BK_REFS \
|
|
190 | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
|
|
191 | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_SHY_GROUPS \
|
502
|
192 | RE_NO_MINIMAL_MATCHING | RE_NO_MULTI_DIGIT_BK_REFS)
|
428
|
193
|
|
194 #define RE_SYNTAX_POSIX_AWK \
|
|
195 (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS)
|
|
196
|
|
197 #define RE_SYNTAX_GREP \
|
|
198 (RE_BK_PLUS_QM | RE_CHAR_CLASSES \
|
|
199 | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
|
|
200 | RE_NEWLINE_ALT | RE_NO_SHY_GROUPS \
|
502
|
201 | RE_NO_MINIMAL_MATCHING | RE_NO_MULTI_DIGIT_BK_REFS)
|
428
|
202
|
|
203 #define RE_SYNTAX_EGREP \
|
|
204 (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \
|
|
205 | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \
|
|
206 | RE_NEWLINE_ALT | RE_NO_BK_PARENS \
|
|
207 | RE_NO_BK_VBAR | RE_NO_SHY_GROUPS \
|
502
|
208 | RE_NO_MINIMAL_MATCHING | RE_NO_MULTI_DIGIT_BK_REFS)
|
428
|
209
|
|
210 #define RE_SYNTAX_POSIX_EGREP \
|
502
|
211 (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES | \
|
|
212 RE_NO_MULTI_DIGIT_BK_REFS)
|
428
|
213
|
|
214 /* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
|
|
215 #define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
|
|
216
|
|
217 #define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
|
|
218
|
|
219 /* Syntax bits common to both basic and extended POSIX regex syntax. */
|
|
220 #define _RE_SYNTAX_POSIX_COMMON \
|
|
221 (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
|
|
222 | RE_INTERVALS | RE_NO_EMPTY_RANGES | RE_NO_SHY_GROUPS \
|
502
|
223 | RE_NO_MINIMAL_MATCHING | RE_NO_MULTI_DIGIT_BK_REFS)
|
428
|
224
|
|
225 #define RE_SYNTAX_POSIX_BASIC \
|
|
226 (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
|
|
227
|
|
228 /* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
|
|
229 RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
|
|
230 isn't minimal, since other operators, such as \`, aren't disabled. */
|
|
231 #define RE_SYNTAX_POSIX_MINIMAL_BASIC \
|
|
232 (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
|
|
233
|
|
234 #define RE_SYNTAX_POSIX_EXTENDED \
|
|
235 (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
|
|
236 | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
|
|
237 | RE_NO_BK_PARENS | RE_NO_BK_VBAR \
|
|
238 | RE_UNMATCHED_RIGHT_PAREN_ORD)
|
|
239
|
|
240 /* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS
|
|
241 replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added. */
|
|
242 #define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
|
|
243 (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
|
|
244 | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
|
|
245 | RE_NO_BK_PARENS | RE_NO_BK_REFS \
|
|
246 | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
|
|
247 /* [[[end syntaxes]]] */
|
|
248
|
|
249 /* Maximum number of duplicates an interval can allow. Some systems
|
|
250 (erroneously) define this in other header files, but we want our
|
|
251 value, so remove any previous define. */
|
|
252 #ifdef RE_DUP_MAX
|
|
253 #undef RE_DUP_MAX
|
|
254 #endif
|
|
255 #define RE_DUP_MAX ((1 << 15) - 1)
|
|
256
|
|
257
|
|
258 /* POSIX `cflags' bits (i.e., information for `regcomp'). */
|
|
259
|
|
260 /* If this bit is set, then use extended regular expression syntax.
|
|
261 If not set, then use basic regular expression syntax. */
|
|
262 #define REG_EXTENDED 1
|
|
263
|
|
264 /* If this bit is set, then ignore case when matching.
|
|
265 If not set, then case is significant. */
|
|
266 #define REG_ICASE (REG_EXTENDED << 1)
|
|
267
|
|
268 /* If this bit is set, then anchors do not match at newline
|
|
269 characters in the string.
|
|
270 If not set, then anchors do match at newlines. */
|
|
271 #define REG_NEWLINE (REG_ICASE << 1)
|
|
272
|
|
273 /* If this bit is set, then report only success or fail in regexec.
|
|
274 If not set, then returns differ between not matching and errors. */
|
|
275 #define REG_NOSUB (REG_NEWLINE << 1)
|
|
276
|
|
277
|
|
278 /* POSIX `eflags' bits (i.e., information for regexec). */
|
|
279
|
|
280 /* If this bit is set, then the beginning-of-line operator doesn't match
|
|
281 the beginning of the string (presumably because it's not the
|
|
282 beginning of a line).
|
|
283 If not set, then the beginning-of-line operator does match the
|
|
284 beginning of the string. */
|
|
285 #define REG_NOTBOL 1
|
|
286
|
|
287 /* Like REG_NOTBOL, except for the end-of-line. */
|
|
288 #define REG_NOTEOL (1 << 1)
|
|
289
|
|
290
|
|
291 /* If any error codes are removed, changed, or added, update the
|
|
292 `re_error_msg' table in regex.c. */
|
|
293 typedef enum
|
|
294 {
|
|
295 REG_NOERROR = 0, /* Success. */
|
|
296 REG_NOMATCH, /* Didn't find a match (for regexec). */
|
|
297
|
|
298 /* POSIX regcomp return error codes. (In the order listed in the
|
|
299 standard.) */
|
|
300 REG_BADPAT, /* Invalid pattern. */
|
|
301 REG_ECOLLATE, /* Not implemented. */
|
|
302 REG_ECTYPE, /* Invalid character class name. */
|
|
303 REG_EESCAPE, /* Trailing backslash. */
|
|
304 REG_ESUBREG, /* Invalid back reference. */
|
|
305 REG_EBRACK, /* Unmatched left bracket. */
|
|
306 REG_EPAREN, /* Parenthesis imbalance. */
|
|
307 REG_EBRACE, /* Unmatched \{. */
|
|
308 REG_BADBR, /* Invalid contents of \{\}. */
|
|
309 REG_ERANGE, /* Invalid range end. */
|
|
310 REG_ESPACE, /* Ran out of memory. */
|
|
311 REG_BADRPT, /* No preceding re for repetition op. */
|
|
312
|
|
313 /* Error codes we've added. */
|
|
314 REG_EEND, /* Premature end. */
|
|
315 REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */
|
|
316 REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
|
|
317 #ifdef emacs
|
|
318 ,REG_ESYNTAX /* Invalid syntax designator. */
|
|
319 #endif
|
|
320 #ifdef MULE
|
|
321 ,REG_ERANGESPAN /* Ranges may not span charsets. */
|
|
322 ,REG_ECATEGORY /* Invalid category designator */
|
|
323 #endif
|
|
324 } reg_errcode_t;
|
|
325
|
|
326 /* This data structure represents a compiled pattern. Before calling
|
|
327 the pattern compiler, the fields `buffer', `allocated', `fastmap',
|
|
328 `translate', and `no_sub' can be set. After the pattern has been
|
|
329 compiled, the `re_nsub' field is available. All other fields are
|
|
330 private to the regex routines. */
|
|
331
|
|
332 struct re_pattern_buffer
|
|
333 {
|
|
334 /* [[[begin pattern_buffer]]] */
|
|
335 /* Space that holds the compiled pattern. It is declared as
|
|
336 `unsigned char *' because its elements are
|
|
337 sometimes used as array indexes. */
|
|
338 unsigned char *buffer;
|
|
339
|
|
340 /* Number of bytes to which `buffer' points. */
|
647
|
341 long allocated;
|
428
|
342
|
|
343 /* Number of bytes actually used in `buffer'. */
|
647
|
344 long used;
|
428
|
345
|
|
346 /* Syntax setting with which the pattern was compiled. */
|
|
347 reg_syntax_t syntax;
|
|
348
|
|
349 /* Pointer to a fastmap, if any, otherwise zero. re_search uses
|
|
350 the fastmap, if there is one, to skip over impossible
|
|
351 starting points for matches. */
|
|
352 char *fastmap;
|
|
353
|
|
354 /* Either a translate table to apply to all characters before
|
|
355 comparing them, or zero for no translation. The translation
|
|
356 is applied to a pattern when it is compiled and to a string
|
|
357 when it is matched. */
|
446
|
358 RE_TRANSLATE_TYPE translate;
|
428
|
359
|
502
|
360 /* Number of returnable groups found by the compiler. (This does
|
|
361 not count shy groups.) */
|
647
|
362 int re_nsub;
|
428
|
363
|
502
|
364 /* Total number of groups found by the compiler. (Including
|
|
365 shy ones.) */
|
|
366 int re_ngroups;
|
|
367
|
428
|
368 /* Zero if this pattern cannot match the empty string, one else.
|
|
369 Well, in truth it's used only in `re_search_2', to see
|
|
370 whether or not we should use the fastmap, so we don't set
|
|
371 this absolutely perfectly; see `re_compile_fastmap' (the
|
|
372 `duplicate' case). */
|
647
|
373 unsigned int can_be_null : 1;
|
428
|
374
|
|
375 /* If REGS_UNALLOCATED, allocate space in the `regs' structure
|
|
376 for `max (RE_NREGS, re_nsub + 1)' groups.
|
|
377 If REGS_REALLOCATE, reallocate space if necessary.
|
|
378 If REGS_FIXED, use what's there. */
|
|
379 #define REGS_UNALLOCATED 0
|
|
380 #define REGS_REALLOCATE 1
|
|
381 #define REGS_FIXED 2
|
647
|
382 unsigned int regs_allocated : 2;
|
428
|
383
|
|
384 /* Set to zero when `regex_compile' compiles a pattern; set to one
|
|
385 by `re_compile_fastmap' if it updates the fastmap. */
|
647
|
386 unsigned int fastmap_accurate : 1;
|
428
|
387
|
|
388 /* If set, `re_match_2' does not return information about
|
|
389 subexpressions. */
|
647
|
390 unsigned int no_sub : 1;
|
428
|
391
|
|
392 /* If set, a beginning-of-line anchor doesn't match at the
|
|
393 beginning of the string. */
|
647
|
394 unsigned int not_bol : 1;
|
428
|
395
|
|
396 /* Similarly for an end-of-line anchor. */
|
647
|
397 unsigned int not_eol : 1;
|
428
|
398
|
|
399 /* If true, an anchor at a newline matches. */
|
647
|
400 unsigned int newline_anchor : 1;
|
428
|
401
|
647
|
402 unsigned int warned_about_incompatible_back_references : 1;
|
502
|
403
|
|
404 /* Mapping between back references and groups (may not be
|
|
405 equivalent with shy groups). */
|
|
406 int *external_to_internal_register;
|
|
407
|
|
408 int external_to_internal_register_size;
|
|
409
|
428
|
410 /* [[[end pattern_buffer]]] */
|
|
411 };
|
|
412
|
|
413 typedef struct re_pattern_buffer regex_t;
|
|
414
|
|
415 /* Type for byte offsets within the string. POSIX mandates this. */
|
|
416 typedef int regoff_t;
|
|
417
|
|
418
|
|
419 /* This is the structure we store register match data in. See
|
|
420 regex.texinfo for a full description of what registers match. */
|
|
421 struct re_registers
|
|
422 {
|
1468
|
423 int num_regs; /* number of registers allocated */
|
428
|
424 regoff_t *start;
|
|
425 regoff_t *end;
|
|
426 };
|
|
427
|
|
428
|
|
429 /* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
|
|
430 `re_match_2' returns information about at least this many registers
|
|
431 the first time a `regs' structure is passed. */
|
|
432 #ifndef RE_NREGS
|
|
433 #define RE_NREGS 30
|
|
434 #endif
|
|
435
|
|
436
|
|
437 /* POSIX specification for registers. Aside from the different names than
|
|
438 `re_registers', POSIX uses an array of structures, instead of a
|
|
439 structure of arrays. */
|
|
440 typedef struct
|
|
441 {
|
|
442 regoff_t rm_so; /* Byte offset from string's start to substring's start. */
|
|
443 regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
|
|
444 } regmatch_t;
|
|
445
|
|
446 /* Declarations for routines. */
|
|
447
|
|
448 /* Sets the current default syntax to SYNTAX, and return the old syntax.
|
|
449 You can also simply assign to the `re_syntax_options' variable. */
|
|
450 reg_syntax_t re_set_syntax (reg_syntax_t syntax);
|
|
451
|
|
452 /* Compile the regular expression PATTERN, with length LENGTH
|
|
453 and syntax given by the global `re_syntax_options', into the buffer
|
|
454 BUFFER. Return NULL if successful, and an error string if not. */
|
442
|
455 const char *re_compile_pattern (const char *pattern, int length,
|
428
|
456 struct re_pattern_buffer *buffer);
|
|
457
|
|
458
|
|
459 /* Compile a fastmap for the compiled pattern in BUFFER; used to
|
|
460 accelerate searches. Return 0 if successful and -2 if was an
|
|
461 internal error. */
|
826
|
462 int re_compile_fastmap (struct re_pattern_buffer *buffer
|
|
463 RE_LISP_SHORT_CONTEXT_ARGS_DECL);
|
428
|
464
|
|
465
|
|
466 /* Search in the string STRING (with length LENGTH) for the pattern
|
|
467 compiled into BUFFER. Start searching at position START, for RANGE
|
|
468 characters. Return the starting position of the match, -1 for no
|
|
469 match, or -2 for an internal error. Also return register
|
|
470 information in REGS (if REGS and BUFFER->no_sub are nonzero). */
|
442
|
471 int re_search (struct re_pattern_buffer *buffer, const char *string,
|
428
|
472 int length, int start, int range,
|
826
|
473 struct re_registers *regs RE_LISP_CONTEXT_ARGS_DECL);
|
428
|
474
|
|
475
|
|
476 /* Like `re_search', but search in the concatenation of STRING1 and
|
|
477 STRING2. Also, stop searching at index START + STOP. */
|
442
|
478 int re_search_2 (struct re_pattern_buffer *buffer, const char *string1,
|
|
479 int length1, const char *string2, int length2, int start,
|
826
|
480 int range, struct re_registers *regs, int stop
|
|
481 RE_LISP_CONTEXT_ARGS_DECL);
|
428
|
482
|
826
|
483 #ifndef emacs /* never used by XEmacs */
|
428
|
484
|
|
485 /* Like `re_search', but return how many characters in STRING the regexp
|
|
486 in BUFFER matched, starting at position START. */
|
442
|
487 int re_match (struct re_pattern_buffer *buffer, const char *string,
|
826
|
488 int length, int start, struct re_registers *regs
|
|
489 RE_LISP_CONTEXT_ARGS_DECL);
|
428
|
490
|
826
|
491 #endif /* not emacs */
|
428
|
492
|
|
493 /* Relates to `re_match' as `re_search_2' relates to `re_search'. */
|
442
|
494 int re_match_2 (struct re_pattern_buffer *buffer, const char *string1,
|
|
495 int length1, const char *string2, int length2,
|
826
|
496 int start, struct re_registers *regs, int stop
|
|
497 RE_LISP_CONTEXT_ARGS_DECL);
|
428
|
498
|
|
499 /* Set REGS to hold NUM_REGS registers, storing them in STARTS and
|
|
500 ENDS. Subsequent matches using BUFFER and REGS will use this memory
|
|
501 for recording register information. STARTS and ENDS must be
|
|
502 allocated with malloc, and must each be at least `NUM_REGS * sizeof
|
|
503 (regoff_t)' bytes long.
|
|
504
|
|
505 If NUM_REGS == 0, then subsequent matches should allocate their own
|
|
506 register data.
|
|
507
|
|
508 Unless this function is called, the first search or match using
|
|
509 PATTERN_BUFFER will allocate its own register data, without
|
|
510 freeing the old data. */
|
|
511 void re_set_registers (struct re_pattern_buffer *buffer,
|
647
|
512 struct re_registers *regs, int num_regs,
|
428
|
513 regoff_t *starts, regoff_t *ends);
|
|
514
|
|
515 #ifdef _REGEX_RE_COMP
|
|
516 /* 4.2 bsd compatibility. */
|
442
|
517 char *re_comp (const char *);
|
|
518 int re_exec (const char *);
|
428
|
519 #endif
|
|
520
|
|
521 /* POSIX compatibility. */
|
442
|
522 int regcomp (regex_t *preg, const char *pattern, int cflags);
|
|
523 int regexec (const regex_t *preg, const char *string, size_t nmatch,
|
428
|
524 regmatch_t pmatch[], int eflags);
|
442
|
525 size_t regerror (int errcode, const regex_t *preg, char *errbuf,
|
428
|
526 size_t errbuf_size);
|
|
527 void regfree (regex_t *preg);
|
|
528
|
440
|
529 #endif /* INCLUDED_regex_h_ */
|