Debian Codegraph @

generic/regex.h

raw
1 #ifndef _REGEX_H_
2 #define _REGEX_H_ /* never again */
3
4 #include "tclInt.h"
5
6 /*
7 * regular expressions
8 *
9 * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved.
10 *
11 * Development of this software was funded, in part, by Cray Research Inc.,
12 * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics
13 * Corporation, none of whom are responsible for the results. The author
14 * thanks all of them.
15 *
16 * Redistribution and use in source and binary forms -- with or without
17 * modification -- are permitted for any purpose, provided that
18 * redistributions in source form retain this entire copyright notice and
19 * indicate the origin and nature of any modifications.
20 *
21 * I'd appreciate being given credit for this package in the documentation of
22 * software which uses it, but that is not a requirement.
23 *
24 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
27 * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
30 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 *
36 * Prototypes etc. marked with "^" within comments get gathered up (and
37 * possibly edited) by the regfwd program and inserted near the bottom of this
38 * file.
39 *
40 * We offer the option of declaring one wide-character version of the RE
41 * functions as well as the char versions. To do that, define __REG_WIDE_T to
42 * the type of wide characters (unfortunately, there is no consensus that
43 * wchar_t is suitable) and __REG_WIDE_COMPILE and __REG_WIDE_EXEC to the
44 * names to be used for the compile and execute functions (suggestion:
45 * re_Xcomp and re_Xexec, where X is a letter suggestive of the wide type,
46 * e.g. re_ucomp and re_uexec for Unicode). For cranky old compilers, it may
47 * be necessary to do something like:
48 * #define __REG_WIDE_COMPILE(a,b,c,d) re_Xcomp(a,b,c,d)
49 * #define __REG_WIDE_EXEC(a,b,c,d,e,f,g) re_Xexec(a,b,c,d,e,f,g)
50 * rather than just #defining the names as parameterless macros.
51 *
52 * For some specialized purposes, it may be desirable to suppress the
53 * declarations of the "front end" functions, regcomp() and regexec(), or of
54 * the char versions of the compile and execute functions. To suppress the
55 * front-end functions, define __REG_NOFRONT. To suppress the char versions,
56 * define __REG_NOCHAR.
57 *
58 * The right place to do those defines (and some others you may want, see
59 * below) would be <sys/types.h>. If you don't have control of that file, the
60 * right place to add your own defines to this file is marked below. This is
61 * normally done automatically, by the makefile and regmkhdr, based on the
62 * contents of regcustom.h.
63 */
64
65 /*
66 * voodoo for C++
67 */
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71
72 /*
73 * Add your own defines, if needed, here.
74 */
75
76 /*
77 * Location where a chunk of regcustom.h is automatically spliced into this
78 * file (working from its prototype, regproto.h).
79 */
80
81 /* --- begin --- */
82 /* ensure certain things don't sneak in from system headers */
83 #ifdef __REG_WIDE_T
84 #undef __REG_WIDE_T
85 #endif
86 #ifdef __REG_WIDE_COMPILE
87 #undef __REG_WIDE_COMPILE
88 #endif
89 #ifdef __REG_WIDE_EXEC
90 #undef __REG_WIDE_EXEC
91 #endif
92 #ifdef __REG_REGOFF_T
93 #undef __REG_REGOFF_T
94 #endif
95 #ifdef __REG_NOFRONT
96 #undef __REG_NOFRONT
97 #endif
98 #ifdef __REG_NOCHAR
99 #undef __REG_NOCHAR
100 #endif
101 /* interface types */
102 #define __REG_WIDE_T Tcl_UniChar
103 #define __REG_REGOFF_T long /* not really right, but good enough... */
104 /* names and declarations */
105 #define __REG_WIDE_COMPILE TclReComp
106 #define __REG_WIDE_EXEC TclReExec
107 #define __REG_NOFRONT /* don't want regcomp() and regexec() */
108 #define __REG_NOCHAR /* or the char versions */
109 #define regfree TclReFree
110 #define regerror TclReError
111 /* --- end --- */
112
113 /*
114 * interface types etc.
115 */
116
117 /*
118 * regoff_t has to be large enough to hold either off_t or ssize_t, and must
119 * be signed; it's only a guess that long is suitable, so we offer
120 * <sys/types.h> an override.
121 */
122 #ifdef __REG_REGOFF_T
123 typedef __REG_REGOFF_T regoff_t;
124 #else
125 typedef long regoff_t;
126 #endif
127
128 /*
129 * other interface types
130 */
131
132 /* the biggie, a compiled RE (or rather, a front end to same) */
133 typedef struct {
134 int re_magic; /* magic number */
135 size_t re_nsub; /* number of subexpressions */
136 long re_info; /* information about RE */
137 #define REG_UBACKREF 000001
138 #define REG_ULOOKAHEAD 000002
139 #define REG_UBOUNDS 000004
140 #define REG_UBRACES 000010
141 #define REG_UBSALNUM 000020
142 #define REG_UPBOTCH 000040
143 #define REG_UBBS 000100
144 #define REG_UNONPOSIX 000200
145 #define REG_UUNSPEC 000400
146 #define REG_UUNPORT 001000
147 #define REG_ULOCALE 002000
148 #define REG_UEMPTYMATCH 004000
149 #define REG_UIMPOSSIBLE 010000
150 #define REG_USHORTEST 020000
151 int re_csize; /* sizeof(character) */
152 char *re_endp; /* backward compatibility kludge */
153 /* the rest is opaque pointers to hidden innards */
154 char *re_guts; /* `char *' is more portable than `void *' */
155 char *re_fns;
156 } regex_t;
157
158 /* result reporting (may acquire more fields later) */
159 typedef struct {
160 regoff_t rm_so; /* start of substring */
161 regoff_t rm_eo; /* end of substring */
162 } regmatch_t;
163
164 /* supplementary control and reporting */
165 typedef struct {
166 regmatch_t rm_extend; /* see REG_EXPECT */
167 } rm_detail_t;
168
169 /*
170 * compilation
171 ^ #ifndef __REG_NOCHAR
172 ^ int re_comp(regex_t *, const char *, size_t, int);
173 ^ #endif
174 ^ #ifndef __REG_NOFRONT
175 ^ int regcomp(regex_t *, const char *, int);
176 ^ #endif
177 ^ #ifdef __REG_WIDE_T
178 ^ int __REG_WIDE_COMPILE(regex_t *, const __REG_WIDE_T *, size_t, int);
179 ^ #endif
180 */
181 #define REG_BASIC 000000 /* BREs (convenience) */
182 #define REG_EXTENDED 000001 /* EREs */
183 #define REG_ADVF 000002 /* advanced features in EREs */
184 #define REG_ADVANCED 000003 /* AREs (which are also EREs) */
185 #define REG_QUOTE 000004 /* no special characters, none */
186 #define REG_NOSPEC REG_QUOTE /* historical synonym */
187 #define REG_ICASE 000010 /* ignore case */
188 #define REG_NOSUB 000020 /* don't care about subexpressions */
189 #define REG_EXPANDED 000040 /* expanded format, white space & comments */
190 #define REG_NLSTOP 000100 /* \n doesn't match . or [^ ] */
191 #define REG_NLANCH 000200 /* ^ matches after \n, $ before */
192 #define REG_NEWLINE 000300 /* newlines are line terminators */
193 #define REG_PEND 000400 /* ugh -- backward-compatibility hack */
194 #define REG_EXPECT 001000 /* report details on partial/limited matches */
195 #define REG_BOSONLY 002000 /* temporary kludge for BOS-only matches */
196 #define REG_DUMP 004000 /* none of your business :-) */
197 #define REG_FAKE 010000 /* none of your business :-) */
198 #define REG_PROGRESS 020000 /* none of your business :-) */
199
200 /*
201 * execution
202 ^ #ifndef __REG_NOCHAR
203 ^ int re_exec(regex_t *, const char *, size_t,
204 ^ rm_detail_t *, size_t, regmatch_t [], int);
205 ^ #endif
206 ^ #ifndef __REG_NOFRONT
207 ^ int regexec(regex_t *, const char *, size_t, regmatch_t [], int);
208 ^ #endif
209 ^ #ifdef __REG_WIDE_T
210 ^ int __REG_WIDE_EXEC(regex_t *, const __REG_WIDE_T *, size_t,
211 ^ rm_detail_t *, size_t, regmatch_t [], int);
212 ^ #endif
213 */
214 #define REG_NOTBOL 0001 /* BOS is not BOL */
215 #define REG_NOTEOL 0002 /* EOS is not EOL */
216 #define REG_STARTEND 0004 /* backward compatibility kludge */
217 #define REG_FTRACE 0010 /* none of your business */
218 #define REG_MTRACE 0020 /* none of your business */
219 #define REG_SMALL 0040 /* none of your business */
220
221 /*
222 * misc generics (may be more functions here eventually)
223 ^ void regfree(regex_t *);
224 */
225
226 /*
227 * error reporting
228 * Be careful if modifying the list of error codes -- the table used by
229 * regerror() is generated automatically from this file!
230 *
231 * Note that there is no wide-char variant of regerror at this time; what kind
232 * of character is used for error reports is independent of what kind is used
233 * in matching.
234 *
235 ^ extern size_t regerror(int, char *, size_t);
236 */
237 #define REG_OKAY 0 /* no errors detected */
238 #define REG_NOMATCH 1 /* failed to match */
239 #define REG_BADPAT 2 /* invalid regexp */
240 #define REG_ECOLLATE 3 /* invalid collating element */
241 #define REG_ECTYPE 4 /* invalid character class */
242 #define REG_EESCAPE 5 /* invalid escape \ sequence */
243 #define REG_ESUBREG 6 /* invalid backreference number */
244 #define REG_EBRACK 7 /* brackets [] not balanced */
245 #define REG_EPAREN 8 /* parentheses () not balanced */
246 #define REG_EBRACE 9 /* braces {} not balanced */
247 #define REG_BADBR 10 /* invalid repetition count(s) */
248 #define REG_ERANGE 11 /* invalid character range */
249 #define REG_ESPACE 12 /* out of memory */
250 #define REG_BADRPT 13 /* quantifier operand invalid */
251 #define REG_ASSERT 15 /* "can't happen" -- you found a bug */
252 #define REG_INVARG 16 /* invalid argument to regex function */
253 #define REG_MIXED 17 /* character widths of regex and string differ */
254 #define REG_BADOPT 18 /* invalid embedded option */
255 #define REG_ETOOBIG 19 /* regular expression is too complex */
256 #define REG_ECOLORS 20 /* too many colors */
257 /* two specials for debugging and testing */
258 #define REG_ATOI 101 /* convert error-code name to number */
259 #define REG_ITOA 102 /* convert error-code number to name */
260
261 /*
262 * the prototypes, as possibly munched by regfwd
263 */
264 /* =====^!^===== begin forwards =====^!^===== */
265 /* automatically gathered by fwd; do not hand-edit */
266 /* === regproto.h === */
267 #ifndef __REG_NOCHAR
268 int re_comp(regex_t *, const char *, size_t, int);
269 #endif
270 #ifndef __REG_NOFRONT
271 int regcomp(regex_t *, const char *, int);
272 #endif
273 #ifdef __REG_WIDE_T
274 MODULE_SCOPE int __REG_WIDE_COMPILE(regex_t *, const __REG_WIDE_T *, size_t, int);
275 #endif
276 #ifndef __REG_NOCHAR
277 int re_exec(regex_t *, const char *, size_t, rm_detail_t *, size_t, regmatch_t [], int);
278 #endif
279 #ifndef __REG_NOFRONT
280 int regexec(regex_t *, const char *, size_t, regmatch_t [], int);
281 #endif
282 #ifdef __REG_WIDE_T
283 MODULE_SCOPE int __REG_WIDE_EXEC(regex_t *, const __REG_WIDE_T *, size_t, rm_detail_t *, size_t, regmatch_t [], int);
284 #endif
285 MODULE_SCOPE void regfree(regex_t *);
286 MODULE_SCOPE size_t regerror(int, char *, size_t);
287 /* automatically gathered by fwd; do not hand-edit */
288 /* =====^!^===== end forwards =====^!^===== */
289
290 /*
291 * more C++ voodoo
292 */
293 #ifdef __cplusplus
294 }
295 #endif
296
297 #endif
298
299 /*
300 * Local Variables:
301 * mode: c
302 * c-basic-offset: 4
303 * fill-column: 78
304 * End:
305 */