changeset 769:431756c6e342

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
author thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
date Thu, 21 Apr 2011 15:19:00 +0000
parents f3631db17328
children 01f01ab124a1
files src/main.cpp
diffstat 1 files changed, 24 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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 <algorithm>
 #include <tclap/CmdLine.h>
 
-#ifdef WIN32
+#ifdef _MSC_VER
 
 #include <windows.h>
 #include <direct.h>
@@ -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;