Replace the GNU gzip with a slightly modified NetBSD gzip. The
NetBSD version is a feature-to-feature re-implementation of GNU gzip using the freely-redistributable zlib and this version is expected to be mostly bug-to-bug compatible with the GNU implementation. - Because this is a piece of mature code and we want to make changes so it is added directly rather than importing to src/contrib. - Connect newly added code to src/usr.bin/ and rescue/rescue build. - Disconnect the GNU gzip code from build for now, they will be eventually removed completely. - Provide two new src.conf(5) knobs, WITHOUT_BZIP2_SUPPORT and WITHOUT_BZIP2. Tested by: kris (full exp-7 pointyhat build) Approved by: core (importing a 4-clause BSD licensed file) Approved by: re (adding new utility during -HEAD code slush)
This commit is contained in:
parent
5e40eb222d
commit
2089860135
@ -15,7 +15,6 @@ SUBDIR= bc \
|
||||
${_gperf} \
|
||||
grep \
|
||||
${_groff} \
|
||||
gzip \
|
||||
${_man} \
|
||||
patch \
|
||||
${_rcs} \
|
||||
|
@ -187,9 +187,8 @@ CRUNCH_BUILDOPTS_dhclient= -DRELEASE_CRUNCH -Dlint
|
||||
# Programs from stock /usr/bin
|
||||
#
|
||||
CRUNCH_SRCDIRS+= usr.bin
|
||||
CRUNCH_SRCDIRS+= gnu/usr.bin
|
||||
|
||||
CRUNCH_PROGS_gnu/usr.bin+= gzip
|
||||
CRUNCH_PROGS_usr.bin+= gzip
|
||||
CRUNCH_ALIAS_gzip= gunzip gzcat zcat
|
||||
|
||||
CRUNCH_PROGS_usr.bin+= bzip2
|
||||
|
@ -297,6 +297,7 @@ WITH_IDEA=
|
||||
BIND_UTILS \
|
||||
BLUETOOTH \
|
||||
BOOT \
|
||||
BZIP2 \
|
||||
CALENDAR \
|
||||
CDDL \
|
||||
CPP \
|
||||
@ -434,6 +435,7 @@ MK_GDB:= no
|
||||
# MK_* variable is set to "no".
|
||||
#
|
||||
.for var in \
|
||||
BZIP2 \
|
||||
GNU \
|
||||
INET6 \
|
||||
IPX \
|
||||
|
3
tools/build/options/WITHOUT_BZIP2
Normal file
3
tools/build/options/WITHOUT_BZIP2
Normal file
@ -0,0 +1,3 @@
|
||||
.\" $FreeBSD$
|
||||
Set to not build contributed bzip2 software as a part of the base system.
|
||||
.Sy "The option has no effect yet."
|
2
tools/build/options/WITHOUT_BZIP2_SUPPORT
Normal file
2
tools/build/options/WITHOUT_BZIP2_SUPPORT
Normal file
@ -0,0 +1,2 @@
|
||||
.\" $FreeBSD$
|
||||
Set to build some programs without optional bzip2 support.
|
@ -75,6 +75,7 @@ SUBDIR= alias \
|
||||
getent \
|
||||
getopt \
|
||||
${_gprof} \
|
||||
gzip \
|
||||
head \
|
||||
${_hesinfo} \
|
||||
hexdump \
|
||||
|
36
usr.bin/gzip/Makefile
Normal file
36
usr.bin/gzip/Makefile
Normal file
@ -0,0 +1,36 @@
|
||||
# $NetBSD: Makefile,v 1.10 2006/05/12 02:01:15 mrg Exp $
|
||||
# $FreeBSD$
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
PROG= gzip
|
||||
MAN= gzip.1 gzexe.1 zdiff.1 zforce.1 zgrep.1 zmore.1 znew.1
|
||||
|
||||
DPADD= ${LIBZ}
|
||||
LDADD= -lz
|
||||
WARNS?= 6
|
||||
|
||||
.if ${MK_BZIP2_SUPPORT} != "no"
|
||||
DPADD+= ${LIBBZ2}
|
||||
LDADD+= -lbz2
|
||||
.else
|
||||
CFLAGS+= -DNO_BZIP2_SUPPORT
|
||||
.endif
|
||||
|
||||
SCRIPTS= gzexe zdiff zforce zgrep zmore znew
|
||||
|
||||
MLINKS+= gzip.1 gunzip.1 \
|
||||
gzip.1 gzcat.1 \
|
||||
gzip.1 zcat.1 \
|
||||
zdiff.1 zcmp.1 \
|
||||
zgrep.1 zegrep.1 \
|
||||
zgrep.1 zfgrep.1
|
||||
|
||||
LINKS+= ${BINDIR}/gzip ${BINDIR}/gunzip \
|
||||
${BINDIR}/gzip ${BINDIR}/gzcat \
|
||||
${BINDIR}/gzip ${BINDIR}/zcat \
|
||||
${BINDIR}/zdiff ${BINDIR}/zcmp \
|
||||
${BINDIR}/zgrep ${BINDIR}/zegrep \
|
||||
${BINDIR}/zgrep ${BINDIR}/zfgrep
|
||||
|
||||
.include <bsd.prog.mk>
|
179
usr.bin/gzip/gzexe
Normal file
179
usr.bin/gzip/gzexe
Normal file
@ -0,0 +1,179 @@
|
||||
#!/bin/sh -
|
||||
#
|
||||
# $NetBSD: gzexe,v 1.3 2004/05/01 08:22:41 wiz Exp $
|
||||
# $OpenBSD: gzexe,v 1.3 2003/08/05 18:22:17 deraadt Exp $
|
||||
#
|
||||
#-
|
||||
# Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
#
|
||||
# $FreeBSD$
|
||||
|
||||
# The number of lines plus one in the on-the-fly decompression script
|
||||
lines=19
|
||||
|
||||
# A simple string to recognize already compressed files
|
||||
magic="# compressed by gzexe"
|
||||
|
||||
# Write the decompression script to stdout
|
||||
header () {
|
||||
# first section needs variable expansion, second not
|
||||
cat <<- EOF
|
||||
#!/bin/sh -
|
||||
$magic
|
||||
lines=$lines
|
||||
EOF
|
||||
cat <<- 'EOF'
|
||||
prog=`/usr/bin/basename "$0"`
|
||||
tmp=`/usr/bin/mktemp -d /tmp/gzexeXXXXXXXXXX` || {
|
||||
/bin/echo "$prog: cannot create tmp dir"; exit 1
|
||||
}
|
||||
trap '/bin/rm -rf "$tmp"' 0
|
||||
if /usr/bin/tail +$lines "$0" |
|
||||
/usr/bin/gzip -dc > "$tmp/$prog" 2> /dev/null; then
|
||||
/bin/chmod u+x "$tmp/$prog"
|
||||
"$tmp/$prog" ${1+"$@"}
|
||||
ret=$?
|
||||
else
|
||||
/bin/echo "$prog: cannot decompress $0"
|
||||
ret=1
|
||||
fi
|
||||
exit $ret
|
||||
EOF
|
||||
}
|
||||
|
||||
# Test if a file is compressed by checking the magic line
|
||||
compressed () {
|
||||
test "X`sed -n 2p "$1" 2> /dev/null`" = "X$magic"
|
||||
}
|
||||
|
||||
# Decompress a file
|
||||
decompress () {
|
||||
tmp=`mktemp /tmp/gzexeXXXXXXXXXX` || {
|
||||
echo "$prog: cannot create tmp file"
|
||||
return 1
|
||||
}
|
||||
if ! cp "$1" "$tmp"; then
|
||||
echo "$prog: cannot copy $1 to $tmp"
|
||||
rm -f "$tmp"
|
||||
return 1
|
||||
fi
|
||||
if ! tail +$lines "$tmp" | gzip -vdc > "$1"; then
|
||||
echo "$prog: cannot decompress $1"
|
||||
cp "$tmp" "$1"
|
||||
rm -f "$tmp"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Perform some sanity checks on the file
|
||||
check () {
|
||||
if test ! -e "$1"; then
|
||||
echo "$prog: cannot compress non-existing file $1"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if test ! -f "$1"; then
|
||||
echo "$prog: cannot compress non-regular file $1"
|
||||
return 1
|
||||
fi
|
||||
|
||||
case `basename "$1"` in
|
||||
sh | mktemp | rm | echo | tail | gzip | chmod)
|
||||
echo "$prog: cannot compress $1, I depend on it"
|
||||
return 1
|
||||
esac
|
||||
|
||||
if test ! -x "$1"; then
|
||||
echo "$prog: cannot compress $1, it is not executable"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if test -u "$1" -o -g "$1"; then
|
||||
echo "$prog: cannot compress $1, it has an s bit set"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Compress a file
|
||||
compress () {
|
||||
tmp=`mktemp /tmp/gzexeXXXXXXXXXX` || {
|
||||
echo "$prog: cannot create tmp file"
|
||||
return 1
|
||||
}
|
||||
if ! cp "$1" "$tmp"; then
|
||||
echo "$prog: cannot copy $1 to $tmp"
|
||||
rm -f "$tmp"
|
||||
return 1
|
||||
fi
|
||||
if ! cp "$1" "$1"~; then
|
||||
echo "$prog: cannot create backup copy $1~"
|
||||
rm -f "$1"~ "$tmp"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Use cp to overwrite the existing file preserving mode and owner
|
||||
# if possible. If the file is not writable, this will produce an
|
||||
# error.
|
||||
|
||||
if header "$1" > "$tmp" && gzip -vc "$1" >> "$tmp"; then
|
||||
if ! cp "$tmp" "$1"; then
|
||||
echo "$prog: cannot copy $tmp to $1"
|
||||
rm -f "$tmp"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
echo "$prog: cannot compress $1"
|
||||
rm -f "$1"~ "$tmp"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Is the -d flag specified?
|
||||
dflag=
|
||||
|
||||
# Return value
|
||||
rc=0
|
||||
|
||||
if test "X$1" = X-d; then
|
||||
dflag=1
|
||||
shift
|
||||
fi
|
||||
|
||||
prog=`basename "$0"`
|
||||
USAGE="usage: $prog [-d] file ..."
|
||||
if test $# -eq 0; then
|
||||
echo $USAGE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
while test $# -ne 0; do
|
||||
if test $dflag; then
|
||||
if ! compressed "$1"; then
|
||||
echo "$prog: $1 is not compressed"
|
||||
rc=1;
|
||||
elif ! decompress "$1"; then
|
||||
rc=$?
|
||||
fi
|
||||
else
|
||||
if compressed "$1"; then
|
||||
echo "$prog: $1 is already compressed"
|
||||
rc=1;
|
||||
elif ! check "$1" || ! compress "$1"; then
|
||||
rc=$?
|
||||
fi
|
||||
fi
|
||||
shift
|
||||
done
|
||||
exit $rc
|
73
usr.bin/gzip/gzexe.1
Normal file
73
usr.bin/gzip/gzexe.1
Normal file
@ -0,0 +1,73 @@
|
||||
.\" $NetBSD: gzexe.1,v 1.3 2003/12/28 12:49:41 wiz Exp $
|
||||
.\" $OpenBSD: gzexe.1,v 1.1 2003/07/31 07:32:47 otto Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
||||
.\"
|
||||
.\" Permission to use, copy, modify, and distribute this software for any
|
||||
.\" purpose with or without fee is hereby granted, provided that the above
|
||||
.\" copyright notice and this permission notice appear in all copies.
|
||||
.\"
|
||||
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.Dd January 26, 2007
|
||||
.Dt GZEXE 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm gzexe
|
||||
.Nd create auto-decompressing executables
|
||||
.Sh SYNOPSIS
|
||||
.Nm gzexe
|
||||
.Op Fl d
|
||||
.Ar
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility uses
|
||||
.Xr gzip 1
|
||||
to compress executables, producing executables that decompress on-the-fly
|
||||
when executed.
|
||||
This saves disk space, at the cost of slower execution times.
|
||||
The original executables are saved by copying each of them to a file with
|
||||
the same name with a
|
||||
.Sq ~
|
||||
suffix appended.
|
||||
After verifying that the compressed executables work as expected, the backup
|
||||
files can be removed.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width Ds
|
||||
.It Fl d
|
||||
Decompress executables previously compressed by
|
||||
.Nm .
|
||||
.El
|
||||
.Pp
|
||||
The
|
||||
.Nm
|
||||
program refuses to compress non-regular or non-executable files,
|
||||
files with a setuid or setgid bit set, files that are already
|
||||
compressed using
|
||||
.Nm
|
||||
or programs it needs to perform on-the-fly decompression:
|
||||
.Xr sh 1 ,
|
||||
.Xr mktemp 1 ,
|
||||
.Xr rm 1 ,
|
||||
.Xr echo 1 ,
|
||||
.Xr tail 1 ,
|
||||
.Xr gzip 1 ,
|
||||
and
|
||||
.Xr chmod 1 .
|
||||
.Sh SEE ALSO
|
||||
.Xr gzip 1
|
||||
.Sh CAVEATS
|
||||
The
|
||||
.Nm
|
||||
utility replaces files by overwriting them with the generated
|
||||
compressed executable.
|
||||
To be able to do this, it is required that the original files are writable.
|
202
usr.bin/gzip/gzip.1
Normal file
202
usr.bin/gzip/gzip.1
Normal file
@ -0,0 +1,202 @@
|
||||
.\" $NetBSD: gzip.1,v 1.18 2005/09/30 13:46:56 wiz Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1997, 2003, 2004 Matthew R. Green
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. The name of the author may not be used to endorse or promote products
|
||||
.\" derived from this software without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.Dd January 26, 2007
|
||||
.Dt GZIP 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm gzip
|
||||
.Nd compression/decompression tool using Lempel-Ziv coding (LZ77)
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl cdfhLlNnqrtVv
|
||||
.Op Fl S Ar suffix
|
||||
.Ar file
|
||||
.Oo
|
||||
.Ar file Oo ...
|
||||
.Oc
|
||||
.Oc
|
||||
.Nm gunzip
|
||||
.Op Fl cfhLNqrtVv
|
||||
.Op Fl S Ar suffix
|
||||
.Ar file
|
||||
.Oo
|
||||
.Ar file Oo ...
|
||||
.Oc
|
||||
.Oc
|
||||
.Nm zcat
|
||||
.Op Fl fhV
|
||||
.Ar file
|
||||
.Oo
|
||||
.Ar file Oo ...
|
||||
.Oc
|
||||
.Oc
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
program compresses and decompresses files using Lempel-Ziv coding
|
||||
(LZ77).
|
||||
If no
|
||||
.Ar files
|
||||
are specified,
|
||||
.Nm
|
||||
will compress from standard input, or decompress to standard output.
|
||||
When in compression mode, each
|
||||
.Ar file
|
||||
will be replaced with another file with the suffix, set by the
|
||||
.Fl S Ar suffix
|
||||
option, added, if possible.
|
||||
In decompression mode, each
|
||||
.Ar file
|
||||
will be checked for existence, as will the file with the suffix
|
||||
added.
|
||||
.Pp
|
||||
If invoked as
|
||||
.Nm gunzip
|
||||
then the
|
||||
.Fl d
|
||||
option is enabled.
|
||||
If invoked as
|
||||
.Nm zcat
|
||||
or
|
||||
.Nm gzcat
|
||||
then both the
|
||||
.Fl c
|
||||
and
|
||||
.Fl d
|
||||
options are enabled.
|
||||
.Pp
|
||||
This version of
|
||||
.Nm
|
||||
is also capable of decompressing files compressed using
|
||||
.Xr compress 1
|
||||
or
|
||||
.Xr bzip2 1 .
|
||||
.Sh OPTIONS
|
||||
The following options are available:
|
||||
.Bl -tag -width XXrXXXrecursiveX
|
||||
.It Fl 1 , -fast
|
||||
.It Fl 2 , 3 , 4 , 5 , 6 , 7 , 8
|
||||
.It Fl 9 , -best
|
||||
These options change the compression level used, with the
|
||||
.Fl 1
|
||||
option being the fastest, with less compression, and the
|
||||
.Fl 9
|
||||
option being the slowest, with optimal compression.
|
||||
The default compression level is 6.
|
||||
.It Fl c , -stdout , -to-stdout
|
||||
This option specifies that output will go to the standard output
|
||||
stream, leaving files intact.
|
||||
.It Fl d , -decompress , -uncompress
|
||||
This option selects decompression rather than compression.
|
||||
.It Fl f , -force
|
||||
This option turns on force mode.
|
||||
This allows files with multiple links, overwriting of pre-existing
|
||||
files, reading from or writing to a terminal, and when combined
|
||||
with the
|
||||
.Fl c
|
||||
option, allowing non-compressed data to pass through unchanged.
|
||||
.It Fl h , -help
|
||||
This option prints a usage summary and exits.
|
||||
.It Fl L , -license
|
||||
This option prints
|
||||
.Nm
|
||||
license.
|
||||
.It Fl l , -list
|
||||
This option displays information about the file's compressed and
|
||||
uncompressed size, ratio, uncompressed name.
|
||||
With the
|
||||
.Fl v
|
||||
option, it also displays the compression method, CRC, date and time
|
||||
embedded in the file.
|
||||
.It Fl N , -name
|
||||
This option causes the stored filename in the input file to be used
|
||||
as the output file.
|
||||
.It Fl n , -no-name
|
||||
This option stops the filename from being stored in the output
|
||||
file.
|
||||
.It Fl q , -quiet
|
||||
With this option, no warnings or errors are printed.
|
||||
.It Fl r , -recursive
|
||||
This option is used to
|
||||
.Nm
|
||||
the files in a directory tree individually, using the
|
||||
.Xr fts 3
|
||||
library.
|
||||
.It Fl S Ar suffix , Fl -suffix Ar suffix
|
||||
This option changes the default suffix from .gz to
|
||||
.Ar suffix .
|
||||
.It Fl t , -test
|
||||
This option will test compressed files for integrity.
|
||||
.It Fl V , -version
|
||||
This option prints the version of the
|
||||
.Nm
|
||||
program.
|
||||
.It Fl v , -verbose
|
||||
This option turns on verbose mode, which prints the compression
|
||||
ratio for each file compressed.
|
||||
.El
|
||||
.Sh ENVIRONMENT
|
||||
If the environment variable
|
||||
.Ev GZIP
|
||||
is set, it is parsed as a white-space separated list of options
|
||||
handled before any options on the command line.
|
||||
Options on the command line will override anything in
|
||||
.Ev GZIP .
|
||||
.Sh SEE ALSO
|
||||
.Xr bzip2 1 ,
|
||||
.Xr compress 1 ,
|
||||
.Xr fts 3 ,
|
||||
.Xr zlib 3
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
program was originally written by Jean-loup Gailly, licensed under
|
||||
the GNU Public Licence.
|
||||
Matthew R. Green wrote a simple front end for
|
||||
.Nx 1.3
|
||||
distribution media, based on the freely re-distributable zlib library.
|
||||
It was enhanced to be mostly feature-compatible with the original
|
||||
GNU
|
||||
.Nm
|
||||
program for
|
||||
.Nx 2.0 .
|
||||
.Pp
|
||||
This implementation of
|
||||
.Nm
|
||||
was ported based on the
|
||||
.Nx
|
||||
.Nm
|
||||
20060927, and first appeared in
|
||||
.Fx 7.0 .
|
||||
.Sh AUTHORS
|
||||
This implementation of
|
||||
.Nm
|
||||
was written by
|
||||
.An Matthew R. Green Aq mrg@eterna.com.au .
|
2054
usr.bin/gzip/gzip.c
Normal file
2054
usr.bin/gzip/gzip.c
Normal file
File diff suppressed because it is too large
Load Diff
128
usr.bin/gzip/unbzip2.c
Normal file
128
usr.bin/gzip/unbzip2.c
Normal file
@ -0,0 +1,128 @@
|
||||
/* $NetBSD: unbzip2.c,v 1.10 2006/10/03 08:20:03 simonb Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Simon Burge.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/* This file is #included by gzip.c */
|
||||
|
||||
static off_t
|
||||
unbzip2(int in, int out, char *pre, size_t prelen, off_t *bytes_in)
|
||||
{
|
||||
int ret, end_of_file;
|
||||
off_t bytes_out = 0;
|
||||
bz_stream bzs;
|
||||
static char *inbuf, *outbuf;
|
||||
|
||||
if (inbuf == NULL)
|
||||
inbuf = malloc(BUFLEN);
|
||||
if (outbuf == NULL)
|
||||
outbuf = malloc(BUFLEN);
|
||||
if (inbuf == NULL || outbuf == NULL)
|
||||
maybe_err("malloc");
|
||||
|
||||
bzs.bzalloc = NULL;
|
||||
bzs.bzfree = NULL;
|
||||
bzs.opaque = NULL;
|
||||
|
||||
end_of_file = 0;
|
||||
ret = BZ2_bzDecompressInit(&bzs, 0, 0);
|
||||
if (ret != BZ_OK)
|
||||
maybe_errx("bzip2 init");
|
||||
|
||||
/* Prepend. */
|
||||
bzs.avail_in = prelen;
|
||||
bzs.next_in = pre;
|
||||
|
||||
if (bytes_in)
|
||||
*bytes_in = prelen;
|
||||
|
||||
while (ret >= BZ_OK && ret != BZ_STREAM_END) {
|
||||
if (bzs.avail_in == 0 && !end_of_file) {
|
||||
ssize_t n;
|
||||
|
||||
n = read(in, inbuf, BUFLEN);
|
||||
if (n < 0)
|
||||
maybe_err("read");
|
||||
if (n == 0)
|
||||
end_of_file = 1;
|
||||
bzs.next_in = inbuf;
|
||||
bzs.avail_in = n;
|
||||
if (bytes_in)
|
||||
*bytes_in += n;
|
||||
}
|
||||
|
||||
bzs.next_out = outbuf;
|
||||
bzs.avail_out = BUFLEN;
|
||||
ret = BZ2_bzDecompress(&bzs);
|
||||
|
||||
switch (ret) {
|
||||
case BZ_STREAM_END:
|
||||
case BZ_OK:
|
||||
if (ret == BZ_OK && end_of_file)
|
||||
maybe_err("read");
|
||||
if (!tflag) {
|
||||
ssize_t n;
|
||||
|
||||
n = write(out, outbuf, BUFLEN - bzs.avail_out);
|
||||
if (n < 0)
|
||||
maybe_err("write");
|
||||
bytes_out += n;
|
||||
}
|
||||
break;
|
||||
|
||||
case BZ_DATA_ERROR:
|
||||
maybe_warnx("bzip2 data integrity error");
|
||||
break;
|
||||
|
||||
case BZ_DATA_ERROR_MAGIC:
|
||||
maybe_warnx("bzip2 magic number error");
|
||||
break;
|
||||
|
||||
case BZ_MEM_ERROR:
|
||||
maybe_warnx("bzip2 out of memory");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (ret != BZ_STREAM_END || BZ2_bzDecompressEnd(&bzs) != BZ_OK)
|
||||
return (-1);
|
||||
|
||||
return (bytes_out);
|
||||
}
|
||||
|
111
usr.bin/gzip/zdiff
Normal file
111
usr.bin/gzip/zdiff
Normal file
@ -0,0 +1,111 @@
|
||||
#!/bin/sh -
|
||||
#
|
||||
# $NetBSD: zdiff,v 1.3 2004/03/29 10:01:00 wiz Exp $
|
||||
# $OpenBSD: zdiff,v 1.2 2003/07/29 07:42:44 otto Exp $
|
||||
#
|
||||
#-
|
||||
# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
#
|
||||
# Sponsored in part by the Defense Advanced Research Projects
|
||||
# Agency (DARPA) and Air Force Research Laboratory, Air Force
|
||||
# Materiel Command, USAF, under agreement number F39502-99-1-0512.
|
||||
#
|
||||
# $FreeBSD$
|
||||
|
||||
# Set $prog based on $0
|
||||
case $0 in
|
||||
*cmp) prog=cmp
|
||||
;;
|
||||
*) prog=diff
|
||||
;;
|
||||
esac
|
||||
USAGE="usage: z$prog [options] file1 [file2]"
|
||||
|
||||
# Pull out any command line flags so we can pass them to diff/cmp
|
||||
# XXX - assumes there is no optarg
|
||||
flags=
|
||||
while test $# -ne 0; do
|
||||
case "$1" in
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
flags="$flags $1"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ $# -eq 1 ]; then
|
||||
# One file given, compare compressed to uncompressed
|
||||
files="$1"
|
||||
case "$1" in
|
||||
*[._-][Zz])
|
||||
files="${1%??}"
|
||||
;;
|
||||
*[._-]gz)
|
||||
files="${1%???}"
|
||||
;;
|
||||
*.t[ag]z)
|
||||
files="${1%??}"ar
|
||||
;;
|
||||
*) echo "z$prog: unknown suffix" 1>&2
|
||||
exit 1
|
||||
esac
|
||||
gzip -cdfq "$1" | $prog $flags - "$files"
|
||||
status=$?
|
||||
elif [ $# -eq 2 ]; then
|
||||
# Two files given, compare the two uncompressing as needed
|
||||
case "$1" in
|
||||
*[._-][Zz]|*[._-]gz|*.t[ag]z)
|
||||
files=-
|
||||
filt="gzip -cdfq $1"
|
||||
;;
|
||||
*)
|
||||
files="$1"
|
||||
;;
|
||||
esac
|
||||
case "$2" in
|
||||
*[._-][Zz]|*[._-]gz|*.t[ag]z)
|
||||
if [ "$files" = "-" ]; then
|
||||
tmp=`mktemp -t z$prog.XXXXXXXXXX` || exit 1
|
||||
trap "rm -f $tmp" 0 1 2 3 13 15
|
||||
gzip -cdfq "$2" > $tmp
|
||||
files="$files $tmp"
|
||||
else
|
||||
files="$files -"
|
||||
filt="gzip -cdfq $2"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
files="$files $2"
|
||||
;;
|
||||
esac
|
||||
if [ -n "$filt" ]; then
|
||||
$filt | $prog $flags $files
|
||||
else
|
||||
$prog $flags $files
|
||||
fi
|
||||
status=$?
|
||||
else
|
||||
echo "$USAGE" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit $status
|
109
usr.bin/gzip/zdiff.1
Normal file
109
usr.bin/gzip/zdiff.1
Normal file
@ -0,0 +1,109 @@
|
||||
.\" $NetBSD: zdiff.1,v 1.3 2003/12/28 12:48:03 wiz Exp $
|
||||
.\" $OpenBSD: zdiff.1,v 1.2 2003/07/13 17:39:14 millert Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
.\"
|
||||
.\" Permission to use, copy, modify, and distribute this software for any
|
||||
.\" purpose with or without fee is hereby granted, provided that the above
|
||||
.\" copyright notice and this permission notice appear in all copies.
|
||||
.\"
|
||||
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
.\"
|
||||
.\" Sponsored in part by the Defense Advanced Research Projects
|
||||
.\" Agency (DARPA) and Air Force Research Laboratory, Air Force
|
||||
.\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.Dd January 26, 2007
|
||||
.Dt ZDIFF 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm zcmp ,
|
||||
.Nm zdiff
|
||||
.Nd compare compressed files
|
||||
.Sh SYNOPSIS
|
||||
.Nm zcmp
|
||||
.Op Ar options
|
||||
.Ar file
|
||||
.Op Ar file2
|
||||
.Nm zdiff
|
||||
.Op Ar options
|
||||
.Ar file
|
||||
.Op Ar file2
|
||||
.Sh DESCRIPTION
|
||||
.Nm zcmp
|
||||
and
|
||||
.Nm zdiff
|
||||
are filters that invoke
|
||||
.Xr cmp 1
|
||||
or
|
||||
.Xr diff 1
|
||||
respectively to compare compressed files.
|
||||
Such files generally have a
|
||||
.Dq Z
|
||||
or
|
||||
.Dq gz
|
||||
extension (both the
|
||||
.Xr compress 1
|
||||
and
|
||||
.Xr gzip 1
|
||||
formats are supported).
|
||||
Any
|
||||
.Ar options
|
||||
that are specified are passed to
|
||||
.Xr cmp 1
|
||||
or
|
||||
.Xr diff 1 .
|
||||
.Pp
|
||||
If only
|
||||
.Ar file1
|
||||
is specified, it is compared against a file with the same name, but
|
||||
with the extension removed.
|
||||
When both
|
||||
.Ar file1
|
||||
or
|
||||
.Ar file2
|
||||
are specified, either file may be compressed.
|
||||
.Sh ENVIRONMENT
|
||||
.Bl -tag -width "TMPDIR"
|
||||
.It Ev TMPDIR
|
||||
Directory in which to place temporary files.
|
||||
If unset,
|
||||
.Pa /tmp
|
||||
is used.
|
||||
.El
|
||||
.Sh FILES
|
||||
.Bl -tag -width "/tmp/zdiff.XXXXXXXXXX" -compact
|
||||
.It Pa /tmp/zcmp.XXXXXXXXXX
|
||||
Temporary file for
|
||||
.Nm zcmp .
|
||||
.It Pa /tmp/zdiff.XXXXXXXXXX
|
||||
Temporary file for
|
||||
.Nm zdiff .
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr cmp 1 ,
|
||||
.Xr compress 1 ,
|
||||
.Xr diff 1
|
||||
.Sh CAVEATS
|
||||
.Nm zcmp
|
||||
and
|
||||
.Nm zdiff
|
||||
rely solely on the file extension to determine what is, or is not,
|
||||
a compressed file.
|
||||
Consequently, the following are not supported as arguments:
|
||||
.Bl -dash
|
||||
.It
|
||||
directories
|
||||
.It
|
||||
device special files
|
||||
.It
|
||||
filenames indicating the standard input
|
||||
.Pq Dq \-
|
||||
.El
|
55
usr.bin/gzip/zforce
Normal file
55
usr.bin/gzip/zforce
Normal file
@ -0,0 +1,55 @@
|
||||
#!/bin/sh -
|
||||
#
|
||||
# $NetBSD: zforce,v 1.2 2003/12/28 12:43:43 wiz Exp $
|
||||
# $OpenBSD: zforce,v 1.2 2003/08/05 18:22:17 deraadt Exp $
|
||||
#
|
||||
#-
|
||||
# Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
#
|
||||
# $FreeBSD$
|
||||
prog=`basename $0`
|
||||
USAGE="usage: $prog file ..."
|
||||
if test $# -eq 0; then
|
||||
echo $USAGE
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ret=0
|
||||
|
||||
while test $# -ne 0; do
|
||||
case "$1" in
|
||||
*[._-]gz)
|
||||
shift
|
||||
;;
|
||||
*.t[ag]z)
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
if file "$1" |
|
||||
grep -q "gzip compressed data" 2> /dev/null
|
||||
then
|
||||
n="$1".gz
|
||||
if mv "$1" "$n" 2> /dev/null; then
|
||||
echo "$1" -- renamed to "$n"
|
||||
else
|
||||
ret=1
|
||||
echo $prog: cannot rename "$1" to "$n"
|
||||
fi
|
||||
fi
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
exit $ret
|
53
usr.bin/gzip/zforce.1
Normal file
53
usr.bin/gzip/zforce.1
Normal file
@ -0,0 +1,53 @@
|
||||
.\" $NetBSD: zforce.1,v 1.2 2003/12/28 12:43:43 wiz Exp $
|
||||
.\" $OpenBSD: zforce.1,v 1.1 2003/07/29 11:50:09 otto Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
||||
.\"
|
||||
.\" Permission to use, copy, modify, and distribute this software for any
|
||||
.\" purpose with or without fee is hereby granted, provided that the above
|
||||
.\" copyright notice and this permission notice appear in all copies.
|
||||
.\"
|
||||
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.Dd January 26, 2007
|
||||
.Dt ZFORCE 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm zforce
|
||||
.Nd force gzip files to have a .gz suffix
|
||||
.Sh SYNOPSIS
|
||||
.Nm zforce
|
||||
.Ar
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility renames
|
||||
.Xr gzip 1
|
||||
files to have a
|
||||
.Sq .gz
|
||||
suffix, so that
|
||||
.Xr gzip 1
|
||||
will not compress them twice.
|
||||
This can be useful if file names were truncated during a file transfer.
|
||||
Files that have an existing
|
||||
.Sq .gz ,
|
||||
.Sq -gz ,
|
||||
.Sq _gz ,
|
||||
.Sq .tgz
|
||||
or
|
||||
.Sq .taz
|
||||
suffix, or that have not been compressed by
|
||||
.Xr gzip 1 ,
|
||||
are ignored.
|
||||
.Sh SEE ALSO
|
||||
.Xr gzip 1
|
||||
.Sh CAVEATS
|
||||
.Nm
|
||||
overwrites existing files without warning.
|
122
usr.bin/gzip/zgrep
Normal file
122
usr.bin/gzip/zgrep
Normal file
@ -0,0 +1,122 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# $NetBSD: zgrep,v 1.5 2006/05/03 16:48:29 yamt Exp $
|
||||
#
|
||||
# Copyright (c) 2003 Thomas Klausner.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# 3. The name of the author may not be used to endorse or promote products
|
||||
# derived from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# $FreeBSD$
|
||||
|
||||
grep=/usr/bin/grep
|
||||
zcat=/usr/bin/zcat
|
||||
|
||||
endofopts=0
|
||||
pattern_found=0
|
||||
grep_args=""
|
||||
hyphen=0
|
||||
|
||||
prg=$0
|
||||
|
||||
# handle being called 'zegrep' or 'zfgrep'
|
||||
case ${prg} in
|
||||
*zegrep)
|
||||
grep_args="-E";;
|
||||
*zfgrep)
|
||||
grep_args="-F";;
|
||||
esac
|
||||
|
||||
# skip all options and pass them on to grep taking care of options
|
||||
# with arguments, and if -e was supplied
|
||||
|
||||
while [ $# -gt 0 -a ${endofopts} -eq 0 ]
|
||||
do
|
||||
case $1 in
|
||||
# from GNU grep-2.5.1 -- keep in sync!
|
||||
-[ABCDXdefm])
|
||||
if [ $# -lt 2 ]
|
||||
then
|
||||
echo "${prg}: missing argument for $1 flag" >&2
|
||||
exit 1
|
||||
fi
|
||||
case $1 in
|
||||
-e)
|
||||
pattern="$2"
|
||||
pattern_found=1
|
||||
shift 2
|
||||
break
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
grep_args="${grep_args} $1 $2"
|
||||
shift 2
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
endofopts=1
|
||||
;;
|
||||
-)
|
||||
hyphen=1
|
||||
shift
|
||||
;;
|
||||
-*)
|
||||
grep_args="${grep_args} $1"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
# pattern to grep for
|
||||
endofopts=1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# if no -e option was found, take next argument as grep-pattern
|
||||
if [ ${pattern_found} -lt 1 ]
|
||||
then
|
||||
if [ $# -ge 1 ]; then
|
||||
pattern="$1"
|
||||
shift
|
||||
elif [ ${hyphen} -gt 0 ]; then
|
||||
pattern="-"
|
||||
else
|
||||
echo "${prg}: missing pattern" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# call grep ...
|
||||
if [ $# -lt 1 ]
|
||||
then
|
||||
# ... on stdin
|
||||
${zcat} -fq - | ${grep} ${grep_args} -- "${pattern}" -
|
||||
else
|
||||
# ... on all files given on the command line
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
${zcat} -fq -- "$1" | ${grep} -H --label="${1}" ${grep_args} -- "${pattern}" -
|
||||
shift
|
||||
done
|
||||
fi
|
||||
|
||||
exit 0
|
98
usr.bin/gzip/zgrep.1
Normal file
98
usr.bin/gzip/zgrep.1
Normal file
@ -0,0 +1,98 @@
|
||||
.\" $NetBSD: zgrep.1,v 1.2 2005/09/11 23:30:20 wiz Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2003 Thomas Klausner.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. The name of the author may not be used to endorse or promote products
|
||||
.\" derived from this software without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.Dd January 26, 2007
|
||||
.Dt ZGREP 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm zgrep ,
|
||||
.Nm zegrep ,
|
||||
.Nm zfgrep
|
||||
.Nd print lines matching a pattern in gzip-compressed files
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Ar grep-flags
|
||||
.Op Fl -
|
||||
.Ar pattern
|
||||
.Op Ar files ...
|
||||
.Pp
|
||||
.Nm zegrep
|
||||
.Op Ar grep-flags
|
||||
.Op Fl -
|
||||
.Ar pattern
|
||||
.Op Ar
|
||||
.Pp
|
||||
.Nm zfgrep
|
||||
.Op Ar grep-flags
|
||||
.Op Fl -
|
||||
.Ar pattern
|
||||
.Op Ar
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
runs
|
||||
.Xr grep 1
|
||||
on
|
||||
.Ar files
|
||||
or stdin, if no
|
||||
.Ar files
|
||||
argument is given, after decompressing them with
|
||||
.Xr zcat 1 .
|
||||
.Pp
|
||||
The
|
||||
.Ar grep-flags
|
||||
and
|
||||
.Ar pattern
|
||||
arguments are passed on to
|
||||
.Xr grep 1 .
|
||||
If an
|
||||
.Fl e
|
||||
flag is found in the
|
||||
.Ar grep-flags ,
|
||||
.Nm
|
||||
will not look for a
|
||||
.Ar pattern
|
||||
argument.
|
||||
.Pp
|
||||
.Nm zegrep
|
||||
calls
|
||||
.Xr egrep 1 ,
|
||||
while
|
||||
.Nm zfgrep
|
||||
calls
|
||||
.Xr fgrep 1 .
|
||||
.Sh EXIT STATUS
|
||||
In case of missing arguments or missing pattern,
|
||||
1 will be returned, otherwise 0.
|
||||
.Sh SEE ALSO
|
||||
.Xr egrep 1 ,
|
||||
.Xr fgrep 1 ,
|
||||
.Xr grep 1 ,
|
||||
.Xr gzip 1 ,
|
||||
.Xr zcat 1
|
||||
.Sh AUTHORS
|
||||
.An Thomas Klausner
|
||||
.Aq wiz@NetBSD.org
|
75
usr.bin/gzip/zmore
Normal file
75
usr.bin/gzip/zmore
Normal file
@ -0,0 +1,75 @@
|
||||
#!/bin/sh -
|
||||
#
|
||||
# $NetBSD: zmore,v 1.3 2004/03/29 09:59:42 wiz Exp $
|
||||
# $OpenBSD: zmore,v 1.4 2003/07/29 07:42:45 otto Exp $
|
||||
#
|
||||
#-
|
||||
# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
#
|
||||
# Sponsored in part by the Defense Advanced Research Projects
|
||||
# Agency (DARPA) and Air Force Research Laboratory, Air Force
|
||||
# Materiel Command, USAF, under agreement number F39502-99-1-0512.
|
||||
#
|
||||
# $FreeBSD$
|
||||
|
||||
# Pull out any command line flags so we can pass them to more/less
|
||||
flags=
|
||||
while test $# -ne 0; do
|
||||
case "$1" in
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
flags="$flags $1"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# No files means read from stdin
|
||||
if [ $# -eq 0 ]; then
|
||||
gzip -cdfq 2>&1 | ${PAGER-more} $flags
|
||||
exit 0
|
||||
fi
|
||||
|
||||
oterm=`stty -g 2>/dev/null`
|
||||
while test $# -ne 0; do
|
||||
gzip -cdfq "$1" 2>&1 | ${PAGER-more} $flags
|
||||
prev="$1"
|
||||
shift
|
||||
if tty -s && test -n "$oterm" -a $# -gt 0; then
|
||||
#echo -n "--More--(Next file: $1)"
|
||||
echo -n "$prev (END) - Next: $1 "
|
||||
trap "stty $oterm 2>/dev/null" 0 1 2 3 13 15
|
||||
stty cbreak -echo 2>/dev/null
|
||||
REPLY=`dd bs=1 count=1 2>/dev/null`
|
||||
stty $oterm 2>/dev/null
|
||||
trap - 0 1 2 3 13 15
|
||||
echo
|
||||
case "$REPLY" in
|
||||
s)
|
||||
shift
|
||||
;;
|
||||
e|q)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
exit 0
|
94
usr.bin/gzip/zmore.1
Normal file
94
usr.bin/gzip/zmore.1
Normal file
@ -0,0 +1,94 @@
|
||||
.\" $NetBSD: zmore.1,v 1.3 2003/12/28 12:47:52 wiz Exp $
|
||||
.\" $OpenBSD: zmore.1,v 1.3 2003/06/23 21:00:48 deraadt Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
.\"
|
||||
.\" Permission to use, copy, modify, and distribute this software for any
|
||||
.\" purpose with or without fee is hereby granted, provided that the above
|
||||
.\" copyright notice and this permission notice appear in all copies.
|
||||
.\"
|
||||
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
.\"
|
||||
.\" Sponsored in part by the Defense Advanced Research Projects
|
||||
.\" Agency (DARPA) and Air Force Research Laboratory, Air Force
|
||||
.\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.Dd January 26, 2007
|
||||
.Dt ZMORE 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm zmore
|
||||
.Nd view compressed files on a CRT
|
||||
.Sh SYNOPSIS
|
||||
.Nm zmore
|
||||
.Op Ar flags
|
||||
.Op Ar file ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
is a filter that allows the viewing of files compressed with Lempel-Ziv
|
||||
encoding.
|
||||
Such files generally have a
|
||||
.Dq Z
|
||||
or
|
||||
.Dq gz
|
||||
extension (both the
|
||||
.Xr compress 1
|
||||
and
|
||||
.Xr gzip 1
|
||||
formats are supported).
|
||||
Any
|
||||
.Ar flags
|
||||
that are specified are passed to the user's preferred
|
||||
.Ev PAGER
|
||||
(which is
|
||||
.Pa /usr/bin/more
|
||||
by default).
|
||||
.Pp
|
||||
When multiple files are specified,
|
||||
.Nm
|
||||
will pause at the end of each file and present the following prompt to the user:
|
||||
.Bd -literal -offset indent
|
||||
prev_file (END) - Next: next_file
|
||||
.Ed
|
||||
.Pp
|
||||
Where
|
||||
.Sy prev_file
|
||||
is the file that was just displayed and
|
||||
.Sy next_file
|
||||
is the next file to be displayed.
|
||||
The following keys are recognized at the prompt:
|
||||
.Bl -tag -width "e or q" -offset indent
|
||||
.It Ic e No or Ic q
|
||||
quit
|
||||
.Nm zmore .
|
||||
.It Ic s
|
||||
skip the next file (or exit if the next file is the last).
|
||||
.El
|
||||
.Pp
|
||||
If no files are specified,
|
||||
.Nm
|
||||
will read from the standard input.
|
||||
In this mode
|
||||
.Nm
|
||||
will assume
|
||||
.Xr gzip 1
|
||||
style compression since there is no suffix on which to make a decision.
|
||||
.Sh ENVIRONMENT
|
||||
.Bl -tag -width "PAGER"
|
||||
.It Ev PAGER
|
||||
Program used to display files.
|
||||
If unset,
|
||||
.Pa /usr/bin/more
|
||||
is used.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr compress 1 ,
|
||||
.Xr less 1 ,
|
||||
.Xr more 1
|
138
usr.bin/gzip/znew
Normal file
138
usr.bin/gzip/znew
Normal file
@ -0,0 +1,138 @@
|
||||
#!/bin/ksh -
|
||||
#
|
||||
# $NetBSD: znew,v 1.2 2003/12/28 12:43:43 wiz Exp $
|
||||
# $OpenBSD: znew,v 1.2 2003/08/05 18:22:17 deraadt Exp $
|
||||
#
|
||||
#-
|
||||
# Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
#
|
||||
# $FreeBSD$
|
||||
|
||||
# Return 0 if the first arg file size is smaller than the second, 1 otherwise.
|
||||
smaller () {
|
||||
a=`du -k "$1" | awk '{ print $1 }'`
|
||||
b=`du -k "$2" | awk '{ print $1 }'`
|
||||
test $a -lt $b
|
||||
}
|
||||
|
||||
# Check gzip integrity if the -t flag is specified
|
||||
checkfile () {
|
||||
if test $tflag -eq 1; then
|
||||
gzip -qt < "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
# Decompress a file and then gzip it
|
||||
process () {
|
||||
prefix="${1%.Z}"
|
||||
filez="$prefix".Z
|
||||
filegz="$prefix".gz
|
||||
|
||||
if test ! -e "$filez"; then
|
||||
echo "$prog: $filez does not exist"
|
||||
return 1
|
||||
fi
|
||||
if test ! -f "$filez"; then
|
||||
echo "$prog: $filez is not a regular file"
|
||||
return 1
|
||||
fi
|
||||
if test -e "$filegz" -a $fflag -eq 0; then
|
||||
echo "$prog: $filegz already exists"
|
||||
return 1
|
||||
fi
|
||||
|
||||
tmp=`mktemp /tmp/znewXXXXXXXXXX` || {
|
||||
echo "$prog: cannot create tmp file"
|
||||
return 1
|
||||
}
|
||||
trap 'rm -f "$tmp"; exit 1' HUP INT QUIT PIPE TERM
|
||||
|
||||
# Do the actual work, producing a file "$tmp"
|
||||
if uncompress -f -c < "$filez" | gzip -f $gzipflags -o "$tmp"; then
|
||||
|
||||
if test $kflag -eq 1 && smaller "$filez" "$tmp"; then
|
||||
echo -n "$prog: $filez is smaller than $filegz"
|
||||
echo "; keeping it"
|
||||
rm -f "$tmp"
|
||||
return 0
|
||||
fi
|
||||
if ! checkfile "$tmp"; then
|
||||
echo "$prog: integrity check of $tmp failed"
|
||||
rm -f "$tmp"
|
||||
return 1;
|
||||
fi
|
||||
|
||||
# Try to keep the mode of the original file
|
||||
if ! cp -fp "$filez" "$filegz"; then
|
||||
echo "$prog: warning: could not keep mode of $filez"
|
||||
fi
|
||||
if ! cp "$tmp" "$filegz" 2> /dev/null; then
|
||||
echo "$prog: warning: could not keep mode of $filez"
|
||||
if ! cp -f "$tmp" "$filegz" 2> /dev/null; then
|
||||
echo "$prog: could not copy $tmp to $filegz"
|
||||
rm -f "$filegz" "$tmp"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
if ! touch -fr "$filez" "$filegz"; then
|
||||
echo -n "$prog: warning: could not keep timestamp of "
|
||||
echo "$filez"
|
||||
fi
|
||||
rm -f "$filez" "$tmp"
|
||||
else
|
||||
echo "$prog: failed to process $filez"
|
||||
rm -f "$tmp"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
prog=`basename "$0"`
|
||||
usage="usage: $prog [-ftv9K] file ..."
|
||||
|
||||
fflag=0
|
||||
tflag=0
|
||||
kflag=0
|
||||
gzipflags=
|
||||
|
||||
# -P flag is recognized to maintain compatibility, but ignored. Pipe mode is
|
||||
# always used
|
||||
while getopts :ftv9PK i; do
|
||||
case $i in
|
||||
f) fflag=1;;
|
||||
t) tflag=1;;
|
||||
v) gzipflags="-v $gzipflags";;
|
||||
9) gzipflags="-9 $gzipflags";;
|
||||
P) ;;
|
||||
K) kflag=1;;
|
||||
\?) echo "$usage"; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift OPTIND-1
|
||||
|
||||
if test $# -eq 0; then
|
||||
echo "$usage"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rc=0
|
||||
|
||||
while test $# -ne 0; do
|
||||
if ! process "$1"; then
|
||||
rc=$?
|
||||
fi
|
||||
shift
|
||||
done
|
||||
exit $rc
|
71
usr.bin/gzip/znew.1
Normal file
71
usr.bin/gzip/znew.1
Normal file
@ -0,0 +1,71 @@
|
||||
.\" $NetBSD: znew.1,v 1.2 2003/12/28 12:43:43 wiz Exp $
|
||||
.\" $OpenBSD: znew.1,v 1.1 2003/08/02 20:52:50 otto Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
||||
.\"
|
||||
.\" Permission to use, copy, modify, and distribute this software for any
|
||||
.\" purpose with or without fee is hereby granted, provided that the above
|
||||
.\" copyright notice and this permission notice appear in all copies.
|
||||
.\"
|
||||
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.Dd January 26, 2007
|
||||
.Dt ZNEW 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm znew
|
||||
.Nd convert compressed files to gzipped files
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl ftv9K
|
||||
.Ar
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility uncompresses files compressed by
|
||||
.Xr compress 1
|
||||
and recompresses them with
|
||||
.Xr gzip 1 .
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width Ds
|
||||
.It Fl f
|
||||
Overwrite existing
|
||||
.Sq .gz
|
||||
files.
|
||||
Unless this option is specified,
|
||||
.Nm
|
||||
refuses to overwrite existing files.
|
||||
.It Fl t
|
||||
Test integrity of the gzipped file before deleting the original file.
|
||||
If the integrity check fails, the original
|
||||
.Sq .Z
|
||||
file is not removed.
|
||||
.It Fl v
|
||||
Print a report specifying the achieved compression ratios.
|
||||
.It Fl 9
|
||||
Use the -9 mode of
|
||||
.Xr gzip 1 ,
|
||||
achieving better compression at the cost of slower execution.
|
||||
.It Fl K
|
||||
Keep the original
|
||||
.Sq .Z
|
||||
file if it uses less disk blocks than the gzipped one.
|
||||
A disk block is 1024 bytes.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr gzip 1
|
||||
.Sh CAVEATS
|
||||
The
|
||||
.Nm
|
||||
utility tries to maintain the file mode of the original file.
|
||||
If the original file is not writable, it is not able to do that and
|
||||
.Nm
|
||||
will print a warning.
|
390
usr.bin/gzip/zuncompress.c
Normal file
390
usr.bin/gzip/zuncompress.c
Normal file
@ -0,0 +1,390 @@
|
||||
/* $NetBSD: zuncompress.c,v 1.6 2005/11/22 09:05:30 mrg Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1985, 1986, 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Diomidis Spinellis and James A. Woods, derived from original
|
||||
* work by Spencer Thomas and Joseph Orost.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: NetBSD: zopen.c,v 1.8 2003/08/07 11:13:29 agc Exp
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/* This file is #included by gzip.c */
|
||||
|
||||
static int zread(void *, char *, int);
|
||||
|
||||
#define tab_prefixof(i) (zs->zs_codetab[i])
|
||||
#define tab_suffixof(i) ((char_type *)(zs->zs_htab))[i]
|
||||
#define de_stack ((char_type *)&tab_suffixof(1 << BITS))
|
||||
|
||||
#define BITS 16 /* Default bits. */
|
||||
#define HSIZE 69001 /* 95% occupancy */ /* XXX may not need HSIZE */
|
||||
#define BIT_MASK 0x1f /* Defines for third byte of header. */
|
||||
#define BLOCK_MASK 0x80
|
||||
#define CHECK_GAP 10000 /* Ratio check interval. */
|
||||
#define BUFSIZE (64 * 1024)
|
||||
|
||||
/*
|
||||
* Masks 0x40 and 0x20 are free. I think 0x20 should mean that there is
|
||||
* a fourth header byte (for expansion).
|
||||
*/
|
||||
#define INIT_BITS 9 /* Initial number of bits/code. */
|
||||
|
||||
/*
|
||||
* the next two codes should not be changed lightly, as they must not
|
||||
* lie within the contiguous general code space.
|
||||
*/
|
||||
#define FIRST 257 /* First free entry. */
|
||||
#define CLEAR 256 /* Table clear output code. */
|
||||
|
||||
|
||||
#define MAXCODE(n_bits) ((1 << (n_bits)) - 1)
|
||||
|
||||
typedef long code_int;
|
||||
typedef long count_int;
|
||||
typedef u_char char_type;
|
||||
|
||||
static char_type magic_header[] =
|
||||
{'\037', '\235'}; /* 1F 9D */
|
||||
|
||||
static char_type rmask[9] =
|
||||
{0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
|
||||
|
||||
/* XXX zuncompress global */
|
||||
off_t total_compressed_bytes;
|
||||
size_t compressed_prelen;
|
||||
char *compressed_pre;
|
||||
|
||||
struct s_zstate {
|
||||
FILE *zs_fp; /* File stream for I/O */
|
||||
char zs_mode; /* r or w */
|
||||
enum {
|
||||
S_START, S_MIDDLE, S_EOF
|
||||
} zs_state; /* State of computation */
|
||||
int zs_n_bits; /* Number of bits/code. */
|
||||
int zs_maxbits; /* User settable max # bits/code. */
|
||||
code_int zs_maxcode; /* Maximum code, given n_bits. */
|
||||
code_int zs_maxmaxcode; /* Should NEVER generate this code. */
|
||||
count_int zs_htab [HSIZE];
|
||||
u_short zs_codetab [HSIZE];
|
||||
code_int zs_hsize; /* For dynamic table sizing. */
|
||||
code_int zs_free_ent; /* First unused entry. */
|
||||
/*
|
||||
* Block compression parameters -- after all codes are used up,
|
||||
* and compression rate changes, start over.
|
||||
*/
|
||||
int zs_block_compress;
|
||||
int zs_clear_flg;
|
||||
long zs_ratio;
|
||||
count_int zs_checkpoint;
|
||||
int zs_offset;
|
||||
long zs_in_count; /* Length of input. */
|
||||
long zs_bytes_out; /* Length of compressed output. */
|
||||
long zs_out_count; /* # of codes output (for debugging). */
|
||||
char_type zs_buf[BITS];
|
||||
union {
|
||||
struct {
|
||||
long zs_fcode;
|
||||
code_int zs_ent;
|
||||
code_int zs_hsize_reg;
|
||||
int zs_hshift;
|
||||
} w; /* Write paramenters */
|
||||
struct {
|
||||
char_type *zs_stackp;
|
||||
int zs_finchar;
|
||||
code_int zs_code, zs_oldcode, zs_incode;
|
||||
int zs_roffset, zs_size;
|
||||
char_type zs_gbuf[BITS];
|
||||
} r; /* Read parameters */
|
||||
} u;
|
||||
};
|
||||
|
||||
static code_int getcode(struct s_zstate *zs);
|
||||
|
||||
static off_t
|
||||
zuncompress(FILE *in, FILE *out, char *pre, size_t prelen,
|
||||
off_t *compressed_bytes)
|
||||
{
|
||||
off_t bin, bout = 0;
|
||||
char *buf;
|
||||
|
||||
buf = malloc(BUFSIZE);
|
||||
if (buf == NULL)
|
||||
return -1;
|
||||
|
||||
/* XXX */
|
||||
compressed_prelen = prelen;
|
||||
if (prelen != 0)
|
||||
compressed_pre = pre;
|
||||
else
|
||||
compressed_pre = NULL;
|
||||
|
||||
while ((bin = fread(buf, 1, sizeof(buf), in)) != 0) {
|
||||
if (tflag == 0 && fwrite(buf, 1, bin, out) != (size_t)bin) {
|
||||
free(buf);
|
||||
return -1;
|
||||
}
|
||||
bout += bin;
|
||||
}
|
||||
|
||||
if (compressed_bytes)
|
||||
*compressed_bytes = total_compressed_bytes;
|
||||
|
||||
free(buf);
|
||||
return bout;
|
||||
}
|
||||
|
||||
static int
|
||||
zclose(void *zs)
|
||||
{
|
||||
free(zs);
|
||||
/* We leave the caller to close the fd passed to zdopen() */
|
||||
return 0;
|
||||
}
|
||||
|
||||
FILE *
|
||||
zdopen(int fd)
|
||||
{
|
||||
struct s_zstate *zs;
|
||||
|
||||
if ((zs = calloc(1, sizeof(struct s_zstate))) == NULL)
|
||||
return (NULL);
|
||||
|
||||
zs->zs_state = S_START;
|
||||
|
||||
/* XXX we can get rid of some of these */
|
||||
zs->zs_hsize = HSIZE; /* For dynamic table sizing. */
|
||||
zs->zs_free_ent = 0; /* First unused entry. */
|
||||
zs->zs_block_compress = BLOCK_MASK;
|
||||
zs->zs_clear_flg = 0; /* XXX we calloc()'d this structure why = 0? */
|
||||
zs->zs_ratio = 0;
|
||||
zs->zs_checkpoint = CHECK_GAP;
|
||||
zs->zs_in_count = 1; /* Length of input. */
|
||||
zs->zs_out_count = 0; /* # of codes output (for debugging). */
|
||||
zs->u.r.zs_roffset = 0;
|
||||
zs->u.r.zs_size = 0;
|
||||
|
||||
/*
|
||||
* Layering compress on top of stdio in order to provide buffering,
|
||||
* and ensure that reads and write work with the data specified.
|
||||
*/
|
||||
if ((zs->zs_fp = fdopen(fd, "r")) == NULL) {
|
||||
free(zs);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return funopen(zs, zread, NULL, NULL, zclose);
|
||||
}
|
||||
|
||||
/*
|
||||
* Decompress read. This routine adapts to the codes in the file building
|
||||
* the "string" table on-the-fly; requiring no table to be stored in the
|
||||
* compressed file. The tables used herein are shared with those of the
|
||||
* compress() routine. See the definitions above.
|
||||
*/
|
||||
static int
|
||||
zread(void *cookie, char *rbp, int num)
|
||||
{
|
||||
u_int count, i;
|
||||
struct s_zstate *zs;
|
||||
u_char *bp, header[3];
|
||||
|
||||
if (num == 0)
|
||||
return (0);
|
||||
|
||||
zs = cookie;
|
||||
count = num;
|
||||
bp = (u_char *)rbp;
|
||||
switch (zs->zs_state) {
|
||||
case S_START:
|
||||
zs->zs_state = S_MIDDLE;
|
||||
break;
|
||||
case S_MIDDLE:
|
||||
goto middle;
|
||||
case S_EOF:
|
||||
goto eof;
|
||||
}
|
||||
|
||||
/* Check the magic number */
|
||||
for (i = 0; i < 3 && compressed_prelen; i++, compressed_prelen--)
|
||||
header[i] = *compressed_pre++;
|
||||
|
||||
if (fread(header + i, 1, sizeof(header) - i, zs->zs_fp) !=
|
||||
sizeof(header) - i ||
|
||||
memcmp(header, magic_header, sizeof(magic_header)) != 0) {
|
||||
errno = EFTYPE;
|
||||
return (-1);
|
||||
}
|
||||
total_compressed_bytes = 0;
|
||||
zs->zs_maxbits = header[2]; /* Set -b from file. */
|
||||
zs->zs_block_compress = zs->zs_maxbits & BLOCK_MASK;
|
||||
zs->zs_maxbits &= BIT_MASK;
|
||||
zs->zs_maxmaxcode = 1L << zs->zs_maxbits;
|
||||
if (zs->zs_maxbits > BITS) {
|
||||
errno = EFTYPE;
|
||||
return (-1);
|
||||
}
|
||||
/* As above, initialize the first 256 entries in the table. */
|
||||
zs->zs_maxcode = MAXCODE(zs->zs_n_bits = INIT_BITS);
|
||||
for (zs->u.r.zs_code = 255; zs->u.r.zs_code >= 0; zs->u.r.zs_code--) {
|
||||
tab_prefixof(zs->u.r.zs_code) = 0;
|
||||
tab_suffixof(zs->u.r.zs_code) = (char_type) zs->u.r.zs_code;
|
||||
}
|
||||
zs->zs_free_ent = zs->zs_block_compress ? FIRST : 256;
|
||||
|
||||
zs->u.r.zs_finchar = zs->u.r.zs_oldcode = getcode(zs);
|
||||
if (zs->u.r.zs_oldcode == -1) /* EOF already? */
|
||||
return (0); /* Get out of here */
|
||||
|
||||
/* First code must be 8 bits = char. */
|
||||
*bp++ = (u_char)zs->u.r.zs_finchar;
|
||||
count--;
|
||||
zs->u.r.zs_stackp = de_stack;
|
||||
|
||||
while ((zs->u.r.zs_code = getcode(zs)) > -1) {
|
||||
|
||||
if ((zs->u.r.zs_code == CLEAR) && zs->zs_block_compress) {
|
||||
for (zs->u.r.zs_code = 255; zs->u.r.zs_code >= 0;
|
||||
zs->u.r.zs_code--)
|
||||
tab_prefixof(zs->u.r.zs_code) = 0;
|
||||
zs->zs_clear_flg = 1;
|
||||
zs->zs_free_ent = FIRST - 1;
|
||||
if ((zs->u.r.zs_code = getcode(zs)) == -1) /* O, untimely death! */
|
||||
break;
|
||||
}
|
||||
zs->u.r.zs_incode = zs->u.r.zs_code;
|
||||
|
||||
/* Special case for KwKwK string. */
|
||||
if (zs->u.r.zs_code >= zs->zs_free_ent) {
|
||||
*zs->u.r.zs_stackp++ = zs->u.r.zs_finchar;
|
||||
zs->u.r.zs_code = zs->u.r.zs_oldcode;
|
||||
}
|
||||
|
||||
/* Generate output characters in reverse order. */
|
||||
while (zs->u.r.zs_code >= 256) {
|
||||
*zs->u.r.zs_stackp++ = tab_suffixof(zs->u.r.zs_code);
|
||||
zs->u.r.zs_code = tab_prefixof(zs->u.r.zs_code);
|
||||
}
|
||||
*zs->u.r.zs_stackp++ = zs->u.r.zs_finchar = tab_suffixof(zs->u.r.zs_code);
|
||||
|
||||
/* And put them out in forward order. */
|
||||
middle: do {
|
||||
if (count-- == 0)
|
||||
return (num);
|
||||
*bp++ = *--zs->u.r.zs_stackp;
|
||||
} while (zs->u.r.zs_stackp > de_stack);
|
||||
|
||||
/* Generate the new entry. */
|
||||
if ((zs->u.r.zs_code = zs->zs_free_ent) < zs->zs_maxmaxcode) {
|
||||
tab_prefixof(zs->u.r.zs_code) = (u_short) zs->u.r.zs_oldcode;
|
||||
tab_suffixof(zs->u.r.zs_code) = zs->u.r.zs_finchar;
|
||||
zs->zs_free_ent = zs->u.r.zs_code + 1;
|
||||
}
|
||||
|
||||
/* Remember previous code. */
|
||||
zs->u.r.zs_oldcode = zs->u.r.zs_incode;
|
||||
}
|
||||
zs->zs_state = S_EOF;
|
||||
eof: return (num - count);
|
||||
}
|
||||
|
||||
/*-
|
||||
* Read one code from the standard input. If EOF, return -1.
|
||||
* Inputs:
|
||||
* stdin
|
||||
* Outputs:
|
||||
* code or -1 is returned.
|
||||
*/
|
||||
static code_int
|
||||
getcode(struct s_zstate *zs)
|
||||
{
|
||||
code_int gcode;
|
||||
int r_off, bits, i;
|
||||
char_type *bp;
|
||||
|
||||
bp = zs->u.r.zs_gbuf;
|
||||
if (zs->zs_clear_flg > 0 || zs->u.r.zs_roffset >= zs->u.r.zs_size ||
|
||||
zs->zs_free_ent > zs->zs_maxcode) {
|
||||
/*
|
||||
* If the next entry will be too big for the current gcode
|
||||
* size, then we must increase the size. This implies reading
|
||||
* a new buffer full, too.
|
||||
*/
|
||||
if (zs->zs_free_ent > zs->zs_maxcode) {
|
||||
zs->zs_n_bits++;
|
||||
if (zs->zs_n_bits == zs->zs_maxbits) /* Won't get any bigger now. */
|
||||
zs->zs_maxcode = zs->zs_maxmaxcode;
|
||||
else
|
||||
zs->zs_maxcode = MAXCODE(zs->zs_n_bits);
|
||||
}
|
||||
if (zs->zs_clear_flg > 0) {
|
||||
zs->zs_maxcode = MAXCODE(zs->zs_n_bits = INIT_BITS);
|
||||
zs->zs_clear_flg = 0;
|
||||
}
|
||||
/* XXX */
|
||||
for (i = 0; i < zs->zs_n_bits && compressed_prelen; i++, compressed_prelen--)
|
||||
zs->u.r.zs_gbuf[i] = *compressed_pre++;
|
||||
zs->u.r.zs_size = fread(zs->u.r.zs_gbuf + i, 1, zs->zs_n_bits - i, zs->zs_fp);
|
||||
zs->u.r.zs_size += i;
|
||||
if (zs->u.r.zs_size <= 0) /* End of file. */
|
||||
return (-1);
|
||||
zs->u.r.zs_roffset = 0;
|
||||
|
||||
total_compressed_bytes += zs->u.r.zs_size;
|
||||
|
||||
/* Round size down to integral number of codes. */
|
||||
zs->u.r.zs_size = (zs->u.r.zs_size << 3) - (zs->zs_n_bits - 1);
|
||||
}
|
||||
r_off = zs->u.r.zs_roffset;
|
||||
bits = zs->zs_n_bits;
|
||||
|
||||
/* Get to the first byte. */
|
||||
bp += (r_off >> 3);
|
||||
r_off &= 7;
|
||||
|
||||
/* Get first part (low order bits). */
|
||||
gcode = (*bp++ >> r_off);
|
||||
bits -= (8 - r_off);
|
||||
r_off = 8 - r_off; /* Now, roffset into gcode word. */
|
||||
|
||||
/* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
|
||||
if (bits >= 8) {
|
||||
gcode |= *bp++ << r_off;
|
||||
r_off += 8;
|
||||
bits -= 8;
|
||||
}
|
||||
|
||||
/* High order bits. */
|
||||
gcode |= (*bp & rmask[bits]) << r_off;
|
||||
zs->u.r.zs_roffset += zs->zs_n_bits;
|
||||
|
||||
return (gcode);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user