diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-11-08 17:00:52 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-11-08 17:00:52 +0000 |
commit | fbb39c83b69d6c4de943c0b7374000339635d13d (patch) | |
tree | 874ba86bb5753f4afd5a770308df9e555c78cf90 /findutils/grep.c | |
parent | 07e5297ca7707d2fd56ab2fa8e1ea0c9805035e3 (diff) | |
download | busybox-w32-fbb39c83b69d6c4de943c0b7374000339635d13d.tar.gz busybox-w32-fbb39c83b69d6c4de943c0b7374000339635d13d.tar.bz2 busybox-w32-fbb39c83b69d6c4de943c0b7374000339635d13d.zip |
Stuff
-Erik
Diffstat (limited to 'findutils/grep.c')
-rw-r--r-- | findutils/grep.c | 59 |
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[] = | |||
43 | "This version of grep matches strings (not full regexps).\n"; | 43 | "This version of grep matches strings (not full regexps).\n"; |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | int tellName=TRUE; | ||
47 | int ignoreCase=FALSE; | ||
48 | int tellLine=FALSE; | ||
49 | |||
50 | static do_grep(char* needle, char* haystack ) | ||
51 | { | ||
52 | line = 0; | ||
53 | |||
54 | while (fgets (haystack, sizeof (haystack), fp)) { | ||
55 | line++; | ||
56 | cp = &haystack[strlen (haystack) - 1]; | ||
57 | |||
58 | if (*cp != '\n') | ||
59 | fprintf (stderr, "%s: Line too long\n", name); | ||
60 | |||
61 | if (find_match(haystack, needle, ignoreCase) == TRUE) { | ||
62 | if (tellName==TRUE) | ||
63 | printf ("%s: ", name); | ||
64 | |||
65 | if (tellLine==TRUE) | ||
66 | printf ("%ld: ", line); | ||
67 | |||
68 | fputs (haystack, stdout); | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | |||
46 | 73 | ||
47 | extern int grep_main (int argc, char **argv) | 74 | extern int grep_main (int argc, char **argv) |
48 | { | 75 | { |
@@ -50,9 +77,6 @@ extern int grep_main (int argc, char **argv) | |||
50 | char *needle; | 77 | char *needle; |
51 | char *name; | 78 | char *name; |
52 | char *cp; | 79 | char *cp; |
53 | int tellName=TRUE; | ||
54 | int ignoreCase=FALSE; | ||
55 | int tellLine=FALSE; | ||
56 | long line; | 80 | long line; |
57 | char haystack[BUF_SIZE]; | 81 | char haystack[BUF_SIZE]; |
58 | 82 | ||
@@ -91,7 +115,16 @@ extern int grep_main (int argc, char **argv) | |||
91 | needle = *argv++; | 115 | needle = *argv++; |
92 | argc--; | 116 | argc--; |
93 | 117 | ||
118 | |||
94 | while (argc-- > 0) { | 119 | while (argc-- > 0) { |
120 | |||
121 | if (argc==0) { | ||
122 | file = stdin; | ||
123 | } | ||
124 | else | ||
125 | file = fopen(*argv, "r"); | ||
126 | |||
127 | |||
95 | name = *argv++; | 128 | name = *argv++; |
96 | 129 | ||
97 | fp = fopen (name, "r"); | 130 | fp = fopen (name, "r"); |
@@ -100,26 +133,6 @@ extern int grep_main (int argc, char **argv) | |||
100 | continue; | 133 | continue; |
101 | } | 134 | } |
102 | 135 | ||
103 | line = 0; | ||
104 | |||
105 | while (fgets (haystack, sizeof (haystack), fp)) { | ||
106 | line++; | ||
107 | cp = &haystack[strlen (haystack) - 1]; | ||
108 | |||
109 | if (*cp != '\n') | ||
110 | fprintf (stderr, "%s: Line too long\n", name); | ||
111 | |||
112 | if (find_match(haystack, needle, ignoreCase) == TRUE) { | ||
113 | if (tellName==TRUE) | ||
114 | printf ("%s: ", name); | ||
115 | |||
116 | if (tellLine==TRUE) | ||
117 | printf ("%ld: ", line); | ||
118 | |||
119 | fputs (haystack, stdout); | ||
120 | } | ||
121 | } | ||
122 | |||
123 | if (ferror (fp)) | 136 | if (ferror (fp)) |
124 | perror (name); | 137 | perror (name); |
125 | 138 | ||