summaryrefslogtreecommitdiffstats
path: root/src/scripts/xzless.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/scripts/xzless.in')
-rw-r--r--src/scripts/xzless.in21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/scripts/xzless.in b/src/scripts/xzless.in
index 79a849e..6346966 100644
--- a/src/scripts/xzless.in
+++ b/src/scripts/xzless.in
@@ -1,4 +1,5 @@
#!@POSIX_SHELL@
+# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 1998, 2002, 2006, 2007 Free Software Foundation
@@ -23,7 +24,7 @@
# specified via XZ_OPT.
xz='@xz@ --format=auto'
-version='xzless (@PACKAGE_NAME@) @VERSION@'
+version='xzless (@PACKAGE_NAME@) @PACKAGE_VERSION@'
usage="Usage: ${0##*/} [OPTION]... [FILE]...
Like 'less', but operate on the uncompressed contents of xz compressed FILEs.
@@ -47,13 +48,27 @@ if test "${LESSMETACHARS+set}" != set; then
LESSMETACHARS="$space$tab$nl'"';*?"()<>[|&^`#\$%=~'
fi
-if test "$(less -V | { read _ ver _ && echo ${ver%%.*}; })" -ge 429; then
+VER=$(less -V | { read _ ver _ && echo ${ver%%.*}; })
+if test "$VER" -ge 451; then
+ # less 451 or later: If the compressed file is valid but has
+ # zero bytes of uncompressed data, using two vertical bars ||- makes
+ # "less" check the exit status of xz and if it is zero then display
+ # an empty file. With a single vertical bar |- and no output from xz,
+ # "less" would attempt to display the raw input file instead.
+ LESSOPEN="||-$xz -cdfqQ -- %s"
+elif test "$VER" -ge 429; then
# less 429 or later: LESSOPEN pipe will be used on
# standard input if $LESSOPEN begins with |-.
LESSOPEN="|-$xz -cdfqQ -- %s"
else
LESSOPEN="|$xz -cdfqQ -- %s"
fi
+
+SHOW_PREPROC_ERRORS=
+if test "$VER" -ge 632; then
+ SHOW_PREPROC_ERRORS=--show-preproc-errors
+fi
+
export LESSMETACHARS LESSOPEN
-exec less "$@"
+exec less $SHOW_PREPROC_ERRORS "$@"