[comp.sys.amiga.programmer] keyboards and C

kenh@ersys.edmonton.ab.ca (Ken Huisman) (06/11/91)

I need to know if there is a way to examine stdin to see if there
is a character waiting.  Something like that ol' get function in
basic which grabbed a character from the keyboard if there was one,
and if there wasn't just returned nothing.
 
I have to make this work on a Sparcstation in C, so if anyone has
an idea, I'd appreciate it if it wasn
't
machine-specific.
 
Thanks.
 
Ken
ersys!kenh@nro.cs.athabascau.ca

Ken Huisman              kenh@ersys.edmonton.ab.ca
Edmonton Remote Systems:  Serving Northern Alberta since 1982

carolyn@cbmvax.commodore.com (Carolyn Scheppner - CATS) (06/14/91)

In article <B5Xc43w164w@ersys.edmonton.ab.ca> kenh@ersys.edmonton.ab.ca (Ken Huisman) writes:
>I need to know if there is a way to examine stdin to see if there
>is a character waiting.  Something like that ol' get function in
>basic which grabbed a character from the keyboard if there was one,
>and if there wasn't just returned nothing.

If stdin is an AmigaDOS filehandle (ie. if you linked with something
like Astartup.obj my.o library Amiga.lib LC.lib) then you should
be able to use WaitForChar() directly on stdin:

(from dos.doc)

    NAME
        WaitForChar -- Determine if chars arrive within a time limit

    SYNOPSIS
        status = WaitForChar( file, timeout )
        D0                    D1    D2

        BOOL WaitForChar(BPTR, LONG)

The timeout is in microseconds so give something reasonably large
enough.  Do NOT give 0.  Read the autodoc....


If you have a Lattice/SAS or Aztec FILE * stdin, then you will
have to look at their structure definition for FILE in their
include files and see if they show the field which contains the
AmigaDOS filehandle.  If they do then, (assume it's called filehandle)
you could do something like   if(WaitForChar( cfile->filehandle, 1000 ))
-- 
==========================================================================
 Carolyn Scheppner -- Tech. Mgr. CATS - Commodore Amiga Technical Support
 PHONE 215-431-9180 {uunet,rutgers}!cbmvax!carolyn  carolyn@commodore.com

 Oh I'm a numberjack and I'm OK, I code all night and I work all day...
==========================================================================