Annotation of coherent/g/usr/bin/gzip/znew.in, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.