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