From 337ac0a0658376f8a9b2aa740acde95f021e53ec Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Wed, 27 Nov 2013 22:08:26 +0100 Subject: [PATCH] Fix Cygwin gcc compiling Te strtok_r function seems unknown in Cygwin, so we provided our own. Some Windows-specific stuff was under #ifdef _MSC_VER, like that would be the same as #ifdef WIN32. Checking for input in console mode is taken care of. The Makefile was adapted to make MINGW compiles. --- Makefile | 6 +++--- io.c | 9 +++++++-- proce.c | 18 ++++++++++++++++++ shogi.h | 8 +++++++- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 888eb3c..ed03b82 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ OBJS =data.o main.o io.o proce.o utility.o ini.o attack.o book.o makemove.o \ # -DDFPN build the DFPN worker of mate-problems server. # -DDFPN_CLIENT enables the client-mode of mate-problem server. -OPT =-DNDEBUG -DMINIMUM -DHAVE_SSE4 -msse4.1 -DDFPN -DTLP -DDFPN_CLIENT -DINANIWA_SHIFT -DMNJ_LAN -DCSA_LAN -DXBOARD -DMPV +OPT =-DNDEBUG -DMINIMUM -DTLP -DINANIWA_SHIFT -DXBOARD -DMPV -DNO_LOGGING help: @echo "try targets as:" @@ -37,7 +37,7 @@ help: @echo " icc-ampl" gcc: - $(MAKE) CC=gcc CFLAGS='-std=gnu99 -O2 -Wall $(OPT)' LDFLAG1='-lm -lpthread' bonanza + $(MAKE) CC=gcc CFLAGS='-std=gnu99 -O2 -Wall $(OPT) -mno-cygwin' LDFLAG1='-lm -lpthread -lwsock32 -mno-cygwin' bonanza gcc-pgo: $(MAKE) clean @@ -60,7 +60,7 @@ icc-pgo: $(MAKE) CC=icc CFLAGS='-w2 $(OPT) -std=gnu99 -O2 -ipo -prof_use -prof_dir ./profdir' LDFLAG1='-static -ipo -pthread' bonanza bonanza : $(OBJS) - $(CC) $(LDFLAG1) -o bonanza $(OBJS) $(LDFLAG2) + $(CC) $(LDFLAG1) -o bonanza $(OBJS) bres.o $(LDFLAG2) $(OBJS) : shogi.h param.h bitop.h dfpn.o dfpnhash.o: dfpn.h diff --git a/io.c b/io.c index 75f12bb..2a633e6 100644 --- a/io.c +++ b/io.c @@ -540,7 +540,7 @@ out_beep( void ) int stdout_normal( void ) { -# if defined(_WIN32) +# if defined(_MSC_VER) HANDLE hStdout; WORD wAttributes; @@ -568,7 +568,7 @@ stdout_normal( void ) int stdout_stress( int is_promote, int ifrom ) { -# if defined(_WIN32) +# if defined(_MSC_VER) HANDLE hStdout; WORD wAttributes; @@ -734,6 +734,11 @@ check_input_buffer( void ) &dwTotalBytesAvail, &dwBytesLeftThisMessage ); if ( ! bSuccess ) { + if( GetLastError() == 6) + { + return _kbhit(); + } + Out("peek error %d\n", GetLastError()); str_error = "PeekNamedPipe() faild."; return -1; } diff --git a/proce.c b/proce.c index 81707f9..8556ef1 100644 --- a/proce.c +++ b/proce.c @@ -109,6 +109,24 @@ int CONV is_move( const char *str ) } +#if defined(_WIN32) +char * +strtok_r( char *s, const char *t, char **next) +{ + char *p, *r; + if( ! s ) s = *next; + if( ! s ) return NULL; + while( *s && strchr(t, *s) ) s++; + if( ! *s ) return NULL; + r = s; + while( *s && ! (p = strchr(t, *s)) ) s++; + *next = s + 1; + if( ! *s ) *next = NULL; + *s = '\0'; + return r; +} +#endif + int CONV procedure( tree_t * restrict ptree ) { diff --git a/shogi.h b/shogi.h index 8c55744..cbbe00e 100644 --- a/shogi.h +++ b/shogi.h @@ -8,9 +8,15 @@ #if defined(_WIN32) # include -# define CONV __fastcall +# ifdef _MSC_VER +# define CONV __fastcall +# else +# define CONV +# endif # define SCKT_NULL INVALID_SOCKET +# define WIN32_PIPE typedef SOCKET sckt_t; +char *strtok_r( char *s, const char *t, char **next); #else -- 1.7.0.4