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));
23 string = "abcdefghijklmn";
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));
31 string = "abcdefghijklmn";
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(("Match %s", string));
49 if (!silc_regex(string, regex, &bmatch, NULL))
51 silc_buffer_printf(&bmatch, TRUE);
54 SILC_LOG_DEBUG(("Regex %s", regex));
56 SILC_LOG_DEBUG(("Match %s", string));
57 if (!silc_regex(string, regex, &bmatch, NULL))
59 silc_buffer_printf(&bmatch, TRUE);
62 SILC_LOG_DEBUG(("Regex %s", regex));
64 SILC_LOG_DEBUG(("DO NOT Match %s", string));
65 if (silc_regex(string, regex, &bmatch, NULL))
69 SILC_LOG_DEBUG(("Regex %s", regex));
71 SILC_LOG_DEBUG(("Match %s", string));
72 if (!silc_regex(string, regex, &bmatch, NULL))
74 silc_buffer_printf(&bmatch, TRUE);
77 SILC_LOG_DEBUG(("Regex %s", regex));
79 SILC_LOG_DEBUG(("DO NOT Match %s", string));
80 if (silc_regex(string, regex, &bmatch, NULL))
84 SILC_LOG_DEBUG(("Regex %s", regex));
86 SILC_LOG_DEBUG(("Match %s", string));
87 if (!silc_regex(string, regex, &bmatch, NULL))
89 silc_buffer_printf(&bmatch, TRUE);
92 SILC_LOG_DEBUG(("Regex %s", regex));
94 SILC_LOG_DEBUG(("Match %s", string));
95 if (!silc_regex(string, regex, &bmatch, NULL))
97 silc_buffer_printf(&bmatch, TRUE);
100 SILC_LOG_DEBUG(("Regex %s", regex));
102 SILC_LOG_DEBUG(("DO NOT Match %s", string));
103 if (silc_regex(string, regex, &bmatch, NULL))
107 SILC_LOG_DEBUG(("Regex %s", regex));
109 SILC_LOG_DEBUG(("Match %s", string));
110 if (!silc_regex(string, regex, &bmatch, NULL))
112 silc_buffer_printf(&bmatch, TRUE);
115 SILC_LOG_DEBUG(("Regex %s", regex));
116 string = "aaaaaaaaaaaaa";
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(("DO NOT Match %s", string));
126 if (silc_regex(string, regex, &bmatch, NULL))
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);
139 SILC_LOG_DEBUG(("Regex %s", regex));
141 SILC_LOG_DEBUG(("Match %s", string));
142 if (!silc_regex(string, regex, &bmatch, NULL))
144 silc_buffer_printf(&bmatch, TRUE);
147 SILC_LOG_DEBUG(("Regex %s", regex));
149 SILC_LOG_DEBUG(("Match %s", string));
150 if (!silc_regex(string, regex, &bmatch, NULL))
152 silc_buffer_printf(&bmatch, TRUE);
156 SILC_LOG_DEBUG(("Regex %s", regex));
158 SILC_LOG_DEBUG(("Match %s", string));
159 if (!silc_regex(string, regex, &bmatch, NULL))
161 silc_buffer_printf(&bmatch, TRUE);
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(("DO NOT Match %s", string));
175 if (silc_regex(string, regex, &bmatch, NULL))
180 SILC_LOG_DEBUG(("Regex %s", regex));
182 SILC_LOG_DEBUG(("Match %s", string));
183 if (!silc_regex(string, regex, &bmatch, NULL))
185 silc_buffer_printf(&bmatch, TRUE);
188 SILC_LOG_DEBUG(("Regex %s", regex));
190 SILC_LOG_DEBUG(("Match %s", string));
191 if (!silc_regex(string, regex, &bmatch, NULL))
193 silc_buffer_printf(&bmatch, TRUE);
196 SILC_LOG_DEBUG(("Regex %s", regex));
198 SILC_LOG_DEBUG(("DO NOT Match %s", string));
199 if (silc_regex(string, regex, &bmatch, NULL))
203 regex = "(H..).(o..)";
204 SILC_LOG_DEBUG(("Regex %s", regex));
205 if (!silc_regex_compile(®, regex, 0))
208 string = "Hello World";
209 SILC_LOG_DEBUG(("Match %s", string));
210 if (!silc_regex_match(®, string, strlen(string), num_match, match, 0))
212 for (i = 0; i < num_match; i++) {
213 if (match[i].start != -1) {
214 SILC_LOG_DEBUG(("Match start %d, end %d", match[i].start,
216 sub = silc_memdup(string + match[i].start, match[i].end -
218 SILC_LOG_DEBUG(("Match substring '%s'", sub));
223 silc_regex_free(®);
226 SILC_LOG_DEBUG(("Regex %s", regex));
227 if (!silc_regex_compile(®, regex, 0))
231 SILC_LOG_DEBUG(("Match %s", string));
232 if (!silc_regex_match(®, string, strlen(string), 0, NULL, 0))
236 SILC_LOG_DEBUG(("Match %s", string));
237 if (!silc_regex_match(®, string, strlen(string), 0, NULL, 0))
240 string = "foo20, bar, foo100, foo";
241 SILC_LOG_DEBUG(("Match all substrings in %s", string));
242 while (silc_regex_match(®, string, strlen(string), 1, match, 0)) {
243 SILC_LOG_DEBUG(("Match start %d", match[0].start));
244 sub = silc_memdup(string + match[0].start, match[0].end - match[0].start);
245 SILC_LOG_DEBUG(("Match substring '%s'", sub));
247 string += match[0].end;
250 string = "foo20, bar, foo100, Foo, foo0";
251 SILC_LOG_DEBUG(("Match all substrings at once in %s", string));
252 if (!silc_regex_match(®, string, strlen(string), num_match, match, 0))
255 for (i = 0; i < num_match; i++) {
256 if (match[i].start != -1) {
257 SILC_LOG_DEBUG(("Match start %d", match[i].start));
258 sub = silc_memdup(string + match[i].start, match[i].end -
260 SILC_LOG_DEBUG(("Match substring '%s'", sub));
265 silc_regex_free(®);
267 regex = "^(([^:]+)://)?([^:/]+)(:([0-9]+))?(/.*)";
268 SILC_LOG_DEBUG(("Regex %s", regex));
269 if (!silc_regex_compile(®, regex, 0))
272 string = "http://silcnet.org:443/foobar/pelle.html";
273 SILC_LOG_DEBUG(("Parse URI"));
274 if (!silc_regex_match(®, string, strlen(string), num_match, match, 0))
277 for (i = 0; i < num_match; i++) {
278 if (match[i].start != -1) {
279 SILC_LOG_DEBUG(("Match start %d", match[i].start));
280 sub = silc_memdup(string + match[i].start, match[i].end -
282 SILC_LOG_DEBUG(("Match substring '%s'", sub));
287 string = "http://silcnet.org/";
288 SILC_LOG_DEBUG(("Parse URI"));
289 if (!silc_regex_match(®, string, strlen(string), num_match, match, 0))
292 for (i = 0; i < num_match; i++) {
293 if (match[i].start != -1) {
294 SILC_LOG_DEBUG(("Match start %d", match[i].start));
295 sub = silc_memdup(string + match[i].start, match[i].end -
297 SILC_LOG_DEBUG(("Match substring '%s'", sub));
302 silc_regex_free(®);
305 SILC_LOG_DEBUG(("Regex %s", regex));
306 if (!silc_regex_compile(®, regex, 0))
310 SILC_LOG_DEBUG(("Match all substrings at once in %s", string));
311 if (!silc_regex_match(®, string, strlen(string), num_match, match, 0))
314 for (i = 0; i < num_match; i++) {
315 if (match[i].start != -1) {
316 SILC_LOG_DEBUG(("Match start %d", match[i].start));
317 sub = silc_memdup(string + match[i].start, match[i].end -
319 SILC_LOG_DEBUG(("Match substring '%s'", sub));
324 silc_regex_free(®);
327 SILC_LOG_DEBUG(("Regex %s", regex));
328 if (!silc_regex_compile(®, regex, 0))
332 SILC_LOG_DEBUG(("Test NOTBOL 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(®);
343 SILC_LOG_DEBUG(("Regex %s", regex));
344 if (!silc_regex_compile(®, regex, 0))
348 SILC_LOG_DEBUG(("Test NOTEOL flag", string));
349 if (silc_regex_match(®, string, strlen(string), 0, NULL,
352 if (silc_errno != SILC_ERR_NOT_FOUND)
354 SILC_LOG_DEBUG(("Did not match (OK)"));
356 silc_regex_free(®);
361 SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE"));
362 fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE");