gbranden pushed a commit to branch master in repository groff. commit 320e9f6ec85d57a75ec541173011fcaca7a1be93 Author: G. Branden Robinson <g.branden.robin...@gmail.com> AuthorDate: Sun Feb 23 20:11:47 2025 -0600
[troff]: Make `lf` request more flexible. Treat `lf`'s second argument, if present, like string contents. * src/roff/troff/input.cpp (line_file): Do it. * src/roff/groff/tests/lf-request-works.sh: Test it. * doc/groff.texi.in (Debugging) <lf>: * man/groff.7.man (Request short reference) <lf>: * man/groff_diff.7.man (Altered requests) <lf>: (Other differences): Document it. * NEWS: Update items. Thanks to onf for pointing out that soelim(1)'s injection of `lf` requests would make reported file names misleading. --- ChangeLog | 19 +++++++++++++++++++ NEWS | 14 +++++++------- doc/groff.texi.in | 27 ++++++++++++++++++++++----- man/groff.7.man | 13 +++++++++++-- man/groff_diff.7.man | 20 ++++++++++++++++++++ src/roff/groff/tests/lf-request-works.sh | 11 +++++++++++ src/roff/troff/input.cpp | 12 +++++++----- 7 files changed, 97 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5cbb76415..e6f81b1a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2025-02-23 G. Branden Robinson <g.branden.robin...@gmail.com> + + [troff]: Treat `lf`'s second argument, if present, like string + contents. + + * src/roff/troff/input.cpp (line_file): Do it. + + * src/roff/groff/tests/lf-request-works.sh: Test it. + + * doc/groff.texi.in (Debugging) <lf>: + * man/groff.7.man (Request short reference) <lf>: + * man/groff_diff.7.man (Altered requests) <lf>: + (Other differences): Document it. + + * NEWS: Update items. + + Thanks to onf for pointing out that soelim(1)'s injection of + `lf` requests would make reported file names misleading. + 2025-02-23 G. Branden Robinson <g.branden.robin...@gmail.com> Add unit test for `lf` request. diff --git a/NEWS b/NEWS index dee304b13..471835a57 100644 --- a/NEWS +++ b/NEWS @@ -110,15 +110,15 @@ troff warning diagnostic in the "range" category. * GNU troff now strips a leading neutral double quote from the argument - to the `cf`, `hpf`, `hpfa`, `mso`, `msoquiet`, `nx`, `pi`, `pso`, - `so`, `soquiet`, `sy`, and `trf` requests, and the second argument to - the `open` and `opena` requests, allowing it to contain embedded - leading spaces. + to the `cf`, `hpf`, `hpfa`, `lf`, `mso`, `msoquiet`, `nx`, `pi`, + `pso`, `so`, `soquiet`, `sy`, and `trf` requests, and the second + argument to the `open` and `opena` requests, allowing it to contain + embedded leading spaces. * GNU troff now accepts space characters in the argument to the `cf`, - `hpf`, `hpfa`, `mso`, `msoquiet`, `nx`, `so`, `soquiet`, and `trf` - requests, and the second argument to the `open` and `opena` requests. - See "soelim" below. + `hpf`, `hpfa`, `lf`, `mso`, `msoquiet`, `nx`, `so`, `soquiet`, and + `trf` requests, and the second argument to the `open` and `opena` + requests. See "soelim" below. * The "el" warning category has been withdrawn. If enabled (which it was not by default), the formatter would emit a diagnostic if it diff --git a/doc/groff.texi.in b/doc/groff.texi.in index fdbab280f..5749e3014 100644 --- a/doc/groff.texi.in +++ b/doc/groff.texi.in @@ -17396,17 +17396,34 @@ output nodes corresponding to the pending input line to the standard error stream. @c END Keep parallel with section "Debugging" of groff(7). -@Defreq {lf, line [@Var{name}]} +@Defreq {lf, input-line-number [[@code{"}]@Var{file-identifier}]} @pindex soelim @cindex multi-file documents @cindex documents, multi-file @cindex assign input line number request (@code{lf}) @cindex input line number, assignment, request (@code{lf}) @cindex number, input line, assignment request (@code{lf}) -Set the input line number (and, optionally, the name) GNU -@code{troff} shall use for error and warning messages. @var{line} is -the input line number of the @emph{next} line. Without an argument, the -request is ignored. +Set the input line number +(and, +optionally, +the file name) +GNU +@command{troff} +uses when reporting diagnostics. +@var{line} +is the input line number of the +@emph{next} +line. +@var{file-identifier} +is a sequence of ordinary characters and/or spaces. +@c XXX: or tabs, leaders, backspace, and delete characters +@c ...limiting the file names you can express; see Savannah #65108. +GNU +@command{troff} +.I troff \" GNU +strips a leading leading neutral double quote from +@var{file-identifier}, +allowing it to contain embedded leading spaces. @code{lf}'s primary purpose is to aid the debugging of documents that undergo preprocessing. Programs like @command{tbl} that transform input diff --git a/man/groff.7.man b/man/groff.7.man index 06ead9634..b53338a5d 100644 --- a/man/groff.7.man +++ b/man/groff.7.man @@ -3728,11 +3728,20 @@ Set number of next input line to .IR n . . .TPx -.REQ .lf "n f" +.REQ .lf "n file-identifier" Set number of next input line to .I n and report input file name as -.IR f . +.IR file-identifier , +a sequence of ordinary characters and/or spaces. +.\" XXX: or tabs, leaders, backspace, and delete characters +.\" ...limiting the file names you can express; see Savannah #65108. +. +GNU +.I troff \" GNU +strips a leading leading neutral double quote from +.IR file-identifier , +allowing it to contain embedded leading spaces. . .TPx .REQ .lg diff --git a/man/groff_diff.7.man b/man/groff_diff.7.man index b109daba9..e248b688d 100644 --- a/man/groff_diff.7.man +++ b/man/groff_diff.7.man @@ -4219,6 +4219,21 @@ request is selected. . . .TP +.BI .lf\~ next-line-number\~\c +.RB [[ \[dq] ]\c +.IR file-identifier ] +GNU +.I troff \" GNU +strips a leading neutral double quote from the optional second argument, +allowing it to contain embedded leading spaces. +. +Further, +non-leading spaces in +.I file-identifier +are also accepted. +. +. +.TP .BR .nx\~ [[ \[dq] ]\c .IR file ] GNU @@ -6255,6 +6270,11 @@ and and .B sy requests, +and the second argument +(if present) +to the +.B lf +request, allowing it to contain embedded leading spaces. . . diff --git a/src/roff/groff/tests/lf-request-works.sh b/src/roff/groff/tests/lf-request-works.sh index bca19ee7c..9fa33daa7 100755 --- a/src/roff/groff/tests/lf-request-works.sh +++ b/src/roff/groff/tests/lf-request-works.sh @@ -49,6 +49,17 @@ output=$(printf "%s\n" "$input" | "$groff" 2>&1) echo "$output" echo "$output" | grep -Fqx '901 myfile' || wail +input='. +.lf 900 my file +.ec @ +.tm @n[.c] @n[.F] +.' + +echo "checking 'lf' request behavior with spaceful second argument" >&2 +output=$(printf "%s\n" "$input" | "$groff" 2>&1) +echo "$output" +echo "$output" | grep -Fqx '901 my file' || wail + test -z "$fail" # vim:set autoindent expandtab shiftwidth=2 tabstop=2 textwidth=72: diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp index 2656ff236..423a495fc 100644 --- a/src/roff/troff/input.cpp +++ b/src/roff/troff/input.cpp @@ -6405,12 +6405,14 @@ void line_file() { int n; if (get_integer(&n)) { - const char *filename = 0 /* nullptr */; - if (has_arg()) { - symbol s = get_long_name(); - filename = s.contents(); + if (has_arg(true /* peek */)) { + const char *reported_file_name = read_string(); + (void) input_stack::set_location(reported_file_name, (n - 1)); + delete[] reported_file_name; + tok.next(); + return; } - (void) input_stack::set_location(filename, (n - 1)); + (void) input_stack::set_location(0 /* nullptr */, (n - 1)); } skip_line(); } _______________________________________________ groff-commit mailing list groff-commit@gnu.org https://lists.gnu.org/mailman/listinfo/groff-commit