[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: invoking gunzip.exe
From: |
Paul Eggert |
Subject: |
Re: invoking gunzip.exe |
Date: |
Fri, 04 May 2007 13:08:48 -0700 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) |
Eric Blake <address@hidden> writes:
> You have a point here, and there is even precedence for this - coreutils
> intentionally ships ls, dir, and vdir as separate executables, rather than
> shipping dir and vdir as shell wrappers around ls. They share the same
> source except for a minimal #define that determines the separate default
> options between the three.
>
> Another benefit of making gunzip a full-blown executable, instead of a
> shell wrapper, is better help output.
Better, but still incorrect. For example:
$ dir --help | grep show-control
--show-control-chars show non graphic characters as-is (default
--show-control-chars is not the default with 'dir'.
The underlying problem here is trying to implement programs that are
conceptually different by using the same source code. The --help
problem can be solved by careful attention to details, but it's easy
to get the details wrong regardless of whether one uses shell scripts
or separate executables.
> It is still possible to make a wrapper script give intelligent help
> (witness coreutils' groups, wrapping id), but it involves a lot more than
> a simple two-liner. At which point, a simple #define difference in
> default options between two similar executables seems more maintainable.
It leads to multiple copies of the same code, which has performance
and maintenance issues of its own.
> Another benefit of making gunzip a full-blown executable rather than a
> shell wrapper is that the startup time is faster (and on cygwin and mingw,
> the extra process and time of a shell script wrapper is noticeable).
But no extra process is involved here; the shell script does not fork.
> Uncompressing is a common task, and should not be artificially slowed down
> because a shell script is in the mix when a binary could do the job.
The overhead is so small on my Debian stable host (with a 5-year-old
CPU) that I can't easily measure it. Perhaps things are different on
Cygwin but I suspect in practice the overhead is relatively small
there, too. At any rate we shouldn't let the tail wag the dog.
Anyway, I installed the following, which should bring the 'help'
output up to a standard that's a bit higher than coreutils, and also
addresses a possible security concern on poorly-managed hosts.
2007-05-04 Paul Eggert <address@hidden>
* Makefile.am (.in): Substitute @bindir@, not BINDIR, for
consistency with other substitutions.
(check-local): Use --__bindir . rather than setting GZIP_BINDIR=.,
to allay security concerns voiced by Joerg Lehners in
<http://lists.gnu.org/archive/html/bug-gzip/2007-04/msg00003.html>.
* gunzip.in, gzexe.in, zcat.in, zcmp.in, zdiff.in, zegrep.in, zfgrep.in:
* zforce.in, zgrep.in, zless.in, zmore.in, znew.in:
Support --__bindir rather than GZIP_BINDIR.
* gunzip.in, zcat.in, zcmp.in: Support --help and --version
directly, to avoid some confusion in help and version output.
Problem reported by Eric Blake in
<http://lists.gnu.org/archive/html/bug-gzip/2007-04/msg00006.html>.
Index: Makefile.am
===================================================================
RCS file: /cvsroot/gzip/gzip/Makefile.am,v
retrieving revision 1.21
diff -u -p -r1.21 Makefile.am
--- Makefile.am 5 Feb 2007 20:54:26 -0000 1.21
+++ Makefile.am 4 May 2007 19:53:23 -0000
@@ -56,7 +56,7 @@ SUFFIXES = .in
.in:
sed \
-e 's|/bin/sh|$(SHELL)|g' \
- -e 's|BINDIR|$${GZIP_BINDIR-'\''$(bindir)'\''}|g' \
+ -e 's|address@hidden@|'\''$(bindir)'\''|g' \
-e 's|address@hidden@|$(VERSION)|g' \
$(srcdir)/address@hidden >$@
chmod a+x $@
@@ -65,12 +65,12 @@ SUFFIXES = .in
FILES_TO_CHECK = $(bin_SCRIPTS) $(gzip_LDADD) \
$(top_srcdir)/ChangeLog $(top_srcdir)/configure $(top_srcdir)/gzip.c
check-local: $(FILES_TO_CHECK) gzip.doc.gz
- { test '$(srcdir)' != . || GZIP_BINDIR=. ./zdiff -c gzip.doc.gz; }
- GZIP_BINDIR=. ./zdiff -c $(srcdir)/gzip.doc $(srcdir)/gzip.doc
- GZIP_BINDIR=. ./zdiff $(srcdir)/gzip.doc gzip.doc.gz
- GZIP_BINDIR=. ./zdiff -c - $(srcdir)/gzip.doc <gzip.doc.gz
- GZIP_BINDIR=. ./zdiff -c gzip.doc.gz gzip.doc.gz
- GZIP_BINDIR=. ./zgrep -iV >/dev/null
+ { test '$(srcdir)' != . || ./zdiff --__bindir . -c gzip.doc.gz; }
+ ./zdiff --__bindir . -c $(srcdir)/gzip.doc $(srcdir)/gzip.doc
+ ./zdiff --__bindir . $(srcdir)/gzip.doc gzip.doc.gz
+ ./zdiff --__bindir . -c - $(srcdir)/gzip.doc <gzip.doc.gz
+ ./zdiff --__bindir . -c gzip.doc.gz gzip.doc.gz
+ ./zgrep --__bindir . -iV >/dev/null
for file in $(FILES_TO_CHECK); do \
./gzip -cv -- "$$file" | ./gzip -d | cmp - "$$file" || exit; \
done
Index: gunzip.in
===================================================================
RCS file: /cvsroot/gzip/gzip/gunzip.in,v
retrieving revision 1.1
diff -u -p -r1.1 gunzip.in
--- gunzip.in 5 Feb 2007 20:54:26 -0000 1.1
+++ gunzip.in 4 May 2007 19:53:23 -0000
@@ -1,3 +1,61 @@
#!/bin/sh
-PATH=BINDIR:$PATH
+# Uncompress files. This is the inverse of gzip.
+
+# Copyright (C) 2007 Free Software Foundation
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
address@hidden@
+case $1 in
+--__bindir) bindir=${2?}; shift; shift;;
+esac
+PATH=$bindir:$PATH
+
+version="gunzip (gzip) @VERSION@
+Copyright (C) 2007 Free Software Foundation, Inc.
+This is free software. You may redistribute copies of it under the terms of
+the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
+There is NO WARRANTY, to the extent permitted by law.
+
+Written by Paul Eggert."
+
+usage="Usage: $0 [OPTION]... [FILE]...
+Uncompress FILEs (by default, in-place).
+
+Mandatory arguments to long options are mandatory for short options too.
+
+ -c, --stdout write on standard output, keep original files unchanged
+ -f, --force force overwrite of output file and compress links
+ -l, --list list compressed file contents
+ -n, --no-name do not save or restore the original name and time stamp
+ -N, --name save or restore the original name and time stamp
+ -q, --quiet suppress all warnings
+ -r, --recursive operate recursively on directories
+ -S, --suffix=SUF use suffix SUF on compressed files
+ -t, --test test compressed file integrity
+ -v, --verbose verbose mode
+ --help display this help and exit
+ --version display version information and exit
+
+With no FILE, or when FILE is -, read standard input.
+
+Report bugs to <address@hidden>."
+
+case $1 in
+--help) exec echo "$usage";;
+--version) exec echo "$version";;
+esac
+
exec gzip -d "$@"
Index: gzexe.in
===================================================================
RCS file: /cvsroot/gzip/gzip/gzexe.in,v
retrieving revision 1.9
diff -u -p -r1.9 gzexe.in
--- gzexe.in 5 Feb 2007 20:54:26 -0000 1.9
+++ gzexe.in 4 May 2007 19:53:23 -0000
@@ -53,7 +53,11 @@ Rename each FILE with a compressed versi
Report bugs to <address@hidden>."
-PATH="BINDIR:$PATH"
address@hidden@
+case $1 in
+--__bindir) bindir=${2?}; shift; shift;;
+esac
+PATH=$bindir:$PATH
decomp=0
res=0
Index: zcat.in
===================================================================
RCS file: /cvsroot/gzip/gzip/zcat.in,v
retrieving revision 1.1
diff -u -p -r1.1 zcat.in
--- zcat.in 5 Feb 2007 20:54:26 -0000 1.1
+++ zcat.in 4 May 2007 19:53:23 -0000
@@ -1,3 +1,56 @@
#!/bin/sh
-PATH=BINDIR:$PATH
+# Uncompress files to standard output.
+
+# Copyright (C) 2007 Free Software Foundation
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
address@hidden@
+case $1 in
+--__bindir) bindir=${2?}; shift; shift;;
+esac
+PATH=$bindir:$PATH
+
+version="zcat (gzip) @VERSION@
+Copyright (C) 2007 Free Software Foundation, Inc.
+This is free software. You may redistribute copies of it under the terms of
+the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
+There is NO WARRANTY, to the extent permitted by law.
+
+Written by Paul Eggert."
+
+usage="Usage: $0 [OPTION]... [FILE]...
+Uncompress FILEs to standard output.
+
+ -f, --force force; read compressed data even from a terminal
+ -l, --list list compressed file contents
+ -q, --quiet suppress all warnings
+ -r, --recursive operate recursively on directories
+ -S, --suffix=SUF use suffix SUF on compressed files
+ -t, --test test compressed file integrity
+ -v, --verbose verbose mode
+ --help display this help and exit
+ --version display version information and exit
+
+With no FILE, or when FILE is -, read standard input.
+
+Report bugs to <address@hidden>."
+
+case $1 in
+--help) exec echo "$usage";;
+--version) exec echo "$version";;
+esac
+
exec gzip -cd "$@"
Index: zcmp.in
===================================================================
RCS file: /cvsroot/gzip/gzip/zcmp.in,v
retrieving revision 1.1
diff -u -p -r1.1 zcmp.in
--- zcmp.in 5 Feb 2007 20:54:26 -0000 1.1
+++ zcmp.in 4 May 2007 19:53:23 -0000
@@ -1,3 +1,50 @@
#!/bin/sh
-PATH=BINDIR:$PATH
+# Compare the uncompressed contents of compressed files, byte by byte.
+
+# Copyright (C) 2007 Free Software Foundation
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
address@hidden@
+case $1 in
+--__bindir) bindir=${2?}; shift; shift;;
+esac
+PATH=$bindir:$PATH
+
+version="zcmp (gzip) @VERSION@
+Copyright (C) 2007 Free Software Foundation, Inc.
+This is free software. You may redistribute copies of it under the terms of
+the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
+There is NO WARRANTY, to the extent permitted by law.
+
+Written by Paul Eggert."
+
+usage="Usage: $0 [OPTION]... FILE1 [FILE2]
+Compare FILE1 to FILE2 byte by byte, using their uncompressed contents
+if they are compressed. If FILE2 is omitted, compare FILE1 to the
+uncompressed contents of FILE1.gz. Do comparisons like 'cmp' does.
+
+Options are the same as for 'cmp'.
+
+If a FILE is '-' or missing, read standard input.
+
+Report bugs to <address@hidden>."
+
+case $1 in
+--help) exec echo "$usage";;
+--version) exec echo "$version";;
+esac
+
exec zdiff --__cmp "$@"
Index: zdiff.in
===================================================================
RCS file: /cvsroot/gzip/gzip/zdiff.in,v
retrieving revision 1.10
diff -u -p -r1.10 zdiff.in
--- zdiff.in 8 Feb 2007 22:54:59 -0000 1.10
+++ zdiff.in 4 May 2007 19:53:23 -0000
@@ -18,7 +18,11 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-PATH=BINDIR:$PATH
address@hidden@
+case $1 in
+--__bindir) bindir=${2?}; shift; shift;;
+esac
+PATH=$bindir:$PATH
case $1 in
--__cmp) shift
Index: zegrep.in
===================================================================
RCS file: /cvsroot/gzip/gzip/zegrep.in,v
retrieving revision 1.1
diff -u -p -r1.1 zegrep.in
--- zegrep.in 5 Feb 2007 20:54:26 -0000 1.1
+++ zegrep.in 4 May 2007 19:53:23 -0000
@@ -1,3 +1,7 @@
#!/bin/sh
-PATH=BINDIR:$PATH
address@hidden@
+case $1 in
+--__bindir) bindir=${2?}; shift; shift;;
+esac
+PATH=$bindir:$PATH
exec zgrep -E "$@"
Index: zfgrep.in
===================================================================
RCS file: /cvsroot/gzip/gzip/zfgrep.in,v
retrieving revision 1.1
diff -u -p -r1.1 zfgrep.in
--- zfgrep.in 5 Feb 2007 20:54:26 -0000 1.1
+++ zfgrep.in 4 May 2007 19:53:23 -0000
@@ -1,3 +1,7 @@
#!/bin/sh
-PATH=BINDIR:$PATH
address@hidden@
+case $1 in
+--__bindir) bindir=${2?}; shift; shift;;
+esac
+PATH=$bindir:$PATH
exec zgrep -F "$@"
Index: zforce.in
===================================================================
RCS file: /cvsroot/gzip/gzip/zforce.in,v
retrieving revision 1.6
diff -u -p -r1.6 zforce.in
--- zforce.in 5 Feb 2007 20:54:26 -0000 1.6
+++ zforce.in 4 May 2007 19:53:23 -0000
@@ -23,7 +23,11 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-PATH="BINDIR:$PATH"; export PATH
address@hidden@
+case $1 in
+--__bindir) bindir=${2?}; shift; shift;;
+esac
+PATH=$bindir:$PATH; export PATH
version="zforce (gzip) @VERSION@
Copyright (C) 2007 Free Software Foundation, Inc.
Index: zgrep.in
===================================================================
RCS file: /cvsroot/gzip/gzip/zgrep.in,v
retrieving revision 1.9
diff -u -p -r1.9 zgrep.in
--- zgrep.in 5 Feb 2007 20:54:26 -0000 1.9
+++ zgrep.in 4 May 2007 19:53:23 -0000
@@ -20,7 +20,12 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-PATH=BINDIR:$PATH
address@hidden@
+case $1 in
+--__bindir) bindir=${2?}; shift; shift;;
+esac
+PATH=$bindir:$PATH
+
grep='${GREP-grep}'
version='zgrep (gzip) @VERSION@
Index: zless.in
===================================================================
RCS file: /cvsroot/gzip/gzip/zless.in,v
retrieving revision 1.7
diff -u -p -r1.7 zless.in
--- zless.in 5 Feb 2007 20:54:26 -0000 1.7
+++ zless.in 4 May 2007 19:53:23 -0000
@@ -16,7 +16,11 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-PATH="BINDIR:$PATH"; export PATH
address@hidden@
+case $1 in
+--__bindir) bindir=${2?}; shift; shift;;
+esac
+PATH=$bindir:$PATH; export PATH
version="zless (gzip) @VERSION@
Copyright (C) 2007 Free Software Foundation, Inc.
Index: zmore.in
===================================================================
RCS file: /cvsroot/gzip/gzip/zmore.in,v
retrieving revision 1.6
diff -u -p -r1.6 zmore.in
--- zmore.in 5 Feb 2007 20:54:26 -0000 1.6
+++ zmore.in 4 May 2007 19:53:23 -0000
@@ -17,7 +17,11 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-PATH="BINDIR:$PATH"; export PATH
address@hidden@
+case $1 in
+--__bindir) bindir=${2?}; shift; shift;;
+esac
+PATH=$bindir:$PATH; export PATH
version="zmore (gzip) @VERSION@
Copyright (C) 2007 Free Software Foundation, Inc.
Index: znew.in
===================================================================
RCS file: /cvsroot/gzip/gzip/znew.in,v
retrieving revision 1.8
diff -u -p -r1.8 znew.in
--- znew.in 29 Mar 2007 22:38:48 -0000 1.8
+++ znew.in 4 May 2007 19:53:23 -0000
@@ -17,7 +17,11 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-PATH="BINDIR:$PATH"; export PATH
address@hidden@
+case $1 in
+--__bindir) bindir=${2?}; shift; shift;;
+esac
+PATH=$bindir:$PATH; export PATH
version="znew (gzip) @VERSION@
Copyright (C) 2007 Free Software Foundation, Inc.
- Re: invoking gunzip.exe,
Paul Eggert <=