diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-03-01 14:41:39 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-03-01 14:41:39 +0100 |
commit | 70ee23399cb2c77dec0b6ad3b6030f7cf3105b8f (patch) | |
tree | 67a73c080cad3444093f15ce9da90610f49d29cf | |
parent | 63d9da322f438a98bb654cc4976874fa89f1fa62 (diff) | |
download | busybox-w32-70ee23399cb2c77dec0b6ad3b6030f7cf3105b8f.tar.gz busybox-w32-70ee23399cb2c77dec0b6ad3b6030f7cf3105b8f.tar.bz2 busybox-w32-70ee23399cb2c77dec0b6ad3b6030f7cf3105b8f.zip |
vi: code shrink
function old new delta
setops 85 73 -12
colon 2965 2915 -50
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-62) Total: -62 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/vi.c | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/editors/vi.c b/editors/vi.c index e77c348fb..abc0aeae8 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -2258,7 +2258,7 @@ static char *get_one_address(char *p, int *addr) // get colon addr, if present | |||
2258 | q = begin_line(dot); | 2258 | q = begin_line(dot); |
2259 | *addr = count_lines(text, q); | 2259 | *addr = count_lines(text, q); |
2260 | } | 2260 | } |
2261 | #if ENABLE_FEATURE_VI_YANKMARK | 2261 | # if ENABLE_FEATURE_VI_YANKMARK |
2262 | else if (*p == '\'') { // is this a mark addr | 2262 | else if (*p == '\'') { // is this a mark addr |
2263 | p++; | 2263 | p++; |
2264 | c = tolower(*p); | 2264 | c = tolower(*p); |
@@ -2272,8 +2272,8 @@ static char *get_one_address(char *p, int *addr) // get colon addr, if present | |||
2272 | } | 2272 | } |
2273 | } | 2273 | } |
2274 | } | 2274 | } |
2275 | #endif | 2275 | # endif |
2276 | #if ENABLE_FEATURE_VI_SEARCH | 2276 | # if ENABLE_FEATURE_VI_SEARCH |
2277 | else if (*p == '/') { // a search pattern | 2277 | else if (*p == '/') { // a search pattern |
2278 | q = strchrnul(p + 1, '/'); | 2278 | q = strchrnul(p + 1, '/'); |
2279 | if (p + 1 != q) { | 2279 | if (p + 1 != q) { |
@@ -2290,7 +2290,7 @@ static char *get_one_address(char *p, int *addr) // get colon addr, if present | |||
2290 | *addr = count_lines(text, q); | 2290 | *addr = count_lines(text, q); |
2291 | } | 2291 | } |
2292 | } | 2292 | } |
2293 | #endif | 2293 | # endif |
2294 | else if (*p == '$') { // the last line in file | 2294 | else if (*p == '$') { // the last line in file |
2295 | p++; | 2295 | p++; |
2296 | q = begin_line(end - 1); | 2296 | q = begin_line(end - 1); |
@@ -2333,16 +2333,13 @@ static char *get_address(char *p, int *b, int *e) // get two colon addrs, if pre | |||
2333 | return p; | 2333 | return p; |
2334 | } | 2334 | } |
2335 | 2335 | ||
2336 | #if ENABLE_FEATURE_VI_SET && ENABLE_FEATURE_VI_SETOPTS | 2336 | # if ENABLE_FEATURE_VI_SET && ENABLE_FEATURE_VI_SETOPTS |
2337 | static void setops(const char *args, const char *opname, int flg_no, | 2337 | static void setops(const char *args, const char *nm_longname, int flg_no, int opt) |
2338 | const char *short_opname, int opt) | ||
2339 | { | 2338 | { |
2340 | const char *a = args + flg_no; | 2339 | const char *a = args + flg_no; |
2341 | int l = strlen(opname) - 1; // opname have + ' ' | ||
2342 | 2340 | ||
2343 | // maybe strncmp? we had tons of erroneous strncasecmp's... | 2341 | if (strcmp(a, nm_longname) == 0 |
2344 | if (strncasecmp(a, opname, l) == 0 | 2342 | || strcmp(a, nm_longname + 3) == 0 |
2345 | || strncasecmp(a, short_opname, 2) == 0 | ||
2346 | ) { | 2343 | ) { |
2347 | if (flg_no) | 2344 | if (flg_no) |
2348 | vi_setops &= ~opt; | 2345 | vi_setops &= ~opt; |
@@ -2350,7 +2347,7 @@ static void setops(const char *args, const char *opname, int flg_no, | |||
2350 | vi_setops |= opt; | 2347 | vi_setops |= opt; |
2351 | } | 2348 | } |
2352 | } | 2349 | } |
2353 | #endif | 2350 | # endif |
2354 | 2351 | ||
2355 | #endif /* FEATURE_VI_COLON */ | 2352 | #endif /* FEATURE_VI_COLON */ |
2356 | 2353 | ||
@@ -2734,13 +2731,12 @@ static void colon(char *buf) | |||
2734 | i = 0; | 2731 | i = 0; |
2735 | if (argp[0] == 'n' && argp[1] == 'o') // "noXXX" | 2732 | if (argp[0] == 'n' && argp[1] == 'o') // "noXXX" |
2736 | i = 2; | 2733 | i = 2; |
2737 | setops(argp, "autoindent ", i, "ai", VI_AUTOINDENT); | 2734 | setops(argp, "ai""\0""autoindent", i, VI_AUTOINDENT); |
2738 | setops(argp, "flash " , i, "fl", VI_ERR_METHOD); | 2735 | setops(argp, "fl""\0""flash" , i, VI_ERR_METHOD); |
2739 | setops(argp, "ignorecase ", i, "ic", VI_IGNORECASE); | 2736 | setops(argp, "ic""\0""ignorecase", i, VI_IGNORECASE); |
2740 | setops(argp, "showmatch " , i, "sm", VI_SHOWMATCH ); | 2737 | setops(argp, "sm""\0""showmatch" , i, VI_SHOWMATCH ); |
2741 | if (strncmp(argp, "tabstop=", 8) == 0) { | 2738 | if (strncmp(argp, "tabstop=", 8) == 0) { |
2742 | int t = 0; | 2739 | int t = bb_strtou(argp + 8, NULL, 10); |
2743 | sscanf(argp + 8, "%u", &t); | ||
2744 | if (t > 0 && t <= MAX_TABSTOP) | 2740 | if (t > 0 && t <= MAX_TABSTOP) |
2745 | tabstop = t; | 2741 | tabstop = t; |
2746 | } | 2742 | } |