diff options
author | Denys Vlasenko | 2017-08-02 17:27:28 +0200 |
---|---|---|
committer | Denys Vlasenko | 2017-08-02 17:27:28 +0200 |
commit | 84ea60ed65f6ea6fd3b2170e44bbff5de410a78b (patch) | |
tree | 54837341ed6ed021d9b20400b8a8a5aea7bd3b62 /libbb | |
parent | dd4b446f76736c0a13a61a38d7d816b6e6b5fca2 (diff) | |
download | busybox-84ea60ed65f6ea6fd3b2170e44bbff5de410a78b.zip busybox-84ea60ed65f6ea6fd3b2170e44bbff5de410a78b.tar.gz |
line editing: make read_line_input() not take timeout param
It's almost always -1.
function old new delta
read_line_input 3902 3912 +10
new_line_input_t 24 31 +7
pgetc 583 585 +2
save_command_ps_at_cur_history 80 78 -2
read_line 76 74 -2
fgetc_interactive 246 244 -2
addLines 84 82 -2
doCommands 2226 2222 -4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/5 up/down: 19/-12) Total: 7 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/lineedit.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index e5721b0..0106093 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -1267,6 +1267,7 @@ line_input_t* FAST_FUNC new_line_input_t(int flags) { line_input_t *n = xzalloc(sizeof(*n)); n->flags = flags; + n->timeout = -1; #if MAX_HISTORY > 0 n->max_history = MAX_HISTORY; #endif @@ -2130,7 +2131,7 @@ enum { * Backspace deletes last matched char. * Control keys exit search and return to normal editing (at current history line). */ -static int32_t reverse_i_search(void) +static int32_t reverse_i_search(int timeout) { char match_buf[128]; /* for user input */ char read_key_buffer[KEYCODE_BUFFER_SIZE]; @@ -2152,8 +2153,8 @@ static int32_t reverse_i_search(void) int h; unsigned match_buf_len = strlen(match_buf); -//FIXME: correct timeout? - ic = lineedit_read_key(read_key_buffer, -1); +//FIXME: correct timeout? (i.e. count it down?) + ic = lineedit_read_key(read_key_buffer, timeout); switch (ic) { case CTRL('R'): /* searching for the next match */ @@ -2256,9 +2257,10 @@ static int32_t reverse_i_search(void) * (in both cases the cursor remains on the input line, '\n' is not printed) * >0 length of input string, including terminating '\n' */ -int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize, int timeout) +int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize) { int len; + int timeout; #if ENABLE_FEATURE_TAB_COMPLETION smallint lastWasTab = 0; #endif @@ -2297,8 +2299,15 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman maxsize = MAX_LINELEN; S.maxsize = maxsize; - /* With zero flags, no other fields are ever used */ - state = st ? st : (line_input_t*) &const_int_0; + timeout = -1; + /* Make state->flags == 0 if st is NULL. + * With zeroed flags, no other fields are ever referenced. + */ + state = (line_input_t*) &const_int_0; + if (st) { + state = st; + timeout = st->timeout; + } #if MAX_HISTORY > 0 # if ENABLE_FEATURE_EDITING_SAVEHISTORY if (state->hist_file) @@ -2510,7 +2519,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman } #if ENABLE_FEATURE_REVERSE_SEARCH case CTRL('R'): - ic = ic_raw = reverse_i_search(); + ic = ic_raw = reverse_i_search(timeout); goto again; #endif |