summaryrefslogtreecommitdiff
path: root/findutils
diff options
context:
space:
mode:
authorEric Andersen2000-06-13 06:24:53 +0000
committerEric Andersen2000-06-13 06:24:53 +0000
commit053b1462b72feea51b3b8745662447d5f8d18fda (patch)
tree83edeea4d3913d4bbfab0fef6f46f5f4cbbd548c /findutils
parentbaf22bff21f91a8c715729892113c1bf5b7b8c4a (diff)
downloadbusybox-053b1462b72feea51b3b8745662447d5f8d18fda.zip
busybox-053b1462b72feea51b3b8745662447d5f8d18fda.tar.gz
Fix a bug pointed out by Michal Jaegermann <michal@ellpspace.math.ualberta.ca>
where you used to see: ./grep -q -i B some_file B: No such file or directory This is now fixed. -Erik
Diffstat (limited to 'findutils')
-rw-r--r--findutils/grep.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index bb1a146..1272a46 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -39,6 +39,9 @@
#include <signal.h>
#include <time.h>
#include <ctype.h>
+#define BB_DECLARE_EXTERN
+#define bb_need_too_few_args
+#include "messages.c"
static const char grep_usage[] =
"grep [OPTIONS]... PATTERN [FILE]...\n"
@@ -92,7 +95,6 @@ static void do_grep(FILE * fp, char *needle, char *fileName, int tellName,
extern int grep_main(int argc, char **argv)
{
FILE *fp;
- char *cp;
char *needle;
char *fileName;
int tellName = TRUE;
@@ -100,18 +102,14 @@ extern int grep_main(int argc, char **argv)
int tellLine = FALSE;
int invertSearch = FALSE;
- argc--;
- argv++;
if (argc < 1) {
usage(grep_usage);
}
+ argv++;
- if (**argv == '-') {
- argc--;
- cp = *argv++;
-
- while (*++cp)
- switch (*cp) {
+ while (--argc >= 0 && *argv && (**argv == '-')) {
+ while (*++(*argv)) {
+ switch (**argv) {
case 'i':
ignoreCase = TRUE;
break;
@@ -135,6 +133,12 @@ extern int grep_main(int argc, char **argv)
default:
usage(grep_usage);
}
+ }
+ argv++;
+ }
+
+ if (argc == 0 || *argv == NULL) {
+ fatalError(too_few_args, "grep");
}
needle = *argv++;