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>
This commit is contained in:
Denys Vlasenko 2022-01-05 22:04:21 +01:00
parent 34e0bb3931
commit 076f5e064f

View File

@ -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