diff options
Diffstat (limited to 'utility.c')
-rw-r--r-- | utility.c | 76 |
1 files changed, 0 insertions, 76 deletions
@@ -1033,82 +1033,6 @@ int get_console_fd(char *tty_name) #endif /* BB_CHVT || BB_DEALLOCVT || BB_SETKEYCODES */ -#if !defined BB_REGEXP && (defined BB_GREP || defined BB_SED) - -/* 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 in regexp.c - * -Erik Andersen - */ -extern int find_match(char *haystack, char *needle, int ignoreCase) -{ - - if (ignoreCase == FALSE) - haystack = strstr(haystack, needle); - else - haystack = stristr(haystack, needle); - if (haystack == NULL) - return FALSE; - return TRUE; -} - - -/* This performs substitutions after a string match has been found. */ -extern int replace_match(char *haystack, char *needle, char *newNeedle, - int ignoreCase) -{ - int foundOne = 0; - char *where, *slider, *slider1, *oldhayStack; - - if (ignoreCase == FALSE) - where = strstr(haystack, needle); - else - where = stristr(haystack, needle); - - if (strcmp(needle, newNeedle) == 0) - return FALSE; - - oldhayStack = (char *) xmalloc((unsigned) (strlen(haystack))); - while (where != NULL) { - foundOne++; - strcpy(oldhayStack, haystack); - 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 > 0) - return TRUE; - else - return FALSE; -} - -#endif /* ! BB_REGEXP && (BB_GREP || BB_SED) */ - - #if defined BB_FIND || defined BB_INSMOD /* * Routine to see if a text string is matched by a wildcard pattern. |