Date: Sat, 14 Jun 2008 22:57:50 GMT From: Gabor Kovesdan <gabor@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 143475 for review Message-ID: <200806142257.m5EMvo0n087949@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200806142257.m5EMvo0n087949>