diff options
Diffstat (limited to '')
-rw-r--r-- | src/regress/lib/libc/regex/Makefile | 27 | ||||
-rw-r--r-- | src/regress/lib/libc/regex/debug.c | 208 | ||||
-rw-r--r-- | src/regress/lib/libc/regex/debug.ih | 17 | ||||
-rw-r--r-- | src/regress/lib/libc/regex/main.c | 516 | ||||
-rw-r--r-- | src/regress/lib/libc/regex/main.ih | 22 | ||||
-rw-r--r-- | src/regress/lib/libc/regex/split.c | 317 | ||||
-rw-r--r-- | src/regress/lib/libc/regex/t_exhaust.c | 183 | ||||
-rw-r--r-- | src/regress/lib/libc/regex/tests | 612 |
8 files changed, 0 insertions, 1902 deletions
diff --git a/src/regress/lib/libc/regex/Makefile b/src/regress/lib/libc/regex/Makefile deleted file mode 100644 index 5b9a080209..0000000000 --- a/src/regress/lib/libc/regex/Makefile +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | # $OpenBSD: Makefile,v 1.11 2017/04/16 16:01:05 kettenis Exp $ | ||
2 | # $NetBSD: Makefile,v 1.2 1995/02/16 19:38:45 cgd Exp $ | ||
3 | |||
4 | PROG= re | ||
5 | SRCS= main.c split.c debug.c regcomp.c regerror.c regexec.c regfree.c | ||
6 | .PATH: ${.CURDIR}/../../../../lib/libc/regex | ||
7 | CLEANFILES += t_exhaust | ||
8 | |||
9 | CFLAGS+= -I${.CURDIR}/../../../../lib/libc/regex -DREDEBUG -DPOSIX_MISTAKE | ||
10 | CFLAGS+= -D'DEF_WEAK(x)=asm("")' | ||
11 | |||
12 | TESTS= ${.CURDIR}/tests | ||
13 | |||
14 | REGRESS_TARGETS = do-reg do-reg-long do-reg-backref | ||
15 | # cannot run with large limits | ||
16 | #REGRESS_TARGETS += do-t_exhaust | ||
17 | |||
18 | do-reg: ${PROG} | ||
19 | ./re < ${TESTS} | ||
20 | do-reg-long: ${PROG} | ||
21 | ./re -el < ${TESTS} | ||
22 | do-reg-backref: ${PROG} | ||
23 | ./re -er < ${TESTS} | ||
24 | #do-t_exhaust: t_exhaust | ||
25 | # ./t_exhaust | ||
26 | |||
27 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/regex/debug.c b/src/regress/lib/libc/regex/debug.c deleted file mode 100644 index 7044a2a185..0000000000 --- a/src/regress/lib/libc/regex/debug.c +++ /dev/null | |||
@@ -1,208 +0,0 @@ | |||
1 | /* $OpenBSD: debug.c,v 1.5 2020/12/31 17:20:19 millert Exp $ */ | ||
2 | /* $NetBSD: debug.c,v 1.2 1995/04/20 22:39:42 cgd Exp $ */ | ||
3 | |||
4 | #include <stdio.h> | ||
5 | #include <string.h> | ||
6 | #include <ctype.h> | ||
7 | #include <limits.h> | ||
8 | #include <stdlib.h> | ||
9 | #include <sys/types.h> | ||
10 | #include <regex.h> | ||
11 | |||
12 | #include "utils.h" | ||
13 | #include "regex2.h" | ||
14 | #include "debug.ih" | ||
15 | |||
16 | /* | ||
17 | - regprint - print a regexp for debugging | ||
18 | == void regprint(regex_t *r, FILE *d); | ||
19 | */ | ||
20 | void | ||
21 | regprint(r, d) | ||
22 | regex_t *r; | ||
23 | FILE *d; | ||
24 | { | ||
25 | register struct re_guts *g = r->re_g; | ||
26 | register int i; | ||
27 | register int c; | ||
28 | register int last; | ||
29 | |||
30 | fprintf(d, "%ld states", (long)g->nstates); | ||
31 | fprintf(d, ", first %ld last %ld", (long)g->firststate, | ||
32 | (long)g->laststate); | ||
33 | if (g->iflags&USEBOL) | ||
34 | fprintf(d, ", USEBOL"); | ||
35 | if (g->iflags&USEEOL) | ||
36 | fprintf(d, ", USEEOL"); | ||
37 | if (g->iflags&BAD) | ||
38 | fprintf(d, ", BAD"); | ||
39 | if (g->nsub > 0) | ||
40 | fprintf(d, ", nsub=%ld", (long)g->nsub); | ||
41 | if (g->must != NULL) | ||
42 | fprintf(d, ", must(%ld) `%*s'", (long)g->mlen, (int)g->mlen, | ||
43 | g->must); | ||
44 | if (g->backrefs) | ||
45 | fprintf(d, ", backrefs"); | ||
46 | if (g->nplus > 0) | ||
47 | fprintf(d, ", nplus %ld", (long)g->nplus); | ||
48 | fprintf(d, "\n"); | ||
49 | s_print(g, d); | ||
50 | } | ||
51 | |||
52 | /* | ||
53 | - s_print - print the strip for debugging | ||
54 | == static void s_print(register struct re_guts *g, FILE *d); | ||
55 | */ | ||
56 | static void | ||
57 | s_print(g, d) | ||
58 | register struct re_guts *g; | ||
59 | FILE *d; | ||
60 | { | ||
61 | register sop *s; | ||
62 | register cset *cs; | ||
63 | register int i; | ||
64 | register int done = 0; | ||
65 | register sop opnd; | ||
66 | register int col = 0; | ||
67 | register int last; | ||
68 | register sopno offset = 2; | ||
69 | # define GAP() { if (offset % 5 == 0) { \ | ||
70 | if (col > 40) { \ | ||
71 | fprintf(d, "\n\t"); \ | ||
72 | col = 0; \ | ||
73 | } else { \ | ||
74 | fprintf(d, " "); \ | ||
75 | col++; \ | ||
76 | } \ | ||
77 | } else \ | ||
78 | col++; \ | ||
79 | offset++; \ | ||
80 | } | ||
81 | |||
82 | if (OP(g->strip[0]) != OEND) | ||
83 | fprintf(d, "missing initial OEND!\n"); | ||
84 | for (s = &g->strip[1]; !done; s++) { | ||
85 | opnd = OPND(*s); | ||
86 | switch (OP(*s)) { | ||
87 | case OEND: | ||
88 | fprintf(d, "\n"); | ||
89 | done = 1; | ||
90 | break; | ||
91 | case OCHAR: | ||
92 | if (strchr("\\|()^$.[+*?{}!<> ", (char)opnd) != NULL) | ||
93 | fprintf(d, "\\%c", (char)opnd); | ||
94 | else | ||
95 | fprintf(d, "%s", regchar((char)opnd)); | ||
96 | break; | ||
97 | case OBOL: | ||
98 | fprintf(d, "^"); | ||
99 | break; | ||
100 | case OEOL: | ||
101 | fprintf(d, "$"); | ||
102 | break; | ||
103 | case OBOW: | ||
104 | fprintf(d, "\\{"); | ||
105 | break; | ||
106 | case OEOW: | ||
107 | fprintf(d, "\\}"); | ||
108 | break; | ||
109 | case OANY: | ||
110 | fprintf(d, "."); | ||
111 | break; | ||
112 | case OANYOF: | ||
113 | fprintf(d, "[(%ld)", (long)opnd); | ||
114 | cs = &g->sets[opnd]; | ||
115 | last = -1; | ||
116 | for (i = 0; i < g->csetsize+1; i++) /* +1 flushes */ | ||
117 | if (CHIN(cs, i) && i < g->csetsize) { | ||
118 | if (last < 0) { | ||
119 | fprintf(d, "%s", regchar(i)); | ||
120 | last = i; | ||
121 | } | ||
122 | } else { | ||
123 | if (last >= 0) { | ||
124 | if (last != i-1) | ||
125 | fprintf(d, "-%s", | ||
126 | regchar(i-1)); | ||
127 | last = -1; | ||
128 | } | ||
129 | } | ||
130 | fprintf(d, "]"); | ||
131 | break; | ||
132 | case OBACK_: | ||
133 | fprintf(d, "(\\<%ld>", (long)opnd); | ||
134 | break; | ||
135 | case O_BACK: | ||
136 | fprintf(d, "<%ld>\\)", (long)opnd); | ||
137 | break; | ||
138 | case OPLUS_: | ||
139 | fprintf(d, "(+"); | ||
140 | if (OP(*(s+opnd)) != O_PLUS) | ||
141 | fprintf(d, "<%ld>", (long)opnd); | ||
142 | break; | ||
143 | case O_PLUS: | ||
144 | if (OP(*(s-opnd)) != OPLUS_) | ||
145 | fprintf(d, "<%ld>", (long)opnd); | ||
146 | fprintf(d, "+)"); | ||
147 | break; | ||
148 | case OQUEST_: | ||
149 | fprintf(d, "(?"); | ||
150 | if (OP(*(s+opnd)) != O_QUEST) | ||
151 | fprintf(d, "<%ld>", (long)opnd); | ||
152 | break; | ||
153 | case O_QUEST: | ||
154 | if (OP(*(s-opnd)) != OQUEST_) | ||
155 | fprintf(d, "<%ld>", (long)opnd); | ||
156 | fprintf(d, "?)"); | ||
157 | break; | ||
158 | case OLPAREN: | ||
159 | fprintf(d, "((<%ld>", (long)opnd); | ||
160 | break; | ||
161 | case ORPAREN: | ||
162 | fprintf(d, "<%ld>))", (long)opnd); | ||
163 | break; | ||
164 | case OCH_: | ||
165 | fprintf(d, "<"); | ||
166 | if (OP(*(s+opnd)) != OOR2) | ||
167 | fprintf(d, "<%ld>", (long)opnd); | ||
168 | break; | ||
169 | case OOR1: | ||
170 | if (OP(*(s-opnd)) != OOR1 && OP(*(s-opnd)) != OCH_) | ||
171 | fprintf(d, "<%ld>", (long)opnd); | ||
172 | fprintf(d, "|"); | ||
173 | break; | ||
174 | case OOR2: | ||
175 | fprintf(d, "|"); | ||
176 | if (OP(*(s+opnd)) != OOR2 && OP(*(s+opnd)) != O_CH) | ||
177 | fprintf(d, "<%ld>", (long)opnd); | ||
178 | break; | ||
179 | case O_CH: | ||
180 | if (OP(*(s-opnd)) != OOR1) | ||
181 | fprintf(d, "<%ld>", (long)opnd); | ||
182 | fprintf(d, ">"); | ||
183 | break; | ||
184 | default: | ||
185 | fprintf(d, "!%ld(%ld)!", (long)OP(*s), (long)opnd); | ||
186 | break; | ||
187 | } | ||
188 | if (!done) | ||
189 | GAP(); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | /* | ||
194 | - regchar - make a character printable | ||
195 | == static char *regchar(int ch); | ||
196 | */ | ||
197 | static char * /* -> representation */ | ||
198 | regchar(ch) | ||
199 | int ch; | ||
200 | { | ||
201 | static char buf[10]; | ||
202 | |||
203 | if (isprint(ch) || ch == ' ') | ||
204 | snprintf(buf, sizeof buf, "%c", ch); | ||
205 | else | ||
206 | snprintf(buf, sizeof buf, "\\%o", ch); | ||
207 | return(buf); | ||
208 | } | ||
diff --git a/src/regress/lib/libc/regex/debug.ih b/src/regress/lib/libc/regex/debug.ih deleted file mode 100644 index 9eb313af23..0000000000 --- a/src/regress/lib/libc/regex/debug.ih +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | /* $OpenBSD: debug.ih,v 1.3 2002/02/16 21:27:32 millert Exp $ */ | ||
2 | /* $NetBSD: debug.ih,v 1.2 1995/04/20 22:39:47 cgd Exp $ */ | ||
3 | |||
4 | /* ========= begin header generated by ./mkh ========= */ | ||
5 | #ifdef __cplusplus | ||
6 | extern "C" { | ||
7 | #endif | ||
8 | |||
9 | /* === debug.c === */ | ||
10 | void regprint(regex_t *r, FILE *d); | ||
11 | static void s_print(register struct re_guts *g, FILE *d); | ||
12 | static char *regchar(int ch); | ||
13 | |||
14 | #ifdef __cplusplus | ||
15 | } | ||
16 | #endif | ||
17 | /* ========= end header generated by ./mkh ========= */ | ||
diff --git a/src/regress/lib/libc/regex/main.c b/src/regress/lib/libc/regex/main.c deleted file mode 100644 index 4501e86b87..0000000000 --- a/src/regress/lib/libc/regex/main.c +++ /dev/null | |||
@@ -1,516 +0,0 @@ | |||
1 | /* $OpenBSD: main.c,v 1.12 2022/12/04 23:50:46 cheloha Exp $ */ | ||
2 | /* $NetBSD: main.c,v 1.2 1995/04/20 22:39:51 cgd Exp $ */ | ||
3 | |||
4 | #include <stdio.h> | ||
5 | #include <stdlib.h> | ||
6 | #include <string.h> | ||
7 | #include <sys/types.h> | ||
8 | #include <regex.h> | ||
9 | #include <assert.h> | ||
10 | #include <unistd.h> | ||
11 | |||
12 | #include "main.ih" | ||
13 | |||
14 | char *progname; | ||
15 | int debug = 0; | ||
16 | int line = 0; | ||
17 | int status = 0; | ||
18 | |||
19 | int copts = REG_EXTENDED; | ||
20 | int eopts = 0; | ||
21 | regoff_t startoff = 0; | ||
22 | regoff_t endoff = 0; | ||
23 | |||
24 | |||
25 | extern int split(char *, char *[], int, char *); | ||
26 | extern void regprint(regex_t *, FILE *); | ||
27 | |||
28 | /* | ||
29 | - main - do the simple case, hand off to regress() for regression | ||
30 | */ | ||
31 | int | ||
32 | main(int argc, char *argv[]) | ||
33 | |||
34 | { | ||
35 | regex_t re; | ||
36 | # define NS 10 | ||
37 | regmatch_t subs[NS]; | ||
38 | char erbuf[100]; | ||
39 | int err; | ||
40 | size_t len; | ||
41 | int c; | ||
42 | int errflg = 0; | ||
43 | register int i; | ||
44 | |||
45 | progname = argv[0]; | ||
46 | |||
47 | while ((c = getopt(argc, argv, "c:E:e:S:x")) != -1) | ||
48 | switch (c) { | ||
49 | case 'c': /* compile options */ | ||
50 | copts = options('c', optarg); | ||
51 | break; | ||
52 | case 'E': /* end offset */ | ||
53 | endoff = (regoff_t)atoi(optarg); | ||
54 | break; | ||
55 | case 'e': /* execute options */ | ||
56 | eopts = options('e', optarg); | ||
57 | break; | ||
58 | case 'S': /* start offset */ | ||
59 | startoff = (regoff_t)atoi(optarg); | ||
60 | break; | ||
61 | case 'x': /* Debugging. */ | ||
62 | debug++; | ||
63 | break; | ||
64 | default: | ||
65 | errflg++; | ||
66 | break; | ||
67 | } | ||
68 | if (errflg) { | ||
69 | fprintf(stderr, "usage: %s ", progname); | ||
70 | fprintf(stderr, "[-x] [-c copt] [-E endoff] [-e eopt] [-S startoff] [re]\n"); | ||
71 | exit(2); | ||
72 | } | ||
73 | |||
74 | if (optind >= argc) { | ||
75 | regress(stdin); | ||
76 | exit(status); | ||
77 | } | ||
78 | |||
79 | err = regcomp(&re, argv[optind++], copts); | ||
80 | if (err) { | ||
81 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | ||
82 | fprintf(stderr, "error %s, %zu/%zu `%s'\n", | ||
83 | eprint(err), len, sizeof(erbuf), erbuf); | ||
84 | exit(status); | ||
85 | } | ||
86 | regprint(&re, stdout); | ||
87 | |||
88 | if (optind >= argc) { | ||
89 | regfree(&re); | ||
90 | exit(status); | ||
91 | } | ||
92 | |||
93 | if (eopts®_STARTEND) { | ||
94 | subs[0].rm_so = startoff; | ||
95 | subs[0].rm_eo = strlen(argv[optind]) - endoff; | ||
96 | } | ||
97 | err = regexec(&re, argv[optind], (size_t)NS, subs, eopts); | ||
98 | if (err) { | ||
99 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | ||
100 | fprintf(stderr, "error %s, %zu/%zu `%s'\n", | ||
101 | eprint(err), len, sizeof(erbuf), erbuf); | ||
102 | exit(status); | ||
103 | } | ||
104 | if (!(copts®_NOSUB)) { | ||
105 | len = (size_t)(subs[0].rm_eo - subs[0].rm_so); | ||
106 | if (subs[0].rm_so != -1) { | ||
107 | if (len != 0) | ||
108 | printf("match `%.*s'\n", (int)len, | ||
109 | argv[optind] + subs[0].rm_so); | ||
110 | else | ||
111 | printf("match `'@%.1s\n", | ||
112 | argv[optind] + subs[0].rm_so); | ||
113 | } | ||
114 | for (i = 1; i < NS; i++) | ||
115 | if (subs[i].rm_so != -1) | ||
116 | printf("(%d) `%.*s'\n", i, | ||
117 | (int)(subs[i].rm_eo - subs[i].rm_so), | ||
118 | argv[optind] + subs[i].rm_so); | ||
119 | } | ||
120 | exit(status); | ||
121 | } | ||
122 | |||
123 | /* | ||
124 | - regress - main loop of regression test | ||
125 | == void regress(FILE *in); | ||
126 | */ | ||
127 | void | ||
128 | regress(in) | ||
129 | FILE *in; | ||
130 | { | ||
131 | char inbuf[1000]; | ||
132 | # define MAXF 10 | ||
133 | char *f[MAXF]; | ||
134 | int nf; | ||
135 | int i; | ||
136 | char erbuf[100]; | ||
137 | size_t ne; | ||
138 | char *badpat = "invalid regular expression"; | ||
139 | # define SHORT 10 | ||
140 | char *bpname = "REG_BADPAT"; | ||
141 | regex_t re; | ||
142 | |||
143 | while (fgets(inbuf, sizeof(inbuf), in) != NULL) { | ||
144 | line++; | ||
145 | if (inbuf[0] == '#' || inbuf[0] == '\n') | ||
146 | continue; /* NOTE CONTINUE */ | ||
147 | inbuf[strcspn(inbuf, "\n")] = '\0'; /* get rid of stupid \n */ | ||
148 | if (debug) | ||
149 | fprintf(stdout, "%d:\n", line); | ||
150 | nf = split(inbuf, f, MAXF, "\t\t"); | ||
151 | if (nf < 3) { | ||
152 | fprintf(stderr, "bad input, line %d\n", line); | ||
153 | exit(1); | ||
154 | } | ||
155 | for (i = 0; i < nf; i++) | ||
156 | if (strcmp(f[i], "\"\"") == 0) | ||
157 | f[i] = ""; | ||
158 | if (nf <= 3) | ||
159 | f[3] = NULL; | ||
160 | if (nf <= 4) | ||
161 | f[4] = NULL; | ||
162 | try(f[0], f[1], f[2], f[3], f[4], options('c', f[1])); | ||
163 | if (opt('&', f[1])) /* try with either type of RE */ | ||
164 | try(f[0], f[1], f[2], f[3], f[4], | ||
165 | options('c', f[1]) &~ REG_EXTENDED); | ||
166 | } | ||
167 | |||
168 | ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf)); | ||
169 | if (strcmp(erbuf, badpat) != 0 || ne != strlen(badpat)+1) { | ||
170 | fprintf(stderr, "end: regerror() test gave `%s' not `%s'\n", | ||
171 | erbuf, badpat); | ||
172 | status = 1; | ||
173 | } | ||
174 | ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, (size_t)SHORT); | ||
175 | if (strncmp(erbuf, badpat, SHORT-1) != 0 || erbuf[SHORT-1] != '\0' || | ||
176 | ne != strlen(badpat)+1) { | ||
177 | fprintf(stderr, "end: regerror() short test gave `%s' not `%.*s'\n", | ||
178 | erbuf, SHORT-1, badpat); | ||
179 | status = 1; | ||
180 | } | ||
181 | ne = regerror(REG_ITOA|REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf)); | ||
182 | if (strcmp(erbuf, bpname) != 0 || ne != strlen(bpname)+1) { | ||
183 | fprintf(stderr, "end: regerror() ITOA test gave `%s' not `%s'\n", | ||
184 | erbuf, bpname); | ||
185 | status = 1; | ||
186 | } | ||
187 | re.re_endp = bpname; | ||
188 | ne = regerror(REG_ATOI, &re, erbuf, sizeof(erbuf)); | ||
189 | if (atoi(erbuf) != (int)REG_BADPAT) { | ||
190 | fprintf(stderr, "end: regerror() ATOI test gave `%s' not `%ld'\n", | ||
191 | erbuf, (long)REG_BADPAT); | ||
192 | status = 1; | ||
193 | } else if (ne != strlen(erbuf)+1) { | ||
194 | fprintf(stderr, "end: regerror() ATOI test len(`%s') = %ld\n", | ||
195 | erbuf, (long)REG_BADPAT); | ||
196 | status = 1; | ||
197 | } | ||
198 | } | ||
199 | |||
200 | /* | ||
201 | - try - try it, and report on problems | ||
202 | == void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts); | ||
203 | */ | ||
204 | void | ||
205 | try(f0, f1, f2, f3, f4, opts) | ||
206 | char *f0; | ||
207 | char *f1; | ||
208 | char *f2; | ||
209 | char *f3; | ||
210 | char *f4; | ||
211 | int opts; /* may not match f1 */ | ||
212 | { | ||
213 | regex_t re; | ||
214 | # define NSUBS 10 | ||
215 | regmatch_t subs[NSUBS]; | ||
216 | # define NSHOULD 15 | ||
217 | char *should[NSHOULD]; | ||
218 | int nshould; | ||
219 | char erbuf[100]; | ||
220 | int err; | ||
221 | int len; | ||
222 | char *type = (opts & REG_EXTENDED) ? "ERE" : "BRE"; | ||
223 | register int i; | ||
224 | char *grump; | ||
225 | char f0copy[1000]; | ||
226 | char f2copy[1000]; | ||
227 | |||
228 | strlcpy(f0copy, f0, sizeof f0copy); | ||
229 | re.re_endp = (opts®_PEND) ? f0copy + strlen(f0copy) : NULL; | ||
230 | fixstr(f0copy); | ||
231 | err = regcomp(&re, f0copy, opts); | ||
232 | if (err != 0 && (!opt('C', f1) || err != efind(f2))) { | ||
233 | /* unexpected error or wrong error */ | ||
234 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | ||
235 | fprintf(stderr, "%d: %s error %s, %d/%zu `%s'\n", | ||
236 | line, type, eprint(err), len, | ||
237 | sizeof(erbuf), erbuf); | ||
238 | status = 1; | ||
239 | } else if (err == 0 && opt('C', f1)) { | ||
240 | /* unexpected success */ | ||
241 | fprintf(stderr, "%d: %s should have given REG_%s\n", | ||
242 | line, type, f2); | ||
243 | status = 1; | ||
244 | err = 1; /* so we won't try regexec */ | ||
245 | } | ||
246 | |||
247 | if (err != 0) { | ||
248 | regfree(&re); | ||
249 | return; | ||
250 | } | ||
251 | |||
252 | strlcpy(f2copy, f2, sizeof f2copy); | ||
253 | fixstr(f2copy); | ||
254 | |||
255 | if (options('e', f1)®_STARTEND) { | ||
256 | if (strchr(f2, '(') == NULL || strchr(f2, ')') == NULL) | ||
257 | fprintf(stderr, "%d: bad STARTEND syntax\n", line); | ||
258 | subs[0].rm_so = strchr(f2, '(') - f2 + 1; | ||
259 | subs[0].rm_eo = strchr(f2, ')') - f2; | ||
260 | /* the preceding character is relevant with REG_NOTBOL */ | ||
261 | f2copy[subs[0].rm_so - 1] = subs[0].rm_so > 1 ? | ||
262 | f2copy[subs[0].rm_so - 2] : 'X'; | ||
263 | } | ||
264 | err = regexec(&re, f2copy, NSUBS, subs, options('e', f1)); | ||
265 | |||
266 | if (err != 0 && (f3 != NULL || err != REG_NOMATCH)) { | ||
267 | /* unexpected error or wrong error */ | ||
268 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | ||
269 | fprintf(stderr, "%d: %s exec error %s, %d/%zu `%s'\n", | ||
270 | line, type, eprint(err), len, | ||
271 | sizeof(erbuf), erbuf); | ||
272 | status = 1; | ||
273 | } else if (err != 0) { | ||
274 | /* nothing more to check */ | ||
275 | } else if (f3 == NULL) { | ||
276 | /* unexpected success */ | ||
277 | fprintf(stderr, "%d: %s exec should have failed\n", | ||
278 | line, type); | ||
279 | status = 1; | ||
280 | err = 1; /* just on principle */ | ||
281 | } else if (opts®_NOSUB) { | ||
282 | /* nothing more to check */ | ||
283 | } else if ((grump = check(f2, subs[0], f3)) != NULL) { | ||
284 | fprintf(stderr, "%d: %s %s\n", line, type, grump); | ||
285 | status = 1; | ||
286 | err = 1; | ||
287 | } | ||
288 | |||
289 | if (err != 0 || f4 == NULL) { | ||
290 | regfree(&re); | ||
291 | return; | ||
292 | } | ||
293 | |||
294 | for (i = 1; i < NSHOULD; i++) | ||
295 | should[i] = NULL; | ||
296 | nshould = split(f4, should+1, NSHOULD-1, ","); | ||
297 | if (nshould == 0) { | ||
298 | nshould = 1; | ||
299 | should[1] = ""; | ||
300 | } | ||
301 | for (i = 1; i < NSUBS; i++) { | ||
302 | grump = check(f2, subs[i], should[i]); | ||
303 | if (grump != NULL) { | ||
304 | fprintf(stderr, "%d: %s $%d %s\n", line, | ||
305 | type, i, grump); | ||
306 | status = 1; | ||
307 | err = 1; | ||
308 | } | ||
309 | } | ||
310 | |||
311 | regfree(&re); | ||
312 | } | ||
313 | |||
314 | /* | ||
315 | - options - pick options out of a regression-test string | ||
316 | == int options(int type, char *s); | ||
317 | */ | ||
318 | int | ||
319 | options(type, s) | ||
320 | int type; /* 'c' compile, 'e' exec */ | ||
321 | char *s; | ||
322 | { | ||
323 | register char *p; | ||
324 | register int o = (type == 'c') ? copts : eopts; | ||
325 | register char *legal = (type == 'c') ? "bisnmp" : "^$#tl"; | ||
326 | |||
327 | for (p = s; *p != '\0'; p++) | ||
328 | if (strchr(legal, *p) != NULL) | ||
329 | switch (*p) { | ||
330 | case 'b': | ||
331 | o &= ~REG_EXTENDED; | ||
332 | break; | ||
333 | case 'i': | ||
334 | o |= REG_ICASE; | ||
335 | break; | ||
336 | case 's': | ||
337 | o |= REG_NOSUB; | ||
338 | break; | ||
339 | case 'n': | ||
340 | o |= REG_NEWLINE; | ||
341 | break; | ||
342 | case 'm': | ||
343 | o &= ~REG_EXTENDED; | ||
344 | o |= REG_NOSPEC; | ||
345 | break; | ||
346 | case 'p': | ||
347 | o |= REG_PEND; | ||
348 | break; | ||
349 | case '^': | ||
350 | o |= REG_NOTBOL; | ||
351 | break; | ||
352 | case '$': | ||
353 | o |= REG_NOTEOL; | ||
354 | break; | ||
355 | case '#': | ||
356 | o |= REG_STARTEND; | ||
357 | break; | ||
358 | case 't': /* trace */ | ||
359 | o |= REG_TRACE; | ||
360 | break; | ||
361 | case 'l': /* force long representation */ | ||
362 | o |= REG_LARGE; | ||
363 | break; | ||
364 | case 'r': /* force backref use */ | ||
365 | o |= REG_BACKR; | ||
366 | break; | ||
367 | } | ||
368 | return(o); | ||
369 | } | ||
370 | |||
371 | /* | ||
372 | - opt - is a particular option in a regression string? | ||
373 | == int opt(int c, char *s); | ||
374 | */ | ||
375 | int /* predicate */ | ||
376 | opt(c, s) | ||
377 | int c; | ||
378 | char *s; | ||
379 | { | ||
380 | return(strchr(s, c) != NULL); | ||
381 | } | ||
382 | |||
383 | /* | ||
384 | - fixstr - transform magic characters in strings | ||
385 | == void fixstr(register char *p); | ||
386 | */ | ||
387 | void | ||
388 | fixstr(p) | ||
389 | register char *p; | ||
390 | { | ||
391 | if (p == NULL) | ||
392 | return; | ||
393 | |||
394 | for (; *p != '\0'; p++) | ||
395 | if (*p == 'N') | ||
396 | *p = '\n'; | ||
397 | else if (*p == 'T') | ||
398 | *p = '\t'; | ||
399 | else if (*p == 'S') | ||
400 | *p = ' '; | ||
401 | else if (*p == 'Z') | ||
402 | *p = '\0'; | ||
403 | } | ||
404 | |||
405 | /* | ||
406 | - check - check a substring match | ||
407 | == char *check(char *str, regmatch_t sub, char *should); | ||
408 | */ | ||
409 | char * /* NULL or complaint */ | ||
410 | check(str, sub, should) | ||
411 | char *str; | ||
412 | regmatch_t sub; | ||
413 | char *should; | ||
414 | { | ||
415 | register int len; | ||
416 | register int shlen; | ||
417 | register char *p; | ||
418 | static char grump[500]; | ||
419 | register char *at = NULL; | ||
420 | |||
421 | if (should != NULL && strcmp(should, "-") == 0) | ||
422 | should = NULL; | ||
423 | if (should != NULL && should[0] == '@') { | ||
424 | at = should + 1; | ||
425 | should = ""; | ||
426 | } | ||
427 | |||
428 | /* check rm_so and rm_eo for consistency */ | ||
429 | if (sub.rm_so > sub.rm_eo || (sub.rm_so == -1 && sub.rm_eo != -1) || | ||
430 | (sub.rm_so != -1 && sub.rm_eo == -1) || | ||
431 | (sub.rm_so != -1 && sub.rm_so < 0) || | ||
432 | (sub.rm_eo != -1 && sub.rm_eo < 0) ) { | ||
433 | snprintf(grump, sizeof grump, | ||
434 | "start %ld end %ld", (long)sub.rm_so, | ||
435 | (long)sub.rm_eo); | ||
436 | return(grump); | ||
437 | } | ||
438 | |||
439 | /* check for no match */ | ||
440 | if (sub.rm_so == -1 && should == NULL) | ||
441 | return(NULL); | ||
442 | if (sub.rm_so == -1) | ||
443 | return("did not match"); | ||
444 | |||
445 | /* check for in range */ | ||
446 | if (sub.rm_eo > strlen(str)) { | ||
447 | snprintf(grump, sizeof grump, | ||
448 | "start %ld end %ld, past end of string", | ||
449 | (long)sub.rm_so, (long)sub.rm_eo); | ||
450 | return(grump); | ||
451 | } | ||
452 | |||
453 | len = (int)(sub.rm_eo - sub.rm_so); | ||
454 | p = str + sub.rm_so; | ||
455 | |||
456 | /* check for not supposed to match */ | ||
457 | if (should == NULL) { | ||
458 | snprintf(grump, sizeof grump, "matched `%.*s'", len, p); | ||
459 | return(grump); | ||
460 | } | ||
461 | |||
462 | /* check for wrong match */ | ||
463 | shlen = (int)strlen(should); | ||
464 | if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) { | ||
465 | snprintf(grump, sizeof grump, "matched `%.*s' instead", len, p); | ||
466 | return(grump); | ||
467 | } | ||
468 | if (shlen > 0) | ||
469 | return(NULL); | ||
470 | |||
471 | /* check null match in right place */ | ||
472 | if (at == NULL) | ||
473 | return(NULL); | ||
474 | shlen = strlen(at); | ||
475 | if (shlen == 0) | ||
476 | shlen = 1; /* force check for end-of-string */ | ||
477 | if (strncmp(p, at, shlen) != 0) { | ||
478 | snprintf(grump, sizeof grump, "matched null at `%.20s'", p); | ||
479 | return(grump); | ||
480 | } | ||
481 | return(NULL); | ||
482 | } | ||
483 | |||
484 | /* | ||
485 | - eprint - convert error number to name | ||
486 | == static char *eprint(int err); | ||
487 | */ | ||
488 | static char * | ||
489 | eprint(err) | ||
490 | int err; | ||
491 | { | ||
492 | static char epbuf[100]; | ||
493 | size_t len; | ||
494 | |||
495 | len = regerror(REG_ITOA|err, (regex_t *)NULL, epbuf, sizeof(epbuf)); | ||
496 | assert(len <= sizeof(epbuf)); | ||
497 | return(epbuf); | ||
498 | } | ||
499 | |||
500 | /* | ||
501 | - efind - convert error name to number | ||
502 | == static int efind(char *name); | ||
503 | */ | ||
504 | static int | ||
505 | efind(name) | ||
506 | char *name; | ||
507 | { | ||
508 | static char efbuf[100]; | ||
509 | regex_t re; | ||
510 | |||
511 | snprintf(efbuf, sizeof efbuf, "REG_%s", name); | ||
512 | assert(strlen(efbuf) < sizeof(efbuf)); | ||
513 | re.re_endp = efbuf; | ||
514 | (void) regerror(REG_ATOI, &re, efbuf, sizeof(efbuf)); | ||
515 | return(atoi(efbuf)); | ||
516 | } | ||
diff --git a/src/regress/lib/libc/regex/main.ih b/src/regress/lib/libc/regex/main.ih deleted file mode 100644 index 0860e26333..0000000000 --- a/src/regress/lib/libc/regex/main.ih +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | /* $OpenBSD: main.ih,v 1.3 2002/02/16 21:27:32 millert Exp $ */ | ||
2 | /* $NetBSD: main.ih,v 1.2 1995/04/20 22:39:55 cgd Exp $ */ | ||
3 | |||
4 | /* ========= begin header generated by ./mkh ========= */ | ||
5 | #ifdef __cplusplus | ||
6 | extern "C" { | ||
7 | #endif | ||
8 | |||
9 | /* === main.c === */ | ||
10 | void regress(FILE *in); | ||
11 | void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts); | ||
12 | int options(int type, char *s); | ||
13 | int opt(int c, char *s); | ||
14 | void fixstr(register char *p); | ||
15 | char *check(char *str, regmatch_t sub, char *should); | ||
16 | static char *eprint(int err); | ||
17 | static int efind(char *name); | ||
18 | |||
19 | #ifdef __cplusplus | ||
20 | } | ||
21 | #endif | ||
22 | /* ========= end header generated by ./mkh ========= */ | ||
diff --git a/src/regress/lib/libc/regex/split.c b/src/regress/lib/libc/regex/split.c deleted file mode 100644 index fcd81a3503..0000000000 --- a/src/regress/lib/libc/regex/split.c +++ /dev/null | |||
@@ -1,317 +0,0 @@ | |||
1 | /* $OpenBSD: split.c,v 1.5 2007/09/09 23:25:12 chl Exp $ */ | ||
2 | /* $NetBSD: split.c,v 1.2 1995/04/20 22:39:57 cgd Exp $ */ | ||
3 | |||
4 | #include <stdio.h> | ||
5 | #include <string.h> | ||
6 | |||
7 | int split(char *string, char *fields[], int nfields, char *sep); | ||
8 | |||
9 | /* | ||
10 | - split - divide a string into fields, like awk split() | ||
11 | = int split(char *string, char *fields[], int nfields, char *sep); | ||
12 | */ | ||
13 | int /* number of fields, including overflow */ | ||
14 | split(char *string, char *fields[], int nfields, char *sep) | ||
15 | { | ||
16 | register char *p = string; | ||
17 | register char c; /* latest character */ | ||
18 | register char sepc = sep[0]; | ||
19 | register char sepc2; | ||
20 | register int fn; | ||
21 | register char **fp = fields; | ||
22 | register char *sepp; | ||
23 | register int trimtrail; | ||
24 | |||
25 | /* white space */ | ||
26 | if (sepc == '\0') { | ||
27 | while ((c = *p++) == ' ' || c == '\t') | ||
28 | continue; | ||
29 | p--; | ||
30 | trimtrail = 1; | ||
31 | sep = " \t"; /* note, code below knows this is 2 long */ | ||
32 | sepc = ' '; | ||
33 | } else | ||
34 | trimtrail = 0; | ||
35 | sepc2 = sep[1]; /* now we can safely pick this up */ | ||
36 | |||
37 | /* catch empties */ | ||
38 | if (*p == '\0') | ||
39 | return(0); | ||
40 | |||
41 | /* single separator */ | ||
42 | if (sepc2 == '\0') { | ||
43 | fn = nfields; | ||
44 | for (;;) { | ||
45 | *fp++ = p; | ||
46 | fn--; | ||
47 | if (fn == 0) | ||
48 | break; | ||
49 | while ((c = *p++) != sepc) | ||
50 | if (c == '\0') | ||
51 | return(nfields - fn); | ||
52 | *(p-1) = '\0'; | ||
53 | } | ||
54 | /* we have overflowed the fields vector -- just count them */ | ||
55 | fn = nfields; | ||
56 | for (;;) { | ||
57 | while ((c = *p++) != sepc) | ||
58 | if (c == '\0') | ||
59 | return(fn); | ||
60 | fn++; | ||
61 | } | ||
62 | /* not reached */ | ||
63 | } | ||
64 | |||
65 | /* two separators */ | ||
66 | if (sep[2] == '\0') { | ||
67 | fn = nfields; | ||
68 | for (;;) { | ||
69 | *fp++ = p; | ||
70 | fn--; | ||
71 | while ((c = *p++) != sepc && c != sepc2) | ||
72 | if (c == '\0') { | ||
73 | if (trimtrail && **(fp-1) == '\0') | ||
74 | fn++; | ||
75 | return(nfields - fn); | ||
76 | } | ||
77 | if (fn == 0) | ||
78 | break; | ||
79 | *(p-1) = '\0'; | ||
80 | while ((c = *p++) == sepc || c == sepc2) | ||
81 | continue; | ||
82 | p--; | ||
83 | } | ||
84 | /* we have overflowed the fields vector -- just count them */ | ||
85 | fn = nfields; | ||
86 | while (c != '\0') { | ||
87 | while ((c = *p++) == sepc || c == sepc2) | ||
88 | continue; | ||
89 | p--; | ||
90 | fn++; | ||
91 | while ((c = *p++) != '\0' && c != sepc && c != sepc2) | ||
92 | continue; | ||
93 | } | ||
94 | /* might have to trim trailing white space */ | ||
95 | if (trimtrail) { | ||
96 | p--; | ||
97 | while ((c = *--p) == sepc || c == sepc2) | ||
98 | continue; | ||
99 | p++; | ||
100 | if (*p != '\0') { | ||
101 | if (fn == nfields+1) | ||
102 | *p = '\0'; | ||
103 | fn--; | ||
104 | } | ||
105 | } | ||
106 | return(fn); | ||
107 | } | ||
108 | |||
109 | /* n separators */ | ||
110 | fn = 0; | ||
111 | for (;;) { | ||
112 | if (fn < nfields) | ||
113 | *fp++ = p; | ||
114 | fn++; | ||
115 | for (;;) { | ||
116 | c = *p++; | ||
117 | if (c == '\0') | ||
118 | return(fn); | ||
119 | sepp = sep; | ||
120 | while ((sepc = *sepp++) != '\0' && sepc != c) | ||
121 | continue; | ||
122 | if (sepc != '\0') /* it was a separator */ | ||
123 | break; | ||
124 | } | ||
125 | if (fn < nfields) | ||
126 | *(p-1) = '\0'; | ||
127 | for (;;) { | ||
128 | c = *p++; | ||
129 | sepp = sep; | ||
130 | while ((sepc = *sepp++) != '\0' && sepc != c) | ||
131 | continue; | ||
132 | if (sepc == '\0') /* it wasn't a separator */ | ||
133 | break; | ||
134 | } | ||
135 | p--; | ||
136 | } | ||
137 | |||
138 | /* not reached */ | ||
139 | } | ||
140 | |||
141 | #ifdef TEST_SPLIT | ||
142 | |||
143 | |||
144 | /* | ||
145 | * test program | ||
146 | * pgm runs regression | ||
147 | * pgm sep splits stdin lines by sep | ||
148 | * pgm str sep splits str by sep | ||
149 | * pgm str sep n splits str by sep n times | ||
150 | */ | ||
151 | int | ||
152 | main(argc, argv) | ||
153 | int argc; | ||
154 | char *argv[]; | ||
155 | { | ||
156 | char buf[512]; | ||
157 | register int n; | ||
158 | # define MNF 10 | ||
159 | char *fields[MNF]; | ||
160 | |||
161 | if (argc > 4) | ||
162 | for (n = atoi(argv[3]); n > 0; n--) { | ||
163 | (void) strlcpy(buf, argv[1], sizeof buf); | ||
164 | } | ||
165 | else if (argc > 3) | ||
166 | for (n = atoi(argv[3]); n > 0; n--) { | ||
167 | (void) strlcpy(buf, argv[1], sizeof buf); | ||
168 | (void) split(buf, fields, MNF, argv[2]); | ||
169 | } | ||
170 | else if (argc > 2) | ||
171 | dosplit(argv[1], argv[2]); | ||
172 | else if (argc > 1) | ||
173 | while (fgets(buf, sizeof(buf), stdin) != NULL) { | ||
174 | buf[strcspn(buf, "\n")] = '\0'; /* stomp newline */ | ||
175 | dosplit(buf, argv[1]); | ||
176 | } | ||
177 | else | ||
178 | regress(); | ||
179 | |||
180 | exit(0); | ||
181 | } | ||
182 | |||
183 | dosplit(string, seps) | ||
184 | char *string; | ||
185 | char *seps; | ||
186 | { | ||
187 | # define NF 5 | ||
188 | char *fields[NF]; | ||
189 | register int nf; | ||
190 | |||
191 | nf = split(string, fields, NF, seps); | ||
192 | print(nf, NF, fields); | ||
193 | } | ||
194 | |||
195 | print(nf, nfp, fields) | ||
196 | int nf; | ||
197 | int nfp; | ||
198 | char *fields[]; | ||
199 | { | ||
200 | register int fn; | ||
201 | register int bound; | ||
202 | |||
203 | bound = (nf > nfp) ? nfp : nf; | ||
204 | printf("%d:\t", nf); | ||
205 | for (fn = 0; fn < bound; fn++) | ||
206 | printf("\"%s\"%s", fields[fn], (fn+1 < nf) ? ", " : "\n"); | ||
207 | } | ||
208 | |||
209 | #define RNF 5 /* some table entries know this */ | ||
210 | struct { | ||
211 | char *str; | ||
212 | char *seps; | ||
213 | int nf; | ||
214 | char *fi[RNF]; | ||
215 | } tests[] = { | ||
216 | "", " ", 0, { "" }, | ||
217 | " ", " ", 2, { "", "" }, | ||
218 | "x", " ", 1, { "x" }, | ||
219 | "xy", " ", 1, { "xy" }, | ||
220 | "x y", " ", 2, { "x", "y" }, | ||
221 | "abc def g ", " ", 5, { "abc", "def", "", "g", "" }, | ||
222 | " a bcd", " ", 4, { "", "", "a", "bcd" }, | ||
223 | "a b c d e f", " ", 6, { "a", "b", "c", "d", "e f" }, | ||
224 | " a b c d ", " ", 6, { "", "a", "b", "c", "d " }, | ||
225 | |||
226 | "", " _", 0, { "" }, | ||
227 | " ", " _", 2, { "", "" }, | ||
228 | "x", " _", 1, { "x" }, | ||
229 | "x y", " _", 2, { "x", "y" }, | ||
230 | "ab _ cd", " _", 2, { "ab", "cd" }, | ||
231 | " a_b c ", " _", 5, { "", "a", "b", "c", "" }, | ||
232 | "a b c_d e f", " _", 6, { "a", "b", "c", "d", "e f" }, | ||
233 | " a b c d ", " _", 6, { "", "a", "b", "c", "d " }, | ||
234 | |||
235 | "", " _~", 0, { "" }, | ||
236 | " ", " _~", 2, { "", "" }, | ||
237 | "x", " _~", 1, { "x" }, | ||
238 | "x y", " _~", 2, { "x", "y" }, | ||
239 | "ab _~ cd", " _~", 2, { "ab", "cd" }, | ||
240 | " a_b c~", " _~", 5, { "", "a", "b", "c", "" }, | ||
241 | "a b_c d~e f", " _~", 6, { "a", "b", "c", "d", "e f" }, | ||
242 | "~a b c d ", " _~", 6, { "", "a", "b", "c", "d " }, | ||
243 | |||
244 | "", " _~-", 0, { "" }, | ||
245 | " ", " _~-", 2, { "", "" }, | ||
246 | "x", " _~-", 1, { "x" }, | ||
247 | "x y", " _~-", 2, { "x", "y" }, | ||
248 | "ab _~- cd", " _~-", 2, { "ab", "cd" }, | ||
249 | " a_b c~", " _~-", 5, { "", "a", "b", "c", "" }, | ||
250 | "a b_c-d~e f", " _~-", 6, { "a", "b", "c", "d", "e f" }, | ||
251 | "~a-b c d ", " _~-", 6, { "", "a", "b", "c", "d " }, | ||
252 | |||
253 | "", " ", 0, { "" }, | ||
254 | " ", " ", 2, { "", "" }, | ||
255 | "x", " ", 1, { "x" }, | ||
256 | "xy", " ", 1, { "xy" }, | ||
257 | "x y", " ", 2, { "x", "y" }, | ||
258 | "abc def g ", " ", 4, { "abc", "def", "g", "" }, | ||
259 | " a bcd", " ", 3, { "", "a", "bcd" }, | ||
260 | "a b c d e f", " ", 6, { "a", "b", "c", "d", "e f" }, | ||
261 | " a b c d ", " ", 6, { "", "a", "b", "c", "d " }, | ||
262 | |||
263 | "", "", 0, { "" }, | ||
264 | " ", "", 0, { "" }, | ||
265 | "x", "", 1, { "x" }, | ||
266 | "xy", "", 1, { "xy" }, | ||
267 | "x y", "", 2, { "x", "y" }, | ||
268 | "abc def g ", "", 3, { "abc", "def", "g" }, | ||
269 | "\t a bcd", "", 2, { "a", "bcd" }, | ||
270 | " a \tb\t c ", "", 3, { "a", "b", "c" }, | ||
271 | "a b c d e ", "", 5, { "a", "b", "c", "d", "e" }, | ||
272 | "a b\tc d e f", "", 6, { "a", "b", "c", "d", "e f" }, | ||
273 | " a b c d e f ", "", 6, { "a", "b", "c", "d", "e f " }, | ||
274 | |||
275 | NULL, NULL, 0, { NULL }, | ||
276 | }; | ||
277 | |||
278 | regress() | ||
279 | { | ||
280 | char buf[512]; | ||
281 | register int n; | ||
282 | char *fields[RNF+1]; | ||
283 | register int nf; | ||
284 | register int i; | ||
285 | register int printit; | ||
286 | register char *f; | ||
287 | |||
288 | for (n = 0; tests[n].str != NULL; n++) { | ||
289 | (void) strlcpy(buf, tests[n].str, sizeof buf); | ||
290 | fields[RNF] = NULL; | ||
291 | nf = split(buf, fields, RNF, tests[n].seps); | ||
292 | printit = 0; | ||
293 | if (nf != tests[n].nf) { | ||
294 | printf("split `%s' by `%s' gave %d fields, not %d\n", | ||
295 | tests[n].str, tests[n].seps, nf, tests[n].nf); | ||
296 | printit = 1; | ||
297 | } else if (fields[RNF] != NULL) { | ||
298 | printf("split() went beyond array end\n"); | ||
299 | printit = 1; | ||
300 | } else { | ||
301 | for (i = 0; i < nf && i < RNF; i++) { | ||
302 | f = fields[i]; | ||
303 | if (f == NULL) | ||
304 | f = "(NULL)"; | ||
305 | if (strcmp(f, tests[n].fi[i]) != 0) { | ||
306 | printf("split `%s' by `%s', field %d is `%s', not `%s'\n", | ||
307 | tests[n].str, tests[n].seps, | ||
308 | i, fields[i], tests[n].fi[i]); | ||
309 | printit = 1; | ||
310 | } | ||
311 | } | ||
312 | } | ||
313 | if (printit) | ||
314 | print(nf, RNF, fields); | ||
315 | } | ||
316 | } | ||
317 | #endif | ||
diff --git a/src/regress/lib/libc/regex/t_exhaust.c b/src/regress/lib/libc/regex/t_exhaust.c deleted file mode 100644 index f54bab18da..0000000000 --- a/src/regress/lib/libc/regex/t_exhaust.c +++ /dev/null | |||
@@ -1,183 +0,0 @@ | |||
1 | /* $OpenBSD: t_exhaust.c,v 1.4 2024/07/15 10:11:56 anton Exp $ */ | ||
2 | /* $NetBSD: t_exhaust.c,v 1.2 2011/10/21 00:41:34 christos Exp $ */ | ||
3 | |||
4 | /*- | ||
5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * This code is derived from software contributed to The NetBSD Foundation | ||
9 | * by Christos Zoulas. | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or without | ||
12 | * modification, are permitted provided that the following conditions | ||
13 | * are met: | ||
14 | * 1. Redistributions of source code must retain the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer. | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in the | ||
18 | * documentation and/or other materials provided with the distribution. | ||
19 | * 3. All advertising materials mentioning features or use of this software | ||
20 | * must display the following acknowledgement: | ||
21 | * This product includes software developed by the NetBSD | ||
22 | * Foundation, Inc. and its contributors. | ||
23 | * 4. Neither the name of The NetBSD Foundation nor the names of its | ||
24 | * contributors may be used to endorse or promote products derived | ||
25 | * from this software without specific prior written permission. | ||
26 | * | ||
27 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
28 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
29 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
30 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
31 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
32 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
33 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
34 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
35 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
36 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
37 | * POSSIBILITY OF SUCH DAMAGE. | ||
38 | */ | ||
39 | |||
40 | #include <stdio.h> | ||
41 | #include <regex.h> | ||
42 | #include <string.h> | ||
43 | #include <stdlib.h> | ||
44 | #include <err.h> | ||
45 | //#include <atf-c.h> | ||
46 | |||
47 | |||
48 | static char * | ||
49 | mkstr(const char *str, size_t len) | ||
50 | { | ||
51 | size_t i, slen = strlen(str); | ||
52 | char *p = malloc(slen * len + 1); | ||
53 | if (p == NULL) | ||
54 | err(1, "malloc"); | ||
55 | for (i = 0; i < len; i++) | ||
56 | strlcpy(&p[i * slen], str, slen * len + 1 - (i * slen)); | ||
57 | return p; | ||
58 | } | ||
59 | |||
60 | static char * | ||
61 | concat(const char *d, const char *s) | ||
62 | { | ||
63 | size_t dlen = strlen(d); | ||
64 | size_t slen = strlen(s); | ||
65 | char *p = malloc(dlen + slen + 1); | ||
66 | strlcpy(p, d, dlen + slen + 1); | ||
67 | strlcat(p, s, dlen + slen + 1); | ||
68 | return p; | ||
69 | } | ||
70 | |||
71 | static char * | ||
72 | p0(size_t len) | ||
73 | { | ||
74 | char *d, *s1, *s2; | ||
75 | s1 = mkstr("\\(", len); | ||
76 | s2 = concat(s1, ")"); | ||
77 | free(s1); | ||
78 | d = concat("(", s2); | ||
79 | free(s2); | ||
80 | return d; | ||
81 | } | ||
82 | |||
83 | static char * | ||
84 | p1(size_t len) | ||
85 | { | ||
86 | char *d, *s1, *s2, *s3; | ||
87 | s1 = mkstr("\\(", 60); | ||
88 | s2 = mkstr("(.*)", len); | ||
89 | s3 = concat(s1, s2); | ||
90 | free(s2); | ||
91 | free(s1); | ||
92 | s1 = concat(s3, ")"); | ||
93 | free(s3); | ||
94 | d = concat("(", s1); | ||
95 | free(s1); | ||
96 | return d; | ||
97 | } | ||
98 | |||
99 | static char * | ||
100 | ps(const char *m, const char *s, size_t len) | ||
101 | { | ||
102 | char *d, *s1, *s2, *s3; | ||
103 | s1 = mkstr(m, len); | ||
104 | s2 = mkstr(s, len); | ||
105 | s3 = concat(s1, s2); | ||
106 | free(s2); | ||
107 | free(s1); | ||
108 | d = concat("(.?)", s3); | ||
109 | free(s3); | ||
110 | return d; | ||
111 | } | ||
112 | |||
113 | static char * | ||
114 | p2(size_t len) | ||
115 | { | ||
116 | return ps("((.*){0,255}", ")", len); | ||
117 | } | ||
118 | |||
119 | static char * | ||
120 | p3(size_t len) | ||
121 | { | ||
122 | return ps("(.\\{0,}", ")", len); | ||
123 | } | ||
124 | |||
125 | static char * | ||
126 | p4(size_t len) | ||
127 | { | ||
128 | return ps("((.*){1,255}", ")", len); | ||
129 | } | ||
130 | |||
131 | static char * | ||
132 | p5(size_t len) | ||
133 | { | ||
134 | return ps("(", "){1,100}", len); | ||
135 | } | ||
136 | |||
137 | static char * | ||
138 | p6(size_t len) | ||
139 | { | ||
140 | char *d, *s1, *s2; | ||
141 | s1 = mkstr("(?:(.*)|", len); | ||
142 | s2 = concat(s1, "(.*)"); | ||
143 | free(s1); | ||
144 | s1 = mkstr(")", len); | ||
145 | d = concat(s2, s1); | ||
146 | free(s1); | ||
147 | free(s2); | ||
148 | return d; | ||
149 | } | ||
150 | |||
151 | static char *(*patterns[])(size_t) = { | ||
152 | p0, | ||
153 | p1, | ||
154 | p2, | ||
155 | p3, | ||
156 | p4, | ||
157 | p5, | ||
158 | p6, | ||
159 | }; | ||
160 | |||
161 | int | ||
162 | main(void) | ||
163 | { | ||
164 | regex_t re; | ||
165 | int e, ret = 0; | ||
166 | size_t i; | ||
167 | |||
168 | for (i = 0; i < sizeof(patterns) / sizeof(patterns[0]); i++) { | ||
169 | char *d = (*patterns[i])(9999); | ||
170 | e = regcomp(&re, d, i == 6 ? REG_BASIC : REG_EXTENDED); | ||
171 | free(d); | ||
172 | if (e) { | ||
173 | if (e != REG_ESPACE) { | ||
174 | printf("regcomp returned %d for pattern %zu", e, i); | ||
175 | ret = 1; | ||
176 | } | ||
177 | continue; | ||
178 | } | ||
179 | (void)regexec(&re, "aaaaaaaa", 0, NULL, 0); | ||
180 | regfree(&re); | ||
181 | } | ||
182 | return ret; | ||
183 | } | ||
diff --git a/src/regress/lib/libc/regex/tests b/src/regress/lib/libc/regex/tests deleted file mode 100644 index f3fd9d0e6b..0000000000 --- a/src/regress/lib/libc/regex/tests +++ /dev/null | |||
@@ -1,612 +0,0 @@ | |||
1 | # $OpenBSD: tests,v 1.10 2021/04/02 14:20:57 otto Exp $ | ||
2 | # $NetBSD: tests,v 1.5 1995/04/20 22:40:00 cgd Exp $ | ||
3 | |||
4 | # regular expression test set | ||
5 | # Lines are at least three fields, separated by one or more tabs. "" stands | ||
6 | # for an empty field. First field is an RE. Second field is flags. If | ||
7 | # C flag given, regcomp() is expected to fail, and the third field is the | ||
8 | # error name (minus the leading REG_). | ||
9 | # | ||
10 | # Otherwise it is expected to succeed, and the third field is the string to | ||
11 | # try matching it against. If there is no fourth field, the match is | ||
12 | # expected to fail. If there is a fourth field, it is the substring that | ||
13 | # the RE is expected to match. If there is a fifth field, it is a comma- | ||
14 | # separated list of what the subexpressions should match, with - indicating | ||
15 | # no match for that one. In both the fourth and fifth fields, a (sub)field | ||
16 | # starting with @ indicates that the (sub)expression is expected to match | ||
17 | # a null string followed by the stuff after the @; this provides a way to | ||
18 | # test where null strings match. The character `N' in REs and strings | ||
19 | # is newline, `S' is space, `T' is tab, `Z' is NUL. | ||
20 | # | ||
21 | # The full list of flags: | ||
22 | # - placeholder, does nothing | ||
23 | # b RE is a BRE, not an ERE | ||
24 | # & try it as both an ERE and a BRE | ||
25 | # C regcomp() error expected, third field is error name | ||
26 | # i REG_ICASE | ||
27 | # m ("mundane") REG_NOSPEC | ||
28 | # s REG_NOSUB (not really testable) | ||
29 | # n REG_NEWLINE | ||
30 | # ^ REG_NOTBOL | ||
31 | # $ REG_NOTEOL | ||
32 | # # REG_STARTEND (see below) | ||
33 | # p REG_PEND | ||
34 | # | ||
35 | # For REG_STARTEND, the start/end offsets are those of the substring | ||
36 | # enclosed in (). | ||
37 | |||
38 | # basics | ||
39 | a & a a | ||
40 | abc & abc abc | ||
41 | abc|de - abc abc | ||
42 | a|b|c - abc a | ||
43 | |||
44 | # parentheses and perversions thereof | ||
45 | a(b)c - abc abc | ||
46 | a\(b\)c b abc abc | ||
47 | a( C EPAREN | ||
48 | a( b a( a( | ||
49 | a\( - a( a( | ||
50 | a\( bC EPAREN | ||
51 | a\(b bC EPAREN | ||
52 | a(b C EPAREN | ||
53 | a(b b a(b a(b | ||
54 | # gag me with a right parenthesis -- 1003.2 goofed here (my fault, partly) | ||
55 | a) - a) a) | ||
56 | ) - ) ) | ||
57 | # end gagging (in a just world, those *should* give EPAREN) | ||
58 | a) b a) a) | ||
59 | a\) bC EPAREN | ||
60 | \) bC EPAREN | ||
61 | a()b - ab ab | ||
62 | a\(\)b b ab ab | ||
63 | |||
64 | # anchoring and REG_NEWLINE | ||
65 | ^abc$ & abc abc | ||
66 | ^b & abc | ||
67 | a^b - a^b | ||
68 | a^b b a^b a^b | ||
69 | a$b - a$b | ||
70 | a$b b a$b a$b | ||
71 | ^ & abc @abc | ||
72 | $ & abc @ | ||
73 | ^$ & "" @ | ||
74 | $^ - "" @ | ||
75 | \($\)\(^\) b "" @ | ||
76 | # stop retching, those are legitimate (although disgusting) | ||
77 | ^^ - "" @ | ||
78 | $$ - "" @ | ||
79 | b$ & abNc | ||
80 | b$ &n abNc b | ||
81 | ^b & aNbNc | ||
82 | b$ & aNbNc | ||
83 | ^a &n aNb a | ||
84 | ^b &n abc | ||
85 | ^b$ &n aNbNc b | ||
86 | ^$ &n aNNb @Nb | ||
87 | ^$ n abc | ||
88 | ^$ n abcN @ | ||
89 | $^ n aNNb @Nb | ||
90 | \($\)\(^\) bn aNNb @Nb | ||
91 | ^^ n^ aNNb @Nb | ||
92 | $$ n aNNb @NN | ||
93 | ^a &^ a | ||
94 | a$ &$ a | ||
95 | ^b &^ abc | ||
96 | ^b &^ aNb | ||
97 | ^a &^n aNb | ||
98 | ^b &^n abc | ||
99 | ^b &^n aNb b | ||
100 | a$ &$n bNa | ||
101 | b$ &$n bNa b | ||
102 | a*(^b$)c* - b b | ||
103 | a*\(^b$\)c* b b b | ||
104 | |||
105 | # certain syntax errors and non-errors | ||
106 | | C EMPTY | ||
107 | | b | | | ||
108 | * C BADRPT | ||
109 | * b * * | ||
110 | + C BADRPT | ||
111 | ? C BADRPT | ||
112 | "" &C EMPTY | ||
113 | () - abc @abc | ||
114 | \(\) b abc @abc | ||
115 | a||b C EMPTY | ||
116 | |ab C EMPTY | ||
117 | ab| C EMPTY | ||
118 | (|a)b C EMPTY | ||
119 | (a|)b C EMPTY | ||
120 | (*a) C BADRPT | ||
121 | (+a) C BADRPT | ||
122 | (?a) C BADRPT | ||
123 | ({1}a) C BADRPT | ||
124 | \(\{1\}a\) bC BADRPT | ||
125 | (a|*b) C BADRPT | ||
126 | (a|+b) C BADRPT | ||
127 | (a|?b) C BADRPT | ||
128 | (a|{1}b) C BADRPT | ||
129 | ^* C BADRPT | ||
130 | ^* b * * | ||
131 | ^+ C BADRPT | ||
132 | ^? C BADRPT | ||
133 | ^{1} C BADRPT | ||
134 | ^\{1\} bC BADRPT | ||
135 | |||
136 | # metacharacters, backslashes | ||
137 | a.c & abc abc | ||
138 | a[bc]d & abd abd | ||
139 | a\*c & a*c a*c | ||
140 | a\\b & a\b a\b | ||
141 | a\\\*b & a\*b a\*b | ||
142 | a\bc & abc abc | ||
143 | a\ &C EESCAPE | ||
144 | a\\bc & a\bc a\bc | ||
145 | \{ bC BADRPT | ||
146 | a\[b & a[b a[b | ||
147 | a[b &C EBRACK | ||
148 | # trailing $ is a peculiar special case for the BRE code | ||
149 | a$ & a a | ||
150 | a$ & a$ | ||
151 | a\$ & a | ||
152 | a\$ & a$ a$ | ||
153 | a\\$ & a | ||
154 | a\\$ & a$ | ||
155 | a\\$ & a\$ | ||
156 | a\\$ & a\ a\ | ||
157 | |||
158 | # back references, ugh | ||
159 | a\(b\)\2c bC ESUBREG | ||
160 | a\(b\1\)c bC ESUBREG | ||
161 | a\(b*\)c\1d b abbcbbd abbcbbd bb | ||
162 | a\(b*\)c\1d b abbcbd | ||
163 | a\(b*\)c\1d b abbcbbbd | ||
164 | ^\(.\)\1 b abc | ||
165 | a\([bc]\)\1d b abcdabbd abbd b | ||
166 | a\(\([bc]\)\2\)*d b abbccd abbccd | ||
167 | a\(\([bc]\)\2\)*d b abbcbd | ||
168 | # actually, this next one probably ought to fail, but the spec is unclear | ||
169 | a\(\(b\)*\2\)*d b abbbd abbbd | ||
170 | # here is a case that no NFA implementation does right | ||
171 | \(ab*\)[ab]*\1 b ababaaa ababaaa a | ||
172 | # check out normal matching in the presence of back refs | ||
173 | \(a\)\1bcd b aabcd aabcd | ||
174 | \(a\)\1bc*d b aabcd aabcd | ||
175 | \(a\)\1bc*d b aabd aabd | ||
176 | \(a\)\1bc*d b aabcccd aabcccd | ||
177 | \(a\)\1bc*[ce]d b aabcccd aabcccd | ||
178 | ^\(a\)\1b\(c\)*cd$ b aabcccd aabcccd | ||
179 | \(b*\)\(a*\1\)* b ab a | ||
180 | \([^_]*\)\(_*\1\)* b foo_foo_bar_bar_bar_baz foo_foo foo,_foo | ||
181 | \([^_]*\)\(_*\1\)* b bar_bar_bar_baz bar_bar_bar bar,_bar | ||
182 | \([^_]*\)\(_*\1\)* b foo_bar_baz foo foo | ||
183 | \(.*\)\1 b "" "" | ||
184 | \(.*\)\1 b a "" | ||
185 | \(.*\)\1 b aa aa | ||
186 | \(.*\)\1 b aaa aa | ||
187 | \(.*\)\1 b aaaa aaaa | ||
188 | \([^_]*\)\1 b "" "" | ||
189 | \([^_]*\)\1 b a "" | ||
190 | \([^_]*\)\1 b aa aa | ||
191 | \([^_]*\)\1 b aaa aa | ||
192 | \([^_]*\)\1 b aaaa aaaa | ||
193 | foo\(.*\)bar\1 b foolbarl foolbarl l | ||
194 | foo\(.*\)bar\1 b foobar foobar "" | ||
195 | \(\(.\)b\)*\1 b aba | ||
196 | \(\(.\)b\)*\1 b abba | ||
197 | \(\(.\)b\)*\1 b abbba | ||
198 | \(\(.\)b\)*\1 b abbbba bbbb bb,b | ||
199 | \(\(.\)b\)*\1 b abbbbba abbbbb bb,b | ||
200 | \(\(.\)b\)*\1 b abbbbbba abbbbb bb,b | ||
201 | \(\(.\)b\)*\1 b abbbbbbbbbbbbbba abbbbbbbbbbbbb bb,b | ||
202 | \(\(.\)b\)*\1 b abbbbbbbbbbbbbbba abbbbbbbbbbbbbbb bb,b | ||
203 | # these used to segfault, buffer underflow in engine.c, backref() | ||
204 | \(^a\)*\(b.\)\2 b^ sbxbxe bxbx -,bx | ||
205 | \([[:<:]]a\)*\(b.\)\2 b^ sbxbxe bxbx -,bx | ||
206 | |||
207 | # ordinary repetitions | ||
208 | ab*c & abc abc | ||
209 | ab+c - abc abc | ||
210 | ab?c - abc abc | ||
211 | a\(*\)b b a*b a*b | ||
212 | a\(**\)b b ab ab | ||
213 | a\(***\)b bC BADRPT | ||
214 | *a b *a *a | ||
215 | **a b a a | ||
216 | ***a bC BADRPT | ||
217 | |||
218 | # the dreaded bounded repetitions | ||
219 | { & { { | ||
220 | {abc & {abc {abc | ||
221 | {1 C BADRPT | ||
222 | {1} C BADRPT | ||
223 | a{b & a{b a{b | ||
224 | a{1}b - ab ab | ||
225 | a\{1\}b b ab ab | ||
226 | a{1,}b - ab ab | ||
227 | a\{1,\}b b ab ab | ||
228 | a{1,2}b - aab aab | ||
229 | a\{1,2\}b b aab aab | ||
230 | a{1 C EBRACE | ||
231 | a\{1 bC EBRACE | ||
232 | a{1a C EBRACE | ||
233 | a\{1a bC EBRACE | ||
234 | a{1a} C BADBR | ||
235 | a\{1a\} bC BADBR | ||
236 | a{,2} - a{,2} a{,2} | ||
237 | a\{,2\} bC BADBR | ||
238 | a{,} - a{,} a{,} | ||
239 | a\{,\} bC BADBR | ||
240 | a{1,x} C BADBR | ||
241 | a\{1,x\} bC BADBR | ||
242 | a{1,x C EBRACE | ||
243 | a\{1,x bC EBRACE | ||
244 | a{300} C BADBR | ||
245 | a\{300\} bC BADBR | ||
246 | a{1,0} C BADBR | ||
247 | a\{1,0\} bC BADBR | ||
248 | ab{0,0}c - abcac ac | ||
249 | ab\{0,0\}c b abcac ac | ||
250 | ab{0,1}c - abcac abc | ||
251 | ab\{0,1\}c b abcac abc | ||
252 | ab{0,3}c - abbcac abbc | ||
253 | ab\{0,3\}c b abbcac abbc | ||
254 | ab{1,1}c - acabc abc | ||
255 | ab\{1,1\}c b acabc abc | ||
256 | ab{1,3}c - acabc abc | ||
257 | ab\{1,3\}c b acabc abc | ||
258 | ab{2,2}c - abcabbc abbc | ||
259 | ab\{2,2\}c b abcabbc abbc | ||
260 | ab{2,4}c - abcabbc abbc | ||
261 | ab\{2,4\}c b abcabbc abbc | ||
262 | ((a{1,10}){1,10}){1,10} - a a a,a | ||
263 | |||
264 | # multiple repetitions | ||
265 | a** &C BADRPT | ||
266 | a++ C BADRPT | ||
267 | a?? C BADRPT | ||
268 | a*+ C BADRPT | ||
269 | a*? C BADRPT | ||
270 | a+* C BADRPT | ||
271 | a+? C BADRPT | ||
272 | a?* C BADRPT | ||
273 | a?+ C BADRPT | ||
274 | a{1}{1} C BADRPT | ||
275 | a*{1} C BADRPT | ||
276 | a+{1} C BADRPT | ||
277 | a?{1} C BADRPT | ||
278 | a{1}* C BADRPT | ||
279 | a{1}+ C BADRPT | ||
280 | a{1}? C BADRPT | ||
281 | a*{b} - a{b} a{b} | ||
282 | a\{1\}\{1\} bC BADRPT | ||
283 | a*\{1\} bC BADRPT | ||
284 | a\{1\}* bC BADRPT | ||
285 | |||
286 | # brackets, and numerous perversions thereof | ||
287 | a[b]c & abc abc | ||
288 | a[ab]c & abc abc | ||
289 | a[^ab]c & adc adc | ||
290 | a[]b]c & a]c a]c | ||
291 | a[[b]c & a[c a[c | ||
292 | a[-b]c & a-c a-c | ||
293 | a[^]b]c & adc adc | ||
294 | a[^-b]c & adc adc | ||
295 | a[b-]c & a-c a-c | ||
296 | a[b &C EBRACK | ||
297 | a[] &C EBRACK | ||
298 | a[1-3]c & a2c a2c | ||
299 | a[3-1]c &C ERANGE | ||
300 | a[1-3-5]c &C ERANGE | ||
301 | a[[.-.]--]c & a-c a-c | ||
302 | a[1- &C ERANGE | ||
303 | a[[. &C EBRACK | ||
304 | a[[.x &C EBRACK | ||
305 | a[[.x. &C EBRACK | ||
306 | a[[.x.] &C EBRACK | ||
307 | a[[.x.]] & ax ax | ||
308 | a[[.x,.]] &C ECOLLATE | ||
309 | a[[.one.]]b & a1b a1b | ||
310 | a[[.notdef.]]b &C ECOLLATE | ||
311 | a[[.].]]b & a]b a]b | ||
312 | a[[:alpha:]]c & abc abc | ||
313 | a[[:notdef:]]c &C ECTYPE | ||
314 | a[[: &C EBRACK | ||
315 | a[[:alpha &C EBRACK | ||
316 | a[[:alpha:] &C EBRACK | ||
317 | a[[:alpha,:] &C ECTYPE | ||
318 | a[[:]:]]b &C ECTYPE | ||
319 | a[[:-:]]b &C ECTYPE | ||
320 | a[[:alph:]] &C ECTYPE | ||
321 | a[[:alphabet:]] &C ECTYPE | ||
322 | [[:alnum:]]+ - -%@a0X- a0X | ||
323 | [[:alpha:]]+ - -%@aX0- aX | ||
324 | [[:blank:]]+ - aSSTb SST | ||
325 | [[:cntrl:]]+ - aNTb NT | ||
326 | [[:digit:]]+ - a019b 019 | ||
327 | [[:graph:]]+ - Sa%bS a%b | ||
328 | [[:lower:]]+ - AabC ab | ||
329 | [[:print:]]+ - NaSbN aSb | ||
330 | [[:punct:]]+ - S%-&T %-& | ||
331 | [[:space:]]+ - aSNTb SNT | ||
332 | [[:upper:]]+ - aBCd BC | ||
333 | [[:xdigit:]]+ - p0f3Cq 0f3C | ||
334 | a[[=b=]]c & abc abc | ||
335 | a[[= &C EBRACK | ||
336 | a[[=b &C EBRACK | ||
337 | a[[=b= &C EBRACK | ||
338 | a[[=b=] &C EBRACK | ||
339 | a[[=b,=]] &C ECOLLATE | ||
340 | a[[=one=]]b & a1b a1b | ||
341 | |||
342 | # complexities | ||
343 | a(((b)))c - abc abc | ||
344 | a(b|(c))d - abd abd | ||
345 | a(b*|c)d - abbd abbd | ||
346 | # just gotta have one DFA-buster, of course | ||
347 | a[ab]{20} - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab | ||
348 | # and an inline expansion in case somebody gets tricky | ||
349 | a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab] - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab | ||
350 | # and in case somebody just slips in an NFA... | ||
351 | a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab](wee|week)(knights|night) - aaaaabaaaabaaaabaaaabweeknights aaaaabaaaabaaaabaaaabweeknights | ||
352 | # fish for anomalies as the number of states passes 32 | ||
353 | 12345678901234567890123456789 - a12345678901234567890123456789b 12345678901234567890123456789 | ||
354 | 123456789012345678901234567890 - a123456789012345678901234567890b 123456789012345678901234567890 | ||
355 | 1234567890123456789012345678901 - a1234567890123456789012345678901b 1234567890123456789012345678901 | ||
356 | 12345678901234567890123456789012 - a12345678901234567890123456789012b 12345678901234567890123456789012 | ||
357 | 123456789012345678901234567890123 - a123456789012345678901234567890123b 123456789012345678901234567890123 | ||
358 | # and one really big one, beyond any plausible word width | ||
359 | 1234567890123456789012345678901234567890123456789012345678901234567890 - a1234567890123456789012345678901234567890123456789012345678901234567890b 1234567890123456789012345678901234567890123456789012345678901234567890 | ||
360 | # fish for problems as brackets go past 8 | ||
361 | [ab][cd][ef][gh][ij][kl][mn] - xacegikmoq acegikm | ||
362 | [ab][cd][ef][gh][ij][kl][mn][op] - xacegikmoq acegikmo | ||
363 | [ab][cd][ef][gh][ij][kl][mn][op][qr] - xacegikmoqy acegikmoq | ||
364 | [ab][cd][ef][gh][ij][kl][mn][op][q] - xacegikmoqy acegikmoq | ||
365 | |||
366 | # subtleties of matching | ||
367 | abc & xabcy abc | ||
368 | a\(b\)?c\1d b acd | ||
369 | aBc i Abc Abc | ||
370 | a[Bc]*d i abBCcd abBCcd | ||
371 | 0[[:upper:]]1 &i 0a1 0a1 | ||
372 | 0[[:lower:]]1 &i 0A1 0A1 | ||
373 | a[^b]c &i abc | ||
374 | a[^b]c &i aBc | ||
375 | a[^b]c &i adc adc | ||
376 | [a]b[c] - abc abc | ||
377 | [a]b[a] - aba aba | ||
378 | [abc]b[abc] - abc abc | ||
379 | [abc]b[abd] - abd abd | ||
380 | a(b?c)+d - accd accd | ||
381 | (wee|week)(knights|night) - weeknights weeknights | ||
382 | (we|wee|week|frob)(knights|night|day) - weeknights weeknights | ||
383 | a[bc]d - xyzaaabcaababdacd abd | ||
384 | a[ab]c - aaabc abc | ||
385 | abc s abc abc | ||
386 | a* & b @b | ||
387 | |||
388 | # Let's have some fun -- try to match a C comment. | ||
389 | # first the obvious, which looks okay at first glance... | ||
390 | /\*.*\*/ - /*x*/ /*x*/ | ||
391 | # but... | ||
392 | /\*.*\*/ - /*x*/y/*z*/ /*x*/y/*z*/ | ||
393 | # okay, we must not match */ inside; try to do that... | ||
394 | /\*([^*]|\*[^/])*\*/ - /*x*/ /*x*/ | ||
395 | /\*([^*]|\*[^/])*\*/ - /*x*/y/*z*/ /*x*/ | ||
396 | # but... | ||
397 | /\*([^*]|\*[^/])*\*/ - /*x**/y/*z*/ /*x**/y/*z*/ | ||
398 | # and a still fancier version, which does it right (I think)... | ||
399 | /\*([^*]|\*+[^*/])*\*+/ - /*x*/ /*x*/ | ||
400 | /\*([^*]|\*+[^*/])*\*+/ - /*x*/y/*z*/ /*x*/ | ||
401 | /\*([^*]|\*+[^*/])*\*+/ - /*x**/y/*z*/ /*x**/ | ||
402 | /\*([^*]|\*+[^*/])*\*+/ - /*x****/y/*z*/ /*x****/ | ||
403 | /\*([^*]|\*+[^*/])*\*+/ - /*x**x*/y/*z*/ /*x**x*/ | ||
404 | /\*([^*]|\*+[^*/])*\*+/ - /*x***x/y/*z*/ /*x***x/y/*z*/ | ||
405 | |||
406 | # subexpressions | ||
407 | a(b)(c)d - abcd abcd b,c | ||
408 | a(((b)))c - abc abc b,b,b | ||
409 | a(b|(c))d - abd abd b,- | ||
410 | a(b*|c|e)d - abbd abbd bb | ||
411 | a(b*|c|e)d - acd acd c | ||
412 | a(b*|c|e)d - ad ad @d | ||
413 | a(b?)c - abc abc b | ||
414 | a(b?)c - ac ac @c | ||
415 | a(b+)c - abc abc b | ||
416 | a(b+)c - abbbc abbbc bbb | ||
417 | a(b*)c - ac ac @c | ||
418 | (a|ab)(bc([de]+)f|cde) - abcdef abcdef a,bcdef,de | ||
419 | # the regression tester only asks for 9 subexpressions | ||
420 | a(b)(c)(d)(e)(f)(g)(h)(i)(j)k - abcdefghijk abcdefghijk b,c,d,e,f,g,h,i,j | ||
421 | a(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)l - abcdefghijkl abcdefghijkl b,c,d,e,f,g,h,i,j,k | ||
422 | a([bc]?)c - abc abc b | ||
423 | a([bc]?)c - ac ac @c | ||
424 | a([bc]+)c - abc abc b | ||
425 | a([bc]+)c - abcc abcc bc | ||
426 | a([bc]+)bc - abcbc abcbc bc | ||
427 | a(bb+|b)b - abb abb b | ||
428 | a(bbb+|bb+|b)b - abb abb b | ||
429 | a(bbb+|bb+|b)b - abbb abbb bb | ||
430 | a(bbb+|bb+|b)bb - abbb abbb b | ||
431 | (.*).* - abcdef abcdef abcdef | ||
432 | (a*)* - bc @b @b | ||
433 | |||
434 | # do we get the right subexpression when it is used more than once? | ||
435 | a(b|c)*d - ad ad - | ||
436 | a(b|c)*d - abcd abcd c | ||
437 | a(b|c)+d - abd abd b | ||
438 | a(b|c)+d - abcd abcd c | ||
439 | a(b|c?)+d - ad ad @d | ||
440 | a(b|c?)+d - abcd abcd @d | ||
441 | a(b|c){0,0}d - ad ad - | ||
442 | a(b|c){0,1}d - ad ad - | ||
443 | a(b|c){0,1}d - abd abd b | ||
444 | a(b|c){0,2}d - ad ad - | ||
445 | a(b|c){0,2}d - abcd abcd c | ||
446 | a(b|c){0,}d - ad ad - | ||
447 | a(b|c){0,}d - abcd abcd c | ||
448 | a(b|c){1,1}d - abd abd b | ||
449 | a(b|c){1,1}d - acd acd c | ||
450 | a(b|c){1,2}d - abd abd b | ||
451 | a(b|c){1,2}d - abcd abcd c | ||
452 | a(b|c){1,}d - abd abd b | ||
453 | a(b|c){1,}d - abcd abcd c | ||
454 | a(b|c){2,2}d - acbd acbd b | ||
455 | a(b|c){2,2}d - abcd abcd c | ||
456 | a(b|c){2,4}d - abcd abcd c | ||
457 | a(b|c){2,4}d - abcbd abcbd b | ||
458 | a(b|c){2,4}d - abcbcd abcbcd c | ||
459 | a(b|c){2,}d - abcd abcd c | ||
460 | a(b|c){2,}d - abcbd abcbd b | ||
461 | a(b+|((c)*))+d - abd abd @d,@d,- | ||
462 | a(b+|((c)*))+d - abcd abcd @d,@d,- | ||
463 | |||
464 | # check out the STARTEND option | ||
465 | ^[abc] &# a(b)c b | ||
466 | ^[abc] &# a(xb)c | ||
467 | ^[abc] &# aN(b)c b | ||
468 | ^[abc] &n# a(b)c b | ||
469 | ^[abc] &n# a(xb)c | ||
470 | ^[abc] &n# aN(b)c b | ||
471 | ^[abc] &^# a(b)c | ||
472 | ^[abc] &^# a(xb)c | ||
473 | ^[abc] &^# aN(b)c | ||
474 | ^[abc] &n^# a(b)c | ||
475 | ^[abc] &n^# a(xb)c | ||
476 | ^[abc] &n^# aN(b)c b | ||
477 | [abc] &# a(d)c | ||
478 | [abc] &# a(bc)d b | ||
479 | [abc] &# a(dc)d c | ||
480 | . &# a()c | ||
481 | b.*c &# b(bc)c bc | ||
482 | b.* &# b(bc)c bc | ||
483 | .*c &# b(bc)c bc | ||
484 | |||
485 | # plain strings, with the NOSPEC flag | ||
486 | abc m abc abc | ||
487 | abc m xabcy abc | ||
488 | abc m xyz | ||
489 | a*b m aba*b a*b | ||
490 | a*b m ab | ||
491 | "" mC EMPTY | ||
492 | |||
493 | # cases involving NULs | ||
494 | aZb & a a | ||
495 | aZb &p a | ||
496 | aZb &p# (aZb) aZb | ||
497 | aZ*b &p# (ab) ab | ||
498 | a.b &# (aZb) aZb | ||
499 | a.* &# (aZb)c aZb | ||
500 | |||
501 | # word boundaries (ick) | ||
502 | [[:<:]]a & a a | ||
503 | \<a & a a | ||
504 | [[:<:]]a & ba | ||
505 | \<a & ba | ||
506 | [[:<:]]a & -a a | ||
507 | \<a & -a a | ||
508 | [[:<:]]a & Na a | ||
509 | \<a & Na a | ||
510 | [[:<:]]a &n a a | ||
511 | \<a &n a a | ||
512 | [[:<:]]a &n ba | ||
513 | \<a &n ba | ||
514 | [[:<:]]a &n -a a | ||
515 | \<a &n -a a | ||
516 | [[:<:]]a &n Na a | ||
517 | \<a &n Na a | ||
518 | [[:<:]]a &^ a | ||
519 | \<a &^ a | ||
520 | [[:<:]]a &^ ba | ||
521 | \<a &^ ba | ||
522 | [[:<:]]a &^ -a a | ||
523 | \<a &^ -a a | ||
524 | [[:<:]]a &^ Na a | ||
525 | \<a &^ Na a | ||
526 | [[:<:]]a &n^ a | ||
527 | \<a &n^ a | ||
528 | [[:<:]]a &n^ ba | ||
529 | \<a &n^ ba | ||
530 | [[:<:]]a &n^ -a a | ||
531 | \<a &n^ -a a | ||
532 | [[:<:]]a &n^ Na a | ||
533 | \<a &n^ Na a | ||
534 | [[:<:]]b &# a(b)c b | ||
535 | \<b &# a(b)c b | ||
536 | [[:<:]]b &# a(xb)c | ||
537 | \<b &# a(xb)c | ||
538 | [[:<:]]b &# -(b)c b | ||
539 | \<b &# -(b)c b | ||
540 | [[:<:]]b &# aN(b)c b | ||
541 | \<b &# aN(b)c b | ||
542 | [[:<:]]b &n# a(b)c b | ||
543 | \<b &n# a(b)c b | ||
544 | [[:<:]]b &n# a(xb)c | ||
545 | \<b &n# a(xb)c | ||
546 | [[:<:]]b &n# -(b)c b | ||
547 | \<b &n# -(b)c b | ||
548 | [[:<:]]b &n# aN(b)c b | ||
549 | \<b &n# aN(b)c b | ||
550 | [[:<:]]b &^# a(b)c | ||
551 | \<b &^# a(b)c | ||
552 | [[:<:]]b &^# a(xb)c | ||
553 | \<b &^# a(xb)c | ||
554 | [[:<:]]b &^# -(b)c b | ||
555 | \<b &^# -(b)c b | ||
556 | [[:<:]]b &^# aN(b)c b | ||
557 | \<b &^# aN(b)c b | ||
558 | [[:<:]]b &n^# a(b)c | ||
559 | \<b &n^# a(b)c | ||
560 | [[:<:]]b &n^# a(xb)c | ||
561 | \<b &n^# a(xb)c | ||
562 | [[:<:]]b &n^# -(b)c b | ||
563 | \<b &n^# -(b)c b | ||
564 | [[:<:]]b &n^# aN(b)c b | ||
565 | \<b &n^# aN(b)c b | ||
566 | a[[:>:]] & a a | ||
567 | a\> & a a | ||
568 | a[[:>:]] & ab | ||
569 | a\> & ab | ||
570 | a[[:>:]] & a- a | ||
571 | a\> & a- a | ||
572 | [[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc abc | ||
573 | \<a.c\> & axcd-dayc-dazce-abc abc | ||
574 | [[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc-q abc | ||
575 | \<a.c\> & axcd-dayc-dazce-abc-q abc | ||
576 | [[:<:]]a.c[[:>:]] & axc-dayc-dazce-abc axc | ||
577 | \<a.c\> & axc-dayc-dazce-abc axc | ||
578 | [[:<:]]b.c[[:>:]] & a_bxc-byc_d-bzc-q bzc | ||
579 | \<b.c\> & a_bxc-byc_d-bzc-q bzc | ||
580 | [[:<:]].x..[[:>:]] & y_xa_-_xb_y-_xc_-axdc _xc_ | ||
581 | \<.x..\> & y_xa_-_xb_y-_xc_-axdc _xc_ | ||
582 | [[:<:]]a_b[[:>:]] & x_a_b | ||
583 | \<a_b\> & x_a_b | ||
584 | |||
585 | # past problems, and suspected problems | ||
586 | (A[1])|(A[2])|(A[3])|(A[4])|(A[5])|(A[6])|(A[7])|(A[8])|(A[9])|(A[A]) - A1 A1 | ||
587 | abcdefghijklmnop i abcdefghijklmnop abcdefghijklmnop | ||
588 | abcdefghijklmnopqrstuv i abcdefghijklmnopqrstuv abcdefghijklmnopqrstuv | ||
589 | (ALAK)|(ALT[AB])|(CC[123]1)|(CM[123]1)|(GAMC)|(LC[23][EO ])|(SEM[1234])|(SL[ES][12])|(SLWW)|(SLF )|(SLDT)|(VWH[12])|(WH[34][EW])|(WP1[ESN]) - CC11 CC11 | ||
590 | CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a - CC11 CC11 | ||
591 | Char \([a-z0-9_]*\)\[.* b Char xyz[k Char xyz[k xyz | ||
592 | a?b - ab ab | ||
593 | -\{0,1\}[0-9]*$ b -5 -5 | ||
594 | |||
595 | # FreeBSD PR 130504 | ||
596 | (.|())(b) - ab ab | ||
597 | (()|.)(b) - ab ab | ||
598 | |||
599 | # Some BRE cases where \{0,\} makes a backref go wrong, as reported by Michael Paoli | ||
600 | Y*\(x\)\1 b YYxx YYxx | ||
601 | Y\{2,\}\(x\)\1 b YYxx YYxx | ||
602 | # Fails currently | ||
603 | #Y\{0,\}\(x\)\1 b YYxx YYxx | ||
604 | Y\{0,\}\(x\) b YYxx YYx | ||
605 | Y\{2,\}x\{1,\} b YYxx YYxx | ||
606 | Y\{2,\}x\{0,\}z b YYxxz YYxxz | ||
607 | Y\{0,\}x\{0,\}z b YYxxz YYxxz | ||
608 | Y\{2,\}\(xy\)\1 b YYxyxy YYxyxy | ||
609 | # Fails currently | ||
610 | #Y\{0,\}\(xy\)\1 b YYxyxy YYxyxy | ||
611 | Y*\(xy\)\1 b YYxyxy YYxyxy | ||
612 | Y\{0,\}\(xy\)xy b YYxyxy YYxyxy | ||