Diff reduction against NetBSD. The most notable change is to zdiff(1) to

handle more file formats including bzip2 and xz.

MFC after:	2 weeks
This commit is contained in:
Xin LI 2011-05-23 09:02:44 +00:00
parent 104c8fc527
commit be07528c53
5 changed files with 128 additions and 63 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.10 2006/05/12 02:01:15 mrg Exp $ # $NetBSD: Makefile,v 1.13 2009/04/14 22:15:20 lukem Exp $
# $FreeBSD$ # $FreeBSD$
.include <bsd.own.mk> .include <bsd.own.mk>

View File

@ -1,4 +1,4 @@
/* $NetBSD: gzip.c,v 1.97 2009/10/11 09:17:21 mrg Exp $ */ /* $NetBSD: gzip.c,v 1.99 2011/03/23 12:59:44 tsutsui Exp $ */
/*- /*-
* Copyright (c) 1997, 1998, 2003, 2004, 2006 Matthew R. Green * Copyright (c) 1997, 1998, 2003, 2004, 2006 Matthew R. Green
@ -31,7 +31,7 @@
#ifndef lint #ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006\ __COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006\
Matthew R. Green. All rights reserved."); Matthew R. Green. All rights reserved.");
__RCSID("$FreeBSD$"); __FBSDID("$FreeBSD$");
#endif /* not lint */ #endif /* not lint */
/* /*
@ -146,7 +146,7 @@ static suffixes_t suffixes[] = {
#define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0]) #define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0])
#define SUFFIX_MAXLEN 30 #define SUFFIX_MAXLEN 30
static const char gzip_version[] = "FreeBSD gzip 20100407"; static const char gzip_version[] = "FreeBSD gzip 20110523";
#ifndef SMALL #ifndef SMALL
static const char gzip_copyright[] = \ static const char gzip_copyright[] = \
@ -314,7 +314,7 @@ main(int argc, char **argv)
dflag = cflag = 1; dflag = cflag = 1;
#ifdef SMALL #ifdef SMALL
#define OPT_LIST "123456789cdhltV" #define OPT_LIST "123456789cdhlV"
#else #else
#define OPT_LIST "123456789acdfhklLNnqrS:tVv" #define OPT_LIST "123456789acdfhklLNnqrS:tVv"
#endif #endif
@ -918,6 +918,7 @@ gz_uncompress(int in, int out, char *pre, size_t prelen, off_t *gsizep,
case Z_BUF_ERROR: case Z_BUF_ERROR:
if (z.avail_out > 0 && !done_reading) if (z.avail_out > 0 && !done_reading)
continue; continue;
case Z_STREAM_END: case Z_STREAM_END:
case Z_OK: case Z_OK:
break; break;

View File

@ -1,10 +1,12 @@
#!/bin/sh - #!/bin/sh -
# #
# $NetBSD: zdiff,v 1.3 2004/03/29 10:01:00 wiz Exp $ # $NetBSD: zdiff,v 1.5 2010/04/14 20:30:28 joerg Exp $
#
# $OpenBSD: zdiff,v 1.2 2003/07/29 07:42:44 otto Exp $ # $OpenBSD: zdiff,v 1.2 2003/07/29 07:42:44 otto Exp $
# #
#- #-
# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com> # Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
# Copyright (c) 2010 Joerg Sonnenberger <joerg@NetBSD.org>
# #
# Permission to use, copy, modify, and distribute this software for any # Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above # purpose with or without fee is hereby granted, provided that the above
@ -31,7 +33,57 @@ case $0 in
*) prog=diff *) prog=diff
;; ;;
esac esac
USAGE="usage: z$prog [options] file1 [file2]" USAGE="usage: $0 [options] file1 [file2]"
check_suffix() {
case "$1" in
*[._-][Zz])
setvar $2 "${1%??}"
setvar $3 "gzip -cdqf"
;;
*[._-]bz)
setvar $2 "${1%???}"
setvar $3 "bzip2 -cdqf"
;;
*[._-]gz)
setvar $2 "${1%???}"
setvar $3 "gzip -cdqf"
;;
*[._-]xz)
setvar $2 "${1%???}"
setvar $3 "xz -cdqf"
;;
*[._-]bz2)
setvar $2 "${1%????}"
setvar $3 "bzip2 -cdqf"
;;
*[._-]lzma)
setvar $2 "${1%?????}"
setvar $3 "xz -cdqf"
;;
*.t[ag]z)
setvar $2 "${1%??}"ar
setvar $3 "gzip -cdqf"
;;
*.tbz)
setvar $2 "${1%??}"ar
setvar $3 "bzip2 -cdqf"
;;
*.tbz2)
setvar $2 "${1%???}"ar
setvar $3 "bzip2 -cdqf"
;;
*.t[lx]z)
setvar $2 "${1%??}"ar
setvar $3 "xz -cdqf"
;;
*)
setvar $2 "$1"
setvar $3 ""
;;
esac
}
# Pull out any command line flags so we can pass them to diff/cmp # Pull out any command line flags so we can pass them to diff/cmp
# XXX - assumes there is no optarg # XXX - assumes there is no optarg
@ -42,6 +94,9 @@ while test $# -ne 0; do
shift shift
break break
;; ;;
-)
break
;;
-*) -*)
flags="$flags $1" flags="$flags $1"
shift shift
@ -55,52 +110,28 @@ done
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
# One file given, compare compressed to uncompressed # One file given, compare compressed to uncompressed
files="$1" files="$1"
case "$1" in check_suffix "$1" files filt
*[._-][Zz]) if [ -z "$filt" ]; then
files="${1%??}" echo "z$prog: unknown suffix" 1>&2
;; exit 1
*[._-]gz) fi
files="${1%???}" $filt -- "$1" | $prog $flags -- - "$files"
;;
*.t[ag]z)
files="${1%??}"ar
;;
*) echo "z$prog: unknown suffix" 1>&2
exit 1
esac
gzip -cdfq "$1" | $prog $flags - "$files"
status=$? status=$?
elif [ $# -eq 2 ]; then elif [ $# -eq 2 ]; then
# Two files given, compare the two uncompressing as needed # Two files given, compare the two uncompressing as needed
case "$1" in check_suffix "$1" files filt
*[._-][Zz]|*[._-]gz|*.t[ag]z) check_suffix "$2" files2 filt2
files=- if [ -z "$filt" -a -z "$filt2" ]; then
filt="gzip -cdfq $1" $prog $flags -- "$1" "$2"
;; elif [ -z "$filt" -a -n "$filt2" -a "$1" != "-" ]; then
*) $filt2 -- "$2" | $prog $flags -- "$1" -
files="$1" elif [ -n "$filt" -a -z "$filt2" -a "$2" != "-" ]; then
;; $filt -- "$1" | $prog $flags -- - "$2"
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 else
$prog $flags $files tmp=`mktemp -t z$prog.XXXXXXXXXX` || exit 1
trap "rm -f $tmp" 0 1 2 3 13 15
${filt2:-cat} -- "$2" > $tmp || exit $?
${filt:-cat} -- "$1" | $prog $flags -- - "$tmp"
fi fi
status=$? status=$?
else else

View File

@ -1,7 +1,8 @@
.\" $NetBSD: zdiff.1,v 1.3 2003/12/28 12:48:03 wiz Exp $ .\" $NetBSD: zdiff.1,v 1.5 2010/04/14 19:52:05 wiz Exp $
.\" $OpenBSD: zdiff.1,v 1.2 2003/07/13 17:39:14 millert 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> .\" Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
.\" Copyright (c) 2010 Joerg Sonnenberger <joerg@NetBSD.org>
.\" .\"
.\" Permission to use, copy, modify, and distribute this software for any .\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above .\" purpose with or without fee is hereby granted, provided that the above
@ -20,7 +21,7 @@
.\" Materiel Command, USAF, under agreement number F39502-99-1-0512. .\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
.\" .\"
.\" $FreeBSD$ .\" $FreeBSD$
.Dd January 26, 2007 .Dd May 23, 2011
.Dt ZDIFF 1 .Dt ZDIFF 1
.Os .Os
.Sh NAME .Sh NAME
@ -45,15 +46,6 @@ are filters that invoke
or or
.Xr diff 1 .Xr diff 1
respectively to compare compressed files. 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 Any
.Ar options .Ar options
that are specified are passed to that are specified are passed to
@ -70,6 +62,45 @@ When both
or or
.Ar file2 .Ar file2
are specified, either file may be compressed. are specified, either file may be compressed.
.Pp
Extensions handled by
.Xr gzip 1 :
.Bl -bullet -compact
.It
z, Z,
.It
gz,
.It
taz,
.It
tgz.
.El
.Pp
Extensions handled by
.Xr bzip2 1 :
.Bl -bullet -compact
.It
bz,
.It
bz2,
.It
tbz,
.It
tbz2.
.El
.Pp
Extensions handled by
.Xr xz 1 :
.Bl -bullet -compact
.It
lzma,
.It
xz,
.It
tlz,
.It
txz.
.El
.Sh ENVIRONMENT .Sh ENVIRONMENT
.Bl -tag -width "TMPDIR" .Bl -tag -width "TMPDIR"
.It Ev TMPDIR .It Ev TMPDIR
@ -88,9 +119,11 @@ Temporary file for
.Nm zdiff . .Nm zdiff .
.El .El
.Sh SEE ALSO .Sh SEE ALSO
.Xr bzip2 1 ,
.Xr cmp 1 , .Xr cmp 1 ,
.Xr compress 1 , .Xr diff 1 ,
.Xr diff 1 .Xr gzip 1 ,
.Xr xz 1
.Sh CAVEATS .Sh CAVEATS
.Nm zcmp .Nm zcmp
and and

View File

@ -1,4 +1,4 @@
/* $NetBSD: zuncompress.c,v 1.7 2009/04/12 10:31:14 lukem Exp $ */ /* $NetBSD: zuncompress.c,v 1.8 2010/11/06 21:42:32 mrg Exp $ */
/*- /*-
* Copyright (c) 1985, 1986, 1992, 1993 * Copyright (c) 1985, 1986, 1992, 1993