1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21: #include <sys/types.h>
22: #include <mcheck.h>
23: #include <regex.h>
24: #include <stdio.h>
25: #include <stdlib.h>
26:
27:
28: struct
29: {
30: const char *pattern;
31: const char *string;
32: int flags, nmatch;
33: } tests[] = {
34: { "^<\\([^~]*\\)\\([^~]\\)[^~]*~\\1\\(.\\).*|=.*\\3.*\\2",
35: "<,.8~2,~so-|=-~.0,123456789<><", REG_NOSUB, 0 },
36:
37: { "a^b", "a^b", REG_EXTENDED, 0 }
38: };
39:
40: int
41: main (void)
42: {
43: regex_t re;
44: regmatch_t rm[4];
45: size_t i;
46: int n, ret = 0;
47:
48: mtrace ();
49:
50: for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
51: {
52: n = regcomp (&re, tests[i].pattern, tests[i].flags);
53: if (n != 0)
54: {
55: char buf[500];
56: regerror (n, &re, buf, sizeof (buf));
57: printf ("regcomp %zd failed: %s\n", i, buf);
58: ret = 1;
59: continue;
60: }
61:
62: if (! regexec (&re, tests[i].string, tests[i].nmatch,
63: tests[i].nmatch ? rm : NULL, 0))
64: {
65: printf ("regexec %zd incorrectly matched\n", i);
66: ret = 1;
67: }
68:
69: regfree (&re);
70: }
71:
72: return ret;
73: }