summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/regex
diff options
context:
space:
mode:
authorderaadt <>2003-07-31 21:48:04 +0000
committerderaadt <>2003-07-31 21:48:04 +0000
commit33c506bfed3ead4cc96819ce600895082c214755 (patch)
treef684ac5f268a986ffa67596e223c418beaac533a /src/regress/lib/libc/regex
parent1e17357c09b2a156a0fa1407b68c4158394b9d7e (diff)
downloadopenbsd-33c506bfed3ead4cc96819ce600895082c214755.tar.gz
openbsd-33c506bfed3ead4cc96819ce600895082c214755.tar.bz2
openbsd-33c506bfed3ead4cc96819ce600895082c214755.zip
various cleanups; david says results are same
Diffstat (limited to 'src/regress/lib/libc/regex')
-rw-r--r--src/regress/lib/libc/regex/debug.c6
-rw-r--r--src/regress/lib/libc/regex/main.c29
-rw-r--r--src/regress/lib/libc/regex/split.c10
3 files changed, 22 insertions, 23 deletions
diff --git a/src/regress/lib/libc/regex/debug.c b/src/regress/lib/libc/regex/debug.c
index 7834e970c7..11129e7249 100644
--- a/src/regress/lib/libc/regex/debug.c
+++ b/src/regress/lib/libc/regex/debug.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: debug.c,v 1.3 2001/01/29 02:05:43 niklas Exp $ */ 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 $ */ 2/* $NetBSD: debug.c,v 1.2 1995/04/20 22:39:42 cgd Exp $ */
3 3
4#include <stdio.h> 4#include <stdio.h>
@@ -238,8 +238,8 @@ int ch;
238 static char buf[10]; 238 static char buf[10];
239 239
240 if (isprint(ch) || ch == ' ') 240 if (isprint(ch) || ch == ' ')
241 sprintf(buf, "%c", ch); 241 snprintf(buf, sizeof buf, "%c", ch);
242 else 242 else
243 sprintf(buf, "\\%o", ch); 243 snprintf(buf, sizeof buf, "\\%o", ch);
244 return(buf); 244 return(buf);
245} 245}
diff --git a/src/regress/lib/libc/regex/main.c b/src/regress/lib/libc/regex/main.c
index 6e63ffc235..02f4bd7cf2 100644
--- a/src/regress/lib/libc/regex/main.c
+++ b/src/regress/lib/libc/regex/main.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: main.c,v 1.3 1997/01/15 23:41:07 millert Exp $ */ 1/* $OpenBSD: main.c,v 1.4 2003/07/31 21:48:03 deraadt Exp $ */
2/* $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 $ */
3 3
4#include <stdio.h> 4#include <stdio.h>
@@ -22,16 +22,15 @@ regoff_t startoff = 0;
22regoff_t endoff = 0; 22regoff_t endoff = 0;
23 23
24 24
25extern int split(); 25extern int split(char *, char *[], int, char *);
26extern void regprint(); 26extern void regprint(regex_t *, FILE *);
27 27
28/* 28/*
29 - main - do the simple case, hand off to regress() for regression 29 - main - do the simple case, hand off to regress() for regression
30 */ 30 */
31int 31int
32main(argc, argv) 32main(int argc, char *argv[])
33int argc; 33
34char *argv[];
35{ 34{
36 regex_t re; 35 regex_t re;
37# define NS 10 36# define NS 10
@@ -431,8 +430,9 @@ char *should;
431 (sub.rm_so != -1 && sub.rm_eo == -1) || 430 (sub.rm_so != -1 && sub.rm_eo == -1) ||
432 (sub.rm_so != -1 && sub.rm_so < 0) || 431 (sub.rm_so != -1 && sub.rm_so < 0) ||
433 (sub.rm_eo != -1 && sub.rm_eo < 0) ) { 432 (sub.rm_eo != -1 && sub.rm_eo < 0) ) {
434 sprintf(grump, "start %ld end %ld", (long)sub.rm_so, 433 snprintf(grump, sizeof grump,
435 (long)sub.rm_eo); 434 "start %ld end %ld", (long)sub.rm_so,
435 (long)sub.rm_eo);
436 return(grump); 436 return(grump);
437 } 437 }
438 438
@@ -444,8 +444,9 @@ char *should;
444 444
445 /* check for in range */ 445 /* check for in range */
446 if (sub.rm_eo > strlen(str)) { 446 if (sub.rm_eo > strlen(str)) {
447 sprintf(grump, "start %ld end %ld, past end of string", 447 snprintf(grump, sizeof grump,
448 (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);
449 return(grump); 450 return(grump);
450 } 451 }
451 452
@@ -455,13 +456,13 @@ char *should;
455 456
456 /* check for not supposed to match */ 457 /* check for not supposed to match */
457 if (should == NULL) { 458 if (should == NULL) {
458 sprintf(grump, "matched `%.*s'", len, p); 459 snprintf(grump, sizeof grump, "matched `%.*s'", len, p);
459 return(grump); 460 return(grump);
460 } 461 }
461 462
462 /* check for wrong match */ 463 /* check for wrong match */
463 if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) { 464 if (len != shlen || strncmp(p, should, (size_t)shlen) != 0) {
464 sprintf(grump, "matched `%.*s' instead", len, p); 465 snprintf(grump, sizeof grump, "matched `%.*s' instead", len, p);
465 return(grump); 466 return(grump);
466 } 467 }
467 if (shlen > 0) 468 if (shlen > 0)
@@ -474,7 +475,7 @@ char *should;
474 if (shlen == 0) 475 if (shlen == 0)
475 shlen = 1; /* force check for end-of-string */ 476 shlen = 1; /* force check for end-of-string */
476 if (strncmp(p, at, shlen) != 0) { 477 if (strncmp(p, at, shlen) != 0) {
477 sprintf(grump, "matched null at `%.20s'", p); 478 snprintf(grump, sizeof grump, "matched null at `%.20s'", p);
478 return(grump); 479 return(grump);
479 } 480 }
480 return(NULL); 481 return(NULL);
@@ -507,7 +508,7 @@ char *name;
507 static char efbuf[100]; 508 static char efbuf[100];
508 regex_t re; 509 regex_t re;
509 510
510 sprintf(efbuf, "REG_%s", name); 511 snprintf(efbuf, sizeof efbuf, "REG_%s", name);
511 assert(strlen(efbuf) < sizeof(efbuf)); 512 assert(strlen(efbuf) < sizeof(efbuf));
512 re.re_endp = efbuf; 513 re.re_endp = efbuf;
513 (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/split.c b/src/regress/lib/libc/regex/split.c
index 52cb6c681e..1e17a55b89 100644
--- a/src/regress/lib/libc/regex/split.c
+++ b/src/regress/lib/libc/regex/split.c
@@ -1,19 +1,17 @@
1/* $OpenBSD: split.c,v 1.2 2001/01/29 02:05:44 niklas Exp $ */ 1/* $OpenBSD: split.c,v 1.3 2003/07/31 21:48:03 deraadt Exp $ */
2/* $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 $ */
3 3
4#include <stdio.h> 4#include <stdio.h>
5#include <string.h> 5#include <string.h>
6 6
7int split(char *string, char *fields[], int nfields, char *sep);
8
7/* 9/*
8 - split - divide a string into fields, like awk split() 10 - split - divide a string into fields, like awk split()
9 = int split(char *string, char *fields[], int nfields, char *sep); 11 = int split(char *string, char *fields[], int nfields, char *sep);
10 */ 12 */
11int /* number of fields, including overflow */ 13int /* number of fields, including overflow */
12split(string, fields, nfields, sep) 14split(char *string, char *fields[], int nfields, char *sep)
13char *string;
14char *fields[]; /* list is not NULL-terminated */
15int nfields; /* number of entries available in fields[] */
16char *sep; /* "" white, "c" single char, "ab" [ab]+ */
17{ 15{
18 register char *p = string; 16 register char *p = string;
19 register char c; /* latest character */ 17 register char c; /* latest character */