groff-commit
[Top][All Lists]
Advanced

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

[groff] 63/80: [pic]: Align with modern groff conventions.


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

gbranden pushed a commit to branch master
in repository groff.

commit d5a2a2e49cf82f902fb3188d3bb8326484546761
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Fri Nov 29 03:32:00 2024 -0600

    [pic]: Align with modern groff conventions.
    
    * src/preproc/pic/main.cpp (top_input::get, top_input::peek, do_file):
      Drop pointless construction of temporary value from argument that is
      already of the desired type.
    
      (do_file, do_whole_file, main): Recast wording of diagnostic messages.
    
      (do_file, main): Replace `assert(0)` call with communicative
      predicate.
    
      (usage): If asked for `--help`, summarize command purpose in message.
    
      (main): Use standard symbols `EXIT_SUCCESS` and `EXIT_FAILURE` instead
      of `0` and `1` literals, respectively.  Distinguish `ferror()` status
      and `fflush(stdout)` failures when cleaning up before exit.
---
 ChangeLog                | 18 +++++++++++++++
 src/preproc/pic/main.cpp | 59 ++++++++++++++++++++++++++++++++----------------
 2 files changed, 58 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9a082f793..5fd9c5112 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2024-11-29  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [pic]: Align with modern groff conventions.
+
+       * src/preproc/pic/main.cpp (top_input::get, top_input::peek)
+       (do_file): Drop pointless construction of temporary value from
+       argument that is already of the desired type.
+       (do_file, do_whole_file, main): Recast wording of diagnostic
+       messages.
+       (do_file, main): Replace `assert(0)` call with
+       communicative predicate.
+       (usage): If asked for `--help`, summarize command purpose in
+       message.
+       (main): Use standard symbols `EXIT_SUCCESS` and `EXIT_FAILURE`
+       instead of `0` and `1` literals, respectively.  Distinguish
+       `ferror()` status and `fflush(stdout)` failures when cleaning up
+       before exit.
+
 2024-11-29  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        [grn]: Align with modern groff conventions.
diff --git a/src/preproc/pic/main.cpp b/src/preproc/pic/main.cpp
index 1c56583c0..f3f72512d 100644
--- a/src/preproc/pic/main.cpp
+++ b/src/preproc/pic/main.cpp
@@ -26,7 +26,7 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 #include <stdio.h> // EOF, FILE, fclose(), ferror(), fflush(), fopen(),
                   // fprintf(), fputs(), getc(), printf(), setbuf(),
                   // stderr, stdin, stdout, ungetc()
-#include <stdlib.h> // free(), exit()
+#include <stdlib.h> // exit(), EXIT_FAILURE, EXIT_SUCCESS, free()
 #include <string.h> // strerror()
 
 #include "pic.h"
@@ -95,7 +95,7 @@ int top_input::get()
   }
   int c = getc(fp);
   while (is_invalid_input_char(c)) {
-    error("invalid input character code %1", int(c));
+    error("invalid input character code %1", c);
     c = getc(fp);
     bol = 0;
   }
@@ -168,7 +168,7 @@ int top_input::peek()
     return push_back[0];
   int c = getc(fp);
   while (is_invalid_input_char(c)) {
-    error("invalid input character code %1", int(c));
+    error("invalid input character code %1", c);
     c = getc(fp);
     bol = 0;
   }
@@ -323,7 +323,7 @@ void do_file(const char *filename)
     fp = fopen(filename, "r");
     if (fp == 0) {
       delete out;
-      fatal("can't open '%1': %2", filename, strerror(errno));
+      fatal("cannot open '%1': %2", filename, strerror(errno));
     }
   }
   string fn(filename);
@@ -332,11 +332,12 @@ void do_file(const char *filename)
   current_filename = fn.contents();
   out->set_location(current_filename, 1);
   current_lineno = 1;
-  enum { START, MIDDLE, HAD_DOT, HAD_P, HAD_PS, HAD_l, HAD_lf } state = START;
+  enum { START, MIDDLE, HAD_DOT, HAD_P, HAD_PS, HAD_l, HAD_lf } state
+    = START;
   for (;;) {
     int c = getc(fp);
     while (is_invalid_input_char(c)) {
-      error("invalid input character code %1", int(c));
+      error("invalid input character code %1", c);
       c = getc(fp);
     }
     if (c == EOF)
@@ -443,7 +444,7 @@ void do_file(const char *filename)
       }
       break;
     default:
-      assert(0);
+      assert(0 == "unhandled parser state");
     }
   }
   switch (state) {
@@ -483,7 +484,7 @@ void do_whole_file(const char *filename)
     errno = 0;
     fp = fopen(filename, "r");
     if (fp == 0)
-      fatal("can't open '%1': %2", filename, strerror(errno));
+      fatal("cannot open '%1': %2", filename, strerror(errno));
   }
   lex_init(new file_input(fp, filename));
   if (yyparse())
@@ -504,6 +505,22 @@ void usage(FILE *stream)
 #endif
   fprintf(stream, "usage: %s {-v | --version}\n", program_name);
   fprintf(stream, "usage: %s --help\n", program_name);
+  if (stdout == stream) {
+    fputs(
+"\n"
+"GNU pic is a troff(1) preprocessor that translates descriptions of\n"
+"diagrammatic pictures embedded in roff(7)"
+#ifdef TEX_SUPPORT
+" or TeX"
+#endif
+" input into the language\n"
+"understood by"
+#ifdef TEX_SUPPORT
+" TeX or"
+#endif
+" troff.  See the pic(1) manual page.\n",
+          stream);
+  }
 }
 
 #if defined(__MSDOS__) || defined(__EMX__)
@@ -575,7 +592,7 @@ int main(int argc, char **argv)
       whole_file_flag++;
       fig_flag++;
 #else
-      fatal("fig support not included");
+      fatal("fig support is not built into this configuration");
 #endif
       break;
     case 'n':
@@ -583,26 +600,27 @@ int main(int argc, char **argv)
       break;
     case 'p':
     case 'x':
-      warning("-%1 option is obsolete", char(opt));
+      warning("command-line option '-%1' is obsolete; ignoring",
+             char(opt));
       break;
     case 't':
 #ifdef TEX_SUPPORT
       tex_flag++;
 #else
-      fatal("TeX support not included");
+      fatal("TeX support is not built into this configuration");
 #endif
       break;
     case 'c':
 #ifdef TEX_SUPPORT
       tpic_flag++;
 #else
-      fatal("TeX support not included");
+      fatal("TeX support is not built into this configuration");
 #endif
       break;
     case 'v':
       {
        printf("GNU pic (groff) version %s\n", Version_string);
-       exit(0);
+       exit(EXIT_SUCCESS);
        break;
       }
     case 'z':
@@ -611,7 +629,7 @@ int main(int argc, char **argv)
       break;
     case CHAR_MAX + 1: // --help
       usage(stdout);
-      exit(0);
+      exit(EXIT_SUCCESS);
       break;
     case '?':
       error("unrecognized command-line option '%1'", char(optopt));
@@ -619,7 +637,7 @@ int main(int argc, char **argv)
       exit(2);
       break;
     default:
-      assert(0);
+      assert(0 == "unhandled getopt_long return value");
     }
   parse_init();
 #ifdef TEX_SUPPORT
@@ -652,8 +670,9 @@ int main(int argc, char **argv)
       do_whole_file("-");
     else if (argc - optind > 1) {
       usage(stderr);
-      exit(1);
-    } else
+      exit(EXIT_FAILURE);
+    }
+    else
       do_whole_file(argv[optind]);
   }
   else {
@@ -667,8 +686,10 @@ int main(int argc, char **argv)
   }
 #endif
   delete out;
-  if (ferror(stdout) || fflush(stdout) < 0)
-    fatal("output error");
+  if (ferror(stdout))
+    fatal("error status on standard output stream");
+  if (fflush(stdout) < 0)
+    fatal("cannot flush standard output stream: %1", strerror(errno));
   return had_parse_error;
 }
 



reply via email to

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