Convert getopt.c to K&R style.
authorDavid Griffith <dave@661.org>
Sat, 21 Sep 2019 22:52:39 +0000 (15:52 -0700)
committerDavid Griffith <dave@661.org>
Mon, 23 Sep 2019 00:48:04 +0000 (17:48 -0700)
src/common/getopt.c

index 415fcde288cda39b8254859e3ac4f99f8c9a766f..efe99af648c2bb1f1c7fb4f95061e28a381c360e 100644 (file)
@@ -22,51 +22,43 @@ const char *optarg = NULL;
 
 int cdecl getopt (int argc, char *argv[], const char *options)
 {
-    static int pos = 1;
+       static int pos = 1;
+       const char *p;
 
-    const char *p;
+       if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == 0)
+               return EOF;
 
-    if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == 0)
-       return EOF;
+       optopt = argv[optind][pos++];
+       optarg = NULL;
 
-    optopt = argv[optind][pos++];
-    optarg = NULL;
-
-    if (argv[optind][pos] == 0)
-       { pos = 1; optind++; }
-
-    p = strchr (options, optopt);
-
-    if (optopt == ':' || p == NULL) {
-
-       fputs ("illegal option -- ", stdout);
-       goto error;
-
-    } else if (p[1] == ':') {
-
-       if (optind >= argc) {
-
-           fputs ("option requires an argument -- ", stdout);
-           goto error;
-
-       } else {
-
-           optarg = argv[optind];
-
-           if (pos != 1)
-               optarg += pos;
-
-           pos = 1; optind++;
+       if (argv[optind][pos] == 0) {
+               pos = 1;
+               optind++;
+       }
 
+       p = strchr(options, optopt);
+
+       if (optopt == ':' || p == NULL) {
+               fputs("illegal option -- ", stdout);
+               goto error;
+       } else if (p[1] == ':') {
+               if (optind >= argc) {
+                       fputs("option requires an argument -- ", stdout);
+                       goto error;
+               } else {
+                       optarg = argv[optind];
+                       if (pos != 1)
+                               optarg += pos;
+                       pos = 1;
+                       optind++;
+               }
        }
-    }
-    return optopt;
+       return optopt;
 
 error:
 
-    fputc (optopt, stdout);
-    fputc ('\n', stdout);
-
-    return '?';
+       fputc(optopt, stdout);
+       fputc('\n', stdout);
 
-}/* getopt */
+       return '?';
+} /* getopt */