diff options
Diffstat (limited to 'usr.bin/tr/tr.c')
-rw-r--r-- | usr.bin/tr/tr.c | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/usr.bin/tr/tr.c b/usr.bin/tr/tr.c index 18905a23a79..bb9bfdc6e56 100644 --- a/usr.bin/tr/tr.c +++ b/usr.bin/tr/tr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tr.c,v 1.19 2015/10/09 01:37:09 deraadt Exp $ */ +/* $OpenBSD: tr.c,v 1.20 2021/11/02 15:45:52 cheloha Exp $ */ /* $NetBSD: tr.c,v 1.5 1995/08/31 22:13:48 jtc Exp $ */ /* @@ -85,7 +85,7 @@ int main(int argc, char *argv[]) { int ch, cnt, lastch, *p; - int cflag, dflag, sflag, isstring2; + int cflag, dflag, sflag; if (pledge("stdio", NULL) == -1) err(1, "pledge"); @@ -110,18 +110,8 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - switch(argc) { - case 0: - default: + if (argc < 1 || argc > 2) usage(); - /* NOTREACHED */ - case 1: - isstring2 = 0; - break; - case 2: - isstring2 = 1; - break; - } /* * tr -ds [-Cc] string1 string2 @@ -129,7 +119,7 @@ main(int argc, char *argv[]) * Squeeze all characters in string2. */ if (dflag && sflag) { - if (!isstring2) + if (argc != 2) usage(); setup(string1, argv[0], &s1, cflag); @@ -148,7 +138,7 @@ main(int argc, char *argv[]) * Delete all characters (or complemented characters) in string1. */ if (dflag) { - if (isstring2) + if (argc != 1) usage(); setup(string1, argv[0], &s1, cflag); @@ -163,7 +153,7 @@ main(int argc, char *argv[]) * tr -s [-Cc] string1 * Squeeze all characters (or complemented characters) in string1. */ - if (sflag && !isstring2) { + if (sflag && argc == 1) { setup(string1, argv[0], &s1, cflag); for (lastch = OOBCH; (ch = getchar()) != EOF;) @@ -180,7 +170,7 @@ main(int argc, char *argv[]) * the character in the same position in string2. If the -s option is * specified, squeeze all the characters in string2. */ - if (!isstring2) + if (argc != 2) usage(); s1.str = (unsigned char *)argv[0]; |