gbranden pushed a commit to branch master
in repository groff.

commit 1bc99ac0ac4f998efd2345722773a2cc87d879b4
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Nov 14 11:20:23 2025 -0600

    [troff]: Improve diagnostic messages (2/2).
    
    * src/roff/troff/input.cpp (token::description): Improve quotation of
      special character names.
---
 ChangeLog                |  5 +++++
 src/roff/troff/input.cpp | 23 +++++++++++++++++------
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a97ebf6e5..fa634c7f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2025-11-14  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/input.cpp (token::description): Improve
+       quotation of special character names.
+
 2025-11-14  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/input.cpp (token::description): Improve
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 3cbbe39a7..6a8af79c0 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -2907,12 +2907,23 @@ const char *token::description()
   case TOKEN_SPACE:
     return "a space";
   case TOKEN_SPECIAL_CHAR:
-    // TODO: This truncates the names of impractically long special
-    // character names.  Do something about that.  (The truncation is
-    // visually indicated by the absence of a closing quotation mark.)
-    (void) snprintf(buf, maxstr, "special character \"%s\"",
-                   nm.contents());
-    return buf;
+    // We normally using 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.
+    {
+      const char *sc = nm.contents();
+      char qc = '\'';
+      if (strchr(sc, '\'') != 0 /* nullptr */)
+       qc = '"';
+      // TODO: This truncates the names of impractically long special
+      // character names.  Do something about that.  (The truncation is
+      // visually indicated by the absence of a closing quotation mark.)
+      (void) snprintf(buf, maxstr, "special character %c%s%c", qc, sc,
+                     qc);
+      return buf;
+    }
   case TOKEN_SPREAD:
     return "an escaped 'p'";
   case TOKEN_STRETCHABLE_SPACE:

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

Reply via email to