[ros-diffs] [janderwald] 24586: - avoid using _tprintf - use EnvironmentVariable as a singleton

janderwald at svn.reactos.org janderwald at svn.reactos.org
Fri Oct 20 22:09:30 CEST 2006


Author: janderwald
Date: Sat Oct 21 00:09:29 2006
New Revision: 24586

URL: http://svn.reactos.org/svn/reactos?rev=24586&view=rev
Log:
- avoid using _tprintf 
- use EnvironmentVariable as a singleton

Modified:
    trunk/reactos/tools/sysreg/conf_parser.cpp
    trunk/reactos/tools/sysreg/conf_parser.h
    trunk/reactos/tools/sysreg/env_var.cpp
    trunk/reactos/tools/sysreg/env_var.h
    trunk/reactos/tools/sysreg/pipe_reader.cpp
    trunk/reactos/tools/sysreg/rosboot_test.cpp
    trunk/reactos/tools/sysreg/sym_file.cpp
    trunk/reactos/tools/sysreg/sysreg.cpp

Modified: trunk/reactos/tools/sysreg/conf_parser.cpp
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/conf_parser.cpp?rev=24586&r1=24585&r2=24586&view=diff
==============================================================================
--- trunk/reactos/tools/sysreg/conf_parser.cpp (original)
+++ trunk/reactos/tools/sysreg/conf_parser.cpp Sat Oct 21 00:09:29 2006
@@ -14,9 +14,20 @@
 
 namespace Sysreg_
 {
-	using std::cout;
+#ifdef UNICODE
+
+	using std::wcerr;
+	using std::endl;
+
+#define cerr wcerr
+
+#else
+
 	using std::cerr;
 	using std::endl;
+
+#endif
+
 	using std::ifstream;
 //---------------------------------------------------------------------------------------
 	ConfigParser::ConfigParser()
@@ -84,9 +95,7 @@
 		ConfigMap::iterator it = m_Map.find (ConfVariable);
 		if (it == m_Map.end ())
 		{
-#ifdef NDEBUG
 			cerr << "ConfigParser::getValue failed to find " << ConfVariable << endl;
-#endif
 			return false;
 		}
 		

Modified: trunk/reactos/tools/sysreg/conf_parser.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/conf_parser.h?rev=24586&r1=24585&r2=24586&view=diff
==============================================================================
--- trunk/reactos/tools/sysreg/conf_parser.h (original)
+++ trunk/reactos/tools/sysreg/conf_parser.h Sat Oct 21 00:09:29 2006
@@ -18,6 +18,7 @@
 namespace Sysreg_
 {
 	using std::map;
+	using std::wstring;
 //---------------------------------------------------------------------------------------
 ///
 /// class ConfigParser
@@ -34,6 +35,7 @@
 	class ConfigParser
 	{
 	public:
+
 	typedef std::basic_string<TCHAR> string;
 	typedef std::basic_istringstream<TCHAR> istringstream;
 	typedef map<string, string> ConfigMap;

Modified: trunk/reactos/tools/sysreg/env_var.cpp
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/env_var.cpp?rev=24586&r1=24585&r2=24586&view=diff
==============================================================================
--- trunk/reactos/tools/sysreg/env_var.cpp (original)
+++ trunk/reactos/tools/sysreg/env_var.cpp Sat Oct 21 00:09:29 2006
@@ -13,9 +13,22 @@
 
 namespace System_
 {
-	using std::cout;
+#ifdef UNICODE
+
+	using std::wcerr;
 	using std::endl;
+
+#define cerr wcerr
+
+#else
+
 	using std::cerr;
+	using std::endl;
+
+#endif
+
+
+	EnvironmentVariable::EnvironmentMap EnvironmentVariable::m_Map;
 
 //---------------------------------------------------------------------------------------
 	EnvironmentVariable::EnvironmentVariable() 
@@ -44,17 +57,13 @@
 		
 		if (!value)
 		{
-#ifdef NDEBUG
 			cerr << "EnvironmentVariable::getValue found no value for " << EnvName << endl;
-#endif
 			return false;
 		}
 
 		if (!_tcslen(value))
 		{
-#ifdef NDEBUG
 			cerr << "EnvironmentVariable::getValue found no value for " << EnvName << endl;
-#endif
 			return false;
 		}
 

Modified: trunk/reactos/tools/sysreg/env_var.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/env_var.h?rev=24586&r1=24585&r2=24586&view=diff
==============================================================================
--- trunk/reactos/tools/sysreg/env_var.h (original)
+++ trunk/reactos/tools/sysreg/env_var.h Sat Oct 21 00:09:29 2006
@@ -28,16 +28,8 @@
 
 	class EnvironmentVariable
 	{
-	typedef map<string, string> EnvironmentMap;
 	public:
-//---------------------------------------------------------------------------------------
-///
-/// EnvironmentVariable
-///
-/// Description: constructor of class EnvironmentVariable
-
-		EnvironmentVariable();
-
+		typedef map<string, string> EnvironmentMap;
 //---------------------------------------------------------------------------------------
 ///
 /// ~EnvironmentVariable
@@ -58,11 +50,20 @@
 /// @param EnvValue value of the environment variable
 /// @return bool
 
-		bool getValue(const string & EnvName, string & EnvValue);
+		static bool getValue(const string & EnvName, string & EnvValue);
 
 
 	protected:
-		EnvironmentMap m_Map;
+
+//---------------------------------------------------------------------------------------
+///
+/// EnvironmentVariable
+///
+/// Description: constructor of class EnvironmentVariable
+
+		EnvironmentVariable();
+
+		static EnvironmentMap m_Map;
 
 	}; // end of class EnvironmentVariable
 

Modified: trunk/reactos/tools/sysreg/pipe_reader.cpp
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/pipe_reader.cpp?rev=24586&r1=24585&r2=24586&view=diff
==============================================================================
--- trunk/reactos/tools/sysreg/pipe_reader.cpp (original)
+++ trunk/reactos/tools/sysreg/pipe_reader.cpp Sat Oct 21 00:09:29 2006
@@ -14,9 +14,19 @@
 
 namespace System_
 {
-	using std::cout;
+#ifdef UNICODE
+
+	using std::wcerr;
 	using std::endl;
+
+#define cerr wcerr
+
+#else
+
 	using std::cerr;
+	using std::endl;
+
+#endif
 
 //---------------------------------------------------------------------------------------
 	PipeReader::PipeReader() : m_File(NULL)
@@ -36,24 +46,18 @@
 	{
 		if (m_File != NULL)
 		{
-#ifdef NDEBUG			
 			cerr << "PipeReader::openPipe> pipe already open" << endl;
-#endif
 			return false;
 		}
 		// 
 		m_File = _tpopen(PipeCmd.c_str(), AccessMode.c_str());
 		if (m_File)
 		{
-#ifdef NDEBUG
 			cerr << "PipeReader::openPipe> successfully opened pipe" << endl;
-#endif
 			return true;
 		}
 
-#ifdef NDEBUG
 		cerr << "PipeReader::openPipe> failed to open pipe " << PipeCmd << endl;
-#endif
 		return false;
 	}
 
@@ -63,9 +67,7 @@
 	{
 		if (!m_File)
 		{
-#ifdef NDEBUG
 			cerr << "PipeReader::closePipe> pipe is not open" << endl;
-#endif
 			return false;
 		}
 
@@ -73,9 +75,7 @@
 		
 		if (res == UINT_MAX)
 		{
-#ifdef NDEBUG
 			cerr << "Error: _pclose failed " <<endl;
-#endif
 			return false;
 		}
 
@@ -105,16 +105,9 @@
 		TCHAR * res = _fgetts(buf, size, m_File);
 		if (!res)
 		{
-#ifdef NDEBUG
 			cerr << "Error: PipeReader::readPipe failed" << endl;
-#endif
 			return 0;
 		}
-
-#ifdef NDEBUG
-		cerr << "PipeReader::readPipe> res: " << Buffer << endl;
-#endif
-
 		return _tcslen(buf);
 	}
 

Modified: trunk/reactos/tools/sysreg/rosboot_test.cpp
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/rosboot_test.cpp?rev=24586&r1=24585&r2=24586&view=diff
==============================================================================
--- trunk/reactos/tools/sysreg/rosboot_test.cpp (original)
+++ trunk/reactos/tools/sysreg/rosboot_test.cpp Sat Oct 21 00:09:29 2006
@@ -16,9 +16,20 @@
 
 namespace Sysreg_
 {
-	using std::cout;
+#ifdef UNICODE
+
+	using std::wcerr;
 	using std::endl;
+
+#define cerr wcerr
+
+#else
+
 	using std::cerr;
+	using std::endl;
+
+#endif
+
 
 	using System_::PipeReader;
 
@@ -72,7 +83,8 @@
 		}
 		else
 		{
-			_tprintf(_T("Error: unknown debug port %s Currently only file|pipe is supported\n"), debug_port);
+			cerr <<"Error: unknown debug port " << debug_port <<endl
+				<<" Currently only file|pipe is supported" <<endl;
 			return false;
 		}
 
@@ -90,7 +102,7 @@
 		/// TBD the information needs to be written into an provided log object
 		/// which writes the info into HTML/log / sends etc ....
 
-		_tprintf(debug_data.c_str ());
+		cerr << debug_data << endl;
 		return true;
 
 	}
@@ -102,7 +114,7 @@
 
 		if (!pipe_reader.openPipe(boot_cmd, string(_T("rt"))))
 		{
-			_tprintf(_T("Error: failed to open pipe with cmd: %s\n"), boot_cmd.c_str ());
+			cerr << "Error: failed to open pipe with cmd: " << boot_cmd <<endl;
 			return false;
 		}
 		string Buffer;
@@ -130,13 +142,13 @@
 
 		if (!pipe_reader.openPipe(boot_cmd, string(_T("rt"))))
 		{
-			_tprintf(_T("Error: failed to open pipe with cmd: %s\n"), boot_cmd.c_str ());
+			cerr << "Error: failed to open pipe with cmd: " << boot_cmd << endl;
 			return false;
 		}
 		FILE * file = _tfopen(debug_log.c_str (), _T("rt"));
 		if (!file)
 		{
-			_tprintf(_T("Error: failed to open debug log %s\n", debug_log.c_str ()));
+			cerr << "Error: failed to open debug log " << debug_log << endl;
 			pipe_reader.closePipe ();
 			return false;
 		}
@@ -156,6 +168,7 @@
 		}while(!pipe_reader.isEof ());
 
 		pipe_reader.closePipe ();		
+		return true;
 	}
 
 } // end of namespace Sysreg_

Modified: trunk/reactos/tools/sysreg/sym_file.cpp
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/sym_file.cpp?rev=24586&r1=24585&r2=24586&view=diff
==============================================================================
--- trunk/reactos/tools/sysreg/sym_file.cpp (original)
+++ trunk/reactos/tools/sysreg/sym_file.cpp Sat Oct 21 00:09:29 2006
@@ -25,9 +25,22 @@
 
 namespace System_
 {
-	using std::cout;
+
+#ifdef UNICODE
+
+	using std::wcerr;
 	using std::endl;
+
+#define cerr wcerr
+
+#else
+
 	using std::cerr;
+	using std::endl;
+
+#endif
+
+
 	using std::vector;
 
 	string SymbolFile::VAR_ROS_OUTPUT = _T("ROS_OUTPUT");
@@ -52,13 +65,12 @@
 	bool SymbolFile::initialize(ConfigParser & conf_parser, const System_::string &Path) 
 	{
 		vector<string> vect;
-		EnvironmentVariable envvar;
 		string current_dir;
 
 		if (Path == _T(""))
 		{
 			current_dir = _T("output-i386");
-			envvar.getValue(SymbolFile::VAR_ROS_OUTPUT, current_dir);
+			EnvironmentVariable::getValue(SymbolFile::VAR_ROS_OUTPUT, current_dir);
 		}
 		else
 		{
@@ -101,6 +113,8 @@
 					string path = current_dir;
 					path.insert (path.length () -1, _T("\\"));
 					path.insert (path.length () -1, filename);
+					
+					cerr << "Module Name " << modulename << endl << "File Name " << filename << endl;
 
 					m_Map.insert(std::make_pair<string, string>(modulename, path));
 
@@ -168,7 +182,7 @@
 
 		if (!pipe_reader.openPipe (pipe_cmd))
 		{
-			_tprintf(_T("SymbolFile::resolveAddress> failed to open pipe %s"), pipe_cmd);
+			cerr << "SymbolFile::resolveAddress> failed to open pipe" <<pipe_cmd <<endl;
 			return false;
 		}
 
@@ -189,7 +203,7 @@
 
 		if (it == m_Map.end ())
 		{
-			_tprintf(_T("SymbolFile::resolveAddress> no symbol file found for module %s"), ModuleName.c_str());
+			cerr << "SymbolFile::resolveAddress> no symbol file found for module " << ModuleName << endl;
 			return false;
 		}
 

Modified: trunk/reactos/tools/sysreg/sysreg.cpp
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/sysreg/sysreg.cpp?rev=24586&r1=24585&r2=24586&view=diff
==============================================================================
--- trunk/reactos/tools/sysreg/sysreg.cpp (original)
+++ trunk/reactos/tools/sysreg/sysreg.cpp Sat Oct 21 00:09:29 2006
@@ -11,12 +11,24 @@
 
 #include "sysreg.h"
 
+#ifdef UNICODE
+
+	using std::wcerr;
+	using std::endl;
+	using std::wcout;
+
+#define cerr wcerr
+#define cout wcout
+
+#else
+
+	using std::cerr;
+	using std::endl;
+
+#endif
+
 
 typedef std::basic_string<TCHAR> string;
-
-using std::cout;
-using std::endl;
-using std::cerr;
 
 
 using System_::EnvironmentVariable;
@@ -63,7 +75,7 @@
 	RegressionTest * regtest = comp_factory.createComponent (argv[2]);
 	if (!regtest)
 	{
-		_tprintf(_T("Error: the requested regression test does not exist"));
+		cerr << "Error: the requested regression test does not exist" << endl;
 		return -1;
 	}
 	
@@ -75,11 +87,11 @@
 
 	if (regtest->execute (config))
 	{
-		_tprintf(_T("The regression test %s completed successfully\n"), regtest->getName ().c_str ());
+		cout << "The regression test " << regtest->getName () << " completed successfully" << endl;
 	}
 	else
 	{
-		_tprintf(_T("The regression test %s failed\n"), regtest->getName ().c_str ());
+		cout << "The regression test " << regtest->getName () << "failed" << endl;
 	}
 
 	return 0;




More information about the Ros-diffs mailing list