gbranden pushed a commit to branch master
in repository groff.

commit 431c81f144ec6fd0513cfd255a7d52f1dd9f834b
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Nov 14 16:01:47 2025 -0600

    [troff]: Track character class defn locations.
    
    * src/roff/troff/request.h (class macro): Declare new member function
      `dump()`, for specialized use with macros that always have zero-length
      contents.  What are these?  They correspond to the character class
      `charinfo` objects created by the `class` request.
    
    * src/roff/troff/input.cpp (define_class): Create a macro object with no
      contents and associate it with the character class being created.
    
      (macro::dump): New member function dumps file name and line number
      information.
---
 ChangeLog                | 13 +++++++++++++
 src/roff/troff/input.cpp | 12 ++++++++++++
 src/roff/troff/request.h |  1 +
 3 files changed, 26 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 9088ff3ce..6be839e08 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,19 @@
        buffer sizes (for C strings), and so doing express the maximal
        expected output to that buffer.
 
+2025-11-14  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/request.h (class macro): Declare new member
+       function `dump()`, for specialized use with macros that always
+       have zero-length contents.  What are these?  They correspond to
+       the character class `charinfo` objects created by the `class`
+       request.
+       * src/roff/troff/input.cpp (define_class): Create a macro object
+       with no contents and associate it with the character class being
+       created.
+       (macro::dump): New member function dumps file name and line
+       number information.
+
 2025-11-14  G. Branden Robinson <[email protected]>
 
        * Makefile.am: Include "contrib/install-font/install-font.am".
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 342260bdf..886425696 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -3922,6 +3922,14 @@ void macro::print_size()
   errprint("%1", len);
 }
 
+// Use this only for zero-length macros associated with charinfo objects
+// that are character classes.
+void macro::dump()
+{
+  if (filename != 0 /* nullptr */)
+    errprint("file name: \"%1\", line number: %2\n", filename, lineno);
+}
+
 void macro::json_dump()
 {
   bool need_comma = false;
@@ -8522,6 +8530,10 @@ void define_class()
     return;
   }
   charinfo *ci = get_charinfo(nm);
+  // Assign the charinfo an empty macro as a hack to record the
+  // file:line location of its definition.
+  macro *m = new macro;
+  (void) ci->set_macro(m);
   charinfo *child1 = 0 /* nullptr */, *child2 = 0 /* nullptr */;
   while (!tok.is_newline() && !tok.is_eof()) {
     tok.skip();
diff --git a/src/roff/troff/request.h b/src/roff/troff/request.h
index ce9967cf2..dd7f92428 100644
--- a/src/roff/troff/request.h
+++ b/src/roff/troff/request.h
@@ -70,6 +70,7 @@ public:
   bool is_diversion();
   bool is_string();
   void clear_string_flag();
+  void dump();
   void json_dump();
   friend class string_iterator;
   friend void chop_macro();

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

Reply via email to