groff-commit
[Top][All Lists]
Advanced

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

[groff] 04/30: troff: Migrate to modern getopt_long(3) usage.


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

gbranden pushed a commit to branch master
in repository groff.

commit c1cefe3c9388f7f975b7692881f1280e5af6a94e
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Fri Dec 20 00:02:13 2024 -0600

    troff: Migrate to modern getopt_long(3) usage.
    
    * src/roff/troff/input.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                | 7 +++++++
 src/roff/troff/input.cpp | 9 +++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8cad79e3d..ff043b3c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-12-20  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       * src/roff/troff/input.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-21  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        [groff]: Fix thinkos in new test.
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index da9361d4d..2aac8ad51 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -8963,9 +8963,8 @@ int main(int argc, char **argv)
 #else
 #define DEBUG_OPTION ""
 #endif
-  opterr = 0;
   while ((c = getopt_long(argc, argv,
-                         "abciI:vw:W:zCEf:m:n:o:r:d:F:M:T:tqs:RU"
+                         ":abciI:vw:W:zCEf:m:n:o:r:d:F:M:T:tqs:RU"
                          DEBUG_OPTION, long_options, 0))
         != EOF)
     switch (c) {
@@ -9079,6 +9078,12 @@ int main(int argc, char **argv)
       usage(stderr, argv[0]);
       exit(2);
       break;           // never reached
+    case ':':
+      error("command-line option '%1' requires an argument",
+           char(optopt));
+      usage(stderr, argv[0]);
+      exit(2);
+      break;           // never reached
     default:
       assert(0 == "unhandled case of command-line option");
     }



reply via email to

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