From a46f6701b98aa0d1b7ca0a587130daf7fc0a500d Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 30 Dec 2006 03:01:51 +0000 Subject: [PATCH] * zgrep.in (version): Fix bug: $grep wasn't evaluated. * zgrep.in: Rewrite to make the option processing more compatible with GNU and POSIX grep. Assume POSIX shell for more stuff, since we're already assuming that. * Makefile.am (check-local): Check zgrep -iV. --- ChangeLog | 9 +++++++++ Makefile.am | 1 + zgrep.in | 39 +++++++++++++++++++++++---------------- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6db0e1e..c43b5b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-12-29 Paul Eggert + + * zgrep.in (version): Fix bug: $grep wasn't evaluated. + + * zgrep.in: Rewrite to make the option processing more + compatible with GNU and POSIX grep. Assume POSIX shell + for more stuff, since we're already assuming that. + * Makefile.am (check-local): Check zgrep -iV. + 2006-12-26 Paul Eggert Fix Debian bug 367673 plus several diff --git a/Makefile.am b/Makefile.am index 6a72aee..35ce96e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -69,6 +69,7 @@ check-local: $(FILES_TO_CHECK) gzip.doc.gz ./zdiff gzip.doc gzip.doc.gz ./zdiff -c - gzip.doc /dev/null for file in $(FILES_TO_CHECK); do \ ./gzip -cv -- "$$file" | ./gzip -d | cmp - "$$file" || exit; \ done diff --git a/zgrep.in b/zgrep.in index 5cc13b3..b787b01 100644 --- a/zgrep.in +++ b/zgrep.in @@ -28,13 +28,13 @@ case "$0" in (*) grep='${GREP-grep}' ;; esac -version="z$grep (gzip) @VERSION@ +eval 'version="z'"$grep"' (gzip) @VERSION@ Copyright (C) 2006 Free Software Foundation, Inc. This is free software. You may redistribute copies of it under the terms of the GNU General Public License . There is NO WARRANTY, to the extent permitted by law. -Written by Jean-loup Gailly." +Written by Jean-loup Gailly."' usage="Usage: z$grep [OPTION]... [-e] PATTERN [FILE]... Look for instances of PATTERN in the input FILEs, using their @@ -50,6 +50,7 @@ escape=' s/'\''/'\''\\'\'''\''/g $s/X$/'\''/ ' +operands= have_pat=0 files_with_matches=0 files_without_matches=0 @@ -58,34 +59,39 @@ with_filename=0 while test $# -ne 0; do option=$1 + shift optarg= - case $1 in + case $option in (-[0123456789abcdhHiIKLlnoqrRsTuUvVwxyzZ]?*) - option=$(expr "X$1" : 'X\(-.[0-9]*\)') - arg2=-\'$(expr "X$1X" : 'X-.[0-9]*\(.*\)' | sed "$escape") - shift - eval "set X $arg2 "'${1+"$@"}';; + arg2=-\'$(expr "X${option}X" : 'X-.[0-9]*\(.*\)' | sed "$escape") + eval "set -- $arg2 "'${1+"$@"}' + option=$(expr "X$option" : 'X\(-.[0-9]*\)');; (--binary-*=* | --[lm]a*=* | --reg*=*) ;; (-[ABCDefm] | --binary-* | --file | --[lm]a* | --reg*) have_optarg=1 - case ${2?"$1 option requires an argument"} in + case ${1?"$option option requires an argument"} in (*\'*) - optarg=" '"$(printf '%sX\n' "$2" | sed "$escape");; + optarg=" '"$(printf '%sX\n' "$1" | sed "$escape");; (*) - optarg=" '$2'";; + optarg=" '$1'";; esac shift;; (--) - shift break;; - (-*) + (-?*) ;; (*) - break;; + case $option in + (*\'*) + operands="$operands '"$(printf '%sX\n' "$option" | sed "$escape");; + (*) + operands="$operands '$option'";; + esac + ${POSIXLY_CORRECT+break} + continue;; esac - shift case $option in (-[drRzZ] | --di* | --exc* | --inc* | --rec* | --nu*) @@ -122,6 +128,8 @@ while test $# -ne 0; do grep="$grep $option$optarg" done +eval "set -- $operands "'${1+"$@"}' + if test $have_pat -eq 0; then case ${1?"missing pattern; try \`$0 --help' for help"} in (*\'*) @@ -133,8 +141,7 @@ if test $have_pat -eq 0; then fi if test $# -eq 0; then - set X - - shift + set -- - fi exec 3>&1 -- 2.47.2