1 /* Definitions for data structures and routines for the regular
2 expression library, version 0.12.
4 Copyright (C) 1985, 1989, 1990, 1991, 1992, 1993
5 Free Software Foundation, Inc.
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)
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #ifndef __REGEXP_LIBRARY_H__
22 #define __REGEXP_LIBRARY_H__
25 typedef unsigned long active_reg_t;
27 typedef unsigned long reg_syntax_t;
29 #define RE_BACKSLASH_ESCAPE_IN_LISTS (1L)
30 #define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
31 #define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
32 #define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
33 #define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
34 #define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
35 #define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
36 #define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
37 #define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
38 #define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
39 #define RE_LIMITED_OPS (RE_INTERVALS << 1)
40 #define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
41 #define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
42 #define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
43 #define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
44 #define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
45 #define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
46 #define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
47 #define RE_NO_GNU_OPS (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
49 extern reg_syntax_t re_syntax_options;
51 #define RE_SYNTAX_EMACS 0
53 #define RE_SYNTAX_AWK \
54 (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL | \
55 RE_NO_BK_PARENS | RE_NO_BK_REFS | \
56 RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES | \
57 RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS | \
58 RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS)
60 #define RE_SYNTAX_GNU_AWK \
61 ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS) | \
62 & ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS))
64 #define RE_SYNTAX_POSIX_AWK \
65 (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | \
66 RE_INTERVALS | RE_NO_GNU_OPS)
68 #define RE_SYNTAX_GREP \
69 (RE_BK_PLUS_QM | RE_CHAR_CLASSES | \
70 RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS | \
73 #define RE_SYNTAX_EGREP \
74 (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS | \
75 RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE | \
76 RE_NEWLINE_ALT | RE_NO_BK_PARENS | \
79 #define RE_SYNTAX_POSIX_EGREP \
80 (RE_SYNTAX_EGREP | RE_INTERVALS | \
83 #define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
85 #define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
87 #define _RE_SYNTAX_POSIX_COMMON \
88 (RE_CHAR_CLASSES | RE_DOT_NEWLINE | \
89 RE_DOT_NOT_NULL | RE_INTERVALS | \
92 #define RE_SYNTAX_POSIX_BASIC \
93 (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
95 #define RE_SYNTAX_POSIX_MINIMAL_BASIC \
96 (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
98 #define RE_SYNTAX_POSIX_EXTENDED \
99 (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS | \
100 RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES | \
101 RE_NO_BK_PARENS | RE_NO_BK_VBAR | \
102 RE_UNMATCHED_RIGHT_PAREN_ORD)
104 #define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
105 (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS | \
106 RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES | \
107 RE_NO_BK_PARENS | RE_NO_BK_REFS | \
108 RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
110 /* Maximum number of duplicates an interval can allow */
111 #define RE_DUP_MAX (0x7fff)
113 /* POSIX 'cflags' bits */
114 #define REG_EXTENDED 1
115 #define REG_ICASE (REG_EXTENDED << 1)
116 #define REG_NEWLINE (REG_ICASE << 1)
117 #define REG_NOSUB (REG_NEWLINE << 1)
120 /* POSIX `eflags' bits */
122 #define REG_NOTEOL (1 << 1)
124 /* If any error codes are removed, changed, or added, update the
125 `re_error_msg' table in regex.c. */
128 REG_NOERROR = 0, /* Success. */
129 REG_NOMATCH, /* Didn't find a match (for regexec). */
131 /* POSIX regcomp return error codes */
132 REG_BADPAT, /* Invalid pattern. */
133 REG_ECOLLATE, /* Not implemented. */
134 REG_ECTYPE, /* Invalid character class name. */
135 REG_EESCAPE, /* Trailing backslash. */
136 REG_ESUBREG, /* Invalid back reference. */
137 REG_EBRACK, /* Unmatched left bracket. */
138 REG_EPAREN, /* Parenthesis imbalance. */
139 REG_EBRACE, /* Unmatched \{. */
140 REG_BADBR, /* Invalid contents of \{\}. */
141 REG_ERANGE, /* Invalid range end. */
142 REG_ESPACE, /* Ran out of memory. */
143 REG_BADRPT, /* No preceding re for repetition op. */
145 /* Error codes we've added */
146 REG_EEND, /* Premature end. */
147 REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */
148 REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
151 #define REGS_UNALLOCATED 0
152 #define REGS_REALLOCATE 1
155 /* This data structure represents a compiled pattern */
156 struct re_pattern_buffer
158 unsigned char *buffer;
159 unsigned long allocated;
165 unsigned can_be_null : 1;
166 unsigned regs_allocated : 2;
167 unsigned fastmap_accurate : 1;
169 unsigned not_bol : 1;
170 unsigned not_eol : 1;
171 unsigned newline_anchor : 1;
174 typedef struct re_pattern_buffer regex_t;
176 /* search.c (search_buffer) in Emacs needs this one opcode value. It is
177 defined both in `regex.c' and here. */
178 #define RE_EXACTN_VALUE 1
180 /* Type for byte offsets within the string. POSIX mandates this. */
181 typedef int regoff_t;
184 /* This is the structure we store register match data in. See
185 regex.texinfo for a full description of what registers match. */
199 /* POSIX specification for registers. Aside from the different names than
200 `re_registers', POSIX uses an array of structures, instead of a
201 structure of arrays. */
204 regoff_t rm_so; /* Byte offset from string's start to substring's start. */
205 regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
208 /* Declarations for routines. */
210 extern reg_syntax_t re_set_syntax (reg_syntax_t syntax);
212 extern const char *re_compile_pattern (const char *pattern, size_t length,
213 struct re_pattern_buffer *buffer);
215 extern int re_compile_fastmap (struct re_pattern_buffer *buffer);
217 extern int re_search (struct re_pattern_buffer *buffer, const char *string,
218 int length, int start, int range,
219 struct re_registers *regs);
221 extern int re_search_2 (struct re_pattern_buffer *buffer, const char *string1,
222 int length1, const char *string2, int length2,
223 int start, int range, struct re_registers *regs,
226 extern int re_match (struct re_pattern_buffer *buffer, const char *string,
227 int length, int start, struct re_registers *regs);
229 extern int re_match_2 (struct re_pattern_buffer *buffer, const char *string1,
230 int length1, const char *string2, int length2,
231 int start, struct re_registers *regs, int stop);
233 extern void re_set_registers (struct re_pattern_buffer *buffer,
234 struct re_registers *regs, unsigned num_regs,
235 regoff_t *starts, regoff_t *ends);
237 /* 4.2 bsd compatibility. */
238 extern char *re_comp (const char *);
239 extern int re_exec (const char *);
241 /* POSIX compatibility. */
242 extern int regcomp (regex_t *preg, const char *pattern, int cflags);
244 extern int regexec (const regex_t *preg, const char *string, size_t nmatch,
245 regmatch_t pmatch[], int eflags);
247 extern size_t regerror (int errcode, const regex_t *preg, char *errbuf,
250 extern void regfree (regex_t *preg);
252 #endif /* not __REGEXP_LIBRARY_H__ */