]> icculus.org git repositories - icculus/xz.git/blob - src/scripts/lzdiff
s/decompressed/compressed/ in the command line tool's
[icculus/xz.git] / src / scripts / lzdiff
1 #!/bin/sh
2 # sh is buggy on RS/6000 AIX 3.2. Replace above line with #!/bin/ksh
3
4 # lzcmp and lzdiff are used to invoke the cmp or the diff pro-
5 # gram  on compressed files.  All options specified are passed
6 # directly to cmp or diff.  If only 1 file is specified,  then
7 # the files compared  are file1 and an uncompressed file1.lzma.
8 # If two files are specified, then they are  uncompressed  and
9 # fed  to  cmp  or  diff.  The exit status from cmp or diff is
10 # preserved.
11
12 prog=`echo $0 | sed 's|.*/||'`
13 case "$prog" in
14   *cmp) comp=${CMP-cmp}   ;;
15   *)    comp=${DIFF-diff} ;;
16 esac
17
18 OPTIONS=
19 FILES=
20 for ARG
21 do
22     case "$ARG" in
23     -*) OPTIONS="$OPTIONS $ARG";;
24      *) if test -f "$ARG"; then
25             FILES="$FILES $ARG"
26         else
27             echo "${prog}: $ARG not found or not a regular file"
28             exit 2
29         fi ;;
30     esac
31 done
32 if test -z "$FILES"; then
33         echo "Usage: $prog [${comp}_options] file [file]"
34         exit 2
35 fi
36 set $FILES
37 if test $# -eq 1; then
38         FILE=`echo "$1" | sed 's/[-.][tlaz]*$//'`
39         lzma -dc "$1" | $comp $OPTIONS - "$FILE"
40
41 elif test $# -eq 2; then
42         case "$1" in
43         *[-.]lzma | *.t[la]z)
44                 case "$2" in
45                 *[-.]lzma | *.t[la]z)
46                         F=`echo "$2" | sed 's|.*/||;s|[-.][tlaz]*||'`
47                         TF=`/usr/bin/mktemp ${TMPDIR:-/tmp}/"$F".XXXXXXXXXX` || exit 1
48                         trap 'rm -f "$TF"; exit 2' EXIT HUP INT PIPE TERM
49                         lzma -dc "$2" > "$TF" || exit
50                         lzma -dc "$1" | $comp $OPTIONS - "$TF"
51                         STAT="$?"
52                         rm -f "$TF" || STAT=2
53                         trap EXIT HUP INT PIPE TERM
54                         exit $STAT;;
55
56                 *)      lzma -dc "$1" | $comp $OPTIONS - "$2";;
57                 esac;;
58         *)      case "$2" in
59                 *[-.]lzma | *.t[la]z)
60                         lzma -dc "$2" | $comp $OPTIONS "$1" -;;
61                 *)      $comp $OPTIONS "$1" "$2";;
62                 esac;;
63         esac
64 else
65         echo "Usage: $prog [${comp}_options] file [file]"
66         exit 2
67 fi