2
* Copyright (c) 2002 by The XFree86 Project, Inc.
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
11
* The above copyright notice and this permission notice shall be included in
12
* all copies or substantial portions of the Software.
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
* THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
* Except as contained in this notice, the name of the XFree86 Project shall
23
* not be used in advertising or otherwise to promote the sale, use or other
24
* dealings in this Software without prior written authorization from the
27
* Author: Paulo César Pereira de Andrade
33
* Compile with: cc -o tests tests.c -L. -lre
41
main(int argc, char *argv[])
45
int line, ecode, i, len, group, failed;
49
FILE *fp = fopen("tests.txt", "r");
52
fprintf(stderr, "failed to open tests.txt\n");
56
ecode = line = group = failed = 0;
58
while (fgets(buf, sizeof(buf), fp)) {
60
if (buf[0] == '#' || buf[0] == '\n')
62
else if (buf[0] == '/') {
63
char *ptr = strrchr(buf, '/');
66
fprintf(stderr, "syntax error at line %d\n", line);
73
for (*ptr++ = '\0'; *ptr; ptr++) {
79
ecode = recomp(&cod, buf + 1, flags);
83
else if (buf[0] == '>') {
84
if (cod.cod == NULL) {
85
fprintf(stderr, "no previous pattern at line %d\n", line);
88
len = strlen(buf) - 1;
91
for (i = 0, --len; i < len - 1; i++) {
93
memmove(str + i, str + i + 1, len);
123
ecode = reexec(&cod, str, 10, &mat[0], 0);
124
if (ecode && ecode != RE_NOMATCH) {
125
reerror(failed, &cod, buf, sizeof(buf));
126
fprintf(stderr, "%s, at line %d\n", buf, line);
130
else if (buf[0] == ':') {
132
len = strlen(buf) - 1;
134
if (failed == RE_EESCAPE && strcmp(buf, ":EESCAPE") == 0)
136
if (failed == RE_ESUBREG && strcmp(buf, ":ESUBREG") == 0)
138
if (failed == RE_EBRACK && strcmp(buf, ":EBRACK") == 0)
140
if (failed == RE_EPAREN && strcmp(buf, ":EPAREN") == 0)
142
if (failed == RE_EBRACE && strcmp(buf, ":EBRACE") == 0)
144
if (failed == RE_EBADBR && strcmp(buf, ":EBADBR") == 0)
146
if (failed == RE_ERANGE && strcmp(buf, ":ERANGE") == 0)
148
if (failed == RE_ESPACE && strcmp(buf, ":ESPACE") == 0)
150
if (failed == RE_BADRPT && strcmp(buf, ":BADRPT") == 0)
152
if (failed == RE_EMPTY && strcmp(buf, ":EMPTY") == 0)
154
reerror(failed, &cod, buf, sizeof(buf));
155
fprintf(stderr, "Error value %d doesn't match: %s, at line %d\n",
160
fprintf(stderr, "found match when shoudn't, at line %d\n", line);
166
reerror(failed, &cod, buf, sizeof(buf));
167
fprintf(stderr, "%s, at line %d\n", buf, line);
170
if (sscanf(buf, "%ld,%ld:", &so, &eo) != 2) {
171
fprintf(stderr, "expecting match offsets at line %d\n", line);
175
fprintf(stderr, "didn't match, at line %d\n", line);
178
else if (group >= 10) {
179
fprintf(stderr, "syntax error at line %d (too many groups)\n",
183
else if (so != mat[group].rm_so || eo != mat[group].rm_eo) {
184
fprintf(stderr, "match failed at line %d, got %ld,%ld: ",
185
line, mat[group].rm_so, mat[group].rm_eo);
186
if (mat[group].rm_so < mat[group].rm_eo)
187
fwrite(str + mat[group].rm_so,
188
mat[group].rm_eo - mat[group].rm_so, 1, stderr);