Add -afterGame option
[xboard.git] / xboard.c
index f6eee62..4a6d7f0 100644 (file)
--- a/xboard.c
+++ b/xboard.c
@@ -473,9 +473,8 @@ void BoardOptionsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms)
 void LoadOptionsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
 void SaveOptionsProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
 void EditBookProc P((Widget w, XEvent *event, String *prms, Cardinal *nprms));
+void SelectMove P((Widget w, XEvent * event, String * params, Cardinal * nParams));
 void GameListOptionsPopDown P(());
-void ShufflePopDown P(());
-void TimeControlPopDown P(());
 void GenericPopDown P(());
 void update_ics_width P(());
 int get_term_width P(());
@@ -684,7 +683,7 @@ MenuItem modeMenu[] = {
     {N_("Machine Black  Ctrl+B"), "Machine Black", MachineBlackProc},
     {N_("Two Machines   Ctrl+T"), "Two Machines", TwoMachinesProc},
     {N_("Analysis Mode  Ctrl+A"), "Analysis Mode", AnalyzeModeProc},
-    {N_("Analyze File      Ctrl+F"), "Analyze File", AnalyzeFileProc },
+    {N_("Analyze Game   Ctrl+G"), "Analyze File", AnalyzeFileProc },
     {N_("Edit Game         Ctrl+E"), "Edit Game", EditGameProc},
     {N_("Edit Position      Ctrl+Shift+E"), "Edit Position", EditPositionProc},
     {N_("Training"),      "Training", TrainingProc},
@@ -1038,13 +1037,11 @@ XtActionsRec boardActions[] = {
     { "GameListPopDown", (XtActionProc) GameListPopDown },
     { "GameListOptionsPopDown", (XtActionProc) GameListOptionsPopDown },
     { "PromotionPopDown", (XtActionProc) PromotionPopDown },
-    { "HistoryPopDown", (XtActionProc) HistoryPopDown },
     { "EngineOutputPopDown", (XtActionProc) EngineOutputPopDown },
     { "EvalGraphPopDown", (XtActionProc) EvalGraphPopDown },
-    { "ShufflePopDown", (XtActionProc) ShufflePopDown },
-    { "TimeControlPopDown", (XtActionProc) TimeControlPopDown },
     { "GenericPopDown", (XtActionProc) GenericPopDown },
     { "CopyMemoProc", (XtActionProc) CopyMemoProc },
+    { "SelectMove", (XtActionProc) SelectMove },
 };
 
 char globalTranslations[] =
@@ -1054,6 +1051,8 @@ char globalTranslations[] =
    :Ctrl<Key>o: LoadGameProc() \n \
    :Meta<Key>Next: LoadNextGameProc() \n \
    :Meta<Key>Prior: LoadPrevGameProc() \n \
+   :Ctrl<Key>Down: LoadSelectedProc(3) \n \
+   :Ctrl<Key>Up: LoadSelectedProc(-3) \n \
    :Ctrl<Key>s: SaveGameProc() \n \
    :Ctrl<Key>c: CopyGameProc() \n \
    :Ctrl<Key>v: PasteGameProc() \n \
@@ -1068,7 +1067,7 @@ char globalTranslations[] =
    :Ctrl<Key>b: MachineBlackProc() \n \
    :Ctrl<Key>t: TwoMachinesProc() \n \
    :Ctrl<Key>a: AnalysisModeProc() \n \
-   :Ctrl<Key>f: AnalyzeFileProc() \n \
+   :Ctrl<Key>g: AnalyzeFileProc() \n \
    :Ctrl<Key>e: EditGameProc() \n \
    :Ctrl<Key>E: EditPositionProc() \n \
    :Meta<Key>O: EngineOutputProc() \n \
@@ -1090,6 +1089,8 @@ char globalTranslations[] =
    :Meta<Key>Right: ForwardProc() \n \
    :Meta<Key>Home: ToStartProc() \n \
    :Meta<Key>Left: BackwardProc() \n \
+   :<Key>Left: BackwardProc() \n \
+   :<Key>Right: ForwardProc() \n \
    :<Key>Home: RevertProc() \n \
    :<Key>End: TruncateGameProc() \n \
    :Ctrl<Key>m: MoveNowProc() \n \
@@ -1133,8 +1134,12 @@ char boardTranslations[] =
    Any<Btn3Down>: XawPositionSimpleMenu(menuB) XawPositionSimpleMenu(menuD) \
                  PieceMenuPopup(menuB) \n";
 
-char whiteTranslations[] = "<BtnDown>: WhiteClock()\n";
-char blackTranslations[] = "<BtnDown>: BlackClock()\n";
+char whiteTranslations[] =
+   "Shift<BtnDown>: WhiteClock(1)\n \
+   <BtnDown>: WhiteClock(0)\n";
+char blackTranslations[] =
+   "Shift<BtnDown>: BlackClock(1)\n \
+   <BtnDown>: BlackClock(0)\n";
 
 char ICSInputTranslations[] =
     "<Key>Up: UpKeyProc() \n "
@@ -1592,8 +1597,8 @@ GetWindowCoords()
 { // wrapper to shield use of window handles from back-end (make addressible by number?)
   // In XBoard this will have to wait until awareness of window parameters is implemented
   GetActualPlacement(shellWidget, &wpMain);
-  if(EngineOutputIsUp()) GetActualPlacement(engineOutputShell, &wpEngineOutput); else
-  if(MoveHistoryIsUp()) GetActualPlacement(historyShell, &wpMoveHistory);
+  if(EngineOutputIsUp()) GetActualPlacement(engineOutputShell, &wpEngineOutput);
+  if(MoveHistoryIsUp()) GetActualPlacement(shells[7], &wpMoveHistory);
   if(EvalGraphIsUp()) GetActualPlacement(evalGraphShell, &wpEvalGraph);
   if(GameListIsUp()) GetActualPlacement(gameListShell, &wpGameList);
   if(shellUp[1]) GetActualPlacement(shells[1], &wpComment);
@@ -1651,7 +1656,7 @@ ConvertToLine(int argc, char **argv)
   line[0] = NULLCHAR;
   for(i=1; i<argc; i++)
     {
-      if( (strchr(argv[i], ' ') || strchr(argv[i], '\n') ||strchr(argv[i], '\t') )
+      if( (strchr(argv[i], ' ') || strchr(argv[i], '\n') ||strchr(argv[i], '\t') || argv[i][0] == NULLCHAR)
          && argv[i][0] != '{' )
        snprintf(buf, sizeof(buf)/sizeof(buf[0]), "{%s} ", argv[i]);
       else
@@ -2696,6 +2701,8 @@ XBoard square size (hint): %d\n\
     return 0;
 }
 
+static Boolean noEcho;
+
 void
 ShutDownFrontEnd()
 {
@@ -2705,6 +2712,7 @@ ShutDownFrontEnd()
     if (saveSettingsOnExit) SaveSettings(settingsFileName);
     unlink(gameCopyFilename);
     unlink(gamePasteFilename);
+    if(noEcho) EchoOn();
 }
 
 RETSIGTYPE TermSizeSigHandler(int sig)
@@ -3593,7 +3601,7 @@ void CreateXPMBoard(char *s, int kind)
 {
     XpmAttributes attr;
     attr.valuemask = 0;
-    if(s == NULL || *s == 0 || *s == '*') { useTexture &= ~(kind+1); return; }
+    if(!appData.useBitmaps || s == NULL || *s == 0 || *s == '*') { useTexture &= ~(kind+1); return; }
     if (XpmReadFileToPixmap(xDisplay, xBoardWindow, s, &(xpmBoardBitmap[kind]), NULL, &attr) == 0) {
        useTexture |= kind + 1; textureW[kind] = attr.width; textureH[kind] = attr.height;
     }
@@ -4141,6 +4149,7 @@ void WhiteClock(w, event, prms, nprms)
      String *prms;
      Cardinal *nprms;
 {
+    shiftKey = prms[0][0] & 1;
     ClockClick(0);
 }
 
@@ -4150,6 +4159,7 @@ void BlackClock(w, event, prms, nprms)
      String *prms;
      Cardinal *nprms;
 {
+    shiftKey = prms[0][0] & 1;
     ClockClick(1);
 }
 
@@ -4993,6 +5003,14 @@ void CommentPopDown()
     PopDown(1);
 }
 
+static char *openName;
+FILE *openFP;
+
+void DelayedLoad()
+{
+  (void) (*fileProc)(openFP, 0, openName);
+}
+
 void FileNamePopUp(label, def, filter, proc, openMode)
      char *label;
      char *def;
@@ -5003,12 +5021,11 @@ void FileNamePopUp(label, def, filter, proc, openMode)
     fileProc = proc;           /* I can't see a way not */
     fileOpenMode = openMode;   /*   to use globals here */
     {   // [HGM] use file-selector dialog stolen from Ghostview
-       char *name;
        int index; // this is not supported yet
-       FILE *f;
-       if(f = XsraSelFile(shellWidget, label, NULL, NULL, "could not open: ",
-                          (def[0] ? def : NULL), filter, openMode, NULL, &name))
-         (void) (*fileProc)(f, index=0, name);
+       if(openFP = XsraSelFile(shellWidget, label, NULL, NULL, "could not open: ",
+                          (def[0] ? def : NULL), filter, openMode, NULL, &openName))
+         // [HGM] delay to give expose event opportunity to redraw board after browser-dialog popdown before lengthy load starts
+         ScheduleDelayedEvent(&DelayedLoad, 50);
     }
 }
 
@@ -5126,7 +5143,7 @@ void PromotionPopUp()
                         (XtPointer) dialog);
       XawDialogAddButton(dialog, _("Captain"), PromotionCallback,
                         (XtPointer) dialog);
-    } else {\r
+    } else {
     XawDialogAddButton(dialog, _("Queen"), PromotionCallback,
                       (XtPointer) dialog);
     XawDialogAddButton(dialog, _("Rook"), PromotionCallback,
@@ -5137,7 +5154,7 @@ void PromotionPopUp()
                       (XtPointer) dialog);
     }
     if (!appData.testLegality || gameInfo.variant == VariantSuicide ||
-        gameInfo.variant == VariantSpartan && !WhiteOnMove(currentMove) ||\r
+        gameInfo.variant == VariantSpartan && !WhiteOnMove(currentMove) ||
         gameInfo.variant == VariantGiveaway) {
       XawDialogAddButton(dialog, _("King"), PromotionCallback,
                         (XtPointer) dialog);
@@ -5736,8 +5753,6 @@ SendGameSelection(Widget w, Atom *selection, Atom *target,
 
 void CopySomething()
 {
-  int ret;
-
   /*
    * Set both PRIMARY (the selection) and CLIPBOARD, since we don't
    * have a notion of a game that is selected but not copied.
@@ -5924,13 +5939,13 @@ void AnalyzeFileProc(w, event, prms, nprms)
       DisplayError(buf, 0);
       return;
     }
-    Reset(FALSE, TRUE);
+//    Reset(FALSE, TRUE);
 #ifndef OPTIONSDIALOG
     if (!appData.showThinking)
       ShowThinkingProc(w,event,prms,nprms);
 #endif
     AnalyzeFileEvent();
-    FileNamePopUp(_("File to analyze"), "", ".pgn .game", LoadGamePopUp, "rb");
+//    FileNamePopUp(_("File to analyze"), "", ".pgn .game", LoadGamePopUp, "rb");
     AnalysisPeriodicEvent(1);
 }
 
@@ -5949,7 +5964,7 @@ void MatchProc(w, event, prms, nprms)
      String *prms;
      Cardinal *nprms;
 {
-    MatchEvent(2);\r
+    MatchEvent(2);
 }
 
 void IcsClientProc(w, event, prms, nprms)
@@ -6939,6 +6954,7 @@ void DisplayTitle(text)
     XtSetArg(args[i], XtNiconName, (XtArgVal) icon);    i++;
     XtSetArg(args[i], XtNtitle, (XtArgVal) title);      i++;
     XtSetValues(shellWidget, args, i);
+    XSync(xDisplay, False);
 }
 
 
@@ -7227,15 +7243,29 @@ PlayAlarmSound()
 }
 
 void
+PlayTellSound()
+{
+  PlaySound(appData.soundTell);
+}
+
+void
 EchoOn()
 {
     system("stty echo");
+    noEcho = False;
 }
 
 void
 EchoOff()
 {
     system("stty -echo");
+    noEcho = True;
+}
+
+void
+RunCommand(char *buf)
+{
+    system(buf);
 }
 
 void
@@ -7738,7 +7768,7 @@ int OpenTCP(host, port, pr)
     struct addrinfo hints;
     struct addrinfo *ais, *ai;
     int error;
-    int s;
+    int s=0;
     ChildProc *cp;
 
     memset(&hints, 0, sizeof(hints));
@@ -8636,8 +8666,8 @@ AnimateMove(board, fromX, fromY, toX, toY)
 }
 
 void
-DragPieceBegin(x, y)
-     int x; int y;
+DragPieceBegin(x, y, instantly)
+     int x; int y; Boolean instantly;
 {
     int         boardX, boardY, color;
     XPoint corner;