aboutsummaryrefslogtreecommitdiff
path: root/libbb/lineedit.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2017-08-22 14:56:12 +0100
committerRon Yorston <rmy@pobox.com>2017-08-22 14:56:12 +0100
commitce9af1cc5ea23f754587448cf35b5120c77bfeef (patch)
tree69e5eaba5e75ab909ed92d5045393471b8ff3c13 /libbb/lineedit.c
parentc170026700eabb10147dd848c45c06995b43a32e (diff)
parente837a0dbbebf4229306df98fe9ee3b9bb30630c4 (diff)
downloadbusybox-w32-ce9af1cc5ea23f754587448cf35b5120c77bfeef.tar.gz
busybox-w32-ce9af1cc5ea23f754587448cf35b5120c77bfeef.tar.bz2
busybox-w32-ce9af1cc5ea23f754587448cf35b5120c77bfeef.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb/lineedit.c')
-rw-r--r--libbb/lineedit.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 051a39b2e..c2b0a3842 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -1320,6 +1320,7 @@ line_input_t* FAST_FUNC new_line_input_t(int flags)
1320{ 1320{
1321 line_input_t *n = xzalloc(sizeof(*n)); 1321 line_input_t *n = xzalloc(sizeof(*n));
1322 n->flags = flags; 1322 n->flags = flags;
1323 n->timeout = -1;
1323#if MAX_HISTORY > 0 1324#if MAX_HISTORY > 0
1324 n->max_history = MAX_HISTORY; 1325 n->max_history = MAX_HISTORY;
1325#endif 1326#endif
@@ -2192,7 +2193,7 @@ enum {
2192 * Backspace deletes last matched char. 2193 * Backspace deletes last matched char.
2193 * Control keys exit search and return to normal editing (at current history line). 2194 * Control keys exit search and return to normal editing (at current history line).
2194 */ 2195 */
2195static int32_t reverse_i_search(void) 2196static int32_t reverse_i_search(int timeout)
2196{ 2197{
2197 char match_buf[128]; /* for user input */ 2198 char match_buf[128]; /* for user input */
2198 char read_key_buffer[KEYCODE_BUFFER_SIZE]; 2199 char read_key_buffer[KEYCODE_BUFFER_SIZE];
@@ -2214,8 +2215,8 @@ static int32_t reverse_i_search(void)
2214 int h; 2215 int h;
2215 unsigned match_buf_len = strlen(match_buf); 2216 unsigned match_buf_len = strlen(match_buf);
2216 2217
2217//FIXME: correct timeout? 2218//FIXME: correct timeout? (i.e. count it down?)
2218 ic = lineedit_read_key(read_key_buffer, -1); 2219 ic = lineedit_read_key(read_key_buffer, timeout);
2219 2220
2220 switch (ic) { 2221 switch (ic) {
2221 case CTRL('R'): /* searching for the next match */ 2222 case CTRL('R'): /* searching for the next match */
@@ -2318,9 +2319,10 @@ static int32_t reverse_i_search(void)
2318 * (in both cases the cursor remains on the input line, '\n' is not printed) 2319 * (in both cases the cursor remains on the input line, '\n' is not printed)
2319 * >0 length of input string, including terminating '\n' 2320 * >0 length of input string, including terminating '\n'
2320 */ 2321 */
2321int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize, int timeout) 2322int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize)
2322{ 2323{
2323 int len; 2324 int len;
2325 int timeout;
2324#if ENABLE_FEATURE_TAB_COMPLETION 2326#if ENABLE_FEATURE_TAB_COMPLETION
2325 smallint lastWasTab = 0; 2327 smallint lastWasTab = 0;
2326#endif 2328#endif
@@ -2366,8 +2368,15 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2366 maxsize = MAX_LINELEN; 2368 maxsize = MAX_LINELEN;
2367 S.maxsize = maxsize; 2369 S.maxsize = maxsize;
2368 2370
2369 /* With zero flags, no other fields are ever used */ 2371 timeout = -1;
2370 state = st ? st : (line_input_t*) &const_int_0; 2372 /* Make state->flags == 0 if st is NULL.
2373 * With zeroed flags, no other fields are ever referenced.
2374 */
2375 state = (line_input_t*) &const_int_0;
2376 if (st) {
2377 state = st;
2378 timeout = st->timeout;
2379 }
2371#if MAX_HISTORY > 0 2380#if MAX_HISTORY > 0
2372# if ENABLE_FEATURE_EDITING_SAVEHISTORY 2381# if ENABLE_FEATURE_EDITING_SAVEHISTORY
2373 if (state->hist_file) 2382 if (state->hist_file)
@@ -2584,7 +2593,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2584 } 2593 }
2585#if ENABLE_FEATURE_REVERSE_SEARCH 2594#if ENABLE_FEATURE_REVERSE_SEARCH
2586 case CTRL('R'): 2595 case CTRL('R'):
2587 ic = ic_raw = reverse_i_search(); 2596 ic = ic_raw = reverse_i_search(timeout);
2588 goto again; 2597 goto again;
2589#endif 2598#endif
2590 2599