diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2022-01-05 22:04:21 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2022-01-05 22:04:21 +0100 |
| commit | 076f5e064fa7b6cc2c03b030abcf2cbd60514180 (patch) | |
| tree | 44d5aefae7f06f10b304e5413988dfe16b3e5fe9 /miscutils | |
| parent | 34e0bb3931b595e7a48061255692ec4ff29499c5 (diff) | |
| download | busybox-w32-076f5e064fa7b6cc2c03b030abcf2cbd60514180.tar.gz busybox-w32-076f5e064fa7b6cc2c03b030abcf2cbd60514180.tar.bz2 busybox-w32-076f5e064fa7b6cc2c03b030abcf2cbd60514180.zip | |
less: code shrink
function old new delta
restore_tty - 29 +29
less_main 2107 2105 -2
getch_nowait 253 251 -2
buffer_print 614 612 -2
less_exit 51 12 -39
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/4 up/down: 29/-45) Total: -16 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/less.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index 26983f40d..6825e5577 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
| @@ -325,15 +325,18 @@ static void print_statusline(const char *str) | |||
| 325 | } | 325 | } |
| 326 | 326 | ||
| 327 | /* Exit the program gracefully */ | 327 | /* Exit the program gracefully */ |
| 328 | static void less_exit(int code) | 328 | static void restore_tty(void) |
| 329 | { | 329 | { |
| 330 | set_tty_cooked(); | 330 | set_tty_cooked(); |
| 331 | if (!(G.kbd_fd_orig_flags & O_NONBLOCK)) | 331 | if (!(G.kbd_fd_orig_flags & O_NONBLOCK)) |
| 332 | ndelay_off(kbd_fd); | 332 | ndelay_off(kbd_fd); |
| 333 | clear_line(); | 333 | clear_line(); |
| 334 | if (code < 0) | 334 | } |
| 335 | kill_myself_with_sig(- code); /* does not return */ | 335 | |
| 336 | exit(code); | 336 | static void less_exit(void) |
| 337 | { | ||
| 338 | restore_tty(); | ||
| 339 | exit(EXIT_SUCCESS); | ||
| 337 | } | 340 | } |
| 338 | 341 | ||
| 339 | #if (ENABLE_FEATURE_LESS_DASHCMD && ENABLE_FEATURE_LESS_LINENUMS) \ | 342 | #if (ENABLE_FEATURE_LESS_DASHCMD && ENABLE_FEATURE_LESS_LINENUMS) \ |
| @@ -913,7 +916,7 @@ static void buffer_print(void) | |||
| 913 | ) { | 916 | ) { |
| 914 | i = option_mask32 & FLAG_F ? 0 : cur_fline; | 917 | i = option_mask32 & FLAG_F ? 0 : cur_fline; |
| 915 | if (max_fline - i <= max_displayed_line) | 918 | if (max_fline - i <= max_displayed_line) |
| 916 | less_exit(EXIT_SUCCESS); | 919 | less_exit(); |
| 917 | } | 920 | } |
| 918 | status_print(); | 921 | status_print(); |
| 919 | } | 922 | } |
| @@ -1146,7 +1149,7 @@ static int64_t getch_nowait(void) | |||
| 1146 | goto again; | 1149 | goto again; |
| 1147 | } | 1150 | } |
| 1148 | /* EOF/error (ssh session got killed etc) */ | 1151 | /* EOF/error (ssh session got killed etc) */ |
| 1149 | less_exit(EXIT_SUCCESS); | 1152 | less_exit(); |
| 1150 | } | 1153 | } |
| 1151 | set_tty_cooked(); | 1154 | set_tty_cooked(); |
| 1152 | return key64; | 1155 | return key64; |
| @@ -1297,7 +1300,7 @@ static void colon_process(void) | |||
| 1297 | change_file(-1); | 1300 | change_file(-1); |
| 1298 | break; | 1301 | break; |
| 1299 | case 'q': | 1302 | case 'q': |
| 1300 | less_exit(EXIT_SUCCESS); | 1303 | less_exit(); |
| 1301 | break; | 1304 | break; |
| 1302 | case 'x': | 1305 | case 'x': |
| 1303 | change_file(0); | 1306 | change_file(0); |
| @@ -1715,7 +1718,7 @@ static void keypress_process(int keypress) | |||
| 1715 | buffer_line(cur_fline); | 1718 | buffer_line(cur_fline); |
| 1716 | break; | 1719 | break; |
| 1717 | case 'q': case 'Q': | 1720 | case 'q': case 'Q': |
| 1718 | less_exit(EXIT_SUCCESS); | 1721 | less_exit(); |
| 1719 | break; | 1722 | break; |
| 1720 | #if ENABLE_FEATURE_LESS_MARKS | 1723 | #if ENABLE_FEATURE_LESS_MARKS |
| 1721 | case 'm': | 1724 | case 'm': |
| @@ -1793,7 +1796,8 @@ static void keypress_process(int keypress) | |||
| 1793 | 1796 | ||
| 1794 | static void sig_catcher(int sig) | 1797 | static void sig_catcher(int sig) |
| 1795 | { | 1798 | { |
| 1796 | less_exit(- sig); | 1799 | restore_tty(); |
| 1800 | kill_myself_with_sig(sig); /* does not return */ | ||
| 1797 | } | 1801 | } |
| 1798 | 1802 | ||
| 1799 | #if ENABLE_FEATURE_LESS_WINCH | 1803 | #if ENABLE_FEATURE_LESS_WINCH |
