gbranden pushed a commit to branch master
in repository groff.

commit 1277744e72b39adf8be930164b6f2a9db3501000
Author: G. Branden Robinson <[email protected]>
AuthorDate: Tue Aug 20 16:02:54 2024 -0500

    [troff]: Improve diagnostic messages.
    
    * src/roff/troff/input.cpp (get_delimited_name, do_if_request)
      (read_drawing_command, read_drawing_command_color_arguments): When
      complaining of mismatched or missing closing delimeter, report the
      identity of the delimiter we were expecting.
    
    * src/roff/troff/reg.cpp (alter_format): When complaining of invalid
      register format, list the valid ones.
---
 ChangeLog                |  9 +++++++++
 src/roff/troff/input.cpp | 34 ++++++++++++++++++++++++++++++----
 src/roff/troff/reg.cpp   |  3 ++-
 3 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9c72d987a..eccc3fbab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-08-20  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/input.cpp (get_delimited_name, do_if_request)
+       (read_drawing_command, read_drawing_command_color_arguments):
+       When complaining of mismatched or missing closing delimeter,
+       report the identity of the delimiter we were expecting.
+       * src/roff/troff/reg.cpp (alter_format): When complaining of
+       invalid register format, list the valid ones.
+
 2024-08-20  G. Branden Robinson <[email protected]>
 
        * tmac/fallbacks.tmac: Define fallback character for U+2717
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 224286d43..93d7b4918 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -5453,7 +5453,14 @@ static symbol get_delimited_name()
        && (want_att_compat || input_stack::get_level() == start_level))
       break;
     if ((buf[i] = tok.ch()) == 0) {
-      error("missing delimiter (got %1)", tok.description());
+      // token::description() writes to static, class-wide storage, so
+      // we must allocate a copy of it before issuing the next
+      // diagnostic.
+      char *delimdesc = strdup(start_token.description());
+      if (start_token != tok)
+       error("closing delimiter does not match; expected %1, got %2",
+             delimdesc, tok.description());
+      free(delimdesc);
       if (buf != abuf)
        delete[] buf;
       return NULL_SYMBOL;
@@ -6111,6 +6118,7 @@ static bool do_if_request()
   else if (tok.is_space())
     result = false;
   else if (tok.is_usable_as_delimiter()) {
+    // Perform (formatted) output comparison.
     token delim = tok;
     int delim_level = input_stack::get_level();
     environment env1(curenv);
@@ -6122,8 +6130,14 @@ static bool do_if_request()
       for (;;) {
        tok.next();
        if (tok.is_newline() || tok.is_eof()) {
+         // token::description() writes to static, class-wide storage,
+         // so we must allocate a copy of it before issuing the next
+         // diagnostic.
+         char *delimdesc = strdup(delim.description());
          warning(WARN_DELIM, "missing closing delimiter in output"
-                 " comparison operator (got %1)", tok.description());
+                 " comparison operator; expected %1, got %2",
+                 delimdesc, tok.description());
+         free(delimdesc);
          tok.next();
          curenv = oldenv;
          return false;
@@ -8959,8 +8973,14 @@ static node *read_drawing_command()
          delete[] oldpoint;
        }
        if (tok.is_newline() || tok.is_eof()) {
+         // token::description() writes to static, class-wide storage,
+         // so we must allocate a copy of it before issuing the next
+         // diagnostic.
+         char *delimdesc = strdup(start_token.description());
          warning(WARN_DELIM, "missing closing delimiter in drawing"
-                 " escape sequence (got %1)", tok.description());
+                 " escape sequence; expected %1, got %2", delimdesc,
+                 tok.description());
+         free(delimdesc);
          had_error = true;
          break;
        }
@@ -9072,8 +9092,14 @@ static void read_drawing_command_color_arguments(token 
&start)
     curenv->set_fill_color(col);
   while (tok != start) {
     if (tok.is_newline() || tok.is_eof()) {
+      // token::description() writes to static, class-wide storage, so
+      // we must allocate a copy of it before issuing the next
+      // diagnostic.
+      char *delimdesc = strdup(start.description());
       warning(WARN_DELIM, "missing closing delimiter in color space"
-             " drawing escape sequence (got %1)", tok.description());
+             " drawing escape sequence; expected %1, got %2",
+             delimdesc, tok.description());
+      free(delimdesc);
       input_stack::push(make_temp_iterator("\n"));
       break;
     }
diff --git a/src/roff/troff/reg.cpp b/src/roff/troff/reg.cpp
index 654b2c371..1264a6f23 100644
--- a/src/roff/troff/reg.cpp
+++ b/src/roff/troff/reg.cpp
@@ -423,7 +423,8 @@ void alter_format()
   else if (tok.is_newline() || tok.is_eof())
     warning(WARN_MISSING, "missing register format");
   else
-    error("invalid register format (got %1)", tok.description());
+    error("invalid register format; expected 'i', 'I', 'a', 'A',"
+          " or decimal digits, got %1", tok.description());
   skip_line();
 }
 

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

Reply via email to