sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 728f36aa77215b6ad919bbc6e13ff22cf3f81809
parent 5197affac58759205f648e523f730977fc3eae08
Author: sin <sin@2f30.org>
Date:   Thu, 20 Nov 2014 14:14:26 +0000

Implement grep -s

Diffstat:
Mgrep.1 | 5++++-
Mgrep.c | 19++++++++++++-------
2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/grep.1 b/grep.1 @@ -3,7 +3,7 @@ grep \- search files for a pattern .SH SYNOPSIS .B grep -.RB [ \-EHchilnqv ] +.RB [ \-EHchilnqsv ] .RB [ \-e .I pattern ] .I pattern @@ -53,6 +53,9 @@ prefixes each matching line with its line number in the input. .B \-q prints nothing, only returns status. .TP +.B \-s +Suppress the error messages ordinarily written for nonexistent or unreadable files. +.TP .B \-v selects lines which do .B not diff --git a/grep.c b/grep.c @@ -14,12 +14,13 @@ enum { Match = 0, NoMatch = 1, Error = 2 }; static void addpattern(const char *); static int grep(FILE *, const char *); -static int eflag = 0; -static int vflag = 0; -static int hflag = 0; -static int Hflag = 0; +static int Hflag; +static int eflag; +static int hflag; +static int sflag; +static int vflag; static int many; -static char mode = 0; +static char mode; struct pattern { char *pattern; @@ -32,7 +33,7 @@ static SLIST_HEAD(phead, pattern) phead; static void usage(void) { - enprintf(Error, "usage: %s [-EHcilnqv] [-e pattern] pattern [files...]\n", argv0); + enprintf(Error, "usage: %s [-EHcilnqsv] [-e pattern] pattern [files...]\n", argv0); } int @@ -67,6 +68,9 @@ main(int argc, char *argv[]) case 'i': flags |= REG_ICASE; break; + case 's': + sflag = 1; + break; case 'v': vflag = 1; break; @@ -93,7 +97,8 @@ main(int argc, char *argv[]) } else { for (i = 0; i < argc; i++) { if (!(fp = fopen(argv[i], "r"))) { - weprintf("fopen %s:", argv[i]); + if (!sflag) + weprintf("fopen %s:", argv[i]); match = Error; continue; }