From owner-svn-src-all@FreeBSD.ORG Thu Oct 20 16:08:11 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9B2DD1065673; Thu, 20 Oct 2011 16:08:11 +0000 (UTC) (envelope-from gabor@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8965C8FC14; Thu, 20 Oct 2011 16:08:11 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p9KG8BOs081808; Thu, 20 Oct 2011 16:08:11 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p9KG8BUO081802; Thu, 20 Oct 2011 16:08:11 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201110201608.p9KG8BUO081802@svn.freebsd.org> From: Gabor Kovesdan Date: Thu, 20 Oct 2011 16:08:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226573 - in stable/9/usr.bin/grep: . regex X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Oct 2011 16:08:11 -0000 Author: gabor Date: Thu Oct 20 16:08:11 2011 New Revision: 226573 URL: http://svn.freebsd.org/changeset/base/226573 Log: MFC r226432, r226273: - Use getprogname() instead of __progname - Allow disabling bzip2 support with WITHOUT_BZIP2 - Fix handling patterns that start with a dot - Remove superfluous semicolon - Fix counting of match limit (-m) Approved by: re (kib), delphij (mentor, implicit) Modified: stable/9/usr.bin/grep/Makefile stable/9/usr.bin/grep/file.c stable/9/usr.bin/grep/grep.c stable/9/usr.bin/grep/regex/tre-fastmatch.c stable/9/usr.bin/grep/util.c Directory Properties: stable/9/usr.bin/grep/ (props changed) Modified: stable/9/usr.bin/grep/Makefile ============================================================================== --- stable/9/usr.bin/grep/Makefile Thu Oct 20 15:58:05 2011 (r226572) +++ stable/9/usr.bin/grep/Makefile Thu Oct 20 16:08:11 2011 (r226573) @@ -26,9 +26,6 @@ LINKS= ${BINDIR}/grep ${BINDIR}/egrep \ ${BINDIR}/grep ${BINDIR}/zgrep \ ${BINDIR}/grep ${BINDIR}/zegrep \ ${BINDIR}/grep ${BINDIR}/zfgrep \ - ${BINDIR}/grep ${BINDIR}/bzgrep \ - ${BINDIR}/grep ${BINDIR}/bzegrep \ - ${BINDIR}/grep ${BINDIR}/bzfgrep \ ${BINDIR}/grep ${BINDIR}/xzgrep \ ${BINDIR}/grep ${BINDIR}/xzegrep \ ${BINDIR}/grep ${BINDIR}/xzfgrep \ @@ -41,9 +38,6 @@ MLINKS= grep.1 egrep.1 \ grep.1 zgrep.1 \ grep.1 zegrep.1 \ grep.1 zfgrep.1 \ - grep.1 bzgrep.1 \ - grep.1 bzegrep.1 \ - grep.1 bzfgrep.1 \ grep.1 xzgrep.1 \ grep.1 xzegrep.1 \ grep.1 xzfgrep.1 \ @@ -52,8 +46,22 @@ MLINKS= grep.1 egrep.1 \ grep.1 lzfgrep.1 .endif -LDADD= -lz -lbz2 -llzma -DPADD= ${LIBZ} ${LIBBZ2} ${LIBLZMA} +LDADD= -lz -llzma +DPADD= ${LIBZ} ${LIBLZMA} + +.if !defined(WITHOUT_BZIP2) +LDADD+= -lbz2 +DPADD+= ${LIBBZ2} + +LINKS+= ${BINDIR}/grep ${BINDIR}/bzgrep \ + ${BINDIR}/grep ${BINDIR}/bzegrep \ + ${BINDIR}/grep ${BINDIR}/bzfgrep +MLINKS+= grep.1 bzgrep.1 \ + grep.1 bzegrep.1 \ + grep.1 bzfgrep.1 +.else +CFLAGS+= -DWITHOUT_BZIP2 +.endif .if !defined(WITHOUT_GNU_COMPAT) CFLAGS+= -I/usr/include/gnu Modified: stable/9/usr.bin/grep/file.c ============================================================================== --- stable/9/usr.bin/grep/file.c Thu Oct 20 15:58:05 2011 (r226572) +++ stable/9/usr.bin/grep/file.c Thu Oct 20 16:08:11 2011 (r226573) @@ -38,7 +38,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include #include #include @@ -51,14 +50,20 @@ __FBSDID("$FreeBSD$"); #include #include +#ifndef WITHOUT_BZIP2 +#include +#endif + #include "grep.h" #define MAXBUFSIZ (32 * 1024) #define LNBUFBUMP 80 static gzFile gzbufdesc; -static BZFILE* bzbufdesc; static lzma_stream lstrm = LZMA_STREAM_INIT; +#ifndef WITHOUT_BZIP2 +static BZFILE* bzbufdesc; +#endif static unsigned char *buffer; static unsigned char *bufpos; @@ -72,7 +77,6 @@ static inline int grep_refill(struct file *f) { ssize_t nr; - int bzerr; if (filebehave == FILE_MMAP) return (0); @@ -80,9 +84,12 @@ grep_refill(struct file *f) bufpos = buffer; bufrem = 0; - if (filebehave == FILE_GZIP) + if (filebehave == FILE_GZIP) { nr = gzread(gzbufdesc, buffer, MAXBUFSIZ); - else if (filebehave == FILE_BZIP && bzbufdesc != NULL) { +#ifndef WITHOUT_BZIP2 + } else if (filebehave == FILE_BZIP && bzbufdesc != NULL) { + int bzerr; + nr = BZ2_bzRead(&bzerr, bzbufdesc, buffer, MAXBUFSIZ); switch (bzerr) { case BZ_OK: @@ -108,6 +115,7 @@ grep_refill(struct file *f) /* Make sure we exit with an error */ nr = -1; } +#endif } else if ((filebehave == FILE_XZ) || (filebehave == FILE_LZMA)) { lzma_action action = LZMA_RUN; uint8_t in_buf[MAXBUFSIZ]; @@ -271,9 +279,11 @@ grep_open(const char *path) (gzbufdesc = gzdopen(f->fd, "r")) == NULL) goto error2; +#ifndef WITHOUT_BZIP2 if (filebehave == FILE_BZIP && (bzbufdesc = BZ2_bzdopen(f->fd, "r")) == NULL) goto error2; +#endif /* Fill read buffer, also catches errors early */ if (bufrem == 0 && grep_refill(f) != 0) Modified: stable/9/usr.bin/grep/grep.c ============================================================================== --- stable/9/usr.bin/grep/grep.c Thu Oct 20 15:58:05 2011 (r226572) +++ stable/9/usr.bin/grep/grep.c Thu Oct 20 16:08:11 2011 (r226573) @@ -150,15 +150,13 @@ bool prev; /* flag whether or not the int tail; /* lines left to print */ bool notfound; /* file not found */ -extern char *__progname; - /* * Prints usage information and returns 2. */ static void usage(void) { - fprintf(stderr, getstr(4), __progname); + fprintf(stderr, getstr(4), getprogname()); fprintf(stderr, "%s", getstr(5)); fprintf(stderr, "%s", getstr(5)); fprintf(stderr, "%s", getstr(6)); @@ -332,7 +330,8 @@ int main(int argc, char *argv[]) { char **aargv, **eargv, *eopts; - char *pn, *ep; + char *ep; + const char *pn; unsigned long long l; unsigned int aargc, eargc, i; int c, lastc, needpattern, newarg, prevoptind; @@ -346,7 +345,7 @@ main(int argc, char *argv[]) /* Check what is the program name of the binary. In this way we can have all the funcionalities in one binary without the need of scripting and using ugly hacks. */ - pn = __progname; + pn = getprogname(); if (pn[0] == 'b' && pn[1] == 'z') { filebehave = FILE_BZIP; pn += 2; @@ -508,6 +507,10 @@ main(int argc, char *argv[]) cflags |= REG_ICASE; break; case 'J': +#ifdef WITHOUT_BZIP2 + errno = EOPNOTSUPP; + err(2, "bzip2 support was disabled at compile-time"); +#endif filebehave = FILE_BZIP; break; case 'L': @@ -568,7 +571,7 @@ main(int argc, char *argv[]) filebehave = FILE_MMAP; break; case 'V': - printf(getstr(9), __progname, VERSION); + printf(getstr(9), getprogname(), VERSION); exit(0); case 'v': vflag = true; Modified: stable/9/usr.bin/grep/regex/tre-fastmatch.c ============================================================================== --- stable/9/usr.bin/grep/regex/tre-fastmatch.c Thu Oct 20 15:58:05 2011 (r226572) +++ stable/9/usr.bin/grep/regex/tre-fastmatch.c Thu Oct 20 16:08:11 2011 (r226573) @@ -1,4 +1,4 @@ -/* $FreeBSD$ */ +/* $FreeBSD$ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -548,7 +548,7 @@ tre_compile_fast(fastmatch_t *fg, const int cflags) { tre_char_t *tmp; - size_t pos = 0, hasdot = 0, whasdot = 0;; + size_t pos = 0, hasdot = 0, whasdot = 0; ssize_t firstdot = -1, wfirstdot = -1; bool escaped = false; bool *_escmap = NULL; @@ -694,7 +694,7 @@ badpat: return REG_BADPAT; } - fg->hasdot = whasdot; + fg->hasdot = wfirstdot > -1; /* * The pattern has been processed and copied to tmp as a literal string Modified: stable/9/usr.bin/grep/util.c ============================================================================== --- stable/9/usr.bin/grep/util.c Thu Oct 20 15:58:05 2011 (r226572) +++ stable/9/usr.bin/grep/util.c Thu Oct 20 16:08:11 2011 (r226573) @@ -233,7 +233,7 @@ procfile(const char *fn) linesqueued++; } c += t; - if (mflag && mcount < 0) + if (mflag && mcount <= 0) break; } if (Bflag > 0)