summaryrefslogtreecommitdiff
path: root/findutils
diff options
context:
space:
mode:
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 9495bf8..50a2961 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);