summaryrefslogtreecommitdiffstats
path: root/gnu
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>2002-10-06 07:02:30 +0000
committerobrien <obrien@FreeBSD.org>2002-10-06 07:02:30 +0000
commit3079aa5131853e5db003d3cc05434660c85abd5e (patch)
treeb0f691902592cf358ccd0294e172ae0a77049e6c /gnu
parent742de9da6c3be1225671a5605d84562e8049011a (diff)
downloadFreeBSD-src-3079aa5131853e5db003d3cc05434660c85abd5e.zip
FreeBSD-src-3079aa5131853e5db003d3cc05434660c85abd5e.tar.gz
Allow -J to simultaneously do non-bzip2 grepping.
Don't allow -J and -Z together. Partially submitted by: knu
Diffstat (limited to 'gnu')
-rw-r--r--gnu/usr.bin/grep/grep.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/gnu/usr.bin/grep/grep.c b/gnu/usr.bin/grep/grep.c
index f342599..c553edb 100644
--- a/gnu/usr.bin/grep/grep.c
+++ b/gnu/usr.bin/grep/grep.c
@@ -66,7 +66,7 @@ static int filename_mask;
/* Short options. */
static char const short_options[] =
-"0123456789A:B:C::EFGHIRUVX:abcd:e:f:hiLlnqrsuvwxyZz";
+"0123456789A:B:C::EFGHIJRUVX:abcd:e:f:hiLlnqrsuvwxyZz";
/* Non-boolean long options that have no corresponding short equivalents. */
enum
@@ -490,14 +490,26 @@ fillbuf (size_t save, struct stats *stats)
{
ssize_t bytesread;
do
- if (BZflag)
+ if (BZflag && bzbufdesc)
{
- bytesread = BZ2_bzread (bzbufdesc, buffer + bufsalloc, readsize);
- /* gzread() will return "non-error" when given input that isn't
- its type of compression. So we need to mimic that behavor
- for the bzgrep case. */
- if (bytesread == -1)
- bytesread = 0;
+ int bzerr;
+ bytesread = BZ2_bzRead (&bzerr, bzbufdesc, buffer + bufsalloc, readsize);
+
+ switch (bzerr)
+ {
+ case BZ_OK:
+ case BZ_STREAM_END:
+ /* ok */
+ break;
+ case BZ_DATA_ERROR_MAGIC:
+ BZ2_bzReadClose (&bzerr, bzbufdesc); bzbufdesc = NULL;
+ lseek (bufdesc, 0, SEEK_SET);
+ bytesread = read (bufdesc, buffer + bufsalloc, readsize);
+ break;
+ default:
+ bytesread = 0;
+ break;
+ }
}
else
#if HAVE_LIBZ > 0
@@ -747,7 +759,7 @@ grep (int fd, char const *file, struct stats *stats)
{
/* Close fd now, so that we don't open a lot of file descriptors
when we recurse deeply. */
- if (BZflag)
+ if (BZflag && bzbufdesc)
BZ2_bzclose(bzbufdesc);
else
#if HAVE_LIBZ > 0
@@ -923,7 +935,7 @@ grepfile (char const *file, struct stats *stats)
if (list_files == 1 - 2 * status)
printf ("%s%c", filename, '\n' & filename_mask);
- if (BZflag)
+ if (BZflag && bzbufdesc)
BZ2_bzclose(bzbufdesc);
else
#if HAVE_LIBZ > 0
@@ -1321,6 +1333,11 @@ main (int argc, char **argv)
binary_files = WITHOUT_MATCH_BINARY_FILES;
break;
case 'J':
+ if (Zflag)
+ {
+ printf (_("Cannot mix -Z and -J.\n"));
+ usage (2);
+ }
BZflag = 1;
break;
case 'U':
@@ -1431,6 +1448,11 @@ main (int argc, char **argv)
break;
case 'Z':
#if HAVE_LIBZ > 0
+ if (BZflag)
+ {
+ printf (_("Cannot mix -J and -Z.\n"));
+ usage (2);
+ }
Zflag = 1;
#else
filename_mask = 0;
OpenPOWER on IntegriCloud