]>
Commit | Line | Data |
---|---|---|
1 | #ifndef _REGEX_H_ | |
2 | #define _REGEX_H_ /* never again */ | |
3 | ||
4 | /* | |
5 | * regular expressions | |
6 | * | |
7 | * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved. | |
8 | * | |
9 | * Development of this software was funded, in part, by Cray Research Inc., | |
10 | * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics | |
11 | * Corporation, none of whom are responsible for the results. The author | |
12 | * thanks all of them. | |
13 | * | |
14 | * Redistribution and use in source and binary forms -- with or without | |
15 | * modification -- are permitted for any purpose, provided that | |
16 | * redistributions in source form retain this entire copyright notice and | |
17 | * indicate the origin and nature of any modifications. | |
18 | * | |
19 | * I'd appreciate being given credit for this package in the documentation | |
20 | * of software which uses it, but that is not a requirement. | |
21 | * | |
22 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
23 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | |
24 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | |
25 | * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
28 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
31 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
32 | * | |
33 | * $Id$ | |
34 | */ | |
35 | ||
36 | /* | |
37 | * Add your own defines, if needed, here. | |
38 | */ | |
39 | #ifdef __cplusplus | |
40 | extern "C" { | |
41 | #endif | |
42 | ||
43 | /***************************** | |
44 | WXWINDOWS CUSTOM | |
45 | *****************************/ | |
46 | #ifndef _REGEX_CUSTOM_H_ | |
47 | # define wx_wchar wxChar | |
48 | /* FreeBSD, Watcom and DMars require this, CW doesn't have nor need it. */ | |
49 | /* Others also don't seem to need it. If you have an error related to */ | |
50 | /* (not) including <sys/types.h> please report details to */ | |
51 | /* wx-dev@lists.wxwindows.org */ | |
52 | # if defined(__UNIX__) || defined(__WATCOMC__) || defined(__DIGITALMARS__) | |
53 | # include <sys/types.h> | |
54 | # endif | |
55 | #endif /* ndef _REGEX_CUSTOM_H_ */ | |
56 | /***************************** | |
57 | END WXWINDOWS CUSTOM | |
58 | *****************************/ | |
59 | ||
60 | #include <stdio.h> | |
61 | #include <stdlib.h> | |
62 | ||
63 | /* | |
64 | * interface types etc. | |
65 | */ | |
66 | ||
67 | /* | |
68 | * regoff_t has to be large enough to hold either off_t or ssize_t, | |
69 | * and must be signed; it's only a guess that long is suitable. | |
70 | */ | |
71 | typedef long regoff_t; | |
72 | ||
73 | /* | |
74 | * other interface types | |
75 | */ | |
76 | ||
77 | /* the biggie, a compiled RE (or rather, a front end to same) */ | |
78 | typedef struct | |
79 | { | |
80 | int re_magic; /* magic number */ | |
81 | size_t re_nsub; /* number of subexpressions */ | |
82 | long re_info; /* information about RE */ | |
83 | #define REG_UBACKREF 000001 | |
84 | #define REG_ULOOKAHEAD 000002 | |
85 | #define REG_UBOUNDS 000004 | |
86 | #define REG_UBRACES 000010 | |
87 | #define REG_UBSALNUM 000020 | |
88 | #define REG_UPBOTCH 000040 | |
89 | #define REG_UBBS 000100 | |
90 | #define REG_UNONPOSIX 000200 | |
91 | #define REG_UUNSPEC 000400 | |
92 | #define REG_UUNPORT 001000 | |
93 | #define REG_ULOCALE 002000 | |
94 | #define REG_UEMPTYMATCH 004000 | |
95 | #define REG_UIMPOSSIBLE 010000 | |
96 | #define REG_USHORTEST 020000 | |
97 | int re_csize; /* sizeof(character) */ | |
98 | char *re_endp; /* backward compatibility kludge */ | |
99 | /* the rest is opaque pointers to hidden innards */ | |
100 | char *re_guts; /* `char *' is more portable than `void *' */ | |
101 | char *re_fns; | |
102 | } regex_t; | |
103 | ||
104 | /* result reporting (may acquire more fields later) */ | |
105 | typedef struct | |
106 | { | |
107 | regoff_t rm_so; /* start of substring */ | |
108 | regoff_t rm_eo; /* end of substring */ | |
109 | } regmatch_t; | |
110 | ||
111 | /* supplementary control and reporting */ | |
112 | typedef struct | |
113 | { | |
114 | regmatch_t rm_extend; /* see REG_EXPECT */ | |
115 | } rm_detail_t; | |
116 | ||
117 | ||
118 | ||
119 | /* | |
120 | * regex compilation flags | |
121 | */ | |
122 | #define REG_BASIC 000000 /* BREs (convenience) */ | |
123 | #define REG_EXTENDED 000001 /* EREs */ | |
124 | #define REG_ADVF 000002 /* advanced features in EREs */ | |
125 | #define REG_ADVANCED 000003 /* AREs (which are also EREs) */ | |
126 | #define REG_QUOTE 000004 /* no special characters, none */ | |
127 | #define REG_NOSPEC REG_QUOTE /* historical synonym */ | |
128 | #define REG_ICASE 000010 /* ignore case */ | |
129 | #define REG_NOSUB 000020 /* don't care about subexpressions */ | |
130 | #define REG_EXPANDED 000040 /* expanded format, white space & comments */ | |
131 | #define REG_NLSTOP 000100 /* \n doesn't match . or [^ ] */ | |
132 | #define REG_NLANCH 000200 /* ^ matches after \n, $ before */ | |
133 | #define REG_NEWLINE 000300 /* newlines are line terminators */ | |
134 | #define REG_PEND 000400 /* ugh -- backward-compatibility hack */ | |
135 | #define REG_EXPECT 001000 /* report details on partial/limited | |
136 | * matches */ | |
137 | #define REG_BOSONLY 002000 /* temporary kludge for BOS-only matches */ | |
138 | #define REG_DUMP 004000 /* none of your business :-) */ | |
139 | #define REG_FAKE 010000 /* none of your business :-) */ | |
140 | #define REG_PROGRESS 020000 /* none of your business :-) */ | |
141 | ||
142 | ||
143 | ||
144 | /* | |
145 | * regex execution flags | |
146 | */ | |
147 | #define REG_NOTBOL 0001 /* BOS is not BOL */ | |
148 | #define REG_NOTEOL 0002 /* EOS is not EOL */ | |
149 | #define REG_STARTEND 0004 /* backward compatibility kludge */ | |
150 | #define REG_FTRACE 0010 /* none of your business */ | |
151 | #define REG_MTRACE 0020 /* none of your business */ | |
152 | #define REG_SMALL 0040 /* none of your business */ | |
153 | ||
154 | ||
155 | /* | |
156 | * error reporting | |
157 | * Be careful if modifying the list of error codes -- the table used by | |
158 | * regerror() is generated automatically from this file! | |
159 | */ | |
160 | #define REG_OKAY 0 /* no errors detected */ | |
161 | #define REG_NOMATCH 1 /* failed to match */ | |
162 | #define REG_BADPAT 2 /* invalid regexp */ | |
163 | #define REG_ECOLLATE 3 /* invalid collating element */ | |
164 | #define REG_ECTYPE 4 /* invalid character class */ | |
165 | #define REG_EESCAPE 5 /* invalid escape \ sequence */ | |
166 | #define REG_ESUBREG 6 /* invalid backreference number */ | |
167 | #define REG_EBRACK 7 /* brackets [] not balanced */ | |
168 | #define REG_EPAREN 8 /* parentheses () not balanced */ | |
169 | #define REG_EBRACE 9 /* braces {} not balanced */ | |
170 | #define REG_BADBR 10 /* invalid repetition count(s) */ | |
171 | #define REG_ERANGE 11 /* invalid character range */ | |
172 | #define REG_ESPACE 12 /* out of memory */ | |
173 | #define REG_BADRPT 13 /* quantifier operand invalid */ | |
174 | #define REG_ASSERT 15 /* "can't happen" -- you found a bug */ | |
175 | #define REG_INVARG 16 /* invalid argument to regex function */ | |
176 | #define REG_MIXED 17 /* character widths of regex and string | |
177 | * differ */ | |
178 | #define REG_BADOPT 18 /* invalid embedded option */ | |
179 | /* two specials for debugging and testing */ | |
180 | #define REG_ATOI 101 /* convert error-code name to number */ | |
181 | #define REG_ITOA 102 /* convert error-code number to name */ | |
182 | ||
183 | ||
184 | ||
185 | /* | |
186 | * the prototypes for exported functions | |
187 | */ | |
188 | extern int wx_regcomp(regex_t *, const wx_wchar *, size_t, int); | |
189 | extern int regcomp(regex_t *, const wx_wchar *, int); | |
190 | extern int wx_regexec(regex_t *, const wx_wchar *, size_t, rm_detail_t *, size_t, regmatch_t[], int); | |
191 | extern int regexec(regex_t *, const wx_wchar *, size_t, regmatch_t[], int); | |
192 | extern void regfree(regex_t *); | |
193 | extern size_t regerror(int, const regex_t *, char *, size_t); | |
194 | extern void wx_regfree(regex_t *); | |
195 | extern size_t wx_regerror(int, const regex_t *, char *, size_t); | |
196 | ||
197 | #ifdef __cplusplus | |
198 | } | |
199 | #endif | |
200 | ||
201 | #endif /* _REGEX_H_ */ |