gbranden pushed a commit to branch master
in repository groff.

commit ba78e9f7422ca4f3b725e3ad8a05fee9c44c0026
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Mar 15 08:10:25 2026 -0500

    [troff]: Implement `.ul` register.
    
    ...for orthogonal completeness with respect to the `.ce`, `.rj`, and
    `.itc` registers.
    
    * src/roff/troff/env.h (class environment): Declare new accessor member
      function `get_underlined_line_count()`.
    
    * src/roff/troff/env.cpp (environment::get_underlined_line_count):
      Define it.
    
      (init_env_requests): Wire up `.ul` register name to
      `get_underlined_line_count()`.
    
    * src/roff/groff/tests/dot-ul-register-works.sh: Test it.
    
    * src/roff/groff/groff.am (groff_TESTS): Run test.
    
    * doc/groff.texi.in (Artificial Fonts):
    * man/groff.7.man (Read-only registers):
    * man/groff_diff.7.man (New registers):
    * NEWS: Document it.
    
    Fixes <https://savannah.gnu.org/bugs/?68130>.
---
 ChangeLog                                     | 22 ++++++++++
 NEWS                                          |  4 ++
 doc/groff.texi.in                             |  9 +++-
 man/groff.7.man                               | 10 +++++
 man/groff_diff.7.man                          |  7 ++++
 src/roff/groff/groff.am                       |  1 +
 src/roff/groff/tests/dot-ul-register-works.sh | 59 +++++++++++++++++++++++++++
 src/roff/troff/env.cpp                        |  6 +++
 src/roff/troff/env.h                          |  1 +
 9 files changed, 118 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index d210d22a3..1bbdb3bb3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2026-03-14  G. Branden Robinson <[email protected]>
+
+       [troff]: Implement `.ul` register for orthogonal completeness
+       with respect to the `.ce`, `.rj`, and `.itc` registers.
+
+       * src/roff/troff/env.h (class environment): Declare new accessor
+       member function `get_underlined_line_count()`.
+       * src/roff/troff/env.cpp
+       (environment::get_underlined_line_count): Define it.
+       (init_env_requests): Wire up `.ul` register name to
+       `get_underlined_line_count()`.
+
+       * src/roff/groff/tests/dot-ul-register-works.sh: Test it.
+       * src/roff/groff/groff.am (groff_TESTS): Run test.
+
+       * doc/groff.texi.in (Artificial Fonts):
+       * man/groff.7.man (Read-only registers):
+       * man/groff_diff.7.man (New registers):
+       * NEWS: Document it.
+
+       Fixes <https://savannah.gnu.org/bugs/?68130>.
+
 2026-03-10  G. Branden Robinson <[email protected]>
 
        [troff]: Fix Savannah #68137.
diff --git a/NEWS b/NEWS
index 0bff96225..bdb002fc1 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,10 @@ troff
 *  GNU troff, the formatter, now issues warnings in the "delim",
    "syntax", and "escape" categories by default.
 
+*  A new read-only register `.ul` reports the count of productive input
+   lines remaining to be be underlined in the environment (as configured
+   by either the `cu` or `ul` requests).
+
 
 VERSION 1.24.1
 ==============
diff --git a/doc/groff.texi.in b/doc/groff.texi.in
index 0a94f69d8..8aa31feef 100644
--- a/doc/groff.texi.in
+++ b/doc/groff.texi.in
@@ -13948,7 +13948,8 @@ the slant is only assigned,
 never incremented or decremented.
 @endDefesc
 
