Fix multi-leg promotions
[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, 2011, 2012, 2013, 2014, 2015, 2016 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, ArgBackupSettingsFile, ArgTwo, ArgInstall, ArgMaster,
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 char dataDir[MSG_SIZ] = DATADIR;
104
105 int junk;
106 int saveDate;
107 int dateStamp;
108 Boolean singleList;
109 Boolean autoClose;
110 char *homeDir;
111 char *firstEngineLine;
112 char *secondEngineLine;
113 char *icsNick;
114 char *theme;
115
116 void EnsureOnScreen(int *x, int *y, int minX, int minY);
117 char StringGet(void *getClosure);
118 void ParseFont(char *name, int number);
119 void SetFontDefaults();
120 void CreateFonts();
121 void ParseColor(int n, char *name);
122 void ParseTextAttribs(ColorClass cc, char *s);
123 void ParseBoardSize(void * addr, char *name);
124 void ParseCommPortSettings(char *name);
125 void LoadAllSounds();
126 void SetCommPortDefaults();
127 void SaveFontArg(FILE *f, ArgDescriptor *ad);
128 void ExportSounds();
129 void SaveAttribsArg(FILE *f, ArgDescriptor *ad);
130 void SaveColor(FILE *f, ArgDescriptor *ad);
131 void SaveBoardSize(FILE *f, char *name, void *addr);
132 void PrintCommPortSettings(FILE *f, char *name);
133 void GetWindowCoords();
134 int  MainWindowUp();
135 void PopUpStartupDialog();
136 typedef char GetFunc(void *getClosure);
137 void ParseArgs(GetFunc get, void *cl);
138
139 // [HGM] this is an exact duplicate of something in winboard.c. Move to backend.c?
140 char *defaultTextAttribs[] =
141 {
142   COLOR_SHOUT, COLOR_SSHOUT, COLOR_CHANNEL1, COLOR_CHANNEL, COLOR_KIBITZ,
143   COLOR_TELL, COLOR_CHALLENGE, COLOR_REQUEST, COLOR_SEEK, COLOR_NORMAL,
144   "#000000"
145 };
146
147 ArgDescriptor argDescriptors[] = {
148   /* positional arguments */
149   { "opt", ArgSettingsFilename, (void *) NULL, FALSE, INVALID },
150   { "loadPositionFile", ArgFilename, (void *) &appData.loadPositionFile, FALSE, INVALID },
151   { "tourneyFile", ArgFilename, (void *) &appData.tourneyFile, FALSE, INVALID },
152   { "is", ArgString, (void *) &icsNick, FALSE, INVALID },
153   { "loadGameFile", ArgFilename, (void *) &appData.loadGameFile, FALSE, INVALID },
154   { "", ArgNone, NULL, FALSE, INVALID },
155   /* keyword arguments */
156   { "saveDate", ArgInt, (void *) &saveDate, TRUE, 0 },
157   { "date", ArgInt, (void *) &dateStamp, FALSE, 0 },
158   { "autoClose", ArgTrue, (void *) &autoClose, FALSE, FALSE },
159   JAWS_ARGS
160   { "whitePieceColor", ArgColor, (void *) 0, TRUE, (ArgIniType) WHITE_PIECE_COLOR },
161   { "wpc", ArgColor, (void *) 0, FALSE, INVALID },
162   { "blackPieceColor", ArgColor, (void *) 1, TRUE, (ArgIniType) BLACK_PIECE_COLOR },
163   { "bpc", ArgColor, (void *) 1, FALSE, INVALID },
164   { "lightSquareColor", ArgColor, (void *) 2, TRUE, (ArgIniType) LIGHT_SQUARE_COLOR },
165   { "lsc", ArgColor, (void *) 2, FALSE, INVALID },
166   { "darkSquareColor", ArgColor, (void *) 3, TRUE, (ArgIniType) DARK_SQUARE_COLOR },
167   { "dsc", ArgColor, (void *) 3, FALSE, INVALID },
168   { "highlightSquareColor", ArgColor, (void *) 4, TRUE, (ArgIniType) HIGHLIGHT_SQUARE_COLOR },
169   { "hsc", ArgColor, (void *) 4, FALSE, INVALID },
170   { "premoveHighlightColor", ArgColor, (void *) 5, TRUE, (ArgIniType) PREMOVE_HIGHLIGHT_COLOR },
171   { "phc", ArgColor, (void *) 5, FALSE, INVALID },
172   { "movesPerSession", ArgInt, (void *) &appData.movesPerSession, TRUE, (ArgIniType) MOVES_PER_SESSION },
173   { "mps", ArgInt, (void *) &appData.movesPerSession, FALSE, INVALID },
174   { "initString", ArgString, (void *) &appData.firstInitString, FALSE, INVALID },
175   { "firstInitString", ArgString, (void *) &appData.firstInitString, FALSE, (ArgIniType) INIT_STRING },
176   { "secondInitString", ArgString, (void *) &appData.secondInitString, FALSE, (ArgIniType) INIT_STRING },
177   { "firstComputerString", ArgString, (void *) &appData.firstComputerString,
178     FALSE, (ArgIniType) COMPUTER_STRING },
179   { "secondComputerString", ArgString, (void *) &appData.secondComputerString,
180     FALSE, (ArgIniType) COMPUTER_STRING },
181   { "firstChessProgram", ArgFilename, (void *) &appData.firstChessProgram,
182     FALSE, (ArgIniType) FIRST_CHESS_PROGRAM },
183   { "fcp", ArgFilename, (void *) &appData.firstChessProgram, FALSE, INVALID },
184   { "secondChessProgram", ArgFilename, (void *) &appData.secondChessProgram,
185     FALSE, (ArgIniType) SECOND_CHESS_PROGRAM },
186   { "scp", ArgFilename, (void *) &appData.secondChessProgram, FALSE, INVALID },
187   { "fe", ArgString, (void *) &firstEngineLine, FALSE, "" },
188   { "se", ArgString, (void *) &secondEngineLine, FALSE, "" },
189   { "firstPlaysBlack", ArgBoolean, (void *) &appData.firstPlaysBlack, FALSE, FALSE },
190   { "fb", ArgTrue, (void *) &appData.firstPlaysBlack, FALSE, FALSE },
191   { "xfb", ArgFalse, (void *) &appData.firstPlaysBlack, FALSE, INVALID },
192   { "-fb", ArgFalse, (void *) &appData.firstPlaysBlack, FALSE, INVALID },
193   { "noChessProgram", ArgBoolean, (void *) &appData.noChessProgram, FALSE, FALSE },
194   { "ncp", ArgTrue, (void *) &appData.noChessProgram, FALSE, INVALID },
195   { "xncp", ArgFalse, (void *) &appData.noChessProgram, FALSE, INVALID },
196   { "-ncp", ArgFalse, (void *) &appData.noChessProgram, FALSE, INVALID },
197   { "firstHost", ArgString, (void *) &appData.firstHost, FALSE, (ArgIniType) FIRST_HOST },
198   { "fh", ArgString, (void *) &appData.firstHost, FALSE, INVALID },
199   { "secondHost", ArgString, (void *) &appData.secondHost, FALSE, (ArgIniType) SECOND_HOST },
200   { "sh", ArgString, (void *) &appData.secondHost, FALSE, INVALID },
201   { "firstDirectory", ArgFilename, (void *) &appData.firstDirectory, FALSE, (ArgIniType) FIRST_DIRECTORY },
202   { "fd", ArgFilename, (void *) &appData.firstDirectory, FALSE, INVALID },
203   { "secondDirectory", ArgFilename, (void *) &appData.secondDirectory, FALSE, (ArgIniType) SECOND_DIRECTORY },
204   { "sd", ArgFilename, (void *) &appData.secondDirectory, FALSE, INVALID },
205   { "variations", ArgBoolean, (void *) &appData.variations, TRUE, (ArgIniType) FALSE },
206   { "appendPV", ArgBoolean, (void *) &appData.autoExtend, TRUE, (ArgIniType) FALSE },
207   { "theme", ArgString, (void *) &theme, FALSE, (ArgIniType) "" },
208
209   /* some options only used by the XBoard front end, and ignored in WinBoard         */
210   /* Their saving is controlled by XBOARD, which in WinBoard is defined as FALSE */
211   { "internetChessServerInputBox", ArgBoolean, (void *) &appData.icsInputBox, XBOARD, (ArgIniType) FALSE },
212   { "icsinput", ArgTrue, (void *) &appData.icsInputBox, FALSE, INVALID },
213   { "xicsinput", ArgFalse, (void *) &appData.icsInputBox, FALSE, INVALID },
214   { "cmail", ArgString, (void *) &appData.cmailGameName, FALSE, (ArgIniType) "" },
215   { "soundProgram", ArgFilename, (void *) &appData.soundProgram, XBOARD, (ArgIniType) "play" },
216   { "fontSizeTolerance", ArgInt, (void *) &appData.fontSizeTolerance, XBOARD, (ArgIniType) 4 },
217   { "lowTimeWarningColor", ArgColor, (void *) 6, XBOARD, (ArgIniType) LOWTIMEWARNING_COLOR },
218   { "lowTimeWarning", ArgBoolean, (void *) &appData.lowTimeWarning, XBOARD, (ArgIniType) FALSE },
219   { "titleInWindow", ArgBoolean, (void *) &appData.titleInWindow, XBOARD, (ArgIniType) FALSE },
220   { "title", ArgTrue, (void *) &appData.titleInWindow, FALSE, INVALID },
221   { "xtitle", ArgFalse, (void *) &appData.titleInWindow, FALSE, INVALID },
222   { "flashCount", ArgInt, (void *) &appData.flashCount, XBOARD, INVALID }, // let X handle this
223   { "flashRate", ArgInt, (void *) &appData.flashRate, XBOARD, (ArgIniType) FLASH_RATE },
224   { "pieceImageDirectory", ArgFilename, (void *) &appData.pieceDirectory, TRUE, (ArgIniType) "" },
225   { "pid", ArgFilename, (void *) &appData.pieceDirectory, FALSE, INVALID },
226   { "trueColors", ArgBoolean, (void *) &appData.trueColors, XBOARD, (ArgIniType) (2*!XBOARD) },
227   { "jewelled", ArgInt, (void *) &appData.jewelled, FALSE, (ArgIniType) -1 },
228   { "soundDirectory", ArgFilename, (void *) &appData.soundDirectory, XBOARD, (ArgIniType) "" },
229   { "msLoginDelay", ArgInt, (void *) &appData.msLoginDelay, XBOARD, (ArgIniType) MS_LOGIN_DELAY },
230   { "pasteSelection", ArgBoolean, (void *) &appData.pasteSelection, XBOARD, (ArgIniType) FALSE },
231
232   { "dropMenu", ArgBoolean, (void *) &appData.dropMenu, TRUE, (ArgIniType) FALSE },
233   { "pieceMenu", ArgBoolean, (void *) &appData.pieceMenu, TRUE, (ArgIniType) TRUE },
234   { "sweepPromotions", ArgBoolean, (void *) &appData.sweepSelect, TRUE, (ArgIniType) FALSE },
235   { "monoMouse", ArgBoolean, (void *) &appData.monoMouse, XBOARD, (ArgIniType) FALSE },
236   { "remoteShell", ArgFilename, (void *) &appData.remoteShell, FALSE, (ArgIniType) REMOTE_SHELL },
237   { "rsh", ArgFilename, (void *) &appData.remoteShell, FALSE, INVALID },
238   { "remoteUser", ArgString, (void *) &appData.remoteUser, FALSE, (ArgIniType) "" },
239   { "ruser", ArgString, (void *) &appData.remoteUser, FALSE, INVALID },
240   { "timeDelay", ArgFloat, (void *) &appData.timeDelay, TRUE, INVALID },
241   { "td", ArgFloat, (void *) &appData.timeDelay, FALSE, INVALID },
242   { "timeControl", ArgString, (void *) &appData.timeControl, TRUE, (ArgIniType) TIME_CONTROL },
243   { "tc", ArgString, (void *) &appData.timeControl, FALSE, INVALID },
244   { "timeIncrement", ArgFloat, (void *) &appData.timeIncrement, FALSE, INVALID },
245   { "inc", ArgFloat, (void *) &appData.timeIncrement, FALSE, INVALID },
246   { "internetChessServerMode", ArgBoolean, (void *) &appData.icsActive, FALSE, INVALID },
247   { "ics", ArgTrue, (void *) &appData.icsActive, FALSE, (ArgIniType) FALSE },
248   { "xics", ArgFalse, (void *) &appData.icsActive, FALSE, INVALID },
249   { "-ics", ArgFalse, (void *) &appData.icsActive, FALSE, INVALID },
250   { "is", ArgString, (void *) &icsNick, FALSE, "" },
251   { "internetChessServerHost", ArgString, (void *) &appData.icsHost, FALSE, (ArgIniType) "" },
252   { "icshost", ArgString, (void *) &appData.icsHost, FALSE, INVALID },
253   { "internetChessServerPort", ArgString, (void *) &appData.icsPort, FALSE, (ArgIniType) ICS_PORT },
254   { "icsport", ArgString, (void *) &appData.icsPort, FALSE, INVALID },
255   { "internetChessServerCommPort", ArgString, (void *) &appData.icsCommPort, FALSE, (ArgIniType) ICS_COMM_PORT },
256   { "icscomm", ArgString, (void *) &appData.icsCommPort, FALSE, INVALID },
257   { "internetChessServerComPort", ArgString, (void *) &appData.icsCommPort, FALSE, INVALID },
258   { "icscom", ArgString, (void *) &appData.icsCommPort, FALSE, INVALID },
259   { "internetChessServerLogonScript", ArgFilename, (void *) &appData.icsLogon, FALSE, (ArgIniType) ICS_LOGON },
260   { "icslogon", ArgFilename, (void *) &appData.icsLogon, FALSE, INVALID },
261   { "useTelnet", ArgBoolean, (void *) &appData.useTelnet, FALSE, INVALID },
262   { "telnet", ArgTrue, (void *) &appData.useTelnet, FALSE, INVALID },
263   { "xtelnet", ArgFalse, (void *) &appData.useTelnet, FALSE, INVALID },
264   { "-telnet", ArgFalse, (void *) &appData.useTelnet, FALSE, INVALID },
265   { "telnetProgram", ArgFilename, (void *) &appData.telnetProgram, FALSE, (ArgIniType) TELNET_PROGRAM },
266   { "internetChessserverHelper", ArgFilename, (void *) &appData.icsHelper,
267         FALSE, INVALID }, // for XB
268   { "icshelper", ArgFilename, (void *) &appData.icsHelper, FALSE, (ArgIniType) "" },
269   { "seekGraph", ArgBoolean, (void *) &appData.seekGraph, TRUE, (ArgIniType) FALSE },
270   { "sg", ArgTrue, (void *) &appData.seekGraph, FALSE, INVALID },
271   { "autoRefresh", ArgBoolean, (void *) &appData.autoRefresh, TRUE, (ArgIniType) FALSE },
272   { "autoBox", ArgBoolean, (void *) &appData.autoBox, XBOARD, (ArgIniType) TRUE },
273   { "gateway", ArgString, (void *) &appData.gateway, FALSE, (ArgIniType) "" },
274   { "loadGameFile", ArgFilename, (void *) &appData.loadGameFile, FALSE, (ArgIniType) "" },
275   { "lgf", ArgFilename, (void *) &appData.loadGameFile, FALSE, INVALID },
276   { "loadGameIndex", ArgInt, (void *) &appData.loadGameIndex, FALSE, (ArgIniType) 0 },
277   { "lgi", ArgInt, (void *) &appData.loadGameIndex, FALSE, INVALID },
278   { "saveGameFile", ArgFilename, (void *) &appData.saveGameFile, TRUE, (ArgIniType) "" },
279   { "sgf", ArgFilename, (void *) &appData.saveGameFile, FALSE, INVALID },
280   { "autoSaveGames", ArgBoolean, (void *) &appData.autoSaveGames, TRUE, (ArgIniType) FALSE },
281   { "autosave", ArgTrue, (void *) &appData.autoSaveGames, FALSE, INVALID },
282   { "xautosave", ArgFalse, (void *) &appData.autoSaveGames, FALSE, INVALID },
283   { "-autosave", ArgFalse, (void *) &appData.autoSaveGames, FALSE, INVALID },
284   { "onlyOwnGames", ArgBoolean, (void *) &appData.onlyOwn, TRUE, (ArgIniType) FALSE },
285   { "loadPositionFile", ArgFilename, (void *) &appData.loadPositionFile, FALSE, (ArgIniType) "" },
286   { "lpf", ArgFilename, (void *) &appData.loadPositionFile, FALSE, INVALID },
287   { "loadPositionIndex", ArgInt, (void *) &appData.loadPositionIndex, FALSE, (ArgIniType) 1 },
288   { "lpi", ArgInt, (void *) &appData.loadPositionIndex, FALSE, INVALID },
289   { "positionDir", ArgFilename, (void *) &appData.positionDir, FALSE, (ArgIniType) "" },
290   { "savePositionFile", ArgFilename, (void *) &appData.savePositionFile, FALSE, (ArgIniType) "" },
291   { "spf", ArgFilename, (void *) &appData.savePositionFile, FALSE, INVALID },
292   { "matchMode", ArgBoolean, (void *) &appData.matchMode, FALSE, (ArgIniType) FALSE },
293   { "mm", ArgTrue, (void *) &appData.matchMode, FALSE, INVALID },
294   { "xmm", ArgFalse, (void *) &appData.matchMode, FALSE, INVALID },
295   { "-mm", ArgFalse, (void *) &appData.matchMode, FALSE, INVALID },
296   { "matchGames", ArgInt, (void *) &appData.matchGames, FALSE, (ArgIniType) 0 },
297   { "mg", ArgInt, (void *) &appData.matchGames, FALSE, INVALID },
298   { "monoMode", ArgBoolean, (void *) &appData.monoMode, TRUE, (ArgIniType) FALSE },
299   { "mono", ArgTrue, (void *) &appData.monoMode, FALSE, INVALID },
300   { "xmono", ArgFalse, (void *) &appData.monoMode, FALSE, INVALID },
301   { "-mono", ArgFalse, (void *) &appData.monoMode, FALSE, INVALID },
302   { "debugMode", ArgBoolean, (void *) &appData.debugMode, FALSE, (ArgIniType) FALSE },
303   { "debug", ArgTrue, (void *) &appData.debugMode, FALSE, INVALID },
304   { "xdebug", ArgFalse, (void *) &appData.debugMode, FALSE, INVALID },
305   { "-debug", ArgFalse, (void *) &appData.debugMode, FALSE, INVALID },
306   { "clockMode", ArgBoolean, (void *) &appData.clockMode, FALSE, (ArgIniType) TRUE },
307   { "clock", ArgTrue, (void *) &appData.clockMode, FALSE, INVALID },
308   { "xclock", ArgFalse, (void *) &appData.clockMode, FALSE, INVALID },
309   { "-clock", ArgFalse, (void *) &appData.clockMode, FALSE, INVALID },
310   { "searchTime", ArgString, (void *) &appData.searchTime, FALSE, (ArgIniType) "" },
311   { "st", ArgString, (void *) &appData.searchTime, FALSE, INVALID },
312   { "searchDepth", ArgInt, (void *) &appData.searchDepth, FALSE, (ArgIniType) 0 },
313   { "depth", ArgInt, (void *) &appData.searchDepth, FALSE, INVALID },
314   { "showCoords", ArgBoolean, (void *) &appData.showCoords, TRUE, (ArgIniType) FALSE },
315   { "coords", ArgTrue, (void *) &appData.showCoords, FALSE, INVALID },
316   { "xcoords", ArgFalse, (void *) &appData.showCoords, FALSE, INVALID },
317   { "-coords", ArgFalse, (void *) &appData.showCoords, FALSE, INVALID },
318   { "showThinking", ArgBoolean, (void *) &appData.showThinking, TRUE, (ArgIniType) FALSE },
319   { "thinking", ArgTrue, (void *) &appData.showThinking, FALSE, INVALID },
320   { "xthinking", ArgFalse, (void *) &appData.showThinking, FALSE, INVALID },
321   { "-thinking", ArgFalse, (void *) &appData.showThinking, FALSE, INVALID },
322   { "ponderNextMove", ArgBoolean, (void *) &appData.ponderNextMove, TRUE, (ArgIniType) TRUE },
323   { "ponder", ArgTrue, (void *) &appData.ponderNextMove, FALSE, INVALID },
324   { "xponder", ArgFalse, (void *) &appData.ponderNextMove, FALSE, INVALID },
325   { "-ponder", ArgFalse, (void *) &appData.ponderNextMove, FALSE, INVALID },
326   { "periodicUpdates", ArgBoolean, (void *) &appData.periodicUpdates, TRUE, (ArgIniType) TRUE },
327   { "periodic", ArgTrue, (void *) &appData.periodicUpdates, FALSE, INVALID },
328   { "xperiodic", ArgFalse, (void *) &appData.periodicUpdates, FALSE, INVALID },
329   { "-periodic", ArgFalse, (void *) &appData.periodicUpdates, FALSE, INVALID },
330   { "popupExitMessage", ArgBoolean, (void *) &appData.popupExitMessage, TRUE, (ArgIniType) TRUE },
331   { "exit", ArgTrue, (void *) &appData.popupExitMessage, FALSE, INVALID },
332   { "xexit", ArgFalse, (void *) &appData.popupExitMessage, FALSE, INVALID },
333   { "-exit", ArgFalse, (void *) &appData.popupExitMessage, FALSE, INVALID },
334   { "popupMoveErrors", ArgBoolean, (void *) &appData.popupMoveErrors, TRUE, (ArgIniType) FALSE },
335   { "popup", ArgTrue, (void *) &appData.popupMoveErrors, FALSE, INVALID },
336   { "xpopup", ArgFalse, (void *) &appData.popupMoveErrors, FALSE, INVALID },
337   { "-popup", ArgFalse, (void *) &appData.popupMoveErrors, FALSE, INVALID },
338   { "popUpErrors", ArgBoolean, (void *) &appData.popupMoveErrors,
339     FALSE, INVALID }, /* only so that old WinBoard.ini files from betas can be read */
340   { "clockFont", ArgFont, (void *) CLOCK_FONT, TRUE, INVALID },
341   { "messageFont", ArgFont, (void *) MESSAGE_FONT, TRUE, INVALID },
342   { "font", ArgFont, (void *) MESSAGE_FONT, FALSE, INVALID }, /* only so that old .xboardrc files will parse. -font does not work from the command line because it is captured by the X libraries. */
343   { "coordFont", ArgFont, (void *) COORD_FONT, TRUE, INVALID },
344   { "tagsFont", ArgFont, (void *) EDITTAGS_FONT, TRUE, INVALID },
345   { "commentFont", ArgFont, (void *) COMMENT_FONT, TRUE, INVALID },
346   { "icsFont", ArgFont, (void *) CONSOLE_FONT, TRUE, INVALID },
347   { "moveHistoryFont", ArgFont, (void *) MOVEHISTORY_FONT, TRUE, INVALID }, /* [AS] */
348   { "gameListFont", ArgFont, (void *) GAMELIST_FONT, TRUE, INVALID }, /* [HGM] */
349   { "boardSize", ArgBoardSize, (void *) &boardSize,
350     TRUE, (ArgIniType) -1 }, /* must come after all fonts */
351   { "size", ArgBoardSize, (void *) &boardSize, FALSE, INVALID },
352   { "ringBellAfterMoves", ArgBoolean, (void *) &appData.ringBellAfterMoves,
353     FALSE, (ArgIniType) TRUE }, /* historical; kept only so old winboard.ini files will parse */
354   { "bell", ArgTrue, (void *) &appData.ringBellAfterMoves, FALSE, INVALID }, // for XB
355   { "xbell", ArgFalse, (void *) &appData.ringBellAfterMoves, FALSE, INVALID }, // for XB
356   { "movesound", ArgTrue, (void *) &appData.ringBellAfterMoves, FALSE, INVALID }, // for XB
357   { "xmovesound", ArgFalse, (void *) &appData.ringBellAfterMoves, FALSE, INVALID }, // for XB
358   { "alwaysOnTop", ArgBoolean, (void *) &alwaysOnTop, TRUE, INVALID },
359   { "top", ArgTrue, (void *) &alwaysOnTop, FALSE, INVALID },
360   { "xtop", ArgFalse, (void *) &alwaysOnTop, FALSE, INVALID },
361   { "-top", ArgFalse, (void *) &alwaysOnTop, FALSE, INVALID },
362   { "autoCallFlag", ArgBoolean, (void *) &appData.autoCallFlag, TRUE, (ArgIniType) FALSE },
363   { "autoflag", ArgTrue, (void *) &appData.autoCallFlag, FALSE, INVALID },
364   { "xautoflag", ArgFalse, (void *) &appData.autoCallFlag, FALSE, INVALID },
365   { "-autoflag", ArgFalse, (void *) &appData.autoCallFlag, FALSE, INVALID },
366   { "autoComment", ArgBoolean, (void *) &appData.autoComment, TRUE, (ArgIniType) FALSE },
367   { "autocomm", ArgTrue, (void *) &appData.autoComment, FALSE, INVALID },
368   { "xautocomm", ArgFalse, (void *) &appData.autoComment, FALSE, INVALID },
369   { "-autocomm", ArgFalse, (void *) &appData.autoComment, FALSE, INVALID },
370   { "autoCreateLogon", ArgBoolean, (void *) &appData.autoCreateLogon, TRUE, (ArgIniType) FALSE },
371   { "autoObserve", ArgBoolean, (void *) &appData.autoObserve, TRUE, (ArgIniType) FALSE },
372   { "autobs", ArgTrue, (void *) &appData.autoObserve, FALSE, INVALID },
373   { "xautobs", ArgFalse, (void *) &appData.autoObserve, FALSE, INVALID },
374   { "-autobs", ArgFalse, (void *) &appData.autoObserve, FALSE, INVALID },
375   { "flipView", ArgBoolean, (void *) &appData.flipView, FALSE, (ArgIniType) FALSE },
376   { "flip", ArgTrue, (void *) &appData.flipView, FALSE, INVALID },
377   { "xflip", ArgFalse, (void *) &appData.flipView, FALSE, INVALID },
378   { "-flip", ArgFalse, (void *) &appData.flipView, FALSE, INVALID },
379   { "autoFlipView", ArgBoolean, (void *) &appData.autoFlipView, TRUE, (ArgIniType) TRUE },
380   { "autoflip", ArgTrue, (void *) &appData.autoFlipView, FALSE, INVALID },
381   { "xautoflip", ArgFalse, (void *) &appData.autoFlipView, FALSE, INVALID },
382   { "-autoflip", ArgFalse, (void *) &appData.autoFlipView, FALSE, INVALID },
383   { "autoRaiseBoard", ArgBoolean, (void *) &appData.autoRaiseBoard, TRUE, (ArgIniType) TRUE },
384   { "autoraise", ArgTrue, (void *) &appData.autoRaiseBoard, FALSE, INVALID },
385   { "xautoraise", ArgFalse, (void *) &appData.autoRaiseBoard, FALSE, INVALID },
386   { "-autoraise", ArgFalse, (void *) &appData.autoRaiseBoard, FALSE, INVALID },
387   { "alwaysPromoteToQueen", ArgBoolean, (void *) &appData.alwaysPromoteToQueen, TRUE, (ArgIniType) FALSE },
388   { "queen", ArgTrue, (void *) &appData.alwaysPromoteToQueen, FALSE, INVALID },
389   { "xqueen", ArgFalse, (void *) &appData.alwaysPromoteToQueen, FALSE, INVALID },
390   { "-queen", ArgFalse, (void *) &appData.alwaysPromoteToQueen, FALSE, INVALID },
391   { "oldSaveStyle", ArgBoolean, (void *) &appData.oldSaveStyle, TRUE, (ArgIniType) FALSE },
392   { "oldsave", ArgTrue, (void *) &appData.oldSaveStyle, FALSE, INVALID },
393   { "xoldsave", ArgFalse, (void *) &appData.oldSaveStyle, FALSE, INVALID },
394   { "-oldsave", ArgFalse, (void *) &appData.oldSaveStyle, FALSE, INVALID },
395   { "quietPlay", ArgBoolean, (void *) &appData.quietPlay, TRUE, (ArgIniType) FALSE },
396   { "quiet", ArgTrue, (void *) &appData.quietPlay, FALSE, INVALID },
397   { "xquiet", ArgFalse, (void *) &appData.quietPlay, FALSE, INVALID },
398   { "-quiet", ArgFalse, (void *) &appData.quietPlay, FALSE, INVALID },
399   { "getMoveList", ArgBoolean, (void *) &appData.getMoveList, TRUE, (ArgIniType) TRUE },
400   { "moves", ArgTrue, (void *) &appData.getMoveList, FALSE, INVALID },
401   { "xmoves", ArgFalse, (void *) &appData.getMoveList, FALSE, INVALID },
402   { "-moves", ArgFalse, (void *) &appData.getMoveList, FALSE, INVALID },
403   { "testLegality", ArgBoolean, (void *) &appData.testLegality, TRUE, (ArgIniType) TRUE },
404   { "legal", ArgTrue, (void *) &appData.testLegality, FALSE, INVALID },
405   { "xlegal", ArgFalse, (void *) &appData.testLegality, FALSE, INVALID },
406   { "-legal", ArgFalse, (void *) &appData.testLegality, FALSE, INVALID },
407   { "premove", ArgBoolean, (void *) &appData.premove, TRUE, (ArgIniType) TRUE },
408   { "pre", ArgTrue, (void *) &appData.premove, FALSE, INVALID },
409   { "xpre", ArgFalse, (void *) &appData.premove, FALSE, INVALID },
410   { "-pre", ArgFalse, (void *) &appData.premove, FALSE, INVALID },
411   { "premoveWhite", ArgBoolean, (void *) &appData.premoveWhite, TRUE, (ArgIniType) FALSE },
412   { "prewhite", ArgTrue, (void *) &appData.premoveWhite, FALSE, INVALID },
413   { "xprewhite", ArgFalse, (void *) &appData.premoveWhite, FALSE, INVALID },
414   { "-prewhite", ArgFalse, (void *) &appData.premoveWhite, FALSE, INVALID },
415   { "premoveWhiteText", ArgString, (void *) &appData.premoveWhiteText, TRUE, (ArgIniType) "" },
416   { "premoveBlack", ArgBoolean, (void *) &appData.premoveBlack, TRUE, (ArgIniType) FALSE },
417   { "preblack", ArgTrue, (void *) &appData.premoveBlack, FALSE, INVALID },
418   { "xpreblack", ArgFalse, (void *) &appData.premoveBlack, FALSE, INVALID },
419   { "-preblack", ArgFalse, (void *) &appData.premoveBlack, FALSE, INVALID },
420   { "premoveBlackText", ArgString, (void *) &appData.premoveBlackText, TRUE, (ArgIniType) "" },
421   { "icsAlarm", ArgBoolean, (void *) &appData.icsAlarm, TRUE, (ArgIniType) TRUE},
422   { "alarm", ArgTrue, (void *) &appData.icsAlarm, FALSE},
423   { "xalarm", ArgFalse, (void *) &appData.icsAlarm, FALSE},
424   { "-alarm", ArgFalse, (void *) &appData.icsAlarm, FALSE},
425   { "icsAlarmTime", ArgInt, (void *) &appData.icsAlarmTime, TRUE, (ArgIniType) 5000},
426   { "localLineEditing", ArgBoolean, (void *) &appData.localLineEditing, FALSE, (ArgIniType) TRUE},
427   { "edit", ArgTrue, (void *) &appData.localLineEditing, FALSE, INVALID },
428   { "xedit", ArgFalse, (void *) &appData.localLineEditing, FALSE, INVALID },
429   { "-edit", ArgFalse, (void *) &appData.localLineEditing, FALSE, INVALID },
430   { "animateMoving", ArgBoolean, (void *) &appData.animate, TRUE, (ArgIniType) TRUE },
431   { "animate", ArgTrue, (void *) &appData.animate, FALSE, INVALID },
432   { "xanimate", ArgFalse, (void *) &appData.animate, FALSE, INVALID },
433   { "-animate", ArgFalse, (void *) &appData.animate, FALSE, INVALID },
434   { "animateSpeed", ArgInt, (void *) &appData.animSpeed, TRUE, (ArgIniType) 10 },
435   { "animateDragging", ArgBoolean, (void *) &appData.animateDragging, TRUE, (ArgIniType) TRUE },
436   { "drag", ArgTrue, (void *) &appData.animateDragging, FALSE, INVALID },
437   { "xdrag", ArgFalse, (void *) &appData.animateDragging, FALSE, INVALID },
438   { "-drag", ArgFalse, (void *) &appData.animateDragging, FALSE, INVALID },
439   { "blindfold", ArgBoolean, (void *) &appData.blindfold, TRUE, (ArgIniType) FALSE },
440   { "blind", ArgTrue, (void *) &appData.blindfold, FALSE, INVALID },
441   { "xblind", ArgFalse, (void *) &appData.blindfold, FALSE, INVALID },
442   { "-blind", ArgFalse, (void *) &appData.blindfold, FALSE, INVALID },
443   { "highlightLastMove", ArgBoolean,
444     (void *) &appData.highlightLastMove, TRUE, (ArgIniType) TRUE },
445   { "highlight", ArgTrue, (void *) &appData.highlightLastMove, FALSE, INVALID },
446   { "xhighlight", ArgFalse, (void *) &appData.highlightLastMove, FALSE, INVALID },
447   { "-highlight", ArgFalse, (void *) &appData.highlightLastMove, FALSE, INVALID },
448   { "highlightDragging", ArgBoolean,
449     (void *) &appData.highlightDragging, !XBOARD, (ArgIniType) TRUE },
450   { "highdrag", ArgTrue, (void *) &appData.highlightDragging, FALSE, INVALID },
451   { "xhighdrag", ArgFalse, (void *) &appData.highlightDragging, FALSE, INVALID },
452   { "-highdrag", ArgFalse, (void *) &appData.highlightDragging, FALSE, INVALID },
453   { "colorizeMessages", ArgBoolean, (void *) &appData.colorize, TRUE, (ArgIniType) TRUE },
454   { "colorize", ArgTrue, (void *) &appData.colorize, FALSE, INVALID },
455   { "xcolorize", ArgFalse, (void *) &appData.colorize, FALSE, INVALID },
456   { "-colorize", ArgFalse, (void *) &appData.colorize, FALSE, INVALID },
457   { "colorShout", ArgAttribs, (void *) ColorShout, TRUE, INVALID },
458   { "colorSShout", ArgAttribs, (void *) ColorSShout, TRUE, INVALID },
459   { "colorCShout", ArgAttribs, (void *) ColorSShout, FALSE, INVALID }, // for XB
460   { "colorChannel1", ArgAttribs, (void *) ColorChannel1, TRUE, INVALID },
461   { "colorChannel", ArgAttribs, (void *) ColorChannel, TRUE, INVALID },
462   { "colorKibitz", ArgAttribs, (void *) ColorKibitz, TRUE, INVALID },
463   { "colorTell", ArgAttribs, (void *) ColorTell, TRUE, INVALID },
464   { "colorChallenge", ArgAttribs, (void *) ColorChallenge, TRUE, INVALID },
465   { "colorRequest", ArgAttribs, (void *) ColorRequest, TRUE, INVALID },
466   { "colorSeek", ArgAttribs, (void *) ColorSeek, TRUE, INVALID },
467   { "colorNormal", ArgAttribs, (void *) ColorNormal, TRUE, INVALID },
468   { "colorBackground", ArgColor, (void *) 7, TRUE, COLOR_BKGD },
469   { "soundShout", ArgFilename, (void *) &appData.soundShout, TRUE, (ArgIniType) "" },
470   { "soundSShout", ArgFilename, (void *) &appData.soundSShout, TRUE, (ArgIniType) "" },
471   { "soundCShout", ArgFilename, (void *) &appData.soundSShout, FALSE, (ArgIniType) "" }, // for XB
472   { "soundChannel1", ArgFilename, (void *) &appData.soundChannel1, TRUE, (ArgIniType) "" },
473   { "soundChannel", ArgFilename, (void *) &appData.soundChannel, TRUE, (ArgIniType) "" },
474   { "soundKibitz", ArgFilename, (void *) &appData.soundKibitz, TRUE, (ArgIniType) "" },
475   { "soundTell", ArgFilename, (void *) &appData.soundTell, TRUE, (ArgIniType) "" },
476   { "soundChallenge", ArgFilename, (void *) &appData.soundChallenge, TRUE, (ArgIniType) "" },
477   { "soundRequest", ArgFilename, (void *) &appData.soundRequest, TRUE, (ArgIniType) "" },
478   { "soundSeek", ArgFilename, (void *) &appData.soundSeek, TRUE, (ArgIniType) "" },
479   { "soundMove", ArgFilename, (void *) &appData.soundMove, TRUE, (ArgIniType) "" },
480   { "soundBell", ArgFilename, (void *) &appData.soundBell, TRUE, (ArgIniType) SOUND_BELL },
481   { "soundRoar", ArgFilename, (void *) &appData.soundRoar, TRUE, (ArgIniType) "" },
482   { "soundIcsWin", ArgFilename, (void *) &appData.soundIcsWin, TRUE, (ArgIniType) "" },
483   { "soundIcsLoss", ArgFilename, (void *) &appData.soundIcsLoss, TRUE, (ArgIniType) "" },
484   { "soundIcsDraw", ArgFilename, (void *) &appData.soundIcsDraw, TRUE, (ArgIniType) "" },
485   { "soundIcsUnfinished", ArgFilename, (void *) &appData.soundIcsUnfinished, TRUE, (ArgIniType) "" },
486   { "soundIcsAlarm", ArgFilename, (void *) &appData.soundIcsAlarm, TRUE, (ArgIniType) "" },
487   { "disguisePromotedPieces", ArgBoolean, (void *) &appData.disguise, TRUE, (ArgIniType) TRUE },
488   { "reuseFirst", ArgBoolean, (void *) &appData.reuseFirst, FALSE, (ArgIniType) TRUE },
489   { "reuse", ArgTrue, (void *) &appData.reuseFirst, FALSE, INVALID },
490   { "xreuse", ArgFalse, (void *) &appData.reuseFirst, FALSE, INVALID },
491   { "-reuse", ArgFalse, (void *) &appData.reuseFirst, FALSE, INVALID },
492   { "reuseChessPrograms", ArgBoolean,
493     (void *) &appData.reuseFirst, FALSE, INVALID }, /* backward compat only */
494   { "reuseSecond", ArgBoolean, (void *) &appData.reuseSecond, FALSE, (ArgIniType) TRUE },
495   { "reuse2", ArgTrue, (void *) &appData.reuseSecond, FALSE, INVALID },
496   { "xreuse2", ArgFalse, (void *) &appData.reuseSecond, FALSE, INVALID },
497   { "-reuse2", ArgFalse, (void *) &appData.reuseSecond, FALSE, INVALID },
498   { "comPortSettings", ArgCommSettings, (void *) /*&dcb*/ 0, TRUE, INVALID },
499   { "settingsFile", ArgSettingsFilename, (void *) &settingsFileName, FALSE, (ArgIniType) SETTINGS_FILE },
500   { "ini", ArgSettingsFilename, (void *) &settingsFileName, FALSE, INVALID },
501   { "at", ArgSettingsFilename, (void *) NULL, FALSE, INVALID },
502   { "opt", ArgSettingsFilename, (void *) NULL, FALSE, INVALID },
503   { "saveSettingsFile", ArgFilename, (void *) &settingsFileName, FALSE, INVALID },
504   { "backupSettingsFile", ArgBackupSettingsFile, (void *) &settingsFileName, FALSE, INVALID },
505   { "saveSettingsOnExit", ArgBoolean, (void *) &saveSettingsOnExit, TRUE, (ArgIniType) TRUE },
506   { "chessProgram", ArgBoolean, (void *) &chessProgram, FALSE, (ArgIniType) FALSE },
507   { "cp", ArgTrue, (void *) &chessProgram, FALSE, INVALID },
508   { "xcp", ArgFalse, (void *) &chessProgram, FALSE, INVALID },
509   { "-cp", ArgFalse, (void *) &chessProgram, FALSE, INVALID },
510   { "icsMenu", ArgString, (void *) &icsTextMenuString, TRUE, (ArgIniType) ICS_TEXT_MENU_DEFAULT },
511   { "icsNames", ArgString, (void *) &icsNames, TRUE, (ArgIniType) ICS_NAMES },
512   { "singleEngineList", ArgBoolean, (void *) &singleList, !XBOARD, (ArgIniType) FALSE },
513   { "recentEngines", ArgInt, (void *) &appData.recentEngines, TRUE, (ArgIniType) 6 },
514   { "recentEngineList", ArgString, (void *) &appData.recentEngineList, TRUE, (ArgIniType) "" },
515   { "firstChessProgramNames", ArgString, (void *) &firstChessProgramNames,
516     TRUE, (ArgIniType) FCP_NAMES },
517   { "secondChessProgramNames", ArgString, (void *) &secondChessProgramNames,
518     !XBOARD, (ArgIniType) SCP_NAMES },
519   { "themeNames", ArgString, (void *) &appData.themeNames, TRUE, (ArgIniType) "native -upf false -ub false -ubt false -pid \"\"\n" },
520   { "addMasterOption", ArgMaster, NULL, FALSE, INVALID },
521   { "installEngine", ArgInstall, (void *) &firstChessProgramNames, FALSE, (ArgIniType) "" },
522   { "installTheme", ArgInstall, (void *) &appData.themeNames, FALSE, (ArgIniType) "" },
523   { "initialMode", ArgString, (void *) &appData.initialMode, FALSE, (ArgIniType) "" },
524   { "mode", ArgString, (void *) &appData.initialMode, FALSE, INVALID },
525   { "variant", ArgString, (void *) &appData.variant, FALSE, (ArgIniType) "normal" },
526   { "firstProtocolVersion", ArgInt, (void *) &appData.firstProtocolVersion, FALSE, (ArgIniType) PROTOVER },
527   { "secondProtocolVersion", ArgInt, (void *) &appData.secondProtocolVersion,FALSE, (ArgIniType) PROTOVER },
528   { "showButtonBar", ArgBoolean, (void *) &appData.showButtonBar, TRUE, (ArgIniType) TRUE },
529   { "buttons", ArgTrue, (void *) &appData.showButtonBar, FALSE, INVALID },
530   { "xbuttons", ArgFalse, (void *) &appData.showButtonBar, FALSE, INVALID },
531   { "-buttons", ArgFalse, (void *) &appData.showButtonBar, FALSE, INVALID },
532
533   /* [AS] New features */
534   { "firstScoreAbs", ArgBoolean, (void *) &appData.firstScoreIsAbsolute, FALSE, (ArgIniType) FALSE },
535   { "secondScoreAbs", ArgBoolean, (void *) &appData.secondScoreIsAbsolute, FALSE, (ArgIniType) FALSE },
536   { "pgnExtendedInfo", ArgBoolean, (void *) &appData.saveExtendedInfoInPGN, TRUE, (ArgIniType) FALSE },
537   { "hideThinkingFromHuman", ArgBoolean, (void *) &appData.hideThinkingFromHuman, TRUE, (ArgIniType) FALSE },
538   { "pgnTimeLeft", ArgBoolean, (void *) &appData.cumulativeTimePGN, TRUE, (ArgIniType) FALSE },
539   { "liteBackTextureFile", ArgFilename, (void *) &appData.liteBackTextureFile, TRUE, (ArgIniType) "" },
540   { "lbtf", ArgFilename, (void *) &appData.liteBackTextureFile, FALSE, INVALID },
541   { "darkBackTextureFile", ArgFilename, (void *) &appData.darkBackTextureFile, TRUE, (ArgIniType) "" },
542   { "dbtf", ArgFilename, (void *) &appData.darkBackTextureFile, FALSE, INVALID },
543   { "liteBackTextureMode", ArgInt, (void *) &appData.liteBackTextureMode, TRUE, (ArgIniType) BACK_TEXTURE_MODE_PLAIN },
544   { "lbtm", ArgInt, (void *) &appData.liteBackTextureMode, FALSE, INVALID },
545   { "darkBackTextureMode", ArgInt, (void *) &appData.darkBackTextureMode, TRUE, (ArgIniType) BACK_TEXTURE_MODE_PLAIN },
546   { "dbtm", ArgInt, (void *) &appData.darkBackTextureMode, FALSE, INVALID },
547   { "renderPiecesWithFont", ArgString, (void *) &appData.renderPiecesWithFont, TRUE, (ArgIniType) "" },
548   { "pf", ArgString, (void *) &appData.renderPiecesWithFont, FALSE, INVALID },
549   { "fontPieceToCharTable", ArgString, (void *) &appData.fontToPieceTable, TRUE, (ArgIniType) "" },
550   { "fptc", ArgString, (void *) &appData.fontToPieceTable, FALSE, INVALID },
551   { "fontPieceBackColorWhite", ArgColor, (void *) 8, TRUE, (ArgIniType) WHITE_PIECE_COLOR },
552   { "fontPieceForeColorWhite", ArgColor, (void *) 9, TRUE, (ArgIniType) WHITE_PIECE_COLOR },
553   { "fontPieceBackColorBlack", ArgColor, (void *) 10, TRUE, (ArgIniType) BLACK_PIECE_COLOR },
554   { "fontPieceForeColorBlack", ArgColor, (void *) 11, TRUE, (ArgIniType) BLACK_PIECE_COLOR },
555   { "fpfcw", ArgColor, (void *) 9, FALSE, INVALID },
556   { "fpbcb", ArgColor, (void *) 10, FALSE, INVALID },
557   { "fontPieceSize", ArgInt, (void *) &appData.fontPieceSize, TRUE, (ArgIniType) 80 },
558   { "overrideLineGap", ArgInt, (void *) &appData.overrideLineGap, TRUE, (ArgIniType) 1 },
559   { "adjudicateLossThreshold", ArgInt, (void *) &appData.adjudicateLossThreshold, TRUE, (ArgIniType) 0 },
560   { "delayBeforeQuit", ArgInt, (void *) &appData.delayBeforeQuit, TRUE, (ArgIniType) 0 },
561   { "delayAfterQuit", ArgInt, (void *) &appData.delayAfterQuit, TRUE, (ArgIniType) 0 },
562   { "nameOfDebugFile", ArgFilename, (void *) &appData.nameOfDebugFile, FALSE, (ArgIniType) DEBUG_FILE },
563   { "debugfile", ArgFilename, (void *) &appData.nameOfDebugFile, FALSE, INVALID },
564   { "pgnEventHeader", ArgString, (void *) &appData.pgnEventHeader, TRUE, (ArgIniType) "Computer Chess Game" },
565   { "defaultFrcPosition", ArgInt, (void *) &appData.defaultFrcPosition, TRUE, (ArgIniType) -1 },
566   { "shuffleOpenings", ArgTrue, (void *) &shuffleOpenings, FALSE, INVALID },
567   { "fischerCastling", ArgTrue, (void *) &appData.fischerCastling, FALSE, INVALID },
568   { "gameListTags", ArgString, (void *) &appData.gameListTags, TRUE, (ArgIniType) GLT_DEFAULT_TAGS },
569   { "saveOutOfBookInfo", ArgBoolean, (void *) &appData.saveOutOfBookInfo, TRUE, (ArgIniType) TRUE },
570   { "showEvalInMoveHistory", ArgBoolean, (void *) &appData.showEvalInMoveHistory, TRUE, (ArgIniType) TRUE },
571   { "evalHistColorWhite", ArgColor, (void *) 12, TRUE, (ArgIniType) "#FFFFB0" },
572   { "evalHistColorBlack", ArgColor, (void *) 13, TRUE, (ArgIniType) "#AD5D3D" },
573   { "highlightMoveWithArrow", ArgBoolean, (void *) &appData.highlightMoveWithArrow, TRUE, (ArgIniType) FALSE },
574   { "highlightArrowColor", ArgColor, (void *) 14, TRUE, (ArgIniType) "#FFFF80" },
575   { "stickyWindows", ArgBoolean, (void *) &appData.useStickyWindows, TRUE, (ArgIniType) TRUE },
576   { "adjudicateDrawMoves", ArgInt, (void *) &appData.adjudicateDrawMoves, TRUE, (ArgIniType) 0 },
577   { "autoDisplayComment", ArgBoolean, (void *) &appData.autoDisplayComment, TRUE, (ArgIniType) TRUE },
578   { "autoDisplayTags", ArgBoolean, (void *) &appData.autoDisplayTags, TRUE, (ArgIniType) TRUE },
579   { "firstIsUCI", ArgBoolean, (void *) &appData.firstIsUCI, FALSE, (ArgIniType) FALSE },
580   { "fUCI", ArgTrue, (void *) &appData.firstIsUCI, FALSE, INVALID },
581   { "firstUCI", ArgTrue, (void *) &appData.firstIsUCI, FALSE, INVALID },
582   { "secondIsUCI", ArgBoolean, (void *) &appData.secondIsUCI, FALSE, (ArgIniType) FALSE },
583   { "secondUCI", ArgTrue, (void *) &appData.secondIsUCI, FALSE, INVALID },
584   { "sUCI", ArgTrue, (void *) &appData.secondIsUCI, FALSE, INVALID },
585   { "fUCCI", ArgTwo, (void *) &appData.firstIsUCI, FALSE, INVALID },
586   { "sUCCI", ArgTwo, (void *) &appData.secondIsUCI, FALSE, INVALID },
587   { "fUSI", ArgTwo, (void *) &appData.firstIsUCI, FALSE, INVALID },
588   { "sUSI", ArgTwo, (void *) &appData.secondIsUCI, FALSE, INVALID },
589   { "firstHasOwnBookUCI", ArgBoolean, (void *) &appData.firstHasOwnBookUCI, FALSE, (ArgIniType) TRUE },
590   { "fNoOwnBookUCI", ArgFalse, (void *) &appData.firstHasOwnBookUCI, FALSE, INVALID },
591   { "firstXBook", ArgFalse, (void *) &appData.firstHasOwnBookUCI, FALSE, INVALID },
592   { "secondHasOwnBookUCI", ArgBoolean, (void *) &appData.secondHasOwnBookUCI, FALSE, (ArgIniType) TRUE },
593   { "sNoOwnBookUCI", ArgFalse, (void *) &appData.secondHasOwnBookUCI, FALSE, INVALID },
594   { "secondXBook", ArgFalse, (void *) &appData.secondHasOwnBookUCI, FALSE, INVALID },
595   { "adapterCommand", ArgFilename, (void *) &appData.adapterCommand, TRUE, (ArgIniType) "polyglot -noini -ec \"%fcp\" -ed \"%fd\"" },
596   { "uxiAdapter", ArgFilename, (void *) &appData.ucciAdapter, TRUE, (ArgIniType) "" },
597   { "polyglotDir", ArgFilename, (void *) &appData.polyglotDir, TRUE, (ArgIniType) "" },
598   { "usePolyglotBook", ArgBoolean, (void *) &appData.usePolyglotBook, TRUE, (ArgIniType) FALSE },
599   { "polyglotBook", ArgFilename, (void *) &appData.polyglotBook, TRUE, (ArgIniType) "" },
600   { "bookDepth", ArgInt, (void *) &appData.bookDepth, TRUE, (ArgIniType) 12 },
601   { "bookVariation", ArgInt, (void *) &appData.bookStrength, TRUE, (ArgIniType) 50 },
602   { "discourageOwnBooks", ArgBoolean, (void *) &appData.defNoBook, TRUE, (ArgIniType) FALSE },
603   { "mcBookMode", ArgTrue, (void *) &mcMode, FALSE, (ArgIniType) FALSE },
604   { "defaultHashSize", ArgInt, (void *) &appData.defaultHashSize, TRUE, (ArgIniType) 64 },
605   { "defaultCacheSizeEGTB", ArgInt, (void *) &appData.defaultCacheSizeEGTB, TRUE, (ArgIniType) 4 },
606   { "defaultPathEGTB", ArgFilename, (void *) &appData.defaultPathEGTB, TRUE, (ArgIniType) "c:\\egtb" },
607   { "language", ArgFilename, (void *) &appData.language, TRUE, (ArgIniType) "" },
608   { "userFileDirectory", ArgFilename, (void *) &homeDir, FALSE, (ArgIniType) installDir },
609   { "usePieceFont", ArgBoolean, (void *) &appData.useFont, TRUE, (ArgIniType) FALSE },
610   { "upf", ArgBoolean, (void *) &appData.useFont, FALSE, INVALID },
611   { "useBoardTexture", ArgBoolean, (void *) &appData.useBitmaps, TRUE, (ArgIniType) FALSE },
612   { "ubt", ArgBoolean, (void *) &appData.useBitmaps, FALSE, INVALID },
613   { "useBorder", ArgBoolean, (void *) &appData.useBorder, TRUE, (ArgIniType) FALSE },
614   { "ub", ArgBoolean, (void *) &appData.useBorder, FALSE, INVALID },
615   { "border", ArgFilename, (void *) &appData.border, TRUE, (ArgIniType) "" },
616   { "finger", ArgFilename, (void *) &appData.finger, FALSE, (ArgIniType) "" },
617   { "epd", ArgTrue, (void *) &appData.epd, FALSE, INVALID },
618   { "inscriptions", ArgString, (void *) &appData.inscriptions, FALSE, (ArgIniType) "" },
619   { "autoInstall", ArgString, (void *) &appData.autoInstall, XBOARD, (ArgIniType) "" },
620   { "fixedSize", ArgBoolean, (void *) &appData.fixedSize, TRUE, (ArgIniType) FALSE },
621   { "showMoveTime", ArgBoolean, (void *) &appData.moveTime, TRUE, (ArgIniType) FALSE },
622
623   // [HGM] tournament options
624   { "tourneyFile", ArgFilename, (void *) &appData.tourneyFile, FALSE, (ArgIniType) "" },
625   { "tf", ArgFilename, (void *) &appData.tourneyFile, FALSE, INVALID },
626   { "participants", ArgString, (void *) &appData.participants, FALSE, (ArgIniType) "" },
627   { "tourneyType", ArgInt, (void *) &appData.tourneyType, FALSE, (ArgIniType) 0 },
628   { "tt", ArgInt, (void *) &appData.tourneyType, FALSE, INVALID },
629   { "tourneyCycles", ArgInt, (void *) &appData.tourneyCycles, FALSE, (ArgIniType) 1 },
630   { "cy", ArgInt, (void *) &appData.tourneyCycles, FALSE, INVALID },
631   { "results", ArgString, (void *) &appData.results, FALSE, (ArgIniType) "" },
632   { "syncAfterRound", ArgBoolean, (void *) &appData.roundSync, FALSE, (ArgIniType) FALSE },
633   { "syncAfterCycle", ArgBoolean, (void *) &appData.cycleSync, FALSE, (ArgIniType) TRUE },
634   { "seedBase", ArgInt, (void *) &appData.seedBase, FALSE, (ArgIniType) 1 },
635   { "pgnNumberTag", ArgBoolean, (void *) &appData.numberTag, TRUE, (ArgIniType) FALSE },
636   { "afterGame", ArgString, (void *) &appData.afterGame, FALSE, INVALID },
637   { "afterTourney", ArgString, (void *) &appData.afterTourney, FALSE, INVALID },
638
639   /* [HGM] board-size, adjudication and misc. options */
640   { "oneClickMove", ArgBoolean, (void *) &appData.oneClick, TRUE, (ArgIniType) FALSE },
641   { "boardWidth", ArgInt, (void *) &appData.NrFiles, FALSE, (ArgIniType) -1 },
642   { "boardHeight", ArgInt, (void *) &appData.NrRanks, FALSE, (ArgIniType) -1 },
643   { "rankOffset", ArgInt, (void *) &appData.rankOffset, FALSE, (ArgIniType) 0 },
644   { "holdingsSize", ArgInt, (void *) &appData.holdingsSize, FALSE, (ArgIniType) -1 },
645   { "defaultMatchGames", ArgInt, (void *) &appData.defaultMatchGames, TRUE, (ArgIniType) 10 },
646   { "matchPause", ArgInt, (void *) &appData.matchPause, TRUE, (ArgIniType) 10000 },
647   { "pieceToCharTable", ArgString, (void *) &appData.pieceToCharTable, FALSE, INVALID },
648   { "pieceNickNames", ArgString, (void *) &appData.pieceNickNames, FALSE, INVALID },
649   { "colorNickNames", ArgString, (void *) &appData.colorNickNames, FALSE, INVALID },
650   { "flipBlack", ArgBoolean, (void *) &appData.upsideDown, FALSE, (ArgIniType) FALSE },
651   { "allWhite", ArgBoolean, (void *) &appData.allWhite, FALSE, (ArgIniType) FALSE },
652   { "alphaRank", ArgBoolean, (void *) &appData.alphaRank, FALSE, (ArgIniType) FALSE },
653   { "firstAlphaRank", ArgBoolean, (void *) &first.alphaRank, FALSE, (ArgIniType) FALSE },
654   { "secondAlphaRank", ArgBoolean, (void *) &second.alphaRank, FALSE, (ArgIniType) FALSE },
655   { "testClaims", ArgBoolean, (void *) &appData.testClaims, TRUE, (ArgIniType) FALSE },
656   { "checkMates", ArgBoolean, (void *) &appData.checkMates, TRUE, (ArgIniType) FALSE },
657   { "materialDraws", ArgBoolean, (void *) &appData.materialDraws, TRUE, (ArgIniType) FALSE },
658   { "trivialDraws", ArgBoolean, (void *) &appData.trivialDraws, TRUE, (ArgIniType) FALSE },
659   { "ruleMoves", ArgInt, (void *) &appData.ruleMoves, TRUE, (ArgIniType) 51 },
660   { "repeatsToDraw", ArgInt, (void *) &appData.drawRepeats, TRUE, (ArgIniType) 6 },
661   { "backgroundObserve", ArgBoolean, (void *) &appData.bgObserve, TRUE, (ArgIniType) FALSE },
662   { "dualBoard", ArgBoolean, (void *) &appData.dualBoard, TRUE, (ArgIniType) FALSE },
663   { "autoKibitz", ArgTrue, (void *) &appData.autoKibitz, FALSE, INVALID },
664   { "engineDebugOutput", ArgInt, (void *) &appData.engineComments, FALSE, (ArgIniType) 1 },
665   { "userName", ArgString, (void *) &appData.userName, FALSE, INVALID },
666   { "rewindIndex", ArgInt, (void *) &appData.rewindIndex, FALSE, INVALID },
667   { "sameColorGames", ArgInt, (void *) &appData.sameColorGames, FALSE, INVALID },
668   { "smpCores", ArgInt, (void *) &appData.smpCores, TRUE, (ArgIniType) 1 },
669   { "egtFormats", ArgString, (void *) &appData.egtFormats, TRUE, (ArgIniType) "" },
670   { "niceEngines", ArgInt, (void *) &appData.niceEngines, TRUE, INVALID },
671   { "logoSize", ArgInt, (void *) &appData.logoSize, XBOARD, INVALID },
672   { "logoDir", ArgFilename, (void *) &appData.logoDir, XBOARD, (ArgIniType) "." },
673   { "firstLogo", ArgFilename, (void *) &appData.firstLogo, FALSE, (ArgIniType) "" },
674   { "secondLogo", ArgFilename, (void *) &appData.secondLogo, FALSE, (ArgIniType) "" },
675   { "autoLogo", ArgBoolean, (void *) &appData.autoLogo, TRUE, INVALID },
676   { "firstOptions", ArgString, (void *) &appData.firstOptions, FALSE, (ArgIniType) "" },
677   { "secondOptions", ArgString, (void *) &appData.secondOptions, FALSE, (ArgIniType) "" },
678   { "firstFeatures", ArgString, (void *) &appData.features[0], FALSE, (ArgIniType) "" },
679   { "secondFeatures", ArgString, (void *) &appData.features[1], FALSE, (ArgIniType) "" },
680   { "featureDefaults", ArgString, (void *) &appData.featureDefaults, TRUE, (ArgIniType) "" },
681   { "firstNeedsNoncompliantFEN", ArgString, (void *) &appData.fenOverride1, FALSE, (ArgIniType) NULL },
682   { "secondNeedsNoncompliantFEN", ArgString, (void *) &appData.fenOverride2, FALSE, (ArgIniType) NULL },
683   { "keepAlive", ArgInt, (void *) &appData.keepAlive, FALSE, INVALID },
684   { "icstype", ArgInt, (void *) &ics_type, FALSE, INVALID },
685   { "forceIllegalMoves", ArgTrue, (void *) &appData.forceIllegal, FALSE, INVALID },
686   { "showTargetSquares", ArgBoolean, (void *) &appData.markers, TRUE, (ArgIniType) FALSE },
687   { "firstPgnName", ArgString, (void *) &appData.pgnName[0], FALSE, (ArgIniType) "" },
688   { "fn", ArgString, (void *) &appData.pgnName[0], FALSE, INVALID },
689   { "secondPgnName", ArgString, (void *) &appData.pgnName[1], FALSE, (ArgIniType) "" },
690   { "sn", ArgString, (void *) &appData.pgnName[1], FALSE, INVALID },
691   { "absoluteAnalysisScores", ArgBoolean, (void *) &appData.whitePOV, TRUE, FALSE },
692   { "scoreWhite", ArgBoolean, (void *) &appData.scoreWhite, TRUE, FALSE },
693   { "evalZoom", ArgInt, (void *) &appData.zoom, TRUE, (ArgIniType) 1 },
694   { "evalThreshold", ArgInt, (void *) &appData.evalThreshold, TRUE, (ArgIniType) 25 },
695   { "firstPseudo", ArgTrue, (void *) &appData.pseudo[0], FALSE, FALSE },
696   { "secondPseudo", ArgTrue, (void *) &appData.pseudo[1], FALSE, FALSE },
697   { "fSAN", ArgTrue, (void *) &appData.pvSAN[0], FALSE, FALSE },
698   { "sSAN", ArgTrue, (void *) &appData.pvSAN[1], FALSE, FALSE },
699   { "pairingEngine", ArgFilename, (void *) &appData.pairingEngine, TRUE, "" },
700   { "defaultTourneyName", ArgFilename, (void *) &appData.defName, TRUE, "" },
701   { "eloThresholdAny", ArgInt, (void *) &appData.eloThreshold1, FALSE, (ArgIniType) 0 },
702   { "eloThresholdBoth", ArgInt, (void *) &appData.eloThreshold2, FALSE, (ArgIniType) 0 },
703   { "dateThreshold", ArgInt, (void *) &appData.dateThreshold, FALSE, (ArgIniType) 0 },
704   { "searchMode", ArgInt, (void *) &appData.searchMode, FALSE, (ArgIniType) 1 },
705   { "stretch", ArgInt, (void *) &appData.stretch, FALSE, (ArgIniType) 1 },
706   { "ignoreColors", ArgBoolean, (void *) &appData.ignoreColors, FALSE, FALSE },
707   { "findMirrorImage", ArgBoolean, (void *) &appData.findMirror, FALSE, FALSE },
708   { "viewer", ArgTrue, (void *) &appData.viewer, FALSE, FALSE },
709   { "viewerOptions", ArgString, (void *) &appData.viewerOptions, TRUE, (ArgIniType) "-ncp -engineOutputUp false -saveSettingsOnExit false" },
710   { "tourneyOptions", ArgString, (void *) &appData.tourneyOptions, TRUE, (ArgIniType) "-ncp -mm -saveSettingsOnExit false" },
711   { "autoCopyPV", ArgBoolean, (void *) &appData.autoCopyPV, TRUE, FALSE },
712   { "topLevel", ArgBoolean, (void *) &appData.topLevel, XBOARD, (ArgIniType) TOPLEVEL },
713   { "dialogColor", ArgString, (void *) &appData.dialogColor, XBOARD, (ArgIniType) "" },
714   { "buttonColor", ArgString, (void *) &appData.buttonColor, XBOARD, (ArgIniType) "" },
715   { "firstDrawDepth", ArgInt, (void *) &appData.drawDepth[0], FALSE, (ArgIniType) 0 },
716   { "secondDrawDepth", ArgInt, (void *) &appData.drawDepth[1], FALSE, (ArgIniType) 0 },
717   { "memoHeaders", ArgBoolean, (void *) &appData.headers, TRUE, (ArgIniType) FALSE },
718   { "startupMessage", ArgString, (void *) &appData.message, FALSE, (ArgIniType) "" },
719   { "messageSuppress", ArgString, (void *) &appData.suppress, XBOARD, (ArgIniType) "" },
720   { "fen", ArgString, (void *) &appData.fen, FALSE, (ArgIniType) "" },
721   { "men", ArgString, (void *) &appData.men, FALSE, (ArgIniType) "" },
722   { "analysisBell", ArgInt, (void *) &appData.analysisBell, TRUE, (ArgIniType) 0 },
723
724 #if ZIPPY
725   { "zippyTalk", ArgBoolean, (void *) &appData.zippyTalk, FALSE, (ArgIniType) ZIPPY_TALK },
726   { "zt", ArgTrue, (void *) &appData.zippyTalk, FALSE, INVALID },
727   { "xzt", ArgFalse, (void *) &appData.zippyTalk, FALSE, INVALID },
728   { "-zt", ArgFalse, (void *) &appData.zippyTalk, FALSE, INVALID },
729   { "zippyPlay", ArgBoolean, (void *) &appData.zippyPlay, FALSE, (ArgIniType) ZIPPY_PLAY },
730   { "zp", ArgTrue, (void *) &appData.zippyPlay, FALSE, INVALID },
731   { "xzp", ArgFalse, (void *) &appData.zippyPlay, FALSE, INVALID },
732   { "-zp", ArgFalse, (void *) &appData.zippyPlay, FALSE, INVALID },
733   { "zippyLines", ArgFilename, (void *) &appData.zippyLines, FALSE, (ArgIniType) ZIPPY_LINES },
734   { "zippyPinhead", ArgString, (void *) &appData.zippyPinhead, FALSE, (ArgIniType) ZIPPY_PINHEAD },
735   { "zippyPassword", ArgString, (void *) &appData.zippyPassword, FALSE, (ArgIniType) ZIPPY_PASSWORD },
736   { "zippyPassword2", ArgString, (void *) &appData.zippyPassword2, FALSE, (ArgIniType) ZIPPY_PASSWORD2 },
737   { "zippyWrongPassword", ArgString, (void *) &appData.zippyWrongPassword,
738     FALSE, (ArgIniType) ZIPPY_WRONG_PASSWORD },
739   { "zippyAcceptOnly", ArgString, (void *) &appData.zippyAcceptOnly, FALSE, (ArgIniType) ZIPPY_ACCEPT_ONLY },
740   { "zippyUseI", ArgBoolean, (void *) &appData.zippyUseI, FALSE, (ArgIniType) ZIPPY_USE_I },
741   { "zui", ArgTrue, (void *) &appData.zippyUseI, FALSE, INVALID },
742   { "xzui", ArgFalse, (void *) &appData.zippyUseI, FALSE, INVALID },
743   { "-zui", ArgFalse, (void *) &appData.zippyUseI, FALSE, INVALID },
744   { "zippyBughouse", ArgInt, (void *) &appData.zippyBughouse, FALSE, (ArgIniType) ZIPPY_BUGHOUSE },
745   { "zippyNoplayCrafty", ArgBoolean, (void *) &appData.zippyNoplayCrafty,
746     FALSE, (ArgIniType) ZIPPY_NOPLAY_CRAFTY },
747   { "znc", ArgTrue, (void *) &appData.zippyNoplayCrafty, FALSE, INVALID },
748   { "xznc", ArgFalse, (void *) &appData.zippyNoplayCrafty, FALSE, INVALID },
749   { "-znc", ArgFalse, (void *) &appData.zippyNoplayCrafty, FALSE, INVALID },
750   { "zippyGameEnd", ArgString, (void *) &appData.zippyGameEnd, FALSE, (ArgIniType) ZIPPY_GAME_END },
751   { "zippyGameStart", ArgString, (void *) &appData.zippyGameStart, FALSE, (ArgIniType) ZIPPY_GAME_START },
752   { "zippyAdjourn", ArgBoolean, (void *) &appData.zippyAdjourn, FALSE, (ArgIniType) ZIPPY_ADJOURN },
753   { "zadj", ArgTrue, (void *) &appData.zippyAdjourn, FALSE, INVALID },
754   { "xzadj", ArgFalse, (void *) &appData.zippyAdjourn, FALSE, INVALID },
755   { "-zadj", ArgFalse, (void *) &appData.zippyAdjourn, FALSE, INVALID },
756   { "zippyAbort", ArgBoolean, (void *) &appData.zippyAbort, FALSE, (ArgIniType) ZIPPY_ABORT },
757   { "zab", ArgTrue, (void *) &appData.zippyAbort, FALSE, INVALID },
758   { "xzab", ArgFalse, (void *) &appData.zippyAbort, FALSE, INVALID },
759   { "-zab", ArgFalse, (void *) &appData.zippyAbort, FALSE, INVALID },
760   { "zippyVariants", ArgString, (void *) &appData.zippyVariants, FALSE, (ArgIniType) ZIPPY_VARIANTS },
761   { "zippyMaxGames", ArgInt, (void *)&appData.zippyMaxGames, FALSE, (ArgIniType) ZIPPY_MAX_GAMES},
762   { "zippyReplayTimeout", ArgInt, (void *)&appData.zippyReplayTimeout, FALSE, (ArgIniType) ZIPPY_REPLAY_TIMEOUT },
763   { "zippyShortGame", ArgInt, (void *)&appData.zippyShortGame, FALSE, INVALID },
764   /* Kludge to allow winboard.ini files from buggy 4.0.4 to be read: */
765   { "zippyReplyTimeout", ArgInt, (void *)&junk, FALSE, INVALID },
766 #endif
767   /* [HGM] options for broadcasting and time odds */
768   { "chatBoxes", ArgString, (void *) &appData.chatBoxes, !XBOARD, (ArgIniType) NULL },
769   { "serverMoves", ArgString, (void *) &appData.serverMovesName, FALSE, (ArgIniType) NULL },
770   { "serverFile", ArgString, (void *) &appData.serverFileName, FALSE, (ArgIniType) NULL },
771   { "suppressLoadMoves", ArgBoolean, (void *) &appData.suppressLoadMoves, FALSE, (ArgIniType) FALSE },
772   { "serverPause", ArgInt, (void *) &appData.serverPause, FALSE, (ArgIniType) 15 },
773   { "firstTimeOdds", ArgInt, (void *) &appData.firstTimeOdds, FALSE, (ArgIniType) 1 },
774   { "secondTimeOdds", ArgInt, (void *) &appData.secondTimeOdds, FALSE, (ArgIniType) 1 },
775   { "timeOddsMode", ArgInt, (void *) &appData.timeOddsMode, TRUE, INVALID },
776   { "firstAccumulateTC", ArgInt, (void *) &appData.firstAccumulateTC, FALSE, (ArgIniType) 1 },
777   { "secondAccumulateTC", ArgInt, (void *) &appData.secondAccumulateTC, FALSE, (ArgIniType) 1 },
778   { "firstNPS", ArgInt, (void *) &appData.firstNPS, FALSE, (ArgIniType) -1 },
779   { "secondNPS", ArgInt, (void *) &appData.secondNPS, FALSE, (ArgIniType) -1 },
780   { "noGUI", ArgTrue, (void *) &appData.noGUI, FALSE, INVALID },
781   { "keepLineBreaksICS", ArgBoolean, (void *) &appData.noJoin, TRUE, INVALID },
782   { "wrapContinuationSequence", ArgString, (void *) &appData.wrapContSeq, FALSE, INVALID },
783   { "useInternalWrap", ArgTrue, (void *) &appData.useInternalWrap, FALSE, INVALID }, /* noJoin usurps this if set */
784   { "openCommand", ArgString, (void *) &appData.sysOpen, FALSE, "xdg-open" },
785
786   // [HGM] placement: put all window layouts last in ini file, but man X,Y before all others
787   { "minX", ArgZ, (void *) &minX, FALSE, INVALID }, // [HGM] placement: to make sure auxiliary windows can be placed
788   { "minY", ArgZ, (void *) &minY, FALSE, INVALID },
789   { "winWidth",  ArgInt, (void *) &wpMain.width,  TRUE, INVALID }, // [HGM] placement: dummies to remember right & bottom
790   { "winHeight", ArgInt, (void *) &wpMain.height, TRUE, INVALID }, //       for attaching auxiliary windows to them
791   { "x", ArgInt, (void *) &wpMain.x, TRUE, (ArgIniType) CW_USEDEFAULT },
792   { "y", ArgInt, (void *) &wpMain.y, TRUE, (ArgIniType) CW_USEDEFAULT },
793   { "icsUp", ArgBoolean, (void *) &wpConsole.visible, XBOARD, (ArgIniType) FALSE },
794   { "icsX", ArgX,   (void *) &wpConsole.x, TRUE, (ArgIniType) CW_USEDEFAULT },
795   { "icsY", ArgY,   (void *) &wpConsole.y, TRUE, (ArgIniType) CW_USEDEFAULT },
796   { "icsW", ArgInt, (void *) &wpConsole.width, TRUE, (ArgIniType) CW_USEDEFAULT },
797   { "icsH", ArgInt, (void *) &wpConsole.height, TRUE, (ArgIniType) CW_USEDEFAULT },
798   { "commentX", ArgX,   (void *) &wpComment.x, TRUE, (ArgIniType) CW_USEDEFAULT },
799   { "commentY", ArgY,   (void *) &wpComment.y, TRUE, (ArgIniType) CW_USEDEFAULT },
800   { "commentW", ArgInt, (void *) &wpComment.width, TRUE, (ArgIniType) CW_USEDEFAULT },
801   { "commentH", ArgInt, (void *) &wpComment.height, TRUE, (ArgIniType) CW_USEDEFAULT },
802   { "tagsX", ArgX,   (void *) &wpTags.x, TRUE, (ArgIniType) CW_USEDEFAULT },
803   { "tagsY", ArgY,   (void *) &wpTags.y, TRUE, (ArgIniType) CW_USEDEFAULT },
804   { "tagsW", ArgInt, (void *) &wpTags.width, TRUE, (ArgIniType) CW_USEDEFAULT },
805   { "tagsH", ArgInt, (void *) &wpTags.height, TRUE, (ArgIniType) CW_USEDEFAULT },
806   { "gameListX", ArgX,   (void *) &wpGameList.x, TRUE, (ArgIniType) CW_USEDEFAULT },
807   { "gameListY", ArgY,   (void *) &wpGameList.y, TRUE, (ArgIniType) CW_USEDEFAULT },
808   { "gameListW", ArgInt, (void *) &wpGameList.width, TRUE, (ArgIniType) CW_USEDEFAULT },
809   { "gameListH", ArgInt, (void *) &wpGameList.height, TRUE, (ArgIniType) CW_USEDEFAULT },
810 #if XBOARD
811   { "slaveX", ArgX,   (void *) &wpDualBoard.x, TRUE, (ArgIniType) CW_USEDEFAULT },
812   { "slaveY", ArgY,   (void *) &wpDualBoard.y, TRUE, (ArgIniType) CW_USEDEFAULT },
813   { "slaveW", ArgInt, (void *) &wpDualBoard.width, FALSE, (ArgIniType) CW_USEDEFAULT },
814   { "slaveH", ArgInt, (void *) &wpDualBoard.height, FALSE, (ArgIniType) CW_USEDEFAULT },
815 #endif
816   /* [AS] Layout stuff */
817   { "moveHistoryUp", ArgBoolean, (void *) &wpMoveHistory.visible, TRUE, (ArgIniType) TRUE },
818   { "moveHistoryX", ArgX,   (void *) &wpMoveHistory.x, TRUE, (ArgIniType) CW_USEDEFAULT },
819   { "moveHistoryY", ArgY,   (void *) &wpMoveHistory.y, TRUE, (ArgIniType) CW_USEDEFAULT },
820   { "moveHistoryW", ArgInt, (void *) &wpMoveHistory.width, TRUE, (ArgIniType) CW_USEDEFAULT },
821   { "moveHistoryH", ArgInt, (void *) &wpMoveHistory.height, TRUE, (ArgIniType) CW_USEDEFAULT },
822
823   { "evalGraphUp", ArgBoolean, (void *) &wpEvalGraph.visible, TRUE, (ArgIniType) TRUE },
824   { "evalGraphX", ArgX,   (void *) &wpEvalGraph.x, TRUE, (ArgIniType) CW_USEDEFAULT },
825   { "evalGraphY", ArgY,   (void *) &wpEvalGraph.y, TRUE, (ArgIniType) CW_USEDEFAULT },
826   { "evalGraphW", ArgInt, (void *) &wpEvalGraph.width, TRUE, (ArgIniType) CW_USEDEFAULT },
827   { "evalGraphH", ArgInt, (void *) &wpEvalGraph.height, TRUE, (ArgIniType) CW_USEDEFAULT },
828
829   { "engineOutputUp", ArgBoolean, (void *) &wpEngineOutput.visible, TRUE, (ArgIniType) TRUE },
830   { "engineOutputX", ArgX,   (void *) &wpEngineOutput.x, TRUE, (ArgIniType) CW_USEDEFAULT },
831   { "engineOutputY", ArgY,   (void *) &wpEngineOutput.y, TRUE, (ArgIniType) CW_USEDEFAULT },
832   { "engineOutputW", ArgInt, (void *) &wpEngineOutput.width, TRUE, (ArgIniType) CW_USEDEFAULT },
833   { "engineOutputH", ArgInt, (void *) &wpEngineOutput.height, TRUE, (ArgIniType) CW_USEDEFAULT },
834
835   { NULL, ArgNone, NULL, FALSE, INVALID }
836 };
837
838
839 /* Kludge for indirection files on command line */
840 char* lastIndirectionFilename;
841 ArgDescriptor argDescriptorIndirection =
842 { "", ArgSettingsFilename, (void *) NULL, FALSE };
843
844 void
845 ExitArgError(char *msg, char *badArg, Boolean quit)
846 {
847   char buf[MSG_SIZ];
848   int len;
849
850   len = snprintf(buf, MSG_SIZ, msg, badArg);
851   if( (len >= MSG_SIZ) && appData.debugMode )
852     fprintf(debugFP, "ExitArgError: buffer truncated. Input: msg=%s badArg=%s\n", msg, badArg);
853
854   if(!quit) { printf(_("%s in settings file\n"), buf); return; } // DisplayError does not work yet at this stage...
855   DisplayFatalError(buf, 0, 2);
856   exit(2);
857 }
858
859 void
860 AppendToSettingsFile (char *line)
861 {
862   char buf[MSG_SIZ];
863   FILE *f;
864   int c;
865   if(f = fopen(SETTINGS_FILE, "r")) {
866     do {
867       int i = 0;
868       while((buf[i] = c = fgetc(f)) != '\n' && c != EOF) if(i < MSG_SIZ-1) i++;
869       buf[i] = NULLCHAR;
870       if(!strcmp(line, buf)) return; // line occurs
871     } while(c != EOF);
872     // line did not occur; add it
873     fclose(f);
874     if(f = fopen(SETTINGS_FILE, "a")) {
875       TimeMark now;
876       GetTimeMark(&now);
877       fprintf(f, "-date %10lu\n%s\n", now.sec, line);
878       fclose(f);
879     }
880   }
881 }
882
883 int
884 ValidateInt(char *s)
885 {
886   char *p = s;
887   if(*p == '-' || *p == '+') p++;
888   while(*p) if(!isdigit(*p++)) ExitArgError(_("Bad integer value %s"), s, TRUE);
889   return atoi(s);
890 }
891
892 char
893 StringGet(void *getClosure)
894 {
895   char **p = (char **) getClosure;
896   return *((*p)++);
897 }
898
899 char
900 FileGet(void *getClosure)
901 {
902   int c;
903   FILE* f = (FILE*) getClosure;
904
905   c = getc(f);
906   if (c == '\r') c = getc(f); // work around DOS format files by bypassing the '\r' completely
907   if (c == EOF)
908     return NULLCHAR;
909   else
910     return (char) c;
911 }
912
913 /* Parse settings file named "name". If file found, return the
914    full name in fullname and return TRUE; else return FALSE */
915 Boolean
916 ParseSettingsFile(char *name, char **addr)
917 {
918   FILE *f;
919   int ok,len;
920   char buf[MSG_SIZ], fullname[MSG_SIZ];
921
922
923   ok = MySearchPath(installDir, name, fullname);
924   if(!ok && strchr(name, '.') == NULL)
925     { // append default file-name extension '.ini' when needed
926       len = snprintf(buf,MSG_SIZ, "%s.ini", name);
927       if( (len >= MSG_SIZ) && appData.debugMode )
928         fprintf(debugFP, "ParseSettingsFile: buffer truncated. Input: name=%s \n",name);
929
930       ok = MySearchPath(installDir, buf, fullname);
931     }
932   if (ok) {
933     f = fopen(fullname, "r");
934 #ifdef DATADIR
935     if(f == NULL && *fullname != '/' && !addr) {         // when a relative name did not work
936         char buf[MSG_SIZ];
937         snprintf(buf, MSG_SIZ, "~/.xboard/themes/conf/%s", name);
938         MySearchPath(installDir, buf, fullname); // first look in user's own files
939         f = fopen(fullname, "r");
940         if(f == NULL) {
941             snprintf(buf, MSG_SIZ, "%s/themes/conf", dataDir);
942             MySearchPath(buf, name, fullname); // also look in standard place
943             f = fopen(fullname, "r");
944         }
945     }
946 #endif
947     if (f != NULL) {
948       if (addr != NULL) {
949             ASSIGN(*addr, fullname);
950       }
951       ParseArgs(FileGet, f);
952       fclose(f);
953       return TRUE;
954     }
955   }
956   return FALSE;
957 }
958
959 void
960 ParseArgs(GetFunc get, void *cl)
961 {
962   char argName[MAX_ARG_LEN];
963   char argValue[MAX_ARG_LEN];
964   ArgDescriptor *ad;
965   char start;
966   char *q, *r, *s;
967   int i, octval;
968   char ch;
969   int posarg = 4; // default is game file
970
971   ch = get(cl);
972   for (;;) {
973     int posflag = 0;
974     while (ch == ' ' || ch == '\n' || ch == '\t') ch = get(cl);
975     if (ch == NULLCHAR) break;
976     if (ch == ';') {
977       /* Comment to end of line */
978       ch = get(cl);
979       while (ch != '\n' && ch != NULLCHAR) ch = get(cl);
980       continue;
981     } else if (ch == SLASH || ch == '-') {
982       /* Switch */
983       q = argName;
984       while (ch != ' ' && ch != '=' && ch != ':' && ch != NULLCHAR &&
985              ch != '\n' && ch != '\t') {
986         *q++ = ch;
987         ch = get(cl);
988       }
989       *q = NULLCHAR;
990       for (ad = argDescriptors; ad->argName != NULL; ad++)
991         if (strcmp(ad->argName, argName + 1) == 0) break;
992       if (ad->argName == NULL) {
993         char endChar = (ch && ch != '\n' && (ch = get(cl)) == '{' ? '}' : '\n');
994         ExitArgError(_("Unrecognized argument %s"), argName, get != &FileGet); // [HGM] make unknown argument non-fatal
995         while (ch != endChar && ch != NULLCHAR) ch = get(cl); // but skip rest of line it is on (or until closing '}' )
996         if(ch == '}') ch = get(cl);
997         continue; // so that when it is in a settings file, it is the only setting that will be purged from it
998       }
999     } else if (ch == '@') {
1000       /* Indirection file */
1001       ad = &argDescriptorIndirection;
1002       ch = get(cl);
1003     } else {
1004       /* Positional argument */
1005       ad = &argDescriptors[posarg++];
1006       posflag++;
1007       strncpy(argName, ad->argName,sizeof(argName)/sizeof(argName[0]));
1008     }
1009
1010     if (ad->argType == ArgTwo) { // [HGM] kludgey arg type, not suitable for saving
1011       *(Boolean *) ad->argLoc = 2;
1012       continue;
1013     }
1014     if (ad->argType == ArgTrue) {
1015       *(Boolean *) ad->argLoc = TRUE;
1016       continue;
1017     }
1018     if (ad->argType == ArgFalse) {
1019       *(Boolean *) ad->argLoc = FALSE;
1020       continue;
1021     }
1022
1023     while (ch == ' ' || ch == '=' || ch == ':' || ch == '\t') ch = get(cl);
1024     if (ch == NULLCHAR || ch == '\n') {
1025       ExitArgError(_("No value provided for argument %s"), argName, TRUE);
1026     }
1027     q = argValue;
1028     if (ch == '{') {
1029       // Quoting with { }.  No characters have to (or can) be escaped.
1030       // Thus the string cannot contain a '}' character.
1031       start = ch;
1032       ch = get(cl);
1033       while (start) {
1034         switch (ch) {
1035         case NULLCHAR:
1036           start = NULLCHAR;
1037           break;
1038
1039         case '}':
1040           ch = get(cl);
1041           start = NULLCHAR;
1042           break;
1043
1044         default:
1045           *q++ = ch;
1046           ch = get(cl);
1047           break;
1048         }
1049       }
1050     } else if (ch == '\'' || ch == '"') {
1051       // Quoting with ' ' or " ", with \ as escape character.
1052       // Inconvenient for long strings that may contain Windows filenames.
1053       start = ch;
1054       ch = get(cl);
1055       while (start) {
1056         switch (ch) {
1057         case NULLCHAR:
1058           start = NULLCHAR;
1059           break;
1060
1061         default:
1062         not_special:
1063           *q++ = ch;
1064           ch = get(cl);
1065           break;
1066
1067         case '\'':
1068         case '\"':
1069           if (ch == start) {
1070             ch = get(cl);
1071             start = NULLCHAR;
1072             break;
1073           } else {
1074             goto not_special;
1075           }
1076
1077         case '\\':
1078           if (ad->argType == ArgFilename
1079               || ad->argType == ArgSettingsFilename) {
1080               goto not_special;
1081           }
1082           ch = get(cl);
1083           switch (ch) {
1084           case NULLCHAR:
1085             ExitArgError(_("Incomplete \\ escape in value for %s"), argName, TRUE);
1086             break;
1087           case 'n':
1088             *q++ = '\n';
1089             ch = get(cl);
1090             break;
1091           case 'r':
1092             *q++ = '\r';
1093             ch = get(cl);
1094             break;
1095           case 't':
1096             *q++ = '\t';
1097             ch = get(cl);
1098             break;
1099           case 'b':
1100             *q++ = '\b';
1101             ch = get(cl);
1102             break;
1103           case 'f':
1104             *q++ = '\f';
1105             ch = get(cl);
1106             break;
1107           default:
1108             octval = 0;
1109             for (i = 0; i < 3; i++) {
1110               if (ch >= '0' && ch <= '7') {
1111                 octval = octval*8 + (ch - '0');
1112                 ch = get(cl);
1113               } else {
1114                 break;
1115               }
1116             }
1117             if (i > 0) {
1118               *q++ = (char) octval;
1119             } else {
1120               *q++ = ch;
1121               ch = get(cl);
1122             }
1123             break;
1124           }
1125           break;
1126         }
1127       }
1128     } else {
1129       while ((ch != ' ' || posflag) && ch != NULLCHAR && ch != '\t' && ch != '\n') { // space allowed in positional arg
1130         *q++ = ch;
1131         ch = get(cl);
1132       }
1133     }
1134     *q = NULLCHAR;
1135
1136     if(posflag) { // positional argument: the argName was implied, and per default set as -lgf
1137       int len = strlen(argValue) - 4; // start of filename extension
1138       if(len < 0) len = 0;
1139       if(!StrCaseCmp(argValue + len, ".trn")) {
1140         ad = &argDescriptors[2]; // correct implied type to -tf
1141         appData.tourney = TRUE; // let it parse -tourneyOptions later
1142       } else if(!StrCaseCmp(argValue + len, ".fen") || !StrCaseCmp(argValue + len, ".epd")) {
1143         ad = &argDescriptors[1]; // correct implied type to -lpf
1144         appData.viewer = TRUE;
1145       } else if(!StrCaseCmp(argValue + len, ".ini") || !StrCaseCmp(argValue + len, ".xop")) {
1146         ad = &argDescriptors[0]; // correct implied type to -opt
1147       } else if(GetEngineLine(argValue, 11)) {
1148         ad = &argDescriptors[3]; // correct implied type to -is
1149       } else { // keep default -lgf, but let it imply viewer mode as well
1150         appData.viewer = TRUE;
1151       }
1152       strncpy(argName, ad->argName,sizeof(argName)/sizeof(argName[0]));
1153     }
1154
1155     switch (ad->argType) {
1156     case ArgInt:
1157       *(int *) ad->argLoc = ValidateInt(argValue);
1158       break;
1159
1160     case ArgX:
1161       *(int *) ad->argLoc = ValidateInt(argValue) + wpMain.x; // [HGM] placement: translate stored relative to absolute
1162       break;
1163
1164     case ArgY:
1165       *(int *) ad->argLoc = ValidateInt(argValue) + wpMain.y; // (this is really kludgey, it should be done where used...)
1166       break;
1167
1168     case ArgZ:
1169       *(int *) ad->argLoc = ValidateInt(argValue);
1170       EnsureOnScreen(&wpMain.x, &wpMain.y, minX, minY);
1171       break;
1172
1173     case ArgFloat:
1174       *(float *) ad->argLoc = (float) atof(argValue);
1175       break;
1176
1177     case ArgString:
1178     case ArgFilename:
1179       if(argValue[0] == '~' && argValue[1] == '~') {
1180         char buf[4*MSG_SIZ]; // expand ~~
1181         snprintf(buf, 4*MSG_SIZ, "%s%s", dataDir, argValue+2);
1182         ASSIGN(*(char **) ad->argLoc, buf);
1183         break;
1184       }
1185       ASSIGN(*(char **) ad->argLoc, argValue);
1186       break;
1187
1188     case ArgBackupSettingsFile: // no-op if non-default settings-file already successfully read
1189         if(strcmp(*(char**)ad->argLoc, SETTINGS_FILE)) break;
1190     case ArgSettingsFilename:
1191       {
1192         if (ParseSettingsFile(argValue, (char**)ad->argLoc)) {
1193         } else {
1194           if (ad->argLoc != NULL) {
1195           } else {
1196             ExitArgError(_("Failed to open indirection file %s"), argValue, TRUE);
1197           }
1198         }
1199       }
1200       break;
1201
1202     case ArgBoolean:
1203       switch (argValue[0]) {
1204       case 't':
1205       case 'T':
1206         *(Boolean *) ad->argLoc = TRUE;
1207         break;
1208       case 'f':
1209       case 'F':
1210         *(Boolean *) ad->argLoc = FALSE;
1211         break;
1212       default:
1213         ExitArgError(_("Unrecognized boolean argument value %s"), argValue, TRUE);
1214         break;
1215       }
1216       break;
1217
1218     case ArgColor:
1219       ParseColor((int)(intptr_t)ad->argLoc, argValue);
1220       break;
1221
1222     case ArgAttribs: {
1223       ColorClass cc = (ColorClass)ad->argLoc;
1224         ParseTextAttribs(cc, argValue); // [HGM] wrapper for platform independency
1225       }
1226       break;
1227
1228     case ArgBoardSize:
1229       ParseBoardSize(ad->argLoc, argValue);
1230       break;
1231
1232     case ArgFont:
1233       ParseFont(argValue, (int)(intptr_t)ad->argLoc);
1234       break;
1235
1236     case ArgCommSettings:
1237       ParseCommPortSettings(argValue);
1238       break;
1239
1240     case ArgMaster:
1241       AppendToSettingsFile(argValue);
1242       break;
1243
1244     case ArgInstall:
1245       q = *(char **) ad->argLoc;
1246       r = NULL; s = argValue;
1247       if(argValue[0] == '#') { // group specification
1248         r = strstr(argValue, "\\n");
1249         if(r) *r++ = '\n', *r++ = NULLCHAR, s = r, r = argValue; // split s into line-to-add (s) and group (r)
1250       }
1251       if((saveDate == 0 || saveDate - dateStamp < 0) && !strstr(q, s) ) { // not seen before, and line does not occur yet
1252         int l = strlen(q) + strlen(s);
1253         if(r) { // must be put in group r
1254           char *p = strstr(q, r);
1255           if(p) { // group already exists
1256             p += strlen(r) - 1; // determine insertion point (immediately after group header line)
1257             *(char **) ad->argLoc = malloc(l+2);
1258             *p++ = NULLCHAR; // spit old value (q) at insertion point into q and p
1259             snprintf(*(char **) ad->argLoc, l+2, "%s\n%s\n%s", q, s, p); // insert (with newline)
1260           } else { // group did not exist, create at end
1261             l += strlen(r) + 8;
1262             *(char **) ad->argLoc = malloc(l);
1263             snprintf(*(char **) ad->argLoc, l, "%s%s%s\n# end\n", q, r, s);
1264           }
1265         } else { // no group, just add line at end
1266           *(char **) ad->argLoc = malloc(l+2);
1267           snprintf(*(char **) ad->argLoc, l+2, "%s%s\n", q, s);
1268         }
1269         free(q);
1270       }
1271       break;
1272
1273     case ArgNone:
1274       ExitArgError(_("Unrecognized argument %s"), argValue, TRUE);
1275       break;
1276     case ArgTwo:
1277     case ArgTrue:
1278     case ArgFalse: ;
1279     }
1280   }
1281 }
1282
1283 void
1284 ParseArgsFromString(char *p)
1285 {
1286     ParseArgs(StringGet, &p);
1287 }
1288
1289 void
1290 ParseArgsFromFile(FILE *f)
1291 {
1292     ParseArgs(FileGet, f);
1293 }
1294
1295 void
1296 ParseIcsTextMenu(char *icsTextMenuString)
1297 {
1298 //  int flags = 0;
1299   IcsTextMenuEntry *e = icsTextMenuEntry;
1300   char *p = icsTextMenuString;
1301   while (e->item != NULL && e < icsTextMenuEntry + ICS_TEXT_MENU_SIZE) {
1302     free(e->item);
1303     e->item = NULL;
1304     if (e->command != NULL) {
1305       free(e->command);
1306       e->command = NULL;
1307     }
1308     e++;
1309   }
1310   e = icsTextMenuEntry;
1311   while (*p && e < icsTextMenuEntry + ICS_TEXT_MENU_SIZE) {
1312     if (*p == ';' || *p == '\n') {
1313       e->item = strdup("-");
1314       e->command = NULL;
1315       p++;
1316     } else if (*p == '-') {
1317       e->item = strdup("-");
1318       e->command = NULL;
1319       p++;
1320       if (*p) p++;
1321     } else {
1322       char *q, *r, *s, *t;
1323       char c;
1324       q = strchr(p, ',');
1325       if (q == NULL) break;
1326       *q = NULLCHAR;
1327       r = strchr(q + 1, ',');
1328       if (r == NULL) break;
1329       *r = NULLCHAR;
1330       s = strchr(r + 1, ',');
1331       if (s == NULL) break;
1332       *s = NULLCHAR;
1333       c = ';';
1334       t = strchr(s + 1, c);
1335       if (t == NULL) {
1336         c = '\n';
1337         t = strchr(s + 1, c);
1338       }
1339       if (t != NULL) *t = NULLCHAR;
1340       e->item = strdup(p);
1341       e->command = strdup(q + 1);
1342       e->getname = *(r + 1) != '0';
1343       e->immediate = *(s + 1) != '0';
1344       *q = ',';
1345       *r = ',';
1346       *s = ',';
1347       if (t == NULL) break;
1348       *t = c;
1349       p = t + 1;
1350     }
1351     e++;
1352   }
1353 }
1354
1355 void
1356 SetDefaultTextAttribs()
1357 {
1358   ColorClass cc;
1359   for (cc = (ColorClass)0; cc < ColorNone; cc++) {
1360     ParseTextAttribs(cc, defaultTextAttribs[cc]);
1361   }
1362 }
1363
1364 void
1365 SetDefaultsFromList()
1366 { // [HGM] ini: take defaults from argDescriptor list
1367   int i;
1368
1369   for(i=0; argDescriptors[i].argName != NULL; i++) {
1370     if(argDescriptors[i].defaultValue != INVALID)
1371       switch(argDescriptors[i].argType) {
1372         case ArgBoolean:
1373         case ArgTwo:
1374         case ArgTrue:
1375         case ArgFalse:
1376           *(Boolean *) argDescriptors[i].argLoc = (int)(intptr_t)argDescriptors[i].defaultValue;
1377           break;
1378         case ArgInt:
1379         case ArgX:
1380         case ArgY:
1381         case ArgZ:
1382           *(int *) argDescriptors[i].argLoc = (int)(intptr_t)argDescriptors[i].defaultValue;
1383           break;
1384         case ArgString:
1385         case ArgFilename:
1386         case ArgSettingsFilename:
1387           if((char *)argDescriptors[i].defaultValue)
1388           *(char **) argDescriptors[i].argLoc = strdup((char *)argDescriptors[i].defaultValue);
1389           break;
1390         case ArgBoardSize:
1391           *(int *) argDescriptors[i].argLoc = (int)(intptr_t)argDescriptors[i].defaultValue;
1392           break;
1393         case ArgColor:
1394           ParseColor((int)(intptr_t)argDescriptors[i].argLoc, (char*)argDescriptors[i].defaultValue);
1395           break;
1396         case ArgFloat: // floats cannot be casted to int without precision loss
1397         default: ; // some arg types cannot be initialized through table
1398     }
1399   }
1400 }
1401
1402 void
1403 InitAppData(char *lpCmdLine)
1404 {
1405   int i;
1406   char buf[MAX_ARG_LEN], currDir[MSG_SIZ];
1407   char *p;
1408
1409   /* Initialize to defaults */
1410   SetDefaultsFromList(); // this sets most defaults
1411
1412   // some parameters for which there are no options!
1413   appData.Iconic = FALSE; /*unused*/
1414   appData.icsEngineAnalyze = FALSE;
1415
1416   // float: casting to int is not harmless, so default cannot be contained in table
1417   appData.timeDelay = TIME_DELAY;
1418   appData.timeIncrement = -314159;
1419
1420   // some complex, platform-dependent stuff that could not be handled from table
1421   SetDefaultTextAttribs();
1422   SetFontDefaults();
1423   SetCommPortDefaults();
1424
1425   /* Parse default settings file if any */
1426   ParseSettingsFile(settingsFileName, &settingsFileName);
1427
1428   /* Parse command line */
1429   ParseArgs(StringGet, &lpCmdLine);
1430
1431   if(appData.viewer && appData.viewerOptions[0]) ParseArgsFromString(appData.viewerOptions);
1432   if(appData.tourney && appData.tourneyOptions[0]) ParseArgsFromString(appData.tourneyOptions);
1433   chessProgram |= GetEngineLine(firstEngineLine, 0) || GetEngineLine(secondEngineLine, 1);
1434   appData.icsActive |= GetEngineLine(icsNick, 10);
1435
1436   /* [HGM] make sure board size is acceptable */
1437   if(appData.NrFiles > BOARD_FILES ||
1438      appData.NrRanks > BOARD_RANKS   )
1439       DisplayFatalError("Recompile with BOARD_RANKS or BOARD_FILES, to support this size", 0, 2);
1440
1441   if(!*appData.secondChessProgram) { // [HGM] scp defaults to fcp
1442     ASSIGN(appData.secondChessProgram, appData.firstChessProgram);
1443     ASSIGN(appData.secondDirectory, appData.firstDirectory);
1444     appData.secondIsUCI = appData.firstIsUCI; // copy type too!
1445   }
1446
1447   /* [HGM] After parsing the options from the .ini file, and overruling them
1448    * with options from the command line, we now make an even higher priority
1449    * overrule by WB options attached to the engine command line. This so that
1450    * tournament managers can use WB options (such as /timeOdds) that follow
1451    * the engines.
1452    */
1453   if(appData.firstChessProgram != NULL) {
1454       char *p = StrStr(appData.firstChessProgram, "WBopt");
1455       static char *f = "first";
1456       char buf[MSG_SIZ], *q = buf;
1457       int len;
1458
1459       if(p != NULL)
1460         { // engine command line contains WinBoard options
1461           len = snprintf(buf, MSG_SIZ, p+6, f, f, f, f, f, f, f, f, f, f); // replace %s in them by "first"
1462           if( (len >= MSG_SIZ) && appData.debugMode )
1463             fprintf(debugFP, "InitAppData: buffer truncated.\n");
1464
1465           ParseArgs(StringGet, &q);
1466           p[-1] = 0; // cut them offengine command line
1467         }
1468   }
1469   // now do same for second chess program
1470   if(appData.secondChessProgram != NULL) {
1471       char *p = StrStr(appData.secondChessProgram, "WBopt");
1472       static char *s = "second";
1473       char buf[MSG_SIZ], *q = buf;
1474       int len;
1475
1476       if(p != NULL)
1477         { // engine command line contains WinBoard options
1478           len = snprintf(buf,MSG_SIZ, p+6, s, s, s, s, s, s, s, s, s, s); // replace %s in them by "first"
1479           if( (len >= MSG_SIZ) && appData.debugMode )
1480             fprintf(debugFP, "InitAppData: buffer truncated.\n");
1481
1482           ParseArgs(StringGet, &q);
1483           p[-1] = 0; // cut them offengine command line
1484         }
1485   }
1486
1487   /* Propagate options that affect others */
1488   if (appData.matchMode || appData.matchGames) chessProgram = TRUE;
1489   if (appData.icsActive || appData.noChessProgram) {
1490      chessProgram = FALSE;  /* not local chess program mode */
1491   }
1492   if(appData.timeIncrement == -314159) { // new storage mechanism of (mps,inc) in use and no -inc on command line
1493     if(appData.movesPerSession <= 0) { // new encoding of incremental mode
1494       appData.timeIncrement = -appData.movesPerSession/1000.;
1495     } else appData.timeIncrement = -1;
1496   }
1497   if(appData.movesPerSession <= 0) appData.movesPerSession = MOVES_PER_SESSION; // mps <= 0 is invalid in any case
1498   if(*appData.defaultPathEGTB) { // append value of deprecated -defaultPathEGTB to -egtFormats
1499     snprintf(buf, MAX_ARG_LEN, "%s%snalimov:%s", appData.egtFormats, (*appData.egtFormats ?"," : ""), appData.defaultPathEGTB);
1500     ASSIGN(appData.egtFormats, buf);
1501     ASSIGN(appData.defaultPathEGTB, "");
1502   }
1503
1504   /* Open startup dialog if needed */
1505   if ((!appData.noChessProgram && !chessProgram && !appData.icsActive) ||
1506       (appData.icsActive && *appData.icsHost == NULLCHAR) ||
1507       (chessProgram && (*appData.firstChessProgram == NULLCHAR ||
1508                         *appData.secondChessProgram == NULLCHAR)))
1509                 PopUpStartupDialog();
1510
1511   /* Make sure save files land in the right (?) directory */
1512   if (MyGetFullPathName(appData.saveGameFile, buf)) {
1513     appData.saveGameFile = strdup(buf);
1514   }
1515   if (MyGetFullPathName(appData.savePositionFile, buf)) {
1516     appData.savePositionFile = strdup(buf);
1517   }
1518
1519   if(autoClose) { // was called for updating settingsfile only
1520     if(saveSettingsOnExit) SaveSettings(settingsFileName);
1521     exit(0);
1522   }
1523
1524   /* Finish initialization for fonts and sounds */
1525   CreateFonts();
1526
1527   GetCurrentDirectory(MSG_SIZ, currDir);
1528   SetCurrentDirectory(installDir);
1529   LoadAllSounds();
1530   SetCurrentDirectory(currDir);
1531
1532   p = icsTextMenuString;
1533   if (p[0] == '@') {
1534     FILE* f = fopen(p + 1, "r");
1535     if (f == NULL) {
1536       DisplayFatalError(p + 1, errno, 2);
1537       return;
1538     }
1539     i = fread(buf, 1, sizeof(buf)-1, f);
1540     fclose(f);
1541     buf[i] = NULLCHAR;
1542     p = buf;
1543   }
1544   ParseIcsTextMenu(strdup(p));
1545 }
1546
1547 void
1548 SaveSettings(char* name)
1549 {
1550   FILE *f;
1551   ArgDescriptor *ad;
1552   char dir[MSG_SIZ], buf[MSG_SIZ];
1553   int mps = appData.movesPerSession;
1554
1555   if (!MainWindowUp() && !autoClose) return;
1556
1557   saveDate = programStartTime.sec;
1558
1559   GetCurrentDirectory(MSG_SIZ, dir);
1560   if(MySearchPath(installDir, name, buf)) {
1561     f = fopen(buf, "w");
1562   } else {
1563     SetCurrentDirectory(installDir);
1564     f = fopen(name, "w");
1565     SetCurrentDirectory(dir);
1566   }
1567   if (f == NULL) {
1568     DisplayError(name, errno);
1569     return;
1570   }
1571
1572   fprintf(f, ";\n");
1573   fprintf(f, "; %s Save Settings file\n", PACKAGE_STRING);
1574   fprintf(f, ";\n");
1575   fprintf(f, "; You can edit the values of options that are already set in this file,\n");
1576   fprintf(f, "; but if you add other options, the next Save Settings will not save them.\n");
1577   fprintf(f, "; Use a shortcut, an @indirection file, or a .bat file instead.\n");
1578   fprintf(f, ";\n");
1579
1580   GetWindowCoords();
1581
1582   /* [AS] Move history */
1583   wpMoveHistory.visible = MoveHistoryIsUp();
1584
1585   /* [AS] Eval graph */
1586   wpEvalGraph.visible = EvalGraphIsUp();
1587
1588   /* [AS] Engine output */
1589   wpEngineOutput.visible = EngineOutputIsUp();
1590
1591   // [HGM] in WB we have to copy sound names to appData first
1592   ExportSounds();
1593
1594   if(appData.timeIncrement >= 0) appData.movesPerSession = -1000*appData.timeIncrement; // kludge to store mps & inc as one
1595
1596   for (ad = argDescriptors; ad->argName != NULL; ad++) {
1597     if (!ad->save) continue;
1598     switch (ad->argType) {
1599     case ArgString:
1600       {
1601         char *p = *(char **)ad->argLoc;
1602         if(p == NULL) break; // just in case
1603         if ((strchr(p, '\\') || strchr(p, '\n')) && !strchr(p, '}')) {
1604           /* Quote multiline values or \-containing values
1605              with { } if possible */
1606           fprintf(f, OPTCHAR "%s" SEPCHAR "{%s}\n", ad->argName, p);
1607         } else {
1608           /* Else quote with " " */
1609           fprintf(f, OPTCHAR "%s" SEPCHAR "\"", ad->argName);
1610           while (*p) {
1611             if (*p == '\n') fprintf(f, "\n");
1612             else if (*p == '\r') fprintf(f, "\\r");
1613             else if (*p == '\t') fprintf(f, "\\t");
1614             else if (*p == '\b') fprintf(f, "\\b");
1615             else if (*p == '\f') fprintf(f, "\\f");
1616             else if (*p < ' ') fprintf(f, "\\%03o", *p);
1617             else if (*p == '\"') fprintf(f, "\\\"");
1618             else if (*p == '\\') fprintf(f, "\\\\");
1619             else putc(*p, f);
1620             p++;
1621           }
1622           fprintf(f, "\"\n");
1623         }
1624       }
1625       break;
1626     case ArgInt:
1627     case ArgZ:
1628       fprintf(f, OPTCHAR "%s" SEPCHAR "%d\n", ad->argName, *(int *)ad->argLoc);
1629       break;
1630     case ArgX:
1631       fprintf(f, OPTCHAR "%s" SEPCHAR "%d\n", ad->argName, *(int *)ad->argLoc - wpMain.x); // [HGM] placement: store relative value
1632       break;
1633     case ArgY:
1634       fprintf(f, OPTCHAR "%s" SEPCHAR "%d\n", ad->argName, *(int *)ad->argLoc - wpMain.y);
1635       break;
1636     case ArgFloat:
1637       fprintf(f, OPTCHAR "%s" SEPCHAR "%g\n", ad->argName, *(float *)ad->argLoc);
1638       break;
1639     case ArgBoolean:
1640       fprintf(f, OPTCHAR "%s" SEPCHAR "%s\n", ad->argName,
1641         (*(Boolean *)ad->argLoc) ? "true" : "false");
1642       break;
1643     case ArgTrue:
1644       if (*(Boolean *)ad->argLoc) fprintf(f, OPTCHAR "%s\n", ad->argName);
1645       break;
1646     case ArgFalse:
1647       if (!*(Boolean *)ad->argLoc) fprintf(f, OPTCHAR "%s\n", ad->argName);
1648       break;
1649     case ArgColor:
1650       SaveColor(f, ad);
1651       break;
1652     case ArgAttribs:
1653       SaveAttribsArg(f, ad);
1654       break;
1655     case ArgFilename:
1656       if(*(char**)ad->argLoc == NULL) break; // just in case
1657       { char buf[MSG_SIZ];
1658         snprintf(buf, MSG_SIZ, "%s", *(char**)ad->argLoc);
1659 #ifdef OSXAPP
1660         if(strstr(buf, dataDir) == buf)
1661           snprintf(buf, MSG_SIZ, "~~%s", *(char**)ad->argLoc + strlen(dataDir));
1662 #endif
1663         if (strchr(buf, '\"')) {
1664           fprintf(f, OPTCHAR "%s" SEPCHAR "'%s'\n", ad->argName, buf);
1665         } else {
1666           fprintf(f, OPTCHAR "%s" SEPCHAR "\"%s\"\n", ad->argName, buf);
1667         }
1668       }
1669       break;
1670     case ArgBoardSize:
1671       SaveBoardSize(f, ad->argName, ad->argLoc);
1672       break;
1673     case ArgFont:
1674       SaveFontArg(f, ad);
1675       break;
1676     case ArgCommSettings:
1677       PrintCommPortSettings(f, ad->argName);
1678     case ArgTwo:
1679     case ArgNone:
1680     case ArgBackupSettingsFile:
1681     case ArgSettingsFilename: ;
1682     case ArgMaster: ;
1683     case ArgInstall: ;
1684     }
1685   }
1686   fclose(f);
1687   appData.movesPerSession = mps;
1688 }
1689
1690 Boolean
1691 GetArgValue(char *name)
1692 { // retrieve (as text) current value of string or int argument given by name
1693   // (this is used for maing the values available in the adapter command)
1694   ArgDescriptor *ad;
1695   int len;
1696
1697   for (ad = argDescriptors; ad->argName != NULL; ad++)
1698     if (strcmp(ad->argName, name) == 0) break;
1699
1700   if (ad->argName == NULL) return FALSE;
1701
1702   switch(ad->argType) {
1703     case ArgString:
1704     case ArgFilename:
1705       strncpy(name, *(char**) ad->argLoc, MSG_SIZ);
1706
1707       return TRUE;
1708     case ArgInt:
1709       len = snprintf(name, MSG_SIZ, "%d", *(int*) ad->argLoc);
1710       if( (len >= MSG_SIZ) && appData.debugMode )
1711         fprintf(debugFP, "GetArgValue: buffer truncated.\n");
1712
1713       return TRUE;
1714     case ArgBoolean:
1715       len = snprintf(name, MSG_SIZ, "%s", *(Boolean*) ad->argLoc ? "true" : "false");
1716       if( (len >= MSG_SIZ) && appData.debugMode )
1717         fprintf(debugFP, "GetArgValue: buffer truncated.\n");
1718
1719       return TRUE;
1720     default: ;
1721   }
1722
1723   return FALSE;
1724 }