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))
188 SILC_LOG_DEBUG(("Regex %s", regex));
190 SILC_LOG_DEBUG(("Match %s", string));
191 if (!silc_regex(string, regex, &bmatch, NULL))
193 silc_file_write(1, silc_buffer_data(&bmatch), silc_buffer_len(&bmatch));
196 regex = "(H..).(o..)";
197 SILC_LOG_DEBUG(("Regex %s", regex));
198 if (!silc_regex_compile(®, regex, 0))
201 string = "Hello World";
202 SILC_LOG_DEBUG(("Match %s", string));
203 if (!silc_regex_match(®, string, strlen(string), num_match, match, 0))
205 for (i = 0; i < num_match; i++) {
206 if (match[i].start != -1) {
207 SILC_LOG_DEBUG(("Match start %d, end %d", match[i].start,
209 sub = silc_memdup(string + match[i].start, match[i].end -
211 SILC_LOG_DEBUG(("Match substring '%s'", sub));
216 silc_regex_free(®);
219 SILC_LOG_DEBUG(("Regex %s", regex));
220 if (!silc_regex_compile(®, regex, 0))
224 SILC_LOG_DEBUG(("Match %s", string));
225 if (!silc_regex_match(®, string, strlen(string), 0, NULL, 0))
229 SILC_LOG_DEBUG(("Match %s", string));
230 if (!silc_regex_match(®, string, strlen(string), 0, NULL, 0))
233 string = "foo20, bar, foo100, foo";
234 SILC_LOG_DEBUG(("Match all substrings in %s", string));
235 while (silc_regex_match(®, string, strlen(string), 1, match, 0)) {
236 SILC_LOG_DEBUG(("Match start %d", match[0].start));
237 sub = silc_memdup(string + match[0].start, match[0].end - match[0].start);
238 SILC_LOG_DEBUG(("Match substring '%s'", sub));
240 string += match[0].end;
243 string = "foo20, bar, foo100, Foo, foo0";
244 SILC_LOG_DEBUG(("Match all substrings at once in %s", string));
245 if (!silc_regex_match(®, string, strlen(string), num_match, match, 0))
248 for (i = 0; i < num_match; i++) {
249 if (match[i].start != -1) {
250 SILC_LOG_DEBUG(("Match start %d", match[i].start));
251 sub = silc_memdup(string + match[i].start, match[i].end -
253 SILC_LOG_DEBUG(("Match substring '%s'", sub));
258 silc_regex_free(®);
260 regex = "^(([^:]+)://)?([^:/]+)(:([0-9]+))?(/.*)";
261 SILC_LOG_DEBUG(("Regex %s", regex));
262 if (!silc_regex_compile(®, regex, 0))
265 string = "http://silcnet.org:443/foobar/pelle.html";
266 SILC_LOG_DEBUG(("Parse URI"));
267 if (!silc_regex_match(®, string, strlen(string), num_match, match, 0))
270 for (i = 0; i < num_match; i++) {
271 if (match[i].start != -1) {
272 SILC_LOG_DEBUG(("Match start %d", match[i].start));
273 sub = silc_memdup(string + match[i].start, match[i].end -
275 SILC_LOG_DEBUG(("Match substring '%s'", sub));
280 string = "http://silcnet.org/";
281 SILC_LOG_DEBUG(("Parse URI"));
282 if (!silc_regex_match(®, string, strlen(string), num_match, match, 0))
285 for (i = 0; i < num_match; i++) {
286 if (match[i].start != -1) {
287 SILC_LOG_DEBUG(("Match start %d", match[i].start));
288 sub = silc_memdup(string + match[i].start, match[i].end -
290 SILC_LOG_DEBUG(("Match substring '%s'", sub));
295 silc_regex_free(®);
298 SILC_LOG_DEBUG(("Regex %s", regex));
299 if (!silc_regex_compile(®, regex, 0))
303 SILC_LOG_DEBUG(("Match all substrings at once in %s", string));
304 if (!silc_regex_match(®, string, strlen(string), num_match, match, 0))
307 for (i = 0; i < num_match; i++) {
308 if (match[i].start != -1) {
309 SILC_LOG_DEBUG(("Match start %d", match[i].start));
310 sub = silc_memdup(string + match[i].start, match[i].end -
312 SILC_LOG_DEBUG(("Match substring '%s'", sub));
317 silc_regex_free(®);
320 SILC_LOG_DEBUG(("Regex %s", regex));
321 if (!silc_regex_compile(®, regex, 0))
325 SILC_LOG_DEBUG(("Test NOTBOL flag", string));
326 if (silc_regex_match(®, string, strlen(string), 0, NULL,
329 if (silc_errno != SILC_ERR_NOT_FOUND)
331 SILC_LOG_DEBUG(("Did not match (OK)"));
333 silc_regex_free(®);
336 SILC_LOG_DEBUG(("Regex %s", regex));
337 if (!silc_regex_compile(®, regex, 0))
341 SILC_LOG_DEBUG(("Test NOTEOL flag", string));
342 if (silc_regex_match(®, string, strlen(string), 0, NULL,
345 if (silc_errno != SILC_ERR_NOT_FOUND)
347 SILC_LOG_DEBUG(("Did not match (OK)"));
349 silc_regex_free(®);
354 SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE"));
355 fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE");