summaryrefslogtreecommitdiffstats
path: root/zcat.in
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--zcat.in85
1 files changed, 34 insertions, 51 deletions
diff --git a/zcat.in b/zcat.in
index f5590ea..bf3f07a 100644
--- a/zcat.in
+++ b/zcat.in
@@ -7,11 +7,10 @@
LC_ALL=C
export LC_ALL
-invocation_name=$0
args=
-default_prog=lzip
+two_hyphens=0
-# Loop over args until pattern is found
+# Loop over args until a filename is found
while [ x"$1" != x ] ; do
case "$1" in
@@ -22,10 +21,10 @@ while [ x"$1" != x ] ; do
echo "transparent concatenation of any combination of compressed and"
echo "non-compressed files. If any given file is compressed, its uncompressed"
echo "content is used. If a given file does not exist, zcat tries the"
- echo "compressed file name corresponding to the default compressor selected."
+ echo "compressed file names corresponding to the supported compressors."
echo "The supported compressors are gzip, bzip2, lzip and xz."
echo
- echo "Usage: ${invocation_name} [OPTIONS] [CAT_OPTIONS] [FILES]"
+ echo "Usage: $0 [OPTIONS] [CAT_OPTIONS] [FILES]"
echo
echo "CAT_OPTIONS are passed directly to cat."
echo "The exit status from cat is preserved."
@@ -33,13 +32,9 @@ while [ x"$1" != x ] ; do
echo "Options:"
echo " -h, --help display this help and exit"
echo " -V, --version output version information and exit"
- echo " --gzip use gzip as default decompressor"
- echo " --bzip2 use bzip2 as default decompressor"
- echo " --lzip use lzip as default decompressor (default)"
- echo " --xz use xz as default decompressor"
echo
- echo "Report bugs to lzip-bug@nongnu.org"
- echo "Lzip home page: http://www.nongnu.org/lzip/lzip.html"
+ echo "Report bugs to zutils-bug@nongnu.org"
+ echo "Zutils home page: http://www.nongnu.org/zutils/zutils.html"
exit 0 ;;
--version | --ve* | -V)
echo "Zcat VERSION"
@@ -47,18 +42,10 @@ while [ x"$1" != x ] ; do
echo "This script is free software: you have unlimited permission"
echo "to copy, distribute and modify it."
exit 0 ;;
- --gz*)
- default_prog=gzip ;;
- --bz*)
- default_prog=bzip2 ;;
- --lz*)
- default_prog=lzip ;;
- --xz*)
- default_prog=xz ;;
-)
;;
--)
- shift; break ;;
+ shift ; two_hyphens=1 ; break ;;
-?*)
args="${args} $1" ;;
*)
@@ -67,41 +54,37 @@ while [ x"$1" != x ] ; do
shift
done
-if test $# -eq 0; then
- ${default_prog} -cd | cat ${args}
- exit $?
-fi
retval=0
for i in "$@" ; do
- prog="${default_prog} -cdfq"
- case "$i" in
- *.gz | *.tgz)
- prog="gzip -cdfq" ;;
- *.bz2 | *.tbz | *.tbz2)
- prog="bzip2 -cdfq" ;;
- *.lz | *.tlz)
- prog="lzip -cdfq" ;;
- *.xz | *.txz)
- prog="xz -cdfq" ;;
- *)
- if test -f "$i"; then prog=cat
- else
- case ${default_prog} in
- gzip)
- if test -f "$i.gz"; then i="$i.gz"; fi ;;
- bzip2)
- if test -f "$i.bz2"; then i="$i.bz2"; fi ;;
- lzip)
- if test -f "$i.lz"; then i="$i.lz"; fi ;;
- xz)
- if test -f "$i.xz"; then i="$i.xz"; fi ;;
+ if [ "$i" = "--" ] && [ ${two_hyphens} = 0 ] ; then two_hyphens=1
+ else
+ if [ -f "$i" ]; then
+ case "$i" in
+ *.gz | *.tgz)
+ prog="gzip -cdfq" ;;
+ *.bz2 | *.tbz | *.tbz2)
+ prog="bzip2 -cdfq" ;;
+ *.lz | *.tlz)
+ prog="lzip -cdfq" ;;
+ *.xz | *.txz)
+ prog="xz -cdfq" ;;
+ *)
+ prog=cat ;;
esac
- fi ;;
- esac
- ${prog} -- "$i" | cat ${args}
- r=$?
- test "$r" -ne 0 && retval="$r"
+ elif [ -f "$i.gz" ]; then i="$i.gz" ; prog="gzip -cdfq"
+ elif [ -f "$i.bz2" ]; then i="$i.bz2" ; prog="bzip2 -cdfq"
+ elif [ -f "$i.lz" ]; then i="$i.lz" ; prog="lzip -cdfq"
+ elif [ -f "$i.xz" ]; then i="$i.xz" ; prog="xz -cdfq"
+ else
+ echo "$0: File \"$i\" not found or not a regular file" 1>&2
+ if [ ${retval} = 0 ]; then retval=1 ; fi
+ continue
+ fi
+ ${prog} -- "$i" | cat ${args}
+ r=$?
+ if [ $r != 0 ]; then retval=$r ; fi
+ fi
done
exit ${retval}