From 4a9acd2e4d21586f2af629ec44cd78c237dcd702 Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Sat, 19 Oct 2013 19:07:12 +0200 Subject: [PATCH] Change ElapsedTime to a normal display function. The FIONREAD version is clearly tied to Curses, and the NOFIONREAD works corectly with xshogi/xboard as well as Raw. No reason for a separate mechanism. --without-curses now builds as expected. --- gnushogi/Makefile.in | 5 - gnushogi/Makefile.profile.in | 5 - gnushogi/cursesdsp.c | 101 +++++++++++++++++++ gnushogi/cursesdsp.h | 3 + gnushogi/dspwrappers.c | 1 + gnushogi/dspwrappers.h | 1 + gnushogi/gnushogi.h | 4 +- gnushogi/rawdsp.c | 64 ++++++++++++ gnushogi/rawdsp.h | 3 + gnushogi/sysdeps.c | 220 ------------------------------------------ 10 files changed, 175 insertions(+), 232 deletions(-) delete mode 100644 gnushogi/sysdeps.c diff --git a/gnushogi/Makefile.in b/gnushogi/Makefile.in index 5934c4a..09d4245 100644 --- a/gnushogi/Makefile.in +++ b/gnushogi/Makefile.in @@ -121,7 +121,6 @@ COMMONFILES = \ pattern.o \ rawdsp.o \ search.o \ - sysdeps.o \ tcontrl.o \ util.o @@ -198,9 +197,6 @@ rawdsp.o: rawdsp.c search.o: search.c $(CC) $(CFLAGS) -c $< -sysdeps.o: sysdeps.c - $(CC) $(CFLAGS) -c $< - tcontrl.o: tcontrl.c $(CC) $(CFLAGS) -c $< @@ -279,7 +275,6 @@ makepattern.o: pattern.c gnushogi.h $(SRCDIR)/pattern.h pattern.o: pattern.c gnushogi.h $(SRCDIR)/pattern.h $(SRCDIR)/pattern.inc rawdsp.o: rawdsp.c gnushogi.h $(ROOT)/version.h search.o: search.c gnushogi.h $(ROOT)/version.h -sysdeps.o: sysdeps.c gnushogi.h $(ROOT)/version.h tcontrl.o: tcontrl.c gnushogi.h $(ROOT)/version.h util.o: util.c gnushogi.h $(ROOT)/version.h pat2inc.o: pat2inc.c $(SRCDIR)/pattern.h $(SRCDIR)/gnushogi.h diff --git a/gnushogi/Makefile.profile.in b/gnushogi/Makefile.profile.in index 406b289..246d1c2 100644 --- a/gnushogi/Makefile.profile.in +++ b/gnushogi/Makefile.profile.in @@ -119,7 +119,6 @@ COMMONFILES = \ pattern.o \ rawdsp.o \ search.o \ - sysdeps.o \ tcontrl.o \ util.o @@ -194,9 +193,6 @@ rawdsp.o: search.o: $(CC) $(CFLAGS) -c search.c -sysdeps.o: - $(CC) $(CFLAGS) -c sysdeps.c - tcontrl.o: $(CC) $(CFLAGS) -c tcontrl.c @@ -280,7 +276,6 @@ makepattern.o: pattern.c gnushogi.h pattern.h pattern.o: pattern.c gnushogi.h pattern.h pattern.inc rawdsp.o: rawdsp.c gnushogi.h ../version.h search.o: search.c gnushogi.h ../version.h -sysdeps.o: sysdeps.c gnushogi.h ../version.h tcontrl.o: tcontrl.c gnushogi.h ../version.h util.o: util.c gnushogi.h ../version.h pat2inc.o: pat2inc.c pattern.h gnushogi.h diff --git a/gnushogi/cursesdsp.c b/gnushogi/cursesdsp.c index e15a394..47c34d2 100644 --- a/gnushogi/cursesdsp.c +++ b/gnushogi/cursesdsp.c @@ -43,6 +43,20 @@ #include "gnushogi.h" #include "cursesdsp.h" +#if HAVE_UNISTD_H +#include +#endif + +#if HAVE_SYS_FILIO_H +/* Definition of FIONREAD */ +#include +#endif + +#if HAVE_ERRNO_H +/* Definition of errno(). */ +#include +#endif + #define FLUSH_SCANW fflush(stdout), scanw int mycnt1, mycnt2; @@ -1186,3 +1200,90 @@ Curses_DoTable(short table[NO_SQUARES]) } } + +/* + * Determine the time that has passed since the search was started. If the + * elapsed time exceeds the target(ResponseTime + ExtraTime) then set timeout + * to true which will terminate the search. + * iop = COMPUTE_MODE calculate et, bump ETnodes + * iop = COMPUTE_AND_INIT_MODE calculate et, set timeout if time exceeded, + * set reference time + */ +void +Curses_ElapsedTime(ElapsedTime_mode iop) +{ + long current_time; + int i; + int nchar; + +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv; +#endif + + if ((i = ioctl((int) 0, FIONREAD, &nchar))) + { + perror("FIONREAD"); + fprintf(stderr, + "You probably have a non-ANSI ; " + "see README. %d %d %x\n", + i, errno, FIONREAD); + exit(1); + } + + if (nchar) + { + if (!flag.timeout) + flag.back = true; + + flag.bothsides = false; + } + +#ifdef HAVE_GETTIMEOFDAY + gettimeofday(&tv, NULL); + current_time = tv.tv_sec*100 + (tv.tv_usec/10000); +#else + et = ((current_time = time((long *) 0)) - time0) * 100; +#endif + +#ifdef INTERRUPT_TEST + if (iop == INIT_INTERRUPT_MODE) + { + itime0 = current_time; + } + else if (iop == COMPUTE_INTERRUPT_MODE) + { + it = current_time - itime0; + } + else +#endif + { +#ifdef HAVE_GETTIMEOFDAY + et = current_time - time0; +#endif + ETnodes = NodeCnt + znodes; + + if (et < 0) + { +#ifdef INTERRUPT_TEST + printf("elapsed time %ld not positive\n", et); +#endif + et = 0; + } + + if (iop == COMPUTE_AND_INIT_MODE) + { + if ((et > (ResponseTime + ExtraTime)) && (Sdepth > MINDEPTH)) + flag.timeout = true; + + time0 = current_time; + } + + if (!NOT_CURSES) + { +#ifdef QUIETBACKGROUND + if (!background) +#endif + UpdateClocks(); + } + } +} diff --git a/gnushogi/cursesdsp.h b/gnushogi/cursesdsp.h index b7c3643..d286b6d 100644 --- a/gnushogi/cursesdsp.h +++ b/gnushogi/cursesdsp.h @@ -34,6 +34,8 @@ #ifndef _CURSESDSP_H_ #define _CURSESDSP_H_ +#include "gnushogi.h" + /* The following are common to rawdsp.h and cursesdsp.h */ void Curses_ChangeAlphaWindow(void); @@ -46,6 +48,7 @@ void Curses_Die(int sig); void Curses_DoDebug(void); void Curses_DoTable(short table[NO_SQUARES]); void Curses_EditBoard(void); +void Curses_ElapsedTime(ElapsedTime_mode iop); void Curses_ExitShogi(void); void Curses_GiveHint(void); void Curses_Initialize(void); diff --git a/gnushogi/dspwrappers.c b/gnushogi/dspwrappers.c index dc139ce..cd7c3da 100644 --- a/gnushogi/dspwrappers.c +++ b/gnushogi/dspwrappers.c @@ -86,6 +86,7 @@ DISPLAY_VOIDFUNC(ChangeXwindow) DISPLAY_VOIDFUNC(ClearScreen) DISPLAY_VOIDFUNC(DoDebug) DISPLAY_FUNC(DoTable, (short table[NO_SQUARES]), (table)) +DISPLAY_FUNC(ElapsedTime, (ElapsedTime_mode iop), (iop)) DISPLAY_VOIDFUNC(EditBoard) DISPLAY_VOIDFUNC(ExitShogi) DISPLAY_VOIDFUNC(GiveHint) diff --git a/gnushogi/dspwrappers.h b/gnushogi/dspwrappers.h index 31400d2..e4b723f 100644 --- a/gnushogi/dspwrappers.h +++ b/gnushogi/dspwrappers.h @@ -43,6 +43,7 @@ extern void ChangeXwindow(void); extern void ClearScreen(void); extern void DoDebug(void); extern void DoTable(short table[NO_SQUARES]); +extern void ElapsedTime(ElapsedTime_mode iop); extern void EditBoard(void); extern void ExitShogi(void); extern void GiveHint(void); diff --git a/gnushogi/gnushogi.h b/gnushogi/gnushogi.h index 1eeef98..367db6c 100644 --- a/gnushogi/gnushogi.h +++ b/gnushogi/gnushogi.h @@ -175,7 +175,6 @@ extern void movealgbr(short m, char *s); # define PTBLBDSIZE (NO_SQUARES + NO_PIECES) #endif -#include "dspwrappers.h" /* Display functions. */ #include "eval.h" #define SCORE_LIMIT 12000 @@ -1031,7 +1030,6 @@ typedef enum #endif } ElapsedTime_mode; -extern void ElapsedTime(ElapsedTime_mode iop); extern void SetResponseTime(short side); extern void CheckForTimeout(int score, int globalscore, int Jscore, int zwndw); @@ -1090,4 +1088,6 @@ typedef enum extern int VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv); extern unsigned short TTage; +#include "dspwrappers.h" /* Display functions. */ + #endif /* _GNUSHOGI_H_ */ diff --git a/gnushogi/rawdsp.c b/gnushogi/rawdsp.c index 42ca071..08ef9d3 100644 --- a/gnushogi/rawdsp.c +++ b/gnushogi/rawdsp.c @@ -987,3 +987,67 @@ Raw_ShowPostnValues(void) mtl[opponent], pscore[opponent], GameType[opponent]); printf("\nhung black %d hung white %d\n", hung[black], hung[white]); } + + +/* + * Determine the time that has passed since the search was started. If the + * elapsed time exceeds the target(ResponseTime + ExtraTime) then set timeout + * to true which will terminate the search. + * iop = COMPUTE_MODE calculate et, bump ETnodes + * iop = COMPUTE_AND_INIT_MODE calculate et, set timeout if time exceeded, + * set reference time + */ +void +Raw_ElapsedTime(ElapsedTime_mode iop) +{ + long current_time; +#ifdef HAVE_GETTIMEOFDAY + struct timeval tv; + gettimeofday(&tv, NULL); + current_time = tv.tv_sec*100 + (tv.tv_usec/10000); +#else + et = ((current_time = time((long *) 0)) - time0) * 100; +#endif + +#ifdef INTERRUPT_TEST + if (iop == INIT_INTERRUPT_MODE) + { + itime0 = current_time; + } + else if (iop == COMPUTE_INTERRUPT_MODE) + { + it = current_time - itime0; + } + else +#endif + { +#ifdef HAVE_GETTIMEOFDAY + et = current_time - time0; +#endif + ETnodes = NodeCnt + znodes; + + if (et < 0) + { +#ifdef INTERRUPT_TEST + printf("elapsed time %ld not positive\n", et); +#endif + et = 0; + } + + if (iop == COMPUTE_AND_INIT_MODE) + { + if ((et > (ResponseTime + ExtraTime)) && (Sdepth > MINDEPTH)) + flag.timeout = true; + + time0 = current_time; + } + + if (!NOT_CURSES) + { +#ifdef QUIETBACKGROUND + if (!background) +#endif + UpdateClocks(); + } + } +} diff --git a/gnushogi/rawdsp.h b/gnushogi/rawdsp.h index a60ae5d..e3edf30 100644 --- a/gnushogi/rawdsp.h +++ b/gnushogi/rawdsp.h @@ -34,6 +34,8 @@ #ifndef _RAWDSP_H_ #define _RAWDSP_H_ +#include "gnushogi.h" + /* The following are common to rawdsp.h and cursesdsp.h */ void Raw_ChangeAlphaWindow(void); @@ -46,6 +48,7 @@ void Raw_Die(int sig); void Raw_DoDebug(void); void Raw_DoTable(short table[NO_SQUARES]); void Raw_EditBoard(void); +void Raw_ElapsedTime(ElapsedTime_mode iop); void Raw_ExitShogi(void); void Raw_GiveHint(void); void Raw_Initialize(void); diff --git a/gnushogi/sysdeps.c b/gnushogi/sysdeps.c deleted file mode 100644 index 6672154..0000000 --- a/gnushogi/sysdeps.c +++ /dev/null @@ -1,220 +0,0 @@ -/* - * FILE: sysdeps.c - * - * System-dependent functions for GNU Shogi. - * - * ---------------------------------------------------------------------- - * Copyright (c) 1993, 1994, 1995 Matthias Mutz - * Copyright (c) 1999 Michael Vanier and the Free Software Foundation - * - * GNU SHOGI is based on GNU CHESS - * - * Copyright (c) 1988, 1989, 1990 John Stanback - * Copyright (c) 1992 Free Software Foundation - * - * This file is part of GNU SHOGI. - * - * GNU Shogi is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 3 of the License, - * or (at your option) any later version. - * - * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - * - * You should have received a copy of the GNU General Public License along - * with GNU Shogi; see the file COPYING. If not, see - * . - * ---------------------------------------------------------------------- - * - */ - -#include "gnushogi.h" - -#if HAVE_UNISTD_H -#include -#endif - -#if HAVE_SYS_FILIO_H -/* Definition of FIONREAD */ -#include -#endif - -#if HAVE_ERRNO_H -/* Definition of errno(). */ -#include -#endif - -/* Forward declarations. */ - -void ElapsedTime_NOFIONREAD(ElapsedTime_mode iop); -void ElapsedTime_FIONREAD(ElapsedTime_mode iop); - - -/* - * Determine the time that has passed since the search was started. If the - * elapsed time exceeds the target(ResponseTime + ExtraTime) then set timeout - * to true which will terminate the search. - * iop = COMPUTE_MODE calculate et, bump ETnodes - * iop = COMPUTE_AND_INIT_MODE calculate et, set timeout if time exceeded, - * set reference time - */ - -/* - * ElapsedTime() is actually a wrapper function around the different - * versions of ElapsedTime_XXX(). This allows us to compile all the - * different ways of measuring time in one executable. - */ - -void -ElapsedTime(ElapsedTime_mode iop) -{ - switch (display_type) - { - case DISPLAY_RAW: - ElapsedTime_NOFIONREAD(iop); - break; - - default: - ElapsedTime_FIONREAD(iop); - break; - } -} - - -void -ElapsedTime_FIONREAD(ElapsedTime_mode iop) -{ - long current_time; - int i; - int nchar; - -#ifdef HAVE_GETTIMEOFDAY - struct timeval tv; -#endif - - if ((i = ioctl((int) 0, FIONREAD, &nchar))) - { - perror("FIONREAD"); - fprintf(stderr, - "You probably have a non-ANSI ; " - "see README. %d %d %x\n", - i, errno, FIONREAD); - exit(1); - } - - if (nchar) - { - if (!flag.timeout) - flag.back = true; - - flag.bothsides = false; - } - -#ifdef HAVE_GETTIMEOFDAY - gettimeofday(&tv, NULL); - current_time = tv.tv_sec*100 + (tv.tv_usec/10000); -#else - et = ((current_time = time((long *) 0)) - time0) * 100; -#endif - -#ifdef INTERRUPT_TEST - if (iop == INIT_INTERRUPT_MODE) - { - itime0 = current_time; - } - else if (iop == COMPUTE_INTERRUPT_MODE) - { - it = current_time - itime0; - } - else -#endif - { -#ifdef HAVE_GETTIMEOFDAY - et = current_time - time0; -#endif - ETnodes = NodeCnt + znodes; - - if (et < 0) - { -#ifdef INTERRUPT_TEST - printf("elapsed time %ld not positive\n", et); -#endif - et = 0; - } - - if (iop == COMPUTE_AND_INIT_MODE) - { - if ((et > (ResponseTime + ExtraTime)) && (Sdepth > MINDEPTH)) - flag.timeout = true; - - time0 = current_time; - } - - if (!NOT_CURSES) - { -#ifdef QUIETBACKGROUND - if (!background) -#endif - UpdateClocks(); - } - } -} - - -void -ElapsedTime_NOFIONREAD(ElapsedTime_mode iop) -{ - long current_time; -#ifdef HAVE_GETTIMEOFDAY - struct timeval tv; - gettimeofday(&tv, NULL); - current_time = tv.tv_sec*100 + (tv.tv_usec/10000); -#else - et = ((current_time = time((long *) 0)) - time0) * 100; -#endif - -#ifdef INTERRUPT_TEST - if (iop == INIT_INTERRUPT_MODE) - { - itime0 = current_time; - } - else if (iop == COMPUTE_INTERRUPT_MODE) - { - it = current_time - itime0; - } - else -#endif - { -#ifdef HAVE_GETTIMEOFDAY - et = current_time - time0; -#endif - ETnodes = NodeCnt + znodes; - - if (et < 0) - { -#ifdef INTERRUPT_TEST - printf("elapsed time %ld not positive\n", et); -#endif - et = 0; - } - - if (iop == COMPUTE_AND_INIT_MODE) - { - if ((et > (ResponseTime + ExtraTime)) && (Sdepth > MINDEPTH)) - flag.timeout = true; - - time0 = current_time; - } - - if (!NOT_CURSES) - { -#ifdef QUIETBACKGROUND - if (!background) -#endif - UpdateClocks(); - } - } -} -- 1.7.0.4