From owner-cvs-all Tue Sep 17 15:56:29 2002 Delivered-To: cvs-all@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E685037B401; Tue, 17 Sep 2002 15:56:26 -0700 (PDT) Received: from mail.musha.org (daemon.musha.org [210.189.104.8]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2B0B443E6E; Tue, 17 Sep 2002 15:56:26 -0700 (PDT) (envelope-from knu@iDaemons.org) Received: from archon.local.idaemons.org (archon.local.idaemons.org [192.168.1.32]) by mail.musha.org (Postfix) with ESMTP id CA0CE519B2; Wed, 18 Sep 2002 07:56:23 +0900 (JST) Date: Wed, 18 Sep 2002 07:56:23 +0900 Message-ID: <86y9a05ip4.wl@archon.local.idaemons.org> From: "Akinori MUSHA" To: "David E. O'Brien" Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/gnu/usr.bin/grep Makefile grep.1 grep.c In-Reply-To: <86ofayjsdr.wl@archon.local.idaemons.org> References: <200209160427.g8G4RUom036315@freefall.freebsd.org> <86ofayjsdr.wl@archon.local.idaemons.org> User-Agent: Wanderlust/2.9.15 (Unchained Melody) EMIKO/1.14.1 (Choanoflagellata) LIMIT/1.14.7 (Fujiidera) APEL/10.3 Emacs/21.2 (i386--freebsd) MULE/5.0 (SAKAKI) Organization: Associated I. Daemons X-PGP-Public-Key: finger knu@FreeBSD.org X-PGP-Fingerprint: 081D 099C 1705 861D 4B70 B04A 920B EFC7 9FD9 E1EE MIME-Version: 1.0 (generated by EMIKO 1.14.1 - "Choanoflagellata") Content-Type: text/plain; charset=US-ASCII Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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