From 3cf52d19581b2077480e7d2e63010baa1f5399c1 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Tue, 12 Oct 1999 22:26:06 +0000 Subject: More stuff... --- findutils/grep.c | 144 +++++++++++++++++++++++++++---------------------------- 1 file changed, 71 insertions(+), 73 deletions(-) (limited to 'findutils') 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 @@ */ #include "internal.h" -#ifdef BB_GREP #include #include @@ -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 */ -- cgit v1.2.3