Date: Wed, 18 Sep 2002 07:56:23 +0900 From: "Akinori MUSHA" <knu@iDaemons.org> To: "David E. O'Brien" <obrien@FreeBSD.org> Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/gnu/usr.bin/grep Makefile grep.1 grep.c Message-ID: <86y9a05ip4.wl@archon.local.idaemons.org> In-Reply-To: <86ofayjsdr.wl@archon.local.idaemons.org> References: <200209160427.g8G4RUom036315@freefall.freebsd.org> <86ofayjsdr.wl@archon.local.idaemons.org>
next in thread | previous in thread | raw e-mail | index | archive | help
At Mon, 16 Sep 2002 16:38:56 +0900, I wrote: > At Sun, 15 Sep 2002 21:27:30 -0700 (PDT), > o`brien wrote: > > obrien 2002/09/15 21:27:30 PDT > > > > Modified files: > > gnu/usr.bin/grep Makefile grep.1 grep.c > > Log: > > Create bzgrep. > > Neat. Thanks! I found a couple of problems with the bz2 support: 1. The -J option is not listed in short_options[]. :) 2. Unlike gzread(), BZ2_bzread() does not work against a non-bzip2ed stream. (I guess BZ2_bzread() should be fixed in future because it claims to be compatible with gzread()) The attached patch should fix them and make `grep -J foo foo.bz2' work just as expected. -- / /__ __ Akinori.org / MUSHA.org / ) ) ) ) / FreeBSD.org / Ruby-lang.org Akinori MUSHA aka / (_ / ( (__( @ iDaemons.org / and.or.jp "When I leave I don't know what I'm hoping to find When I leave I don't know what I'm leaving behind.." Index: grep.c =================================================================== RCS file: /home/ncvs/src/gnu/usr.bin/grep/grep.c,v retrieving revision 1.22 diff -u -r1.22 grep.c --- grep.c 16 Sep 2002 04:27:29 -0000 1.22 +++ grep.c 17 Sep 2002 22:45:52 -0000 @@ -66,7 +66,7 @@ /* 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,25 @@ { 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; + bytesread = read (bufdesc, buffer + bufsalloc, readsize); + break; + default: + bytesread = 0; + break; + } } else #if HAVE_LIBZ > 0 @@ -747,7 +758,7 @@ { /* 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 +934,7 @@ 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 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86y9a05ip4.wl>