gbranden pushed a commit to branch master
in repository groff.
commit 2cb1979ec2a11d38dd5df782614a8455a4a61dbc
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sat Jun 28 20:28:47 2025 -0500
[troff]: Add `GROFF_DUMP_NODES` experiment.
Add experimental, undocumented global node dumping feature. This
essentially produces a graph of the internal representation of the
entire input. (It's a forest, with one tree per output line.)
* src/roff/troff/input.h: Declare new global Boolean,
`want_nodes_dumped`.
* src/roff/troff/input.cpp: Define new global Boolean,
`want_nodes_dumped`, defaulting false.
(main): Set it to true if the environment variable `GROFF_DUMP_NODES`
exists (with any value).
* src/roff/troff/env.cpp (environment::do_break): Check the new global
variable; if it is true and if output is going to the top-level
diversion, dump the pending output line's node list in JSON format (to
the standard error stream) just prior to writing it as *roff output
(to the standard output stream).
---
ChangeLog | 19 +++++++++++++++++++
src/roff/troff/env.cpp | 2 ++
src/roff/troff/input.cpp | 3 +++
src/roff/troff/input.h | 1 +
4 files changed, 25 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index 4e8fbc16b..c3a59cc64 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2025-06-28 G. Branden Robinson <[email protected]>
+
+ [troff]: Add experimental, undocumented global node dumping
+ feature. This essentially produces a graph of the internal
+ representation of the entire input. (It's a forest, with one
+ tree per output line.)
+
+ * src/roff/troff/input.h: Declare new global Boolean,
+ `want_nodes_dumped`.
+ * src/roff/troff/input.cpp: Define new global Boolean,
+ `want_nodes_dumped`, defaulting false.
+ (main): Set it to true if the environment variable
+ `GROFF_DUMP_NODES` exists (with any value).
+ * src/roff/troff/env.cpp (environment::do_break): Check the new
+ global variable; if it is true and if output is going to the
+ top-level diversion, dump the pending output line's node list in
+ JSON format (to the standard error stream) just prior to writing
+ it as *roff output (to the standard output stream).
+
2025-06-29 G. Branden Robinson <[email protected]>
* tmac/pdf.tmac (pdf:SS): Delete now-unused macro.
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index f74d8ba98..9625b2da9 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -2601,6 +2601,8 @@ void environment::do_break(bool want_adjustment)
break;
}
}
+ if (want_nodes_dumped && (curdiv == topdiv))
+ curenv->dump_pending_nodes();
node *tem = line;
line = 0 /* nullptr */;
output_line(tem, width_total, was_centered);
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 7d7ff16e8..71f01d599 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -121,6 +121,7 @@ static symbol blank_line_macro_name;
static symbol leading_spaces_macro_name;
static bool want_att_compat = false;
bool want_abstract_output = false;
+bool want_nodes_dumped = false;
bool want_output_suppressed = false;
bool is_writing_html = false;
static int suppression_level = 0; // depth of nested \O escapes
@@ -9217,6 +9218,8 @@ int main(int argc, char **argv)
bool want_startup_macro_files_skipped = false;
int next_page_number = 0; // pacify compiler
hresolution = vresolution = 1;
+ if (getenv("GROFF_DUMP_NODES") != 0 /* nullptr */)
+ want_nodes_dumped = true;
// restore $PATH if called from groff
char* groff_path = getenv("GROFF_PATH__");
if (groff_path != 0 /* nullptr */) {
diff --git a/src/roff/troff/input.h b/src/roff/troff/input.h
index b351ffaa4..5f7d87484 100644
--- a/src/roff/troff/input.h
+++ b/src/roff/troff/input.h
@@ -69,6 +69,7 @@ extern void do_stroke_color(symbol);
extern void do_fill_color(symbol);
extern bool suppress_push;
+extern bool want_nodes_dumped;
// Local Variables:
// fill-column: 72
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit