In .search I have:
Code: Select all
#ifndef ANSI
if (xb_mode && bioskey ()) {
time_exit = TRUE;
return 0;
}
#endif
Code: Select all
#ifndef ANSI
#ifndef WIN32
int bioskey (void) {
fd_set readfds;
FD_ZERO (&readfds);
FD_SET (fileno (stdin), &readfds);
tv.tv_sec=0; tv.tv_usec=0;
select (16, &readfds, 0, 0, &tv);
return (FD_ISSET (fileno (stdin), &readfds));
}
#else
#undef frame
#include <windows.h>
#define frame 0
int bioskey (void) {
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 1;
}
return dw;
} else {
GetNumberOfConsoleInputEvents (inh, &dw);
return dw <= 1 ? 0 : dw;
}
return (0);
}
#endif
#endif
Code: Select all
int interrupt(void)
{
int c;
#ifdef HAVE_SELECT
FD_ZERO(&read_fds);
FD_SET(0,&read_fds);
tv.tv_sec = tv.tv_usec = 0;
select(1,&read_fds,NULL,NULL,&tv);
if(FD_ISSET(0,&read_fds))
{
c = getc(stdin);
if (c == '?') /*Move now*/
{
return 1;
}
else if (c == '.') /* Stat request */
{
getc(stdin);
post_stat_thinking();
return 0;
}
ungetc(c, stdin);
if (!is_pondering && (Variant == Bughouse || Variant == Crazyhouse)) return 0;
return 1;
}
else return 0;
#else
#ifdef _WIN32
static int init = 0, pipe;
static HANDLE inh;
DWORD dw;
if(xb_mode) { // winboard interrupt code taken from crafty
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);
FlushConsoleInputBuffer(inh);
}
}
if(pipe) {
if(!PeekNamedPipe(inh, NULL, 0, NULL, &dw, NULL))
{
c = getc(stdin);
if (c == '?') /*Move now*/
{
return 1;
}
else if (c == '.') /* Stat request */
{
getc(stdin);
post_stat_thinking();
return 0;
}
ungetc(c, stdin);
if (!is_pondering && (Variant == Bughouse || Variant == Crazyhouse)) return 0;
return 1;
}
if (dw)
{
c = getc(stdin);
if (c == '?') /*Move now*/
{
return 1;
}
else if (c == '.') /* Stat request */
{
getc(stdin);
post_stat_thinking();
return 0;
}
ungetc(c, stdin);
if (!is_pondering && (Variant == Bughouse || Variant == Crazyhouse)) return 0;
return 1;
}
else return 0;
} else {
GetNumberOfConsoleInputEvents(inh, &dw);
if (dw <= 1)
{
return 0;
}
else
{
c = getc(stdin);
if (c == '?') /*Move now*/
{
return 1;
}
else if (c == '.') /* Stat request */
{
getc(stdin);
post_stat_thinking();
return 0;
}
ungetc(c, stdin);
if (!is_pondering && (Variant == Bughouse || Variant == Crazyhouse)) return 0;
return 1;
};
}
}
#else
#endif
#endif
return 0;
}