diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-04-01 17:17:02 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-04-01 17:17:02 +0200 |
| commit | b29dce4bc293d6800e94569ac7d0df54bd1f8a94 (patch) | |
| tree | c6d2255548855c14532179b5713403d073420e78 | |
| parent | 26f5e9d21ccf10ff447c68e4a28be2e723055356 (diff) | |
| download | busybox-w32-b29dce4bc293d6800e94569ac7d0df54bd1f8a94.tar.gz busybox-w32-b29dce4bc293d6800e94569ac7d0df54bd1f8a94.tar.bz2 busybox-w32-b29dce4bc293d6800e94569ac7d0df54bd1f8a94.zip | |
vi: code shrink
function old new delta
get_input_line 172 175 +3
char_insert 444 447 +3
rawmode 36 24 -12
edit_file 644 626 -18
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/2 up/down: 6/-30) Total: -24 bytes
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 fe907c841..993630d6f 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
| @@ -320,8 +320,9 @@ struct globals { | |||
| 320 | int screensize; // and its size | 320 | int screensize; // and its size |
| 321 | int tabstop; | 321 | int tabstop; |
| 322 | int last_forward_char; // last char searched for with 'f' (int because of Unicode) | 322 | int last_forward_char; // last char searched for with 'f' (int because of Unicode) |
| 323 | char erase_char; // the users erase character | 323 | #if ENABLE_FEATURE_VI_CRASHME |
| 324 | char last_input_char; // last char read from user | 324 | char last_input_char; // last char read from user |
| 325 | #endif | ||
| 325 | 326 | ||
| 326 | #if ENABLE_FEATURE_VI_DOT_CMD | 327 | #if ENABLE_FEATURE_VI_DOT_CMD |
| 327 | smallint adding2q; // are we currently adding user input to q | 328 | smallint adding2q; // are we currently adding user input to q |
| @@ -433,8 +434,9 @@ struct globals { | |||
| 433 | #define screenbegin (G.screenbegin ) | 434 | #define screenbegin (G.screenbegin ) |
| 434 | #define tabstop (G.tabstop ) | 435 | #define tabstop (G.tabstop ) |
| 435 | #define last_forward_char (G.last_forward_char ) | 436 | #define last_forward_char (G.last_forward_char ) |
| 436 | #define erase_char (G.erase_char ) | 437 | #if ENABLE_FEATURE_VI_CRASHME |
| 437 | #define last_input_char (G.last_input_char ) | 438 | #define last_input_char (G.last_input_char ) |
| 439 | #endif | ||
| 438 | #if ENABLE_FEATURE_VI_READONLY | 440 | #if ENABLE_FEATURE_VI_READONLY |
| 439 | #define readonly_mode (G.readonly_mode ) | 441 | #define readonly_mode (G.readonly_mode ) |
| 440 | #else | 442 | #else |
| @@ -560,7 +562,6 @@ static void rawmode(void) | |||
| 560 | { | 562 | { |
| 561 | // no TERMIOS_CLEAR_ISIG: leave ISIG on - allow signals | 563 | // no TERMIOS_CLEAR_ISIG: leave ISIG on - allow signals |
| 562 | set_termios_to_raw(STDIN_FILENO, &term_orig, TERMIOS_RAW_CRNL); | 564 | set_termios_to_raw(STDIN_FILENO, &term_orig, TERMIOS_RAW_CRNL); |
| 563 | erase_char = term_orig.c_cc[VERASE]; | ||
| 564 | } | 565 | } |
| 565 | 566 | ||
| 566 | static void cookmode(void) | 567 | static void cookmode(void) |
| @@ -1082,7 +1083,7 @@ static char *get_input_line(const char *prompt) | |||
| 1082 | c = get_one_char(); | 1083 | c = get_one_char(); |
| 1083 | if (c == '\n' || c == '\r' || c == 27) | 1084 | if (c == '\n' || c == '\r' || c == 27) |
| 1084 | break; // this is end of input | 1085 | break; // this is end of input |
| 1085 | if (c == erase_char || c == 8 || c == 127) { | 1086 | if (c == term_orig.c_cc[VERASE] || c == 8 || c == 127) { |
| 1086 | // user wants to erase prev char | 1087 | // user wants to erase prev char |
| 1087 | buf[--i] = '\0'; | 1088 | buf[--i] = '\0'; |
| 1088 | write1("\b \b"); // erase char on screen | 1089 | write1("\b \b"); // erase char on screen |
| @@ -1978,7 +1979,7 @@ static char *char_insert(char *p, char c, int undo) // insert the char c at 'p' | |||
| 1978 | if ((p[-1] != '\n') && (dot > text)) { | 1979 | if ((p[-1] != '\n') && (dot > text)) { |
| 1979 | p--; | 1980 | p--; |
| 1980 | } | 1981 | } |
| 1981 | } else if (c == erase_char || c == 8 || c == 127) { // Is this a BS | 1982 | } else if (c == term_orig.c_cc[VERASE] || c == 8 || c == 127) { // Is this a BS |
| 1982 | if (p > text) { | 1983 | if (p > text) { |
| 1983 | p--; | 1984 | p--; |
| 1984 | p = text_hole_delete(p, p, ALLOW_UNDO_QUEUED); // shrink buffer 1 char | 1985 | p = text_hole_delete(p, p, ALLOW_UNDO_QUEUED); // shrink buffer 1 char |
| @@ -4189,7 +4190,10 @@ static void edit_file(char *fn) | |||
| 4189 | mark[26] = mark[27] = text; // init "previous context" | 4190 | mark[26] = mark[27] = text; // init "previous context" |
| 4190 | #endif | 4191 | #endif |
| 4191 | 4192 | ||
| 4192 | last_forward_char = last_input_char = '\0'; | 4193 | last_forward_char = '\0'; |
| 4194 | #if ENABLE_FEATURE_VI_CRASHME | ||
| 4195 | last_input_char = '\0'; | ||
| 4196 | #endif | ||
| 4193 | crow = 0; | 4197 | crow = 0; |
| 4194 | ccol = 0; | 4198 | ccol = 0; |
| 4195 | 4199 | ||
| @@ -4253,7 +4257,10 @@ static void edit_file(char *fn) | |||
| 4253 | } | 4257 | } |
| 4254 | } | 4258 | } |
| 4255 | #endif | 4259 | #endif |
| 4256 | last_input_char = c = get_one_char(); // get a cmd from user | 4260 | c = get_one_char(); // get a cmd from user |
| 4261 | #if ENABLE_FEATURE_VI_CRASHME | ||
| 4262 | last_input_char = c; | ||
| 4263 | #endif | ||
| 4257 | #if ENABLE_FEATURE_VI_YANKMARK | 4264 | #if ENABLE_FEATURE_VI_YANKMARK |
| 4258 | // save a copy of the current line- for the 'U" command | 4265 | // save a copy of the current line- for the 'U" command |
| 4259 | if (begin_line(dot) != cur_line) { | 4266 | if (begin_line(dot) != cur_line) { |
