]>
git.saurik.com Git - apple/file_cmds.git/blob - gzip/zdiff
3 # $NetBSD: zdiff,v 1.5 2010/04/14 20:30:28 joerg Exp $
5 # $OpenBSD: zdiff,v 1.2 2003/07/29 07:42:44 otto Exp $
8 # Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
9 # Copyright (c) 2010 Joerg Sonnenberger <joerg@NetBSD.org>
11 # Permission to use, copy, modify, and distribute this software for any
12 # purpose with or without fee is hereby granted, provided that the above
13 # copyright notice and this permission notice appear in all copies.
15 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 # Sponsored in part by the Defense Advanced Research Projects
24 # Agency (DARPA) and Air Force Research Laboratory, Air Force
25 # Materiel Command, USAF, under agreement number F39502-99-1-0512.
27 # $FreeBSD: src/usr.bin/gzip/zdiff,v 1.2 2011/05/23 09:02:44 delphij Exp $
29 # Set $prog based on $0
36 USAGE
="usage: $0 [options] file1 [file2]"
42 setvar
$3 "gzip -cdqf"
46 setvar
$3 "bzip2 -cdqf"
50 setvar
$3 "gzip -cdqf"
58 setvar
$3 "bzip2 -cdqf"
61 setvar
$2 "${1%?????}"
66 setvar
$3 "gzip -cdqf"
70 setvar
$3 "bzip2 -cdqf"
73 setvar
$2 "${1%???}"ar
74 setvar
$3 "bzip2 -cdqf"
88 # Pull out any command line flags so we can pass them to diff/cmp
89 # XXX - assumes there is no optarg
91 while test $# -ne 0; do
110 if [ $# -eq 1 ]; then
111 # One file given, compare compressed to uncompressed
113 check_suffix
"$1" files filt
114 if [ -z "$filt" ]; then
115 echo "z$prog: unknown suffix" 1>&2
118 $filt -- "$1" | $prog $flags -- - "$files"
120 elif [ $# -eq 2 ]; then
121 # Two files given, compare the two uncompressing as needed
122 check_suffix
"$1" files filt
123 check_suffix
"$2" files2 filt2
124 if [ -z "$filt" -a -z "$filt2" ]; then
125 $prog $flags -- "$1" "$2"
126 elif [ -z "$filt" -a -n "$filt2" -a "$1" != "-" ]; then
127 $filt2 -- "$2" | $prog $flags -- "$1" -
128 elif [ -n "$filt" -a -z "$filt2" -a "$2" != "-" ]; then
129 $filt -- "$1" | $prog $flags -- - "$2"
131 tmp
=`mktemp -t z$prog.XXXXXXXXXX` || exit 1
132 trap "rm -f $tmp" 0 1 2 3 13 15
133 ${filt2:-cat} -- "$2" > $tmp || exit $?
134 ${filt:-cat} -- "$1" | $prog $flags -- - "$tmp"