groff-commit
[Top][All Lists]
Advanced

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

[groff] 17/26: [soelim]: Fix code style nits.


From: G. Branden Robinson
Subject: [groff] 17/26: [soelim]: Fix code style nits.
Date: Thu, 14 Nov 2024 11:54:11 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit b764e876cf80fbdbe86304cd0062fe42b900ef68
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Tue Nov 12 10:14:04 2024 -0600

    [soelim]: Fix code style nits.
    
    * src/preproc/soelim/soelim.cpp (main): Use standard C library symbols
      `EXIT_SUCCESS` and `EXIT_FAILURE` with `exit()` calls instead of
      integer literals.
    
      (main, do_file): Replace `assert(0)` calls with communicative
      predicates.
    
      (do_file): Check return value of `fclose()`, and exit with fatal error
      if it fails.
    
      (main): Distinguish `ferror()` status and `fflush(stdout)` failures
      when cleaning up before exit.
---
 ChangeLog                     |  8 ++++++++
 src/preproc/soelim/soelim.cpp | 22 +++++++++++++---------
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6295b7b3b..212e5bf4c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,14 @@
        for assignments.
        (do_file): Adjust language of diagnostic message.
        (usage): Expand usage message with an actual description.
+       (main): Use standard C library symbols `EXIT_SUCCESS` and
+       `EXIT_FAILURE` with `exit()` calls instead of integer literals.
+       (main, do_file): Replace `assert(0)` calls with communicative
+       predicates.
+       (do_file): Check return value of `fclose()`, and exit with fatal
+       error if it fails.
+       (main): Distinguish `ferror()` status and `fflush(stdout)`
+       failures when cleaning up before exit.
 
 2024-11-12  G. Branden Robinson <g.branden.robinson@gmail.com>
 
diff --git a/src/preproc/soelim/soelim.cpp b/src/preproc/soelim/soelim.cpp
index 5b7d966fa..e10447d06 100644
--- a/src/preproc/soelim/soelim.cpp
+++ b/src/preproc/soelim/soelim.cpp
@@ -84,7 +84,7 @@ int main(int argc, char **argv)
     switch (opt) {
     case 'v':
       printf("GNU soelim (groff) version %s\n", Version_string);
-      exit(0);
+      exit(EXIT_SUCCESS);
       break;
     case 'C':
       want_att_compat = true;
@@ -100,7 +100,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));
@@ -108,7 +108,7 @@ int main(int argc, char **argv)
       exit(2);
       break;
     default:
-      assert(0);
+      assert(0 == "unhandled getopt_long return value");
     }
   int nbad = 0;
   if (optind >= argc)
@@ -116,9 +116,11 @@ int main(int argc, char **argv)
   else
     for (int i = optind; i < argc; i++)
       nbad += !do_file(argv[i]);
-  if (ferror(stdout) || fflush(stdout) < 0)
-    fatal("output error");
-  return nbad != 0;
+  if (ferror(stdout))
+    fatal("error status on standard output stream");
+  if (fflush(stdout) < 0)
+    fatal("cannot flush standard output stream: %1", strerror(errno));
+  return (nbad != 0);
 }
 
 void set_location()
@@ -302,7 +304,7 @@ int do_file(const char *filename)
       }
       break;
     default:
-      assert(0);
+      assert(0 == "unhandled state in file parser");
     }
   }
   switch (state) {
@@ -328,8 +330,10 @@ int do_file(const char *filename)
     break;
   }
   if (fp != stdin)
-    fclose(fp);
-  current_filename = 0;
+    if (fclose(fp) < 0)
+      fatal("cannot close '%1': %2", whole_filename.contents(),
+           strerror(errno));
+  current_filename = 0 /* nullptr */;
   return 1;
 }
 



reply via email to

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