gbranden pushed a commit to branch master
in repository groff.
commit f2e672d312c3b67564a36a70a1cc5e9dc57e30e9
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed Sep 17 15:10:35 2025 -0500
[troff]: "Asciify" suppressed nodes as nothing.
* src/roff/troff/node.cpp: New file-scoped global variable
`is_output_supressed` tracks whether output is suppressed with the
`\O` escape sequence.
(suppress_node::asciify): New member function assigns to
`is_output_supressed` per the escape sequence argument (indirectly,
via the unhelpfully named `is_on` tri-state member variable.)
(node::asciify, glyph_node::asciify, kern_pair_node::asciify)
(dbreak_node::asciify, ligature_node::asciify)
(break_char_node::asciify, italic_corrected_node::asciify)
(left_italic_corrected_node::asciify)
(space_char_hmotion_node::asciify, word_space_node::asciify)
(unbreakable_space_node::asciify, composite_node::asciify): Texify
node contents only if output is not suppressed.
---
ChangeLog | 16 +++++++--
src/roff/troff/node.cpp | 91 +++++++++++++++++++++++++++++--------------------
2 files changed, 68 insertions(+), 39 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e43681bdf..50120538e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,8 +2,20 @@
* src/roff/troff/node.h (class suppress_node): Declare
`asciify` member function, thus overriding base class.
- * src/roff/troff/node.cpp (suppress_node::asciify): New member
- function simply does nothing.
+ * src/roff/troff/node.cpp: New file-scoped global variable
+ `is_output_supressed` tracks whether output is suppressed with
+ the `\O` escape sequence.
+ (suppress_node::asciify): New member function assigns to
+ `is_output_supressed` per the escape sequence argument
+ {indirectly, via the unhelpfully named `is_on` tri-state
+ member variable.}
+ (node::asciify, glyph_node::asciify, kern_pair_node::asciify)
+ (dbreak_node::asciify, ligature_node::asciify)
+ (break_char_node::asciify, italic_corrected_node::asciify)
+ (left_italic_corrected_node::asciify)
+ (space_char_hmotion_node::asciify, word_space_node::asciify)
+ (unbreakable_space_node::asciify, composite_node::asciify):
+ Texify node contents only if output is not suppressed.
2025-09-15 G. Branden Robinson <[email protected]>
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index fa2806674..11e82f0bb 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -63,6 +63,8 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
#include <stack>
+static bool is_output_supressed = false;
+
// declarations to avoid friend name injections
class tfont;
class tfont_spec;
@@ -3890,29 +3892,34 @@ void zero_width_node::ascii_print(ascii_output_file
*out)
void node::asciify(macro *m)
{
- m->append(this);
+ if (!is_output_supressed)
+ m->append(this);
}
void glyph_node::asciify(macro *m)
{
- unsigned char c = ci->get_asciify_code();
- if (0U == c)
- c = ci->get_ascii_code();
- if (c != 0U)
- m->append(c);
- else
- m->append(this);
+ if (!is_output_supressed) {
+ unsigned char c = ci->get_asciify_code();
+ if (0U == c) {
+ c = ci->get_ascii_code();
+ if (c != 0U)
+ m->append(c);
+ else
+ m->append(this);
+ }
+ else
+ m->append(this);
+ }
}
void kern_pair_node::asciify(macro *m)
{
- assert(n1 != 0 /* nullptr */);
- assert(n2 != 0 /* nullptr */);
- if (n1 != 0 /* nullptr */)
- n1->asciify(m);
- if (n2 != 0 /* nullptr */)
- n2->asciify(m);
- n1 = n2 = 0 /* nullptr */;
+ if (!is_output_supressed) {
+ if (n1 != 0 /* nullptr */)
+ n1->asciify(m);
+ if (n2 != 0 /* nullptr */)
+ n2->asciify(m);
+ }
}
static void asciify_reverse_node_list(macro *m, node *n)
@@ -3928,26 +3935,29 @@ static void asciify_reverse_node_list(macro *m, node *n)
void dbreak_node::asciify(macro *m)
{
assert(m != 0 /* nullptr */);
- if (m != 0 /* nullptr */)
- asciify_reverse_node_list(m, none);
- none = 0 /* nullptr */;
+ if (!is_output_supressed) {
+ if (m != 0 /* nullptr */)
+ asciify_reverse_node_list(m, none);
+ none = 0 /* nullptr */;
+ }
}
void ligature_node::asciify(macro *m)
{
assert(n1 != 0 /* nullptr */);
assert(n2 != 0 /* nullptr */);
- if (n1 != 0 /* nullptr */)
- n1->asciify(m);
- if (n2 != 0 /* nullptr */)
- n2->asciify(m);
- n1 = n2 = 0 /* nullptr */;
+ if (!is_output_supressed) {
+ if (n1 != 0 /* nullptr */)
+ n1->asciify(m);
+ if (n2 != 0 /* nullptr */)
+ n2->asciify(m);
+ }
}
void break_char_node::asciify(macro *m)
{
assert(nodes != 0 /* nullptr */);
- if (nodes != 0 /* nullptr */)
+ if (!is_output_supressed && (nodes != 0 /* nullptr */))
nodes->asciify(m);
nodes = 0 /* nullptr */;
}
@@ -3955,7 +3965,7 @@ void break_char_node::asciify(macro *m)
void italic_corrected_node::asciify(macro *m)
{
assert(nodes != 0 /* nullptr */);
- if (nodes != 0 /* nullptr */)
+ if (!is_output_supressed && (nodes != 0 /* nullptr */))
nodes->asciify(m);
nodes = 0 /* nullptr */;
}
@@ -3963,7 +3973,7 @@ void italic_corrected_node::asciify(macro *m)
void left_italic_corrected_node::asciify(macro *m)
{
assert(nodes != 0 /* nullptr */);
- if (nodes != 0 /* nullptr */)
+ if (!is_output_supressed && (nodes != 0 /* nullptr */))
nodes->asciify(m);
nodes = 0 /* nullptr */;
}
@@ -3988,7 +3998,8 @@ space_char_hmotion_node::space_char_hmotion_node(hunits
i, color *c,
void space_char_hmotion_node::asciify(macro *m)
{
- m->append(' ');
+ if (!is_output_supressed)
+ m->append(' ');
}
void space_node::asciify(macro *)
@@ -3997,13 +4008,16 @@ void space_node::asciify(macro *)
void word_space_node::asciify(macro *m)
{
- for (width_list *w = orig_width; w != 0 /* nullptr */; w = w->next)
- m->append(' ');
+ if (!is_output_supressed) {
+ for (width_list *w = orig_width; w != 0 /* nullptr */; w = w->next)
+ m->append(' ');
+ }
}
void unbreakable_space_node::asciify(macro *m)
{
- m->append(' ');
+ if (!is_output_supressed)
+ m->append(' ');
}
void line_start_node::asciify(macro *)
@@ -4064,6 +4078,7 @@ void overstrike_node::asciify(macro *)
void suppress_node::asciify(macro *)
{
+ is_output_supressed = (is_on == 0); // it's a three-valued Boolean :-/
}
void vline_node::asciify(macro *)
@@ -4799,13 +4814,15 @@ hyphenation_type composite_node::get_hyphenation_type()
void composite_node::asciify(macro *m)
{
- unsigned char c = ci->get_asciify_code();
- if (0U == c)
- c = ci->get_ascii_code();
- if (c != 0U)
- m->append(c);
- else
- m->append(this);
+ if (!is_output_supressed) {
+ unsigned char c = ci->get_asciify_code();
+ if (0U == c)
+ c = ci->get_ascii_code();
+ if (c != 0U)
+ m->append(c);
+ else
+ m->append(this);
+ }
}
void composite_node::ascii_print(ascii_output_file *ascii)
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit