diff options
author | Ron Yorston <rmy@pobox.com> | 2021-04-15 12:06:11 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-04-15 13:09:12 +0200 |
commit | 47f78913f7576596d44c602a015735cb9c49f4f0 (patch) | |
tree | cbc4b77208ce31c124f2634253d58564518c2938 | |
parent | d488def0e453781e0471cfb0971ad709a95c7919 (diff) | |
download | busybox-w32-47f78913f7576596d44c602a015735cb9c49f4f0.tar.gz busybox-w32-47f78913f7576596d44c602a015735cb9c49f4f0.tar.bz2 busybox-w32-47f78913f7576596d44c602a015735cb9c49f4f0.zip |
vi: allow backward search to specify line address
It should be possible to use a backward search as a line address
in colon commands.
function old new delta
colon 3661 3701 +40
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 40/0) Total: 40 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/vi.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/editors/vi.c b/editors/vi.c index 1d326f454..0866e0fa9 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -2346,9 +2346,9 @@ static char *get_one_address(char *p, int *addr) // get colon addr, if present | |||
2346 | { | 2346 | { |
2347 | int st; | 2347 | int st; |
2348 | # if ENABLE_FEATURE_VI_YANKMARK || ENABLE_FEATURE_VI_SEARCH | 2348 | # if ENABLE_FEATURE_VI_YANKMARK || ENABLE_FEATURE_VI_SEARCH |
2349 | char *q; | 2349 | char *q, c; |
2350 | # endif | 2350 | # endif |
2351 | IF_FEATURE_VI_YANKMARK(char c;) | 2351 | IF_FEATURE_VI_SEARCH(int dir;) |
2352 | 2352 | ||
2353 | *addr = -1; // assume no addr | 2353 | *addr = -1; // assume no addr |
2354 | if (*p == '.') { // the current line | 2354 | if (*p == '.') { // the current line |
@@ -2372,18 +2372,25 @@ static char *get_one_address(char *p, int *addr) // get colon addr, if present | |||
2372 | } | 2372 | } |
2373 | # endif | 2373 | # endif |
2374 | # if ENABLE_FEATURE_VI_SEARCH | 2374 | # if ENABLE_FEATURE_VI_SEARCH |
2375 | else if (*p == '/') { // a search pattern | 2375 | else if (*p == '/' || *p == '?') { // a search pattern |
2376 | q = strchrnul(p + 1, '/'); | 2376 | c = *p; |
2377 | q = strchrnul(p + 1, c); | ||
2377 | if (p + 1 != q) { | 2378 | if (p + 1 != q) { |
2378 | // save copy of new pattern | 2379 | // save copy of new pattern |
2379 | free(last_search_pattern); | 2380 | free(last_search_pattern); |
2380 | last_search_pattern = xstrndup(p, q - p); | 2381 | last_search_pattern = xstrndup(p, q - p); |
2381 | } | 2382 | } |
2382 | p = q; | 2383 | p = q; |
2383 | if (*p == '/') | 2384 | if (*p == c) |
2384 | p++; | 2385 | p++; |
2385 | q = char_search(next_line(dot), last_search_pattern + 1, | 2386 | if (c == '/') { |
2386 | (FORWARD << 1) | FULL); | 2387 | q = next_line(dot); |
2388 | dir = (FORWARD << 1) | FULL; | ||
2389 | } else { | ||
2390 | q = begin_line(dot); | ||
2391 | dir = ((unsigned)BACK << 1) | FULL; | ||
2392 | } | ||
2393 | q = char_search(q, last_search_pattern + 1, dir); | ||
2387 | if (q == NULL) | 2394 | if (q == NULL) |
2388 | return NULL; | 2395 | return NULL; |
2389 | *addr = count_lines(text, q); | 2396 | *addr = count_lines(text, q); |