How can I detect waiting characters in a curses application ?

Tom Boutell boutell at freezer.it.udel.edu
Fri Dec 7 12:18:10 AEST 1990


In article <1990Dec6.234823.2763 at ux1.cso.uiuc.edu> carroll at cs.uiuc.edu (Alan M. Carroll) writes:
>Try this. (test by compiling and running. Type and hit return. Works
>for me on ISC 2.0.2).
>
>#include <stropts.h>
>#include <poll.h>
>
>int istypeahead(fd) int fd;		/* file descriptor */
... Lots of good code ...
>}
>
>main()
>{
>  while (1)
>    {
>      if (istypeahead(0)) printf("Input waiting\n");
       Not so good. Or rather, not so portable. I strongly suggets you do
       this instead:
       if (istypeahead(fileno(stdin))) printf("Input waiting\n");
       This is very widely compatible; I've just been through this
       particular mill. Trust me- I know. (-: Of course, it's most
       sensible to save fileno(stdin) to an int and just use
       istypeahead(stdinfd) where stdinfd is the int in question.
>      else printf("No input\n");
>      sleep(1);
>    }
>}

Otherwise very good stuff.


-- 
THE TECHNOLOGY HOUSE: An idea whose time has come!
My girlfriend is a pseudo- aardvark. She is quite insistent on this point.
And remember- when all else fails- and no one else can help-
boutell at freezer.it.udel.edu



More information about the Comp.unix.programmer mailing list