Commit 7ee09b81 authored by Martin Schultz's avatar Martin Schultz

use macro during console creation on windows

parent ceb7fc99
......@@ -111,62 +111,42 @@
#ifdef WIN32
#define CONNECT_CONSOLE \
FILE* check = freopen("CONIN$", "r", stdin); \
if (check) { \
std::cerr << "Error reopening stdin" << std::endl; \
} \
check = freopen("CONOUT$", "w", stdout); \
if (check) { \
std::cerr << "Error reopening stdout" << std::endl; \
} \
check = freopen("CONOUT$", "w", stderr); \
if (check) { \
std::cerr << "Error reopening stderr" << std::endl; \
}
void attachConsole()
{
//try to attach the console of the parent process
if (AttachConsole(-1))
{
//if the console was attached change stdinput and output
FILE* check = freopen("CONIN$", "r", stdin);
if (check) {
std::cerr << "Error reopening stdin" << std::endl;
}
check = freopen("CONOUT$", "w", stdout);
if (check) {
std::cerr << "Error reopening stdout" << std::endl;
}
check = freopen("CONOUT$", "w", stderr);
if (check) {
std::cerr << "Error reopening stderr" << std::endl;
}
CONNECT_CONSOLE
}
else
{
//create and attach a new console if needed
#ifndef NDEBUG
//always open a console in debug mode
AllocConsole();
AllocConsole();
CONNECT_CONSOLE
FILE* check = freopen("CONIN$", "r", stdin);
if (check) {
std::cerr << "Error reopening stdin" << std::endl;
}
check = freopen("CONOUT$", "w", stdout);
if (check) {
std::cerr << "Error reopening stdout" << std::endl;
}
check = freopen("CONOUT$", "w", stderr);
if (check) {
std::cerr << "Error reopening stderr" << std::endl;
}
return;
#endif
if (OpenFlipper::Options::logToConsole())
{
AllocConsole();
FILE* check = freopen("CONIN$", "r", stdin);
if (check) {
std::cerr << "Error reopening stdin" << std::endl;
}
check = freopen("CONOUT$", "w", stdout);
if (check) {
std::cerr << "Error reopening stdout" << std::endl;
}
check = freopen("CONOUT$", "w", stderr);
if (check) {
std::cerr << "Error reopening stderr" << std::endl;
}
CONNECT_CONSOLE
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment