groff-commit
[Top][All Lists]
Advanced

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

[groff] 07/27: src/preproc/html/pre-html.cpp: Refactor (6/11).


From: G. Branden Robinson
Subject: [groff] 07/27: src/preproc/html/pre-html.cpp: Refactor (6/11).
Date: Sat, 2 Jul 2022 00:43:11 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 4d1d60cd1c188160735ebc9861d0a07fa3504f81
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Jun 27 20:40:26 2022 -0500

    src/preproc/html/pre-html.cpp: Refactor (6/11).
    
    * src/preproc/html/pre-html.cpp (makeFileName, checkImageDir,
      char_buffer::run_output_filter, scanArguments): Call `fatal()` instead
      of `error()` and then `exit(1)`.
    
      (char_buffer::run_output_filter): Stop passing unnecessary null
      pointer argument to diagnostic message functions.  Stop calling
      `fflush()` after libgroff diagnostic function, which always
      (ultimately) flushes the standard error stream itself.
    
      (scanArguments): Use `EXIT_SUCCESS` and `EXIT_FAILURE` constants from
      C library instead of integer literals for exit status.
---
 ChangeLog                     | 10 ++++++++
 src/preproc/html/pre-html.cpp | 54 +++++++++++++++----------------------------
 2 files changed, 29 insertions(+), 35 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bb7c0da2..5d86b8f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,11 +10,21 @@
        library that this file makes.  Improve check for error from
        `fread()` by not regarding a return value of zero when the
        end-of-file indicator is set as an error condition.
+       (makeFileName, checkImageDir, char_buffer::run_output_filter,
+       scanArguments): Call `fatal()` instead of `error()` and then
+       `exit(1)`.
+       (char_buffer::run_output_filter): Stop passing unnecessary null
+       pointer argument to diagnostic message functions.  Stop calling
+       `fflush()` after libgroff diagnostic function, which always
+       {ultimately} flushes the standard error stream itself.
        (makeTempFiles, do_file, main): Boolify.  Use idiomatic C++98
        null pointer constant.  Annotate it as null pointer to ease any
        future migration to ISO C++11.
        (makeTempFiles, do_file): Reorder null pointer equality
        comparisons to avoid inadvertent lvalue assignment.
+       (scanArguments, main): Use `EXIT_SUCCESS` and `EXIT_FAILURE`
+       constants from C library instead of integer literals for exit
+       status.
        (do_file): Demote return type from `int` to `bool`.  Return
        Boolean literals.  Drop conditional with empty consequent.
        (main): Declare local variables closer to the points of use.
diff --git a/src/preproc/html/pre-html.cpp b/src/preproc/html/pre-html.cpp
index 21cc3603..e8a3175e 100644
--- a/src/preproc/html/pre-html.cpp
+++ b/src/preproc/html/pre-html.cpp
@@ -547,15 +547,11 @@ static void writeString(const char *s)
 
 static void makeFileName(void)
 {
-  if ((image_dir != NULL) && (strchr(image_dir, '%') != NULL)) {
-    error("cannot use a '%%' within the image directory name");
-    exit(1);
-  }
+  if ((image_dir != NULL) && (strchr(image_dir, '%') != NULL))
+    fatal("'%%' is prohibited within the image directory name");
 
-  if ((image_template != NULL) && (strchr(image_template, '%') != NULL)) {
-    error("cannot use a '%%' within the image template");
-    exit(1);
-  }
+  if ((image_template != NULL) && (strchr(image_template, '%') != NULL))
+    fatal("'%%' is prohibited within the image template");
 
   if (image_dir == NULL)
     image_dir = (char *)"";
@@ -609,10 +605,9 @@ static void setupAntiAlias(void)
 static void checkImageDir(void)
 {
   if (image_dir != NULL && strcmp(image_dir, "") != 0)
-    if (!(mkdir(image_dir, 0777) == 0 || errno == EEXIST)) {
-      error("cannot create directory '%1'", image_dir);
-      exit(1);
-    }
+    if (!(mkdir(image_dir, 0777) == 0 || errno == EEXIST))
+      fatal("cannot create directory '%1': %2", image_dir,
+           strerror(errno));
 }
 
 /*
@@ -1216,9 +1211,9 @@ static int save_and_redirect(int was, int willbe)
 }
 
 /*
- *  alterDeviceTo - If, toImage, is set
+ *  alterDeviceTo - If toImage is set
  *                     the argument list is altered to include
- *                     IMAGE_DEVICE and we invoke groff rather than troff.
+ *                     IMAGE_DEVICE; we invoke groff rather than troff.
  *                  Else
  *                     set -Thtml and groff.
  */
@@ -1376,14 +1371,8 @@ int char_buffer::run_output_filter(int filter, int argc, 
char **argv)
 
     // Now we are ready to launch the output filter.
 
-    execvp(argv[0], argv);
-
-    // If we get to here then the 'exec...' request for the output filter
-    // failed.  Diagnose it and bail out.
-
-    error("couldn't exec %1: %2", argv[0], strerror(errno), ((char *)0));
-    fflush(stderr);    // just in case error() didn't
-    exit(1);
+    execvp(argv[0], argv); // does not return unless it fails
+    fatal("cannot execute '%1': %2", argv[0], strerror(errno));
   }
 
   else {
@@ -1445,8 +1434,7 @@ int char_buffer::run_output_filter(int filter, int argc, 
char **argv)
   if ((child_pid = spawnvp(_P_NOWAIT, argv[0], argv)) < 0) {
     // Should the spawn request fail we issue a diagnostic and bail out.
 
-    error("cannot spawn %1: %2", argv[0], strerror(errno), ((char *)0));
-    exit(1);
+    fatal("cannot spawn %1: %2", argv[0], strerror(errno));
   }
 
   // Once the post-processor has been started we revert our 'stdin'
@@ -1631,10 +1619,8 @@ static int scanArguments(int argc, char **argv)
     case 'a':
       textAlphaBits = min(max(MIN_ALPHA_BITS, atoi(optarg)),
                          MAX_ALPHA_BITS);
-      if (textAlphaBits == 3) {
-       error("cannot use 3 bits of antialiasing information");
-       exit(1);
-      }
+      if (textAlphaBits == 3)
+       fatal("cannot use 3 bits of antialiasing information");
       break;
     case 'b':
       // handled by post-grohtml (set background color to white)
@@ -1659,10 +1645,8 @@ static int scanArguments(int argc, char **argv)
     case 'g':
       graphicAlphaBits = min(max(MIN_ALPHA_BITS, atoi(optarg)),
                             MAX_ALPHA_BITS);
-      if (graphicAlphaBits == 3) {
-       error("cannot use 3 bits of antialiasing information");
-       exit(1);
-      }
+      if (graphicAlphaBits == 3)
+       fatal("cannot use 3 bits of antialiasing information");
       break;
     case 'G':
       // handled by post-grohtml (don't write CreationDate HTML comment)
@@ -1702,7 +1686,7 @@ static int scanArguments(int argc, char **argv)
       break;
     case 'v':
       printf("GNU pre-grohtml (groff) version %s\n", Version_string);
-      exit(0);
+      exit(EXIT_SUCCESS);
     case 'V':
       // handled by post-grohtml (create validator button)
       break;
@@ -1720,11 +1704,11 @@ static int scanArguments(int argc, char **argv)
       break;
     case CHAR_MAX + 1: // --help
       usage(stdout);
-      exit(0);
+      exit(EXIT_SUCCESS);
       break;
     case '?':
       usage(stderr);
-      exit(1);
+      exit(EXIT_FAILURE);
       break;
     default:
       break;



reply via email to

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