for helping track this one down.
* More doc updates
* 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
#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"
extern int grep_main(int argc, char **argv)
{
FILE *fp;
- char *cp;
char *needle;
char *fileName;
int tellName = TRUE;
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;
default:
usage(grep_usage);
}
+ }
+ argv++;
+ }
+
+ if (argc == 0 || *argv == NULL) {
+ fatalError(too_few_args, "grep");
}
needle = *argv++;
#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"
extern int grep_main(int argc, char **argv)
{
FILE *fp;
- char *cp;
char *needle;
char *fileName;
int tellName = TRUE;
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;
default:
usage(grep_usage);
}
+ }
+ argv++;
+ }
+
+ if (argc == 0 || *argv == NULL) {
+ fatalError(too_few_args, "grep");
}
needle = *argv++;