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 3 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.
23 --__bindir) bindir
=${2?}; shift; shift;;
29 prog
=cmp; cmp='${CMP-cmp}' ;;
30 *) prog
=diff; cmp='${DIFF-diff}';;
33 version
="z$prog (gzip) @VERSION@
34 Copyright (C) 2007, 2009 Free Software Foundation, Inc.
35 This is free software. You may redistribute copies of it under the terms of
36 the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
37 There is NO WARRANTY, to the extent permitted by law.
39 Written by Jean-loup Gailly."
41 usage
="Usage: $0 [OPTION]... FILE1 [FILE2]
42 Compare FILE1 to FILE2, using their uncompressed contents if they are
43 compressed. If FILE2 is omitted, compare FILE1 to the uncompressed
44 contents of FILE1.gz. Do comparisons like '$prog' does.
46 OPTIONs are the same as for '$prog'.
48 Report bugs to <bug-gzip@gnu.org>."
50 # sed script to escape all ' for the shell, and then (to handle trailing
51 # newlines correctly) turn trailing X on last line into '.
53 s/'\''/'\''\\'\'''\''/g
59 --h*) printf '%s\n' "$usage" ||
exit 2; exit;;
60 --v*) echo "$version" ||
exit 2; exit;;
62 -*\'*) cmp="$cmp '"`printf '%sX\n' "$1" | sed "$escape"`;;
63 -?
*) cmp="$cmp '$1'";;
72 test "X$file" = X- ||
<"$file" ||
exit 2
78 if test $# -eq 1; then
80 *[-.
]gz
* |
*[-.
][zZ
] |
*.t
[ga
]z
)
81 FILE
=`expr "X$1" : 'X\(.*\)[-.][zZtga]*$'`
84 (gzip -cd -- "$1" 4>&-; echo $?
>&4) 3>&- |
eval "$cmp" - '"$FILE"' >&3
87 echo >&2 "$0: $1: unknown compressed file extension"
90 elif test $# -eq 2; then
92 *[-.
]gz
* |
*[-.
][zZ
] |
*.t
[ga
]z |
-)
94 *[-.
]gz
* |
*[-.
][zZ
] |
*.t
[ga
]z |
-)
95 if test "$1$2" = --; then
98 (gzip -cdfq - 4>&-; echo $?
>&4) 3>&- |
102 # Reject Solaris 8's buggy /bin/bash 2.03.
104 (echo X |
eval "$cmp" /dev
/fd
/5 - >/dev
/null
2>&1) \
109 (gzip -cdfq -- "$1" 4>&-; echo $?
>&4) 3>&- |
110 ( (gzip -cdfq -- "$2" 4>&-; echo $?
>&4) 3>&- 5<&- </dev
/null |
111 eval "$cmp" /dev
/fd
/5 -) 5<&0
114 *[1-9]*) gzip_status
=1;;
118 F
=`expr "/$2" : '.*/\(.*\)[-.][zZtga]*$'` || F
=$prog
121 test -n "$tmp" && rm -f "$tmp"
123 ' HUP INT PIPE TERM
0
124 if type mktemp
>/dev
/null
2>&1; then
125 tmp
=`mktemp -t -- "$F.XXXXXX"` ||
exit 2
128 tmp
=${TMPDIR-/tmp}/$F.$$
130 gzip -cdfq -- "$2" > "$tmp" ||
exit 2
133 (gzip -cdfq -- "$1" 4>&-; echo $?
>&4) 3>&- |
134 eval "$cmp" - '"$tmp"' >&3
137 rm -f "$tmp" || gzip_status
=$?
138 trap - HUP INT PIPE TERM
0
144 (gzip -cdfq -- "$1" 4>&-; echo $?
>&4) 3>&- |
145 eval "$cmp" - '"$2"' >&3
149 *[-.
]gz
* |
*[-.
][zZ
] |
*.t
[ga
]z |
-)
152 (gzip -cdfq -- "$2" 4>&-; echo $?
>&4) 3>&- |
153 eval "$cmp" '"$1"' - >&3
155 *) eval "$cmp" '"$1"' '"$2"';;
159 echo >&2 "$0: invalid number of operands; try \`$0 --help' for help"
164 test "$gzip_status" -eq 0 ||
exit 2