Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F141935564
D10282.id27100.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D10282.id27100.diff
View Options
Index: share/mk/src.opts.mk
===================================================================
--- share/mk/src.opts.mk
+++ share/mk/src.opts.mk
@@ -62,6 +62,7 @@
BOOTPARAMD \
BOOTPD \
BSD_CPIO \
+ BSD_GREP_FASTMATCH \
BSDINSTALL \
BSNMP \
BZIP2 \
Index: tools/build/options/WITHOUT_BSD_GREP_FASTMATCH
===================================================================
--- /dev/null
+++ tools/build/options/WITHOUT_BSD_GREP_FASTMATCH
@@ -0,0 +1,4 @@
+.\" $FreeBSD$
+Set this option to exclude the fastmatch implementation from
+.Nm grep ,
+instead using only regex(3)
Index: usr.bin/grep/Makefile
===================================================================
--- usr.bin/grep/Makefile
+++ usr.bin/grep/Makefile
@@ -15,10 +15,14 @@
.endif
SRCS= file.c grep.c queue.c util.c
-# Extra files ported backported form some regex improvements
+.if ${MK_BSD_GREP_FASTMATCH} == "yes"
+# Extra files ported backported for some regex improvements
.PATH: ${.CURDIR}/regex
SRCS+= fastmatch.c hashtable.c tre-compile.c tre-fastmatch.c
CFLAGS+=-I${.CURDIR}/regex
+.else
+CFLAGS+= -DWITHOUT_FASTMATCH
+.endif
CFLAGS.gcc+= --param max-inline-insns-single=500
Index: usr.bin/grep/grep.h
===================================================================
--- usr.bin/grep/grep.h
+++ usr.bin/grep/grep.h
@@ -36,7 +36,9 @@
#include <stdio.h>
#include <zlib.h>
+#ifndef WITHOUT_FASTMATCH
#include "fastmatch.h"
+#endif
#ifdef WITHOUT_NLS
#define getstr(n) errstr[n]
@@ -126,7 +128,9 @@
extern struct pat *pattern;
extern struct epat *dpattern, *fpattern;
extern regex_t *er_pattern, *r_pattern;
+#ifndef WITHOUT_FASTMATCH
extern fastmatch_t *fg_pattern;
+#endif
/* For regex errors */
#define RE_ERROR_BUF 512
Index: usr.bin/grep/grep.c
===================================================================
--- usr.bin/grep/grep.c
+++ usr.bin/grep/grep.c
@@ -49,7 +49,9 @@
#include <string.h>
#include <unistd.h>
+#ifndef WITHOUT_FASTMATCH
#include "fastmatch.h"
+#endif
#include "grep.h"
#ifndef WITHOUT_NLS
@@ -86,7 +88,9 @@
static unsigned int pattern_sz;
struct pat *pattern;
regex_t *r_pattern;
+#ifndef WITHOUT_FASTMATCH
fastmatch_t *fg_pattern;
+#endif
/* Filename exclusion/inclusion patterns */
unsigned int fpatterns, dpatterns;
@@ -705,20 +709,24 @@
usage();
}
+#ifndef WITHOUT_FASTMATCH
fg_pattern = grep_calloc(patterns, sizeof(*fg_pattern));
+#endif
r_pattern = grep_calloc(patterns, sizeof(*r_pattern));
/* Check if cheating is allowed (always is for fgrep). */
for (i = 0; i < patterns; ++i) {
+#ifndef WITHOUT_FASTMATCH
+ /* Attempt compilation with fastmatch regex, fallback to regex(3) */
if (fastncomp(&fg_pattern[i], pattern[i].pat,
- pattern[i].len, cflags) != 0) {
- /* Fall back to full regex library */
- c = regcomp(&r_pattern[i], pattern[i].pat, cflags);
- if (c != 0) {
- regerror(c, &r_pattern[i], re_error,
- RE_ERROR_BUF);
- errx(2, "%s", re_error);
- }
+ pattern[i].len, cflags) == 0)
+ continue;
+#endif
+ c = regcomp(&r_pattern[i], pattern[i].pat, cflags);
+ if (c != 0) {
+ regerror(c, &r_pattern[i], re_error,
+ RE_ERROR_BUF);
+ errx(2, "%s", re_error);
}
}
Index: usr.bin/grep/util.c
===================================================================
--- usr.bin/grep/util.c
+++ usr.bin/grep/util.c
@@ -49,7 +49,9 @@
#include <wchar.h>
#include <wctype.h>
+#ifndef WITHOUT_FASTMATCH
#include "fastmatch.h"
+#endif
#include "grep.h"
static int linesqueued;
@@ -295,10 +297,12 @@
for (i = 0; i < patterns; i++) {
pmatch.rm_so = st;
pmatch.rm_eo = l->len;
+#ifndef WITHOUT_FASTMATCH
if (fg_pattern[i].pattern)
r = fastexec(&fg_pattern[i],
l->dat, 1, &pmatch, leflags);
else
+#endif
r = regexec(&r_pattern[i], l->dat, 1,
&pmatch, leflags);
r = (r == 0) ? 0 : REG_NOMATCH;
@@ -310,7 +314,11 @@
(size_t)pmatch.rm_eo != l->len)
r = REG_NOMATCH;
/* Check for whole word match */
+#ifndef WITHOUT_FASTMATCH
if (r == 0 && (wflag || fg_pattern[i].word)) {
+#else
+ if (r == 0 && wflag) {
+#endif
wchar_t wbegin, wend;
wbegin = wend = L' ';
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jan 14, 8:06 AM (7 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27635532
Default Alt Text
D10282.id27100.diff (4 KB)
Attached To
Mode
D10282: bsdgrep(1): Add BSD_GREP_FASTMATCH option for removing fastmatch implementation
Attached
Detach File
Event Timeline
Log In to Comment