gbranden pushed a commit to branch master
in repository groff.

commit 31144d6d0ef60464f84de22b64055841e5b0c1bc
Author: G. Branden Robinson <g.branden.robin...@gmail.com>
AuthorDate: Tue Feb 4 04:31:31 2025 -0600

    [troff]: Improve diagnostic messages.
    
    * src/roff/troff/input.cpp (token::description): When describing special
      character, include its identifier.
---
 ChangeLog                |  5 +++++
 src/roff/troff/input.cpp | 13 +++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b87a39d04..e1116e1a3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2025-02-02  G. Branden Robinson <g.branden.robin...@gmail.com>
+
+       * src/roff/troff/input.cpp (token::description): When describing
+       special character, include its identifier.
+
 2025-01-28  G. Branden Robinson <g.branden.robin...@gmail.com>
 
        * src/roff/troff/input.cpp (is_char_usable_as_delimiter):
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 9f82c2a84..d0a3e916f 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -2686,7 +2686,11 @@ bool token::is_usable_as_delimiter(bool report_error)
 
 const char *token::description()
 {
-  const size_t bufsz = sizeof "character code XXX (U+XXXX)" + 1;
+  // Reserve a buffer large enough to handle the two lengthiest cases.
+  //   "character code XXX (U+XXXX)"
+  //   "special character 'bracketrighttp'"
+  const size_t maxstr = sizeof "special character 'bracketrighttp'";
+  const size_t bufsz = maxstr + 2; // for trailing '"' and null
   static char buf[bufsz];
   (void) memset(buf, 0, bufsz);
   switch (type) {
@@ -2734,7 +2738,12 @@ const char *token::description()
   case TOKEN_SPACE:
     return "a space";
   case TOKEN_SPECIAL_CHAR:
-    return "a special character";
+    // 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;
   case TOKEN_SPREAD:
     return "an escaped 'p'";
   case TOKEN_STRETCHABLE_SPACE:

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

Reply via email to