diff options
Diffstat (limited to 'src/regress/lib/libc/regex')
| -rw-r--r-- | src/regress/lib/libc/regex/Makefile | 10 | ||||
| -rw-r--r-- | src/regress/lib/libc/regex/debug.c | 7 | ||||
| -rw-r--r-- | src/regress/lib/libc/regex/debug.ih | 7 | ||||
| -rw-r--r-- | src/regress/lib/libc/regex/main.c | 42 | ||||
| -rw-r--r-- | src/regress/lib/libc/regex/main.ih | 17 | ||||
| -rw-r--r-- | src/regress/lib/libc/regex/split.c | 15 | ||||
| -rw-r--r-- | src/regress/lib/libc/regex/tests | 6 |
7 files changed, 60 insertions, 44 deletions
diff --git a/src/regress/lib/libc/regex/Makefile b/src/regress/lib/libc/regex/Makefile index 93b7bb9052..a29686bca4 100644 --- a/src/regress/lib/libc/regex/Makefile +++ b/src/regress/lib/libc/regex/Makefile | |||
| @@ -1,16 +1,20 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.5 2002/09/02 20:01:43 avsm Exp $ | ||
| 1 | # $NetBSD: Makefile,v 1.2 1995/02/16 19:38:45 cgd Exp $ | 2 | # $NetBSD: Makefile,v 1.2 1995/02/16 19:38:45 cgd Exp $ |
| 2 | 3 | ||
| 3 | PROG= re | 4 | PROG= re |
| 4 | SRCS= main.c split.c debug.c | 5 | SRCS= main.c split.c debug.c |
| 5 | NOMAN= | ||
| 6 | 6 | ||
| 7 | CFLAGS+= -I${.CURDIR}/../../../../lib/libc/regex | 7 | CFLAGS+= -I${.CURDIR}/../../../../lib/libc/regex |
| 8 | 8 | ||
| 9 | TESTS= ${.CURDIR}/tests | 9 | TESTS= ${.CURDIR}/tests |
| 10 | 10 | ||
| 11 | regress: | 11 | REGRESS_TARGETS=do-reg do-reg-long do-reg-backref |
| 12 | |||
| 13 | do-reg: ${PROG} | ||
| 12 | ./re < ${TESTS} | 14 | ./re < ${TESTS} |
| 15 | do-reg-long: ${PROG} | ||
| 13 | ./re -el < ${TESTS} | 16 | ./re -el < ${TESTS} |
| 17 | do-reg-backref: ${PROG} | ||
| 14 | ./re -er < ${TESTS} | 18 | ./re -er < ${TESTS} |
| 15 | 19 | ||
| 16 | .include <bsd.prog.mk> | 20 | .include <bsd.regress.mk> |
diff --git a/src/regress/lib/libc/regex/debug.c b/src/regress/lib/libc/regex/debug.c index 861f550611..11129e7249 100644 --- a/src/regress/lib/libc/regex/debug.c +++ b/src/regress/lib/libc/regex/debug.c | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | /* $OpenBSD: debug.c,v 1.4 2003/07/31 21:48:03 deraadt Exp $ */ | ||
| 1 | /* $NetBSD: debug.c,v 1.2 1995/04/20 22:39:42 cgd Exp $ */ | 2 | /* $NetBSD: debug.c,v 1.2 1995/04/20 22:39:42 cgd Exp $ */ |
| 2 | 3 | ||
| 3 | #include <stdio.h> | 4 | #include <stdio.h> |
| @@ -218,7 +219,7 @@ FILE *d; | |||
| 218 | fprintf(d, ">"); | 219 | fprintf(d, ">"); |
| 219 | break; | 220 | break; |
| 220 | default: | 221 | default: |
| 221 | fprintf(d, "!%d(%d)!", OP(*s), opnd); | 222 | fprintf(d, "!%ld(%ld)!", (long)OP(*s), (long)opnd); |
| 222 | break; | 223 | break; |
| 223 | } | 224 | } |
| 224 | if (!done) | 225 | if (!done) |
| @@ -237,8 +238,8 @@ int ch; | |||
| 237 | static char buf[10]; | 238 | static char buf[10]; |
| 238 | 239 | ||
| 239 | if (isprint(ch) || ch == ' ') | 240 | if (isprint(ch) || ch == ' ') |
| 240 | sprintf(buf, "%c", ch); | 241 | snprintf(buf, sizeof buf, "%c", ch); |
| 241 | else | 242 | else |
| 242 | sprintf(buf, "\\%o", ch); | 243 | snprintf(buf, sizeof buf, "\\%o", ch); |
| 243 | return(buf); | 244 | return(buf); |
| 244 | } | 245 | } |
diff --git a/src/regress/lib/libc/regex/debug.ih b/src/regress/lib/libc/regex/debug.ih index fb9bac0c75..9eb313af23 100644 --- a/src/regress/lib/libc/regex/debug.ih +++ b/src/regress/lib/libc/regex/debug.ih | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | /* $OpenBSD: debug.ih,v 1.3 2002/02/16 21:27:32 millert Exp $ */ | ||
| 1 | /* $NetBSD: debug.ih,v 1.2 1995/04/20 22:39:47 cgd Exp $ */ | 2 | /* $NetBSD: debug.ih,v 1.2 1995/04/20 22:39:47 cgd Exp $ */ |
| 2 | 3 | ||
| 3 | /* ========= begin header generated by ./mkh ========= */ | 4 | /* ========= begin header generated by ./mkh ========= */ |
| @@ -6,9 +7,9 @@ extern "C" { | |||
| 6 | #endif | 7 | #endif |
| 7 | 8 | ||
| 8 | /* === debug.c === */ | 9 | /* === debug.c === */ |
| 9 | void regprint __P((regex_t *r, FILE *d)); | 10 | void regprint(regex_t *r, FILE *d); |
| 10 | static void s_print __P((register struct re_guts *g, FILE *d)); | 11 | static void s_print(register struct re_guts *g, FILE *d); |
| 11 | static char *regchar __P((int ch)); | 12 | static char *regchar(int ch); |
| 12 | 13 | ||
| 13 | #ifdef __cplusplus | 14 | #ifdef __cplusplus |
| 14 | } | 15 | } |
diff --git a/src/regress/lib/libc/regex/main.c b/src/regress/lib/libc/regex/main.c index 8d88a8b9b8..fd092905fa 100644 --- a/src/regress/lib/libc/regex/main.c +++ b/src/regress/lib/libc/regex/main.c | |||
| @@ -1,10 +1,13 @@ | |||
| 1 | /* $OpenBSD: main.c,v 1.5 2004/02/28 08:06:46 deraadt Exp $ */ | ||
| 1 | /* $NetBSD: main.c,v 1.2 1995/04/20 22:39:51 cgd Exp $ */ | 2 | /* $NetBSD: main.c,v 1.2 1995/04/20 22:39:51 cgd Exp $ */ |
| 2 | 3 | ||
| 3 | #include <stdio.h> | 4 | #include <stdio.h> |
| 5 | #include <stdlib.h> | ||
| 4 | #include <string.h> | 6 | #include <string.h> |
| 5 | #include <sys/types.h> | 7 | #include <sys/types.h> |
| 6 | #include <regex.h> | 8 | #include <regex.h> |
| 7 | #include <assert.h> | 9 | #include <assert.h> |
| 10 | #include <unistd.h> | ||
| 8 | 11 | ||
| 9 | #include "main.ih" | 12 | #include "main.ih" |
| 10 | 13 | ||
| @@ -19,15 +22,15 @@ regoff_t startoff = 0; | |||
| 19 | regoff_t endoff = 0; | 22 | regoff_t endoff = 0; |
| 20 | 23 | ||
| 21 | 24 | ||
| 22 | extern int split(); | 25 | extern int split(char *, char *[], int, char *); |
| 23 | extern void regprint(); | 26 | extern void regprint(regex_t *, FILE *); |
| 24 | 27 | ||
| 25 | /* | 28 | /* |
| 26 | - main - do the simple case, hand off to regress() for regression | 29 | - main - do the simple case, hand off to regress() for regression |
| 27 | */ | 30 | */ |
| 28 | main(argc, argv) | 31 | int |
| 29 | int argc; | 32 | main(int argc, char *argv[]) |
| 30 | char *argv[]; | 33 | |
| 31 | { | 34 | { |
| 32 | regex_t re; | 35 | regex_t re; |
| 33 | # define NS 10 | 36 | # define NS 10 |
| @@ -43,7 +46,7 @@ char *argv[]; | |||
| 43 | 46 | ||
| 44 | progname = argv[0]; | 47 | progname = argv[0]; |
| 45 | 48 | ||
| 46 | while ((c = getopt(argc, argv, "c:e:S:E:x")) != EOF) | 49 | while ((c = getopt(argc, argv, "c:e:S:E:x")) != -1) |
| 47 | switch (c) { | 50 | switch (c) { |
| 48 | case 'c': /* compile options */ | 51 | case 'c': /* compile options */ |
| 49 | copts = options('c', optarg); | 52 | copts = options('c', optarg); |
| @@ -102,10 +105,10 @@ char *argv[]; | |||
| 102 | exit(status); | 105 | exit(status); |
| 103 | } | 106 | } |
| 104 | if (!(copts®_NOSUB)) { | 107 | if (!(copts®_NOSUB)) { |
| 105 | len = (int)(subs[0].rm_eo - subs[0].rm_so); | 108 | len = (size_t)(subs[0].rm_eo - subs[0].rm_so); |
| 106 | if (subs[0].rm_so != -1) { | 109 | if (subs[0].rm_so != -1) { |
| 107 | if (len != 0) | 110 | if (len != 0) |
| 108 | printf("match `%.*s'\n", len, | 111 | printf("match `%.*s'\n", (int)len, |
| 109 | argv[optind] + subs[0].rm_so); | 112 | argv[optind] + subs[0].rm_so); |
| 110 | else | 113 | else |
| 111 | printf("match `'@%.1s\n", | 114 | printf("match `'@%.1s\n", |
| @@ -225,7 +228,7 @@ int opts; /* may not match f1 */ | |||
| 225 | char f0copy[1000]; | 228 | char f0copy[1000]; |
| 226 | char f2copy[1000]; | 229 | char f2copy[1000]; |
| 227 | 230 | ||
| 228 | strcpy(f0copy, f0); | 231 | strlcpy(f0copy, f0, sizeof f0copy); |
| 229 | re.re_endp = (opts®_PEND) ? f0copy + strlen(f0copy) : NULL; | 232 | re.re_endp = (opts®_PEND) ? f0copy + strlen(f0copy) : NULL; |
| 230 | fixstr(f0copy); | 233 | fixstr(f0copy); |
| 231 | err = regcomp(&re, f0copy, opts); | 234 | err = regcomp(&re, f0copy, opts); |
| @@ -249,7 +252,7 @@ int opts; /* may not match f1 */ | |||
| 249 | return; | 252 | return; |
| 250 | } | 253 | } |
| 251 | 254 | ||
| 252 | strcpy(f2copy, f2); | 255 | strlcpy(f2copy, f2, sizeof f2copy); |
| 253 | fixstr(f2copy); | 256 | fixstr(f2copy); |
| 254 | 257 | ||
| 255 | if (options('e', f1)®_STARTEND) { | 258 | if (options('e', f1)®_STARTEND) { |
| @@ -427,8 +430,9 @@ char *should; | |||
| 427 | (sub.rm_so != -1 && sub.rm_eo == -1) || | 430 | (sub.rm_so != -1 && sub.rm_eo == -1) || |
| 428 | (sub.rm_so != -1 && sub.rm_so < 0) || | 431 | (sub.rm_so != -1 && sub.rm_so < 0) || |
| 429 | (sub.rm_eo != -1 && sub.rm_eo < 0) ) { | 432 | (sub.rm_eo != -1 && sub.rm_eo < 0) ) { |
| 430 | sprintf(grump, "start %ld end %ld", (long)sub.rm_so, | 433 | snprintf(grump, sizeof grump, |
| 431 | (long)sub.rm_eo); | 434 | "start %ld end %ld", (long)sub.rm_so, |
| 435 | (long)sub.rm_eo); | ||
| 432 | return(grump); | 436 | return(grump); |
| 433 | } | 437 | } |
| 434 | 438 | ||
| @@ -440,8 +444,9 @@ char *should; | |||
| 440 | 444 | ||
| 441 | /* check for in range */ | 445 | /* check for in range */ |
| 442 | if (sub.rm_eo > strlen(str)) { | 446 | if (sub.rm_eo > strlen(str)) { |
| 443 | sprintf(grump, "start %ld end %ld, past end of string", | 447 | snprintf(grump, sizeof grump, |
| 444 | (long)sub.rm_so, (long)sub.rm_eo); | 448 | "start %ld end %ld, past end of string", |
| 449 | (long)sub.rm_so, (long)sub.rm_eo); | ||
| 445 | return(grump); | 450 | return(grump); |
| 446 | } | 451 | } |
| 447 | 452 | ||
| @@ -451,13 +456,13 @@ char *should; | |||
| 451 | 456 | ||
| 452 | /* check for not supposed to match */ | 457 | /* check for not supposed to match */ |
| 453 | if (should == NULL) { | 458 | if (should == NULL) { |
| 454 | sprintf(grump, "matched `%.*s'", len, p); | 459 | snprintf(grump, sizeof grump, "matched `%.*s'", len, p); |
| 455 | return(grump); | 460 | return(grump); |
| 456 | } | 461 | } |
| 457 | 462 | ||
| 458 | /* check for wrong match */ | 463 | /* check for wrong match */ |
| 459 | if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) { | 464 | if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) { |
| 460 | sprintf(grump, "matched `%.*s' instead", len, p); | 465 | snprintf(grump, sizeof grump, "matched `%.*s' instead", len, p); |
| 461 | return(grump); | 466 | return(grump); |
| 462 | } | 467 | } |
| 463 | if (shlen > 0) | 468 | if (shlen > 0) |
| @@ -470,7 +475,7 @@ char *should; | |||
| 470 | if (shlen == 0) | 475 | if (shlen == 0) |
| 471 | shlen = 1; /* force check for end-of-string */ | 476 | shlen = 1; /* force check for end-of-string */ |
| 472 | if (strncmp(p, at, shlen) != 0) { | 477 | if (strncmp(p, at, shlen) != 0) { |
| 473 | sprintf(grump, "matched null at `%.20s'", p); | 478 | snprintf(grump, sizeof grump, "matched null at `%.20s'", p); |
| 474 | return(grump); | 479 | return(grump); |
| 475 | } | 480 | } |
| 476 | return(NULL); | 481 | return(NULL); |
| @@ -501,10 +506,9 @@ efind(name) | |||
| 501 | char *name; | 506 | char *name; |
| 502 | { | 507 | { |
| 503 | static char efbuf[100]; | 508 | static char efbuf[100]; |
| 504 | size_t n; | ||
| 505 | regex_t re; | 509 | regex_t re; |
| 506 | 510 | ||
| 507 | sprintf(efbuf, "REG_%s", name); | 511 | snprintf(efbuf, sizeof efbuf, "REG_%s", name); |
| 508 | assert(strlen(efbuf) < sizeof(efbuf)); | 512 | assert(strlen(efbuf) < sizeof(efbuf)); |
| 509 | re.re_endp = efbuf; | 513 | re.re_endp = efbuf; |
| 510 | (void) regerror(REG_ATOI, &re, efbuf, sizeof(efbuf)); | 514 | (void) regerror(REG_ATOI, &re, efbuf, sizeof(efbuf)); |
diff --git a/src/regress/lib/libc/regex/main.ih b/src/regress/lib/libc/regex/main.ih index 135e3e792d..0860e26333 100644 --- a/src/regress/lib/libc/regex/main.ih +++ b/src/regress/lib/libc/regex/main.ih | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | /* $OpenBSD: main.ih,v 1.3 2002/02/16 21:27:32 millert Exp $ */ | ||
| 1 | /* $NetBSD: main.ih,v 1.2 1995/04/20 22:39:55 cgd Exp $ */ | 2 | /* $NetBSD: main.ih,v 1.2 1995/04/20 22:39:55 cgd Exp $ */ |
| 2 | 3 | ||
| 3 | /* ========= begin header generated by ./mkh ========= */ | 4 | /* ========= begin header generated by ./mkh ========= */ |
| @@ -6,14 +7,14 @@ extern "C" { | |||
| 6 | #endif | 7 | #endif |
| 7 | 8 | ||
| 8 | /* === main.c === */ | 9 | /* === main.c === */ |
| 9 | void regress __P((FILE *in)); | 10 | void regress(FILE *in); |
| 10 | void try __P((char *f0, char *f1, char *f2, char *f3, char *f4, int opts)); | 11 | void try(char *f0, char *f1, char *f2, char *f3, char *f4, int opts); |
| 11 | int options __P((int type, char *s)); | 12 | int options(int type, char *s); |
| 12 | int opt __P((int c, char *s)); | 13 | int opt(int c, char *s); |
| 13 | void fixstr __P((register char *p)); | 14 | void fixstr(register char *p); |
| 14 | char *check __P((char *str, regmatch_t sub, char *should)); | 15 | char *check(char *str, regmatch_t sub, char *should); |
| 15 | static char *eprint __P((int err)); | 16 | static char *eprint(int err); |
| 16 | static int efind __P((char *name)); | 17 | static int efind(char *name); |
| 17 | 18 | ||
| 18 | #ifdef __cplusplus | 19 | #ifdef __cplusplus |
| 19 | } | 20 | } |
diff --git a/src/regress/lib/libc/regex/split.c b/src/regress/lib/libc/regex/split.c index dd1ca14480..f0f72c8b66 100644 --- a/src/regress/lib/libc/regex/split.c +++ b/src/regress/lib/libc/regex/split.c | |||
| @@ -1,18 +1,17 @@ | |||
| 1 | /* $OpenBSD: split.c,v 1.4 2004/02/28 08:06:47 deraadt Exp $ */ | ||
| 1 | /* $NetBSD: split.c,v 1.2 1995/04/20 22:39:57 cgd Exp $ */ | 2 | /* $NetBSD: split.c,v 1.2 1995/04/20 22:39:57 cgd Exp $ */ |
| 2 | 3 | ||
| 3 | #include <stdio.h> | 4 | #include <stdio.h> |
| 4 | #include <string.h> | 5 | #include <string.h> |
| 5 | 6 | ||
| 7 | int split(char *string, char *fields[], int nfields, char *sep); | ||
| 8 | |||
| 6 | /* | 9 | /* |
| 7 | - split - divide a string into fields, like awk split() | 10 | - split - divide a string into fields, like awk split() |
| 8 | = int split(char *string, char *fields[], int nfields, char *sep); | 11 | = int split(char *string, char *fields[], int nfields, char *sep); |
| 9 | */ | 12 | */ |
| 10 | int /* number of fields, including overflow */ | 13 | int /* number of fields, including overflow */ |
| 11 | split(string, fields, nfields, sep) | 14 | split(char *string, char *fields[], int nfields, char *sep) |
| 12 | char *string; | ||
| 13 | char *fields[]; /* list is not NULL-terminated */ | ||
| 14 | int nfields; /* number of entries available in fields[] */ | ||
| 15 | char *sep; /* "" white, "c" single char, "ab" [ab]+ */ | ||
| 16 | { | 15 | { |
| 17 | register char *p = string; | 16 | register char *p = string; |
| 18 | register char c; /* latest character */ | 17 | register char c; /* latest character */ |
| @@ -161,11 +160,11 @@ char *argv[]; | |||
| 161 | 160 | ||
| 162 | if (argc > 4) | 161 | if (argc > 4) |
| 163 | for (n = atoi(argv[3]); n > 0; n--) { | 162 | for (n = atoi(argv[3]); n > 0; n--) { |
| 164 | (void) strcpy(buf, argv[1]); | 163 | (void) strlcpy(buf, argv[1], sizeof buf); |
| 165 | } | 164 | } |
| 166 | else if (argc > 3) | 165 | else if (argc > 3) |
| 167 | for (n = atoi(argv[3]); n > 0; n--) { | 166 | for (n = atoi(argv[3]); n > 0; n--) { |
| 168 | (void) strcpy(buf, argv[1]); | 167 | (void) strlcpy(buf, argv[1], sizeof buf); |
| 169 | (void) split(buf, fields, MNF, argv[2]); | 168 | (void) split(buf, fields, MNF, argv[2]); |
| 170 | } | 169 | } |
| 171 | else if (argc > 2) | 170 | else if (argc > 2) |
| @@ -287,7 +286,7 @@ regress() | |||
| 287 | register char *f; | 286 | register char *f; |
| 288 | 287 | ||
| 289 | for (n = 0; tests[n].str != NULL; n++) { | 288 | for (n = 0; tests[n].str != NULL; n++) { |
| 290 | (void) strcpy(buf, tests[n].str); | 289 | (void) strlcpy(buf, tests[n].str, sizeof buf); |
| 291 | fields[RNF] = NULL; | 290 | fields[RNF] = NULL; |
| 292 | nf = split(buf, fields, RNF, tests[n].seps); | 291 | nf = split(buf, fields, RNF, tests[n].seps); |
| 293 | printit = 0; | 292 | printit = 0; |
diff --git a/src/regress/lib/libc/regex/tests b/src/regress/lib/libc/regex/tests index 8e89f161b1..3c1a51f8b4 100644 --- a/src/regress/lib/libc/regex/tests +++ b/src/regress/lib/libc/regex/tests | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | # $OpenBSD: tests,v 1.3 2004/04/02 18:35:54 otto Exp $ | ||
| 1 | # $NetBSD: tests,v 1.5 1995/04/20 22:40:00 cgd Exp $ | 2 | # $NetBSD: tests,v 1.5 1995/04/20 22:40:00 cgd Exp $ |
| 2 | 3 | ||
| 3 | # regular expression test set | 4 | # regular expression test set |
| @@ -168,6 +169,10 @@ a\(\(b\)*\2\)*d b abbbd abbbd | |||
| 168 | \(a\)\1bc*d b aabcccd aabcccd | 169 | \(a\)\1bc*d b aabcccd aabcccd |
| 169 | \(a\)\1bc*[ce]d b aabcccd aabcccd | 170 | \(a\)\1bc*[ce]d b aabcccd aabcccd |
| 170 | ^\(a\)\1b\(c\)*cd$ b aabcccd aabcccd | 171 | ^\(a\)\1b\(c\)*cd$ b aabcccd aabcccd |
| 172 | \(b*\)\(a*\1\)* b ab "" | ||
| 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 | ||
| 171 | 176 | ||
| 172 | # ordinary repetitions | 177 | # ordinary repetitions |
| 173 | ab*c & abc abc | 178 | ab*c & abc abc |
| @@ -475,3 +480,4 @@ CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a - CC11 CC11 | |||
| 475 | Char \([a-z0-9_]*\)\[.* b Char xyz[k Char xyz[k xyz | 480 | Char \([a-z0-9_]*\)\[.* b Char xyz[k Char xyz[k xyz |
| 476 | a?b - ab ab | 481 | a?b - ab ab |
| 477 | -\{0,1\}[0-9]*$ b -5 -5 | 482 | -\{0,1\}[0-9]*$ b -5 -5 |
| 483 | |||
