summaryrefslogtreecommitdiff
path: root/usr.bin/compress
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2003-07-12 16:01:50 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2003-07-12 16:01:50 +0000
commit5d5c2965b803f0569263c9a431f999d09c65c8c2 (patch)
treef5d453d2d2d9dce472fa281eae58430ac2586b4f /usr.bin/compress
parentd2db2c9ab834e84b7a26478e7f2c0bf857543e78 (diff)
Add zdiff
Diffstat (limited to 'usr.bin/compress')
-rw-r--r--usr.bin/compress/Makefile12
-rw-r--r--usr.bin/compress/zdiff106
-rw-r--r--usr.bin/compress/zdiff.1106
3 files changed, 219 insertions, 5 deletions
diff --git a/usr.bin/compress/Makefile b/usr.bin/compress/Makefile
index 751abbe428e..1cf5da1f19c 100644
--- a/usr.bin/compress/Makefile
+++ b/usr.bin/compress/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.13 2003/06/23 19:04:36 millert Exp $
+# $OpenBSD: Makefile,v 1.14 2003/07/12 16:01:49 millert Exp $
PROG= compress
SRCS= main.c zopen.c gzopen.c
@@ -7,20 +7,22 @@ LINKS= ${BINDIR}/compress ${BINDIR}/uncompress \
${BINDIR}/compress ${BINDIR}/zcat \
${BINDIR}/compress ${BINDIR}/gzip \
${BINDIR}/compress ${BINDIR}/gunzip \
- ${BINDIR}/compress ${BINDIR}/gzcat
+ ${BINDIR}/compress ${BINDIR}/gzcat \
+ ${BINDIR}/zdiff ${BINDIR}/zcmp
+
MLINKS= compress.1 uncompress.1 \
compress.1 zcat.1 \
compress.1 gzip.1 \
compress.1 gunzip.1 \
- compress.1 gzcat.1
+ compress.1 gzcat.1 \
+ zdiff.1 zcmp.1
LDADD=-lz
DPADD=${LIBZ}
afterinstall:
install -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
- ${.CURDIR}/zmore ${DESTDIR}${BINDIR}
-# ${.CURDIR}/zmore ${.CURDIR}/zdiff \
+ ${.CURDIR}/zmore ${.CURDIR}/zdiff ${DESTDIR}${BINDIR}
# ${.CURDIR}/zforce ${.CURDIR}/gzexe ${.CURDIR}/znew \
# ${DESTDIR}${BINDIR}
diff --git a/usr.bin/compress/zdiff b/usr.bin/compress/zdiff
new file mode 100644
index 00000000000..8f8bc0bff26
--- /dev/null
+++ b/usr.bin/compress/zdiff
@@ -0,0 +1,106 @@
+#!/bin/sh -
+#
+# 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.
+#
+
+# 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
+ compress -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="compress -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
+ compress -cdfq "$2" > $tmp
+ files="$files $tmp"
+ else
+ files="$files -"
+ filt="compress -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
diff --git a/usr.bin/compress/zdiff.1 b/usr.bin/compress/zdiff.1
new file mode 100644
index 00000000000..4b7343479e0
--- /dev/null
+++ b/usr.bin/compress/zdiff.1
@@ -0,0 +1,106 @@
+.\" $OpenBSD: zdiff.1,v 1.1 2003/07/12 16:01:49 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.
+.\"
+.Dd June 23, 2003
+.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"
+.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 the file extension to determine what is, or is not,
+a compressed file.
+Consequently, the following are not supported as arguments:
+.Bl -dash -width "XX"
+.It
+directories
+.It
+device special files
+.It
+filenames indicating the standard input ("'")
+.El