summaryrefslogtreecommitdiff
path: root/editors/vi.c
diff options
context:
space:
mode:
authorDenis Vlasenko2007-09-07 13:43:28 +0000
committerDenis Vlasenko2007-09-07 13:43:28 +0000
commit87f3b26b3a17369c12f4f9a70d6845796f8648d6 (patch)
tree2f7fe9fc910d5e97f695c902f848db497fec8bfd /editors/vi.c
parent40f0bcf9d3f8f8a8d14a9b2cff51761019c75cf4 (diff)
downloadbusybox-87f3b26b3a17369c12f4f9a70d6845796f8648d6.zip
busybox-87f3b26b3a17369c12f4f9a70d6845796f8648d6.tar.gz
*: replace select-for-one descriptor with poll, it's smaller.
$ ./.cmk bloatcheck function old new delta readit 406 364 -42 syslogd_main 1249 1206 -43 traceroute_main 4115 4060 -55 mysleep 112 45 -67 arpping 579 441 -138 tftp 1575 1182 -393 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/6 up/down: 0/-738) Total: -738 bytes text data bss dec hex filename 770580 1051 10764 782395 bf03b busybox_old 769820 1051 10764 781635 bed43 busybox_unstripped
Diffstat (limited to 'editors/vi.c')
-rw-r--r--editors/vi.c36
1 files changed, 13 insertions, 23 deletions
diff --git a/editors/vi.c b/editors/vi.c
index afbddc2..f7f8480 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
static void show_help(void); // display some help info
static void rawmode(void); // set "raw" mode on tty
static void cookmode(void); // return to "cooked" mode on tty
-static int mysleep(int); // sleep for 'h' 1/100 seconds
+// sleep for 'h' 1/100 seconds, return 1/0 if stdin is (ready for read)/(not ready)
+static int mysleep(int);
static char readit(void); // read (maybe cursor) key from stdin
static char get_one_char(void); // read 1 char from stdin
static int file_size(const char *); // what is the byte size of "fn"
@@ -2134,17 +2135,11 @@ static void catch_sig(int sig)
static int mysleep(int hund) // sleep for 'h' 1/100 seconds
{
- fd_set rfds;
- struct timeval tv;
+ struct pollfd pfd[1];
- // Don't hang- Wait 5/100 seconds- 1 Sec= 1000000
- fflush(stdout);
- FD_ZERO(&rfds);
- FD_SET(0, &rfds);
- tv.tv_sec = 0;
- tv.tv_usec = hund * 10000;
- select(1, &rfds, NULL, NULL, &tv);
- return FD_ISSET(0, &rfds);
+ pfd[0].fd = 0;
+ pfd[0].events = POLLIN;
+ return poll(pfd, 1, hund*10) > 0;
}
#define readbuffer bb_common_bufsiz1
@@ -2217,25 +2212,20 @@ static char readit(void) // read (maybe cursor) key from stdin
if (n <= 0)
return 0; // error
if (readbuffer[0] == 27) {
- fd_set rfds;
- struct timeval tv;
-
// This is an ESC char. Is this Esc sequence?
// Could be bare Esc key. See if there are any
// more chars to read after the ESC. This would
// be a Function or Cursor Key sequence.
- FD_ZERO(&rfds);
- FD_SET(0, &rfds);
- tv.tv_sec = 0;
- tv.tv_usec = 50000; // Wait 5/100 seconds- 1 Sec=1000000
-
+ struct pollfd pfd[1];
+ pfd[0].fd = 0;
+ pfd[0].events = POLLIN;
+ // Wait 50 ms
// keep reading while there are input chars and room in buffer
- while (select(1, &rfds, NULL, NULL, &tv) > 0 && n <= (MAX_LINELEN - 5)) {
+ while (poll(pfd, 1, 50) > 0 && n <= (MAX_LINELEN - 5)) {
// read the rest of the ESC string
- int r = read(0, (void *) (readbuffer + n), MAX_LINELEN - n);
- if (r > 0) {
+ int r = read(0, readbuffer + n, MAX_LINELEN - n);
+ if (r > 0)
n += r;
- }
}
}
readed_for_parse = n;