gbranden pushed a commit to branch master
in repository groff.

commit ebd74fa93d07bd78cc784a8d213e55261a575259
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sat Jul 13 12:06:11 2024 -0500

    [libgroff,eqn,troff]: Trivially refactor (4/5).
    
    * src/libs/libgroff/searchpath.cpp (search_path::search_path)
      (search_path::open_file, search_path::open_file_cautious)
    * src/preproc/eqn/main.cpp (main):
    * src/roff/troff/input.cpp (file_iterator::set_location, next_file)
      (do_open, close_request, do_write_request, write_macro_request)
      (transparent_file, open_macro_package, process_macro_package_argument)
      (process_startup_file, do_macro_source, process_input_file):
      Explicitly compare variable of pointer type to null pointer constant
      instead of letting it pun down to a Boolean.
---
 ChangeLog                        | 11 +++++++++++
 src/libs/libgroff/searchpath.cpp | 26 +++++++++++++-------------
 src/preproc/eqn/main.cpp         |  2 +-
 src/roff/troff/input.cpp         | 28 ++++++++++++++--------------
 4 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e4e232ede..275ed00b6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,17 @@
        * src/libs/libgroff/font.cpp (glyph_to_unicode): Add parentheses
        to complex expression.
 
+       * src/libs/libgroff/searchpath.cpp (search_path::search_path)
+       (search_path::open_file, search_path::open_file_cautious)
+       * src/preproc/eqn/main.cpp (main):
+       * src/roff/troff/input.cpp (file_iterator::set_location)
+       (next_file, do_open, close_request, do_write_request)
+       (write_macro_request, transparent_file, open_macro_package)
+       (process_macro_package_argument, process_startup_file)
+       (do_macro_source, process_input_file): Explicitly compare
+       variable of pointer type to null pointer constant instead of
+       letting it pun down to a Boolean.
+
 2024-07-13  G. Branden Robinson <[email protected]>
 
        * src/libs/libgroff/font.cpp (font::load, font::load_desc):
