Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[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 # $DragonFly: src/gnu/usr.bin/gzip/Attic/zdiff,v 1.2 2003/06/17 04:25:46 dillon Exp $
14
15 prog=`echo $0 | sed 's|.*/||'`
16 case "$prog" in
17   *cmp) comp=${CMP-cmp}   ;;
18   *)    comp=${DIFF-diff} ;;
19 esac
20
21 OPTIONS=
22 FILES=
23 for ARG
24 do
25     case "$ARG" in
26     -*) OPTIONS="$OPTIONS $ARG";;
27      *) if test -f "$ARG"; then
28             FILES="$FILES $ARG"
29         else
30             echo "${prog}: $ARG not found or not a regular file"
31             exit 1
32         fi ;;
33     esac
34 done
35 if test -z "$FILES"; then
36         echo "Usage: $prog [${comp}_options] file [file]"
37         exit 1
38 fi
39 set $FILES
40 if test $# -eq 1; then
41         FILE=`echo "$1" | sed 's/[-.][zZtga]*$//'`
42         gzip -cd "$1" | $comp $OPTIONS - "$FILE"
43         STAT="$?"
44
45 elif test $# -eq 2; then
46         case "$1" in
47         *[-.]gz* | *[-.][zZ] | *.t[ga]z)
48                 case "$2" in
49                 *[-.]gz* | *[-.][zZ] | *.t[ga]z)
50                         F=`echo "$2" | sed 's|.*/||;s|[-.][zZtga]*||'`
51                         tmp=`mktemp -t "$F"`
52                         gzip -cdfq "$2" > "$tmp"
53                         gzip -cdfq "$1" | $comp $OPTIONS - "$tmp"
54                         STAT="$?"
55                         /bin/rm -f "$tmp";;
56
57                 *)      gzip -cdfq "$1" | $comp $OPTIONS - "$2"
58                         STAT="$?";;
59                 esac;;
60         *)      case "$2" in
61                 *[-.]gz* | *[-.][zZ] | *.t[ga]z)
62                         gzip -cdfq "$2" | $comp $OPTIONS "$1" -
63                         STAT="$?";;
64                 *)      $comp $OPTIONS "$1" "$2"
65                         STAT="$?";;
66                 esac;;
67         esac
68         exit "$STAT"
69 else
70         echo "Usage: $prog [${comp}_options] file [file]"
71         exit 1
72 fi