summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorkevans <kevans@FreeBSD.org>2017-08-17 17:09:28 +0000
committerkevans <kevans@FreeBSD.org>2017-08-17 17:09:28 +0000
commit474233cc1f9d6afe3dcc415bcbd8fb0d882d088b (patch)
treee35e59be79836fe9b89d0163bc2d1a90266f816b /usr.bin
parent3427b972705992ab10e73d3d30b116d40d42e439 (diff)
downloadFreeBSD-src-474233cc1f9d6afe3dcc415bcbd8fb0d882d088b.zip
FreeBSD-src-474233cc1f9d6afe3dcc415bcbd8fb0d882d088b.tar.gz
MFC r318914: bsdgrep: correct assumptions to prepare for chunking
Correct a couple of minor BSD grep assumptions that are valid for line processing but not future chunk-based processing. Approved by: emaste (mentor, blanket MFC)
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/grep/grep.c2
-rw-r--r--usr.bin/grep/grep.h2
-rw-r--r--usr.bin/grep/util.c8
3 files changed, 6 insertions, 6 deletions
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c
index ef868bc..6ef3e1f 100644
--- a/usr.bin/grep/grep.c
+++ b/usr.bin/grep/grep.c
@@ -79,7 +79,7 @@ const char *errstr[] = {
};
/* Flags passed to regcomp() and regexec() */
-int cflags = REG_NOSUB;
+int cflags = REG_NOSUB | REG_NEWLINE;
int eflags = REG_STARTEND;
/* XXX TODO: Get rid of this flag.
diff --git a/usr.bin/grep/grep.h b/usr.bin/grep/grep.h
index 9128984..d206c59 100644
--- a/usr.bin/grep/grep.h
+++ b/usr.bin/grep/grep.h
@@ -82,7 +82,7 @@ extern const char *errstr[];
#define EXCL_PAT 0
#define INCL_PAT 1
-#define MAX_LINE_MATCHES 32
+#define MAX_MATCHES 32
struct file {
int fd;
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c
index 627916c..4b9f568 100644
--- a/usr.bin/grep/util.c
+++ b/usr.bin/grep/util.c
@@ -61,7 +61,7 @@ static bool first_match = true;
* other useful bits
*/
struct parsec {
- regmatch_t matches[MAX_LINE_MATCHES]; /* Matches made */
+ regmatch_t matches[MAX_MATCHES]; /* Matches made */
struct str ln; /* Current line */
size_t lnstart; /* Position in line */
size_t matchidx; /* Latest match index */
@@ -295,7 +295,7 @@ procfile(const char *fn)
/* Print the matching line, but only if not quiet/binary */
if (t == 0 && printmatch) {
printline(&pc, ':');
- while (pc.matchidx >= MAX_LINE_MATCHES) {
+ while (pc.matchidx >= MAX_MATCHES) {
/* Reset matchidx and try again */
pc.matchidx = 0;
if (procline(&pc) == 0)
@@ -401,7 +401,7 @@ procline(struct parsec *pc)
lastmatches = 0;
startm = matchidx;
retry = 0;
- if (st > 0)
+ if (st > 0 && pc->ln.dat[st - 1] != fileeol)
leflags |= REG_NOTBOL;
/* Loop to compare with all the patterns */
for (i = 0; i < patterns; i++) {
@@ -483,7 +483,7 @@ procline(struct parsec *pc)
}
/* avoid excessive matching - skip further patterns */
if ((color == NULL && !oflag) || qflag || lflag ||
- matchidx >= MAX_LINE_MATCHES) {
+ matchidx >= MAX_MATCHES) {
pc->lnstart = nst;
lastmatches = 0;
break;
OpenPOWER on IntegriCloud