Initial import from FreeBSD RELENG_4:
[dragonfly.git] / gnu / usr.bin / gzip / zdiff
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 # $FreeBSD: src/gnu/usr.bin/gzip/zdiff,v 1.5.2.1 2002/01/28 01:21:12 nectar Exp $
13
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 1
31         fi ;;
32     esac
33 done
34 if test -z "$FILES"; then
35         echo "Usage: $prog [${comp}_options] file [file]"
36         exit 1
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         STAT="$?"
43
44 elif test $# -eq 2; then
45         case "$1" in
46         *[-.]gz* | *[-.][zZ] | *.t[ga]z)
47                 case "$2" in
48                 *[-.]gz* | *[-.][zZ] | *.t[ga]z)
49                         F=`echo "$2" | sed 's|.*/||;s|[-.][zZtga]*||'`
50                         tmp=`mktemp -t "$F"`
51                         gzip -cdfq "$2" > "$tmp"
52                         gzip -cdfq "$1" | $comp $OPTIONS - "$tmp"
53                         STAT="$?"
54                         /bin/rm -f "$tmp";;
55
56                 *)      gzip -cdfq "$1" | $comp $OPTIONS - "$2"
57                         STAT="$?";;
58                 esac;;
59         *)      case "$2" in
60                 *[-.]gz* | *[-.][zZ] | *.t[ga]z)
61                         gzip -cdfq "$2" | $comp $OPTIONS "$1" -
62                         STAT="$?";;
63                 *)      $comp $OPTIONS "$1" "$2"
64                         STAT="$?";;
65                 esac;;
66         esac
67         exit "$STAT"
68 else
69         echo "Usage: $prog [${comp}_options] file [file]"
70         exit 1
71 fi