diff --git a/src/libs/libgroff/searchpath.cpp b/src/libs/libgroff/searchpath.cpp
index d276a4a94..0bc03ac68 100644
--- a/src/libs/libgroff/searchpath.cpp
+++ b/src/libs/libgroff/searchpath.cpp
@@ -42,7 +42,7 @@ search_path::search_path(const char *envvar, const char 
*standard,
   if (add_home)
     home = getenv("HOME");
   char *e = 0;
-  if (envvar)
+  if (envvar != 0)
     e = getenv(envvar);
   dirs = new char[((e && *e) ? strlen(e) + 1 : 0)
                  + (add_current ? 1 + 1 : 0)
@@ -100,8 +100,8 @@ FILE *search_path::open_file(const char *name, char **pathp)
   assert(name != 0);
   if (IS_ABSOLUTE(name) || *dirs == '\0') {
     FILE *fp = fopen(name, "r");
-    if (fp) {
-      if (pathp)
+    if (fp != 0) {
+      if (pathp != 0)
        *pathp = strsave(name);
       return fp;
     }
@@ -112,7 +112,7 @@ FILE *search_path::open_file(const char *name, char **pathp)
   char *p = dirs;
   for (;;) {
     char *end = strchr(p, PATH_SEP_CHAR);
-    if (!end)
+    if (0 == end)
       end = strchr(p, '\0');
     int need_slash = end > p && strchr(DIR_SEPS, end[-1]) == 0;
     char *origpath = new char[(end - p) + need_slash + namelen + 1];
@@ -130,8 +130,8 @@ FILE *search_path::open_file(const char *name, char **pathp)
 #endif
     FILE *fp = fopen(path, "r");
     int err = errno;
-    if (fp) {
-      if (pathp)
+    if (fp != 0) {
+      if (pathp != 0)
        *pathp = path;
       else {
        free(path);
@@ -151,18 +151,18 @@ FILE *search_path::open_file(const char *name, char 
**pathp)
 FILE *search_path::open_file_cautious(const char *name, char **pathp,
                                      const char *mode)
 {
-  if (!mode)
+  if (0 == mode)
     mode = "r";
   bool reading = (strchr(mode, 'r') != 0);
   if (0 == name || strcmp(name, "-") == 0) {
-    if (pathp)
+    if (pathp != 0)
       *pathp = strsave(reading ? "stdin" : "stdout");
     return (reading ? stdin : stdout);
   }
   if (!reading || IS_ABSOLUTE(name) || *dirs == '\0') {
     FILE *fp = fopen(name, mode);
-    if (fp) {
-      if (pathp)
+    if (fp != 0) {
+      if (pathp != 0)
        *pathp = strsave(name);
       return fp;
     }
@@ -173,7 +173,7 @@ FILE *search_path::open_file_cautious(const char *name, 
char **pathp,
   char *p = dirs;
   for (;;) {
     char *end = strchr(p, PATH_SEP_CHAR);
-    if (!end)
+    if (0 == end)
       end = strchr(p, '\0');
     int need_slash = end > p && strchr(DIR_SEPS, end[-1]) == 0;
     char *origpath = new char[(end - p) + need_slash + namelen + 1];
@@ -191,8 +191,8 @@ FILE *search_path::open_file_cautious(const char *name, 
char **pathp,
 #endif
     FILE *fp = fopen(path, mode);
     int err = errno;
-    if (fp) {
-      if (pathp)
+    if (fp != 0) {
+      if (pathp != 0)
        *pathp = path;
       else {
        free(path);
diff --git a/src/preproc/eqn/main.cpp b/src/preproc/eqn/main.cpp
index 17a149c10..b7eed4b6b 100644
--- a/src/preproc/eqn/main.cpp
+++ b/src/preproc/eqn/main.cpp
@@ -447,7 +447,7 @@ int main(int argc, char **argv)
   if (want_startup_file) {
     char *path;
     FILE *fp = config_macro_path.open_file(STARTUP_FILE, &path);
-    if (fp) {
+    if (fp != 0) {
       do_file(fp, path);
       if (fclose(fp) < 0)
        fatal("unable to close '%1': %2", STARTUP_FILE,
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index d1fa4f45b..ab6c8ccf9 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -512,7 +512,7 @@ void file_iterator::backtrace()
 
 bool file_iterator::set_location(const char *f, int ln)
 {
-  if (f)
+  if (f != 0)
     filename = f;
   lineno = ln;
   return true;
@@ -898,7 +898,7 @@ void next_file()
   else {
     errno = 0;
     FILE *fp = include_search_path.open_file_cautious(nm.contents());
-    if (!fp)
+    if (0 == fp)
       error("can't open '%1': %2", nm.contents(), strerror(errno));
     else
       input_stack::next_file(fp, nm.contents());
@@ -6973,7 +6973,7 @@ static void do_open(bool append)
     if (!filename.is_null()) {
       errno = 0;
       FILE *fp = fopen(filename.contents(), append ? "a" : "w");
-      if (!fp) {
+      if (0 == fp) {
        error("unable to open file '%1' for %2: %3",
              filename.contents(),
              append ? "appending" : "writing",
@@ -7014,7 +7014,7 @@ static void close_request()
   symbol stream = get_name(true /* required */);
   if (!stream.is_null()) {
     FILE *fp = (FILE *)stream_dictionary.remove(stream);
-    if (!fp)
+    if (0 == fp)
       error("cannot close nonexistent stream '%1'", stream.contents());
     else {
       int status = fclose(fp);
@@ -7036,7 +7036,7 @@ void do_write_request(int newline)
     return;
   }
   FILE *fp = (FILE *)stream_dictionary.lookup(stream);
-  if (!fp) {
+  if (0 == fp) {
     error("no stream named '%1'", stream.contents());
     skip_line();
     return;
@@ -7072,7 +7072,7 @@ void write_macro_request()
     return;
   }
   FILE *fp = (FILE *)stream_dictionary.lookup(stream);
-  if (!fp) {
+  if (0 == fp) {
     error("no stream named '%1'", stream.contents());
     skip_line();
     return;
@@ -7926,7 +7926,7 @@ void transparent_file()
   if (!filename.is_null()) {
     errno = 0;
     FILE *fp = include_search_path.open_file_cautious(filename.contents());
-    if (!fp)
+    if (0 == fp)
       error("can't open '%1': %2", filename.contents(), strerror(errno));
     else {
       int bol = 1;
@@ -8028,15 +8028,15 @@ static FILE *open_macro_package(const char *mac, char 
**path)
   strcpy(s1, mac);
   strcat(s1, MACRO_POSTFIX);
   FILE *fp = mac_path->open_file(s1, path);
-  if ((!fp) && (ENOENT != errno))
+  if ((0 == fp) && (ENOENT != errno))
     error("unable to open macro file '%1': %2", s1, strerror(errno));
   delete[] s1;
-  if (!fp) {
+  if (0 == fp) {
     char *s2 = new char[strlen(mac) + strlen(MACRO_PREFIX) + 1];
     strcpy(s2, MACRO_PREFIX);
     strcat(s2, mac);
     fp = mac_path->open_file(s2, path);
-    if ((!fp) && (ENOENT != errno))
+    if ((0 == fp) && (ENOENT != errno))
       error("unable to open macro file '%1': %2", s2, strerror(errno));
     delete[] s2;
   }
@@ -8047,7 +8047,7 @@ static void process_macro_package_argument(const char 
*mac)
 {
   char *path;
   FILE *fp = open_macro_package(mac, &path);
-  if (!fp)
+  if (0 == fp)
     fatal("unable to open macro file for -m argument '%1'", mac);
   const char *s = symbol(path).contents();
   free(path);
@@ -8062,7 +8062,7 @@ static void process_startup_file(const char *filename)
   search_path *orig_mac_path = mac_path;
   mac_path = &config_macro_path;
   FILE *fp = mac_path->open_file(filename, &path);
-  if (fp) {
+  if (fp != 0) {
     input_stack::push(new file_iterator(fp, symbol(path).contents()));
     free(path);
     tok.next();
@@ -8081,7 +8081,7 @@ void do_macro_source(bool quietly)
       tok.next();
     char *path;
     FILE *fp = mac_path->open_file(nm.contents(), &path);
-    if (fp) {
+    if (fp != 0) {
       input_stack::push(new file_iterator(fp, symbol(path).contents()));
       free(path);
     }
@@ -8120,7 +8120,7 @@ static void process_input_file(const char *name)
   else {
     errno = 0;
     fp = include_search_path.open_file_cautious(name);
-    if (!fp)
+    if (0 == fp)
       fatal("can't open '%1': %2", name, strerror(errno));
   }
   input_stack::push(new file_iterator(fp, name));

_______________________________________________
Groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to