WANTED: do while no key pressed (in portable code)

Hank Dietz hankd at pur-ee.UUCP
Tue Mar 28 06:15:04 AEST 1989


In article <796 at vector.UUCP> chip at vector.UUCP (Chip Rosenthal) writes:
>In article <16535 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>>In article <22064 at agate.BERKELEY.EDU> air at anableps.berkeley.edu writes:
...[lots of stuff as to foolishness of key press testing and how it
    could never be done portably]....

I think he's just looking for a way to do things like update the screen
incrementally, only performing update until a new keyboard command makes the
yet-to-be-drawn portion of the screen image be out-of-date (e.g., as in
editors like emacs) -- a very sane thing to want to do.  Unfortunately, you
can't do it portably because a non-blocking read was not one of those things
designed into unix (or CP/M).

It could only be done under v6pwb unix by using two processes: one does a
raw mode read, spits out the char on a pipe, and signals the other process
that a char has arrived so that it can read the pipe and not block.  Yuck.

In v7, it was added as empty(fd) (actually read(fd,NULL,0)) to test if a
char could be read without actually reading it.  Then you got an ioctl mode
for non-blocking input.  Then you got cbreak mode.  Etc.  I think the only
thing that works on all unix systems is the raw mode v6pwb two-process hack.

In most cases, under unix, you probably also want no echo mode set.

As for other OS, in later versions of CP/M (v2), non-blocking input of a
char became bdos(6,0xff) (as raw mode with no echo).  The problem is that a
return value of zero represented either no input available or that the NUL
char was input -- you couldn't tell which.  I am blissfully ignorant of the
situation relative to MSDOS (but it probably follows the CP/M convention).

I too would really like a package which uses the BEST POSSIBLE
IMPLEMENTATION for each OS...  anyone out there want to write and post one?

						-hankd at ee.ecn.purdue.edu



More information about the Comp.lang.c mailing list