From 08dfa20da1fdeb6985ede488a2062e72b103ae29 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Sat, 31 Oct 2015 00:16:17 +0000 Subject: [PATCH] utilities:linux: Add function to change stdout stream stdout is not necessarily at stdout - at least not after I'm done with it. --- common/include/Utilities/Console.h | 3 +++ common/src/Utilities/Console.cpp | 24 +++++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/common/include/Utilities/Console.h b/common/include/Utilities/Console.h index 3cec1595c0..2f27446622 100644 --- a/common/include/Utilities/Console.h +++ b/common/include/Utilities/Console.h @@ -238,6 +238,9 @@ public: extern IConsoleWriter Console; +#ifdef __linux__ +extern void Console_SetStdout(FILE *fp); +#endif extern void Console_SetActiveHandler( const IConsoleWriter& writer, FILE* flushfp=NULL ); extern const wxString& ConsoleBuffer_Get(); extern void ConsoleBuffer_Clear(); diff --git a/common/src/Utilities/Console.cpp b/common/src/Utilities/Console.cpp index d1a9dffb35..97f1623469 100644 --- a/common/src/Utilities/Console.cpp +++ b/common/src/Utilities/Console.cpp @@ -32,6 +32,15 @@ static DeclareTls(ConsoleColors) conlog_Color( DefaultConsoleColor ); static wxString m_buffer; // used by ConsoleBuffer static Mutex m_bufferlock; // used by ConsoleBuffer +#ifdef __linux__ +static FILE *stdout_fp = stdout; + +void Console_SetStdout(FILE *fp) +{ + stdout_fp = fp; +} +#endif + // This function re-assigns the console log writer(s) to the specified target. It makes sure // to flush any contents from the buffered console log (which typically accumulates due to // log suspension during log file/window re-init operations) into the new log. @@ -71,11 +80,12 @@ void MSW_OutputDebugString( const wxString& text ) static bool hasDebugger = wxIsDebuggerRunning(); if( hasDebugger ) OutputDebugString( text ); #else - fputs(text.utf8_str(), stdout); - fflush(stdout); + fputs(text.utf8_str(), stdout_fp); + fflush(stdout_fp); #endif } + // -------------------------------------------------------------------------------------- // ConsoleNull // -------------------------------------------------------------------------------------- @@ -165,17 +175,17 @@ static void __concall ConsoleStdout_Newline() static void __concall ConsoleStdout_DoSetColor( ConsoleColors color ) { #ifdef __linux__ - fprintf(stdout, "\033[0m%s", GetLinuxConsoleColor(color)); - fflush(stdout); + fprintf(stdout_fp, "\033[0m%s", GetLinuxConsoleColor(color)); + fflush(stdout_fp); #endif } static void __concall ConsoleStdout_SetTitle( const wxString& title ) { #ifdef __linux__ - fputs("\033]0;", stdout); - fputs(title.utf8_str(), stdout); - fputs("\007", stdout); + fputs("\033]0;", stdout_fp); + fputs(title.utf8_str(), stdout_fp); + fputs("\007", stdout_fp); #endif }