[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 18/26: [soelim]: Fix Savannah #66027.
From: |
G. Branden Robinson |
Subject: |
[groff] 18/26: [soelim]: Fix Savannah #66027. |
Date: |
Thu, 14 Nov 2024 11:54:11 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit f539e5df1dbb3a65b49302c5f8145604b4b02ef0
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Tue Nov 12 10:26:07 2024 -0600
[soelim]: Fix Savannah #66027.
Read argument to `so` request in a more GNU troff-ish fashion (and a
more AT&T troff-ish fasion, if one considers the `ds` and `as`
requests). Accept but discard a leading double quote to permit
embedding of leading spaces in the file name, and accept unescaped
literal spaces in argument.
* src/preproc/soelim/soelim.cpp (do_so): Do it.
* src/preproc/soelim/soelim.1.man (Description): Document it.
* src/preproc/soelim/tests/space-in-argument-works.sh: Add unit test.
* src/preproc/soelim/soelim.am (soelim_TESTS): Run test.
* NEWS: Add item.
Fixes <https://savannah.gnu.org/bugs/?66027>.
---
ChangeLog | 19 +++++++
NEWS | 11 ++++
src/preproc/soelim/soelim.1.man | 33 +++++++++--
src/preproc/soelim/soelim.am | 10 +++-
src/preproc/soelim/soelim.cpp | 7 ++-
.../soelim/tests/space-in-argument-works.sh | 65 ++++++++++++++++++++++
6 files changed, 133 insertions(+), 12 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 212e5bf4c..c4d0c78da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2024-11-12 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ [soelim]: Read argument to `so` request in a more GNU troff-ish
+ fashion (and a more AT&T troff-ish fasion, if one considers the
+ `ds` and `as` requests). Accept but discard a leading double
+ quote to permit embedding of leading spaces in the file name,
+ and accept unescaped literal spaces in argument.
+
+ * src/preproc/soelim/soelim.cpp (do_so): Do it.
+ * src/preproc/soelim/soelim.1.man (Description): Document it.
+
+ * src/preproc/soelim/tests/space-in-argument-works.sh: Add unit
+ test.
+ * src/preproc/soelim/soelim.am (soelim_TESTS): Run test.
+
+ * NEWS: Add item.
+
+ Fixes <https://savannah.gnu.org/bugs/?66027>.
+
2024-11-12 G. Branden Robinson <g.branden.robinson@gmail.com>
[soelim]: Fix code style nits.
diff --git a/NEWS b/NEWS
index a40ed64fe..ca2bda6ba 100644
--- a/NEWS
+++ b/NEWS
@@ -184,6 +184,17 @@ nroff
* nroff now supports clustered options ("-tzms", for example) as groff,
troff, and other GNU getopt-using programs do.
+soelim
+------
+
+* soelim no longer requires embedded space characters in `so` arguments
+ to be backslash-escaped. (It continues to support that syntax.) If
+ the argument to a `so` request must contain leading spaces, any such
+ sequence of spaces must now be prefixed with a double quote character
+ ("), which the program then discards. These changes are to better
+ align this program's parsing rules with those of GNU troff and of
+ AT&T troff historically; consider the `ds` and `as` requests.
+
Macro packages
--------------
diff --git a/src/preproc/soelim/soelim.1.man b/src/preproc/soelim/soelim.1.man
index 7bec18434..5670a8348 100644
--- a/src/preproc/soelim/soelim.1.man
+++ b/src/preproc/soelim/soelim.1.man
@@ -135,19 +135,34 @@ The program writes to the standard output stream.
.
.
.PP
-If the name of a
+.I @g@soelim
+reads the
.I included-file
-contains a backslash,
+argument as
+GNU
+.I troff \" GNU
+does.
+.
+It ignores spaces immediately after \[lq]so\[rq];
+to embed a sequence of one or more leading spaces in the argument,
+prefix the sequence with a neutral double quote
+.RB ( \[dq] ).
+.
+Non-leading spaces are interpreted literally.
+.
+If the included file name requires a backslash,
use
.B \[rs]\[rs]
or
.B \[rs]e
to embed it.
.
-To embed a space,
-write
-.RB \[lq] \[rs]\~ \[rq]
-(backslash followed by a space).
+A backslash followed by a space
+.RB (\[lq] \[rs]\~ \[rq])
+also encodes a space,
+for compatibility with earlier versions of
+GNU
+.IR soelim . \" GNU
.
Any other escape sequence in
.IR included-file ,
@@ -157,6 +172,12 @@ prevents
.I @g@soelim
from replacing the source request.
.
+AT&T and descendant versions of
+.I soelim
+have no means of embedding spaces in file names;
+they replace the first space encountered with a newline
+and stop interpreting the request.
+.
.
.PP
The dot must be at the beginning of a line and must be followed by
diff --git a/src/preproc/soelim/soelim.am b/src/preproc/soelim/soelim.am
index 1aa7941d1..b8b109974 100644
--- a/src/preproc/soelim/soelim.am
+++ b/src/preproc/soelim/soelim.am
@@ -1,4 +1,4 @@
-# Copyright (C) 2014-2020 Free Software Foundation, Inc.
+# Copyright (C) 2014-2024 Free Software Foundation, Inc.
#
# This file is part of groff.
#
@@ -7,8 +7,8 @@
# 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
+# 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.
#
@@ -23,6 +23,10 @@ EXTRA_DIST += \
src/preproc/soelim/TODO \
src/preproc/soelim/soelim.1.man
+soelim_TESTS =
+TESTS += $(soelim_TESTS)
+EXTRA_DIST += $(soelim_TESTS)
+
# Local Variables:
# fill-column: 72
diff --git a/src/preproc/soelim/soelim.cpp b/src/preproc/soelim/soelim.cpp
index e10447d06..28e80d736 100644
--- a/src/preproc/soelim/soelim.cpp
+++ b/src/preproc/soelim/soelim.cpp
@@ -140,9 +140,10 @@ void do_so(const char *line)
p++;
string filename;
bool is_filename_valid = true;
- for (const char *q = p;
- is_filename_valid && *q != '\0' && *q != '\n' && *q != ' ';
- q++)
+ const char *q = p;
+ if ('"' == *q)
+ q++;
+ for (; is_filename_valid && (*q != '\0') && (*q != '\n'); q++)
if (*q == '\\') {
switch (*++q) {
case 'e':
diff --git a/src/preproc/soelim/tests/space-in-argument-works.sh
b/src/preproc/soelim/tests/space-in-argument-works.sh
new file mode 100755
index 000000000..236645178
--- /dev/null
+++ b/src/preproc/soelim/tests/space-in-argument-works.sh
@@ -0,0 +1,65 @@
+#!/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/>.
+#
+
+soelim="${abs_top_builddir:-.}/soelim"
+
+fail=
+
+wail () {
+ echo "...FAILED" >&2
+ fail=yes
+}
+
+tmpfile="bar baz.groff"
+
+cleanup () {
+ rm -f "$tmpfile"
+}
+
+# A process handling a fatal signal should:
+# 1. Mask _all_ fatal signals.
+# 2. Perform cleanup operations.
+# 3. Unmask the signal (removing the handler).
+# 4. Signal its own process group with the signal caught so that the
+# the children exit and shell accurately reports how the process
+# died.
+fatals="HUP INT QUIT TERM"
+for s in $fatals
+do
+ trap "trap '' $fatals; cleanup; trap - $fatals; kill -$s -$$" $s
+done
+
+printf 'bar\nbaz\n' > "$tmpfile"
+
+input='.
+foo
+.so bar baz.groff
+qux
+.'
+
+output=$(echo "$input" | "$soelim" -r | tr '\n' ' ')
+echo "$output"
+# Note trailing space after second dot.
+echo "$output" | grep -Fqx ". foo bar baz qux . " || wail
+
+cleanup
+test -z "$fail"
+
+# vim:set autoindent expandtab shiftwidth=2 tabstop=2 textwidth=72:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 18/26: [soelim]: Fix Savannah #66027.,
G. Branden Robinson <=