From owner-p4-projects@FreeBSD.ORG Fri Jun 13 17:52:11 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E05BA1065671; Fri, 13 Jun 2008 17:52:10 +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 8A1C7106567D for ; Fri, 13 Jun 2008 17:52:10 +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 6E9A68FC16 for ; Fri, 13 Jun 2008 17:52:10 +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 m5DHqA4g095186 for ; Fri, 13 Jun 2008 17:52:10 GMT (envelope-from gabor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m5DHqATr095184 for perforce@freebsd.org; Fri, 13 Jun 2008 17:52:10 GMT (envelope-from gabor@freebsd.org) Date: Fri, 13 Jun 2008 17:52:10 GMT Message-Id: <200806131752.m5DHqATr095184@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 143422 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: Fri, 13 Jun 2008 17:52:11 -0000 http://perforce.freebsd.org/chv.cgi?CH=143422 Change 143422 by gabor@gabor_server on 2008/06/13 17:51:54 - Check in some work-in-progress code for -J Affected files ... .. //depot/projects/soc2008/gabor_textproc/grep/Makefile#3 edit .. //depot/projects/soc2008/gabor_textproc/grep/binary.c#5 edit .. //depot/projects/soc2008/gabor_textproc/grep/file.c#4 edit .. //depot/projects/soc2008/gabor_textproc/grep/grep.c#16 edit .. //depot/projects/soc2008/gabor_textproc/grep/grep.h#12 edit Differences ... ==== //depot/projects/soc2008/gabor_textproc/grep/Makefile#3 (text+ko) ==== @@ -15,9 +15,9 @@ grep.1 zegrep.1 \ grep.1 zfgrep.1 -CFLAGS+= -std=c99 -Wall -pedantic +CFLAGS+= -std=c99 -Wall -pedantic -ggdb -LDADD= -lz -DPADD= ${LIBZ} +LDADD= -lz -lbz2 +DPADD= ${LIBZ} ${LIBBZ2} .include ==== //depot/projects/soc2008/gabor_textproc/grep/binary.c#5 (text+ko) ==== @@ -34,6 +34,7 @@ #endif #endif /* not lint */ +#include #include #include #include ==== //depot/projects/soc2008/gabor_textproc/grep/file.c#4 (text+ko) ==== @@ -36,6 +36,7 @@ #include +#include #include #include #include @@ -51,6 +52,7 @@ #define FILE_STDIO 0 #define FILE_MMAP 1 #define FILE_GZIP 2 +#define FILE_BZIP 3 struct file { int type; @@ -58,9 +60,27 @@ FILE *f; struct mmfile *mmf; gzFile *gzf; + BZFILE *bzf; }; static char * +bzfgetln(BZFILE *f, size_t *len) +{ + int bzerror; + + if (lnbuflen != *len) + { + lnbuflen = *len; + lnbuf = grep_realloc(lnbuf, ++lnbuflen); + } + + if (BZ2_bzRead(&bzerror, f, lnbuf, *len) > 0) + return (lnbuf); + else + return (NULL); +} + +static char * gzfgetln(gzFile *f, size_t *len) { size_t n; @@ -113,6 +133,11 @@ f->noseek = lseek(fd, 0L, SEEK_SET) == -1; if ((f->gzf = gzdopen(fd, mode)) != NULL) return (f); + } else if (Jflag) { + f->type = FILE_BZIP; + f->noseek = lseek(fd, 0L, SEEK_SET) == -1; + if ((f->bzf = BZ2_bzdopen(fd, mode)) != NULL) + return (f); } else { f->type = FILE_STDIO; @@ -139,8 +164,11 @@ f->type = FILE_GZIP; if ((f->gzf = gzopen(fname, mode)) != NULL) return (f); - } else - { + } else if (Jflag) { + f->type = FILE_BZIP; + if ((f->bzf = BZ2_bzopen(fname, mode)) != NULL) + return (f); + } else { /* try mmap first; if it fails, try stdio */ if ((f->mmf = mmopen(fname, mode)) != NULL) { f->type = FILE_MMAP; @@ -168,6 +196,10 @@ return (mmbin_file(f->mmf)); case FILE_GZIP: return (gzbin_file(f->gzf)); + case FILE_BZIP: +/*XXX + return (bzbin_file(f->bzf)); */ + return (0); default: /* NOTREACHED */ errx(2, "invalid file type"); @@ -184,6 +216,8 @@ return (mmfgetln(f->mmf, l)); case FILE_GZIP: return (gzfgetln(f->gzf, l)); + case FILE_BZIP: + return (bzfgetln(f->bzf, l)); default: /* NOTREACHED */ errx(2, "invalid file type"); @@ -203,6 +237,9 @@ case FILE_GZIP: gzclose(f->gzf); break; + case FILE_BZIP: + BZ2_bzclose(f->bzf); + break; default: /* NOTREACHED */ errx(2, "invalid file type"); ==== //depot/projects/soc2008/gabor_textproc/grep/grep.c#16 (text+ko) ==== @@ -72,12 +72,13 @@ int Fflag; /* -F: interpret pattern as list of fixed strings */ int Gflag; /* -G: interpret pattern as basic regexp */ int Hflag; /* -H: always print file name */ +int Jflag; /* -J: grep in bzipped file */ int Lflag; /* -L: only show names of files with no matches */ int Oflag; /* -O: if -R, follow explicitly listed symlinks */ int Pflag; /* -P: if -R, no symlinks are followed */ int Rflag; /* -R: recursively search directory trees */ int Sflag; /* -S: if -R, follow all symlinks */ -int Zflag; /* -Z: decompress input before processing */ +int Zflag; /* -Z: grep in gzipped file */ int bflag; /* -b: show block numbers for each match */ int cflag; /* -c: only show a count of matching lines */ int hflag; /* -h: don't print filename headers */ @@ -123,7 +124,7 @@ usage(void) { fprintf(stderr, - "usage: %s [-abcDEFGHhIiLlnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]\n" + "usage: %s [-abcDEFGHhIiJLlnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]\n" "\t[-e pattern] [-f file] [--binary-files=value] [--color=when]\n" "\t[--context[=num]] [--directories=action] [--label] [--line-buffered]\n" "\t[--null] [pattern] [file ...]\n" @@ -131,7 +132,7 @@ exit(2); } -static char *optstr = "0123456789A:B:CD:EFGHILOPSRUVZabcd:e:f:hilnoqrsuvwxy"; +static char *optstr = "0123456789A:B:CD:EFGHIJLOPSRUVZabcd:e:f:hilnoqrsuvwxy"; struct option long_options[] = { @@ -159,8 +160,7 @@ {"no-filename", no_argument, NULL, 'h'}, {"with-filename", no_argument, NULL, 'H'}, {"ignore-case", no_argument, NULL, 'i'}, -/* XXX: UNIMPLEMENTED - {"bz2decompress", no_argument, NULL, 'J'}, */ + {"bz2decompress", no_argument, NULL, 'J'}, {"files-with-matches", no_argument, NULL, 'l'}, {"files-without-match", no_argument, NULL, 'L'}, /* XXX: UNIMPLEMENTED @@ -377,6 +377,10 @@ iflag = 1; cflags |= REG_ICASE; break; + case 'J': + Zflag = 0; + Jflag++; + break; case 'L': lflag = 0; Lflag = qflag = 1; ==== //depot/projects/soc2008/gabor_textproc/grep/grep.h#12 (text+ko) ==== @@ -60,7 +60,7 @@ extern int cflags, eflags; /* Command line flags */ -extern int Aflag, Bflag, Dflag, Eflag, Fflag, Gflag, Hflag, Lflag, Pflag, +extern int Aflag, Bflag, Dflag, Eflag, Fflag, Gflag, Hflag, Jflag, Lflag, Pflag, Sflag, Rflag, Zflag, bflag, cflag, hflag, iflag, lflag, nflag, Oflag, oflag, qflag, sflag, vflag, wflag, xflag,