Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F141986140
D10580.id28250.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D10580.id28250.diff
View Options
Index: contrib/ipfilter/lib/printpoolnode.c
===================================================================
--- contrib/ipfilter/lib/printpoolnode.c
+++ contrib/ipfilter/lib/printpoolnode.c
@@ -33,8 +33,30 @@
printmask(np->ipn_addr.adf_family,
(u_32_t *)&np->ipn_mask.adf_addr);
} else {
- PRINTF("\tAddress: %s%s", np->ipn_info ? "! " : "",
- inet_ntoa(np->ipn_addr.adf_addr.in4));
+#ifdef AF_INET6
+ if (np->ipn_addr.adf_family == AF_INET6) {
+ char buf[INET6_ADDRSTRLEN + 1];
+ const char *str;
+
+ buf[0] = '\0';
+ str = inet_ntop(AF_INET6, &np->ipn_addr.adf_addr.in6,
+ buf, sizeof(buf) - 1);
+ if (str == NULL)
+ str = "???";
+ PRINTF("\tAddress: %s%s", np->ipn_info ? "! " : "",
+ str);
+ } else if (np->ipn_addr.adf_family == AF_INET) {
+#else
+ if (np->ipn_addr.adf_family == AF_INET) {
+#endif
+ PRINTF("\tAddress: %s%s", np->ipn_info ? "! " : "",
+ inet_ntoa(np->ipn_addr.adf_addr.in4));
+ } else {
+ PRINTF("\tAddress: family: %d",
+ np->ipn_addr.adf_family);
+#ifdef AF_INET6
+ }
+#endif
printmask(np->ipn_addr.adf_family,
(u_32_t *)&np->ipn_mask.adf_addr);
#ifdef USE_QUAD_T
Index: contrib/netbsd-tests/usr.bin/grep/t_grep.sh
===================================================================
--- contrib/netbsd-tests/usr.bin/grep/t_grep.sh
+++ contrib/netbsd-tests/usr.bin/grep/t_grep.sh
@@ -490,6 +490,39 @@
atf_check -s exit:1 grep -v -w "x" test2
}
+atf_test_case ocolor_metadata
+ocolor_metadata_head()
+{
+ atf_set "descr" "Check for -n/-b producing per-line metadata output"
+}
+ocolor_metadata_body()
+{
+ grep_type
+ if [ $? -eq $GREP_TYPE_GNU_FREEBSD ]; then
+ atf_expect_fail "this test does not pass with GNU grep in base"
+ fi
+
+ printf "xxx\nyyyy\nzzz\nfoobarbaz\n" > test1
+ check_expr="^[^:]*[0-9][^:]*:[^:]+$"
+
+ atf_check -o inline:"1:1:xx\n" grep -bon "xx$" test1
+
+ atf_check -o inline:"2:4:yyyy\n" grep -bn "yy" test1
+
+ atf_check -o inline:"2:6:yy\n" grep -bon "yy$" test1
+
+ # These checks ensure that grep isn't producing bogus line numbering
+ # in the middle of a line.
+ atf_check -s exit:1 -x \
+ "grep -Eon 'x|y|z|f' test1 | grep -Ev '${check_expr}'"
+
+ atf_check -s exit:1 -x \
+ "grep -En 'x|y|z|f' --color=always test1 | grep -Ev '${check_expr}'"
+
+ atf_check -s exit:1 -x \
+ "grep -Eon 'x|y|z|f' --color=always test1 | grep -Ev '${check_expr}'"
+}
+
atf_test_case grep_nomatch_flags
grep_nomatch_flags_head()
{
@@ -550,6 +583,7 @@
atf_add_test_case fgrep_sanity
atf_add_test_case egrep_sanity
atf_add_test_case grep_sanity
+ atf_add_test_case ocolor_metadata
atf_add_test_case grep_nomatch_flags
# End FreeBSD
}
Index: usr.bin/grep/grep.h
===================================================================
--- usr.bin/grep/grep.h
+++ usr.bin/grep/grep.h
@@ -90,6 +90,7 @@
};
struct str {
+ off_t boff;
off_t off;
size_t len;
char *dat;
Index: usr.bin/grep/queue.c
===================================================================
--- usr.bin/grep/queue.c
+++ usr.bin/grep/queue.c
@@ -65,6 +65,7 @@
item->data.dat = grep_malloc(sizeof(char) * x->len);
item->data.len = x->len;
item->data.line_no = x->line_no;
+ item->data.boff = x->boff;
item->data.off = x->off;
memcpy(item->data.dat, x->dat, x->len);
item->data.file = x->file;
Index: usr.bin/grep/util.c
===================================================================
--- usr.bin/grep/util.c
+++ usr.bin/grep/util.c
@@ -61,10 +61,11 @@
* other useful bits
*/
struct parsec {
- regmatch_t matches[MAX_LINE_MATCHES]; /* Matches made */
- struct str ln; /* Current line */
- size_t matchidx; /* Latest used match index */
- bool binary; /* Binary file? */
+ regmatch_t matches[MAX_LINE_MATCHES]; /* Matches made */
+ struct str ln; /* Current line */
+ size_t matchidx; /* Latest match index */
+ int printed; /* Metadata printed? */
+ bool binary; /* Binary file? */
};
@@ -231,8 +232,10 @@
strcpy(pc.ln.file, fn);
pc.ln.line_no = 0;
pc.ln.len = 0;
+ pc.ln.boff = 0;
pc.ln.off = -1;
pc.binary = f->binary;
+ pc.printed = 0;
tail = 0;
last_outed = 0;
same_file = false;
@@ -247,7 +250,9 @@
for (c = 0; c == 0 || !(lflag || qflag); ) {
/* Reset match count for every line processed */
+ pc.printed = 0;
pc.matchidx = 0;
+ pc.ln.boff = 0;
pc.ln.off += pc.ln.len + 1;
if ((pc.ln.dat = grep_fgetln(f, &pc.ln.len)) == NULL ||
pc.ln.len == 0) {
@@ -294,7 +299,7 @@
if (t != 0 && doctx) {
/* Deal with any -A context */
if (tail > 0) {
- printline(&pc, '-');
+ grep_printline(&pc.ln, '-');
tail--;
if (Bflag > 0)
clearqueue();
@@ -590,7 +595,7 @@
if (bflag) {
if (printsep)
putchar(sep);
- printf("%lld", (long long)line->off);
+ printf("%lld", (long long)(line->off + line->boff));
printsep = true;
}
if (printsep)
@@ -615,13 +620,22 @@
/* --color and -o */
if ((oflag || color) && matchidx > 0) {
- printline_metadata(&pc->ln, sep);
+ /* Only print metadata once per line if --color */
+ if (!oflag && pc->printed == 0)
+ printline_metadata(&pc->ln, sep);
for (i = 0; i < matchidx; i++) {
match = pc->matches[i];
/* Don't output zero length matches */
if (match.rm_so == match.rm_eo)
continue;
- if (!oflag)
+ /*
+ * Metadata is printed on a per-line basis, so every
+ * match gets file metadata with the -o flag.
+ */
+ if (oflag) {
+ pc->ln.boff = match.rm_so;
+ printline_metadata(&pc->ln, sep);
+ } else
fwrite(pc->ln.dat + a, match.rm_so - a, 1,
stdout);
if (color)
@@ -642,4 +656,5 @@
}
} else
grep_printline(&pc->ln, sep);
+ pc->printed++;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 15, 12:59 PM (4 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27650915
Default Alt Text
D10580.id28250.diff (5 KB)
Attached To
Mode
D10580: bsdgrep(1): Correct line metadata printing (-b,-H,-n) on a per-line basis
Attached
Detach File
Event Timeline
Log In to Comment