]> granicus.if.org Git - fortune-mod/commitdiff
Wrap C/etc. single-line blocks in { ... }
authorShlomi Fish <shlomif@shlomifish.org>
Fri, 17 Dec 2021 06:00:25 +0000 (08:00 +0200)
committerShlomi Fish <shlomif@shlomifish.org>
Fri, 17 Dec 2021 06:00:25 +0000 (08:00 +0200)
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
.

fortune-mod/util/getopt.c

index f65925427625c631152990d48ef40029cd558c1b..338910481bb9ad86c94458844dd13d81b6f740da 100644 (file)
@@ -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;
     }