Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: NT and stdin?

Author: Alexander Kure

Date: 11:57:55 11/03/99

Go up one level in this thread


On November 03, 1999 at 06:11:19, Inmann Werner wrote:

>Hello to all, "understanding" NT.
>
>I am getting crazy in trying my program to get run under NT!!!!
>Never done NT and not knowing it anyway.
>
>I isolated the problem (hope so)
>
>I read incoming "keystrokes" (Winboard) after detecting that there are
>keystrokes in a loop with
>
>getkey(charac)
>int *charac;
>{
>int rr;
>char bu[81];
>
>NM2:
>rr=read(fileno(stdin),&bu,1);
>if (rr<=0) goto NM2;
>*charac=bu[0];
>return(0);
>}
>
>ok, a litte "crazy" code, but nice working with win95/98 and Linux.
>But with NT, if do the loop calling getkey, the first character of each text is
>always a "W"!!!!!!!
>
>Example debug File
>WO         or
>W2E4
>.....
>
>to ask, if keystrokes are available I use the "simple" routine from crafty.
>it should not change anything?!?!?
>
>
>checkkey()
>{
>static int init = 0, pipe;
>static HANDLE inh;
>DWORD dw;
>
>  if (!init)
>  {
>		init = 1;
>		inh = GetStdHandle(STD_INPUT_HANDLE);
>		pipe = !GetConsoleMode(inh, &dw);
>		if (!pipe)
>		{
>			  SetConsoleMode(inh, dw & ~(ENABLE_MOUSE_INPUT|ENABLE_WINDOW_INPUT));
>			  FlushConsoleInputBuffer(inh);
>		}
>  }
>
>  if (pipe)
>  {
>		if (!PeekNamedPipe(inh, NULL, 0, NULL, &dw, NULL))
>		{
>		  return 0;
>		}
>		return(dw);
>  }else
>  {
>		GetNumberOfConsoleInputEvents(inh, &dw);
>		return dw <= 1 ? 0 : dw;
>  }
>  return(0);
>}
>
>*************************
>
>any suggestion??
>(I use Watcom C Compiler)
>
>Werner

Hi Werner,

Seems you are mixing WIN32 API calls (GetConsoleMode(),
FlushConsoleInputBuffer(), ...) with low level calls from the C standard library
(read()). Wonder how this worked under Linux ;-)
Maybe you can try ReadConsoleInput() for retrieving data from stdin.

Greetings Alex

PS: goto????????

>NM2:
>rr=read(fileno(stdin),&bu,1);
>if (rr<=0) goto NM2;

better style would be

while (read(fileno(stdin),&bu,1) <= 0);
...



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.