gbranden pushed a commit to branch master
in repository groff.

commit b4532353dcb95a31404e803064c1e6674f2b2f94
Author: G. Branden Robinson <g.branden.robin...@gmail.com>
AuthorDate: Tue Feb 4 05:16:23 2025 -0600

    [troff]: Refactor and annotate.
    
    * src/roff/troff/input.cpp (define_character): Declare variables closer
      to their point of use.  Reorder conditional branches to put the more
      common case first.  Use C++ `static_cast` operator instead of C-style
      type cast.
---
 ChangeLog                |  7 +++++++
 src/roff/troff/input.cpp | 13 ++++++++-----
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 20936512b..f1fcffd2f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2025-02-04  G. Branden Robinson <g.branden.robin...@gmail.com>
+
+       * src/roff/troff/input.cpp (define_character): Refactor and
+       annotate.  Declare variables closer to their point of use.
+       Reorder conditional branches to put the more common case first.
+       Use C++ `static_cast` operator instead of C-style type cast.
+
 2025-02-04  G. Branden Robinson <g.branden.robin...@gmail.com>
 
        * src/roff/troff/input.cpp: Refactor.
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 32b158ffb..f9406fd50 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -4597,8 +4597,6 @@ static const char *character_mode_description(char_mode 
mode)
 void define_character(char_mode mode, const char *font_name)
 {
   const char *modestr = character_mode_description(mode);
-  node *n = 0 /* nullptr */;
-  int c;
   tok.skip();
   charinfo *ci = tok.get_char(true /* required */);
   if (0 /* nullptr */ == ci) {
@@ -4613,6 +4611,8 @@ void define_character(char_mode mode, const char 
*font_name)
     ci = get_charinfo(symbol(s.contents()));
   }
   tok.next();
+  int c;
+  node *n = 0 /* nullptr */;
   if (tok.is_newline())
     c = '\n';
   else if (tok.is_tab())
@@ -4631,13 +4631,16 @@ void define_character(char_mode mode, const char 
*font_name)
   if (c == '"')
     c = get_copy(&n);
   macro *m = new macro;
+  // Construct a macro from input characters; if the input character
+  // code is 0, we've read a node--append that.
   while (c != '\n' && c != EOF) {
-    if (c == 0)
-      m->append(n);
+    if (c != 0)
+      m->append(static_cast<unsigned char>(c));
     else
-      m->append((unsigned char) c);
+      m->append(n);
     c = get_copy(&n);
   }
+  // Assign the macro to the character, discarding any previous macro.
   m = ci->set_macro(m, mode);
   if (m)
     delete m;

_______________________________________________
groff-commit mailing list
groff-commit@gnu.org
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to