]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - usr.bin/gzip/zdiff
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / usr.bin / gzip / zdiff
1 #!/bin/sh -
2 #
3 # $NetBSD: zdiff,v 1.3 2004/03/29 10:01:00 wiz Exp $
4 # $OpenBSD: zdiff,v 1.2 2003/07/29 07:42:44 otto Exp $
5 #
6 #-
7 # Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
8 #
9 # Permission to use, copy, modify, and distribute this software for any
10 # purpose with or without fee is hereby granted, provided that the above
11 # copyright notice and this permission notice appear in all copies.
12 #
13 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #
21 # Sponsored in part by the Defense Advanced Research Projects
22 # Agency (DARPA) and Air Force Research Laboratory, Air Force
23 # Materiel Command, USAF, under agreement number F39502-99-1-0512.
24 #
25 # $FreeBSD$
26
27 # Set $prog based on $0
28 case $0 in
29         *cmp)   prog=cmp
30                 ;;
31         *)      prog=diff
32                 ;;
33 esac
34 USAGE="usage: z$prog [options] file1 [file2]"
35
36 # Pull out any command line flags so we can pass them to diff/cmp
37 # XXX - assumes there is no optarg
38 flags=
39 while test $# -ne 0; do
40         case "$1" in
41                 --)
42                         shift
43                         break
44                         ;;
45                 -*)
46                         flags="$flags $1"
47                         shift
48                         ;;
49                 *)
50                         break
51                         ;;
52         esac
53 done
54
55 if [ $# -eq 1 ]; then
56         # One file given, compare compressed to uncompressed
57         files="$1"
58         case "$1" in
59                 *[._-][Zz])
60                         files="${1%??}"
61                         ;;
62                 *[._-]gz)
63                         files="${1%???}"
64                         ;;
65                 *.t[ag]z)
66                         files="${1%??}"ar
67                         ;;
68                 *)      echo "z$prog: unknown suffix" 1>&2
69                         exit 1
70         esac
71         gzip -cdfq "$1" | $prog $flags - "$files"
72         status=$?
73 elif [ $# -eq 2 ]; then
74         # Two files given, compare the two uncompressing as needed
75         case "$1" in
76                 *[._-][Zz]|*[._-]gz|*.t[ag]z)
77                         files=-
78                         filt="gzip -cdfq $1"
79                         ;;
80                 *)
81                         files="$1"
82                         ;;
83         esac
84         case "$2" in
85                 *[._-][Zz]|*[._-]gz|*.t[ag]z)
86                         if [ "$files" = "-" ]; then
87                                 tmp=`mktemp -t z$prog.XXXXXXXXXX` || exit 1
88                                 trap "rm -f $tmp" 0 1 2 3 13 15
89                                 gzip -cdfq "$2" > $tmp
90                                 files="$files $tmp"
91                         else
92                                 files="$files -"
93                                 filt="gzip -cdfq $2"
94                         fi
95                         ;;
96                 *)
97                         files="$files $2"
98                         ;;
99         esac
100         if [ -n "$filt" ]; then
101                 $filt | $prog $flags $files
102         else
103                 $prog $flags $files
104         fi
105         status=$?
106 else
107         echo "$USAGE" 1>&2
108         exit 1
109 fi
110
111 exit $status