From: Shlomi Fish Date: Fri, 17 Dec 2021 06:00:25 +0000 (+0200) Subject: Wrap C/etc. single-line blocks in { ... } X-Git-Tag: fortune-mod-3.12.0~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1e73c2354751be8871f5e1077abc1370f9d2dc2f;p=fortune-mod Wrap C/etc. single-line blocks in { ... } Of if / else / while / for / etc. It is less errorprone this way. See: * https://fc-solve.shlomifish.org/docs/distro/HACKING.html#one-line-clauses * https://medium.com/@jonathanabrams/single-line-if-statements-2565c62ff492 . --- diff --git a/fortune-mod/util/getopt.c b/fortune-mod/util/getopt.c index f659254..3389104 100644 --- a/fortune-mod/util/getopt.c +++ b/fortune-mod/util/getopt.c @@ -77,23 +77,33 @@ int getopt(int nargc, char *const nargv[], const char *ostr) * assume it means -1. */ if (optopt == (int)'-') + { return (-1); + } if (!*place) + { ++optind; + } if (opterr && *ostr != ':') + { (void)printf("illegal option -- %c\n", optopt); + } return (BADCH); } if (*++oli != ':') { /* don't need argument */ optarg = NULL; if (!*place) + { ++optind; + } } else { /* need an argument */ if (*place) /* no white space */ + { optarg = place; + } else if (nargc <= ++optind) { /* no arg */ place = EMSG; @@ -108,7 +118,9 @@ int getopt(int nargc, char *const nargv[], const char *ostr) return (BADCH); } else /* white space */ + { optarg = nargv[optind]; + } place = EMSG; ++optind; }