20 #include "test_regex.h"
35 #if CFG_USE_CLB || CFG_USE_XSI
36 static void print_ere_error(
int code, api_posix_regex_t* ere)
41 # if CFG_USE_POSIX_API >= 200112 || CFG_USE_XSI
43 api_posix_setlocale(API_POSIX_LC_MESSAGES,
"POSIX");
45 len = api_posix_regerror(code, ere, buf, 0);
46 buf = (
char*) api_posix_malloc(len);
49 fprintf(stderr,
TEST_TAB "Out of memory\n");
53 api_posix_regerror(code, ere, buf, len);
54 fprintf(stderr,
TEST_TAB "%s\n", buf);
55 api_posix_free((
void*) buf);
57 # if CFG_USE_POSIX_API >= 200112 || CFG_USE_XSI
58 api_posix_setlocale(API_POSIX_LC_MESSAGES,
"");
81 int res = API_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 api_posix_regex_t ere[TS_NUM];
104 for(i = 0; i < TS_NUM; ++i)
107 rv = api_posix_regcomp(&ere[i], pat[i],
108 API_POSIX_REG_EXTENDED | API_POSIX_REG_NOSUB);
111 print_error(
"'api_posix_regcomp()' reported error");
112 fprintf(stderr,
TEST_TAB "Pattern: \"%s\"\n", pat[i]);
113 print_ere_error(rv, &ere[i]);
114 res = API_POSIX_EXIT_FAILURE;
119 if(API_POSIX_EXIT_SUCCESS == res)
122 for(i = 0; i < TS_NUM; ++i)
124 rv = api_posix_regexec(&ere[i], ts[i], 0, NULL, 0);
127 print_error(
"'api_posix_regexec()' reported error");
128 fprintf(stderr,
TEST_TAB "Pattern: \"%s\"\n", pat[i]);
129 fprintf(stderr,
TEST_TAB "String : \"%s\"\n", ts[i]);
130 print_ere_error(rv, &ere[i]);
131 res = API_POSIX_EXIT_FAILURE;
136 for(i = 0; i < TS_NUM; ++i) { api_posix_regfree(&ere[i]); }
140 res = API_POSIX_EXIT_FAILURE;