[hackers] [sbase] Properly handle -F and -i || sin
commit f4d8ff9598ed8d57bd3c73748b3077ccae4a8f88
Author: sin <sin_AT_2f30.org>
Date: Thu Nov 20 17:38:31 2014 +0000
Properly handle -F and -i
diff --git a/grep.c b/grep.c
index b2c41b7..1c28928 100644
--- a/grep.c
+++ b/grep.c
_AT_@ -20,6 +20,7 @@ static int Hflag;
static int eflag;
static int fflag;
static int hflag;
+static int iflag;
static int sflag;
static int vflag;
static int xflag;
_AT_@ -78,6 +79,7 @@ main(int argc, char *argv[])
break;
case 'i':
flags |= REG_ICASE;
+ iflag = 1;
break;
case 's':
sflag = 1;
_AT_@ -197,10 +199,17 @@ grep(FILE *fp, const char *str)
if (regexec(&pnode->preg, buf, 0, NULL, 0) ^ vflag)
continue;
} else {
- if (!xflag)
- match = strstr(buf, pnode->pattern) ? Match : NoMatch;
- else
- match = strcmp(buf, pnode->pattern);
+ if (!xflag) {
+ if ((iflag ? strcasestr : strstr)(buf, pnode->pattern))
+ match = Match;
+ else
+ match = NoMatch;
+ } else {
+ if (!(iflag ? strcasecmp : strcmp)(buf, pnode->pattern))
+ match = Match;
+ else
+ match = NoMatch;
+ }
if (match ^ vflag)
continue;
}
Received on Thu Nov 20 2014 - 18:40:51 CET
This archive was generated by hypermail 2.3.0
: Thu Nov 20 2014 - 18:48:19 CET