5 int main(int argc, char **argv)
7 SilcBool success = FALSE;
9 SilcRegexMatchStruct match[10];
10 int i, num_match = 10;
11 char *regex, *string, *sub;
12 SilcBufferStruct bmatch;
14 if (argc > 1 && !strcmp(argv[1], "-d")) {
17 silc_log_debug_hexdump(TRUE);
18 silc_log_set_debug_string("*regex*,*errno*");
22 SILC_LOG_DEBUG(("Regex %s", regex));
24 SILC_LOG_DEBUG(("Match %s", string));
25 if (!silc_regex(string, regex, &bmatch, NULL))
27 silc_buffer_printf(&bmatch, TRUE);
30 SILC_LOG_DEBUG(("Regex %s", regex));
32 SILC_LOG_DEBUG(("Match %s", string));
33 if (!silc_regex(string, regex, &bmatch, NULL))
35 silc_buffer_printf(&bmatch, TRUE);
38 SILC_LOG_DEBUG(("Regex %s", regex));
40 SILC_LOG_DEBUG(("Match %s", string));
41 if (!silc_regex(string, regex, &bmatch, NULL))
43 silc_buffer_printf(&bmatch, TRUE);
46 SILC_LOG_DEBUG(("Regex %s", regex));
48 SILC_LOG_DEBUG(("DO NOT Match %s", string));
49 if (silc_regex(string, regex, &bmatch, NULL))
53 SILC_LOG_DEBUG(("Regex %s", regex));
55 SILC_LOG_DEBUG(("Match %s", string));
56 if (!silc_regex(string, regex, &bmatch, NULL))
58 silc_buffer_printf(&bmatch, TRUE);
61 SILC_LOG_DEBUG(("Regex %s", regex));
63 SILC_LOG_DEBUG(("DO NOT Match %s", string));
64 if (silc_regex(string, regex, &bmatch, NULL))
68 SILC_LOG_DEBUG(("Regex %s", regex));
70 SILC_LOG_DEBUG(("Match %s", string));
71 if (!silc_regex(string, regex, &bmatch, NULL))
73 silc_buffer_printf(&bmatch, TRUE);
76 SILC_LOG_DEBUG(("Regex %s", regex));
78 SILC_LOG_DEBUG(("Match %s", string));
79 if (!silc_regex(string, regex, &bmatch, NULL))
81 silc_buffer_printf(&bmatch, TRUE);
84 SILC_LOG_DEBUG(("Regex %s", regex));
86 SILC_LOG_DEBUG(("DO NOT Match %s", string));
87 if (silc_regex(string, regex, &bmatch, NULL))
91 SILC_LOG_DEBUG(("Regex %s", regex));
93 SILC_LOG_DEBUG(("Match %s", string));
94 if (!silc_regex(string, regex, &bmatch, NULL))
96 silc_buffer_printf(&bmatch, TRUE);
99 SILC_LOG_DEBUG(("Regex %s", regex));
100 string = "aaaaaaaaaaaaa";
101 SILC_LOG_DEBUG(("Match %s", string));
102 if (!silc_regex(string, regex, &bmatch, NULL))
104 silc_buffer_printf(&bmatch, TRUE);
107 SILC_LOG_DEBUG(("Regex %s", regex));
109 SILC_LOG_DEBUG(("DO NOT Match %s", string));
110 if (silc_regex(string, regex, &bmatch, NULL))
115 SILC_LOG_DEBUG(("Regex %s", regex));
117 SILC_LOG_DEBUG(("Match %s", string));
118 if (!silc_regex(string, regex, &bmatch, NULL))
120 silc_buffer_printf(&bmatch, TRUE);
123 SILC_LOG_DEBUG(("Regex %s", regex));
125 SILC_LOG_DEBUG(("Match %s", string));
126 if (!silc_regex(string, regex, &bmatch, NULL))
128 silc_buffer_printf(&bmatch, TRUE);
131 SILC_LOG_DEBUG(("Regex %s", regex));
133 SILC_LOG_DEBUG(("Match %s", string));
134 if (!silc_regex(string, regex, &bmatch, NULL))
136 silc_buffer_printf(&bmatch, TRUE);
140 SILC_LOG_DEBUG(("Regex %s", regex));
142 SILC_LOG_DEBUG(("Match %s", string));
143 if (!silc_regex(string, regex, &bmatch, NULL))
145 silc_buffer_printf(&bmatch, TRUE);
148 SILC_LOG_DEBUG(("Regex %s", regex));
150 SILC_LOG_DEBUG(("Match %s", string));
151 if (!silc_regex(string, regex, &bmatch, NULL))
153 silc_buffer_printf(&bmatch, TRUE);
156 SILC_LOG_DEBUG(("Regex %s", regex));
158 SILC_LOG_DEBUG(("DO NOT Match %s", string));
159 if (silc_regex(string, regex, &bmatch, NULL))
164 SILC_LOG_DEBUG(("Regex %s", regex));
166 SILC_LOG_DEBUG(("Match %s", string));
167 if (!silc_regex(string, regex, &bmatch, NULL))
169 silc_buffer_printf(&bmatch, TRUE);
172 SILC_LOG_DEBUG(("Regex %s", regex));
174 SILC_LOG_DEBUG(("Match %s", string));
175 if (!silc_regex(string, regex, &bmatch, NULL))
177 silc_buffer_printf(&bmatch, TRUE);
180 SILC_LOG_DEBUG(("Regex %s", regex));
182 SILC_LOG_DEBUG(("DO NOT Match %s", string));
183 if (silc_regex(string, regex, &bmatch, NULL))
187 regex = "(H..).(o..)";
188 SILC_LOG_DEBUG(("Regex %s", regex));
189 if (!silc_regex_compile(®, regex, 0))
192 string = "Hello World";
193 SILC_LOG_DEBUG(("Match %s", string));
194 if (!silc_regex_match(®, string, strlen(string), num_match, match, 0))
196 for (i = 0; i < num_match; i++) {
197 if (match[i].start != -1) {
198 SILC_LOG_DEBUG(("Match start %d, end %d", match[i].start,
200 sub = silc_memdup(string + match[i].start, match[i].end -
202 SILC_LOG_DEBUG(("Match substring '%s'", sub));
207 silc_regex_free(®);
210 SILC_LOG_DEBUG(("Regex %s", regex));
211 if (!silc_regex_compile(®, regex, 0))
215 SILC_LOG_DEBUG(("Match %s", string));
216 if (!silc_regex_match(®, string, strlen(string), 0, NULL, 0))
220 SILC_LOG_DEBUG(("Match %s", string));
221 if (!silc_regex_match(®, string, strlen(string), 0, NULL, 0))
224 string = "foo20, bar, foo100, foo";
225 SILC_LOG_DEBUG(("Match all substrings in %s", string));
226 while (silc_regex_match(®, string, strlen(string), 1, match, 0)) {
227 SILC_LOG_DEBUG(("Match start %d", match[0].start));
228 sub = silc_memdup(string + match[0].start, match[0].end - match[0].start);
229 SILC_LOG_DEBUG(("Match substring '%s'", sub));
231 string += match[0].end;
234 string = "foo20, bar, foo100, Foo, foo0";
235 SILC_LOG_DEBUG(("Match all substrings at once in %s", string));
236 if (!silc_regex_match(®, string, strlen(string), num_match, match, 0))
239 for (i = 0; i < num_match; i++) {
240 if (match[i].start != -1) {
241 SILC_LOG_DEBUG(("Match start %d", match[i].start));
242 sub = silc_memdup(string + match[i].start, match[i].end -
244 SILC_LOG_DEBUG(("Match substring '%s'", sub));
249 silc_regex_free(®);
251 regex = "^(([^:]+)://)?([^:/]+)(:([0-9]+))?(/.*)";
252 SILC_LOG_DEBUG(("Regex %s", regex));
253 if (!silc_regex_compile(®, regex, 0))
256 string = "http://silcnet.org:443/foobar/pelle.html";
257 SILC_LOG_DEBUG(("Parse URI"));
258 if (!silc_regex_match(®, string, strlen(string), num_match, match, 0))
261 for (i = 0; i < num_match; i++) {
262 if (match[i].start != -1) {
263 SILC_LOG_DEBUG(("Match start %d", match[i].start));
264 sub = silc_memdup(string + match[i].start, match[i].end -
266 SILC_LOG_DEBUG(("Match substring '%s'", sub));
271 string = "http://silcnet.org/";
272 SILC_LOG_DEBUG(("Parse URI"));
273 if (!silc_regex_match(®, string, strlen(string), num_match, match, 0))
276 for (i = 0; i < num_match; i++) {
277 if (match[i].start != -1) {
278 SILC_LOG_DEBUG(("Match start %d", match[i].start));
279 sub = silc_memdup(string + match[i].start, match[i].end -
281 SILC_LOG_DEBUG(("Match substring '%s'", sub));
286 silc_regex_free(®);
289 SILC_LOG_DEBUG(("Regex %s", regex));
290 if (!silc_regex_compile(®, regex, 0))
294 SILC_LOG_DEBUG(("Match all substrings at once in %s", string));
295 if (!silc_regex_match(®, string, strlen(string), num_match, match, 0))
298 for (i = 0; i < num_match; i++) {
299 if (match[i].start != -1) {
300 SILC_LOG_DEBUG(("Match start %d", match[i].start));
301 sub = silc_memdup(string + match[i].start, match[i].end -
303 SILC_LOG_DEBUG(("Match substring '%s'", sub));
308 silc_regex_free(®);
311 SILC_LOG_DEBUG(("Regex %s", regex));
312 if (!silc_regex_compile(®, regex, 0))
316 SILC_LOG_DEBUG(("Test NOTBOL flag", string));
317 if (silc_regex_match(®, string, strlen(string), 0, NULL,
320 if (silc_errno != SILC_ERR_NOT_FOUND)
322 SILC_LOG_DEBUG(("Did not match (OK)"));
324 silc_regex_free(®);
327 SILC_LOG_DEBUG(("Regex %s", regex));
328 if (!silc_regex_compile(®, regex, 0))
332 SILC_LOG_DEBUG(("Test NOTEOL flag", string));
333 if (silc_regex_match(®, string, strlen(string), 0, NULL,
336 if (silc_errno != SILC_ERR_NOT_FOUND)
338 SILC_LOG_DEBUG(("Did not match (OK)"));
340 silc_regex_free(®);
345 SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE"));
346 fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE");