From 92723556969b9743119b516b6205bec78aa09985 Mon Sep 17 00:00:00 2001 From: radius Date: Sat, 8 Oct 2016 15:33:29 -0500 Subject: [PATCH] make the console toggleable at runtime instead of compilation time --- Makefile | 4 ++++ verbosity.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/Makefile b/Makefile index c6032882d2..29cf95fc3a 100644 --- a/Makefile +++ b/Makefile @@ -63,6 +63,10 @@ else OPTIMIZE_FLAG = -O3 -ffast-math endif +ifneq ($(findstring Win32,$(OS)),) + LDFLAGS += -mwindows +endif + CFLAGS += -Wall $(OPTIMIZE_FLAG) $(INCLUDE_DIRS) $(DEBUG_FLAG) -I. APPEND_CFLAGS := $(CFLAGS) diff --git a/verbosity.c b/verbosity.c index 5c1e397d8b..759bc5b4f1 100644 --- a/verbosity.c +++ b/verbosity.c @@ -26,6 +26,10 @@ #endif #endif +#ifdef _WIN32 +#include +#endif + #include #include @@ -50,11 +54,22 @@ static bool main_verbosity = false; void verbosity_enable(void) { main_verbosity = true; +#ifdef _WIN32 + AllocConsole(); + AttachConsole( GetCurrentProcessId()) ; + freopen( "CON", "w", stdout ); + freopen( "CON", "w", stderr ); +#endif } void verbosity_disable(void) { main_verbosity = false; +#ifdef _WIN32 + HWND wnd = GetConsoleWindow(); + FreeConsole(); + PostMessage(wnd, WM_CLOSE, 0, 0); +#endif } bool verbosity_is_enabled(void)