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
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=222210
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$
.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
@ -31,7 +31,7 @@
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006\
Matthew R. Green. All rights reserved.");
__RCSID("$FreeBSD$");
__FBSDID("$FreeBSD$");
#endif /* not lint */
/*
@ -146,7 +146,7 @@ static suffixes_t suffixes[] = {
#define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0])
#define SUFFIX_MAXLEN 30
static const char gzip_version[] = "FreeBSD gzip 20100407";
static const char gzip_version[] = "FreeBSD gzip 20110523";
#ifndef SMALL
static const char gzip_copyright[] = \
@ -314,7 +314,7 @@ main(int argc, char **argv)
dflag = cflag = 1;
#ifdef SMALL
#define OPT_LIST "123456789cdhltV"
#define OPT_LIST "123456789cdhlV"
#else
#define OPT_LIST "123456789acdfhklLNnqrS:tVv"
#endif
@ -918,6 +918,7 @@ gz_uncompress(int in, int out, char *pre, size_t prelen, off_t *gsizep,
case Z_BUF_ERROR:
if (z.avail_out > 0 && !done_reading)
continue;
case Z_STREAM_END:
case Z_OK:
break;

View File

@ -1,10 +1,12 @@
#!/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 $
#
#-
# 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
# purpose with or without fee is hereby granted, provided that the above
@ -31,7 +33,57 @@ case $0 in
*) prog=diff
;;
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
# XXX - assumes there is no optarg
@ -42,6 +94,9 @@ while test $# -ne 0; do
shift
break
;;
-)
break
;;
-*)
flags="$flags $1"
shift
@ -55,52 +110,28 @@ 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"
check_suffix "$1" files filt
if [ -z "$filt" ]; then
echo "z$prog: unknown suffix" 1>&2
exit 1
fi
$filt -- "$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
check_suffix "$1" files filt
check_suffix "$2" files2 filt2
if [ -z "$filt" -a -z "$filt2" ]; then
$prog $flags -- "$1" "$2"
elif [ -z "$filt" -a -n "$filt2" -a "$1" != "-" ]; then
$filt2 -- "$2" | $prog $flags -- "$1" -
elif [ -n "$filt" -a -z "$filt2" -a "$2" != "-" ]; then
$filt -- "$1" | $prog $flags -- - "$2"
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
status=$?
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 $
.\"
.\" 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
.\" 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.
.\"
.\" $FreeBSD$
.Dd January 26, 2007
.Dd May 23, 2011
.Dt ZDIFF 1
.Os
.Sh NAME
@ -45,15 +46,6 @@ are filters that invoke
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
@ -70,6 +62,45 @@ When both
or
.Ar file2
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
.Bl -tag -width "TMPDIR"
.It Ev TMPDIR
@ -88,9 +119,11 @@ Temporary file for
.Nm zdiff .
.El
.Sh SEE ALSO
.Xr bzip2 1 ,
.Xr cmp 1 ,
.Xr compress 1 ,
.Xr diff 1
.Xr diff 1 ,
.Xr gzip 1 ,
.Xr xz 1
.Sh CAVEATS
.Nm zcmp
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