[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: Re: [PATCH] vi: fixes to string search in colon commands, closes 10321
From: Denys Vlasenko <vda.linux () googlemail ! com>
Date: 2020-01-29 13:10:20
Message-ID: CAK1hOcO3N14i_VimHbfsVU-=3zvWOYMuJjQgQ4t_n5b_TLm1NQ () mail ! gmail ! com
[Download RAW message or body]
Applied, thanks!
On Thu, Jan 23, 2020 at 4:31 PM Ron Yorston <rmy@pobox.com> wrote:
>
> Handling of string searches in colon commands (e.g ':/pat1/,/pat2/cmd')
> differ from standard vi:
>
> - As reported in bug 10321 such searches can't be repeated using the
> 'n' command. This is because the last search pattern isn't updated.
>
> - The search also can't be repeated using the command '://' because
> an empty search pattern doesn't imply the use of the last search
> pattern.
>
> - Such searches should start on the line after the current line,
> otherwise '://' never moves to the next occurrence of the pattern.
> This can also affect other cases where line ranges are specified
> using search patterns.
>
> Fix these various issues.
>
> function old new delta
> get_one_address 325 342 +17
>
> Signed-off-by: Ron Yorston <rmy@pobox.com>
> ---
> editors/vi.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/editors/vi.c b/editors/vi.c
> index 51dfc1209..1dd0b6fb6 100644
> --- a/editors/vi.c
> +++ b/editors/vi.c
> @@ -2251,7 +2251,6 @@ static char *get_one_address(char *p, int *addr) // get \
> colon addr, if present int st;
> char *q;
> IF_FEATURE_VI_YANKMARK(char c;)
> - IF_FEATURE_VI_SEARCH(char *pat;)
>
> *addr = -1; // assume no addr
> if (*p == '.') { // the current line
> @@ -2276,16 +2275,20 @@ static char *get_one_address(char *p, int *addr) // \
> get colon addr, if present #endif
> #if ENABLE_FEATURE_VI_SEARCH
> else if (*p == '/') { // a search pattern
> - q = strchrnul(++p, '/');
> - pat = xstrndup(p, q - p); // save copy of pattern
> + q = strchrnul(p + 1, '/');
> + if (p + 1 != q) {
> + // save copy of new pattern
> + free(last_search_pattern);
> + last_search_pattern = xstrndup(p, q - p);
> + }
> p = q;
> if (*p == '/')
> p++;
> - q = char_search(dot, pat, (FORWARD << 1) | FULL);
> + q = char_search(next_line(dot), last_search_pattern + 1,
> + (FORWARD << 1) | FULL);
> if (q != NULL) {
> *addr = count_lines(text, q);
> }
> - free(pat);
> }
> #endif
> else if (*p == '$') { // the last line in file
> --
> 2.24.1
>
> _______________________________________________
> busybox mailing list
> busybox@busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic