diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-10-12 22:26:06 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-10-12 22:26:06 +0000 |
commit | 3cf52d19581b2077480e7d2e63010baa1f5399c1 (patch) | |
tree | d91b0cb332ebc976126e36a394655dde7a15d8b1 /findutils/grep.c | |
parent | 2ce1edcf544ac675e6762c9861a6b918401ea716 (diff) | |
download | busybox-w32-3cf52d19581b2077480e7d2e63010baa1f5399c1.tar.gz busybox-w32-3cf52d19581b2077480e7d2e63010baa1f5399c1.tar.bz2 busybox-w32-3cf52d19581b2077480e7d2e63010baa1f5399c1.zip |
More stuff...
Diffstat (limited to 'findutils/grep.c')
-rw-r--r-- | findutils/grep.c | 144 |
1 files changed, 71 insertions, 73 deletions
diff --git a/findutils/grep.c b/findutils/grep.c index 52ef6c0fe..657bb2570 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -11,7 +11,6 @@ | |||
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include "internal.h" | 13 | #include "internal.h" |
14 | #ifdef BB_GREP | ||
15 | 14 | ||
16 | #include <stdio.h> | 15 | #include <stdio.h> |
17 | #include <dirent.h> | 16 | #include <dirent.h> |
@@ -31,7 +30,76 @@ const char grep_usage[] = | |||
31 | 30 | ||
32 | 31 | ||
33 | 32 | ||
34 | static int search (const char *string, const char *word, int ignoreCase); | 33 | /* |
34 | * See if the specified word is found in the specified string. | ||
35 | */ | ||
36 | static int search (const char *string, const char *word, int ignoreCase) | ||
37 | { | ||
38 | const char *cp1; | ||
39 | const char *cp2; | ||
40 | int len; | ||
41 | int lowFirst; | ||
42 | int ch1; | ||
43 | int ch2; | ||
44 | |||
45 | len = strlen (word); | ||
46 | |||
47 | if (!ignoreCase) { | ||
48 | while (TRUE) { | ||
49 | string = strchr (string, word[0]); | ||
50 | |||
51 | if (string == NULL) | ||
52 | return FALSE; | ||
53 | |||
54 | if (memcmp (string, word, len) == 0) | ||
55 | return TRUE; | ||
56 | |||
57 | string++; | ||
58 | } | ||
59 | } | ||
60 | |||
61 | /* | ||
62 | * Here if we need to check case independence. | ||
63 | * Do the search by lower casing both strings. | ||
64 | */ | ||
65 | lowFirst = *word; | ||
66 | |||
67 | if (isupper (lowFirst)) | ||
68 | lowFirst = tolower (lowFirst); | ||
69 | |||
70 | while (TRUE) { | ||
71 | while (*string && (*string != lowFirst) && | ||
72 | (!isupper (*string) || (tolower (*string) != lowFirst))) { | ||
73 | string++; | ||
74 | } | ||
75 | |||
76 | if (*string == '\0') | ||
77 | return FALSE; | ||
78 | |||
79 | cp1 = string; | ||
80 | cp2 = word; | ||
81 | |||
82 | do { | ||
83 | if (*cp2 == '\0') | ||
84 | return TRUE; | ||
85 | |||
86 | ch1 = *cp1++; | ||
87 | |||
88 | if (isupper (ch1)) | ||
89 | ch1 = tolower (ch1); | ||
90 | |||
91 | ch2 = *cp2++; | ||
92 | |||
93 | if (isupper (ch2)) | ||
94 | ch2 = tolower (ch2); | ||
95 | |||
96 | } | ||
97 | while (ch1 == ch2); | ||
98 | |||
99 | string++; | ||
100 | } | ||
101 | return (TRUE); | ||
102 | } | ||
35 | 103 | ||
36 | 104 | ||
37 | extern int grep_main (int argc, char **argv) | 105 | extern int grep_main (int argc, char **argv) |
@@ -122,76 +190,6 @@ extern int grep_main (int argc, char **argv) | |||
122 | } | 190 | } |
123 | 191 | ||
124 | 192 | ||
125 | /* | 193 | /* END CODE */ |
126 | * See if the specified word is found in the specified string. | ||
127 | */ | ||
128 | static int search (const char *string, const char *word, int ignoreCase) | ||
129 | { | ||
130 | const char *cp1; | ||
131 | const char *cp2; | ||
132 | int len; | ||
133 | int lowFirst; | ||
134 | int ch1; | ||
135 | int ch2; | ||
136 | |||
137 | len = strlen (word); | ||
138 | |||
139 | if (!ignoreCase) { | ||
140 | while (TRUE) { | ||
141 | string = strchr (string, word[0]); | ||
142 | |||
143 | if (string == NULL) | ||
144 | return FALSE; | ||
145 | |||
146 | if (memcmp (string, word, len) == 0) | ||
147 | return TRUE; | ||
148 | |||
149 | string++; | ||
150 | } | ||
151 | } | ||
152 | |||
153 | /* | ||
154 | * Here if we need to check case independence. | ||
155 | * Do the search by lower casing both strings. | ||
156 | */ | ||
157 | lowFirst = *word; | ||
158 | |||
159 | if (isupper (lowFirst)) | ||
160 | lowFirst = tolower (lowFirst); | ||
161 | |||
162 | while (TRUE) { | ||
163 | while (*string && (*string != lowFirst) && | ||
164 | (!isupper (*string) || (tolower (*string) != lowFirst))) { | ||
165 | string++; | ||
166 | } | ||
167 | |||
168 | if (*string == '\0') | ||
169 | return FALSE; | ||
170 | |||
171 | cp1 = string; | ||
172 | cp2 = word; | ||
173 | |||
174 | do { | ||
175 | if (*cp2 == '\0') | ||
176 | return TRUE; | ||
177 | |||
178 | ch1 = *cp1++; | ||
179 | |||
180 | if (isupper (ch1)) | ||
181 | ch1 = tolower (ch1); | ||
182 | |||
183 | ch2 = *cp2++; | ||
184 | |||
185 | if (isupper (ch2)) | ||
186 | ch2 = tolower (ch2); | ||
187 | |||
188 | } | ||
189 | while (ch1 == ch2); | ||
190 | 194 | ||
191 | string++; | ||
192 | } | ||
193 | return (TRUE); | ||
194 | } | ||
195 | 195 | ||
196 | #endif | ||
197 | /* END CODE */ | ||