groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 09/09: [nroff]: Work around substandard Unix systems.


From: G. Branden Robinson
Subject: [groff] 09/09: [nroff]: Work around substandard Unix systems.
Date: Wed, 4 Dec 2024 09:51:23 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit e05cf6d3b39bbc7ef8ab540948270f61ad70f366
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Wed Dec 4 08:08:55 2024 -0600

    [nroff]: Work around substandard Unix systems.
    
    ...practicing malicious non-compliance with POSIX.  (Issue 4 had been
    out for _ten years_ when Solaris 10 was released.)
    
    * src/roff/nroff/nroff.sh: We can use POSIX shell parameter substitution
      only if the shell supports it, but it's a hard feature to test for
      within a shell script because non-conforming shells reject it as bad
      syntax, aborting interpretation of the script.  Use the error return
      status of `unset` applied to a nonexistent variable as a proxy.  If
      the shell is thus adjudged as lousy, use a cruder method of obtaining
      the basename of the script, and refuse to process option clusters,
      because we need parameter substitution to handle them.
    
    * src/roff/nroff/tests/verbose_option_works.sh: Skip test if the system
      lacks a grep conforming to POSIX Issue 4 (1994).
---
 ChangeLog                                    | 16 ++++++++++++++++
 src/roff/nroff/nroff.sh                      | 19 ++++++++++++++++++-
 src/roff/nroff/tests/verbose_option_works.sh |  6 ++++++
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 573f25c8f..61e241146 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2024-12-04  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [nroff]: Work around malicious non-compliance with POSIX.
+
+       * src/roff/nroff/nroff.sh: We can use POSIX shell parameter
+       substitution only if the shell supports it, but it's a hard
+       feature to test for within a shell script because non-conforming
+       shells reject it as bad syntax, aborting interpretation of the
+       script.  Use the error return status of `unset` applied to a
+       nonexistent variable as a proxy.  If the shell is thus adjudged
+       as lousy, use a cruder method of obtaining the basename of the
+       script, and refuse to process option clusters, because we need
+       parameter substitution to handle them.
+       * src/roff/nroff/tests/verbose_option_works.sh: Skip test if
+       the system lacks a grep conforming to POSIX Issue 4 (1994).
+
 2024-12-04  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * src/roff/troff/input.cpp (is_conditional_expression_true):
diff --git a/src/roff/nroff/nroff.sh b/src/roff/nroff/nroff.sh
index 00398c4dc..4e7800f06 100644
--- a/src/roff/nroff/nroff.sh
+++ b/src/roff/nroff/nroff.sh
@@ -21,7 +21,16 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-prog=${0##*/}
+# Screen for shells non-conforming with POSIX Issue 4 (1994).
+badshell=yes
+unset groff_ku7kiodu || badshell=
+
+if [ -n "$badshell" ]
+then
+  prog=`basename $0`
+else
+  prog=${0##*/}
+fi
 
 T=
 Topt=
@@ -55,6 +64,14 @@ do
         break
         ;;
       -[abCEikpRStUvzZ]*)
+        if test -n "$badshell"
+        then
+          # POSIX doesn't actually require $SHELL, but fortunately at
+          # least one craptastic non-conforming shell offers it.
+          echo "$prog: option cluster '$thisarg' not supported with" \
+            "POSIX non-conforming shell '$SHELL'" >&2
+          exit 2
+        fi
         remainder=${thisarg#-?}
         thisarg=${thisarg%%$remainder}
         newargs="$newargs $thisarg"
diff --git a/src/roff/nroff/tests/verbose_option_works.sh 
b/src/roff/nroff/tests/verbose_option_works.sh
index f42f25ce3..a9f3f6526 100755
--- a/src/roff/nroff/tests/verbose_option_works.sh
+++ b/src/roff/nroff/tests/verbose_option_works.sh
@@ -18,6 +18,12 @@
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
 #
 
+if ! echo foobar | grep -qx . >/dev/null 2>&1
+then
+    echo "$0: grep command does not support -qx options; skipping" >&2
+    exit 77 # skip
+fi
+
 fail=
 
 wail () {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]