home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR40 / GNUZIP_.ZIP / ZNEW.IN < prev   
Text File  |  1993-03-28  |  3KB  |  114 lines

  1. :
  2. #!/bin/sh
  3.  
  4. check=0
  5. pipe=0
  6. opt=
  7. files=
  8. keep=0
  9. block=1024
  10. # block is the disk block size (best guess, need not be exact)
  11.  
  12. for arg
  13. do
  14.   case "$arg" in
  15.   -*)     opt="$opt $arg";;
  16.    *)     files="$files $arg";;
  17.   esac
  18. done
  19.  
  20. if test -z "$files"; then
  21.   echo 'recompress .Z files into .z (gzip) files'
  22.   echo usage: `echo $0 | sed 's,^.*/,,'` "[-tv9P]" file.Z...
  23.   echo "  -t tests the new files before deleting originals"
  24.   echo "  -v be verbose"
  25.   echo "  -9 use the slowest compression method (optimal compression)"
  26.   echo "  -K keep a .Z file when it is smaller than the .z file"
  27.   if touch -r foo$$ 2>/dev/null; then
  28.     echo "  -P use pipes for the conversion"
  29.   else
  30.     echo "  -P use pipes for the conversion (does not preserve timestamp)"
  31.   fi
  32.   rm -f foo$$
  33.   exit 1
  34. fi
  35. opt=`echo $opt | sed -e 's/ //g' -e 's/-//g'`
  36. case "$opt" in
  37.   *t*) check=1; opt=`echo $opt | sed 's/t//g'`
  38. esac
  39. case "$opt" in
  40.   *K*) keep=1; opt=`echo $opt | sed 's/K//g'`
  41. esac
  42. case "$opt" in
  43.   *P*) pipe=1; opt=`echo $opt | sed 's/P//g'`
  44. esac
  45. if test -n "$opt"; then
  46.   opt="-$opt"
  47. fi
  48.  
  49. for i in $files; do
  50.   n=`echo $i | sed 's/.Z$//'`
  51.   if test ! -f $n.Z ; then
  52.     echo $n.Z not found
  53.     exit 1
  54.   fi
  55.   old=`wc -c < $n.Z`
  56.   if test $pipe -eq 1; then
  57.     if gzip -d < $n.Z | gzip $opt > $n.z; then
  58.       # Copy time stamp from old file to new one, if possible.
  59.       touch -r $n.Z $n.z 2> /dev/null
  60.     else
  61.       echo error while recompressing $n.Z
  62.       exit 1
  63.     fi
  64.   else
  65.     if test $check -eq 1; then
  66.       if cp -p $n.Z $n.$$ 2> /dev/null || cp $n.Z $n.$$; then
  67.     :
  68.       else
  69.     echo cannot backup $n.Z
  70.     exit 1
  71.       fi
  72.     fi
  73.     if gzip -d $n.Z; then
  74.       :
  75.     else
  76.       test $check -eq 1 && mv $n.$$ $n.Z
  77.       echo error while uncompressing $n.Z
  78.       exit 1
  79.     fi
  80.     if gzip $opt $n; then
  81.       :
  82.     else
  83.       test $check -eq 1 && mv $n.$$ $n.Z
  84.       echo error while recompressing $n
  85.       exit 1
  86.     fi
  87.   fi
  88.   new=`wc -c < $n.z`
  89.   if test $keep -eq 1 -a `expr \( $old + $block - 1 \) / $block` -lt \
  90.                          `expr \( $new + $block - 1 \) / $block`; then
  91.     if test $pipe -eq 1; then
  92.       rm -f $n.z
  93.     elif test $check -eq 1; then
  94.       mv $n.$$ $n.Z && rm -f $n.z
  95.     else
  96.       gzip -d $n.z && compress $n && rm -f $n.z
  97.     fi
  98.     echo "$n.Z smaller than $n.z -- unchanged"
  99.  
  100.   elif test $check -eq 1; then
  101.     if gzip -t $n.z ; then
  102.       rm -f $n.$$ $n.Z
  103.     else
  104.       test $pipe -eq 0 && mv $n.$$ $n.Z
  105.       rm -f $n.z
  106.       echo error while testing $n.z, $n.Z unchanged
  107.       exit 1
  108.     fi
  109.   elif test $pipe -eq 1; then
  110.     rm -f $n.Z
  111.   fi
  112. done
  113. exit 0
  114.