gbranden pushed a commit to branch master
in repository groff.

commit 825dd547190b31edcb23e198b63f6e2952b4fde5
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Jul 12 07:24:23 2026 -0500

    [troff]: Refactor.
    
    * src/roff/troff/input.cpp (token::description):
    * src/roff/troff/node.cpp (make_glyph_node): Adapt new special character
      identifier quoting technique from `transparent_translate()`.
    
    When code is clear enough, comments are unnecessary.  Fingers crossed.
---
 ChangeLog                |  7 +++++++
 src/roff/troff/input.cpp | 16 +++++-----------
 src/roff/troff/node.cpp  | 22 ++++++++--------------
 3 files changed, 20 insertions(+), 25 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 600201695..671e379ad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2026-07-12  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/input.cpp (token::description):
+       * src/roff/troff/node.cpp (make_glyph_node): Adapt new special
+       character identifier quoting technique from
+       `transparent_translate()`.
+
 2026-07-12  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/input.cpp (transparent_translate): Improve
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 8ccdd85be..6b1749a0b 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -3157,17 +3157,7 @@ const char *token::description()
     return "a space";
   case TOKEN_SPECIAL_CHAR:
   case TOKEN_DELIMITED_SPECIAL_CHAR:
-    // We normally use apostrophes for quotation in diagnostic messages,
-    // but many special character names contain them.  Fall back to
-    // double quotes if this one does.  A user-defined special character
-    // name could contain both characters; we expect such users to lie
-    // comfortably in the bed they made for themselves.
-    // XXX: duplicates logic in node.cpp:make_glyph_node()
     {
-      const char *sc = nm.contents();
-      char qc = '\'';
-      if (strchr(sc, '\'') != 0 /* nullptr */)
-       qc = '"';
       // TODO: This truncates the names of impractically long special
       // character or character class names.  Do something about that.
       // (The truncation is visually indicated by the absence of a
@@ -3186,7 +3176,11 @@ const char *token::description()
        ctype = special_character_or_class;
       else if (ci->is_class())
        ctype = character_class;
-      (void) snprintf(buf, bufsz, "%s %c%s%c", ctype, qc, sc, qc);
+      char quote = '\'';
+      if (nm.contains(quote))
+       quote = '"';
+      (void) snprintf(buf, bufsz, "%s %c%s%c", ctype, quote,
+                     nm.contents(), quote);
       return buf;
     }
   case TOKEN_SPREAD:
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 0d3915108..64b190853 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -5661,23 +5661,17 @@ static node *make_glyph_node(charinfo *s, environment 
*env,
                    int(input_code));
        }
        else if (s->nm.contents()) {
-         // We normally use apostrophes for quotation in diagnostic
-         // messages, but many special character names contain them.
-         // Fall back to double quotes if this one does.  A user-
-         // defined special character name could contain both
-         // characters; we expect such users to lie comfortably in the
-         // bed they made for themselves.
-         // XXX: duplicates logic in input.cpp:token::description()
-         const char *nm = s->nm.contents();
-         char qc = '\'';
-         if (strchr(nm, '\'') != 0 /* nullptr */)
-           qc = '"';
          // If the contents are empty, get_char_for_escape_parameter()
          // should already have thrown an error.
-         if (nm[0] != '\0') {
-           const char *backslash = (nm[1] == '\0') ? "\\" : "";
+         symbol nm = s->nm;
+         const char *str = nm.contents();
+         if (str[0] != '\0') {
+           char quote = '\'';
+           if (nm.contains(quote))
+             quote = '"';
+           const char *backslash = (str[1] == '\0') ? "\\" : "";
            warning(WARN_CHAR, "special character %1%2%3%1 not defined",
-                   qc, backslash, nm);
+                   quote, backslash, str);
          }
        }
       }

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

Reply via email to