diff options
Diffstat (limited to 'xorg-server/hw/xwin/xlaunch/main.cc')
-rw-r--r-- | xorg-server/hw/xwin/xlaunch/main.cc | 123 |
1 files changed, 114 insertions, 9 deletions
diff --git a/xorg-server/hw/xwin/xlaunch/main.cc b/xorg-server/hw/xwin/xlaunch/main.cc index 2247d3aaf..b3b1001ff 100644 --- a/xorg-server/hw/xwin/xlaunch/main.cc +++ b/xorg-server/hw/xwin/xlaunch/main.cc @@ -23,6 +23,10 @@ * holders shall not be used in advertising or otherwise to promote the sale, * use or other dealings in this Software without prior written authorization. */ + +#define printf _not_used_ /* Make sure that we do not use the standard printf definition because + we are going to reimplement it in this file */ + #include "window/util.h" #include "window/wizard.h" #include "resources/resources.h" @@ -34,6 +38,68 @@ #include <X11/Xlib.h> +#ifdef _MSC_VER +#define snprintf _snprintf +#endif +#include <fcntl.h> +#include <io.h> +#undef printf + +#if defined(_MSC_VER) && defined(_DLL) +#define _CRTEXP __declspec(dllexport) +#else +#define _CRTEXP +#endif + +_Check_return_opt_ _CRTEXP int __cdecl printf(_In_z_ _Printf_format_string_ const char * pFmt, ...) +{ + static int ConsoleCreated=0; + va_list arglist; + if (!ConsoleCreated) + { + int hConHandle; + long lStdHandle; + CONSOLE_SCREEN_BUFFER_INFO coninfo; + + FILE *fp; + const unsigned int MAX_CONSOLE_LINES = 500; + ConsoleCreated=1; + if (!AttachConsole(ATTACH_PARENT_PROCESS)) + AllocConsole(); + + // set the screen buffer to be big enough to let us scroll text + GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo); + coninfo.dwSize.Y = MAX_CONSOLE_LINES; + SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize); + + // redirect unbuffered STDOUT to the console + lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE); + hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); + fp = _fdopen( hConHandle, "w" ); + *stdout = *fp; + setvbuf( stdout, NULL, _IONBF, 0 ); + + // redirect unbuffered STDIN to the console + lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE); + hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); + fp = _fdopen( hConHandle, "r" ); + *stdin = *fp; + setvbuf( stdin, NULL, _IONBF, 0 ); + + // redirect unbuffered STDERR to the console + lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE); + hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); + fp = _fdopen( hConHandle, "w" ); + *stderr = *fp; + setvbuf( stderr, NULL, _IONBF, 0 ); + + } + + va_start(arglist, pFmt ); + return vfprintf(stderr, pFmt, arglist); +} + + /// @brief Send WM_ENDSESSION to all program windows. /// This will shutdown the started xserver BOOL CALLBACK KillWindowsProc(HWND hwnd, LPARAM lParam) @@ -108,7 +174,10 @@ class CMyWizard : public CWizard } // Check for valid input if (config.display.empty()) + { + MessageBox(hwndDlg,"Please fill in a display number.","Error",MB_OK); SetWindowLong(hwndDlg, DWL_MSGRESULT, -1); + } else SetWindowLong(hwndDlg, DWL_MSGRESULT, IDD_CLIENTS); return TRUE; @@ -489,7 +558,7 @@ class CMyWizard : public CWizard return NULL; } - /// @brief Do the actual start of Xming and clients + /// @brief Do the actual start of VCXsrv and clients void StartUp() { std::string buffer; @@ -500,12 +569,12 @@ class CMyWizard : public CWizard std::string display = "localhost" + display_id + ":0"; #ifdef _DEBUG - // Debug only: Switch to Xming installation directory - SetCurrentDirectory("C:\\Programme\\Xming"); + // Debug only: Switch to VCXsrv installation directory + SetCurrentDirectory("C:\\Programme\\vcxsrv"); #endif - // Build Xming commandline - buffer = "Xming " + display_id + " "; + // Build Xsrv commandline + buffer = "vcxsrv " + display_id + " "; switch (config.window) { case CConfig::MultiWindow: @@ -577,7 +646,7 @@ class CMyWizard : public CWizard sic.cb = sizeof(sic); ZeroMemory( &pic, sizeof(pic) ); - // Start Xming process. + // Start VCXsrv process. #ifdef _DEBUG printf("%s\n", buffer.c_str()); #endif @@ -627,7 +696,7 @@ class CMyWizard : public CWizard #ifdef _DEBUG printf("killing process!\n"); #endif - // Check if Xming is still running + // Check if Xsrv is still running DWORD exitcode; GetExitCodeProcess(pi.hProcess, &exitcode); unsigned counter = 0; @@ -636,7 +705,7 @@ class CMyWizard : public CWizard if (++counter > 10) TerminateProcess(pi.hProcess, (DWORD)-1); else - // Shutdown Xming (the soft way!) + // Shutdown Xsrv (the soft way!) EnumThreadWindows(pi.dwThreadId, KillWindowsProc, 0); Sleep(500); GetExitCodeProcess(pi.hProcess, &exitcode); @@ -695,6 +764,42 @@ int main(int argc, char **argv) } } - +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +{ + int argc=1; + #define MAXNRARGS 20 + char *argv[MAXNRARGS]={"plink"}; + char *pTmp=lpCmdLine; + while (*pTmp && argc<MAXNRARGS-1) + { + char *pEnd; + if (*pTmp=='"') + { + pEnd=strchr(pTmp+1,'"'); + } + else if (*pTmp!=' ') + { + pEnd=strchr(pTmp,' '); + } + else + { + pTmp++; + continue; + } + if (pEnd) + { + *pEnd=0; + argv[argc++]=pTmp; + pTmp=pEnd+1; + } + else + { + argv[argc++]=pTmp; + break; + } + } + + return main(argc,argv); +} |