bzdiff 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/sh
  2. # sh is buggy on RS/6000 AIX 3.2. Replace above line with #!/bin/ksh
  3. # Bzcmp/diff wrapped for bzip2,
  4. # adapted from zdiff by Philippe Troin <phil@fifi.org> for Debian GNU/Linux.
  5. # Bzcmp and bzdiff are used to invoke the cmp or the diff pro-
  6. # gram on compressed files. All options specified are passed
  7. # directly to cmp or diff. If only 1 file is specified, then
  8. # the files compared are file1 and an uncompressed file1.gz.
  9. # If two files are specified, then they are uncompressed (if
  10. # necessary) and fed to cmp or diff. The exit status from cmp
  11. # or diff is preserved.
  12. PATH="/usr/bin:/bin:$PATH"; export PATH
  13. prog=`echo $0 | sed 's|.*/||'`
  14. case "$prog" in
  15. *cmp) comp=${CMP-cmp} ;;
  16. *) comp=${DIFF-diff} ;;
  17. esac
  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 1
  29. fi ;;
  30. esac
  31. done
  32. if test -z "$FILES"; then
  33. echo "Usage: $prog [${comp}_options] file [file]"
  34. exit 1
  35. fi
  36. tmp=`mktemp ${TMPDIR:-/tmp}/bzdiff.XXXXXXXXXX` || {
  37. echo 'cannot create a temporary file' >&2
  38. exit 1
  39. }
  40. set $FILES
  41. if test $# -eq 1; then
  42. FILE=`echo "$1" | sed 's/.bz2$//'`
  43. bzip2 -cd "$FILE.bz2" | $comp $OPTIONS - "$FILE"
  44. STAT="$?"
  45. elif test $# -eq 2; then
  46. case "$1" in
  47. *.bz2)
  48. case "$2" in
  49. *.bz2)
  50. F=`echo "$2" | sed 's|.*/||;s|.bz2$||'`
  51. bzip2 -cdfq "$2" > $tmp
  52. bzip2 -cdfq "$1" | $comp $OPTIONS - $tmp
  53. STAT="$?"
  54. /bin/rm -f $tmp;;
  55. *) bzip2 -cdfq "$1" | $comp $OPTIONS - "$2"
  56. STAT="$?";;
  57. esac;;
  58. *) case "$2" in
  59. *.bz2)
  60. bzip2 -cdfq "$2" | $comp $OPTIONS "$1" -
  61. STAT="$?";;
  62. *) $comp $OPTIONS "$1" "$2"
  63. STAT="$?";;
  64. esac;;
  65. esac
  66. exit "$STAT"
  67. else
  68. echo "Usage: $prog [${comp}_options] file [file]"
  69. exit 1
  70. fi