3 # Copyright (C) 1998, 2002, 2004, 2007, 2010 Free Software Foundation
4 # Copyright (C) 1993 Jean-loup Gailly
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 --__bindir) bindir=${2?}; shift; shift;;
24 PATH=$bindir:$PATH; export PATH
26 version="znew (gzip) @VERSION@
27 Copyright (C) 2010-2014 Free Software Foundation, Inc.
28 This is free software. You may redistribute copies of it under the terms of
29 the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
30 There is NO WARRANTY, to the extent permitted by law.
32 Written by Jean-loup Gailly."
34 usage="Usage: $0 [OPTION]... [FILE]...
35 Recompress files from .Z (compress) format to .gz (gzip) format.
39 -f Force recompression even if a .gz file already exists.
40 -t Test the new files before deleting originals.
41 -v Verbose; display name and statistics for each file compressed.
42 -9 Use the slowest compression method (optimal compression).
43 -P Use pipes for the conversion to reduce disk space usage.
44 -K Keep a .Z file when it is smaller than the .gz file; implies -t.
45 --help display this help and exit
46 --version output version information and exit
48 Report bugs to <bug-gzip@gnu.org>."
59 # block is the disk block size (best guess, need not be exact)
61 # Beware -s or --suffix in $GZIP.
68 --help) exec echo "$usage";;
69 --version) exec echo "$version";;
70 -*) opt="$opt $arg"; shift;;
75 if test $# -eq 0; then
76 echo >&2 "$0: invalid number of operands; try \`$0 --help' for help"
80 opt=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'`
82 *t*) check=1; opt=`echo "$opt" | sed 's/t//g'`
85 *K*) keep=1; check=1; opt=`echo "$opt" | sed 's/K//g'`
88 *P*) pipe=1; opt=`echo "$opt" | sed 's/P//g'`
90 if test -n "$opt"; then
95 n=`echo "$i" | sed 's/.Z$//'`
96 if test ! -f "$n.Z" ; then
100 test $keep -eq 1 && old=`wc -c < "$n.Z"`
101 if test $pipe -eq 1; then
102 if gzip -d < "$n.Z" | gzip $opt > "$n$ext"; then
103 # Copy file attributes from old file to new one, if possible.
104 touch -r"$n.Z" -- "$n$ext" 2>/dev/null
105 chmod --reference="$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.$$"; 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
145 mv "$n.$$" "$n.Z" && rm -f "$n$ext"
147 echo "$n.Z smaller than $n$ext -- unchanged"
149 elif test $check -eq 1; then
150 if gzip -t "$n$ext" ; then
153 test $pipe -eq 0 && mv "$n.$$" "$n.Z"
155 echo "error while testing $n$ext, $n.Z unchanged"
158 elif test $pipe -eq 1; then