gbranden pushed a commit to branch master in repository groff. commit 4c586f362787b23dffbf32754e17a8a6748ee9be Author: G. Branden Robinson <g.branden.robin...@gmail.com> AuthorDate: Mon Mar 3 07:44:02 2025 -0600
[troff]: Implement recursive node dumping (5p/9). * src/roff/troff/node.h (struct width_list): Declare `dump()` member function. (class word_space_node): Specialize (override) `dump_properties()` for this class. * src/roff/troff/node.cpp (width_list::dump): New member function traverses a singly-linked of `width_list` nodes, and reports values of `width` and `sentence_width` properties. (word_space_node::dump_properties): New member function reports values of `width_list` (if not a null pointer) and `unformat` properties. Changes `pline` request output as follows. -{"type": "word_space_node", "diversion level": 0, "is_special_node": false, "hunits": 2500}] +{"type": "word_space_node", "diversion level": 0, "is_special_node": false, "hunits": 2500, "width_list": [{ "width": 2500, "sentence_width": 2500 }], "unformat": false}] --- ChangeLog | 13 +++++++++++++ src/roff/troff/node.cpp | 30 ++++++++++++++++++++++++++++++ src/roff/troff/node.h | 2 ++ 3 files changed, 45 insertions(+) diff --git a/ChangeLog b/ChangeLog index c4050044f..5b78df7d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2025-03-03 G. Branden Robinson <g.branden.robin...@gmail.com> + + * src/roff/troff/node.h (struct width_list): Declare `dump()` + member function. + (class word_space_node): Specialize (override) + `dump_properties()` for this class. + * src/roff/troff/node.cpp (width_list::dump): New member + function traverses a singly-linked of `width_list` nodes, and + reports values of `width` and `sentence_width` properties. + (word_space_node::dump_properties): New member function + reports values of `width_list` (if not a null pointer) and + `unformat` properties. + 2025-03-03 G. Branden Robinson <g.branden.robin...@gmail.com> * src/roff/troff/node.h (class draw_node): Specialize (override) diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp index facd48f88..c9595a8a5 100644 --- a/src/roff/troff/node.cpp +++ b/src/roff/troff/node.cpp @@ -4622,6 +4622,25 @@ width_list::width_list(width_list *w) { } +void width_list::dump() +{ + fputc('[', stderr); + bool need_comma = false; + fprintf(stderr, "{ \"width\": %d", width.to_units()); + fprintf(stderr, ", \"sentence_width\": %d }", + sentence_width.to_units()); + fflush(stderr); + width_list *n = this; + while (n->next != 0 /* nullptr */) { + if (need_comma) + fputs(", ", stderr); + need_comma = true; + n = n->next; + } + fputc(']', stderr); + fflush(stderr); +} + word_space_node::word_space_node(hunits d, color *c, width_list *w, node *x) : space_node(d, c, x), orig_width(w), unformat(false) { @@ -4634,6 +4653,17 @@ word_space_node::word_space_node(hunits d, int s, color *c, { } +void word_space_node::dump_properties() +{ + space_node::dump_properties(); + if (orig_width != 0 /* nullptr */) { + fputs(", \"width_list\": ", stderr); + orig_width->dump(); + } + fprintf(stderr, ", \"unformat\": %s", unformat ? "true" : "false"); + fflush(stderr); +} + word_space_node::~word_space_node() { width_list *w = orig_width; diff --git a/src/roff/troff/node.h b/src/roff/troff/node.h index 35b39d1ad..1d522bb41 100644 --- a/src/roff/troff/node.h +++ b/src/roff/troff/node.h @@ -229,6 +229,7 @@ struct width_list { width_list *next; width_list(hunits, hunits); width_list(width_list *); + void dump(); }; class word_space_node : public space_node { @@ -253,6 +254,7 @@ public: bool did_space_merge(hunits, hunits, hunits); bool causes_tprint(); bool is_tag(); + void dump_properties(); }; class unbreakable_space_node : public word_space_node { _______________________________________________ groff-commit mailing list groff-commit@gnu.org https://lists.gnu.org/mailman/listinfo/groff-commit