Date: Fri, 13 Jun 2008 17:52:10 GMT From: Gabor Kovesdan <gabor@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 143422 for review Message-ID: <200806131752.m5DHqATr095184@repoman.freebsd.org>
index | next in thread | raw e-mail
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 <bsd.prog.mk> ==== //depot/projects/soc2008/gabor_textproc/grep/binary.c#5 (text+ko) ==== @@ -34,6 +34,7 @@ #endif #endif /* not lint */ +#include <bzlib.h> #include <ctype.h> #include <err.h> #include <stdio.h> ==== //depot/projects/soc2008/gabor_textproc/grep/file.c#4 (text+ko) ==== @@ -36,6 +36,7 @@ #include <sys/param.h> +#include <bzlib.h> #include <err.h> #include <stdio.h> #include <stdlib.h> @@ -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,home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200806131752.m5DHqATr095184>
