gbranden pushed a commit to branch master
in repository groff.

commit 7f259f122aabcb34ffc85e7dcf1e802ce9eecfd7
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sat Mar 14 10:45:48 2026 -0500

    [troff]: Fix Savannah #64275.
    
    * src/roff/troff/env.cpp: Throw warning in category "style" if (a)
      centering or right-alignment is configured while a temporary
      indentation is in effect; or (b) a temporary indentation request is
      issued while centering or right-alignment are in effect.
    
      (cancel_temporary_indentation): New function--which I suspect should
      be a member function of class `environment`, but which would be
      confusingly inconsistent with existing practice--sets the temporary
      indentation amount to zero and sets the property of having a temporary
      indent off.  (Those are not the same thing.  Temporary indentation
      _overrides_ ordinary indentation, so a temporary indent of zero is
      often sensible.)  Also tell the mysterious MTSM machine that temporary
      indentation is off.
    
      (center): Throw the aforementioned warning from this `ce`
      request handler.
    
      (right_justify): Throw the aforementioned warning from this `rj`
      request handler.
    
      (temporary_indent): Throw the aforementioned warning from this
      `ti` request handler.
    
    * src/roff/troff/env.h (class environment): Declare new non-OO
      `cancel_temporary_indentation()` function as a friend.
      (Eighties-style.  <finger guns>)
    
    * doc/groff.texi.in (Warnings):
    * src/roff/troff/troff.1.man (Warnings): Document it.
    
    Fixes <https://savannah.gnu.org/bugs/?64275>.  See
    <https://lists.gnu.org/archive/html/groff/2023-05/msg00079.html>
    for illustration of the ill-defined composition of these features and
    (brief) discussion.
---
 ChangeLog                  | 32 ++++++++++++++++++++++++++++++++
 doc/groff.texi.in          |  5 ++++-
 src/roff/troff/env.cpp     | 28 +++++++++++++++++++++++++++-
 src/roff/troff/env.h       |  6 ++++++
 src/roff/troff/troff.1.man |  5 ++++-
 5 files changed, 73 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fead03ec8..7cd62918b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,35 @@
+2026-03-14  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/env.cpp: Throw warning in category "style" if
+       {a} centering or right-alignment is configured while a temporary
+       indentation is in effect; or {b} a temporary indentation request
+       is issued while centering or right-alignment are in effect.
+       (cancel_temporary_indentation): New function--which I suspect
+       should be a member function of class `environment`, but which
+       would be confusingly inconsistent with existing practice--sets
+       the temporary indentation amount to zero and sets the property
+       of having a temporary indent off.  (Those are not the same
+       thing.  Temporary indentation _overrides_ ordinary indentation,
+       so a temporary indent of zero is often sensible.)  Also tell the
+       mysterious MTSM machine that temporary indentation is off.
+       (center): Throw the aforementioned warning from this `ce`
+       request handler.
+       (right_justify): Throw the aforementioned warning from this `rj`
+       request handler.
+       (temporary_indent): Throw the aforementioned warning from this
+       `ti` request handler.
+       * src/roff/troff/env.h (class environment): Declare new non-OO
+       `cancel_temporary_indentation()` function as a friend.
+       {Eighties-style.  <finger guns>}
+
+       * doc/groff.texi.in (Warnings):
+       * src/roff/troff/troff.1.man (Warnings): Document it.
+
+       Fixes <https://savannah.gnu.org/bugs/?64275>.  See
+       <https://lists.gnu.org/archive/html/groff/2023-05/msg00079.html>
+       for illustration of the ill-defined composition of these
+       features and (brief) discussion.
+
 2026-03-14  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/env.cpp (environment::space): Throw warning in
diff --git a/doc/groff.texi.in b/doc/groff.texi.in
index 137a93caf..e5bb29c5a 100644
--- a/doc/groff.texi.in
+++ b/doc/groff.texi.in
@@ -21604,7 +21604,10 @@ ambiguous delimiters are accepted without warning.
 Input was non-idiomatic or likely to produce an unexpected result
 (or none at all),
 but is not invalid:
