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 grep \- search files for a pattern
.SH SYNOPSIS .SH SYNOPSIS
.B grep .B grep
.RB [ \-cilnqv ] .RB [ \-Ecilnqv ]
.I pattern .I pattern
.RI [ file ...] .RI [ file ...]
.SH DESCRIPTION .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. status code is 2.
.SH OPTIONS .SH OPTIONS
.TP .TP
.B \-E
matches using extended regex.
.TP
.B \-c .B \-c
prints only a count of matching lines. prints only a count of matching lines.
.TP .TP

8
grep.c
View File

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