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