gbranden pushed a commit to branch master
in repository groff.

commit f574a96f585b284ca0546064cd232e624ebefaec
Author: G. Branden Robinson <[email protected]>
AuthorDate: Tue Sep 3 12:14:29 2024 -0500

    [troff]: Make `pev` dump font's valid size table.
    
    * src/roff/troff/env.cpp (override_sizes): Fix regression introduced in
      commit 5f2704d64a, yesterday.  However, it was hard to tell whether
      the request works.
    
      (font_size::dump_size_table): New static member function reports the
      valid size table of the environment's currently selected font.
    
      (environment::print_env): Report the valid size table.
    
    * src/roff/groff/tests/sizes-request-works.sh: Test it.
    * src/roff/groff/groff.am (groff_TESTS): Run test.
    
    Fixes <https://savannah.gnu.org/bugs/?66164>.
---
 ChangeLog                                   | 15 +++++++++++++
 src/roff/groff/groff.am                     |  1 +
 src/roff/groff/tests/sizes-request-works.sh | 34 +++++++++++++++++++++++++++++
 src/roff/troff/env.cpp                      | 28 ++++++++++++++++++++++--
 src/roff/troff/env.h                        |  1 +
 5 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e2af9e972..d39638f8a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2024-09-03  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/env.cpp (override_sizes): Fix regression
+       introduced in commit 5f2704d64a, yesterday.  However, it was
+       hard to tell whether the request works.
+       (font_size::dump_size_table): New static member function reports
+       the valid size table of the environment's currently selected
+       font.
+       (environment::print_env): Report the valid size table.
+
+       * src/roff/groff/tests/sizes-request-works.sh: Test it.
+       * src/roff/groff/groff.am (groff_TESTS): Run test.
+
+       Fixes <https://savannah.gnu.org/bugs/?66164>.
+
 2024-09-03  G. Branden Robinson <[email protected]>
 
        Add tests to prevent recurrence of Savannah #66164.
diff --git a/src/roff/groff/groff.am b/src/roff/groff/groff.am
index 7cf6944e5..9fb262493 100644
--- a/src/roff/groff/groff.am
+++ b/src/roff/groff/groff.am
@@ -86,6 +86,7 @@ groff_TESTS = \
   src/roff/groff/tests/regression_savannah_58337.sh \
   src/roff/groff/tests/regression_savannah_59202.sh \
   src/roff/groff/tests/set-stroke-thickness.sh \
+  src/roff/groff/tests/sizes-request-works.sh \
   src/roff/groff/tests/soquiet-request-works.sh \
   src/roff/groff/tests/stringdown-and-stringup-requests-work.sh \
   src/roff/groff/tests/stringdown-request-rejects-request-names.sh \
diff --git a/src/roff/groff/tests/sizes-request-works.sh 
b/src/roff/groff/tests/sizes-request-works.sh
new file mode 100755
index 000000000..b40c62a9d
--- /dev/null
+++ b/src/roff/groff/tests/sizes-request-works.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+#
+# Copyright (C) 2024 Free Software Foundation, Inc.
+#
+# This file is part of groff.
+#
+# 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"
+
+input='.
+.pev
+.sizes 2-20 36
+.pev
+.'
+
+echo "checking that 'sizes' request works" >&2
+output=$(printf '%s\n' "$input" | "$groff" -T ps 2>&1)
+echo "$output" | grep 'valid type size table'
+echo "$output" | grep -Fq '2s-20s, 36s'
+
+# 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 6083ca5a2..ffd163345 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -248,6 +248,30 @@ void font_size::init_size_table(int *sizes)
   qsort(size_table, nranges, sizeof(size_range), compare_ranges);
 }
 
+void font_size::dump_size_table()
+{
+  int lo, hi;
+  errprint("  valid type size table for selected font: ");
+  if (nranges == 0)
+    errprint(" empty!");
+  else {
+    bool need_comma = false;
+    for (int i = 0; i < nranges; i++) {
+      lo = size_table[i].min;
+      hi = size_table[i].max;
+      if (need_comma)
+       errprint(", ");
+      if (lo == hi)
+       errprint("%1s", lo);
+      else
+       errprint("%1s-%2s", lo, hi);
+      need_comma = true;
+    }
+  }
+  errprint("\n");
+  fflush(stderr);
+}
+
 font_size::font_size(int sp)
 {
   for (int i = 0; i < nranges; i++) {
@@ -1323,10 +1347,9 @@ void point_size()
   skip_line();
 }
 
-// TODO: .psizes
 void override_sizes()
 {
-  if (!has_arg()) {
+  if (!has_arg(true /* peek */)) {
     warning(WARN_MISSING, "available font sizes override request"
            " expects at least one argument");
     skip_line();
@@ -3437,6 +3460,7 @@ void environment::print_env()
     errprint("  previous requested type size: %1s\n",
             prev_requested_size);
     errprint("  requested type size: %1s\n", requested_size);
+    font_size::dump_size_table();
   }
   errprint("  previous font selection: %1 ('%2')\n", prev_fontno,
           get_font_name(prev_fontno, this).contents());
diff --git a/src/roff/troff/env.h b/src/roff/troff/env.h
index f64341d1c..3052cb50e 100644
--- a/src/roff/troff/env.h
+++ b/src/roff/troff/env.h
@@ -36,6 +36,7 @@ public:
   int operator==(font_size);
   int operator!=(font_size);
   static void init_size_table(int *sizes);
+  static void dump_size_table();
 };
 
 inline font_size::font_size() : p(0)

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

Reply via email to