20 #include "test_regex.h"
35 #if CFG_USE_CLB || CFG_USE_XSI
36 static void print_ere_error(
int code, posix_regex_t* ere)
41 # if CFG_USE_POSIX_API >= 200112 || CFG_USE_XSI
43 posix_setlocale(POSIX_LC_MESSAGES,
"POSIX");
45 len = posix_regerror(code, ere, buf, 0);
46 buf = (
char*) posix_malloc(len);
49 fprintf(stderr,
TEST_TAB "Out of memory\n");
53 posix_regerror(code, ere, buf, len);
54 fprintf(stderr,
TEST_TAB "%s\n", buf);
55 posix_free((
void*) buf);
57 # if CFG_USE_POSIX_API >= 200112 || CFG_USE_XSI
58 posix_setlocale(POSIX_LC_MESSAGES,
"");
81 int res = POSIX_EXIT_SUCCESS;
82 #if CFG_USE_CLB || CFG_USE_XSI
83 # define TS_NUM (size_t) 5
84 static const char* pat[TS_NUM] = {
87 "Bracket expression: [Xa]",
88 "Bracket expression: [Xa]",
91 static const char* ts[TS_NUM] =
93 "This is an ASCII string",
95 "Bracket expression: X",
96 "Bracket expression: a",
100 posix_regex_t ere[TS_NUM];
104 for(i = 0; i < TS_NUM; ++i)
107 rv = posix_regcomp(&ere[i], pat[i], POSIX_REG_EXTENDED | POSIX_REG_NOSUB);
111 fprintf(stderr,
TEST_TAB "Pattern: \"%s\"\n", pat[i]);
112 print_ere_error(rv, &ere[i]);
113 res = POSIX_EXIT_FAILURE;
118 if(POSIX_EXIT_SUCCESS == res)
121 for(i = 0; i < TS_NUM; ++i)
123 rv = posix_regexec(&ere[i], ts[i], 0, NULL, 0);
127 fprintf(stderr,
TEST_TAB "Pattern: \"%s\"\n", pat[i]);
128 fprintf(stderr,
TEST_TAB "String : \"%s\"\n", ts[i]);
129 print_ere_error(rv, &ere[i]);
130 res = POSIX_EXIT_FAILURE;
135 for(i = 0; i < TS_NUM; ++i) { posix_regfree(&ere[i]); }
139 res = POSIX_EXIT_FAILURE;