This commit is contained in:
Connor Lane Smith 2011-06-04 11:57:31 +01:00
parent e565522068
commit 763409841f
2 changed files with 11 additions and 2 deletions

5
grep.1
View File

@ -3,7 +3,7 @@
grep \- search files for a pattern
.SH SYNOPSIS
.B grep
.RB [ \-cilnqv ]
.RB [ \-Ecilnqv ]
.I pattern
.RI [ file ...]
.SH DESCRIPTION
@ -17,6 +17,9 @@ The status code is 0 if any lines match, and 1 if not. If an error occurred the
status code is 2.
.SH OPTIONS
.TP
.B \-E
matches using extended regex.
.TP
.B \-c
prints only a count of matching lines.
.TP

8
grep.c
View File

@ -8,6 +8,7 @@
static void grep(FILE *, const char *, regex_t *);
static bool Eflag = false;
static bool iflag = false;
static bool vflag = false;
static bool many;
@ -22,8 +23,11 @@ main(int argc, char *argv[])
regex_t preg;
FILE *fp;
while((c = getopt(argc, argv, "cilnqv")) != -1)
while((c = getopt(argc, argv, "Ecilnqv")) != -1)
switch(c) {
case 'E':
Eflag = true;
break;
case 'c':
case 'l':
case 'n':
@ -43,6 +47,8 @@ main(int argc, char *argv[])
fprintf(stderr, "usage: %s [-cilnqv] pattern [files...]\n", argv[0]);
exit(2);
}
if(Eflag)
flags |= REG_EXTENDED;
if(iflag)
flags |= REG_ICASE;
regcomp(&preg, argv[optind++], flags);