From 01ccdd1d3c5221789f1ac62ced12b7984d910705 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 11 Jan 2017 16:17:59 +0100 Subject: libbb: consolidate the code to set termios unbuffered mode function old new delta set_termios_to_raw - 116 +116 count_lines 72 74 +2 powertop_main 1458 1430 -28 top_main 943 914 -29 more_main 759 714 -45 fsck_minix_main 2969 2921 -48 conspy_main 1197 1135 -62 rawmode 99 36 -63 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/6 up/down: 118/-275) Total: -157 bytes Signed-off-by: Denys Vlasenko --- editors/vi.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'editors/vi.c') diff --git a/editors/vi.c b/editors/vi.c index b56b04bdd..1e5ef44fb 100644 --- a/editors/vi.c +++ b/editors/vi.c @@ -354,7 +354,7 @@ struct globals { #if ENABLE_FEATURE_VI_USE_SIGNALS sigjmp_buf restart; // catch_sig() #endif - struct termios term_orig, term_vi; // remember what the cooked mode was + struct termios term_orig; // remember what the cooked mode was #if ENABLE_FEATURE_VI_COLON char *initial_cmds[3]; // currently 2 entries, NULL terminated #endif @@ -462,7 +462,6 @@ struct globals { #define context_end (G.context_end ) #define restart (G.restart ) #define term_orig (G.term_orig ) -#define term_vi (G.term_vi ) #define initial_cmds (G.initial_cmds ) #define readbuffer (G.readbuffer ) #define scr_out_buf (G.scr_out_buf ) @@ -2731,15 +2730,9 @@ static char *swap_context(char *p) // goto new context for '' command make this //----- Set terminal attributes -------------------------------- static void rawmode(void) { - tcgetattr(0, &term_orig); - term_vi = term_orig; - term_vi.c_lflag &= (~ICANON & ~ECHO); // leave ISIG on - allow intr's - term_vi.c_iflag &= (~IXON & ~ICRNL); - term_vi.c_oflag &= (~ONLCR); - term_vi.c_cc[VMIN] = 1; - term_vi.c_cc[VTIME] = 0; - erase_char = term_vi.c_cc[VERASE]; - tcsetattr_stdin_TCSANOW(&term_vi); + // no TERMIOS_CLEAR_ISIG: leave ISIG on - allow signals + set_termios_to_raw(STDIN_FILENO, &term_orig, TERMIOS_RAW_CRNL); + erase_char = term_orig.c_cc[VERASE]; } static void cookmode(void) -- cgit v1.2.3