groff-commit
[Top][All Lists]
Advanced

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

[groff] 05/12: [grolj4, indxbib]: Improve diagnostic messages.


From: G. Branden Robinson
Subject: [groff] 05/12: [grolj4, indxbib]: Improve diagnostic messages.
Date: Fri, 6 Dec 2024 06:00:35 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit 04f966e321b932fd6d7e9724f2b041e8feaa93f8
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Thu Dec 5 02:31:12 2024 -0600

    [grolj4, indxbib]: Improve diagnostic messages.
    
    * src/devices/grolj4/lj4.cpp (main): When reporting out-of-range option
      arguments, include the erroneous user-supplied argument.  Use interval
      notation correctly.
    
    * src/utils/indxbib/indxbib.cpp (check_integer_arg): Use interval
      notation correctly.  Annotate why we can't report the erroneous
      user-supplied argument.
    
      (read_common_words_file): Fix typo in diagnostic message.
---
 ChangeLog                     | 12 ++++++++++++
 src/devices/grolj4/lj4.cpp    |  8 ++++----
 src/utils/indxbib/indxbib.cpp |  8 +++++---
 3 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e444491ee..c78445ecf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2024-12-05  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [grolj4, indxbib]: Improve diagnostic messages.
+
+       * src/devices/grolj4/lj4.cpp (main): When reporting out-of-range
+       option arguments, include the erroneous user-supplied argument.
+       Use interval notation correctly.
+       * src/utils/indxbib/indxbib.cpp (check_integer_arg): Use
+       interval notation correctly.  Annotate why we can't report the
+       erroneous user-supplied argument.
+       (read_common_words_file): Fix typo in diagnostic message.
+
 2024-12-04  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        [nroff]: Work around malicious non-compliance with POSIX.
diff --git a/src/devices/grolj4/lj4.cpp b/src/devices/grolj4/lj4.cpp
index a84c9c0d3..f882dd89f 100644
--- a/src/devices/grolj4/lj4.cpp
+++ b/src/devices/grolj4/lj4.cpp
@@ -678,8 +678,8 @@ int main(int argc, char **argv)
          error("argument to command-line option 'c' option must be a"
                " positive integer");
        else if (n <= 0 || n > 32767)
-         error("argument to command-line option 'c' out of range"
-               " [0, 32767)");
+         error("argument to command-line option 'c' must be in range"
+               " (0, 32767]; got '%1'", optarg);
        else
          ncopies = unsigned(n);
        break;
@@ -692,8 +692,8 @@ int main(int argc, char **argv)
          error("argument to command-line option 'w' must be a"
                " non-negative integer");
        else if (n < 0 || n > INT_MAX)
-         error("argument to command-line option 'w' out of range"
-               " (0, %1)", INT_MAX);
+         error("argument to command-line option 'w' must be in range"
+               " [0, %1]; got '%2'", INT_MAX, optarg);
        else
          line_width_factor = int(n);
        break;
diff --git a/src/utils/indxbib/indxbib.cpp b/src/utils/indxbib/indxbib.cpp
index 781e735c8..8bb705702 100644
--- a/src/utils/indxbib/indxbib.cpp
+++ b/src/utils/indxbib/indxbib.cpp
@@ -367,8 +367,10 @@ static void check_integer_arg(char opt, const char *arg, 
int min,
   if (ptr == arg)
     fatal("command-line '%1' option argument is not an integer", opt);
   if ((ERANGE == errno) || (n < min) || (n > INT_MAX))
-    fatal("command-line '%1' option argument must be between %2 and %3",
-         arg, min, INT_MAX);
+    // We'd report the invalid argument, "errarg.h" doesn't support
+    // formatting more than 3 args.
+    fatal("command-line '%1' option argument must be in range [%2, %3]",
+         opt, min, INT_MAX);
   if (*ptr != '\0')
     fatal("invalid integer in argument to command-line option '%1'",
          opt);
@@ -412,7 +414,7 @@ static void read_common_words_file()
   errno = 0;
   FILE *fp = fopen(common_words_file, "r");
   if (!fp)
-    fatal("cannott open '%1': %2", common_words_file, strerror(errno));
+    fatal("cannot open '%1': %2", common_words_file, strerror(errno));
   common_words_table = new word_list * [hash_table_size];
   for (int i = 0; i < hash_table_size; i++)
     common_words_table[i] = 0;



reply via email to

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