Fix u64 format for cygwin
[xboard.git] / backend.h
1 /*
2  * backend.h -- Interface exported by XBoard back end
3  *
4  * Copyright 1991 by Digital Equipment Corporation, Maynard,
5  * Massachusetts.
6  *
7  * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,
8  * 2007, 2008, 2009 Free Software Foundation, Inc.
9  *
10  * Enhancements Copyright 2005 Alessandro Scotti
11  *
12  * The following terms apply to Digital Equipment Corporation's copyright
13  * interest in XBoard:
14  * ------------------------------------------------------------------------
15  * All Rights Reserved
16  *
17  * Permission to use, copy, modify, and distribute this software and its
18  * documentation for any purpose and without fee is hereby granted,
19  * provided that the above copyright notice appear in all copies and that
20  * both that copyright notice and this permission notice appear in
21  * supporting documentation, and that the name of Digital not be
22  * used in advertising or publicity pertaining to distribution of the
23  * software without specific, written prior permission.
24  *
25  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
26  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
27  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
28  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
29  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
30  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
31  * SOFTWARE.
32  * ------------------------------------------------------------------------
33  *
34  * The following terms apply to the enhanced version of XBoard
35  * distributed by the Free Software Foundation:
36  * ------------------------------------------------------------------------
37  *
38  * GNU XBoard is free software: you can redistribute it and/or modify
39  * it under the terms of the GNU General Public License as published by
40  * the Free Software Foundation, either version 3 of the License, or (at
41  * your option) any later version.
42  *
43  * GNU XBoard is distributed in the hope that it will be useful, but
44  * WITHOUT ANY WARRANTY; without even the implied warranty of
45  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
46  * General Public License for more details.
47  *
48  * You should have received a copy of the GNU General Public License
49  * along with this program. If not, see http://www.gnu.org/licenses/.  *
50  *
51  *------------------------------------------------------------------------
52  ** See the file ChangeLog for a revision history.  */
53
54 #ifndef _BACKEND
55 #define _BACKEND
56
57 /* unsigned int 64 for engine nodes work and display */
58 #ifdef WIN32
59        /* I don't know the name for this type of other compiler
60         * If it not work, just modify here
61         * This is for MS Visual Studio
62         */
63        #ifdef _MSC_VER
64                #define u64 unsigned __int64
65                #define s64 signed __int64
66                #define u64Display "%I64u"
67                #define s64Display "%I64d"
68                #define u64Const(c) (c ## UI64)
69                #define s64Const(c) (c ## I64)
70        #else
71                /* place holder
72                 * or dummy types for other compiler
73                 * [HGM] seems that -mno-cygwin comple needs %I64?
74                 */
75                #define u64 unsigned long long
76                #define s64 signed long long
77                #ifdef USE_I64
78                   #define u64Display "%I64u"
79                   #define s64Display "%I64d"
80                #else
81                   #define u64Display "%llu"
82                   #define s64Display "%lld"
83                #endif
84                #define u64Const(c) (c ## ULL)
85                #define s64Const(c) (c ## LL)
86        #endif
87 #else
88        /* GNU gcc */
89        #define u64 unsigned long long
90        #define s64 signed long long
91        #define u64Display "%llu"
92        #define s64Display "%lld"
93        #define u64Const(c) (c ## ull)
94        #define s64Const(c) (c ## ll)
95 #endif
96
97 #include "lists.h"
98 #include "frontend.h"
99
100 extern int gotPremove;
101 extern GameMode gameMode;
102 extern int pausing, cmailMsgLoaded, flipView, mute;
103 extern char white_holding[], black_holding[];
104 extern int currentMove, backwardMostMove, forwardMostMove;
105 extern int blackPlaysFirst;
106 extern FILE *debugFP;
107 extern char* programVersion;
108 extern ProcRef firstProgramPR, secondProgramPR;
109 extern Board boards[];
110 extern char marker[BOARD_RANKS][BOARD_FILES];
111
112 char *CmailMsg P((void));
113 /* Tord: Added the useFEN960 parameter in PositionToFEN() below */
114 char *PositionToFEN P((int move, char* useFEN960));
115 void AlphaRank P((char *s, int n)); /* [HGM] Shogi move preprocessor */
116 void EditPositionPasteFEN P((char *fen));
117 void TimeDelay P((long ms));
118 void SendMultiLineToICS P(( char *text ));
119 void AnalysisPeriodicEvent P((int force));
120 void SetWhiteToPlayEvent P((void));
121 void SetBlackToPlayEvent P((void));
122 void InitBackEnd1 P((void));
123 void InitBackEnd2 P((void));
124 int HasPromotionChoice P((int fromX, int fromY, int toX, int toY, char *choice));
125 int InPalace P((int row, int column));
126 int PieceForSquare P((int x, int y));
127 int OKToStartUserMove P((int x, int y));
128 void Reset P((int redraw, int init));
129 void ResetGameEvent P((void));
130 Boolean HasPattern P(( const char * text, const char * pattern ));\r
131 Boolean SearchPattern P(( const char * text, const char * pattern ));\r
132 int LoadGame P((FILE *f, int n, char *title, int useList));
133 int LoadGameFromFile P((char *filename, int n, char *title, int useList));
134 int CmailLoadGame P((FILE *f, int n, char *title, int useList));
135 int ReloadGame P((int offset));
136 int SaveGame P((FILE *f, int dummy, char *dummy2));
137 int SaveGameToFile P((char *filename, int append));
138 int LoadPosition P((FILE *f, int n, char *title));
139 int ReloadPosition P((int offset));
140 int SavePosition P((FILE *f, int dummy, char *dummy2));
141 void EditPositionEvent P((void));
142 void FlipViewEvent P((void));
143 void MachineWhiteEvent P((void));
144 void MachineBlackEvent P((void));
145 void TwoMachinesEvent P((void));
146 void EditGameEvent P((void));
147 void TrainingEvent P((void));
148 void IcsClientEvent P((void));
149 void ForwardEvent P((void));
150 void BackwardEvent P((void));
151 void ToEndEvent P((void));
152 void ToStartEvent P((void));
153 void ToNrEvent P((int to));
154 void RevertEvent P((void));
155 void RetractMoveEvent P((void));
156 void MoveNowEvent P((void));
157 void TruncateGameEvent P((void));
158 void PauseEvent P((void));
159 void CallFlagEvent P((void));
160 void AcceptEvent P((void));
161 void DeclineEvent P((void));
162 void RematchEvent P((void));
163 void DrawEvent P((void));
164 void AbortEvent P((void));
165 void AdjournEvent P((void));
166 void ResignEvent P((void));
167 void UserAdjudicationEvent P((int result));
168 void StopObservingEvent P((void));
169 void StopExaminingEvent P((void));
170 void PonderNextMoveEvent P((int newState));
171 void NewSettingeEvent P((int option, char *command, int value));
172 void ShowThinkingEvent P(());
173 void PeriodicUpdatesEvent P((int newState));
174 void HintEvent P((void));
175 void BookEvent P((void));
176 void AboutGameEvent P((void));
177 void ExitEvent P((int status));
178 char *DefaultFileName P((char *));
179 ChessMove UserMoveTest P((int fromX, int fromY, int toX, int toY, int promoChar, Boolean captureOwn));
180 void UserMoveEvent P((int fromX, int fromY, int toX, int toY, int promoChar));
181 void DecrementClocks P((void));
182 char *TimeString P((long millisec));
183 void AutoPlayGameLoop P((void));
184 void AdjustClock P((Boolean which, int dir));
185 void DisplayBothClocks P((void));
186 void EditPositionMenuEvent P((ChessSquare selection, int x, int y));
187 void DropMenuEvent P((ChessSquare selection, int x, int y));
188 int ParseTimeControl P((char *tc, int ti, int mps));
189 void ProcessICSInitScript P((FILE * f));
190 void EditCommentEvent P((void));
191 void ReplaceComment P((int index, char *text));
192 int ReplaceTags P((char *tags, GameInfo *gi));/* returns nonzero on error */
193 void AppendComment P((int index, char *text, Boolean addBraces));
194 void ReloadCmailMsgEvent P((int unregister));
195 void MailMoveEvent P((void));
196 void EditTagsEvent P((void));
197 void GetMoveListEvent P((void));
198 void ExitAnalyzeMode P((void));
199 void AnalyzeModeEvent P((void));
200 void AnalyzeFileEvent P((void));
201 void InitPosition P((int redraw));
202 void NewSettingEvent P((int option, char *command, int value));
203 void DoEcho P((void));
204 void DontEcho P((void));
205 void TidyProgramName P((char *prog, char *host, char *buf));
206 void AskQuestionEvent P((char *title, char *question,
207                          char *replyPrefix, char *which));
208 Boolean ParseOneMove P((char *move, int moveNum,
209                         ChessMove *moveType, int *fromX, int *fromY,
210                         int *toX, int *toY, char *promoChar));
211 char *VariantName P((VariantClass v));
212 VariantClass StringToVariant P((char *e));
213 double u64ToDouble P((u64 value));
214 void OutputChatMessage P((int partner, char *mess));
215 void EditPositionDone P((Boolean fakeRights));
216 Boolean GetArgValue P((char *name));
217 Boolean LoadPV P((int x, int y));
218 Boolean LoadMultiPV P((int x, int y, char *buf, int index, int *start, int *end));
219 void UnLoadPV P(());
220 void MovePV P((int x, int y, int h));
221
222 char *StrStr P((char *string, char *match));
223 char *StrCaseStr P((char *string, char *match));
224 char *StrSave P((char *s));
225 char *StrSavePtr P((char *s, char **savePtr));
226 char *SavePart P((char *));
227
228 #ifndef _amigados
229 int StrCaseCmp P((char *s1, char *s2));
230 int ToLower P((int c));
231 int ToUpper P((int c));
232 #else
233 #define StrCaseCmp Stricmp  /*  Use utility.library functions   */
234 #include <proto/utility.h>
235 #endif
236
237 extern GameInfo gameInfo;
238
239 /* ICS vars used with backend.c and zippy.c */
240 #define ICS_GENERIC 0
241 #define ICS_ICC 1
242 #define ICS_FICS 2
243 #define ICS_CHESSNET 3 /* not really supported */
244 int ics_type;
245
246  
247
248 /* pgntags.c prototypes
249  */
250 char *PGNTags P((GameInfo *));
251 void PrintPGNTags P((FILE *f, GameInfo *));
252 int ParsePGNTag P((char *, GameInfo *));
253 char *PGNResult P((ChessMove result));
254
255
256 /* gamelist.c prototypes
257  */
258 /* A game node in the double linked list of games.
259  */
260 typedef struct _ListGame {
261     ListNode node;
262     int number;
263     unsigned long offset;   /*  Byte offset of game within file.     */
264     GameInfo gameInfo;      /*  Note that some entries may be NULL. */
265 } ListGame;
266  
267 extern List gameList;
268 void ClearGameInfo P((GameInfo *));
269 int GameListBuild P((FILE *));
270 void GameListInitGameInfo P((GameInfo *));
271 char *GameListLine P((int, GameInfo *));
272 char * GameListLineFull P(( int, GameInfo *));
273 void GLT_TagsToList P(( char * tags ));
274 void GLT_ParseList P((void));
275
276 extern char* StripHighlight P((char *));  /* returns static data */
277 extern char* StripHighlightAndTitle P((char *));  /* returns static data */
278 extern void ics_update_width P((int new_width));
279 extern Boolean set_cont_sequence P((char *new_seq));
280 extern int wrap P((char *dest, char *src, int count, int width, int *lp));
281
282 typedef enum { CheckBox, ComboBox, TextBox, Button, Spin, ResetButton,
283                    SaveButton, FileName, PathName, Slider, Message } Control;
284
285 typedef struct _OPT {   // [HGM] options: descriptor of UCI-style option
286     int value;          // current setting, starts as default
287     int min;
288     int max;
289     void *handle;       // for use by front end
290     char *textValue;    // points to beginning of text value in name field
291     char **choice;      // points to array of combo choices in cps->combo
292     Control type;
293     char name[MSG_SIZ]; // holds both option name and text value
294 } Option;
295
296 typedef struct _CPS {
297     char *which;
298     int maybeThinking;
299     ProcRef pr;
300     InputSourceRef isr;
301     char *twoMachinesColor; /* "white\n" or "black\n" */
302     char *program;
303     char *host;
304     char *dir;
305     struct _CPS *other;
306     char *initString;
307     char *computerString;
308     int sendTime; /* 0=don't, 1=do, 2=test */
309     int sendDrawOffers;
310     int useSigint;
311     int useSigterm;
312     int offeredDraw; /* countdown */
313     int reuse;
314     int useSetboard; /* 0=use "edit"; 1=use "setboard" */
315     int useSAN;      /* 0=use coordinate notation; 1=use SAN */
316     int usePing;     /* 0=not OK to use ping; 1=OK */
317     int lastPing;
318     int lastPong;
319     int usePlayother;/* 0=not OK to use playother; 1=OK */
320     int useColors;   /* 0=avoid obsolete white/black commands; 1=use them */
321     int useUsermove; /* 0=just send move; 1=send "usermove move" */
322     int sendICS;     /* 0=don't use "ics" command; 1=do */
323     int sendName;    /* 0=don't use "name" command; 1=do */
324     int sdKludge;    /* 0=use "sd DEPTH" command; 1=use "depth\nDEPTH" */
325     int stKludge;    /* 0=use "st TIME" command; 1=use "level 1 TIME" */
326     char tidy[MSG_SIZ];
327     int matchWins;
328     char variants[MSG_SIZ];
329     int analysisSupport;
330     int analyzing;
331     int protocolVersion;
332     int initDone;
333
334     /* Added by Tord: */
335     int useFEN960;   /* 0=use "KQkq" style FENs, 1=use "HAha" style FENs */
336     int useOOCastle; /* 0="O-O" notation for castling, 1="king capture rook" notation */
337     /* End of additions by Tord */
338
339     int scoreIsAbsolute; /* [AS] 0=don't know (standard), 1=score is always from white side */
340     int isUCI;           /* [AS] 0=no (Winboard), 1=UCI (requires Polyglot) */
341     int hasOwnBookUCI;   /* [AS] 0=use GUI or Polyglot book, 1=has own book */
342
343     /* [HGM] time odds */
344     float timeOdds; /* factor through which we divide time for this engine  */
345     int debug;      /* [HGM] ignore engine debug lines starting with '#'    */
346     int maxNrOfSessions; /* [HGM] secondary TC: max args in 'level' command */
347     int accumulateTC; /* [HGM] secondary TC: how to handle extra sessions   */
348     int nps;          /* [HGM] nps: factor for node count to replace time   */
349     int supportsNPS;
350     int alphaRank;    /* [HGM] shogi: engine uses shogi-type coordinates    */
351     int maxCores;     /* [HGM] SMP: engine understands cores command        */
352     int memSize;      /* [HGM] memsize: engine understands memory command   */
353     char egtFormats[MSG_SIZ];     /* [HGM] EGT: supported tablebase formats */
354     int bookSuspend;  /* [HGM] book: go was deferred because of book hit    */
355     int nrOptions;    /* [HGM] options: remembered option="..." features    */
356 #define MAX_OPTIONS 200
357     Option option[MAX_OPTIONS];
358     int comboCnt;
359     char *comboList[20*MAX_OPTIONS];
360     char *optionSettings;
361     void *programLogo; /* [HGM] logo: bitmap of the logo                    */
362     char *fenOverride; /* [HGM} FRC: force FEN casling & ep fields by hand  */
363     char userError;    /* [HGM] crash: flag to suppress fatal-error messages*/\r
364 } ChessProgramState;
365
366 extern ChessProgramState first, second;
367
368 /* Search stats from chessprogram */
369 typedef struct {
370   char movelist[2*MSG_SIZ]; /* Last PV we were sent */
371   int depth;              /* Current search depth */
372   int nr_moves;           /* Total nr of root moves */
373   int moves_left;         /* Moves remaining to be searched */
374   char move_name[MOVE_LEN];  /* Current move being searched, if provided */
375   u64 nodes;    /* # of nodes searched */
376   int time;               /* Search time (centiseconds) */
377   int score;              /* Score (centipawns) */
378   int got_only_move;      /* If last msg was "(only move)" */
379   int got_fail;           /* 0 - nothing, 1 - got "--", 2 - got "++" */
380   int ok_to_send;         /* handshaking between send & recv */
381   int line_is_book;       /* 1 if movelist is book moves */
382   int seen_stat;          /* 1 if we've seen the stat01: line */
383 } ChessProgramStats;
384
385 extern ChessProgramStats_Move pvInfoList[MAX_MOVES];
386 extern int shuffleOpenings;
387 extern ChessProgramStats programStats;
388 extern int opponentKibitzes; // used by wengineo.c
389 extern int errorExitStatus;\r
390
391 #endif /* _BACKEND */