From 0a2ec9c1acdcaa2f133f4ee12e478cd710aa4792 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Fri, 27 Sep 2013 09:39:28 +0200 Subject: [PATCH] Windows port This patch makes GNU Shogi compilable with gcc under Cygwin, using the -mno-cygwin flag, so that it can run as a native Windows application, independent of Cygwin1.dll. The patch is fully conditional, based on defined(WIN32). YD: rebased onto recent refactorings --- gnushogi/gnushogi.h | 11 +++++++---- gnushogi/init.c | 2 ++ gnushogi/rawdsp.c | 13 +++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/gnushogi/gnushogi.h b/gnushogi/gnushogi.h index 60cedaa..8a16fc7 100644 --- a/gnushogi/gnushogi.h +++ b/gnushogi/gnushogi.h @@ -81,7 +81,6 @@ extern short nolist; /* Don't list game after exit. */ #define small_ushort unsigned char -typedef small_short BYTE; typedef small_ushort UBYTE; typedef short SHORT; typedef unsigned short USHORT; @@ -130,9 +129,13 @@ typedef unsigned long ULONG; #include #include -#include -#include - +#ifdef WIN32 +# include +#else + typedef small_short BYTE; +# include +# include +#endif #if TIME_WITH_SYS_TIME # include diff --git a/gnushogi/init.c b/gnushogi/init.c index 3eeaef3..3ae048d 100644 --- a/gnushogi/init.c +++ b/gnushogi/init.c @@ -69,7 +69,9 @@ unsigned int ttbllimit; /* .... MOVE GENERATION VARIABLES AND INITIALIZATIONS .... */ +#ifndef WIN32 #define max(a, b) (((a) < (b))?(b):(a)) +#endif #define odd(a) ((a) & 1) diff --git a/gnushogi/rawdsp.c b/gnushogi/rawdsp.c index e8e7b98..5c4d45d 100644 --- a/gnushogi/rawdsp.c +++ b/gnushogi/rawdsp.c @@ -35,8 +35,10 @@ #include #include #include +#ifndef WIN32 #include #include +#endif #include "gnushogi.h" #include "rawdsp.h" @@ -217,6 +219,10 @@ Raw_Initialize(void) if (XSHOGI) { +#ifdef WIN32 + /* needed because of inconsistency between MSVC run-time system and gcc includes */ + setbuf(stdout, NULL); +#else #ifdef HAVE_SETLINEBUF setlinebuf(stdout); #else @@ -226,6 +232,7 @@ Raw_Initialize(void) # error "Need setlinebuf() or setvbuf() to compile gnushogi!" # endif #endif +#endif printf("GNU Shogi %s\n", PACKAGE_VERSION); } @@ -944,6 +951,11 @@ Raw_ShowPostnValues(void) void Raw_PollForInput(void) { +#ifdef WIN32 + DWORD cnt; + if (!PeekNamedPipe(GetStdHandle(STD_INPUT_HANDLE), NULL, 0, NULL, &cnt, NULL)) + cnt = 1; +#else static struct pollfd pollfds[1] = { /* [0] = */ { /* .fd = */ STDIN_FILENO, /* .events = */ POLLIN } }; int cnt = poll(pollfds, sizeof(pollfds)/sizeof(pollfds[0]), 0); @@ -951,6 +963,7 @@ Raw_PollForInput(void) perror("polling standard input"); ExitShogi(); } +#endif if (cnt) { /* if anything to read, or error occured */ if (!flag.timeout) flag.back = true; /* previous: flag.timeout = true; */ -- 1.7.0.4