diff options
| author | lukem <lukem@NetBSD.org> | 1997-10-20 00:56:04 +0000 |
|---|---|---|
| committer | lukem <lukem@NetBSD.org> | 1997-10-20 00:56:04 +0000 |
| commit | 7e4d6ea181ef5489c58ade84a43bf122c128e188 (patch) | |
| tree | f33ce2f310d79beff31e9ae9989f4655f7748940 /usr.bin/tr | |
| parent | e5a1e707a32339395c1fa92c8d0e322416b96226 (diff) | |
WARNSify, fix .Nm usage, getopt returns -1 not EOF, use <err.h>
Diffstat (limited to 'usr.bin/tr')
| -rw-r--r-- | usr.bin/tr/extern.h | 3 | ||||
| -rw-r--r-- | usr.bin/tr/str.c | 39 | ||||
| -rw-r--r-- | usr.bin/tr/tr.1 | 20 | ||||
| -rw-r--r-- | usr.bin/tr/tr.c | 51 |
4 files changed, 44 insertions, 69 deletions
diff --git a/usr.bin/tr/extern.h b/usr.bin/tr/extern.h index df0fe4bc686..6e5f2c45c58 100644 --- a/usr.bin/tr/extern.h +++ b/usr.bin/tr/extern.h @@ -1,4 +1,4 @@ -/* $NetBSD: extern.h,v 1.4 1995/11/01 00:45:22 pk Exp $ */ +/* $NetBSD: extern.h,v 1.5 1997/10/20 00:56:04 lukem Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -49,5 +49,4 @@ typedef struct { #define NCHARS (UCHAR_MAX + 1) /* Number of possible characters. */ #define OOBCH (UCHAR_MAX + 1) /* Out of band character value. */ -void err __P((const char *fmt, ...)); int next __P((STR *)); diff --git a/usr.bin/tr/str.c b/usr.bin/tr/str.c index bec54a12864..1e5a8f9cc8e 100644 --- a/usr.bin/tr/str.c +++ b/usr.bin/tr/str.c @@ -1,4 +1,4 @@ -/* $NetBSD: str.c,v 1.7 1995/08/31 22:13:47 jtc Exp $ */ +/* $NetBSD: str.c,v 1.8 1997/10/20 00:56:05 lukem Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -33,16 +33,18 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint #if 0 static char sccsid[] = "@(#)str.c 8.2 (Berkeley) 4/28/95"; #endif -static char rcsid[] = "$NetBSD: str.c,v 1.7 1995/08/31 22:13:47 jtc Exp $"; +__RCSID("$NetBSD: str.c,v 1.8 1997/10/20 00:56:05 lukem Exp $"); #endif /* not lint */ #include <sys/cdefs.h> #include <sys/types.h> +#include <err.h> #include <errno.h> #include <stddef.h> #include <stdio.h> @@ -62,9 +64,9 @@ static void genseq __P((STR *)); int next(s) - register STR *s; + STR *s; { - register int ch; + int ch; switch (s->state) { case EOS: @@ -114,13 +116,14 @@ next(s) return (1); } /* NOTREACHED */ + return (0); } static int bracket(s) - register STR *s; + STR *s; { - register char *p; + char *p; switch (s->str[1]) { case ':': /* "[:class:]" */ @@ -140,7 +143,7 @@ bracket(s) default: /* "[\###*n]" or "[#*n]" */ if ((p = strpbrk(s->str + 2, "*]")) == NULL) return (0); - if (p[0] != '*' || index(p, ']') == NULL) + if (p[0] != '*' || strchr(p, ']') == NULL) return (0); s->str += 1; genseq(s); @@ -174,18 +177,18 @@ static void genclass(s) STR *s; { - register int cnt, (*func) __P((int)); + int cnt, (*func) __P((int)); CLASS *cp, tmp; int *p; tmp.name = s->str; if ((cp = (CLASS *)bsearch(&tmp, classes, sizeof(classes) / sizeof(CLASS), sizeof(CLASS), c_class)) == NULL) - err("unknown class %s", s->str); + errx(1, "unknown class %s", s->str); if ((cp->set = p = malloc((NCHARS + 1) * sizeof(int))) == NULL) - err("%s", strerror(errno)); - bzero(p, (NCHARS + 1) * sizeof(int)); + err(1, "malloc"); + memset(p, 0, (NCHARS + 1) * sizeof(int)); for (cnt = 0, func = cp->func; cnt < NCHARS; ++cnt) if ((func)(cnt)) *p++ = cnt; @@ -214,11 +217,11 @@ genequiv(s) if (*s->str == '\\') { s->equiv[0] = backslash(s); if (*s->str != '=') - err("misplaced equivalence equals sign"); + errx(1, "misplaced equivalence equals sign"); } else { s->equiv[0] = s->str[0]; if (s->str[1] != '=') - err("misplaced equivalence equals sign"); + errx(1, "misplaced equivalence equals sign"); } s->str += 2; s->cnt = 0; @@ -252,14 +255,14 @@ genseq(s) char *ep; if (s->which == STRING1) - err("sequences only valid in string2"); + errx(1, "sequences only valid in string2"); if (*s->str == '\\') s->lastch = backslash(s); else s->lastch = *s->str++; if (*s->str != '*') - err("misplaced sequence asterisk"); + errx(1, "misplaced sequence asterisk"); switch (*++s->str) { case '\\': @@ -277,7 +280,7 @@ genseq(s) break; } } - err("illegal sequence count"); + errx(1, "illegal sequence count"); /* NOTREACHED */ } @@ -290,9 +293,9 @@ genseq(s) */ static int backslash(s) - register STR *s; + STR *s; { - register int ch, cnt, val; + int ch, cnt, val; for (cnt = val = 0;;) { ch = *++s->str; diff --git a/usr.bin/tr/tr.1 b/usr.bin/tr/tr.1 index 42a131ff34d..a1862fd7589 100644 --- a/usr.bin/tr/tr.1 +++ b/usr.bin/tr/tr.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: tr.1,v 1.5 1994/12/07 08:35:13 jtc Exp $ +.\" $NetBSD: tr.1,v 1.6 1997/10/20 00:56:05 lukem Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -43,24 +43,24 @@ .Nm tr .Nd translate characters .Sh SYNOPSIS -.Nm tr +.Nm .Op Fl cs .Ar string1 string2 -.Nm tr +.Nm "" .Op Fl c .Fl d .Ar string1 -.Nm tr +.Nm "" .Op Fl c .Fl s .Ar string1 -.Nm tr +.Nm "" .Op Fl c .Fl ds .Ar string1 string2 .Sh DESCRIPTION The -.Nm tr +.Nm utility copies the standard input to the standard output with substitution or deletion of selected characters. .Pp @@ -228,7 +228,7 @@ it's interpreted as a decimal value. .El .Pp The -.Nm tr +.Nm utility exits 0 on success, and >0 if an error occurs. .Sh EXAMPLES The following examples are shown as given to the shell: @@ -264,13 +264,13 @@ represent the three characters ``a'', ``-'' and ``z'' will have to be rewritten as ``a\e-z''. .Pp The -.Nm tr +.Nm utility has historically not permitted the manipulation of NUL bytes in its input and, additionally, stripped NUL's from its input stream. This implementation has removed this behavior as a bug. .Pp The -.Nm tr +.Nm utility has historically been extremely forgiving of syntax errors, for example, the .Fl c @@ -280,7 +280,7 @@ options were ignored unless two strings were specified. This implementation will not permit illegal syntax. .Sh STANDARDS The -.Nm tr +.Nm utility is expected to be .St -p1003.2 compatible. diff --git a/usr.bin/tr/tr.c b/usr.bin/tr/tr.c index 1eb114651cb..ed546a05b2c 100644 --- a/usr.bin/tr/tr.c +++ b/usr.bin/tr/tr.c @@ -1,4 +1,4 @@ -/* $NetBSD: tr.c,v 1.5 1995/08/31 22:13:48 jtc Exp $ */ +/* $NetBSD: tr.c,v 1.6 1997/10/20 00:56:06 lukem Exp $ */ /* * Copyright (c) 1988, 1993 @@ -33,21 +33,22 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1988, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; +__COPYRIGHT("@(#) Copyright (c) 1988, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95"; #endif -static char rcsid[] = "$NetBSD: tr.c,v 1.5 1995/08/31 22:13:48 jtc Exp $"; +__RCSID("$NetBSD: tr.c,v 1.6 1997/10/20 00:56:06 lukem Exp $"); #endif /* not lint */ #include <sys/types.h> +#include <err.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -93,6 +94,7 @@ static int string1[NCHARS] = { STR s1 = { STRING1, NORMAL, 0, OOBCH, { 0, OOBCH }, NULL, NULL }; STR s2 = { STRING2, NORMAL, 0, OOBCH, { 0, OOBCH }, NULL, NULL }; +int main __P((int, char **)); static void setup __P((int *, char *, STR *, int)); static void usage __P((void)); @@ -101,11 +103,11 @@ main(argc, argv) int argc; char **argv; { - register int ch, cnt, lastch, *p; + int ch, cnt, lastch, *p; int cflag, dflag, sflag, isstring2; cflag = dflag = sflag = 0; - while ((ch = getopt(argc, argv, "cds")) != EOF) + while ((ch = getopt(argc, argv, "cds")) != -1) switch((char)ch) { case 'c': cflag = 1; @@ -204,7 +206,7 @@ main(argc, argv) *p++ = OOBCH; if (!next(&s2)) - err("empty string2"); + errx(1, "empty string2"); /* If string2 runs out of characters, use the last one specified. */ if (sflag) @@ -244,10 +246,10 @@ setup(string, arg, str, cflag) STR *str; int cflag; { - register int cnt, *p; + int cnt, *p; str->str = arg; - bzero(string, NCHARS * sizeof(int)); + memset(string, 0, NCHARS * sizeof(int)); while (next(str)) string[str->lastch] = 1; if (cflag) @@ -264,32 +266,3 @@ usage() (void)fprintf(stderr, " tr [-c] -ds string1 string2\n"); exit(1); } - -#if __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif - -void -#if __STDC__ -err(const char *fmt, ...) -#else -err(fmt, va_alist) - char *fmt; - va_dcl -#endif -{ - va_list ap; -#if __STDC__ - va_start(ap, fmt); -#else - va_start(ap); -#endif - (void)fprintf(stderr, "tr: "); - (void)vfprintf(stderr, fmt, ap); - va_end(ap); - (void)fprintf(stderr, "\n"); - exit(1); - /* NOTREACHED */ -} |
