From: Yann Dirson Date: Thu, 5 Dec 2013 22:31:07 +0000 (+0100) Subject: Merge branch 'maint' into master X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=b25be4481e49ce9e343ed301ab57be999e583083;hp=-c;p=gnushogi.git Merge branch 'maint' into master --- b25be4481e49ce9e343ed301ab57be999e583083 diff --combined configure.ac index b13f537,923ec35..146e17a --- a/configure.ac +++ b/configure.ac @@@ -5,7 -5,7 +5,7 @@@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.57) - AC_INIT([gnushogi],[1.4.0+],[https://savannah.gnu.org/bugs/?group=gnushogi]) + AC_INIT([gnushogi],[1.4.1-rc0+],[https://savannah.gnu.org/bugs/?group=gnushogi]) AC_CONFIG_SRCDIR([gnushogi/gnushogi.h]) AC_CONFIG_HEADER(config.h) @@@ -47,8 -47,8 +47,8 @@@ AS_IF([test "x$with_curses" != xno] [-ltermcap])]) # other libraries. - AC_CHECK_LIB(m, pow) - AC_CHECK_LIB(termcap, tgoto) + AC_CHECK_LIB([m], [pow]) + AC_CHECK_LIB([termcap], [tgoto]) @@@ -57,7 -57,7 +57,7 @@@ if [[ $ac_cv_c_compiler_gnu = yes ]] then -WARNINGS="-Wall -Wno-implicit-int -Wstrict-prototypes -ansi -pedantic" +WARNINGS="-Wall -Wno-implicit-int -Wstrict-prototypes -ansi" CEXTRAFLAGS="-fsigned-char -funroll-loops" # For profiling targets: CEXTRAFLAGS2="-fsigned-char -pg -fprofile-arcs -ftest-coverage" @@@ -103,19 -103,18 +103,18 @@@ AC_MSG_NOTICE([library functions] AC_FUNC_FORK AC_PROG_GCC_TRADITIONAL AC_FUNC_MALLOC AC_TYPE_SIGNAL AC_CHECK_FUNCS([dup2 gethostname gettimeofday memset pow strcasecmp]) AC_CHECK_FUNCS([strchr strerror strrchr strstr strtol]) - AC_CHECK_FUNCS(memcpy bcopy) - AC_CHECK_FUNCS(setlinebuf setvbuf) + AC_CHECK_FUNCS([memcpy bcopy]) + AC_CHECK_FUNCS([setvbuf setlinebuf]) # # Set various user-definable options. # - AC_ARG_ENABLE(minishogi, + AC_ARG_ENABLE([minishogi], [ --enable-minishogi Build gnuminishogi instead of gnushogi (default: no)], [AC_DEFINE([MINISHOGI], [], [Define to build gnuminishogi instead of gnushogi]) @@@ -130,36 -129,36 +129,36 @@@ SECOND_SHOGI_PROGRAM=gnushog FIRST_HOST=localhost SECOND_HOST=localhost - AC_ARG_ENABLE(xshogi, + AC_ARG_ENABLE([xshogi], AS_HELP_STRING([--enable-xshogi], [compile the xshogi graphical interface to GNU shogi (default: no)]), - enable_xshogi=$enableval, - enable_xshogi=no) + [enable_xshogi=$enableval], + [enable_xshogi=no]) - AC_ARG_WITH(top-part-bitmaps, + AC_ARG_WITH([top-part-bitmaps], AS_HELP_STRING([--with-top-part-bitmaps], [use top part of Kanji bitmaps only in xshogi]), - OPT=-DTOP_PART_BITMAPS) + [OPT=-DTOP_PART_BITMAPS]) - AC_ARG_WITH(first-shogi-program, + AC_ARG_WITH([first-shogi-program], AS_HELP_STRING([--with-first-shogi-program=PROGNAME], [use PROGNAME as the first shogi program in xshogi (default: gnushogi)]), - FIRST_SHOGI_PROGRAM=$withval) + [FIRST_SHOGI_PROGRAM=$withval]) - AC_ARG_WITH(second-shogi-program, + AC_ARG_WITH([second-shogi-program], AS_HELP_STRING([--with-second-shogi-program=PROGNAME], [use PROGNAME as the second shogi program in xshogi (default: gnushogi)]), - SECOND_SHOGI_PROGRAM=$withval) + [SECOND_SHOGI_PROGRAM=$withval]) - AC_ARG_WITH(first-host, + AC_ARG_WITH([first-host], AS_HELP_STRING([--with-first-host=HOSTNAME], [use HOSTNAME as the machine on which the first shogi program runs in xshogi (default: localhost)]), - FIRST_HOST=$withval) + [FIRST_HOST=$withval]) - AC_ARG_WITH(second-host, + AC_ARG_WITH([second-host], AS_HELP_STRING([--with-second-host=HOSTNAME], [use HOSTNAME as the machine on which the second shogi program runs in xshogi (default: localhost)]), - SECOND_HOST=$withval) + [SECOND_HOST=$withval]) AC_SUBST(OPT) AC_SUBST(FIRST_SHOGI_PROGRAM) diff --combined gnushogi/commondsp.c index 235d078,4cbfb81..4e3eb07 --- a/gnushogi/commondsp.c +++ b/gnushogi/commondsp.c @@@ -31,6 -31,10 +31,10 @@@ * */ + /* request *snprintf prototypes */ + #define _POSIX_C_SOURCE 200112L + #include + #if defined HAVE_GETTIMEOFDAY #include #endif @@@ -47,7 -51,6 +51,7 @@@ char mvstr[4][6]; char *InPtr; int InBackground = false; +struct display *dsp = &raw_display; #if defined(BOOKTEST) @@@ -124,6 -127,8 +128,6 @@@ movealgbr(short m, char *s #endif /* BOOKTEST */ - - /* * Generate move strings in different formats. * @@@ -163,7 -168,7 +167,7 @@@ algbr(short f, short t, short flag if ((f == t) && ((f != 0) || (t != 0))) { if (!barebones) { - Printf("error in algbr: FROM=TO=%d, flag=0x%4x\n", t, flag); + dsp->Printf("error in algbr: FROM=TO=%d, flag=0x%4x\n", t, flag); } mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0'; @@@ -215,6 -220,7 +219,6 @@@ } - /* * Compare the string 's' to the list of legal moves available for the * opponent. If a match is found, make the move on the board. @@@ -295,7 -301,7 +299,7 @@@ VerifyMove(char *s, VerifyMove_mode iop if (SqAttacked(PieceList[opponent][0], computer, &blocked)) { UnmakeMove(opponent, &xnode, &tempb, &tempc, &tempsf, &tempst); - AlwaysShowMessage("Illegal move (in check) %s", s); + dsp->AlwaysShowMessage("Illegal move (in check) %s", s); return false; } else @@@ -303,7 -309,7 +307,7 @@@ if (iop == VERIFY_AND_TRY_MODE) return true; - UpdateDisplay(xnode.f, xnode.t, 0, (short) xnode.flags); + dsp->UpdateDisplay(xnode.f, xnode.t, 0, (short) xnode.flags); GameList[GameCnt].depth = GameList[GameCnt].score = 0; GameList[GameCnt].nodes = 0; ElapsedTime(COMPUTE_AND_INIT_MODE); @@@ -328,7 -334,7 +332,7 @@@ char buf[20]; sprintf(buf, "%s mates!\n", ColorStr[opponent]); - ShowMessage(buf); + dsp->ShowMessage(buf); flag.mate = true; } } @@@ -337,20 -343,21 +341,20 @@@ } } - AlwaysShowMessage("Illegal move (no match) %s", s); + dsp->AlwaysShowMessage("Illegal move (no match) %s", s); if (!barebones && (cnt > 1)) { sprintf(buffer, "Ambiguous Move %s!", s); - ShowMessage(buffer); + dsp->ShowMessage(buffer); } return false; } - static int -parser(char *f, int side, short *fpiece) +parser(char *f, short *fpiece) { int c1, r1, c2, r2; short i, p = false; @@@ -398,6 -405,7 +402,6 @@@ skip( } - void skipb() { @@@ -406,25 -414,8 +410,25 @@@ } +void RequestInputString(char* buffer, unsigned bufsize) +{ + static char fmt[10]; + int ret = snprintf(fmt, sizeof(fmt), "%%%us", bufsize); + if (ret < 0 ) { + perror("RequestInputString snprintf"); + exit(1); + } + if (ret >= sizeof(fmt)) { + fprintf(stderr, + "Insufficient format-buffer size in %s for bufsize=%u\n", + __FUNCTION__, bufsize); + exit(1); + } + dsp->doRequestInputString(fmt, buffer); +} + -void +static void GetGame(void) { FILE *fd; @@@ -436,7 -427,7 +440,7 @@@ if (savefile[0]) { strcpy(fname, savefile); } else { - ShowMessage("Enter file name: "); + dsp->ShowMessage("Enter file name: "); RequestInputString(fname, sizeof(fname)-1); } @@@ -588,7 -579,7 +592,7 @@@ InPtr = fname; skipb(); g = &GameList[GameCnt]; - g->gmove = parser(InPtr, side, &g->fpiece); + g->gmove = parser(InPtr, &g->fpiece); skip(); g->score = atoi(InPtr); skip(); @@@ -641,13 -632,14 +645,13 @@@ ZeroRPT(); InitializeStats(); - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); Sdepth = 0; hint = 0; } - -void +static void SaveGame(void) { FILE *fd; @@@ -660,7 -652,7 +664,7 @@@ if (savefile[0]) { strcpy(fname, savefile); } else { - ShowMessage("Enter file name: "); + dsp->ShowMessage("Enter file name: "); RequestInputString(fname, sizeof(fname)-1); } @@@ -785,21 -777,22 +789,21 @@@ fclose(fd); - ShowMessage("Game saved"); + dsp->ShowMessage("Game saved"); } else { - ShowMessage("Could not open file"); + dsp->ShowMessage("Could not open file"); } } - /* * GetXGame, SaveXGame and BookGame used to only be defined if * xshogi wasn't defined -- wonder why? */ -void +static void GetXGame(void) { FILE *fd; @@@ -808,7 -801,7 +812,7 @@@ short sq; short side, isp; - ShowMessage("Enter file name: "); + dsp->ShowMessage("Enter file name: "); RequestInputString(fname, sizeof(fname)-1); if (fname[0] == '\0') @@@ -922,13 -915,13 +926,13 @@@ Game50 = 1; ZeroRPT(); InitializeStats(); - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); Sdepth = 0; hint = 0; } -void +static void SaveXGame(void) { FILE *fd; @@@ -937,7 -930,7 +941,7 @@@ short sq, piece; short side, isp; - ShowMessage("Enter file name: "); + dsp->ShowMessage("Enter file name: "); RequestInputString(fname, sizeof(fname)-1); if (fname[0] == '\0') @@@ -1008,7 -1001,7 +1012,7 @@@ } -void +static void BookSave(void) { FILE *fd; @@@ -1019,7 -1012,7 +1023,7 @@@ strcpy(fname, savefile); } else { /* Enter file name */ - ShowMessage("Enter file name: "); + dsp->ShowMessage("Enter file name: "); RequestInputString(fname, sizeof(fname)-1); } @@@ -1091,15 -1084,16 +1095,15 @@@ fclose(fd); - ShowMessage("Game saved"); + dsp->ShowMessage("Game saved"); } else { - ShowMessage("Could not open file"); + dsp->ShowMessage("Could not open file"); } } - void ListGame(void) { @@@ -1227,7 -1221,8 +1231,7 @@@ } - -void +static void FlagMove(char c) { switch(c) @@@ -1249,11 -1244,13 +1253,11 @@@ } - - /* * Undo the most recent half-move. */ -void +static void Undo(void) { short f, t; @@@ -1302,14 -1299,15 +1306,14 @@@ flag.mate = false; Sdepth = 0; player = player ^ 1; - ShowSidetoMove(); - UpdateDisplay(0, 0, 1, 0); + dsp->ShowSidetoMove(); + dsp->UpdateDisplay(0, 0, 1, 0); if (flag.regularstart) Book = false; } - void FlagString(unsigned short flags, char *s) { @@@ -1362,7 -1360,8 +1366,7 @@@ } - -void +static void TestSpeed(void(*f)(short side, short ply, short in_check, short blockable), unsigned j) @@@ -1412,14 -1411,15 +1416,14 @@@ else et = 1; - ShowNodeCnt(cnt); + dsp->ShowNodeCnt(cnt); } - -void +static void TestPSpeed(short(*f) (short side), unsigned j) { - short i; + unsigned i; long cnt, t1, t2; #ifdef HAVE_GETTIMEOFDAY struct timeval tv; @@@ -1449,22 -1449,24 +1453,22 @@@ else et = 1; - ShowNodeCnt(cnt); + dsp->ShowNodeCnt(cnt); } - -void -SetOppTime(char *s) +static void +SetOppTime(char *time) { int m, t, sec; sec = 0; - time = &s[strlen("otime")]; t = (int)strtol(time, &time, 10); if (*time == ':') { time++; + /* FIXME: sec is parsed but ignored */ sec = (int)strtol(time, &time, 10); } @@@ -1486,18 -1488,20 +1490,18 @@@ } - -void -SetMachineTime(char *s) +static void +SetMachineTime(char *time) { - char *time; int m, t, sec; - time = &s[strlen("time")]; sec = 0; t = (int)strtol(time, &time, 10); if (*time == ':') { time++; + /* FIXME: sec is parsed but ignored */ sec = (int)strtol(time, &time, 10); } @@@ -1519,19 -1523,24 +1523,19 @@@ } - - - /* FIXME! This is truly the function from hell! */ /* * Process the user's command. If easy mode is OFF (the computer is thinking * on opponents time) and the program is out of book, then make the 'hint' * move on the board and call SelectMove() to find a response. The user - * terminates the search by entering ^C (quit siqnal) before entering a - * command. If the opponent does not make the hint move, then set Sdepth to - * zero. + * terminates the search by entering a command. If the opponent does not make + * the hint move, then set Sdepth to zero. */ void InputCommand(char *command) { - int eof = 0; short have_shown_prompt = false; short ok, done, is_move = false; unsigned short mv; @@@ -1558,8 -1567,10 +1562,8 @@@ algbr((short) hint >> 8, (short) hint & 0xff, false); strcpy(s, mvstr[0]); -#if !defined NOPOST if (flag.post) - GiveHint(); -#endif + dsp->GiveHint(); /* do the hint move */ if (VerifyMove(s, VERIFY_AND_TRY_MODE, &mv)) @@@ -1567,7 -1578,7 +1571,7 @@@ Sdepth = 0; #ifdef QUIETBACKGROUND - ShowPrompt(); + dsp->ShowPrompt(); have_shown_prompt = true; #endif /* QUIETBACKGROUND */ @@@ -1614,7 -1625,7 +1618,7 @@@ { #endif /* QUIETBACKGROUND */ - ShowPrompt(); + dsp->ShowPrompt(); #ifdef QUIETBACKGROUND } @@@ -1623,16 -1634,21 +1627,16 @@@ #endif /* QUIETBACKGROUND */ if (command == NULL) { - if (NOT_CURSES) - s[0] = '\0'; - - eof = GetString(sx); + int eof = dsp->GetString(sx); + if (eof) + dsp->ExitShogi(); } else { strcpy(sx, command); done = true; } - sscanf(sx, "%s", s); - - if (eof) - ExitShogi(); - - if (s[0] == '\0') + /* extract first word */ + if (sscanf(sx, "%s", s) < 1) continue; if (strcmp(s, "bd") == 0) /* bd -- display board */ @@@ -1643,8 -1659,8 +1647,8 @@@ if (old_xshogi) display_type = DISPLAY_RAW; - ClearScreen(); - UpdateDisplay(0, 0, 1, 0); + dsp->ClearScreen(); + dsp->UpdateDisplay(0, 0, 1, 0); if (old_xshogi) display_type = DISPLAY_X; @@@ -1655,21 -1671,27 +1659,21 @@@ } else if (strcmp(s, "alg") == 0) { - /* noop */ ; /* alg */ + /* noop */ ; } else if ((strcmp(s, "quit") == 0) || (strcmp(s, "exit") == 0)) { flag.quit = true; } else if ((strcmp(s, "set") == 0) || (strcmp(s, "edit") == 0)) { - EditBoard(); + dsp->EditBoard(); } - else if ((strcmp(s, "setup") == 0)) + else if (strcmp(s, "setup") == 0) { - SetupBoard(); + dsp->SetupBoard(); } else if (strcmp(s, "first") == 0) { @@@ -1693,7 -1715,7 +1697,7 @@@ } else if (strcmp(s, "help") == 0) { - help(); + dsp->help(); } else if (strcmp(s, "material") == 0) { @@@ -1719,19 -1741,16 +1723,19 @@@ else if (strcmp(s, "new") == 0) { NewGame(); - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); } else if (strcmp(s, "list") == 0) { ListGame(); } - else if ((strcmp(s, "level") == 0) - || (strcmp(s, "clock") == 0)) + else if (strcmp(s, "level") == 0) + { + dsp->SelectLevel(sx + strlen("level")); + } + else if (strcmp(s, "clock") == 0) { - SelectLevel(sx); + dsp->SelectLevel(sx + strlen("clock")); } else if (strcmp(s, "hash") == 0) { @@@ -1747,19 -1766,19 +1751,19 @@@ } else if (strcmp(s, "time") == 0) { - SetMachineTime(sx); + SetMachineTime(sx + strlen("time")); } else if (strcmp(s, "otime") == 0) { - SetOppTime(sx); + SetOppTime(sx + strlen("otime")); } else if (strcmp(s, "Awindow") == 0) { - ChangeAlphaWindow(); + dsp->ChangeAlphaWindow(); } else if (strcmp(s, "Bwindow") == 0) { - ChangeBetaWindow(); + dsp->ChangeBetaWindow(); } else if (strcmp(s, "rcptr") == 0) { @@@ -1767,7 -1786,7 +1771,7 @@@ } else if (strcmp(s, "hint") == 0) { - GiveHint(); + dsp->GiveHint(); } else if (strcmp(s, "both") == 0) { @@@ -1781,8 -1800,8 +1785,8 @@@ else if (strcmp(s, "reverse") == 0) { flag.reverse = !flag.reverse; - ClearScreen(); - UpdateDisplay(0, 0, 1, 0); + dsp->ClearScreen(); + dsp->UpdateDisplay(0, 0, 1, 0); } else if (strcmp(s, "switch") == 0) { @@@ -1860,15 -1879,11 +1864,15 @@@ } else if (strcmp(s, "depth") == 0) { - ChangeSearchDepth(); + dsp->ChangeSearchDepth(sx + strlen("depth")); + } + else if (strcmp(s, "sd") == 0) + { + dsp->ChangeSearchDepth(sx + strlen("sd")); } else if (strcmp(s, "hashdepth") == 0) { - ChangeHashDepth(); + dsp->ChangeHashDepth(); } else if (strcmp(s, "random") == 0) { @@@ -1888,26 -1903,26 +1892,26 @@@ } else if (strcmp(s, "contempt") == 0) { - SetContempt(); + dsp->SetContempt(); } else if (strcmp(s, "xwndw") == 0) { - ChangeXwindow(); + dsp->ChangeXwindow(); } else if (strcmp(s, "rv") == 0) { flag.rv = !flag.rv; - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); } else if (strcmp(s, "coords") == 0) { flag.coords = !flag.coords; - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); } else if (strcmp(s, "stars") == 0) { flag.stars = !flag.stars; - UpdateDisplay(0, 0, 1, 0); + dsp->UpdateDisplay(0, 0, 1, 0); } else if (!XSHOGI && strcmp(s, "moves") == 0) { @@@ -1925,44 -1940,44 +1929,44 @@@ #endif SwagHt = 0; - ShowMessage("Testing MoveList Speed"); + dsp->ShowMessage("Testing MoveList Speed"); temp = generate_move_flags; generate_move_flags = true; TestSpeed(MoveList, 1); generate_move_flags = temp; - ShowMessage("Testing CaptureList Speed"); + dsp->ShowMessage("Testing CaptureList Speed"); TestSpeed(CaptureList, 1); - ShowMessage("Testing Eval Speed"); + dsp->ShowMessage("Testing Eval Speed"); ExaminePosition(opponent); TestPSpeed(ScorePosition, 1); } else if (!XSHOGI && strcmp(s, "test") == 0) { #ifdef SLOW_CPU - ShowMessage("Testing MoveList Speed"); + dsp->ShowMessage("Testing MoveList Speed"); TestSpeed(MoveList, 2000); - ShowMessage("Testing CaptureList Speed"); + dsp->ShowMessage("Testing CaptureList Speed"); TestSpeed(CaptureList, 3000); - ShowMessage("Testing Eval Speed"); + dsp->ShowMessage("Testing Eval Speed"); ExaminePosition(opponent); TestPSpeed(ScorePosition, 1500); #else - ShowMessage("Testing MoveList Speed"); + dsp->ShowMessage("Testing MoveList Speed"); TestSpeed(MoveList, 20000); - ShowMessage("Testing CaptureList Speed"); + dsp->ShowMessage("Testing CaptureList Speed"); TestSpeed(CaptureList, 30000); - ShowMessage("Testing Eval Speed"); + dsp->ShowMessage("Testing Eval Speed"); ExaminePosition(opponent); TestPSpeed(ScorePosition, 15000); #endif } else if (!XSHOGI && strcmp(s, "p") == 0) { - ShowPostnValues(); + dsp->ShowPostnValues(); } else if (!XSHOGI && strcmp(s, "debug") == 0) { - DoDebug(); + dsp->DoDebug(); } else { @@@ -1978,7 -1993,7 +1982,7 @@@ if (rpt >= 3) { DRAW = DRAW_REPETITION; - ShowMessage(DRAW); + dsp->ShowMessage(DRAW); GameList[GameCnt].flags |= draw; flag.mate = true; @@@ -2011,6 -2026,8 +2015,6 @@@ } #ifdef notdef /* optional pass best line to frontend with move */ -# if !defined NOPOST - if (flag.post && !flag.mate) { int i; @@@ -2023,12 -2040,15 +2027,12 @@@ printf("%5s ", mvstr[0]); } } -# endif printf("\n"); #endif } } - - void SetTimeControl(void) { @@@ -2048,3 -2068,4 +2052,3 @@@ et = 0; ElapsedTime(COMPUTE_AND_INIT_MODE); } - diff --combined gnushogi/cursesdsp.c index 6300368,4d00015..277f185 --- a/gnushogi/cursesdsp.c +++ b/gnushogi/cursesdsp.c @@@ -30,11 -30,12 +30,13 @@@ * ---------------------------------------------------------------------- */ + /* request *snprintf prototypes*/ + #define _POSIX_C_SOURCE 200112L #include #include #include +#include #include #include @@@ -42,6 -43,7 +44,6 @@@ #include #include "gnushogi.h" -#include "cursesdsp.h" #if HAVE_UNISTD_H #include @@@ -70,17 -72,12 +72,17 @@@ unsigned short MV[MAXDEPTH] int MSCORE; char *DRAW; -/* Forward declarations. */ -/* FIXME: change this name, puh-leeze! */ +/**************************************** + * forward declarations + ****************************************/ +/* FIXME: change this name, puh-leeze! */ static void UpdateCatched(void); static void DrawPiece(short sq); static void ShowScore(short score); +void Curses_UpdateDisplay(short f, short t, short redraw, short isspec); +void Curses_Die(int sig); +void Curses_ShowSidetoMove(void); /**************************************** * Trivial output functions. @@@ -109,6 -106,14 +111,6 @@@ gotoXY(short x, short y } -static void -ClearMessage(void) -{ - gotoXY(TAB, 6); - ClearEoln(); -} - - void Curses_ShowCurrentMove(short pnt, short f, short t) { @@@ -162,26 -167,20 +164,26 @@@ Curses_ShowMessage(char *s void -Curses_AlwaysShowMessage(const char *format, va_list ap) +Curses_AlwaysShowMessage(const char *format, ...) { static char buffer[60]; + va_list ap; + va_start(ap, format); vsnprintf(buffer, sizeof(buffer), format, ap); Curses_ShowMessage(buffer); + va_end(ap); } void -Curses_Printf(const char *format, va_list ap) +Curses_Printf(const char *format, ...) { static char buffer[60]; + va_list ap; + va_start(ap, format); vsnprintf(buffer, sizeof(buffer), format, ap); printw("%s", buffer); + va_end(ap); } @@@ -675,7 -674,7 +677,7 @@@ Curses_OutputMove(void t = (l + h) >> 1; } - ShowNodeCnt(NodeCnt); + Curses_ShowNodeCnt(NodeCnt); gotoXY(TAB, 23); printw("Max Tree = %5d", t); ClearEoln(); @@@ -717,7 -716,7 +719,7 @@@ Curses_UpdateClocks(void printw("%d:%02d ", m, s); if (flag.post) - ShowNodeCnt(NodeCnt); + Curses_ShowNodeCnt(NodeCnt); refresh(); } @@@ -767,8 -766,10 +769,8 @@@ DrawPiece(short sq void Curses_ShowPostnValue(short sq) { - short score; - gotoXY(4 + 5 * VIR_C(sq), 5 + 2 * (7 - VIR_R(sq))); /* CHECKME */ - score = ScorePosition(color[sq]); + (void) ScorePosition(color[sq]); if (color[sq] != neutral) #if defined SAVE_SVALUE @@@ -965,7 -966,7 +967,7 @@@ Curses_GiveHint(void void -Curses_ChangeSearchDepth(void) +Curses_ChangeSearchDepth(char* sx) { Curses_ShowMessage("depth = "); FLUSH_SCANW("%hd", &MaxSearchDepth); @@@ -1201,48 -1202,3 +1203,48 @@@ Curses_SetupBoard(void { Curses_ShowMessage("'setup' command is not supported in Cursesmode"); } + + +struct display curses_display = +{ + .ChangeAlphaWindow = Curses_ChangeAlphaWindow, + .ChangeBetaWindow = Curses_ChangeBetaWindow, + .ChangeHashDepth = Curses_ChangeHashDepth, + .ChangeSearchDepth = Curses_ChangeSearchDepth, + .ChangeXwindow = Curses_ChangeXwindow, + .ClearScreen = Curses_ClearScreen, + .DoDebug = Curses_DoDebug, + .DoTable = Curses_DoTable, + .EditBoard = Curses_EditBoard, + .ExitShogi = Curses_ExitShogi, + .GiveHint = Curses_GiveHint, + .Initialize = Curses_Initialize, + .ShowNodeCnt = Curses_ShowNodeCnt, + .OutputMove = Curses_OutputMove, + .PollForInput = Curses_PollForInput, + .SetContempt = Curses_SetContempt, + .SearchStartStuff = Curses_SearchStartStuff, + .SelectLevel = Curses_SelectLevel, + .ShowCurrentMove = Curses_ShowCurrentMove, + .ShowDepth = Curses_ShowDepth, + .ShowGameType = Curses_ShowGameType, + .ShowLine = Curses_ShowLine, + .ShowMessage = Curses_ShowMessage, + .AlwaysShowMessage = Curses_AlwaysShowMessage, + .Printf = Curses_Printf, + .doRequestInputString = Curses_doRequestInputString, + .GetString = Curses_GetString, + .SetupBoard = Curses_SetupBoard, + .ShowPatternCount = Curses_ShowPatternCount, + .ShowPostnValue = Curses_ShowPostnValue, + .ShowPostnValues = Curses_ShowPostnValues, + .ShowPrompt = Curses_ShowPrompt, + .ShowResponseTime = Curses_ShowResponseTime, + .ShowResults = Curses_ShowResults, + .ShowSidetoMove = Curses_ShowSidetoMove, + .ShowStage = Curses_ShowStage, + .TerminateSearch = Curses_TerminateSearch, + .UpdateClocks = Curses_UpdateClocks, + .UpdateDisplay = Curses_UpdateDisplay, + .help = Curses_help, +}; diff --combined gnushogi/rawdsp.c index 6e621b6,8337d41..09d977a --- a/gnushogi/rawdsp.c +++ b/gnushogi/rawdsp.c @@@ -32,7 -32,6 +32,7 @@@ #include #include #include +#include #include #include #include @@@ -42,6 -41,7 +42,6 @@@ #endif #include "gnushogi.h" -#include "rawdsp.h" unsigned short MV[MAXDEPTH]; int MSCORE; @@@ -51,11 -51,6 +51,11 @@@ char *DRAW extern char *InPtr; extern short pscore[]; +/**************************************** + * forward declarations + ****************************************/ + +void Raw_UpdateDisplay(short f, short t, short redraw, short isspec); /**************************************** * Trivial output functions. @@@ -131,23 -126,17 +131,23 @@@ Raw_ShowMessage(char *s void -Raw_AlwaysShowMessage(const char *format, va_list ap) +Raw_AlwaysShowMessage(const char *format, ...) { + va_list ap; + va_start(ap, format); vprintf(format, ap); printf("\n"); + va_end(ap); } void -Raw_Printf(const char *format, va_list ap) +Raw_Printf(const char *format, ...) { + va_list ap; + va_start(ap, format); vprintf(format, ap); + va_end(ap); } @@@ -162,17 -151,10 +162,17 @@@ in Raw_GetString(char* sx) { int eof = 0; + char *nl; sx[0] = '\0'; while(!eof && !sx[0]) eof = (fgets(sx, 80, stdin) == NULL); + + /* remove any trailing newline */ + nl = strchr(sx, '\n'); + if (nl) + nl[0] = '\0'; + return eof; } @@@ -241,13 -223,13 +241,13 @@@ Raw_Initialize(void /* needed because of inconsistency between MSVC run-time system and gcc includes */ setbuf(stdout, NULL); #else - #ifdef HAVE_SETLINEBUF - setlinebuf(stdout); - #else - # ifdef HAVE_SETVBUF + #ifdef HAVE_SETVBUF setvbuf(stdout, NULL, _IOLBF, BUFSIZ); + #else + # ifdef HAVE_SETLINEBUF + setlinebuf(stdout); # else - # error "Need setlinebuf() or setvbuf() to compile gnushogi!" + # error "Need setvbuf() or setlinebuf() to compile gnushogi!" # endif #endif #endif @@@ -307,48 -289,30 +307,48 @@@ Raw_help(void { Raw_ClearScreen(); printf("GNU Shogi %s command summary\n", PACKAGE_VERSION); - printf("----------------------------------" - "------------------------------\n"); - fputs ("7g7f move from 7g to 7f quit Exit Shogi\n", stdout); - printf("S6h move silver to 6h beep turn %s\n", (flag.beep) ? "OFF" : "ON"); - printf("2d2c+ move to 2c and promote material turn %s\n", (flag.material) ? "OFF" : "ON"); - printf("P*5e drop pawn to 5e easy turn %s\n", (flag.easy) ? "OFF" : "ON"); - printf("tsume toggle tsume mode hash turn %s\n", (flag.hash) ? "OFF" : "ON"); - fputs ("bd redraw board reverse board display\n", stdout); - printf("list game to shogi.lst book turn %s used %d of %d\n", (Book) ? "OFF" : "ON", bookcount, booksize); - fputs ("undo undo last ply remove take back a move\n", stdout); - fputs ("edit edit board force toggle manual move mode\n", stdout); - fputs ("switch sides with computer both computer match\n", stdout); - fputs ("black computer plays black white computer plays white\n", stdout); - fputs ("depth set search depth clock set time control\n", stdout); - fputs ("post principle variation hint suggest a move\n", stdout); - fputs ("save game to file get game from file\n", stdout); - printf("xsave pos. to xshogi file xget" - " pos. from xshogi file\n"); - fputs("random randomize play new start new game\n", stdout); - printf("--------------------------------" - "--------------------------------\n"); + printf("----------------------------------------------------------------\n"); + printf("7g7f move from 7g to 7f quit Exit Shogi\n"); + printf("S6h move silver to 6h beep turn %s\n", + (flag.beep) ? "OFF" : "ON"); + printf("2d2c+ move to 2c and promote material turn %s\n", + (flag.material) ? "OFF" : "ON"); + printf("P*5e drop pawn to 5e easy turn %s\n", + (flag.easy) ? "OFF" : "ON"); + printf("tsume toggle tsume mode hash turn %s\n", + (flag.hash) ? "OFF" : "ON"); + printf("bd redraw board reverse board display\n"); + printf("list game to shogi.lst book turn %s used %d of %d\n", + (Book) ? "OFF" : "ON", bookcount, booksize); + printf("undo undo last ply remove take back a move\n"); + printf("edit edit board force toggle manual move mode\n"); + printf("switch sides with computer both computer match\n"); + printf("black computer plays black white computer plays white\n"); + printf("sd set search depth clock set time control\n"); + printf("post principle variation hint suggest a move\n"); + printf("save game to file get game from file\n"); + printf("xsave pos. to xshogi file xget pos. from xshogi file\n"); + printf("random randomize play new start new game\n"); + printf("setup first \n"); + printf("go computer plays now material turn %s\n", + flag.material ? "OFF" : "ON"); + printf("level time control gamein \n"); + printf("time set engine clock otime set opponent clock\n"); + printf("Awindow Bwindow \n"); + printf("rcptr turn %3s bsave book save\n", + flag.rcptr ? "OFF" : "ON "); + printf("hashdepth hard turn easy OFF\n"); + printf("contempt xwndw \n"); + printf("rv turn %3s coords turn %s\n", + flag.rv ? "OFF" : "ON ", flag.coords ? "OFF" : "ON"); + printf("stars turn %3s moves \n", + flag.stars ? "OFF" : "ON "); + printf("test p \n"); + printf("debug depth alias for 'sd'\n"); + printf("----------------------------------------------------------------\n"); printf("Computer: %-12s Opponent: %s\n", ColorStr[computer], ColorStr[opponent]); - printf("Depth: %-12d Response time: %d sec\n", + printf("Depth: %-12d Response time: %ld sec\n", MaxSearchDepth, MaxResponseTime/100); printf("Random: %-12s Easy mode: %s\n", (dither) ? "ON" : "OFF", (flag.easy) ? "ON" : "OFF"); @@@ -356,7 -320,7 +356,7 @@@ (flag.beep) ? "ON" : "OFF", (flag.hash) ? "ON" : "OFF"); printf("Tsume: %-12s Force: %s\n", (flag.tsume) ? "ON" : "OFF", (flag.force) ? "ON" : "OFF"); - printf("Time Control %s %d moves %d sec %d add %d depth\n", + printf("Time Control %s %d moves %ld sec %d add %d depth\n", (TCflag) ? "ON" : "OFF", TimeControl.moves[black], TimeControl.clock[black] / 100, TCadd/100, MaxSearchDepth); @@@ -723,17 -687,28 +723,17 @@@ Raw_GiveHint(void void Raw_SelectLevel(char *sx) { + /* FIXME: NO_SQUARES is nonsense here */ + char T[NO_SQUARES + 1], *p; - char T[NO_SQUARES + 1], *p, *q; - - if ((p = strstr(sx, "level")) != NULL) - p += strlen("level"); - else if ((p = strstr(sx, "clock")) != NULL) - p += strlen("clock"); - - strcat(sx, "XX"); - q = T; - *q = '\0'; + strncpy(T, sx, NO_SQUARES); + T[NO_SQUARES] = '\0'; - for (; *p != 'X'; *q++ = *p++); - - *q = '\0'; - - /* line empty ask for input */ + /* if line empty, ask for input */ if (!T[0]) { fputs("Enter #moves #minutes: ", stdout); fgets(T, NO_SQUARES + 1, stdin); - strcat(T, "XX"); } /* skip blackspace */ @@@ -743,7 -718,6 +743,7 @@@ if (*p == 'f') { /* its a fischer clock game */ + char *q; p++; TCminutes = (short)strtol(p, &q, 10); TCadd = (short)strtol(q, NULL, 10) *100; @@@ -753,7 -727,6 +753,7 @@@ else { /* regular game */ + char *q; TCadd = 0; TCmoves = (short)strtol(p, &q, 10); TCminutes = (short)strtol(q, &q, 10); @@@ -794,16 -767,10 +794,16 @@@ void -Raw_ChangeSearchDepth(void) +Raw_ChangeSearchDepth(char *sx) { - printf("depth = "); - scanf("%hd", &MaxSearchDepth); + char buf[80+1]; + strncpy(buf, sx, 80); buf[80] = '\0'; + /* if line empty, ask for input */ + if (!buf[0]) { + printf("depth = "); + fgets(buf, 80+1, stdin); + } + sscanf(buf, "%hd", &MaxSearchDepth); TCflag = !(MaxSearchDepth > 0); } @@@ -841,7 -808,8 +841,7 @@@ Raw_ChangeXwindow(void void Raw_ShowPostnValue(short sq) { - short score; - score = ScorePosition(color[sq]); + (void) ScorePosition(color[sq]); if (color[sq] != neutral) { @@@ -988,12 -956,12 +988,12 @@@ Raw_PollForInput(void 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 } }; + static struct pollfd pollfds[1] = { [0] = { .fd = STDIN_FILENO, + .events = POLLIN } }; int cnt = poll(pollfds, sizeof(pollfds)/sizeof(pollfds[0]), 0); if (cnt < 0) { perror("polling standard input"); - ExitShogi(); + Raw_ExitShogi(); } #endif if (cnt) { /* if anything to read, or error occured */ @@@ -1002,47 -970,3 +1002,47 @@@ flag.bothsides = false; } } + +struct display raw_display = +{ + .ChangeAlphaWindow = Raw_ChangeAlphaWindow, + .ChangeBetaWindow = Raw_ChangeBetaWindow, + .ChangeHashDepth = Raw_ChangeHashDepth, + .ChangeSearchDepth = Raw_ChangeSearchDepth, + .ChangeXwindow = Raw_ChangeXwindow, + .ClearScreen = Raw_ClearScreen, + .DoDebug = Raw_DoDebug, + .DoTable = Raw_DoTable, + .EditBoard = Raw_EditBoard, + .ExitShogi = Raw_ExitShogi, + .GiveHint = Raw_GiveHint, + .Initialize = Raw_Initialize, + .ShowNodeCnt = Raw_ShowNodeCnt, + .OutputMove = Raw_OutputMove, + .PollForInput = Raw_PollForInput, + .SetContempt = Raw_SetContempt, + .SearchStartStuff = Raw_SearchStartStuff, + .SelectLevel = Raw_SelectLevel, + .ShowCurrentMove = Raw_ShowCurrentMove, + .ShowDepth = Raw_ShowDepth, + .ShowGameType = Raw_ShowGameType, + .ShowLine = Raw_ShowLine, + .ShowMessage = Raw_ShowMessage, + .AlwaysShowMessage = Raw_AlwaysShowMessage, + .Printf = Raw_Printf, + .doRequestInputString = Raw_doRequestInputString, + .GetString = Raw_GetString, + .SetupBoard = Raw_SetupBoard, + .ShowPatternCount = Raw_ShowPatternCount, + .ShowPostnValue = Raw_ShowPostnValue, + .ShowPostnValues = Raw_ShowPostnValues, + .ShowPrompt = Raw_ShowPrompt, + .ShowResponseTime = Raw_ShowResponseTime, + .ShowResults = Raw_ShowResults, + .ShowSidetoMove = Raw_ShowSidetoMove, + .ShowStage = Raw_ShowStage, + .TerminateSearch = Raw_TerminateSearch, + .UpdateClocks = Raw_UpdateClocks, + .UpdateDisplay = Raw_UpdateDisplay, + .help = Raw_help, +};