diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-04-01 16:15:51 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-04-01 16:15:51 +0200 |
commit | 2a57608f673698ddbde6704ef1f01f2fd443710b (patch) | |
tree | 6e8c005c842b3ec5a90ed1f32732999f6c9ec82a | |
parent | 6ce60b9cca55c908de3747f1224b2e8aabb557bf (diff) | |
download | busybox-w32-2a57608f673698ddbde6704ef1f01f2fd443710b.tar.gz busybox-w32-2a57608f673698ddbde6704ef1f01f2fd443710b.tar.bz2 busybox-w32-2a57608f673698ddbde6704ef1f01f2fd443710b.zip |
vi: code shrink
function old new delta
get_one_char 108 103 -5
edit_file 651 644 -7
do_cmd 4696 4688 -8
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-20) Total: -20 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/vi.c | 58 |
1 files changed, 28 insertions, 30 deletions
diff --git a/editors/vi.c b/editors/vi.c index 5c585a390..af23ae7d2 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -1029,43 +1029,41 @@ static int readit(void) // read (maybe cursor) key from stdin | |||
1029 | return c; | 1029 | return c; |
1030 | } | 1030 | } |
1031 | 1031 | ||
1032 | #if ENABLE_FEATURE_VI_DOT_CMD | ||
1032 | static int get_one_char(void) | 1033 | static int get_one_char(void) |
1033 | { | 1034 | { |
1034 | int c; | 1035 | int c; |
1035 | 1036 | ||
1036 | #if ENABLE_FEATURE_VI_DOT_CMD | ||
1037 | if (!adding2q) { | 1037 | if (!adding2q) { |
1038 | // we are not adding to the q. | 1038 | // we are not adding to the q. |
1039 | // but, we may be reading from a q | 1039 | // but, we may be reading from a saved q. |
1040 | if (ioq == 0) { | 1040 | // (checking "ioq" for NULL is wrong, it's not reset to NULL |
1041 | // there is no current q, read from STDIN | 1041 | // when done - "ioq_start" is reset instead). |
1042 | c = readit(); // get the users input | 1042 | if (ioq_start != NULL) { |
1043 | } else { | 1043 | // there is a queue to get chars from. |
1044 | // there is a queue to get chars from first | ||
1045 | // careful with correct sign expansion! | 1044 | // careful with correct sign expansion! |
1046 | c = (unsigned char)*ioq++; | 1045 | c = (unsigned char)*ioq++; |
1047 | if (c == '\0') { | 1046 | if (c != '\0') |
1048 | // the end of the q, read from STDIN | 1047 | return c; |
1049 | free(ioq_start); | 1048 | // the end of the q |
1050 | ioq_start = ioq = 0; | 1049 | free(ioq_start); |
1051 | c = readit(); // get the users input | 1050 | ioq_start = NULL; |
1052 | } | 1051 | // read from STDIN: |
1053 | } | 1052 | } |
1053 | return readit(); | ||
1054 | } | ||
1055 | // we are adding STDIN chars to q. | ||
1056 | c = readit(); | ||
1057 | if (lmc_len >= MAX_INPUT_LEN - 1) { | ||
1058 | status_line_bold("last_modifying_cmd overrun"); | ||
1054 | } else { | 1059 | } else { |
1055 | // adding STDIN chars to q | 1060 | last_modifying_cmd[lmc_len++] = c; |
1056 | c = readit(); // get the users input | ||
1057 | if (lmc_len >= MAX_INPUT_LEN - 1) { | ||
1058 | status_line_bold("last_modifying_cmd overrun"); | ||
1059 | } else { | ||
1060 | // add new char to q | ||
1061 | last_modifying_cmd[lmc_len++] = c; | ||
1062 | } | ||
1063 | } | 1061 | } |
1064 | #else | ||
1065 | c = readit(); // get the users input | ||
1066 | #endif /* FEATURE_VI_DOT_CMD */ | ||
1067 | return c; | 1062 | return c; |
1068 | } | 1063 | } |
1064 | #else | ||
1065 | # define get_one_char() readit() | ||
1066 | #endif | ||
1069 | 1067 | ||
1070 | // Get input line (uses "status line" area) | 1068 | // Get input line (uses "status line" area) |
1071 | static char *get_input_line(const char *prompt) | 1069 | static char *get_input_line(const char *prompt) |
@@ -1781,7 +1779,7 @@ static void start_new_cmd_q(char c) | |||
1781 | // get buffer for new cmd | 1779 | // get buffer for new cmd |
1782 | // if there is a current cmd count put it in the buffer first | 1780 | // if there is a current cmd count put it in the buffer first |
1783 | if (cmdcnt > 0) { | 1781 | if (cmdcnt > 0) { |
1784 | lmc_len = sprintf(last_modifying_cmd, "%d%c", cmdcnt, c); | 1782 | lmc_len = sprintf(last_modifying_cmd, "%u%c", cmdcnt, c); |
1785 | } else { // just save char c onto queue | 1783 | } else { // just save char c onto queue |
1786 | last_modifying_cmd[0] = c; | 1784 | last_modifying_cmd[0] = c; |
1787 | lmc_len = 1; | 1785 | lmc_len = 1; |
@@ -3415,9 +3413,8 @@ static void do_cmd(int c) | |||
3415 | case '.': // .- repeat the last modifying command | 3413 | case '.': // .- repeat the last modifying command |
3416 | // Stuff the last_modifying_cmd back into stdin | 3414 | // Stuff the last_modifying_cmd back into stdin |
3417 | // and let it be re-executed. | 3415 | // and let it be re-executed. |
3418 | if (lmc_len > 0) { | 3416 | if (lmc_len != 0) { |
3419 | last_modifying_cmd[lmc_len] = 0; | 3417 | ioq = ioq_start = xstrndup(last_modifying_cmd, lmc_len); |
3420 | ioq = ioq_start = xstrdup(last_modifying_cmd); | ||
3421 | } | 3418 | } |
3422 | break; | 3419 | break; |
3423 | #endif | 3420 | #endif |
@@ -4221,7 +4218,7 @@ static void edit_file(char *fn) | |||
4221 | c = '\0'; | 4218 | c = '\0'; |
4222 | #if ENABLE_FEATURE_VI_DOT_CMD | 4219 | #if ENABLE_FEATURE_VI_DOT_CMD |
4223 | free(ioq_start); | 4220 | free(ioq_start); |
4224 | ioq = ioq_start = NULL; | 4221 | ioq_start = NULL; |
4225 | lmc_len = 0; | 4222 | lmc_len = 0; |
4226 | adding2q = 0; | 4223 | adding2q = 0; |
4227 | #endif | 4224 | #endif |
@@ -4273,7 +4270,8 @@ static void edit_file(char *fn) | |||
4273 | #if ENABLE_FEATURE_VI_DOT_CMD | 4270 | #if ENABLE_FEATURE_VI_DOT_CMD |
4274 | // These are commands that change text[]. | 4271 | // These are commands that change text[]. |
4275 | // Remember the input for the "." command | 4272 | // Remember the input for the "." command |
4276 | if (!adding2q && ioq_start == NULL | 4273 | if (!adding2q |
4274 | && ioq_start == NULL | ||
4277 | && cmd_mode == 0 // command mode | 4275 | && cmd_mode == 0 // command mode |
4278 | && c > '\0' // exclude NUL and non-ASCII chars | 4276 | && c > '\0' // exclude NUL and non-ASCII chars |
4279 | && c < 0x7f // (Unicode and such) | 4277 | && c < 0x7f // (Unicode and such) |