From 24d8e7d787aa1940030a1beaabdd4388588ca512 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Fri, 29 Oct 1999 06:50:17 +0000 Subject: Stuf --- utility.c | 86 ++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 37 deletions(-) (limited to 'utility.c') diff --git a/utility.c b/utility.c index 41e7ccc14..e0f9d1246 100644 --- a/utility.c +++ b/utility.c @@ -778,70 +778,82 @@ int get_console_fd(char* tty_name) #if !defined BB_REGEXP && (defined BB_GREP || defined BB_FIND ) + +/* Do a case insensitive strstr() */ +char* stristr(char *haystack, const char *needle) +{ + int len = strlen( needle ); + while( *haystack ) { + if( !strncasecmp( haystack, needle, len ) ) + break; + haystack++; + } + + if( !(*haystack) ) + haystack = NULL; + + return haystack; +} + /* This tries to find a needle in a haystack, but does so by * only trying to match literal strings (look 'ma, no regexps!) * This is short, sweet, and carries _very_ little baggage, - * unlike its beefier cousin a few lines down... + * unlike its beefier cousin in regexp.c * -Erik Andersen */ extern int find_match(char *haystack, char *needle, int ignoreCase) { - if (ignoreCase == FALSE) { + if (ignoreCase == FALSE) haystack = strstr (haystack, needle); - if (haystack == NULL) - return FALSE; - return TRUE; - } else { - int i; - char needle1[BUF_SIZE]; - char haystack1[BUF_SIZE]; - - strncpy( haystack1, haystack, sizeof(haystack1)); - strncpy( needle1, needle, sizeof(needle1)); - for( i=0; i strlen(needle)) { haystack = (char *)realloc(haystack, (unsigned)(strlen(haystack) - strlen(needle) + strlen(newNeedle))); - for(slider=haystack;slider!=where;slider++); - *slider=0; - haystack=strcat(haystack, newNeedle); - slider+=1+sizeof(newNeedle); - haystack = strcat(haystack, slider); - where = strstr (where+1, needle); } - } else { - // FIXME - +#endif + for(slider=haystack,slider1=oldhayStack;slider!=where;slider++,slider1++); + *slider=0; + haystack=strcat(haystack, newNeedle); + slider1+=strlen(needle); + haystack = strcat(haystack, slider1); + where = strstr (slider, needle); } + free( oldhayStack); + if (foundOne) return TRUE; else return FALSE; } + #endif /* END CODE */ -- cgit v1.2.3