groff-commit
[Top][All Lists]
Advanced

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

[groff] 80/80: [lookbib]: Align with modern groff conventions.


From: G. Branden Robinson
Subject: [groff] 80/80: [lookbib]: Align with modern groff conventions.
Date: Sat, 30 Nov 2024 04:02:31 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit cb42f30186fc3019210874d503749acc7d2d3af2
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sat Nov 30 02:26:13 2024 -0600

    [lookbib]: Align with modern groff conventions.
    
    * src/utils/lookbib/lookbib.cpp (usage): If asked for `--help`,
      summarize command purpose in message.
    
      (main): Recast wording of diagnostic messages.  Use standard symbol
      `EXIT_SUCCESS` instead of `0` literal.  `sizeof` is an operator, not a
      function, so don't parenthesize its operand when it's an lvalue {as
      opposed to a type name}.
---
 ChangeLog                     | 11 +++++++++++
 src/utils/lookbib/lookbib.cpp | 30 +++++++++++++++++++++++-------
 2 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d368fbb3b..ae4477754 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2024-11-30  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [lookbib]: Align with modern groff conventions.
+
+       * src/utils/lookbib/lookbib.cpp (usage): If asked for `--help`,
+       summarize command purpose in message.
+       (main): Recast wording of diagnostic messages.  Use standard
+       symbol `EXIT_SUCCESS` instead of `0` literal.  `sizeof` is an
+       operator, not a function, so don't parenthesize its operand when
+       it's an lvalue {as opposed to a type name}.
+
 2024-11-30  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * src/utils/lookbib/lookbib.cpp (main): Emit error diagnostic
diff --git a/src/utils/lookbib/lookbib.cpp b/src/utils/lookbib/lookbib.cpp
index ab0647c85..cd261af4b 100644
--- a/src/utils/lookbib/lookbib.cpp
+++ b/src/utils/lookbib/lookbib.cpp
@@ -22,7 +22,11 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 
 #include <assert.h>
 #include <errno.h>
-#include <stdlib.h>
+#include <stdio.h> // EOF, FILE, fflush(), fgets(), fileno(), fprintf(),
+                  // printf(), putchar(), setbuf(), stderr, stdin,
+                  // stdout
+#include <stdlib.h> // exit(), EXIT_SUCCESS, strtol()
+#include <string.h> // strerror()
 
 #include "lib.h"
 
@@ -33,7 +37,7 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 #include "refid.h"
 #include "search.h"
 
-/* for isatty() */
+// needed for isatty()
 #include "posix.h"
 #include "nonposix.h"
 
@@ -46,6 +50,16 @@ static void usage(FILE *stream)
          "usage: %s {-v | --version}\n"
          "usage: %s --help\n",
          program_name, program_name, program_name);
+  if (stdout == stream)
+    fputs("\n"
+"GNU lookbib writes a prompt to the standard error stream (unless the\n"
+"standard input stream is not a terminal), reads from the standard\n"
+"input a line containing a set of keywords, searches each\n"
+"bibliographic DATABASE for references containing those keywords,\n"
+"writes any references found to the standard output stream, and\n"
+"repeats this process until the end of input.  See the lookbib(1)\n"
+"manual page.\n",
+         stream);
 }
 
 int main(int argc, char **argv)
@@ -74,7 +88,8 @@ int main(int argc, char **argv)
        char *ptr;
        long n = strtol(optarg, &ptr, 10);
        if (ptr == optarg) {
-         error("bad integer '%1' in 't' option", optarg);
+         error("invalid integer '%1' in argument to command-line 't'"
+               " option; ignoring", optarg);
          break;
        }
        if (n < 1)
@@ -85,12 +100,12 @@ int main(int argc, char **argv)
     case 'v':
       {
        printf("GNU lookbib (groff) version %s\n", Version_string);
-       exit(0);
+       exit(EXIT_SUCCESS);
        break;
       }
     case CHAR_MAX + 1: // --help
       usage(stdout);
-      exit(0);
+      exit(EXIT_SUCCESS);
       break;
     case '?':
       error("unrecognized command-line option '%1'", char(optopt));
@@ -117,7 +132,7 @@ int main(int argc, char **argv)
       fputs("> ", stderr);
       fflush(stderr);
     }
-    if (!fgets(line, sizeof(line), stdin))
+    if (!fgets(line, sizeof line, stdin))
       break;
     char *ptr = line;
     while (csspace(*ptr))
@@ -130,7 +145,8 @@ int main(int argc, char **argv)
     int count;
     for (count = 0; iter.next(&start, &len); count++) {
       if (fwrite(start, 1, len, stdout) != (size_t)len)
-       fatal("write error on stdout: %1", strerror(errno));
+       fatal("cannot write to standard output stream: %1",
+             strerror(errno));
       // Can happen for last reference in file.
       if (start[len - 1] != '\n')
        putchar('\n');



reply via email to

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