]> git.cworth.org Git - gzip/blob - zdiff.in
Imported Debian patch 1.3.5-13
[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 prog=`echo $0 | sed 's|.*/||'`
15 case "$prog" in
16   *cmp) comp=${CMP-cmp}   ;;
17   *)    comp=${DIFF-diff} ;;
18 esac
19
20 OPTIONS=
21 FILES=
22 for ARG
23 do
24     case "$ARG" in
25     -*) OPTIONS="$OPTIONS $ARG";;
26      *) if test -f "$ARG"; then
27             FILES="$FILES $ARG"
28         else
29             echo "${prog}: $ARG not found or not a regular file"
30             exit 2
31         fi ;;
32     esac
33 done
34 if test -z "$FILES"; then
35         echo "Usage: $prog [${comp}_options] file [file]"
36         exit 2
37 fi
38 set $FILES
39 if test $# -eq 1; then
40         FILE=`echo "$1" | sed 's/[-.][zZtga]*$//'`
41         gzip -cd "$1" | $comp $OPTIONS - "$FILE"
42
43 elif test $# -eq 2; then
44         case "$1" in
45         *[-.]gz* | *[-.][zZ] | *.t[ga]z)
46                 case "$2" in
47                 *[-.]gz* | *[-.][zZ] | *.t[ga]z)
48                         F=`echo "$2" | sed 's|.*/||;s|[-.][zZtga]*||'`
49                         set -C
50                         trap 'rm -f /tmp/"$F".$$; exit 2' HUP INT PIPE TERM 0
51                         gzip -cdfq "$2" > /tmp/"$F".$$ || exit
52                         gzip -cdfq "$1" | $comp $OPTIONS - /tmp/"$F".$$
53                         STAT="$?"
54                         /bin/rm -f /tmp/"$F".$$ || STAT=2
55                         trap - HUP INT PIPE TERM 0
56                         exit $STAT;;
57
58                 *)      gzip -cdfq "$1" | $comp $OPTIONS - "$2";;
59                 esac;;
60         *)      case "$2" in
61                 *[-.]gz* | *[-.][zZ] | *.t[ga]z)
62                         gzip -cdfq "$2" | $comp $OPTIONS "$1" -;;
63                 *)      $comp $OPTIONS "$1" "$2";;
64                 esac;;
65         esac
66 else
67         echo "Usage: $prog [${comp}_options] file [file]"
68         exit 2
69 fi