Let file selecor remember last used directory (GTK)
[xboard.git] / menus.c
1 /*
2  * menus.c -- platform-indendent menu handling code for 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 Free Software Foundation, Inc.
9  *
10  * The following terms apply to Digital Equipment Corporation's copyright
11  * interest in XBoard:
12  * ------------------------------------------------------------------------
13  * All Rights Reserved
14  *
15  * Permission to use, copy, modify, and distribute this software and its
16  * documentation for any purpose and without fee is hereby granted,
17  * provided that the above copyright notice appear in all copies and that
18  * both that copyright notice and this permission notice appear in
19  * supporting documentation, and that the name of Digital not be
20  * used in advertising or publicity pertaining to distribution of the
21  * software without specific, written prior permission.
22  *
23  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
24  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
25  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
26  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
27  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
28  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
29  * SOFTWARE.
30  * ------------------------------------------------------------------------
31  *
32  * The following terms apply to the enhanced version of XBoard
33  * distributed by the Free Software Foundation:
34  * ------------------------------------------------------------------------
35  *
36  * GNU XBoard is free software: you can redistribute it and/or modify
37  * it under the terms of the GNU General Public License as published by
38  * the Free Software Foundation, either version 3 of the License, or (at
39  * your option) any later version.
40  *
41  * GNU XBoard is distributed in the hope that it will be useful, but
42  * WITHOUT ANY WARRANTY; without even the implied warranty of
43  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
44  * General Public License for more details.
45  *
46  * You should have received a copy of the GNU General Public License
47  * along with this program. If not, see http://www.gnu.org/licenses/.  *
48  *
49  *------------------------------------------------------------------------
50  ** See the file ChangeLog for a revision history.  */
51
52 #define HIGHDRAG 1
53
54 #include "config.h"
55
56 #include <stdio.h>
57 #include <ctype.h>
58 #include <signal.h>
59 #include <errno.h>
60 #include <sys/types.h>
61 #include <sys/stat.h>
62 #include <pwd.h>
63 #include <math.h>
64
65 #if STDC_HEADERS
66 # include <stdlib.h>
67 # include <string.h>
68 #else /* not STDC_HEADERS */
69 extern char *getenv();
70 # if HAVE_STRING_H
71 #  include <string.h>
72 # else /* not HAVE_STRING_H */
73 #  include <strings.h>
74 # endif /* not HAVE_STRING_H */
75 #endif /* not STDC_HEADERS */
76
77 #if HAVE_UNISTD_H
78 # include <unistd.h>
79 #endif
80
81 #if ENABLE_NLS
82 #include <locale.h>
83 #endif
84
85 // [HGM] bitmaps: put before incuding the bitmaps / pixmaps, to know how many piece types there are.
86 #include "common.h"
87
88 #include "frontend.h"
89 #include "backend.h"
90 #include "menus.h"
91 #include "gettext.h"
92
93 #ifdef ENABLE_NLS
94 # define  _(s) gettext (s)
95 # define N_(s) gettext_noop (s)
96 #else
97 # define  _(s) (s)
98 # define N_(s)  s
99 #endif
100
101 /*
102  * Button/menu procedures
103  */
104
105 char  *gameCopyFilename, *gamePasteFilename;
106 Boolean saveSettingsOnExit;
107 char *settingsFileName;
108 char gamesDir[MSG_SIZ], positionsDir[MSG_SIZ], textureDir[MSG_SIZ], bookDir[MSG_SIZ], piecesDir[MSG_SIZ];
109
110 static int
111 LoadGamePopUp (FILE *f, int gameNumber, char *title)
112 {
113     cmailMsgLoaded = FALSE;
114     if (gameNumber == 0) {
115         int error = GameListBuild(f);
116         if (error) {
117             DisplayError(_("Cannot build game list"), error);
118         } else if (!ListEmpty(&gameList) &&
119                    ((ListGame *) gameList.tailPred)->number > 1) {
120             GameListPopUp(f, title);
121             return TRUE;
122         }
123         GameListDestroy();
124         gameNumber = 1;
125     }
126     return LoadGame(f, gameNumber, title, FALSE);
127 }
128
129 void
130 LoadGameProc ()
131 {
132     if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
133         Reset(FALSE, TRUE);
134     }
135     FileNamePopUp(_("Load game file name?"), "", ".pgn .game", LoadGamePopUp, "rb");
136 }
137
138 void
139 LoadNextGameProc ()
140 {
141     ReloadGame(1);
142 }
143
144 void
145 LoadPrevGameProc ()
146 {
147     ReloadGame(-1);
148 }
149
150 void
151 ReloadGameProc ()
152 {
153     ReloadGame(0);
154 }
155
156 void
157 LoadNextPositionProc ()
158 {
159     ReloadPosition(1);
160 }
161
162 void
163 LoadPrevPositionProc ()
164 {
165     ReloadPosition(-1);
166 }
167
168 void
169 ReloadPositionProc ()
170 {
171     ReloadPosition(0);
172 }
173
174 void
175 LoadPositionProc()
176 {
177     if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
178         Reset(FALSE, TRUE);
179     }
180     FileNamePopUp(_("Load position file name?"), "", ".fen .epd .pos", LoadPosition, "rb");
181 }
182
183 void
184 SaveGameProc ()
185 {
186     FileNamePopUp(_("Save game file name?"),
187                   DefaultFileName(appData.oldSaveStyle ? "game" : "pgn"),
188                   appData.oldSaveStyle ? ".game" : ".pgn",
189                   SaveGame, "a");
190 }
191
192 void
193 SavePositionProc ()
194 {
195     FileNamePopUp(_("Save position file name?"),
196                   DefaultFileName(appData.oldSaveStyle ? "pos" : "fen"),
197                   appData.oldSaveStyle ? ".pos" : ".fen",
198                   SavePosition, "a");
199 }
200
201 void
202 ReloadCmailMsgProc ()
203 {
204     ReloadCmailMsgEvent(FALSE);
205 }
206
207 void
208 CopyFENToClipboard ()
209 { // wrapper to make call from back-end possible
210   CopyPositionProc();
211 }
212
213 void
214 CopyPositionProc ()
215 {
216     static char *selected_fen_position=NULL;
217     if(gameMode == EditPosition) EditPositionDone(TRUE);
218     if (selected_fen_position) free(selected_fen_position);
219     selected_fen_position = (char *)PositionToFEN(currentMove, NULL, 1);
220     if (!selected_fen_position) return;
221     CopySomething(selected_fen_position);
222 }
223
224 void
225 CopyGameProc ()
226 {
227   int ret;
228
229   ret = SaveGameToFile(gameCopyFilename, FALSE);
230   if (!ret) return;
231
232   CopySomething(NULL);
233 }
234
235 void
236 CopyGameListProc ()
237 {
238   if(!SaveGameListAsText(fopen(gameCopyFilename, "w"))) return;
239   CopySomething(NULL);
240 }
241
242 void
243 AutoSaveGame ()
244 {
245     SaveGameProc();
246 }
247
248
249 void
250 QuitProc ()
251 {
252     ExitEvent(0);
253 }
254
255 void
256 MatchProc ()
257 {
258     MatchEvent(2);
259 }
260
261 void
262 AdjuWhiteProc ()
263 {
264     UserAdjudicationEvent(+1);
265 }
266
267 void
268 AdjuBlackProc ()
269 {
270     UserAdjudicationEvent(-1);
271 }
272
273 void
274 AdjuDrawProc ()
275 {
276     UserAdjudicationEvent(0);
277 }
278
279 void
280 RevertProc ()
281 {
282     RevertEvent(False);
283 }
284
285 void
286 AnnotateProc ()
287 {
288     RevertEvent(True);
289 }
290
291 void
292 FlipViewProc ()
293 {
294     if(twoBoards) { partnerUp = 1; DrawPosition(True, NULL); partnerUp = 0; }
295     flipView = !flipView;
296     DrawPosition(True, NULL);
297 }
298
299 void
300 SaveOnExitProc ()
301 {
302   saveSettingsOnExit = !saveSettingsOnExit;
303
304   MarkMenuItem("Options.SaveSettingsonExit", saveSettingsOnExit);
305 }
306
307 void
308 SaveSettingsProc ()
309 {
310   SaveSettings(settingsFileName);
311 }
312
313 void
314 InfoProc ()
315 {
316     char buf[MSG_SIZ];
317 #ifdef OSXAPP
318     snprintf(buf, MSG_SIZ, "%s ./info.command", appData.sysOpen);
319 #else
320     snprintf(buf, sizeof(buf), "xterm -e info --directory %s --directory . -f %s &",
321             INFODIR, INFOFILE);
322 #endif
323     system(buf);
324 }
325
326 void
327 BugReportProc ()
328 {
329     char buf[MSG_SIZ];
330     snprintf(buf, MSG_SIZ, "%s mailto:bug-xboard@gnu.org", appData.sysOpen);
331     system(buf);
332 }
333
334 void
335 GuideProc ()
336 {
337     char buf[MSG_SIZ];
338     snprintf(buf, MSG_SIZ, "%s http://www.gnu.org/software/xboard/user_guide/UserGuide.html", appData.sysOpen);
339     system(buf);
340 }
341
342 void
343 HomePageProc ()
344 {
345     char buf[MSG_SIZ];
346     snprintf(buf, MSG_SIZ, "%s http://www.gnu.org/software/xboard/", appData.sysOpen);
347     system(buf);
348 }
349
350 void
351 NewsPageProc ()
352 {
353     char buf[MSG_SIZ];
354     snprintf(buf, MSG_SIZ, "%s http://www.gnu.org/software/xboard/whats_new/portal.html", appData.sysOpen);
355     system(buf);
356 }
357
358 void
359 AboutProc ()
360 {
361     char buf[2 * MSG_SIZ];
362 #if ZIPPY
363     char *zippy = _(" (with Zippy code)");
364 #else
365     char *zippy = "";
366 #endif
367     snprintf(buf, sizeof(buf),
368 _("%s%s\n\n"
369 "Copyright 1991 Digital Equipment Corporation\n"
370 "Enhancements Copyright 1992-2014 Free Software Foundation\n"
371 "Enhancements Copyright 2005 Alessandro Scotti\n\n"
372 "%s is free software and carries NO WARRANTY;"
373 "see the file COPYING for more information.\n"
374 "The GTK build of this version is experimental and unstable\n\n"
375 "Visit XBoard on the web at: http://www.gnu.org/software/xboard/\n"
376 "Check out the newest features at: http://www.gnu.org/software/xboard/whats_new.html\n\n"
377 "Report bugs via email at: <bug-xboard@gnu.org>\n\n"
378   ),
379             programVersion, zippy, PACKAGE);
380     ErrorPopUp(_("About XBoard"), buf, FALSE);
381 }
382
383 void
384 DebugProc ()
385 {
386     appData.debugMode = !appData.debugMode;
387     if(!strcmp(appData.nameOfDebugFile, "stderr")) return; // stderr is already open, and should never be closed
388     if(!appData.debugMode) fclose(debugFP);
389     else {
390         debugFP = fopen(appData.nameOfDebugFile, "w");
391         if(debugFP == NULL) debugFP = stderr;
392         else setbuf(debugFP, NULL);
393     }
394 }
395
396 void
397 EditEngineProc ()
398 {
399     EditTagsPopUp(firstChessProgramNames, &firstChessProgramNames);
400 }
401
402 void
403 NothingProc ()
404 {
405     return;
406 }
407
408 #ifdef OPTIONSDIALOG
409 #   define MARK_MENU_ITEM(X,Y)
410 #else
411 #   define MARK_MENU_ITEM(X,Y) MarkMenuItem(X, Y)
412 #endif
413
414 void
415 PonderNextMoveProc ()
416 {
417   PonderNextMoveEvent(!appData.ponderNextMove);
418   MARK_MENU_ITEM("Options.PonderNextMove", appData.ponderNextMove);
419 }
420
421 void
422 AlwaysQueenProc ()
423 {
424     appData.alwaysPromoteToQueen = !appData.alwaysPromoteToQueen;
425     MARK_MENU_ITEM("Options.AlwaysQueen", appData.alwaysPromoteToQueen);
426 }
427
428 void
429 AnimateDraggingProc ()
430 {
431     appData.animateDragging = !appData.animateDragging;
432
433     if (appData.animateDragging) CreateAnimVars();
434     MARK_MENU_ITEM("Options.AnimateDragging", appData.animateDragging);
435 }
436
437 void
438 AnimateMovingProc ()
439 {
440     appData.animate = !appData.animate;
441     if (appData.animate) CreateAnimVars();
442     MARK_MENU_ITEM("Options.AnimateMoving", appData.animate);
443 }
444
445 void
446 AutoflagProc ()
447 {
448     appData.autoCallFlag = !appData.autoCallFlag;
449     MARK_MENU_ITEM("Options.AutoFlag", appData.autoCallFlag);
450 }
451
452 void
453 AutoflipProc ()
454 {
455     appData.autoFlipView = !appData.autoFlipView;
456     MARK_MENU_ITEM("Options.AutoFlipView", appData.autoFlipView);
457 }
458
459 void
460 BlindfoldProc ()
461 {
462     appData.blindfold = !appData.blindfold;
463     MARK_MENU_ITEM("Options.Blindfold", appData.blindfold);
464     DrawPosition(True, NULL);
465 }
466
467 void
468 TestLegalityProc ()
469 {
470     appData.testLegality = !appData.testLegality;
471     MARK_MENU_ITEM("Options.TestLegality", appData.testLegality);
472 }
473
474
475 void
476 FlashMovesProc ()
477 {
478     if (appData.flashCount == 0) {
479         appData.flashCount = 3;
480     } else {
481         appData.flashCount = -appData.flashCount;
482     }
483     MARK_MENU_ITEM("Options.FlashMoves", appData.flashCount > 0);
484 }
485
486 #if HIGHDRAG
487 void
488 HighlightDraggingProc ()
489 {
490     appData.highlightDragging = !appData.highlightDragging;
491     MARK_MENU_ITEM("Options.HighlightDragging", appData.highlightDragging);
492 }
493 #endif
494
495 void
496 HighlightLastMoveProc ()
497 {
498     appData.highlightLastMove = !appData.highlightLastMove;
499     MARK_MENU_ITEM("Options.HighlightLastMove", appData.highlightLastMove);
500 }
501
502 void
503 HighlightArrowProc ()
504 {
505     appData.highlightMoveWithArrow = !appData.highlightMoveWithArrow;
506     MARK_MENU_ITEM("Options.HighlightWithArrow", appData.highlightMoveWithArrow);
507 }
508
509 void
510 IcsAlarmProc ()
511 {
512     appData.icsAlarm = !appData.icsAlarm;
513 //    MARK_MENU_ITEM("Options.ICSAlarm", appData.icsAlarm);
514 }
515
516 void
517 MoveSoundProc ()
518 {
519     appData.ringBellAfterMoves = !appData.ringBellAfterMoves;
520     MARK_MENU_ITEM("Options.MoveSound", appData.ringBellAfterMoves);
521 }
522
523 void
524 OneClickProc ()
525 {
526     appData.oneClick = !appData.oneClick;
527     MARK_MENU_ITEM("Options.OneClickMoving", appData.oneClick);
528 }
529
530 void
531 PeriodicUpdatesProc ()
532 {
533     PeriodicUpdatesEvent(!appData.periodicUpdates);
534     MARK_MENU_ITEM("Options.PeriodicUpdates", appData.periodicUpdates);
535 }
536
537 void
538 PopupExitMessageProc ()
539 {
540     appData.popupExitMessage = !appData.popupExitMessage;
541     MARK_MENU_ITEM("Options.PopupExitMessage", appData.popupExitMessage);
542 }
543
544 void
545 PopupMoveErrorsProc ()
546 {
547     appData.popupMoveErrors = !appData.popupMoveErrors;
548     MARK_MENU_ITEM("Options.PopupMoveErrors", appData.popupMoveErrors);
549 }
550
551 void
552 PremoveProc ()
553 {
554     appData.premove = !appData.premove;
555 //    MARK_MENU_ITEM("Options.Premove", appData.premove);
556 }
557
558 void
559 ShowCoordsProc ()
560 {
561     appData.showCoords = !appData.showCoords;
562     MARK_MENU_ITEM("Options.ShowCoords", appData.showCoords);
563     DrawPosition(True, NULL);
564 }
565
566 void
567 ShowThinkingProc ()
568 {
569     appData.showThinking = !appData.showThinking; // [HGM] thinking: taken out of ShowThinkingEvent
570     ShowThinkingEvent();
571 }
572
573 void
574 HideThinkingProc ()
575 {
576   appData.hideThinkingFromHuman = !appData.hideThinkingFromHuman; // [HGM] thinking: taken out of ShowThinkingEvent
577   ShowThinkingEvent();
578
579   MARK_MENU_ITEM("Options.HideThinking", appData.hideThinkingFromHuman);
580 }
581
582 void
583 CreateBookDelayed ()
584 {
585   ScheduleDelayedEvent(CreateBookEvent, 50);
586 }
587
588 void
589 SaveSelectedProc ()
590 {
591   FileNamePopUp(_("Save game file name?"),
592                   "",
593                   ".pgn",
594                   SaveSelected, "a");
595 }
596
597 /*
598  *  Menu definition tables
599  */
600
601 MenuItem fileMenu[] = {
602   {N_("New Game"),             "<Ctrl>n",          "NewGame",              ResetGameEvent},
603   {N_("New Shuffle Game..."),   NULL,              "NewShuffleGame",       ShuffleMenuProc},
604   {N_("New Variant..."),       "<Alt><Shift>v",    "NewVariant",           NewVariantProc},// [HGM] variant: not functional yet
605   {"----",                      NULL,               NULL,                  NothingProc},
606   {N_("Load Game"),            "<Ctrl>o",          "LoadGame",             LoadGameProc,           CHECK},
607   {N_("Load Position"),        "<Ctrl><Shift>o",   "LoadPosition",         LoadPositionProc},
608   {N_("Next Position"),        "<Shift>Page_Down", "LoadNextPosition",     LoadNextPositionProc},
609   {N_("Prev Position"),        "<Shift>Page_Up",   "LoadPreviousPosition", LoadPrevPositionProc},
610   {"----",                      NULL,               NULL,                  NothingProc},
611   {N_("Save Game"),            "<Ctrl>s",          "SaveGame",             SaveGameProc},
612   {N_("Save Position"),        "<Ctrl><Shift>s",   "SavePosition",         SavePositionProc},
613   {N_("Save Selected Games"),   NULL,              "SaveSelected",         SaveSelectedProc},
614   {N_("Save Games as Book"),    NULL,              "CreateBook",           CreateBookDelayed},
615   {"----",                      NULL,               NULL,                  NothingProc},
616   {N_("Mail Move"),             NULL,              "MailMove",             MailMoveEvent},
617   {N_("Reload CMail Message"),  NULL,              "ReloadCMailMessage",   ReloadCmailMsgProc},
618   {"----",                      NULL,               NULL,                  NothingProc},
619   {N_("Quit "),                "<Ctrl>q",          "Quit",                 QuitProc},
620   {NULL,                        NULL,               NULL,                  NULL}
621 };
622
623 MenuItem editMenu[] = {
624   {N_("Copy Game"),      "<Ctrl>c",        "CopyGame",      CopyGameProc},
625   {N_("Copy Position"),  "<Ctrl><Shift>c", "CopyPosition",  CopyPositionProc},
626   {N_("Copy Game List"),  NULL,            "CopyGameList",  CopyGameListProc},
627   {"----",                NULL,             NULL,           NothingProc},
628   {N_("Paste Game"),     "<Ctrl>v",        "PasteGame",     PasteGameProc},
629   {N_("Paste Position"), "<Ctrl><Shift>v", "PastePosition", PastePositionProc},
630   {"----",                NULL,             NULL,           NothingProc},
631   {N_("Edit Game"),      "<Ctrl>e",        "EditGame",      EditGameEvent},
632   {N_("Edit Position"),  "<Ctrl><Shift>e", "EditPosition",  EditPositionEvent},
633   {N_("Edit Tags"),       NULL,            "EditTags",      EditTagsProc},
634   {N_("Edit Comment"),    NULL,            "EditComment",   EditCommentProc},
635   {N_("Edit Book"),       NULL,            "EditBook",      EditBookEvent},
636   {"----",                NULL,             NULL,           NothingProc},
637   {N_("Revert"),         "Home",           "Revert",        RevertProc},
638   {N_("Annotate"),        NULL,            "Annotate",      AnnotateProc},
639   {N_("Truncate Game"),  "End",            "TruncateGame",  TruncateGameEvent},
640   {"----",                NULL,             NULL,           NothingProc},
641   {N_("Backward"),       "<Alt>Left",      "Backward",      BackwardEvent},
642   {N_("Forward"),        "<Alt>Right",     "Forward",       ForwardEvent},
643   {N_("Back to Start"),  "<Alt>Home",      "BacktoStart",   ToStartEvent},
644   {N_("Forward to End"), "<Alt>End",       "ForwardtoEnd",  ToEndEvent},
645   {NULL,                  NULL,             NULL,           NULL}
646 };
647
648 MenuItem viewMenu[] = {
649   {N_("Flip View"),         "F2",            "FlipView",        FlipViewProc,           CHECK},
650   {"----",                   NULL,            NULL,             NothingProc},
651   {N_("Engine Output"),     "<Alt><Shift>o", "EngineOutput",    EngineOutputProc,       CHECK},
652   {N_("Move History"),      "<Alt><Shift>h", "MoveHistory",     HistoryShowProc,        CHECK}, // [HGM] hist: activate 4.2.7 code
653   {N_("Evaluation Graph"),  "<Alt><Shift>e", "EvaluationGraph", EvalGraphProc,          CHECK},
654   {N_("Game List"),         "<Alt><Shift>g", "GameList",        ShowGameListProc,       CHECK},
655   {N_("ICS text menu"),      NULL,           "ICStextmenu",     IcsTextProc,            CHECK},
656   {"----",                   NULL,            NULL,             NothingProc},
657   {N_("Tags"),               NULL,           "Tags",            EditTagsProc,           CHECK},
658   {N_("Comments"),           NULL,           "Comments",        EditCommentProc,        CHECK},
659   {N_("ICS Input Box"),      NULL,           "ICSInputBox",     IcsInputBoxProc,        CHECK},
660   {N_("ICS/Chat Console"),   NULL,           "OpenChatWindow",  ChatProc,               CHECK},
661   {"----",                   NULL,            NULL,             NothingProc},
662   {N_("Board..."),           NULL,           "Board",           BoardOptionsProc},
663   {N_("Game List Tags..."),  NULL,           "GameListTags",    GameListOptionsProc},
664   {NULL,                     NULL,            NULL,             NULL}
665 };
666
667 MenuItem modeMenu[] = {
668   {N_("Machine White"),  "<Ctrl>w",        "MachineWhite",  MachineWhiteEvent,              RADIO },
669   {N_("Machine Black"),  "<Ctrl>b",        "MachineBlack",  MachineBlackEvent,              RADIO },
670   {N_("Two Machines"),   "<Ctrl>t",        "TwoMachines",   TwoMachinesEvent,               RADIO },
671   {N_("Analysis Mode"),  "<Ctrl>a",        "AnalysisMode",  (MenuProc*) AnalyzeModeEvent,   RADIO },
672   {N_("Analyze Game"),   "<Ctrl>g",        "AnalyzeFile",   AnalyzeFileEvent,               RADIO },
673   {N_("Edit Game"),      "<Ctrl>e",        "EditGame",      EditGameEvent,                  RADIO },
674   {N_("Edit Position"),  "<Ctrl><Shift>e", "EditPosition",  EditPositionEvent,              RADIO },
675   {N_("Training"),        NULL,            "Training",      TrainingEvent,                  RADIO },
676   {N_("ICS Client"),      NULL,            "ICSClient",     IcsClientEvent,                 RADIO },
677   {"----",                NULL,             NULL,           NothingProc},
678   {N_("Machine Match"),   NULL,            "MachineMatch",  MatchProc,                      CHECK },
679   {N_("Pause"),          "Pause",          "Pause",         PauseEvent,                     CHECK },
680   {NULL,                  NULL,             NULL,           NULL}
681 };
682
683 MenuItem actionMenu[] = {
684   {N_("Accept"),             "F3",   "Accept",             AcceptEvent},
685   {N_("Decline"),            "F4",   "Decline",            DeclineEvent},
686   {N_("Rematch"),            "F12",  "Rematch",            RematchEvent},
687   {"----",                    NULL,   NULL,                NothingProc},
688   {N_("Call Flag"),          "F5",   "CallFlag",           CallFlagEvent},
689   {N_("Draw"),               "F6",   "Draw",               DrawEvent},
690   {N_("Adjourn"),            "F7",   "Adjourn",            AdjournEvent},
691   {N_("Abort"),              "F8",   "Abort",              AbortEvent},
692   {N_("Resign"),             "F9",   "Resign",             ResignEvent},
693   {"----",                    NULL,   NULL,                NothingProc},
694   {N_("Stop Observing"),     "F10",  "StopObserving",      StopObservingEvent},
695   {N_("Stop Examining"),     "F11",  "StopExamining",      StopExaminingEvent},
696   {N_("Upload to Examine"),   NULL,  "UploadtoExamine",    UploadGameEvent},
697   {"----",                    NULL,   NULL,                NothingProc},
698   {N_("Adjudicate to White"), NULL,  "AdjudicatetoWhite",  AdjuWhiteProc},
699   {N_("Adjudicate to Black"), NULL,  "AdjudicatetoBlack",  AdjuBlackProc},
700   {N_("Adjudicate Draw"),     NULL,  "AdjudicateDraw",     AdjuDrawProc},
701   {NULL,                      NULL,   NULL,                NULL}
702 };
703
704 MenuItem engineMenu[100] = {
705   {N_("Edit Engine List..."),      NULL,     "EditEngList",      EditEngineProc},
706   {"----",                         NULL,      NULL,              NothingProc},
707   {N_("Load New 1st Engine..."),   NULL,     "LoadNew1stEngine", LoadEngine1Proc},
708   {N_("Load New 2nd Engine..."),   NULL,     "LoadNew2ndEngine", LoadEngine2Proc},
709   {"----",                         NULL,      NULL,              NothingProc},
710   {N_("Engine #1 Settings..."),    NULL,     "Engine#1Settings", FirstSettingsProc},
711   {N_("Engine #2 Settings..."),    NULL,     "Engine#2Settings", SecondSettingsProc},
712   {"----",                         NULL,      NULL,              NothingProc},
713   {N_("Hint"),                     NULL,     "Hint",             HintEvent},
714   {N_("Book"),                     NULL,     "Book",             BookEvent},
715   {"----",                         NULL,      NULL,              NothingProc},
716   {N_("Move Now"),                "<Ctrl>m", "MoveNow",          MoveNowEvent},
717   {N_("Retract Move"),            "<Ctrl>x", "RetractMove",      RetractMoveEvent},
718   {NULL,                           NULL,      NULL,              NULL}
719 };
720
721 MenuItem optionsMenu[] = {
722 #ifdef OPTIONSDIALOG
723   {N_("General..."),              NULL,             "General",             OptionsProc},
724 #endif
725   {N_("Time Control..."),        "<Alt><Shift>t",   "TimeControl",         TimeControlProc},
726   {N_("Common Engine..."),       "<Alt><Shift>u",   "CommonEngine",        UciMenuProc},
727   {N_("Adjudications..."),       "<Alt><Shift>j",   "Adjudications",       EngineMenuProc},
728   {N_("ICS..."),                  NULL,             "ICS",                 IcsOptionsProc},
729   {N_("Tournament..."),           NULL,             "Match",               MatchOptionsProc},
730   {N_("Load Game..."),            NULL,             "LoadGame",            LoadOptionsProc},
731   {N_("Save Game..."),            NULL,             "SaveGame",            SaveOptionsProc},
732   {N_("Game List..."),            NULL,             "GameList",            GameListOptionsProc},
733   {N_("Sounds..."),               NULL,             "Sounds",              SoundOptionsProc},
734   {"----",                        NULL,              NULL,                 NothingProc},
735 #ifndef OPTIONSDIALOG
736   {N_("Always Queen"),           "<Ctrl><Shift>q",  "AlwaysQueen",         AlwaysQueenProc},
737   {N_("Animate Dragging"),        NULL,             "AnimateDragging",     AnimateDraggingProc},
738   {N_("Animate Moving"),         "<Ctrl><Shift>a",  "AnimateMoving",       AnimateMovingProc},
739   {N_("Auto Flag"),              "<Ctrl><Shift>f",  "AutoFlag",            AutoflagProc},
740   {N_("Auto Flip View"),          NULL,             "AutoFlipView",        AutoflipProc},
741   {N_("Blindfold"),               NULL,             "Blindfold",           BlindfoldProc},
742   {N_("Flash Moves"),             NULL,             "FlashMoves",          FlashMovesProc},
743 #if HIGHDRAG
744   {N_("Highlight Dragging"),      NULL,             "HighlightDragging",   HighlightDraggingProc},
745 #endif
746   {N_("Highlight Last Move"),     NULL,             "HighlightLastMove",   HighlightLastMoveProc},
747   {N_("Highlight With Arrow"),    NULL,             "HighlightWithArrow",  HighlightArrowProc},
748   {N_("Move Sound"),              NULL,             "MoveSound",           MoveSoundProc},
749   {N_("One-Click Moving"),        NULL,             "OneClickMoving",      OneClickProc},
750   {N_("Periodic Updates"),        NULL,             "PeriodicUpdates",     PeriodicUpdatesProc},
751   {N_("Ponder Next Move"),       "<Ctrl><Shift>p",  "PonderNextMove",      PonderNextMoveProc},
752   {N_("Popup Exit Message"),      NULL,             "PopupExitMessage",    PopupExitMessageProc},
753   {N_("Popup Move Errors"),       NULL,             "PopupMoveErrors",     PopupMoveErrorsProc},
754   {N_("Show Coords"),             NULL,             "ShowCoords",          ShowCoordsProc},
755   {N_("Hide Thinking"),          "<Ctrl><Shift>h",  "HideThinking",        HideThinkingProc},
756   {N_("Test Legality"),          "<Ctrl><Shift>l",  "TestLegality",        TestLegalityProc},
757   {"----",                        NULL,              NULL,                 NothingProc},
758 #endif
759   {N_("Save Settings Now"),       NULL,             "SaveSettingsNow",     SaveSettingsProc},
760   {N_("Save Settings on Exit"),   NULL,             "SaveSettingsonExit",  SaveOnExitProc,         CHECK },
761   {NULL,                          NULL,              NULL,                 NULL}
762 };
763
764 MenuItem helpMenu[] = {
765   {N_("Info XBoard"),            NULL,   "InfoXBoard",           InfoProc},
766   {N_("Man XBoard"),            "F1",    "ManXBoard",            ManProc},
767   {"----",                       NULL,    NULL,                  NothingProc},
768   {N_("XBoard Home Page"),       NULL,   "XBoardHomePage",       HomePageProc},
769   {N_("On-line User Guide"),     NULL,   "On-lineUserGuide",     GuideProc},
770   {N_("Development News"),       NULL,   "DevelopmentNews",      NewsPageProc},
771   {N_("e-Mail Bug Report"),      NULL,   "e-MailBugReport",      BugReportProc},
772   {"----",                       NULL,    NULL,                  NothingProc},
773   {N_("About XBoard"),           NULL,   "AboutXBoard",          AboutProc},
774   {NULL,                         NULL,    NULL,                  NULL}
775 };
776
777 MenuItem noMenu[] = {
778   { "", "<Alt>Next" ,"LoadNextGame", LoadNextGameProc },
779   { "", "<Alt>Prior" ,"LoadPrevGame", LoadPrevGameProc },
780   { "", NULL,"ReloadGame", ReloadGameProc },
781   { "", NULL,"ReloadPosition", ReloadPositionProc },
782 #ifndef OPTIONSDIALOG
783   { "", NULL,"AlwaysQueen", AlwaysQueenProc },
784   { "", NULL,"AnimateDragging", AnimateDraggingProc },
785   { "", NULL,"AnimateMoving", AnimateMovingProc },
786   { "", NULL,"Autoflag", AutoflagProc },
787   { "", NULL,"Autoflip", AutoflipProc },
788   { "", NULL,"Blindfold", BlindfoldProc },
789   { "", NULL,"FlashMoves", FlashMovesProc },
790 #if HIGHDRAG
791   { "", NULL,"HighlightDragging", HighlightDraggingProc },
792 #endif
793   { "", NULL,"HighlightLastMove", HighlightLastMoveProc },
794   { "", NULL,"MoveSound", MoveSoundProc },
795   { "", NULL,"PeriodicUpdates", PeriodicUpdatesProc },
796   { "", NULL,"PopupExitMessage", PopupExitMessageProc },
797   { "", NULL,"PopupMoveErrors", PopupMoveErrorsProc },
798   { "", NULL,"ShowCoords", ShowCoordsProc },
799   { "", NULL,"ShowThinking", ShowThinkingProc },
800   { "", NULL,"HideThinking", HideThinkingProc },
801   { "", NULL,"TestLegality", TestLegalityProc },
802 #endif
803   { "", NULL,"AboutGame", AboutGameEvent },
804   { "", "<Ctrl>d" ,"DebugProc", DebugProc },
805   { "", NULL,"Nothing", NothingProc },
806   {NULL, NULL, NULL, NULL}
807 };
808
809 Menu menuBar[] = {
810     {N_("File"),    "File", fileMenu},
811     {N_("Edit"),    "Edit", editMenu},
812     {N_("View"),    "View", viewMenu},
813     {N_("Mode"),    "Mode", modeMenu},
814     {N_("Action"),  "Action", actionMenu},
815     {N_("Engine"),  "Engine", engineMenu},
816     {N_("Options"), "Options", optionsMenu},
817     {N_("Help"),    "Help", helpMenu},
818     {NULL, NULL, NULL},
819     {   "",         "None", noMenu}
820 };
821
822 MenuItem *
823 MenuNameToItem (char *menuName)
824 {
825     int i=0;
826     char buf[MSG_SIZ], *p;
827     MenuItem *menuTab;
828     static MenuItem a = { NULL, NULL, NULL, NothingProc };
829     extern Option mainOptions[];
830     safeStrCpy(buf, menuName, MSG_SIZ);
831     p = strchr(buf, '.');
832     if(!p) menuTab = noMenu, p = menuName; else {
833         *p++ = NULLCHAR;
834         for(i=0; menuBar[i].name; i++)
835             if(!strcmp(buf, menuBar[i].name)) break;
836         if(!menuBar[i].name) return NULL; // main menu not found
837         menuTab = menuBar[i].mi;
838     }
839     if(*p == NULLCHAR) { a.handle = mainOptions[i+1].handle; return &a; } // main menu bar
840     for(i=0; menuTab[i].string; i++)
841         if(menuTab[i].ref && !strcmp(p, menuTab[i].ref)) return menuTab + i;
842     return NULL; // item not found
843 }
844
845 int firstEngineItem;
846
847 void
848 AppendEnginesToMenu (char *list)
849 {
850     int i=0;
851     char *p;
852     if(appData.icsActive || appData.recentEngines <= 0) return;
853     for(firstEngineItem=0; engineMenu[firstEngineItem].string; firstEngineItem++);
854     recentEngines = strdup(list);
855     while (*list) {
856         p = strchr(list, '\n'); if(p == NULL) break;
857         if(i == 0) engineMenu[firstEngineItem++].string = "----"; // at least one valid item to add
858         *p = 0;
859         if(firstEngineItem + i < 99)
860             engineMenu[firstEngineItem+i].string = strdup(list); // just set name; MenuProc stays NULL
861         i++; *p = '\n'; list = p + 1;
862     }
863 }
864
865 Enables icsEnables[] = {
866     { "File.MailMove", False },
867     { "File.ReloadCMailMessage", False },
868     { "Mode.MachineBlack", False },
869     { "Mode.MachineWhite", False },
870     { "Mode.AnalysisMode", False },
871     { "Mode.AnalyzeFile", False },
872     { "Mode.TwoMachines", False },
873     { "Mode.MachineMatch", False },
874 #if !ZIPPY
875     { "Engine.Hint", False },
876     { "Engine.Book", False },
877     { "Engine.MoveNow", False },
878 #ifndef OPTIONSDIALOG
879     { "PeriodicUpdates", False },
880     { "HideThinking", False },
881     { "PonderNextMove", False },
882 #endif
883 #endif
884     { "Engine.Engine#1Settings", False },
885     { "Engine.Engine#2Settings", False },
886     { "Engine.Load1stEngine", False },
887     { "Engine.Load2ndEngine", False },
888     { "Edit.Annotate", False },
889     { "Options.Match", False },
890     { NULL, False }
891 };
892
893 Enables ncpEnables[] = {
894     { "File.MailMove", False },
895     { "File.ReloadCMailMessage", False },
896     { "Mode.MachineWhite", False },
897     { "Mode.MachineBlack", False },
898     { "Mode.AnalysisMode", False },
899     { "Mode.AnalyzeFile", False },
900     { "Mode.TwoMachines", False },
901     { "Mode.MachineMatch", False },
902     { "Mode.ICSClient", False },
903     { "View.ICStextmenu", False },
904     { "View.ICSInputBox", False },
905     { "View.OpenChatWindow", False },
906     { "Action.", False },
907     { "Edit.Revert", False },
908     { "Edit.Annotate", False },
909     { "Engine.Engine#1Settings", False },
910     { "Engine.Engine#2Settings", False },
911     { "Engine.MoveNow", False },
912     { "Engine.RetractMove", False },
913     { "Options.ICS", False },
914 #ifndef OPTIONSDIALOG
915     { "Options.AutoFlag", False },
916     { "Options.AutoFlip View", False },
917 //    { "Options.ICSAlarm", False },
918     { "Options.MoveSound", False },
919     { "Options.HideThinking", False },
920     { "Options.PeriodicUpdates", False },
921     { "Options.PonderNextMove", False },
922 #endif
923     { "Engine.Hint", False },
924     { "Engine.Book", False },
925     { NULL, False }
926 };
927
928 Enables gnuEnables[] = {
929     { "Mode.ICSClient", False },
930     { "View.ICStextmenu", False },
931     { "View.ICSInputBox", False },
932     { "View.OpenChatWindow", False },
933     { "Action.Accept", False },
934     { "Action.Decline", False },
935     { "Action.Rematch", False },
936     { "Action.Adjourn", False },
937     { "Action.StopExamining", False },
938     { "Action.StopObserving", False },
939     { "Action.UploadtoExamine", False },
940     { "Edit.Revert", False },
941     { "Edit.Annotate", False },
942     { "Options.ICS", False },
943
944     /* The next two options rely on SetCmailMode being called *after*    */
945     /* SetGNUMode so that when GNU is being used to give hints these     */
946     /* menu options are still available                                  */
947
948     { "File.MailMove", False },
949     { "File.ReloadCMailMessage", False },
950     // [HGM] The following have been added to make a switch from ncp to GNU mode possible
951     { "Mode.MachineWhite", True },
952     { "Mode.MachineBlack", True },
953     { "Mode.AnalysisMode", True },
954     { "Mode.AnalyzeFile", True },
955     { "Mode.TwoMachines", True },
956     { "Mode.MachineMatch", True },
957     { "Engine.Engine#1Settings", True },
958     { "Engine.Engine#2Settings", True },
959     { "Engine.Hint", True },
960     { "Engine.Book", True },
961     { "Engine.MoveNow", True },
962     { "Engine.RetractMove", True },
963     { "Action.", True },
964     { NULL, False }
965 };
966
967 Enables cmailEnables[] = {
968     { "Action.", True },
969     { "Action.CallFlag", False },
970     { "Action.Draw", True },
971     { "Action.Adjourn", False },
972     { "Action.Abort", False },
973     { "Action.StopObserving", False },
974     { "Action.StopExamining", False },
975     { "File.MailMove", True },
976     { "File.ReloadCMailMessage", True },
977     { NULL, False }
978 };
979
980 Enables trainingOnEnables[] = {
981   { "Edit.EditComment", False },
982   { "Mode.Pause", False },
983   { "Edit.Forward", False },
984   { "Edit.Backward", False },
985   { "Edit.ForwardtoEnd", False },
986   { "Edit.BacktoStart", False },
987   { "Engine.MoveNow", False },
988   { "Edit.TruncateGame", False },
989   { NULL, False }
990 };
991
992 Enables trainingOffEnables[] = {
993   { "Edit.EditComment", True },
994   { "Mode.Pause", True },
995   { "Edit.Forward", True },
996   { "Edit.Backward", True },
997   { "Edit.ForwardtoEnd", True },
998   { "Edit.BacktoStart", True },
999   { "Engine.MoveNow", True },
1000   { "Engine.TruncateGame", True },
1001   { NULL, False }
1002 };
1003
1004 Enables machineThinkingEnables[] = {
1005   { "File.LoadGame", False },
1006 //  { "LoadNextGame", False },
1007 //  { "LoadPreviousGame", False },
1008 //  { "ReloadSameGame", False },
1009   { "Edit.PasteGame", False },
1010   { "File.LoadPosition", False },
1011 //  { "LoadNextPosition", False },
1012 //  { "LoadPreviousPosition", False },
1013 //  { "ReloadSamePosition", False },
1014   { "Edit.PastePosition", False },
1015   { "Mode.MachineWhite", False },
1016   { "Mode.MachineBlack", False },
1017   { "Mode.TwoMachines", False },
1018 //  { "MachineMatch", False },
1019   { "Engine.RetractMove", False },
1020   { NULL, False }
1021 };
1022
1023 Enables userThinkingEnables[] = {
1024   { "File.LoadGame", True },
1025 //  { "LoadNextGame", True },
1026 //  { "LoadPreviousGame", True },
1027 //  { "ReloadSameGame", True },
1028   { "Edit.PasteGame", True },
1029   { "File.LoadPosition", True },
1030 //  { "LoadNextPosition", True },
1031 //  { "LoadPreviousPosition", True },
1032 //  { "ReloadSamePosition", True },
1033   { "Edit.PastePosition", True },
1034   { "Mode.MachineWhite", True },
1035   { "Mode.MachineBlack", True },
1036   { "Mode.TwoMachines", True },
1037 //  { "MachineMatch", True },
1038   { "Engine.RetractMove", True },
1039   { NULL, False }
1040 };
1041
1042 void
1043 SetICSMode ()
1044 {
1045   SetMenuEnables(icsEnables);
1046
1047 #if ZIPPY
1048   if (appData.zippyPlay && !appData.noChessProgram) { /* [DM] icsEngineAnalyze */
1049      EnableNamedMenuItem("Mode.AnalysisMode", True);
1050      EnableNamedMenuItem("Engine.Engine#1Settings", True);
1051   }
1052 #endif
1053 }
1054
1055 void
1056 SetNCPMode ()
1057 {
1058   SetMenuEnables(ncpEnables);
1059 }
1060
1061 void
1062 SetGNUMode ()
1063 {
1064   SetMenuEnables(gnuEnables);
1065 }
1066
1067 void
1068 SetCmailMode ()
1069 {
1070   SetMenuEnables(cmailEnables);
1071 }
1072
1073 void
1074 SetTrainingModeOn ()
1075 {
1076   SetMenuEnables(trainingOnEnables);
1077   if (appData.showButtonBar) {
1078     EnableButtonBar(False);
1079   }
1080   CommentPopDown();
1081 }
1082
1083 void
1084 SetTrainingModeOff ()
1085 {
1086   SetMenuEnables(trainingOffEnables);
1087   if (appData.showButtonBar) {
1088     EnableButtonBar(True);
1089   }
1090 }
1091
1092 void
1093 SetUserThinkingEnables ()
1094 {
1095   if (appData.noChessProgram) return;
1096   SetMenuEnables(userThinkingEnables);
1097 }
1098
1099 void
1100 SetMachineThinkingEnables ()
1101 {
1102   if (appData.noChessProgram) return;
1103   SetMenuEnables(machineThinkingEnables);
1104   switch (gameMode) {
1105   case MachinePlaysBlack:
1106   case MachinePlaysWhite:
1107   case TwoMachinesPlay:
1108     EnableNamedMenuItem(ModeToWidgetName(gameMode), True);
1109     break;
1110   default:
1111     break;
1112   }
1113 }
1114
1115 void
1116 GreyRevert (Boolean grey)
1117 {
1118     EnableNamedMenuItem("Edit.Revert", !grey);
1119     EnableNamedMenuItem("Edit.Annotate", !grey);
1120 }
1121
1122 char *
1123 ModeToWidgetName (GameMode mode)
1124 {
1125     switch (mode) {
1126       case BeginningOfGame:
1127         if (appData.icsActive)
1128           return "Mode.ICSClient";
1129         else if (appData.noChessProgram ||
1130                  *appData.cmailGameName != NULLCHAR)
1131           return "Mode.EditGame";
1132         else
1133           return "Mode.MachineBlack";
1134       case MachinePlaysBlack:
1135         return "Mode.MachineBlack";
1136       case MachinePlaysWhite:
1137         return "Mode.MachineWhite";
1138       case AnalyzeMode:
1139         return "Mode.AnalysisMode";
1140       case AnalyzeFile:
1141         return "Mode.AnalyzeFile";
1142       case TwoMachinesPlay:
1143         return "Mode.TwoMachines";
1144       case EditGame:
1145         return "Mode.EditGame";
1146       case PlayFromGameFile:
1147         return "File.LoadGame";
1148       case EditPosition:
1149         return "Mode.EditPosition";
1150       case Training:
1151         return "Mode.Training";
1152       case IcsPlayingWhite:
1153       case IcsPlayingBlack:
1154       case IcsObserving:
1155       case IcsIdle:
1156       case IcsExamining:
1157         return "Mode.ICSClient";
1158       default:
1159       case EndOfGame:
1160         return NULL;
1161     }
1162 }
1163
1164 static void
1165 InstallNewEngine (char *command, char *dir, char *variants, char *protocol)
1166 { // install the given engine in XBoard's -firstChessProgramNames
1167     char buf[MSG_SIZ], *quote = "";
1168     if(strchr(command, ' ')) { // quoting needed
1169         if(!strchr(command, '"')) quote = "\""; else
1170         if(!strchr(command, '\'')) quote = "'"; else {
1171             printf("Could not auto-install %s\n", command); // too complex
1172         }
1173     }
1174     // construct engine line, with optional -fd and -fUCI arguments
1175     snprintf(buf, MSG_SIZ, "%s%s%s", quote, command, quote);
1176     if(strcmp(dir, "") && strcmp(dir, "."))
1177         snprintf(buf + strlen(buf), MSG_SIZ - strlen(buf), " -fd %s", dir);
1178     if(!strcmp(protocol, "uci"))
1179         snprintf(buf + strlen(buf), MSG_SIZ - strlen(buf), " -fUCI");
1180     if(strstr(firstChessProgramNames, buf)) return; // avoid duplicats
1181     // append line
1182     quote = malloc(strlen(firstChessProgramNames) + strlen(buf) + 2);
1183     sprintf(quote, "%s%s\n", firstChessProgramNames, buf);
1184     FREE(firstChessProgramNames); firstChessProgramNames = quote;
1185 }
1186
1187 #ifdef HAVE_DIRENT_H
1188 #include <dirent.h>
1189 #else
1190 #include <sys/dir.h>
1191 #define dirent direct
1192 #endif
1193
1194 static void
1195 InstallFromDir (char *dirName, char *protocol, char *settingsFile)
1196 {   // scan system for new plugin specs in given directory
1197     DIR *dir;
1198     struct dirent *dp;
1199     struct stat statBuf;
1200     time_t lastSaved = 0;
1201     char buf[1024];
1202
1203     if(!stat(settingsFile, &statBuf)) lastSaved = statBuf.st_mtime;
1204     snprintf(buf, 1024, "%s/%s", dirName, protocol);
1205
1206     if(!(dir = opendir(buf))) return;
1207     while( (dp = readdir(dir))) {
1208         time_t installed = 0;
1209         if(!strstr(dp->d_name, ".eng")) continue; // to suppress . and ..
1210         snprintf(buf, 1024, "%s/%s/%s", dirName, protocol, dp->d_name);
1211         if(!stat(buf, &statBuf)) installed = statBuf.st_mtime;
1212         if(lastSaved == 0 || (int) (installed - lastSaved) > 0) { // first time we see it
1213             FILE *f = fopen(buf, "r");
1214             if(f) { // read the plugin-specs
1215                 char engineCommand[1024], engineDir[1024], variants[1024];
1216                 char bad=0, dummy, *engineCom = engineCommand;
1217                 int major, minor;
1218                 if(fscanf(f, "plugin spec %d.%d%c", &major, &minor, &dummy) != 3 ||
1219                    fscanf(f, "%[^\n]%c", engineCommand, &dummy) != 2 ||
1220                    fscanf(f, "%[^\n]%c", variants, &dummy) != 2) bad = 1;
1221                 fclose(f);
1222                 if(bad) continue;
1223                 // uncomment following two lines for chess-only installs
1224 //              if(!(p = strstr(variants, "chess")) ||
1225 //                   p != variants && p[-1] != ',' || p[5] && p[5] != ',') continue;
1226                 // split off engine working directory (if any)
1227                 strcpy(engineDir, "");
1228                 if(sscanf(engineCommand, "cd %[^;];%c", engineDir, &dummy) == 2)
1229                     engineCom = engineCommand + strlen(engineDir) + 4;
1230                 InstallNewEngine(engineCom, engineDir, variants, protocol);
1231             }
1232         }
1233     }
1234     closedir(dir);
1235 }
1236
1237 static void
1238 AutoInstallProtocol (char *settingsFile, char *protocol)
1239 {   // install new engines for given protocol (both from package and source)
1240     InstallFromDir("/usr/local/share/games/plugins", protocol, settingsFile);
1241     InstallFromDir("/usr/share/games/plugins", protocol, settingsFile);
1242 }
1243
1244 void
1245 AutoInstall (char *settingsFile)
1246 {   // install all new XBoard and UCI engines
1247     AutoInstallProtocol(settingsFile, "xboard");
1248     AutoInstallProtocol(settingsFile, "uci");
1249 }
1250
1251 void
1252 InitMenuMarkers()
1253 {
1254 #ifndef OPTIONSDIALOG
1255     if (appData.alwaysPromoteToQueen) {
1256         MarkMenuItem("Options.Always Queen", True);
1257     }
1258     if (appData.animateDragging) {
1259         MarkMenuItem("Options.Animate Dragging", True);
1260     }
1261     if (appData.animate) {
1262         MarkMenuItem("Options.Animate Moving", True);
1263     }
1264     if (appData.autoCallFlag) {
1265         MarkMenuItem("Options.Auto Flag", True);
1266     }
1267     if (appData.autoFlipView) {
1268         XtSetValues(XtNameToWidget(menuBarWidget,"Options.Auto Flip View", True);
1269     }
1270     if (appData.blindfold) {
1271         MarkMenuItem("Options.Blindfold", True);
1272     }
1273     if (appData.flashCount > 0) {
1274         MarkMenuItem("Options.Flash Moves", True);
1275     }
1276 #if HIGHDRAG
1277     if (appData.highlightDragging) {
1278         MarkMenuItem("Options.Highlight Dragging", True);
1279     }
1280 #endif
1281     if (appData.highlightLastMove) {
1282         MarkMenuItem("Options.Highlight Last Move", True);
1283     }
1284     if (appData.highlightMoveWithArrow) {
1285         MarkMenuItem("Options.Arrow", True);
1286     }
1287 //    if (appData.icsAlarm) {
1288 //      MarkMenuItem("Options.ICS Alarm", True);
1289 //    }
1290     if (appData.ringBellAfterMoves) {
1291         MarkMenuItem("Options.Move Sound", True);
1292     }
1293     if (appData.oneClick) {
1294         MarkMenuItem("Options.OneClick", True);
1295     }
1296     if (appData.periodicUpdates) {
1297         MarkMenuItem("Options.Periodic Updates", True);
1298     }
1299     if (appData.ponderNextMove) {
1300         MarkMenuItem("Options.Ponder Next Move", True);
1301     }
1302     if (appData.popupExitMessage) {
1303         MarkMenuItem("Options.Popup Exit Message", True);
1304     }
1305     if (appData.popupMoveErrors) {
1306         MarkMenuItem("Options.Popup Move Errors", True);
1307     }
1308 //    if (appData.premove) {
1309 //      MarkMenuItem("Options.Premove", True);
1310 //    }
1311     if (appData.showCoords) {
1312         MarkMenuItem("Options.Show Coords", True);
1313     }
1314     if (appData.hideThinkingFromHuman) {
1315         MarkMenuItem("Options.Hide Thinking", True);
1316     }
1317     if (appData.testLegality) {
1318         MarkMenuItem("Options.Test Legality", True);
1319     }
1320 #endif
1321     if (saveSettingsOnExit) {
1322         MarkMenuItem("Options.SaveSettingsonExit", True);
1323     }
1324     EnableNamedMenuItem("File.SaveSelected", False);
1325
1326     // all XBoard builds get here, but not WinBoard...
1327     if(*appData.autoInstall) AutoInstall(settingsFileName);
1328 }