grep: cleanup

This commit is contained in:
Connor Lane Smith 2011-06-04 12:00:23 +01:00
parent 763409841f
commit de221bc6f5

12
grep.c
View File

@ -8,8 +8,6 @@
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 vflag = false; static bool vflag = false;
static bool many; static bool many;
static bool match = false; static bool match = false;
@ -26,7 +24,7 @@ main(int argc, char *argv[])
while((c = getopt(argc, argv, "Ecilnqv")) != -1) while((c = getopt(argc, argv, "Ecilnqv")) != -1)
switch(c) { switch(c) {
case 'E': case 'E':
Eflag = true; flags |= REG_EXTENDED;
break; break;
case 'c': case 'c':
case 'l': case 'l':
@ -35,7 +33,7 @@ main(int argc, char *argv[])
mode = c; mode = c;
break; break;
case 'i': case 'i':
iflag = true; flags |= REG_ICASE;
break; break;
case 'v': case 'v':
vflag = true; vflag = true;
@ -44,13 +42,9 @@ main(int argc, char *argv[])
exit(2); exit(2);
} }
if(optind == argc) { if(optind == argc) {
fprintf(stderr, "usage: %s [-cilnqv] pattern [files...]\n", argv[0]); fprintf(stderr, "usage: %s [-Ecilnqv] pattern [files...]\n", argv[0]);
exit(2); exit(2);
} }
if(Eflag)
flags |= REG_EXTENDED;
if(iflag)
flags |= REG_ICASE;
regcomp(&preg, argv[optind++], flags); regcomp(&preg, argv[optind++], flags);
many = (argc > optind+1); many = (argc > optind+1);