summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/regex
diff options
context:
space:
mode:
Diffstat (limited to 'src/regress/lib/libc/regex')
-rw-r--r--src/regress/lib/libc/regex/Makefile24
-rw-r--r--src/regress/lib/libc/regex/debug.c245
-rw-r--r--src/regress/lib/libc/regex/debug.ih17
-rw-r--r--src/regress/lib/libc/regex/main.c516
-rw-r--r--src/regress/lib/libc/regex/main.ih22
-rw-r--r--src/regress/lib/libc/regex/split.c317
-rw-r--r--src/regress/lib/libc/regex/t_exhaust.c186
-rw-r--r--src/regress/lib/libc/regex/tests503
8 files changed, 0 insertions, 1830 deletions
diff --git a/src/regress/lib/libc/regex/Makefile b/src/regress/lib/libc/regex/Makefile
deleted file mode 100644
index 6b646a46ac..0000000000
--- a/src/regress/lib/libc/regex/Makefile
+++ /dev/null
@@ -1,24 +0,0 @@
1# $OpenBSD: Makefile,v 1.8 2011/11/05 15:07:12 otto Exp $
2# $NetBSD: Makefile,v 1.2 1995/02/16 19:38:45 cgd Exp $
3
4PROG= re
5SRCS= main.c split.c debug.c regcomp.c regerror.c regexec.c regfree.c
6.PATH: ${.CURDIR}/../../../../lib/libc/regex
7CLEANFILES += t_exhaust
8
9CFLAGS+= -I${.CURDIR}/../../../../lib/libc/regex -DREDEBUG -DPOSIX_MISTAKE
10
11TESTS= ${.CURDIR}/tests
12
13REGRESS_TARGETS=do-reg do-reg-long do-reg-backref do-t_exhaust
14
15do-reg: ${PROG}
16 ./re < ${TESTS}
17do-reg-long: ${PROG}
18 ./re -el < ${TESTS}
19do-reg-backref: ${PROG}
20 ./re -er < ${TESTS}
21do-t_exhaust: t_exhaust
22 ./t_exhaust
23
24.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 11129e7249..0000000000
--- a/src/regress/lib/libc/regex/debug.c
+++ /dev/null
@@ -1,245 +0,0 @@
1/* $OpenBSD: debug.c,v 1.4 2003/07/31 21:48:03 deraadt 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 */
20void
21regprint(r, d)
22regex_t *r;
23FILE *d;
24{
25 register struct re_guts *g = r->re_g;
26 register int i;
27 register int c;
28 register int last;
29 int nincat[NC];
30
31 fprintf(d, "%ld states, %d categories", (long)g->nstates,
32 g->ncategories);
33 fprintf(d, ", first %ld last %ld", (long)g->firststate,
34 (long)g->laststate);
35 if (g->iflags&USEBOL)
36 fprintf(d, ", USEBOL");
37 if (g->iflags&USEEOL)
38 fprintf(d, ", USEEOL");
39 if (g->iflags&BAD)
40 fprintf(d, ", BAD");
41 if (g->nsub > 0)
42 fprintf(d, ", nsub=%ld", (long)g->nsub);
43 if (g->must != NULL)
44 fprintf(d, ", must(%ld) `%*s'", (long)g->mlen, (int)g->mlen,
45 g->must);
46 if (g->backrefs)
47 fprintf(d, ", backrefs");
48 if (g->nplus > 0)
49 fprintf(d, ", nplus %ld", (long)g->nplus);
50 fprintf(d, "\n");
51 s_print(g, d);
52 for (i = 0; i < g->ncategories; i++) {
53 nincat[i] = 0;
54 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
55 if (g->categories[c] == i)
56 nincat[i]++;
57 }
58 fprintf(d, "cc0#%d", nincat[0]);
59 for (i = 1; i < g->ncategories; i++)
60 if (nincat[i] == 1) {
61 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
62 if (g->categories[c] == i)
63 break;
64 fprintf(d, ", %d=%s", i, regchar(c));
65 }
66 fprintf(d, "\n");
67 for (i = 1; i < g->ncategories; i++)
68 if (nincat[i] != 1) {
69 fprintf(d, "cc%d\t", i);
70 last = -1;
71 for (c = CHAR_MIN; c <= CHAR_MAX+1; c++) /* +1 does flush */
72 if (c <= CHAR_MAX && g->categories[c] == i) {
73 if (last < 0) {
74 fprintf(d, "%s", regchar(c));
75 last = c;
76 }
77 } else {
78 if (last >= 0) {
79 if (last != c-1)
80 fprintf(d, "-%s",
81 regchar(c-1));
82 last = -1;
83 }
84 }
85 fprintf(d, "\n");
86 }
87}
88
89/*
90 - s_print - print the strip for debugging
91 == static void s_print(register struct re_guts *g, FILE *d);
92 */
93static void
94s_print(g, d)
95register struct re_guts *g;
96FILE *d;
97{
98 register sop *s;
99 register cset *cs;
100 register int i;
101 register int done = 0;
102 register sop opnd;
103 register int col = 0;
104 register int last;
105 register sopno offset = 2;
106# define GAP() { if (offset % 5 == 0) { \
107 if (col > 40) { \
108 fprintf(d, "\n\t"); \
109 col = 0; \
110 } else { \
111 fprintf(d, " "); \
112 col++; \
113 } \
114 } else \
115 col++; \
116 offset++; \
117 }
118
119 if (OP(g->strip[0]) != OEND)
120 fprintf(d, "missing initial OEND!\n");
121 for (s = &g->strip[1]; !done; s++) {
122 opnd = OPND(*s);
123 switch (OP(*s)) {
124 case OEND:
125 fprintf(d, "\n");
126 done = 1;
127 break;
128 case OCHAR:
129 if (strchr("\\|()^$.[+*?{}!<> ", (char)opnd) != NULL)
130 fprintf(d, "\\%c", (char)opnd);
131 else
132 fprintf(d, "%s", regchar((char)opnd));
133 break;
134 case OBOL:
135 fprintf(d, "^");
136 break;
137 case OEOL:
138 fprintf(d, "$");
139 break;
140 case OBOW:
141 fprintf(d, "\\{");
142 break;
143 case OEOW:
144 fprintf(d, "\\}");
145 break;
146 case OANY:
147 fprintf(d, ".");
148 break;
149 case OANYOF:
150 fprintf(d, "[(%ld)", (long)opnd);
151 cs = &g->sets[opnd];
152 last = -1;
153 for (i = 0; i < g->csetsize+1; i++) /* +1 flushes */
154 if (CHIN(cs, i) && i < g->csetsize) {
155 if (last < 0) {
156 fprintf(d, "%s", regchar(i));
157 last = i;
158 }
159 } else {
160 if (last >= 0) {
161 if (last != i-1)
162 fprintf(d, "-%s",
163 regchar(i-1));
164 last = -1;
165 }
166 }
167 fprintf(d, "]");
168 break;
169 case OBACK_:
170 fprintf(d, "(\\<%ld>", (long)opnd);
171 break;
172 case O_BACK:
173 fprintf(d, "<%ld>\\)", (long)opnd);
174 break;
175 case OPLUS_:
176 fprintf(d, "(+");
177 if (OP(*(s+opnd)) != O_PLUS)
178 fprintf(d, "<%ld>", (long)opnd);
179 break;
180 case O_PLUS:
181 if (OP(*(s-opnd)) != OPLUS_)
182 fprintf(d, "<%ld>", (long)opnd);
183 fprintf(d, "+)");
184 break;
185 case OQUEST_:
186 fprintf(d, "(?");
187 if (OP(*(s+opnd)) != O_QUEST)
188 fprintf(d, "<%ld>", (long)opnd);
189 break;
190 case O_QUEST:
191 if (OP(*(s-opnd)) != OQUEST_)
192 fprintf(d, "<%ld>", (long)opnd);
193 fprintf(d, "?)");
194 break;
195 case OLPAREN:
196 fprintf(d, "((<%ld>", (long)opnd);
197 break;
198 case ORPAREN:
199 fprintf(d, "<%ld>))", (long)opnd);
200 break;
201 case OCH_:
202 fprintf(d, "<");
203 if (OP(*(s+opnd)) != OOR2)
204 fprintf(d, "<%ld>", (long)opnd);
205 break;
206 case OOR1:
207 if (OP(*(s-opnd)) != OOR1 && OP(*(s-opnd)) != OCH_)
208 fprintf(d, "<%ld>", (long)opnd);
209 fprintf(d, "|");
210 break;
211 case OOR2:
212 fprintf(d, "|");
213 if (OP(*(s+opnd)) != OOR2 && OP(*(s+opnd)) != O_CH)
214 fprintf(d, "<%ld>", (long)opnd);
215 break;
216 case O_CH:
217 if (OP(*(s-opnd)) != OOR1)
218 fprintf(d, "<%ld>", (long)opnd);
219 fprintf(d, ">");
220 break;
221 default:
222 fprintf(d, "!%ld(%ld)!", (long)OP(*s), (long)opnd);
223 break;
224 }
225 if (!done)
226 GAP();
227 }
228}
229
230/*
231 - regchar - make a character printable
232 == static char *regchar(int ch);
233 */
234static char * /* -> representation */
235regchar(ch)
236int ch;
237{
238 static char buf[10];
239
240 if (isprint(ch) || ch == ' ')
241 snprintf(buf, sizeof buf, "%c", ch);
242 else
243 snprintf(buf, sizeof buf, "\\%o", ch);
244 return(buf);
245}
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
6extern "C" {
7#endif
8
9/* === debug.c === */
10void regprint(regex_t *r, FILE *d);
11static void s_print(register struct re_guts *g, FILE *d);
12static 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 e0ed86f5e8..0000000000
--- a/src/regress/lib/libc/regex/main.c
+++ /dev/null
@@ -1,516 +0,0 @@
1/* $OpenBSD: main.c,v 1.7 2007/09/12 19:32:35 otto 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
14char *progname;
15int debug = 0;
16int line = 0;
17int status = 0;
18
19int copts = REG_EXTENDED;
20int eopts = 0;
21regoff_t startoff = 0;
22regoff_t endoff = 0;
23
24
25extern int split(char *, char *[], int, char *);
26extern void regprint(regex_t *, FILE *);
27
28/*
29 - main - do the simple case, hand off to regress() for regression
30 */
31int
32main(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 extern int optind;
45 extern char *optarg;
46
47 progname = argv[0];
48
49 while ((c = getopt(argc, argv, "c:e:S:E:x")) != -1)
50 switch (c) {
51 case 'c': /* compile options */
52 copts = options('c', optarg);
53 break;
54 case 'e': /* execute options */
55 eopts = options('e', optarg);
56 break;
57 case 'S': /* start offset */
58 startoff = (regoff_t)atoi(optarg);
59 break;
60 case 'E': /* end offset */
61 endoff = (regoff_t)atoi(optarg);
62 break;
63 case 'x': /* Debugging. */
64 debug++;
65 break;
66 case '?':
67 default:
68 errflg++;
69 break;
70 }
71 if (errflg) {
72 fprintf(stderr, "usage: %s ", progname);
73 fprintf(stderr, "[-c copt][-C][-d] [re]\n");
74 exit(2);
75 }
76
77 if (optind >= argc) {
78 regress(stdin);
79 exit(status);
80 }
81
82 err = regcomp(&re, argv[optind++], copts);
83 if (err) {
84 len = regerror(err, &re, erbuf, sizeof(erbuf));
85 fprintf(stderr, "error %s, %zu/%zu `%s'\n",
86 eprint(err), len, sizeof(erbuf), erbuf);
87 exit(status);
88 }
89 regprint(&re, stdout);
90
91 if (optind >= argc) {
92 regfree(&re);
93 exit(status);
94 }
95
96 if (eopts&REG_STARTEND) {
97 subs[0].rm_so = startoff;
98 subs[0].rm_eo = strlen(argv[optind]) - endoff;
99 }
100 err = regexec(&re, argv[optind], (size_t)NS, subs, eopts);
101 if (err) {
102 len = regerror(err, &re, erbuf, sizeof(erbuf));
103 fprintf(stderr, "error %s, %zu/%zu `%s'\n",
104 eprint(err), len, sizeof(erbuf), erbuf);
105 exit(status);
106 }
107 if (!(copts&REG_NOSUB)) {
108 len = (size_t)(subs[0].rm_eo - subs[0].rm_so);
109 if (subs[0].rm_so != -1) {
110 if (len != 0)
111 printf("match `%.*s'\n", (int)len,
112 argv[optind] + subs[0].rm_so);
113 else
114 printf("match `'@%.1s\n",
115 argv[optind] + subs[0].rm_so);
116 }
117 for (i = 1; i < NS; i++)
118 if (subs[i].rm_so != -1)
119 printf("(%d) `%.*s'\n", i,
120 (int)(subs[i].rm_eo - subs[i].rm_so),
121 argv[optind] + subs[i].rm_so);
122 }
123 exit(status);
124}
125
126/*
127 - regress - main loop of regression test
128 == void regress(FILE *in);
129 */
130void
131regress(in)
132FILE *in;
133{
134 char inbuf[1000];
135# define MAXF 10
136 char *f[MAXF];
137 int nf;
138 int i;
139 char erbuf[100];
140 size_t ne;
141 char *badpat = "invalid regular expression";
142# define SHORT 10
143 char *bpname = "REG_BADPAT";
144 regex_t re;
145
146 while (fgets(inbuf, sizeof(inbuf), in) != NULL) {
147 line++;
148 if (inbuf[0] == '#' || inbuf[0] == '\n')
149 continue; /* NOTE CONTINUE */
150 inbuf[strcspn(inbuf, "\n")] = '\0'; /* get rid of stupid \n */
151 if (debug)
152 fprintf(stdout, "%d:\n", line);
153 nf = split(inbuf, f, MAXF, "\t\t");
154 if (nf < 3) {
155 fprintf(stderr, "bad input, line %d\n", line);
156 exit(1);
157 }
158 for (i = 0; i < nf; i++)
159 if (strcmp(f[i], "\"\"") == 0)
160 f[i] = "";
161 if (nf <= 3)
162 f[3] = NULL;
163 if (nf <= 4)
164 f[4] = NULL;
165 try(f[0], f[1], f[2], f[3], f[4], options('c', f[1]));
166 if (opt('&', f[1])) /* try with either type of RE */
167 try(f[0], f[1], f[2], f[3], f[4],
168 options('c', f[1]) &~ REG_EXTENDED);
169 }
170
171 ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf));
172 if (strcmp(erbuf, badpat) != 0 || ne != strlen(badpat)+1) {
173 fprintf(stderr, "end: regerror() test gave `%s' not `%s'\n",
174 erbuf, badpat);
175 status = 1;
176 }
177 ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, (size_t)SHORT);
178 if (strncmp(erbuf, badpat, SHORT-1) != 0 || erbuf[SHORT-1] != '\0' ||
179 ne != strlen(badpat)+1) {
180 fprintf(stderr, "end: regerror() short test gave `%s' not `%.*s'\n",
181 erbuf, SHORT-1, badpat);
182 status = 1;
183 }
184 ne = regerror(REG_ITOA|REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf));
185 if (strcmp(erbuf, bpname) != 0 || ne != strlen(bpname)+1) {
186 fprintf(stderr, "end: regerror() ITOA test gave `%s' not `%s'\n",
187 erbuf, bpname);
188 status = 1;
189 }
190 re.re_endp = bpname;
191 ne = regerror(REG_ATOI, &re, erbuf, sizeof(erbuf));
192 if (atoi(erbuf) != (int)REG_BADPAT) {
193 fprintf(stderr, "end: regerror() ATOI test gave `%s' not `%ld'\n",
194 erbuf, (long)REG_BADPAT);
195 status = 1;
196 } else if (ne != strlen(erbuf)+1) {
197 fprintf(stderr, "end: regerror() ATOI test len(`%s') = %ld\n",
198 erbuf, (long)REG_BADPAT);
199 status = 1;
200 }
201}
202
203/*
204 - try - try it, and report on problems
205 == void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts);
206 */
207void
208try(f0, f1, f2, f3, f4, opts)
209char *f0;
210char *f1;
211char *f2;
212char *f3;
213char *f4;
214int opts; /* may not match f1 */
215{
216 regex_t re;
217# define NSUBS 10
218 regmatch_t subs[NSUBS];
219# define NSHOULD 15
220 char *should[NSHOULD];
221 int nshould;
222 char erbuf[100];
223 int err;
224 int len;
225 char *type = (opts & REG_EXTENDED) ? "ERE" : "BRE";
226 register int i;
227 char *grump;
228 char f0copy[1000];
229 char f2copy[1000];
230
231 strlcpy(f0copy, f0, sizeof f0copy);
232 re.re_endp = (opts&REG_PEND) ? f0copy + strlen(f0copy) : NULL;
233 fixstr(f0copy);
234 err = regcomp(&re, f0copy, opts);
235 if (err != 0 && (!opt('C', f1) || err != efind(f2))) {
236 /* unexpected error or wrong error */
237 len = regerror(err, &re, erbuf, sizeof(erbuf));
238 fprintf(stderr, "%d: %s error %s, %d/%zu `%s'\n",
239 line, type, eprint(err), len,
240 sizeof(erbuf), erbuf);
241 status = 1;
242 } else if (err == 0 && opt('C', f1)) {
243 /* unexpected success */
244 fprintf(stderr, "%d: %s should have given REG_%s\n",
245 line, type, f2);
246 status = 1;
247 err = 1; /* so we won't try regexec */
248 }
249
250 if (err != 0) {
251 regfree(&re);
252 return;
253 }
254
255 strlcpy(f2copy, f2, sizeof f2copy);
256 fixstr(f2copy);
257
258 if (options('e', f1)&REG_STARTEND) {
259 if (strchr(f2, '(') == NULL || strchr(f2, ')') == NULL)
260 fprintf(stderr, "%d: bad STARTEND syntax\n", line);
261 subs[0].rm_so = strchr(f2, '(') - f2 + 1;
262 subs[0].rm_eo = strchr(f2, ')') - f2;
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&REG_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 */
318int
319options(type, s)
320int type; /* 'c' compile, 'e' exec */
321char *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 */
375int /* predicate */
376opt(c, s)
377int c;
378char *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 */
387void
388fixstr(p)
389register 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 */
409char * /* NULL or complaint */
410check(str, sub, should)
411char *str;
412regmatch_t sub;
413char *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 shlen = (int)strlen(should);
455 p = str + sub.rm_so;
456
457 /* check for not supposed to match */
458 if (should == NULL) {
459 snprintf(grump, sizeof grump, "matched `%.*s'", len, p);
460 return(grump);
461 }
462
463 /* check for wrong match */
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 */
488static char *
489eprint(err)
490int 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 */
504static int
505efind(name)
506char *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
6extern "C" {
7#endif
8
9/* === main.c === */
10void regress(FILE *in);
11void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts);
12int options(int type, char *s);
13int opt(int c, char *s);
14void fixstr(register char *p);
15char *check(char *str, regmatch_t sub, char *should);
16static char *eprint(int err);
17static 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
7int 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 */
13int /* number of fields, including overflow */
14split(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 */
151int
152main(argc, argv)
153int argc;
154char *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
183dosplit(string, seps)
184char *string;
185char *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
195print(nf, nfp, fields)
196int nf;
197int nfp;
198char *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 */
210struct {
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
278regress()
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 e4d4e4f5d7..0000000000
--- a/src/regress/lib/libc/regex/t_exhaust.c
+++ /dev/null
@@ -1,186 +0,0 @@
1/* $OpenBSD: t_exhaust.c,v 1.2 2011/11/06 15:47:07 otto 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 <sys/cdefs.h>
41
42#include <stdio.h>
43#include <regex.h>
44#include <string.h>
45#include <stdlib.h>
46#include <err.h>
47//#include <atf-c.h>
48
49
50static char *
51mkstr(const char *str, size_t len)
52{
53 size_t i, slen = strlen(str);
54 char *p = malloc(slen * len + 1);
55 if (p == NULL)
56 err(1, "malloc");
57 for (i = 0; i < len; i++)
58 strlcpy(&p[i * slen], str, slen * len + 1 - (i * slen));
59 return p;
60}
61
62static char *
63concat(const char *d, const char *s)
64{
65 size_t dlen = strlen(d);
66 size_t slen = strlen(s);
67 char *p = malloc(dlen + slen + 1);
68 strlcpy(p, d, dlen + slen + 1);
69 strlcat(p, s, dlen + slen + 1);
70 return p;
71}
72
73static char *
74p0(size_t len)
75{
76 char *d, *s1, *s2;
77 s1 = mkstr("\\(", len);
78 s2 = concat(s1, ")");
79 free(s1);
80 d = concat("(", s2);
81 free(s2);
82 return d;
83}
84
85static char *
86p1(size_t len)
87{
88 char *d, *s1, *s2, *s3;
89 s1 = mkstr("\\(", 60);
90 s2 = mkstr("(.*)", len);
91 s3 = concat(s1, s2);
92 free(s2);
93 free(s1);
94 s1 = concat(s3, ")");
95 free(s3);
96 d = concat("(", s1);
97 free(s1);
98 return d;
99}
100
101static char *
102ps(const char *m, const char *s, size_t len)
103{
104 char *d, *s1, *s2, *s3;
105 s1 = mkstr(m, len);
106 s2 = mkstr(s, len);
107 s3 = concat(s1, s2);
108 free(s2);
109 free(s1);
110 d = concat("(.?)", s3);
111 free(s3);
112 return d;
113}
114
115static char *
116p2(size_t len)
117{
118 return ps("((.*){0,255}", ")", len);
119}
120
121static char *
122p3(size_t len)
123{
124 return ps("(.\\{0,}", ")", len);
125}
126
127static char *
128p4(size_t len)
129{
130 return ps("((.*){1,255}", ")", len);
131}
132
133static char *
134p5(size_t len)
135{
136 return ps("(", "){1,100}", len);
137}
138
139static char *
140p6(size_t len)
141{
142 char *d, *s1, *s2;
143 s1 = mkstr("(?:(.*)|", len);
144 s2 = concat(s1, "(.*)");
145 free(s1);
146 s1 = mkstr(")", len);
147 d = concat(s2, s1);
148 free(s1);
149 free(s2);
150 return d;
151}
152
153static char *(*patterns[])(size_t) = {
154 p0,
155 p1,
156 p2,
157 p3,
158 p4,
159 p5,
160 p6,
161};
162
163
164main()
165{
166 regex_t re;
167 int e, ret = 0;
168 size_t i;
169
170 for (i = 0; i < sizeof(patterns) / sizeof(patterns[0]); i++) {
171 char *d = (*patterns[i])(9999);
172 e = regcomp(&re, d, i == 6 ? REG_BASIC : REG_EXTENDED);
173 free(d);
174 if (e) {
175 if (e != REG_ESPACE) {
176 printf("regcomp returned %d for pattern %zu", e, i);
177 ret = 1;
178 }
179 continue;
180 }
181 (void)regexec(&re, "aaaaaaaa", 0, NULL, 0);
182 regfree(&re);
183 }
184 return ret;
185}
186
diff --git a/src/regress/lib/libc/regex/tests b/src/regress/lib/libc/regex/tests
deleted file mode 100644
index c827c868b7..0000000000
--- a/src/regress/lib/libc/regex/tests
+++ /dev/null
@@ -1,503 +0,0 @@
1# $OpenBSD: tests,v 1.5 2004/11/29 16:50:31 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
39a & a a
40abc & abc abc
41abc|de - abc abc
42a|b|c - abc a
43
44# parentheses and perversions thereof
45a(b)c - abc abc
46a\(b\)c b abc abc
47a( C EPAREN
48a( b a( a(
49a\( - a( a(
50a\( bC EPAREN
51a\(b bC EPAREN
52a(b C EPAREN
53a(b b a(b a(b
54# gag me with a right parenthesis -- 1003.2 goofed here (my fault, partly)
55a) - a) a)
56) - ) )
57# end gagging (in a just world, those *should* give EPAREN)
58a) b a) a)
59a\) bC EPAREN
60\) bC EPAREN
61a()b - ab ab
62a\(\)b b ab ab
63
64# anchoring and REG_NEWLINE
65^abc$ & abc abc
66a^b - a^b
67a^b b a^b a^b
68a$b - a$b
69a$b b a$b a$b
70^ & abc @abc
71$ & abc @
72^$ & "" @
73$^ - "" @
74\($\)\(^\) b "" @
75# stop retching, those are legitimate (although disgusting)
76^^ - "" @
77$$ - "" @
78b$ & abNc
79b$ &n abNc b
80^b$ & aNbNc
81^b$ &n aNbNc b
82^$ &n aNNb @Nb
83^$ n abc
84^$ n abcN @
85$^ n aNNb @Nb
86\($\)\(^\) bn aNNb @Nb
87^^ n^ aNNb @Nb
88$$ n aNNb @NN
89^a ^ a
90a$ $ a
91^a ^n aNb
92^b ^n aNb b
93a$ $n bNa
94b$ $n bNa b
95a*(^b$)c* - b b
96a*\(^b$\)c* b b b
97
98# certain syntax errors and non-errors
99| C EMPTY
100| b | |
101* C BADRPT
102* b * *
103+ C BADRPT
104? C BADRPT
105"" &C EMPTY
106() - abc @abc
107\(\) b abc @abc
108a||b C EMPTY
109|ab C EMPTY
110ab| C EMPTY
111(|a)b C EMPTY
112(a|)b C EMPTY
113(*a) C BADRPT
114(+a) C BADRPT
115(?a) C BADRPT
116({1}a) C BADRPT
117\(\{1\}a\) bC BADRPT
118(a|*b) C BADRPT
119(a|+b) C BADRPT
120(a|?b) C BADRPT
121(a|{1}b) C BADRPT
122^* C BADRPT
123^* b * *
124^+ C BADRPT
125^? C BADRPT
126^{1} C BADRPT
127^\{1\} bC BADRPT
128
129# metacharacters, backslashes
130a.c & abc abc
131a[bc]d & abd abd
132a\*c & a*c a*c
133a\\b & a\b a\b
134a\\\*b & a\*b a\*b
135a\bc & abc abc
136a\ &C EESCAPE
137a\\bc & a\bc a\bc
138\{ bC BADRPT
139a\[b & a[b a[b
140a[b &C EBRACK
141# trailing $ is a peculiar special case for the BRE code
142a$ & a a
143a$ & a$
144a\$ & a
145a\$ & a$ a$
146a\\$ & a
147a\\$ & a$
148a\\$ & a\$
149a\\$ & a\ a\
150
151# back references, ugh
152a\(b\)\2c bC ESUBREG
153a\(b\1\)c bC ESUBREG
154a\(b*\)c\1d b abbcbbd abbcbbd bb
155a\(b*\)c\1d b abbcbd
156a\(b*\)c\1d b abbcbbbd
157^\(.\)\1 b abc
158a\([bc]\)\1d b abcdabbd abbd b
159a\(\([bc]\)\2\)*d b abbccd abbccd
160a\(\([bc]\)\2\)*d b abbcbd
161# actually, this next one probably ought to fail, but the spec is unclear
162a\(\(b\)*\2\)*d b abbbd abbbd
163# here is a case that no NFA implementation does right
164\(ab*\)[ab]*\1 b ababaaa ababaaa a
165# check out normal matching in the presence of back refs
166\(a\)\1bcd b aabcd aabcd
167\(a\)\1bc*d b aabcd aabcd
168\(a\)\1bc*d b aabd aabd
169\(a\)\1bc*d b aabcccd aabcccd
170\(a\)\1bc*[ce]d b aabcccd aabcccd
171^\(a\)\1b\(c\)*cd$ b aabcccd aabcccd
172\(b*\)\(a*\1\)* b ab a
173\([^_]*\)\(_*\1\)* b foo_foo_bar_bar_bar_baz foo_foo foo,_foo
174\([^_]*\)\(_*\1\)* b bar_bar_bar_baz bar_bar_bar bar,_bar
175\([^_]*\)\(_*\1\)* b foo_bar_baz foo foo
176\(.*\)\1 b "" ""
177\(.*\)\1 b a ""
178\(.*\)\1 b aa aa
179\(.*\)\1 b aaa aa
180\(.*\)\1 b aaaa aaaa
181\([^_]*\)\1 b "" ""
182\([^_]*\)\1 b a ""
183\([^_]*\)\1 b aa aa
184\([^_]*\)\1 b aaa aa
185\([^_]*\)\1 b aaaa aaaa
186foo\(.*\)bar\1 b foolbarl foolbarl l
187foo\(.*\)bar\1 b foobar foobar ""
188\(\(.\)b\)*\1 b aba
189\(\(.\)b\)*\1 b abba
190\(\(.\)b\)*\1 b abbba
191\(\(.\)b\)*\1 b abbbba bbbb bb,b
192\(\(.\)b\)*\1 b abbbbba abbbbb bb,b
193\(\(.\)b\)*\1 b abbbbbba abbbbb bb,b
194\(\(.\)b\)*\1 b abbbbbbbbbbbbbba abbbbbbbbbbbbb bb,b
195\(\(.\)b\)*\1 b abbbbbbbbbbbbbbba abbbbbbbbbbbbbbb bb,b
196
197# ordinary repetitions
198ab*c & abc abc
199ab+c - abc abc
200ab?c - abc abc
201a\(*\)b b a*b a*b
202a\(**\)b b ab ab
203a\(***\)b bC BADRPT
204*a b *a *a
205**a b a a
206***a bC BADRPT
207
208# the dreaded bounded repetitions
209{ & { {
210{abc & {abc {abc
211{1 C BADRPT
212{1} C BADRPT
213a{b & a{b a{b
214a{1}b - ab ab
215a\{1\}b b ab ab
216a{1,}b - ab ab
217a\{1,\}b b ab ab
218a{1,2}b - aab aab
219a\{1,2\}b b aab aab
220a{1 C EBRACE
221a\{1 bC EBRACE
222a{1a C EBRACE
223a\{1a bC EBRACE
224a{1a} C BADBR
225a\{1a\} bC BADBR
226a{,2} - a{,2} a{,2}
227a\{,2\} bC BADBR
228a{,} - a{,} a{,}
229a\{,\} bC BADBR
230a{1,x} C BADBR
231a\{1,x\} bC BADBR
232a{1,x C EBRACE
233a\{1,x bC EBRACE
234a{300} C BADBR
235a\{300\} bC BADBR
236a{1,0} C BADBR
237a\{1,0\} bC BADBR
238ab{0,0}c - abcac ac
239ab\{0,0\}c b abcac ac
240ab{0,1}c - abcac abc
241ab\{0,1\}c b abcac abc
242ab{0,3}c - abbcac abbc
243ab\{0,3\}c b abbcac abbc
244ab{1,1}c - acabc abc
245ab\{1,1\}c b acabc abc
246ab{1,3}c - acabc abc
247ab\{1,3\}c b acabc abc
248ab{2,2}c - abcabbc abbc
249ab\{2,2\}c b abcabbc abbc
250ab{2,4}c - abcabbc abbc
251ab\{2,4\}c b abcabbc abbc
252((a{1,10}){1,10}){1,10} - a a a,a
253
254# multiple repetitions
255a** &C BADRPT
256a++ C BADRPT
257a?? C BADRPT
258a*+ C BADRPT
259a*? C BADRPT
260a+* C BADRPT
261a+? C BADRPT
262a?* C BADRPT
263a?+ C BADRPT
264a{1}{1} C BADRPT
265a*{1} C BADRPT
266a+{1} C BADRPT
267a?{1} C BADRPT
268a{1}* C BADRPT
269a{1}+ C BADRPT
270a{1}? C BADRPT
271a*{b} - a{b} a{b}
272a\{1\}\{1\} bC BADRPT
273a*\{1\} bC BADRPT
274a\{1\}* bC BADRPT
275
276# brackets, and numerous perversions thereof
277a[b]c & abc abc
278a[ab]c & abc abc
279a[^ab]c & adc adc
280a[]b]c & a]c a]c
281a[[b]c & a[c a[c
282a[-b]c & a-c a-c
283a[^]b]c & adc adc
284a[^-b]c & adc adc
285a[b-]c & a-c a-c
286a[b &C EBRACK
287a[] &C EBRACK
288a[1-3]c & a2c a2c
289a[3-1]c &C ERANGE
290a[1-3-5]c &C ERANGE
291a[[.-.]--]c & a-c a-c
292a[1- &C ERANGE
293a[[. &C EBRACK
294a[[.x &C EBRACK
295a[[.x. &C EBRACK
296a[[.x.] &C EBRACK
297a[[.x.]] & ax ax
298a[[.x,.]] &C ECOLLATE
299a[[.one.]]b & a1b a1b
300a[[.notdef.]]b &C ECOLLATE
301a[[.].]]b & a]b a]b
302a[[:alpha:]]c & abc abc
303a[[:notdef:]]c &C ECTYPE
304a[[: &C EBRACK
305a[[:alpha &C EBRACK
306a[[:alpha:] &C EBRACK
307a[[:alpha,:] &C ECTYPE
308a[[:]:]]b &C ECTYPE
309a[[:-:]]b &C ECTYPE
310a[[:alph:]] &C ECTYPE
311a[[:alphabet:]] &C ECTYPE
312[[:alnum:]]+ - -%@a0X- a0X
313[[:alpha:]]+ - -%@aX0- aX
314[[:blank:]]+ - aSSTb SST
315[[:cntrl:]]+ - aNTb NT
316[[:digit:]]+ - a019b 019
317[[:graph:]]+ - Sa%bS a%b
318[[:lower:]]+ - AabC ab
319[[:print:]]+ - NaSbN aSb
320[[:punct:]]+ - S%-&T %-&
321[[:space:]]+ - aSNTb SNT
322[[:upper:]]+ - aBCd BC
323[[:xdigit:]]+ - p0f3Cq 0f3C
324a[[=b=]]c & abc abc
325a[[= &C EBRACK
326a[[=b &C EBRACK
327a[[=b= &C EBRACK
328a[[=b=] &C EBRACK
329a[[=b,=]] &C ECOLLATE
330a[[=one=]]b & a1b a1b
331
332# complexities
333a(((b)))c - abc abc
334a(b|(c))d - abd abd
335a(b*|c)d - abbd abbd
336# just gotta have one DFA-buster, of course
337a[ab]{20} - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab
338# and an inline expansion in case somebody gets tricky
339a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab] - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab
340# and in case somebody just slips in an NFA...
341a[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
342# fish for anomalies as the number of states passes 32
34312345678901234567890123456789 - a12345678901234567890123456789b 12345678901234567890123456789
344123456789012345678901234567890 - a123456789012345678901234567890b 123456789012345678901234567890
3451234567890123456789012345678901 - a1234567890123456789012345678901b 1234567890123456789012345678901
34612345678901234567890123456789012 - a12345678901234567890123456789012b 12345678901234567890123456789012
347123456789012345678901234567890123 - a123456789012345678901234567890123b 123456789012345678901234567890123
348# and one really big one, beyond any plausible word width
3491234567890123456789012345678901234567890123456789012345678901234567890 - a1234567890123456789012345678901234567890123456789012345678901234567890b 1234567890123456789012345678901234567890123456789012345678901234567890
350# fish for problems as brackets go past 8
351[ab][cd][ef][gh][ij][kl][mn] - xacegikmoq acegikm
352[ab][cd][ef][gh][ij][kl][mn][op] - xacegikmoq acegikmo
353[ab][cd][ef][gh][ij][kl][mn][op][qr] - xacegikmoqy acegikmoq
354[ab][cd][ef][gh][ij][kl][mn][op][q] - xacegikmoqy acegikmoq
355
356# subtleties of matching
357abc & xabcy abc
358a\(b\)?c\1d b acd
359aBc i Abc Abc
360a[Bc]*d i abBCcd abBCcd
3610[[:upper:]]1 &i 0a1 0a1
3620[[:lower:]]1 &i 0A1 0A1
363a[^b]c &i abc
364a[^b]c &i aBc
365a[^b]c &i adc adc
366[a]b[c] - abc abc
367[a]b[a] - aba aba
368[abc]b[abc] - abc abc
369[abc]b[abd] - abd abd
370a(b?c)+d - accd accd
371(wee|week)(knights|night) - weeknights weeknights
372(we|wee|week|frob)(knights|night|day) - weeknights weeknights
373a[bc]d - xyzaaabcaababdacd abd
374a[ab]c - aaabc abc
375abc s abc abc
376a* & b @b
377
378# Let's have some fun -- try to match a C comment.
379# first the obvious, which looks okay at first glance...
380/\*.*\*/ - /*x*/ /*x*/
381# but...
382/\*.*\*/ - /*x*/y/*z*/ /*x*/y/*z*/
383# okay, we must not match */ inside; try to do that...
384/\*([^*]|\*[^/])*\*/ - /*x*/ /*x*/
385/\*([^*]|\*[^/])*\*/ - /*x*/y/*z*/ /*x*/
386# but...
387/\*([^*]|\*[^/])*\*/ - /*x**/y/*z*/ /*x**/y/*z*/
388# and a still fancier version, which does it right (I think)...
389/\*([^*]|\*+[^*/])*\*+/ - /*x*/ /*x*/
390/\*([^*]|\*+[^*/])*\*+/ - /*x*/y/*z*/ /*x*/
391/\*([^*]|\*+[^*/])*\*+/ - /*x**/y/*z*/ /*x**/
392/\*([^*]|\*+[^*/])*\*+/ - /*x****/y/*z*/ /*x****/
393/\*([^*]|\*+[^*/])*\*+/ - /*x**x*/y/*z*/ /*x**x*/
394/\*([^*]|\*+[^*/])*\*+/ - /*x***x/y/*z*/ /*x***x/y/*z*/
395
396# subexpressions
397a(b)(c)d - abcd abcd b,c
398a(((b)))c - abc abc b,b,b
399a(b|(c))d - abd abd b,-
400a(b*|c|e)d - abbd abbd bb
401a(b*|c|e)d - acd acd c
402a(b*|c|e)d - ad ad @d
403a(b?)c - abc abc b
404a(b?)c - ac ac @c
405a(b+)c - abc abc b
406a(b+)c - abbbc abbbc bbb
407a(b*)c - ac ac @c
408(a|ab)(bc([de]+)f|cde) - abcdef abcdef a,bcdef,de
409# the regression tester only asks for 9 subexpressions
410a(b)(c)(d)(e)(f)(g)(h)(i)(j)k - abcdefghijk abcdefghijk b,c,d,e,f,g,h,i,j
411a(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)l - abcdefghijkl abcdefghijkl b,c,d,e,f,g,h,i,j,k
412a([bc]?)c - abc abc b
413a([bc]?)c - ac ac @c
414a([bc]+)c - abc abc b
415a([bc]+)c - abcc abcc bc
416a([bc]+)bc - abcbc abcbc bc
417a(bb+|b)b - abb abb b
418a(bbb+|bb+|b)b - abb abb b
419a(bbb+|bb+|b)b - abbb abbb bb
420a(bbb+|bb+|b)bb - abbb abbb b
421(.*).* - abcdef abcdef abcdef
422(a*)* - bc @b @b
423
424# do we get the right subexpression when it is used more than once?
425a(b|c)*d - ad ad -
426a(b|c)*d - abcd abcd c
427a(b|c)+d - abd abd b
428a(b|c)+d - abcd abcd c
429a(b|c?)+d - ad ad @d
430a(b|c?)+d - abcd abcd @d
431a(b|c){0,0}d - ad ad -
432a(b|c){0,1}d - ad ad -
433a(b|c){0,1}d - abd abd b
434a(b|c){0,2}d - ad ad -
435a(b|c){0,2}d - abcd abcd c
436a(b|c){0,}d - ad ad -
437a(b|c){0,}d - abcd abcd c
438a(b|c){1,1}d - abd abd b
439a(b|c){1,1}d - acd acd c
440a(b|c){1,2}d - abd abd b
441a(b|c){1,2}d - abcd abcd c
442a(b|c){1,}d - abd abd b
443a(b|c){1,}d - abcd abcd c
444a(b|c){2,2}d - acbd acbd b
445a(b|c){2,2}d - abcd abcd c
446a(b|c){2,4}d - abcd abcd c
447a(b|c){2,4}d - abcbd abcbd b
448a(b|c){2,4}d - abcbcd abcbcd c
449a(b|c){2,}d - abcd abcd c
450a(b|c){2,}d - abcbd abcbd b
451a(b+|((c)*))+d - abd abd @d,@d,-
452a(b+|((c)*))+d - abcd abcd @d,@d,-
453
454# check out the STARTEND option
455[abc] &# a(b)c b
456[abc] &# a(d)c
457[abc] &# a(bc)d b
458[abc] &# a(dc)d c
459. &# a()c
460b.*c &# b(bc)c bc
461b.* &# b(bc)c bc
462.*c &# b(bc)c bc
463
464# plain strings, with the NOSPEC flag
465abc m abc abc
466abc m xabcy abc
467abc m xyz
468a*b m aba*b a*b
469a*b m ab
470"" mC EMPTY
471
472# cases involving NULs
473aZb & a a
474aZb &p a
475aZb &p# (aZb) aZb
476aZ*b &p# (ab) ab
477a.b &# (aZb) aZb
478a.* &# (aZb)c aZb
479
480# word boundaries (ick)
481[[:<:]]a & a a
482[[:<:]]a & ba
483[[:<:]]a & -a a
484a[[:>:]] & a a
485a[[:>:]] & ab
486a[[:>:]] & a- a
487[[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc abc
488[[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc-q abc
489[[:<:]]a.c[[:>:]] & axc-dayc-dazce-abc axc
490[[:<:]]b.c[[:>:]] & a_bxc-byc_d-bzc-q bzc
491[[:<:]].x..[[:>:]] & y_xa_-_xb_y-_xc_-axdc _xc_
492[[:<:]]a_b[[:>:]] & x_a_b
493
494# past problems, and suspected problems
495(A[1])|(A[2])|(A[3])|(A[4])|(A[5])|(A[6])|(A[7])|(A[8])|(A[9])|(A[A]) - A1 A1
496abcdefghijklmnop i abcdefghijklmnop abcdefghijklmnop
497abcdefghijklmnopqrstuv i abcdefghijklmnopqrstuv abcdefghijklmnopqrstuv
498(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
499CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a - CC11 CC11
500Char \([a-z0-9_]*\)\[.* b Char xyz[k Char xyz[k xyz
501a?b - ab ab
502-\{0,1\}[0-9]*$ b -5 -5
503