Merge branch 'maint'
authorYann Dirson <ydirson@free.fr>
Sun, 12 Jan 2014 14:30:26 +0000 (15:30 +0100)
committerYann Dirson <ydirson@free.fr>
Sun, 12 Jan 2014 14:30:26 +0000 (15:30 +0100)
20 files changed:
configure.ac
gnushogi/Makefile.in
gnushogi/book.c
gnushogi/commondsp.c
gnushogi/cursesdsp.c
gnushogi/cursesdsp.h [deleted file]
gnushogi/dspwrappers.c [deleted file]
gnushogi/dspwrappers.h [deleted file]
gnushogi/eval.c
gnushogi/genmove.c
gnushogi/gnushogi.h
gnushogi/init-common.c
gnushogi/init.c
gnushogi/main.c
gnushogi/makepattern.c
gnushogi/rawdsp.c
gnushogi/rawdsp.h [deleted file]
gnushogi/search.c
gnushogi/tcontrl.c
gnushogi/util.c

index 9b8039d..e6ab85f 100644 (file)
@@ -57,7 +57,7 @@ AC_CHECK_LIB([termcap], [tgoto])
 
 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"
 else
 # Who knows what warnings your compiler uses?
index d8749dc..f0c8684 100644 (file)
@@ -115,7 +115,6 @@ NOTCOMMONFILES = \
                 book.o         \
                 commondsp.o    \
                 @CURSESDSP@    \
-                dspwrappers.o  \
                 eval.o         \
                 genmove.o      \
                 init.o         \
@@ -165,9 +164,6 @@ commondsp.o: commondsp.c
 cursesdsp.o: cursesdsp.c
        $(CC) $(CFLAGS) -c $<
 
-dspwrappers.o: dspwrappers.c
-       $(CC) $(CFLAGS) -c $<
-
 genmove.o: genmove.c
        $(CC) $(CFLAGS) -c $<
 
@@ -274,11 +270,11 @@ attacks.o:     attacks.c gnushogi.h
 book.o:        book.c gnushogi.h
 commondsp.o:   commondsp.c gnushogi.h
 cursesdsp.o:   cursesdsp.c gnushogi.h
-dspwrappers.o: dspwrappers.c gnushogi.h
 genmove.o:     genmove.c gnushogi.h
 globals.o:     globals.c gnushogi.h
 eval.o:        eval.c eval.h gnushogi.h $(SRCDIR)/pattern.h
 init.o:        init.c gnushogi.h $(SRCDIR)/pattern.h
+init-common.o: init-common.c gnushogi.h
 main.o:        main.c gnushogi.h
 makepattern.o: pattern.c gnushogi.h $(SRCDIR)/pattern.h
 pattern.o:     pattern.c gnushogi.h $(SRCDIR)/pattern.h pattern.inc
index ae3956f..88d21be 100644 (file)
@@ -365,7 +365,7 @@ RESET(void)
 
 static
 int
-Vparse (FILE * fd, USHORT *mv, USHORT *flags, USHORT side, int moveno)
+Vparse (FILE * fd, USHORT *mv, USHORT *flags, int moveno)
 {
     int c, i;
     char s[255];
@@ -646,7 +646,7 @@ GetOpenings(void)
 {
     short i;
     int mustwrite = false, first;
-    unsigned short xside, side;
+    unsigned short side;
     short c;
     USHORT mv, flags;
     unsigned int x;
@@ -715,11 +715,10 @@ GetOpenings(void)
         {
             /* setvbuf(fd, buffr, _IOFBF, 2048); */
             side = black;
-            xside = white;
             hashbd = hashkey = 0;
             i = 0;
 
-            while ((c = Vparse(fd, &mv, &flags, side, i)) >= 0)
+            while ((c = Vparse(fd, &mv, &flags, i)) >= 0)
             {
                 if (c == 1)
                 {
@@ -821,7 +820,6 @@ GetOpenings(void)
                     computer = opponent;
                     opponent = computer ^ 1;
 
-                    xside = side;
                     side = side ^ 1;
                 }
                 else if (i > 0)
@@ -832,8 +830,6 @@ GetOpenings(void)
                     RESET();
                     i = 0;
                     side = black;
-                    xside = white;
-
                 }
             }
 
@@ -875,8 +871,8 @@ GetOpenings(void)
 
         }
 
-        sprintf(msg, "Book used %d(%d).", B.bookcount, B.booksize);
-        ShowMessage(msg);
+        sprintf(msg, "Book used %lu(%lu).", B.bookcount, B.booksize);
+        dsp->ShowMessage(msg);
     }
 
     /* Set everything back to start the game. */
@@ -886,7 +882,7 @@ GetOpenings(void)
     /* Now get ready to play .*/
     if (!B.bookcount)
     {
-        ShowMessage("Can't find book.");
+        dsp->ShowMessage("Can't find book.");
         Book = 0;
     }
 }
@@ -894,7 +890,7 @@ GetOpenings(void)
 
 
 /*
- * OpeningBook(hint, side)
+ * OpeningBook(hint)
  *
  * Go through each of the opening lines of play and check for a match with
  * the current game listing. If a match occurs, generate a random
@@ -906,7 +902,7 @@ GetOpenings(void)
  */
 
 int
-OpeningBook(unsigned short *hint, short side)
+OpeningBook(unsigned short *hint)
 {
     unsigned short r, m;
     int possibles = TrPnt[2] - TrPnt[1];
index 4cbfb81..4e3eb07 100644 (file)
@@ -51,6 +51,7 @@
 char mvstr[4][6];
 char *InPtr;
 int InBackground = false;
+struct display *dsp = &raw_display;
 
 
 #if defined(BOOKTEST)
@@ -127,8 +128,6 @@ movealgbr(short m, char *s)
 #endif /* BOOKTEST */
 
 
-
-
 /*
  * Generate move strings in different formats.
  *
@@ -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';
@@ -220,7 +219,6 @@ algbr(short f, short t, short flag)
 }
 
 
-
 /*
  * 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.
@@ -301,7 +299,7 @@ VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv)
         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
@@ -309,7 +307,7 @@ VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv)
             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);
@@ -334,7 +332,7 @@ VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv)
                     char buf[20];
 
                     sprintf(buf, "%s mates!\n", ColorStr[opponent]);
-                    ShowMessage(buf);
+                    dsp->ShowMessage(buf);
                     flag.mate = true;
                 }
             }
@@ -343,21 +341,20 @@ VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv)
         }
     }
 
-    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;
@@ -405,7 +402,6 @@ skip()
 }
 
 
-
 void
 skipb()
 {
@@ -414,8 +410,25 @@ skipb()
 }
 
 
+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;
@@ -427,7 +440,7 @@ GetGame(void)
     if (savefile[0]) {
         strcpy(fname, savefile);
     } else {
-        ShowMessage("Enter file name: ");
+        dsp->ShowMessage("Enter file name: ");
         RequestInputString(fname, sizeof(fname)-1);
     }
 
@@ -579,7 +592,7 @@ GetGame(void)
             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();
@@ -632,14 +645,13 @@ GetGame(void)
 
     ZeroRPT();
     InitializeStats();
-    UpdateDisplay(0, 0, 1, 0);
+    dsp->UpdateDisplay(0, 0, 1, 0);
     Sdepth = 0;
     hint = 0;
 }
 
 
-
-void
+static void
 SaveGame(void)
 {
     FILE *fd;
@@ -652,7 +664,7 @@ SaveGame(void)
     if (savefile[0]) {
         strcpy(fname, savefile);
     } else {
-        ShowMessage("Enter file name: ");
+        dsp->ShowMessage("Enter file name: ");
         RequestInputString(fname, sizeof(fname)-1);
     }
 
@@ -777,22 +789,21 @@ SaveGame(void)
 
         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;
@@ -801,7 +812,7 @@ GetXGame(void)
     short sq;
     short side, isp;
 
-    ShowMessage("Enter file name: ");
+    dsp->ShowMessage("Enter file name: ");
     RequestInputString(fname, sizeof(fname)-1);
 
     if (fname[0] == '\0')
@@ -915,13 +926,13 @@ GetXGame(void)
     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;
@@ -930,7 +941,7 @@ SaveXGame(void)
     short sq, piece;
     short side, isp;
 
-    ShowMessage("Enter file name: ");
+    dsp->ShowMessage("Enter file name: ");
     RequestInputString(fname, sizeof(fname)-1);
 
     if (fname[0] == '\0')
@@ -1001,7 +1012,7 @@ SaveXGame(void)
 }
 
 
-void
+static void
 BookSave(void)
 {
     FILE *fd;
@@ -1012,7 +1023,7 @@ BookSave(void)
         strcpy(fname, savefile);
     } else {
         /* Enter file name */
-        ShowMessage("Enter file name: ");
+        dsp->ShowMessage("Enter file name: ");
         RequestInputString(fname, sizeof(fname)-1);
     }
 
