summaryrefslogtreecommitdiffstats
path: root/usr.bin/grep
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>2013-02-08 16:10:16 +0000
committerobrien <obrien@FreeBSD.org>2013-02-08 16:10:16 +0000
commit3028e3f8aba938dfd0bf9fda987b8a72140b8027 (patch)
treeb2f038222ff8a70f687652441df00d2b564c8abe /usr.bin/grep
parent952a6d5a7cd3d3f9007acfa06805262fc04a105f (diff)
parent1d08d5f677c1dfa810e381073590adbae19cc69f (diff)
downloadFreeBSD-src-3028e3f8aba938dfd0bf9fda987b8a72140b8027.zip
FreeBSD-src-3028e3f8aba938dfd0bf9fda987b8a72140b8027.tar.gz
Sync with HEAD.
Diffstat (limited to 'usr.bin/grep')
-rw-r--r--usr.bin/grep/Makefile15
-rw-r--r--usr.bin/grep/file.c9
-rw-r--r--usr.bin/grep/grep.c17
-rw-r--r--usr.bin/grep/grep.h1
-rw-r--r--usr.bin/grep/regex/tre-fastmatch.c2
-rw-r--r--usr.bin/grep/util.c3
6 files changed, 36 insertions, 11 deletions
diff --git a/usr.bin/grep/Makefile b/usr.bin/grep/Makefile
index 3d4b67b..359954b 100644
--- a/usr.bin/grep/Makefile
+++ b/usr.bin/grep/Makefile
@@ -40,17 +40,24 @@ MLINKS= grep.1 egrep.1 \
grep.1 lzfgrep.1
.endif
+LDADD= -lz
+DPADD= ${LIBZ}
+
+.if !defined(WITHOUT_LZMA_SUPPORT)
+LDADD+= -llzma
+DPADD+= ${LIBLZMA}
+
LINKS+= ${BINDIR}/${PROG} ${BINDIR}/xzgrep \
${BINDIR}/${PROG} ${BINDIR}/xzegrep \
${BINDIR}/${PROG} ${BINDIR}/xzfgrep \
${BINDIR}/${PROG} ${BINDIR}/lzgrep \
${BINDIR}/${PROG} ${BINDIR}/lzegrep \
${BINDIR}/${PROG} ${BINDIR}/lzfgrep
+.else
+CFLAGS+= -DWITHOUT_LZMA
+.endif
-LDADD= -lz -llzma
-DPADD= ${LIBZ} ${LIBLZMA}
-
-.if !defined(WITHOUT_BZIP2)
+.if !defined(WITHOUT_BZIP2_SUPPORT)
LDADD+= -lbz2
DPADD+= ${LIBBZ2}
diff --git a/usr.bin/grep/file.c b/usr.bin/grep/file.c
index 8cee2c0..6bcaa52 100644
--- a/usr.bin/grep/file.c
+++ b/usr.bin/grep/file.c
@@ -41,7 +41,6 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <errno.h>
#include <fcntl.h>
-#include <lzma.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
@@ -50,6 +49,10 @@ __FBSDID("$FreeBSD$");
#include <wctype.h>
#include <zlib.h>
+#ifndef WITHOUT_LZMA
+#include <lzma.h>
+#endif
+
#ifndef WITHOUT_BZIP2
#include <bzlib.h>
#endif
@@ -60,7 +63,9 @@ __FBSDID("$FreeBSD$");
#define LNBUFBUMP 80
static gzFile gzbufdesc;
+#ifndef WITHOUT_LZMA
static lzma_stream lstrm = LZMA_STREAM_INIT;
+#endif
#ifndef WITHOUT_BZIP2
static BZFILE* bzbufdesc;
#endif
@@ -116,6 +121,7 @@ grep_refill(struct file *f)
nr = -1;
}
#endif
+#ifndef WITHOUT_LZMA
} else if ((filebehave == FILE_XZ) || (filebehave == FILE_LZMA)) {
lzma_action action = LZMA_RUN;
uint8_t in_buf[MAXBUFSIZ];
@@ -146,6 +152,7 @@ grep_refill(struct file *f)
return (-1);
bufrem = MAXBUFSIZ - lstrm.avail_out;
return (0);
+#endif /* WIHTOUT_LZMA */
} else
nr = read(f->fd, buffer, MAXBUFSIZ);
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c
index 43d9334..117a5a9 100644
--- a/usr.bin/grep/grep.c
+++ b/usr.bin/grep/grep.c
@@ -108,6 +108,7 @@ bool iflag; /* -i: ignore case */
bool lflag; /* -l: only show names of files with matches */
bool mflag; /* -m x: stop reading the files after x matches */
long long mcount; /* count for -m */
+long long mlimit; /* requested value for -m */
bool nflag; /* -n: show line numbers in front of matching lines */
bool oflag; /* -o: print only matching part */
bool qflag; /* -q: quiet mode (don't output anything) */
@@ -478,7 +479,13 @@ main(int argc, char *argv[])
grepbehave = GREP_EXTENDED;
break;
case 'e':
- add_pattern(optarg, strlen(optarg));
+ {
+ char *token;
+ char *string = optarg;
+
+ while ((token = strsep(&string, "\n")) != NULL)
+ add_pattern(token, strlen(token));
+ }
needpattern = 0;
break;
case 'F':
@@ -524,7 +531,7 @@ main(int argc, char *argv[])
case 'm':
mflag = true;
errno = 0;
- mcount = strtoll(optarg, &ep, 10);
+ mlimit = mcount = strtoll(optarg, &ep, 10);
if (((errno == ERANGE) && (mcount == LLONG_MAX)) ||
((errno == EINVAL) && (mcount == 0)))
err(2, NULL);
@@ -667,7 +674,11 @@ main(int argc, char *argv[])
/* Process patterns from command line */
if (aargc != 0 && needpattern) {
- add_pattern(*aargv, strlen(*aargv));
+ char *token;
+ char *string = *aargv;
+
+ while ((token = strsep(&string, "\n")) != NULL)
+ add_pattern(token, strlen(token));
--aargc;
++aargv;
}
diff --git a/usr.bin/grep/grep.h b/usr.bin/grep/grep.h
index 2a8f425..4ee348e 100644
--- a/usr.bin/grep/grep.h
+++ b/usr.bin/grep/grep.h
@@ -115,6 +115,7 @@ extern bool Eflag, Fflag, Gflag, Hflag, Lflag,
extern bool dexclude, dinclude, fexclude, finclude, lbflag, nullflag;
extern unsigned long long Aflag, Bflag;
extern long long mcount;
+extern long long mlimit;
extern char *label;
extern const char *color;
extern int binbehave, devbehave, dirbehave, filebehave, grepbehave, linkbehave;
diff --git a/usr.bin/grep/regex/tre-fastmatch.c b/usr.bin/grep/regex/tre-fastmatch.c
index 6f1aec6..b7a7c91 100644
--- a/usr.bin/grep/regex/tre-fastmatch.c
+++ b/usr.bin/grep/regex/tre-fastmatch.c
@@ -468,7 +468,7 @@ static int fastcmp(const fastmatch_t *fg, const void *data,
fg->nosub = (cflags & REG_NOSUB); \
\
/* Cannot handle REG_ICASE with MB string */ \
- if (fg->icase && (TRE_MB_CUR_MAX > 1)) \
+ if (fg->icase && (TRE_MB_CUR_MAX > 1) && n > 0) \
{ \
DPRINT(("Cannot use fast matcher for MBS with REG_ICASE\n")); \
return REG_BADPAT; \
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c
index 4fb1240..0a3706f 100644
--- a/usr.bin/grep/util.c
+++ b/usr.bin/grep/util.c
@@ -176,8 +176,7 @@ procfile(const char *fn)
mode_t s;
int c, t;
- if (mflag && (mcount <= 0))
- return (0);
+ mcount = mlimit;
if (strcmp(fn, "-") == 0) {
fn = label != NULL ? label : getstr(1);
OpenPOWER on IntegriCloud