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/Makefile16
-rw-r--r--src/regress/lib/libc/regex/debug.c244
-rw-r--r--src/regress/lib/libc/regex/debug.ih16
-rw-r--r--src/regress/lib/libc/regex/main.c515
-rw-r--r--src/regress/lib/libc/regex/main.ih21
-rw-r--r--src/regress/lib/libc/regex/split.c318
-rw-r--r--src/regress/lib/libc/regex/tests477
7 files changed, 1607 insertions, 0 deletions
diff --git a/src/regress/lib/libc/regex/Makefile b/src/regress/lib/libc/regex/Makefile
new file mode 100644
index 0000000000..93b7bb9052
--- /dev/null
+++ b/src/regress/lib/libc/regex/Makefile
@@ -0,0 +1,16 @@
1# $NetBSD: Makefile,v 1.2 1995/02/16 19:38:45 cgd Exp $
2
3PROG= re
4SRCS= main.c split.c debug.c
5NOMAN=
6
7CFLAGS+= -I${.CURDIR}/../../../../lib/libc/regex
8
9TESTS= ${.CURDIR}/tests
10
11regress:
12 ./re < ${TESTS}
13 ./re -el < ${TESTS}
14 ./re -er < ${TESTS}
15
16.include <bsd.prog.mk>
diff --git a/src/regress/lib/libc/regex/debug.c b/src/regress/lib/libc/regex/debug.c
new file mode 100644
index 0000000000..41cd4a557d
--- /dev/null
+++ b/src/regress/lib/libc/regex/debug.c
@@ -0,0 +1,244 @@
1/* $NetBSD: debug.c,v 1.2 1995/04/20 22:39:42 cgd Exp $ */
2
3#include <stdio.h>
4#include <string.h>
5#include <ctype.h>
6#include <limits.h>
7#include <stdlib.h>
8#include <sys/types.h>
9#include <regex.h>
10
11#include "utils.h"
12#include "regex2.h"
13#include "debug.ih"
14
15/*
16 - regprint - print a regexp for debugging
17 == void regprint(regex_t *r, FILE *d);
18 */
19void
20regprint(r, d)
21regex_t *r;
22FILE *d;
23{
24 register struct re_guts *g = r->re_g;
25 register int i;
26 register int c;
27 register int last;
28 int nincat[NC];
29
30 fprintf(d, "%ld states, %d categories", (long)g->nstates,
31 g->ncategories);
32 fprintf(d, ", first %ld last %ld", (long)g->firststate,
33 (long)g->laststate);
34 if (g->iflags&USEBOL)
35 fprintf(d, ", USEBOL");
36 if (g->iflags&USEEOL)
37 fprintf(d, ", USEEOL");
38 if (g->iflags&BAD)
39 fprintf(d, ", BAD");
40 if (g->nsub > 0)
41 fprintf(d, ", nsub=%ld", (long)g->nsub);
42 if (g->must != NULL)
43 fprintf(d, ", must(%ld) `%*s'", (long)g->mlen, (int)g->mlen,
44 g->must);
45 if (g->backrefs)
46 fprintf(d, ", backrefs");
47 if (g->nplus > 0)
48 fprintf(d, ", nplus %ld", (long)g->nplus);
49 fprintf(d, "\n");
50 s_print(g, d);
51 for (i = 0; i < g->ncategories; i++) {
52 nincat[i] = 0;
53 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
54 if (g->categories[c] == i)
55 nincat[i]++;
56 }
57 fprintf(d, "cc0#%d", nincat[0]);
58 for (i = 1; i < g->ncategories; i++)
59 if (nincat[i] == 1) {
60 for (c = CHAR_MIN; c <= CHAR_MAX; c++)
61 if (g->categories[c] == i)
62 break;
63 fprintf(d, ", %d=%s", i, regchar(c));
64 }
65 fprintf(d, "\n");
66 for (i = 1; i < g->ncategories; i++)
67 if (nincat[i] != 1) {
68 fprintf(d, "cc%d\t", i);
69 last = -1;
70 for (c = CHAR_MIN; c <= CHAR_MAX+1; c++) /* +1 does flush */
71 if (c <= CHAR_MAX && g->categories[c] == i) {
72 if (last < 0) {
73 fprintf(d, "%s", regchar(c));
74 last = c;
75 }
76 } else {
77 if (last >= 0) {
78 if (last != c-1)
79 fprintf(d, "-%s",
80 regchar(c-1));
81 last = -1;
82 }
83 }
84 fprintf(d, "\n");
85 }
86}
87
88/*
89 - s_print - print the strip for debugging
90 == static void s_print(register struct re_guts *g, FILE *d);
91 */
92static void
93s_print(g, d)
94register struct re_guts *g;
95FILE *d;
96{
97 register sop *s;
98 register cset *cs;
99 register int i;
100 register int done = 0;
101 register sop opnd;
102 register int col = 0;
103 register int last;
104 register sopno offset = 2;
105# define GAP() { if (offset % 5 == 0) { \
106 if (col > 40) { \
107 fprintf(d, "\n\t"); \
108 col = 0; \
109 } else { \
110 fprintf(d, " "); \
111 col++; \
112 } \
113 } else \
114 col++; \
115 offset++; \
116 }
117
118 if (OP(g->strip[0]) != OEND)
119 fprintf(d, "missing initial OEND!\n");
120 for (s = &g->strip[1]; !done; s++) {
121 opnd = OPND(*s);
122 switch (OP(*s)) {
123 case OEND:
124 fprintf(d, "\n");
125 done = 1;
126 break;
127 case OCHAR:
128 if (strchr("\\|()^$.[+*?{}!<> ", (char)opnd) != NULL)
129 fprintf(d, "\\%c", (char)opnd);
130 else
131 fprintf(d, "%s", regchar((char)opnd));
132 break;
133 case OBOL:
134 fprintf(d, "^");
135 break;
136 case OEOL:
137 fprintf(d, "$");
138 break;
139 case OBOW:
140 fprintf(d, "\\{");
141 break;
142 case OEOW:
143 fprintf(d, "\\}");
144 break;
145 case OANY:
146 fprintf(d, ".");
147 break;
148 case OANYOF:
149 fprintf(d, "[(%ld)", (long)opnd);
150 cs = &g->sets[opnd];
151 last = -1;
152 for (i = 0; i < g->csetsize+1; i++) /* +1 flushes */
153 if (CHIN(cs, i) && i < g->csetsize) {
154 if (last < 0) {
155 fprintf(d, "%s", regchar(i));
156 last = i;
157 }
158 } else {
159 if (last >= 0) {
160 if (last != i-1)
161 fprintf(d, "-%s",
162 regchar(i-1));
163 last = -1;
164 }
165 }
166 fprintf(d, "]");
167 break;
168 case OBACK_:
169 fprintf(d, "(\\<%ld>", (long)opnd);
170 break;
171 case O_BACK:
172 fprintf(d, "<%ld>\\)", (long)opnd);
173 break;
174 case OPLUS_:
175 fprintf(d, "(+");
176 if (OP(*(s+opnd)) != O_PLUS)
177 fprintf(d, "<%ld>", (long)opnd);
178 break;
179 case O_PLUS:
180 if (OP(*(s-opnd)) != OPLUS_)
181 fprintf(d, "<%ld>", (long)opnd);
182 fprintf(d, "+)");
183 break;
184 case OQUEST_:
185 fprintf(d, "(?");
186 if (OP(*(s+opnd)) != O_QUEST)
187 fprintf(d, "<%ld>", (long)opnd);
188 break;
189 case O_QUEST:
190 if (OP(*(s-opnd)) != OQUEST_)
191 fprintf(d, "<%ld>", (long)opnd);
192 fprintf(d, "?)");
193 break;
194 case OLPAREN:
195 fprintf(d, "((<%ld>", (long)opnd);
196 break;
197 case ORPAREN:
198 fprintf(d, "<%ld>))", (long)opnd);
199 break;
200 case OCH_:
201 fprintf(d, "<");
202 if (OP(*(s+opnd)) != OOR2)
203 fprintf(d, "<%ld>", (long)opnd);
204 break;
205 case OOR1:
206 if (OP(*(s-opnd)) != OOR1 && OP(*(s-opnd)) != OCH_)
207 fprintf(d, "<%ld>", (long)opnd);
208 fprintf(d, "|");
209 break;
210 case OOR2:
211 fprintf(d, "|");
212 if (OP(*(s+opnd)) != OOR2 && OP(*(s+opnd)) != O_CH)
213 fprintf(d, "<%ld>", (long)opnd);
214 break;
215 case O_CH:
216 if (OP(*(s-opnd)) != OOR1)
217 fprintf(d, "<%ld>", (long)opnd);
218 fprintf(d, ">");
219 break;
220 default:
221 fprintf(d, "!%ld(%ld)!", (long)OP(*s), (long)opnd);
222 break;
223 }
224 if (!done)
225 GAP();
226 }
227}
228
229/*
230 - regchar - make a character printable
231 == static char *regchar(int ch);
232 */
233static char * /* -> representation */
234regchar(ch)
235int ch;
236{
237 static char buf[10];
238
239 if (isprint(ch) || ch == ' ')
240 sprintf(buf, "%c", ch);
241 else
242 sprintf(buf, "\\%o", ch);
243 return(buf);
244}
diff --git a/src/regress/lib/libc/regex/debug.ih b/src/regress/lib/libc/regex/debug.ih
new file mode 100644
index 0000000000..fb9bac0c75
--- /dev/null
+++ b/src/regress/lib/libc/regex/debug.ih
@@ -0,0 +1,16 @@
1/* $NetBSD: debug.ih,v 1.2 1995/04/20 22:39:47 cgd Exp $ */
2
3/* ========= begin header generated by ./mkh ========= */
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8/* === debug.c === */
9void regprint __P((regex_t *r, FILE *d));
10static void s_print __P((register struct re_guts *g, FILE *d));
11static char *regchar __P((int ch));
12
13#ifdef __cplusplus
14}
15#endif
16/* ========= end header generated by ./mkh ========= */
diff --git a/src/regress/lib/libc/regex/main.c b/src/regress/lib/libc/regex/main.c
new file mode 100644
index 0000000000..6e63ffc235
--- /dev/null
+++ b/src/regress/lib/libc/regex/main.c
@@ -0,0 +1,515 @@
1/* $OpenBSD: main.c,v 1.3 1997/01/15 23:41:07 millert 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();
26extern void regprint();
27
28/*
29 - main - do the simple case, hand off to regress() for regression
30 */
31int
32main(argc, argv)
33int argc;
34char *argv[];
35{
36 regex_t re;
37# define NS 10
38 regmatch_t subs[NS];
39 char erbuf[100];
40 int err;
41 size_t len;
42 int c;
43 int errflg = 0;
44 register int i;
45 extern int optind;
46 extern char *optarg;
47
48 progname = argv[0];
49
50 while ((c = getopt(argc, argv, "c:e:S:E:x")) != -1)
51 switch (c) {
52 case 'c': /* compile options */
53 copts = options('c', 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 'E': /* end offset */
62 endoff = (regoff_t)atoi(optarg);
63 break;
64 case 'x': /* Debugging. */
65 debug++;
66 break;
67 case '?':
68 default:
69 errflg++;
70 break;
71 }
72 if (errflg) {
73 fprintf(stderr, "usage: %s ", progname);
74 fprintf(stderr, "[-c copt][-C][-d] [re]\n");
75 exit(2);
76 }
77
78 if (optind >= argc) {
79 regress(stdin);
80 exit(status);
81 }
82
83 err = regcomp(&re, argv[optind++], copts);
84 if (err) {
85 len = regerror(err, &re, erbuf, sizeof(erbuf));
86 fprintf(stderr, "error %s, %d/%d `%s'\n",
87 eprint(err), len, sizeof(erbuf), erbuf);
88 exit(status);
89 }
90 regprint(&re, stdout);
91
92 if (optind >= argc) {
93 regfree(&re);
94 exit(status);
95 }
96
97 if (eopts&REG_STARTEND) {
98 subs[0].rm_so = startoff;
99 subs[0].rm_eo = strlen(argv[optind]) - endoff;
100 }
101 err = regexec(&re, argv[optind], (size_t)NS, subs, eopts);
102 if (err) {
103 len = regerror(err, &re, erbuf, sizeof(erbuf));
104 fprintf(stderr, "error %s, %d/%d `%s'\n",
105 eprint(err), len, sizeof(erbuf), erbuf);
106 exit(status);
107 }
108 if (!(copts&REG_NOSUB)) {
109 len = (size_t)(subs[0].rm_eo - subs[0].rm_so);
110 if (subs[0].rm_so != -1) {
111 if (len != 0)
112 printf("match `%.*s'\n", (int)len,
113 argv[optind] + subs[0].rm_so);
114 else
115 printf("match `'@%.1s\n",
116 argv[optind] + subs[0].rm_so);
117 }
118 for (i = 1; i < NS; i++)
119 if (subs[i].rm_so != -1)
120 printf("(%d) `%.*s'\n", i,
121 (int)(subs[i].rm_eo - subs[i].rm_so),
122 argv[optind] + subs[i].rm_so);
123 }
124 exit(status);
125}
126
127/*
128 - regress - main loop of regression test
129 == void regress(FILE *in);
130 */
131void
132regress(in)
133FILE *in;
134{
135 char inbuf[1000];
136# define MAXF 10
137 char *f[MAXF];
138 int nf;
139 int i;
140 char erbuf[100];
141 size_t ne;
142 char *badpat = "invalid regular expression";
143# define SHORT 10
144 char *bpname = "REG_BADPAT";
145 regex_t re;
146
147 while (fgets(inbuf, sizeof(inbuf), in) != NULL) {
148 line++;
149 if (inbuf[0] == '#' || inbuf[0] == '\n')
150 continue; /* NOTE CONTINUE */
151 inbuf[strlen(inbuf)-1] = '\0'; /* get rid of stupid \n */
152 if (debug)
153 fprintf(stdout, "%d:\n", line);
154 nf = split(inbuf, f, MAXF, "\t\t");
155 if (nf < 3) {
156 fprintf(stderr, "bad input, line %d\n", line);
157 exit(1);
158 }
159 for (i = 0; i < nf; i++)
160 if (strcmp(f[i], "\"\"") == 0)
161 f[i] = "";
162 if (nf <= 3)
163 f[3] = NULL;
164 if (nf <= 4)
165 f[4] = NULL;
166 try(f[0], f[1], f[2], f[3], f[4], options('c', f[1]));
167 if (opt('&', f[1])) /* try with either type of RE */
168 try(f[0], f[1], f[2], f[3], f[4],
169 options('c', f[1]) &~ REG_EXTENDED);
170 }
171
172 ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf));
173 if (strcmp(erbuf, badpat) != 0 || ne != strlen(badpat)+1) {
174 fprintf(stderr, "end: regerror() test gave `%s' not `%s'\n",
175 erbuf, badpat);
176 status = 1;
177 }
178 ne = regerror(REG_BADPAT, (regex_t *)NULL, erbuf, (size_t)SHORT);
179 if (strncmp(erbuf, badpat, SHORT-1) != 0 || erbuf[SHORT-1] != '\0' ||
180 ne != strlen(badpat)+1) {
181 fprintf(stderr, "end: regerror() short test gave `%s' not `%.*s'\n",
182 erbuf, SHORT-1, badpat);
183 status = 1;
184 }
185 ne = regerror(REG_ITOA|REG_BADPAT, (regex_t *)NULL, erbuf, sizeof(erbuf));
186 if (strcmp(erbuf, bpname) != 0 || ne != strlen(bpname)+1) {
187 fprintf(stderr, "end: regerror() ITOA test gave `%s' not `%s'\n",
188 erbuf, bpname);
189 status = 1;
190 }
191 re.re_endp = bpname;
192 ne = regerror(REG_ATOI, &re, erbuf, sizeof(erbuf));
193 if (atoi(erbuf) != (int)REG_BADPAT) {
194 fprintf(stderr, "end: regerror() ATOI test gave `%s' not `%ld'\n",
195 erbuf, (long)REG_BADPAT);
196 status = 1;
197 } else if (ne != strlen(erbuf)+1) {
198 fprintf(stderr, "end: regerror() ATOI test len(`%s') = %ld\n",
199 erbuf, (long)REG_BADPAT);
200 status = 1;
201 }
202}
203
204/*
205 - try - try it, and report on problems
206 == void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts);
207 */
208void
209try(f0, f1, f2, f3, f4, opts)
210char *f0;
211char *f1;
212char *f2;
213char *f3;
214char *f4;
215int opts; /* may not match f1 */
216{
217 regex_t re;
218# define NSUBS 10
219 regmatch_t subs[NSUBS];
220# define NSHOULD 15
221 char *should[NSHOULD];
222 int nshould;
223 char erbuf[100];
224 int err;
225 int len;
226 char *type = (opts & REG_EXTENDED) ? "ERE" : "BRE";
227 register int i;
228 char *grump;
229 char f0copy[1000];
230 char f2copy[1000];
231
232 strcpy(f0copy, f0);
233 re.re_endp = (opts&REG_PEND) ? f0copy + strlen(f0copy) : NULL;
234 fixstr(f0copy);
235 err = regcomp(&re, f0copy, opts);
236 if (err != 0 && (!opt('C', f1) || err != efind(f2))) {
237 /* unexpected error or wrong error */
238 len = regerror(err, &re, erbuf, sizeof(erbuf));
239 fprintf(stderr, "%d: %s error %s, %d/%d `%s'\n",
240 line, type, eprint(err), len,
241 sizeof(erbuf), erbuf);
242 status = 1;
243 } else if (err == 0 && opt('C', f1)) {
244 /* unexpected success */
245 fprintf(stderr, "%d: %s should have given REG_%s\n",
246 line, type, f2);
247 status = 1;
248 err = 1; /* so we won't try regexec */
249 }
250
251 if (err != 0) {
252 regfree(&re);
253 return;
254 }
255
256 strcpy(f2copy, f2);
257 fixstr(f2copy);
258
259 if (options('e', f1)&REG_STARTEND) {
260 if (strchr(f2, '(') == NULL || strchr(f2, ')') == NULL)
261 fprintf(stderr, "%d: bad STARTEND syntax\n", line);
262 subs[0].rm_so = strchr(f2, '(') - f2 + 1;
263 subs[0].rm_eo = strchr(f2, ')') - f2;
264 }
265 err = regexec(&re, f2copy, NSUBS, subs, options('e', f1));
266
267 if (err != 0 && (f3 != NULL || err != REG_NOMATCH)) {
268 /* unexpected error or wrong error */
269 len = regerror(err, &re, erbuf, sizeof(erbuf));
270 fprintf(stderr, "%d: %s exec error %s, %d/%d `%s'\n",
271 line, type, eprint(err), len,
272 sizeof(erbuf), erbuf);
273 status = 1;
274 } else if (err != 0) {
275 /* nothing more to check */
276 } else if (f3 == NULL) {
277 /* unexpected success */
278 fprintf(stderr, "%d: %s exec should have failed\n",
279 line, type);
280 status = 1;
281 err = 1; /* just on principle */
282 } else if (opts&REG_NOSUB) {
283 /* nothing more to check */
284 } else if ((grump = check(f2, subs[0], f3)) != NULL) {
285 fprintf(stderr, "%d: %s %s\n", line, type, grump);
286 status = 1;
287 err = 1;
288 }
289
290 if (err != 0 || f4 == NULL) {
291 regfree(&re);
292 return;
293 }
294
295 for (i = 1; i < NSHOULD; i++)
296 should[i] = NULL;
297 nshould = split(f4, should+1, NSHOULD-1, ",");
298 if (nshould == 0) {
299 nshould = 1;
300 should[1] = "";
301 }
302 for (i = 1; i < NSUBS; i++) {
303 grump = check(f2, subs[i], should[i]);
304 if (grump != NULL) {
305 fprintf(stderr, "%d: %s $%d %s\n", line,
306 type, i, grump);
307 status = 1;
308 err = 1;
309 }
310 }
311
312 regfree(&re);
313}
314
315/*
316 - options - pick options out of a regression-test string
317 == int options(int type, char *s);
318 */
319int
320options(type, s)
321int type; /* 'c' compile, 'e' exec */
322char *s;
323{
324 register char *p;
325 register int o = (type == 'c') ? copts : eopts;
326 register char *legal = (type == 'c') ? "bisnmp" : "^$#tl";
327
328 for (p = s; *p != '\0'; p++)
329 if (strchr(legal, *p) != NULL)
330 switch (*p) {
331 case 'b':
332 o &= ~REG_EXTENDED;
333 break;
334 case 'i':
335 o |= REG_ICASE;
336 break;
337 case 's':
338 o |= REG_NOSUB;
339 break;
340 case 'n':
341 o |= REG_NEWLINE;
342 break;
343 case 'm':
344 o &= ~REG_EXTENDED;
345 o |= REG_NOSPEC;
346 break;
347 case 'p':
348 o |= REG_PEND;
349 break;
350 case '^':
351 o |= REG_NOTBOL;
352 break;
353 case '$':
354 o |= REG_NOTEOL;
355 break;
356 case '#':
357 o |= REG_STARTEND;
358 break;
359 case 't': /* trace */
360 o |= REG_TRACE;
361 break;
362 case 'l': /* force long representation */
363 o |= REG_LARGE;
364 break;
365 case 'r': /* force backref use */
366 o |= REG_BACKR;
367 break;
368 }
369 return(o);
370}
371
372/*
373 - opt - is a particular option in a regression string?
374 == int opt(int c, char *s);
375 */
376int /* predicate */
377opt(c, s)
378int c;
379char *s;
380{
381 return(strchr(s, c) != NULL);
382}
383
384/*
385 - fixstr - transform magic characters in strings
386 == void fixstr(register char *p);
387 */
388void
389fixstr(p)
390register char *p;
391{
392 if (p == NULL)
393 return;
394
395 for (; *p != '\0'; p++)
396 if (*p == 'N')
397 *p = '\n';
398 else if (*p == 'T')
399 *p = '\t';
400 else if (*p == 'S')
401 *p = ' ';
402 else if (*p == 'Z')
403 *p = '\0';
404}
405
406/*
407 - check - check a substring match
408 == char *check(char *str, regmatch_t sub, char *should);
409 */
410char * /* NULL or complaint */
411check(str, sub, should)
412char *str;
413regmatch_t sub;
414char *should;
415{
416 register int len;
417 register int shlen;
418 register char *p;
419 static char grump[500];
420 register char *at = NULL;
421
422 if (should != NULL && strcmp(should, "-") == 0)
423 should = NULL;
424 if (should != NULL && should[0] == '@') {
425 at = should + 1;
426 should = "";
427 }
428
429 /* check rm_so and rm_eo for consistency */
430 if (sub.rm_so > sub.rm_eo || (sub.rm_so == -1 && sub.rm_eo != -1) ||
431 (sub.rm_so != -1 && sub.rm_eo == -1) ||
432 (sub.rm_so != -1 && sub.rm_so < 0) ||
433 (sub.rm_eo != -1 && sub.rm_eo < 0) ) {
434 sprintf(grump, "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 sprintf(grump, "start %ld end %ld, past end of string",
448 (long)sub.rm_so, (long)sub.rm_eo);
449 return(grump);
450 }
451
452 len = (int)(sub.rm_eo - sub.rm_so);
453 shlen = (int)strlen(should);
454 p = str + sub.rm_so;
455
456 /* check for not supposed to match */
457 if (should == NULL) {
458 sprintf(grump, "matched `%.*s'", len, p);
459 return(grump);
460 }
461
462 /* check for wrong match */
463 if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) {
464 sprintf(grump, "matched `%.*s' instead", len, p);
465 return(grump);
466 }
467 if (shlen > 0)
468 return(NULL);
469
470 /* check null match in right place */
471 if (at == NULL)
472 return(NULL);
473 shlen = strlen(at);
474 if (shlen == 0)
475 shlen = 1; /* force check for end-of-string */
476 if (strncmp(p, at, shlen) != 0) {
477 sprintf(grump, "matched null at `%.20s'", p);
478 return(grump);
479 }
480 return(NULL);
481}
482
483/*
484 - eprint - convert error number to name
485 == static char *eprint(int err);
486 */
487static char *
488eprint(err)
489int err;
490{
491 static char epbuf[100];
492 size_t len;
493
494 len = regerror(REG_ITOA|err, (regex_t *)NULL, epbuf, sizeof(epbuf));
495 assert(len <= sizeof(epbuf));
496 return(epbuf);
497}
498
499/*
500 - efind - convert error name to number
501 == static int efind(char *name);
502 */
503static int
504efind(name)
505char *name;
506{
507 static char efbuf[100];
508 regex_t re;
509
510 sprintf(efbuf, "REG_%s", name);
511 assert(strlen(efbuf) < sizeof(efbuf));
512 re.re_endp = efbuf;
513 (void) regerror(REG_ATOI, &re, efbuf, sizeof(efbuf));
514 return(atoi(efbuf));
515}
diff --git a/src/regress/lib/libc/regex/main.ih b/src/regress/lib/libc/regex/main.ih
new file mode 100644
index 0000000000..135e3e792d
--- /dev/null
+++ b/src/regress/lib/libc/regex/main.ih
@@ -0,0 +1,21 @@
1/* $NetBSD: main.ih,v 1.2 1995/04/20 22:39:55 cgd Exp $ */
2
3/* ========= begin header generated by ./mkh ========= */
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8/* === main.c === */
9void regress __P((FILE *in));
10void try __P((char *f0, char *f1, char *f2, char *f3, char *f4, int opts));
11int options __P((int type, char *s));
12int opt __P((int c, char *s));
13void fixstr __P((register char *p));
14char *check __P((char *str, regmatch_t sub, char *should));
15static char *eprint __P((int err));
16static int efind __P((char *name));
17
18#ifdef __cplusplus
19}
20#endif
21/* ========= end header generated by ./mkh ========= */
diff --git a/src/regress/lib/libc/regex/split.c b/src/regress/lib/libc/regex/split.c
new file mode 100644
index 0000000000..dd1ca14480
--- /dev/null
+++ b/src/regress/lib/libc/regex/split.c
@@ -0,0 +1,318 @@
1/* $NetBSD: split.c,v 1.2 1995/04/20 22:39:57 cgd Exp $ */
2
3#include <stdio.h>
4#include <string.h>
5
6/*
7 - split - divide a string into fields, like awk split()
8 = int split(char *string, char *fields[], int nfields, char *sep);
9 */
10int /* number of fields, including overflow */
11split(string, fields, nfields, sep)
12char *string;
13char *fields[]; /* list is not NULL-terminated */
14int nfields; /* number of entries available in fields[] */
15char *sep; /* "" white, "c" single char, "ab" [ab]+ */
16{
17 register char *p = string;
18 register char c; /* latest character */
19 register char sepc = sep[0];
20 register char sepc2;
21 register int fn;
22 register char **fp = fields;
23 register char *sepp;
24 register int trimtrail;
25
26 /* white space */
27 if (sepc == '\0') {
28 while ((c = *p++) == ' ' || c == '\t')
29 continue;
30 p--;
31 trimtrail = 1;
32 sep = " \t"; /* note, code below knows this is 2 long */
33 sepc = ' ';
34 } else
35 trimtrail = 0;
36 sepc2 = sep[1]; /* now we can safely pick this up */
37
38 /* catch empties */
39 if (*p == '\0')
40 return(0);
41
42 /* single separator */
43 if (sepc2 == '\0') {
44 fn = nfields;
45 for (;;) {
46 *fp++ = p;
47 fn--;
48 if (fn == 0)
49 break;
50 while ((c = *p++) != sepc)
51 if (c == '\0')
52 return(nfields - fn);
53 *(p-1) = '\0';
54 }
55 /* we have overflowed the fields vector -- just count them */
56 fn = nfields;
57 for (;;) {
58 while ((c = *p++) != sepc)
59 if (c == '\0')
60 return(fn);
61 fn++;
62 }
63 /* not reached */
64 }
65
66 /* two separators */
67 if (sep[2] == '\0') {
68 fn = nfields;
69 for (;;) {
70 *fp++ = p;
71 fn--;
72 while ((c = *p++) != sepc && c != sepc2)
73 if (c == '\0') {
74 if (trimtrail && **(fp-1) == '\0')
75 fn++;
76 return(nfields - fn);
77 }
78 if (fn == 0)
79 break;
80 *(p-1) = '\0';
81 while ((c = *p++) == sepc || c == sepc2)
82 continue;
83 p--;
84 }
85 /* we have overflowed the fields vector -- just count them */
86 fn = nfields;
87 while (c != '\0') {
88 while ((c = *p++) == sepc || c == sepc2)
89 continue;
90 p--;
91 fn++;
92 while ((c = *p++) != '\0' && c != sepc && c != sepc2)
93 continue;
94 }
95 /* might have to trim trailing white space */
96 if (trimtrail) {
97 p--;
98 while ((c = *--p) == sepc || c == sepc2)
99 continue;
100 p++;
101 if (*p != '\0') {
102 if (fn == nfields+1)
103 *p = '\0';
104 fn--;
105 }
106 }
107 return(fn);
108 }
109
110 /* n separators */
111 fn = 0;
112 for (;;) {
113 if (fn < nfields)
114 *fp++ = p;
115 fn++;
116 for (;;) {
117 c = *p++;
118 if (c == '\0')
119 return(fn);
120 sepp = sep;
121 while ((sepc = *sepp++) != '\0' && sepc != c)
122 continue;
123 if (sepc != '\0') /* it was a separator */
124 break;
125 }
126 if (fn < nfields)
127 *(p-1) = '\0';
128 for (;;) {
129 c = *p++;
130 sepp = sep;
131 while ((sepc = *sepp++) != '\0' && sepc != c)
132 continue;
133 if (sepc == '\0') /* it wasn't a separator */
134 break;
135 }
136 p--;
137 }
138
139 /* not reached */
140}
141
142#ifdef TEST_SPLIT
143
144
145/*
146 * test program
147 * pgm runs regression
148 * pgm sep splits stdin lines by sep
149 * pgm str sep splits str by sep
150 * pgm str sep n splits str by sep n times
151 */
152int
153main(argc, argv)
154int argc;
155char *argv[];
156{
157 char buf[512];
158 register int n;
159# define MNF 10
160 char *fields[MNF];
161
162 if (argc > 4)
163 for (n = atoi(argv[3]); n > 0; n--) {
164 (void) strcpy(buf, argv[1]);
165 }
166 else if (argc > 3)
167 for (n = atoi(argv[3]); n > 0; n--) {
168 (void) strcpy(buf, argv[1]);
169 (void) split(buf, fields, MNF, argv[2]);
170 }
171 else if (argc > 2)
172 dosplit(argv[1], argv[2]);
173 else if (argc > 1)
174 while (fgets(buf, sizeof(buf), stdin) != NULL) {
175 buf[strlen(buf)-1] = '\0'; /* stomp newline */
176 dosplit(buf, argv[1]);
177 }
178 else
179 regress();
180
181 exit(0);
182}
183
184dosplit(string, seps)
185char *string;
186char *seps;
187{
188# define NF 5
189 char *fields[NF];
190 register int nf;
191
192 nf = split(string, fields, NF, seps);
193 print(nf, NF, fields);
194}
195
196print(nf, nfp, fields)
197int nf;
198int nfp;
199char *fields[];
200{
201 register int fn;
202 register int bound;
203
204 bound = (nf > nfp) ? nfp : nf;
205 printf("%d:\t", nf);
206 for (fn = 0; fn < bound; fn++)
207 printf("\"%s\"%s", fields[fn], (fn+1 < nf) ? ", " : "\n");
208}
209
210#define RNF 5 /* some table entries know this */
211struct {
212 char *str;
213 char *seps;
214 int nf;
215 char *fi[RNF];
216} tests[] = {
217 "", " ", 0, { "" },
218 " ", " ", 2, { "", "" },
219 "x", " ", 1, { "x" },
220 "xy", " ", 1, { "xy" },
221 "x y", " ", 2, { "x", "y" },
222 "abc def g ", " ", 5, { "abc", "def", "", "g", "" },
223 " a bcd", " ", 4, { "", "", "a", "bcd" },
224 "a b c d e f", " ", 6, { "a", "b", "c", "d", "e f" },
225 " a b c d ", " ", 6, { "", "a", "b", "c", "d " },
226
227 "", " _", 0, { "" },
228 " ", " _", 2, { "", "" },
229 "x", " _", 1, { "x" },
230 "x y", " _", 2, { "x", "y" },
231 "ab _ cd", " _", 2, { "ab", "cd" },
232 " a_b c ", " _", 5, { "", "a", "b", "c", "" },
233 "a b c_d e f", " _", 6, { "a", "b", "c", "d", "e f" },
234 " a b c d ", " _", 6, { "", "a", "b", "c", "d " },
235
236 "", " _~", 0, { "" },
237 " ", " _~", 2, { "", "" },
238 "x", " _~", 1, { "x" },
239 "x y", " _~", 2, { "x", "y" },
240 "ab _~ cd", " _~", 2, { "ab", "cd" },
241 " a_b c~", " _~", 5, { "", "a", "b", "c", "" },
242 "a b_c d~e f", " _~", 6, { "a", "b", "c", "d", "e f" },
243 "~a b c d ", " _~", 6, { "", "a", "b", "c", "d " },
244
245 "", " _~-", 0, { "" },
246 " ", " _~-", 2, { "", "" },
247 "x", " _~-", 1, { "x" },
248 "x y", " _~-", 2, { "x", "y" },
249 "ab _~- cd", " _~-", 2, { "ab", "cd" },
250 " a_b c~", " _~-", 5, { "", "a", "b", "c", "" },
251 "a b_c-d~e f", " _~-", 6, { "a", "b", "c", "d", "e f" },
252 "~a-b c d ", " _~-", 6, { "", "a", "b", "c", "d " },
253
254 "", " ", 0, { "" },
255 " ", " ", 2, { "", "" },
256 "x", " ", 1, { "x" },
257 "xy", " ", 1, { "xy" },
258 "x y", " ", 2, { "x", "y" },
259 "abc def g ", " ", 4, { "abc", "def", "g", "" },
260 " a bcd", " ", 3, { "", "a", "bcd" },
261 "a b c d e f", " ", 6, { "a", "b", "c", "d", "e f" },
262 " a b c d ", " ", 6, { "", "a", "b", "c", "d " },
263
264 "", "", 0, { "" },
265 " ", "", 0, { "" },
266 "x", "", 1, { "x" },
267 "xy", "", 1, { "xy" },
268 "x y", "", 2, { "x", "y" },
269 "abc def g ", "", 3, { "abc", "def", "g" },
270 "\t a bcd", "", 2, { "a", "bcd" },
271 " a \tb\t c ", "", 3, { "a", "b", "c" },
272 "a b c d e ", "", 5, { "a", "b", "c", "d", "e" },
273 "a b\tc d e f", "", 6, { "a", "b", "c", "d", "e f" },
274 " a b c d e f ", "", 6, { "a", "b", "c", "d", "e f " },
275
276 NULL, NULL, 0, { NULL },
277};
278
279regress()
280{
281 char buf[512];
282 register int n;
283 char *fields[RNF+1];
284 register int nf;
285 register int i;
286 register int printit;
287 register char *f;
288
289 for (n = 0; tests[n].str != NULL; n++) {
290 (void) strcpy(buf, tests[n].str);
291 fields[RNF] = NULL;
292 nf = split(buf, fields, RNF, tests[n].seps);
293 printit = 0;
294 if (nf != tests[n].nf) {
295 printf("split `%s' by `%s' gave %d fields, not %d\n",
296 tests[n].str, tests[n].seps, nf, tests[n].nf);
297 printit = 1;
298 } else if (fields[RNF] != NULL) {
299 printf("split() went beyond array end\n");
300 printit = 1;
301 } else {
302 for (i = 0; i < nf && i < RNF; i++) {
303 f = fields[i];
304 if (f == NULL)
305 f = "(NULL)";
306 if (strcmp(f, tests[n].fi[i]) != 0) {
307 printf("split `%s' by `%s', field %d is `%s', not `%s'\n",
308 tests[n].str, tests[n].seps,
309 i, fields[i], tests[n].fi[i]);
310 printit = 1;
311 }
312 }
313 }
314 if (printit)
315 print(nf, RNF, fields);
316 }
317}
318#endif
diff --git a/src/regress/lib/libc/regex/tests b/src/regress/lib/libc/regex/tests
new file mode 100644
index 0000000000..8e89f161b1
--- /dev/null
+++ b/src/regress/lib/libc/regex/tests
@@ -0,0 +1,477 @@
1# $NetBSD: tests,v 1.5 1995/04/20 22:40:00 cgd Exp $
2
3# regular expression test set
4# Lines are at least three fields, separated by one or more tabs. "" stands
5# for an empty field. First field is an RE. Second field is flags. If
6# C flag given, regcomp() is expected to fail, and the third field is the
7# error name (minus the leading REG_).
8#
9# Otherwise it is expected to succeed, and the third field is the string to
10# try matching it against. If there is no fourth field, the match is
11# expected to fail. If there is a fourth field, it is the substring that
12# the RE is expected to match. If there is a fifth field, it is a comma-
13# separated list of what the subexpressions should match, with - indicating
14# no match for that one. In both the fourth and fifth fields, a (sub)field
15# starting with @ indicates that the (sub)expression is expected to match
16# a null string followed by the stuff after the @; this provides a way to
17# test where null strings match. The character `N' in REs and strings
18# is newline, `S' is space, `T' is tab, `Z' is NUL.
19#
20# The full list of flags:
21# - placeholder, does nothing
22# b RE is a BRE, not an ERE
23# & try it as both an ERE and a BRE
24# C regcomp() error expected, third field is error name
25# i REG_ICASE
26# m ("mundane") REG_NOSPEC
27# s REG_NOSUB (not really testable)
28# n REG_NEWLINE
29# ^ REG_NOTBOL
30# $ REG_NOTEOL
31# # REG_STARTEND (see below)
32# p REG_PEND
33#
34# For REG_STARTEND, the start/end offsets are those of the substring
35# enclosed in ().
36
37# basics
38a & a a
39abc & abc abc
40abc|de - abc abc
41a|b|c - abc a
42
43# parentheses and perversions thereof
44a(b)c - abc abc
45a\(b\)c b abc abc
46a( C EPAREN
47a( b a( a(
48a\( - a( a(
49a\( bC EPAREN
50a\(b bC EPAREN
51a(b C EPAREN
52a(b b a(b a(b
53# gag me with a right parenthesis -- 1003.2 goofed here (my fault, partly)
54a) - a) a)
55) - ) )
56# end gagging (in a just world, those *should* give EPAREN)
57a) b a) a)
58a\) bC EPAREN
59\) bC EPAREN
60a()b - ab ab
61a\(\)b b ab ab
62
63# anchoring and REG_NEWLINE
64^abc$ & abc abc
65a^b - a^b
66a^b b a^b a^b
67a$b - a$b
68a$b b a$b a$b
69^ & abc @abc
70$ & abc @
71^$ & "" @
72$^ - "" @
73\($\)\(^\) b "" @
74# stop retching, those are legitimate (although disgusting)
75^^ - "" @
76$$ - "" @
77b$ & abNc
78b$ &n abNc b
79^b$ & aNbNc
80^b$ &n aNbNc b
81^$ &n aNNb @Nb
82^$ n abc
83^$ n abcN @
84$^ n aNNb @Nb
85\($\)\(^\) bn aNNb @Nb
86^^ n^ aNNb @Nb
87$$ n aNNb @NN
88^a ^ a
89a$ $ a
90^a ^n aNb
91^b ^n aNb b
92a$ $n bNa
93b$ $n bNa b
94a*(^b$)c* - b b
95a*\(^b$\)c* b b b
96
97# certain syntax errors and non-errors
98| C EMPTY
99| b | |
100* C BADRPT
101* b * *
102+ C BADRPT
103? C BADRPT
104"" &C EMPTY
105() - abc @abc
106\(\) b abc @abc
107a||b C EMPTY
108|ab C EMPTY
109ab| C EMPTY
110(|a)b C EMPTY
111(a|)b C EMPTY
112(*a) C BADRPT
113(+a) C BADRPT
114(?a) C BADRPT
115({1}a) C BADRPT
116\(\{1\}a\) bC BADRPT
117(a|*b) C BADRPT
118(a|+b) C BADRPT
119(a|?b) C BADRPT
120(a|{1}b) C BADRPT
121^* C BADRPT
122^* b * *
123^+ C BADRPT
124^? C BADRPT
125^{1} C BADRPT
126^\{1\} bC BADRPT
127
128# metacharacters, backslashes
129a.c & abc abc
130a[bc]d & abd abd
131a\*c & a*c a*c
132a\\b & a\b a\b
133a\\\*b & a\*b a\*b
134a\bc & abc abc
135a\ &C EESCAPE
136a\\bc & a\bc a\bc
137\{ bC BADRPT
138a\[b & a[b a[b
139a[b &C EBRACK
140# trailing $ is a peculiar special case for the BRE code
141a$ & a a
142a$ & a$
143a\$ & a
144a\$ & a$ a$
145a\\$ & a
146a\\$ & a$
147a\\$ & a\$
148a\\$ & a\ a\
149
150# back references, ugh
151a\(b\)\2c bC ESUBREG
152a\(b\1\)c bC ESUBREG
153a\(b*\)c\1d b abbcbbd abbcbbd bb
154a\(b*\)c\1d b abbcbd
155a\(b*\)c\1d b abbcbbbd
156^\(.\)\1 b abc
157a\([bc]\)\1d b abcdabbd abbd b
158a\(\([bc]\)\2\)*d b abbccd abbccd
159a\(\([bc]\)\2\)*d b abbcbd
160# actually, this next one probably ought to fail, but the spec is unclear
161a\(\(b\)*\2\)*d b abbbd abbbd
162# here is a case that no NFA implementation does right
163\(ab*\)[ab]*\1 b ababaaa ababaaa a
164# check out normal matching in the presence of back refs
165\(a\)\1bcd b aabcd aabcd
166\(a\)\1bc*d b aabcd aabcd
167\(a\)\1bc*d b aabd aabd
168\(a\)\1bc*d b aabcccd aabcccd
169\(a\)\1bc*[ce]d b aabcccd aabcccd
170^\(a\)\1b\(c\)*cd$ b aabcccd aabcccd
171
172# ordinary repetitions
173ab*c & abc abc
174ab+c - abc abc
175ab?c - abc abc
176a\(*\)b b a*b a*b
177a\(**\)b b ab ab
178a\(***\)b bC BADRPT
179*a b *a *a
180**a b a a
181***a bC BADRPT
182
183# the dreaded bounded repetitions
184{ & { {
185{abc & {abc {abc
186{1 C BADRPT
187{1} C BADRPT
188a{b & a{b a{b
189a{1}b - ab ab
190a\{1\}b b ab ab
191a{1,}b - ab ab
192a\{1,\}b b ab ab
193a{1,2}b - aab aab
194a\{1,2\}b b aab aab
195a{1 C EBRACE
196a\{1 bC EBRACE
197a{1a C EBRACE
198a\{1a bC EBRACE
199a{1a} C BADBR
200a\{1a\} bC BADBR
201a{,2} - a{,2} a{,2}
202a\{,2\} bC BADBR
203a{,} - a{,} a{,}
204a\{,\} bC BADBR
205a{1,x} C BADBR
206a\{1,x\} bC BADBR
207a{1,x C EBRACE
208a\{1,x bC EBRACE
209a{300} C BADBR
210a\{300\} bC BADBR
211a{1,0} C BADBR
212a\{1,0\} bC BADBR
213ab{0,0}c - abcac ac
214ab\{0,0\}c b abcac ac
215ab{0,1}c - abcac abc
216ab\{0,1\}c b abcac abc
217ab{0,3}c - abbcac abbc
218ab\{0,3\}c b abbcac abbc
219ab{1,1}c - acabc abc
220ab\{1,1\}c b acabc abc
221ab{1,3}c - acabc abc
222ab\{1,3\}c b acabc abc
223ab{2,2}c - abcabbc abbc
224ab\{2,2\}c b abcabbc abbc
225ab{2,4}c - abcabbc abbc
226ab\{2,4\}c b abcabbc abbc
227((a{1,10}){1,10}){1,10} - a a a,a
228
229# multiple repetitions
230a** &C BADRPT
231a++ C BADRPT
232a?? C BADRPT
233a*+ C BADRPT
234a*? C BADRPT
235a+* C BADRPT
236a+? C BADRPT
237a?* C BADRPT
238a?+ C BADRPT
239a{1}{1} C BADRPT
240a*{1} C BADRPT
241a+{1} C BADRPT
242a?{1} C BADRPT
243a{1}* C BADRPT
244a{1}+ C BADRPT
245a{1}? C BADRPT
246a*{b} - a{b} a{b}
247a\{1\}\{1\} bC BADRPT
248a*\{1\} bC BADRPT
249a\{1\}* bC BADRPT
250
251# brackets, and numerous perversions thereof
252a[b]c & abc abc
253a[ab]c & abc abc
254a[^ab]c & adc adc
255a[]b]c & a]c a]c
256a[[b]c & a[c a[c
257a[-b]c & a-c a-c
258a[^]b]c & adc adc
259a[^-b]c & adc adc
260a[b-]c & a-c a-c
261a[b &C EBRACK
262a[] &C EBRACK
263a[1-3]c & a2c a2c
264a[3-1]c &C ERANGE
265a[1-3-5]c &C ERANGE
266a[[.-.]--]c & a-c a-c
267a[1- &C ERANGE
268a[[. &C EBRACK
269a[[.x &C EBRACK
270a[[.x. &C EBRACK
271a[[.x.] &C EBRACK
272a[[.x.]] & ax ax
273a[[.x,.]] &C ECOLLATE
274a[[.one.]]b & a1b a1b
275a[[.notdef.]]b &C ECOLLATE
276a[[.].]]b & a]b a]b
277a[[:alpha:]]c & abc abc
278a[[:notdef:]]c &C ECTYPE
279a[[: &C EBRACK
280a[[:alpha &C EBRACK
281a[[:alpha:] &C EBRACK
282a[[:alpha,:] &C ECTYPE
283a[[:]:]]b &C ECTYPE
284a[[:-:]]b &C ECTYPE
285a[[:alph:]] &C ECTYPE
286a[[:alphabet:]] &C ECTYPE
287[[:alnum:]]+ - -%@a0X- a0X
288[[:alpha:]]+ - -%@aX0- aX
289[[:blank:]]+ - aSSTb SST
290[[:cntrl:]]+ - aNTb NT
291[[:digit:]]+ - a019b 019
292[[:graph:]]+ - Sa%bS a%b
293[[:lower:]]+ - AabC ab
294[[:print:]]+ - NaSbN aSb
295[[:punct:]]+ - S%-&T %-&
296[[:space:]]+ - aSNTb SNT
297[[:upper:]]+ - aBCd BC
298[[:xdigit:]]+ - p0f3Cq 0f3C
299a[[=b=]]c & abc abc
300a[[= &C EBRACK
301a[[=b &C EBRACK
302a[[=b= &C EBRACK
303a[[=b=] &C EBRACK
304a[[=b,=]] &C ECOLLATE
305a[[=one=]]b & a1b a1b
306
307# complexities
308a(((b)))c - abc abc
309a(b|(c))d - abd abd
310a(b*|c)d - abbd abbd
311# just gotta have one DFA-buster, of course
312a[ab]{20} - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab
313# and an inline expansion in case somebody gets tricky
314a[ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab][ab] - aaaaabaaaabaaaabaaaab aaaaabaaaabaaaabaaaab
315# and in case somebody just slips in an NFA...
316a[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
317# fish for anomalies as the number of states passes 32
31812345678901234567890123456789 - a12345678901234567890123456789b 12345678901234567890123456789
319123456789012345678901234567890 - a123456789012345678901234567890b 123456789012345678901234567890
3201234567890123456789012345678901 - a1234567890123456789012345678901b 1234567890123456789012345678901
32112345678901234567890123456789012 - a12345678901234567890123456789012b 12345678901234567890123456789012
322123456789012345678901234567890123 - a123456789012345678901234567890123b 123456789012345678901234567890123
323# and one really big one, beyond any plausible word width
3241234567890123456789012345678901234567890123456789012345678901234567890 - a1234567890123456789012345678901234567890123456789012345678901234567890b 1234567890123456789012345678901234567890123456789012345678901234567890
325# fish for problems as brackets go past 8
326[ab][cd][ef][gh][ij][kl][mn] - xacegikmoq acegikm
327[ab][cd][ef][gh][ij][kl][mn][op] - xacegikmoq acegikmo
328[ab][cd][ef][gh][ij][kl][mn][op][qr] - xacegikmoqy acegikmoq
329[ab][cd][ef][gh][ij][kl][mn][op][q] - xacegikmoqy acegikmoq
330
331# subtleties of matching
332abc & xabcy abc
333a\(b\)?c\1d b acd
334aBc i Abc Abc
335a[Bc]*d i abBCcd abBCcd
3360[[:upper:]]1 &i 0a1 0a1
3370[[:lower:]]1 &i 0A1 0A1
338a[^b]c &i abc
339a[^b]c &i aBc
340a[^b]c &i adc adc
341[a]b[c] - abc abc
342[a]b[a] - aba aba
343[abc]b[abc] - abc abc
344[abc]b[abd] - abd abd
345a(b?c)+d - accd accd
346(wee|week)(knights|night) - weeknights weeknights
347(we|wee|week|frob)(knights|night|day) - weeknights weeknights
348a[bc]d - xyzaaabcaababdacd abd
349a[ab]c - aaabc abc
350abc s abc abc
351a* & b @b
352
353# Let's have some fun -- try to match a C comment.
354# first the obvious, which looks okay at first glance...
355/\*.*\*/ - /*x*/ /*x*/
356# but...
357/\*.*\*/ - /*x*/y/*z*/ /*x*/y/*z*/
358# okay, we must not match */ inside; try to do that...
359/\*([^*]|\*[^/])*\*/ - /*x*/ /*x*/
360/\*([^*]|\*[^/])*\*/ - /*x*/y/*z*/ /*x*/
361# but...
362/\*([^*]|\*[^/])*\*/ - /*x**/y/*z*/ /*x**/y/*z*/
363# and a still fancier version, which does it right (I think)...
364/\*([^*]|\*+[^*/])*\*+/ - /*x*/ /*x*/
365/\*([^*]|\*+[^*/])*\*+/ - /*x*/y/*z*/ /*x*/
366/\*([^*]|\*+[^*/])*\*+/ - /*x**/y/*z*/ /*x**/
367/\*([^*]|\*+[^*/])*\*+/ - /*x****/y/*z*/ /*x****/
368/\*([^*]|\*+[^*/])*\*+/ - /*x**x*/y/*z*/ /*x**x*/
369/\*([^*]|\*+[^*/])*\*+/ - /*x***x/y/*z*/ /*x***x/y/*z*/
370
371# subexpressions
372a(b)(c)d - abcd abcd b,c
373a(((b)))c - abc abc b,b,b
374a(b|(c))d - abd abd b,-
375a(b*|c|e)d - abbd abbd bb
376a(b*|c|e)d - acd acd c
377a(b*|c|e)d - ad ad @d
378a(b?)c - abc abc b
379a(b?)c - ac ac @c
380a(b+)c - abc abc b
381a(b+)c - abbbc abbbc bbb
382a(b*)c - ac ac @c
383(a|ab)(bc([de]+)f|cde) - abcdef abcdef a,bcdef,de
384# the regression tester only asks for 9 subexpressions
385a(b)(c)(d)(e)(f)(g)(h)(i)(j)k - abcdefghijk abcdefghijk b,c,d,e,f,g,h,i,j
386a(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)l - abcdefghijkl abcdefghijkl b,c,d,e,f,g,h,i,j,k
387a([bc]?)c - abc abc b
388a([bc]?)c - ac ac @c
389a([bc]+)c - abc abc b
390a([bc]+)c - abcc abcc bc
391a([bc]+)bc - abcbc abcbc bc
392a(bb+|b)b - abb abb b
393a(bbb+|bb+|b)b - abb abb b
394a(bbb+|bb+|b)b - abbb abbb bb
395a(bbb+|bb+|b)bb - abbb abbb b
396(.*).* - abcdef abcdef abcdef
397(a*)* - bc @b @b
398
399# do we get the right subexpression when it is used more than once?
400a(b|c)*d - ad ad -
401a(b|c)*d - abcd abcd c
402a(b|c)+d - abd abd b
403a(b|c)+d - abcd abcd c
404a(b|c?)+d - ad ad @d
405a(b|c?)+d - abcd abcd @d
406a(b|c){0,0}d - ad ad -
407a(b|c){0,1}d - ad ad -
408a(b|c){0,1}d - abd abd b
409a(b|c){0,2}d - ad ad -
410a(b|c){0,2}d - abcd abcd c
411a(b|c){0,}d - ad ad -
412a(b|c){0,}d - abcd abcd c
413a(b|c){1,1}d - abd abd b
414a(b|c){1,1}d - acd acd c
415a(b|c){1,2}d - abd abd b
416a(b|c){1,2}d - abcd abcd c
417a(b|c){1,}d - abd abd b
418a(b|c){1,}d - abcd abcd c
419a(b|c){2,2}d - acbd acbd b
420a(b|c){2,2}d - abcd abcd c
421a(b|c){2,4}d - abcd abcd c
422a(b|c){2,4}d - abcbd abcbd b
423a(b|c){2,4}d - abcbcd abcbcd c
424a(b|c){2,}d - abcd abcd c
425a(b|c){2,}d - abcbd abcbd b
426a(b+|((c)*))+d - abd abd @d,@d,-
427a(b+|((c)*))+d - abcd abcd @d,@d,-
428
429# check out the STARTEND option
430[abc] &# a(b)c b
431[abc] &# a(d)c
432[abc] &# a(bc)d b
433[abc] &# a(dc)d c
434. &# a()c
435b.*c &# b(bc)c bc
436b.* &# b(bc)c bc
437.*c &# b(bc)c bc
438
439# plain strings, with the NOSPEC flag
440abc m abc abc
441abc m xabcy abc
442abc m xyz
443a*b m aba*b a*b
444a*b m ab
445"" mC EMPTY
446
447# cases involving NULs
448aZb & a a
449aZb &p a
450aZb &p# (aZb) aZb
451aZ*b &p# (ab) ab
452a.b &# (aZb) aZb
453a.* &# (aZb)c aZb
454
455# word boundaries (ick)
456[[:<:]]a & a a
457[[:<:]]a & ba
458[[:<:]]a & -a a
459a[[:>:]] & a a
460a[[:>:]] & ab
461a[[:>:]] & a- a
462[[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc abc
463[[:<:]]a.c[[:>:]] & axcd-dayc-dazce-abc-q abc
464[[:<:]]a.c[[:>:]] & axc-dayc-dazce-abc axc
465[[:<:]]b.c[[:>:]] & a_bxc-byc_d-bzc-q bzc
466[[:<:]].x..[[:>:]] & y_xa_-_xb_y-_xc_-axdc _xc_
467[[:<:]]a_b[[:>:]] & x_a_b
468
469# past problems, and suspected problems
470(A[1])|(A[2])|(A[3])|(A[4])|(A[5])|(A[6])|(A[7])|(A[8])|(A[9])|(A[A]) - A1 A1
471abcdefghijklmnop i abcdefghijklmnop abcdefghijklmnop
472abcdefghijklmnopqrstuv i abcdefghijklmnopqrstuv abcdefghijklmnopqrstuv
473(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
474CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a - CC11 CC11
475Char \([a-z0-9_]*\)\[.* b Char xyz[k Char xyz[k xyz
476a?b - ab ab
477-\{0,1\}[0-9]*$ b -5 -5