security fix: replaced sprintf with snprintf
[xboard.git] / args.h
1 /*
2  * args.c -- Option parsing and saving for X and Windows versions of XBoard
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, 2010 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
55 // Note: this file is not a normal header, but contains executable code
56 // for #inclusion in winboard.c and xboard.c, rather than separate compilation,
57 // so that it can make use of the proper context of #defined symbols and
58 // declarations in those files.
59
60 typedef enum {
61   ArgString, ArgInt, ArgFloat, ArgBoolean, ArgTrue, ArgFalse, ArgNone,
62   ArgColor, ArgAttribs, ArgFilename, ArgBoardSize, ArgFont, ArgCommSettings,
63   ArgSettingsFilename,
64   ArgX, ArgY, ArgZ // [HGM] placement: for window-placement options stored relative to main window
65 } ArgType;
66
67 typedef void *ArgIniType;
68
69 #define INVALID (ArgIniType) 6915 /* Some number unlikely to be needed as default for anything */
70 #define MAX_ARG_LEN 128*1024 /* [AS] For Roger Brown's very long list! */
71
72 typedef struct {
73   char *argName;
74   ArgType argType;
75   /***
76   union {
77     String *pString;       // ArgString
78     int *pInt;             // ArgInt
79     float *pFloat;         // ArgFloat
80     Boolean *pBoolean;     // ArgBoolean
81     COLORREF *pColor;      // ArgColor
82     ColorClass cc;         // ArgAttribs
83     String *pFilename;     // ArgFilename
84     BoardSize *pBoardSize; // ArgBoardSize
85     int whichFont;         // ArgFont
86     DCB *pDCB;             // ArgCommSettings
87     String *pFilename;     // ArgSettingsFilename
88   } argLoc;
89   ***/
90   void *argLoc;
91   Boolean save;
92   ArgIniType defaultValue;
93 } ArgDescriptor;
94
95 typedef struct {
96   char *item;
97   char *command;
98   Boolean getname;
99   Boolean immediate;
100 } IcsTextMenuEntry;
101
102 IcsTextMenuEntry icsTextMenuEntry[ICS_TEXT_MENU_SIZE];
103
104 int junk;
105
106 void EnsureOnScreen(int *x, int *y, int minX, int minY);
107 char StringGet(void *getClosure);
108 void ParseFont(char *name, int number);
109 void SetFontDefaults();
110 void CreateFonts();
111 void ParseColor(int n, char *name);
112 void ParseTextAttribs(ColorClass cc, char *s);
113 void ParseBoardSize(void * addr, char *name);
114 void ParseCommPortSettings(char *name);
115 void LoadAllSounds();
116 void SetCommPortDefaults();
117 void SaveFontArg(FILE *f, ArgDescriptor *ad);
118 void ExportSounds();
119 void SaveAttribsArg(FILE *f, ArgDescriptor *ad);
120 void SaveColor(FILE *f, ArgDescriptor *ad);
121 void SaveBoardSize(FILE *f, char *name, void *addr);
122 void PrintCommPortSettings(FILE *f, char *name);
123 void GetWindowCoords();
124 int  MySearchPath(char *installDir, char *name, char *fullname);
125 int  MyGetFullPathName(char *name, char *fullname);
126 int  MainWindowUp();
127 void PopUpStartupDialog();
128 typedef char GetFunc(void *getClosure);
129 void ParseArgs(GetFunc get, void *cl);
130
131 // [HGM] this is an exact duplicate of something in winboard.c. Move to backend.c?
132 char *defaultTextAttribs[] =
133 {
134   COLOR_SHOUT, COLOR_SSHOUT, COLOR_CHANNEL1, COLOR_CHANNEL, COLOR_KIBITZ,
135   COLOR_TELL, COLOR_CHALLENGE, COLOR_REQUEST, COLOR_SEEK, COLOR_NORMAL,
136   "#000000"
137 };
138
139 ArgDescriptor argDescriptors[] = {
140   /* positional arguments */
141   { "loadGameFile", ArgFilename, (void *) &appData.loadGameFile, FALSE, INVALID },
142   { "", ArgNone, NULL, FALSE, INVALID },
143   /* keyword arguments */
144   JAWS_ARGS
145   { "whitePieceColor", ArgColor, (void *) 0, TRUE, (ArgIniType) WHITE_PIECE_COLOR },
146   { "wpc", ArgColor, (void *) 0, FALSE, INVALID },
147   { "blackPieceColor", ArgColor, (void *) 1, TRUE, (ArgIniType) BLACK_PIECE_COLOR },
148   { "bpc", ArgColor, (void *) 1, FALSE, INVALID },
149   { "lightSquareColor", ArgColor, (void *) 2, TRUE, (ArgIniType) LIGHT_SQUARE_COLOR },
150   { "lsc", ArgColor, (void *) 2, FALSE, INVALID },
151   { "darkSquareColor", ArgColor, (void *) 3, TRUE, (ArgIniType) DARK_SQUARE_COLOR },
152   { "dsc", ArgColor, (void *) 3, FALSE, INVALID },
153   { "highlightSquareColor", ArgColor, (void *) 4, TRUE, (ArgIniType) HIGHLIGHT_SQUARE_COLOR },
154   { "hsc", ArgColor, (void *) 4, FALSE, INVALID },
155   { "premoveHighlightColor", ArgColor, (void *) 5, TRUE, (ArgIniType) PREMOVE_HIGHLIGHT_COLOR },
156   { "phc", ArgColor, (void *) 5, FALSE, INVALID },
157   { "movesPerSession", ArgInt, (void *) &appData.movesPerSession, TRUE, (ArgIniType) MOVES_PER_SESSION },
158   { "mps", ArgInt, (void *) &appData.movesPerSession, FALSE, INVALID },
159   { "initString", ArgString, (void *) &appData.initString, FALSE, INVALID },
160   { "firstInitString", ArgString, (void *) &appData.initString, FALSE, (ArgIniType) INIT_STRING },
161   { "secondInitString", ArgString, (void *) &appData.secondInitString, FALSE, (ArgIniType) INIT_STRING },
162   { "firstComputerString", ArgString, (void *) &appData.firstComputerString,
163     FALSE, (ArgIniType) COMPUTER_STRING },
164   { "secondComputerString", ArgString, (void *) &appData.secondComputerString,
165     FALSE, (ArgIniType) COMPUTER_STRING },
166   { "firstChessProgram", ArgFilename, (void *) &appData.firstChessProgram,
167     FALSE, (ArgIniType) FIRST_CHESS_PROGRAM },
168   { "fcp", ArgFilename, (void *) &appData.firstChessProgram, FALSE, INVALID },
169   { "secondChessProgram", ArgFilename, (void *) &appData.secondChessProgram,
170     FALSE, (ArgIniType) SECOND_CHESS_PROGRAM },
171   { "scp", ArgFilename, (void *) &appData.secondChessProgram, FALSE, INVALID },
172   { "firstPlaysBlack", ArgBoolean, (void *) &appData.firstPlaysBlack, FALSE, FALSE },
173   { "fb", ArgTrue, (void *) &appData.firstPlaysBlack, FALSE, FALSE },
174   { "xfb", ArgFalse, (void *) &appData.firstPlaysBlack, FALSE, INVALID },
175   { "-fb", ArgFalse, (void *) &appData.firstPlaysBlack, FALSE, INVALID },
176   { "noChessProgram", ArgBoolean, (void *) &appData.noChessProgram, FALSE, FALSE },
177   { "ncp", ArgTrue, (void *) &appData.noChessProgram, FALSE, INVALID },
178   { "xncp", ArgFalse, (void *) &appData.noChessProgram, FALSE, INVALID },
179   { "-ncp", ArgFalse, (void *) &appData.noChessProgram, FALSE, INVALID },
180   { "firstHost", ArgString, (void *) &appData.firstHost, FALSE, (ArgIniType) FIRST_HOST },
181   { "fh", ArgString, (void *) &appData.firstHost, FALSE, INVALID },
182   { "secondHost", ArgString, (void *) &appData.secondHost, FALSE, (ArgIniType) SECOND_HOST },
183   { "sh", ArgString, (void *) &appData.secondHost, FALSE, INVALID },
184   { "firstDirectory", ArgFilename, (void *) &appData.firstDirectory, FALSE, (ArgIniType) FIRST_DIRECTORY },
185   { "fd", ArgFilename, (void *) &appData.firstDirectory, FALSE, INVALID },
186   { "secondDirectory", ArgFilename, (void *) &appData.secondDirectory, FALSE, (ArgIniType) SECOND_DIRECTORY },
187   { "sd", ArgFilename, (void *) &appData.secondDirectory, FALSE, INVALID },
188
189   /* some options only used by the XBoard front end, and ignored in WinBoard         */
190   /* Their saving is controlled by XBOARD, which in WinBoard is defined as FALSE */
191   { "internetChessServerInputBox", ArgBoolean, (void *) &appData.icsInputBox, XBOARD, (ArgIniType) FALSE },
192   { "icsinput", ArgTrue, (void *) &appData.icsInputBox, FALSE, INVALID },
193   { "xicsinput", ArgFalse, (void *) &appData.icsInputBox, FALSE, INVALID },
194   { "cmail", ArgString, (void *) &appData.cmailGameName, FALSE, (ArgIniType) "" },
195   { "soundProgram", ArgFilename, (void *) &appData.soundProgram, XBOARD, (ArgIniType) "play" },
196   { "fontSizeTolerance", ArgInt, (void *) &appData.fontSizeTolerance, XBOARD, (ArgIniType) 4 },
197   { "lowTimeWarningColor", ArgColor, (void *) 6, XBOARD, (ArgIniType) LOWTIMEWARNING_COLOR },
198   { "lowTimeWarning", ArgBoolean, (void *) &appData.lowTimeWarning, XBOARD, (ArgIniType) FALSE },
199   { "titleInWindow", ArgBoolean, (void *) &appData.titleInWindow, XBOARD, (ArgIniType) FALSE },
200   { "title", ArgTrue, (void *) &appData.titleInWindow, FALSE, INVALID },
201   { "xtitle", ArgFalse, (void *) &appData.titleInWindow, FALSE, INVALID },
202   { "flashCount", ArgInt, (void *) &appData.flashCount, XBOARD, INVALID }, // let X handle this
203   { "flashRate", ArgInt, (void *) &appData.flashRate, XBOARD, (ArgIniType) FLASH_RATE },
204   { "pixmapDirectory", ArgFilename, (void *) &appData.pixmapDirectory, XBOARD, (ArgIniType) "" },
205   { "pixmap", ArgFilename, (void *) &appData.pixmapDirectory, FALSE, INVALID },
206   { "bitmapDirectory", ArgFilename, (void *) &appData.bitmapDirectory, XBOARD, (ArgIniType) "" },
207   { "bm", ArgFilename, (void *) &appData.bitmapDirectory, FALSE, INVALID },
208   { "msLoginDelay", ArgInt, (void *) &appData.msLoginDelay, XBOARD, (ArgIniType) MS_LOGIN_DELAY },
209   { "pasteSelection", ArgBoolean, (void *) &appData.pasteSelection, XBOARD, (ArgIniType) FALSE },
210
211   { "dropMenu", ArgBoolean, (void *) &appData.dropMenu, TRUE, (ArgIniType) FALSE },
212   { "remoteShell", ArgFilename, (void *) &appData.remoteShell, FALSE, (ArgIniType) REMOTE_SHELL },
213   { "rsh", ArgFilename, (void *) &appData.remoteShell, FALSE, INVALID },
214   { "remoteUser", ArgString, (void *) &appData.remoteUser, FALSE, INVALID },
215   { "ruser", ArgString, (void *) &appData.remoteUser, FALSE, INVALID },
216   { "timeDelay", ArgFloat, (void *) &appData.timeDelay, TRUE, INVALID },
217   { "td", ArgFloat, (void *) &appData.timeDelay, FALSE, INVALID },
218   { "timeControl", ArgString, (void *) &appData.timeControl, TRUE, (ArgIniType) TIME_CONTROL },
219   { "tc", ArgString, (void *) &appData.timeControl, FALSE, INVALID },
220   { "timeIncrement", ArgInt, (void *) &appData.timeIncrement, TRUE, (ArgIniType) TIME_INCREMENT },
221   { "inc", ArgInt, (void *) &appData.timeIncrement, FALSE, INVALID },
222   { "internetChessServerMode", ArgBoolean, (void *) &appData.icsActive, FALSE, INVALID },
223   { "ics", ArgTrue, (void *) &appData.icsActive, FALSE, (ArgIniType) FALSE },
224   { "xics", ArgFalse, (void *) &appData.icsActive, FALSE, INVALID },
225   { "-ics", ArgFalse, (void *) &appData.icsActive, FALSE, INVALID },
226   { "internetChessServerHost", ArgString, (void *) &appData.icsHost, FALSE, (ArgIniType) "" },
227   { "icshost", ArgString, (void *) &appData.icsHost, FALSE, INVALID },
228   { "internetChessServerPort", ArgString, (void *) &appData.icsPort, FALSE, (ArgIniType) ICS_PORT },
229   { "icsport", ArgString, (void *) &appData.icsPort, FALSE, INVALID },
230   { "internetChessServerCommPort", ArgString, (void *) &appData.icsCommPort, FALSE, (ArgIniType) ICS_COMM_PORT },
231   { "icscomm", ArgString, (void *) &appData.icsCommPort, FALSE, INVALID },
232   { "internetChessServerComPort", ArgString, (void *) &appData.icsCommPort, FALSE, INVALID },
233   { "icscom", ArgString, (void *) &appData.icsCommPort, FALSE, INVALID },
234   { "internetChessServerLogonScript", ArgFilename, (void *) &appData.icsLogon, FALSE, (ArgIniType) ICS_LOGON },
235   { "icslogon", ArgFilename, (void *) &appData.icsLogon, FALSE, INVALID },
236   { "useTelnet", ArgBoolean, (void *) &appData.useTelnet, FALSE, INVALID },
237   { "telnet", ArgTrue, (void *) &appData.useTelnet, FALSE, INVALID },
238   { "xtelnet", ArgFalse, (void *) &appData.useTelnet, FALSE, INVALID },
239   { "-telnet", ArgFalse, (void *) &appData.useTelnet, FALSE, INVALID },
240   { "telnetProgram", ArgFilename, (void *) &appData.telnetProgram, FALSE, (ArgIniType) TELNET_PROGRAM },
241   { "internetChessserverHelper", ArgFilename, (void *) &appData.icsHelper,
242         FALSE, INVALID }, // for XB
243   { "icshelper", ArgFilename, (void *) &appData.icsHelper, FALSE, (ArgIniType) "" },
244   { "seekGraph", ArgBoolean, (void *) &appData.seekGraph, TRUE, (ArgIniType) FALSE },
245   { "sg", ArgTrue, (void *) &appData.seekGraph, FALSE, INVALID },
246   { "autoRefresh", ArgBoolean, (void *) &appData.autoRefresh, TRUE, (ArgIniType) FALSE },
247   { "gateway", ArgString, (void *) &appData.gateway, FALSE, (ArgIniType) "" },
248   { "loadGameFile", ArgFilename, (void *) &appData.loadGameFile, FALSE, (ArgIniType) "" },
249   { "lgf", ArgFilename, (void *) &appData.loadGameFile, FALSE, INVALID },
250   { "loadGameIndex", ArgInt, (void *) &appData.loadGameIndex, FALSE, (ArgIniType) 0 },
251   { "lgi", ArgInt, (void *) &appData.loadGameIndex, FALSE, INVALID },
252   { "saveGameFile", ArgFilename, (void *) &appData.saveGameFile, TRUE, (ArgIniType) "" },
253   { "sgf", ArgFilename, (void *) &appData.saveGameFile, FALSE, INVALID },
254   { "autoSaveGames", ArgBoolean, (void *) &appData.autoSaveGames, TRUE, (ArgIniType) FALSE },
255   { "autosave", ArgTrue, (void *) &appData.autoSaveGames, FALSE, INVALID },
256   { "xautosave", ArgFalse, (void *) &appData.autoSaveGames, FALSE, INVALID },
257   { "-autosave", ArgFalse, (void *) &appData.autoSaveGames, FALSE, INVALID },
258   { "loadPositionFile", ArgFilename, (void *) &appData.loadPositionFile, FALSE, (ArgIniType) "" },
259   { "lpf", ArgFilename, (void *) &appData.loadPositionFile, FALSE, INVALID },
260   { "loadPositionIndex", ArgInt, (void *) &appData.loadPositionIndex, FALSE, (ArgIniType) 1 },
261   { "lpi", ArgInt, (void *) &appData.loadPositionIndex, FALSE, INVALID },
262   { "savePositionFile", ArgFilename, (void *) &appData.savePositionFile, FALSE, (ArgIniType) "" },
263   { "spf", ArgFilename, (void *) &appData.savePositionFile, FALSE, INVALID },
264   { "matchMode", ArgBoolean, (void *) &appData.matchMode, FALSE, (ArgIniType) FALSE },
265   { "mm", ArgTrue, (void *) &appData.matchMode, FALSE, INVALID },
266   { "xmm", ArgFalse, (void *) &appData.matchMode, FALSE, INVALID },
267   { "-mm", ArgFalse, (void *) &appData.matchMode, FALSE, INVALID },
268   { "matchGames", ArgInt, (void *) &appData.matchGames, FALSE, (ArgIniType) 0 },
269   { "mg", ArgInt, (void *) &appData.matchGames, FALSE, INVALID },
270   { "monoMode", ArgBoolean, (void *) &appData.monoMode, TRUE, (ArgIniType) FALSE },
271   { "mono", ArgTrue, (void *) &appData.monoMode, FALSE, INVALID },
272   { "xmono", ArgFalse, (void *) &appData.monoMode, FALSE, INVALID },
273   { "-mono", ArgFalse, (void *) &appData.monoMode, FALSE, INVALID },
274   { "debugMode", ArgBoolean, (void *) &appData.debugMode, FALSE, (ArgIniType) FALSE },
275   { "debug", ArgTrue, (void *) &appData.debugMode, FALSE, INVALID },
276   { "xdebug", ArgFalse, (void *) &appData.debugMode, FALSE, INVALID },
277   { "-debug", ArgFalse, (void *) &appData.debugMode, FALSE, INVALID },
278   { "clockMode", ArgBoolean, (void *) &appData.clockMode, FALSE, (ArgIniType) TRUE },
279   { "clock", ArgTrue, (void *) &appData.clockMode, FALSE, INVALID },
280   { "xclock", ArgFalse, (void *) &appData.clockMode, FALSE, INVALID },
281   { "-clock", ArgFalse, (void *) &appData.clockMode, FALSE, INVALID },
282   { "searchTime", ArgString, (void *) &appData.searchTime, FALSE, (ArgIniType) "" },
283   { "st", ArgString, (void *) &appData.searchTime, FALSE, INVALID },
284   { "searchDepth", ArgInt, (void *) &appData.searchDepth, FALSE, (ArgIniType) 0 },
285   { "depth", ArgInt, (void *) &appData.searchDepth, FALSE, INVALID },
286   { "showCoords", ArgBoolean, (void *) &appData.showCoords, TRUE, (ArgIniType) FALSE },
287   { "coords", ArgTrue, (void *) &appData.showCoords, FALSE, INVALID },
288   { "xcoords", ArgFalse, (void *) &appData.showCoords, FALSE, INVALID },
289   { "-coords", ArgFalse, (void *) &appData.showCoords, FALSE, INVALID },
290   { "showThinking", ArgBoolean, (void *) &appData.showThinking, TRUE, (ArgIniType) FALSE },
291   { "thinking", ArgTrue, (void *) &appData.showThinking, FALSE, INVALID },
292   { "xthinking", ArgFalse, (void *) &appData.showThinking, FALSE, INVALID },
293   { "-thinking", ArgFalse, (void *) &appData.showThinking, FALSE, INVALID },
294   { "ponderNextMove", ArgBoolean, (void *) &appData.ponderNextMove, TRUE, (ArgIniType) TRUE },
295   { "ponder", ArgTrue, (void *) &appData.ponderNextMove, FALSE, INVALID },
296   { "xponder", ArgFalse, (void *) &appData.ponderNextMove, FALSE, INVALID },
297   { "-ponder", ArgFalse, (void *) &appData.ponderNextMove, FALSE, INVALID },
298   { "periodicUpdates", ArgBoolean, (void *) &appData.periodicUpdates, TRUE, (ArgIniType) TRUE },
299   { "periodic", ArgTrue, (void *) &appData.periodicUpdates, FALSE, INVALID },
300   { "xperiodic", ArgFalse, (void *) &appData.periodicUpdates, FALSE, INVALID },
301   { "-periodic", ArgFalse, (void *) &appData.periodicUpdates, FALSE, INVALID },
302   { "popupExitMessage", ArgBoolean, (void *) &appData.popupExitMessage, TRUE, (ArgIniType) TRUE },
303   { "exit", ArgTrue, (void *) &appData.popupExitMessage, FALSE, INVALID },
304   { "xexit", ArgFalse, (void *) &appData.popupExitMessage, FALSE, INVALID },
305   { "-exit", ArgFalse, (void *) &appData.popupExitMessage, FALSE, INVALID },
306   { "popupMoveErrors", ArgBoolean, (void *) &appData.popupMoveErrors, TRUE, (ArgIniType) FALSE },
307   { "popup", ArgTrue, (void *) &appData.popupMoveErrors, FALSE, INVALID },
308   { "xpopup", ArgFalse, (void *) &appData.popupMoveErrors, FALSE, INVALID },
309   { "-popup", ArgFalse, (void *) &appData.popupMoveErrors, FALSE, INVALID },
310   { "popUpErrors", ArgBoolean, (void *) &appData.popupMoveErrors,
311     FALSE, INVALID }, /* only so that old WinBoard.ini files from betas can be read */
312   { "clockFont", ArgFont, (void *) CLOCK_FONT, TRUE, INVALID },
313   { "messageFont", ArgFont, (void *) MESSAGE_FONT, !XBOARD, INVALID },
314   { "font", ArgFont, (void *) MESSAGE_FONT, XBOARD, INVALID },
315   { "coordFont", ArgFont, (void *) COORD_FONT, TRUE, INVALID },
316   { "tagsFont", ArgFont, (void *) EDITTAGS_FONT, TRUE, INVALID },
317   { "commentFont", ArgFont, (void *) COMMENT_FONT, TRUE, INVALID },
318   { "icsFont", ArgFont, (void *) CONSOLE_FONT, TRUE, INVALID },
319   { "moveHistoryFont", ArgFont, (void *) MOVEHISTORY_FONT, TRUE, INVALID }, /* [AS] */
320   { "boardSize", ArgBoardSize, (void *) &boardSize,
321     TRUE, (ArgIniType) -1 }, /* must come after all fonts */
322   { "size", ArgBoardSize, (void *) &boardSize, FALSE, INVALID },
323   { "ringBellAfterMoves", ArgBoolean, (void *) &appData.ringBellAfterMoves,
324     FALSE, (ArgIniType) TRUE }, /* historical; kept only so old winboard.ini files will parse */
325   { "bell", ArgTrue, (void *) &appData.ringBellAfterMoves, FALSE, INVALID }, // for XB
326   { "xbell", ArgFalse, (void *) &appData.ringBellAfterMoves, FALSE, INVALID }, // for XB
327   { "movesound", ArgTrue, (void *) &appData.ringBellAfterMoves, FALSE, INVALID }, // for XB
328   { "xmovesound", ArgFalse, (void *) &appData.ringBellAfterMoves, FALSE, INVALID }, // for XB
329   { "alwaysOnTop", ArgBoolean, (void *) &alwaysOnTop, TRUE, INVALID },
330   { "top", ArgTrue, (void *) &alwaysOnTop, FALSE, INVALID },
331   { "xtop", ArgFalse, (void *) &alwaysOnTop, FALSE, INVALID },
332   { "-top", ArgFalse, (void *) &alwaysOnTop, FALSE, INVALID },
333   { "autoCallFlag", ArgBoolean, (void *) &appData.autoCallFlag, TRUE, (ArgIniType) FALSE },
334   { "autoflag", ArgTrue, (void *) &appData.autoCallFlag, FALSE, INVALID },
335   { "xautoflag", ArgFalse, (void *) &appData.autoCallFlag, FALSE, INVALID },
336   { "-autoflag", ArgFalse, (void *) &appData.autoCallFlag, FALSE, INVALID },
337   { "autoComment", ArgBoolean, (void *) &appData.autoComment, TRUE, (ArgIniType) FALSE },
338   { "autocomm", ArgTrue, (void *) &appData.autoComment, FALSE, INVALID },
339   { "xautocomm", ArgFalse, (void *) &appData.autoComment, FALSE, INVALID },
340   { "-autocomm", ArgFalse, (void *) &appData.autoComment, FALSE, INVALID },
341   { "autoObserve", ArgBoolean, (void *) &appData.autoObserve, TRUE, (ArgIniType) FALSE },
342   { "autobs", ArgTrue, (void *) &appData.autoObserve, FALSE, INVALID },
343   { "xautobs", ArgFalse, (void *) &appData.autoObserve, FALSE, INVALID },
344   { "-autobs", ArgFalse, (void *) &appData.autoObserve, FALSE, INVALID },
345   { "flipView", ArgBoolean, (void *) &appData.flipView, FALSE, (ArgIniType) FALSE },
346   { "flip", ArgTrue, (void *) &appData.flipView, FALSE, INVALID },
347   { "xflip", ArgFalse, (void *) &appData.flipView, FALSE, INVALID },
348   { "-flip", ArgFalse, (void *) &appData.flipView, FALSE, INVALID },
349   { "autoFlipView", ArgBoolean, (void *) &appData.autoFlipView, TRUE, (ArgIniType) TRUE },
350   { "autoflip", ArgTrue, (void *) &appData.autoFlipView, FALSE, INVALID },
351   { "xautoflip", ArgFalse, (void *) &appData.autoFlipView, FALSE, INVALID },
352   { "-autoflip", ArgFalse, (void *) &appData.autoFlipView, FALSE, INVALID },
353   { "autoRaiseBoard", ArgBoolean, (void *) &appData.autoRaiseBoard, TRUE, (ArgIniType) TRUE },
354   { "autoraise", ArgTrue, (void *) &appData.autoRaiseBoard, FALSE, INVALID },
355   { "xautoraise", ArgFalse, (void *) &appData.autoRaiseBoard, FALSE, INVALID },
356   { "-autoraise", ArgFalse, (void *) &appData.autoRaiseBoard, FALSE, INVALID },
357   { "alwaysPromoteToQueen", ArgBoolean, (void *) &appData.alwaysPromoteToQueen, TRUE, (ArgIniType) FALSE },
358   { "queen", ArgTrue, (void *) &appData.alwaysPromoteToQueen, FALSE, INVALID },
359   { "xqueen", ArgFalse, (void *) &appData.alwaysPromoteToQueen, FALSE, INVALID },
360   { "-queen", ArgFalse, (void *) &appData.alwaysPromoteToQueen, FALSE, INVALID },
361   { "oldSaveStyle", ArgBoolean, (void *) &appData.oldSaveStyle, TRUE, (ArgIniType) FALSE },
362   { "oldsave", ArgTrue, (void *) &appData.oldSaveStyle, FALSE, INVALID },
363   { "xoldsave", ArgFalse, (void *) &appData.oldSaveStyle, FALSE, INVALID },
364   { "-oldsave", ArgFalse, (void *) &appData.oldSaveStyle, FALSE, INVALID },
365   { "quietPlay", ArgBoolean, (void *) &appData.quietPlay, TRUE, (ArgIniType) FALSE },
366   { "quiet", ArgTrue, (void *) &appData.quietPlay, FALSE, INVALID },
367   { "xquiet", ArgFalse, (void *) &appData.quietPlay, FALSE, INVALID },
368   { "-quiet", ArgFalse, (void *) &appData.quietPlay, FALSE, INVALID },
369   { "getMoveList", ArgBoolean, (void *) &appData.getMoveList, TRUE, (ArgIniType) TRUE },
370   { "moves", ArgTrue, (void *) &appData.getMoveList, FALSE, INVALID },
371   { "xmoves", ArgFalse, (void *) &appData.getMoveList, FALSE, INVALID },
372   { "-moves", ArgFalse, (void *) &appData.getMoveList, FALSE, INVALID },
373   { "testLegality", ArgBoolean, (void *) &appData.testLegality, TRUE, (ArgIniType) TRUE },
374   { "legal", ArgTrue, (void *) &appData.testLegality, FALSE, INVALID },
375   { "xlegal", ArgFalse, (void *) &appData.testLegality, FALSE, INVALID },
376   { "-legal", ArgFalse, (void *) &appData.testLegality, FALSE, INVALID },
377   { "premove", ArgBoolean, (void *) &appData.premove, TRUE, (ArgIniType) TRUE },
378   { "pre", ArgTrue, (void *) &appData.premove, FALSE, INVALID },
379   { "xpre", ArgFalse, (void *) &appData.premove, FALSE, INVALID },
380   { "-pre", ArgFalse, (void *) &appData.premove, FALSE, INVALID },
381   { "premoveWhite", ArgBoolean, (void *) &appData.premoveWhite, TRUE, (ArgIniType) FALSE },
382   { "prewhite", ArgTrue, (void *) &appData.premoveWhite, FALSE, INVALID },
383   { "xprewhite", ArgFalse, (void *) &appData.premoveWhite, FALSE, INVALID },
384   { "-prewhite", ArgFalse, (void *) &appData.premoveWhite, FALSE, INVALID },
385   { "premoveWhiteText", ArgString, (void *) &appData.premoveWhiteText, TRUE, (ArgIniType) "" },
386   { "premoveBlack", ArgBoolean, (void *) &appData.premoveBlack, TRUE, (ArgIniType) FALSE },
387   { "preblack", ArgTrue, (void *) &appData.premoveBlack, FALSE, INVALID },
388   { "xpreblack", ArgFalse, (void *) &appData.premoveBlack, FALSE, INVALID },
389   { "-preblack", ArgFalse, (void *) &appData.premoveBlack, FALSE, INVALID },
390   { "premoveBlackText", ArgString, (void *) &appData.premoveBlackText, TRUE, (ArgIniType) "" },
391   { "icsAlarm", ArgBoolean, (void *) &appData.icsAlarm, TRUE, (ArgIniType) TRUE},
392   { "alarm", ArgTrue, (void *) &appData.icsAlarm, FALSE},
393   { "xalarm", ArgFalse, (void *) &appData.icsAlarm, FALSE},
394   { "-alarm", ArgFalse, (void *) &appData.icsAlarm, FALSE},
395   { "icsAlarmTime", ArgInt, (void *) &appData.icsAlarmTime, TRUE, (ArgIniType) 5000},
396   { "localLineEditing", ArgBoolean, (void *) &appData.localLineEditing, FALSE, (ArgIniType) TRUE},
397   { "edit", ArgTrue, (void *) &appData.localLineEditing, FALSE, INVALID },
398   { "xedit", ArgFalse, (void *) &appData.localLineEditing, FALSE, INVALID },
399   { "-edit", ArgFalse, (void *) &appData.localLineEditing, FALSE, INVALID },
400   { "animateMoving", ArgBoolean, (void *) &appData.animate, TRUE, (ArgIniType) TRUE },
401   { "animate", ArgTrue, (void *) &appData.animate, FALSE, INVALID },
402   { "xanimate", ArgFalse, (void *) &appData.animate, FALSE, INVALID },
403   { "-animate", ArgFalse, (void *) &appData.animate, FALSE, INVALID },
404   { "animateSpeed", ArgInt, (void *) &appData.animSpeed, TRUE, (ArgIniType) 10 },
405   { "animateDragging", ArgBoolean, (void *) &appData.animateDragging, TRUE, (ArgIniType) TRUE },
406   { "drag", ArgTrue, (void *) &appData.animateDragging, FALSE, INVALID },
407   { "xdrag", ArgFalse, (void *) &appData.animateDragging, FALSE, INVALID },
408   { "-drag", ArgFalse, (void *) &appData.animateDragging, FALSE, INVALID },
409   { "blindfold", ArgBoolean, (void *) &appData.blindfold, TRUE, (ArgIniType) FALSE },
410   { "blind", ArgTrue, (void *) &appData.blindfold, FALSE, INVALID },
411   { "xblind", ArgFalse, (void *) &appData.blindfold, FALSE, INVALID },
412   { "-blind", ArgFalse, (void *) &appData.blindfold, FALSE, INVALID },
413   { "highlightLastMove", ArgBoolean,
414     (void *) &appData.highlightLastMove, TRUE, (ArgIniType) TRUE },
415   { "highlight", ArgTrue, (void *) &appData.highlightLastMove, FALSE, INVALID },
416   { "xhighlight", ArgFalse, (void *) &appData.highlightLastMove, FALSE, INVALID },
417   { "-highlight", ArgFalse, (void *) &appData.highlightLastMove, FALSE, INVALID },
418   { "highlightDragging", ArgBoolean,
419     (void *) &appData.highlightDragging, TRUE, INVALID },
420   { "highdrag", ArgTrue, (void *) &appData.highlightDragging, FALSE, INVALID },
421   { "xhighdrag", ArgFalse, (void *) &appData.highlightDragging, FALSE, INVALID },
422   { "-highdrag", ArgFalse, (void *) &appData.highlightDragging, FALSE, INVALID },
423   { "colorizeMessages", ArgBoolean, (void *) &appData.colorize, TRUE, (ArgIniType) TRUE },
424   { "colorize", ArgTrue, (void *) &appData.colorize, FALSE, INVALID },
425   { "xcolorize", ArgFalse, (void *) &appData.colorize, FALSE, INVALID },
426   { "-colorize", ArgFalse, (void *) &appData.colorize, FALSE, INVALID },
427   { "colorShout", ArgAttribs, (void *) ColorShout, TRUE, INVALID },
428   { "colorSShout", ArgAttribs, (void *) ColorSShout, TRUE, INVALID },
429   { "colorCShout", ArgAttribs, (void *) ColorSShout, FALSE, INVALID }, // for XB
430   { "colorChannel1", ArgAttribs, (void *) ColorChannel1, TRUE, INVALID },
431   { "colorChannel", ArgAttribs, (void *) ColorChannel, TRUE, INVALID },
432   { "colorKibitz", ArgAttribs, (void *) ColorKibitz, TRUE, INVALID },
433   { "colorTell", ArgAttribs, (void *) ColorTell, TRUE, INVALID },
434   { "colorChallenge", ArgAttribs, (void *) ColorChallenge, TRUE, INVALID },
435   { "colorRequest", ArgAttribs, (void *) ColorRequest, TRUE, INVALID },
436   { "colorSeek", ArgAttribs, (void *) ColorSeek, TRUE, INVALID },
437   { "colorNormal", ArgAttribs, (void *) ColorNormal, TRUE, INVALID },
438   { "colorBackground", ArgColor, (void *) 7, TRUE, COLOR_BKGD },
439   { "soundShout", ArgFilename, (void *) &appData.soundShout, TRUE, (ArgIniType) "" },
440   { "soundSShout", ArgFilename, (void *) &appData.soundSShout, TRUE, (ArgIniType) "" },
441   { "soundCShout", ArgFilename, (void *) &appData.soundSShout, FALSE, (ArgIniType) "" }, // for XB
442   { "soundChannel1", ArgFilename, (void *) &appData.soundChannel1, TRUE, (ArgIniType) "" },
443   { "soundChannel", ArgFilename, (void *) &appData.soundChannel, TRUE, (ArgIniType) "" },
444   { "soundKibitz", ArgFilename, (void *) &appData.soundKibitz, TRUE, (ArgIniType) "" },
445   { "soundTell", ArgFilename, (void *) &appData.soundTell, TRUE, (ArgIniType) "" },
446   { "soundChallenge", ArgFilename, (void *) &appData.soundChallenge, TRUE, (ArgIniType) "" },
447   { "soundRequest", ArgFilename, (void *) &appData.soundRequest, TRUE, (ArgIniType) "" },
448   { "soundSeek", ArgFilename, (void *) &appData.soundSeek, TRUE, (ArgIniType) "" },
449   { "soundMove", ArgFilename, (void *) &appData.soundMove, TRUE, (ArgIniType) "" },
450   { "soundBell", ArgFilename, (void *) &appData.soundBell, TRUE, (ArgIniType) SOUND_BELL },
451   { "soundIcsWin", ArgFilename, (void *) &appData.soundIcsWin, TRUE, (ArgIniType) "" },
452   { "soundIcsLoss", ArgFilename, (void *) &appData.soundIcsLoss, TRUE, (ArgIniType) "" },
453   { "soundIcsDraw", ArgFilename, (void *) &appData.soundIcsDraw, TRUE, (ArgIniType) "" },
454   { "soundIcsUnfinished", ArgFilename, (void *) &appData.soundIcsUnfinished, TRUE, (ArgIniType) "" },
455   { "soundIcsAlarm", ArgFilename, (void *) &appData.soundIcsAlarm, TRUE, (ArgIniType) "" },
456   { "reuseFirst", ArgBoolean, (void *) &appData.reuseFirst, FALSE, (ArgIniType) TRUE },
457   { "reuse", ArgTrue, (void *) &appData.reuseFirst, FALSE, INVALID },
458   { "xreuse", ArgFalse, (void *) &appData.reuseFirst, FALSE, INVALID },
459   { "-reuse", ArgFalse, (void *) &appData.reuseFirst, FALSE, INVALID },
460   { "reuseChessPrograms", ArgBoolean,
461     (void *) &appData.reuseFirst, FALSE, INVALID }, /* backward compat only */
462   { "reuseSecond", ArgBoolean, (void *) &appData.reuseSecond, FALSE, (ArgIniType) TRUE },
463   { "reuse2", ArgTrue, (void *) &appData.reuseSecond, FALSE, INVALID },
464   { "xreuse2", ArgFalse, (void *) &appData.reuseSecond, FALSE, INVALID },
465   { "-reuse2", ArgFalse, (void *) &appData.reuseSecond, FALSE, INVALID },
466   { "comPortSettings", ArgCommSettings, (void *) /*&dcb*/ 0, TRUE, INVALID },
467   { "settingsFile", ArgSettingsFilename, (void *) &settingsFileName, FALSE, (ArgIniType) SETTINGS_FILE },
468   { "ini", ArgSettingsFilename, (void *) &settingsFileName, FALSE, INVALID },
469   { "saveSettingsFile", ArgFilename, (void *) &settingsFileName, FALSE, INVALID },
470   { "saveSettingsOnExit", ArgBoolean, (void *) &saveSettingsOnExit, TRUE, (ArgIniType) TRUE },
471   { "chessProgram", ArgBoolean, (void *) &chessProgram, FALSE, (ArgIniType) FALSE },
472   { "cp", ArgTrue, (void *) &chessProgram, FALSE, INVALID },
473   { "xcp", ArgFalse, (void *) &chessProgram, FALSE, INVALID },
474   { "-cp", ArgFalse, (void *) &chessProgram, FALSE, INVALID },
475   { "icsMenu", ArgString, (void *) &icsTextMenuString, TRUE, (ArgIniType) ICS_TEXT_MENU_DEFAULT },
476   { "icsNames", ArgString, (void *) &icsNames, TRUE, (ArgIniType) ICS_NAMES },
477   { "firstChessProgramNames", ArgString, (void *) &firstChessProgramNames,
478     TRUE, (ArgIniType) FCP_NAMES },
479   { "secondChessProgramNames", ArgString, (void *) &secondChessProgramNames,
480     TRUE, (ArgIniType) SCP_NAMES },
481   { "initialMode", ArgString, (void *) &appData.initialMode, FALSE, (ArgIniType) "" },
482   { "mode", ArgString, (void *) &appData.initialMode, FALSE, INVALID },
483   { "variant", ArgString, (void *) &appData.variant, FALSE, (ArgIniType) "normal" },
484   { "firstProtocolVersion", ArgInt, (void *) &appData.firstProtocolVersion, FALSE, (ArgIniType) PROTOVER },
485   { "secondProtocolVersion", ArgInt, (void *) &appData.secondProtocolVersion,FALSE, (ArgIniType) PROTOVER },
486   { "showButtonBar", ArgBoolean, (void *) &appData.showButtonBar, TRUE, (ArgIniType) TRUE },
487   { "buttons", ArgTrue, (void *) &appData.showButtonBar, FALSE, INVALID },
488   { "xbuttons", ArgFalse, (void *) &appData.showButtonBar, FALSE, INVALID },
489   { "-buttons", ArgFalse, (void *) &appData.showButtonBar, FALSE, INVALID },
490
491   /* [AS] New features */
492   { "firstScoreAbs", ArgBoolean, (void *) &appData.firstScoreIsAbsolute, FALSE, (ArgIniType) FALSE },
493   { "secondScoreAbs", ArgBoolean, (void *) &appData.secondScoreIsAbsolute, FALSE, (ArgIniType) FALSE },
494   { "pgnExtendedInfo", ArgBoolean, (void *) &appData.saveExtendedInfoInPGN, TRUE, (ArgIniType) FALSE },
495   { "hideThinkingFromHuman", ArgBoolean, (void *) &appData.hideThinkingFromHuman, TRUE, (ArgIniType) FALSE },
496   { "liteBackTextureFile", ArgString, (void *) &appData.liteBackTextureFile, TRUE, (ArgIniType) "" },
497   { "darkBackTextureFile", ArgString, (void *) &appData.darkBackTextureFile, TRUE, (ArgIniType) "" },
498   { "liteBackTextureMode", ArgInt, (void *) &appData.liteBackTextureMode, TRUE, (ArgIniType) BACK_TEXTURE_MODE_PLAIN },
499   { "darkBackTextureMode", ArgInt, (void *) &appData.darkBackTextureMode, TRUE, (ArgIniType) BACK_TEXTURE_MODE_PLAIN },
500   { "renderPiecesWithFont", ArgString, (void *) &appData.renderPiecesWithFont, TRUE, (ArgIniType) "" },
501   { "fontPieceToCharTable", ArgString, (void *) &appData.fontToPieceTable, TRUE, (ArgIniType) "" },
502   { "fontPieceBackColorWhite", ArgColor, (void *) 8, TRUE, (ArgIniType) WHITE_PIECE_COLOR },
503   { "fontPieceForeColorWhite", ArgColor, (void *) 9, TRUE, (ArgIniType) WHITE_PIECE_COLOR },
504   { "fontPieceBackColorBlack", ArgColor, (void *) 10, TRUE, (ArgIniType) BLACK_PIECE_COLOR },
505   { "fontPieceForeColorBlack", ArgColor, (void *) 11, TRUE, (ArgIniType) BLACK_PIECE_COLOR },
506   { "fontPieceSize", ArgInt, (void *) &appData.fontPieceSize, TRUE, (ArgIniType) 80 },
507   { "overrideLineGap", ArgInt, (void *) &appData.overrideLineGap, TRUE, (ArgIniType) 1 },
508   { "adjudicateLossThreshold", ArgInt, (void *) &appData.adjudicateLossThreshold, TRUE, (ArgIniType) 0 },
509   { "delayBeforeQuit", ArgInt, (void *) &appData.delayBeforeQuit, TRUE, (ArgIniType) 0 },
510   { "delayAfterQuit", ArgInt, (void *) &appData.delayAfterQuit, TRUE, (ArgIniType) 0 },
511   { "nameOfDebugFile", ArgFilename, (void *) &appData.nameOfDebugFile, FALSE, (ArgIniType) DEBUG_FILE },
512   { "debugfile", ArgFilename, (void *) &appData.nameOfDebugFile, FALSE, INVALID },
513   { "pgnEventHeader", ArgString, (void *) &appData.pgnEventHeader, TRUE, (ArgIniType) "Computer Chess Game" },
514   { "defaultFrcPosition", ArgInt, (void *) &appData.defaultFrcPosition, TRUE, (ArgIniType) -1 },
515   { "shuffleOpenings", ArgTrue, (void *) &shuffleOpenings, FALSE, INVALID },
516   { "gameListTags", ArgString, (void *) &appData.gameListTags, TRUE, (ArgIniType) GLT_DEFAULT_TAGS },
517   { "saveOutOfBookInfo", ArgBoolean, (void *) &appData.saveOutOfBookInfo, TRUE, (ArgIniType) TRUE },
518   { "showEvalInMoveHistory", ArgBoolean, (void *) &appData.showEvalInMoveHistory, TRUE, (ArgIniType) TRUE },
519   { "evalHistColorWhite", ArgColor, (void *) 12, TRUE, (ArgIniType) "#FFFFB0" },
520   { "evalHistColorBlack", ArgColor, (void *) 13, TRUE, (ArgIniType) "#AD5D3D" },
521   { "highlightMoveWithArrow", ArgBoolean, (void *) &appData.highlightMoveWithArrow, TRUE, (ArgIniType) FALSE },
522   { "highlightArrowColor", ArgColor, (void *) 14, TRUE, (ArgIniType) "#FFFF80" },
523   { "stickyWindows", ArgBoolean, (void *) &appData.useStickyWindows, TRUE, (ArgIniType) TRUE },
524   { "adjudicateDrawMoves", ArgInt, (void *) &appData.adjudicateDrawMoves, TRUE, (ArgIniType) 0 },
525   { "autoDisplayComment", ArgBoolean, (void *) &appData.autoDisplayComment, TRUE, (ArgIniType) TRUE },
526   { "autoDisplayTags", ArgBoolean, (void *) &appData.autoDisplayTags, TRUE, (ArgIniType) TRUE },
527   { "firstIsUCI", ArgBoolean, (void *) &appData.firstIsUCI, FALSE, (ArgIniType) FALSE },
528   { "fUCI", ArgTrue, (void *) &appData.firstIsUCI, FALSE, INVALID },
529   { "firstUCI", ArgTrue, (void *) &appData.firstIsUCI, FALSE, INVALID },
530   { "secondIsUCI", ArgBoolean, (void *) &appData.secondIsUCI, FALSE, (ArgIniType) FALSE },
531   { "sUCI", ArgTrue, (void *) &appData.secondIsUCI, FALSE, INVALID },
532   { "secondUCI", ArgTrue, (void *) &appData.secondIsUCI, FALSE, INVALID },
533   { "firstHasOwnBookUCI", ArgBoolean, (void *) &appData.firstHasOwnBookUCI, FALSE, (ArgIniType) TRUE },
534   { "fNoOwnBookUCI", ArgFalse, (void *) &appData.firstHasOwnBookUCI, FALSE, INVALID },
535   { "firstXBook", ArgFalse, (void *) &appData.firstHasOwnBookUCI, FALSE, INVALID },
536   { "secondHasOwnBookUCI", ArgBoolean, (void *) &appData.secondHasOwnBookUCI, FALSE, (ArgIniType) TRUE },
537   { "sNoOwnBookUCI", ArgFalse, (void *) &appData.secondHasOwnBookUCI, FALSE, INVALID },
538   { "secondXBook", ArgFalse, (void *) &appData.secondHasOwnBookUCI, FALSE, INVALID },
539   { "adapterCommand", ArgFilename, (void *) &appData.adapterCommand, TRUE, (ArgIniType) "polyglot -noini -ec \"%fcp\" -ed \"%fd\"" },
540   { "polyglotDir", ArgFilename, (void *) &appData.polyglotDir, TRUE, (ArgIniType) "" },
541   { "usePolyglotBook", ArgBoolean, (void *) &appData.usePolyglotBook, TRUE, (ArgIniType) FALSE },
542   { "polyglotBook", ArgFilename, (void *) &appData.polyglotBook, TRUE, (ArgIniType) "" },
543   { "bookDepth", ArgInt, (void *) &appData.bookDepth, TRUE, (ArgIniType) 12 },
544   { "bookVariation", ArgInt, (void *) &appData.bookStrength, TRUE, (ArgIniType) 50 },
545   { "defaultHashSize", ArgInt, (void *) &appData.defaultHashSize, TRUE, (ArgIniType) 64 },
546   { "defaultCacheSizeEGTB", ArgInt, (void *) &appData.defaultCacheSizeEGTB, TRUE, (ArgIniType) 4 },
547   { "defaultPathEGTB", ArgFilename, (void *) &appData.defaultPathEGTB, TRUE, (ArgIniType) "c:\\egtb" },
548   { "language", ArgFilename, (void *) &appData.language, TRUE, (ArgIniType) "" },
549
550   /* [HGM] board-size, adjudication and misc. options */
551   { "oneClickMove", ArgBoolean, (void *) &appData.oneClick, TRUE, (ArgIniType) FALSE },
552   { "boardWidth", ArgInt, (void *) &appData.NrFiles, FALSE, (ArgIniType) -1 },
553   { "boardHeight", ArgInt, (void *) &appData.NrRanks, FALSE, (ArgIniType) -1 },
554   { "holdingsSize", ArgInt, (void *) &appData.holdingsSize, FALSE, (ArgIniType) -1 },
555   { "defaultMatchGames", ArgInt, (void *) &appData.defaultMatchGames, TRUE, (ArgIniType) 10 },
556   { "matchPause", ArgInt, (void *) &appData.matchPause, TRUE, (ArgIniType) 10000 },
557   { "pieceToCharTable", ArgString, (void *) &appData.pieceToCharTable, FALSE, INVALID },
558   { "pieceNickNames", ArgString, (void *) &appData.pieceNickNames, FALSE, INVALID },
559   { "colorNickNames", ArgString, (void *) &appData.colorNickNames, FALSE, INVALID },
560   { "flipBlack", ArgBoolean, (void *) &appData.upsideDown, TRUE, (ArgIniType) FALSE },
561   { "allWhite", ArgBoolean, (void *) &appData.allWhite, TRUE, (ArgIniType) FALSE },
562   { "alphaRank", ArgBoolean, (void *) &appData.alphaRank, FALSE, (ArgIniType) FALSE },
563   { "firstAlphaRank", ArgBoolean, (void *) &first.alphaRank, FALSE, (ArgIniType) FALSE },
564   { "secondAlphaRank", ArgBoolean, (void *) &second.alphaRank, FALSE, (ArgIniType) FALSE },
565   { "testClaims", ArgBoolean, (void *) &appData.testClaims, TRUE, (ArgIniType) FALSE },
566   { "checkMates", ArgBoolean, (void *) &appData.checkMates, TRUE, (ArgIniType) FALSE },
567   { "materialDraws", ArgBoolean, (void *) &appData.materialDraws, TRUE, (ArgIniType) FALSE },
568   { "trivialDraws", ArgBoolean, (void *) &appData.trivialDraws, TRUE, (ArgIniType) FALSE },
569   { "ruleMoves", ArgInt, (void *) &appData.ruleMoves, TRUE, (ArgIniType) 51 },
570   { "repeatsToDraw", ArgInt, (void *) &appData.drawRepeats, TRUE, (ArgIniType) 6 },
571   { "backgroundObserve", ArgBoolean, (void *) &appData.bgObserve, TRUE, (ArgIniType) FALSE },
572   { "dualBoard", ArgBoolean, (void *) &appData.dualBoard, TRUE, (ArgIniType) FALSE },
573   { "autoKibitz", ArgTrue, (void *) &appData.autoKibitz, FALSE, INVALID },
574   { "engineDebugOutput", ArgInt, (void *) &appData.engineComments, FALSE, (ArgIniType) 1 },
575   { "userName", ArgString, (void *) &appData.userName, FALSE, INVALID },
576   { "rewindIndex", ArgInt, (void *) &appData.rewindIndex, FALSE, INVALID },
577   { "sameColorGames", ArgInt, (void *) &appData.sameColorGames, FALSE, INVALID },
578   { "smpCores", ArgInt, (void *) &appData.smpCores, TRUE, (ArgIniType) 1 },
579   { "egtFormats", ArgString, (void *) &appData.egtFormats, TRUE, (ArgIniType) "" },
580   { "niceEngines", ArgInt, (void *) &appData.niceEngines, TRUE, INVALID },
581   { "firstLogo", ArgFilename, (void *) &appData.firstLogo, FALSE, INVALID },
582   { "secondLogo", ArgFilename, (void *) &appData.secondLogo, FALSE, INVALID },
583   { "autoLogo", ArgBoolean, (void *) &appData.autoLogo, TRUE, INVALID },
584   { "firstOptions", ArgString, (void *) &appData.firstOptions, FALSE, (ArgIniType) "" },
585   { "secondOptions", ArgString, (void *) &appData.secondOptions, FALSE, (ArgIniType) "" },
586   { "firstNeedsNoncompliantFEN", ArgString, (void *) &appData.fenOverride1, FALSE, (ArgIniType) NULL },
587   { "secondNeedsNoncompliantFEN", ArgString, (void *) &appData.fenOverride2, FALSE, (ArgIniType) NULL },
588   { "keepAlive", ArgInt, (void *) &appData.keepAlive, FALSE, INVALID },
589   { "icstype", ArgInt, (void *) &ics_type, FALSE, INVALID },
590   { "forceIllegalMoves", ArgTrue, (void *) &appData.forceIllegal, FALSE, INVALID },
591   { "showTargetSquares", ArgBoolean, (void *) &appData.markers, TRUE, FALSE },
592
593 #if ZIPPY
594   { "zippyTalk", ArgBoolean, (void *) &appData.zippyTalk, FALSE, (ArgIniType) ZIPPY_TALK },
595   { "zt", ArgTrue, (void *) &appData.zippyTalk, FALSE, INVALID },
596   { "xzt", ArgFalse, (void *) &appData.zippyTalk, FALSE, INVALID },
597   { "-zt", ArgFalse, (void *) &appData.zippyTalk, FALSE, INVALID },
598   { "zippyPlay", ArgBoolean, (void *) &appData.zippyPlay, FALSE, (ArgIniType) ZIPPY_PLAY },
599   { "zp", ArgTrue, (void *) &appData.zippyPlay, FALSE, INVALID },
600   { "xzp", ArgFalse, (void *) &appData.zippyPlay, FALSE, INVALID },
601   { "-zp", ArgFalse, (void *) &appData.zippyPlay, FALSE, INVALID },
602   { "zippyLines", ArgFilename, (void *) &appData.zippyLines, FALSE, (ArgIniType) ZIPPY_LINES },
603   { "zippyPinhead", ArgString, (void *) &appData.zippyPinhead, FALSE, (ArgIniType) ZIPPY_PINHEAD },
604   { "zippyPassword", ArgString, (void *) &appData.zippyPassword, FALSE, (ArgIniType) ZIPPY_PASSWORD },
605   { "zippyPassword2", ArgString, (void *) &appData.zippyPassword2, FALSE, (ArgIniType) ZIPPY_PASSWORD2 },
606   { "zippyWrongPassword", ArgString, (void *) &appData.zippyWrongPassword,
607     FALSE, (ArgIniType) ZIPPY_WRONG_PASSWORD },
608   { "zippyAcceptOnly", ArgString, (void *) &appData.zippyAcceptOnly, FALSE, (ArgIniType) ZIPPY_ACCEPT_ONLY },
609   { "zippyUseI", ArgBoolean, (void *) &appData.zippyUseI, FALSE, (ArgIniType) ZIPPY_USE_I },
610   { "zui", ArgTrue, (void *) &appData.zippyUseI, FALSE, INVALID },
611   { "xzui", ArgFalse, (void *) &appData.zippyUseI, FALSE, INVALID },
612   { "-zui", ArgFalse, (void *) &appData.zippyUseI, FALSE, INVALID },
613   { "zippyBughouse", ArgInt, (void *) &appData.zippyBughouse, FALSE, (ArgIniType) ZIPPY_BUGHOUSE },
614   { "zippyNoplayCrafty", ArgBoolean, (void *) &appData.zippyNoplayCrafty,
615     FALSE, (ArgIniType) ZIPPY_NOPLAY_CRAFTY },
616   { "znc", ArgTrue, (void *) &appData.zippyNoplayCrafty, FALSE, INVALID },
617   { "xznc", ArgFalse, (void *) &appData.zippyNoplayCrafty, FALSE, INVALID },
618   { "-znc", ArgFalse, (void *) &appData.zippyNoplayCrafty, FALSE, INVALID },
619   { "zippyGameEnd", ArgString, (void *) &appData.zippyGameEnd, FALSE, (ArgIniType) ZIPPY_GAME_END },
620   { "zippyGameStart", ArgString, (void *) &appData.zippyGameStart, FALSE, (ArgIniType) ZIPPY_GAME_START },
621   { "zippyAdjourn", ArgBoolean, (void *) &appData.zippyAdjourn, FALSE, (ArgIniType) ZIPPY_ADJOURN },
622   { "zadj", ArgTrue, (void *) &appData.zippyAdjourn, FALSE, INVALID },
623   { "xzadj", ArgFalse, (void *) &appData.zippyAdjourn, FALSE, INVALID },
624   { "-zadj", ArgFalse, (void *) &appData.zippyAdjourn, FALSE, INVALID },
625   { "zippyAbort", ArgBoolean, (void *) &appData.zippyAbort, FALSE, (ArgIniType) ZIPPY_ABORT },
626   { "zab", ArgTrue, (void *) &appData.zippyAbort, FALSE, INVALID },
627   { "xzab", ArgFalse, (void *) &appData.zippyAbort, FALSE, INVALID },
628   { "-zab", ArgFalse, (void *) &appData.zippyAbort, FALSE, INVALID },
629   { "zippyVariants", ArgString, (void *) &appData.zippyVariants, FALSE, (ArgIniType) ZIPPY_VARIANTS },
630   { "zippyMaxGames", ArgInt, (void *)&appData.zippyMaxGames, FALSE, (ArgIniType) ZIPPY_MAX_GAMES},
631   { "zippyReplayTimeout", ArgInt, (void *)&appData.zippyReplayTimeout, FALSE, (ArgIniType) ZIPPY_REPLAY_TIMEOUT },
632   { "zippyShortGame", ArgInt, (void *)&appData.zippyShortGame, FALSE, INVALID },
633   /* Kludge to allow winboard.ini files from buggy 4.0.4 to be read: */
634   { "zippyReplyTimeout", ArgInt, (void *)&junk, FALSE, INVALID },
635 #endif
636   /* [HGM] options for broadcasting and time odds */
637   { "chatBoxes", ArgString, (void *) &appData.chatBoxes, !XBOARD, (ArgIniType) NULL },
638   { "serverMoves", ArgString, (void *) &appData.serverMovesName, FALSE, (ArgIniType) NULL },
639   { "suppressLoadMoves", ArgBoolean, (void *) &appData.suppressLoadMoves, FALSE, (ArgIniType) FALSE },
640   { "serverPause", ArgInt, (void *) &appData.serverPause, FALSE, (ArgIniType) 15 },
641   { "firstTimeOdds", ArgInt, (void *) &appData.firstTimeOdds, FALSE, (ArgIniType) 1 },
642   { "secondTimeOdds", ArgInt, (void *) &appData.secondTimeOdds, FALSE, (ArgIniType) 1 },
643   { "timeOddsMode", ArgInt, (void *) &appData.timeOddsMode, TRUE, INVALID },
644   { "firstAccumulateTC", ArgInt, (void *) &appData.firstAccumulateTC, FALSE, (ArgIniType) 1 },
645   { "secondAccumulateTC", ArgInt, (void *) &appData.secondAccumulateTC, FALSE, (ArgIniType) 1 },
646   { "firstNPS", ArgInt, (void *) &appData.firstNPS, FALSE, (ArgIniType) -1 },
647   { "secondNPS", ArgInt, (void *) &appData.secondNPS, FALSE, (ArgIniType) -1 },
648   { "noGUI", ArgTrue, (void *) &appData.noGUI, FALSE, INVALID },
649   { "keepLineBreaksICS", ArgBoolean, (void *) &appData.noJoin, TRUE, INVALID },
650   { "wrapContinuationSequence", ArgString, (void *) &appData.wrapContSeq, FALSE, INVALID },
651   { "useInternalWrap", ArgTrue, (void *) &appData.useInternalWrap, FALSE, INVALID }, /* noJoin usurps this if set */
652
653   // [HGM] placement: put all window layouts last in ini file, but man X,Y before all others
654   { "minX", ArgZ, (void *) &minX, FALSE, INVALID }, // [HGM] placement: to make suer auxialary windows can be placed
655   { "minY", ArgZ, (void *) &minY, FALSE, INVALID },
656   { "winWidth",  ArgInt, (void *) &wpMain.width,  TRUE, INVALID }, // [HGM] placement: dummies to remember right & bottom
657   { "winHeight", ArgInt, (void *) &wpMain.height, TRUE, INVALID }, //       for attaching auxiliary windows to them
658   { "x", ArgInt, (void *) &wpMain.x, TRUE, (ArgIniType) CW_USEDEFAULT },
659   { "y", ArgInt, (void *) &wpMain.y, TRUE, (ArgIniType) CW_USEDEFAULT },
660   { "icsX", ArgX,   (void *) &wpConsole.x, TRUE, (ArgIniType) CW_USEDEFAULT },
661   { "icsY", ArgY,   (void *) &wpConsole.y, TRUE, (ArgIniType) CW_USEDEFAULT },
662   { "icsW", ArgInt, (void *) &wpConsole.width, TRUE, (ArgIniType) CW_USEDEFAULT },
663   { "icsH", ArgInt, (void *) &wpConsole.height, TRUE, (ArgIniType) CW_USEDEFAULT },
664   { "analysisX", ArgX,   (void *) &junk, FALSE, INVALID }, // [HGM] placement: analysis window no longer exists
665   { "analysisY", ArgY,   (void *) &junk, FALSE, INVALID }, //       provided for compatibility with old ini files
666   { "analysisW", ArgInt, (void *) &junk, FALSE, INVALID },
667   { "analysisH", ArgInt, (void *) &junk, FALSE, INVALID },
668   { "commentX", ArgX,   (void *) &wpComment.x, TRUE, (ArgIniType) CW_USEDEFAULT },
669   { "commentY", ArgY,   (void *) &wpComment.y, TRUE, (ArgIniType) CW_USEDEFAULT },
670   { "commentW", ArgInt, (void *) &wpComment.width, TRUE, (ArgIniType) CW_USEDEFAULT },
671   { "commentH", ArgInt, (void *) &wpComment.height, TRUE, (ArgIniType) CW_USEDEFAULT },
672   { "tagsX", ArgX,   (void *) &wpTags.x, TRUE, (ArgIniType) CW_USEDEFAULT },
673   { "tagsY", ArgY,   (void *) &wpTags.y, TRUE, (ArgIniType) CW_USEDEFAULT },
674   { "tagsW", ArgInt, (void *) &wpTags.width, TRUE, (ArgIniType) CW_USEDEFAULT },
675   { "tagsH", ArgInt, (void *) &wpTags.height, TRUE, (ArgIniType) CW_USEDEFAULT },
676   { "gameListX", ArgX,   (void *) &wpGameList.x, TRUE, (ArgIniType) CW_USEDEFAULT },
677   { "gameListY", ArgY,   (void *) &wpGameList.y, TRUE, (ArgIniType) CW_USEDEFAULT },
678   { "gameListW", ArgInt, (void *) &wpGameList.width, TRUE, (ArgIniType) CW_USEDEFAULT },
679   { "gameListH", ArgInt, (void *) &wpGameList.height, TRUE, (ArgIniType) CW_USEDEFAULT },
680   /* [AS] Layout stuff */
681   { "moveHistoryUp", ArgBoolean, (void *) &wpMoveHistory.visible, TRUE, (ArgIniType) TRUE },
682   { "moveHistoryX", ArgX,   (void *) &wpMoveHistory.x, TRUE, (ArgIniType) CW_USEDEFAULT },
683   { "moveHistoryY", ArgY,   (void *) &wpMoveHistory.y, TRUE, (ArgIniType) CW_USEDEFAULT },
684   { "moveHistoryW", ArgInt, (void *) &wpMoveHistory.width, TRUE, (ArgIniType) CW_USEDEFAULT },
685   { "moveHistoryH", ArgInt, (void *) &wpMoveHistory.height, TRUE, (ArgIniType) CW_USEDEFAULT },
686
687   { "evalGraphUp", ArgBoolean, (void *) &wpEvalGraph.visible, TRUE, (ArgIniType) TRUE },
688   { "evalGraphX", ArgX,   (void *) &wpEvalGraph.x, TRUE, (ArgIniType) CW_USEDEFAULT },
689   { "evalGraphY", ArgY,   (void *) &wpEvalGraph.y, TRUE, (ArgIniType) CW_USEDEFAULT },
690   { "evalGraphW", ArgInt, (void *) &wpEvalGraph.width, TRUE, (ArgIniType) CW_USEDEFAULT },
691   { "evalGraphH", ArgInt, (void *) &wpEvalGraph.height, TRUE, (ArgIniType) CW_USEDEFAULT },
692
693   { "engineOutputUp", ArgBoolean, (void *) &wpEngineOutput.visible, TRUE, (ArgIniType) TRUE },
694   { "engineOutputX", ArgX,   (void *) &wpEngineOutput.x, TRUE, (ArgIniType) CW_USEDEFAULT },
695   { "engineOutputY", ArgY,   (void *) &wpEngineOutput.y, TRUE, (ArgIniType) CW_USEDEFAULT },
696   { "engineOutputW", ArgInt, (void *) &wpEngineOutput.width, TRUE, (ArgIniType) CW_USEDEFAULT },
697   { "engineOutputH", ArgInt, (void *) &wpEngineOutput.height, TRUE, (ArgIniType) CW_USEDEFAULT },
698
699   { NULL, ArgNone, NULL, FALSE, INVALID }
700 };
701
702
703 /* Kludge for indirection files on command line */
704 char* lastIndirectionFilename;
705 ArgDescriptor argDescriptorIndirection =
706 { "", ArgSettingsFilename, (void *) NULL, FALSE };
707
708 void
709 ExitArgError(char *msg, char *badArg)
710 {
711   char buf[MSG_SIZ];
712   int len;
713
714   len = snprintf(buf,MSG_SIZ, "%s %s", msg, badArg);
715   if( (len > MSG_SIZ) && appData.debugMode )
716     fprintf(debugFP, "ExitArgError: buffer truncated. Input: msg=%s badArg=%s\n", msg, badArg);
717
718   DisplayFatalError(buf, 0, 2);
719   exit(2);
720 }
721
722 int
723 ValidateInt(char *s)
724 {
725   char *p = s;
726   if(*p == '-' || *p == '+') p++;
727   while(*p) if(!isdigit(*p++)) ExitArgError("Bad integer value", s);
728   return atoi(s);
729 }
730
731 char
732 StringGet(void *getClosure)
733 {
734   char **p = (char **) getClosure;
735   return *((*p)++);
736 }
737
738 char
739 FileGet(void *getClosure)
740 {
741   int c;
742   FILE* f = (FILE*) getClosure;
743
744   c = getc(f);
745   if (c == '\r') c = getc(f); // work around DOS format files by bypassing the '\r' completely
746   if (c == EOF)
747     return NULLCHAR;
748   else
749     return (char) c;
750 }
751
752 /* Parse settings file named "name". If file found, return the
753    full name in fullname and return TRUE; else return FALSE */
754 Boolean
755 ParseSettingsFile(char *name, char **addr)
756 {
757   FILE *f;
758   int ok,len;
759   char buf[MSG_SIZ], fullname[MSG_SIZ];
760
761
762   ok = MySearchPath(installDir, name, fullname);
763   if(!ok && strchr(name, '.') == NULL)
764     { // append default file-name extension '.ini' when needed
765       len = snprintf(buf,MSG_SIZ, "%s.ini", name);
766       if( (len > MSG_SIZ) && appData.debugMode )
767         fprintf(debugFP, "ParseSettingsFile: buffer truncated. Input: name=%s \n",name);
768
769       ok = MySearchPath(installDir, buf, fullname);
770     }
771   if (ok) {
772     f = fopen(fullname, "r");
773     if (f != NULL) {
774       if (addr != NULL) {
775             *addr = strdup(fullname);
776       }
777       ParseArgs(FileGet, f);
778       fclose(f);
779       return TRUE;
780     }
781   }
782   return FALSE;
783 }
784
785 void
786 ParseArgs(GetFunc get, void *cl)
787 {
788   char argName[MAX_ARG_LEN];
789   char argValue[MAX_ARG_LEN];
790   ArgDescriptor *ad;
791   char start;
792   char *q;
793   int i, octval;
794   char ch;
795   int posarg = 0;
796
797   ch = get(cl);
798   for (;;) {
799     while (ch == ' ' || ch == '\n' || ch == '\t') ch = get(cl);
800     if (ch == NULLCHAR) break;
801     if (ch == ';') {
802       /* Comment to end of line */
803       ch = get(cl);
804       while (ch != '\n' && ch != NULLCHAR) ch = get(cl);
805       continue;
806     } else if (ch == '/' || ch == '-') {
807       /* Switch */
808       q = argName;
809       while (ch != ' ' && ch != '=' && ch != ':' && ch != NULLCHAR &&
810              ch != '\n' && ch != '\t') {
811         *q++ = ch;
812         ch = get(cl);
813       }
814       *q = NULLCHAR;
815
816       for (ad = argDescriptors; ad->argName != NULL; ad++)
817         if (strcmp(ad->argName, argName + 1) == 0) break;
818
819       if (ad->argName == NULL)
820         ExitArgError("Unrecognized argument", argName);
821
822     } else if (ch == '@') {
823       /* Indirection file */
824       ad = &argDescriptorIndirection;
825       ch = get(cl);
826     } else {
827       /* Positional argument */
828       ad = &argDescriptors[posarg++];
829       strncpy(argName, ad->argName,sizeof(argName)/sizeof(argName[0]));
830     }
831
832     if (ad->argType == ArgTrue) {
833       *(Boolean *) ad->argLoc = TRUE;
834       continue;
835     }
836     if (ad->argType == ArgFalse) {
837       *(Boolean *) ad->argLoc = FALSE;
838       continue;
839     }
840
841     while (ch == ' ' || ch == '=' || ch == ':' || ch == '\t') ch = get(cl);
842     if (ch == NULLCHAR || ch == '\n') {
843       ExitArgError("No value provided for argument", argName);
844     }
845     q = argValue;
846     if (ch == '{') {
847       // Quoting with { }.  No characters have to (or can) be escaped.
848       // Thus the string cannot contain a '}' character.
849       start = ch;
850       ch = get(cl);
851       while (start) {
852         switch (ch) {
853         case NULLCHAR:
854           start = NULLCHAR;
855           break;
856
857         case '}':
858           ch = get(cl);
859           start = NULLCHAR;
860           break;
861
862         default:
863           *q++ = ch;
864           ch = get(cl);
865           break;
866         }
867       }
868     } else if (ch == '\'' || ch == '"') {
869       // Quoting with ' ' or " ", with \ as escape character.
870       // Inconvenient for long strings that may contain Windows filenames.
871       start = ch;
872       ch = get(cl);
873       while (start) {
874         switch (ch) {
875         case NULLCHAR:
876           start = NULLCHAR;
877           break;
878
879         default:
880         not_special:
881           *q++ = ch;
882           ch = get(cl);
883           break;
884
885         case '\'':
886         case '\"':
887           if (ch == start) {
888             ch = get(cl);
889             start = NULLCHAR;
890             break;
891           } else {
892             goto not_special;
893           }
894
895         case '\\':
896           if (ad->argType == ArgFilename
897               || ad->argType == ArgSettingsFilename) {
898               goto not_special;
899           }
900           ch = get(cl);
901           switch (ch) {
902           case NULLCHAR:
903             ExitArgError("Incomplete \\ escape in value for", argName);
904             break;
905           case 'n':
906             *q++ = '\n';
907             ch = get(cl);
908             break;
909           case 'r':
910             *q++ = '\r';
911             ch = get(cl);
912             break;
913           case 't':
914             *q++ = '\t';
915             ch = get(cl);
916             break;
917           case 'b':
918             *q++ = '\b';
919             ch = get(cl);
920             break;
921           case 'f':
922             *q++ = '\f';
923             ch = get(cl);
924             break;
925           default:
926             octval = 0;
927             for (i = 0; i < 3; i++) {
928               if (ch >= '0' && ch <= '7') {
929                 octval = octval*8 + (ch - '0');
930                 ch = get(cl);
931               } else {
932                 break;
933               }
934             }
935             if (i > 0) {
936               *q++ = (char) octval;
937             } else {
938               *q++ = ch;
939               ch = get(cl);
940             }
941             break;
942           }
943           break;
944         }
945       }
946     } else {
947       while (ch != ' ' && ch != NULLCHAR && ch != '\t' && ch != '\n') {
948         *q++ = ch;
949         ch = get(cl);
950       }
951     }
952     *q = NULLCHAR;
953
954     switch (ad->argType) {
955     case ArgInt:
956       *(int *) ad->argLoc = ValidateInt(argValue);
957       break;
958
959     case ArgX:
960       *(int *) ad->argLoc = ValidateInt(argValue) + wpMain.x; // [HGM] placement: translate stored relative to absolute
961       break;
962
963     case ArgY:
964       *(int *) ad->argLoc = ValidateInt(argValue) + wpMain.y; // (this is really kludgey, it should be done where used...)
965       break;
966
967     case ArgZ:
968       *(int *) ad->argLoc = ValidateInt(argValue);
969       EnsureOnScreen(&wpMain.x, &wpMain.y, minX, minY);
970       break;
971
972     case ArgFloat:
973       *(float *) ad->argLoc = (float) atof(argValue);
974       break;
975
976     case ArgString:
977     case ArgFilename:
978       *(char **) ad->argLoc = strdup(argValue);
979       break;
980
981     case ArgSettingsFilename:
982       {
983         if (ParseSettingsFile(argValue, (char**)ad->argLoc)) {
984         } else {
985           if (ad->argLoc != NULL) {
986           } else {
987             ExitArgError("Failed to open indirection file", argValue);
988           }
989         }
990       }
991       break;
992
993     case ArgBoolean:
994       switch (argValue[0]) {
995       case 't':
996       case 'T':
997         *(Boolean *) ad->argLoc = TRUE;
998         break;
999       case 'f':
1000       case 'F':
1001         *(Boolean *) ad->argLoc = FALSE;
1002         break;
1003       default:
1004         ExitArgError("Unrecognized boolean argument value", argValue);
1005         break;
1006       }
1007       break;
1008
1009     case ArgColor:
1010       ParseColor((int)ad->argLoc, argValue);
1011       break;
1012
1013     case ArgAttribs: {
1014       ColorClass cc = (ColorClass)ad->argLoc;
1015         ParseTextAttribs(cc, argValue); // [HGM] wrapper for platform independency
1016       }
1017       break;
1018
1019     case ArgBoardSize:
1020       ParseBoardSize(ad->argLoc, argValue);
1021       break;
1022
1023     case ArgFont:
1024       ParseFont(argValue, (int)ad->argLoc);
1025       break;
1026
1027     case ArgCommSettings:
1028       ParseCommPortSettings(argValue);
1029       break;
1030
1031     case ArgNone:
1032       ExitArgError("Unrecognized argument", argValue);
1033       break;
1034     case ArgTrue:
1035     case ArgFalse: ;
1036     }
1037   }
1038 }
1039
1040 void
1041 ParseIcsTextMenu(char *icsTextMenuString)
1042 {
1043 //  int flags = 0;
1044   IcsTextMenuEntry *e = icsTextMenuEntry;
1045   char *p = icsTextMenuString;
1046   while (e->item != NULL && e < icsTextMenuEntry + ICS_TEXT_MENU_SIZE) {
1047     free(e->item);
1048     e->item = NULL;
1049     if (e->command != NULL) {
1050       free(e->command);
1051       e->command = NULL;
1052     }
1053     e++;
1054   }
1055   e = icsTextMenuEntry;
1056   while (*p && e < icsTextMenuEntry + ICS_TEXT_MENU_SIZE) {
1057     if (*p == ';' || *p == '\n') {
1058       e->item = strdup("-");
1059       e->command = NULL;
1060       p++;
1061     } else if (*p == '-') {
1062       e->item = strdup("-");
1063       e->command = NULL;
1064       p++;
1065       if (*p) p++;
1066     } else {
1067       char *q, *r, *s, *t;
1068       char c;
1069       q = strchr(p, ',');
1070       if (q == NULL) break;
1071       *q = NULLCHAR;
1072       r = strchr(q + 1, ',');
1073       if (r == NULL) break;
1074       *r = NULLCHAR;
1075       s = strchr(r + 1, ',');
1076       if (s == NULL) break;
1077       *s = NULLCHAR;
1078       c = ';';
1079       t = strchr(s + 1, c);
1080       if (t == NULL) {
1081         c = '\n';
1082         t = strchr(s + 1, c);
1083       }
1084       if (t != NULL) *t = NULLCHAR;
1085       e->item = strdup(p);
1086       e->command = strdup(q + 1);
1087       e->getname = *(r + 1) != '0';
1088       e->immediate = *(s + 1) != '0';
1089       *q = ',';
1090       *r = ',';
1091       *s = ',';
1092       if (t == NULL) break;
1093       *t = c;
1094       p = t + 1;
1095     }
1096     e++;
1097   }
1098 }
1099
1100 void
1101 SetDefaultTextAttribs()
1102 {
1103   ColorClass cc;
1104   for (cc = (ColorClass)0; cc < ColorNone; cc++) {
1105     ParseTextAttribs(cc, defaultTextAttribs[cc]);
1106   }
1107 }
1108
1109 void
1110 SetDefaultsFromList()
1111 { // [HGM] ini: take defaults from argDescriptor list
1112   int i;
1113
1114   for(i=0; argDescriptors[i].argName != NULL; i++) {
1115     if(argDescriptors[i].defaultValue != INVALID)
1116       switch(argDescriptors[i].argType) {
1117         case ArgBoolean:
1118         case ArgTrue:
1119         case ArgFalse:
1120           *(Boolean *) argDescriptors[i].argLoc = (int)argDescriptors[i].defaultValue;
1121           break;
1122         case ArgInt:
1123         case ArgX:
1124         case ArgY:
1125         case ArgZ:
1126           *(int *) argDescriptors[i].argLoc = (int)argDescriptors[i].defaultValue;
1127           break;
1128         case ArgString:
1129         case ArgFilename:
1130         case ArgSettingsFilename:
1131           *(char **) argDescriptors[i].argLoc = (char *)argDescriptors[i].defaultValue;
1132           break;
1133         case ArgBoardSize:
1134           *(int *) argDescriptors[i].argLoc = (int)argDescriptors[i].defaultValue;
1135           break;
1136         case ArgColor:
1137           ParseColor((int)argDescriptors[i].argLoc, (char*)argDescriptors[i].defaultValue);
1138           break;
1139         case ArgFloat: // floats cannot be casted to int without precision loss
1140         default: ; // some arg types cannot be initialized through table
1141     }
1142   }
1143 }
1144
1145 void
1146 InitAppData(char *lpCmdLine)
1147 {
1148   int i;
1149   char buf[MAX_ARG_LEN], currDir[MSG_SIZ];
1150   char *p;
1151
1152   /* Initialize to defaults */
1153   SetDefaultsFromList(); // this sets most defaults
1154
1155   // some parameters for which there are no options!
1156   appData.Iconic = FALSE; /*unused*/
1157   appData.icsEngineAnalyze = FALSE;
1158
1159   // float: casting to int is not harmless, so default cannot be contained in table
1160   appData.timeDelay = TIME_DELAY;
1161
1162   // some complex, platform-dependent stuff that could not be handled from table
1163   SetDefaultTextAttribs();
1164   SetFontDefaults();
1165   SetCommPortDefaults();
1166
1167   /* Parse default settings file if any */
1168   ParseSettingsFile(settingsFileName, &settingsFileName);
1169
1170   /* Parse command line */
1171   ParseArgs(StringGet, &lpCmdLine);
1172
1173   /* [HGM] make sure board size is acceptable */
1174   if(appData.NrFiles > BOARD_FILES ||
1175      appData.NrRanks > BOARD_RANKS   )
1176       DisplayFatalError("Recompile with BOARD_RANKS or BOARD_FILES, to support this size", 0, 2);
1177
1178   /* [HGM] After parsing the options from the .ini file, and overruling them
1179    * with options from the command line, we now make an even higher priority
1180    * overrule by WB options attached to the engine command line. This so that
1181    * tournament managers can use WB options (such as /timeOdds) that follow
1182    * the engines.
1183    */
1184   if(appData.firstChessProgram != NULL) {
1185       char *p = StrStr(appData.firstChessProgram, "WBopt");
1186       static char *f = "first";
1187       char buf[MSG_SIZ], *q = buf;
1188       int len;
1189
1190       if(p != NULL)
1191         { // engine command line contains WinBoard options
1192           len = snprintf(buf, MSG_SIZ, p+6, f, f, f, f, f, f, f, f, f, f); // replace %s in them by "first"
1193           if( (len > MSG_SIZ) && appData.debugMode )
1194             fprintf(debugFP, "InitAppData: buffer truncated.\n");
1195
1196           ParseArgs(StringGet, &q);
1197           p[-1] = 0; // cut them offengine command line
1198         }
1199   }
1200   // now do same for second chess program
1201   if(appData.secondChessProgram != NULL) {
1202       char *p = StrStr(appData.secondChessProgram, "WBopt");
1203       static char *s = "second";
1204       char buf[MSG_SIZ], *q = buf;
1205       int len;
1206
1207       if(p != NULL)
1208         { // engine command line contains WinBoard options
1209           len = snprintf(buf,MSG_SIZ, p+6, s, s, s, s, s, s, s, s, s, s); // replace %s in them by "first"
1210           if( (len > MSG_SIZ) && appData.debugMode )
1211             fprintf(debugFP, "InitAppData: buffer truncated.\n");
1212
1213           ParseArgs(StringGet, &q);
1214           p[-1] = 0; // cut them offengine command line
1215         }
1216   }
1217
1218   /* Propagate options that affect others */
1219   if (appData.matchMode || appData.matchGames) chessProgram = TRUE;
1220   if (appData.icsActive || appData.noChessProgram) {
1221      chessProgram = FALSE;  /* not local chess program mode */
1222   }
1223
1224   /* Open startup dialog if needed */
1225   if ((!appData.noChessProgram && !chessProgram && !appData.icsActive) ||
1226       (appData.icsActive && *appData.icsHost == NULLCHAR) ||
1227       (chessProgram && (*appData.firstChessProgram == NULLCHAR ||
1228                         *appData.secondChessProgram == NULLCHAR)))
1229                 PopUpStartupDialog();
1230
1231   /* Make sure save files land in the right (?) directory */
1232   if (MyGetFullPathName(appData.saveGameFile, buf)) {
1233     appData.saveGameFile = strdup(buf);
1234   }
1235   if (MyGetFullPathName(appData.savePositionFile, buf)) {
1236     appData.savePositionFile = strdup(buf);
1237   }
1238
1239   /* Finish initialization for fonts and sounds */
1240   CreateFonts();
1241
1242   GetCurrentDirectory(MSG_SIZ, currDir);
1243   SetCurrentDirectory(installDir);
1244   LoadAllSounds();
1245   SetCurrentDirectory(currDir);
1246
1247   p = icsTextMenuString;
1248   if (p[0] == '@') {
1249     FILE* f = fopen(p + 1, "r");
1250     if (f == NULL) {
1251       DisplayFatalError(p + 1, errno, 2);
1252       return;
1253     }
1254     i = fread(buf, 1, sizeof(buf)-1, f);
1255     fclose(f);
1256     buf[i] = NULLCHAR;
1257     p = buf;
1258   }
1259   ParseIcsTextMenu(strdup(p));
1260 }
1261
1262 void
1263 SaveSettings(char* name)
1264 {
1265   FILE *f;
1266   ArgDescriptor *ad;
1267   char dir[MSG_SIZ], buf[MSG_SIZ];
1268
1269   if (!MainWindowUp()) return;
1270
1271   GetCurrentDirectory(MSG_SIZ, dir);
1272   if(MySearchPath(installDir, name, buf)) {
1273     f = fopen(buf, "w");
1274   } else {
1275     SetCurrentDirectory(installDir);
1276     f = fopen(name, "w");
1277     SetCurrentDirectory(dir);
1278   }
1279   if (f == NULL) {
1280     DisplayError(name, errno);
1281     return;
1282   }
1283
1284   fprintf(f, ";\n");
1285   fprintf(f, "; %s Save Settings file\n", PACKAGE_STRING);
1286   fprintf(f, ";\n");
1287   fprintf(f, "; You can edit the values of options that are already set in this file,\n");
1288   fprintf(f, "; but if you add other options, the next Save Settings will not save them.\n");
1289   fprintf(f, "; Use a shortcut, an @indirection file, or a .bat file instead.\n");
1290   fprintf(f, ";\n");
1291
1292   GetWindowCoords();
1293
1294   /* [AS] Move history */
1295   wpMoveHistory.visible = MoveHistoryIsUp();
1296
1297   /* [AS] Eval graph */
1298   wpEvalGraph.visible = EvalGraphIsUp();
1299
1300   /* [AS] Engine output */
1301   wpEngineOutput.visible = EngineOutputIsUp();
1302
1303   // [HGM] in WB we have to copy sound names to appData first
1304   ExportSounds();
1305
1306   for (ad = argDescriptors; ad->argName != NULL; ad++) {
1307     if (!ad->save) continue;
1308     switch (ad->argType) {
1309     case ArgString:
1310       {
1311         char *p = *(char **)ad->argLoc;
1312         if(p == NULL) break; // just in case
1313         if ((strchr(p, '\\') || strchr(p, '\n')) && !strchr(p, '}')) {
1314           /* Quote multiline values or \-containing values
1315              with { } if possible */
1316           fprintf(f, OPTCHAR "%s" SEPCHAR "{%s}\n", ad->argName, p);
1317         } else {
1318           /* Else quote with " " */
1319           fprintf(f, OPTCHAR "%s" SEPCHAR "\"", ad->argName);
1320           while (*p) {
1321             if (*p == '\n') fprintf(f, "\n");
1322             else if (*p == '\r') fprintf(f, "\\r");
1323             else if (*p == '\t') fprintf(f, "\\t");
1324             else if (*p == '\b') fprintf(f, "\\b");
1325             else if (*p == '\f') fprintf(f, "\\f");
1326             else if (*p < ' ') fprintf(f, "\\%03o", *p);
1327             else if (*p == '\"') fprintf(f, "\\\"");
1328             else if (*p == '\\') fprintf(f, "\\\\");
1329             else putc(*p, f);
1330             p++;
1331           }
1332           fprintf(f, "\"\n");
1333         }
1334       }
1335       break;
1336     case ArgInt:
1337     case ArgZ:
1338       fprintf(f, OPTCHAR "%s" SEPCHAR "%d\n", ad->argName, *(int *)ad->argLoc);
1339       break;
1340     case ArgX:
1341       fprintf(f, OPTCHAR "%s" SEPCHAR "%d\n", ad->argName, *(int *)ad->argLoc - wpMain.x); // [HGM] placement: store relative value
1342       break;
1343     case ArgY:
1344       fprintf(f, OPTCHAR "%s" SEPCHAR "%d\n", ad->argName, *(int *)ad->argLoc - wpMain.y);
1345       break;
1346     case ArgFloat:
1347       fprintf(f, OPTCHAR "%s" SEPCHAR "%g\n", ad->argName, *(float *)ad->argLoc);
1348       break;
1349     case ArgBoolean:
1350       fprintf(f, OPTCHAR "%s" SEPCHAR "%s\n", ad->argName,
1351         (*(Boolean *)ad->argLoc) ? "true" : "false");
1352       break;
1353     case ArgTrue:
1354       if (*(Boolean *)ad->argLoc) fprintf(f, OPTCHAR "%s\n", ad->argName);
1355       break;
1356     case ArgFalse:
1357       if (!*(Boolean *)ad->argLoc) fprintf(f, OPTCHAR "%s\n", ad->argName);
1358       break;
1359     case ArgColor:
1360       SaveColor(f, ad);
1361       break;
1362     case ArgAttribs:
1363       SaveAttribsArg(f, ad);
1364       break;
1365     case ArgFilename:
1366       if(*(char**)ad->argLoc == NULL) break; // just in case
1367       if (strchr(*(char **)ad->argLoc, '\"')) {
1368         fprintf(f, OPTCHAR "%s" SEPCHAR "'%s'\n", ad->argName, *(char **)ad->argLoc);
1369       } else {
1370         fprintf(f, OPTCHAR "%s" SEPCHAR "\"%s\"\n", ad->argName, *(char **)ad->argLoc);
1371       }
1372       break;
1373     case ArgBoardSize:
1374       SaveBoardSize(f, ad->argName, ad->argLoc);
1375       break;
1376     case ArgFont:
1377       SaveFontArg(f, ad);
1378       break;
1379     case ArgCommSettings:
1380       PrintCommPortSettings(f, ad->argName);
1381     case ArgNone:
1382     case ArgSettingsFilename: ;
1383     }
1384   }
1385   fclose(f);
1386 }
1387
1388 Boolean
1389 GetArgValue(char *name)
1390 { // retrieve (as text) current value of string or int argument given by name
1391   // (this is used for maing the values available in the adapter command)
1392   ArgDescriptor *ad;
1393   int len;
1394
1395   for (ad = argDescriptors; ad->argName != NULL; ad++)
1396     if (strcmp(ad->argName, name) == 0) break;
1397
1398   if (ad->argName == NULL) return FALSE;
1399
1400   switch(ad->argType) {
1401     case ArgString:
1402     case ArgFilename:
1403       strncpy(name, *(char**) ad->argLoc, MSG_SIZ);
1404
1405       return TRUE;
1406     case ArgInt:
1407       len = snprintf(name, MSG_SIZ, "%d", *(int*) ad->argLoc);
1408       if( (len > MSG_SIZ) && appData.debugMode )
1409         fprintf(debugFP, "GetArgValue: buffer truncated.\n");
1410
1411       return TRUE;
1412     case ArgBoolean:
1413       len = snprintf(name, MSG_SIZ, "%s", *(Boolean*) ad->argLoc ? "true" : "false");
1414       if( (len > MSG_SIZ) && appData.debugMode )
1415         fprintf(debugFP, "GetArgValue: buffer truncated.\n");
1416
1417       return TRUE;
1418     default: ;
1419   }
1420
1421   return FALSE;
1422 }