3 # Copyright (C) 1998, 2002, 2006, 2007 Free Software Foundation
4 # Copyright (C) 1993 Jean-loup Gailly
6 # Modified for XZ Utils by Andrew Dudman and Lasse Collin.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 #SET_PATH - This line is a placeholder to ease patching this script.
20 # Instead of unsetting XZ_OPT, just make sure that xz will use file format
21 # autodetection. This way memory usage limit and thread limit can be
22 # specified via XZ_OPT. With gzip, bzip2, and lzop it's OK to just unset the
23 # environment variables.
24 xz='@xz@ --format=auto'
25 unset GZIP BZIP BZIP2 LZOP
28 *cmp*) prog=xzcmp; cmp=${CMP:-cmp};;
29 *) prog=xzdiff; cmp=${DIFF:-diff};;
32 version="$prog (@PACKAGE_NAME@) @VERSION@"
34 usage="Usage: ${0##*/} [OPTION]... FILE1 [FILE2]
35 Compare FILE1 to FILE2, using their uncompressed contents if they are
36 compressed. If FILE2 is omitted, then the files compared are FILE1 and
37 FILE1 from which the compression format suffix has been stripped.
39 Do comparisons like '$cmp' does. OPTIONs are the same as for '$cmp'.
41 Report bugs to <@PACKAGE_BUGREPORT@>."
43 # sed script to escape all ' for the shell, and then (to handle trailing
44 # newlines correctly) turn trailing X on last line into '.
46 s/'\''/'\''\\'\'''\''/g
52 --h*) printf '%s\n' "$usage" || exit 2; exit;;
53 --v*) echo "$version" || exit 2; exit;;
55 -*\'*) cmp="$cmp '"`printf '%sX\n' "$1" | sed "$escape"`;;
56 -?*) cmp="$cmp '$1'";;
64 test "X$file" = X- || <"$file" || exit 2
72 if test $# -eq 1; then
74 *[-.]xz | *[-.]lzma | *.t[lx]z)
76 *[-.]bz2 | *.tbz | *.tbz2)
78 *[-.][zZ] | *_z | *[-.]gz | *.t[ag]z)
83 echo >&2 "$0: $1: Unknown compressed file name suffix"
87 *[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma | *[-.]lzo)
88 FILE=`expr "X$1" : 'X\(.*\)[-.][abglmoxzZ2]*$'`;;
90 FILE=`expr "X$1" : 'X\(.*[-.]t\)[abglx]z$'`ar;;
92 FILE=`expr "X$1" : 'X\(.*[-.]t\)bz2$'`ar;;
94 FILE=`expr "X$1" : 'X\(.*[-.]t\)zo$'`ar;;
98 ($xz1 -cd -- "$1" 4>&-; echo $? >&4) 3>&- | eval "$cmp" - '"$FILE"' >&3
100 elif test $# -eq 2; then
102 *[-.]bz2 | *.tbz | *.tbz2) xz1=bzip2;;
103 *[-.][zZ] | *_z | *[-.]gz | *.t[ag]z) xz1=gzip;;
104 *[-.]lzo | *.tzo) xz1=lzop;;
107 *[-.]bz2 | *.tbz | *.tbz2) xz2=bzip2;;
108 *[-.][zZ] | *_z | *[-.]gz | *.t[ag]z) xz2=gzip;;
109 *[-.]lzo | *.tzo) xz2=lzop;;
112 *[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma | *.t[abglx]z | *.tbz2 | *[-.]lzo | *.tzo | -)
114 *[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma | *.t[abglx]z | *.tbz2 | *[-.]lzo | *.tzo | -)
115 if test "$1$2" = --; then
118 ($xz1 -cdfq - 4>&-; echo $? >&4) 3>&- |
121 elif # Reject Solaris 8's buggy /bin/bash 2.03.
122 echo X | (echo X | eval "$cmp" /dev/fd/5 - >/dev/null 2>&1) 5<&0; then
125 ($xz1 -cdfq -- "$1" 4>&-; echo $? >&4) 3>&- |
126 ( ($xz2 -cdfq -- "$2" 4>&-; echo $? >&4) 3>&- 5<&- </dev/null |
127 eval "$cmp" /dev/fd/5 - >&3) 5<&0
131 *[1-9]*) xz_status=1;;
136 F=`expr "/$2" : '.*/\(.*\)[-.][ablmotxz2]*$'` || F=$prog
139 test -n "$tmp" && rm -f "$tmp"
141 ' HUP INT PIPE TERM 0
142 tmp=`mktemp -t -- "$F.XXXXXX"` || exit 2
143 $xz2 -cdfq -- "$2" > "$tmp" || exit 2
146 ($xz1 -cdfq -- "$1" 4>&-; echo $? >&4) 3>&- |
147 eval "$cmp" - '"$tmp"' >&3
150 rm -f "$tmp" || xz_status=$?
151 trap - HUP INT PIPE TERM 0
157 ($xz1 -cdfq -- "$1" 4>&-; echo $? >&4) 3>&- |
158 eval "$cmp" - '"$2"' >&3
163 *[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma | *.t[abglx]z | *.tbz2 | *[-.]lzo | *.tzo | -)
166 ($xz2 -cdfq -- "$2" 4>&-; echo $? >&4) 3>&- |
167 eval "$cmp" '"$1"' - >&3
170 eval "$cmp" '"$1"' '"$2"';;
174 echo >&2 "$0: Invalid number of operands; try \`${0##*/} --help' for help"
179 test "$xz_status" -eq 0 || exit 2