mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-23 10:14:55 +00:00
Allow -J to simultaneously do non-bzip2 grepping.
Don't allow -J and -Z together. Partially submitted by: knu
This commit is contained in:
parent
427748f7df
commit
0bd38bab78
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=104555
|
@ -66,7 +66,7 @@ static int filename_mask;
|
||||||
|
|
||||||
/* Short options. */
|
/* Short options. */
|
||||||
static char const 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. */
|
/* Non-boolean long options that have no corresponding short equivalents. */
|
||||||
enum
|
enum
|
||||||
|
@ -490,14 +490,26 @@ fillbuf (size_t save, struct stats *stats)
|
||||||
{
|
{
|
||||||
ssize_t bytesread;
|
ssize_t bytesread;
|
||||||
do
|
do
|
||||||
if (BZflag)
|
if (BZflag && bzbufdesc)
|
||||||
{
|
{
|
||||||
bytesread = BZ2_bzread (bzbufdesc, buffer + bufsalloc, readsize);
|
int bzerr;
|
||||||
/* gzread() will return "non-error" when given input that isn't
|
bytesread = BZ2_bzRead (&bzerr, bzbufdesc, buffer + bufsalloc, readsize);
|
||||||
its type of compression. So we need to mimic that behavor
|
|
||||||
for the bzgrep case. */
|
switch (bzerr)
|
||||||
if (bytesread == -1)
|
{
|
||||||
|
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;
|
bytesread = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#if HAVE_LIBZ > 0
|
#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
|
/* Close fd now, so that we don't open a lot of file descriptors
|
||||||
when we recurse deeply. */
|
when we recurse deeply. */
|
||||||
if (BZflag)
|
if (BZflag && bzbufdesc)
|
||||||
BZ2_bzclose(bzbufdesc);
|
BZ2_bzclose(bzbufdesc);
|
||||||
else
|
else
|
||||||
#if HAVE_LIBZ > 0
|
#if HAVE_LIBZ > 0
|
||||||
|
@ -923,7 +935,7 @@ grepfile (char const *file, struct stats *stats)
|
||||||
if (list_files == 1 - 2 * status)
|
if (list_files == 1 - 2 * status)
|
||||||
printf ("%s%c", filename, '\n' & filename_mask);
|
printf ("%s%c", filename, '\n' & filename_mask);
|
||||||
|
|
||||||
if (BZflag)
|
if (BZflag && bzbufdesc)
|
||||||
BZ2_bzclose(bzbufdesc);
|
BZ2_bzclose(bzbufdesc);
|
||||||
else
|
else
|
||||||
#if HAVE_LIBZ > 0
|
#if HAVE_LIBZ > 0
|
||||||
|
@ -1321,6 +1333,11 @@ main (int argc, char **argv)
|
||||||
binary_files = WITHOUT_MATCH_BINARY_FILES;
|
binary_files = WITHOUT_MATCH_BINARY_FILES;
|
||||||
break;
|
break;
|
||||||
case 'J':
|
case 'J':
|
||||||
|
if (Zflag)
|
||||||
|
{
|
||||||
|
printf (_("Cannot mix -Z and -J.\n"));
|
||||||
|
usage (2);
|
||||||
|
}
|
||||||
BZflag = 1;
|
BZflag = 1;
|
||||||
break;
|
break;
|
||||||
case 'U':
|
case 'U':
|
||||||
|
@ -1431,6 +1448,11 @@ main (int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
case 'Z':
|
case 'Z':
|
||||||
#if HAVE_LIBZ > 0
|
#if HAVE_LIBZ > 0
|
||||||
|
if (BZflag)
|
||||||
|
{
|
||||||
|
printf (_("Cannot mix -J and -Z.\n"));
|
||||||
|
usage (2);
|
||||||
|
}
|
||||||
Zflag = 1;
|
Zflag = 1;
|
||||||
#else
|
#else
|
||||||
filename_mask = 0;
|
filename_mask = 0;
|
||||||
|
|
Loading…
Reference in a new issue