source clean up. Fix compiler warning, removed unused variables, etc.
[xboard.git] / winboard / winboard.c
index a00473e..bdfc1f3 100644 (file)
@@ -70,6 +70,7 @@
 #include <dlgs.h>\r
 #include <richedit.h>\r
 #include <mmsystem.h>\r
+#include <ctype.h>\r
 \r
 #if __GNUC__\r
 #include <errno.h>\r
@@ -99,6 +100,9 @@ extern int whiteFlag, blackFlag;
 Boolean flipClock = FALSE;\r
 \r
 void DisplayHoldingsCount(HDC hdc, int x, int y, int align, int copyNumber);\r
+VOID NewVariantPopup(HWND hwnd);\r
+int FinishMove P((ChessMove moveType, int fromX, int fromY, int toX, int toY,\r
+                  /*char*/int promoChar));\r
 \r
 typedef struct {\r
   ChessSquare piece;  \r
@@ -177,7 +181,7 @@ static HWND hwndPause;    /* pause button */
 static HBITMAP pieceBitmap[3][(int) BlackPawn]; /* [HGM] nr of bitmaps referred to bP in stead of wK */\r
 static HBRUSH lightSquareBrush, darkSquareBrush,\r
   blackSquareBrush, /* [HGM] for band between board and holdings */\r
-  whitePieceBrush, blackPieceBrush, iconBkgndBrush, outlineBrush;\r
+  whitePieceBrush, blackPieceBrush, iconBkgndBrush /*, outlineBrush*/;\r
 static POINT gridEndpoints[(BOARD_SIZE + 1) * 4];\r
 static DWORD gridVertexCounts[(BOARD_SIZE + 1) * 2];\r
 static HPEN gridPen = NULL;\r
@@ -247,7 +251,7 @@ SizeInfo sizeInfo[] =
   { NULL, 0, 0, 0, 0, 0, 0 }\r
 };\r
 \r
