diff options
author | Ron Yorston <rmy@pobox.com> | 2018-02-25 22:09:54 +0300 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-02-25 22:09:54 +0300 |
commit | 23286900da2f38de6b7f0c8318263eac4ce774d1 (patch) | |
tree | 5e7bf2e0aa87ac17de2f92adfd2de48683c0abfa /libbb/lineedit.c | |
parent | e20a703fd34fa0f3ac17c53d868735a99d794a3e (diff) |
lineedit: allow window size tracking to be disabled
function old new delta
lineedit_read_key 269 261 -8
win_changed 47 - -47
read_line_input 3884 3821 -63
cmdedit_setwidth 63 - -63
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 0/2 up/down: 0/-181) Total: -181 bytes
Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/lineedit.c')
-rw-r--r-- | libbb/lineedit.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 896bbc88c..678c4d29c 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -151,9 +151,11 @@ struct lineedit_statics { unsigned num_matches; #endif +#if ENABLE_FEATURE_EDITING_WINCH unsigned SIGWINCH_saved; volatile unsigned SIGWINCH_count; volatile smallint ok_to_redraw; +#endif #if ENABLE_FEATURE_EDITING_VI # define DELBUFSIZ 128 @@ -165,8 +167,10 @@ struct lineedit_statics { smallint sent_ESC_br6n; #endif +#if ENABLE_FEATURE_EDITING_WINCH /* Largish struct, keeping it last results in smaller code */ struct sigaction SIGWINCH_handler; +#endif }; /* See lineedit_ptr_hack.c */ @@ -2030,6 +2034,7 @@ static void parse_and_put_prompt(const char *prmt_ptr) } #endif +#if ENABLE_FEATURE_EDITING_WINCH static void cmdedit_setwidth(void) { int new_y; @@ -2054,6 +2059,7 @@ static void win_changed(int nsig UNUSED_PARAM) S.SIGWINCH_count++; } } +#endif static int lineedit_read_key(char *read_key_buffer, int timeout) { @@ -2072,9 +2078,9 @@ static int lineedit_read_key(char *read_key_buffer, int timeout) * * Note: read_key sets errno to 0 on success. */ - S.ok_to_redraw = 1; + IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 1;) ic = read_key(STDIN_FILENO, read_key_buffer, timeout); - S.ok_to_redraw = 0; + IF_FEATURE_EDITING_WINCH(S.ok_to_redraw = 0;) if (errno) { #if ENABLE_UNICODE_SUPPORT if (errno == EAGAIN && unicode_idx != 0) @@ -2408,11 +2414,12 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman parse_and_put_prompt(prompt); ask_terminal(); +#if ENABLE_FEATURE_EDITING_WINCH /* Install window resize handler (NB: after *all* init is complete) */ S.SIGWINCH_handler.sa_handler = win_changed; S.SIGWINCH_handler.sa_flags = SA_RESTART; sigaction(SIGWINCH, &S.SIGWINCH_handler, &S.SIGWINCH_handler); - +#endif read_key_buffer[0] = 0; while (1) { /* @@ -2424,6 +2431,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman * in one place. */ int32_t ic, ic_raw; +#if ENABLE_FEATURE_EDITING_WINCH unsigned count; count = S.SIGWINCH_count; @@ -2431,7 +2439,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman S.SIGWINCH_saved = count; cmdedit_setwidth(); } - +#endif ic = ic_raw = lineedit_read_key(read_key_buffer, timeout); #if ENABLE_FEATURE_REVERSE_SEARCH @@ -2868,8 +2876,10 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman /* restore initial_settings */ tcsetattr_stdin_TCSANOW(&initial_settings); +#if ENABLE_FEATURE_EDITING_WINCH /* restore SIGWINCH handler */ sigaction_set(SIGWINCH, &S.SIGWINCH_handler); +#endif fflush_all(); len = command_len; |