regex.h revision 218
1218Sconklin/* Definitions for data structures and routines for the regular
2218Sconklin   expression library, version 0.12.
3218Sconklin
4218Sconklin   Copyright (C) 1985, 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
5218Sconklin
6218Sconklin   This program is free software; you can redistribute it and/or modify
7218Sconklin   it under the terms of the GNU General Public License as published by
8218Sconklin   the Free Software Foundation; either version 2, or (at your option)
9218Sconklin   any later version.
10218Sconklin
11218Sconklin   This program is distributed in the hope that it will be useful,
12218Sconklin   but WITHOUT ANY WARRANTY; without even the implied warranty of
13218Sconklin   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14218Sconklin   GNU General Public License for more details.
15218Sconklin
16218Sconklin   You should have received a copy of the GNU General Public License
17218Sconklin   along with this program; if not, write to the Free Software
18218Sconklin   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
19218Sconklin
20218Sconklin#ifndef __REGEXP_LIBRARY_H__
21218Sconklin#define __REGEXP_LIBRARY_H__
22218Sconklin
23218Sconklin/* POSIX says that <sys/types.h> must be included (by the caller) before
24218Sconklin   <regex.h>.  */
25218Sconklin
26218Sconklin#ifdef VMS
27218Sconklin/* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
28218Sconklin   should be there.  */
29218Sconklin#include <stddef.h>
30218Sconklin#endif
31218Sconklin
32218Sconklin
33218Sconklin/* The following bits are used to determine the regexp syntax we
34218Sconklin   recognize.  The set/not-set meanings are chosen so that Emacs syntax
35218Sconklin   remains the value 0.  The bits are given in alphabetical order, and
36218Sconklin   the definitions shifted by one from the previous bit; thus, when we
37218Sconklin   add or remove a bit, only one other definition need change.  */
38218Sconklintypedef unsigned reg_syntax_t;
39218Sconklin
40218Sconklin/* If this bit is not set, then \ inside a bracket expression is literal.
41218Sconklin   If set, then such a \ quotes the following character.  */
42218Sconklin#define RE_BACKSLASH_ESCAPE_IN_LISTS (1)
43218Sconklin
44218Sconklin/* If this bit is not set, then + and ? are operators, and \+ and \? are
45218Sconklin     literals.
46218Sconklin   If set, then \+ and \? are operators and + and ? are literals.  */
47218Sconklin#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
48218Sconklin
49218Sconklin/* If this bit is set, then character classes are supported.  They are:
50218Sconklin     [:alpha:], [:upper:], [:lower:],  [:digit:], [:alnum:], [:xdigit:],
51218Sconklin     [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
52218Sconklin   If not set, then character classes are not supported.  */
53218Sconklin#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
54218Sconklin
55218Sconklin/* If this bit is set, then ^ and $ are always anchors (outside bracket
56218Sconklin     expressions, of course).
57218Sconklin   If this bit is not set, then it depends:
58218Sconklin        ^  is an anchor if it is at the beginning of a regular
59218Sconklin           expression or after an open-group or an alternation operator;
60218Sconklin        $  is an anchor if it is at the end of a regular expression, or
61218Sconklin           before a close-group or an alternation operator.
62218Sconklin
63218Sconklin   This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
64218Sconklin   POSIX draft 11.2 says that * etc. in leading positions is undefined.
65218Sconklin   We already implemented a previous draft which made those constructs
66218Sconklin   invalid, though, so we haven't changed the code back.  */
67218Sconklin#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
68218Sconklin
69218Sconklin/* If this bit is set, then special characters are always special
70218Sconklin     regardless of where they are in the pattern.
71218Sconklin   If this bit is not set, then special characters are special only in
72218Sconklin     some contexts; otherwise they are ordinary.  Specifically,
73218Sconklin     * + ? and intervals are only special when not after the beginning,
74218Sconklin     open-group, or alternation operator.  */
75218Sconklin#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
76218Sconklin
77218Sconklin/* If this bit is set, then *, +, ?, and { cannot be first in an re or
78218Sconklin     immediately after an alternation or begin-group operator.  */
79218Sconklin#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
80218Sconklin
81218Sconklin/* If this bit is set, then . matches newline.
82218Sconklin   If not set, then it doesn't.  */
83218Sconklin#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
84218Sconklin
85218Sconklin/* If this bit is set, then . doesn't match NUL.
86218Sconklin   If not set, then it does.  */
87218Sconklin#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
88218Sconklin
89218Sconklin/* If this bit is set, nonmatching lists [^...] do not match newline.
90218Sconklin   If not set, they do.  */
91218Sconklin#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
92218Sconklin
93218Sconklin/* If this bit is set, either \{...\} or {...} defines an
94218Sconklin     interval, depending on RE_NO_BK_BRACES.
95218Sconklin   If not set, \{, \}, {, and } are literals.  */
96218Sconklin#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
97218Sconklin
98218Sconklin/* If this bit is set, +, ? and | aren't recognized as operators.
99218Sconklin   If not set, they are.  */
100218Sconklin#define RE_LIMITED_OPS (RE_INTERVALS << 1)
101218Sconklin
102218Sconklin/* If this bit is set, newline is an alternation operator.
103218Sconklin   If not set, newline is literal.  */
104218Sconklin#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
105218Sconklin
106218Sconklin/* If this bit is set, then `{...}' defines an interval, and \{ and \}
107218Sconklin     are literals.
108218Sconklin  If not set, then `\{...\}' defines an interval.  */
109218Sconklin#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
110218Sconklin
111218Sconklin/* If this bit is set, (...) defines a group, and \( and \) are literals.
112218Sconklin   If not set, \(...\) defines a group, and ( and ) are literals.  */
113218Sconklin#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
114218Sconklin
115218Sconklin/* If this bit is set, then \<digit> matches <digit>.
116218Sconklin   If not set, then \<digit> is a back-reference.  */
117218Sconklin#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
118218Sconklin
119218Sconklin/* If this bit is set, then | is an alternation operator, and \| is literal.
120218Sconklin   If not set, then \| is an alternation operator, and | is literal.  */
121218Sconklin#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
122218Sconklin
123218Sconklin/* If this bit is set, then an ending range point collating higher
124218Sconklin     than the starting range point, as in [z-a], is invalid.
125218Sconklin   If not set, then when ending range point collates higher than the
126218Sconklin     starting range point, the range is ignored.  */
127218Sconklin#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
128218Sconklin
129218Sconklin/* If this bit is set, then an unmatched ) is ordinary.
130218Sconklin   If not set, then an unmatched ) is invalid.  */
131218Sconklin#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
132218Sconklin
133218Sconklin/* This global variable defines the particular regexp syntax to use (for
134218Sconklin   some interfaces).  When a regexp is compiled, the syntax used is
135218Sconklin   stored in the pattern buffer, so changing this does not affect
136218Sconklin   already-compiled regexps.  */
137218Sconklinextern reg_syntax_t re_syntax_options;
138218Sconklin
139218Sconklin/* Define combinations of the above bits for the standard possibilities.
140218Sconklin   (The [[[ comments delimit what gets put into the Texinfo file, so
141218Sconklin   don't delete them!)  */
142218Sconklin/* [[[begin syntaxes]]] */
143218Sconklin#define RE_SYNTAX_EMACS 0
144218Sconklin
145218Sconklin#define RE_SYNTAX_AWK							\
146218Sconklin  (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL			\
147218Sconklin   | RE_NO_BK_PARENS            | RE_NO_BK_REFS				\
148218Sconklin   | RE_NO_BK_VBAR               | RE_NO_EMPTY_RANGES			\
149218Sconklin   | RE_UNMATCHED_RIGHT_PAREN_ORD)
150218Sconklin
151218Sconklin#define RE_SYNTAX_POSIX_AWK 						\
152218Sconklin  (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS)
153218Sconklin
154218Sconklin#define RE_SYNTAX_GREP							\
155218Sconklin  (RE_BK_PLUS_QM              | RE_CHAR_CLASSES				\
156218Sconklin   | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS				\
157218Sconklin   | RE_NEWLINE_ALT)
158218Sconklin
159218Sconklin#define RE_SYNTAX_EGREP							\
160218Sconklin  (RE_CHAR_CLASSES        | RE_CONTEXT_INDEP_ANCHORS			\
161218Sconklin   | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE			\
162218Sconklin   | RE_NEWLINE_ALT       | RE_NO_BK_PARENS				\
163218Sconklin   | RE_NO_BK_VBAR)
164218Sconklin
165218Sconklin#define RE_SYNTAX_POSIX_EGREP						\
166218Sconklin  (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES)
167218Sconklin
168218Sconklin/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff.  */
169218Sconklin#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
170218Sconklin
171218Sconklin#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
172218Sconklin
173218Sconklin/* Syntax bits common to both basic and extended POSIX regex syntax.  */
174218Sconklin#define _RE_SYNTAX_POSIX_COMMON						\
175218Sconklin  (RE_CHAR_CLASSES | RE_DOT_NEWLINE      | RE_DOT_NOT_NULL		\
176218Sconklin   | RE_INTERVALS  | RE_NO_EMPTY_RANGES)
177218Sconklin
178218Sconklin#define RE_SYNTAX_POSIX_BASIC						\
179218Sconklin  (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
180218Sconklin
181218Sconklin/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
182218Sconklin   RE_LIMITED_OPS, i.e., \? \+ \| are not recognized.  Actually, this
183218Sconklin   isn't minimal, since other operators, such as \`, aren't disabled.  */
184218Sconklin#define RE_SYNTAX_POSIX_MINIMAL_BASIC					\
185218Sconklin  (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
186218Sconklin
187218Sconklin#define RE_SYNTAX_POSIX_EXTENDED					\
188218Sconklin  (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS			\
189218Sconklin   | RE_CONTEXT_INDEP_OPS  | RE_NO_BK_BRACES				\
190218Sconklin   | RE_NO_BK_PARENS       | RE_NO_BK_VBAR				\
191218Sconklin   | RE_UNMATCHED_RIGHT_PAREN_ORD)
192218Sconklin
193218Sconklin/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS
194218Sconklin   replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added.  */
195218Sconklin#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED				\
196218Sconklin  (_RE_SYNTAX_POSIX_COMMON  | RE_CONTEXT_INDEP_ANCHORS			\
197218Sconklin   | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES				\
198218Sconklin   | RE_NO_BK_PARENS        | RE_NO_BK_REFS				\
199218Sconklin   | RE_NO_BK_VBAR	    | RE_UNMATCHED_RIGHT_PAREN_ORD)
200218Sconklin/* [[[end syntaxes]]] */
201218Sconklin
202218Sconklin/* Maximum number of duplicates an interval can allow.  Some systems
203218Sconklin   (erroneously) define this in other header files, but we want our
204218Sconklin   value, so remove any previous define.  */
205218Sconklin#ifdef RE_DUP_MAX
206218Sconklin#undef RE_DUP_MAX
207218Sconklin#endif
208218Sconklin#define RE_DUP_MAX ((1 << 15) - 1)
209218Sconklin
210218Sconklin
211218Sconklin/* POSIX `cflags' bits (i.e., information for `regcomp').  */
212218Sconklin
213218Sconklin/* If this bit is set, then use extended regular expression syntax.
214218Sconklin   If not set, then use basic regular expression syntax.  */
215218Sconklin#define REG_EXTENDED 1
216218Sconklin
217218Sconklin/* If this bit is set, then ignore case when matching.
218218Sconklin   If not set, then case is significant.  */
219218Sconklin#define REG_ICASE (REG_EXTENDED << 1)
220218Sconklin
221218Sconklin/* If this bit is set, then anchors do not match at newline
222218Sconklin     characters in the string.
223218Sconklin   If not set, then anchors do match at newlines.  */
224218Sconklin#define REG_NEWLINE (REG_ICASE << 1)
225218Sconklin
226218Sconklin/* If this bit is set, then report only success or fail in regexec.
227218Sconklin   If not set, then returns differ between not matching and errors.  */
228218Sconklin#define REG_NOSUB (REG_NEWLINE << 1)
229218Sconklin
230218Sconklin
231218Sconklin/* POSIX `eflags' bits (i.e., information for regexec).  */
232218Sconklin
233218Sconklin/* If this bit is set, then the beginning-of-line operator doesn't match
234218Sconklin     the beginning of the string (presumably because it's not the
235218Sconklin     beginning of a line).
236218Sconklin   If not set, then the beginning-of-line operator does match the
237218Sconklin     beginning of the string.  */
238218Sconklin#define REG_NOTBOL 1
239218Sconklin
240218Sconklin/* Like REG_NOTBOL, except for the end-of-line.  */
241218Sconklin#define REG_NOTEOL (1 << 1)
242218Sconklin
243218Sconklin
244218Sconklin/* If any error codes are removed, changed, or added, update the
245218Sconklin   `re_error_msg' table in regex.c.  */
246218Sconklintypedef enum
247218Sconklin{
248218Sconklin  REG_NOERROR = 0,	/* Success.  */
249218Sconklin  REG_NOMATCH,		/* Didn't find a match (for regexec).  */
250218Sconklin
251218Sconklin  /* POSIX regcomp return error codes.  (In the order listed in the
252218Sconklin     standard.)  */
253218Sconklin  REG_BADPAT,		/* Invalid pattern.  */
254218Sconklin  REG_ECOLLATE,		/* Not implemented.  */
255218Sconklin  REG_ECTYPE,		/* Invalid character class name.  */
256218Sconklin  REG_EESCAPE,		/* Trailing backslash.  */
257218Sconklin  REG_ESUBREG,		/* Invalid back reference.  */
258218Sconklin  REG_EBRACK,		/* Unmatched left bracket.  */
259218Sconklin  REG_EPAREN,		/* Parenthesis imbalance.  */
260218Sconklin  REG_EBRACE,		/* Unmatched \{.  */
261218Sconklin  REG_BADBR,		/* Invalid contents of \{\}.  */
262218Sconklin  REG_ERANGE,		/* Invalid range end.  */
263218Sconklin  REG_ESPACE,		/* Ran out of memory.  */
264218Sconklin  REG_BADRPT,		/* No preceding re for repetition op.  */
265218Sconklin
266218Sconklin  /* Error codes we've added.  */
267218Sconklin  REG_EEND,		/* Premature end.  */
268218Sconklin  REG_ESIZE,		/* Compiled pattern bigger than 2^16 bytes.  */
269218Sconklin  REG_ERPAREN		/* Unmatched ) or \); not returned from regcomp.  */
270218Sconklin} reg_errcode_t;
271218Sconklin
272218Sconklin/* This data structure represents a compiled pattern.  Before calling
273218Sconklin   the pattern compiler, the fields `buffer', `allocated', `fastmap',
274218Sconklin   `translate', and `no_sub' can be set.  After the pattern has been
275218Sconklin   compiled, the `re_nsub' field is available.  All other fields are
276218Sconklin   private to the regex routines.  */
277218Sconklin
278218Sconklinstruct re_pattern_buffer
279218Sconklin{
280218Sconklin/* [[[begin pattern_buffer]]] */
281218Sconklin	/* Space that holds the compiled pattern.  It is declared as
282218Sconklin          `unsigned char *' because its elements are
283218Sconklin           sometimes used as array indexes.  */
284218Sconklin  unsigned char *buffer;
285218Sconklin
286218Sconklin	/* Number of bytes to which `buffer' points.  */
287218Sconklin  unsigned long allocated;
288218Sconklin
289218Sconklin	/* Number of bytes actually used in `buffer'.  */
290218Sconklin  unsigned long used;
291218Sconklin
292218Sconklin        /* Syntax setting with which the pattern was compiled.  */
293218Sconklin  reg_syntax_t syntax;
294218Sconklin
295218Sconklin        /* Pointer to a fastmap, if any, otherwise zero.  re_search uses
296218Sconklin           the fastmap, if there is one, to skip over impossible
297218Sconklin           starting points for matches.  */
298218Sconklin  char *fastmap;
299218Sconklin
300218Sconklin        /* Either a translate table to apply to all characters before
301218Sconklin           comparing them, or zero for no translation.  The translation
302218Sconklin           is applied to a pattern when it is compiled and to a string
303218Sconklin           when it is matched.  */
304218Sconklin  char *translate;
305218Sconklin
306218Sconklin	/* Number of subexpressions found by the compiler.  */
307218Sconklin  size_t re_nsub;
308218Sconklin
309218Sconklin        /* Zero if this pattern cannot match the empty string, one else.
310218Sconklin           Well, in truth it's used only in `re_search_2', to see
311218Sconklin           whether or not we should use the fastmap, so we don't set
312218Sconklin           this absolutely perfectly; see `re_compile_fastmap' (the
313218Sconklin           `duplicate' case).  */
314218Sconklin  unsigned can_be_null : 1;
315218Sconklin
316218Sconklin        /* If REGS_UNALLOCATED, allocate space in the `regs' structure
317218Sconklin             for `max (RE_NREGS, re_nsub + 1)' groups.
318218Sconklin           If REGS_REALLOCATE, reallocate space if necessary.
319218Sconklin           If REGS_FIXED, use what's there.  */
320218Sconklin#define REGS_UNALLOCATED 0
321218Sconklin#define REGS_REALLOCATE 1
322218Sconklin#define REGS_FIXED 2
323218Sconklin  unsigned regs_allocated : 2;
324218Sconklin
325218Sconklin        /* Set to zero when `regex_compile' compiles a pattern; set to one
326218Sconklin           by `re_compile_fastmap' if it updates the fastmap.  */
327218Sconklin  unsigned fastmap_accurate : 1;
328218Sconklin
329218Sconklin        /* If set, `re_match_2' does not return information about
330218Sconklin           subexpressions.  */
331218Sconklin  unsigned no_sub : 1;
332218Sconklin
333218Sconklin        /* If set, a beginning-of-line anchor doesn't match at the
334218Sconklin           beginning of the string.  */
335218Sconklin  unsigned not_bol : 1;
336218Sconklin
337218Sconklin        /* Similarly for an end-of-line anchor.  */
338218Sconklin  unsigned not_eol : 1;
339218Sconklin
340218Sconklin        /* If true, an anchor at a newline matches.  */
341218Sconklin  unsigned newline_anchor : 1;
342218Sconklin
343218Sconklin/* [[[end pattern_buffer]]] */
344218Sconklin};
345218Sconklin
346218Sconklintypedef struct re_pattern_buffer regex_t;
347218Sconklin
348218Sconklin
349218Sconklin/* search.c (search_buffer) in Emacs needs this one opcode value.  It is
350218Sconklin   defined both in `regex.c' and here.  */
351218Sconklin#define RE_EXACTN_VALUE 1
352218Sconklin
353218Sconklin/* Type for byte offsets within the string.  POSIX mandates this.  */
354218Sconklintypedef int regoff_t;
355218Sconklin
356218Sconklin
357218Sconklin/* This is the structure we store register match data in.  See
358218Sconklin   regex.texinfo for a full description of what registers match.  */
359218Sconklinstruct re_registers
360218Sconklin{
361218Sconklin  unsigned num_regs;
362218Sconklin  regoff_t *start;
363218Sconklin  regoff_t *end;
364218Sconklin};
365218Sconklin
366218Sconklin
367218Sconklin/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
368218Sconklin   `re_match_2' returns information about at least this many registers
369218Sconklin   the first time a `regs' structure is passed.  */
370218Sconklin#ifndef RE_NREGS
371218Sconklin#define RE_NREGS 30
372218Sconklin#endif
373218Sconklin
374218Sconklin
375218Sconklin/* POSIX specification for registers.  Aside from the different names than
376218Sconklin   `re_registers', POSIX uses an array of structures, instead of a
377218Sconklin   structure of arrays.  */
378218Sconklintypedef struct
379218Sconklin{
380218Sconklin  regoff_t rm_so;  /* Byte offset from string's start to substring's start.  */
381218Sconklin  regoff_t rm_eo;  /* Byte offset from string's start to substring's end.  */
382218Sconklin} regmatch_t;
383218Sconklin
384218Sconklin/* Declarations for routines.  */
385218Sconklin
386218Sconklin/* To avoid duplicating every routine declaration -- once with a
387218Sconklin   prototype (if we are ANSI), and once without (if we aren't) -- we
388218Sconklin   use the following macro to declare argument types.  This
389218Sconklin   unfortunately clutters up the declarations a bit, but I think it's
390218Sconklin   worth it.  */
391218Sconklin
392218Sconklin#if __STDC__
393218Sconklin
394218Sconklin#define _RE_ARGS(args) args
395218Sconklin
396218Sconklin#else /* not __STDC__ */
397218Sconklin
398218Sconklin#define _RE_ARGS(args) ()
399218Sconklin
400218Sconklin#endif /* not __STDC__ */
401218Sconklin
402218Sconklin/* Sets the current default syntax to SYNTAX, and return the old syntax.
403218Sconklin   You can also simply assign to the `re_syntax_options' variable.  */
404218Sconklinextern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax));
405218Sconklin
406218Sconklin/* Compile the regular expression PATTERN, with length LENGTH
407218Sconklin   and syntax given by the global `re_syntax_options', into the buffer
408218Sconklin   BUFFER.  Return NULL if successful, and an error string if not.  */
409218Sconklinextern const char *re_compile_pattern
410218Sconklin  _RE_ARGS ((const char *pattern, int length,
411218Sconklin             struct re_pattern_buffer *buffer));
412218Sconklin
413218Sconklin
414218Sconklin/* Compile a fastmap for the compiled pattern in BUFFER; used to
415218Sconklin   accelerate searches.  Return 0 if successful and -2 if was an
416218Sconklin   internal error.  */
417218Sconklinextern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
418218Sconklin
419218Sconklin
420218Sconklin/* Search in the string STRING (with length LENGTH) for the pattern
421218Sconklin   compiled into BUFFER.  Start searching at position START, for RANGE
422218Sconklin   characters.  Return the starting position of the match, -1 for no
423218Sconklin   match, or -2 for an internal error.  Also return register
424218Sconklin   information in REGS (if REGS and BUFFER->no_sub are nonzero).  */
425218Sconklinextern int re_search
426218Sconklin  _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
427218Sconklin            int length, int start, int range, struct re_registers *regs));
428218Sconklin
429218Sconklin
430218Sconklin/* Like `re_search', but search in the concatenation of STRING1 and
431218Sconklin   STRING2.  Also, stop searching at index START + STOP.  */
432218Sconklinextern int re_search_2
433218Sconklin  _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
434218Sconklin             int length1, const char *string2, int length2,
435218Sconklin             int start, int range, struct re_registers *regs, int stop));
436218Sconklin
437218Sconklin
438218Sconklin/* Like `re_search', but return how many characters in STRING the regexp
439218Sconklin   in BUFFER matched, starting at position START.  */
440218Sconklinextern int re_match
441218Sconklin  _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
442218Sconklin             int length, int start, struct re_registers *regs));
443218Sconklin
444218Sconklin
445218Sconklin/* Relates to `re_match' as `re_search_2' relates to `re_search'.  */
446218Sconklinextern int re_match_2
447218Sconklin  _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
448218Sconklin             int length1, const char *string2, int length2,
449218Sconklin             int start, struct re_registers *regs, int stop));
450218Sconklin
451218Sconklin
452218Sconklin/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
453218Sconklin   ENDS.  Subsequent matches using BUFFER and REGS will use this memory
454218Sconklin   for recording register information.  STARTS and ENDS must be
455218Sconklin   allocated with malloc, and must each be at least `NUM_REGS * sizeof
456218Sconklin   (regoff_t)' bytes long.
457218Sconklin
458218Sconklin   If NUM_REGS == 0, then subsequent matches should allocate their own
459218Sconklin   register data.
460218Sconklin
461218Sconklin   Unless this function is called, the first search or match using
462218Sconklin   PATTERN_BUFFER will allocate its own register data, without
463218Sconklin   freeing the old data.  */
464218Sconklinextern void re_set_registers
465218Sconklin  _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs,
466218Sconklin             unsigned num_regs, regoff_t *starts, regoff_t *ends));
467218Sconklin
468218Sconklin/* 4.2 bsd compatibility.  */
469218Sconklinextern char *re_comp _RE_ARGS ((const char *));
470218Sconklinextern int re_exec _RE_ARGS ((const char *));
471218Sconklin
472218Sconklin/* POSIX compatibility.  */
473218Sconklinextern int regcomp _RE_ARGS ((regex_t *preg, const char *pattern, int cflags));
474218Sconklinextern int regexec
475218Sconklin  _RE_ARGS ((const regex_t *preg, const char *string, size_t nmatch,
476218Sconklin             regmatch_t pmatch[], int eflags));
477218Sconklinextern size_t regerror
478218Sconklin  _RE_ARGS ((int errcode, const regex_t *preg, char *errbuf,
479218Sconklin             size_t errbuf_size));
480218Sconklinextern void regfree _RE_ARGS ((regex_t *preg));
481218Sconklin
482218Sconklin#endif /* not __REGEXP_LIBRARY_H__ */
483218Sconklin
484218Sconklin/*
485218SconklinLocal variables:
486218Sconklinmake-backup-files: t
487218Sconklinversion-control: t
488218Sconklintrim-versions-without-asking: nil
489218SconklinEnd:
490218Sconklin*/
491