-#define MF(x) {x, {0, }, {0, }, 0}\r
+#define MF(x) {x, {{0,}, 0. }, {0, }, 0}\r
 MyFont fontRec[NUM_SIZES][NUM_FONTS] =\r
 {\r
   { MF(CLOCK_FONT_TINY), MF(MESSAGE_FONT_TINY), MF(COORD_FONT_TINY), MF(CONSOLE_FONT_TINY), MF(COMMENT_FONT_TINY), MF(EDITTAGS_FONT_TINY), MF(MOVEHISTORY_FONT_ALL) },\r
@@ -478,6 +482,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
 {\r
   MSG msg;\r
   HANDLE hAccelMain, hAccelNoAlt, hAccelNoICS;\r
+//  INITCOMMONCONTROLSEX ex;\r
 \r
   debugFP = stderr;\r
 \r
@@ -490,6 +495,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
   if (!InitInstance(hInstance, nCmdShow, lpCmdLine)) {\r
     return (FALSE);\r
   }\r
+//  InitCommonControlsEx(&ex);\r
+  InitCommonControls();\r
 \r
   hAccelMain = LoadAccelerators (hInstance, szAppName);\r
   hAccelNoAlt = LoadAccelerators (hInstance, "NO_ALT");\r
@@ -1407,6 +1414,7 @@ FileGet(void *getClosure)
   FILE* f = (FILE*) getClosure;\r
 \r
   c = getc(f);\r
+  if (c == '\r') c = getc(f); // work around DOS format files by bypassing the '\r' completely\r
   if (c == EOF)\r
     return NULLCHAR;\r
   else\r
@@ -1862,12 +1870,6 @@ InitAppData(LPSTR lpCmdLine)
   dcb.fNull = FALSE;\r
   dcb.fRtsControl = RTS_CONTROL_ENABLE;\r
   dcb.fAbortOnError = FALSE;\r
-  /* Microsoft SDK >= Feb. 2003 (MS VS >= 2002) */\r
-  #if (defined(_MSC_VER) && _MSC_VER <= 1200) \r
-       //dcb.wReserved = 0;\r
-  #else\r
-    dcb.wReserved = 0;\r
-  #endif\r
   dcb.ByteSize = 7;\r
   dcb.Parity = SPACEPARITY;\r
   dcb.StopBits = ONESTOPBIT;\r
@@ -2286,14 +2288,14 @@ SaveSettings(char* name)
     case ArgColor:\r
       {\r
        COLORREF color = *(COLORREF *)ad->argLoc;\r
-       fprintf(f, "/%s=#%02x%02x%02x\n", ad->argName, \r
+       fprintf(f, "/%s=#%02lx%02lx%02lx\n", ad->argName, \r
          color&0xff, (color>>8)&0xff, (color>>16)&0xff);\r
       }\r
       break;\r
     case ArgAttribs:\r
       {\r
        MyTextAttribs* ta = &textAttribs[(ColorClass)ad->argLoc];\r
-       fprintf(f, "/%s=\"%s%s%s%s%s#%02x%02x%02x\"\n", ad->argName,\r
+       fprintf(f, "/%s=\"%s%s%s%s%s#%02lx%02lx%02lx\"\n", ad->argName,\r
           (ta->effects & CFE_BOLD) ? "b" : "",\r
           (ta->effects & CFE_ITALIC) ? "i" : "",\r
           (ta->effects & CFE_UNDERLINE) ? "u" : "",\r
@@ -2331,6 +2333,8 @@ SaveSettings(char* name)
       break;\r
     case ArgCommSettings:\r
       PrintCommSettings(f, ad->argName, (DCB *)ad->argLoc);\r
+    case ArgNone:\r
+    case ArgSettingsFilename: ;\r
     }\r
   }\r
   fclose(f);\r
@@ -3258,7 +3262,6 @@ InitDrawingSizes(BoardSize boardSize, int flags)
        boardRect.top + lineGap / 2 + (i * (squareSize + lineGap));\r
       gridEndpoints[i*2 + 1].x = boardRect.left + lineGap / 2 +\r
         BOARD_WIDTH * (squareSize + lineGap);\r
-       lineGap / 2 + (i * (squareSize + lineGap));\r
       gridVertexCounts[i*2] = gridVertexCounts[i*2 + 1] = 2;\r
     }\r
     for (i = 0; i < BOARD_WIDTH + 1; i++) {\r
@@ -3678,8 +3681,8 @@ DrawPieceOnDC(HDC hdc, ChessSquare piece, int color, int sqcolor, int x, int y,
   } else {\r
     tmpSize = squareSize;\r
     if(minorSize &&\r
-        (piece >= (int)WhiteNightrider && piece <= WhiteGrasshopper ||\r
-         piece >= (int)BlackNightrider && piece <= BlackGrasshopper)  ) {\r
+        ((piece >= (int)WhiteNightrider && piece <= WhiteGrasshopper) ||\r
+         (piece >= (int)BlackNightrider && piece <= BlackGrasshopper))  ) {\r
       /* [HGM] no bitmap available for promoted pieces in Crazyhouse        */\r
       /* Bitmaps of smaller size are substituted, but we have to align them */\r
       x += (squareSize - minorSize)>>1;\r
@@ -4215,9 +4218,9 @@ void fputDW(FILE *f, int x)
 VOID\r
 DrawLogoOnDC(HDC hdc, RECT logoRect, ChessProgramState *cps)\r
 {\r
-  HBITMAP bufferBitmap;\r
+//  HBITMAP bufferBitmap;\r
   BITMAP bi;\r
-  RECT Rect;\r
+//  RECT Rect;\r
   HDC tmphdc;\r
   HBITMAP hbm;\r
   int w = 100, h = 50;\r
@@ -4556,7 +4559,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board)
         boardRect.bottom - boardRect.top,\r
         tmphdc, boardRect.left, boardRect.top, SRCCOPY);\r
   if(saveDiagFlag) { \r
-    BITMAP b; int i, j, m, w, wb, fac=0; char pData[1000000]; \r
+    BITMAP b; int i, j=0, m, w, wb, fac=0; char pData[1000000]; \r
     BITMAPINFOHEADER bih; int color[16], nrColors=0;\r
 \r
     GetObject(bufferBitmap, sizeof(b), &b);\r
@@ -4600,7 +4603,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board)
                    while(p&3) pData[p++] = 0;\r
                }\r
                fac = 3;\r
-               wb = (wb+31>>5)<<2;\r
+               wb = ((wb+31)>>5)<<2;\r
        }\r
        // write BITMAPFILEHEADER\r
        fprintf(diagFile, "BM");\r
@@ -4660,9 +4663,6 @@ int
 SaveDiagram(f)\r
      FILE *f;\r
 {\r
-    time_t tm;\r
-    char *fen;\r
-\r
     saveDiagFlag = 1; diagFile = f;\r
     HDCDrawPosition(NULL, TRUE, NULL);\r
 \r
@@ -4687,7 +4687,7 @@ PaintProc(HWND hwnd)
   PAINTSTRUCT ps;\r
   HFONT       oldFont;\r
 \r
-  if(hdc = BeginPaint(hwnd, &ps)) {\r
+  if((hdc = BeginPaint(hwnd, &ps))) {\r
     if (IsIconic(hwnd)) {\r
       DrawIcon(hdc, 2, 2, iconCurrent);\r
     } else {\r
@@ -4780,7 +4780,7 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
   POINT pt;\r
   static int recursive = 0;\r
   HMENU hmenu;\r
-  BOOLEAN needsRedraw = FALSE;\r
+//  BOOLEAN needsRedraw = FALSE;\r
   BOOLEAN saveAnimate;\r
   BOOLEAN forceFullRepaint = IsFullRepaintPreferrable(); /* [AS] */\r
   static BOOLEAN sameAgain = FALSE, promotionChoice = FALSE;\r
@@ -4855,7 +4855,7 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
       }\r
       if (!appData.highlightLastMove) {\r
         ClearHighlights();\r
-       DrawPosition(forceFullRepaint || FALSE, NULL);\r
+       DrawPosition((int) (forceFullRepaint || FALSE), NULL);\r
       }\r
       fromX = fromY = -1;\r
       dragInfo.start.x = dragInfo.start.y = -1;\r
@@ -4864,8 +4864,8 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
     } else if (x < 0 || y < 0\r
       /* [HGM] block clicks between board and holdings */\r
               || x == BOARD_LEFT-1 || x == BOARD_RGHT\r
-              || x == BOARD_LEFT-2 && y < BOARD_HEIGHT-gameInfo.holdingsSize\r
-              || x == BOARD_RGHT+1 && y >= gameInfo.holdingsSize\r
+              || (x == BOARD_LEFT-2 && y < BOARD_HEIGHT-gameInfo.holdingsSize)\r
+              || (x == BOARD_RGHT+1 && y >= gameInfo.holdingsSize)\r
        /* EditPosition, empty square, or different color piece;\r
           click-click move is possible */\r
                                ) {\r
@@ -4895,8 +4895,8 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
         if(moveType != ImpossibleMove) {\r
           /* [HGM] We use PromotionToKnight in Shogi to indicate frorced promotion */\r
           if (moveType == WhitePromotionKnight || moveType == BlackPromotionKnight ||\r
-             (moveType == WhitePromotionQueen || moveType == BlackPromotionQueen) &&\r
-              appData.alwaysPromoteToQueen) {\r
+            ((moveType == WhitePromotionQueen || moveType == BlackPromotionQueen) &&\r
+              appData.alwaysPromoteToQueen)) {\r
                   FinishMove(moveType, fromX, fromY, toX, toY, 'q');\r
                   if (!appData.highlightLastMove) {\r
                       ClearHighlights();\r
@@ -5001,8 +5001,8 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
           /* [HGM] use move type to determine if move is promotion.\r
              Knight is Shogi kludge for mandatory promotion, Queen means choice */\r
           if (moveType == WhitePromotionKnight || moveType == BlackPromotionKnight ||\r
-             (moveType == WhitePromotionQueen || moveType == BlackPromotionQueen) &&\r
-              appData.alwaysPromoteToQueen) \r
+            ((moveType == WhitePromotionQueen || moveType == BlackPromotionQueen) &&\r
+              appData.alwaysPromoteToQueen)) \r
                FinishMove(moveType, fromX, fromY, toX, toY, 'q');\r
           else \r
           if (moveType == WhitePromotionQueen || moveType == BlackPromotionQueen ) {\r
@@ -5066,12 +5066,12 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
         * Play moves forward\r
         */\r
        if((short)HIWORD(wParam) > 0 && currentMove < forwardMostMove) \r
-               if(lastDir == 1) ForwardEvent(); else lastDir = 1; // [HGM] suppress first event in each direction\r
+               { if(lastDir == 1) ForwardEvent(); else lastDir = 1; } // [HGM] suppress first event in direction\r
        /* Mouse Wheel is being rolled backward\r
         * Play moves backward\r
         */\r
        if((short)HIWORD(wParam) < 0 && currentMove > backwardMostMove) \r
-               if(lastDir == -1) BackwardEvent(); else lastDir = -1;\r
+               { if(lastDir == -1) BackwardEvent(); else lastDir = -1; }\r
     }\r
     break;\r
 \r
@@ -5229,16 +5229,16 @@ Promotion(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
               SW_SHOW : SW_HIDE);\r
     /* [HGM] Only allow C & A promotions if these pieces are defined */\r
     ShowWindow(GetDlgItem(hDlg, PB_Archbishop),\r
-       (PieceToChar(WhiteAngel) >= 'A' &&\r
-        PieceToChar(WhiteAngel) != '~' ||\r
-        PieceToChar(BlackAngel) >= 'A' &&\r
-        PieceToChar(BlackAngel) != '~'   ) ?\r
+       ((PieceToChar(WhiteAngel) >= 'A' &&\r
+         PieceToChar(WhiteAngel) != '~') ||\r
+        (PieceToChar(BlackAngel) >= 'A' &&\r
+         PieceToChar(BlackAngel) != '~')   ) ?\r
               SW_SHOW : SW_HIDE);\r
     ShowWindow(GetDlgItem(hDlg, PB_Chancellor), \r
-       (PieceToChar(WhiteMarshall) >= 'A' &&\r
-        PieceToChar(WhiteMarshall) != '~' ||\r
-        PieceToChar(BlackMarshall) >= 'A' &&\r
-        PieceToChar(BlackMarshall) != '~'   ) ?\r
+       ((PieceToChar(WhiteMarshall) >= 'A' &&\r
+         PieceToChar(WhiteMarshall) != '~') ||\r
+        (PieceToChar(BlackMarshall) >= 'A' &&\r
+         PieceToChar(BlackMarshall) != '~')   ) ?\r
               SW_SHOW : SW_HIDE);\r
     /* [HGM] Hide B & R button in Shogi, use Q as promote, N as defer */\r
     ShowWindow(GetDlgItem(hDlg, PB_Rook),\r
@@ -6788,7 +6788,7 @@ SetStartupDialogEnables(HWND hDlg)
 {\r
   EnableWindow(GetDlgItem(hDlg, OPT_ChessEngineName),\r
     IsDlgButtonChecked(hDlg, OPT_ChessEngine) ||\r
-    appData.zippyPlay && IsDlgButtonChecked(hDlg, OPT_ChessServer));\r
+    (appData.zippyPlay && IsDlgButtonChecked(hDlg, OPT_ChessServer)));\r
   EnableWindow(GetDlgItem(hDlg, OPT_SecondChessEngineName),\r
     IsDlgButtonChecked(hDlg, OPT_ChessEngine));\r
   EnableWindow(GetDlgItem(hDlg, OPT_ChessServerName),\r
@@ -7414,8 +7414,6 @@ VOID
 GothicPopUp(char *title, VariantClass variant)\r
 {\r
   FARPROC lpProc;\r
-  char *p, *q;\r
-  BOOLEAN modal = hwndMain == NULL;\r
   static char *lastTitle;\r
 \r
   strncpy(errorTitle, title, sizeof(errorTitle));\r
@@ -7496,7 +7494,7 @@ IcsTextMenuEntry icsTextMenuEntry[ICS_TEXT_MENU_SIZE];
 void\r
 ParseIcsTextMenu(char *icsTextMenuString)\r
 {\r
-  int flags = 0;\r
+//  int flags = 0;\r
   IcsTextMenuEntry *e = icsTextMenuEntry;\r
   char *p = icsTextMenuString;\r
   while (e->item != NULL && e < icsTextMenuEntry + ICS_TEXT_MENU_SIZE) {\r
@@ -7939,8 +7937,8 @@ LRESULT CALLBACK
 ConsoleWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
 {\r
   static SnapData sd;\r
-  static HWND hText, hInput, hFocus;\r
-  InputSource *is = consoleInputSource;\r
+  static HWND hText, hInput /*, hFocus*/;\r
+//  InputSource *is = consoleInputSource;\r
   RECT rect;\r
   static int sizeX, sizeY;\r
   int newSizeX, newSizeY;\r
@@ -8305,7 +8303,7 @@ void CheckForInputBufferFull( InputSource * is )
 \r
         if( p >= is->next ) {\r
             if (appData.debugMode) {\r
-                fprintf( debugFP, "Input line exceeded buffer size (source id=%u)\n", is->id );\r
+                fprintf( debugFP, "Input line exceeded buffer size (source id=%lu)\n", is->id );\r
             }\r
 \r
             is->error = ERROR_BROKEN_PIPE; /* [AS] Just any non-successful code! */\r
@@ -8354,7 +8352,7 @@ InputThread(LPVOID arg)
   CloseHandle(is->hFile);\r
 \r
   if (appData.debugMode) {\r
-    fprintf( debugFP, "Input thread terminated (id=%u, error=%d, count=%d)\n", is->id, is->error, is->count );\r
+    fprintf( debugFP, "Input thread terminated (id=%lu, error=%d, count=%ld)\n", is->id, is->error, is->count );\r
   }\r
 \r
   return 0;\r
@@ -9236,7 +9234,7 @@ LRESULT CALLBACK GameListOptions_Proc(HWND hDlg, UINT message, WPARAM wParam, LP
             {\r
                 char * pc = lpUserGLT;\r
                 int idx = 0;\r
-                int cnt = (int) SendDlgItemMessage( hDlg, IDC_GameListTags, LB_GETCOUNT, 0, 0 );\r
+//                int cnt = (int) SendDlgItemMessage( hDlg, IDC_GameListTags, LB_GETCOUNT, 0, 0 );\r
                 char id;\r
 \r
                 do {\r
@@ -9787,7 +9785,7 @@ DestroyChildProcess(ProcRef pr, int/*boolean*/ signal)
         result = TerminateProcess( cp->hProcess, 0 );\r
 \r
         if ( appData.debugMode) {\r
-            fprintf( debugFP, "Terminating process %u, result=%d\n", cp->pid, result );\r
+            fprintf( debugFP, "Terminating process %lu, result=%d\n", cp->pid, result );\r
         }\r
     }\r
     else if( signal == 10 ) {\r
@@ -9797,7 +9795,7 @@ DestroyChildProcess(ProcRef pr, int/*boolean*/ signal)
             result = TerminateProcess( cp->hProcess, 0 );\r
 \r
             if ( appData.debugMode) {\r
-                fprintf( debugFP, "Process %u still alive after timeout, killing... result=%d\n", cp->pid, result );\r
+                fprintf( debugFP, "Process %lu still alive after timeout, killing... result=%d\n", cp->pid, result );\r
             }\r
 \r
         }\r
@@ -10701,4 +10699,3 @@ void SetProgramStats( FrontEndProgramStats * stats )
 \r
     EngineOutputUpdate( stats );\r
 }\r
-///
\ No newline at end of file