[hackers] [sbase] grep: add -h (inverse of -H) aswell || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Mon, 17 Nov 2014 11:05:15 +0100

commit f6552e36691c27c147aaafe3be9eb6011eef728f
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Sun Nov 16 20:03:25 2014 +0100

    grep: add -h (inverse of -H) aswell

diff --git a/grep.1 b/grep.1
index 8fad4e5..9a593ad 100644
--- a/grep.1
+++ b/grep.1
_AT_@ -3,7 +3,7 @@
 grep \- search files for a pattern
 .SH SYNOPSIS
 .B grep
-.RB [ \-EHcilnqv ]
+.RB [ \-EHchilnqv ]
 .RB [ \-e
 .I pattern ]
 .I pattern
_AT_@ -38,6 +38,9 @@ This option is most useful when multiple -e options are used to
 specify multiple patterns, or when a pattern begins with a dash
 (`-').
 .TP
+.B \-h
+do not prefix each line with 'filename:' prefix.
+.TP
 .B \-i
 matches lines case insensitively.
 .TP
diff --git a/grep.c b/grep.c
index 6c6215d..b2bf051 100644
--- a/grep.c
+++ b/grep.c
_AT_@ -16,6 +16,7 @@ static int grep(FILE *, const char *);
 
 static int eflag = 0;
 static int vflag = 0;
+static int hflag = 0;
 static int Hflag = 0;
 static int many;
 static char mode = 0;
_AT_@ -54,6 +55,9 @@ main(int argc, char *argv[])
                 addpattern(EARGF(usage()));
                 eflag = 1;
                 break;
+ case 'h':
+ hflag = 1;
+ break;
         case 'c':
         case 'l':
         case 'n':
_AT_@ -145,7 +149,7 @@ grep(FILE *fp, const char *str)
                         case 'q':
                                 exit(Match);
                         default:
- if (many || Hflag)
+ if (!hflag && (many || Hflag))
                                         printf("%s:", str);
                                 if (mode == 'n')
                                         printf("%ld:", n);
Received on Mon Nov 17 2014 - 11:05:15 CET

This archive was generated by hypermail 2.3.0 : Mon Nov 17 2014 - 11:12:13 CET