|
|
|
@ -17,6 +17,7 @@ static int dflag;
|
|
|
|
|
static int iflag;
|
|
|
|
|
static int qflag;
|
|
|
|
|
static int vflag;
|
|
|
|
|
static long mflag;
|
|
|
|
|
static long matches;
|
|
|
|
|
|
|
|
|
|
static regex_t pattern;
|
|
|
|
@ -29,9 +30,11 @@ match(char *file, char *s)
|
|
|
|
|
if (vflag ^ (regexec(&pattern, s, 0, 0, 0) == 0)) {
|
|
|
|
|
if (qflag)
|
|
|
|
|
exit(0);
|
|
|
|
|
matches++;
|
|
|
|
|
if (!cflag)
|
|
|
|
|
printf("%s\n", file);
|
|
|
|
|
matches++;
|
|
|
|
|
if (mflag && matches >= mflag)
|
|
|
|
|
exit(0);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -126,18 +129,19 @@ int
|
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
int c;
|
|
|
|
|
while ((c = getopt(argc, argv, "acdiqv")) != -1)
|
|
|
|
|
while ((c = getopt(argc, argv, "acdim:qv")) != -1)
|
|
|
|
|
switch(c) {
|
|
|
|
|
case 'a': aflag = 1; break;
|
|
|
|
|
case 'c': cflag = 1; break;
|
|
|
|
|
case 'd': dflag = 1; break;
|
|
|
|
|
case 'i': iflag = REG_ICASE; break;
|
|
|
|
|
case 'm': mflag = atol(optarg); break;
|
|
|
|
|
case 'q': qflag = 1; break;
|
|
|
|
|
case 'v': vflag = 1; break;
|
|
|
|
|
default:
|
|
|
|
|
usage:
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Usage: magrep [-c|-q] [-v] [-i] [-a|-d] header:regex [msgs...]\n");
|
|
|
|
|
"Usage: magrep [-c|-q|-m max] [-v] [-i] [-a|-d] header:regex [msgs...]\n");
|
|
|
|
|
exit(2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -163,7 +167,7 @@ main(int argc, char *argv[])
|
|
|
|
|
else
|
|
|
|
|
blaze822_loop(argc-optind, argv+optind, magrep);
|
|
|
|
|
|
|
|
|
|
if (cflag)
|
|
|
|
|
if (cflag && !qflag && !mflag)
|
|
|
|
|
printf("%ld\n", matches);
|
|
|
|
|
|
|
|
|
|
return !matches;
|
|
|
|
|