From owner-p4-projects@FreeBSD.ORG Sat Jun 14 22:57:50 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 807C81065672; Sat, 14 Jun 2008 22:57:50 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 42BEF106564A for ; Sat, 14 Jun 2008 22:57:50 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 30CA38FC0C for ; Sat, 14 Jun 2008 22:57:50 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m5EMvo8t087951 for ; Sat, 14 Jun 2008 22:57:50 GMT (envelope-from gabor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m5EMvo0n087949 for perforce@freebsd.org; Sat, 14 Jun 2008 22:57:50 GMT (envelope-from gabor@freebsd.org) Date: Sat, 14 Jun 2008 22:57:50 GMT Message-Id: <200806142257.m5EMvo0n087949@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gabor@freebsd.org using -f From: Gabor Kovesdan To: Perforce Change Reviews Cc: Subject: PERFORCE change 143475 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Jun 2008 22:57:50 -0000 http://perforce.freebsd.org/chv.cgi?CH=143475 Change 143475 by gabor@gabor_server on 2008/06/14 22:56:55 - Implement -J / --bz2decompress Affected files ... .. //depot/projects/soc2008/gabor_textproc/grep/binary.c#6 edit .. //depot/projects/soc2008/gabor_textproc/grep/file.c#5 edit .. //depot/projects/soc2008/gabor_textproc/grep/grep.1#10 edit Differences ... ==== //depot/projects/soc2008/gabor_textproc/grep/binary.c#6 (text+ko) ==== ==== //depot/projects/soc2008/gabor_textproc/grep/file.c#5 (text+ko) ==== @@ -66,18 +66,32 @@ static char * bzfgetln(BZFILE *f, size_t *len) { - int bzerror; + size_t n; + char c; + int bzerr = 0; + + for (n = 0; ; ++n) { + BZ2_bzRead(&bzerr, f, &c, 1); + + if ((bzerr == BZ_STREAM_END) || (bzerr == BZ_SEQUENCE_ERROR)) { + if (n == 0) + return (NULL); + else + break; + } else if (bzerr != BZ_OK) + err(2, NULL); - if (lnbuflen != *len) - { - lnbuflen = *len; - lnbuf = grep_realloc(lnbuf, ++lnbuflen); + if (n >= lnbuflen) { + lnbuflen *= 2; + lnbuf = grep_realloc(lnbuf, ++lnbuflen); + } + if (c == '\n') + break; + lnbuf[n] = c; } - if (BZ2_bzRead(&bzerror, f, lnbuf, *len) > 0) - return (lnbuf); - else - return (NULL); + *len = n; + return (lnbuf); } static char * @@ -197,7 +211,7 @@ case FILE_GZIP: return (gzbin_file(f->gzf)); case FILE_BZIP: -/*XXX +/* XXX: we cannot seek in bzip2 files, just suppose that it is not binary return (bzbin_file(f->bzf)); */ return (0); default: ==== //depot/projects/soc2008/gabor_textproc/grep/grep.1#10 (text+ko) ==== @@ -29,7 +29,7 @@ .\" .\" @(#)grep.1 8.3 (Berkeley) 4/18/94 .\" -.Dd 13 Jun, 2008 +.Dd 15 Jun, 2008 .Dt GREP 1 .Os .Sh NAME @@ -39,7 +39,7 @@ .Sh SYNOPSIS .Nm grep .Bk -words -.Op Fl abcdDEFGHhIiLlmnOoPqRSsUVvwxZ +.Op Fl abcdDEFGHhIiJLlmnOoPqRSsUVvwxZ .Op Fl A Ar num .Op Fl B Ar num .Op Fl C Ns Op Ar num @@ -227,6 +227,10 @@ By default, .Nm grep is case sensitive. +.It Fl J, Fl Fl bz2decompress +Decompress the +.Xr bzip2 1 +compressed file before looking for the text. .It Fl L , Fl Fl files-without-match Only the names of files not containing selected lines are written to standard output. @@ -418,7 +422,7 @@ specification. .Pp The flags -.Op Fl AaBbCGHhILoPRSUVwZ +.Op Fl AaBbCDdGHhIJLmoPRSUVwZ are extensions to that specification, and the behaviour of the .Fl f flag when used with an empty pattern file is left undefined.