3 # Copyright (C) 1998, 2002, 2004, 2007, 2010-2022 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 3 of the License, or
10 # (at your option) any later version.
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 along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 version
="znew (gzip) @VERSION@
22 Copyright (C) 2010-2018 Free Software Foundation, Inc.
23 This is free software. You may redistribute copies of it under the terms of
24 the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.
25 There is NO WARRANTY, to the extent permitted by law.
27 Written by Jean-loup Gailly."
29 usage
="Usage: $0 [OPTION]... [FILE]...
30 Recompress files from .Z (compress) format to .gz (gzip) format.
34 -f Force recompression even if a .gz file already exists.
35 -t Test the new files before deleting originals.
36 -v Verbose; display name and statistics for each file compressed.
37 -9 Use the slowest compression method (optimal compression).
38 -P Use pipes for the conversion to reduce disk space usage.
39 -K Keep a .Z file when it is smaller than the .gz file; implies -t.
40 --help display this help and exit
41 --version output version information and exit
43 Report bugs to <bug-gzip@gnu.org>."
54 # block is the disk block size (best guess, need not be exact)
56 # Beware -s or --suffix in $GZIP.
63 --help) printf '%s\n' "$usage" ||
exit 1; exit;;
64 --version) printf '%s\n' "$version" ||
exit 1; exit;;
65 -*) opt
="$opt $arg"; shift;;
70 if test $# -eq 0; then
71 echo >&2 "$0: invalid number of operands; try \`$0 --help' for help"
75 opt
=`printf '%s\n' "$opt" | sed -e 's/ //g' -e 's/-//g'`
77 *t
*) check
=1; opt
=`printf '%s\n' "$opt" | sed 's/t//g'`
80 *K
*) keep
=1; check
=1; opt
=`printf '%s\n' "$opt" | sed 's/K//g'`
83 *P
*) pipe
=1; opt
=`printf '%s\n' "$opt" | sed 's/P//g'`
85 if test -n "$opt"; then
90 n
=`printf '%s\n' "$i" | sed 's/.Z$//'`
91 if test ! -f "$n.Z" ; then
92 printf '%s\n' "$n.Z not found"
95 test $keep -eq 1 && old
=`wc -c < "$n.Z"`
96 if test $pipe -eq 1; then
97 if gzip -d < "$n.Z" |
gzip $opt > "$n$ext"; then
98 # Copy file attributes from old file to new one, if possible.
99 touch -r"$n.Z" -- "$n$ext" 2>/dev
/null
100 chmod --reference="$n.Z" -- "$n$ext" 2>/dev
/null
102 printf '%s\n' "error while recompressing $n.Z"
106 if test $check -eq 1; then
107 if cp -p "$n.Z" "$n.$$"; then
110 printf '%s\n' "cannot backup $n.Z"
114 if gzip -d "$n.Z"; then
117 test $check -eq 1 && mv "$n.$$" "$n.Z"
118 printf '%s\n' "error while uncompressing $n.Z"
121 if gzip $opt "$n"; then
124 if test $check -eq 1; then
125 mv "$n.$$" "$n.Z" && rm -f "$n"
126 printf '%s\n' "error while recompressing $n"
128 # compress $n (might be dangerous if disk full)
129 printf '%s\n' "error while recompressing $n, left uncompressed"
134 test $keep -eq 1 && new
=`wc -c < "$n$ext"`
135 if test $keep -eq 1 && test `expr \( $old + $block - 1 \) / $block` -lt \
136 `expr \( $new + $block - 1 \) / $block`; then
137 if test $pipe -eq 1; then
140 mv "$n.$$" "$n.Z" && rm -f "$n$ext"
142 printf '%s\n' "$n.Z smaller than $n$ext -- unchanged"
144 elif test $check -eq 1; then
145 if gzip -t "$n$ext" ; then
148 test $pipe -eq 0 && mv "$n.$$" "$n.Z"
150 printf '%s\n' "error while testing $n$ext, $n.Z unchanged"
153 elif test $pipe -eq 1; then