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
This commit is contained in:
parent
baf22bff21
commit
053b1462b7
@ -78,6 +78,7 @@
|
|||||||
for helping track this one down.
|
for helping track this one down.
|
||||||
* More doc updates
|
* More doc updates
|
||||||
* Fixed grep "Line too long" problem -- John Beppu
|
* Fixed grep "Line too long" problem -- John Beppu
|
||||||
|
* Fixed 'grep -q -i B some_file' so it works
|
||||||
* math takes input from stdin if no args are given. -- John Beppu
|
* math takes input from stdin if no args are given. -- John Beppu
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,6 +39,9 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#define BB_DECLARE_EXTERN
|
||||||
|
#define bb_need_too_few_args
|
||||||
|
#include "messages.c"
|
||||||
|
|
||||||
static const char grep_usage[] =
|
static const char grep_usage[] =
|
||||||
"grep [OPTIONS]... PATTERN [FILE]...\n"
|
"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)
|
extern int grep_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *cp;
|
|
||||||
char *needle;
|
char *needle;
|
||||||
char *fileName;
|
char *fileName;
|
||||||
int tellName = TRUE;
|
int tellName = TRUE;
|
||||||
@ -100,18 +102,14 @@ extern int grep_main(int argc, char **argv)
|
|||||||
int tellLine = FALSE;
|
int tellLine = FALSE;
|
||||||
int invertSearch = FALSE;
|
int invertSearch = FALSE;
|
||||||
|
|
||||||
argc--;
|
|
||||||
argv++;
|
|
||||||
if (argc < 1) {
|
if (argc < 1) {
|
||||||
usage(grep_usage);
|
usage(grep_usage);
|
||||||
}
|
}
|
||||||
|
argv++;
|
||||||
|
|
||||||
if (**argv == '-') {
|
while (--argc >= 0 && *argv && (**argv == '-')) {
|
||||||
argc--;
|
while (*++(*argv)) {
|
||||||
cp = *argv++;
|
switch (**argv) {
|
||||||
|
|
||||||
while (*++cp)
|
|
||||||
switch (*cp) {
|
|
||||||
case 'i':
|
case 'i':
|
||||||
ignoreCase = TRUE;
|
ignoreCase = TRUE;
|
||||||
break;
|
break;
|
||||||
@ -136,6 +134,12 @@ extern int grep_main(int argc, char **argv)
|
|||||||
usage(grep_usage);
|
usage(grep_usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
argv++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc == 0 || *argv == NULL) {
|
||||||
|
fatalError(too_few_args, "grep");
|
||||||
|
}
|
||||||
|
|
||||||
needle = *argv++;
|
needle = *argv++;
|
||||||
argc--;
|
argc--;
|
||||||
|
22
grep.c
22
grep.c
@ -39,6 +39,9 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#define BB_DECLARE_EXTERN
|
||||||
|
#define bb_need_too_few_args
|
||||||
|
#include "messages.c"
|
||||||
|
|
||||||
static const char grep_usage[] =
|
static const char grep_usage[] =
|
||||||
"grep [OPTIONS]... PATTERN [FILE]...\n"
|
"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)
|
extern int grep_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char *cp;
|
|
||||||
char *needle;
|
char *needle;
|
||||||
char *fileName;
|
char *fileName;
|
||||||
int tellName = TRUE;
|
int tellName = TRUE;
|
||||||
@ -100,18 +102,14 @@ extern int grep_main(int argc, char **argv)
|
|||||||
int tellLine = FALSE;
|
int tellLine = FALSE;
|
||||||
int invertSearch = FALSE;
|
int invertSearch = FALSE;
|
||||||
|
|
||||||
argc--;
|
|
||||||
argv++;
|
|
||||||
if (argc < 1) {
|
if (argc < 1) {
|
||||||
usage(grep_usage);
|
usage(grep_usage);
|
||||||
}
|
}
|
||||||
|
argv++;
|
||||||
|
|
||||||
if (**argv == '-') {
|
while (--argc >= 0 && *argv && (**argv == '-')) {
|
||||||
argc--;
|
while (*++(*argv)) {
|
||||||
cp = *argv++;
|
switch (**argv) {
|
||||||
|
|
||||||
while (*++cp)
|
|
||||||
switch (*cp) {
|
|
||||||
case 'i':
|
case 'i':
|
||||||
ignoreCase = TRUE;
|
ignoreCase = TRUE;
|
||||||
break;
|
break;
|
||||||
@ -136,6 +134,12 @@ extern int grep_main(int argc, char **argv)
|
|||||||
usage(grep_usage);
|
usage(grep_usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
argv++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc == 0 || *argv == NULL) {
|
||||||
|
fatalError(too_few_args, "grep");
|
||||||
|
}
|
||||||
|
|
||||||
needle = *argv++;
|
needle = *argv++;
|
||||||
argc--;
|
argc--;
|
||||||
|
Loading…
Reference in New Issue
Block a user