MISR Toolkit  1.5.1
regex.h
Go to the documentation of this file.
1 /*
2  regex.h - POSIX.2 compatible regexp interface and TRE extensions
3 
4  Copyright (c) 2001-2006 Ville Laurikari <vl@iki.fi>.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 */
21 
22 #ifndef TRE_REGEX_H
23 #define TRE_REGEX_H 1
24 
25 #ifndef __GNUC__
26 # define __DLL_IMPORT__ __declspec(dllimport)
27 # define __DLL_EXPORT__ __declspec(dllexport)
28 #else
29 # define __DLL_IMPORT__ __attribute__((dllimport)) extern
30 # define __DLL_EXPORT__ __attribute__((dllexport)) extern
31 #endif
32 
33 #if (defined __WIN32__) || (defined _WIN32)
34 # if defined BUILD_LIBTRE_DLL || defined TRE_EXPORTS
35 # define LIBTRE_DLL_IMPEXP __DLL_EXPORT__
36 # elif defined(LIBTRE_STATIC)
37 # define LIBTRE_DLL_IMPEXP
38 # elif defined (USE_LIBTRE_DLL)
39 # define LIBTRE_DLL_IMPEXP __DLL_IMPORT__
40 # elif defined (USE_LIBTRE_STATIC)
41 # define LIBTRE_DLL_IMPEXP
42 # else /* assume USE_LIBTRE_DLL */
43 # define LIBTRE_DLL_IMPEXP __DLL_IMPORT__
44 # endif
45 #else /* __WIN32__ */
46 # define LIBTRE_DLL_IMPEXP
47 #endif
48 
49 #include "tre-config.h"
50 
51 #ifdef HAVE_SYS_TYPES_H
52 #include <sys/types.h>
53 #endif /* HAVE_SYS_TYPES_H */
54 
55 #ifdef HAVE_LIBUTF8_H
56 #include <libutf8.h>
57 #endif /* HAVE_LIBUTF8_H */
58 
59 #ifdef TRE_USE_SYSTEM_REGEX_H
60 /* Include the system regex.h to make TRE ABI compatible with the
61  system regex. */
62 #include TRE_SYSTEM_REGEX_H_PATH
63 #endif /* TRE_USE_SYSTEM_REGEX_H */
64 
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68 
69 #ifdef TRE_USE_SYSTEM_REGEX_H
70 
71 #ifndef REG_OK
72 #define REG_OK 0
73 #endif /* !REG_OK */
74 
75 #ifndef HAVE_REG_ERRCODE_T
76 typedef int reg_errcode_t;
77 #endif /* !HAVE_REG_ERRCODE_T */
78 
79 #if !defined(REG_NOSPEC) && !defined(REG_LITERAL)
80 #define REG_LITERAL 0x1000
81 #endif
82 
83 /* Extra regcomp() flags. */
84 #ifndef REG_BASIC
85 #define REG_BASIC 0
86 #endif /* !REG_BASIC */
87 #define REG_RIGHT_ASSOC (REG_LITERAL << 1)
88 #define REG_UNGREEDY (REG_RIGHT_ASSOC << 1)
89 
90 /* Extra regexec() flags. */
91 #define REG_APPROX_MATCHER 0x1000
92 #define REG_BACKTRACKING_MATCHER (REG_APPROX_MATCHER << 1)
93 
94 #else /* !TRE_USE_SYSTEM_REGEX_H */
95 
96 /* If the we're not using system regex.h, we need to define the
97  structs and enums ourselves. */
98 
99 typedef int regoff_t;
100 typedef struct {
101  size_t re_nsub; /* Number of parenthesized subexpressions. */
102  void *value; /* For internal use only. */
103 } regex_t;
104 
105 typedef struct {
106  regoff_t rm_so;
107  regoff_t rm_eo;
108 } regmatch_t;
109 
110 
111 typedef enum {
112  REG_OK = 0, /* No error. */
113  /* POSIX regcomp() return error codes. (In the order listed in the
114  standard.) */
115  REG_NOMATCH, /* No match. */
116  REG_BADPAT, /* Invalid regexp. */
117  REG_ECOLLATE, /* Unknown collating element. */
118  REG_ECTYPE, /* Unknown character class name. */
119  REG_EESCAPE, /* Trailing backslash. */
120  REG_ESUBREG, /* Invalid back reference. */
121  REG_EBRACK, /* "[]" imbalance */
122  REG_EPAREN, /* "\(\)" or "()" imbalance */
123  REG_EBRACE, /* "\{\}" or "{}" imbalance */
124  REG_BADBR, /* Invalid content of {} */
125  REG_ERANGE, /* Invalid use of range operator */
126  REG_ESPACE, /* Out of memory. */
127  REG_BADRPT /* Invalid use of repetition operators. */
128 } reg_errcode_t;
129 
130 /* POSIX regcomp() flags. */
131 #define REG_EXTENDED 1
132 #define REG_ICASE (REG_EXTENDED << 1)
133 #define REG_NEWLINE (REG_ICASE << 1)
134 #define REG_NOSUB (REG_NEWLINE << 1)
135 
136 /* Extra regcomp() flags. */
137 #define REG_BASIC 0
138 #define REG_LITERAL (REG_NOSUB << 1)
139 #define REG_RIGHT_ASSOC (REG_LITERAL << 1)
140 #define REG_UNGREEDY (REG_RIGHT_ASSOC << 1)
141 
142 /* POSIX regexec() flags. */
143 #define REG_NOTBOL 1
144 #define REG_NOTEOL (REG_NOTBOL << 1)
145 
146 /* Extra regexec() flags. */
147 #define REG_APPROX_MATCHER (REG_NOTEOL << 1)
148 #define REG_BACKTRACKING_MATCHER (REG_APPROX_MATCHER << 1)
149 
150 #endif /* !TRE_USE_SYSTEM_REGEX_H */
151 
152 /* REG_NOSPEC and REG_LITERAL mean the same thing. */
153 #if defined(REG_LITERAL) && !defined(REG_NOSPEC)
154 #define REG_NOSPEC REG_LITERAL
155 #elif defined(REG_NOSPEC) && !defined(REG_LITERAL)
156 #define REG_LITERAL REG_NOSPEC
157 #endif /* defined(REG_NOSPEC) */
158 
159 /* The maximum number of iterations in a bound expression. */
160 #undef RE_DUP_MAX
161 #define RE_DUP_MAX 255
162 
163 /* The POSIX.2 regexp functions */
165 regcomp(regex_t *preg, const char *regex, int cflags);
166 
168 regexec(const regex_t *preg, const char *string, size_t nmatch,
169  regmatch_t pmatch[], int eflags);
170 
171 LIBTRE_DLL_IMPEXP size_t
172 regerror(int errcode, const regex_t *preg, char *errbuf,
173  size_t errbuf_size);
174 
176 regfree(regex_t *preg);
177 
178 #ifdef TRE_WCHAR
179 #ifdef HAVE_WCHAR_H
180 #include <wchar.h>
181 #endif /* HAVE_WCHAR_H */
182 
183 /* Wide character versions (not in POSIX.2). */
185 regwcomp(regex_t *preg, const wchar_t *regex, int cflags);
186 
188 regwexec(const regex_t *preg, const wchar_t *string,
189  size_t nmatch, regmatch_t pmatch[], int eflags);
190 #endif /* TRE_WCHAR */
191 
192 /* Versions with a maximum length argument and therefore the capability to
193  handle null characters in the middle of the strings (not in POSIX.2). */
195 regncomp(regex_t *preg, const char *regex, size_t len, int cflags);
196 
198 regnexec(const regex_t *preg, const char *string, size_t len,
199  size_t nmatch, regmatch_t pmatch[], int eflags);
200 
201 #ifdef TRE_WCHAR
203 regwncomp(regex_t *preg, const wchar_t *regex, size_t len, int cflags);
204 
206 regwnexec(const regex_t *preg, const wchar_t *string, size_t len,
207  size_t nmatch, regmatch_t pmatch[], int eflags);
208 #endif /* TRE_WCHAR */
209 
210 #ifdef TRE_APPROX
211 
212 /* Approximate matching parameter struct. */
213 typedef struct {
214  int cost_ins; /* Default cost of an inserted character. */
215  int cost_del; /* Default cost of a deleted character. */
216  int cost_subst; /* Default cost of a substituted character. */
217  int max_cost; /* Maximum allowed cost of a match. */
218 
219  int max_ins; /* Maximum allowed number of inserts. */
220  int max_del; /* Maximum allowed number of deletes. */
221  int max_subst; /* Maximum allowed number of substitutes. */
222  int max_err; /* Maximum allowed number of errors total. */
223 } regaparams_t;
224 
225 /* Approximate matching result struct. */
226 typedef struct {
227  size_t nmatch; /* Length of pmatch[] array. */
228  regmatch_t *pmatch; /* Submatch data. */
229  int cost; /* Cost of the match. */
230  int num_ins; /* Number of inserts in the match. */
231  int num_del; /* Number of deletes in the match. */
232  int num_subst; /* Number of substitutes in the match. */
233 } regamatch_t;
234 
235 
236 /* Approximate matching functions. */
238 regaexec(const regex_t *preg, const char *string,
239  regamatch_t *match, regaparams_t params, int eflags);
240 
242 reganexec(const regex_t *preg, const char *string, size_t len,
243  regamatch_t *match, regaparams_t params, int eflags);
244 #ifdef TRE_WCHAR
245 /* Wide character approximate matching. */
247 regawexec(const regex_t *preg, const wchar_t *string,
248  regamatch_t *match, regaparams_t params, int eflags);
249 
251 regawnexec(const regex_t *preg, const wchar_t *string, size_t len,
252  regamatch_t *match, regaparams_t params, int eflags);
253 #endif /* TRE_WCHAR */
254 
255 /* Sets the parameters to default values. */
258 #endif /* TRE_APPROX */
259 
260 #ifdef TRE_WCHAR
261 typedef wchar_t tre_char_t;
262 #else /* !TRE_WCHAR */
263 typedef unsigned char tre_char_t;
264 #endif /* !TRE_WCHAR */
265 
266 typedef struct {
267  int (*get_next_char)(tre_char_t *c, unsigned int *pos_add, void *context);
268  void (*rewind)(size_t pos, void *context);
269  int (*compare)(size_t pos1, size_t pos2, size_t len, void *context);
270  void *context;
272 
274 reguexec(const regex_t *preg, const tre_str_source *string,
275  size_t nmatch, regmatch_t pmatch[], int eflags);
276 
277 /* Returns the version string. The returned string is static. */
278 LIBTRE_DLL_IMPEXP char *
279 tre_version(void);
280 
281 /* Returns the value for a config parameter. The type to which `result'
282  must point to depends of the value of `query', see documentation for
283  more details. */
285 tre_config(int query, void *result);
286 
287 enum {
293 };
294 
295 /* Returns 1 if the compiled pattern has back references, 0 if not. */
297 tre_have_backrefs(const regex_t *preg);
298 
299 /* Returns 1 if the compiled pattern uses approximate matching features,
300  0 if not. */
302 tre_have_approx(const regex_t *preg);
303 
304 #ifdef __cplusplus
305 }
306 #endif
307 #endif /* TRE_REGEX_H */
308 
309 /* EOF */
HDFFCLIBAPI intf * len
int num_ins
Definition: regex.h:230
LIBTRE_DLL_IMPEXP int tre_have_backrefs(const regex_t *preg)
LIBTRE_DLL_IMPEXP void regaparams_default(regaparams_t *params)
int cost_del
Definition: regex.h:215
Definition: regex.h:112
regoff_t rm_so
Definition: regex.h:106
#define LIBTRE_DLL_IMPEXP
Definition: regex.h:46
int cost_ins
Definition: regex.h:214
void * value
Definition: regex.h:102
#define regwexec
Definition: regex.h:34
LIBTRE_DLL_IMPEXP int tre_have_approx(const regex_t *preg)
int max_cost
Definition: regex.h:217
LIBTRE_DLL_IMPEXP int regncomp(regex_t *preg, const char *regex, size_t len, int cflags)
LIBTRE_DLL_IMPEXP int tre_config(int query, void *result)
regoff_t rm_eo
Definition: regex.h:107
LIBTRE_DLL_IMPEXP void regfree(regex_t *preg)
int num_subst
Definition: regex.h:232
size_t re_nsub
Definition: regex.h:101
LIBTRE_DLL_IMPEXP int regcomp(regex_t *preg, const char *regex, int cflags)
LIBTRE_DLL_IMPEXP char * tre_version(void)
LIBTRE_DLL_IMPEXP int reganexec(const regex_t *preg, const char *string, size_t len, regamatch_t *match, regaparams_t params, int eflags)
int max_err
Definition: regex.h:222
int num_del
Definition: regex.h:231
#define regwncomp
Definition: regex.h:35
int regoff_t
Definition: regex.h:99
void * context
Definition: regex.h:270
LIBTRE_DLL_IMPEXP size_t regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
#define regwcomp
Definition: regex.h:33
int max_subst
Definition: regex.h:221
#define regawnexec
Definition: regex.h:30
int cost_subst
Definition: regex.h:216
int cost
Definition: regex.h:229
LIBTRE_DLL_IMPEXP int regaexec(const regex_t *preg, const char *string, regamatch_t *match, regaparams_t params, int eflags)
int max_ins
Definition: regex.h:219
size_t nmatch
Definition: regex.h:227
LIBTRE_DLL_IMPEXP int regnexec(const regex_t *preg, const char *string, size_t len, size_t nmatch, regmatch_t pmatch[], int eflags)
reg_errcode_t
Definition: regex.h:111
int max_del
Definition: regex.h:220
#define regwnexec
Definition: regex.h:36
unsigned char tre_char_t
Definition: regex.h:263
LIBTRE_DLL_IMPEXP int reguexec(const regex_t *preg, const tre_str_source *string, size_t nmatch, regmatch_t pmatch[], int eflags)
Definition: regex.h:100
regmatch_t * pmatch
Definition: regex.h:228
LIBTRE_DLL_IMPEXP int regexec(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags)

MISR Toolkit - Copyright © 2005 - 2020 Jet Propulsion Laboratory
Generated on Fri Jun 19 2020 22:49:52