Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/gzip Refactor zdiff and extend functionality to the ...



details:   https://anonhg.NetBSD.org/src/rev/407228e00895
branches:  trunk
changeset: 753968:407228e00895
user:      joerg <joerg%NetBSD.org@localhost>
date:      Wed Apr 14 18:55:12 2010 +0000

description:
Refactor zdiff and extend functionality to the common suffixes for bzip2
and xz.

diffstat:

 usr.bin/gzip/zdiff   |  118 +++++++++++++++++++++++++++++++-------------------
 usr.bin/gzip/zdiff.1 |   59 +++++++++++++++++++-----
 2 files changed, 120 insertions(+), 57 deletions(-)

diffs (254 lines):

diff -r e1081edd0df1 -r 407228e00895 usr.bin/gzip/zdiff
--- a/usr.bin/gzip/zdiff        Wed Apr 14 18:39:56 2010 +0000
+++ b/usr.bin/gzip/zdiff        Wed Apr 14 18:55:12 2010 +0000
@@ -1,10 +1,11 @@
 #!/bin/sh -
 #
-# $NetBSD: zdiff,v 1.3 2004/03/29 10:01:00 wiz Exp $
+# $NetBSD: zdiff,v 1.4 2010/04/14 18:55:12 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@localhost>
+# Copyright (c) 2010 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
 #
 # Permission to use, copy, modify, and distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
@@ -30,7 +31,57 @@
        *)      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
@@ -41,6 +92,9 @@
                        shift
                        break
                        ;;
+               -)
+                       break
+                       ;;
                -*)
                        flags="$flags $1"
                        shift
@@ -54,52 +108,28 @@
 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 -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
+       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
diff -r e1081edd0df1 -r 407228e00895 usr.bin/gzip/zdiff.1
--- a/usr.bin/gzip/zdiff.1      Wed Apr 14 18:39:56 2010 +0000
+++ b/usr.bin/gzip/zdiff.1      Wed Apr 14 18:55:12 2010 +0000
@@ -1,7 +1,8 @@
-.\"    $NetBSD: zdiff.1,v 1.3 2003/12/28 12:48:03 wiz Exp $
+.\"    $NetBSD: zdiff.1,v 1.4 2010/04/14 18:55:12 joerg 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@localhost>
+.\" Copyright (c) 2010 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
 .\"
 .\" Permission to use, copy, modify, and distribute this software for any
 .\" purpose with or without fee is hereby granted, provided that the above
@@ -19,7 +20,7 @@
 .\" Agency (DARPA) and Air Force Research Laboratory, Air Force
 .\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
 .\"
-.Dd June 23, 2003
+.Dd April 14, 2010
 .Dt ZDIFF 1
 .Os
 .Sh NAME
@@ -44,15 +45,6 @@
 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
@@ -69,6 +61,45 @@
 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 bzip 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
@@ -87,9 +118,11 @@
 .Nm zdiff .
 .El
 .Sh SEE ALSO
+.Xr bzip2 1 ,
 .Xr cmp 1 ,
-.Xr compress 1 ,
-.Xr diff 1
+.Xr gzip 1 ,
+.Xr diff 1 ,
+.Xr xz 1
 .Sh CAVEATS
 .Nm zcmp
 and



Home | Main Index | Thread Index | Old Index