Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 28 May 2011 08:37:03 +0000 (UTC)
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r222414 - user/gabor/tre-integration/usr.bin/grep
Message-ID:  <201105280837.p4S8b3oJ075844@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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;
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201105280837.p4S8b3oJ075844>