diff options
author | Eric Andersen | 1999-10-12 22:26:06 +0000 |
---|---|---|
committer | Eric Andersen | 1999-10-12 22:26:06 +0000 |
commit | 3cf52d19581b2077480e7d2e63010baa1f5399c1 (patch) | |
tree | d91b0cb332ebc976126e36a394655dde7a15d8b1 /findutils | |
parent | 2ce1edcf544ac675e6762c9861a6b918401ea716 (diff) | |
download | busybox-3cf52d19581b2077480e7d2e63010baa1f5399c1.zip busybox-3cf52d19581b2077480e7d2e63010baa1f5399c1.tar.gz |
More stuff...
Diffstat (limited to 'findutils')
-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 52ef6c0..657bb25 100644 --- a/findutils/grep.c +++ b/findutils/grep.c @@ -11,7 +11,6 @@ */ #include "internal.h" -#ifdef BB_GREP #include <stdio.h> #include <dirent.h> @@ -31,7 +30,76 @@ const char grep_usage[] = -static int search (const char *string, const char *word, int ignoreCase); +/* + * See if the specified word is found in the specified string. + */ +static int search (const char *string, const char *word, int ignoreCase) +{ + const char *cp1; + const char *cp2; + int len; + int lowFirst; + int ch1; + int ch2; + + len = strlen (word); + + if (!ignoreCase) { + while (TRUE) { + string = strchr (string, word[0]); + + if (string == NULL) + return FALSE; + + if (memcmp (string, word, len) == 0) + return TRUE; + + string++; + } + } + + /* + * Here if we need to check case independence. + * Do the search by lower casing both strings. + */ + lowFirst = *word; + + if (isupper (lowFirst)) + lowFirst = tolower (lowFirst); + + while (TRUE) { + while (*string && (*string != lowFirst) && + (!isupper (*string) || (tolower (*string) != lowFirst))) { + string++; + } + + if (*string == '\0') + return FALSE; + + cp1 = string; + cp2 = word; + + do { + if (*cp2 == '\0') + return TRUE; + + ch1 = *cp1++; + + if (isupper (ch1)) + ch1 = tolower (ch1); + + ch2 = *cp2++; + + if (isupper (ch2)) + ch2 = tolower (ch2); + + } + while (ch1 == ch2); + + string++; + } + return (TRUE); +} extern int grep_main (int argc, char **argv) @@ -122,76 +190,6 @@ extern int grep_main (int argc, char **argv) } -/* - * See if the specified word is found in the specified string. - */ -static int search (const char *string, const char *word, int ignoreCase) -{ - const char *cp1; - const char *cp2; - int len; - int lowFirst; - int ch1; - int ch2; - - len = strlen (word); - - if (!ignoreCase) { - while (TRUE) { - string = strchr (string, word[0]); - - if (string == NULL) - return FALSE; - - if (memcmp (string, word, len) == 0) - return TRUE; - - string++; - } - } - - /* - * Here if we need to check case independence. - * Do the search by lower casing both strings. - */ - lowFirst = *word; - - if (isupper (lowFirst)) - lowFirst = tolower (lowFirst); - - while (TRUE) { - while (*string && (*string != lowFirst) && - (!isupper (*string) || (tolower (*string) != lowFirst))) { - string++; - } - - if (*string == '\0') - return FALSE; - - cp1 = string; - cp2 = word; - - do { - if (*cp2 == '\0') - return TRUE; - - ch1 = *cp1++; - - if (isupper (ch1)) - ch1 = tolower (ch1); - - ch2 = *cp2++; - - if (isupper (ch2)) - ch2 = tolower (ch2); - - } - while (ch1 == ch2); +/* END CODE */ - string++; - } - return (TRUE); -} -#endif -/* END CODE */ |