3 # Copyright (C) 1998, 2002, 2004, 2007, 2010-2024 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.
24 version
="znew (gzip) @VERSION@
25 Copyright (C) 2024 Free Software Foundation, Inc.
26 This is free software. You may redistribute copies of it under the terms of
27 the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.
28 There is NO WARRANTY, to the extent permitted by law.
30 Written by Jean-loup Gailly."
32 usage
="Usage: $0 [OPTION]... [FILE]...
33 Recompress files from .Z (compress) format to .gz (gzip) format.
37 -f Force recompression even if a .gz file already exists.
38 -t Test the new files before deleting originals.
39 -v Verbose; display name and statistics for each file compressed.
40 -9 Use the slowest compression method (optimal compression).
41 -P Use pipes for the conversion to reduce disk space usage.
42 -K Keep a .Z file when it is smaller than the .gz file; implies -t.
43 --help display this help and exit
44 --version output version information and exit
46 Report bugs to <bug-gzip@gnu.org>."
57 # block is the disk block size (best guess, need not be exact)
59 # Beware -s or --suffix in $GZIP.
66 --help) printf '%s\n' "$usage" ||
exit 1; exit;;
67 --version) printf '%s\n' "$version" ||
exit 1; exit;;
68 -*) opt
="$opt $arg"; shift;;
73 if test $# -eq 0; then
74 echo >&2 "$0: invalid number of operands; try \`$0 --help' for help"
78 opt
=`printf '%s\n' "$opt" | sed -e 's/ //g' -e 's/-//g'`
80 *t
*) check
=1; opt
=`printf '%s\n' "$opt" | sed 's/t//g'`
83 *K
*) keep
=1; check
=1; opt
=`printf '%s\n' "$opt" | sed 's/K//g'`
86 *P
*) pipe
=1; opt
=`printf '%s\n' "$opt" | sed 's/P//g'`
88 if test -n "$opt"; then
93 n
=`printf '%s\n' "$i" | sed 's/.Z$//'`
94 if test ! -f "$n.Z" ; then
95 printf '%s\n' "$n.Z not found"
98 test $keep -eq 1 && old
=`wc -c < "$n.Z"`
99 if test $pipe -eq 1; then
100 if 'gzip' -d < "$n.Z" |
'gzip' $opt > "$n$ext"; then
101 # Copy file attributes from old file to new one, if possible.
102 touch -r"$n.Z" -- "$n$ext" 2>/dev
/null
103 chmod --reference="$n.Z" -- "$n$ext" 2>/dev
/null
105 printf '%s\n' "error while recompressing $n.Z"
109 if test $check -eq 1; then
110 if cp -p "$n.Z" "$n.$$"; then
113 printf '%s\n' "cannot backup $n.Z"
117 if 'gzip' -d "$n.Z"; then
120 test $check -eq 1 && mv "$n.$$" "$n.Z"
121 printf '%s\n' "error while uncompressing $n.Z"
124 if 'gzip' $opt "$n"; then
127 if test $check -eq 1; then
128 mv "$n.$$" "$n.Z" && rm -f "$n"
129 printf '%s\n' "error while recompressing $n"
131 # compress $n (might be dangerous if disk full)
132 printf '%s\n' "error while recompressing $n, left uncompressed"
137 test $keep -eq 1 && new
=`wc -c < "$n$ext"`
138 if test $keep -eq 1 && test `expr \( $old + $block - 1 \) / $block` -lt \
139 `expr \( $new + $block - 1 \) / $block`; then
140 if test $pipe -eq 1; then
143 mv "$n.$$" "$n.Z" && rm -f "$n$ext"
145 printf '%s\n' "$n.Z smaller than $n$ext -- unchanged"
147 elif test $check -eq 1; then
148 if 'gzip' -t "$n$ext" ; then
151 test $pipe -eq 0 && mv "$n.$$" "$n.Z"
153 printf '%s\n' "error while testing $n$ext, $n.Z unchanged"
156 elif test $pipe -eq 1; then