]> git.cworth.org Git - gzip/commitdiff
Add patch to fix #168606
authorCarl Worth <cworth@cworth.org>
Fri, 23 Jan 2009 15:44:43 +0000 (02:44 +1100)
committerCarl Worth <cworth@cworth.org>
Fri, 27 Feb 2009 21:43:07 +0000 (13:43 -0800)
This allows reading the pattern from stdin (-f -i) with zgrep,
(which otherwise didn't work at all).

debian/changelog
zgrep.in

index a90c42af2005693ab2322f350194c1d2c5bac3a1..1a4543c00f20a795d44ed456dd68f191a20c8fd2 100644 (file)
@@ -1,8 +1,9 @@
 gzip (1.3.12-8) UNRELEASED; urgency=low
 
   * Add Carl Worth as an uploader.
+  * Fix "-f -" to work with zgrep, closes: #168606 
 
- -- Carl Worth <cworth@cworth.org>  Fri, 27 Feb 2009 12:53:23 -0800
+ -- Carl Worth <cworth@cworth.org>  Fri, 27 Feb 2009 12:54:09 -0800
 
 gzip (1.3.12-7) unstable; urgency=low
 
index 5cca34555b141be0eb87da78184efbb97c087139..7ae779d63af8c03e07dbbc30b921ca979d7c17e7 100644 (file)
--- a/zgrep.in
+++ b/zgrep.in
@@ -47,6 +47,7 @@ escape='
 '
 operands=
 have_pat=0
+pat_on_stdin=0
 files_with_matches=0
 files_without_matches=0
 no_filename=0
@@ -92,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
@@ -146,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; }