From: mread AT ozemail DOT com DOT au (Mark Read) Subject: Re: how to do a timeout in getchar 11 Mar 1998 05:09:07 -0800 Message-ID: <00a801bd4c36$8f05aa20$299f23cb.cygnus.gnu-win32@markread> Reply-To: "Mark Read" Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit To: "root" Cc: Hi Jacob. I've been looking for a way to set a flag if a key *isn't* present in the keybrd buffer, or set a flag *immediately* a SIGINT (eg. ctrl-c) occurs. However, I can't find a solution to either of these requirements. getchar(): Will suspend my loop until a character is received in the kbd buffer. I want my loop to continue executing if *nothing* is in the kbd buffer! _kbhit is ideal for this, but I can't see gnu-win32 supporting this. I searched my entire gnu dir tree, which covers *all* the include directories, and nothing found - no prototype. It was, however, found inside these files: - c:\gnu\tcl\cw3215.dll - c:\gnu\H-i386-cygwin32\bin\cygwin.dll - c:\gnu\H-i386-cygwin32\i386-cygwin32\linwinserve.a and libcygwin.a Isn't libcygwin.a automatically linked at compile time? I added _kbhit() to my source code and the compiler complained about "syntax error before _kbhit". I also recall using kbhit() successfully under Borland C and MSC, both for DOS/Windows years ago. I'd like gnu-win32 to support this useful feature one day (like b20!!?). signal(): Setting a signal trap with a handler is easy. Getting the signal to trigger *immediately* ctrl-c (SIGINT) is detected is beyond me! The signal handler is only executed when a certain event (like the Sockets call "accept()") is called (why's this?? accept gives some time to the op sys to check other things, like message queue?). Jacob, your other solutions are interesting and creative ... 1. "PeekConsoleInput" is a Windows32 thing, and as such, not portable to Unix (I'm writing Sockets code that must operate on both platforms so I can maintain just one set of source code for both platforms). 2. Creating a home-grown version of getchar() that does a non-blocking read operation using "FILE_FLAG_OVERLAPPED" is a novel approach. Again, it's a Windows32 work-around, and therefore no good for my purpose. If you (or anyone) can offer more food for thought on this (and my) problem I'd love to hear ;-) Cheers, Mark. PS. I'm using cdk.exe b18, and Win98 beta3 DOSBOX make (not bash, as I don't understand Unix all that well) as my development environment. -----Original Message----- From: root To: cgf AT bbc DOT com Cc: gnu-win32 AT cygnus DOT com Date: Tuesday, 10 March 1998 6:50 Subject: Re: how to do a timeout in getchar >You can implement a version of getchar that does a non blocking read operation >by opening the file (in this case stdin) with the FILE_FLAG_OVERLAPPED. In that >case the read returns immediately. You could then loop waiting for a signal, >or other event that would stop the loop, or just a character read. > >Another method is to use PeekConsoleInput, in this case you get mouse events, >menu events, focus events, what have you. > >Yet another method is the age old _kbhit method: Read only if there is keyboard >input available. This method works only with the keyboard. You can't use it >with a redirected stdin. > >All those methods can be used to write a version of getchar that looks after >signals, like non-defined signals under Win32: SIGALRM is one of those. > >Since this has only sense if you want Unix-like behaviour, I thought it should >be the job of cygnus to emulate that. > >-- >Jacob Navia Logiciels/Informatique >41 rue Maurice Ravel Tel 01 48.23.51.44 >93430 Villetaneuse Fax 01 48.23.95.39 >France >- >For help on using this list (especially unsubscribing), send a message to >"gnu-win32-request AT cygnus DOT com" with one line of text: "help". > - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".