Generate patterns.inc at build time.
[gnushogi.git] / gnushogi / dspwrappers.c
1 /*
2  * FILE: dspwrappers.c
3  *
4  *     Wrapper functions which call analogous functions in rawdsp.c
5  *     or cursesdsp.c depending on the interface.
6  *
7  * ----------------------------------------------------------------------
8  * Copyright (c) 1993, 1994, 1995 Matthias Mutz
9  * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
10  *
11  * GNU SHOGI is based on GNU CHESS
12  *
13  * Copyright (c) 1988, 1989, 1990 John Stanback
14  * Copyright (c) 1992 Free Software Foundation
15  *
16  * This file is part of GNU SHOGI.
17  *
18  * GNU Shogi is free software; you can redistribute it and/or modify it
19  * under the terms of the GNU General Public License as published by the
20  * Free Software Foundation; either version 3 of the License,
21  * or (at your option) any later version.
22  *
23  * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
24  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
25  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26  * for more details.
27  *
28  * You should have received a copy of the GNU General Public License along
29  * with GNU Shogi; see the file COPYING. If not, see
30  * <http://www.gnu.org/licenses/>.
31  * ----------------------------------------------------------------------
32  *
33  */
34
35 #include "gnushogi.h"
36 #include "dspwrappers.h"
37 #include "rawdsp.h"
38 #include "cursesdsp.h"
39
40 #include <stdio.h>
41
42 #define CASE_DSP_RAW(func,args) \
43   case DISPLAY_RAW:             \
44   case DISPLAY_X:               \
45     func args;                  \
46     break
47
48 #ifdef HAVE_LIBCURSES
49 #define CASE_DSP_CURSES(func,args) \
50   case DISPLAY_CURSES:             \
51     func args;                     \
52     break;
53 #else
54 #define CASE_DSP_CURSES(func,args)
55 #endif
56
57 #define DISPLAY_FUNC(func,argsdecl,args)        \
58   void func argsdecl                            \
59   {                                             \
60     switch (display_type) {                     \
61       CASE_DSP_RAW(Raw_ ## func, args);         \
62       CASE_DSP_CURSES(Curses_ ## func, args);   \
63     }                                           \
64   }
65 #define DISPLAY_VOIDFUNC(func)                  \
66   DISPLAY_FUNC(func,(void),())
67
68 #define DISPLAY_STDARGFUNC(func,argsdecl,last,args)     \
69   void func argsdecl                                    \
70   {                                                     \
71     va_list ap;                                         \
72     va_start(ap, last);                                 \
73     switch (display_type) {                             \
74       CASE_DSP_RAW(Raw_ ## func, args);                 \
75       CASE_DSP_CURSES(Curses_ ## func, args);           \
76     }                                                   \
77     va_end(ap);                                         \
78   }
79
80 DISPLAY_VOIDFUNC(ChangeAlphaWindow)
81 DISPLAY_VOIDFUNC(ChangeBetaWindow)
82 DISPLAY_VOIDFUNC(ChangeHashDepth)
83 DISPLAY_VOIDFUNC(ChangeSearchDepth)
84 DISPLAY_VOIDFUNC(ChangeXwindow)
85 DISPLAY_VOIDFUNC(ClearScreen)
86 DISPLAY_VOIDFUNC(DoDebug)
87 DISPLAY_FUNC(DoTable, (short table[NO_SQUARES]), (table))
88 DISPLAY_VOIDFUNC(EditBoard)
89 DISPLAY_VOIDFUNC(ExitShogi)
90 DISPLAY_VOIDFUNC(GiveHint)
91 DISPLAY_VOIDFUNC(Initialize)
92 DISPLAY_FUNC(ShowNodeCnt, (long NodeCnt), (NodeCnt))
93 DISPLAY_VOIDFUNC(OutputMove)
94 DISPLAY_VOIDFUNC(PollForInput)
95 DISPLAY_VOIDFUNC(SetContempt)
96 DISPLAY_FUNC(SearchStartStuff, (short side), (side))
97 DISPLAY_FUNC(SelectLevel, (char *sx), (sx))
98 DISPLAY_VOIDFUNC(SetupBoard)
99 DISPLAY_FUNC(ShowCurrentMove, (short pnt, short f, short t), (pnt, f, t))
100 DISPLAY_FUNC(ShowDepth, (char ch), (ch))
101 DISPLAY_VOIDFUNC(ShowGameType)
102 DISPLAY_FUNC(ShowLine, (unsigned short *bstline), (bstline))
103 DISPLAY_FUNC(ShowMessage, (char *s), (s))
104 DISPLAY_STDARGFUNC(AlwaysShowMessage, (const char *format, ...), format, (format, ap))
105 DISPLAY_STDARGFUNC(Printf, (const char *format, ...), format, (format, ap))
106 DISPLAY_FUNC(ShowPatternCount, (short side, short n), (side, n))
107 DISPLAY_FUNC(ShowPostnValue, (short sq), (sq))
108 DISPLAY_VOIDFUNC(ShowPostnValues)
109 DISPLAY_VOIDFUNC(ShowPrompt)
110 DISPLAY_VOIDFUNC(ShowResponseTime)
111 DISPLAY_FUNC(ShowResults, (short score, unsigned short *bstline, char ch), (score, bstline, ch))
112 DISPLAY_VOIDFUNC(ShowSidetoMove)
113 DISPLAY_VOIDFUNC(ShowStage)
114 DISPLAY_FUNC(TerminateSearch, (int sig), (sig))
115 DISPLAY_VOIDFUNC(UpdateClocks)
116 DISPLAY_FUNC(UpdateDisplay, (short f, short t, short redraw, short isspec), (f, t, redraw, isspec))
117 DISPLAY_VOIDFUNC(help)
118
119 DISPLAY_FUNC(doRequestInputString, (const char* fmt, char* buffer), (fmt, buffer))
120 void RequestInputString(char* buffer, unsigned bufsize)
121 {
122     static char fmt[10];
123     int ret = snprintf(fmt, sizeof(fmt), "%%%us", bufsize);
124     if (ret >= sizeof(fmt)) {
125         fprintf(stderr,
126                 "Insufficient format-buffer size in %s for bufsize=%u\n",
127                 __FUNCTION__, bufsize);
128         exit(1);
129     }
130     doRequestInputString(fmt, buffer);
131 }
132
133 /*********/
134
135 #define CASE_DSPFUNC_RAW(func,args) \
136   case DISPLAY_RAW:                 \
137   case DISPLAY_X:                   \
138     return (func args);             \
139     break
140
141 #ifdef HAVE_LIBCURSES
142 #define CASE_DSPFUNC_CURSES(func,args) \
143   case DISPLAY_CURSES:                 \
144     return (func args);                \
145     break;
146 #else
147 #define CASE_DSPFUNC_CURSES(func,args)
148 #endif
149
150 #define DISPLAY_INTFUNC(func,argsdecl,args)         \
151   int func argsdecl                                 \
152   {                                                 \
153     switch (display_type) {                         \
154       CASE_DSPFUNC_RAW(Raw_ ## func, args);         \
155       CASE_DSPFUNC_CURSES(Curses_ ## func, args);   \
156     }                                               \
157     assert(0);                                      \
158   }
159
160 DISPLAY_INTFUNC(GetString, (char* sx), (sx))