diff options
Diffstat (limited to 'regexp.c')
-rw-r--r-- | regexp.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -25,6 +25,28 @@ extern int find_match(char *haystack, char *needle, int ignoreCase) | |||
25 | return( status); | 25 | return( status); |
26 | } | 26 | } |
27 | 27 | ||
28 | /* This performs substitutions after a regexp match has been found. | ||
29 | * The new string is returned. It is malloc'ed, and do must be freed. */ | ||
30 | extern char* replace_match(char *haystack, char *needle, char *newNeedle, int ignoreCase) | ||
31 | { | ||
32 | int status; | ||
33 | char* newHaystack; | ||
34 | struct regexp* re; | ||
35 | newHaystack = (char *)malloc((unsigned)(strlen(haystack) - | ||
36 | strlen(needle) + strlen(newNeedle)); | ||
37 | re = regcomp( needle); | ||
38 | status = regexec(re, haystack, FALSE, ignoreCase); | ||
39 | |||
40 | return( newHaystack) | ||
41 | } | ||
42 | |||
43 | |||
44 | extern void regsub(regexp* re, char* src, char* dst) | ||
45 | |||
46 | free( re); | ||
47 | return( status); | ||
48 | } | ||
49 | |||
28 | 50 | ||
29 | /* code swiped from elvis-tiny 1.4 (a clone of vi) and adjusted to | 51 | /* code swiped from elvis-tiny 1.4 (a clone of vi) and adjusted to |
30 | * suit the needs of busybox by Erik Andersen. | 52 | * suit the needs of busybox by Erik Andersen. |