gbranden pushed a commit to branch master
in repository groff.
commit 167abeb16cbcc0d4a2b8e39a905cea16d231b55d
Author: G. Branden Robinson <[email protected]>
AuthorDate: Tue Mar 10 07:21:48 2026 -0500
[troff]: Fix Savannah #68137.
* src/roff/troff/number.cpp (is_valid_expression): When interpreting a
parenthesized sub-expression within a numeric expression while in AT&T
compatibility mode, throw a warning in category "syntax" if
encountering a space in the input, advising of non-portability to that
family of formatters. GNU troff continues to interpret the expression
as it always has.
Fixes <https://savannah.gnu.org/bugs/?68137>.
Illustration:
$ printf '.nr a (1 + 1)\n.tm \\na\n' | ~/groff-1.22.3/bin/groff
2
$ printf '.nr a (1 + 1)\n.tm \\na\n' | ./build/test-groff
2
$ printf '.nr a (1 + 1)\n.tm \\na\n' | ./build/test-groff -C
troff:<standard input>:1: warning: a space within a numeric expression is
not portable to AT&T troff
2
$ printf '.nr a (1 + 1)\n.tm \\na\n' | dwb troff >/dev/null
1
$ printf '.nr a (1 + 1)\n.tm \\na\n' | 9 troff >/dev/null
1
$ printf '.nr a (1 + 1)\n.tm \\na\n' | heirloom troff >/dev/null
2
(Heirloom Doctools troff defaults to a groff compatibility mode. But
maybe not for much longer: <https://github.com/n-t-roff/\
heirloom-doctools/issues/87#issuecomment-496761804).
---
ChangeLog | 13 +++++++++++++
src/roff/troff/number.cpp | 10 ++++++++--
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 054c76ab6..d210d22a3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2026-03-10 G. Branden Robinson <[email protected]>
+
+ [troff]: Fix Savannah #68137.
+
+ * src/roff/troff/number.cpp (is_valid_expression): When
+ interpreting a parenthesized sub-expression within a numeric
+ expression while in AT&T compatibility mode, throw a warning in
+ category "syntax" if encountering a space in the input, advising
+ of non-portability to that family of formatters. GNU troff
+ continues to interpret the expression as it always has.
+
+ Fixes <https://savannah.gnu.org/bugs/?68137>.
+
2026-03-10 G. Branden Robinson <[email protected]>
[troff]: Make `want_att_compat` global. This is a prerequisite
diff --git a/src/roff/troff/number.cpp b/src/roff/troff/number.cpp
index e15f3c6f7..d36151ba9 100644
--- a/src/roff/troff/number.cpp
+++ b/src/roff/troff/number.cpp
@@ -249,8 +249,14 @@ static bool is_valid_expression(units *u, int scaling_unit,
int result = is_valid_term(u, scaling_unit, is_parenthesized,
is_mandatory);
while (result) {
- if (is_parenthesized)
- tok.skip_spaces();
+ if (is_parenthesized) {
+ if (want_att_compat && tok.is_space())
+ warning(WARN_SYNTAX, "%1 within a numeric expression"
+ " is not portable to AT&T troff", tok.description());
+ // See `token::skip_spaces()` in "input.cpp".
+ while (tok.is_space())
+ tok.next();
+ }
int op = tok.ch();// safely compares to char literals; TODO: grochar
switch (op) {
case int('+'): // TODO: grochar
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit