4 # Copyright (C) 1998, 2002, 2004 Free Software Foundation
5 # Copyright (C) 1993 Jean-loup Gailly
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 PATH="BINDIR:$PATH"; export PATH
32 # block is the disk block size (best guess, need not be exact)
34 warn="(does not preserve modes and timestamp)"
37 echo hi > $tmp || exit
38 if test -z "`(${CPMOD-cpmod} $tmp $tmp) 2>&1`"; then
43 if test -z "$cpmod" && ${TOUCH-touch} -r $tmp $tmp 2>/dev/null; then
44 cpmod="${TOUCH-touch}"
46 warn="(does not preserve file modes)"
49 # check if GZIP env. variable uses -S or --suffix
51 ext=`echo $tmp* | sed "s|$tmp||"`
53 if test -z "$ext"; then
54 echo znew: error determining gzip extension
57 if test "$ext" = ".Z"; then
58 echo znew: cannot use .Z as gzip extension.
65 -*) opt="$opt $arg"; shift;;
70 if test $# -eq 0; then
71 echo "recompress .Z files into $ext (gzip) files"
72 echo usage: `echo $0 | sed 's,^.*/,,'` "[-tv9KP]" file.Z...
73 echo " -t tests the new files before deleting originals"
75 echo " -9 use the slowest compression method (optimal compression)"
76 echo " -K keep a .Z file when it is smaller than the $ext file"
77 echo " -P use pipes for the conversion $warn"
81 opt=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
83 *t*) check=1; opt=`echo "$opt" | sed 's/t//g'`
86 *K*) keep=1; opt=`echo "$opt" | sed 's/K//g'`
89 *P*) pipe=1; opt=`echo "$opt" | sed 's/P//g'`
91 if test -n "$opt"; then
96 n=`echo $i | sed 's/.Z$//'`
97 if test ! -f "$n.Z" ; then
101 test $keep -eq 1 && old=`wc -c < "$n.Z"`
102 if test $pipe -eq 1; then
103 if gzip -d < "$n.Z" | gzip $opt > "$n$ext"; then
104 # Copy file attributes from old file to new one, if possible.
105 test -n "$cpmod" && $cpmod $cpmodarg "$n.Z" "$n$ext" 2> /dev/null
107 echo error while recompressing $n.Z
111 if test $check -eq 1; then
112 if cp -p "$n.Z" "$n.$$" 2> /dev/null || cp "$n.Z" "$n.$$"; then
115 echo cannot backup "$n.Z"
119 if gzip -d "$n.Z"; then
122 test $check -eq 1 && mv "$n.$$" "$n.Z"
123 echo error while uncompressing $n.Z
126 if gzip $opt "$n"; then
129 if test $check -eq 1; then
130 mv "$n.$$" "$n.Z" && rm -f "$n"
131 echo error while recompressing $n
133 # compress $n (might be dangerous if disk full)
134 echo error while recompressing $n, left uncompressed
139 test $keep -eq 1 && new=`wc -c < "$n$ext"`
140 if test $keep -eq 1 && test `expr \( $old + $block - 1 \) / $block` -lt \
141 `expr \( $new + $block - 1 \) / $block`; then
142 if test $pipe -eq 1; then
144 elif test $check -eq 1; then
145 mv "$n.$$" "$n.Z" && rm -f "$n$ext"
147 gzip -d "$n$ext" && compress "$n" && rm -f "$n$ext"
149 echo "$n.Z smaller than $n$ext -- unchanged"
151 elif test $check -eq 1; then
152 if gzip -t "$n$ext" ; then
155 test $pipe -eq 0 && mv "$n.$$" "$n.Z"
157 echo error while testing $n$ext, $n.Z unchanged
160 elif test $pipe -eq 1; then