aboutsummaryrefslogtreecommitdiff
path: root/findutils
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-11-08 17:00:52 +0000
committerEric Andersen <andersen@codepoet.org>1999-11-08 17:00:52 +0000
commitfbb39c83b69d6c4de943c0b7374000339635d13d (patch)
tree874ba86bb5753f4afd5a770308df9e555c78cf90 /findutils
parent07e5297ca7707d2fd56ab2fa8e1ea0c9805035e3 (diff)
downloadbusybox-fbb39c83b69d6c4de943c0b7374000339635d13d.tar.gz
Stuff
-Erik
Diffstat (limited to 'findutils')
-rw-r--r--findutils/grep.c59
1 files changed, 36 insertions, 23 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index 9495bf858..50a296178 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -43,6 +43,33 @@ static const char grep_usage[] =
"This version of grep matches strings (not full regexps).\n";
#endif
+int tellName=TRUE;
+int ignoreCase=FALSE;
+int tellLine=FALSE;
+
+static do_grep(char* needle, char* haystack )
+{
+ line = 0;
+
+ while (fgets (haystack, sizeof (haystack), fp)) {
+ line++;
+ cp = &haystack[strlen (haystack) - 1];
+
+ if (*cp != '\n')
+ fprintf (stderr, "%s: Line too long\n", name);
+
+ if (find_match(haystack, needle, ignoreCase) == TRUE) {
+ if (tellName==TRUE)
+ printf ("%s: ", name);
+
+ if (tellLine==TRUE)
+ printf ("%ld: ", line);
+
+ fputs (haystack, stdout);
+ }
+ }
+}
+
extern int grep_main (int argc, char **argv)
{
@@ -50,9 +77,6 @@ extern int grep_main (int argc, char **argv)
char *needle;
char *name;
char *cp;
- int tellName=TRUE;
- int ignoreCase=FALSE;
- int tellLine=FALSE;
long line;
char haystack[BUF_SIZE];
@@ -91,7 +115,16 @@ extern int grep_main (int argc, char **argv)
needle = *argv++;
argc--;
+
while (argc-- > 0) {
+
+ if (argc==0) {
+ file = stdin;
+ }
+ else
+ file = fopen(*argv, "r");
+
+
name = *argv++;
fp = fopen (name, "r");
@@ -100,26 +133,6 @@ extern int grep_main (int argc, char **argv)
continue;
}
- line = 0;
-
- while (fgets (haystack, sizeof (haystack), fp)) {
- line++;
- cp = &haystack[strlen (haystack) - 1];
-
- if (*cp != '\n')
- fprintf (stderr, "%s: Line too long\n", name);
-
- if (find_match(haystack, needle, ignoreCase) == TRUE) {
- if (tellName==TRUE)
- printf ("%s: ", name);
-
- if (tellLine==TRUE)
- printf ("%ld: ", line);
-
- fputs (haystack, stdout);
- }
- }
-
if (ferror (fp))
perror (name);