xref: /minix3/external/bsd/bzip2/dist/bzdiff (revision 4a711bea63dc53acce03198b5fbfaa103fe328d6)
1*4a711beaSLionel Sambuc#!/bin/sh
2*4a711beaSLionel Sambuc# sh is buggy on RS/6000 AIX 3.2. Replace above line with #!/bin/ksh
3*4a711beaSLionel Sambuc
4*4a711beaSLionel Sambuc# Bzcmp/diff wrapped for bzip2,
5*4a711beaSLionel Sambuc# adapted from zdiff by Philippe Troin <phil@fifi.org> for Debian GNU/Linux.
6*4a711beaSLionel Sambuc
7*4a711beaSLionel Sambuc# Bzcmp and bzdiff are used to invoke the cmp or the  diff  pro-
8*4a711beaSLionel Sambuc# gram  on compressed files.  All options specified are passed
9*4a711beaSLionel Sambuc# directly to cmp or diff.  If only 1 file is specified,  then
10*4a711beaSLionel Sambuc# the  files  compared  are file1 and an uncompressed file1.gz.
11*4a711beaSLionel Sambuc# If two files are specified, then they are  uncompressed  (if
12*4a711beaSLionel Sambuc# necessary) and fed to cmp or diff.  The exit status from cmp
13*4a711beaSLionel Sambuc# or diff is preserved.
14*4a711beaSLionel Sambuc
15*4a711beaSLionel SambucPATH="/usr/bin:/bin:$PATH"; export PATH
16*4a711beaSLionel Sambucprog=`echo $0 | sed 's|.*/||'`
17*4a711beaSLionel Sambuccase "$prog" in
18*4a711beaSLionel Sambuc  *cmp) comp=${CMP-cmp}   ;;
19*4a711beaSLionel Sambuc  *)    comp=${DIFF-diff} ;;
20*4a711beaSLionel Sambucesac
21*4a711beaSLionel Sambuc
22*4a711beaSLionel SambucOPTIONS=
23*4a711beaSLionel SambucFILES=
24*4a711beaSLionel Sambucfor ARG
25*4a711beaSLionel Sambucdo
26*4a711beaSLionel Sambuc    case "$ARG" in
27*4a711beaSLionel Sambuc    -*)	OPTIONS="$OPTIONS $ARG";;
28*4a711beaSLionel Sambuc     *)	if test -f "$ARG"; then
29*4a711beaSLionel Sambuc            FILES="$FILES $ARG"
30*4a711beaSLionel Sambuc        else
31*4a711beaSLionel Sambuc            echo "${prog}: $ARG not found or not a regular file"
32*4a711beaSLionel Sambuc	    exit 1
33*4a711beaSLionel Sambuc        fi ;;
34*4a711beaSLionel Sambuc    esac
35*4a711beaSLionel Sambucdone
36*4a711beaSLionel Sambucif test -z "$FILES"; then
37*4a711beaSLionel Sambuc	echo "Usage: $prog [${comp}_options] file [file]"
38*4a711beaSLionel Sambuc	exit 1
39*4a711beaSLionel Sambucfi
40*4a711beaSLionel Sambuctmp=`mktemp ${TMPDIR:-/tmp}/bzdiff.XXXXXXXXXX` || {
41*4a711beaSLionel Sambuc      echo 'cannot create a temporary file' >&2
42*4a711beaSLionel Sambuc      exit 1
43*4a711beaSLionel Sambuc}
44*4a711beaSLionel Sambucset $FILES
45*4a711beaSLionel Sambucif test $# -eq 1; then
46*4a711beaSLionel Sambuc	FILE=`echo "$1" | sed 's/.bz2$//'`
47*4a711beaSLionel Sambuc	bzip2 -cd "$FILE.bz2" | $comp $OPTIONS - "$FILE"
48*4a711beaSLionel Sambuc	STAT="$?"
49*4a711beaSLionel Sambuc
50*4a711beaSLionel Sambucelif test $# -eq 2; then
51*4a711beaSLionel Sambuc	case "$1" in
52*4a711beaSLionel Sambuc        *.bz2)
53*4a711beaSLionel Sambuc                case "$2" in
54*4a711beaSLionel Sambuc	        *.bz2)
55*4a711beaSLionel Sambuc			F=`echo "$2" | sed 's|.*/||;s|.bz2$||'`
56*4a711beaSLionel Sambuc                        bzip2 -cdfq "$2" > $tmp
57*4a711beaSLionel Sambuc                        bzip2 -cdfq "$1" | $comp $OPTIONS - $tmp
58*4a711beaSLionel Sambuc                        STAT="$?"
59*4a711beaSLionel Sambuc			/bin/rm -f $tmp;;
60*4a711beaSLionel Sambuc
61*4a711beaSLionel Sambuc                *)      bzip2 -cdfq "$1" | $comp $OPTIONS - "$2"
62*4a711beaSLionel Sambuc                        STAT="$?";;
63*4a711beaSLionel Sambuc                esac;;
64*4a711beaSLionel Sambuc        *)      case "$2" in
65*4a711beaSLionel Sambuc	        *.bz2)
66*4a711beaSLionel Sambuc                        bzip2 -cdfq "$2" | $comp $OPTIONS "$1" -
67*4a711beaSLionel Sambuc                        STAT="$?";;
68*4a711beaSLionel Sambuc                *)      $comp $OPTIONS "$1" "$2"
69*4a711beaSLionel Sambuc                        STAT="$?";;
70*4a711beaSLionel Sambuc                esac;;
71*4a711beaSLionel Sambuc	esac
72*4a711beaSLionel Sambuc        exit "$STAT"
73*4a711beaSLionel Sambucelse
74*4a711beaSLionel Sambuc	echo "Usage: $prog [${comp}_options] file [file]"
75*4a711beaSLionel Sambuc	exit 1
76*4a711beaSLionel Sambucfi
77