-the end of a sentence was detected prior to the end of a text line.
+the end of a sentence was detected prior to the end of a text line;
+or
+an attempt was made to combine temporary indentation
+with centering or right-adjustment.
 
 @item scale
 @itemx 32
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index b9db99ca1..173b6f0ba 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -1463,6 +1463,13 @@ void no_fill()
   tok.next();
 }
 
+void cancel_temporary_indentation()
+{
+  curenv->temporary_indent = 0;
+  curenv->have_temporary_indent = false;
+  curdiv->modified_tag.excl(MTSM_TI);
+}
+
 void center()
 {
   int n;
@@ -1474,6 +1481,10 @@ void center()
     tok.next();
   if (was_invoked_with_regular_control_character)
     curenv->do_break();
+  if (curenv->have_temporary_indent)
+    warning(WARN_STYLE, "ignoring temporary indentation while"
+           " centering request in effect");
+  cancel_temporary_indentation();
   curenv->right_aligned_line_count = 0;
   curenv->centered_line_count = n;
   curdiv->modified_tag.incl(MTSM_CE);
@@ -1491,6 +1502,10 @@ void right_justify()
     tok.next();
   if (was_invoked_with_regular_control_character)
     curenv->do_break();
+  if (curenv->have_temporary_indent)
+    warning(WARN_STYLE, "ignoring temporary indentation while"
+           " right-alignment request in effect");
+  cancel_temporary_indentation();
   curenv->centered_line_count = 0;
   curenv->right_aligned_line_count = n;
   curdiv->modified_tag.incl(MTSM_RJ);
@@ -1619,8 +1634,19 @@ void temporary_indent()
     // character this request still breaks the line.
   }
   else {
+    if (curenv->centered_line_count > 0) {
+      is_valid = false;
+      warning(WARN_STYLE, "ignoring temporary indentation request while"
+           " centering text");
+    }
+    if (curenv->right_aligned_line_count > 0) {
+      is_valid = false;
+      warning(WARN_STYLE, "ignoring temporary indentation request while"
+             " right-aligning text");
+    }
     if (!read_hunits(&temp, 'm', curenv->get_indent()))
       is_valid = false;
+    // XXX: Why not `skip_line()`?
     while (!tok.is_newline() && !tok.is_eof())
       tok.next();
   }
@@ -1636,7 +1662,7 @@ void temporary_indent()
     curenv->have_temporary_indent = true;
     curdiv->modified_tag.incl(MTSM_TI);
   }
-  tok.next();
+  tok.next(); // XXX: Why not `skip_line()`?
 }
 
 void configure_underlining(bool want_spaces_underlined)
diff --git a/src/roff/troff/env.h b/src/roff/troff/env.h
index 25612b1f9..c2e7935f6 100644
--- a/src/roff/troff/env.h
+++ b/src/roff/troff/env.h
@@ -104,6 +104,11 @@ class font_family;
 class pending_output_line;
 
 // declarations to avoid friend name injection problems
+// XXX: Why are all of these global functions and not object methods?
+// Can't we make most/all of these ordinary member functions of class
+// `environment`?  And have request handlers read and validate request
+// arguments and then, if everything is kosher, call curenv->[one of the
+// below]?  --GBR, 2026
 void title_length();
 void space_size();
 void fill();
@@ -403,6 +408,7 @@ public:
   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();
diff --git a/src/roff/troff/troff.1.man b/src/roff/troff/troff.1.man
index 0cf7bcf93..ee5fa3506 100644
--- a/src/roff/troff/troff.1.man
+++ b/src/roff/troff/troff.1.man
@@ -813,7 +813,10 @@ style      16      T{
 Input was non-idiomatic or likely to produce an unexpected result
 (or none at all),
 but is not invalid:
-the end of a sentence was detected prior to the end of a text line.
+the end of a sentence was detected prior to the end of a text line;
+or
+an attempt was made to combine temporary indentation
+with centering or right-adjustment.
 T}
 .
 .

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

Reply via email to