summaryrefslogtreecommitdiffstats
path: root/usr.bin/grep
diff options
context:
space:
mode:
authorsjg <sjg@FreeBSD.org>2014-08-19 06:50:54 +0000
committersjg <sjg@FreeBSD.org>2014-08-19 06:50:54 +0000
commitd7cd1d425cc1ea9451fa235e3af9b6625c3e0de2 (patch)
treeb04f4bd7cd887f50e7d98af35f46b9834ff86c80 /usr.bin/grep
parent3c8e37b1d04827f33c0c9a7594bd1b1ef7cdb3d3 (diff)
parent4fbde208c6460d576f64d6dc3cdc6cab085a4283 (diff)
downloadFreeBSD-src-d7cd1d425cc1ea9451fa235e3af9b6625c3e0de2.zip
FreeBSD-src-d7cd1d425cc1ea9451fa235e3af9b6625c3e0de2.tar.gz
Merge head from 7/28
Diffstat (limited to 'usr.bin/grep')
-rw-r--r--usr.bin/grep/Makefile.depend1
-rw-r--r--usr.bin/grep/grep.c9
-rw-r--r--usr.bin/grep/queue.c16
-rw-r--r--usr.bin/grep/util.c4
4 files changed, 21 insertions, 9 deletions
diff --git a/usr.bin/grep/Makefile.depend b/usr.bin/grep/Makefile.depend
index b8b81d7..6dc4e1d 100644
--- a/usr.bin/grep/Makefile.depend
+++ b/usr.bin/grep/Makefile.depend
@@ -3,6 +3,7 @@
DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,}
DIRDEPS = \
+ bin/cat.host \
gnu/lib/csu \
gnu/lib/libgcc \
gnu/lib/libregex \
diff --git a/usr.bin/grep/grep.c b/usr.bin/grep/grep.c
index 74446b6..5631877 100644
--- a/usr.bin/grep/grep.c
+++ b/usr.bin/grep/grep.c
@@ -1,4 +1,4 @@
-/* $NetBSD: grep.c,v 1.4 2011/02/16 01:31:33 joerg Exp $ */
+/* $NetBSD: grep.c,v 1.6 2011/04/18 03:48:23 joerg Exp $ */
/* $FreeBSD$ */
/* $OpenBSD: grep.c,v 1.42 2010/07/02 22:18:03 tedu Exp $ */
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
#include <libgen.h>
#include <locale.h>
#include <stdbool.h>
+#define _WITH_GETLINE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -304,6 +305,7 @@ read_patterns(const char *fn)
FILE *f;
char *line;
size_t len;
+ ssize_t rlen;
if ((f = fopen(fn, "r")) == NULL)
err(2, "%s", fn);
@@ -311,8 +313,11 @@ read_patterns(const char *fn)
fclose(f);
return;
}
- while ((line = fgetln(f, &len)) != NULL)
+ len = 0;
+ line = NULL;
+ while ((rlen = getline(&line, &len, f)) != -1)
add_pattern(line, line[0] == '\n' ? 0 : len);
+ free(line);
if (ferror(f))
err(2, "%s", fn);
fclose(f);
diff --git a/usr.bin/grep/queue.c b/usr.bin/grep/queue.c
index afcb827..1887888 100644
--- a/usr.bin/grep/queue.c
+++ b/usr.bin/grep/queue.c
@@ -1,4 +1,4 @@
-/* $NetBSD: queue.c,v 1.2 2011/02/16 01:31:33 joerg Exp $ */
+/* $NetBSD: queue.c,v 1.5 2011/08/31 16:24:57 plunky Exp $ */
/* $FreeBSD$ */
/*-
@@ -68,8 +68,11 @@ enqueue(struct str *x)
STAILQ_INSERT_TAIL(&queue, item, list);
- if (++count > Bflag)
- free(dequeue());
+ if (++count > Bflag) {
+ item = dequeue();
+ free(item->data.dat);
+ free(item);
+ }
}
static struct qentry *
@@ -92,7 +95,8 @@ printqueue(void)
struct qentry *item;
while ((item = dequeue()) != NULL) {
- printline(&item->data, '-', (regmatch_t *)NULL, 0);
+ printline(&item->data, '-', NULL, 0);
+ free(item->data.dat);
free(item);
}
}
@@ -102,6 +106,8 @@ clearqueue(void)
{
struct qentry *item;
- while ((item = dequeue()) != NULL)
+ while ((item = dequeue()) != NULL) {
+ free(item->data.dat);
free(item);
+ }
}
diff --git a/usr.bin/grep/util.c b/usr.bin/grep/util.c
index 0a3706f..3ec12fa 100644
--- a/usr.bin/grep/util.c
+++ b/usr.bin/grep/util.c
@@ -302,7 +302,7 @@ procline(struct str *l, int nottext)
r = REG_NOMATCH;
/* Check for whole word match */
if (r == 0 && (wflag || fg_pattern[i].word)) {
- wint_t wbegin, wend;
+ wchar_t wbegin, wend;
wbegin = wend = L' ';
if (pmatch.rm_so != 0 &&
@@ -336,7 +336,7 @@ procline(struct str *l, int nottext)
}
/* One pass if we are not recording matches */
- if ((color == NULL && !oflag) || qflag || lflag)
+ if (!wflag && ((color == NULL && !oflag) || qflag || lflag))
break;
if (st == (size_t)pmatch.rm_so)
OpenPOWER on IntegriCloud