summaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko2022-01-05 22:04:21 +0100
committerDenys Vlasenko2022-01-05 22:04:21 +0100
commit076f5e064fa7b6cc2c03b030abcf2cbd60514180 (patch)
tree44d5aefae7f06f10b304e5413988dfe16b3e5fe9 /miscutils
parent34e0bb3931b595e7a48061255692ec4ff29499c5 (diff)
downloadbusybox-076f5e064fa7b6cc2c03b030abcf2cbd60514180.zip
busybox-076f5e064fa7b6cc2c03b030abcf2cbd60514180.tar.gz
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.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/miscutils/less.c b/miscutils/less.c
index 26983f4..6825e55 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -325,15 +325,18 @@ static void print_statusline(const char *str)
}
/* Exit the program gracefully */
-static void less_exit(int code)
+static void restore_tty(void)
{
set_tty_cooked();
if (!(G.kbd_fd_orig_flags & O_NONBLOCK))
ndelay_off(kbd_fd);
clear_line();
- if (code < 0)
- kill_myself_with_sig(- code); /* does not return */
- exit(code);
+}
+
+static void less_exit(void)
+{
+ restore_tty();
+ exit(EXIT_SUCCESS);
}
#if (ENABLE_FEATURE_LESS_DASHCMD && ENABLE_FEATURE_LESS_LINENUMS) \
@@ -913,7 +916,7 @@ static void buffer_print(void)
) {
i = option_mask32 & FLAG_F ? 0 : cur_fline;
if (max_fline - i <= max_displayed_line)
- less_exit(EXIT_SUCCESS);
+ less_exit();
}
status_print();
}
@@ -1146,7 +1149,7 @@ static int64_t getch_nowait(void)
goto again;
}
/* EOF/error (ssh session got killed etc) */
- less_exit(EXIT_SUCCESS);
+ less_exit();
}
set_tty_cooked();
return key64;
@@ -1297,7 +1300,7 @@ static void colon_process(void)
change_file(-1);
break;
case 'q':
- less_exit(EXIT_SUCCESS);
+ less_exit();
break;
case 'x':
change_file(0);
@@ -1715,7 +1718,7 @@ static void keypress_process(int keypress)
buffer_line(cur_fline);
break;
case 'q': case 'Q':
- less_exit(EXIT_SUCCESS);
+ less_exit();
break;
#if ENABLE_FEATURE_LESS_MARKS
case 'm':
@@ -1793,7 +1796,8 @@ static void keypress_process(int keypress)
static void sig_catcher(int sig)
{
- less_exit(- sig);
+ restore_tty();
+ kill_myself_with_sig(sig); /* does not return */
}
#if ENABLE_FEATURE_LESS_WINCH