From: shurizzle <me@shurizzle.dev>
To: 9front@9front.org
Subject: [9front] [PATCH] feat(grep): add -H flag
Date: Wed, 26 Jun 2024 02:24:38 +0000 [thread overview]
Message-ID: <mf5lbrqzlbwnf5ue54lunu3q3l2hndnuyurqihv373roy3qk35@mxokij7cd7ee> (raw)
-H is the opposite of -h.
When present, print the file name even if only one file is
passed in the parameters.
---
diff a71a76745b5fd2f3e50778268bc2cad262748416 db274004a40a00a08021473b568912c41d8a0cbb
--- a/sys/man/1/grep
+++ b/sys/man/1/grep
@@ -49,6 +49,9 @@
.B -h
Do not print file name tags (headers) with output lines.
.TP
+.B -H
+Print file name tags (headers) with output lines, even for a single file.
+.TP
.B -e
The following argument is taken as a
.IR pattern .
--- a/sys/src/cmd/grep/main.c
+++ b/sys/src/cmd/grep/main.c
@@ -1,7 +1,7 @@
#define EXTERN
#include "grep.h"
-char *validflags = "bchiLlnsv";
+char *validflags = "bchHiLlnsv";
void
usage(void)
{
@@ -12,8 +12,9 @@
void
main(int argc, char *argv[])
{
- int i, status;
+ int i, h, status;
+ h = 0;
ARGBEGIN {
default:
if(utfrune(validflags, ARGC()) == nil)
@@ -38,6 +39,12 @@
lineno = 1;
str2top(filename);
break;
+ case 'h':
+ h = -1;
+ break;
+ case 'H':
+ h = 1;
+ break;
} ARGEND
if(flags['f'] == 0 && flags['e'] == 0) {
@@ -57,12 +64,12 @@
status = search(0, 0);
break;
case 1:
- status = search(argv[0], 0);
+ status = search(argv[0], h > 0 ? Hflag : 0);
break;
default:
status = 0;
for(i=0; i<argc; i++)
- status |= search(argv[i], Hflag);
+ status |= search(argv[i], h < 0 ? 0 : Hflag);
break;
}
if(status)
@@ -94,8 +101,6 @@
flag |= Bflag; /* dont buffer output */
if(flags['c'])
flag |= Cflag; /* count */
- if(flags['h'])
- flag &= ~Hflag; /* do not print file name in output */
if(flags['i'])
flag |= Iflag; /* fold upper-lower */
if(flags['l'])
next reply other threads:[~2024-06-26 2:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-26 2:24 shurizzle [this message]
2024-06-26 4:56 ` Alex Musolino
2024-06-26 11:18 ` me
2024-06-26 13:49 ` Alex Musolino
2024-06-26 14:08 ` me
2024-06-26 16:31 ` Lyndon Nerenberg (VE7TFX/VE6BBM)
2024-06-26 16:35 ` Lyndon Nerenberg (VE7TFX/VE6BBM)
2024-06-27 20:11 ` Romano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=mf5lbrqzlbwnf5ue54lunu3q3l2hndnuyurqihv373roy3qk35@mxokij7cd7ee \
--to=me@shurizzle.dev \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).