gbranden pushed a commit to branch master
in repository groff.

commit fe55a4e4b5cc555a0bfd7dc9859f73135abe2a6c
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed May 6 08:48:28 2026 -0500

    [troff]: Refactor.
    
    Separate engine logic from parsing logic with respect to an
    environment's temporary indentation.
    
    * src/roff/troff/env.h: Stop globally declaring `temporary_indent()`.
      (class environment): Declare new member functions returning `void`:
      `set_temporary_indent()` and `cancel_temporary_indent()`.  Drop
      declaration of `friend` functions `temporary_indent()` and
      `cancel_temporary_indentation()`.
    
    * src/roff/troff/env.cpp (environment::set_temporary_indent)
      (environment::cancel_temporary_indent): New functions mutate object of
      `environment` class.
    
      (set_temporary_indentation): New function updates the environment and
      through mutator functions, much like the existing
      `cancel_temporary_indentation()` does.
    
      (temporary_indent): Use accessor member functions of `environment`
      class to get at object properties.  Call `set_temporary_indentation()`
      instead of open-coding its operations.
    
    Continues the long process of fixing Savannah #68240.
---
 ChangeLog              | 25 +++++++++++++++++++++++++
 src/roff/troff/env.cpp | 34 ++++++++++++++++++++++++----------
 src/roff/troff/env.h   |  5 ++---
 3 files changed, 51 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 526e2c6e8..977a2c777 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2026-05-06  G. Branden Robinson <[email protected]>
+
+       [troff]: Refactor.  Separate engine logic from parsing logic
+       with respect to an environment's temporary indentation.
+
+       * src/roff/troff/env.h: Stop globally declaring
+       `temporary_indent()`.
+       (class environment): Declare new member functions returning
+       `void`: `set_temporary_indent()` and
+       `cancel_temporary_indent()`.  Drop declaration of `friend`
+       functions `temporary_indent()` and
+       `cancel_temporary_indentation()`.
+       * src/roff/troff/env.cpp (environment::set_temporary_indent)
+       (environment::cancel_temporary_indent): New functions mutate
+       object of `environment` class.
+       (set_temporary_indentation): New function updates the
+       environment and through mutator functions, much like the
+       existing `cancel_temporary_indentation()` does.
+       (temporary_indent): Use accessor member functions of
+       `environment` class to get at object properties.  Call
+       `set_temporary_indentation()` instead of open-coding its
+       operations.
+
+       Continues the long process of fixing Savannah #68240.
+
 2026-05-06  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/env.cpp (temporary_indent): Slightly refactor.
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 9e43344fa..f4113fcd1 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -1191,6 +1191,18 @@ hunits environment::get_temporary_indent()
   return temporary_indent;
 }
 
+void environment::set_temporary_indent(hunits amount)
+{
+  temporary_indent = amount;
+  have_temporary_indent = true;
+}
+
+void environment::cancel_temporary_indent()
+{
+  temporary_indent = 0;
+  have_temporary_indent = false;
+}
+
 hunits environment::get_title_length()
 {
   return title_length;
@@ -1518,10 +1530,15 @@ static void no_fill() // .nf
   tok.next();
 }
 
-void cancel_temporary_indentation()
+static void set_temporary_indentation(hunits amount)
 {
-  curenv->temporary_indent = 0;
-  curenv->have_temporary_indent = false;
+  curenv->set_temporary_indent(amount);
+  curdiv->modified_tag.incl(MTSM_TI);
+}
+
+static void cancel_temporary_indentation()
+{
+  curenv->cancel_temporary_indent();
   curdiv->modified_tag.excl(MTSM_TI);
 }
 
@@ -1687,12 +1704,12 @@ void temporary_indent() // .ti
            " argument");
   else {
     bool is_valid = true;
-    if (curenv->centered_line_count > 0) {
+    if (curenv->get_centered_line_count() > 0) {
       is_valid = false;
       warning(WARN_STYLE, "ignoring temporary indentation request while"
            " centering text");
     }
-    if (curenv->right_aligned_line_count > 0) {
+    if (curenv->get_right_aligned_line_count() > 0) {
       is_valid = false;
       warning(WARN_STYLE, "ignoring temporary indentation request while"
              " right-aligning text");
@@ -1704,11 +1721,8 @@ void temporary_indent() // .ti
              amount.to_units());
       amount = H0;
     }
-    if (is_valid) {
-      curenv->temporary_indent = amount;
-      curenv->have_temporary_indent = true;
-      curdiv->modified_tag.incl(MTSM_TI);
-    }
+    if (is_valid)
+      set_temporary_indentation(amount);
   }
   skip_line();
 }
diff --git a/src/roff/troff/env.h b/src/roff/troff/env.h
index 03606f601..207b7c3d1 100644
--- a/src/roff/troff/env.h
+++ b/src/roff/troff/env.h
@@ -119,7 +119,6 @@ void post_vertical_spacing();
 void line_spacing();
 void line_length();
 void indent();
-void temporary_indent();
 void configure_underlining(bool);
 void do_input_trap(bool);
 void set_tabs();
@@ -305,6 +304,8 @@ public:
   void configure_filling(bool);
   hunits get_indent();                 // .i
   hunits get_temporary_indent();
+  void set_temporary_indent(hunits);
+  void cancel_temporary_indent();
   hunits get_line_length();            // .l
   hunits get_saved_line_length();      // .ll
   hunits get_saved_indent();           // .in
@@ -403,10 +404,8 @@ public:
   friend void line_spacing();
   friend void line_length();
   friend void indent();
-  friend void temporary_indent();
   friend void configure_underlining(bool);
   friend void do_input_trap(bool);
-  friend void cancel_temporary_indentation();
   friend void set_tabs();
   friend void margin_character();
   friend void no_number();

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

Reply via email to