3 # $FreeBSD: src/gnu/usr.bin/gzip/znew,v 1.5.2.1 2002/01/28 01:21:12 nectar Exp $
4 # $DragonFly: src/gnu/usr.bin/gzip/Attic/znew,v 1.2 2003/06/17 04:25:46 dillon Exp $
15 # block is the disk block size (best guess, need not be exact)
17 warn="(does not preserve modes and timestamp)"
18 tmp=`mktemp -d -t znew`
19 if test -z "$tmp"; then
20 echo znew: could not create temporary directory
25 if test -z "`(${CPMOD-cpmod} $tmp/1 $tmp/2) 2>&1`"; then
30 if test -z "$cpmod" && ${TOUCH-touch} -r $tmp/1 $tmp/2 2>/dev/null; then
31 cpmod="${TOUCH-touch}"
33 warn="(does not preserve file modes)"
36 # check if GZIP env. variable uses -S or --suffix
38 ext=`echo $tmp/1* | sed "s|$tmp/1||"`
40 if test -z "$ext"; then
41 echo znew: error determining gzip extension
44 if test "$ext" = ".Z"; then
45 echo znew: cannot use .Z as gzip extension.
52 -*) opt="$opt $arg"; shift;;
57 if test $# -eq 0; then
58 echo "recompress .Z files into $ext (gzip) files"
59 echo usage: `echo $0 | sed 's,^.*/,,'` "[-tv9KP]" file.Z...
60 echo " -t tests the new files before deleting originals"
62 echo " -9 use the slowest compression method (optimal compression)"
63 echo " -K keep a .Z file when it is smaller than the $ext file"
64 echo " -P use pipes for the conversion $warn"
68 opt=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
70 *t*) check=1; opt=`echo "$opt" | sed 's/t//g'`
73 *K*) keep=1; opt=`echo "$opt" | sed 's/K//g'`
76 *P*) pipe=1; opt=`echo "$opt" | sed 's/P//g'`
78 if test -n "$opt"; then
83 n=`echo $i | sed 's/.Z$//'`
84 if test ! -f "$n.Z" ; then
88 test $keep -eq 1 && old=`wc -c < "$n.Z"`
89 if test $pipe -eq 1; then
90 if gzip -d < "$n.Z" | gzip $opt > "$n$ext"; then
91 # Copy file attributes from old file to new one, if possible.
92 test -n "$cpmod" && $cpmod $cpmodarg "$n.Z" "$n$ext" 2> /dev/null
94 echo error while recompressing $n.Z
98 if test $check -eq 1; then
99 if cp -p "$n.Z" "$n.$$" 2> /dev/null || cp "$n.Z" "$n.$$"; then
102 echo cannot backup "$n.Z"
106 if gzip -d "$n.Z"; then
109 test $check -eq 1 && mv "$n.$$" "$n.Z"
110 echo error while uncompressing $n.Z
113 if gzip $opt "$n"; then
116 if test $check -eq 1; then
117 mv "$n.$$" "$n.Z" && rm -f "$n"
118 echo error while recompressing $n
120 # compress $n (might be dangerous if disk full)
121 echo error while recompressing $n, left uncompressed
126 test $keep -eq 1 && new=`wc -c < "$n$ext"`
127 if test $keep -eq 1 -a `expr \( $old + $block - 1 \) / $block` -lt \
128 `expr \( $new + $block - 1 \) / $block`; then
129 if test $pipe -eq 1; then
131 elif test $check -eq 1; then
132 mv "$n.$$" "$n.Z" && rm -f "$n$ext"
134 gzip -d "$n$ext" && compress "$n" && rm -f "$n$ext"
136 echo "$n.Z smaller than $n$ext -- unchanged"
138 elif test $check -eq 1; then
139 if gzip -t "$n$ext" ; then
142 test $pipe -eq 0 && mv "$n.$$" "$n.Z"
144 echo error while testing $n$ext, $n.Z unchanged
147 elif test $pipe -eq 1; then