summaryrefslogtreecommitdiffstats
path: root/zdiff.in
diff options
context:
space:
mode:
Diffstat (limited to 'zdiff.in')
-rw-r--r--zdiff.in71
1 files changed, 34 insertions, 37 deletions
diff --git a/zdiff.in b/zdiff.in
index 4be41d8..21c3fbd 100644
--- a/zdiff.in
+++ b/zdiff.in
@@ -7,12 +7,11 @@
LC_ALL=C
export LC_ALL
-invocation_name=$0
args=
-default_ext=.lz
diff_prog=diff
file1=
file2=
+two_hyphens=0
# Loop over args
while [ x"$1" != x ] ; do
@@ -28,25 +27,24 @@ while [ x"$1" != x ] ; do
echo
echo "Zcmp is a shortcut for \"zdiff --cmp\""
echo
- echo "Usage: ${invocation_name} [OPTIONS] [DIFF_OPTIONS] FILE1 [FILE2]"
+ echo "Usage: $0 [OPTIONS] [DIFF_OPTIONS] FILE1 [FILE2]"
echo
- echo "Compares FILE1 to FILE2. If FILE2 is omitted, compares FILE1 to the"
- echo "uncompressed contents of FILE1.[gz|bz2|lz] (depending on the default"
- echo "compressor selected). DIFF_OPTIONS are passed directly to diff or cmp."
+ echo "Compares FILE1 to FILE2. If FILE2 is omitted and FILE1 is compressed,"
+ echo "compares FILE1 to the file with the corresponding decompressed file"
+ echo "name (removes the extension from FILE1). If FILE2 is omitted and FILE1"
+ echo "is not compressed, compares FILE1 to the uncompressed contents of"
+ echo "FILE1.[gz|bz2|lz|xz] (the first one that is found)."
+ echo "DIFF_OPTIONS are passed directly to diff or cmp."
echo "The exit status from diff or cmp is preserved."
echo
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 " --diff use diff to compare files (default)"
echo " --cmp use cmp to compare files"
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 "Zdiff VERSION"
@@ -54,23 +52,15 @@ 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_ext=.gz ;;
- --bz*)
- default_ext=.bz2 ;;
- --lz*)
- default_ext=.lz ;;
- --xz*)
- default_prog=xz ;;
--diff)
diff_prog=diff ;;
--cmp)
diff_prog=cmp ;;
-)
- echo "${invocation_name}: reading from stdin not supported"
+ echo "$0: reading from stdin not supported"
exit 1 ;;
--)
- shift; break ;;
+ shift; two_hyphens=1 ; break ;;
-?*)
args="${args} $1" ;;
*)
@@ -80,30 +70,30 @@ while [ x"$1" != x ] ; do
done
# Loop over files
-while [ x"$1" != x ] ; do
- if [ "$1" != "--" ] ; then
- if test -f "$1"; then
- if test -z "${file1}"; then file1="$1"
+for i in "$@" ; do
+ if [ "$i" = "--" ] && [ ${two_hyphens} = 0 ] ; then two_hyphens=1
+ else
+ if [ -f "$i" ]; then
+ if [ -z "${file1}" ]; then file1="$i"
else
- if test -z "${file2}"; then file2="$1"
+ if [ -z "${file2}" ]; then file2="$i"
else
- echo "${invocation_name}: Too many files; use --help for usage." 1>&2
+ echo "$0: Too many files; use --help for usage." 1>&2
fi
fi
else
- echo "${invocation_name}: File \"$1\" not found or not a regular file" 1>&2
+ echo "$0: File \"$i\" not found or not a regular file" 1>&2
exit 1
fi
fi
- shift
done
-if test -z "${file1}"; then
- echo "${invocation_name}: No files given; use --help for usage." 1>&2
+if [ -z "${file1}" ]; then
+ echo "$0: No files given; use --help for usage." 1>&2
exit 1
fi
-if test -z "${file2}"; then
+if [ -z "${file2}" ]; then
case "${file1}" in
*.gz)
file2=`printf "%s" "${file1}" | sed 's/.gz$//'` ;;
@@ -124,7 +114,14 @@ if test -z "${file2}"; then
*.txz)
file2=`printf "%s" "${file1}" | sed 's/txz$/tar/'` ;;
*)
- file2="${file1}${default_ext}" ;;
+ if [ -f "${file1}.gz" ]; then file2="${file1}.gz"
+ elif [ -f "${file1}.bz2" ]; then file2="${file1}.bz2"
+ elif [ -f "${file1}.lz" ]; then file2="${file1}.lz"
+ elif [ -f "${file1}.xz" ]; then file2="${file1}.xz"
+ else
+ echo "$0: Compressed version of ${file1} not found; use --help for usage." 1>&2
+ exit 1
+ fi ;;
esac
fi
@@ -144,8 +141,8 @@ case "${file2}" in
esac
retval=0
-if test -n "${prog1}"; then
- if test -n "${prog2}"; then
+if [ -n "${prog1}" ]; then
+ if [ -n "${prog2}" ]; then
tmp_file=`mktemp "${TMPDIR:-/tmp}"/zdiff.XXXXXXXXXX` || {
echo 'cannot create a temporary file' 1>&2
exit 1
@@ -159,7 +156,7 @@ if test -n "${prog1}"; then
retval=$?
fi
else
- if test -n "${prog2}"; then
+ if [ -n "${prog2}" ]; then
${prog2} -cdfq -- "${file2}" | ${diff_prog} ${args} -- "${file1}" -
retval=$?
else