gbranden pushed a commit to branch master
in repository groff.

commit 236e754ccbc6f488ac0d5f88e93ef19d88a7e2d9
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed Apr 15 05:18:06 2026 -0500

    src/roff/troff/node.cpp: Refactor (1/3).
    
    ...some gro(h)t(ml)esquerie.
    
    * src/roff/troff/node.cpp (suppress_node::tprint): Refactor code
      populating "grohtml-info" output to access the formatter's page offset
      and line length parameters directly, instead of going through the
      register dictionary.  Because we're adding them, check that addition
      for overflow; preprocessor-include "<stdckdint.h>" accordingly.
    
    We can consequently drop some now-unused code.
    
    * src/roff/troff/div.cpp (class page_offset_reg): Drop `get_value()`
      declaration.
      (page_offset_reg::get_value): Delete.
---
 ChangeLog               | 15 +++++++++++++++
 src/roff/troff/div.cpp  |  7 -------
 src/roff/troff/node.cpp | 10 ++++++++--
 3 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3c03fdbf3..3b51d9eaa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2026-04-15  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/node.cpp (suppress_node::tprint): Refactor code
+       populating "grohtml-info" output to access the formatter's page
+       offset and line length parameters directly, instead of going
+       through the register dictionary.  Because we're adding them,
+       check that addition for overflow; preprocessor-include
+       "<stdckdint.h>" accordingly.
+
+       We can consequently drop some now-unused code.
+
+       * src/roff/troff/div.cpp (class page_offset_reg): Drop
+       `get_value()` declaration.
+       (page_offset_reg::get_value): Delete.
+
 2026-04-14  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/div.cpp: Drop unused code introduced in initial
diff --git a/src/roff/troff/div.cpp b/src/roff/troff/div.cpp
index a700c69ee..46d8c828b 100644
--- a/src/roff/troff/div.cpp
+++ b/src/roff/troff/div.cpp
@@ -1075,16 +1075,9 @@ static void vertical_position_traps() // .vpt
 
 class page_offset_reg : public reg {
 public:
-  bool get_value(units *);
   const char *get_string();
 };
 
-bool page_offset_reg::get_value(units *res)
-{
-  *res = topdiv->get_page_offset().to_units();
-  return true;
-}
-
 const char *page_offset_reg::get_string()
 {
   return i_to_a(topdiv->get_page_offset().to_units());
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 3f77e5faa..1fb701c90 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -23,6 +23,7 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 #endif
 
 #include <errno.h>
+#include <stdckdint.h> // ckd_add() in suppress_node::tprint() hackery
 #include <stdio.h> // prerequisite of searchpath.h
 #include <stdlib.h> // free(), malloc()
 #include <string.h> // strerror()
@@ -4774,14 +4775,19 @@ void suppress_node::tprint(troff_output_file *out)
        //        topdiv->get_page_number(),
        //        suppression_starting_page_number);
        // `name` will contain a "%d" in which the image_no is placed.
+       units page_width; // not counting the right margin
+       if (ckd_add(&page_width, topdiv->get_page_offset().to_units(),
+                   curenv->get_line_length().to_units()))
+         // This really should never happen.
+         warning(WARN_RANGE, "addition saturated when adding"
+                 " page offset and line length for grohtml-info");
        fprintf(stderr,
                "grohtml-info:page %d  %d  %d  %d  %d  %d  %s  %d  %d"
                "  %s:%s\n",
                topdiv->get_page_number(),
                get_register("opminx"), get_register("opminy"),
                get_register("opmaxx"), get_register("opmaxy"),
-               // page offset + line length
-               get_register(".o") + get_register(".l"),
+               page_width,
                name, hresolution, vresolution, get_string(".F"),
                get_string(".c"));
        fflush(stderr);

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to