groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 06/30: [devices]: Migrate to modern getopt_long(3) usage.


From: G. Branden Robinson
Subject: [groff] 06/30: [devices]: Migrate to modern getopt_long(3) usage.
Date: Sun, 22 Dec 2024 19:39:16 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit 483ec7c552190512b187806b5eb55ea33cbb1147
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Fri Dec 20 00:09:04 2024 -0600

    [devices]: Migrate to modern getopt_long(3) usage.
    
    * src/devices/grodvi/dvi.cpp (main):
    * src/devices/grohtml/post-html.cpp (main):
    * src/devices/grolbp/lbp.cpp (main):
    * src/devices/grolj4/lj4.cpp (main):
    * src/devices/grops/ps.cpp (main):
    * src/devices/grotty/tty.cpp (main): Migrate to modern getopt_long(3)
      usage.  Drop `opterr` assignment; prefix the option string with ":"
      instead.  Handle return of `:`, emit an appropriate usage diagnostic,
      and exit with status 2.
---
 ChangeLog                         | 12 ++++++++++++
 src/devices/grodvi/dvi.cpp        |  9 +++++++--
 src/devices/grohtml/post-html.cpp |  9 +++++++--
 src/devices/grolbp/lbp.cpp        |  9 +++++++--
 src/devices/grolj4/lj4.cpp        |  3 +--
 src/devices/grops/ps.cpp          |  9 +++++++--
 src/devices/grotty/tty.cpp        |  9 +++++++--
 7 files changed, 48 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1dcd4c339..a1f095e6b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,18 @@
        missing, assuming long-side duplexing as before.  Emit usage
        message and exit with status 2 in all other cases.
 
+2024-12-20  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       * src/devices/grodvi/dvi.cpp (main):
+       * src/devices/grohtml/post-html.cpp (main):
+       * src/devices/grolbp/lbp.cpp (main):
+       * src/devices/grolj4/lj4.cpp (main):
+       * src/devices/grops/ps.cpp (main):
+       * src/devices/grotty/tty.cpp (main): Migrate to modern
+       getopt_long(3) usage.  Drop `opterr` assignment; prefix the
+       option string with ":" instead.  Handle return of `:`, emit an
+       appropriate usage diagnostic, and exit with status 2.
+
 2024-12-20  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * src/roff/troff/input.cpp (main): Migrate to modern
diff --git a/src/devices/grodvi/dvi.cpp b/src/devices/grodvi/dvi.cpp
index b37d547e5..4a0f9d0ef 100644
--- a/src/devices/grodvi/dvi.cpp
+++ b/src/devices/grodvi/dvi.cpp
@@ -935,8 +935,7 @@ int main(int argc, char **argv)
     { "version", no_argument, 0, 'v' },
     { NULL, 0, 0, 0 }
   };
-  opterr = 0;
-  while ((c = getopt_long(argc, argv, "dF:I:lp:vw:", long_options,
+  while ((c = getopt_long(argc, argv, ":dF:I:lp:vw:", long_options,
          NULL)) != EOF)
     switch(c) {
     case 'd':
@@ -978,6 +977,12 @@ int main(int argc, char **argv)
       usage(stderr);
       exit(2);
       break;
+    case ':':
+      error("command-line option '%1' requires an argument",
+           char(optopt));
+      usage(stderr);
+      exit(2);
+      break;
     default:
       assert(0 == "unhandled getopt_long return value");
     }
diff --git a/src/devices/grohtml/post-html.cpp 
b/src/devices/grohtml/post-html.cpp
index d6fc16b11..f5ffb1956 100644
--- a/src/devices/grohtml/post-html.cpp
+++ b/src/devices/grohtml/post-html.cpp
@@ -5588,9 +5588,8 @@ int main(int argc, char **argv)
     { "version", no_argument, 0, 'v' },
     { NULL, 0, 0, 0 }
   };
-  opterr = 0;
   while ((c = getopt_long(argc, argv,
-         "a:bCdD:eF:g:Ghi:I:j:k:lno:prs:S:vVx:y", long_options, NULL))
+         ":a:bCdD:eF:g:Ghi:I:j:k:lno:prs:S:vVx:y", long_options, NULL))
         != EOF)
     switch(c) {
     case 'a':
@@ -5701,6 +5700,12 @@ int main(int argc, char **argv)
       usage(stderr);
       exit(2);
       break;
+    case ':':
+      error("command-line option '%1' requires an argument",
+           char(optopt));
+      usage(stderr);
+      exit(2);
+      break;
     default:
       assert(0 == "unhandled getopt_long return value");
     }
diff --git a/src/devices/grolbp/lbp.cpp b/src/devices/grolbp/lbp.cpp
index 019800261..028c9aedc 100644
--- a/src/devices/grolbp/lbp.cpp
+++ b/src/devices/grolbp/lbp.cpp
@@ -657,8 +657,7 @@ int main(int argc, char **argv)
   // command line parsing
   int c;
   int option_index = 0;
-  opterr = 0;
-  while ((c = getopt_long(argc, argv, "c:F:hI:lo:p:vw:", long_options,
+  while ((c = getopt_long(argc, argv, ":c:F:hI:lo:p:vw:", long_options,
                          &option_index))
         != EOF) {
     switch (c) {
@@ -728,6 +727,12 @@ int main(int argc, char **argv)
       usage(stderr);
       exit(2);
       break;
+    case ':':
+      error("command-line option '%1' requires an argument",
+           char(optopt));
+      usage(stderr);
+      exit(2);
+      break;
     default:
       assert(0 == "unhandled getopt_long return value");
     }
diff --git a/src/devices/grolj4/lj4.cpp b/src/devices/grolj4/lj4.cpp
index 34cc62c59..e830026b2 100644
--- a/src/devices/grolj4/lj4.cpp
+++ b/src/devices/grolj4/lj4.cpp
@@ -625,8 +625,7 @@ int main(int argc, char **argv)
     { "version", no_argument, 0, 'v' },
     { NULL, 0, 0, 0 }
   };
-  opterr = 0;
-  while ((c = getopt_long(argc, argv, "c:d:F:I:lp:vw:", long_options,
+  while ((c = getopt_long(argc, argv, ":c:d:F:I:lp:vw:", long_options,
          NULL)) != EOF)
     switch(c) {
     case 'l':
diff --git a/src/devices/grops/ps.cpp b/src/devices/grops/ps.cpp
index fb6ffb0e1..68d27186f 100644
--- a/src/devices/grops/ps.cpp
+++ b/src/devices/grops/ps.cpp
@@ -1864,8 +1864,7 @@ int main(int argc, char **argv)
     { "version", no_argument, 0, 'v' },
     { NULL, 0, 0, 0 }
   };
-  opterr = 0;
-  while ((c = getopt_long(argc, argv, "b:c:F:gI:lmp:P:vw:",
+  while ((c = getopt_long(argc, argv, ":b:c:F:gI:lmp:P:vw:",
          long_options, NULL)) != EOF)
     switch(c) {
     case 'b':
@@ -1928,6 +1927,12 @@ int main(int argc, char **argv)
       usage(stderr);
       exit(2);
       break;
+    case ':':
+      error("command-line option '%1' requires an argument",
+           char(optopt));
+      usage(stderr);
+      exit(2);
+      break;
     default:
       assert(0 == "unhandled getopt_long return value");
     }
diff --git a/src/devices/grotty/tty.cpp b/src/devices/grotty/tty.cpp
index 3cbfc8414..f7fca4ebf 100644
--- a/src/devices/grotty/tty.cpp
+++ b/src/devices/grotty/tty.cpp
@@ -953,8 +953,7 @@ int main(int argc, char **argv)
     { "version", no_argument, 0, 'v' },
     { NULL, 0, 0, 0 }
   };
-  opterr = 0;
-  while ((c = getopt_long(argc, argv, "bBcdfF:hiI:oruUv", long_options,
+  while ((c = getopt_long(argc, argv, ":bBcdfF:hiI:oruUv", long_options,
          NULL)) != EOF)
     switch(c) {
     case 'v':
@@ -1018,6 +1017,12 @@ int main(int argc, char **argv)
       usage(stderr);
       exit(2);
       break;
+    case ':':
+      error("command-line option '%1' requires an argument",
+           char(optopt));
+      usage(stderr);
+      exit(2);
+      break;
     default:
       assert(0 == "unhandled getopt_long return value");
     }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]