Sync usage with man page.
[netbsd-mini2440.git] / usr.bin / gzip / zdiff
blob41031379ccf541669ffc49c5bcb8f1132d974f73
1 #!/bin/sh -
3 # $NetBSD: zdiff,v 1.2 2003/12/28 12:43:43 wiz Exp $
5 # $OpenBSD: zdiff,v 1.2 2003/07/29 07:42:44 otto Exp $
7 # Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
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.
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.
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.
26 # Set $prog based on $0
27 case $0 in
28 *cmp) prog=cmp
30 *) prog=diff
32 esac
33 USAGE="usage: z$prog [options] file1 [file2]"
35 # Pull out any command line flags so we can pass them to diff/cmp
36 # XXX - assumes there is no optarg
37 flags=
38 while test $# -ne 0; do
39 case "$1" in
40 --)
41 shift
42 break
44 -*)
45 flags="$flags $1"
46 shift
49 break
51 esac
52 done
54 if [ $# -eq 1 ]; then
55 # One file given, compare compressed to uncompressed
56 files="$1"
57 case "$1" in
58 *[._-][Zz])
59 files="${1%??}"
61 *[._-]gz)
62 files="${1%???}"
64 *.t[ag]z)
65 files="${1%??}"ar
67 *) echo "z$prog: unknown suffix" 1>&2
68 exit 1
69 esac
70 gzip -cdfq "$1" | $prog $flags - "$files"
71 status=$?
72 elif [ $# -eq 2 ]; then
73 # Two files given, compare the two uncompressing as needed
74 case "$1" in
75 *[._-][Zz]|*[._-]gz|*.t[ag]z)
76 files=-
77 filt="gzip -cdfq $1"
80 files="$1"
82 esac
83 case "$2" in
84 *[._-][Zz]|*[._-]gz|*.t[ag]z)
85 if [ "$files" = "-" ]; then
86 tmp=`mktemp -t z$prog.XXXXXXXXXX` || exit 1
87 trap "rm -f $tmp" 0 1 2 3 13 15
88 gzip -cdfq "$2" > $tmp
89 files="$files $tmp"
90 else
91 files="$files -"
92 filt="gzip -cdfq $2"
96 files="$files $2"
98 esac
99 if [ -n "$filt" ]; then
100 $filt | $prog $flags $files
101 else
102 $prog $flags $files
104 status=$?
105 else
106 echo "$USAGE" 1>&2
107 exit 1
110 exit $status