make the console toggleable at runtime instead of compilation time

This commit is contained in:
radius 2016-10-08 15:33:29 -05:00
parent 5f5571e241
commit 9272355696
2 changed files with 19 additions and 0 deletions

View File

@ -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)

View File

@ -26,6 +26,10 @@
#endif
#endif
#ifdef _WIN32
#include <windows.h>
#endif
#include <stdio.h>
#include <stdarg.h>
@ -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)