9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] grep: always show path with '-n'
@ 2022-02-02 23:01 ori
  2022-02-03  5:14 ` unobe
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: ori @ 2022-02-02 23:01 UTC (permalink / raw)
  To: 9front

With the new 'g', I noticed that sometimes
we'd fail to show the filename; this happens
because 'g' now uses xargs, and if there's
exactly one file picked up by xargs, the
Hflag does not get set.

This change makes grep now print the filename
if Hflag *or* Nflag is set, which is what I'd
expect.

Before:

	% grep -n -- Nflag main.c
	106: 		flag |= Nflag;		/* count only */

After:

	% grep -n -- Nflag main.c
	main.c:106: 		flag |= Nflag;		/* count only */

And it still does something sensible for stdin:

	% grep -n asdf
	asdf
	stdin:1: asdf

Does this make sense to people?


diff 251c3cfd610abd169676852d301a2aa1267c0e57 uncommitted
--- a/sys/src/cmd/grep/main.c
+++ b/sys/src/cmd/grep/main.c
@@ -180,7 +180,7 @@
 			count++;
 			if(flag & (Cflag|Sflag|Llflag|LLflag))
 				goto cont;
-			if(flag & Hflag)
+			if(flag & (Hflag|Nflag))
 				Bprint(&bout, "%s:", file);
 			if(flag & Nflag)
 				Bprint(&bout, "%ld: ", lineno);
@@ -219,7 +219,7 @@
 			count++;
 			if(flag & (Cflag|Sflag|Llflag|LLflag))
 				goto conti;
-			if(flag & Hflag)
+			if(flag & (Hflag|Nflag))
 				Bprint(&bout, "%s:", file);
 			if(flag & Nflag)
 				Bprint(&bout, "%ld: ", lineno);


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-02-05 19:12 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-02 23:01 [9front] grep: always show path with '-n' ori
2022-02-03  5:14 ` unobe
2022-02-03  7:04 ` Steve Simon
2022-02-03 16:47   ` ori
2022-02-03 19:04     ` Nicola Girardi
2022-02-04  0:47       ` ori
2022-02-04  0:48       ` ori
2022-02-04 22:00         ` Nicola Girardi
2022-02-05 16:57           ` hiro
2022-02-05 17:06             ` Stanley Lieber
2022-02-05 18:00               ` hiro
2022-02-04 12:39       ` Alex Musolino
2022-02-05  4:58 ` 有澤 健治

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).