[comp.lang.c] WANTED: do while no key pressed

air@anableps.berkeley.edu (03/26/89)

title says it all.
tnx in adv.
please email to  air@anableps.berkeley.edu

_______  _    __   _    _        __  __  Arthur Ernest Wright @
\     / / \  /    / \  / \  /   /   /  \ (503)344-7969  
 \ O / /__/ /__  /  / /__/ /   /__  \__  ___  _  _  _  
  \ / /    /    /  / /    /   /       |   |  |_ /  | \ /\ |  /\ /_ \/
   v /    /__   \_/ /    /__ /__  \__/    |  |_ \_ | | \/ |_ \/ \/ /

chris@mimsy.UUCP (Chris Torek) (03/26/89)

In article <22064@agate.BERKELEY.EDU> air@anableps.berkeley.edu writes:
>title says it all.

Titles get truncated, so here it is again:

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

Step 1: define, portably, `key pressed'.

I can think of a number of different definitions:

	- there is input available (has nothing to do with `keys' pe se)
	- terminal input is available, character-at-a-time
	- a non-modifier (not SHIFT, etc.) key on a computer keyboard
	  is in the `down' position
	- any key (including SHIFT) is in the down position

The only one that can even make a pretense at portability is the
first, and on a closer look, one discovers that there is no portable
way to do that either.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris

chip@vector.UUCP (Chip Rosenthal) (03/27/89)

In article <16535@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes:
>In article <22064@agate.BERKELEY.EDU> air@anableps.berkeley.edu writes:
>>title says it all.
>one discovers that there is no portable way to do that either.

Not to mention that busy-looping is a poor idea when avoidable.  (That
is the usual purpose of such a function.)

Didn't we go around on this topic just a few weeks?
-- 
Chip Rosenthal     chip@vector.UUCP    | -------- watch this space --------
Dallas Semiconductor   214-450-5337    | - real domain address coming soon -

usenet@agate.BERKELEY.EDU (USENET Administrator) (03/28/89)

From: air@anableps.berkeley.edu ()
Path: anableps.berkeley.edu!air

SUMMARY: Cant get there from here (System dependant code)

That was my guess, and I was right.
tnx again.
air@mica.berkeley.edu


_______  _    __   _    _        __  __  Arthur Ernest Wright @
\     / / \  /    / \  / \  /   /   /  \ (503)344-7969  
 \ O / /__/ /__  /  / /__/ /   /__  \__  ___  _  _  _  
  \ / /    /    /  / /    /   /       |   |  |_ /  | \ /\ |  /\ /_ \/
   v /    /__   \_/ /    /__ /__  \__/    |  |_ \_ | | \/ |_ \/ \/ /

hankd@pur-ee.UUCP (Hank Dietz) (03/28/89)

In article <796@vector.UUCP> chip@vector.UUCP (Chip Rosenthal) writes:
>In article <16535@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes:
>>In article <22064@agate.BERKELEY.EDU> air@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@ee.ecn.purdue.edu

henry@utzoo.uucp (Henry Spencer) (03/29/89)

In article <11119@pur-ee.UUCP> hankd@pur-ee.UUCP (Hank Dietz) writes:
>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...

Sorry, you are thinking of a V7 variant, not V7 as released.  NULL was a
valid buffer address in V7 and hence could not be used for such a test
(and was not -- I just checked our V7 sources).
-- 
Welcome to Mars!  Your         |     Henry Spencer at U of Toronto Zoology
passport and visa, comrade?    | uunet!attcan!utzoo!henry henry@zoo.toronto.edu