@@ -1084,16 +1095,15 @@ BookSave(void)
 
         fclose(fd);
 
-        ShowMessage("Game saved");
+        dsp->ShowMessage("Game saved");
     }
     else
     {
-        ShowMessage("Could not open file");
+        dsp->ShowMessage("Could not open file");
     }
 }
 
 
-
 void
 ListGame(void)
 {
@@ -1221,8 +1231,7 @@ ListGame(void)
 }
 
 
-
-void
+static void
 FlagMove(char c)
 {
     switch(c)
@@ -1244,13 +1253,11 @@ FlagMove(char c)
 }
 
 
-
-
 /*
  * Undo the most recent half-move.
  */
 
-void
+static void
 Undo(void)
 {
     short f, t;
@@ -1299,15 +1306,14 @@ Undo(void)
     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)
 {
@@ -1360,8 +1366,7 @@ FlagString(unsigned short flags, char *s)
 }
 
 
-
-void
+static void
 TestSpeed(void(*f)(short side, short ply,
                    short in_check, short blockable),
           unsigned j)
@@ -1411,15 +1416,14 @@ TestSpeed(void(*f)(short side, short ply,
     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,24 +1453,22 @@ TestPSpeed(short(*f) (short side), unsigned j)
     else
         et = 1;
 
-    ShowNodeCnt(cnt);
+    dsp->ShowNodeCnt(cnt);
 }
 
 
-
-void
-SetOppTime(char *s)
+static void
+SetOppTime(char *time)
 {
-    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);
     }
 
@@ -1488,20 +1490,18 @@ SetOppTime(char *s)
 }
 
 
-
-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);
     }
 
@@ -1523,24 +1523,19 @@ SetMachineTime(char *s)
 }
 
 
-
-
-
 /* 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;
@@ -1567,10 +1562,8 @@ InputCommand(char *command)
         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))
@@ -1578,7 +1571,7 @@ InputCommand(char *command)
             Sdepth = 0;
 
 #ifdef QUIETBACKGROUND
-            ShowPrompt();
+            dsp->ShowPrompt();
             have_shown_prompt = true;
 #endif /* QUIETBACKGROUND */
 
@@ -1625,7 +1618,7 @@ InputCommand(char *command)
         {
 #endif /* QUIETBACKGROUND */
 
-            ShowPrompt();
+            dsp->ShowPrompt();
 
 #ifdef QUIETBACKGROUND
         }
@@ -1634,21 +1627,16 @@ InputCommand(char *command)
 #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 */
@@ -1659,8 +1647,8 @@ InputCommand(char *command)
             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;
@@ -1671,27 +1659,21 @@ InputCommand(char *command)
         }
         else if (strcmp(s, "alg") == 0)
         {
-            /* noop */ ; /* alg */
+            /* noop */ ;
         }
         else if ((strcmp(s, "quit") == 0)
                  || (strcmp(s, "exit") == 0))
         {
             flag.quit = true;
         }
-#if !defined NOPOST
-        else if (strcmp(s, "post") == 0)
-        {
-            flag.post = !flag.post;
-        }
-#endif
         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)
         {
@@ -1715,7 +1697,7 @@ InputCommand(char *command)
         }
         else if (strcmp(s, "help") == 0)
         {
-            help();
+            dsp->help();
         }
         else if (strcmp(s, "material") == 0)
         {
@@ -1741,16 +1723,19 @@ InputCommand(char *command)
         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)
         {
@@ -1766,19 +1751,19 @@ InputCommand(char *command)
         }
         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)
         {
@@ -1786,7 +1771,7 @@ InputCommand(char *command)
         }
         else if (strcmp(s, "hint") == 0)
         {
-            GiveHint();
+            dsp->GiveHint();
         }
         else if (strcmp(s, "both") == 0)
         {
@@ -1800,8 +1785,8 @@ InputCommand(char *command)
         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)
         {
@@ -1879,11 +1864,15 @@ InputCommand(char *command)
         }
         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)
         {
@@ -1903,26 +1892,26 @@ InputCommand(char *command)
         }
         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)
         {
@@ -1940,44 +1929,44 @@ InputCommand(char *command)
 #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
         {
@@ -1993,7 +1982,7 @@ InputCommand(char *command)
                 if (rpt >= 3)
                 {
                     DRAW = DRAW_REPETITION;
-                    ShowMessage(DRAW);
+                    dsp->ShowMessage(DRAW);
                     GameList[GameCnt].flags |= draw;
 
                         flag.mate = true;
@@ -2026,8 +2015,6 @@ InputCommand(char *command)
         }
 
 #ifdef notdef /* optional pass best line to frontend with move */
-#  if !defined NOPOST
-
         if (flag.post && !flag.mate)
         {
             int i;
@@ -2040,15 +2027,12 @@ InputCommand(char *command)
                 printf("%5s ", mvstr[0]);
             }
         }
-#  endif
         printf("\n");
 #endif
     }
 }
 
 
-
-
 void
 SetTimeControl(void)
 {
@@ -2068,4 +2052,3 @@ SetTimeControl(void)
     et = 0;
     ElapsedTime(COMPUTE_AND_INIT_MODE);
 }
-
index 4d00015..277f185 100644 (file)
@@ -36,6 +36,7 @@
 #include <ctype.h>
 #include <signal.h>
 #include <stdio.h>
+#include <stdarg.h>
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -43,7 +44,6 @@
 #include <curses.h>
 
 #include "gnushogi.h"
-#include "cursesdsp.h"
 
 #if HAVE_UNISTD_H
 #include <unistd.h>
@@ -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.
@@ -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)
 {
@@ -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);
 }
 
 
@@ -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();
@@ -716,7 +719,7 @@ Curses_UpdateClocks(void)
     printw("%d:%02d  ", m, s); 
 
     if (flag.post)
-        ShowNodeCnt(NodeCnt);
+        Curses_ShowNodeCnt(NodeCnt);
 
     refresh();
 }
@@ -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
@@ -966,7 +967,7 @@ Curses_GiveHint(void)
 
 
 void
