diff options
Diffstat (limited to 'src/regress/lib/libc/regex/main.c')
-rw-r--r-- | src/regress/lib/libc/regex/main.c | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/src/regress/lib/libc/regex/main.c b/src/regress/lib/libc/regex/main.c index 8d88a8b9b8..e0ed86f5e8 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.7 2007/09/12 19:32:35 otto 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); |
@@ -79,7 +82,7 @@ char *argv[]; | |||
79 | err = regcomp(&re, argv[optind++], copts); | 82 | err = regcomp(&re, argv[optind++], copts); |
80 | if (err) { | 83 | if (err) { |
81 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | 84 | len = regerror(err, &re, erbuf, sizeof(erbuf)); |
82 | fprintf(stderr, "error %s, %d/%d `%s'\n", | 85 | fprintf(stderr, "error %s, %zu/%zu `%s'\n", |
83 | eprint(err), len, sizeof(erbuf), erbuf); | 86 | eprint(err), len, sizeof(erbuf), erbuf); |
84 | exit(status); | 87 | exit(status); |
85 | } | 88 | } |
@@ -97,15 +100,15 @@ char *argv[]; | |||
97 | err = regexec(&re, argv[optind], (size_t)NS, subs, eopts); | 100 | err = regexec(&re, argv[optind], (size_t)NS, subs, eopts); |
98 | if (err) { | 101 | if (err) { |
99 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | 102 | len = regerror(err, &re, erbuf, sizeof(erbuf)); |
100 | fprintf(stderr, "error %s, %d/%d `%s'\n", | 103 | fprintf(stderr, "error %s, %zu/%zu `%s'\n", |
101 | eprint(err), len, sizeof(erbuf), erbuf); | 104 | eprint(err), len, sizeof(erbuf), erbuf); |
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", |
@@ -144,7 +147,7 @@ FILE *in; | |||
144 | line++; | 147 | line++; |
145 | if (inbuf[0] == '#' || inbuf[0] == '\n') | 148 | if (inbuf[0] == '#' || inbuf[0] == '\n') |
146 | continue; /* NOTE CONTINUE */ | 149 | continue; /* NOTE CONTINUE */ |
147 | inbuf[strlen(inbuf)-1] = '\0'; /* get rid of stupid \n */ | 150 | inbuf[strcspn(inbuf, "\n")] = '\0'; /* get rid of stupid \n */ |
148 | if (debug) | 151 | if (debug) |
149 | fprintf(stdout, "%d:\n", line); | 152 | fprintf(stdout, "%d:\n", line); |
150 | nf = split(inbuf, f, MAXF, "\t\t"); | 153 | nf = split(inbuf, f, MAXF, "\t\t"); |
@@ -225,14 +228,14 @@ 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); |
232 | if (err != 0 && (!opt('C', f1) || err != efind(f2))) { | 235 | if (err != 0 && (!opt('C', f1) || err != efind(f2))) { |
233 | /* unexpected error or wrong error */ | 236 | /* unexpected error or wrong error */ |
234 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | 237 | len = regerror(err, &re, erbuf, sizeof(erbuf)); |
235 | fprintf(stderr, "%d: %s error %s, %d/%d `%s'\n", | 238 | fprintf(stderr, "%d: %s error %s, %d/%zu `%s'\n", |
236 | line, type, eprint(err), len, | 239 | line, type, eprint(err), len, |
237 | sizeof(erbuf), erbuf); | 240 | sizeof(erbuf), erbuf); |
238 | status = 1; | 241 | status = 1; |
@@ -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) { |
@@ -263,7 +266,7 @@ int opts; /* may not match f1 */ | |||
263 | if (err != 0 && (f3 != NULL || err != REG_NOMATCH)) { | 266 | if (err != 0 && (f3 != NULL || err != REG_NOMATCH)) { |
264 | /* unexpected error or wrong error */ | 267 | /* unexpected error or wrong error */ |
265 | len = regerror(err, &re, erbuf, sizeof(erbuf)); | 268 | len = regerror(err, &re, erbuf, sizeof(erbuf)); |
266 | fprintf(stderr, "%d: %s exec error %s, %d/%d `%s'\n", | 269 | fprintf(stderr, "%d: %s exec error %s, %d/%zu `%s'\n", |
267 | line, type, eprint(err), len, | 270 | line, type, eprint(err), len, |
268 | sizeof(erbuf), erbuf); | 271 | sizeof(erbuf), erbuf); |
269 | status = 1; | 272 | status = 1; |
@@ -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)); |