diff options
author | hpa <hpa> | 2004-12-20 22:55:48 +0000 |
---|---|---|
committer | hpa <hpa> | 2004-12-20 22:55:48 +0000 |
commit | 227b9fc57a0eb10fae0865d84c5ab88f9eab4f6a (patch) | |
tree | ecef8c238330bf7be0b998b6bd62d33c991758ea | |
parent | 6971c383a933046341da07d30270a91434322426 (diff) | |
download | syslinux-227b9fc57a0eb10fae0865d84c5ab88f9eab4f6a.tar.gz |
Actually get things working with nonblocking raw console read;
this allows us to detect the Esc key.
-rw-r--r-- | com32/include/time.h | 0 | ||||
-rw-r--r-- | com32/lib/sys/line_input.c | 6 | ||||
-rw-r--r-- | com32/lib/sys/rawcon_read.c | 20 | ||||
-rw-r--r-- | com32/libutil/ansiraw.c | 2 | ||||
-rw-r--r-- | com32/libutil/get_key.c | 15 | ||||
-rw-r--r-- | com32/samples/keytest.c | 3 |
6 files changed, 21 insertions, 25 deletions
diff --git a/com32/include/time.h b/com32/include/time.h new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/com32/include/time.h diff --git a/com32/lib/sys/line_input.c b/com32/lib/sys/line_input.c index afeeec00..e0dd3997 100644 --- a/com32/lib/sys/line_input.c +++ b/com32/lib/sys/line_input.c @@ -47,11 +47,9 @@ ssize_t __line_input(struct file_info *fp, char *buf, size_t bufsize, for(;;) { rv = get_char(fp, &ch, 1); - if ( rv == -1 && (errno == EINTR || errno == EAGAIN) ) + if ( rv != 1 ) continue; - else if ( rv != 1 ) - return n; - + switch ( ch ) { case '\n': /* Ignore incoming linefeed */ break; diff --git a/com32/lib/sys/rawcon_read.c b/com32/lib/sys/rawcon_read.c index e767c7a4..483dbfa5 100644 --- a/com32/lib/sys/rawcon_read.c +++ b/com32/lib/sys/rawcon_read.c @@ -54,19 +54,12 @@ ssize_t __rawcon_read(struct file_info *fp, void *buf, size_t count) start = times(NULL); - while ( count ) { - if ( (clock_t)(times(NULL) - start) >= 2+CLK_TCK/20 ) - break; - + while ( n < count ) { /* Poll */ ireg.eax.b[1] = 0x0B; __intcall(0x21, &ireg, &oreg); - if ( !oreg.eax.b[0] ) { - if ( n ) - break; /* We have data, deliver it */ - else - continue; - } + if ( !oreg.eax.b[0] ) + break; /* We have data, go get it */ ireg.eax.b[1] = 0x08; @@ -75,12 +68,7 @@ ssize_t __rawcon_read(struct file_info *fp, void *buf, size_t count) n++; } - if ( n == 0 ) { - errno = EAGAIN; - return -1; - } else { - return n; - } + return n; } const struct input_dev dev_rawcon_r = { diff --git a/com32/libutil/ansiraw.c b/com32/libutil/ansiraw.c index 0e6675a7..1a0820d3 100644 --- a/com32/libutil/ansiraw.c +++ b/com32/libutil/ansiraw.c @@ -85,7 +85,7 @@ void console_ansi_raw(void) tio.c_iflag |= IGNCR; tio.c_lflag &= ~(ISIG|ICANON|ECHO); tio.c_cc[VMIN] = 0; - tio.c_cc[VTIME] = 2; + tio.c_cc[VTIME] = 1; /* Don't 100% busy-wait in Linux */ tcsetattr(0, TCSANOW, &tio); fputs("\033[0m\033[20h", stdout); } diff --git a/com32/libutil/get_key.c b/com32/libutil/get_key.c index e2437612..b9042d6d 100644 --- a/com32/libutil/get_key.c +++ b/com32/libutil/get_key.c @@ -38,6 +38,8 @@ #include <string.h> #include <errno.h> #include <unistd.h> +#include <time.h> +#include <sys/times.h> #include <getkey.h> struct keycode { @@ -116,21 +118,25 @@ int get_key(FILE *f) const struct keycode *kc; int another; unsigned char ch; + clock_t start; nc = 0; + start = times(NULL); do { rv = read(fileno(f), &ch, 1); - if ( rv == 0 ) - return EOF; - else if ( rv == -1 && errno == EAGAIN ) { - if ( nc ) + if ( rv == 0 || (rv == -1 && errno == EAGAIN) ) { + if ( nc && (clock_t)(times(NULL)-start) >= 2+CLK_TCK/20 ) return buffer[0]; /* timeout */ else { + if ( !nc ) + start = times(NULL); another = 1; continue; } } + start = times(NULL); + buffer[nc++] = ch; another = 0; @@ -138,6 +144,7 @@ int get_key(FILE *f) if ( nc == kc->seqlen && !memcmp(buffer, kc->seq, nc) ) return kc->code; else if ( nc < kc->seqlen && !memcmp(buffer, kc->seq, nc) ) { + another = 1; break; } } diff --git a/com32/samples/keytest.c b/com32/samples/keytest.c index 0500e057..d10bd665 100644 --- a/com32/samples/keytest.c +++ b/com32/samples/keytest.c @@ -20,6 +20,8 @@ #include <string.h> #include <stdio.h> #include <stdlib.h> +#include <time.h> +#include <sys/times.h> #include <consoles.h> /* Provided by libutil */ #include <getkey.h> @@ -70,6 +72,7 @@ int main(void) { console_ansi_raw(); + printf("CLK_TCK = %d\n", (int)CLK_TCK); printf("Press keys, end with Ctrl-C...\n"); for (;;) { |