-Curses_ChangeSearchDepth(void)
+Curses_ChangeSearchDepth(char* sx)
 {
     Curses_ShowMessage("depth = ");
     FLUSH_SCANW("%hd", &MaxSearchDepth);
@@ -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 --git a/gnushogi/cursesdsp.h b/gnushogi/cursesdsp.h
deleted file mode 100644 (file)
index 6f2b07e..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * FILE: cursesdsp.h
- *
- *     Curses interface 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
- * <http://www.gnu.org/licenses/>.
- * ----------------------------------------------------------------------
- *
- */
-
-#ifndef _CURSESDSP_H_
-#define _CURSESDSP_H_
-
-#include "gnushogi.h"
-
-/* The following are common to rawdsp.h and cursesdsp.h */
-
-void Curses_ChangeAlphaWindow(void);
-void Curses_ChangeBetaWindow(void);
-void Curses_ChangeHashDepth(void);
-void Curses_ChangeSearchDepth(void);
-void Curses_ChangeXwindow(void);
-void Curses_ClearScreen(void);
-void Curses_Die(int sig);
-void Curses_DoDebug(void);
-void Curses_DoTable(short table[NO_SQUARES]);
-void Curses_EditBoard(void);
-void Curses_ExitShogi(void);
-void Curses_GiveHint(void);
-void Curses_Initialize(void);
-void Curses_ShowNodeCnt(long NodeCnt);
-void Curses_OutputMove(void);
-void Curses_PollForInput(void);
-void Curses_SearchStartStuff(short side);
-void Curses_SelectLevel(char *sx);
-void Curses_SetContempt(void);
-void Curses_ShowCurrentMove(short pnt, short f, short t);
-void Curses_ShowDepth(char ch);
-void Curses_ShowGameType(void);
-void Curses_ShowLine(unsigned short *bstline);
-void Curses_ShowMessage(char *s);
-void Curses_AlwaysShowMessage(const char *format, va_list ap);
-void Curses_Printf(const char *format, va_list ap);
-void Curses_doRequestInputString(const char* fmt, char* buffer);
-int  Curses_GetString(char* sx);
-void Curses_SetupBoard(void);
-void Curses_ShowPatternCount(short side, short n);
-void Curses_ShowPostnValue(short sq);
-void Curses_ShowPostnValues(void);
-void Curses_ShowPrompt(void);
-void Curses_ShowResponseTime(void);
-void Curses_ShowResults(short score, unsigned short *bstline, char ch);
-void Curses_ShowSidetoMove(void);
-void Curses_ShowStage(void);
-void Curses_TerminateSearch(int sig);
-void Curses_UpdateClocks(void);
-void Curses_UpdateDisplay(short f, short t, short redraw, short isspec);
-void Curses_help(void);
-
-#endif /* _CURSESDSP_H_ */
diff --git a/gnushogi/dspwrappers.c b/gnushogi/dspwrappers.c
deleted file mode 100644 (file)
index ee5274d..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * FILE: dspwrappers.c
- *
- *     Wrapper functions which call analogous functions in rawdsp.c
- *     or cursesdsp.c depending on the interface.
- *
- * ----------------------------------------------------------------------
- * 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
- * <http://www.gnu.org/licenses/>.
- * ----------------------------------------------------------------------
- *
- */
-
-/* request *snprintf prototypes*/
-#define _POSIX_C_SOURCE 200112L
-
-#include "gnushogi.h"
-#include "dspwrappers.h"
-#include "rawdsp.h"
-#include "cursesdsp.h"
-
-#include <stdio.h>
-
-#define CASE_DSP_RAW(func,args) \
-  case DISPLAY_RAW:             \
-  case DISPLAY_X:               \
-    func args;                  \
-    break
-
-#ifdef HAVE_LIBCURSES
-#define CASE_DSP_CURSES(func,args) \
-  case DISPLAY_CURSES:             \
-    func args;                     \
-    break;
-#else
-#define CASE_DSP_CURSES(func,args)
-#endif
-
-#define DISPLAY_FUNC(func,argsdecl,args)        \
-  void func argsdecl                            \
-  {                                             \
-    switch (display_type) {                     \
-      CASE_DSP_RAW(Raw_ ## func, args);         \
-      CASE_DSP_CURSES(Curses_ ## func, args);   \
-    }                                           \
-  }
-#define DISPLAY_VOIDFUNC(func)                  \
-  DISPLAY_FUNC(func,(void),())
-
-#define DISPLAY_STDARGFUNC(func,argsdecl,last,args)     \
-  void func argsdecl                                    \
-  {                                                     \
-    va_list ap;                                         \
-    va_start(ap, last);                                 \
-    switch (display_type) {                             \
-      CASE_DSP_RAW(Raw_ ## func, args);                 \
-      CASE_DSP_CURSES(Curses_ ## func, args);           \
-    }                                                   \
-    va_end(ap);                                         \
-  }
-
-DISPLAY_VOIDFUNC(ChangeAlphaWindow)
-DISPLAY_VOIDFUNC(ChangeBetaWindow)
-DISPLAY_VOIDFUNC(ChangeHashDepth)
-DISPLAY_VOIDFUNC(ChangeSearchDepth)
-DISPLAY_VOIDFUNC(ChangeXwindow)
-DISPLAY_VOIDFUNC(ClearScreen)
-DISPLAY_VOIDFUNC(DoDebug)
-DISPLAY_FUNC(DoTable, (short table[NO_SQUARES]), (table))
-DISPLAY_VOIDFUNC(EditBoard)
-DISPLAY_VOIDFUNC(ExitShogi)
-DISPLAY_VOIDFUNC(GiveHint)
-DISPLAY_VOIDFUNC(Initialize)
-DISPLAY_FUNC(ShowNodeCnt, (long NodeCnt), (NodeCnt))
-DISPLAY_VOIDFUNC(OutputMove)
-DISPLAY_VOIDFUNC(PollForInput)
-DISPLAY_VOIDFUNC(SetContempt)
-DISPLAY_FUNC(SearchStartStuff, (short side), (side))
-DISPLAY_FUNC(SelectLevel, (char *sx), (sx))
-DISPLAY_VOIDFUNC(SetupBoard)
-DISPLAY_FUNC(ShowCurrentMove, (short pnt, short f, short t), (pnt, f, t))
-DISPLAY_FUNC(ShowDepth, (char ch), (ch))
-DISPLAY_VOIDFUNC(ShowGameType)
-DISPLAY_FUNC(ShowLine, (unsigned short *bstline), (bstline))
-DISPLAY_FUNC(ShowMessage, (char *s), (s))
-DISPLAY_STDARGFUNC(AlwaysShowMessage, (const char *format, ...), format, (format, ap))
-DISPLAY_STDARGFUNC(Printf, (const char *format, ...), format, (format, ap))
-DISPLAY_FUNC(ShowPatternCount, (short side, short n), (side, n))
-DISPLAY_FUNC(ShowPostnValue, (short sq), (sq))
-DISPLAY_VOIDFUNC(ShowPostnValues)
-DISPLAY_VOIDFUNC(ShowPrompt)
-DISPLAY_VOIDFUNC(ShowResponseTime)
-DISPLAY_FUNC(ShowResults, (short score, unsigned short *bstline, char ch), (score, bstline, ch))
-DISPLAY_VOIDFUNC(ShowSidetoMove)
-DISPLAY_VOIDFUNC(ShowStage)
-DISPLAY_FUNC(TerminateSearch, (int sig), (sig))
-DISPLAY_VOIDFUNC(UpdateClocks)
-DISPLAY_FUNC(UpdateDisplay, (short f, short t, short redraw, short isspec), (f, t, redraw, isspec))
-DISPLAY_VOIDFUNC(help)
-
-DISPLAY_FUNC(doRequestInputString, (const char* fmt, char* buffer), (fmt, buffer))
-void RequestInputString(char* buffer, unsigned bufsize)
-{
-    static char fmt[10];
-    int ret = snprintf(fmt, sizeof(fmt), "%%%us", bufsize);
-    if (ret >= sizeof(fmt)) {
-        fprintf(stderr,
-                "Insufficient format-buffer size in %s for bufsize=%u\n",
-                __FUNCTION__, bufsize);
-        exit(1);
-    }
-    doRequestInputString(fmt, buffer);
-}
-
-/*********/
-
-#define CASE_DSPFUNC_RAW(func,args) \
-  case DISPLAY_RAW:                 \
-  case DISPLAY_X:                   \
-    return (func args);             \
-    break
-
-#ifdef HAVE_LIBCURSES
-#define CASE_DSPFUNC_CURSES(func,args) \
-  case DISPLAY_CURSES:                 \
-    return (func args);                \
-    break;
-#else
-#define CASE_DSPFUNC_CURSES(func,args)
-#endif
-
-#define DISPLAY_INTFUNC(func,argsdecl,args)         \
-  int func argsdecl                                 \
-  {                                                 \
-    switch (display_type) {                         \
-      CASE_DSPFUNC_RAW(Raw_ ## func, args);         \
-      CASE_DSPFUNC_CURSES(Curses_ ## func, args);   \
-    }                                               \
-    assert(0);                                      \
-  }
-
-DISPLAY_INTFUNC(GetString, (char* sx), (sx))
diff --git a/gnushogi/dspwrappers.h b/gnushogi/dspwrappers.h
deleted file mode 100644 (file)
index 0bfe79f..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * FILE: dspwrappers.h
- *
- *     Wrapper functions which call analogous functions in rawdsp.c
- *     or cursesdsp.c depending on the interface.
- *
- * ----------------------------------------------------------------------
- * 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
- * <http://www.gnu.org/licenses/>.
- * ----------------------------------------------------------------------
- *
- */
-
-#ifndef _DSPWRAPPERS_H_
-#define _DSPWRAPPERS_H_
-
-#include <stdarg.h>
-
-extern void ChangeAlphaWindow(void);
-extern void ChangeBetaWindow(void);
-extern void ChangeHashDepth(void);
-extern void ChangeSearchDepth(void);
-extern void ChangeXwindow(void);
-extern void ClearScreen(void);
-extern void DoDebug(void);
-extern void DoTable(short table[NO_SQUARES]);
-extern void EditBoard(void);
-extern void ExitShogi(void);
-extern void GiveHint(void);
-extern void Initialize(void);
-extern void ShowNodeCnt(long NodeCnt);
-extern void OutputMove(void);
-extern void PollForInput(void);
-extern void SetContempt(void);
-extern void SearchStartStuff(short side);
-extern void SelectLevel(char *sx);
-extern void ShowCurrentMove(short pnt, short f, short t);
-extern void ShowDepth(char ch);
-extern void ShowGameType(void);
-extern void ShowLine(unsigned short *bstline);
-extern void ShowMessage(char *s);
-extern void AlwaysShowMessage(const char *format, ...);
-extern void Printf(const char *format, ...);
-extern void RequestInputString(char* buffer, unsigned bufsize);
-extern int  GetString(char* sx);
-extern void SetupBoard(void);
-extern void ShowPatternCount(short side, short n);
-extern void ShowPostnValue(short sq);
-extern void ShowPostnValues(void);
-extern void ShowPrompt(void);
-extern void ShowResponseTime(void);
-extern void ShowResults(short score, unsigned short *bstline, char ch);
-extern void ShowSidetoMove(void);
-extern void ShowStage(void);
-extern void TerminateSearch(int sig);
-extern void UpdateClocks(void);
-extern void UpdateDisplay(short f, short t, short redraw, short isspec);
-extern void help(void);
-
-#endif /* _DSPWRAPPERS_H_ */
index 569b997..6457e24 100644 (file)
@@ -32,9 +32,6 @@
 #include "gnushogi.h"
 #include "pattern.h"
 
-extern void
-ShowStage(void);
-
 /* Hash table for preventing multiple scoring of the same position */
 
 int EADD = 0;       /* number of writes to the cache table */
@@ -1262,13 +1259,12 @@ trapped(short sq)
 
 
 static int
-AttackedPieceValue(short sq, short side)
+AttackedPieceValue(short sq)
 {
-    short s, ds;
+    short s;
 
     s = 0;
 
-       ds = -fv1[HUNGP] * 2;
     hung[c1]++;
     shung[sq]++;
 
@@ -1426,7 +1422,7 @@ PawnValue(short sq, short side)
  */
 
 static inline int
-LanceValue(short sq, short side)
+LanceValue(short sq)
 {
     short s = 0, ds, ad;
 
@@ -1456,7 +1452,7 @@ LanceValue(short sq, short side)
  */
 
 static inline int
-KnightValue(short sq, short side)
+KnightValue(short sq)
 {
     short s = 0, ad;
     short ds, checked_trapped = false;
@@ -1493,7 +1489,7 @@ KnightValue(short sq, short side)
  */
 
 static inline int
-SilverValue(short sq, short side)
+SilverValue(short sq)
 {
     short s= 0, ds, ad;
 
@@ -1541,7 +1537,7 @@ SilverValue(short sq, short side)
  */
 
 static inline int
-GoldValue(short sq, short side)
+GoldValue(short sq)
 {
     short s = 0, ds, ad;
 
@@ -1583,7 +1579,7 @@ GoldValue(short sq, short side)
  */
 
 static inline int
-BishopValue(short sq, short side)
+BishopValue(short sq)
 {
     short s = 0, ds, ad;
 
@@ -1718,7 +1714,7 @@ RookValue(short sq, short side)
  */
 
 static inline int
-PPawnValue(short sq, short side)
+PPawnValue(short sq)
 {
     short s = 0, ds, ad;
 
@@ -1735,7 +1731,7 @@ PPawnValue(short sq, short side)
  */
 
 static inline int
-PLanceValue(short sq, short side)
+PLanceValue(short sq)
 {
     short s = 0, ds, ad;
 
@@ -1751,7 +1747,7 @@ PLanceValue(short sq, short side)
  */
 
 static inline int
-PKnightValue(short sq, short side)
+PKnightValue(short sq)
 {
     short s = 0, ds, ad;
 
@@ -1768,7 +1764,7 @@ PKnightValue(short sq, short side)
  */
 
 static inline int
-PSilverValue(short sq, short side)
+PSilverValue(short sq)
 {
     short s = 0, ds, ad;
 
@@ -1784,7 +1780,7 @@ PSilverValue(short sq, short side)
  */
 
 static inline int
-PBishopValue(short sq, short side)
+PBishopValue(short sq)
 {
     short s = 0, ds, ad;
 
@@ -1800,7 +1796,7 @@ PBishopValue(short sq, short side)
  */
 
 static inline int
-PRookValue(short sq, short side)
+PRookValue(short sq)
 {
     short s = 0, ds, ad;
 
@@ -1818,7 +1814,7 @@ PRookValue(short sq, short side)
  */
 
 static inline int
-KingValue(short sq, short side)
+KingValue(short sq)
 {
     short s = 0, ds;
 
@@ -1904,7 +1900,7 @@ PieceValue(short sq, short side)
         if (a1 == 0)
         {
             /* undefended piece */
-            s += AttackedPieceValue(sq, side);
+            s += AttackedPieceValue(sq);
         }
         else
         {
@@ -1915,7 +1911,7 @@ PieceValue(short sq, short side)
             if (attack_value < piece_value)
             {
                 /* attacked by a weaker piece */
-                s += AttackedPieceValue(sq, side) / 2;
+                s += AttackedPieceValue(sq) / 2;
             }
             else if (abs(attack_value - piece_value) < 10)
             {
@@ -1982,24 +1978,24 @@ PieceValue(short sq, short side)
 
 #ifndef MINISHOGI
     case lance:
-        s += LanceValue(sq, side);
+        s += LanceValue(sq);
         break;
 
     case knight:
-        s += KnightValue(sq, side);
+        s += KnightValue(sq);
         break;
 #endif
 
     case silver:
-        s += SilverValue(sq, side);
+        s += SilverValue(sq);
         break;
 
     case gold:
-        s += GoldValue(sq, side);
+        s += GoldValue(sq);
         break;
 
     case bishop:
-        s += BishopValue(sq, side);
+        s += BishopValue(sq);
         break;
 
     case rook:
@@ -2007,33 +2003,33 @@ PieceValue(short sq, short side)
         break;
 
     case king:
-        s += KingValue(sq, side);
+        s += KingValue(sq);
         break;
 
     case ppawn:
-        s += PPawnValue(sq, side);
+        s += PPawnValue(sq);
         break;
 
 #ifndef MINISHOGI
     case plance:
-        s += PLanceValue(sq, side);
+        s += PLanceValue(sq);
         break;
 
     case pknight:
-        s += PKnightValue(sq, side);
+        s += PKnightValue(sq);
         break;
 #endif
 
     case psilver:
-        s += PSilverValue(sq, side);
+        s += PSilverValue(sq);
         break;
 
     case pbishop:
-        s += PBishopValue(sq, side);
+        s += PBishopValue(sq);
         break;
 
     case prook:
-        s += PRookValue(sq, side);
+        s += PRookValue(sq);
         break;
     }
 
@@ -2138,7 +2134,7 @@ UpdatePatterns(short side, short GameCnt)
     }
 
     if (flag.post)
-        ShowPatternCount(side, n);
+        dsp->ShowPatternCount(side, n);
 
     if (os != END_OF_SEQUENCES)
         update_advance_bonus(side, os);
@@ -2530,8 +2526,8 @@ DetermineGameType(short side_to_move)
     }
     else
     {
-        ShowPatternCount(black, -1);
-        ShowPatternCount(white, -1);
+        dsp->ShowPatternCount(black, -1);
+        dsp->ShowPatternCount(white, -1);
     }
 }
 
@@ -2708,7 +2704,7 @@ DetermineStage(short side)
         stage = 0;
 
     if (flag.post)
-        ShowStage();
+        dsp->ShowStage();
 
     /* Determine stage dependant weights */
 
@@ -2744,6 +2740,7 @@ DetermineStage(short side)
 void
 UpdateWeights(short stage)
 {
+  /* FIXME: this was emptied between 1.1p02 ans 1.2p03, do we keep it ? */
 }
 
 
index 9034b65..d42c1d6 100644 (file)
@@ -245,12 +245,12 @@ gives_check_flag(unsigned short *flags, short side, short f, short t)
 
 
 inline static void
-Link(short side, short piece,
+Link(short side,
      short from, short to, unsigned short local_flag, short s)
 {
     if (*TrP == TREE)
     {
-        ShowMessage("TREE overflow\n");
+        dsp->ShowMessage("TREE overflow\n");
     }
     else
     {
@@ -340,8 +340,8 @@ PromotionPossible(short color, short f, short t, short p)
 }
 
 
-inline int
-NonPromotionPossible(short color, short f,
+static inline int
+NonPromotionPossible(short color,
                      short t, short p)
 {
     switch (p)
@@ -400,7 +400,7 @@ NonPromotionPossible(short color, short f,
 /* bonus for possible next moves */
 
 inline static short
-field_bonus(short ply, short side, short piece,
+field_bonus(short side, short piece,
             short f, short t, unsigned short *local_flag)
 {
     short s, u, ptyp;
@@ -620,7 +620,7 @@ LinkMove(short ply, short f,
     if (score_if_impossible < 0)
     {
         /* The move is flagged as illegal. */
-        Link(side, piece,
+        Link(side,
              f, t, local_flag, score_if_impossible);
 
         return;
@@ -729,7 +729,7 @@ LinkMove(short ply, short f,
             s -= 16 / Captured[side][silver];
 
 #if defined DROPBONUS
-        s += field_bonus(ply, side, piece, f, t, &local_flag);
+        s += field_bonus(side, piece, f, t, &local_flag);
 
         if (s == 10 && piece != pawn)
             local_flag |= questionable;
@@ -818,7 +818,7 @@ LinkMove(short ply, short f,
         else
         {
 #if defined FIELDBONUS
-            s += field_bonus(ply, side, piece, f, t, &local_flag);
+            s += field_bonus(side, piece, f, t, &local_flag);
 #endif
         }
     }
@@ -870,7 +870,7 @@ LinkMove(short ply, short f,
 
     if (try_link || GenerateAllMoves)
     {
-        Link(side, piece, f, t, local_flag,
+        Link(side, f, t, local_flag,
              s - ((SCORE_LIMIT + 1000) * 2));
     }
 
@@ -1040,7 +1040,7 @@ GenMoves(short ply, short sq, short side,
                 LinkMove(ply, sq, u, local_flag | promote, xside, true);
 
                 if ((possible
-                     = NonPromotionPossible(color[sq], sq, u, piece)))
+                     = NonPromotionPossible(color[sq], u, piece)))
                 {
                     LinkMove(ply, sq, u, local_flag, xside, possible);
                 }
@@ -1496,7 +1496,7 @@ CaptureList(short side, short ply,
 
                     if ((PP = PromotionPossible(color[sq], sq, u, piece)))
                     {
-                        Link(side, piece,
+                        Link(side,
                              sq, u, capture | promote,
                              (*value)[stage][board[u]]
 #if !defined SAVE_SVALUE
@@ -1507,7 +1507,7 @@ CaptureList(short side, short ply,
 
                     if (!PP || flag.tsume)
                     {
-                        Link(side, piece,
+                        Link(side,
                              sq, u, capture,
                              (*value)[stage][board[u]]
 #if !defined SAVE_SVALUE
index 677d22c..50cab61 100644 (file)
@@ -43,6 +43,8 @@
 #include "debug.h"
 #include "opts.h"          /* Various option-setting #defines.  */
 
+#include <stdarg.h>
+
 /*
  * Display options.
  */
@@ -57,8 +59,6 @@ typedef enum {
 extern display_t display_type;
 
 #define XSHOGI     (display_type == DISPLAY_X)
-#define NOT_CURSES ((display_type == DISPLAY_X) \
-  || (display_type == DISPLAY_RAW))
 
 
 /* Miscellaneous globals. */
@@ -914,10 +914,8 @@ extern void Unlock_data(void);     /* init.c */
 extern void Initialize_dist(void); /* init.c */
 extern void Initialize_eval(void); /* eval.c */
 extern void NewGame(void);
-extern int  parse(FILE * fd, unsigned short *mv,
-                  short side, char *opening);
 extern void GetOpenings(void);
-extern int  OpeningBook(unsigned short *hint, short side);
+extern int  OpeningBook(unsigned short *hint);
 
 typedef enum
 {
@@ -964,7 +962,6 @@ PutInTTable(short side,
             short score,
             short depth,
             short ply,
-            short alpha,
             short beta,
             unsigned short mv);
 
@@ -1124,6 +1121,55 @@ typedef enum
 extern int VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv);
 extern unsigned short TTage;
 
-#include "dspwrappers.h"   /* Display functions. */
+/* display driver framework */
+
+struct display
+{
+    void (*ChangeAlphaWindow)(void);
+    void (*ChangeBetaWindow)(void);
+    void (*ChangeHashDepth)(void);
+    void (*ChangeSearchDepth)(char *sx);
+    void (*ChangeXwindow)(void);
+    void (*ClearScreen)(void);
+    void (*DoDebug)(void);
+    void (*DoTable)(short table[NO_SQUARES]);
+    void (*EditBoard)(void);
+    void (*ExitShogi)(void);
+    void (*GiveHint)(void);
+    void (*Initialize)(void);
+    void (*ShowNodeCnt)(long NodeCnt);
+    void (*OutputMove)(void);
+    void (*PollForInput)(void);
+    void (*SetContempt)(void);
+    void (*SearchStartStuff)(short side);
+    void (*SelectLevel)(char *sx);
+    void (*ShowCurrentMove)(short pnt, short f, short t);
+    void (*ShowDepth)(char ch);
+    void (*ShowGameType)(void);
+    void (*ShowLine)(unsigned short *bstline);
+    void (*ShowMessage)(char *s);
+    void (*AlwaysShowMessage)(const char *format, ...);
+    void (*Printf)(const char *format, ...);
+    void (*doRequestInputString)(const char* fmt, char* buffer);
+    int  (*GetString)(char* sx);
+    void (*SetupBoard)(void);
+    void (*ShowPatternCount)(short side, short n);
+    void (*ShowPostnValue)(short sq);
+    void (*ShowPostnValues)(void);
+    void (*ShowPrompt)(void);
+    void (*ShowResponseTime)(void);
+    void (*ShowResults)(short score, unsigned short *bstline, char ch);
+    void (*ShowSidetoMove)(void);
+    void (*ShowStage)(void);
+    void (*TerminateSearch)(int sig);
+    void (*UpdateClocks)(void);
+    void (*UpdateDisplay)(short f, short t, short redraw, short isspec);
+    void (*help)(void);
+};
+
+extern struct display *dsp;
+
+extern struct display raw_display;
+extern struct display curses_display;
 
 #endif /* _GNUSHOGI_H_ */
index bd571ce..945f9e0 100644 (file)
@@ -119,7 +119,7 @@ Initialize_data(void)
 
         if (x >= 0)
         {
-            ShowMessage("datatype 'small_short' is unsigned; "
+            dsp->ShowMessage("datatype 'small_short' is unsigned; "
                         "check gnushogi.h\n");
             return 1;
         }
@@ -132,7 +132,7 @@ Initialize_data(void)
     {
         sprintf(buffer, "Cannot allocate %ld bytes for search tree",
                 (long)n);
-        ShowMessage(buffer);
+        dsp->ShowMessage(buffer);
         return 1;
     }
 
@@ -142,7 +142,7 @@ Initialize_data(void)
     if (!hashcode)
     {
         sprintf(buffer, "Cannot allocate %ld bytes for hashcode", (long)n);
-        ShowMessage(buffer);
+        dsp->ShowMessage(buffer);
         return 1;
     }
 
@@ -154,7 +154,7 @@ Initialize_data(void)
         sprintf(buffer,
                 "Cannot allocate %ld bytes for drop_hashcode",
                 (long)n);
-        ShowMessage(buffer);
+        dsp->ShowMessage(buffer);
         return 1;
     }
 
@@ -166,7 +166,7 @@ Initialize_data(void)
         sprintf(buffer,
                 "Cannot allocate %ld bytes for game record",
                 (long)n);
-        ShowMessage(buffer);
+        dsp->ShowMessage(buffer);
         return 1;
     }
 
@@ -183,7 +183,7 @@ Initialize_data(void)
             {
                 sprintf(buffer, "cannot allocate %ld space for nextdir %d",
                         (long)(n), i);
-                ShowMessage(buffer);
+                dsp->ShowMessage(buffer);
             }
 
             nextdir[i] = NULL;
@@ -198,7 +198,7 @@ Initialize_data(void)
             {
                 sprintf(buffer, "cannot allocate %ld space for nextpos %d",
                         (long)(n), i);
-                ShowMessage(buffer);
+                dsp->ShowMessage(buffer);
             }
 
             use_nextpos = false;
@@ -216,7 +216,7 @@ Initialize_data(void)
 
     if (!value)
     {
-        ShowMessage("cannot allocate value space");
+        dsp->ShowMessage("cannot allocate value space");
         return 1;
     }
 
@@ -225,7 +225,7 @@ Initialize_data(void)
 
     if (!fscore)
     {
-        ShowMessage("cannot allocate fscore space");
+        dsp->ShowMessage("cannot allocate fscore space");
         return 1;
     }
 
@@ -237,7 +237,7 @@ Initialize_data(void)
     {
         sprintf(buffer, "Cannot allocate %ld bytes for history table",
                 (long)sizeof_history);
-        ShowMessage(buffer);
+        dsp->ShowMessage(buffer);
         use_history = false;
     }
 #endif
@@ -253,7 +253,7 @@ Initialize_data(void)
         {
             sprintf(buffer, "Cannot allocate %ld bytes for cache table %ld",
                     (long)n, (long)i);
-            ShowMessage(buffer);
+            dsp->ShowMessage(buffer);
             use_etable = false;
         }
     }
@@ -303,7 +303,7 @@ Initialize_data(void)
     {
         sprintf(buffer, "Cannot allocate %ld bytes for transposition table",
                 (long)(2 * n));
-        ShowMessage(buffer);
+        dsp->ShowMessage(buffer);
         ttable[0] = ttable[1] = NULL;
     }
 #endif /* ttblsz */
@@ -314,7 +314,7 @@ Initialize_data(void)
 
     if (!distdata)
     {
-        ShowMessage("cannot allocate distdata space...");
+        dsp->ShowMessage("cannot allocate distdata space...");
         use_distdata = false;
     }
 #endif
index e6b495f..d86abc4 100644 (file)
@@ -591,7 +591,7 @@ NewGame(void)
     }
 
     ClearCaptured();
-    ClearScreen();
+    dsp->ClearScreen();
     InitializeStats();
 
 #ifdef HAVE_GETTIMEOFDAY
@@ -614,9 +614,9 @@ NewGame(void)
         if (TCflag)
             SetTimeControl();
         else if (MaxResponseTime == 0)
-            SelectLevel(sx);
+            dsp->SelectLevel(sx);
 
-        UpdateDisplay(0, 0, 1, 0);
+        dsp->UpdateDisplay(0, 0, 1, 0);
         GetOpenings();
         GetOpeningPatterns(&max_opening_sequence);
 
@@ -675,7 +675,7 @@ InitMain(void)
         barebones    = 0;
     }
 
-    Initialize();
+    dsp->Initialize();
     Initialize_dist();
     Initialize_eval();
 #if !defined SAVE_NEXTPOS
@@ -725,6 +725,6 @@ ExitMain(void)
 #endif /* HASHFILE */
 #endif /* ttblsz */
 
-    ExitShogi();
+    dsp->ExitShogi();
 }
 
index 2dd78b8..980d962 100644 (file)
@@ -80,17 +80,14 @@ main (int argc, char **argv)
                 binbookfile = NULL;
 #endif
             }
-
             break;
 
 #ifdef BINBOOK
         case 'B':
             argc--;
             argv++;
-
             if (argc > 0)
                 binbookfile = argv[0];
-
             break;
 #endif
 
@@ -98,7 +95,7 @@ main (int argc, char **argv)
         case 'C':
             /* Curses interface. */
             display_type = DISPLAY_CURSES;
-
+            dsp = &curses_display;
             break;
 #endif
 
@@ -107,17 +104,14 @@ main (int argc, char **argv)
             hash = ((argv[0][0] == '-') ? false : true);
             break;
 
-
         case 'l':
             argc--;
             argv++;
 
             if (argc > 0)
                 Lang = argv[0];
-
             break;
 
-
         case 'L':
             argc--;
             argv++;
@@ -126,34 +120,28 @@ main (int argc, char **argv)
                 strcpy(listfile, argv[0]);
             break;
 
-
         case 's':
             argc--;
             argv++;
 
             if (argc > 0)
                 strcpy(savefile, argv[0]);
-
             break;
 
-
         case 'P':
             argc--;
             argv++;
 
             if (argc > 0)
                 bookmaxply = atoi(argv[0]);
-
             break;
 
-
         case 'R':
             /* Raw text interface. */
             display_type = DISPLAY_RAW;
-
+            dsp = &raw_display;
             break;
 
-
         case 'S':
             argc--;
             argv++;
@@ -169,23 +157,18 @@ main (int argc, char **argv)
 
             if (argc > 0)
                 rehash = atoi(argv[0]);
-
             if (rehash > MAXrehash)
                 rehash = MAXrehash;
-
             break;
 
-
         case 'T':
             argc--;
             argv++;
 
             if (argc > 0)
                 ttblsize = atoi(argv[0]);
-
-            if ((ttblsize <= MINTTABLE))
+            if (ttblsize <= MINTTABLE)
                 ttblsize = (MINTTABLE) + 1;
-
             break;
 
 #ifdef HASHFILE
@@ -229,7 +212,6 @@ main (int argc, char **argv)
 
             return 0;
 
-
         case 't':   /* Create or test persistent transposition table. */
             hashfile = fopen(HASHFILE, RWA_ACC);
 
@@ -271,7 +253,7 @@ main (int argc, char **argv)
                     }
                 }
 
-                printf("The file contains %d entries out of max %d\n", nr[0], i);
+                printf("The file contains %d entries out of max %ld\n", nr[0], i);
 
                 for (j = 1; j < MAXDEPTH; j++)
                     printf("%d ", nr[j]);
@@ -281,7 +263,6 @@ main (int argc, char **argv)
 
             return 0;
 
-
 #endif /* HASHFILE */
 #endif /* ttblsz */
 
@@ -293,20 +274,17 @@ main (int argc, char **argv)
         case 'X':
             /* X interface. */
             display_type = DISPLAY_X;
-
+            dsp = &raw_display;
             break;
 
-
         case 'x':
             argc--;
             argv++;
 
             if (argc > 0)
                 xwin = argv[0];
-
             break;
 
-
         default:
             fputs("Usage: gnushogi [-a] [-t] [-c size] [-s savefile][-l listfile] [-x xwndw]\n", stderr);
             exit(1);
index 2a846e4..cf869e2 100644 (file)
@@ -40,11 +40,15 @@ static char *patternfile = PATTERNFILE;
 small_short pattern_data[MAX_PATTERN_DATA];
 
 /* minimal ShowMessage to avoid dependency on extraneous display code */
-void
-ShowMessage(char *s)
+static void
+Dummy_ShowMessage(char *s)
 {
     printf("%s\n", s);
 }
+static struct display dummydsp = {
+  .ShowMessage = Dummy_ShowMessage,
+};
+struct display *dsp = &dummydsp;
 
 #define is_digit(c) (((c) >= '0') && ((c) <= '9'))
 #define is_alpha(c) ((((c) >= 'a') && ((c) <= 'z')) \
@@ -220,7 +224,7 @@ ReadOpeningSequences (short *pindex)
             {
                 if (ScanPattern(s, pindex))
                 {
-                    ShowMessage("error in pattern sequence...");
+                    dsp->ShowMessage("error in pattern sequence...");
                     exit(1);
                 }
                 else
@@ -236,12 +240,12 @@ ReadOpeningSequences (short *pindex)
         sprintf(s,
                 "Pattern: %d bytes for %d sequences with %d patterns.\n",
                 *pindex, max_opening_sequence, max_pattern);
-        ShowMessage(s);
+        dsp->ShowMessage(s);
 
         fclose(fd);
     } else {
         sprintf(s, "no pattern file '%s'", patternfile);
-        ShowMessage(s);
+        dsp->ShowMessage(s);
     }
 }
 
index 8337d41..09d977a 100644 (file)
@@ -32,6 +32,7 @@
 #include <ctype.h>
 #include <signal.h>
 #include <stdarg.h>
+#include <stdio.h>
 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/file.h>
@@ -41,7 +42,6 @@
 #endif
 
 #include "gnushogi.h"
-#include "rawdsp.h"
 
 unsigned short MV[MAXDEPTH];
 int MSCORE;
@@ -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.
@@ -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);
 }
 
 
@@ -151,10 +162,17 @@ int
 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;
 }
 
@@ -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");
@@ -320,7 +356,7 @@ Raw_help(void)
            (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);
@@ -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 */
@@ -718,6 +743,7 @@ Raw_SelectLevel(char *sx)
     if (*p == 'f')
     {
         /* its a fischer clock game */
+        char *q;
         p++;
         TCminutes = (short)strtol(p, &q, 10);
         TCadd = (short)strtol(q, NULL, 10) *100;
@@ -727,6 +753,7 @@ Raw_SelectLevel(char *sx)
     else
     {
         /* regular game */
+        char *q;
         TCadd = 0;
         TCmoves = (short)strtol(p, &q, 10);
         TCminutes = (short)strtol(q, &q, 10);
@@ -767,10 +794,16 @@ Raw_SelectLevel(char *sx)
 
 
 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);
 }
 
@@ -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)
     {
@@ -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 */
@@ -970,3 +1002,47 @@ Raw_PollForInput(void)
         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,
+};
diff --git a/gnushogi/rawdsp.h b/gnushogi/rawdsp.h
deleted file mode 100644 (file)
index 699528e..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * FILE: rawdsp.h
- *
- *     Raw text interface 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
- * <http://www.gnu.org/licenses/>.
- * ----------------------------------------------------------------------
- *
- */
-
-#ifndef _RAWDSP_H_
-#define _RAWDSP_H_
-
-#include "gnushogi.h"
-
-/* The following are common to rawdsp.h and cursesdsp.h */
-
-void Raw_ChangeAlphaWindow(void);
-void Raw_ChangeBetaWindow(void);
-void Raw_ChangeHashDepth(void);
-void Raw_ChangeSearchDepth(void);
-void Raw_ChangeXwindow(void);
-void Raw_ClearScreen(void);
-void Raw_Die(int sig);
-void Raw_DoDebug(void);
-void Raw_DoTable(short table[NO_SQUARES]);
-void Raw_EditBoard(void);
-void Raw_ExitShogi(void);
-void Raw_GiveHint(void);
-void Raw_Initialize(void);
-void Raw_ShowNodeCnt(long NodeCnt);
-void Raw_OutputMove(void);
-void Raw_PollForInput(void);
-void Raw_SearchStartStuff(short side);
-void Raw_SelectLevel(char *sx);
-void Raw_SetContempt(void);
-void Raw_ShowCurrentMove(short pnt, short f, short t);
-void Raw_ShowDepth(char ch);
-void Raw_ShowGameType(void);
-void Raw_ShowLine(unsigned short *bstline);
-void Raw_ShowMessage(char *s);
-void Raw_AlwaysShowMessage(const char *format, va_list ap);
-void Raw_Printf(const char *format, va_list ap);
-void Raw_doRequestInputString(const char* fmt, char* buffer);
-int  Raw_GetString(char* sx);
-void Raw_SetupBoard(void);
-void Raw_ShowPatternCount(short side, short n);
-void Raw_ShowPostnValue(short sq);
-void Raw_ShowPostnValues(void);
-void Raw_ShowPrompt(void);
-void Raw_ShowResponseTime(void);
-void Raw_ShowResults(short score, unsigned short *bstline, char ch);
-void Raw_ShowSidetoMove(void);
-void Raw_ShowStage(void);
-void Raw_TerminateSearch(int sig);
-void Raw_UpdateClocks(void);
-void Raw_UpdateDisplay(short f, short t, short redraw, short isspec);
-void Raw_help(void);
-
-#endif /* _RAWDSP_H_ */
-
index 060d958..4b967d0 100644 (file)
@@ -180,7 +180,7 @@ SelectMove(short side, SelectMove_mode iop)
 #ifdef QUIETBACKGROUND
     if (!background)
 #endif /* QUIETBACKGROUND */
-        ShowResponseTime();
+        dsp->ShowResponseTime();
 
     ExtraTime = 0;
 
@@ -189,12 +189,12 @@ SelectMove(short side, SelectMove_mode iop)
 #ifdef QUIETBACKGROUND
     if (!background)
 #endif /* QUIETBACKGROUND */
-        ShowSidetoMove();
+        dsp->ShowSidetoMove();
 
 #ifdef QUIETBACKGROUND
     if (!background)
 #endif /* QUIETBACKGROUND */
-        SearchStartStuff(side);
+        dsp->SearchStartStuff(side);
 
 #ifdef HISTORY
     array_zero(history, sizeof_history);
@@ -258,7 +258,7 @@ SelectMove(short side, SelectMove_mode iop)
 
     if (flag.regularstart && Book)
     {
-        flag.timeout = bookflag = OpeningBook(&hint, side);
+        flag.timeout = bookflag = OpeningBook(&hint);
 
         if (TCflag)
             ResponseTime += ResponseTime;
@@ -304,7 +304,7 @@ SelectMove(short side, SelectMove_mode iop)
 # ifdef QUIETBACKGROUND
         if (!background)
 #endif /* QUIETBACKGROUND */
-            ShowDepth(' ');
+            dsp->ShowDepth(' ');
 
         /* search at this level returns score of PV */
         score = search(side, 1, Sdepth, alpha, beta, PrVar, &rpt);
@@ -320,7 +320,7 @@ SelectMove(short side, SelectMove_mode iop)
 #ifdef QUIETBACKGROUND
             if (!background)
 #endif /* QUIETBACKGROUND */
-                ShowDepth('-');
+                dsp->ShowDepth('-');
 
             if (TCflag && TCcount < MAXTCCOUNTR)
             {
@@ -342,7 +342,7 @@ SelectMove(short side, SelectMove_mode iop)
 #ifdef QUIETBACKGROUND
             if (!background)
 #endif /* QUIETBACKGROUND */
-                ShowDepth('+');
+                dsp->ShowDepth('+');
 
             score = search(side, 1, Sdepth, -(SCORE_LIMIT + 999),
                            (SCORE_LIMIT + 999), PrVar, &rpt);
@@ -395,7 +395,7 @@ SelectMove(short side, SelectMove_mode iop)
 #ifdef QUIETBACKGROUND
         if (!background)
 #endif /* QUIETBACKGROUND */
-            ShowResults(score, PrVar, '.');
+            dsp->ShowResults(score, PrVar, '.');
     }
 
     /********************** end of main loop ***************************/
@@ -452,7 +452,7 @@ SelectMove(short side, SelectMove_mode iop)
         ElapsedTime(COMPUTE_AND_INIT_MODE);
 
     /* update time control info */
-    OutputMove();
+    dsp->OutputMove();
 
     /* if mate set flag */
     if ((score == -(SCORE_LIMIT + 999) || score == (SCORE_LIMIT + 998)))
@@ -580,7 +580,7 @@ search(short side,
 #ifdef QUIETBACKGROUND
             if (!background)
 #endif
-                ShowResponseTime();
+                dsp->ShowResponseTime();
         }
         else if (!TCflag && flag.musttimeout && Sdepth > MINDEPTH)
         {
@@ -710,7 +710,7 @@ search(short side,
                  && (ProbeFTable(side, depth, ply, &alpha, &beta, &score)
                      == true))
         {
-            PutInTTable(side, score, depth, ply, alpha, beta, PV);
+            PutInTTable(side, score, depth, ply, beta, PV);
             bstline[ply] = PV;
             bstline[ply + 1] = 0;
 
@@ -861,7 +861,6 @@ search(short side,
         nxtline[ply + 1] = 0;
 
         /* if at top level */
-#if !defined NOPOST
         if (ply == 1)
         {
 /* at the top update search status */
@@ -870,10 +869,9 @@ search(short side,
 #ifdef QUIETBACKGROUND
                 if (!background)
 #endif /* QUIETBACKGROUND */
-                    ShowCurrentMove(pnt, node->f, node->t);
+                    dsp->ShowCurrentMove(pnt, node->f, node->t);
             }
         }
-#endif
 
         if (!(node->flags & exact))
         {
@@ -984,15 +982,15 @@ search(short side,
                     {
                         if (best > beta)
                         {
-                            ShowResults(best, bstline, '+');
+                            dsp->ShowResults(best, bstline, '+');
                         }
                         else if (best < alpha)
                         {
-                            ShowResults(best, bstline, '-');
+                            dsp->ShowResults(best, bstline, '-');
                         }
                         else
                         {
-                            ShowResults (best, bstline, '&');
+                            dsp->ShowResults(best, bstline, '&');
                         }
                     }
 #ifdef QUIETBACKGROUND
@@ -1025,13 +1023,13 @@ search(short side,
     {
 #  ifdef HASHFILE /* MCV: warning: this confuses the formatter. */
         if (use_ttable
-            && PutInTTable(side, best, depth, ply, alpha, beta, mv)
+            && PutInTTable(side, best, depth, ply, beta, mv)
             && hashfile
             && (depth > HashDepth)
             && (GameCnt < HashMoveLimit))
 #  else
         if (use_ttable
-            && PutInTTable(side, best, depth, ply, alpha, beta, mv))
+            && PutInTTable(side, best, depth, ply, beta, mv))
 #  endif
         {
             PutInFTable(side, best, depth, ply,
@@ -1116,8 +1114,8 @@ UpdatePieceList(short side, short sq, UpdatePieceList_mode iop)
 
 /* Make or Unmake drop move. */
 
-void
-drop(short side, short piece, short f, short t, short iop)
+static void
+drop(short side, short piece, short t, short iop)
 {
     if (iop == 1)
     {
@@ -1285,7 +1283,7 @@ MakeMove(short side,
         *tempst = svalue[t];
 #endif
 
-        (void)drop(side, g->fpiece, f, t, 1);
+        (void)drop(side, g->fpiece, t, 1);
     }
     else
     {
@@ -1413,7 +1411,7 @@ UnmakeMove(short side,
 
     if (node->flags & dropmask)
     {
-        (void)drop(side, (node->flags & pmask), f, t, 2);
+        (void)drop(side, (node->flags & pmask), t, 2);
 
 #if !defined SAVE_SVALUE
         svalue[t] = *tempst;
index fd5f4a5..f8f15dc 100644 (file)
@@ -345,7 +345,7 @@ CheckForTimeout(int score, int globalscore, int Jscore, int zwndw)
 #endif
 
     if (flag.timeout)
-        ShowMessage("timeout");
+        dsp->ShowMessage("timeout");
 }
 
 
@@ -365,7 +365,7 @@ ElapsedTime(ElapsedTime_mode iop)
     struct timeval tv;
 #endif
 
-    PollForInput();
+    dsp->PollForInput();
 
 #ifdef HAVE_GETTIMEOFDAY
     gettimeofday(&tv, NULL);
@@ -410,6 +410,6 @@ ElapsedTime(ElapsedTime_mode iop)
 #ifdef QUIETBACKGROUND
         if (!background)
 #endif
-            UpdateClocks();
+            dsp->UpdateClocks();
     }
 }
index af57cae..3968ecf 100644 (file)
@@ -35,9 +35,9 @@ unsigned int TTadd = 0;
 short recycle;
 short ISZERO = 1;
 
-
+#if 0
 int
-parse(FILE * fd, unsigned short *mv, short side, char *opening)
+parse(FILE * fd, unsigned short *mv, char *opening)
 {
     int c, i, r1, r2, c1, c2;
     char s[128];
@@ -99,7 +99,7 @@ parse(FILE * fd, unsigned short *mv, short side, char *opening)
 
     return 1;
 }
-
+#endif
 
 /*
  * The field of a hashtable is computed as follows:
@@ -226,7 +226,6 @@ PutInTTable(short side,
             short score,
             short depth,
             short ply,
-            short alpha,
             short beta,
             unsigned short mv)
 {