6e6aee236c046ea8a5696fef55050af83e6a8907
[xboard.git] / winboard-dm-beta4 / backend.h
1 /*
2  * backend.h -- Interface exported by XBoard back end
3  * $Id$
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 int pausing, cmailMsgLoaded, flipView;
56 extern char white_holding[], black_holding[];
57 extern int currentMove, backwardMostMove, forwardMostMove;
58 extern int blackPlaysFirst;
59 extern FILE *debugFP;
60 extern char* programVersion;
61 extern ProcRef firstProgramPR, secondProgramPR;
62 extern Board boards[];
63
64 char *CmailMsg P((void));
65 char *PositionToFEN P((int move));
66 void EditPositionPasteFEN P((char *fen));
67 void TimeDelay P((long ms));
68 void SendMultiLineToICS P(( char *text ));
69 void AnalysisPeriodicEvent P((int force));
70 void SetWhiteToPlayEvent P((void));
71 void SetBlackToPlayEvent P((void));
72 void InitBackEnd1 P((void));
73 void InitBackEnd2 P((void));
74 void ConsoleCreate P((void));
75 void DisplayAnalysis P((int NewState, int pv));
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 ResetIcsQueue P((int gamenumber));
108 void PauseEvent P((void));
109 void CallFlagEvent P((void));
110 void AcceptEvent P((void));
111 void DeclineEvent P((void));
112 void RematchEvent P((void));
113 void DrawEvent P((void));
114 void AbortEvent P((void));
115 void AdjournEvent P((void));
116 void ResignEvent P((void));
117 void StopObservingEvent P((void));
118 void StopExaminingEvent P((void));
119 void PonderNextMoveEvent P((int newState));
120 void ShowThinkingEvent P((int newState));
121 void IcsAnalyze P((int newState));
122 void IcsAnalyzeWindowUp P((void));
123 void PeriodicUpdatesEvent P((int newState));
124 void HintEvent P((void));
125 void BookEvent P((void));
126 void AboutGameEvent P((void));
127 void ExitEvent P((int status));
128 char *DefaultFileName P((char *));
129 void UserMoveEvent P((int fromX, int fromY, int toX, int toY, int promoChar));
130 void DecrementClocks P((void));
131 char *TimeString P((long millisec));
132 void AutoPlayGameLoop P((void));
133 void DisplayBothClocks P((void));
134 void EditPositionMenuEvent P((ChessSquare selection, int x, int y));
135 void DropMenuEvent P((ChessSquare selection, int x, int y));
136 int ParseTimeControl P((char *tc, int ti, int mps));
137 void ProcessICSInitScript P((FILE * f));
138 void EditCommentEvent P((void));
139 void ReplaceComment P((int index, char *text));
140 int ReplaceTags P((char *tags, GameInfo *gi));/* returns nonzero on error */
141 void AppendComment P((int index, char *text));
142 void ReloadCmailMsgEvent P((int unregister));
143 void MailMoveEvent P((void));
144 void EditTagsEvent P((void));
145 void GetMoveListEvent P((void));
146 void ExitAnalyzeMode P((void));
147 void AnalyzeModeEvent P((void));
148 void AnalyzeFileEvent P((void));
149 void DoEcho P((void));
150 void DontEcho P((void));
151 void TidyProgramName P((char *prog, char *host, char *buf));
152 void AskQuestionEvent P((char *title, char *question,
153                          char *replyPrefix, char *which));
154 Boolean ParseOneMove P((char *move, int moveNum,
155                         ChessMove *moveType, int *fromX, int *fromY,
156                         int *toX, int *toY, char *promoChar));
157 char *VariantName P((VariantClass v));
158 VariantClass StringToVariant P((char *e));
159
160 char *StrStr P((char *string, char *match));
161 char *StrCaseStr P((char *string, char *match));
162 char *StrSave P((char *s));
163 char *StrSavePtr P((char *s, char **savePtr));
164
165 #ifndef _amigados
166 int StrCaseCmp P((char *s1, char *s2));
167 int ToLower P((int c));
168 int ToUpper P((int c));
169 #else
170 #define StrCaseCmp Stricmp  /*  Use utility.library functions   */
171 #include <proto/utility.h>
172 #endif
173
174 extern GameInfo gameInfo;
175
176
177 /* pgntags.c prototypes
178  */
179 char *PGNTags P((GameInfo *));
180 void PrintPGNTags P((FILE *f, GameInfo *));
181 int ParsePGNTag P((char *, GameInfo *));
182 char *PGNResult P((ChessMove result));
183
184
185 /* gamelist.c prototypes
186  */
187 /* A game node in the double linked list of games.
188  */
189 typedef struct _ListGame {
190     ListNode node;
191     int number;
192     unsigned long offset;   /*  Byte offset of game within file.     */
193     GameInfo gameInfo;      /*  Note that some entries may be NULL. */
194 } ListGame;
195  
196 extern List gameList;
197 void ClearGameInfo P((GameInfo *));
198 int GameListBuild P((FILE *));
199 void GameListInitGameInfo P((GameInfo *));
200 char *GameListLine P((int, GameInfo *));
201
202 extern char* StripHighlight P((char *));  /* returns static data */
203 extern char* StripHighlightAndTitle P((char *));  /* returns static data */
204
205
206 typedef struct _CPS {
207     char *which;
208     int maybeThinking;
209     ProcRef pr;
210     InputSourceRef isr;
211     char *twoMachinesColor; /* "white\n" or "black\n" */
212     char *program;
213     char *host;
214     char *dir;
215     struct _CPS *other;
216     char *initString;
217     char *computerString;
218     int sendTime; /* 0=don't, 1=do, 2=test */
219     int sendDrawOffers;
220     int useSigint;
221     int useSigterm;
222     int offeredDraw; /* countdown */
223     int reuse;
224     int useSetboard; /* 0=use "edit"; 1=use "setboard" */
225     int useSAN;      /* 0=use coordinate notation; 1=use SAN */
226     int usePing;     /* 0=not OK to use ping; 1=OK */
227     int lastPing;
228     int lastPong;
229     int usePlayother;/* 0=not OK to use playother; 1=OK */
230     int useColors;   /* 0=avoid obsolete white/black commands; 1=use them */
231     int useUsermove; /* 0=just send move; 1=send "usermove move" */
232     int sendICS;     /* 0=don't use "ics" command; 1=do */
233     int sendName;    /* 0=don't use "name" command; 1=do */
234     int sdKludge;    /* 0=use "sd DEPTH" command; 1=use "depth\nDEPTH" */
235     int stKludge;    /* 0=use "st TIME" command; 1=use "level 1 TIME" */
236     char tidy[MSG_SIZ];
237     int matchWins;
238     char variants[MSG_SIZ];
239     int analysisSupport;
240     int analyzing;
241     int protocolVersion;
242     int initDone;
243 } ChessProgramState;
244
245 ChessProgramState first, second;
246
247 /* max gamenumber on ICS 
248  * i don't know the real value
249  * but i think 1500 is enought
250  * edit here if you want change 
251  * if we over max value we break all
252  * action and make a fatal error
253  */
254 #define max_gamenum 1500
255
256 /* Smart ICS outut Queue */
257 typedef struct {
258         int counter;
259         long time;
260         int killPv;
261         int move;                       /* only for for killpv++ and --  
262                                                    give not the realstic move number back !!
263                                                 */
264         int MessageMove;        /* Last played move where we send a message */
265         int CurrentMove;        /* current movenumber on observing board */
266         int flag;                       /* 0= we never send a message for this move 1= We send it */
267         int event;                      /* Send event message to board "Hello, i'm..." */
268         int gameNum;            /* reserved */
269         int currentGame;        /* reserved */
270         char lastpv[1024];      /* save last pv */
271         char white[128];        /* white player name */
272         char black[128];        /* black player name */
273 } smartQueue; 
274
275 extern smartQueue icsQueue[max_gamenum];
276
277 int chessfm;
278
279 /* rember if engine send a "stat01:" line for display */
280 static int supportStat; /* 0 = false 1 = true */
281
282 /* save pv - reserved for future */
283 typedef struct {
284         char mainline[1024];
285 } PV[512];
286 PV engineRoom, *er;
287
288 #endif /* _BACKEND */