X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=zgrep.in;h=7ae779d63af8c03e07dbbc30b921ca979d7c17e7;hb=HEAD;hp=4b1b50940cbaa00b0a65ad885974846573445599;hpb=013796abf4c6be0bd130f541c0ece156156239c3;p=gzip diff --git a/zgrep.in b/zgrep.in index 4b1b509..7ae779d 100644 --- a/zgrep.in +++ b/zgrep.in @@ -23,20 +23,13 @@ PATH=BINDIR:$PATH grep='${GREP-grep}' -prog=`echo "$0" | sed 's|.*/||'` -case "$prog" in - *egrep) grep=${EGREP-egrep} ;; - *fgrep) grep=${FGREP-fgrep} ;; - *) grep=${GREP-grep} ;; -esac - -version="z$grep (gzip) @VERSION@ +version='z$grep (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 . There is NO WARRANTY, to the extent permitted by law. -Written by Jean-loup Gailly." +Written by Jean-loup Gailly.' usage="Usage: $0 [OPTION]... [-e] PATTERN [FILE]... Look for instances of PATTERN in the input FILEs, using their @@ -54,6 +47,7 @@ escape=' ' operands= have_pat=0 +pat_on_stdin=0 files_with_matches=0 files_without_matches=0 no_filename=0 @@ -99,6 +93,23 @@ while test $# -ne 0; do printf >&2 '%s: %s: option not supported\n' "$0" "$option" exit 2;; (-[ef]* | --file | --file=* | --reg*) + # The pattern is coming from a file rather than the command-line. + # If the file is actually stdin then we need to do a little + # magic, (since we use stdin to pass the gzip output to grep). + # So find a free fd and change the argument to then use this + # file descriptor for the pattern. + case $optarg in + (" '-'" | " '/dev/stdin'" | " '/dev/fd/0'") + pat_on_stdin=1 + # Start search from 6 since the script already uses 3 and 5 + for fd in $(seq 6 254); do + if test ! -e /dev/fd/$fd; then + pat_fd=$fd + break; + fi + done + optarg=/dev/fd/$pat_fd; + esac have_pat=1;; (--h | --he | --hel | --help) echo "$usage" || exit 2 @@ -112,7 +123,7 @@ while test $# -ne 0; do files_with_matches=1;; (-L | --files-witho*) files_without_matches=1;; - (--no-f*) + (-h | --no-f*) no_filename=1;; (-V | --v | --ve | --ver | --vers | --versi | --versio | --version) echo "$version" || exit 2 @@ -153,6 +164,9 @@ do # Fail if gzip or grep (or sed) fails. gzip_status=$( exec 5>&1 + if test $pat_on_stdin -eq 1; then + eval "exec $pat_fd<&0" + fi (gzip -cdfq -- "$i" 5>&-; echo $? >&5) 3>&- | if test $files_with_matches -eq 1; then eval "$grep" >/dev/null && { printf '%s\n' "$i" || exit 2; }