aboutsummaryrefslogtreecommitdiff
path: root/utility.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-29 00:07:31 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-29 00:07:31 +0000
commitc1525e84dd6a3ac8252ce10e6ae605bd37d60797 (patch)
treebef01229299c4ad89f2e353df0e88af292a8795c /utility.c
parent6b6b3f6ef2f44898a8bddfaae93cc4ef3aa79661 (diff)
downloadbusybox-c1525e84dd6a3ac8252ce10e6ae605bd37d60797.tar.gz
Stuff
Diffstat (limited to 'utility.c')
-rw-r--r--utility.c101
1 files changed, 66 insertions, 35 deletions
diff --git a/utility.c b/utility.c
index 6491d834d..41e7ccc14 100644
--- a/utility.c
+++ b/utility.c
@@ -686,41 +686,6 @@ my_getgrgid(char* group, gid_t gid)
-#if !defined BB_REGEXP && (defined BB_GREP || defined BB_FIND )
-/* 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...
- * -Erik Andersen
- */
-extern int find_match(char *haystack, char *needle, int ignoreCase)
-{
-
- 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<sizeof(haystack1) && haystack1[i]; i++)
- haystack1[i]=tolower( haystack1[i]);
- for( i=0; i<sizeof(needle1) && needle1[i]; i++)
- needle1[i]=tolower( needle1[i]);
- haystack = strstr (haystack1, needle1);
- if (haystack == NULL)
- return FALSE;
- return TRUE;
- }
-}
-#endif
-
-
#if (defined BB_CHVT) || (defined BB_DEALLOCVT)
@@ -812,5 +777,71 @@ int get_console_fd(char* tty_name)
#endif
+#if !defined BB_REGEXP && (defined BB_GREP || defined BB_FIND )
+/* 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...
+ * -Erik Andersen
+ */
+extern int find_match(char *haystack, char *needle, int ignoreCase)
+{
+
+ 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<sizeof(haystack1) && haystack1[i]; i++)
+ haystack1[i]=tolower( haystack1[i]);
+ for( i=0; i<sizeof(needle1) && needle1[i]; i++)
+ needle1[i]=tolower( needle1[i]);
+ haystack = strstr (haystack1, needle1);
+ if (haystack == NULL)
+ return FALSE;
+ return TRUE;
+ }
+}
+
+
+/* This performs substitutions after a regexp match has been found. */
+extern int replace_match(char *haystack, char *needle, char *newNeedle, int ignoreCase)
+{
+ int foundOne;
+ char *where, *slider;
+
+ if (ignoreCase == FALSE) {
+ /*Find needle in haystack */
+ where = strstr (haystack, needle);
+ while(where!=NULL) {
+ foundOne++;
+ fprintf(stderr, "A match: haystack='%s'\n", haystack);
+ 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
+
+ }
+ if (foundOne)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+#endif
/* END CODE */