[hatari-devel] Win32 console patch |
[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]
Hi,
Find attached a patch that allows to run Hatari from a windows commandline, and see any debug output without having to specify -W parameter. This might also have the benefit of speeding up output, since output now goes to the console of the command-shell, not that of the application.
The -W parameter is still needed when you are running the application from the desktop. In this case it behaves as before.
|
diff --git a/src/gui-win/opencon.c b/src/gui-win/opencon.c index f245cf63..e8a46f0e 100644 --- a/src/gui-win/opencon.c +++ b/src/gui-win/opencon.c @@ -17,14 +17,47 @@ #include "opencon.h" #include "../includes/configuration.h" +#ifdef __CYGWIN__ +#define CONSOLE_DEV "/dev/tty" +#else +#define CONSOLE_DEV "CON" +#endif + void Win_OpenCon(void) { if (ConfigureParams.Log.bConsoleWindow) { - AllocConsole(); - freopen("CON", "w", stdout); - freopen("CON", "r", stdin); - freopen("CON", "w", stderr); + if (AllocConsole()) + { + freopen(CONSOLE_DEV, "w", stdout); + freopen(CONSOLE_DEV, "r", stdin); + freopen(CONSOLE_DEV, "w", stderr); + } + } + else + { + HANDLE my_stdout; + HANDLE my_stderr; + DWORD filetype_out; + DWORD filetype_err; + + my_stdout = GetStdHandle(STD_OUTPUT_HANDLE); + my_stderr = GetStdHandle(STD_ERROR_HANDLE); + filetype_out = GetFileType(my_stdout); + filetype_err = GetFileType(my_stderr); + if (my_stdout == INVALID_HANDLE_VALUE || + filetype_out == FILE_TYPE_UNKNOWN || + my_stderr == INVALID_HANDLE_VALUE || + filetype_err == FILE_TYPE_UNKNOWN) + { + if (AttachConsole(ATTACH_PARENT_PROCESS)) + { + if (my_stdout == INVALID_HANDLE_VALUE || filetype_out == FILE_TYPE_UNKNOWN) + freopen(CONSOLE_DEV, "w", stdout); + if (my_stderr == INVALID_HANDLE_VALUE || filetype_err == FILE_TYPE_UNKNOWN) + freopen(CONSOLE_DEV, "w", stderr); + } + } } } diff --git a/src/main.c b/src/main.c index db8760fd..7f0c7f30 100644 --- a/src/main.c +++ b/src/main.c @@ -937,7 +937,7 @@ int main(int argc, char *argv[]) /* monitor type option might require "reset" -> true */ Configuration_Apply(true); -#ifdef WIN32 +#if defined(_WIN32) || defined(__CYGWIN__) Win_OpenCon(); #endif
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |