MISR Toolkit  1.5.1
tre.h
Go to the documentation of this file.
1 /*
2  tre.h - TRE public API definitions
3 
4  This software is released under a BSD-style license.
5  See the file LICENSE for details and copyright.
6 
7 */
8 
9 #ifndef TRE_H
10 #define TRE_H 1
11 
12 #include "tre-config.h"
13 
14 #ifdef HAVE_SYS_TYPES_H
15 #include <sys/types.h>
16 #endif /* HAVE_SYS_TYPES_H */
17 
18 #ifdef HAVE_LIBUTF8_H
19 #include <libutf8.h>
20 #endif /* HAVE_LIBUTF8_H */
21 
22 #ifdef TRE_USE_SYSTEM_REGEX_H
23 /* Include the system regex.h to make TRE ABI compatible with the
24  system regex. */
25 #include TRE_SYSTEM_REGEX_H_PATH
26 #define tre_regcomp regcomp
27 #define tre_regexec regexec
28 #define tre_regerror regerror
29 #define tre_regfree regfree
30 #endif /* TRE_USE_SYSTEM_REGEX_H */
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #ifdef TRE_USE_SYSTEM_REGEX_H
37 
38 #ifndef REG_OK
39 #define REG_OK 0
40 #endif /* !REG_OK */
41 
42 #ifndef HAVE_REG_ERRCODE_T
43 typedef int reg_errcode_t;
44 #endif /* !HAVE_REG_ERRCODE_T */
45 
46 #if !defined(REG_NOSPEC) && !defined(REG_LITERAL)
47 #define REG_LITERAL 0x1000
48 #endif
49 
50 /* Extra tre_regcomp() flags. */
51 #ifndef REG_BASIC
52 #define REG_BASIC 0
53 #endif /* !REG_BASIC */
54 #define REG_RIGHT_ASSOC (REG_LITERAL << 1)
55 #define REG_UNGREEDY (REG_RIGHT_ASSOC << 1)
56 
57 /* Extra tre_regexec() flags. */
58 #define REG_APPROX_MATCHER 0x1000
59 #define REG_BACKTRACKING_MATCHER (REG_APPROX_MATCHER << 1)
60 
61 #else /* !TRE_USE_SYSTEM_REGEX_H */
62 
63 /* If the we're not using system regex.h, we need to define the
64  structs and enums ourselves. */
65 
66 typedef int regoff_t;
67 typedef struct {
68  size_t re_nsub; /* Number of parenthesized subexpressions. */
69  void *value; /* For internal use only. */
70 } regex_t;
71 
72 typedef struct {
73  regoff_t rm_so;
74  regoff_t rm_eo;
75 } regmatch_t;
76 
77 
78 typedef enum {
79  REG_OK = 0, /* No error. */
80  /* POSIX tre_regcomp() return error codes. (In the order listed in the
81  standard.) */
82  REG_NOMATCH, /* No match. */
83  REG_BADPAT, /* Invalid regexp. */
84  REG_ECOLLATE, /* Unknown collating element. */
85  REG_ECTYPE, /* Unknown character class name. */
86  REG_EESCAPE, /* Trailing backslash. */
87  REG_ESUBREG, /* Invalid back reference. */
88  REG_EBRACK, /* "[]" imbalance */
89  REG_EPAREN, /* "\(\)" or "()" imbalance */
90  REG_EBRACE, /* "\{\}" or "{}" imbalance */
91  REG_BADBR, /* Invalid content of {} */
92  REG_ERANGE, /* Invalid use of range operator */
93  REG_ESPACE, /* Out of memory. */
94  REG_BADRPT /* Invalid use of repetition operators. */
96 
97 /* POSIX tre_regcomp() flags. */
98 #define REG_EXTENDED 1
99 #define REG_ICASE (REG_EXTENDED << 1)
100 #define REG_NEWLINE (REG_ICASE << 1)
101 #define REG_NOSUB (REG_NEWLINE << 1)
102 
103 /* Extra tre_regcomp() flags. */
104 #define REG_BASIC 0
105 #define REG_LITERAL (REG_NOSUB << 1)
106 #define REG_RIGHT_ASSOC (REG_LITERAL << 1)
107 #define REG_UNGREEDY (REG_RIGHT_ASSOC << 1)
108 
109 #define REG_USEBYTES (REG_UNGREEDY << 1)
110 
111 /* POSIX tre_regexec() flags. */
112 #define REG_NOTBOL 1
113 #define REG_NOTEOL (REG_NOTBOL << 1)
114 
115 /* Extra tre_regexec() flags. */
116 #define REG_APPROX_MATCHER (REG_NOTEOL << 1)
117 #define REG_BACKTRACKING_MATCHER (REG_APPROX_MATCHER << 1)
118 
119 #endif /* !TRE_USE_SYSTEM_REGEX_H */
120 
121 /* REG_NOSPEC and REG_LITERAL mean the same thing. */
122 #if defined(REG_LITERAL) && !defined(REG_NOSPEC)
123 #define REG_NOSPEC REG_LITERAL
124 #elif defined(REG_NOSPEC) && !defined(REG_LITERAL)
125 #define REG_LITERAL REG_NOSPEC
126 #endif /* defined(REG_NOSPEC) */
127 
128 /* The maximum number of iterations in a bound expression. */
129 #undef RE_DUP_MAX
130 #define RE_DUP_MAX 255
131 
132 /* The POSIX.2 regexp functions */
133 extern int
134 tre_regcomp(regex_t *preg, const char *regex, int cflags);
135 
136 extern int
137 tre_regexec(const regex_t *preg, const char *string, size_t nmatch,
138  regmatch_t pmatch[], int eflags);
139 
140 extern int
141 tre_regcompb(regex_t *preg, const char *regex, int cflags);
142 
143 extern int
144 tre_regexecb(const regex_t *preg, const char *string, size_t nmatch,
145  regmatch_t pmatch[], int eflags);
146 
147 extern size_t
148 tre_regerror(int errcode, const regex_t *preg, char *errbuf,
149  size_t errbuf_size);
150 
151 extern void
152 tre_regfree(regex_t *preg);
153 
154 #ifdef TRE_WCHAR
155 #ifdef HAVE_WCHAR_H
156 #include <wchar.h>
157 #endif /* HAVE_WCHAR_H */
158 
159 /* Wide character versions (not in POSIX.2). */
160 extern int
161 tre_regwcomp(regex_t *preg, const wchar_t *regex, int cflags);
162 
163 extern int
164 tre_regwexec(const regex_t *preg, const wchar_t *string,
165  size_t nmatch, regmatch_t pmatch[], int eflags);
166 #endif /* TRE_WCHAR */
167 
168 /* Versions with a maximum length argument and therefore the capability to
169  handle null characters in the middle of the strings (not in POSIX.2). */
170 extern int
171 tre_regncomp(regex_t *preg, const char *regex, size_t len, int cflags);
172 
173 extern int
174 tre_regnexec(const regex_t *preg, const char *string, size_t len,
175  size_t nmatch, regmatch_t pmatch[], int eflags);
176 
177 /* regn*b versions take byte literally as 8-bit values */
178 extern int
179 tre_regncompb(regex_t *preg, const char *regex, size_t n, int cflags);
180 
181 extern int
182 tre_regnexecb(const regex_t *preg, const char *str, size_t len,
183  size_t nmatch, regmatch_t pmatch[], int eflags);
184 
185 #ifdef TRE_WCHAR
186 extern int
187 tre_regwncomp(regex_t *preg, const wchar_t *regex, size_t len, int cflags);
188 
189 extern int
190 tre_regwnexec(const regex_t *preg, const wchar_t *string, size_t len,
191  size_t nmatch, regmatch_t pmatch[], int eflags);
192 #endif /* TRE_WCHAR */
193 
194 #ifdef TRE_APPROX
195 
196 /* Approximate matching parameter struct. */
197 typedef struct {
198  int cost_ins; /* Default cost of an inserted character. */
199  int cost_del; /* Default cost of a deleted character. */
200  int cost_subst; /* Default cost of a substituted character. */
201  int max_cost; /* Maximum allowed cost of a match. */
202 
203  int max_ins; /* Maximum allowed number of inserts. */
204  int max_del; /* Maximum allowed number of deletes. */
205  int max_subst; /* Maximum allowed number of substitutes. */
206  int max_err; /* Maximum allowed number of errors total. */
207 } regaparams_t;
208 
209 /* Approximate matching result struct. */
210 typedef struct {
211  size_t nmatch; /* Length of pmatch[] array. */
212  regmatch_t *pmatch; /* Submatch data. */
213  int cost; /* Cost of the match. */
214  int num_ins; /* Number of inserts in the match. */
215  int num_del; /* Number of deletes in the match. */
216  int num_subst; /* Number of substitutes in the match. */
217 } regamatch_t;
218 
219 
220 /* Approximate matching functions. */
221 extern int
222 tre_regaexec(const regex_t *preg, const char *string,
223  regamatch_t *match, regaparams_t params, int eflags);
224 
225 extern int
226 tre_reganexec(const regex_t *preg, const char *string, size_t len,
227  regamatch_t *match, regaparams_t params, int eflags);
228 
229 extern int
230 tre_regaexecb(const regex_t *preg, const char *string,
231  regamatch_t *match, regaparams_t params, int eflags);
232 
233 #ifdef TRE_WCHAR
234 /* Wide character approximate matching. */
235 extern int
236 tre_regawexec(const regex_t *preg, const wchar_t *string,
237  regamatch_t *match, regaparams_t params, int eflags);
238 
239 extern int
240 tre_regawnexec(const regex_t *preg, const wchar_t *string, size_t len,
241  regamatch_t *match, regaparams_t params, int eflags);
242 #endif /* TRE_WCHAR */
243 
244 /* Sets the parameters to default values. */
245 extern void
247 #endif /* TRE_APPROX */
248 
249 #ifdef TRE_WCHAR
250 typedef wchar_t tre_char_t;
251 #else /* !TRE_WCHAR */
252 typedef unsigned char tre_char_t;
253 #endif /* !TRE_WCHAR */
254 
255 typedef struct {
256  int (*get_next_char)(tre_char_t *c, unsigned int *pos_add, void *context);
257  void (*rewind)(size_t pos, void *context);
258  int (*compare)(size_t pos1, size_t pos2, size_t len, void *context);
259  void *context;
261 
262 extern int
263 tre_reguexec(const regex_t *preg, const tre_str_source *string,
264  size_t nmatch, regmatch_t pmatch[], int eflags);
265 
266 /* Returns the version string. The returned string is static. */
267 extern char *
268 tre_version(void);
269 
270 /* Returns the value for a config parameter. The type to which `result'
271  must point to depends of the value of `query', see documentation for
272  more details. */
273 extern int
274 tre_config(int query, void *result);
275 
276 enum {
282 };
283 
284 /* Returns 1 if the compiled pattern has back references, 0 if not. */
285 extern int
286 tre_have_backrefs(const regex_t *preg);
287 
288 /* Returns 1 if the compiled pattern uses approximate matching features,
289  0 if not. */
290 extern int
291 tre_have_approx(const regex_t *preg);
292 
293 #ifdef __cplusplus
294 }
295 #endif
296 #endif /* TRE_H */
297 
298 /* EOF */
HDFFCLIBAPI intf * len
char * tre_version(void)
int tre_regwncomp(regex_t *preg, const wchar_t *regex, size_t len, int cflags)
int tre_regwnexec(const regex_t *preg, const wchar_t *string, size_t len, size_t nmatch, regmatch_t pmatch[], int eflags)
int tre_regexec(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags)
int tre_regncomp(regex_t *preg, const char *regex, size_t len, int cflags)
int tre_regaexecb(const regex_t *preg, const char *string, regamatch_t *match, regaparams_t params, int eflags)
int tre_regwexec(const regex_t *preg, const wchar_t *string, size_t nmatch, regmatch_t pmatch[], int eflags)
void tre_regaparams_default(regaparams_t *params)
Definition: tre.h:88
Definition: tre.h:91
int tre_have_backrefs(const regex_t *preg)
reg_errcode_t
Definition: tre.h:78
wchar_t tre_char_t
Definition: tre.h:250
Definition: tre.h:83
Definition: tre.h:79
Definition: tre.h:92
Definition: tre.h:89
void tre_regfree(regex_t *preg)
Definition: tre.h:94
int tre_regawexec(const regex_t *preg, const wchar_t *string, regamatch_t *match, regaparams_t params, int eflags)
int tre_regncompb(regex_t *preg, const char *regex, size_t n, int cflags)
int tre_regnexec(const regex_t *preg, const char *string, size_t len, size_t nmatch, regmatch_t pmatch[], int eflags)
int tre_have_approx(const regex_t *preg)
Definition: tre.h:93
int tre_regawnexec(const regex_t *preg, const wchar_t *string, size_t len, regamatch_t *match, regaparams_t params, int eflags)
HDFFCLIBAPI _fcd _fcd intf * n
int tre_regcomp(regex_t *preg, const char *regex, int cflags)
int tre_config(int query, void *result)
int tre_reguexec(const regex_t *preg, const tre_str_source *string, size_t nmatch, regmatch_t pmatch[], int eflags)
int tre_regnexecb(const regex_t *preg, const char *str, size_t len, size_t nmatch, regmatch_t pmatch[], int eflags)
size_t tre_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
Definition: tre.h:85
int tre_reganexec(const regex_t *preg, const char *string, size_t len, regamatch_t *match, regaparams_t params, int eflags)
int tre_regaexec(const regex_t *preg, const char *string, regamatch_t *match, regaparams_t params, int eflags)
int tre_regwcomp(regex_t *preg, const wchar_t *regex, int cflags)
int regoff_t
Definition: tre.h:66
int tre_regexecb(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags)
int tre_regcompb(regex_t *preg, const char *regex, int cflags)
Definition: tre.h:90
Definition: regex.h:100

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