aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-04-15 12:05:14 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2021-04-15 13:09:12 +0200
commit5d1bb58b13d4a805538e231584721e5738932efc (patch)
tree488809c66d8198f2b92316a165d6ff77a2e37cbb
parent74d565ff1f3756a6a6646c4f7c27dd46beaee06f (diff)
downloadbusybox-w32-5d1bb58b13d4a805538e231584721e5738932efc.tar.gz
busybox-w32-5d1bb58b13d4a805538e231584721e5738932efc.tar.bz2
busybox-w32-5d1bb58b13d4a805538e231584721e5738932efc.zip
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>
-rw-r--r--editors/vi.c55
1 files changed, 28 insertions, 27 deletions
diff --git a/editors/vi.c b/editors/vi.c
index 922d7ea8d..9c32ed836 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)
2345static char *get_one_address(char *p, int *addr) // get colon addr, if present 2345static 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 char *q; 2349 char *q;
2350# endif
2349 IF_FEATURE_VI_YANKMARK(char c;) 2351 IF_FEATURE_VI_YANKMARK(char c;)
2350 2352
2351 *addr = -1; // assume no addr 2353 *addr = -1; // assume no addr
2352 if (*p == '.') { // the current line 2354 if (*p == '.') { // the current line
2353 p++; 2355 p++;
2354 q = begin_line(dot); 2356 *addr = count_lines(text, dot);
2355 *addr = count_lines(text, q);
2356 } 2357 }
2357# if ENABLE_FEATURE_VI_YANKMARK 2358# if ENABLE_FEATURE_VI_YANKMARK
2358 else if (*p == '\'') { // is this a mark addr 2359 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
2389# endif 2390# endif
2390 else if (*p == '$') { // the last line in file 2391 else if (*p == '$') { // the last line in file
2391 p++; 2392 p++;
2392 q = begin_line(end - 1); 2393 *addr = count_lines(text, end - 1);
2393 *addr = count_lines(text, q);
2394 } else if (isdigit(*p)) { // specific line number 2394 } else if (isdigit(*p)) { // specific line number
2395 sscanf(p, "%d%n", addr, &st); 2395 sscanf(p, "%d%n", addr, &st);
2396 p += st; 2396 p += st;
2397 } else {
2398 // unrecognized address - assume -1
2399 *addr = -1;
2400 } 2397 }
2401 return p; 2398 return p;
2402} 2399}
2403 2400
2401# define GET_FIRST 0
2402# define GET_SECOND 1
2403# define GOT_FIRST 2
2404# define GOT_SECOND 3
2405# define GOT 2
2406
2404static char *get_address(char *p, int *b, int *e) // get two colon addrs, if present 2407static char *get_address(char *p, int *b, int *e) // get two colon addrs, if present
2405{ 2408{
2409 int state = GET_FIRST;
2410
2406 //----- get the address' i.e., 1,3 'a,'b ----- 2411 //----- get the address' i.e., 1,3 'a,'b -----
2407 // get FIRST addr, if present 2412 for (;;) {
2408 while (isblank(*p)) 2413 if (isblank(*p)) {
2409 p++; // skip over leading spaces 2414 p++;
2410 if (*p == '%') { // alias for 1,$ 2415 } else if (*p == '%' && state == GET_FIRST) { // alias for 1,$
2411 p++; 2416 p++;
2412 *b = 1; 2417 *b = 1;
2413 *e = count_lines(text, end-1); 2418 *e = count_lines(text, end-1);
2414 goto ga0; 2419 state = GOT_SECOND;
2415 } 2420 } else if (*p == ',' && state == GOT_FIRST) {
2416 p = get_one_address(p, b);
2417 while (isblank(*p))
2418 p++;
2419 if (*p == ',') { // is there a address separator
2420 p++;
2421 while (isblank(*p))
2422 p++; 2421 p++;
2423 // get SECOND addr, if present 2422 state = GET_SECOND;
2424 p = get_one_address(p, e); 2423 } else if (state == GET_FIRST || state == GET_SECOND) {
2424 p = get_one_address(p, state == GET_FIRST ? b : e);
2425 state |= GOT;
2426 } else {
2427 break;
2428 }
2425 } 2429 }
2426 ga0:
2427 while (isblank(*p))
2428 p++; // skip over trailing spaces
2429 return p; 2430 return p;
2430} 2431}
2431 2432