Added grep -q, thanks to a patch from "Konstantin Boldyshev" <konst@voshod.com>
-Erik
This commit is contained in:
parent
d387d01f11
commit
3fe2ecf0d9
@ -7,6 +7,8 @@
|
|||||||
* Fixed the embarrasing failure of the -p opition in the logger app. -erik
|
* Fixed the embarrasing failure of the -p opition in the logger app. -erik
|
||||||
* Re-worked the whole source tree a bit so it will compile under glibc 2.0.7
|
* Re-worked the whole source tree a bit so it will compile under glibc 2.0.7
|
||||||
with the 2.0.x Linux kernel.
|
with the 2.0.x Linux kernel.
|
||||||
|
* Added 'grep -q' thanks to a patch from "Konstantin Boldyshev"
|
||||||
|
<konst@voshod.com>.
|
||||||
|
|
||||||
-Erik Andersen
|
-Erik Andersen
|
||||||
|
|
||||||
|
@ -21,6 +21,14 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
18-Dec-1999 Konstantin Boldyshev <konst@voshod.com>
|
||||||
|
|
||||||
|
+ -q option (be quiet)
|
||||||
|
+ exit code depending on grep result (TRUE or FALSE)
|
||||||
|
(useful for scripts)
|
||||||
|
*/
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "regexp.h"
|
#include "regexp.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -37,13 +45,15 @@ static const char grep_usage[] =
|
|||||||
"OPTIONS:\n"
|
"OPTIONS:\n"
|
||||||
"\t-h\tsuppress the prefixing filename on output\n"
|
"\t-h\tsuppress the prefixing filename on output\n"
|
||||||
"\t-i\tignore case distinctions\n"
|
"\t-i\tignore case distinctions\n"
|
||||||
"\t-n\tprint line number with output lines\n\n"
|
"\t-n\tprint line number with output lines\n"
|
||||||
|
"\t-q\tbe quiet\n\n"
|
||||||
#if defined BB_REGEXP
|
#if defined BB_REGEXP
|
||||||
"This version of grep matches full regular expresions.\n";
|
"This version of grep matches full regular expresions.\n";
|
||||||
#else
|
#else
|
||||||
"This version of grep matches strings (not regular expresions).\n";
|
"This version of grep matches strings (not regular expresions).\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int match = FALSE, beQuiet = FALSE;
|
||||||
|
|
||||||
static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine)
|
static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine)
|
||||||
{
|
{
|
||||||
@ -65,7 +75,10 @@ static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ig
|
|||||||
if (tellLine==TRUE)
|
if (tellLine==TRUE)
|
||||||
printf ("%ld:", line);
|
printf ("%ld:", line);
|
||||||
|
|
||||||
|
if (beQuiet==FALSE)
|
||||||
fputs (haystack, stdout);
|
fputs (haystack, stdout);
|
||||||
|
|
||||||
|
match = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,6 +122,10 @@ extern int grep_main (int argc, char **argv)
|
|||||||
tellLine = TRUE;
|
tellLine = TRUE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'q':
|
||||||
|
beQuiet = TRUE;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
usage(grep_usage);
|
usage(grep_usage);
|
||||||
}
|
}
|
||||||
@ -136,7 +153,7 @@ extern int grep_main (int argc, char **argv)
|
|||||||
fclose (fp);
|
fclose (fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exit( TRUE);
|
exit(match);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
21
grep.c
21
grep.c
@ -21,6 +21,14 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
18-Dec-1999 Konstantin Boldyshev <konst@voshod.com>
|
||||||
|
|
||||||
|
+ -q option (be quiet)
|
||||||
|
+ exit code depending on grep result (TRUE or FALSE)
|
||||||
|
(useful for scripts)
|
||||||
|
*/
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "regexp.h"
|
#include "regexp.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -37,13 +45,15 @@ static const char grep_usage[] =
|
|||||||
"OPTIONS:\n"
|
"OPTIONS:\n"
|
||||||
"\t-h\tsuppress the prefixing filename on output\n"
|
"\t-h\tsuppress the prefixing filename on output\n"
|
||||||
"\t-i\tignore case distinctions\n"
|
"\t-i\tignore case distinctions\n"
|
||||||
"\t-n\tprint line number with output lines\n\n"
|
"\t-n\tprint line number with output lines\n"
|
||||||
|
"\t-q\tbe quiet\n\n"
|
||||||
#if defined BB_REGEXP
|
#if defined BB_REGEXP
|
||||||
"This version of grep matches full regular expresions.\n";
|
"This version of grep matches full regular expresions.\n";
|
||||||
#else
|
#else
|
||||||
"This version of grep matches strings (not regular expresions).\n";
|
"This version of grep matches strings (not regular expresions).\n";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int match = FALSE, beQuiet = FALSE;
|
||||||
|
|
||||||
static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine)
|
static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine)
|
||||||
{
|
{
|
||||||
@ -65,7 +75,10 @@ static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ig
|
|||||||
if (tellLine==TRUE)
|
if (tellLine==TRUE)
|
||||||
printf ("%ld:", line);
|
printf ("%ld:", line);
|
||||||
|
|
||||||
|
if (beQuiet==FALSE)
|
||||||
fputs (haystack, stdout);
|
fputs (haystack, stdout);
|
||||||
|
|
||||||
|
match = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,6 +122,10 @@ extern int grep_main (int argc, char **argv)
|
|||||||
tellLine = TRUE;
|
tellLine = TRUE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'q':
|
||||||
|
beQuiet = TRUE;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
usage(grep_usage);
|
usage(grep_usage);
|
||||||
}
|
}
|
||||||
@ -136,7 +153,7 @@ extern int grep_main (int argc, char **argv)
|
|||||||
fclose (fp);
|
fclose (fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exit( TRUE);
|
exit(match);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user