-@Defreq {ul, [@Var{n}]}
+@DefreqList {ul, [@Var{n}]}
+@DefregListEndx {.ul}
 @cindex underlining (@code{ul})
 Underline
 (in
@@ -13967,6 +13968,12 @@ Omitting the argument implies an
 @var{n}
 of
 @samp{1}.
+The read-only register
+@code{.ul}
+stores the count of productive input lines
+remaining to be underlined,
+which is associated with the environment
+(@pxref{Environments}).
 
 When
 @code{ul}
diff --git a/man/groff.7.man b/man/groff.7.man
index c25944f6a..5cc69fd48 100644
--- a/man/groff.7.man
+++ b/man/groff.7.man
@@ -7623,6 +7623,16 @@ see
 option.
 .
 .TP
+.REG .ul
+Count of input lines remaining to be underlined
+in the environment.
+.
+See
+.request cu
+and
+.request ul .
+.
+.TP
 .REG .v
 The environment's vertical line spacing;
 see
diff --git a/man/groff_diff.7.man b/man/groff_diff.7.man
index 8b06cf661..d31ec8bc1 100644
--- a/man/groff_diff.7.man
+++ b/man/groff_diff.7.man
@@ -5312,6 +5312,13 @@ command-line option to
 .
 .
 .TP
+.B \[rs]n[.ul]
+Interpolate count of input lines remaining to be underlined
+(continuously or not)
+in the environment.
+.
+.
+.TP
 .B \[rs]n[.vpt]
 Interpolate\~1 if vertical position traps are enabled,
 0\~otherwise.
diff --git a/src/roff/groff/groff.am b/src/roff/groff/groff.am
index 4654731ee..d821dc73d 100644
--- a/src/roff/groff/groff.am
+++ b/src/roff/groff/groff.am
@@ -74,6 +74,7 @@ groff_TESTS = \
   src/roff/groff/tests/dot-nm-register-works.sh \
   src/roff/groff/tests/dot-nn-register-works.sh \
   src/roff/groff/tests/dot-trap-register-works.sh \
+  src/roff/groff/tests/dot-ul-register-works.sh \
   src/roff/groff/tests/double-do-request-does-not-fail-assertion.sh \
   src/roff/groff/tests/draw-arc.sh \
   src/roff/groff/tests/draw-circle.sh \
diff --git a/src/roff/groff/tests/dot-ul-register-works.sh 
b/src/roff/groff/tests/dot-ul-register-works.sh
new file mode 100755
index 000000000..1635b85ce
--- /dev/null
+++ b/src/roff/groff/tests/dot-ul-register-works.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+#
+# Copyright 2026 G. Branden Robinson
+#
+# This file is part of groff, the GNU roff typesetting system.
+#
+# groff is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# groff is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+groff="${abs_top_builddir:-.}/test-groff"
+
+# Unit test .ul register.
+
+input='.
+.ec @
+.nf
+.ul 2
+foo @n[.ul]
+bar @n[.ul]
+baz @n[.ul]
+.cu 1
+qux @n[.ul]
+jat @n[.ul]
+.'
+
+# Omitting `-P -cbou` would better illustrate the `cu` and `ul` requests
+# themselves, but is more tedious to pattern-match.
+#
+# Expected output:
+#  foo 2
+#  bar 1
+#  baz 0
+#  qux 1
+#  jat 0
+output=$(echo "$input" | $groff -T ascii -P -cbou)
+echo "$output"
+echo "$output" | grep -qx "foo 2" || exit 1
+echo "$output" | grep -qx "bar 1" || exit 1
+echo "$output" | grep -qx "baz 0" || exit 1
+# Backspace-overstriking still occurs when the continuous underlining
+# device extension is used.  That's probably correct given the
+# long-standing semantics of grotty(1)'s `-o` and `-u` options, but it
+# may also militate for a means of obtaining "least common denominator
+# of video terminal and Teletype Model 37" output, which is what some
+# external tools expect of grotty anyway.  See Savannah #67947.
+echo "$output" | grep -qx "qux.*1" || exit 1
+echo "$output" | grep -qx "jat 0" || exit 1
+
+# vim:set autoindent expandtab shiftwidth=2 tabstop=2 textwidth=72:
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index a229f34c1..07d3aa4e7 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -475,6 +475,11 @@ int environment::get_hyphen_line_count()
   return hyphen_line_count;
 }
 
+int environment::get_underlined_line_count()
+{
+  return underlined_line_count;
+}
+
 int environment::get_centered_line_count()
 {
   return centered_line_count;
@@ -4434,6 +4439,7 @@ void init_env_requests()
   init_string_env_reg(".sty", get_style_name_string);
   init_string_env_reg(".tabs", get_tabs);
   init_int_env_reg(".u", get_fill);
+  init_int_env_reg(".ul", get_underlined_line_count);
   init_vunits_env_reg(".v", get_vertical_spacing);
   init_hunits_env_reg(".w", get_prev_char_width);
   init_int_env_reg(".zoom", get_zoom);
diff --git a/src/roff/troff/env.h b/src/roff/troff/env.h
index 10607b8aa..25612b1f9 100644
--- a/src/roff/troff/env.h
+++ b/src/roff/troff/env.h
@@ -328,6 +328,7 @@ public:
   int get_hyphen_line_count();
   hunits get_hyphenation_space();
   hunits get_hyphenation_margin();
+  int get_underlined_line_count();
   int get_centered_line_count();
   int get_input_trap_line_count();
   int get_input_trap_respects_continuation();

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

Reply via email to