gbranden pushed a commit to branch master
in repository groff.

commit 3294f634db7708021542af5d13cca93373e595f2
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu May 15 08:46:04 2025 -0500

    [troff]: Fix code style nit.
    
    Use unsigned integer literals when assigning to or comparing with
    hyphenation codes, which are of type `unsigned char`.
    
    * src/roff/troff/charinfo.h (charinfo_node::get_asciify_code):
    * src/roff/troff/env.cpp (environment::hyphenate_line)
      (add_hyphenation_exceptions)
      (hyphenate):
    * src/roff/troff/input.cpp (set_hyphenation_codes)
      (charinfo::charinfo)
      (charinfo::set_translation):
    * src/roff/troff/node.cpp (break_char_node::add_self)
      (composite_node::asciify)
      (overstrike_node::get_hyphen_list): Do it.
    
    Also annotate null pointers with `nullptr` comment to ease any future
    transition to C++11, which defines it as a keyword.
---
 ChangeLog                 | 17 +++++++++++++++++
 src/roff/troff/charinfo.h |  4 ++--
 src/roff/troff/env.cpp    | 12 ++++++------
 src/roff/troff/input.cpp  | 10 +++++-----
 src/roff/troff/node.cpp   |  8 ++++----
 5 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 56039cbae..950a1e65e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2025-05-15  G. Branden Robinson <[email protected]>
+
+       [troff]: Fix code style nit; use unsigned integer literals when
+       assigning to or comparing with hyphenation codes, which are of
+       type `unsigned char`.
+
+       * src/roff/troff/charinfo.h (charinfo_node::get_asciify_code):
+       * src/roff/troff/env.cpp (environment::hyphenate_line)
+       (add_hyphenation_exceptions)
+       (hyphenate):
+       * src/roff/troff/input.cpp (set_hyphenation_codes)
+       (charinfo::charinfo)
+       (charinfo::set_translation):
+       * src/roff/troff/node.cpp (break_char_node::add_self)
+       (composite_node::asciify)
+       (overstrike_node::get_hyphen_list): Do it.
+
 2025-05-15  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/node.cpp: Fix code style nits.
diff --git a/src/roff/troff/charinfo.h b/src/roff/troff/charinfo.h
index 5f2a33362..9a84ab828 100644
--- a/src/roff/troff/charinfo.h
+++ b/src/roff/troff/charinfo.h
@@ -212,7 +212,7 @@ inline bool charinfo::is_special()
 inline charinfo *charinfo::get_translation(bool for_transparent_throughput)
 {
   return ((for_transparent_throughput && !is_transparently_translatable)
-         ? 0
+         ? 0 /* nullptr */
          : translation);
 }
 
@@ -228,7 +228,7 @@ inline unsigned char charinfo::get_ascii_code()
 
 inline unsigned char charinfo::get_asciify_code()
 {
-  return (translatable_as_input ? asciify_code : 0);
+  return (translatable_as_input ? asciify_code : 0U);
 }
 
 inline void charinfo::set_flags(unsigned int c)
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index dcb012c26..8f951eff5 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -2144,11 +2144,11 @@ void environment::hyphenate_line(bool must_break_here)
   }
   if (!inhibit) {
     // this is for characters like hyphen and emdash
-    int prev_code = 0;
+    unsigned char prev_code = 0U;
     for (hyphen_list *h = sl; h; h = h->next) {
-      h->is_breakable = (prev_code != 0
+      h->is_breakable = (prev_code != 0U
                         && h->next != 0 /* nullptr */
-                        && h->next->hyphenation_code != 0);
+                        && h->next->hyphenation_code != 0U);
       prev_code = h->hyphenation_code;
     }
   }
@@ -3791,7 +3791,7 @@ static void add_hyphenation_exceptions()
       }
       else {
        unsigned char c = ci->get_hyphenation_code();
-       if (0 == c)
+       if (0U == c)
          break;
        buf[i++] = c;
       }
@@ -4395,7 +4395,7 @@ void hyphenate(hyphen_list *h, unsigned flags)
   if (0 /* nullptr */ == current_language)
     return;
   while (h != 0 /* nullptr */) {
-    while ((h != 0 /* nullptr */) && (0 == h->hyphenation_code))
+    while ((h != 0 /* nullptr */) && (0U == h->hyphenation_code))
       h = h->next;
     int len = 0;
     // Locate hyphenable points within a (subset of) an input word.
@@ -4419,7 +4419,7 @@ void hyphenate(hyphen_list *h, unsigned flags)
     char *bufp = hbuf + 1;
     hyphen_list *tem;
     for (tem = h; tem && len < WORD_MAX; tem = tem->next) {
-      if (tem->hyphenation_code != 0)
+      if (tem->hyphenation_code != 0U)
        bufp[len++] = tem->hyphenation_code;
       else
        break;
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 242517773..bcdefaf1b 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -8110,7 +8110,7 @@ static void set_hyphenation_codes()
       error("cannot use the hyphenation code of a numeral");
       break;
     }
-    unsigned char new_code = '\0';
+    unsigned char new_code = 0U;
     charinfo *cisrc = tok.get_char();
     if (cisrc != 0 /* nullptr */)
       // Common case: assign destination character the hyphenation code
@@ -10135,7 +10135,7 @@ int charinfo::next_index = 0;
 
 charinfo::charinfo(symbol s)
 : translation(0 /* nullptr */), mac(0 /* nullptr */),
-  special_translation(TRANSLATE_NONE), hyphenation_code(0),
+  special_translation(TRANSLATE_NONE), hyphenation_code(0U),
   flags(0), ascii_code(0), asciify_code(0),
   is_not_found(false), is_transparently_translatable(true),
   translatable_as_input(false), mode(CHAR_NORMAL), nm(s)
@@ -10161,11 +10161,11 @@ void charinfo::set_translation(charinfo *ci, int tt, 
int ti)
 {
   translation = ci;
   if (ci && ti) {
-    if (hyphenation_code != 0)
+    if (hyphenation_code != 0U)
       ci->set_hyphenation_code(hyphenation_code);
-    if (asciify_code != 0)
+    if (asciify_code != 0U)
       ci->set_asciify_code(asciify_code);
-    else if (ascii_code != 0)
+    else if (ascii_code != 0U)
       ci->set_asciify_code(ascii_code);
     ci->make_translatable_as_input();
   }
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 20d879432..825bc0c7d 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -3103,7 +3103,7 @@ enum break_char_type {
 node *break_char_node::add_self(node *n, hyphen_list **p)
 {
   bool have_space_node = false;
-  assert(0 == (*p)->hyphenation_code);
+  assert(0U == (*p)->hyphenation_code);
   if (break_code & ALLOWS_BREAK_BEFORE) {
     if (((*p)->is_breakable)
        || (break_code & IGNORES_SURROUNDING_HYPHENATION_CODES)) {
@@ -4733,9 +4733,9 @@ hyphenation_type composite_node::get_hyphenation_type()
 void composite_node::asciify(macro *m)
 {
   unsigned char c = ci->get_asciify_code();
-  if (0 == c)
+  if (0U == c)
     c = ci->get_ascii_code();
-  if (c != 0) {
+  if (c != 0U) {
     m->append(c);
     delete this;
   }
@@ -6142,7 +6142,7 @@ node *overstrike_node::add_self(node *more_nodes, 
hyphen_list **p)
 
 hyphen_list *overstrike_node::get_hyphen_list(hyphen_list *tail, int *)
 {
-  return new hyphen_list(0, tail);
+  return new hyphen_list(0U, tail);
 }
 
 bool bracket_node::is_same_as(node *nd)

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

Reply via email to