diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-02 00:55:41 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-11-02 00:55:41 +0000 |
commit | c51457ca5b0c1938c9b6813c7d72aa7d70fa88f8 (patch) | |
tree | cd9f6b6aa7ee6e79893e3dd3caecf1e87f7a49ca /miscutils/less.c | |
parent | 3c385cd706da9b309527d67e3c91c0d01915722e (diff) | |
download | busybox-w32-c51457ca5b0c1938c9b6813c7d72aa7d70fa88f8.tar.gz busybox-w32-c51457ca5b0c1938c9b6813c7d72aa7d70fa88f8.tar.bz2 busybox-w32-c51457ca5b0c1938c9b6813c7d72aa7d70fa88f8.zip |
less: fix pasting into search line ('/' cmd) -
it was mishandled because pasting "types" very fast
and read_key eats many chars. +30 bytes.
Diffstat (limited to 'miscutils/less.c')
-rw-r--r-- | miscutils/less.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/miscutils/less.c b/miscutils/less.c index 6c793ad8b..36d451271 100644 --- a/miscutils/less.c +++ b/miscutils/less.c | |||
@@ -96,7 +96,9 @@ struct globals { | |||
96 | smallint pattern_valid; | 96 | smallint pattern_valid; |
97 | #endif | 97 | #endif |
98 | smallint terminated; | 98 | smallint terminated; |
99 | smalluint kbd_input_size; | ||
99 | struct termios term_orig, term_less; | 100 | struct termios term_orig, term_less; |
101 | char kbd_input[KEYCODE_BUFFER_SIZE]; | ||
100 | }; | 102 | }; |
101 | #define G (*ptr_to_globals) | 103 | #define G (*ptr_to_globals) |
102 | #define cur_fline (G.cur_fline ) | 104 | #define cur_fline (G.cur_fline ) |
@@ -133,6 +135,8 @@ struct globals { | |||
133 | #define terminated (G.terminated ) | 135 | #define terminated (G.terminated ) |
134 | #define term_orig (G.term_orig ) | 136 | #define term_orig (G.term_orig ) |
135 | #define term_less (G.term_less ) | 137 | #define term_less (G.term_less ) |
138 | #define kbd_input_size (G.kbd_input_size ) | ||
139 | #define kbd_input (G.kbd_input ) | ||
136 | #define INIT_G() do { \ | 140 | #define INIT_G() do { \ |
137 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ | 141 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \ |
138 | less_gets_pos = -1; \ | 142 | less_gets_pos = -1; \ |
@@ -806,7 +810,6 @@ static void reinitialize(void) | |||
806 | 810 | ||
807 | static ssize_t getch_nowait(void) | 811 | static ssize_t getch_nowait(void) |
808 | { | 812 | { |
809 | char input[KEYCODE_BUFFER_SIZE]; | ||
810 | int rd; | 813 | int rd; |
811 | struct pollfd pfd[2]; | 814 | struct pollfd pfd[2]; |
812 | 815 | ||
@@ -837,22 +840,25 @@ static ssize_t getch_nowait(void) | |||
837 | if (less_gets_pos >= 0) | 840 | if (less_gets_pos >= 0) |
838 | move_cursor(max_displayed_line + 2, less_gets_pos + 1); | 841 | move_cursor(max_displayed_line + 2, less_gets_pos + 1); |
839 | fflush(stdout); | 842 | fflush(stdout); |
843 | |||
844 | if (kbd_input_size == 0) { | ||
840 | #if ENABLE_FEATURE_LESS_WINCH | 845 | #if ENABLE_FEATURE_LESS_WINCH |
841 | while (1) { | 846 | while (1) { |
842 | int r; | 847 | int r; |
843 | /* NB: SIGWINCH interrupts poll() */ | 848 | /* NB: SIGWINCH interrupts poll() */ |
844 | r = poll(pfd + rd, 2 - rd, -1); | 849 | r = poll(pfd + rd, 2 - rd, -1); |
845 | if (/*r < 0 && errno == EINTR &&*/ winch_counter) | 850 | if (/*r < 0 && errno == EINTR &&*/ winch_counter) |
846 | return '\\'; /* anything which has no defined function */ | 851 | return '\\'; /* anything which has no defined function */ |
847 | if (r) break; | 852 | if (r) break; |
848 | } | 853 | } |
849 | #else | 854 | #else |
850 | safe_poll(pfd + rd, 2 - rd, -1); | 855 | safe_poll(pfd + rd, 2 - rd, -1); |
851 | #endif | 856 | #endif |
857 | } | ||
852 | 858 | ||
853 | /* We have kbd_fd in O_NONBLOCK mode, read inside read_key() | 859 | /* We have kbd_fd in O_NONBLOCK mode, read inside read_key() |
854 | * would not block even if there is no input available */ | 860 | * would not block even if there is no input available */ |
855 | rd = read_key(kbd_fd, NULL, input); | 861 | rd = read_key(kbd_fd, &kbd_input_size, kbd_input); |
856 | if (rd == -1) { | 862 | if (rd == -1) { |
857 | if (errno == EAGAIN) { | 863 | if (errno == EAGAIN) { |
858 | /* No keyboard input available. Since poll() did return, | 864 | /* No keyboard input available. Since poll() did return, |