18 static const char *pat
[] = {
19 ".?.?.?.?.?.?.?Log\\.13",
20 "(.?)(.?)(.?)(.?)(.?)(.?)(.?)Log\\.13",
21 "((((((((((.?))))))))))((((((((((.?))))))))))((((((((((.?))))))))))"
22 "((((((((((.?))))))))))((((((((((.?))))))))))((((((((((.?))))))))))"
23 "((((((((((.?))))))))))Log\\.13"
26 const char *fname
= "tst-regex2.dat";
32 int fd
= open(fname
, O_RDONLY
);
34 printf("Couldn't open %s: %s\n", fname
, strerror(errno
));
37 if (fstat(fd
, &st
) < 0) {
38 printf("Couldn't fstat %s: %s\n", fname
, strerror(errno
));
42 string
= buf
= malloc(len
+ 1);
44 printf("Couldn't allocate %u bytes\n", len
+ 1);
47 if (read(fd
, buf
, st
.st_size
) != (ssize_t
) st
.st_size
) {
48 printf("Couldn't read %s\n", fname
);
55 #if defined __UCLIBC_HAS_XLOCALE__ || !defined __UCLIBC__
56 setlocale(LC_ALL
, "de_DE.UTF-8");
59 for (testno
= 0; testno
< 2; ++testno
) {
61 for (i
= 0; i
< sizeof(pat
) / sizeof(pat
[0]); ++i
) {
62 struct timeval start
, stop
;
66 printf("test %d pattern %d '%s'\n", testno
, i
, pat
[i
]);
67 gettimeofday(&start
, NULL
);
69 err
= regcomp(&rbuf
, pat
[i
],
70 REG_EXTENDED
| (testno
? REG_NOSUB
: 0));
73 regerror(err
, &rbuf
, errstr
, sizeof(errstr
));
79 regmatch_t pmatch
[71];
80 err
= regexec(&rbuf
, string
, 71, pmatch
, 0);
81 if (err
== REG_NOMATCH
) {
82 puts("regexec failed");
88 if (pmatch
[0].rm_eo
!= pmatch
[0].rm_so
+ 13
89 || pmatch
[0].rm_eo
> len
90 || pmatch
[0].rm_so
< len
- 100
91 || strncmp(string
+ pmatch
[0].rm_so
,
92 " ChangeLog.13 for earlier changes",
93 sizeof " ChangeLog.13 for earlier changes" - 1
96 puts("regexec without REG_NOSUB did not find the correct match");
103 for (j
= 0, l
= 1; j
< 7; ++j
) {
104 for (k
= 0; k
< (i
== 1 ? 1 : 10); ++k
, ++l
) {
105 if (pmatch
[l
].rm_so
!= pmatch
[0].rm_so
+ j
106 || pmatch
[l
].rm_eo
!= pmatch
[l
].rm_so
+ 1
108 printf("pmatch[%d] incorrect\n", l
);
117 gettimeofday(&stop
, NULL
);
118 stop
.tv_sec
-= start
.tv_sec
;
119 if (stop
.tv_usec
< start
.tv_usec
) {
121 stop
.tv_usec
+= 1000000;
123 stop
.tv_usec
-= start
.tv_usec
;
124 printf(" %lu.%06lus\n", (unsigned long) stop
.tv_sec
,
125 (unsigned long) stop
.tv_usec
);
131 for (testno
= 2; testno
< 4; ++testno
) {
133 for (i
= 0; i
< sizeof(pat
) / sizeof(pat
[0]); ++i
) {
134 struct timeval start
, stop
;
135 struct re_pattern_buffer rpbuf
;
136 struct re_registers regs
;
140 printf("test %d pattern %d '%s'\n", testno
, i
, pat
[i
]);
141 gettimeofday(&start
, NULL
);
143 re_set_syntax(RE_SYNTAX_POSIX_EGREP
144 | (testno
== 3 ? RE_NO_SUB
: 0));
145 memset(&rpbuf
, 0, sizeof(rpbuf
));
146 s
= re_compile_pattern(pat
[i
], strlen(pat
[i
]), &rpbuf
);
153 memset(®s
, 0, sizeof(regs
));
154 match
= re_search(&rpbuf
, string
, len
, 0, len
, ®s
);
156 printf("re_search failed (err:%d)\n", match
);
160 if (match
+ 13 > len
) {
161 printf("re_search: match+13 > len (%d > %d)\n", match
+ 13, len
);
165 if (match
< len
- 100) {
166 printf("re_search: match < len-100 (%d < %d)\n", match
, len
- 100);
170 if (strncmp(string
+ match
, " ChangeLog.13 for earlier changes",
171 sizeof(" ChangeLog.13 for earlier changes") - 1
174 printf("re_search did not find the correct match"
175 "(found '%s' instead)\n", string
+ match
);
186 if (regs
.num_regs
!= expected
) {
187 printf("incorrect num_regs %d, expected %d\n", regs
.num_regs
, expected
);
191 if (regs
.start
[0] != match
|| regs
.end
[0] != match
+ 13) {
192 printf("incorrect regs.{start,end}[0] = { %d, %d },"
193 " expected { %d, %d }\n",
194 regs
.start
[0], regs
.end
[0],
200 if (regs
.start
[regs
.num_regs
- 1] != -1
201 || regs
.end
[regs
.num_regs
- 1] != -1
203 printf("incorrect regs.{start,end}[num_regs - 1] = { %d, %d },"
204 " expected { -1, -1 }\n",
205 regs
.start
[regs
.num_regs
- 1], regs
.end
[regs
.num_regs
- 1]
213 for (j
= 0, l
= 1; j
< 7; ++j
) {
214 for (k
= 0; k
< (i
== 1 ? 1 : 10); ++k
, ++l
) {
215 if (regs
.start
[l
] != match
+ j
216 || regs
.end
[l
] != match
+ j
+ 1
218 printf("incorrect regs.{start,end}[%d] = { %d, %d },"
219 " expected { %d, %d }\n",
221 regs
.start
[l
], regs
.end
[l
],
222 match
+ j
, match
+ j
+ 1
232 gettimeofday(&stop
, NULL
);
233 stop
.tv_sec
-= start
.tv_sec
;
234 if (stop
.tv_usec
< start
.tv_usec
) {
236 stop
.tv_usec
+= 1000000;
238 stop
.tv_usec
-= start
.tv_usec
;
239 printf(" %lu.%06lus\n", (unsigned long) stop
.tv_sec
,
240 (unsigned long) stop
.tv_usec
);
249 #define TEST_FUNCTION do_test()
250 #include "../test-skeleton.c"