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