aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/vi.c36
1 files changed, 13 insertions, 23 deletions
diff --git a/editors/vi.c b/editors/vi.c
index afbddc251..f7f84807d 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -237,7 +237,8 @@ static char *yank_delete(char *, char *, int, int); // yank text[] into register
237static void show_help(void); // display some help info 237static void show_help(void); // display some help info
238static void rawmode(void); // set "raw" mode on tty 238static void rawmode(void); // set "raw" mode on tty
239static void cookmode(void); // return to "cooked" mode on tty 239static void cookmode(void); // return to "cooked" mode on tty
240static int mysleep(int); // sleep for 'h' 1/100 seconds 240// sleep for 'h' 1/100 seconds, return 1/0 if stdin is (ready for read)/(not ready)
241static int mysleep(int);
241static char readit(void); // read (maybe cursor) key from stdin 242static char readit(void); // read (maybe cursor) key from stdin
242static char get_one_char(void); // read 1 char from stdin 243static char get_one_char(void); // read 1 char from stdin
243static int file_size(const char *); // what is the byte size of "fn" 244static int file_size(const char *); // what is the byte size of "fn"
@@ -2134,17 +2135,11 @@ static void catch_sig(int sig)
2134 2135
2135static int mysleep(int hund) // sleep for 'h' 1/100 seconds 2136static int mysleep(int hund) // sleep for 'h' 1/100 seconds
2136{ 2137{
2137 fd_set rfds; 2138 struct pollfd pfd[1];
2138 struct timeval tv;
2139 2139
2140 // Don't hang- Wait 5/100 seconds- 1 Sec= 1000000 2140 pfd[0].fd = 0;
2141 fflush(stdout); 2141 pfd[0].events = POLLIN;
2142 FD_ZERO(&rfds); 2142 return poll(pfd, 1, hund*10) > 0;
2143 FD_SET(0, &rfds);
2144 tv.tv_sec = 0;
2145 tv.tv_usec = hund * 10000;
2146 select(1, &rfds, NULL, NULL, &tv);
2147 return FD_ISSET(0, &rfds);
2148} 2143}
2149 2144
2150#define readbuffer bb_common_bufsiz1 2145#define readbuffer bb_common_bufsiz1
@@ -2217,25 +2212,20 @@ static char readit(void) // read (maybe cursor) key from stdin
2217 if (n <= 0) 2212 if (n <= 0)
2218 return 0; // error 2213 return 0; // error
2219 if (readbuffer[0] == 27) { 2214 if (readbuffer[0] == 27) {
2220 fd_set rfds;
2221 struct timeval tv;
2222
2223 // This is an ESC char. Is this Esc sequence? 2215 // This is an ESC char. Is this Esc sequence?
2224 // Could be bare Esc key. See if there are any 2216 // Could be bare Esc key. See if there are any
2225 // more chars to read after the ESC. This would 2217 // more chars to read after the ESC. This would
2226 // be a Function or Cursor Key sequence. 2218 // be a Function or Cursor Key sequence.
2227 FD_ZERO(&rfds); 2219 struct pollfd pfd[1];
2228 FD_SET(0, &rfds); 2220 pfd[0].fd = 0;
2229 tv.tv_sec = 0; 2221 pfd[0].events = POLLIN;
2230 tv.tv_usec = 50000; // Wait 5/100 seconds- 1 Sec=1000000 2222 // Wait 50 ms
2231
2232 // keep reading while there are input chars and room in buffer 2223 // keep reading while there are input chars and room in buffer
2233 while (select(1, &rfds, NULL, NULL, &tv) > 0 && n <= (MAX_LINELEN - 5)) { 2224 while (poll(pfd, 1, 50) > 0 && n <= (MAX_LINELEN - 5)) {
2234 // read the rest of the ESC string 2225 // read the rest of the ESC string
2235 int r = read(0, (void *) (readbuffer + n), MAX_LINELEN - n); 2226 int r = read(0, readbuffer + n, MAX_LINELEN - n);
2236 if (r > 0) { 2227 if (r > 0)
2237 n += r; 2228 n += r;
2238 }
2239 } 2229 }
2240 } 2230 }
2241 readed_for_parse = n; 2231 readed_for_parse = n;