[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 02/03: [troff]: Ignore out-of-range .ad argument.
From: |
G. Branden Robinson |
Subject: |
[groff] 02/03: [troff]: Ignore out-of-range .ad argument. |
Date: |
Mon, 25 Jan 2021 23:57:31 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit 62601add468b2eff56910173e339e3fa4490a3de
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Jan 25 17:36:34 2021 +1100
[troff]: Ignore out-of-range .ad argument.
* src/roff/troff/env.cpp: Add ADJUST_MAX enumeration constant to record
maximum valid numerical adjustment mode.
(adjust): Verify numeric argument against ADJUST_MAX instead of
numeric literal. Ignore excessively large values instead of setting
adjustment mode to "right". Update warning diagnostic.
This is a behavior change, albeit to how an invalid argument is
interpreted. What we call "AT&T troff" in our documentation is a
reference to CSTR #54 in its 1992 revision, which we use as a
specification because source code to the implementations was not freely
available. Because the above circumstance is out-of-spec, "AT&T troff"
says nothing about it and offers no precedent.
Given that, let's have a look at what other *roffs do.
* V7 Unix troff ignored invalid adjustment modes of all kinds, falling
off the end of a switch with no default case.
* DWB, Plan 9, and Solaris troff make no changes to V7 Unix troff here.
* Heirloom Doctools troff and Neatroff extend the range of valid numeric
arguments to support paragraph-at-a-time formatting.
* Neatroff furthermore supports an '.ad k' mode for support of
keshideh/kadisha justification of cursive scripts.
GNU troff's historical behavior here does not seem useful, and prepares
users poorly for adjustment modes groff may support in the future.
---
ChangeLog | 8 ++++++++
src/roff/troff/env.cpp | 18 +++++++++++-------
2 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8bc10cb..75f6ee3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2021-01-25 G. Branden Robinson <g.branden.robinson@gmail.com>
+ * src/roff/troff/env.cpp: Add ADJUST_MAX enumeration constant to
+ record maximum valid numerical adjustment mode.
+ (adjust): Verify numeric argument against ADJUST_MAX instead of
+ a numeric literal. Ignore excessively large values instead of
+ setting adjustment mode to "right". Update warning diagnostic.
+
+2021-01-25 G. Branden Robinson <g.branden.robinson@gmail.com>
+
Add regression test for .ad and .na requests.
* src/roff/groff/tests/adjustment_works.sh: Do it.
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index b86d7c6..83e2985 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -35,7 +35,12 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
symbol default_family("T");
-enum { ADJUST_LEFT = 0, ADJUST_BOTH = 1, ADJUST_CENTER = 3, ADJUST_RIGHT = 5 };
+enum { ADJUST_LEFT = 0,
+ ADJUST_BOTH = 1,
+ ADJUST_CENTER = 3,
+ ADJUST_RIGHT = 5,
+ ADJUST_MAX = 5,
+};
enum {
// Not all combinations are valid; see hyphenate_request() below.
@@ -1297,8 +1302,8 @@ void space_size()
curenv->space_size = n;
if (has_arg() && get_integer(&n))
if (n < 0)
- warning(WARN_RANGE, "negative sentence space size ignored:"
- " '%1'", n);
+ warning(WARN_RANGE, "negative sentence space size ignored: "
+ "'%1'", n);
else
curenv->sentence_space_size = n;
else
@@ -2523,10 +2528,9 @@ void adjust()
if (get_integer(&n)) {
if (n < 0)
warning(WARN_RANGE, "negative adjustment mode");
- else if (n > 5) {
- curenv->adjust_mode = 5;
- warning(WARN_RANGE, "adjustment mode '%1' out of range", n);
- }
+ else if (n > ADJUST_MAX)
+ warning(WARN_RANGE, "out-of-range adjustment mode ignored: "
+ "%1", n);
else
curenv->adjust_mode = n;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 02/03: [troff]: Ignore out-of-range .ad argument.,
G. Branden Robinson <=