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