diff options
author | Scott Soule Cheloha <cheloha@cvs.openbsd.org> | 2021-11-02 15:45:53 +0000 |
---|---|---|
committer | Scott Soule Cheloha <cheloha@cvs.openbsd.org> | 2021-11-02 15:45:53 +0000 |
commit | 2180ef3bb27eebaaddb2f0a0fa9431d132abbae7 (patch) | |
tree | dd7f8b97ee8d02ccf2101046df1d4d100d9b2eac | |
parent | a1a65f093bdd10ea7df8cb415169ba171719d754 (diff) |
tr(1): main(): eliminate isstring2 variable
If only there we a way to express how many positional arguments we
needed to run tr(1) in a given operating mode.
... oh. Wait. We have argc for that.
Remove the isstring2 variable to simplify some of the logic in main().
-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]; |