These are the changes I had made in my source tree between 4.2.6 and
[xboard.git] / winboard / winboard.c
index 455c483..68dab66 100644 (file)
 \r
 #include <windows.h>\r
 #include <winuser.h>\r
+#include <winsock.h>\r
 \r
 #include <stdio.h>\r
 #include <stdlib.h>\r
 #include <malloc.h>\r
-#include <io.h>\r
 #include <sys/stat.h>\r
 #include <fcntl.h>\r
 #include <math.h>\r
 #include <commdlg.h>\r
 #include <dlgs.h>\r
 #include <richedit.h>\r
+#include <mmsystem.h>\r
 \r
 #if __GNUC__\r
 #include <errno.h>\r
@@ -168,6 +169,7 @@ static BOOL paletteChanged = FALSE;
 static HICON iconWhite, iconBlack, iconCurrent;\r
 static int doingSizing = FALSE;\r
 static int lastSizing = 0;\r
+static int prevStderrPort;\r
 \r
 #if __GNUC__ && !defined(_winmajor)\r
 #define oldDialog 0 /* cygwin doesn't define _winmajor; mingw does */\r
@@ -344,8 +346,6 @@ COLORREF consoleBackgroundColor;
 \r
 char *programVersion;\r
 \r
-#include <winsock.h>\r
-\r
 #define CPReal 1\r
 #define CPComm 2\r
 #define CPSock 3\r
@@ -3246,7 +3246,8 @@ Promotion(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     /* Center the dialog over the application window */\r
     CenterWindow(hDlg, GetWindow(hDlg, GW_OWNER));\r
     ShowWindow(GetDlgItem(hDlg, PB_King), \r
-      (!appData.testLegality || gameInfo.variant == VariantSuicide) ?\r
+      (!appData.testLegality || gameInfo.variant == VariantSuicide ||\r
+       gameInfo.variant == VariantGiveaway) ?\r
               SW_SHOW : SW_HIDE);\r
     return TRUE;\r
 \r
@@ -4317,7 +4318,7 @@ OpenFileDialog(HWND hwnd, BOOL write, char *defName, char *defExt,
   if (write ? GetSaveFileName(&openFileName) : \r
               GetOpenFileName(&openFileName)) {\r
     /* open the file */\r
-    f = fopen(openFileName.lpstrFile, write ? "a" : "r");\r
+    f = fopen(openFileName.lpstrFile, write ? "a" : "rb");\r
     if (f == NULL) {\r
       MessageBox(hwnd, "File open failed", NULL,\r
                 MB_OK|MB_ICONEXCLAMATION);\r
@@ -4971,7 +4972,7 @@ ErrorDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
     switch (LOWORD(wParam)) {\r
     case IDOK:\r
     case IDCANCEL:\r
-      if (errorDialog = hDlg) errorDialog = NULL;\r
+      if (errorDialog == hDlg) errorDialog = NULL;\r
       DestroyWindow(hDlg);\r
       return TRUE;\r
 \r
@@ -7202,6 +7203,7 @@ OpenRcmd(char* host, char* user, char* cmd, ProcRef* pr)
   mysa.sin_family = AF_INET;\r
   mysa.sin_addr.s_addr = INADDR_ANY;\r
   for (fromPort = 1023;; fromPort--) {\r
+    if (fromPort == prevStderrPort) continue; // don't reuse port\r
     if (fromPort < 0) {\r
       (void) closesocket(s);\r
       WSACleanup();\r
@@ -7239,6 +7241,7 @@ OpenRcmd(char* host, char* user, char* cmd, ProcRef* pr)
     }\r
     break;\r
   }\r
+  prevStderrPort = fromPort; // remember port used\r
   sprintf(stderrPortStr, "%d", fromPort);\r
 \r
   if (send(s, stderrPortStr, strlen(stderrPortStr) + 1, 0) == SOCKET_ERROR) {\r