--- grep/configure.ac.in	2007-06-29 16:14:07.000000000 +0100
+++ grep-uncompress/configure.ac.in	2007-07-19 00:03:01.000000000 +0100
@@ -44,6 +44,14 @@
   *)   AC_MSG_ERROR(bad value ${enableval} for --disable-perl-regexp) ;;
  esac],[testpcre=yes])
 
+AC_ARG_ENABLE(uncompress,
+ [  --disable-uncompress            disable uncompress],
+ [case "${enableval}" in
+  yes) testzlib=yes ;;
+  no)  testzlib=no ;;
+  *)   AC_MSG_ERROR(bad value ${enableval} for --disable-uncompress) ;;
+ esac],[testzlib=yes])
+
 dnl Checks for programs.
 AC_CANONICAL_HOST
 AC_PROG_AWK
@@ -167,4 +175,9 @@
 	AC_CHECK_LIB(pcre, pcre_exec)
 fi
 
+# support for zlib
+if test x"$testzlib" = x"yes"; then
+	AC_CHECK_LIB(z, gzdopen)
+fi
+
 AC_OUTPUT(Makefile lib/Makefile lib/posix/Makefile src/Makefile tests/Makefile po/Makefile.in intl/Makefile doc/Makefile m4/Makefile vms/Makefile bootstrap/Makefile, [sed -e "/POTFILES =/r po/POTFILES" po/Makefile.in > po/Makefile; echo timestamp > stamp-h])
--- grep/src/grep.c	2007-07-18 23:59:36.000000000 +0100
+++ grep-uncompress/src/grep.c	2007-07-19 00:00:58.000000000 +0100
@@ -37,6 +37,9 @@
 # include <wctype.h>
 #endif
 #include <stdio.h>
+#if defined(HAVE_LIBZ)
+#include <zlib.h>
+#endif
 #include "system.h"
 #include "getopt.h"
 #include "getpagesize.h"
@@ -82,6 +85,9 @@
 /* If nonzero, show only the part of a line matching the expression. */
 static int only_matching;
 
+/* Auto-uncompress. */
+static int do_uncompress;
+
 /* If nonzero, make sure first content char in a line is on a tab stop. */
 static int align_tabs;
 
@@ -268,7 +274,7 @@
 static struct exclude *excluded_directory_patterns;
 /* Short options.  */
 static char const short_options[] =
-"0123456789A:B:C:D:HITUVabcd:e:f:hiKLlm:noqRrsuvwxyZz"
+"0123456789A:B:C:D:HITUVabcd:e:f:hiKLlm:noqRrsuvwxYyZz"
 #ifdef GREP_PROGRAM
 "EFGPX:"
 #endif
@@ -337,6 +343,7 @@
   {"text", no_argument, NULL, 'a'},
   {"binary", no_argument, NULL, 'U'},
   {"unix-byte-offsets", no_argument, NULL, 'u'},
+  {"uncompress", no_argument, NULL, 'Y'},
   {"version", no_argument, NULL, 'V'},
   {"with-filename", no_argument, NULL, 'H'},
   {"word-regexp", no_argument, NULL, 'w'},
@@ -421,6 +428,7 @@
 static off_t after_last_match;	/* Pointer after last matching line that
 				   would have been output if we were
 				   outputting characters. */
+static gzFile bufgz;		/* zlib compressed file descriptor. */
 
 #if defined(HAVE_MMAP)
 static int bufmapped;		/* True if buffer is memory-mapped.  */
@@ -478,6 +486,18 @@
       bufmapped = 0;
 #endif
     }
+
+  if (do_uncompress)
+    {
+      bufgz = gzdopen (fd, "rb");
+      if (bufgz == NULL)
+        {
+          if (errno != 0)
+            error (0, errno, "gzdopen");
+          return 0;
+        }
+    }
+
   return 1;
 }
 
@@ -594,8 +614,8 @@
   if (! fillsize)
     {
       ssize_t bytesread;
-      while ((bytesread = read (bufdesc, readbuf, readsize)) < 0
-	     && errno == EINTR)
+      while ((bytesread = ((bufgz ? gzread (bufgz, readbuf, readsize) : read (bufdesc, readbuf, readsize)))) < 0
+             && errno == EINTR)
 	continue;
       if (bytesread < 0)
 	cc = 0;
@@ -1321,14 +1341,16 @@
 	    error (0, errno, "%s", filename);
 	}
       else
-	while (close (desc) != 0)
-	  if (errno != EINTR)
-	    {
-	      error (0, errno, "%s", file);
-	      break;
-	    }
+        while ((bufgz ? gzclose (bufgz) : close (desc)) != 0)
+          if (errno != EINTR)
+            {
+              error (0, errno, "%s", file);
+              break;
+            }
     }
 
+  bufgz = NULL;
+
   return status;
 }
 
@@ -1464,6 +1486,7 @@
                             TYPE is `binary', `text', or `without-match'\n\
   -a, --text                equivalent to --binary-files=text\n\
   -I                        equivalent to --binary-files=without-match\n\
+  -Y, --uncompress          uncompress compressed input\n\
   -d, --directories=ACTION  how to handle directories;\n\
                             ACTION is `read', `recurse', or `skip'\n\
   -D, --devices=ACTION      how to handle devices, FIFOs and sockets;\n\
@@ -1902,6 +1925,10 @@
 
       case 'X': /* undocumented on purpose */
 	setmatcher (optarg);
+        break;
+
+      case 'Y':
+        do_uncompress = 1;
 	break;
 #endif /* GREP_PROGRAM */
 
