Add routine to check for input
[hachu.git] / 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