Implement grep -s
This commit is contained in:
parent
5197affac5
commit
728f36aa77
5
grep.1
5
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
|
||||
|
|
17
grep.c
17
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,6 +97,7 @@ main(int argc, char *argv[])
|
|||
} else {
|
||||
for (i = 0; i < argc; i++) {
|
||||
if (!(fp = fopen(argv[i], "r"))) {
|
||||
if (!sflag)
|
||||
weprintf("fopen %s:", argv[i]);
|
||||
match = Error;
|
||||
continue;
|
||||
|
|
Loading…
Reference in New Issue
Block a user