1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21: #include <locale.h>
22: #include <stdio.h>
23: #include <string.h>
24: #include <regex.h>
25:
26: int
27: main (void)
28: {
29: struct re_pattern_buffer regex;
30: struct re_registers regs;
31: const char *s;
32: int match;
33: int result = 0;
34:
35: regs.num_regs = 1;
36: memset (®ex, '\0', sizeof (regex));
37: s = re_compile_pattern ("[abc]*d", 7, ®ex);
38: if (s != NULL)
39: {
40: puts ("re_compile_pattern return non-NULL value");
41: result = 1;
42: }
43: else
44: {
45: match = re_match (®ex, "foacabdxy", 9, 2, ®s);
46: if (match != 5)
47: {
48: printf ("re_match returned %d, expected 5\n", match);
49: result = 1;
50: }
51: else if (regs.start[0] != 2 || regs.end[0] != 7)
52: {
53: printf ("re_match returned %d..%d, expected 2..7\n",
54: regs.start[0], regs.end[0]);
55: result = 1;
56: }
57: puts (" -> OK");
58: }
59:
60: return result;
61: }