Properly handle -F and -i
This commit is contained in:
parent
64aac9b504
commit
f4d8ff9598
17
grep.c
17
grep.c
|
@ -20,6 +20,7 @@ static int Hflag;
|
||||||
static int eflag;
|
static int eflag;
|
||||||
static int fflag;
|
static int fflag;
|
||||||
static int hflag;
|
static int hflag;
|
||||||
|
static int iflag;
|
||||||
static int sflag;
|
static int sflag;
|
||||||
static int vflag;
|
static int vflag;
|
||||||
static int xflag;
|
static int xflag;
|
||||||
|
@ -78,6 +79,7 @@ main(int argc, char *argv[])
|
||||||
break;
|
break;
|
||||||
case 'i':
|
case 'i':
|
||||||
flags |= REG_ICASE;
|
flags |= REG_ICASE;
|
||||||
|
iflag = 1;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
sflag = 1;
|
sflag = 1;
|
||||||
|
@ -197,10 +199,17 @@ grep(FILE *fp, const char *str)
|
||||||
if (regexec(&pnode->preg, buf, 0, NULL, 0) ^ vflag)
|
if (regexec(&pnode->preg, buf, 0, NULL, 0) ^ vflag)
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
if (!xflag)
|
if (!xflag) {
|
||||||
match = strstr(buf, pnode->pattern) ? Match : NoMatch;
|
if ((iflag ? strcasestr : strstr)(buf, pnode->pattern))
|
||||||
else
|
match = Match;
|
||||||
match = strcmp(buf, pnode->pattern);
|
else
|
||||||
|
match = NoMatch;
|
||||||
|
} else {
|
||||||
|
if (!(iflag ? strcasecmp : strcmp)(buf, pnode->pattern))
|
||||||
|
match = Match;
|
||||||
|
else
|
||||||
|
match = NoMatch;
|
||||||
|
}
|
||||||
if (match ^ vflag)
|
if (match ^ vflag)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user