1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21: #include <ctype.h>
22: #include <locale.h>
23: #include <regex.h>
24: #include <stdio.h>
25: #include <string.h>
26:
27: int
28: main (void)
29: {
30: struct re_pattern_buffer re;
31: char trans[256];
32: int i, result = 0;
33: const char *s;
34:
35: setlocale (LC_ALL, "de_DE.ISO-8859-1");
36:
37: for (i = 0; i < 256; ++i)
38: trans[i] = tolower (i);
39:
40: re_set_syntax (RE_SYNTAX_POSIX_EGREP);
41:
42: memset (&re, 0, sizeof (re));
43: re.translate = (unsigned char *) trans;
44: s = re_compile_pattern ("\\W", 2, &re);
45:
46: if (s != NULL)
47: {
48: printf ("failed to compile pattern \"\\W\": %s\n", s);
49: result = 1;
50: }
51: else
52: {
53: int ret = re_search (&re, "abc.de", 6, 0, 6, NULL);
54: if (ret != 3)
55: {
56: printf ("1st re_search returned %d\n", ret);
57: result = 1;
58: }
59:
60: ret = re_search (&re, "\xc4\xd6\xae\xf7", 4, 0, 4, NULL);
61: if (ret != 2)
62: {
63: printf ("2nd re_search returned %d\n", ret);
64: result = 1;
65: }
66: re.translate = NULL;
67: regfree (&re);
68: }
69:
70: memset (&re, 0, sizeof (re));
71: re.translate = (unsigned char *) trans;
72: s = re_compile_pattern ("\\w", 2, &re);
73:
74: if (s != NULL)
75: {
76: printf ("failed to compile pattern \"\\w\": %s\n", s);
77: result = 1;
78: }
79: else
80: {
81: int ret = re_search (&re, ".,!abc", 6, 0, 6, NULL);
82: if (ret != 3)
83: {
84: printf ("3rd re_search returned %d\n", ret);
85: result = 1;
86: }
87:
88: ret = re_search (&re, "\xae\xf7\xc4\xd6", 4, 0, 4, NULL);
89: if (ret != 2)
90: {
91: printf ("4th re_search returned %d\n", ret);
92: result = 1;
93: }
94: re.translate = NULL;
95: regfree (&re);
96: }
97:
98: memset (&re, 0, sizeof (re));
99: re.translate = (unsigned char *) trans;
100: s = re_compile_pattern ("[[:DIGIT:]]", 11, &re);
101: if (s == NULL)
102: {
103: printf ("compilation of \"[[:DIGIT:]]\" pattern unexpectedly succeeded: %s\n",
104: s);
105: result = 1;
106: }
107:
108: memset (&re, 0, sizeof (re));
109: re.translate = (unsigned char *) trans;
110: s = re_compile_pattern ("[[:DIGIT:]]", 2, &re);
111: if (s == NULL)
112: {
113: printf ("compilation of \"[[:DIGIT:]]\" pattern unexpectedly succeeded: %s\n",
114: s);
115: result = 1;
116: }
117:
118: return result;
119: }