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