Add routine to check for input
authorH.G. Muller <h.g.muller@hccnet.nl>
Sat, 1 Jun 2013 06:00:36 +0000 (08:00 +0200)
committerH.G. Muller <h.g.muller@hccnet.nl>
Mon, 21 Oct 2013 08:40:24 +0000 (10:40 +0200)
hachu.c

diff --git a/hachu.c b/hachu.c
index 478a20b..ff5cc8f 100644 (file)
--- a/hachu.c
+++ b/hachu.c
 \r
 #ifdef WIN32 \r
 #    include <windows.h>\r
+     int InputWaiting()\r
+     {  // checks for waiting input in pipe\r
+       static int pipe, init;\r
+       static HANDLE inp;\r
+       DWORD cnt;\r
+\r
+       if(!init) inp = GetStdHandle(STD_INPUT_HANDLE);\r
+       if(!PeekNamedPipe(inp, NULL, 0, NULL, &cnt, NULL)) return 1;\r
+       return cnt;\r
+    }\r
 #else\r
 #    include <sys/time.h>\r
+#    include <sys/ioctl.h>\r
+     int InputWaiting()\r
+     {\r
+       int cnt;\r
+       if(ioctl(0, FIONREAD, &cnt)) return 1;\r
+       return cnt;\r
+     }\r
      int GetTickCount() // with thanks to Tord\r
      { struct timeval t;\r
        gettimeofday(&t, NULL);\r