groff-commit
[Top][All Lists]
Advanced

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

[groff] 06/15: [libgroff]: Use C++98 null pointer constant.


From: G. Branden Robinson
Subject: [groff] 06/15: [libgroff]: Use C++98 null pointer constant.
Date: Fri, 17 Sep 2021 05:34:37 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 78993869749fc2abc010b64cb591af0d0ceba063
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Fri Sep 17 14:53:16 2021 +1000

    [libgroff]: Use C++98 null pointer constant.
    
    [libgroff]: Use idiomatic C++98 null pointer constant.
    
    * src/libs/libgroff/font.cpp (text_file::error, glyph_to_unicode,
      font::get_special_device_encoding, font::load):
    * src/libs/libgroff/fontfile.cpp (font::image_generator):
    * src/libs/libgroff/nametoindex.cpp (class charinfo,
      character_indexer::named_char_glyph,
      character_indexer::numbered_char_glyph):
    * src/libs/libgroff/string.cpp (string::clear):
    * src/libs/libgroff/tmpfile.cpp (temp_init::temp_init):
    * src/libs/libgroff/tmpname.cpp (gen_tempname): Use `0` literal instead
      of `NULL` to represent a null pointer; this was idiomatic in C++98 and
      is mostly the practice elsewhere in groff.  Also swap order of null
      pointer equality comparisons when a typo or thinko could lead to
      lvalue assignment.
    
    * src/roff/troff/input.cpp (input_stack::diversion_state,
      input_stack::get_diversion_state, charinfo::contains, glyph_to_name):
      Similar.
---
 ChangeLog                         | 23 +++++++++++++++++++++++
 src/libs/libgroff/font.cpp        | 18 +++++++++---------
 src/libs/libgroff/fontfile.cpp    |  2 +-
 src/libs/libgroff/nametoindex.cpp | 10 +++++-----
 src/libs/libgroff/string.cpp      |  2 +-
 src/libs/libgroff/tmpfile.cpp     | 10 +++++-----
 src/libs/libgroff/tmpname.cpp     |  4 ++--
 src/roff/troff/input.cpp          | 10 +++++-----
 8 files changed, 51 insertions(+), 28 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 47aeb18..900968b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,28 @@
 2021-09-17  G. Branden Robinson <g.branden.robinson@gmail.com>
 
+       [libgroff]: Use idiomatic C++98 null pointer constant.
+
+       * src/libs/libgroff/font.cpp (text_file::error,
+       glyph_to_unicode, font::get_special_device_encoding,
+       font::load):
+       * src/libs/libgroff/fontfile.cpp (font::image_generator):
+       * src/libs/libgroff/nametoindex.cpp (class charinfo,
+       character_indexer::named_char_glyph,
+       character_indexer::numbered_char_glyph):
+       * src/libs/libgroff/string.cpp (string::clear):
+       * src/libs/libgroff/tmpfile.cpp (temp_init::temp_init):
+       * src/libs/libgroff/tmpname.cpp (gen_tempname): Use `0` literal
+       instead of `NULL` to represent a null pointer; this was
+       idiomatic in C++98 and is mostly the practice elsewhere in
+       groff.  Also swap order of null pointer equality comparisons
+       when a typo or thinko could lead to lvalue assignment.
+
+       * src/roff/troff/input.cpp (input_stack::diversion_state,
+       input_stack::get_diversion_state, charinfo::contains,
+       glyph_to_name): Similar.
+
+2021-09-17  G. Branden Robinson <g.branden.robinson@gmail.com>
+
        [libgroff]: Slightly refactor.
 
        * src/libs/libgroff/font.cpp (font::load): Use same loop style
