On Mon, Dec 05, 2022 at 06:37:49AM +1000, David Gwynne wrote: > On Sat, Dec 03, 2022 at 08:14:37PM -0600, Scott Cheloha wrote: > > There are nearly a hundred vestigial question mark cases in the > > top-level getopt(3) loops of various programs. You know, this: > > > > switch (ch) { > > /* ... */ > > case '?': > > default: > > usage(); > > } > > > > All of them are redundant and can be handled by the "default" case, > > which invariably fails the program. > > > > This patch covers bin, games, regress, sbin, usr.bin, and usr.sbin. I > > excluded the csh(1)/ksh(1) builtins. I also excluded nsd and unbound; > > they don't look domestic. gnu is also not domestic and is excluded. > > > > ok? > > mostly ok. can md5.c keep the switch statement and use default instead > of case '?'? everything else looks good.
md5 is an odd one. There are two getopt(3) loops. One for the -b flag and a second loop for everything else. I think the switch statement in the first loop, the -b flag loop, is misleading. We're only looking for the -b flag in that loop, so why do we have a switch statement? The second loop handles unexpected flags in the usual way. millert: any preferences? Index: md5.c =================================================================== RCS file: /cvs/src/bin/md5/md5.c,v retrieving revision 1.97 diff -u -p -r1.97 md5.c --- md5.c 19 Oct 2020 18:15:18 -0000 1.97 +++ md5.c 4 Dec 2022 21:56:26 -0000 @@ -230,13 +230,8 @@ main(int argc, char **argv) /* Check for -b option early since it changes behavior. */ while ((fl = getopt(argc, argv, optstr)) != -1) { - switch (fl) { - case 'b': + if (fl == 'b') bflag = 1; - break; - case '?': - usage(); - } } optind = 1; optreset = 1;