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