# zgrep -- a wrapper around a grep program that decompresses files as needed
# Adapted from a version sent by Charles Levert <charles@comm.polymtl.ca>
# zgrep -- a wrapper around a grep program that decompresses files as needed
# Adapted from a version sent by Charles Levert <charles@comm.polymtl.ca>
-# Copyright (C) 1998, 2001, 2002, 2006, 2007 Free Software Foundation
+# Copyright (C) 1998, 2001, 2002, 2006, 2007, 2009, 2010 Free Software
+# Foundation
+
# Copyright (C) 1993 Jean-loup Gailly
# 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
# Copyright (C) 1993 Jean-loup Gailly
# 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
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-version='z$grep (gzip) @VERSION@
-Copyright (C) 2007 Free Software Foundation, Inc.
+version='zgrep (gzip) @VERSION@
+Copyright (C) 2010-2012 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.
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.
Report bugs to <bug-gzip@gnu.org>."
# sed script to escape all ' for the shell, and then (to handle trailing
Report bugs to <bug-gzip@gnu.org>."
# sed script to escape all ' for the shell, and then (to handle trailing
- (-[0123456789abcdhHiIKLlnoqrRsTuUvVwxyzZ]?*)
- arg2=-\'$(expr "X${option}X" : 'X-.[0-9]*\(.*\)' | sed "$escape")
+ (-[0123456789EFGHIKLPRTUVZabchilnoqrsuvwxyz]?*)
+ arg2=-\'$(expr "X$option" : 'X-.[0-9]*\(.*\)' | sed "$escape")
eval "set -- $arg2 "'${1+"$@"}'
option=$(expr "X$option" : 'X\(-.[0-9]*\)');;
(--binary-*=* | --[lm]a*=* | --reg*=*)
;;
eval "set -- $arg2 "'${1+"$@"}'
option=$(expr "X$option" : 'X\(-.[0-9]*\)');;
(--binary-*=* | --[lm]a*=* | --reg*=*)
;;
+ (-f?*\'*)
+ optarg=" '"$(expr "X$option" : 'X-f\(.*\)' | sed "$escape")
+ option=-f;;
+ (-f?*)
+ optarg=" '"$(expr "X$option" : 'X-f\(.*\)')\'
+ option=-f;;
+ (--file=*\'*)
+ optarg=" '"$(expr "X$option" : 'X--file=\(.*\)' | sed "$escape")
+ option=--file;;
+ (--file=*)
+ optarg=" '"$(expr "X$option" : 'X--file=\(.*\)')\'
+ option=--file;;
(-[drRzZ] | --di* | --exc* | --inc* | --rec* | --nu*)
printf >&2 '%s: %s: option not supported\n' "$0" "$option"
exit 2;;
(-[drRzZ] | --di* | --exc* | --inc* | --rec* | --nu*)
printf >&2 '%s: %s: option not supported\n' "$0" "$option"
exit 2;;
# 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
# 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.
+ # magic, since we use stdin to pass the gzip output to grep.
+ # Turn the -f option into an -e option by copying the file's
+ # contents into OPTARG.
- 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;
+ option=-e
+ optarg=" '"$(sed "$escape") || exit 2;;
(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; }
elif test $files_without_matches -eq 1; then
eval "$grep" >/dev/null || {
(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; }
elif test $files_without_matches -eq 1; then
eval "$grep" >/dev/null || {