[hackers] [sbase] Implement grep -s || sin

From: <git_AT_suckless.org>
Date: Thu, 20 Nov 2014 15:14:59 +0100

commit 728f36aa77215b6ad919bbc6e13ff22cf3f81809
Author: sin <sin_AT_2f30.org>
Date: Thu Nov 20 14:14:26 2014 +0000

    Implement grep -s

diff --git a/grep.1 b/grep.1
index 9a593ad..9971fb2 100644
--- a/grep.1
+++ b/grep.1
_AT_@ -3,7 +3,7 @@
 grep \- search files for a pattern
 .SH SYNOPSIS
 .B grep
-.RB [ \-EHchilnqv ]
+.RB [ \-EHchilnqsv ]
 .RB [ \-e
 .I pattern ]
 .I pattern
_AT_@ -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
index 08d0b0a..8c4ea7d 100644
--- a/grep.c
+++ b/grep.c
_AT_@ -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;
_AT_@ -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
_AT_@ -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;
_AT_@ -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;
                         }
Received on Thu Nov 20 2014 - 15:14:59 CET

This archive was generated by hypermail 2.3.0 : Thu Nov 20 2014 - 15:24:19 CET