changes from Alessandro Scotti from 20060112
[xboard.git] / backend.h
1 /*
2  * backend.h -- Interface exported by XBoard back end
3  * $Id: backend.h,v 2.1 2003/10/27 19:21:00 mann Exp $
4  *
5  * Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts.
6  * Enhancements Copyright 1992-95 Free Software Foundation, Inc.
7  *
8  * The following terms apply to Digital Equipment Corporation's copyright
9  * interest in XBoard:
10  * ------------------------------------------------------------------------
11  * All Rights Reserved
12  *
13  * Permission to use, copy, modify, and distribute this software and its
14  * documentation for any purpose and without fee is hereby granted,
15  * provided that the above copyright notice appear in all copies and that
16  * both that copyright notice and this permission notice appear in
17  * supporting documentation, and that the name of Digital not be
18  * used in advertising or publicity pertaining to distribution of the
19  * software without specific, written prior permission.
20  *
21  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
22  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
23  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
24  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
25  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
26  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
27  * SOFTWARE.
28  * ------------------------------------------------------------------------
29  *
30  * The following terms apply to the enhanced version of XBoard distributed
31  * by the Free Software Foundation:
32  * ------------------------------------------------------------------------
33  * This program is free software; you can redistribute it and/or modify
34  * it under the terms of the GNU General Public License as published by
35  * the Free Software Foundation; either version 2 of the License, or
36  * (at your option) any later version.
37  *
38  * This program is distributed in the hope that it will be useful,
39  * but WITHOUT ANY WARRANTY; without even the implied warranty of
40  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
41  * GNU General Public License for more details.
42  *
43  * You should have received a copy of the GNU General Public License
44  * along with this program; if not, write to the Free Software
45  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
46  * ------------------------------------------------------------------------
47  */
48 #ifndef _BACKEND
49 #define _BACKEND
50
51 #include "lists.h"
52 #include "frontend.h"
53
54 extern int gotPremove;
55 extern GameMode gameMode;
56 extern int pausing, cmailMsgLoaded, flipView;
57 extern char white_holding[], black_holding[];
58 extern int currentMove, backwardMostMove, forwardMostMove;
59 extern int blackPlaysFirst;
60 extern FILE *debugFP;
61 extern char* programVersion;
62 extern ProcRef firstProgramPR, secondProgramPR;
63 extern Board boards[];
64
65 char *CmailMsg P((void));
66 /* Tord: Added the useFEN960 parameter in PositionToFEN() below */
67 char *PositionToFEN P((int move, int useFEN960));
68 void EditPositionPasteFEN P((char *fen));
69 void TimeDelay P((long ms));
70 void SendMultiLineToICS P(( char *text ));
71 void AnalysisPeriodicEvent P((int force));
72 void SetWhiteToPlayEvent P((void));
73 void SetBlackToPlayEvent P((void));
74 void InitBackEnd1 P((void));
75 void InitBackEnd2 P((void));
76 int IsPromotion P((int fromX, int fromY, int toX, int toY));
77 int PieceForSquare P((int x, int y));
78 int OKToStartUserMove P((int x, int y));
79 void Reset P((int redraw, int init));
80 void ResetGameEvent P((void));
81 int LoadGame P((FILE *f, int n, char *title, int useList));
82 int LoadGameFromFile P((char *filename, int n, char *title, int useList));
83 int CmailLoadGame P((FILE *f, int n, char *title, int useList));
84 int ReloadGame P((int offset));
85 int SaveGame P((FILE *f, int dummy, char *dummy2));
86 int SaveGameToFile P((char *filename, int append));
87 int LoadPosition P((FILE *f, int n, char *title));
88 int ReloadPosition P((int offset));
89 int SavePosition P((FILE *f, int dummy, char *dummy2));
90 void EditPositionEvent P((void));
91 void FlipViewEvent P((void));
92 void MachineWhiteEvent P((void));
93 void MachineBlackEvent P((void));
94 void TwoMachinesEvent P((void));
95 void EditGameEvent P((void));
96 void TrainingEvent P((void));
97 void IcsClientEvent P((void));
98 void ForwardEvent P((void));
99 void BackwardEvent P((void));
100 void ToEndEvent P((void));
101 void ToStartEvent P((void));
102 void ToNrEvent P((int to));
103 void RevertEvent P((void));
104 void RetractMoveEvent P((void));
105 void MoveNowEvent P((void));
106 void TruncateGameEvent P((void));
107 void PauseEvent P((void));
108 void CallFlagEvent P((void));
109 void AcceptEvent P((void));
110 void DeclineEvent P((void));
111 void RematchEvent P((void));
112 void DrawEvent P((void));
113 void AbortEvent P((void));
114 void AdjournEvent P((void));
115 void ResignEvent P((void));
116 void UserAdjudicationEvent P((int result));
117 void StopObservingEvent P((void));
118 void StopExaminingEvent P((void));
119 void PonderNextMoveEvent P((int newState));
120 void ShowThinkingEvent P((int newState));
121 void PeriodicUpdatesEvent P((int newState));
122 void HintEvent P((void));
123 void BookEvent P((void));
124 void AboutGameEvent P((void));
125 void ExitEvent P((int status));
126 char *DefaultFileName P((char *));
127 void UserMoveEvent P((int fromX, int fromY, int toX, int toY, int promoChar));
128 void DecrementClocks P((void));
129 char *TimeString P((long millisec));
130 void AutoPlayGameLoop P((void));
131 void DisplayBothClocks P((void));
132 void EditPositionMenuEvent P((ChessSquare selection, int x, int y));
133 void DropMenuEvent P((ChessSquare selection, int x, int y));
134 int ParseTimeControl P((char *tc, int ti, int mps));
135 void ProcessICSInitScript P((FILE * f));
136 void EditCommentEvent P((void));
137 void ReplaceComment P((int index, char *text));
138 int ReplaceTags P((char *tags, GameInfo *gi));/* returns nonzero on error */
139 void AppendComment P((int index, char *text));
140 void ReloadCmailMsgEvent P((int unregister));
141 void MailMoveEvent P((void));
142 void EditTagsEvent P((void));
143 void GetMoveListEvent P((void));
144 void ExitAnalyzeMode P((void));
145 void AnalyzeModeEvent P((void));
146 void AnalyzeFileEvent P((void));
147 void DoEcho P((void));
148 void DontEcho P((void));
149 void TidyProgramName P((char *prog, char *host, char *buf));
150 void AskQuestionEvent P((char *title, char *question,
151                          char *replyPrefix, char *which));
152 Boolean ParseOneMove P((char *move, int moveNum,
153                         ChessMove *moveType, int *fromX, int *fromY,
154                         int *toX, int *toY, char *promoChar));
155 char *VariantName P((VariantClass v));
156 VariantClass StringToVariant P((char *e));
157
158 char *StrStr P((char *string, char *match));
159 char *StrCaseStr P((char *string, char *match));
160 char *StrSave P((char *s));
161 char *StrSavePtr P((char *s, char **savePtr));
162
163 #ifndef _amigados
164 int StrCaseCmp P((char *s1, char *s2));
165 int ToLower P((int c));
166 int ToUpper P((int c));
167 #else
168 #define StrCaseCmp Stricmp  /*  Use utility.library functions   */
169 #include <proto/utility.h>
170 #endif
171
172 extern GameInfo gameInfo;
173
174
175 /* pgntags.c prototypes
176  */
177 char *PGNTags P((GameInfo *));
178 void PrintPGNTags P((FILE *f, GameInfo *));
179 int ParsePGNTag P((char *, GameInfo *));
180 char *PGNResult P((ChessMove result));
181
182
183 /* gamelist.c prototypes
184  */
185 /* A game node in the double linked list of games.
186  */
187 typedef struct _ListGame {
188     ListNode node;
189     int number;
190     unsigned long offset;   /*  Byte offset of game within file.     */
191     GameInfo gameInfo;      /*  Note that some entries may be NULL. */
192 } ListGame;
193  
194 extern List gameList;
195 void ClearGameInfo P((GameInfo *));
196 int GameListBuild P((FILE *));
197 void GameListInitGameInfo P((GameInfo *));
198 char *GameListLine P((int, GameInfo *));
199 char * GameListLineFull P(( int, GameInfo *));
200
201 extern char* StripHighlight P((char *));  /* returns static data */
202 extern char* StripHighlightAndTitle P((char *));  /* returns static data */
203
204 typedef struct _CPS {
205     char *which;
206     int maybeThinking;
207     ProcRef pr;
208     InputSourceRef isr;
209     char *twoMachinesColor; /* "white\n" or "black\n" */
210     char *program;
211     char *host;
212     char *dir;
213     struct _CPS *other;
214     char *initString;
215     char *computerString;
216     int sendTime; /* 0=don't, 1=do, 2=test */
217     int sendDrawOffers;
218     int useSigint;
219     int useSigterm;
220     int offeredDraw; /* countdown */
221     int reuse;
222     int useSetboard; /* 0=use "edit"; 1=use "setboard" */
223     int useSAN;      /* 0=use coordinate notation; 1=use SAN */
224     int usePing;     /* 0=not OK to use ping; 1=OK */
225     int lastPing;
226     int lastPong;
227     int usePlayother;/* 0=not OK to use playother; 1=OK */
228     int useColors;   /* 0=avoid obsolete white/black commands; 1=use them */
229     int useUsermove; /* 0=just send move; 1=send "usermove move" */
230     int sendICS;     /* 0=don't use "ics" command; 1=do */
231     int sendName;    /* 0=don't use "name" command; 1=do */
232     int sdKludge;    /* 0=use "sd DEPTH" command; 1=use "depth\nDEPTH" */
233     int stKludge;    /* 0=use "st TIME" command; 1=use "level 1 TIME" */
234     char tidy[MSG_SIZ];
235     int matchWins;
236     char variants[MSG_SIZ];
237     int analysisSupport;
238     int analyzing;
239     int protocolVersion;
240     int initDone;
241
242     /* Added by Tord: */
243     int useFEN960;   /* 0=use "KQkq" style FENs, 1=use "HAha" style FENs */
244     int useOOCastle; /* 0="O-O" notation for castling, 1="king capture rook" notation */
245     /* End of additions by Tord */
246
247     int scoreIsAbsolute; /* [AS] 0=don't know (standard), 1=score is always from white side */
248     int isUCI;           /* [AS] 0=no (Winboard), 1=UCI (requires Polyglot) */
249     int hasOwnBookUCI;   /* [AS] 0=use GUI or Polyglot book, 1=has own book */
250 } ChessProgramState;
251
252 extern ChessProgramState first, second;
253
254 /* [AS] Search stats from chessprogram, for the played move */
255 typedef struct {
256     int score;  /* Centipawns */
257     int depth;  /* Plies */
258     int time;   /* Milliseconds */
259 } ChessProgramStats_Move;
260
261 extern ChessProgramStats_Move pvInfoList[MAX_MOVES];
262
263 #endif /* _BACKEND */