First step for a GTK version
[xboard.git] / backend.c
index ff989cd..5df4fc6 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -1076,6 +1076,8 @@ ParseTimeControl(tc, ti, mps)
 void
 InitBackEnd2()
 {
+  printf ("DEBUG: in init backend 2\n");
+
     if (appData.debugMode) {
        fprintf(debugFP, "%s\n", programVersion);
     }
@@ -1091,15 +1093,22 @@ InitBackEnd2()
        if(appData.loadPositionIndex >= 0) appData.loadPositionIndex = -1;
        if(appData.loadGameIndex >= 0) appData.loadGameIndex = -1;
     }
+    printf ("DEBUG: before reset\n");
     Reset(TRUE, FALSE);
+    printf ("DEBUG: after reset\n");
     if (appData.noChessProgram || first.protocolVersion == 1) {
+      printf ("DEBUG: first if\n");
       InitBackEnd3();
     } else {
+      printf ("DEBUG: second if 0\n");
       /* kludge: allow timeout for initial "feature" commands */
       FreezeUI();
+      printf ("DEBUG: second if 1\n");
       DisplayMessage("", _("Starting chess program"));
+      printf ("DEBUG: second if 2\n");
       ScheduleDelayedEvent(InitBackEnd3, FEATURE_TIMEOUT);
-    }
+      printf ("DEBUG: second if 3\n");    }
+    printf ("DEBUG: end of init2\n");
 }
 
 void
@@ -4494,6 +4503,8 @@ InitPosition(redraw)
     oldh = gameInfo.holdingsWidth,
     oldv = gameInfo.variant;
 
+    printf ("DEBUG: in init position\n");
+
     currentMove = forwardMostMove = backwardMostMove = 0;
     if(appData.icsActive) shuffleOpenings = FALSE; // [HGM] shuffle: in ICS mode, only shuffle on ICS request
 
@@ -4631,6 +4642,7 @@ InitPosition(redraw)
       shuffleOpenings = 1;
       break;
     }
+    printf ("DEBUG: in init position 1\n");
 
     overrule = 0;
     if(appData.NrFiles >= 0) {
@@ -4689,6 +4701,9 @@ InitPosition(redraw)
             initialPosition[BOARD_HEIGHT-2][j] = BlackBishop;
     }
 
+    printf ("DEBUG: in init position 2\n");
+
+
     if( nrCastlingRights == -1) {
         /* [HGM] Build normal castling rights (must be done after board sizing!) */
         /*       This sets default castling rights from none to normal corners   */
@@ -4737,8 +4752,11 @@ InitPosition(redraw)
       startedFromSetupPosition = TRUE;
     }
 
-    CopyBoard(boards[0], initialPosition);
+    printf ("DEBUG: in init position 3\n");
+       
 
+    CopyBoard(boards[0], initialPosition);
+    printf ("DEBUG: in init position 3.1\n");
     if(oldx != gameInfo.boardWidth ||
        oldy != gameInfo.boardHeight ||
        oldh != gameInfo.holdingsWidth
@@ -4751,10 +4769,16 @@ InitPosition(redraw)
        gameInfo.variant == VariantFalcon
 #endif
                                          )
+      {
+           printf ("DEBUG: in init position 3.2\n");
             InitDrawingSizes(-2 ,0);
+      }
+    printf ("DEBUG: init position 99\n");
 
     if (redraw)
       DrawPosition(TRUE, boards[currentMove]);
+
+    printf ("DEBUG: end init position\n");
 }
 
 void
@@ -7770,7 +7794,7 @@ GameEnds(result, resultDetails, whosays)
        StopClocks();
        if (!isIcsGame && !appData.noChessProgram) 
          SetUserThinkingEnables();
-    
+
         /* [HGM] if a machine claims the game end we verify this claim */
         if(gameMode == TwoMachinesPlay && appData.testClaims) {
            if(appData.testLegality && whosays >= GE_ENGINE1 ) {
@@ -7821,6 +7845,7 @@ GameEnds(result, resultDetails, whosays)
                 }
                 /* (Claiming a loss is accepted no questions asked!) */
            }
