[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
the proposal of enhanced read() call
Hi,
when patching NCurses to work under single TOS I encountered the problem
with function keys - I needed to send a scan-code from read() call to the
NCurses library. I have developed something which doesn't look too well
but it actually works. The idea is to send an ESCape code as a beginning
of ESCape sequence (like it works with termcap under MiNT, for example).
Now I am thinking about patching the read() call much more to allow proper
sending of Shifted function keys (e.g. shift-down_arrow)...
The current solution is however good enough to distinguish the arrow keys,
Help, Undo, Home key and all 20 function keys under NCurses...
Comments on the patch are welcome.
--- read.c Mon Feb 14 23:48:10 1994
+++ /usr/src/libsrc/read.c Sat Jun 7 06:24:26 1997
@@ -39,6 +39,8 @@
* work properly
*/
+static int scancode = -1;
+
long
_read(fd, buf, size)
int fd;
@@ -137,8 +139,18 @@
}
}
else {
+ long key;
again:
- r = _console_read_byte(fd) & 0x00ff;
+ if (scancode > 0 && size == 1) { /* valid scan-code? */
+ *((char *)buf) = scancode;
+ scancode = -1; /* invalidate scan-code */
+ return 1;
+ }
+
+ key = _console_read_byte(fd);
+ r = key & 0x00ff; /* r = ASCII code */
+ key >>= 16; /* key = scan-code */
+
if (flags & ECHO) {
_console_write_byte(fd, (int)r);
}
@@ -155,8 +167,21 @@
goto again;
}
}
- *((char *)buf) = r;
- r = 1;
+ if (r != 0) {
+ *((char *)buf) = r;
+ r = 1;
+ }
+ else {
+ *((char *)buf) = '\034'; /* indicates that a scan-code follows */
+ if (size > 1) {
+ *((char *)buf+1) = key; /* put scan-code to buffer */
+ r = 2;
+ }
+ else {
+ scancode = key & 0x00ff;/* valid scan-code for next read() call */
+ r = 1;
+ }
+ }
}
return r;
Petr
--
WWW: http://ft3.zlin.vutbr.cz/stehlik/home.htm PARCP development
e-mail: stehlik@cas3.zlin.vutbr.cz
netmail: 2:421/36@fidonet.org, 90:1200/2@nest.ftn AfterBurner040 user