diff --git a/src/libs/libgroff/font.cpp b/src/libs/libgroff/font.cpp
index f03f448..f4ff387 100644
--- a/src/libs/libgroff/font.cpp
+++ b/src/libs/libgroff/font.cpp
@@ -148,7 +148,7 @@ void text_file::error(const char *format,
 int glyph_to_unicode(glyph *g)
 {
   const char *nm = glyph_to_name(g);
-  if (nm != NULL) {
+  if (nm != 0) {
     // ASCII character?
     if (nm[0] == 'c' && nm[1] == 'h' && nm[2] == 'a' && nm[3] == 'r'
        && (nm[4] >= '0' && nm[4] <= '9')) {
@@ -179,7 +179,7 @@ int glyph_to_unicode(glyph *g)
     }
     // groff glyphs that map to Unicode?
     const char *unicode = glyph_name_to_unicode(nm);
-    if (unicode != NULL && strchr(unicode, '_') == NULL) {
+    if (unicode != 0 && strchr(unicode, '_') == 0) {
       char *ignore;
       return (int)strtol(unicode, &ignore, 16);
     }
@@ -586,7 +586,7 @@ const char *font::get_special_device_encoding(glyph *g)
   }
   if (is_unicode) {
     // Unicode font
-    return NULL;
+    return 0;
   }
   abort();
 }
@@ -772,7 +772,7 @@ bool font::load(int *not_found, bool head_only)
   }
   FILE *fp;
   char *path;
-  if ((fp = open_file(name, &path)) == NULL) {
+  if ((fp = open_file(name, &path)) == 0) {
     if (not_found)
       *not_found = 1;
     else
@@ -892,7 +892,7 @@ bool font::load(int *not_found, bool head_only)
        if (head_only)
          return true;
        had_charset = true;
-       glyph *last_glyph = NULL;
+       glyph *last_glyph = 0;
        for (;;) {
          if (!t.next_line()) {
            command = 0;
@@ -907,7 +907,7 @@ bool font::load(int *not_found, bool head_only)
            break;
          }
          if (p[0] == '"') {
-           if (last_glyph == NULL) {
+           if (last_glyph == 0) {
              t.error("first charset entry is duplicate");
              return false;
            }
@@ -966,8 +966,8 @@ bool font::load(int *not_found, bool head_only)
                metric.width *= w;
            }
            p = strtok(0, WS);
-           if ((p == NULL) || (strcmp(p, "--") == 0)) {
-             metric.special_device_coding = NULL;
+           if ((0 == p) || (strcmp(p, "--") == 0)) {
+             metric.special_device_coding = 0;
            }
            else {
              char *nam = new char[strlen(p) + 1];
@@ -985,7 +985,7 @@ bool font::load(int *not_found, bool head_only)
            }
          }
        }
-       if (last_glyph == NULL) {
+       if (0 == last_glyph) {
          t.error("I didn't seem to find any characters");
          return false;
        }
diff --git a/src/libs/libgroff/fontfile.cpp b/src/libs/libgroff/fontfile.cpp
index c996c66..0ebe35c 100644
--- a/src/libs/libgroff/fontfile.cpp
+++ b/src/libs/libgroff/fontfile.cpp
@@ -46,7 +46,7 @@ bool font::pass_filenames = false;
 bool font::use_unscaled_charwidths = false;
 bool font::use_charnames_in_special = false;
 bool font::is_unicode = false;
-const char *font::image_generator = NULL;
+const char *font::image_generator = 0;
 const char **font::font_name_table = 0;
 int *font::sizes = 0;
 const char *font::family = 0;
diff --git a/src/libs/libgroff/nametoindex.cpp 
b/src/libs/libgroff/nametoindex.cpp
index 798007e..a8d628c 100644
--- a/src/libs/libgroff/nametoindex.cpp
+++ b/src/libs/libgroff/nametoindex.cpp
@@ -31,7 +31,7 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 // Every glyphinfo is actually a charinfo.
 class charinfo : glyph {
 public:
-  const char *name;    // The glyph name, or NULL.
+  const char *name;    // The glyph name, or a null pointer.
   friend class character_indexer;
 };
 
@@ -104,7 +104,7 @@ inline glyph *character_indexer::named_char_glyph(const 
char *s)
       return ascii_char_glyph((unsigned char)n);
   }
   charinfo *ci = table.lookupassoc(&s);
-  if (ci == NULL) {
+  if (0 == ci) {
     ci = new charinfo[1];
     ci->index = next_index++;
     ci->number = -1;
@@ -120,17 +120,17 @@ inline glyph *character_indexer::numbered_char_glyph(int 
n)
       charinfo *ci = new charinfo;
       ci->index = next_index++;
       ci->number = n;
-      ci->name = NULL;
+      ci->name = 0;
       small_number_glyph[n] = ci;
     }
     return small_number_glyph[n];
   }
   charinfo *ci = ntable.lookup(n);
-  if (ci == NULL) {
+  if (0 == ci) {
     ci = new charinfo[1];
     ci->index = next_index++;
     ci->number = n;
-    ci->name = NULL;
+    ci->name = 0;
     ntable.define(n, ci);
   }
   return ci;
diff --git a/src/libs/libgroff/string.cpp b/src/libs/libgroff/string.cpp
index 2cf267a..2392d16 100644
--- a/src/libs/libgroff/string.cpp
+++ b/src/libs/libgroff/string.cpp
@@ -277,7 +277,7 @@ void string::clear()
 
 int string::search(char c) const
 {
-  char *p = ptr ? (char *)memchr(ptr, c, len) : NULL;
+  char *p = ptr ? (char *)memchr(ptr, c, len) : 0;
   return p ? p - ptr : -1;
 }
 
diff --git a/src/libs/libgroff/tmpfile.cpp b/src/libs/libgroff/tmpfile.cpp
index f054ff1..5e807ae 100644
--- a/src/libs/libgroff/tmpfile.cpp
+++ b/src/libs/libgroff/tmpfile.cpp
@@ -64,22 +64,22 @@ temp_init::temp_init()
   const char *tem;
   // using the first match for any of the environment specs in listed order.
   if (
-      (tem = getenv(GROFF_TMPDIR_ENVVAR)) == NULL
-      && (tem = getenv(TMPDIR_ENVVAR)) == NULL
+      (tem = getenv(GROFF_TMPDIR_ENVVAR)) == 0
+      && (tem = getenv(TMPDIR_ENVVAR)) == 0
 #if defined(__MSDOS__) || defined(_WIN32)
       // If we didn't find a match for either of the above
       // (which are preferred, regardless of the host operating system),
       // and we are hosted on either MS-Windows or MS-DOS,
       // then try the Microsoft conventions.
-      && (tem = getenv(WIN32_TMPDIR_ENVVAR)) == NULL
-      && (tem = getenv(MSDOS_TMPDIR_ENVVAR)) == NULL
+      && (tem = getenv(WIN32_TMPDIR_ENVVAR)) == 0
+      && (tem = getenv(MSDOS_TMPDIR_ENVVAR)) == 0
 #endif
      )
     // If we didn't find an environment spec fall back to this default.
     tem = DEFAULT_TMPDIR;
   size_t tem_len = strlen(tem);
   const char *tem_end = tem + tem_len - 1;
-  int need_slash = strchr(DIR_SEPS, *tem_end) == NULL ? 1 : 0;
+  int need_slash = (strchr(DIR_SEPS, *tem_end) == 0) ? 1 : 0;
   char *tem2 = new char[tem_len + need_slash + 1];
   strcpy(tem2, tem);
   if (need_slash)
diff --git a/src/libs/libgroff/tmpname.cpp b/src/libs/libgroff/tmpname.cpp
index 4d96e90..69dc9a4 100644
--- a/src/libs/libgroff/tmpname.cpp
+++ b/src/libs/libgroff/tmpname.cpp
@@ -78,10 +78,10 @@ int gen_tempname(char *tmpl, int dir)
   /* Get some more or less random data.  */
 #if HAVE_GETTIMEOFDAY
   timeval tv;
-  gettimeofday(&tv, NULL);
+  gettimeofday(&tv, 0);
   uint64_t random_time_bits = ((uint64_t)tv.tv_usec << 16) ^ tv.tv_sec;
 #else
-  uint64_t random_time_bits = time(NULL);
+  uint64_t random_time_bits = time(0);
 #endif
   value += random_time_bits ^ getpid();
 
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 6019dfe..dad498e 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -469,7 +469,7 @@ input_iterator *input_stack::top = &nil_iterator;
 int input_stack::level = 0;
 int input_stack::limit = DEFAULT_INPUT_STACK_LIMIT;
 int input_stack::div_level = 0;
-statem *input_stack::diversion_state = NULL;
+statem *input_stack::diversion_state = 0;
 int suppress_push=0;
 
 
@@ -626,8 +626,8 @@ statem *get_diversion_state()
 
 statem *input_stack::get_diversion_state()
 {
-  if (diversion_state == NULL)
-    return NULL;
+  if (0 == diversion_state)
+    return 0;
   else
     return new statem(diversion_state);
 }
@@ -9032,7 +9032,7 @@ bool charinfo::contains(symbol s, bool already_called)
     return false;
   }
   const char *unicode = glyph_name_to_unicode(s.contents());
-  if (unicode != NULL && strchr(unicode, '_') == NULL) {
+  if (unicode != 0 && strchr(unicode, '_') == 0) {
     char *ignore;
     int c = (int)strtol(unicode, &ignore, 16);
     return contains(c, true);
@@ -9105,7 +9105,7 @@ glyph *number_to_glyph(int n)
 const char *glyph_to_name(glyph *g)
 {
   charinfo *ci = (charinfo *)g; // Every glyph is actually a charinfo.
-  return (ci->nm != UNNAMED_SYMBOL ? ci->nm.contents() : NULL);
+  return (ci->nm != UNNAMED_SYMBOL ? ci->nm.contents() : 0);
 }
 
 // Local Variables:



reply via email to

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