* zdiff.in: Fix typo that broke most usages. Problem reported by
[debian/gzip] / zdiff.in
1 #!/bin/sh
2 # sh is buggy on RS/6000 AIX 3.2. Replace above line with #!/bin/ksh
3
4 # Zcmp and zdiff are used to invoke the cmp or the  diff  pro-
5 # gram  on compressed files.  All options specified are passed
6 # directly to cmp or diff.  If only 1 file is specified,  then
7 # the  files  compared  are file1 and an uncompressed file1.gz.
8 # If two files are specified, then they are  uncompressed  (if
9 # necessary) and fed to cmp or diff.  The exit status from cmp
10 # or diff is preserved.
11
12 PATH="BINDIR:$PATH"; export PATH
13 case "$0" in
14   *cmp) prog=cmp ; cmp='${CMP-cmp}'  ;;
15   *)    prog=diff; cmp='${DIFF-diff}';;
16 esac
17
18 version="z$prog (gzip) @VERSION@
19 Copyright (C) 2006 Free Software Foundation, Inc.
20 This is free software.  You may redistribute copies of it under the terms of
21 the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
22 There is NO WARRANTY, to the extent permitted by law.
23
24 Written by Jean-loup Gailly."
25
26 usage="Usage: z$prog [OPTION]... FILE1 [FILE2]
27 Compare FILE1 to FILE2, using their uncompressed contents if they are
28 compressed.  If FILE2 is omitted, compare FILE1 to the uncompressed
29 contents of FILE1.gz.  Do comparisons like '$prog' does.
30
31 OPTIONs are the same as for '$prog'.
32
33 Report bugs to <bug-gzip@gnu.org>."
34
35 FILES=
36 while :; do
37   case $1 in
38   --h*) echo "$usage" || exit 2; exit;;
39   --v*) echo "$version" || exit 2; exit;;
40   --) shift; break;;
41   -*\'*) echo >&2 "$prog: $1: option contains apostrophe"; exit 2;;
42   -?*) cmp="$cmp '$1'"; shift;;
43   *) break;;
44   esac
45 done
46 cmp="$cmp --"
47
48 for file; do
49   test "X$file" = X- || <"$file" || exit 2
50 done
51
52 if test $# -eq 1; then
53   case $1 in
54   *[-.]gz* | *[-.][zZ] | *.t[ga]z)
55     FILE=`expr "X$1" : 'X\(.*\)[-.][zZtga]*$'`
56     gzip -cd -- "$1" | eval "$cmp" - '"$FILE"';;
57   *)
58     echo >&2 "$prog: $1: unknown compressed file extension"
59     exit 2;;
60   esac
61 elif test $# -eq 2; then
62         case "$1" in
63         *[-.]gz* | *[-.][zZ] | *.t[ga]z | -)
64                 case "$2" in
65                 *[-.]gz* | *[-.][zZ] | *.t[ga]z | -)
66                     if test "$1$2" = --; then
67                         gzip -cdfq - | eval "$cmp" - -
68                     elif test -r /dev/fd/3 3</dev/null; then
69                         gzip -cdfq -- "$1" |
70                           (gzip -cdfq -- "$2" |
71                            eval "$cmp" /dev/fd/3 -) 3<&0
72                     else
73                         F=`expr "/$2" : '.*/\(.*\)[-.][zZtga]*$'` || F=$prog
74                         tmp=
75                         trap '
76                           test -n "$tmp" && rm -f "$tmp"
77                           (exit 2); exit 2
78                         ' HUP INT PIPE TERM 0
79                         if type mktemp >/dev/null 2>&1; then
80                           tmp=`mktemp -t -- "$F.XXXXXX"` || exit
81                         else
82                           set -C
83                           tmp=${TMPDIR-/tmp}/$F.$$
84                         fi
85                         gzip -cdfq -- "$2" > "$tmp" || exit
86                         gzip -cdfq -- "$1" | eval "$cmp" - '"$tmp"'
87                         STAT="$?"
88                         rm -f "$tmp" || STAT=2
89                         trap - HUP INT PIPE TERM 0
90                         exit $STAT
91                     fi;;
92                 *)      gzip -cdfq -- "$1" | eval "$cmp" - '"$2"';;
93                 esac;;
94         *)      case "$2" in
95                 *[-.]gz* | *[-.][zZ] | *.t[ga]z | -)
96                         gzip -cdfq -- "$2" | eval "$cmp" '"$1"' -;;
97                 *)      eval "$cmp" '"$1"' '"$2"';;
98                 esac;;
99         esac
100 else
101         echo >&2 "$usage"
102         exit 2
103 fi