r3413 - in trunk/libmutil: source vs8_proj

erik at minisip.org erik at minisip.org
Fri Aug 31 10:32:26 CEST 2007


Author: erik
Date: 2007-08-31 10:32:25 +0200 (Fri, 31 Aug 2007)
New Revision: 3413

Modified:
   trunk/libmutil/source/TextUI.cxx
   trunk/libmutil/vs8_proj/libmutil.vcproj
Log:

 * Made the function that disables line buffering and auto-echoing 
   of characters work in W32 (the auto-build will show if it works 
   in MINGW32 - I believe _WIN32_WINNT needs to be defined to 0x0500 
   or higher).
 * Changed from getchar to ReadConsole to make the non-line-buffered
   input work.

Modified: trunk/libmutil/source/TextUI.cxx
===================================================================
--- trunk/libmutil/source/TextUI.cxx	2007-08-31 07:10:56 UTC (rev 3412)
+++ trunk/libmutil/source/TextUI.cxx	2007-08-31 08:32:25 UTC (rev 3413)
@@ -37,6 +37,7 @@
 
 #if defined WIN32 || defined _MSC_VER
 #include<conio.h>
+#include<Windows.h>
 #endif
 
 #ifdef _MSC_VER
@@ -111,11 +112,25 @@
 	}
 	return 0;
 #else
-	//#ifdef WIN32
-	//#warning nonblockin_stdin unimplemented on Win32
-	//#endif
-	return -1;
+#if defined(WIN32) || defined(_MSC_VER)
+	HANDLE console = GetStdHandle(STD_INPUT_HANDLE);
+	if (!console){
+		merr << "Error: could not get input handle"<<endl;
+		return -1;
+	}
+	DWORD oldMode;
+	if (!GetConsoleMode(console, &oldMode)){
+		merr << "Error: could not get console mode"<<endl;
+		return -1;
+	}
+	DWORD mode = oldMode & ~ENABLE_LINE_INPUT & ~ENABLE_ECHO_INPUT;
+	if (!SetConsoleMode(console, mode)){
+		cerr << "Error: could not set console mode"<<endl;
+		return -1;
+	}
+	return 0;
 #endif
+#endif
 }
 
 /**
@@ -131,10 +146,28 @@
 			merror("tcsetattr");
 		}
 	}
-#endif	
+#else
+#if defined(WIN32) || defined(_MSC_VER) 
+	HANDLE console = GetStdHandle(STD_INPUT_HANDLE);
+	if (!console){
+		cerr << "Error: could get console handle"<<endl;
+		return;
+	}
+	DWORD oldMode;
+	if (!GetConsoleMode(console, &oldMode)){
+		cerr << "Error: could get console mode"<<endl;
+		return;
+	}
+	DWORD mode = oldMode | ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT;
+	if (!SetConsoleMode(console, mode)){
+		cerr << "Error: could not restore console mode"<<endl;
+	}
+#endif
+#endif
 }
 
 TextUI::TextUI() : maxHints(2000),isAskingDialogQuestion(false){
+
 #ifdef HAVE_TERMIOS_H
 	terminalSavedState = new struct termios;
 #else
@@ -246,7 +279,11 @@
 	int ret;
 	char tmpc;
 #if defined WIN32 || defined _MSC_VER
-	tmpc = getchar();
+//	tmpc = getchar();
+	int n;
+	if (!ReadConsole(GetStdHandle(STD_INPUT_HANDLE),&tmpc,1,(LPDWORD)&n, NULL)){
+		cerr << "Console Error: error reading from stdin"<<endl;
+	}	
 	err=1;
 #else
 	err = read(STDIN_FILENO, &tmpc, 1);
@@ -260,8 +297,10 @@
 	if (tmpc==27){
 		char c1,c2;
 #if defined WIN32 || defined _MSC_VER
-		c1 = getchar();
-		c2 = getchar();
+		//c1 = getchar();
+		ReadConsole(GetStdHandle(STD_INPUT_HANDLE),&c1,1,(LPDWORD)&n, NULL);
+		//c2 = getchar();
+		ReadConsole(GetStdHandle(STD_INPUT_HANDLE),&c2,1,(LPDWORD)&n, NULL);
 		err=1;
 #else
 		read(STDIN_FILENO, &c1, 1);

Modified: trunk/libmutil/vs8_proj/libmutil.vcproj
===================================================================
--- trunk/libmutil/vs8_proj/libmutil.vcproj	2007-08-31 07:10:56 UTC (rev 3412)
+++ trunk/libmutil/vs8_proj/libmutil.vcproj	2007-08-31 08:32:25 UTC (rev 3413)
@@ -4,6 +4,7 @@
 	Version="8.00"
 	Name="libmutil"
 	ProjectGUID="{1F34E60F-605C-4CB8-AE65-5B6A829A5471}"
+	RootNamespace="libmutil"
 	Keyword="Win32Proj"
 	>
 	<Platforms>
@@ -39,7 +40,7 @@
 				Name="VCCLCompilerTool"
 				Optimization="0"
 				AdditionalIncludeDirectories="../include"
-				PreprocessorDefinitions="LIBMUTIL_EXPORTS;DEBUG_OUTPUT"
+				PreprocessorDefinitions="LIBMUTIL_EXPORTS;_WIN32_WINNT=0x0500"
 				MinimalRebuild="true"
 				BasicRuntimeChecks="3"
 				RuntimeLibrary="3"
@@ -113,7 +114,7 @@
 			<Tool
 				Name="VCCLCompilerTool"
 				AdditionalIncludeDirectories="../include"
-				PreprocessorDefinitions="LIBMUTIL_EXPORTS"
+				PreprocessorDefinitions="LIBMUTIL_EXPORTS;_WIN32_WINNT=0x0500"
 				RuntimeLibrary="2"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"



More information about the Minisip-devel mailing list