# HG changeset patch # User thomas_-_s # Date 1303399140 0 # Node ID 431756c6e34265ef87571fa29eb699ba80b6bd39 # Parent f3631db173284e78f95eeaaee5a41ad022462cf8 Made the attachToConsole call be compiler and not system dependent. git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@1046 59b1889a-e5ac-428c-b0c7-476e01d41282 diff -r f3631db17328 -r 431756c6e342 src/main.cpp --- a/src/main.cpp Thu Apr 21 15:17:51 2011 +0000 +++ b/src/main.cpp Thu Apr 21 15:19:00 2011 +0000 @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006-2010 by Thomas Schweitzer * + * Copyright (C) 2006-2011 by Thomas Schweitzer * * thomas-schweitzer(at)arcor.de * * * * This program is free software; you can redistribute it and/or modify * @@ -37,7 +37,7 @@ #include #include -#ifdef WIN32 +#ifdef _MSC_VER #include #include @@ -78,29 +78,41 @@ // Redirect unbuffered STDOUT to the console. lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); - fp = _fdopen( hConHandle, "w" ); - *stdout = *fp; - setvbuf( stdout, NULL, _IONBF, 0 ); + if ( hConHandle != -1 ) { + fp = _fdopen( hConHandle, "w" ); + *stdout = *fp; + setvbuf( stdout, NULL, _IONBF, 0 ); + } // Redirect unbuffered STDIN to the console. lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); - fp = _fdopen( hConHandle, "r" ); - *stdin = *fp; - setvbuf( stdin, NULL, _IONBF, 0 ); + if ( hConHandle != -1 ) { + fp = _fdopen( hConHandle, "r" ); + *stdin = *fp; + setvbuf( stdin, NULL, _IONBF, 0 ); + } // Redirect unbuffered STDERR to the console. lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE); hConHandle = _open_osfhandle(lStdHandle, _O_TEXT); - fp = _fdopen( hConHandle, "w" ); - *stderr = *fp; - setvbuf( stderr, NULL, _IONBF, 0 ); + if ( hConHandle != -1 ) { + fp = _fdopen( hConHandle, "w" ); + *stderr = *fp; + setvbuf( stderr, NULL, _IONBF, 0 ); + } // Make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog point to console as well. std::ios::sync_with_stdio(); return true; } +#else +bool attachToConsole() +{ + return false; +} + #endif using namespace tschweitzer::debugging; @@ -124,10 +136,8 @@ bool tclapExitExceptionThrown = false; int returnValue = 0; -#ifdef WIN32 bool attachedToConsole = false; attachedToConsole = attachToConsole(); -#endif #ifdef __APPLE__ // Filter out -psn_0_118813 and similar parameters. @@ -194,7 +204,7 @@ } if ( returnValue != 0 || tclapExitExceptionThrown ) { -#ifdef WIN32 +#ifdef _MSC_VER if ( attachedToConsole ) { // Workaround for skipped command line prompt: Get the current working directory and print it to console. char* buffer;