diff options
author | Ron Yorston | 2021-04-15 12:05:14 +0100 |
---|---|---|
committer | Denys Vlasenko | 2021-04-15 13:09:12 +0200 |
commit | 5d1bb58b13d4a805538e231584721e5738932efc (patch) | |
tree | 488809c66d8198f2b92316a165d6ff77a2e37cbb /editors | |
parent | 74d565ff1f3756a6a6646c4f7c27dd46beaee06f (diff) | |
download | busybox-5d1bb58b13d4a805538e231584721e5738932efc.zip busybox-5d1bb58b13d4a805538e231584721e5738932efc.tar.gz |
vi: code shrink colon line addresses
Remove some unnecessary code in get_one_address() and rewrite
get_address().
function old new delta
colon 3325 3604 +279
get_one_address 342 - -342
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/0 up/down: 279/-342) Total: -63 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r-- | editors/vi.c | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/editors/vi.c b/editors/vi.c index 922d7ea..9c32ed8 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -2345,14 +2345,15 @@ static char *char_search(char *p, const char *pat, int dir_and_range) static char *get_one_address(char *p, int *addr) // get colon addr, if present { int st; +# if ENABLE_FEATURE_VI_YANKMARK || ENABLE_FEATURE_VI_SEARCH char *q; +# endif IF_FEATURE_VI_YANKMARK(char c;) *addr = -1; // assume no addr if (*p == '.') { // the current line p++; - q = begin_line(dot); - *addr = count_lines(text, q); + *addr = count_lines(text, dot); } # if ENABLE_FEATURE_VI_YANKMARK else if (*p == '\'') { // is this a mark addr @@ -2389,43 +2390,43 @@ static char *get_one_address(char *p, int *addr) // get colon addr, if present # endif else if (*p == '$') { // the last line in file p++; - q = begin_line(end - 1); - *addr = count_lines(text, q); + *addr = count_lines(text, end - 1); } else if (isdigit(*p)) { // specific line number sscanf(p, "%d%n", addr, &st); p += st; - } else { - // unrecognized address - assume -1 - *addr = -1; } return p; } +# define GET_FIRST 0 +# define GET_SECOND 1 +# define GOT_FIRST 2 +# define GOT_SECOND 3 +# define GOT 2 + static char *get_address(char *p, int *b, int *e) // get two colon addrs, if present { + int state = GET_FIRST; + //----- get the address' i.e., 1,3 'a,'b ----- - // get FIRST addr, if present - while (isblank(*p)) - p++; // skip over leading spaces - if (*p == '%') { // alias for 1,$ - p++; - *b = 1; - *e = count_lines(text, end-1); - goto ga0; - } - p = get_one_address(p, b); - while (isblank(*p)) - p++; - if (*p == ',') { // is there a address separator - p++; - while (isblank(*p)) + for (;;) { + if (isblank(*p)) { + p++; + } else if (*p == '%' && state == GET_FIRST) { // alias for 1,$ + p++; + *b = 1; + *e = count_lines(text, end-1); + state = GOT_SECOND; + } else if (*p == ',' && state == GOT_FIRST) { p++; - // get SECOND addr, if present - p = get_one_address(p, e); + state = GET_SECOND; + } else if (state == GET_FIRST || state == GET_SECOND) { + p = get_one_address(p, state == GET_FIRST ? b : e); + state |= GOT; + } else { + break; + } } - ga0: - while (isblank(*p)) - p++; // skip over trailing spaces return p; } |