X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwinboard.c;h=cd2e98cf78d1cb0b0581eb7a304ed8944bcdfdd9;hb=1787d72dbd0f3ff703050df00dc6ebb5eebe14d7;hp=455c48366407ccc055486ecb2b93e85b9764e87b;hpb=05bc30b15e31c427ce208495a889e9ff36e6642b;p=xboard.git diff --git a/winboard/winboard.c b/winboard/winboard.c index 455c483..cd2e98c 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -53,17 +53,18 @@ #include #include +#include #include #include #include -#include #include #include #include #include #include #include +#include #if __GNUC__ #include @@ -168,6 +169,7 @@ static BOOL paletteChanged = FALSE; static HICON iconWhite, iconBlack, iconCurrent; static int doingSizing = FALSE; static int lastSizing = 0; +static int prevStderrPort; #if __GNUC__ && !defined(_winmajor) #define oldDialog 0 /* cygwin doesn't define _winmajor; mingw does */ @@ -335,6 +337,7 @@ HWND analysisDialog = NULL; BOOLEAN analysisDialogUp = FALSE; static int analysisX, analysisY, analysisH, analysisW; +char errorTitle[MSG_SIZ]; char errorMessage[2*MSG_SIZ]; HWND errorDialog = NULL; BOOLEAN moveErrorMessageUp = FALSE; @@ -344,8 +347,6 @@ COLORREF consoleBackgroundColor; char *programVersion; -#include - #define CPReal 1 #define CPComm 2 #define CPSock 3 @@ -3246,7 +3247,8 @@ Promotion(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) /* Center the dialog over the application window */ CenterWindow(hDlg, GetWindow(hDlg, GW_OWNER)); ShowWindow(GetDlgItem(hDlg, PB_King), - (!appData.testLegality || gameInfo.variant == VariantSuicide) ? + (!appData.testLegality || gameInfo.variant == VariantSuicide || + gameInfo.variant == VariantGiveaway) ? SW_SHOW : SW_HIDE); return TRUE; @@ -4317,7 +4319,7 @@ OpenFileDialog(HWND hwnd, BOOL write, char *defName, char *defExt, if (write ? GetSaveFileName(&openFileName) : GetOpenFileName(&openFileName)) { /* open the file */ - f = fopen(openFileName.lpstrFile, write ? "a" : "r"); + f = fopen(openFileName.lpstrFile, write ? "a" : "rb"); if (f == NULL) { MessageBox(hwnd, "File open failed", NULL, MB_OK|MB_ICONEXCLAMATION); @@ -4941,6 +4943,45 @@ PopUpMoveDialog(char firstchar) \*---------------------------------------------------------------------------*/ /* Nonmodal error box */ +LRESULT CALLBACK ErrorDialog(HWND hDlg, UINT message, + WPARAM wParam, LPARAM lParam); + +VOID +ErrorPopUp(char *title, char *content) +{ + FARPROC lpProc; + char *p, *q; + BOOLEAN modal = hwndMain == NULL; + + p = content; + q = errorMessage; + while (*p) { + if (*p == '\n') { + if (modal) { + *q++ = ' '; + p++; + } else { + *q++ = '\r'; + *q++ = *p++; + } + } else { + *q++ = *p++; + } + } + *q = NULLCHAR; + strncpy(errorTitle, title, sizeof(errorTitle)); + errorTitle[sizeof(errorTitle) - 1] = '\0'; + + if (modal) { + MessageBox(NULL, errorMessage, errorTitle, MB_OK|MB_ICONEXCLAMATION); + } else { + lpProc = MakeProcInstance((FARPROC)ErrorDialog, hInst); + CreateDialog(hInst, MAKEINTRESOURCE(DLG_Error), + hwndMain, (DLGPROC)lpProc); + FreeProcInstance(lpProc); + } +} + VOID ErrorPopDown() { @@ -4963,6 +5004,7 @@ ErrorDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) rChild.top + boardRect.top - (rChild.bottom - rChild.top), 0, 0, SWP_NOZORDER|SWP_NOSIZE); errorDialog = hDlg; + SetWindowText(hDlg, errorTitle); hwndText = GetDlgItem(hDlg, OPT_ErrorText); SetDlgItemText(hDlg, OPT_ErrorText, errorMessage); return FALSE; @@ -4971,7 +5013,7 @@ ErrorDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) switch (LOWORD(wParam)) { case IDOK: case IDCANCEL: - if (errorDialog = hDlg) errorDialog = NULL; + if (errorDialog == hDlg) errorDialog = NULL; DestroyWindow(hDlg); return TRUE; @@ -6315,31 +6357,8 @@ DisplayError(char *str, int error) } } } - p = buf; - q = errorMessage; - while (*p) { - if (*p == '\n') { - if (hwndMain != NULL /*!!?*/) { - *q++ = '\r'; - *q++ = *p++; - } else { - *q++ = ' '; - p++; - } - } else { - *q++ = *p++; - } - } - *q = NULLCHAR; - if (hwndMain == NULL) { - MessageBox(NULL, errorMessage, "Error", MB_OK|MB_ICONEXCLAMATION); - } else { - lpProc = MakeProcInstance((FARPROC)ErrorDialog, hInst); - CreateDialog(hInst, MAKEINTRESOURCE(DLG_Error), - hwndMain, (DLGPROC)lpProc); - FreeProcInstance(lpProc); - } + ErrorPopUp("Error", buf); } @@ -6350,7 +6369,7 @@ DisplayMoveError(char *str) ClearHighlights(); DrawPosition(FALSE, NULL); if (appData.popupMoveErrors) { - DisplayError(str, 0); + ErrorPopUp("Error", str); } else { DisplayMessage(str, ""); moveErrorMessageUp = TRUE; @@ -6399,6 +6418,13 @@ DisplayInformation(char *str) } +VOID +DisplayNote(char *str) +{ + ErrorPopUp("Note", str); +} + + typedef struct { char *title, *question, *replyPrefix; ProcRef pr; @@ -7202,6 +7228,7 @@ OpenRcmd(char* host, char* user, char* cmd, ProcRef* pr) mysa.sin_family = AF_INET; mysa.sin_addr.s_addr = INADDR_ANY; for (fromPort = 1023;; fromPort--) { + if (fromPort == prevStderrPort) continue; // don't reuse port if (fromPort < 0) { (void) closesocket(s); WSACleanup(); @@ -7239,6 +7266,7 @@ OpenRcmd(char* host, char* user, char* cmd, ProcRef* pr) } break; } + prevStderrPort = fromPort; // remember port used sprintf(stderrPortStr, "%d", fromPort); if (send(s, stderrPortStr, strlen(stderrPortStr) + 1, 0) == SOCKET_ERROR) {