zdiff revision 1.2
11.1Smrg#!/bin/sh - 21.1Smrg# 31.2Swiz# $NetBSD: zdiff,v 1.2 2003/12/28 12:43:43 wiz Exp $ 41.2Swiz# 51.1Smrg# $OpenBSD: zdiff,v 1.2 2003/07/29 07:42:44 otto Exp $ 61.1Smrg# 71.1Smrg# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com> 81.1Smrg# 91.1Smrg# Permission to use, copy, modify, and distribute this software for any 101.1Smrg# purpose with or without fee is hereby granted, provided that the above 111.1Smrg# copyright notice and this permission notice appear in all copies. 121.1Smrg# 131.1Smrg# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 141.1Smrg# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 151.1Smrg# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 161.1Smrg# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 171.1Smrg# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 181.1Smrg# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 191.1Smrg# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 201.1Smrg# 211.1Smrg# Sponsored in part by the Defense Advanced Research Projects 221.1Smrg# Agency (DARPA) and Air Force Research Laboratory, Air Force 231.1Smrg# Materiel Command, USAF, under agreement number F39502-99-1-0512. 241.1Smrg# 251.1Smrg 261.1Smrg# Set $prog based on $0 271.1Smrgcase $0 in 281.1Smrg *cmp) prog=cmp 291.1Smrg ;; 301.1Smrg *) prog=diff 311.1Smrg ;; 321.1Smrgesac 331.1SmrgUSAGE="usage: z$prog [options] file1 [file2]" 341.1Smrg 351.1Smrg# Pull out any command line flags so we can pass them to diff/cmp 361.1Smrg# XXX - assumes there is no optarg 371.1Smrgflags= 381.1Smrgwhile test $# -ne 0; do 391.1Smrg case "$1" in 401.1Smrg --) 411.1Smrg shift 421.1Smrg break 431.1Smrg ;; 441.1Smrg -*) 451.1Smrg flags="$flags $1" 461.1Smrg shift 471.1Smrg ;; 481.1Smrg *) 491.1Smrg break 501.1Smrg ;; 511.1Smrg esac 521.1Smrgdone 531.1Smrg 541.1Smrgif [ $# -eq 1 ]; then 551.1Smrg # One file given, compare compressed to uncompressed 561.1Smrg files="$1" 571.1Smrg case "$1" in 581.1Smrg *[._-][Zz]) 591.1Smrg files="${1%??}" 601.1Smrg ;; 611.1Smrg *[._-]gz) 621.1Smrg files="${1%???}" 631.1Smrg ;; 641.1Smrg *.t[ag]z) 651.1Smrg files="${1%??}"ar 661.1Smrg ;; 671.1Smrg *) echo "z$prog: unknown suffix" 1>&2 681.1Smrg exit 1 691.1Smrg esac 701.1Smrg compress -cdfq "$1" | $prog $flags - "$files" 711.1Smrg status=$? 721.1Smrgelif [ $# -eq 2 ]; then 731.1Smrg # Two files given, compare the two uncompressing as needed 741.1Smrg case "$1" in 751.1Smrg *[._-][Zz]|*[._-]gz|*.t[ag]z) 761.1Smrg files=- 771.1Smrg filt="compress -cdfq $1" 781.1Smrg ;; 791.1Smrg *) 801.1Smrg files="$1" 811.1Smrg ;; 821.1Smrg esac 831.1Smrg case "$2" in 841.1Smrg *[._-][Zz]|*[._-]gz|*.t[ag]z) 851.1Smrg if [ "$files" = "-" ]; then 861.1Smrg tmp=`mktemp -t z$prog.XXXXXXXXXX` || exit 1 871.1Smrg trap "rm -f $tmp" 0 1 2 3 13 15 881.1Smrg compress -cdfq "$2" > $tmp 891.1Smrg files="$files $tmp" 901.1Smrg else 911.1Smrg files="$files -" 921.1Smrg filt="compress -cdfq $2" 931.1Smrg fi 941.1Smrg ;; 951.1Smrg *) 961.1Smrg files="$files $2" 971.1Smrg ;; 981.1Smrg esac 991.1Smrg if [ -n "$filt" ]; then 1001.1Smrg $filt | $prog $flags $files 1011.1Smrg else 1021.1Smrg $prog $flags $files 1031.1Smrg fi 1041.1Smrg status=$? 1051.1Smrgelse 1061.1Smrg echo "$USAGE" 1>&2 1071.1Smrg exit 1 1081.1Smrgfi 1091.1Smrg 1101.1Smrgexit $status 111