gbranden pushed a commit to branch master in repository groff. commit c9d9a4e1e743d84de96ef4f6d2bde6b09bc67b1e Author: G. Branden Robinson <g.branden.robin...@gmail.com> AuthorDate: Fri Mar 21 14:50:12 2025 -0500
[troff]: Warn on failure to adjust the output line. * src/roff/troff/env.cpp (distribute_space): I planted an `assert()` land mine for myself back in December and it finally went off. Remove assertion that the amount of `desired_space` for adjustment must be nonnegative. While rare, this can in fact happen with perverse inputs such as long, unhyphenable character sequences or short output line lengths. Throw new warnings in category "break" when adjustment is desired but impossible: (1) the output line has no adjustable spaces on it, or (2) any adjustable spaces would have to be squeezable/ shrinkable to achieve a fit, and that is not yet implemented in GNU troff (see Savannah #44018). (Even if/when we do implement it, there will be a [likely configurable] limit to how narrow an adjustable space can become.) * doc/groff.texi.in (Warnings): * src/roff/troff/troff.1.man (Warnings): Document additional circumstances under which warnings in "break" category are thrown. Clarify existing circumstances. Fixes <https://savannah.gnu.org/bugs/?66392>. Also annotate places in code that I think will likely need to change upon tackling Savannah #44018. --- ChangeLog | 25 +++++++++++++++++++++++++ doc/groff.texi.in | 11 ++++++++--- src/roff/troff/env.cpp | 16 +++++++++++++++- src/roff/troff/troff.1.man | 9 ++++++--- 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 833cfb60f..ab1b997cc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +2025-03-21 G. Branden Robinson <g.branden.robin...@gmail.com> + + [troff]: Warn on failure to adjust the output line. + + * src/roff/troff/env.cpp (distribute_space): I planted an + `assert()` land mine for myself back in December and it finally + went off. Remove assertion that the amount of `desired_space` + for adjustment must be nonnegative. While rare, this can in + fact happen with perverse inputs such as long, unhyphenable + character sequences or short output line lengths. Throw new + warnings in category "break" when adjustment is desired but + impossible: (1) the output line has no adjustable spaces on it, + or (2) any adjustable spaces would have to be squeezable/ + shrinkable to achieve a fit, and that is not yet implemented in + GNU troff (see Savannah #44018). (Even if/when we do implement + it, there will be a [likely configurable] limit to how narrow an + adjustable space can become.) + + * doc/groff.texi.in (Warnings): + * src/roff/troff/troff.1.man (Warnings): Document additional + circumstances under which warnings in "break" category are + thrown. Clarify existing circumstances. + + Fixes <https://savannah.gnu.org/bugs/?66392>. + 2025-03-20 G. Branden Robinson <g.branden.robin...@gmail.com> [troff]: Implement macro/string/diversion dumper. diff --git a/doc/groff.texi.in b/doc/groff.texi.in index 4ff7c88d5..03f588f65 100644 --- a/doc/groff.texi.in +++ b/doc/groff.texi.in @@ -17973,9 +17973,14 @@ by default. @itemx 4 @cindex filling, and @code{break} warnings @cindex mode, fill, and @code{break} warnings -A filled output line could not be broken such that its length was less -than the output line length @samp{\n[.l]}. This category is enabled by -default. +@cindex adjustment, and @code{break} warnings +A filled output line could not be +broken such that its length was less than or equal to, +or +adjusted such that its length was exactly equal to, +the output line length +@samp{\n[.l]}. +This category is enabled by default. @item delim @itemx 8 diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp index 37dd7954c..90eea11f2 100644 --- a/src/roff/troff/env.cpp +++ b/src/roff/troff/env.cpp @@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <errno.h> // errno #include <math.h> // ceil() +#include <stdlib.h> // abs() #include <vector> #include <algorithm> // find() @@ -2100,6 +2101,9 @@ breakpoint *environment::choose_breakpoint() } if (best_bp) { if (!best_bp_fits) + // TODO: If we implement shrinkable/squeezable adjustable spaces, + // this warning could become spurious in cases where we can + // achieve the desired adjustment. output_warning(WARN_BREAK, "cannot break line"); return best_bp; } @@ -2189,9 +2193,19 @@ static void distribute_space(node *nd, int nspaces, hunits desired_space, bool force_reverse_node_list = false) { - assert(desired_space >= H0); if (desired_space.is_zero() || nspaces == 0) return; + if (desired_space < H0) { + // TODO: Implement shrinkable/squeezable space adjustments here. + if (nspaces == 0) + output_warning(WARN_BREAK, "cannot adjust line lacking adjustable" + " spaces; overset by %1 units", + abs(desired_space.to_units())); + else + output_warning(WARN_BREAK, "cannot adjust line; overset by %1" + " units", abs(desired_space.to_units())); + return; + } // Positive desired space is the typical case. Negative desired space // is possible if we have overrun an unbreakable line. But we should // not get here if there are no adjustable space nodes to adjust. diff --git a/src/roff/troff/troff.1.man b/src/roff/troff/troff.1.man index 522a52796..3d2dd0bf4 100644 --- a/src/roff/troff/troff.1.man +++ b/src/roff/troff/troff.1.man @@ -579,9 +579,12 @@ _ . .TP \nxu+3n .BR break "\t4" -A filled output line could not be broken such that its length was less -than the output line length -.BR \[rs]n[.l] . +A filled output line could not be +broken such that its length was less than or equal to, +or +adjusted such that its length was exactly equal to, +the output line length +.RB \[lq] \[rs]n[.l] \[rq]. . This category is enabled by default. . _______________________________________________ groff-commit mailing list groff-commit@gnu.org https://lists.gnu.org/mailman/listinfo/groff-commit