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