Hi list, vi supports regex, the bb vi did this also until someone broke it. This patch does a bit of clean up and make the regex support compile again. This is not production stuff. The code has some room for improvements but i want to make it working first.
The big question: REGEX_SEARCH should it depend on something or is it a selectable feature ? re, wh Signed-off-by: harms <[email protected]> diff --git a/editors/vi.c b/editors/vi.c index 3656fee..e7e04fa 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -33,6 +33,7 @@ //usage: ) //usage: "\n -H Short help regarding available features" +#include <regex.h> #include "libbb.h" /* the CRASHME code is unmaintained, and doesn't currently build */ @@ -366,7 +367,7 @@ static void Hit_Return(void); #if ENABLE_FEATURE_VI_SEARCH static char *char_search(char *, const char *, int, int); // search for pattern starting at p -static int mycmp(const char *, const char *, int); // string cmp based in "ignorecase" +//static int mycmp(const char *, const char *, int); // string cmp based in "ignorecase" #endif #if ENABLE_FEATURE_VI_COLON static char *get_one_address(char *, int *); // get colon addr, if present @@ -1561,48 +1562,17 @@ static char *new_screen(int ro, int co) } #if ENABLE_FEATURE_VI_SEARCH -static int mycmp(const char *s1, const char *s2, int len) -{ - if (ENABLE_FEATURE_VI_SETOPTS && ignorecase) { - return strncasecmp(s1, s2, len); - } - return strncmp(s1, s2, len); -} + +//#define REGEX_SEARCH +#ifdef REGEX_SEARCH // search for pattern starting at p static char *char_search(char *p, const char *pat, int dir, int range) { -#ifndef REGEX_SEARCH - char *start, *stop; - int len; - - len = strlen(pat); - if (dir == FORWARD) { - stop = end - 1; // assume range is p - end-1 - if (range == LIMITED) - stop = next_line(p); // range is to next line - for (start = p; start < stop; start++) { - if (mycmp(start, pat, len) == 0) { - return start; - } - } - } else if (dir == BACK) { - stop = text; // assume range is text - p - if (range == LIMITED) - stop = prev_line(p); // range is to prev line - for (start = p - len; start >= stop; start--) { - if (mycmp(start, pat, len) == 0) { - return start; - } - } - } - // pattern not found - return NULL; -#else /* REGEX_SEARCH */ char *q; struct re_pattern_buffer preg; int i; - int size, range; + int size; re_syntax_options = RE_SYNTAX_POSIX_EXTENDED; preg.translate = 0; @@ -1625,7 +1595,7 @@ static char *char_search(char *p, const char *pat, int dir, int range) // RANGE could be negative if we are searching backwards range = q - p; - q = re_compile_pattern(pat, strlen(pat), &preg); + q = (char *)re_compile_pattern(pat,strlen(pat), (struct re_pattern_buffer *)&preg); if (q != 0) { // The pattern was not compiled status_line_bold("bad search pattern: \"%s\": %s", pat, q); @@ -1659,8 +1629,49 @@ static char *char_search(char *p, const char *pat, int dir, int range) p = p - i; } return p; -#endif /* REGEX_SEARCH */ } + +#else + +static int mycmp(const char *s1, const char *s2, int len) +{ + if (ENABLE_FEATURE_VI_SETOPTS && ignorecase) { + return strncasecmp(s1, s2, len); + } + return strncmp(s1, s2, len); +} + +static char *char_search(char *p, const char *pat, int dir, int range) +{ + char *start, *stop; + int len; + + len = strlen(pat); + if (dir == FORWARD) { + stop = end - 1; // assume range is p - end-1 + if (range == LIMITED) + stop = next_line(p); // range is to next line + for (start = p; start < stop; start++) { + if (mycmp(start, pat, len) == 0) { + return start; + } + } + } else if (dir == BACK) { + stop = text; // assume range is text - p + if (range == LIMITED) + stop = prev_line(p); // range is to prev line + for (start = p - len; start >= stop; start--) { + if (mycmp(start, pat, len) == 0) { + return start; + } + } + } + // pattern not found + return NULL; +} + +#endif + #endif /* FEATURE_VI_SEARCH */ static char *char_insert(char *p, char c) // insert the char c at 'p' _______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
