4 PATH="BINDIR:$PATH"; export PATH
14 # block is the disk block size (best guess, need not be exact)
16 warn="(does not preserve modes and timestamp)"
19 echo hi > $tmp.1 || exit 1
20 echo hi > $tmp.2 || exit 1
21 if test -z "`(${CPMOD-cpmod} $tmp.1 $tmp.2) 2>&1`"; then
26 if test -z "$cpmod" && ${TOUCH-touch} -r $tmp.1 $tmp.2 2>/dev/null; then
27 cpmod="${TOUCH-touch}"
29 warn="(does not preserve file modes)"
32 # check if GZIP env. variable uses -S or --suffix
34 ext=`echo $tmp.1* | sed "s|$tmp.1||"`
36 if test -z "$ext"; then
37 echo znew: error determining gzip extension
40 if test "$ext" = ".Z"; then
41 echo znew: cannot use .Z as gzip extension.
48 -*) opt="$opt $arg"; shift;;
53 if test $# -eq 0; then
54 echo "recompress .Z files into $ext (gzip) files"
55 echo usage: `echo $0 | sed 's,^.*/,,'` "[-tv9KP]" file.Z...
56 echo " -t tests the new files before deleting originals"
58 echo " -9 use the slowest compression method (optimal compression)"
59 echo " -K keep a .Z file when it is smaller than the $ext file"
60 echo " -P use pipes for the conversion $warn"
64 opt=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
66 *t*) check=1; opt=`echo "$opt" | sed 's/t//g'`
69 *K*) keep=1; opt=`echo "$opt" | sed 's/K//g'`
72 *P*) pipe=1; opt=`echo "$opt" | sed 's/P//g'`
74 if test -n "$opt"; then
79 n=`echo $i | sed 's/.Z$//'`
80 if test ! -f "$n.Z" ; then
84 test $keep -eq 1 && old=`wc -c < "$n.Z"`
85 if test $pipe -eq 1; then
86 if gzip -d < "$n.Z" | gzip $opt > "$n$ext"; then
87 # Copy file attributes from old file to new one, if possible.
88 test -n "$cpmod" && $cpmod $cpmodarg "$n.Z" "$n$ext" 2> /dev/null
90 echo error while recompressing $n.Z
94 if test $check -eq 1; then
95 if cp -p "$n.Z" "$n.$$" 2> /dev/null || cp "$n.Z" "$n.$$"; then
98 echo cannot backup "$n.Z"
102 if gzip -d "$n.Z"; then
105 test $check -eq 1 && mv "$n.$$" "$n.Z"
106 echo error while uncompressing $n.Z
109 if gzip $opt "$n"; then
112 if test $check -eq 1; then
113 mv "$n.$$" "$n.Z" && rm -f "$n"
114 echo error while recompressing $n
116 # compress $n (might be dangerous if disk full)
117 echo error while recompressing $n, left uncompressed
122 test $keep -eq 1 && new=`wc -c < "$n$ext"`
123 if test $keep -eq 1 -a `expr \( $old + $block - 1 \) / $block` -lt \
124 `expr \( $new + $block - 1 \) / $block`; then
125 if test $pipe -eq 1; then
127 elif test $check -eq 1; then
128 mv "$n.$$" "$n.Z" && rm -f "$n$ext"
130 gzip -d "$n$ext" && compress "$n" && rm -f "$n$ext"
132 echo "$n.Z smaller than $n$ext -- unchanged"
134 elif test $check -eq 1; then
135 if gzip -t "$n$ext" ; then
138 test $pipe -eq 0 && mv "$n.$$" "$n.Z"
140 echo error while testing $n$ext, $n.Z unchanged
143 elif test $pipe -eq 1; then