vi: backward search repair for ENABLE_FEATURE_VI_REGEX_SEARCH

Andrey Dobrovolsky andrey.dobrovolsky.odessa at gmail.com
Tue Feb 9 14:30:13 UTC 2021


commit 50c8bc4e25edac4d4b65419303df1a32db69ef28
Author: AndreyDobrovolskyOdessa <andrey.dobrovolsky.odessa at gmail.com>
Date:   Tue Feb 9 14:44:14 2021 +0200

    Backward search repair for ENABLE_FEATURE_VI_REGEX_SEARCH.

    In order to perform backward search using re_search(), starting
offset must be set
    to the end of the area searched, while "range" parameter is negative.

    The returned value of re_search() is an offset of the pattern
start inside the area
    searched, so char_search() can return area start adress plus
offset, in case re_search()
    returned positive offset, meaning succeful search.

diff --git a/editors/vi.c b/editors/vi.c
index 458ca62..5bfb69d 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -2189,15 +2189,11 @@ static char *char_search(char *p, const char
*pat, int dir_and_range)
  // re_search() >= 0: index of found pattern
  //           struct pattern   char     int   int    int    struct reg
  // re_search(*pattern_buffer, *string, size, start, range, *regs)
- i = re_search(&preg, q, size, /*start:*/ 0, range, /*struct
re_registers*:*/ NULL);
+ i = re_search(&preg, q, size, (range < 0) ? size : 0 , range,
/*struct re_registers*:*/ NULL);
  regfree(&preg);
  if (i < 0)
  return NULL;
- if (dir_and_range > 0) // FORWARD?
- p = p + i;
- else
- p = p - i;
- return p;
+        return (q + i) ;
 }
 # else
 #  if ENABLE_FEATURE_VI_SETOPTS

Best regards!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vi_back_search
Type: application/octet-stream
Size: 1401 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20210209/068eda07/attachment.obj>


More information about the busybox mailing list