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