gbranden pushed a commit to branch master
in repository groff.
commit 9c2d3d95aa84ff2af4f35a4d8d3e65307a8d0ebc
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed Apr 2 08:50:28 2025 -0500
[troff]: Add more info to macro dumps.
* src/roff/troff/input.cpp (macro::json_dump): Add more information when
dumping a macro (or diversion or string): report name of file where
it's defined if this information is available. Also report line
number and length. Also favor `errprint()` over `fputs()`.
---
ChangeLog | 8 ++++++++
src/roff/troff/input.cpp | 23 ++++++++++++++++++++---
2 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e2aa3b6e5..4e504d96c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2025-04-02 G. Branden Robinson <[email protected]>
+
+ * src/roff/troff/input.cpp (macro::json_dump): Add more
+ information when dumping a macro (or diversion or string):
+ report name of file where it's defined if this information is
+ available. Also report line number and length. Also favor
+ `errprint()` over `fputs()`.
+
2025-04-02 G. Branden Robinson <[email protected]>
* src/roff/troff/input.cpp (file_iterator::get_location): This
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index ee847cf1f..41e1b8e1c 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -3711,13 +3711,30 @@ void macro::print_size()
void macro::json_dump()
{
- if (p != 0 /* nullptr */)
+ bool need_comma = false;
+ // XXX: Unfortunately, if you alias or rename a request, the location
+ // of its invocation site is used for location information instead of
+ // its true origin.
+ if (filename != 0 /* nullptr */) {
+ symbol fn(filename); // `symbol` because it can't contain nulls.
+ const char *jsonfn = fn.json_extract();
+ errprint("\"file name\": %1", jsonfn);
+ free(const_cast<char *>(jsonfn));
+ fflush(stderr);
+ errprint(", \"starting line number\": %1", lineno);
+ need_comma = true;
+ }
+ if (need_comma)
+ errprint(", ");
+ errprint("\"length\": %1", len);
+ if (p != 0 /* nullptr */) {
+ if (need_comma)
+ errprint(", ");
if (is_a_diversion)
p->json_dump_diversion();
else
p->json_dump_macro();
- else
- fputs("\"\"", stderr);
+ }
}
// make a copy of the first n bytes
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit