gbranden pushed a commit to branch master
in repository groff.

commit ccb867153a88644a34fc8a8fd1a9ff257dc29c6c
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Jan 17 19:33:29 2025 -0600

    src/roff/troff/input.cpp: Improve diagnostics.
    
    * src/roff/troff/input.cpp (define_character): Improve diagnostic
      message: characterize failing character definition as "invalid", not
      "bad", identify which request is being handled, report expected input,
      and describe input actually received.
---
 ChangeLog                |  7 +++++++
 src/roff/troff/input.cpp | 24 +++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 76f0cfef3..10b48acf6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2025-01-17  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/input.cpp (define_character): Improve
+       diagnostic message: characterize failing character definition as
+       "invalid", not "bad", identify which request is being handled,
+       report expected input, and describe input actually received.
+
 2025-01-17  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/input.cpp (define_character): Fix code style
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 3c2eb0b42..81f81e272 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -4559,7 +4559,29 @@ void define_character(char_mode mode, const char 
*font_name)
   else if (tok.is_tab())
     c = '\t';
   else if (!tok.is_space()) {
-    error("bad character definition");
+    // C++11: There may be a better way to do this with an enum class;
+    // we could then store these constants inside `char_mode`.
+    const char *modestr = 0 /* nullptr */;
+    switch (mode) {
+      case CHAR_NORMAL:
+       modestr = "";
+       break;
+      case CHAR_FALLBACK:
+       modestr = " fallback";
+       break;
+      case CHAR_SPECIAL:
+       modestr = " special fallback";
+       break;
+      case CHAR_FONT_SPECIAL:
+       modestr = " font-specific fallback";
+       break;
+      default:
+       assert(0 == "unhandled case of character mode");
+       break;
+    }
+    error("ignoring invalid%1 character definition; expected one"
+         " ordinary or special character to define, got %2", modestr,
+         tok.description());
     skip_line();
     return;
   }

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

Reply via email to