aboutsummaryrefslogtreecommitdiff
path: root/src/scripts/xzdiff
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2009-07-05 22:25:17 +0300
committerLasse Collin <lasse.collin@tukaani.org>2009-07-05 22:25:17 +0300
commit96e4b257e101d72072d43e144897d92920270669 (patch)
tree5f1852c0c90b41b66dd0b24ba8719b68cea5d048 /src/scripts/xzdiff
parentUse @PACKAGE_HOMEPAGE@ in liblzma.pc.in. (diff)
downloadxz-96e4b257e101d72072d43e144897d92920270669.tar.xz
Major update to the xzgrep and other scripts based on
the latest versions found from gzip CVS repository. configure will try to find a POSIX shell to be used by the scripts. This should ease portability on systems which have pre-POSIX /bin/sh. xzgrep and xzdiff support .xz, .lzma, .gz, and .bz2 files. xzmore and xzless support only .xz and .lzma files. The name of the xz executable used in these scripts is now correct even if --program-transform-name has been used.
Diffstat (limited to '')
-rwxr-xr-xsrc/scripts/xzdiff67
-rw-r--r--src/scripts/xzdiff.158
-rw-r--r--src/scripts/xzdiff.in172
3 files changed, 209 insertions, 88 deletions
diff --git a/src/scripts/xzdiff b/src/scripts/xzdiff
deleted file mode 100755
index 50179bb9..00000000
--- a/src/scripts/xzdiff
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/bin/sh
-# sh is buggy on RS/6000 AIX 3.2. Replace above line with #!/bin/ksh
-
-# xzcmp and xzdiff are used to invoke the cmp or the diff pro-
-# gram on compressed files. All options specified are passed
-# directly to cmp or diff. If only 1 file is specified, then
-# the files compared are file1 and an uncompressed file1.xz.
-# If two files are specified, then they are uncompressed and
-# fed to cmp or diff. The exit status from cmp or diff is
-# preserved.
-
-prog=`echo $0 | sed 's|.*/||'`
-case "$prog" in
- *cmp) comp=${CMP-cmp} ;;
- *) comp=${DIFF-diff} ;;
-esac
-
-OPTIONS=
-FILES=
-for ARG
-do
- case "$ARG" in
- -*) OPTIONS="$OPTIONS $ARG";;
- *) if test -f "$ARG"; then
- FILES="$FILES $ARG"
- else
- echo "${prog}: $ARG not found or not a regular file"
- exit 2
- fi ;;
- esac
-done
-if test -z "$FILES"; then
- echo "Usage: $prog [${comp}_options] file [file]"
- exit 2
-fi
-set $FILES
-if test $# -eq 1; then
- FILE=`echo "$1" | sed 's/[-.][almtxz]*$//'`
- xz -dc "$1" | $comp $OPTIONS - "$FILE"
-
-elif test $# -eq 2; then
- case "$1" in
- *[-.]xz | *.txz | *[-.]lzma | *.tlz)
- case "$2" in
- *[-.]xz | *.txz | *[-.]lzma | *.tlz)
- F=`echo "$2" | sed 's|.*/||;s|[-.][almtxz]*||'`
- TF=`/usr/bin/mktemp ${TMPDIR:-/tmp}/"$F".XXXXXXXXXX` || exit 1
- trap 'rm -f "$TF"; exit 2' EXIT HUP INT PIPE TERM
- xz -dc -- "$2" > "$TF" || exit
- xz -dc -- "$1" | $comp $OPTIONS - "$TF"
- STAT="$?"
- rm -f "$TF" || STAT=2
- trap EXIT HUP INT PIPE TERM
- exit $STAT;;
-
- *) xz -dc -- "$1" | $comp $OPTIONS - "$2";;
- esac;;
- *) case "$2" in
- *[-.]xz | *.txz | *[-.]lzma | *.tlz)
- xz -dc -- "$2" | $comp $OPTIONS "$1" -;;
- *) $comp $OPTIONS "$1" "$2";;
- esac;;
- esac
-else
- echo "Usage: $prog [${comp}_options] file [file]"
- exit 2
-fi
diff --git a/src/scripts/xzdiff.1 b/src/scripts/xzdiff.1
index 7d4f6060..252d1cd3 100644
--- a/src/scripts/xzdiff.1
+++ b/src/scripts/xzdiff.1
@@ -1,7 +1,14 @@
-.\" Original file was take from gzip, thus this man page is under GNU GPLv2+.
-.TH XZDIFF 1 "2009-04-13" "XZ Utils"
+.\"
+.\" Original zdiff.1 for gzip: Jean-loup Gailly
+.\"
+.\" Modifications for XZ Utils: Lasse Collin
+.\" Andrew Dudman
+.\"
+.\" License: GNU GPLv2+
+.\"
+.TH XZDIFF 1 "2009-07-05" "Tukaani" "XZ Utils"
.SH NAME
-xzcmp, xzdiff, lzcmp, lzdiff \- compare .xz and .lzma compressed files
+xzcmp, xzdiff, lzcmp, lzdiff \- compare compressed files
.SH SYNOPSIS
.B xzcmp
.RI [ cmp_options "] " file1 " [" file2 ]
@@ -18,41 +25,50 @@ xzcmp, xzdiff, lzcmp, lzdiff \- compare .xz and .lzma compressed files
.B xzcmp
and
.B xdiff
-are used to invoke the
+invoke
.BR cmp (1)
-or the
+or
.BR diff (1)
-program on compressed files. All options specified are passed directly to
+on files compressed with
+.BR xz (1),
+.BR lzma (1),
+.BR gzip (1),
+or
+.BR bzip2 (1).
+All options specified are passed directly to
.B cmp
or
-.BR diff "."
-If only 1 file is specified, then the files compared are
+.BR diff .
+If only one file is specified, then the files compared are
.I file1
-(which must have .xz or .lzma suffix) and
+(which must have a suffix of a supported compression format) and
.I file1
-from which the .xz or .lzma suffix has been stripped.
+from which the compression format suffix has been stripped.
If two files are specified, then they are uncompressed if necessary and fed to
-.B cmp
+.BR cmp (1)
or
-.BR diff "."
+.BR diff (1).
The exit status from
.B cmp
or
.B diff
is preserved.
-.SH AUTHORS
-This manual page was ripped from
-.BR zdiff (1)
-shipped in gzip package.
+.PP
+The names
+.B lzcmp
+and
+.B lzdiff
+are provided for backward compatibility with LZMA Utils.
.SH "SEE ALSO"
.BR cmp (1),
.BR diff (1),
-.BR xzmore(1),
-.BR xzgrep(1),
-.BR xz (1)
+.BR xz (1),
+.BR gzip (1),
+.BR bzip2 (1),
+.BR zdiff (1)
.SH BUGS
Messages from the
-.B cmp
+.BR cmp (1)
or
-.B diff
+.BR diff (1)
programs refer to temporary filenames instead of those specified.
diff --git a/src/scripts/xzdiff.in b/src/scripts/xzdiff.in
new file mode 100644
index 00000000..3c09ad02
--- /dev/null
+++ b/src/scripts/xzdiff.in
@@ -0,0 +1,172 @@
+#!@POSIX_SHELL@
+
+# Copyright (C) 1998, 2002, 2006, 2007 Free Software Foundation
+# Copyright (C) 1993 Jean-loup Gailly
+
+# Modified for XZ Utils by Andrew Dudman and Lasse Collin.
+
+# This program 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 2 of the License, or
+# (at your option) any later version.
+
+# This program 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.
+
+#SET_PATH - This line is a placeholder to ease patching this script.
+
+# Instead of unsetting XZ_OPT, just make sure that xz will use file format
+# autodetection. This way memory usage limit and thread limit can be
+# specified via XZ_OPT. With gzip and bzip2 it's OK to just unset the
+# environment variables.
+xz='@xz@ --format=auto'
+unset GZIP BZIP BZIP2
+
+case ${0##*/} in
+ *cmp*) prog=xzcmp; cmp=${CMP:-cmp};;
+ *) prog=xzdiff; cmp=${DIFF:-diff};;
+esac
+
+version="$prog (@PACKAGE_NAME@) @VERSION@"
+
+usage="Usage: ${0##*/} [OPTION]... FILE1 [FILE2]
+Compare FILE1 to FILE2, using their uncompressed contents if they are
+compressed. If FILE2 is omitted, then the files compared are FILE1 and
+FILE1 from which the compression format suffix has been stripped.
+
+Do comparisons like '$cmp' does. OPTIONs are the same as for '$cmp'.
+
+Report bugs to <@PACKAGE_BUGREPORT@>."
+
+# sed script to escape all ' for the shell, and then (to handle trailing
+# newlines correctly) turn trailing X on last line into '.
+escape='
+ s/'\''/'\''\\'\'''\''/g
+ $s/X$/'\''/
+'
+
+while :; do
+ case $1 in
+ --h*) printf '%s\n' "$usage" || exit 2; exit;;
+ --v*) echo "$version" || exit 2; exit;;
+ --) shift; break;;
+ -*\'*) cmp="$cmp '"`printf '%sX\n' "$1" | sed "$escape"`;;
+ -?*) cmp="$cmp '$1'";;
+ *) break;;
+ esac
+ shift
+done
+cmp="$cmp --"
+
+for file; do
+ test "X$file" = X- || <"$file" || exit 2
+done
+
+xz1=$xz
+xz2=$xz
+xz_status=0
+exec 3>&1
+
+if test $# -eq 1; then
+ case $1 in
+ *[-.]xz | *[-.]lzma | *.t[lx]z)
+ ;;
+ *[-.]bz2 | *.tbz | *.tbz2)
+ xz1=$bzip2;;
+ *[-.][zZ] | *_z | *[-.]gz | *.t[ag]z)
+ xz1=$gzip;;
+ *)
+ echo >&2 "$0: $1: Unknown compressed file name suffix"
+ exit 2;;
+ esac
+ case $1 in
+ *[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma)
+ FILE=`expr "X$1" : 'X\(.*\)[-.][abglmxzZ2]*$'`
+ *.t[abglx]z)
+ FILE=`expr "X$1" : 'X\(.*[-.]t\)[abglx]z$'`ar
+ *.tbz2)
+ FILE=`expr "X$1" : 'X\(.*[-.]t\)bz2$'`ar
+ esac
+ xz_status=$(
+ exec 4>&1
+ ($xz1 -cd -- "$1" 4>&-; echo $? >&4) 3>&- | eval "$cmp" - '"$FILE"' >&3
+ )
+elif test $# -eq 2; then
+ case $1 in
+ *[-.]bz2 | *.tbz | *.tbz2) xz1=$bzip2;;
+ *[-.][zZ] | *_z | *[-.]gz | *.t[ag]z) xz1=$gzip;;
+ esac
+ case $2 in
+ *[-.]bz2 | *.tbz | *.tbz2) xz2=$bzip2;;
+ *[-.][zZ] | *_z | *[-.]gz | *.t[ag]z) xz2=$gzip;;
+ esac
+ case $1 in
+ *[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma | *.t[abglx]z | *.tbz2 | -)
+ case "$2" in
+ *[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma | *.t[abglx]z | *.tbz2 | -)
+ if test "$1$2" = --; then
+ xz_status=$(
+ exec 4>&1
+ ($xz1 -cdfq - 4>&-; echo $? >&4) 3>&- |
+ eval "$cmp" - - >&3
+ )
+ elif # Reject Solaris 8's buggy /bin/bash 2.03.
+ echo X | (echo X | eval "$cmp" /dev/fd/5 - >/dev/null 2>&1) 5<&0; then
+ xz_status=$(
+ exec 4>&1
+ ($xz1 -cdfq -- "$1" 4>&-; echo $? >&4) 3>&- |
+ ( ($xz2 -cdfq -- "$2" 4>&-; echo $? >&4) 3>&- 5<&- </dev/null |
+ eval "$cmp" /dev/fd/5 -) 5<&0
+ )
+ case $xz_status in
+ *[1-9]*) xz_status=1;;
+ *) xz_status=0;;
+ esac
+ else
+ F=`expr "/$2" : '.*/\(.*\)[-.][ablmtxz2]*$'` || F=$prog
+ tmp=
+ trap '
+ test -n "$tmp" && rm -f "$tmp"
+ (exit 2); exit 2
+ ' HUP INT PIPE TERM 0
+ tmp=`mktemp -t -- "$F.XXXXXX"` || exit 2
+ $xz2 -cdfq -- "$2" > "$tmp" || exit 2
+ xz_status=$(
+ exec 4>&1
+ ($xz1 -cdfq -- "$1" 4>&-; echo $? >&4) 3>&- |
+ eval "$cmp" - '"$tmp"' >&3
+ )
+ cmp_status=$?
+ rm -f "$tmp" || xz_status=$?
+ trap - HUP INT PIPE TERM 0
+ (exit $cmp_status)
+ fi;;
+ *)
+ xz_status=$(
+ exec 4>&1
+ ($xz1 -cdfq -- "$1" 4>&-; echo $? >&4) 3>&- |
+ eval "$cmp" - '"$2"' >&3
+ );;
+ esac;;
+ *)
+ case "$2" in
+ *[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma | *.t[abglx]z | *.tbz2 | -)
+ xz_status=$(
+ exec 4>&1
+ ($xz2 -cdfq -- "$2" 4>&-; echo $? >&4) 3>&- |
+ eval "$cmp" '"$1"' - >&3
+ );;
+ *)
+ eval "$cmp" '"$1"' '"$2"';;
+ esac;;
+ esac
+else
+ echo >&2 "$0: Invalid number of operands; try \`${0##*/} --help' for help"
+ exit 2
+fi
+
+cmp_status=$?
+test "$xz_status" -eq 0 || exit 2
+exit $cmp_status