From owner-svn-src-user@FreeBSD.ORG Sat May 28 08:37:03 2011 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C2183106566B; Sat, 28 May 2011 08:37:03 +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 B2AA38FC14; Sat, 28 May 2011 08:37:03 +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 p4S8b3SQ075849; Sat, 28 May 2011 08:37:03 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p4S8b3oJ075844; Sat, 28 May 2011 08:37:03 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201105280837.p4S8b3oJ075844@svn.freebsd.org> From: Gabor Kovesdan Date: Sat, 28 May 2011 08:37:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r222414 - user/gabor/tre-integration/usr.bin/grep X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 May 2011 08:37:03 -0000 Author: gabor Date: Sat May 28 08:37:03 2011 New Revision: 222414 URL: http://svn.freebsd.org/changeset/base/222414 Log: - Use libc in grep instead of GNU regex - Eliminate literal matching code and depend on TRE's REG_LITERAL Deleted: user/gabor/tre-integration/usr.bin/grep/fastgrep.c Modified: user/gabor/tre-integration/usr.bin/grep/Makefile user/gabor/tre-integration/usr.bin/grep/grep.c user/gabor/tre-integration/usr.bin/grep/grep.h user/gabor/tre-integration/usr.bin/grep/util.c Modified: user/gabor/tre-integration/usr.bin/grep/Makefile ============================================================================== --- user/gabor/tre-integration/usr.bin/grep/Makefile Sat May 28 08:34:30 2011 (r222413) +++ user/gabor/tre-integration/usr.bin/grep/Makefile Sat May 28 08:37:03 2011 (r222414) @@ -3,7 +3,7 @@ # $OpenBSD: Makefile,v 1.6 2003/06/25 15:00:04 millert Exp $ PROG= grep -SRCS= fastgrep.c file.c grep.c queue.c util.c +SRCS= file.c grep.c queue.c util.c LINKS= ${BINDIR}/grep ${BINDIR}/egrep \ ${BINDIR}/grep ${BINDIR}/fgrep \ @@ -22,12 +22,6 @@ WARNS?= 6 LDADD= -lz -lbz2 DPADD= ${LIBZ} ${LIBBZ2} -.if !defined(WITHOUT_GNU_COMPAT) -CFLAGS+= -I/usr/include/gnu -LDADD+= -lgnuregex -DPADD+= ${LIBGNUREGEX} -.endif - .if !defined(WITHOUT_NLS) .include "${.CURDIR}/nls/Makefile.inc" .else Modified: user/gabor/tre-integration/usr.bin/grep/grep.c ============================================================================== --- user/gabor/tre-integration/usr.bin/grep/grep.c Sat May 28 08:34:30 2011 (r222413) +++ user/gabor/tre-integration/usr.bin/grep/grep.c Sat May 28 08:37:03 2011 (r222414) @@ -83,7 +83,6 @@ bool matchall; unsigned int patterns, pattern_sz; char **pattern; regex_t *r_pattern; -fastgrep_t *fg_pattern; /* Filename exclusion/inclusion patterns */ unsigned int fpatterns, fpattern_sz; @@ -638,6 +637,8 @@ main(int argc, char *argv[]) switch (grepbehave) { case GREP_FIXED: + cflags |= REG_LITERAL; + break; case GREP_BASIC: break; case GREP_EXTENDED: @@ -648,27 +649,14 @@ main(int argc, char *argv[]) usage(); } - fg_pattern = grep_calloc(patterns, sizeof(*fg_pattern)); r_pattern = grep_calloc(patterns, sizeof(*r_pattern)); -/* - * XXX: fgrepcomp() and fastcomp() are workarounds for regexec() performance. - * Optimizations should be done there. - */ - /* Check if cheating is allowed (always is for fgrep). */ - if (grepbehave == GREP_FIXED) { - for (i = 0; i < patterns; ++i) - fgrepcomp(&fg_pattern[i], pattern[i]); - } else { - for (i = 0; i < patterns; ++i) { - if (fastcomp(&fg_pattern[i], pattern[i])) { - /* Fall back to full regex library */ - c = regcomp(&r_pattern[i], pattern[i], cflags); - if (c != 0) { - regerror(c, &r_pattern[i], re_error, - RE_ERROR_BUF); - errx(2, "%s", re_error); - } - } + + for (i = 0; i < patterns; ++i) { + c = regcomp(&r_pattern[i], pattern[i], cflags); + if (c != 0) { + regerror(c, &r_pattern[i], re_error, + RE_ERROR_BUF); + errx(2, "%s", re_error); } } Modified: user/gabor/tre-integration/usr.bin/grep/grep.h ============================================================================== --- user/gabor/tre-integration/usr.bin/grep/grep.h Sat May 28 08:34:30 2011 (r222413) +++ user/gabor/tre-integration/usr.bin/grep/grep.h Sat May 28 08:37:03 2011 (r222414) @@ -95,17 +95,6 @@ struct epat { int mode; }; -typedef struct { - size_t len; - unsigned char *pattern; - int qsBc[UCHAR_MAX + 1]; - /* flags */ - bool bol; - bool eol; - bool reversed; - bool word; -} fastgrep_t; - /* Flags passed to regcomp() and regexec() */ extern int cflags, eflags; @@ -125,7 +114,6 @@ extern unsigned int dpatterns, fpatterns extern char **pattern; extern struct epat *dpattern, *fpattern; extern regex_t *er_pattern, *r_pattern; -extern fastgrep_t *fg_pattern; /* For regex errors */ #define RE_ERROR_BUF 512 @@ -150,8 +138,3 @@ void clearqueue(void); void grep_close(struct file *f); struct file *grep_open(const char *path); char *grep_fgetln(struct file *f, size_t *len); - -/* fastgrep.c */ -int fastcomp(fastgrep_t *, const char *); -void fgrepcomp(fastgrep_t *, const char *); -int grep_search(fastgrep_t *, const unsigned char *, size_t, regmatch_t *); Modified: user/gabor/tre-integration/usr.bin/grep/util.c ============================================================================== --- user/gabor/tre-integration/usr.bin/grep/util.c Sat May 28 08:34:30 2011 (r222413) +++ user/gabor/tre-integration/usr.bin/grep/util.c Sat May 28 08:37:03 2011 (r222414) @@ -297,22 +297,10 @@ procline(struct str *l, int nottext) /* Loop to compare with all the patterns */ for (i = 0; i < patterns; i++) { -/* - * XXX: grep_search() is a workaround for speed up and should be - * removed in the future. See fastgrep.c. - */ - if (fg_pattern[i].pattern) { - r = grep_search(&fg_pattern[i], - (unsigned char *)l->dat, - l->len, &pmatch); - r = (r == 0) ? 0 : REG_NOMATCH; - st = pmatch.rm_eo; - } else { - r = regexec(&r_pattern[i], l->dat, 1, - &pmatch, eflags); - r = (r == 0) ? 0 : REG_NOMATCH; - st = pmatch.rm_eo; - } + r = regexec(&r_pattern[i], l->dat, 1, + &pmatch, eflags); + r = (r == 0) ? 0 : REG_NOMATCH; + st = pmatch.rm_eo; if (r == REG_NOMATCH) continue; /* Check for full match */ @@ -321,7 +309,7 @@ procline(struct str *l, int nottext) (size_t)pmatch.rm_eo != l->len) r = REG_NOMATCH; /* Check for whole word match */ - if (r == 0 && fg_pattern[i].word && + if (r == 0 && wflag && pmatch.rm_so != 0) { wint_t wbegin, wend;