+
            /* [HGM] bare: don't allow bare King to win */
            if((gameInfo.holdingsWidth == 0 || gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat)
               && gameInfo.variant != VariantLosers && gameInfo.variant != VariantGiveaway 
@@ -7843,7 +7868,6 @@ GameEnds(result, resultDetails, whosays)
            }
         }
 
-
         if(serverMoves != NULL && !loadFlag) { char c = '=';
             if(result==WhiteWins) c = '+';
             if(result==BlackWins) c = '-';
@@ -8133,6 +8157,7 @@ Reset(redraw, init)
      int redraw, init;
 {
     int i;
+    printf ("DEBUG: in reset\n");
 
     if (appData.debugMode) {
        fprintf(debugFP, "Reset(%d, %d) from gameMode %d\n",
@@ -8158,6 +8183,9 @@ Reset(redraw, init)
     white_holding[0] = black_holding[0] = NULLCHAR;
     ClearProgramStats();
     opponentKibitzes = FALSE; // [HGM] kibitz: do not reserve space in engine-output window in zippy mode
+
+    printf ("DEBUG: in reset 1\n");
+
     
     ResetFrontEnd();
     ClearHighlights();
@@ -8166,7 +8194,11 @@ Reset(redraw, init)
     gotPremove = FALSE;
     alarmSounded = FALSE;
 
+    printf ("DEBUG: in reset 2\n");
+
+
     GameEnds((ChessMove) 0, NULL, GE_PLAYER);
+    printf ("DEBUG: in reset2.1\n");
     if(appData.serverMovesName != NULL) {
         /* [HGM] prepare to make moves file for broadcasting */
         clock_t t = clock();
@@ -8180,17 +8212,24 @@ Reset(redraw, init)
         serverMoves = fopen(appData.serverMovesName, "w");
     }
 
+    printf ("DEBUG: in reset 3\n");
+
     ExitAnalyzeMode();
     gameMode = BeginningOfGame;
     ModeHighlight();
+    printf ("DEBUG: in reset 3.0.1\n");
+
     if(appData.icsActive) gameInfo.variant = VariantNormal;
     InitPosition(redraw);
+    printf ("DEBUG: in reset 3.0.1.1\n");
     for (i = 0; i < MAX_MOVES; i++) {
        if (commentList[i] != NULL) {
            free(commentList[i]);
            commentList[i] = NULL;
        }
     }
+    printf ("DEBUG: in reset 3.1\n");
+
     ResetClocks();
     timeRemaining[0][0] = whiteTimeRemaining;
     timeRemaining[1][0] = blackTimeRemaining;
@@ -8200,9 +8239,17 @@ Reset(redraw, init)
     if (init) {
            InitChessProgram(&first, startedFromSetupPosition);
     }
-    DisplayTitle("");
+    
+    printf ("DEBUG: in reset 4\n");
+       
+
+    GUI_DisplayTitle("");
+    printf ("DEBUG: in reset 5\n");
     DisplayMessage("", "");
+    printf ("DEBUG: in reset 6\n");
     HistorySet(parseList, backwardMostMove, forwardMostMove, currentMove-1);
+
+    printf ("DEBUG: end reset \n");
 }
 
 void
@@ -13147,6 +13194,8 @@ StopClocks()
     if (!StopClockTimer()) return;
     if (!appData.clockMode) return;
 
+    printf("Debug: in stop clocks\n");
+
     GetTimeMark(&now);
 
     lastTickLength = SubtractTimeMarks(&now, &tickStartTM);
@@ -13160,6 +13209,7 @@ StopClocks()
        DisplayBlackClock(blackTimeRemaining, !WhiteOnMove(currentMove));
     }
     CheckFlags();
+    printf("Debug: end stop clocks\n");
 }
        
 /* Start clock of player on move.  Time may have been reset, so