groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 02/02: [troff]: Make `pline` report nodes in fwd order.


From: G. Branden Robinson
Subject: [groff] 02/02: [troff]: Make `pline` report nodes in fwd order.
Date: Tue, 30 Apr 2024 15:16:07 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit b3239d5b58a97d6a33e7d87b449b3f77a2f8a68b
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Tue Apr 30 13:10:02 2024 -0500

    [troff]: Make `pline` report nodes in fwd order.
    
    * src/roff/troff/node.cpp (node::debug_node): Report list of nodes
      produced by most recent input line in forward order, likely
      corresponding to user intuition.  (Internally, the formatter stores
      the nodes in LIFO order, for the convenience of traversing a
      singly-list list.)
    
    Demonstration:
    
    $ cat EXPERIMENTS/test-dumping-pending-output-line-node-list.groff
    foo \f[B]bar\f[]
    baz\~qux
    .pline
    .tm doing `pline` again should result in no output
    .pline
    .pl \n[nl]u
    $ nroff EXPERIMENTS/test-dumping-pending-output-line-node-list.groff
    { line_start_node  nest level 0 }
    { glyph_node [f nest level 0]}
    { glyph_node [o nest level 0]}
    { glyph_node [o nest level 0]}
    { word_space_node  nest level 0 }
    { glyph_node [b nest level 0]}
    { glyph_node [a nest level 0]}
    { glyph_node [r nest level 0]}
    { word_space_node  nest level 0 }
    { glyph_node [b nest level 0]}
    { glyph_node [a nest level 0]}
    { glyph_node [z nest level 0]}
    { unbreakable_space_node  nest level 0 }
    { glyph_node [q nest level 0]}
    { glyph_node [u nest level 0]}
    { glyph_node [x nest level 0]}
    doing `pline` again should result in no output
    foo bar baz qux
---
 ChangeLog               |  8 ++++++++
 src/roff/troff/node.cpp | 14 +++++++++++---
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fb04e4c1a..a64698c65 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-04-30  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       * src/roff/troff/node.cpp (node::debug_node): Report list of
+       nodes produced by most recent input line in forward order,
+       likely corresponding to user intuition.  (Internally, the
+       formatter stores the nodes in LIFO order, for the convenience of
+       traversing a singly-list list.)
+
 2024-04-30  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        [troff]: Add new request `pline` to dump list of nodes
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index cc11507e1..f5d38e1e9 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -57,6 +57,8 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 
 #endif /* not _POSIX_VERSION */
 
+#include <stack>
+
 // declarations to avoid friend name injections
 class tfont;
 class tfont_spec;
@@ -2562,12 +2564,18 @@ void node::debug_node()
 
 void node::debug_node_list()
 {
+  // It's stored in reverse order already; this puts it forward again.
+  std::stack<node *> reversed_node_list;
   node *n = next;
 
-  debug_node();
-  while (n != 0 /* nullptr */) {
-    n->debug_node();
+  assert(next != 0 /* nullptr */);
+  do {
+    reversed_node_list.push(n);
     n = n->next;
+  } while (n != 0 /* nullptr */);
+  while (!reversed_node_list.empty()) {
+    reversed_node_list.top()->debug_node();
+    reversed_node_list.pop();
   }
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]