2 # sh is buggy on RS/6000 AIX 3.2. Replace above line with #!/bin/ksh
4 # Copyright (C) 1998, 2002, 2006, 2007 Free Software Foundation
5 # Copyright (C) 1993 Jean-loup Gailly
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 PATH=${GZIP_BINDIR-'/bin'}:$PATH
25 prog=cmp; cmp='${CMP-cmp}' ;;
26 *) prog=diff; cmp='${DIFF-diff}';;
29 version="z$prog (gzip) 1.3.12
30 Copyright (C) 2007 Free Software Foundation, Inc.
31 This is free software. You may redistribute copies of it under the terms of
32 the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
33 There is NO WARRANTY, to the extent permitted by law.
35 Written by Jean-loup Gailly."
37 usage="Usage: $0 [OPTION]... FILE1 [FILE2]
38 Compare FILE1 to FILE2, using their uncompressed contents if they are
39 compressed. If FILE2 is omitted, compare FILE1 to the uncompressed
40 contents of FILE1.gz. Do comparisons like '$prog' does.
42 OPTIONs are the same as for '$prog'.
44 Report bugs to <bug-gzip@gnu.org>."
46 # sed script to escape all ' for the shell, and then (to handle trailing
47 # newlines correctly) turn trailing X on last line into '.
49 s/'\''/'\''\\'\'''\''/g
55 --h*) printf '%s\n' "$usage" || exit 2; exit;;
56 --v*) echo "$version" || exit 2; exit;;
58 -*\'*) cmp="$cmp '"`printf '%sX\n' "$1" | sed "$escape"`;;
59 -?*) cmp="$cmp '$1'";;
68 test "X$file" = X- || <"$file" || exit 2
74 if test $# -eq 1; then
76 *[-.]gz* | *[-.][zZ] | *.t[ga]z)
77 FILE=`expr "X$1" : 'X\(.*\)[-.][zZtga]*$'`
80 (gzip -cd -- "$1" 4>&-; echo $? >&4) 3>&- | eval "$cmp" - '"$FILE"' >&3
83 echo >&2 "$0: $1: unknown compressed file extension"
86 elif test $# -eq 2; then
88 *[-.]gz* | *[-.][zZ] | *.t[ga]z | -)
90 *[-.]gz* | *[-.][zZ] | *.t[ga]z | -)
91 if test "$1$2" = --; then
94 (gzip -cdfq - 4>&-; echo $? >&4) 3>&- |
98 # Reject Solaris 8's buggy /bin/bash 2.03.
100 (echo X | eval "$cmp" /dev/fd/5 - >/dev/null 2>&1) \
105 (gzip -cdfq -- "$1" 4>&-; echo $? >&4) 3>&- |
106 ( (gzip -cdfq -- "$2" 4>&-; echo $? >&4) 3>&- 5<&- </dev/null |
107 eval "$cmp" /dev/fd/5 - >&3) 5<&0
110 *[1-9]*) gzip_status=1;;
114 F=`expr "/$2" : '.*/\(.*\)[-.][zZtga]*$'` || F=$prog
117 test -n "$tmp" && rm -f "$tmp"
119 ' HUP INT PIPE TERM 0
120 if type mktemp >/dev/null 2>&1; then
121 tmp=`mktemp -t -- "$F.XXXXXX"` || exit 2
124 tmp=${TMPDIR-/tmp}/$F.$$
126 gzip -cdfq -- "$2" > "$tmp" || exit 2
129 (gzip -cdfq -- "$1" 4>&-; echo $? >&4) 3>&- |
130 eval "$cmp" - '"$tmp"' >&3
133 rm -f "$tmp" || gzip_status=$?
134 trap - HUP INT PIPE TERM 0
140 (gzip -cdfq -- "$1" 4>&-; echo $? >&4) 3>&- |
141 eval "$cmp" - '"$2"' >&3
145 *[-.]gz* | *[-.][zZ] | *.t[ga]z | -)
148 (gzip -cdfq -- "$2" 4>&-; echo $? >&4) 3>&- |
149 eval "$cmp" '"$1"' - >&3
151 *) eval "$cmp" '"$1"' '"$2"';;
155 echo >&2 "$0: invalid number of operands; try \`$0 --help' for help"
160 test "$gzip_status" -eq 0 || exit 2