diff options
author | Jose <jose@zeroc.com> | 2017-01-09 17:01:31 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2017-01-09 17:01:31 +0100 |
commit | d4ed7973f1824478477be29989fc125b04207494 (patch) | |
tree | ec488f46a0ee15f987a0a24c87d1fe0a999cc168 /cpp/src | |
parent | IceSSL C#/Java test fixes to sync with C++ changes (diff) | |
download | ice-d4ed7973f1824478477be29989fc125b04207494.tar.bz2 ice-d4ed7973f1824478477be29989fc125b04207494.tar.xz ice-d4ed7973f1824478477be29989fc125b04207494.zip |
Fixed (ICE-6694) - Unicode output in command line tools
Diffstat (limited to 'cpp/src')
60 files changed, 974 insertions, 970 deletions
diff --git a/cpp/src/Glacier2/Glacier2Router.cpp b/cpp/src/Glacier2/Glacier2Router.cpp index 75d138b2868..695579d16e7 100644 --- a/cpp/src/Glacier2/Glacier2Router.cpp +++ b/cpp/src/Glacier2/Glacier2Router.cpp @@ -10,6 +10,7 @@ #include <Ice/UUID.h> #include <IceUtil/Options.h> #include <IceUtil/FileUtil.h> +#include <Ice/ConsoleUtil.h> #include <Ice/Service.h> #include <Glacier2/Instance.h> #include <Glacier2/RouterI.h> @@ -20,6 +21,7 @@ using namespace std; using namespace Ice; using namespace Glacier2; +using namespace IceInternal; namespace { @@ -40,7 +42,7 @@ private: void usage(const std::string&); - InstancePtr _instance; + Glacier2::InstancePtr _instance; SessionRouterIPtr _sessionRouter; }; @@ -108,7 +110,7 @@ RouterService::start(int argc, char* argv[], int& status) if(!args.empty()) { - cerr << argv[0] << ": too many arguments" << endl; + consoleErr << argv[0] << ": too many arguments" << endl; usage(argv[0]); return false; } @@ -341,7 +343,7 @@ RouterService::start(int argc, char* argv[], int& status) // try { - _instance = new Instance(communicator(), clientAdapter, serverAdapter); + _instance = new Glacier2::Instance(communicator(), clientAdapter, serverAdapter); } catch(const Ice::InitializationException& ex) { diff --git a/cpp/src/Glacier2/ProxyVerifier.cpp b/cpp/src/Glacier2/ProxyVerifier.cpp index cd3a2ecbaba..8acc0bea7b0 100644 --- a/cpp/src/Glacier2/ProxyVerifier.cpp +++ b/cpp/src/Glacier2/ProxyVerifier.cpp @@ -8,12 +8,14 @@ // ********************************************************************** #include <Glacier2/ProxyVerifier.h> +#include <Ice/ConsoleUtil.h> #include <vector> #include <string> using namespace std; using namespace Ice; +using namespace IceInternal; // // TODO: Some of the address matching helper classes can probably be @@ -600,16 +602,16 @@ public: void dump() const { - cerr << "address("; + consoleErr << "address("; for(vector<AddressMatcher*>::const_iterator i = _addressRules.begin(); i != _addressRules.end(); ++i) { - cerr << (*i)->toString() << " "; + consoleErr << (*i)->toString() << " "; } if(_portMatcher != 0) { - cerr << "):port(" << _portMatcher->toString() << " "; + consoleErr << "):port(" << _portMatcher->toString() << " "; } - cerr << ")" << endl; + consoleErr << ")" << endl; } private: diff --git a/cpp/src/Ice/EndpointFactoryManager.cpp b/cpp/src/Ice/EndpointFactoryManager.cpp index 14a78b50d59..d69f5e2ff82 100644 --- a/cpp/src/Ice/EndpointFactoryManager.cpp +++ b/cpp/src/Ice/EndpointFactoryManager.cpp @@ -129,8 +129,8 @@ IceInternal::EndpointFactoryManager::create(const string& str, bool oaEndpoint) short type; bs.read(type); EndpointIPtr ue = new IceInternal::OpaqueEndpointI(type, &bs); - cerr << "Normal: " << e->toString() << endl; - cerr << "Opaque: " << ue->toString() << endl; + consoleErr << "Normal: " << e->toString() << endl; + consoleErr << "Opaque: " << ue->toString() << endl; return e; #endif } diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index 7fe278d78ad..105f6b0bd39 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -43,6 +43,7 @@ #include <Ice/RegisterPluginsInit.h> #include <Ice/ObserverHelper.h> #include <Ice/Functional.h> +#include <Ice/ConsoleUtil.h> #include <IceUtil/DisableWarnings.h> #include <IceUtil/FileUtil.h> @@ -141,16 +142,16 @@ public: if(notDestroyedCount > 0) { - cerr << "!! " << IceUtil::Time::now().toDateTime() << " error: "; + consoleErr << "!! " << IceUtil::Time::now().toDateTime() << " error: "; if(notDestroyedCount == 1) { - cerr << "communicator "; + consoleErr << "communicator "; } else { - cerr << notDestroyedCount << " communicators "; + consoleErr << notDestroyedCount << " communicators "; } - cerr << "not destroyed during global destruction."; + consoleErr << "not destroyed during global destruction."; } delete instanceList; @@ -1521,9 +1522,9 @@ IceInternal::Instance::finishSetup(int& argc, char* argv[], const Ice::Communica if(printProcessId) { #ifdef _MSC_VER - cout << GetCurrentProcessId() << endl; + consoleOut << GetCurrentProcessId() << endl; #else - cout << getpid() << endl; + consoleOut << getpid() << endl; #endif } @@ -1930,12 +1931,12 @@ IceInternal::ProcessI::writeMessage(const string& message, Int fd, const Current { case 1: { - cout << message << endl; + consoleOut << message << endl; break; } case 2: { - cerr << message << endl; + consoleErr << message << endl; break; } } diff --git a/cpp/src/Ice/LoggerI.cpp b/cpp/src/Ice/LoggerI.cpp index 5ebf7c460cd..a03c911471f 100644 --- a/cpp/src/Ice/LoggerI.cpp +++ b/cpp/src/Ice/LoggerI.cpp @@ -19,6 +19,7 @@ using namespace std; using namespace Ice; using namespace IceInternal; +using namespace IceUtilInternal; namespace { @@ -57,9 +58,6 @@ Ice::LoggerI::LoggerI(const string& prefix, const string& file, _convert(convert), _converter(getProcessStringConverter()), _sizeMax(sizeMax) -#if defined(_WIN32) && !defined(ICE_OS_UWP) - ,_consoleConverter(createWindowsStringConverter(GetConsoleOutputCP())) -#endif { if(!prefix.empty()) { @@ -253,31 +251,7 @@ Ice::LoggerI::write(const string& message, bool indent) } else { - try - { - // Convert message to UTF-8 - string u8s = nativeToUTF8(s, _converter); - - // Then from UTF-8 to console CP - string consoleString; - _consoleConverter->fromUTF8(reinterpret_cast<const Byte*>(u8s.data()), - reinterpret_cast<const Byte*>(u8s.data() + u8s.size()), - consoleString); - - // We cannot use cerr here as writing to console using cerr - // will do its own conversion and will corrupt the messages. - // - fprintf_s(stderr, "%s\n", consoleString.c_str()); - } - catch(const IceUtil::IllegalConversionException&) - { - // - // If there is a problem with the encoding conversions we just - // write the original message without encoding conversions. - // - fprintf_s(stderr, "%s\n", s.c_str()); - } - fflush(stderr); + consoleErr << s << endl; } #else cerr << s << endl; diff --git a/cpp/src/Ice/LoggerI.h b/cpp/src/Ice/LoggerI.h index 577e868818d..70a3897a86a 100644 --- a/cpp/src/Ice/LoggerI.h +++ b/cpp/src/Ice/LoggerI.h @@ -49,10 +49,6 @@ private: // after which rename could be attempted again. Otherwise is set to zero. // IceUtil::Time _nextRetry; -#if defined(_WIN32) && !defined(ICE_OS_UWP) - const StringConverterPtr _consoleConverter; -#endif - }; ICE_DEFINE_PTR(LoggerIPtr, LoggerI); diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp index 22c8ea8d380..df7b4a81a77 100644 --- a/cpp/src/Ice/ObjectAdapterI.cpp +++ b/cpp/src/Ice/ObjectAdapterI.cpp @@ -31,6 +31,7 @@ #include <Ice/DefaultsAndOverrides.h> #include <Ice/TraceLevels.h> #include <Ice/PropertyNames.h> +#include <Ice/ConsoleUtil.h> #ifdef _WIN32 # include <sys/timeb.h> @@ -149,7 +150,7 @@ Ice::ObjectAdapterI::activate() if(printAdapterReady) { - cout << _name << " ready" << endl; + consoleOut << _name << " ready" << endl; } { diff --git a/cpp/src/Ice/Service.cpp b/cpp/src/Ice/Service.cpp index afccbfe7ead..ebbfe4e45c5 100644 --- a/cpp/src/Ice/Service.cpp +++ b/cpp/src/Ice/Service.cpp @@ -14,6 +14,7 @@ #include <IceUtil/Mutex.h> #include <IceUtil/ArgVector.h> #include <IceUtil/FileUtil.h> +#include <Ice/ConsoleUtil.h> #include <Ice/StringConverter.h> #include <Ice/Service.h> #include <Ice/LoggerI.h> @@ -37,6 +38,7 @@ using namespace std; using namespace Ice; +using namespace IceInternal; Ice::Service* Ice::Service::_instance = 0; static IceUtil::CtrlCHandler* _ctrlCHandler = 0; @@ -660,9 +662,9 @@ Ice::Service::main(int& argc, char* argv[], const InitializationData& initializa { if(argv[0]) { - cerr << argv[0] << ": "; + consoleErr << argv[0] << ": "; } - cerr << "--pidfile must be followed by an argument" << endl; + consoleErr << "--pidfile must be followed by an argument" << endl; return EXIT_FAILURE; } @@ -682,9 +684,9 @@ Ice::Service::main(int& argc, char* argv[], const InitializationData& initializa { if(argv[0]) { - cerr << argv[0] << ": "; + consoleErr << argv[0] << ": "; } - cerr << "--noclose must be used with --daemon" << endl; + consoleErr << "--noclose must be used with --daemon" << endl; return EXIT_FAILURE; } @@ -692,9 +694,9 @@ Ice::Service::main(int& argc, char* argv[], const InitializationData& initializa { if(argv[0]) { - cerr << argv[0] << ": "; + consoleErr << argv[0] << ": "; } - cerr << "--pidfile <file> must be used with --daemon" << endl; + consoleErr << "--pidfile <file> must be used with --daemon" << endl; return EXIT_FAILURE; } @@ -983,15 +985,15 @@ Ice::Service::syserror(const string& msg) { if(!_name.empty()) { - cerr << _name << ": "; + consoleErr << _name << ": "; } if(!msg.empty()) { - cerr << msg << endl; + consoleErr << msg << endl; } if(!errmsg.empty()) { - cerr << errmsg; + consoleErr << errmsg; } } } @@ -1007,9 +1009,9 @@ Ice::Service::error(const string& msg) { if(!_name.empty()) { - cerr << _name << ": "; + consoleErr << _name << ": "; } - cerr << "error: " << msg << endl; + consoleErr << "error: " << msg << endl; } } @@ -1024,9 +1026,9 @@ Ice::Service::warning(const string& msg) { if(!_name.empty()) { - cerr << _name << ": "; + consoleErr << _name << ": "; } - cerr << "warning: " << msg << endl; + consoleErr << "warning: " << msg << endl; } } @@ -1039,7 +1041,7 @@ Ice::Service::trace(const string& msg) } else { - cerr << msg << endl; + consoleErr << msg << endl; } } @@ -1052,7 +1054,7 @@ Ice::Service::print(const string& msg) } else { - cerr << msg << endl; + consoleErr << msg << endl; } } @@ -1532,9 +1534,9 @@ Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initDa { if(argv[0]) { - cerr << argv[0] << ": "; + consoleErr << argv[0] << ": "; } - cerr << strerror(errno) << endl; + consoleErr << strerror(errno) << endl; return EXIT_FAILURE; } @@ -1565,9 +1567,9 @@ Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initDa if(argv[0]) { - cerr << argv[0] << ": "; + consoleErr << argv[0] << ": "; } - cerr << strerror(errno) << endl; + consoleErr << strerror(errno) << endl; _exit(EXIT_FAILURE); } break; @@ -1592,9 +1594,9 @@ Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initDa if(argv[0]) { - cerr << ": "; + consoleErr << ": "; } - cerr << "I/O error while reading error message from child:\n" << strerror(errno) << endl; + consoleErr << "I/O error while reading error message from child:\n" << strerror(errno) << endl; _exit(EXIT_FAILURE); } pos += n; @@ -1602,14 +1604,14 @@ Ice::Service::runDaemon(int argc, char* argv[], const InitializationData& initDa } if(argv[0]) { - cerr << argv[0] << ": "; + consoleErr << argv[0] << ": "; } - cerr << "failure occurred in daemon"; + consoleErr << "failure occurred in daemon"; if(strlen(msg) > 0) { - cerr << ':' << endl << msg; + consoleErr << ':' << endl << msg; } - cerr << endl; + consoleErr << endl; _exit(EXIT_FAILURE); } diff --git a/cpp/src/Ice/Thread.cpp b/cpp/src/Ice/Thread.cpp index 80990aeb8ce..8938e288ac9 100644 --- a/cpp/src/Ice/Thread.cpp +++ b/cpp/src/Ice/Thread.cpp @@ -19,6 +19,7 @@ #include <IceUtil/Thread.h> #include <IceUtil/Time.h> #include <IceUtil/ThreadException.h> +#include <Ice/ConsoleUtil.h> #include <climits> #include <exception> @@ -32,6 +33,7 @@ #endif using namespace std; +using namespace IceInternal; #ifdef ICE_OS_UWP @@ -169,7 +171,7 @@ WINAPI startHook(void* arg) { if(!thread->name().empty()) { - cerr << thread->name() << " terminating" << endl; + consoleErr << thread->name() << " terminating" << endl; } std::terminate(); } @@ -404,7 +406,7 @@ WINAPI startHook(void* arg) { if(!thread->name().empty()) { - cerr << thread->name() << " terminating" << endl; + consoleErr << thread->name() << " terminating" << endl; } std::terminate(); } @@ -650,7 +652,7 @@ startHook(void* arg) { if(!thread->name().empty()) { - cerr << thread->name() << " terminating" << endl; + consoleErr << thread->name() << " terminating" << endl; } std::terminate(); } diff --git a/cpp/src/Ice/Timer.cpp b/cpp/src/Ice/Timer.cpp index c19ba12a92b..474e13a5778 100644 --- a/cpp/src/Ice/Timer.cpp +++ b/cpp/src/Ice/Timer.cpp @@ -9,9 +9,11 @@ #include <IceUtil/Timer.h> #include <IceUtil/Exception.h> +#include <Ice/ConsoleUtil.h> using namespace std; using namespace IceUtil; +using namespace IceInternal; TimerTask::~TimerTask() { @@ -231,19 +233,19 @@ Timer::run() } catch(const IceUtil::Exception& e) { - cerr << "IceUtil::Timer::run(): uncaught exception:\n" << e.what(); + consoleErr << "IceUtil::Timer::run(): uncaught exception:\n" << e.what(); #ifdef __GNUC__ - cerr << "\n" << e.ice_stackTrace(); + consoleErr << "\n" << e.ice_stackTrace(); #endif - cerr << endl; + consoleErr << endl; } catch(const std::exception& e) { - cerr << "IceUtil::Timer::run(): uncaught exception:\n" << e.what() << endl; + consoleErr << "IceUtil::Timer::run(): uncaught exception:\n" << e.what() << endl; } catch(...) { - cerr << "IceUtil::Timer::run(): uncaught exception" << endl; + consoleErr << "IceUtil::Timer::run(): uncaught exception" << endl; } } } diff --git a/cpp/src/Ice/WindowsStringConverter.cpp b/cpp/src/Ice/WindowsStringConverter.cpp deleted file mode 100644 index 6ecd6dd2490..00000000000 --- a/cpp/src/Ice/WindowsStringConverter.cpp +++ /dev/null @@ -1,148 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. -// -// This copy of Ice is licensed to you under the terms described in the -// ICE_LICENSE file included in this distribution. -// -// ********************************************************************** - -#include <Ice/StringConverter.h> - -#ifdef _WIN32 - -#include <IceUtil/StringUtil.h> - - -using namespace Ice; -using namespace std; - -namespace -{ -// -// Converts to/from UTF-8 using MultiByteToWideChar and WideCharToMultiByte -// -class WindowsStringConverter : public StringConverter -{ -public: - - explicit WindowsStringConverter(unsigned int); - - virtual Byte* toUTF8(const char*, const char*, UTF8Buffer&) const; - - virtual void fromUTF8(const Byte*, const Byte*, string& target) const; - -private: - unsigned int _cp; - WstringConverterPtr _unicodeConverter; - -}; - -WindowsStringConverter::WindowsStringConverter(unsigned int cp) : - _cp(cp), - _unicodeConverter(createUnicodeWstringConverter()) -{ -} - -Byte* -WindowsStringConverter::toUTF8(const char* sourceStart, const char* sourceEnd, UTF8Buffer& buffer) const -{ - // - // First convert to UTF-16 - // - int sourceSize = static_cast<int>(sourceEnd - sourceStart); - if(sourceSize == 0) - { - return buffer.getMoreBytes(1, 0); - } - - int writtenWchar = 0; - wstring wbuffer; - - // - // The following code pages doesn't support MB_ERR_INVALID_CHARS flag - // see http://msdn.microsoft.com/en-us/library/windows/desktop/dd319072(v=vs.85).aspx - // - DWORD flags = - (_cp == 50220 || _cp == 50221 || _cp == 50222 || - _cp == 50225 || _cp == 50227 || _cp == 50229 || - _cp == 65000 || _cp == 42 || (_cp >= 57002 && _cp <= 57011)) ? 0 : MB_ERR_INVALID_CHARS; - - do - { - wbuffer.resize(wbuffer.size() == 0 ? sourceSize + 2 : 2 * wbuffer.size()); - writtenWchar = MultiByteToWideChar(_cp, flags, sourceStart, sourceSize, - const_cast<wchar_t*>(wbuffer.data()), static_cast<int>(wbuffer.size())); - } while(writtenWchar == 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER); - - if(writtenWchar == 0) - { - throw IllegalConversionException(__FILE__, __LINE__, IceUtilInternal::lastErrorToString()); - } - - wbuffer.resize(static_cast<size_t>(writtenWchar)); - - // - // Then convert this UTF-16 wbuffer into UTF-8 - // - return _unicodeConverter->toUTF8(wbuffer.data(), wbuffer.data() + wbuffer.size(), buffer); -} - -void -WindowsStringConverter::fromUTF8(const Byte* sourceStart, const Byte* sourceEnd, string& target) const -{ - if(sourceStart == sourceEnd) - { - target = ""; - return; - } - - if(_cp == CP_UTF8) - { - string tmp(reinterpret_cast<const char*>(sourceStart), sourceEnd - sourceStart); - tmp.swap(target); - return; - } - - // - // First convert to wstring (UTF-16) - // - wstring wtarget; - _unicodeConverter->fromUTF8(sourceStart, sourceEnd, wtarget); - - // - // WC_ERR_INVALID_CHARS conversion flag is only supported with 65001 (UTF-8) and - // 54936 (GB18030 Simplified Chinese) - // - DWORD flags = (_cp == 65001 || _cp == 54936) ? WC_ERR_INVALID_CHARS : 0; - - // - // And then to a multi-byte narrow string - // - int writtenChar = -1; - do - { - target.resize(writtenChar == -1 ? - std::max<size_t>(sourceEnd - sourceStart + 2, target.size()) : - 2 * target.size()); - - writtenChar = WideCharToMultiByte(_cp, flags, wtarget.data(), static_cast<int>(wtarget.size()), - const_cast<char*>(target.data()), static_cast<int>(target.size()), - 0, 0); - } while(writtenChar == 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER); - - if(writtenChar == 0) - { - throw IllegalConversionException(__FILE__, __LINE__, IceUtilInternal::lastErrorToString()); - } - - target.resize(static_cast<size_t>(writtenChar)); -} -} - -StringConverterPtr -Ice::createWindowsStringConverter(unsigned int cp) -{ - return ICE_MAKE_SHARED(WindowsStringConverter, cp); -} -#endif diff --git a/cpp/src/Ice/msbuild/iceuwp++11/iceuwp++11.vcxproj b/cpp/src/Ice/msbuild/iceuwp++11/iceuwp++11.vcxproj index 8c7221d57e3..26930d7bc5a 100644 --- a/cpp/src/Ice/msbuild/iceuwp++11/iceuwp++11.vcxproj +++ b/cpp/src/Ice/msbuild/iceuwp++11/iceuwp++11.vcxproj @@ -147,7 +147,7 @@ <ClCompile Include="..\..\SHA1.cpp" /> <ClCompile Include="..\..\..\IceUtil\Shared.cpp" /> <ClCompile Include="..\..\..\IceUtil\StringConverter.cpp" /> - <ClCompile Include="..\..\WindowsStringConverter.cpp" /> + <ClCompile Include="..\..\..\IceUtil\ConsoleUtil.cpp" /> <ClCompile Include="..\..\..\IceUtil\StringUtil.cpp" /> <ClCompile Include="..\..\StreamSocket.cpp" /> <ClCompile Include="..\..\Thread.cpp" /> diff --git a/cpp/src/IceBox/Admin.cpp b/cpp/src/IceBox/Admin.cpp index 822f144dc5e..7d02add95c4 100644 --- a/cpp/src/IceBox/Admin.cpp +++ b/cpp/src/IceBox/Admin.cpp @@ -9,11 +9,13 @@ #include <Ice/Application.h> #include <Ice/SliceChecksums.h> +#include <Ice/ConsoleUtil.h> #include <IceUtil/Options.h> #include <IceBox/IceBox.h> using namespace std; using namespace Ice; +using namespace IceInternal; class Client : public Application { @@ -42,8 +44,8 @@ main(int argc, char* argv[]) void Client::usage() { - cerr << "Usage: " << appName() << " [options] [command...]\n"; - cerr << + consoleErr << "Usage: " << appName() << " [options] [command...]\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -69,7 +71,7 @@ Client::run(int argc, char* argv[]) } catch(const IceUtilInternal::BadOptException& e) { - cerr << e.reason << endl; + consoleErr << e.reason << endl; usage(); return EXIT_FAILURE; } @@ -81,7 +83,7 @@ Client::run(int argc, char* argv[]) } if(opts.isSet("version")) { - cout << ICE_STRING_VERSION << endl; + consoleOut << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -111,7 +113,7 @@ Client::run(int argc, char* argv[]) string managerEndpoints = properties->getProperty("IceBox.ServiceManager.Endpoints"); if(managerEndpoints.empty()) { - cerr << appName() << ": property `IceBoxAdmin.ServiceManager.Proxy' is not set" << endl; + consoleErr << appName() << ": property `IceBoxAdmin.ServiceManager.Proxy' is not set" << endl; return EXIT_FAILURE; } @@ -122,7 +124,7 @@ Client::run(int argc, char* argv[]) string managerAdapterId = properties->getProperty("IceBox.ServiceManager.AdapterId"); if(managerAdapterId.empty()) { - cerr << appName() << ": property `IceBoxAdmin.ServiceManager.Proxy' is not set" << endl; + consoleErr << appName() << ": property `IceBoxAdmin.ServiceManager.Proxy' is not set" << endl; return EXIT_FAILURE; } @@ -135,7 +137,7 @@ Client::run(int argc, char* argv[]) IceBox::ServiceManagerPrxPtr manager = ICE_CHECKED_CAST(IceBox::ServiceManagerPrx, base); if(!manager) { - cerr << appName() << ": `" << base << "' is not an IceBox::ServiceManager" << endl; + consoleErr << appName() << ": `" << base << "' is not an IceBox::ServiceManager" << endl; return EXIT_FAILURE; } @@ -146,11 +148,11 @@ Client::run(int argc, char* argv[]) Ice::SliceChecksumDict::const_iterator q = serverChecksums.find(p->first); if(q == serverChecksums.end()) { - cerr << appName() << ": server is using unknown Slice type `" << q->first << "'" << endl; + consoleErr << appName() << ": server is using unknown Slice type `" << q->first << "'" << endl; } else if(p->second != q->second) { - cerr << appName() << ": server is using a different Slice definition of `" << q->first << "'" << endl; + consoleErr << appName() << ": server is using a different Slice definition of `" << q->first << "'" << endl; } } @@ -164,7 +166,7 @@ Client::run(int argc, char* argv[]) { if(++r == commands.end()) { - cerr << appName() << ": no service name specified." << endl; + consoleErr << appName() << ": no service name specified." << endl; return EXIT_FAILURE; } @@ -174,19 +176,19 @@ Client::run(int argc, char* argv[]) } catch(const IceBox::NoSuchServiceException&) { - cerr << appName() << ": unknown service `" << *r << "'" << endl; + consoleErr << appName() << ": unknown service `" << *r << "'" << endl; return EXIT_FAILURE; } catch(const IceBox::AlreadyStartedException&) { - cerr << appName() << ": service already started." << endl; + consoleErr << appName() << ": service already started." << endl; } } else if((*r) == "stop") { if(++r == commands.end()) { - cerr << appName() << ": no service name specified." << endl; + consoleErr << appName() << ": no service name specified." << endl; return EXIT_FAILURE; } @@ -196,17 +198,17 @@ Client::run(int argc, char* argv[]) } catch(const IceBox::NoSuchServiceException&) { - cerr << appName() << ": unknown service `" << *r << "'" << endl; + consoleErr << appName() << ": unknown service `" << *r << "'" << endl; return EXIT_FAILURE; } catch(const IceBox::AlreadyStoppedException&) { - cerr << appName() << ": service already stopped." << endl; + consoleErr << appName() << ": service already stopped." << endl; } } else { - cerr << appName() << ": unknown command `" << *r << "'" << endl; + consoleErr << appName() << ": unknown command `" << *r << "'" << endl; usage(); return EXIT_FAILURE; } diff --git a/cpp/src/IceBox/ServiceManagerI.cpp b/cpp/src/IceBox/ServiceManagerI.cpp index c767df5552f..fdae86be07f 100644 --- a/cpp/src/IceBox/ServiceManagerI.cpp +++ b/cpp/src/IceBox/ServiceManagerI.cpp @@ -10,6 +10,7 @@ #include <IceUtil/Options.h> #include <IceUtil/StringUtil.h> #include <Ice/Ice.h> +#include <Ice/ConsoleUtil.h> #include <Ice/DynamicLibrary.h> #include <Ice/SliceChecksums.h> #include <Ice/Initialize.h> @@ -17,6 +18,7 @@ #include <IceBox/ServiceManagerI.h> using namespace Ice; +using namespace IceUtilInternal; using namespace IceBox; using namespace std; @@ -467,7 +469,7 @@ IceBox::ServiceManagerI::start() string bundleName = properties->getProperty("IceBox.PrintServicesReady"); if(!bundleName.empty()) { - cout << bundleName << " ready" << endl; + consoleOut << bundleName << " ready" << endl; } // diff --git a/cpp/src/IceGrid/Client.cpp b/cpp/src/IceGrid/Client.cpp index 8dafd14f4ed..06326032ea2 100644 --- a/cpp/src/IceGrid/Client.cpp +++ b/cpp/src/IceGrid/Client.cpp @@ -12,6 +12,7 @@ #include <IceUtil/CtrlCHandler.h> #include <IceUtil/Thread.h> #include <IceUtil/StringUtil.h> +#include <Ice/ConsoleUtil.h> #include <Ice/UUID.h> #include <IceUtil/Mutex.h> #include <IceUtil/MutexPtrLock.h> @@ -37,6 +38,7 @@ using namespace std; using namespace Ice; +using namespace IceInternal; using namespace IceLocatorDiscovery; using namespace IceGrid; @@ -277,8 +279,8 @@ main(int argc, char* argv[]) void Client::usage() { - cerr << "Usage: " << appName() << " [options]\n"; - cerr << + consoleErr << "Usage: " << appName() << " [options]\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -326,27 +328,27 @@ Client::main(StringSeq& args) } catch(const IceUtil::Exception& ex) { - cerr << _appName << ": " << ex << endl; + consoleErr << _appName << ": " << ex << endl; status = EXIT_FAILURE; } catch(const std::exception& ex) { - cerr << _appName << ": std::exception: " << ex.what() << endl; + consoleErr << _appName << ": std::exception: " << ex.what() << endl; status = EXIT_FAILURE; } catch(const std::string& msg) { - cerr << _appName << ": " << msg << endl; + consoleErr << _appName << ": " << msg << endl; status = EXIT_FAILURE; } catch(const char* msg) { - cerr << _appName << ": " << msg << endl; + consoleErr << _appName << ": " << msg << endl; status = EXIT_FAILURE; } catch(...) { - cerr << _appName << ": unknown exception" << endl; + consoleErr << _appName << ": unknown exception" << endl; status = EXIT_FAILURE; } @@ -361,7 +363,7 @@ Client::main(StringSeq& args) } catch(const Exception& ex) { - cerr << ex << endl; + consoleErr << ex << endl; status = EXIT_FAILURE; } } @@ -427,13 +429,13 @@ Client::run(StringSeq& originalArgs) } catch(const IceUtilInternal::BadOptException& e) { - cerr << e.reason << endl; + consoleErr << e.reason << endl; usage(); return EXIT_FAILURE; } if(!args.empty()) { - cerr << _appName << ": too many arguments" << endl; + consoleErr << _appName << ": too many arguments" << endl; usage(); return EXIT_FAILURE; } @@ -445,7 +447,7 @@ Client::run(StringSeq& originalArgs) } if(opts.isSet("version")) { - cout << ICE_STRING_VERSION << endl; + consoleOut << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -455,7 +457,7 @@ Client::run(StringSeq& originalArgs) communicator()->createObjectAdapterWithEndpoints("FileParser", "tcp -h localhost"); adapter->activate(); ObjectPrx proxy = adapter->add(new FileParserI, stringToIdentity("FileParser")); - cout << proxy << endl; + consoleOut << proxy << endl; communicator()->waitForShutdown(); return EXIT_SUCCESS; @@ -506,7 +508,7 @@ Client::run(StringSeq& originalArgs) istringstream is(opts.optArg("port")); if(!(is >> port)) { - cerr << _appName << ": given port number is not a numeric value" << endl; + consoleErr << _appName << ": given port number is not a numeric value" << endl; return EXIT_FAILURE; } } @@ -547,8 +549,8 @@ Client::run(StringSeq& originalArgs) if(!instanceName.empty() && communicator()->getDefaultLocator()->ice_getIdentity().category != instanceName) { - cerr << _appName << ": registry running on `" << host << "' uses a different instance name:\n"; - cerr << communicator()->getDefaultLocator()->ice_getIdentity().category << endl; + consoleErr << _appName << ": registry running on `" << host << "' uses a different instance name:\n"; + consoleErr << communicator()->getDefaultLocator()->ice_getIdentity().category << endl; return EXIT_FAILURE; } } @@ -616,7 +618,7 @@ Client::run(StringSeq& originalArgs) } catch(const Ice::LocalException& ex) { - cerr << _appName << ": registry discovery failed:\n" << ex << endl; + consoleErr << _appName << ": registry discovery failed:\n" << ex << endl; return EXIT_FAILURE; } adapter->destroy(); @@ -624,17 +626,17 @@ Client::run(StringSeq& originalArgs) vector<Ice::LocatorPrx> locators = reply->getLocators(); if(locators.size() > 1) { - cout << "found " << locators.size() << " Ice locators:" << endl; + consoleOut << "found " << locators.size() << " Ice locators:" << endl; unsigned int num = 0; for(vector<Ice::LocatorPrx>::const_iterator p = locators.begin(); p != locators.end(); ++p) { - cout << ++num << ": proxy = `" << *p << "'" <<endl; + consoleOut << ++num << ": proxy = `" << *p << "'" << endl; } num = 0; while(num == 0 && cin.good()) { - cout << "please enter the locator number to use: " << flush; + consoleOut << "please enter the locator number to use: " << flush; string line; getline(cin, line); if(!cin.good() || line.empty()) @@ -656,7 +658,7 @@ Client::run(StringSeq& originalArgs) } else if(locators.size() == 1) { - cout << "using discovered locator:\nproxy = `" << locators[0] << "'" << endl; + consoleOut << "using discovered locator:\nproxy = `" << locators[0] << "'" << endl; communicator()->setDefaultLocator(locators[0]); } } @@ -670,13 +672,13 @@ Client::run(StringSeq& originalArgs) router = Glacier2::RouterPrx::checkedCast(communicator()->getDefaultRouter()->ice_preferSecure(true)); if(!router) { - cerr << _appName << ": configured router is not a Glacier2 router" << endl; + consoleErr << _appName << ": configured router is not a Glacier2 router" << endl; return EXIT_FAILURE; } } catch(const LocalException& ex) { - cerr << _appName << ": could not contact the default router:" << endl << ex << endl; + consoleErr << _appName << ": could not contact the default router:" << endl << ex << endl; return EXIT_FAILURE; } @@ -685,7 +687,7 @@ Client::run(StringSeq& originalArgs) session = AdminSessionPrx::uncheckedCast(router->createSessionFromSecureConnection()); if(!session) { - cerr << _appName + consoleErr << _appName << ": Glacier2 returned a null session, please set the Glacier2.SSLSessionManager property" << endl; return EXIT_FAILURE; @@ -695,7 +697,7 @@ Client::run(StringSeq& originalArgs) { while(id.empty() && cin.good()) { - cout << "user id: " << flush; + consoleOut << "user id: " << flush; getline(cin, id); if(!cin.good()) { @@ -720,7 +722,7 @@ Client::run(StringSeq& originalArgs) if(!session) { - cerr << _appName + consoleErr << _appName << ": Glacier2 returned a null session, please set the Glacier2.SessionManager property" << endl; return EXIT_FAILURE; @@ -760,14 +762,14 @@ Client::run(StringSeq& originalArgs) locator = IceGrid::LocatorPrx::checkedCast(communicator()->getDefaultLocator()); if(!locator) { - cerr << _appName << ": configured locator is not an IceGrid locator" << endl; + consoleErr << _appName << ": configured locator is not an IceGrid locator" << endl; return EXIT_FAILURE; } localRegistry = locator->getLocalRegistry(); } catch(const LocalException& ex) { - cerr << _appName << ": could not contact the default locator:" << endl << ex << endl; + consoleErr << _appName << ": could not contact the default locator:" << endl << ex << endl; return EXIT_FAILURE; } @@ -787,20 +789,20 @@ Client::run(StringSeq& originalArgs) registry = RegistryPrx::checkedCast(locator->findObjectById(registryId)); if(!registry) { - cerr << _appName << ": could not contact an IceGrid registry" << endl; + consoleErr << _appName << ": could not contact an IceGrid registry" << endl; } } catch(const ObjectNotFoundException&) { - cerr << _appName << ": no active registry replica named `" << replica << "'" << endl; + consoleErr << _appName << ": no active registry replica named `" << replica << "'" << endl; return EXIT_FAILURE; } catch(const LocalException& ex) { if(!replica.empty()) { - cerr << _appName << ": could not contact the registry replica named `" << replica << "':\n"; - cerr << ex << endl; + consoleErr << _appName << ": could not contact the registry replica named `" << replica << "':\n"; + consoleErr << ex << endl; return EXIT_FAILURE; } else @@ -816,7 +818,7 @@ Client::run(StringSeq& originalArgs) { name = name.substr(prefix.size()); } - cerr << _appName << ": warning: could not contact master, using slave `" << name << "'" << endl; + consoleErr << _appName << ": warning: could not contact master, using slave `" << name << "'" << endl; } } } @@ -845,7 +847,7 @@ Client::run(StringSeq& originalArgs) { while(id.empty() && cin.good()) { - cout << "user id: " << flush; + consoleOut << "user id: " << flush; getline(cin, id); if(!cin.good()) { @@ -880,8 +882,8 @@ Client::run(StringSeq& originalArgs) } else // No default locator or router set. { - cerr << _appName << ": could not contact the registry:" << endl; - cerr << "no default locator or router configured" << endl; + consoleErr << _appName << ": could not contact the registry:" << endl; + consoleErr << "no default locator or router configured" << endl; return EXIT_FAILURE; } @@ -911,11 +913,11 @@ Client::run(StringSeq& originalArgs) SliceChecksumDict::const_iterator r = serverChecksums.find(q->first); if(r == serverChecksums.end()) { - cerr << appName() << ": server is using unknown Slice type `" << q->first << "'" << endl; + consoleErr << appName() << ": server is using unknown Slice type `" << q->first << "'" << endl; } else if(q->second != r->second) { - cerr << appName() << ": server is using a different Slice definition of `" << q->first << "'" << endl; + consoleErr << appName() << ": server is using a different Slice definition of `" << q->first << "'" << endl; } } @@ -945,17 +947,17 @@ Client::run(StringSeq& originalArgs) } catch(const IceGrid::PermissionDeniedException& ex) { - cout << "permission denied:\n" << ex.reason << endl; + consoleOut << "permission denied:\n" << ex.reason << endl; return EXIT_FAILURE; } catch(const Glacier2::PermissionDeniedException& ex) { - cout << "permission denied:\n" << ex.reason << endl; + consoleOut << "permission denied:\n" << ex.reason << endl; return EXIT_FAILURE; } catch(const Glacier2::CannotCreateSessionException& ex) { - cout << "session creation failed:\n" << ex.reason << endl; + consoleOut << "session creation failed:\n" << ex.reason << endl; return EXIT_FAILURE; } catch(...) @@ -1015,7 +1017,7 @@ Client::run(StringSeq& originalArgs) string Client::getPassword(const string& prompt) { - cout << prompt << flush; + consoleOut << prompt << flush; string password; #ifndef _WIN32 struct termios oldConf; @@ -1033,6 +1035,6 @@ Client::getPassword(const string& prompt) password += c; } #endif - cout << endl; + consoleOut << endl; return IceUtilInternal::trim(password); } diff --git a/cpp/src/IceGrid/IceGridNode.cpp b/cpp/src/IceGrid/IceGridNode.cpp index de7d308702e..0c14ca557b4 100644 --- a/cpp/src/IceGrid/IceGridNode.cpp +++ b/cpp/src/IceGrid/IceGridNode.cpp @@ -12,6 +12,7 @@ #include <IceUtil/StringUtil.h> #include <IceUtil/FileUtil.h> #include <Ice/Ice.h> +#include <Ice/ConsoleUtil.h> #include <Ice/Locator.h> #include <Ice/Service.h> #include <IceGrid/Activator.h> @@ -33,6 +34,7 @@ using namespace std; using namespace Ice; +using namespace IceInternal; using namespace IceGrid; namespace @@ -581,14 +583,14 @@ NodeService::startImpl(int argc, char* argv[], int& status) string password = communicator()->getProperties()->getProperty("IceGridAdmin.Password"); while(id.empty()) { - cout << "user id: " << flush; + consoleOut << "user id: " << flush; getline(cin, id); id = IceUtilInternal::trim(id); } if(password.empty()) { - cout << "password: " << flush; + consoleOut << "password: " << flush; getline(cin, password); password = IceUtilInternal::trim(password); } diff --git a/cpp/src/IceGrid/IceGridRegistry.cpp b/cpp/src/IceGrid/IceGridRegistry.cpp index a4a4f92d682..8d2a3659bd2 100644 --- a/cpp/src/IceGrid/IceGridRegistry.cpp +++ b/cpp/src/IceGrid/IceGridRegistry.cpp @@ -10,12 +10,14 @@ #include <IceUtil/Options.h> #include <Ice/Ice.h> #include <Ice/Service.h> +#include <Ice/ConsoleUtil.h> #include <IceGrid/RegistryI.h> #include <IceGrid/TraceLevels.h> #include <IceGrid/Util.h> using namespace std; using namespace Ice; +using namespace IceUtilInternal; using namespace IceGrid; namespace IceGrid @@ -109,7 +111,7 @@ RegistryService::start(int argc, char* argv[], int& status) if(!args.empty()) { - cerr << argv[0] << ": too many arguments" << endl; + consoleErr << argv[0] << ": too many arguments" << endl; usage(argv[0]); return false; } diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp index 28b09bb87dc..3c45b2c44d6 100644 --- a/cpp/src/IceGrid/Parser.cpp +++ b/cpp/src/IceGrid/Parser.cpp @@ -251,71 +251,17 @@ Ice::StringConverterPtr windowsConsoleConverter = 0; void outputNewline() { -#ifdef _WIN32 - fprintf_s(stdout, "\n"); -#else - cout << endl; -#endif + consoleOut << endl; } void flushOutput() { -#ifdef _WIN32 - fflush(stdout); -#else - cout << flush; -#endif -} - -#ifdef _WIN32 -string toConsoleEncoding(const string& s) -{ - if(windowsConsoleConverter) - { - try - { - // Convert from UTF-8 to console CP - string consoleString; - windowsConsoleConverter->fromUTF8(reinterpret_cast<const IceUtil::Byte*>(s.data()), - reinterpret_cast<const IceUtil::Byte*>(s.data() + s.size()), - consoleString); - - return consoleString; - } - catch(const IceUtil::IllegalConversionException&) - { - // - // If there is a problem with the encoding conversions we just - // return the original message without encoding conversions. - // - return s; - } - } - else - { - return s; - } + consoleOut << flush; } -#endif void outputString(const string& s) { -#ifdef _WIN32 - if(windowsConsoleConverter) - { - fprintf_s(stdout, "%s", toConsoleEncoding(s).c_str()); - } - else - { - // - // Use fprintf_s to avoid encoding conversion when stdout is connected - // to Windows console. - // - fprintf_s(stdout, "%s", s.c_str()); - } -#else - cout << s; -#endif + consoleOut << s; } void writeMessage(const string& message, bool indent) @@ -383,8 +329,6 @@ void printLogMessage(const string& p, const Ice::LogMessage& logMessage) } } - - class RemoteLoggerI : public Ice::RemoteLogger { public: @@ -481,7 +425,7 @@ Parser::usage(const string& category, const string& command) } else { - cout << _helpCommands[category][command]; + consoleOut << _helpCommands[category][command]; } } @@ -505,7 +449,7 @@ Parser::usage(const string& category, const list<string>& args) void Parser::usage() { - cout << + consoleOut << "help Print this message.\n" "exit, quit Exit this program.\n" "CATEGORY help Print the help section of the given CATEGORY.\n" @@ -1119,11 +1063,11 @@ Parser::pingNode(const list<string>& args) { if(_admin->pingNode(args.front())) { - cout << "node is up" << endl; + consoleOut << "node is up" << endl; } else { - cout << "node is down" << endl; + consoleOut << "node is down" << endl; } } catch(const Ice::Exception& ex) @@ -1144,7 +1088,7 @@ Parser::printLoadNode(const list<string>& args) try { LoadInfo load = _admin->getNodeLoad(args.front()); - cout << "load average (1/5/15): " << load.avg1 << " / " << load.avg5 << " / " << load.avg15 << endl; + consoleOut << "load average (1/5/15): " << load.avg1 << " / " << load.avg5 << " / " << load.avg15 << endl; } catch(const Ice::Exception& ex) { @@ -1167,11 +1111,11 @@ Parser::printNodeProcessorSockets(const list<string>& args) { try { - cout << _admin->getNodeProcessorSocketCount(args.front()) << endl; + consoleOut << _admin->getNodeProcessorSocketCount(args.front()) << endl; } catch(const Ice::OperationNotExistException&) { - cout << "not supported" << endl; + consoleOut << "not supported" << endl; } } else @@ -1202,17 +1146,19 @@ Parser::printNodeProcessorSockets(const list<string>& args) } } - cout.flags(ios::left); - cout << setw(20) << "Hostname" << setw(20) << "| # of sockets" << setw(39) << "| Nodes" << endl; - cout << setw(79) << "=====================================================================" << endl; + ostringstream os; + os.flags(ios::left); + os << setw(20) << "Hostname" << setw(20) << "| # of sockets" << setw(39) << "| Nodes" << endl; + os << setw(79) << "=====================================================================" << endl; for(map<string, pair< vector<string>, int> >::const_iterator q = processorSocketCounts.begin(); q != processorSocketCounts.end(); ++q) { - cout << setw(20) << setiosflags(ios::left) <<q->first; - cout << "| " << setw(18) << setiosflags(ios::left) << q->second.second; - cout << "| " << setw(37) << setiosflags(ios::left) << toString(q->second.first); - cout << endl; + os << setw(20) << setiosflags(ios::left) <<q->first; + os << "| " << setw(18) << setiosflags(ios::left) << q->second.second; + os << "| " << setw(37) << setiosflags(ios::left) << toString(q->second.first); + os << endl; } + consoleOut << os.str() << flush; } } catch(const Ice::Exception& ex) @@ -1251,8 +1197,10 @@ Parser::listAllNodes(const list<string>& args) try { + ostringstream os; Ice::StringSeq names = _admin->getAllNodeNames(); - copy(names.begin(), names.end(), ostream_iterator<string>(cout,"\n")); + copy(names.begin(), names.end(), ostream_iterator<string>(os,"\n")); + consoleOut << os.str(); } catch(const Ice::Exception& ex) { @@ -1300,11 +1248,11 @@ Parser::pingRegistry(const list<string>& args) { if(_admin->pingRegistry(args.front())) { - cout << "registry is up" << endl; + consoleOut << "registry is up" << endl; } else { - cout << "registry is down" << endl; + consoleOut << "registry is down" << endl; } } catch(const Ice::Exception& ex) @@ -1350,8 +1298,10 @@ Parser::listAllRegistries(const list<string>& args) try { + ostringstream os; Ice::StringSeq names = _admin->getAllRegistryNames(); - copy(names.begin(), names.end(), ostream_iterator<string>(cout,"\n")); + copy(names.begin(), names.end(), ostream_iterator<string>(os,"\n")); + consoleOut << os.str(); } catch(const Ice::Exception& ex) { @@ -1574,39 +1524,39 @@ Parser::stateServer(const list<string>& args) { case Inactive: { - cout << "inactive (" << enabled << ")" << endl; + consoleOut << "inactive (" << enabled << ")" << endl; break; } case Activating: { - cout << "activating (" << enabled << ")" << endl; + consoleOut << "activating (" << enabled << ")" << endl; break; } case Active: { int pid = _admin->getServerPid(args.front()); - cout << "active (pid = " << pid << ", " << enabled << ")" << endl; + consoleOut << "active (pid = " << pid << ", " << enabled << ")" << endl; break; } case ActivationTimedOut: { int pid = _admin->getServerPid(args.front()); - cout << "activation timed out (pid = " << pid << ", " << enabled << ")" << endl; + consoleOut << "activation timed out (pid = " << pid << ", " << enabled << ")" << endl; break; } case Deactivating: { - cout << "deactivating (" << enabled << ")" << endl; + consoleOut << "deactivating (" << enabled << ")" << endl; break; } case Destroying: { - cout << "destroying (" << enabled << ")" << endl; + consoleOut << "destroying (" << enabled << ")" << endl; break; } case Destroyed: { - cout << "destroyed (" << enabled << ")" << endl; + consoleOut << "destroyed (" << enabled << ")" << endl; break; } default: @@ -1633,7 +1583,7 @@ Parser::pidServer(const list<string>& args) int pid = _admin->getServerPid(args.front()); if(pid > 0) { - cout << pid << endl; + consoleOut << pid << endl; } else { @@ -1668,14 +1618,14 @@ Parser::propertiesServer(const list<string>& args, bool single) if(single) { string val = propAdmin->getProperty(*(++args.begin())); - cout << val << endl; + consoleOut << val << endl; } else { Ice::PropertyDict properties = propAdmin->getPropertiesForPrefix(""); for(Ice::PropertyDict::const_iterator p = properties.begin(); p != properties.end(); ++p) { - cout << p->first << "=" << p->second << endl; + consoleOut << p->first << "=" << p->second << endl; } } } @@ -1730,8 +1680,10 @@ Parser::listAllServers(const list<string>& args) try { + ostringstream os; Ice::StringSeq ids = _admin->getAllServerIds(); - copy(ids.begin(), ids.end(), ostream_iterator<string>(cout,"\n")); + copy(ids.begin(), ids.end(), ostream_iterator<string>(os,"\n")); + consoleOut << os.str(); } catch(const Ice::Exception& ex) { @@ -1926,14 +1878,14 @@ Parser::propertiesService(const list<string>& args, bool single) if(single) { string val = propAdmin->getProperty(property); - cout << val << endl; + consoleOut << val << endl; } else { Ice::PropertyDict properties = propAdmin->getPropertiesForPrefix(""); for(Ice::PropertyDict::const_iterator p = properties.begin(); p != properties.end(); ++p) { - cout << p->first << "=" << p->second << endl; + consoleOut << p->first << "=" << p->second << endl; } } } @@ -1974,7 +1926,7 @@ Parser::listServices(const list<string>& args) { if(p->descriptor) { - cout << p->descriptor->name << endl; + consoleOut << p->descriptor->name << endl; } } } @@ -2001,15 +1953,15 @@ Parser::endpointsAdapter(const list<string>& args) if(adpts.size() == 1 && adpts.begin()->id == adapterId) { string endpoints = _communicator->proxyToString(adpts.begin()->proxy); - cout << (endpoints.empty() ? string("<inactive>") : endpoints) << endl; + consoleOut << (endpoints.empty() ? string("<inactive>") : endpoints) << endl; } else { for(AdapterInfoSeq::const_iterator p = adpts.begin(); p != adpts.end(); ++p) { - cout << (p->id.empty() ? string("<empty>") : p->id) << ": "; + consoleOut << (p->id.empty() ? string("<empty>") : p->id) << ": "; string endpoints = _communicator->proxyToString(p->proxy); - cout << (endpoints.empty() ? string("<inactive>") : endpoints) << endl; + consoleOut << (endpoints.empty() ? string("<inactive>") : endpoints) << endl; } } } @@ -2049,8 +2001,10 @@ Parser::listAllAdapters(const list<string>& args) try { + ostringstream os; Ice::StringSeq ids = _admin->getAllAdapterIds(); - copy(ids.begin(), ids.end(), ostream_iterator<string>(cout,"\n")); + copy(ids.begin(), ids.end(), ostream_iterator<string>(os,"\n")); + consoleOut << os.str(); } catch(const Ice::Exception& ex) { @@ -2122,7 +2076,7 @@ Parser::findObject(const list<string>& args) ObjectInfoSeq objects = _admin->getObjectInfosByType(*(args.begin())); for(ObjectInfoSeq::const_iterator p = objects.begin(); p != objects.end(); ++p) { - cout << _communicator->proxyToString(p->proxy) << endl; + consoleOut << _communicator->proxyToString(p->proxy) << endl; } } catch(const Ice::Exception& ex) @@ -2149,8 +2103,8 @@ Parser::describeObject(const list<string>& args) if(arg.find('*') == string::npos) { ObjectInfo info = _admin->getObjectInfo(Ice::stringToIdentity(arg)); - cout << "proxy = `" << _communicator->proxyToString(info.proxy) << "'" << endl; - cout << "type = `" << info.type << "'" << endl; + consoleOut << "proxy = `" << _communicator->proxyToString(info.proxy) << "'" << endl; + consoleOut << "type = `" << info.type << "'" << endl; return; } else @@ -2165,7 +2119,7 @@ Parser::describeObject(const list<string>& args) for(ObjectInfoSeq::const_iterator p = objects.begin(); p != objects.end(); ++p) { - cout << "proxy = `" << _communicator->proxyToString(p->proxy) << "' type = `" << p->type << "'" << endl; + consoleOut << "proxy = `" << _communicator->proxyToString(p->proxy) << "' type = `" << p->type << "'" << endl; } } @@ -2198,7 +2152,7 @@ Parser::listObject(const list<string>& args) for(ObjectInfoSeq::const_iterator p = objects.begin(); p != objects.end(); ++p) { - cout << _communicator->identityToString(p->proxy->ice_getIdentity()) << endl; + consoleOut << _communicator->identityToString(p->proxy->ice_getIdentity()) << endl; } } catch(const Ice::Exception& ex) @@ -2245,7 +2199,7 @@ Parser::show(const string& reader, const list<string>& origArgs) string id = *p++; string filename = *p++; - cout << reader << " `" << id << "' " << filename << ": " << flush; + consoleOut << reader << " `" << id << "' " << filename << ": " << flush; Ice::StringSeq lines; bool head = opts.isSet("head"); @@ -2574,19 +2528,19 @@ Parser::showLog(const string& id, const string& reader, bool tail, bool follow, void Parser::showBanner() { - cout << "Ice " << ICE_STRING_VERSION << " Copyright (c) 2003-2016 ZeroC, Inc." << endl; + consoleOut << "Ice " << ICE_STRING_VERSION << " Copyright (c) 2003-2016 ZeroC, Inc." << endl; } void Parser::showCopying() { - cout << "This command is not implemented." << endl; + consoleOut << "This command is not implemented." << endl; } void Parser::showWarranty() { - cout << "This command is not implemented." << endl; + consoleOut << "This command is not implemented." << endl; } // @@ -2654,7 +2608,7 @@ Parser::getInput(char* buf, size_t& result, size_t maxSize) } } #else - cout << parser->getPrompt() << flush; + consoleOut << parser->getPrompt() << flush; string line; while(true) { @@ -2746,11 +2700,11 @@ Parser::invalidCommand(const list<string>& s) string cat = *s.begin(); if(_helpCommands.find(cat) == _helpCommands.end()) { - cerr << "unknown `" << cat << "' command (see `help' for more info)" << endl; + consoleErr << "unknown `" << cat << "' command (see `help' for more info)" << endl; } else if(s.size() == 1) { - cerr << "invalid `" << cat << "' command (see `" << cat << " help' for more info)" << endl; + consoleErr << "invalid `" << cat << "' command (see `" << cat << " help' for more info)" << endl; } else { @@ -2758,12 +2712,12 @@ Parser::invalidCommand(const list<string>& s) if(_helpCommands[cat].find(cmd) == _helpCommands[cat].end()) { cmd = cat + " " + cmd; - cerr << "unknown `" << cmd << "' command (see `" << cat << " help' for more info)" << endl; + consoleErr << "unknown `" << cmd << "' command (see `" << cat << " help' for more info)" << endl; } else { cmd = cat + " " + cmd; - cerr << "invalid `" << cmd << "' command (see `" << cmd << " help' for more info)" << endl; + consoleErr << "invalid `" << cmd << "' command (see `" << cmd << " help' for more info)" << endl; } } } @@ -2819,13 +2773,7 @@ void Parser::error(const char* s) { - cerr << "error: " -#ifdef _WIN32 - << toConsoleEncoding(s) -#else - << s -#endif - << endl; + consoleErr << "error: " << s << endl; _errors++; } @@ -2838,13 +2786,7 @@ Parser::error(const string& s) void Parser::warning(const char* s) { - cerr << "warning: " -#ifdef _WIN32 - << toConsoleEncoding(s) -#else - << s -#endif - << endl; + consoleErr << "warning: " << s << endl; } void diff --git a/cpp/src/IcePatch2/Calc.cpp b/cpp/src/IcePatch2/Calc.cpp index e0b6fdf6324..cd63e6c37af 100644 --- a/cpp/src/IcePatch2/Calc.cpp +++ b/cpp/src/IcePatch2/Calc.cpp @@ -10,11 +10,13 @@ #include <IceUtil/Options.h> #include <IceUtil/StringUtil.h> #include <IceUtil/FileUtil.h> +#include <Ice/ConsoleUtil.h> #include <IcePatch2Lib/Util.h> #include <iterator> using namespace std; using namespace Ice; +using namespace IceInternal; using namespace IcePatch2; using namespace IcePatch2Internal; @@ -77,21 +79,21 @@ public: virtual bool remove(const string& path) { - cout << "removing: " << path << endl; + consoleOut << "removing: " << path << endl; return true; } virtual bool checksum(const string& path) { - cout << "checksum: " << path << endl; + consoleOut << "checksum: " << path << endl; return true; } virtual bool compress(const string& path) { - cout << "compress: " << path << endl; + consoleOut << "compress: " << path << endl; return true; } }; @@ -99,8 +101,8 @@ public: void usage(const string& appName) { - cerr << "Usage: " << appName << " [options] DIR [FILES...]\n"; - cerr << + consoleErr << "Usage: " << appName << " [options] DIR [FILES...]\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -147,7 +149,7 @@ main(int argc, char* argv[]) } catch(const IceUtilInternal::BadOptException& e) { - cerr << e.reason << endl; + consoleErr << e.reason << endl; usage(appName); return EXIT_FAILURE; } @@ -159,14 +161,14 @@ main(int argc, char* argv[]) } if(opts.isSet("version")) { - cout << ICE_STRING_VERSION << endl; + consoleOut << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } bool doCompress = opts.isSet("compress"); bool dontCompress = opts.isSet("no-compress"); if(doCompress && dontCompress) { - cerr << appName << ": only one of -z and -Z are mutually exclusive" << endl; + consoleErr << appName << ": only one of -z and -Z are mutually exclusive" << endl; usage(appName); return EXIT_FAILURE; } @@ -183,7 +185,7 @@ main(int argc, char* argv[]) if(args.empty()) { - cerr << appName << ": no data directory specified" << endl; + consoleErr << appName << ": no data directory specified" << endl; usage(appName); return EXIT_FAILURE; } @@ -312,12 +314,12 @@ main(int argc, char* argv[]) } catch(const string& ex) { - cerr << appName << ": " << ex << endl; + consoleErr << appName << ": " << ex << endl; return EXIT_FAILURE; } catch(const char* ex) { - cerr << appName << ": " << ex << endl; + consoleErr << appName << ": " << ex << endl; return EXIT_FAILURE; } diff --git a/cpp/src/IcePatch2/Client.cpp b/cpp/src/IcePatch2/Client.cpp index edf8eabcc7a..93217371140 100644 --- a/cpp/src/IcePatch2/Client.cpp +++ b/cpp/src/IcePatch2/Client.cpp @@ -10,6 +10,7 @@ #include <IceUtil/Options.h> #include <IceUtil/StringUtil.h> #include <Ice/Application.h> +#include <Ice/ConsoleUtil.h> #include <IcePatch2Lib/Util.h> #include <IcePatch2/ClientUtil.h> @@ -22,6 +23,7 @@ using namespace std; using namespace Ice; +using namespace IceInternal; using namespace IcePatch2; using namespace IcePatch2Internal; @@ -50,11 +52,11 @@ public: virtual bool noFileSummary(const string& reason) { - cout << "Cannot load file summary:\n" << reason << endl; + consoleOut << "Cannot load file summary:\n" << reason << endl; string answer; do { - cout << "Do a thorough patch? (yes/no)" << endl; + consoleOut << "Do a thorough patch? (yes/no)" << endl; cin >> answer; answer = IceUtilInternal::toLower(answer); if(answer == "no") @@ -71,7 +73,7 @@ public: { if(!_pressAnyKeyMessage) { - cout << "[Press any key to abort]" << endl; + consoleOut << "[Press any key to abort]" << endl; _pressAnyKeyMessage = true; } @@ -81,7 +83,7 @@ public: virtual bool checksumProgress(const string& path) { - cout << "Calculating checksum for " << getBasename(path) << endl; + consoleOut << "Calculating checksum for " << getBasename(path) << endl; return !keyPressed(); } @@ -96,12 +98,12 @@ public: { if(!_pressAnyKeyMessage) { - cout << "[Press any key to abort]" << endl; + consoleOut << "[Press any key to abort]" << endl; _pressAnyKeyMessage = true; } _lastProgress = "0%"; - cout << "Getting list of files to patch: " << _lastProgress << flush; + consoleOut << "Getting list of files to patch: " << _lastProgress << flush; return !keyPressed(); } @@ -110,19 +112,19 @@ public: { for(unsigned int i = 0; i < _lastProgress.size(); ++i) { - cout << '\b'; + consoleOut << '\b'; } ostringstream s; s << percent << '%'; _lastProgress = s.str(); - cout << _lastProgress << flush; + consoleOut << _lastProgress << flush; return !keyPressed(); } virtual bool fileListEnd() { - cout << endl; + consoleOut << endl; return !keyPressed(); } @@ -131,14 +133,14 @@ public: { if(!_pressAnyKeyMessage) { - cout << "[Press any key to abort]" << endl; + consoleOut << "[Press any key to abort]" << endl; _pressAnyKeyMessage = true; } ostringstream s; s << "0/" << size << " (" << totalProgress << '/' << totalSize << ')'; _lastProgress = s.str(); - cout << getBasename(path) << ' ' << _lastProgress << flush; + consoleOut << getBasename(path) << ' ' << _lastProgress << flush; return !keyPressed(); } @@ -147,19 +149,19 @@ public: { for(unsigned int i = 0; i < _lastProgress.size(); ++i) { - cout << '\b'; + consoleOut << '\b'; } ostringstream s; s << progress << '/' << size << " (" << totalProgress << '/' << totalSize << ')'; _lastProgress = s.str(); - cout << _lastProgress << flush; + consoleOut << _lastProgress << flush; return !keyPressed(); } virtual bool patchEnd() { - cout << endl; + consoleOut << endl; return !keyPressed(); } @@ -237,7 +239,7 @@ private: string answer; do { - cout << "\nConfirm abort? (Y/N)" << endl; + consoleOut << "\nConfirm abort? (Y/N)" << endl; cin >> answer; answer = IceUtilInternal::toLower(answer); if(answer == "n") @@ -281,7 +283,7 @@ Client::run(int argc, char* argv[]) } catch(const IceUtilInternal::BadOptException& e) { - cerr << e.reason << endl; + consoleErr << e.reason << endl; usage(argv[0]); return EXIT_FAILURE; } @@ -293,7 +295,7 @@ Client::run(int argc, char* argv[]) } if(opts.isSet("version")) { - cout << ICE_STRING_VERSION << endl; + consoleOut << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } if(opts.isSet("thorough")) @@ -303,7 +305,7 @@ Client::run(int argc, char* argv[]) if(args.size() > 1) { - cerr << argv[0] << ": too many arguments" << endl; + consoleErr << argv[0] << ": too many arguments" << endl; usage(argv[0]); return EXIT_FAILURE; } @@ -333,13 +335,13 @@ Client::run(int argc, char* argv[]) } catch(const string& ex) { - cerr << argv[0] << ": " << ex << endl; + consoleErr << argv[0] << ": " << ex << endl; return EXIT_FAILURE; } if(aborted) { - cout << "\n[Aborted]" << endl; + consoleOut << "\n[Aborted]" << endl; return EXIT_FAILURE; } else @@ -357,8 +359,8 @@ Client::usage(const string& appName) "-v, --version Display the Ice version.\n" "-t, --thorough Recalculate all checksums."; - cerr << "Usage: " << appName << " [options] [DIR]" << endl; - cerr << options << endl; + consoleErr << "Usage: " << appName << " [options] [DIR]" << endl; + consoleErr << options << endl; } #ifdef _WIN32 diff --git a/cpp/src/IceSSL/RFC2253.cpp b/cpp/src/IceSSL/RFC2253.cpp index e4c57add13a..b6b44c7fa25 100644 --- a/cpp/src/IceSSL/RFC2253.cpp +++ b/cpp/src/IceSSL/RFC2253.cpp @@ -501,15 +501,15 @@ print(const list< list<pair<string, string> > >& r) { if(r.size() > 1) { - cout << "result: " << r.size() << " DNs" << endl; + consoleOut << "result: " << r.size() << " DNs" << endl; } for(list< list<pair<string, string> > >::const_iterator q = r.begin(); q != r.end(); ++q) { list<pair<string, string> > l = *q; - cout << "result: " << l.size() << " RDNs" << endl; + consoleOut << "result: " << l.size() << " RDNs" << endl; for(list<pair<string, string> >::const_iterator p = l.begin(); p != l.end(); ++p) { - cout << "\t\"" << p->first << "\"=\"" << p->second << "\"" << endl; + consoleOut << "\t\"" << p->first << "\"=\"" << p->second << "\"" << endl; } } } @@ -529,13 +529,13 @@ main() { for(int i = 0; i < sizeof(examples)/sizeof(examples[0]); ++i) { - cout << "string: " << examples[i] << endl; + consoleOut << "string: " << examples[i] << endl; print(RFC2253::parse(examples[i])); } } catch(const RFC2253::ParseException& e) { - cout << "error: " << e.reason << endl; + consoleOut << "error: " << e.reason << endl; } } #endif diff --git a/cpp/src/IceStorm/Admin.cpp b/cpp/src/IceStorm/Admin.cpp index 60c206b116a..be27118c284 100644 --- a/cpp/src/IceStorm/Admin.cpp +++ b/cpp/src/IceStorm/Admin.cpp @@ -9,6 +9,7 @@ #include <IceUtil/Options.h> #include <Ice/Application.h> +#include <Ice/ConsoleUtil.h> #include <Ice/SliceChecksums.h> #include <IceStorm/Parser.h> @@ -19,6 +20,7 @@ using namespace std; using namespace Ice; +using namespace IceInternal; using namespace IceStorm; class Client : public Application @@ -56,8 +58,8 @@ main(int argc, char* argv[]) void Client::usage() { - cerr << "Usage: " << appName() << " [options]\n"; - cerr << + consoleErr << "Usage: " << appName() << " [options]\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -85,13 +87,13 @@ Client::run(int argc, char* argv[]) } catch(const IceUtilInternal::BadOptException& e) { - cerr << e.reason << endl; + consoleErr << e.reason << endl; usage(); return EXIT_FAILURE; } if(!args.empty()) { - cerr << argv[0] << ": too many arguments" << endl; + consoleErr << argv[0] << ": too many arguments" << endl; usage(); return EXIT_FAILURE; } @@ -103,7 +105,7 @@ Client::run(int argc, char* argv[]) } if(opts.isSet("version")) { - cout << ICE_STRING_VERSION << endl; + consoleOut << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } if(opts.isSet("e")) @@ -139,7 +141,7 @@ Client::run(int argc, char* argv[]) } catch(const Ice::ProxyParseException&) { - cerr << appName() << ": malformed proxy: " << p->second << endl; + consoleErr << appName() << ": malformed proxy: " << p->second << endl; return EXIT_FAILURE; } } @@ -180,7 +182,7 @@ Client::run(int argc, char* argv[]) if(!defaultManager) { - cerr << appName() << ": no manager proxies configured" << endl; + consoleErr << appName() << ": no manager proxies configured" << endl; return EXIT_FAILURE; } diff --git a/cpp/src/IceStorm/IceStormDB.cpp b/cpp/src/IceStorm/IceStormDB.cpp index b3a927c719e..96c7aa70d20 100644 --- a/cpp/src/IceStorm/IceStormDB.cpp +++ b/cpp/src/IceStorm/IceStormDB.cpp @@ -10,6 +10,7 @@ #include <IceUtil/Options.h> #include <IceUtil/FileUtil.h> #include <Ice/Ice.h> +#include <Ice/ConsoleUtil.h> #include <IceDB/IceDB.h> #include <IceStorm/DBTypes.h> #include <IceUtil/DisableWarnings.h> @@ -17,6 +18,7 @@ using namespace std; using namespace Ice; +using namespace IceInternal; using namespace IceStorm; using namespace IceStormElection; @@ -47,8 +49,8 @@ main(int argc, char* argv[]) void Client::usage() { - cerr << "Usage: " << appName() << " <options>\n"; - cerr << + consoleErr << "Usage: " << appName() << " <options>\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display version.\n" @@ -81,13 +83,13 @@ Client::run(int argc, char* argv[]) } catch(const IceUtilInternal::BadOptException& e) { - cerr << argv[0] << ": " << e.reason << endl; + consoleErr << argv[0] << ": " << e.reason << endl; usage(); return EXIT_FAILURE; } if(!args.empty()) { - cerr << argv[0] << ": too many arguments" << endl; + consoleErr << argv[0] << ": too many arguments" << endl; usage(); return EXIT_FAILURE; } @@ -100,20 +102,20 @@ Client::run(int argc, char* argv[]) if(opts.isSet("version")) { - cout << ICE_STRING_VERSION << endl; + consoleOut << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } if(!(opts.isSet("import") ^ opts.isSet("export"))) { - cerr << argv[0] << ": either --import or --export must be set" << endl; + consoleErr << argv[0] << ": either --import or --export must be set" << endl; usage(); return EXIT_FAILURE; } if(!(opts.isSet("dbhome") ^ opts.isSet("dbpath"))) { - cerr << argv[0] << ": set the database environment directory with either --dbhome or --dbpath" << endl; + consoleErr << argv[0] << ": set the database environment directory with either --dbhome or --dbpath" << endl; usage(); return EXIT_FAILURE; } @@ -145,24 +147,24 @@ Client::run(int argc, char* argv[]) if(import) { - cout << "Importing database to directory " << dbPath << " from file " << dbFile << endl; + consoleOut << "Importing database to directory " << dbPath << " from file " << dbFile << endl; if(!IceUtilInternal::directoryExists(dbPath)) { - cerr << argv[0] << ": output directory does not exist: " << dbPath << endl; + consoleErr << argv[0] << ": output directory does not exist: " << dbPath << endl; return EXIT_FAILURE; } if(!IceUtilInternal::isEmptyDirectory(dbPath)) { - cerr << argv[0] << ": output directory is not empty: " << dbPath << endl; + consoleErr << argv[0] << ": output directory is not empty: " << dbPath << endl; return EXIT_FAILURE; } ifstream fs(IceUtilInternal::streamFilename(dbFile).c_str(), ios::binary); if(fs.fail()) { - cerr << argv[0] << ": could not open input file: " << strerror(errno) << endl; + consoleErr << argv[0] << ": could not open input file: " << strerror(errno) << endl; return EXIT_FAILURE; } fs.unsetf(ios::skipws); @@ -173,7 +175,7 @@ Client::run(int argc, char* argv[]) if(!fileSize) { fs.close(); - cerr << argv[0] << ": empty input file" << endl; + consoleErr << argv[0] << ": empty input file" << endl; return EXIT_FAILURE; } @@ -192,7 +194,7 @@ Client::run(int argc, char* argv[]) stream.read(type); if(type != "IceStorm") { - cerr << argv[0] << ": incorrect input file type: " << type << endl; + consoleErr << argv[0] << ": incorrect input file type: " << type << endl; return EXIT_FAILURE; } stream.read(version); @@ -204,7 +206,7 @@ Client::run(int argc, char* argv[]) if(debug) { - cout << "Writing LLU Map:" << endl; + consoleOut << "Writing LLU Map:" << endl; } IceDB::Dbi<string, LogUpdate, IceDB::IceContext, Ice::OutputStream> @@ -214,14 +216,14 @@ Client::run(int argc, char* argv[]) { if(debug) { - cout << " KEY = " << p->first << endl; + consoleOut << " KEY = " << p->first << endl; } lluMap.put(txn, p->first, p->second); } if(debug) { - cout << "Writing Subscriber Map:" << endl; + consoleOut << "Writing Subscriber Map:" << endl; } IceDB::Dbi<SubscriberRecordKey, SubscriberRecord, IceDB::IceContext, Ice::OutputStream> @@ -231,8 +233,8 @@ Client::run(int argc, char* argv[]) { if(debug) { - cout << " KEY = TOPIC(" << communicator()->identityToString(q->first.topic) - << ") ID(" << communicator()->identityToString(q->first.id) << ")" <<endl; + consoleOut << " KEY = TOPIC(" << communicator()->identityToString(q->first.topic) + << ") ID(" << communicator()->identityToString(q->first.id) << ")" << endl; } subscriberMap.put(txn, q->first, q->second); } @@ -243,7 +245,7 @@ Client::run(int argc, char* argv[]) } else { - cout << "Exporting database from directory " << dbPath << " to file " << dbFile << endl; + consoleOut << "Exporting database from directory " << dbPath << " to file " << dbFile << endl; { IceDB::Env env(dbPath, 2); @@ -251,7 +253,7 @@ Client::run(int argc, char* argv[]) if(debug) { - cout << "Reading LLU Map:" << endl; + consoleOut << "Reading LLU Map:" << endl; } IceDB::Dbi<string, LogUpdate, IceDB::IceContext, Ice::OutputStream> @@ -264,7 +266,7 @@ Client::run(int argc, char* argv[]) { if(debug) { - cout << " KEY = " << s << endl; + consoleOut << " KEY = " << s << endl; } data.llus.insert(std::make_pair(s, llu)); } @@ -272,7 +274,7 @@ Client::run(int argc, char* argv[]) if(debug) { - cout << "Reading Subscriber Map:" << endl; + consoleOut << "Reading Subscriber Map:" << endl; } IceDB::Dbi<SubscriberRecordKey, SubscriberRecord, IceDB::IceContext, Ice::OutputStream> @@ -286,8 +288,8 @@ Client::run(int argc, char* argv[]) { if(debug) { - cout << " KEY = TOPIC(" << communicator()->identityToString(key.topic) - << ") ID(" << communicator()->identityToString(key.id) << ")" <<endl; + consoleOut << " KEY = TOPIC(" << communicator()->identityToString(key.topic) + << ") ID(" << communicator()->identityToString(key.id) << ")" << endl; } data.subscribers.insert(std::make_pair(key, record)); } @@ -305,7 +307,7 @@ Client::run(int argc, char* argv[]) ofstream fs(IceUtilInternal::streamFilename(dbFile).c_str(), ios::binary); if(fs.fail()) { - cerr << argv[0] << ": could not open output file: " << strerror(errno) << endl; + consoleErr << argv[0] << ": could not open output file: " << strerror(errno) << endl; return EXIT_FAILURE; } fs.write(reinterpret_cast<const char*>(stream.b.begin()), stream.b.size()); @@ -314,7 +316,7 @@ Client::run(int argc, char* argv[]) } catch(const IceUtil::Exception& ex) { - cerr << argv[0] << ": " << (import ? "import" : "export") << " failed:\n" << ex << endl; + consoleErr << argv[0] << ": " << (import ? "import" : "export") << " failed:\n" << ex << endl; return EXIT_FAILURE; } diff --git a/cpp/src/IceStorm/Instance.cpp b/cpp/src/IceStorm/Instance.cpp index 6d8334cab4d..68d43558e93 100644 --- a/cpp/src/IceStorm/Instance.cpp +++ b/cpp/src/IceStorm/Instance.cpp @@ -174,11 +174,6 @@ Instance::Instance( __setNoDelete(false); } -Instance::~Instance() -{ - //cout << "~Instance" << endl; -} - void Instance::setNode(const NodeIPtr& node) { diff --git a/cpp/src/IceStorm/Instance.h b/cpp/src/IceStorm/Instance.h index 11d1372e1b8..759ca8dee88 100644 --- a/cpp/src/IceStorm/Instance.h +++ b/cpp/src/IceStorm/Instance.h @@ -69,7 +69,6 @@ public: Instance(const std::string&, const std::string&, const Ice::CommunicatorPtr&, const Ice::ObjectAdapterPtr&, const Ice::ObjectAdapterPtr&, const Ice::ObjectAdapterPtr& = 0, const IceStormElection::NodePrx& = 0); - ~Instance(); void setNode(const IceStormElection::NodeIPtr&); diff --git a/cpp/src/IceStorm/NodeI.cpp b/cpp/src/IceStorm/NodeI.cpp index 2a4e464bf55..098b5167e04 100644 --- a/cpp/src/IceStorm/NodeI.cpp +++ b/cpp/src/IceStorm/NodeI.cpp @@ -118,11 +118,6 @@ GroupNodeInfo::operator=(const GroupNodeInfo& other) } #endif -Replica::~Replica() -{ - //cout << "~Replica" << endl; -} - namespace { static IceUtil::Time @@ -190,11 +185,6 @@ NodeI::NodeI(const InstancePtr& instance, instance->serviceName() + ".Election.ResponseTimeout", 10, properties, _traceLevels); } -NodeI::~NodeI() -{ - //cout << "~NodeI" << endl; -} - void NodeI::start() { diff --git a/cpp/src/IceStorm/NodeI.h b/cpp/src/IceStorm/NodeI.h index 07165f2a70a..9086917ae53 100644 --- a/cpp/src/IceStorm/NodeI.h +++ b/cpp/src/IceStorm/NodeI.h @@ -30,7 +30,6 @@ public: NodeI(const IceStorm::InstancePtr&, const ReplicaPtr&, const Ice::ObjectPrx&, int, const std::map<int, NodePrx>&); - ~NodeI(); void start(); diff --git a/cpp/src/IceStorm/Parser.cpp b/cpp/src/IceStorm/Parser.cpp index df8decb2e14..dd7fd961e33 100644 --- a/cpp/src/IceStorm/Parser.cpp +++ b/cpp/src/IceStorm/Parser.cpp @@ -9,6 +9,7 @@ #include <IceUtil/DisableWarnings.h> #include <Ice/Ice.h> +#include <Ice/ConsoleUtil.h> #include <IceStorm/Parser.h> #include <IceStorm/IceStormInternal.h> #include <algorithm> @@ -23,6 +24,7 @@ extern int yydebug; using namespace std; using namespace Ice; +using namespace IceInternal; using namespace IceStorm; namespace IceStorm @@ -89,7 +91,7 @@ Parser::createParser(const CommunicatorPtr& communicator, const TopicManagerPrx& void Parser::usage() { - cout << + consoleOut << "help Print this message.\n" "exit, quit Exit this program.\n" "create TOPICS Add TOPICS.\n" @@ -229,7 +231,7 @@ Parser::links(const list<string>& args) LinkInfoSeq links = i->second->getLinkInfoSeq(); for(LinkInfoSeq::const_iterator p = links.begin(); p != links.end(); ++p) { - cout << i->first << " to " << (*p).name << " with cost " << (*p).cost << endl; + consoleOut << i->first << " to " << p->name << " with cost " << p->cost << endl; } } } @@ -263,7 +265,7 @@ Parser::topics(const list<string>& args) TopicDict d = manager->retrieveAll(); for(TopicDict::iterator i = d.begin(); i != d.end(); ++i) { - cout << i->first << endl; + consoleOut << i->first << endl; } } catch(const Exception& ex) @@ -299,49 +301,50 @@ Parser::replica(const list<string>& args) error("This topic is not replicated"); } IceStormElection::NodeInfoSeq nodes = node->nodes(); - cout << "replica count: " << nodes.size() << endl; + consoleOut << "replica count: " << nodes.size() << endl; for(IceStormElection::NodeInfoSeq::const_iterator p = nodes.begin(); p != nodes.end(); ++p) { try { IceStormElection::QueryInfo info = p->n->query(); - cout << p->id << ": id: " << info.id << endl; - cout << p->id << ": coord: " << info.coord << endl; - cout << p->id << ": group name: " << info.group << endl; - cout << p->id << ": state: "; + consoleOut << p->id << ": id: " << info.id << endl; + consoleOut << p->id << ": coord: " << info.coord << endl; + consoleOut << p->id << ": group name: " << info.group << endl; + consoleOut << p->id << ": state: "; switch(info.state) { case IceStormElection::NodeStateInactive: - cout << "inactive"; + consoleOut << "inactive"; break; case IceStormElection::NodeStateElection: - cout << "election"; + consoleOut << "election"; break; case IceStormElection::NodeStateReorganization: - cout << "reorganization"; + consoleOut << "reorganization"; break; case IceStormElection::NodeStateNormal: - cout << "normal"; + consoleOut << "normal"; break; default: - cout << "unknown"; + consoleOut << "unknown"; } - cout << endl; - cout << p->id << ": group: "; + consoleOut << endl; + consoleOut << p->id << ": group: "; for(IceStormElection::GroupInfoSeq::const_iterator q = info.up.begin(); q != info.up.end(); ++q) { if(q != info.up.begin()) { - cout << ","; + consoleOut << ","; } - cout << q->id; + consoleOut << q->id; } - cout << endl; - cout << p->id << ": max: " << info.max << endl; + consoleOut << endl; + consoleOut << p->id << ": max: " << info.max + << endl; } catch(const Exception& ex) { - cout << p->id << ": " << ex.ice_id() << endl; + consoleOut << p->id << ": " << ex.ice_id() << endl; } } } @@ -364,11 +367,11 @@ Parser::subscribers(const list<string>& args) for(list<string>::const_iterator i = args.begin(); i != args.end() ; ++i) { TopicPrx topic = _defaultManager->retrieve(*i); - cout << (*i) << ": subscribers:" << endl; + consoleOut << (*i) << ": subscribers:" << endl; IdentitySeq subscribers = topic->getSubscribers(); for(IdentitySeq::const_iterator j = subscribers.begin(); j != subscribers.end(); ++j) { - cout << "\t" << _communicator->identityToString(*j) << endl; + consoleOut << "\t" << _communicator->identityToString(*j) << endl; } } } @@ -383,7 +386,7 @@ Parser::current(const list<string>& args) { if(args.empty()) { - cout << _communicator->identityToString(_defaultManager->ice_getIdentity()) << endl; + consoleOut << _communicator->identityToString(_defaultManager->ice_getIdentity()) << endl; return; } else if(args.size() > 1) @@ -407,7 +410,7 @@ Parser::current(const list<string>& args) void Parser::showBanner() { - cout << "Ice " << ICE_STRING_VERSION << " Copyright (c) 2003-2016 ZeroC, Inc." << endl; + consoleOut << "Ice " << ICE_STRING_VERSION << " Copyright (c) 2003-2016 ZeroC, Inc." << endl; } // @@ -477,7 +480,7 @@ Parser::getInput(char* buf, size_t& result, size_t maxSize) #else - cout << parser->getPrompt() << flush; + consoleOut << parser->getPrompt() << flush; string line; while(true) @@ -545,7 +548,7 @@ Parser::getPrompt() void Parser::error(const char* s) { - cerr << "error: " << s << endl; + consoleErr << "error: " << s << endl; _errors++; } @@ -558,7 +561,7 @@ Parser::error(const string& s) void Parser::warning(const char* s) { - cerr << "warning: " << s << endl; + consoleErr << "warning: " << s << endl; } void @@ -570,7 +573,7 @@ Parser::warning(const string& s) void Parser::invalidCommand(const string& s) { - cerr << s << endl; + consoleErr << s << endl; } int diff --git a/cpp/src/IceStorm/Replica.h b/cpp/src/IceStorm/Replica.h index cfc0704c103..eb615a601e3 100644 --- a/cpp/src/IceStorm/Replica.h +++ b/cpp/src/IceStorm/Replica.h @@ -38,8 +38,6 @@ class Replica : public virtual IceUtil::Shared { public: - ~Replica(); - virtual LogUpdate getLastLogUpdate() const = 0; virtual void sync(const Ice::ObjectPrx&) = 0; virtual void initMaster(const std::set<IceStormElection::GroupNodeInfo>&, const LogUpdate&) = 0; diff --git a/cpp/src/IceStorm/Subscriber.cpp b/cpp/src/IceStorm/Subscriber.cpp index 5c1740ad612..3beabab0963 100644 --- a/cpp/src/IceStorm/Subscriber.cpp +++ b/cpp/src/IceStorm/Subscriber.cpp @@ -34,10 +34,6 @@ public: { } - ~PerSubscriberPublisherI() - { - } - void setSubscriber(const SubscriberPtr& subscriber) { @@ -107,7 +103,6 @@ class SubscriberBatch : public Subscriber public: SubscriberBatch(const InstancePtr&, const SubscriberRecord&, const Ice::ObjectPrx&, int, const Ice::ObjectPrx&); - ~SubscriberBatch(); virtual void flush(); @@ -131,7 +126,6 @@ class SubscriberOneway : public Subscriber public: SubscriberOneway(const InstancePtr&, const SubscriberRecord&, const Ice::ObjectPrx&, int, const Ice::ObjectPrx&); - ~SubscriberOneway(); virtual void flush(); @@ -209,10 +203,6 @@ SubscriberBatch::SubscriberBatch( assert(retryCount == 0); } -SubscriberBatch::~SubscriberBatch() -{ -} - void SubscriberBatch::flush() { @@ -326,10 +316,6 @@ SubscriberOneway::SubscriberOneway( assert(retryCount == 0); } -SubscriberOneway::~SubscriberOneway() -{ -} - void SubscriberOneway::flush() { @@ -629,11 +615,6 @@ Subscriber::create( } } -Subscriber::~Subscriber() -{ - //cout << "~Subscriber" << endl; -} - Ice::ObjectPrx Subscriber::proxy() const { diff --git a/cpp/src/IceStorm/Subscriber.h b/cpp/src/IceStorm/Subscriber.h index 8eb0c18bc61..b7816282727 100644 --- a/cpp/src/IceStorm/Subscriber.h +++ b/cpp/src/IceStorm/Subscriber.h @@ -31,8 +31,6 @@ public: static SubscriberPtr create(const InstancePtr&, const IceStorm::SubscriberRecord&); - ~Subscriber(); - Ice::ObjectPrx proxy() const; // Get the per subscriber object. Ice::Identity id() const; // Return the id of the subscriber. IceStorm::SubscriberRecord record() const; // Get the subscriber record. diff --git a/cpp/src/IceStorm/TopicI.cpp b/cpp/src/IceStorm/TopicI.cpp index acea59e5c15..c500dd32ca2 100644 --- a/cpp/src/IceStorm/TopicI.cpp +++ b/cpp/src/IceStorm/TopicI.cpp @@ -441,11 +441,6 @@ TopicImpl::TopicImpl( __setNoDelete(false); } -TopicImpl::~TopicImpl() -{ - //cout << "~TopicImpl" << endl; -} - string TopicImpl::getName() const { diff --git a/cpp/src/IceStorm/TopicI.h b/cpp/src/IceStorm/TopicI.h index 78dbf5d937d..17b2050cf92 100644 --- a/cpp/src/IceStorm/TopicI.h +++ b/cpp/src/IceStorm/TopicI.h @@ -32,7 +32,6 @@ class TopicImpl : public IceUtil::Shared public: TopicImpl(const PersistentInstancePtr&, const std::string&, const Ice::Identity&, const SubscriberRecordSeq&); - ~TopicImpl(); std::string getName() const; Ice::ObjectPrx getPublisher() const; diff --git a/cpp/src/IceStorm/TopicManagerI.cpp b/cpp/src/IceStorm/TopicManagerI.cpp index 5c4ad1c6cbc..ef18c5cd476 100644 --- a/cpp/src/IceStorm/TopicManagerI.cpp +++ b/cpp/src/IceStorm/TopicManagerI.cpp @@ -43,11 +43,6 @@ public: { } - ~TopicManagerI() - { - //cout << "~TopicManagerI" << endl; - } - virtual TopicPrx create(const string& id, const Ice::Current&) { while(true) @@ -134,11 +129,6 @@ public: { } - ~ReplicaObserverI() - { - //cout << "~ReplicaObserverI" << endl; - } - virtual void init(const LogUpdate& llu, const TopicContentSeq& content, const Ice::Current&) { NodeIPtr node = _instance->node(); @@ -154,7 +144,6 @@ public: try { ObserverUpdateHelper unlock(_instance->node(), llu.generation, __FILE__, __LINE__); - //cout << "createTopic: " << llu.generation << " node generation: " << unlock.generation() << endl; _impl->observerCreateTopic(llu, name); } catch(const ObserverInconsistencyException& e) @@ -231,11 +220,6 @@ public: { } - ~TopicManagerSyncI() - { - //cout << "~TopicManagerSyncI" << endl; - } - virtual void getContent(LogUpdate& llu, TopicContentSeq& content, const Ice::Current&) { _impl->getContent(llu, content); @@ -325,11 +309,6 @@ TopicManagerImpl::TopicManagerImpl(const PersistentInstancePtr& instance) : __setNoDelete(false); } -TopicManagerImpl::~TopicManagerImpl() -{ - //cout << "~TopicManagerImpl" << endl; -} - TopicPrx TopicManagerImpl::create(const string& name) { diff --git a/cpp/src/IceStorm/TopicManagerI.h b/cpp/src/IceStorm/TopicManagerI.h index 2daa178b92a..43a13ecaf5e 100644 --- a/cpp/src/IceStorm/TopicManagerI.h +++ b/cpp/src/IceStorm/TopicManagerI.h @@ -41,7 +41,6 @@ class TopicManagerImpl : public IceStormElection::Replica, public: TopicManagerImpl(const PersistentInstancePtr&); - ~TopicManagerImpl(); // TopicManager methods. TopicPrx create(const std::string&); diff --git a/cpp/src/IceUtil/ConsoleUtil.cpp b/cpp/src/IceUtil/ConsoleUtil.cpp new file mode 100644 index 00000000000..ea743646685 --- /dev/null +++ b/cpp/src/IceUtil/ConsoleUtil.cpp @@ -0,0 +1,152 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <IceUtil/ConsoleUtil.h> +#include <IceUtil/MutexPtrLock.h> +#include <IceUtil/Mutex.h> + +using namespace IceUtilInternal; +using namespace std; + +#if defined(_WIN32) && !defined(ICE_OS_UWP) +namespace +{ + +IceUtil::Mutex* consoleMutex = 0; +ConsoleUtilPtr consoleUtil = 0; + +class Init +{ +public: + + Init() + { + consoleMutex = new IceUtil::Mutex; + consoleUtil = ICE_MAKE_SHARED(ConsoleUtil); + } + + ~Init() + { + delete consoleMutex; + consoleMutex = 0; + } +}; + +Init init; + +} + +const ConsoleUtilPtr& +IceUtilInternal::getConsoleUtil() +{ + return consoleUtil; +} + +ConsoleOut IceUtilInternal::consoleOut; +ConsoleErr IceUtilInternal::consoleErr; + +ConsoleUtil::ConsoleUtil() : + _converter(IceUtil::getProcessStringConverter()), + _consoleConverter(IceUtil::createWindowsStringConverter(GetConsoleOutputCP())) +{ +} + +string +ConsoleUtil::toConsoleEncoding(const string& message) const +{ + try + { + // Convert message to UTF-8 + string u8s = nativeToUTF8(message, _converter); + + // Then from UTF-8 to console CP + string consoleString; + _consoleConverter->fromUTF8(reinterpret_cast<const IceUtil::Byte* > (u8s.data()), + reinterpret_cast<const IceUtil::Byte*>(u8s.data() + u8s.size()), + consoleString); + + return consoleString; + } + catch(const IceUtil::IllegalConversionException&) + { + // + // If there is a problem with the encoding conversions we just + // return the original message without encoding conversions. + // + return message; + } +} + +void +ConsoleUtil::output(const string& message) const +{ + // + // Use fprintf_s to avoid encoding conversion when stderr is connected + // to Windows console. + // + fprintf_s(stdout, "%s", toConsoleEncoding(message).c_str()); +} + +void +ConsoleUtil::error(const string& message) const +{ + // + // Use fprintf_s to avoid encoding conversion when stderr is connected + // to Windows console. + // + fprintf_s(stderr, "%s", toConsoleEncoding(message).c_str()); +} + +ConsoleOut& +IceUtilInternal::endl(ConsoleOut& out) +{ + fprintf_s(stdout, "\n"); + fflush(stdout); + return out; +} + +ConsoleOut& +IceUtilInternal::flush(ConsoleOut& out) +{ + fflush(stdout); + return out; +} + +ConsoleOut& +ConsoleOut::operator<<(ConsoleOut& (*pf)(ConsoleOut&)) +{ + pf(*this); + return *this; +} + +ConsoleErr& +IceUtilInternal::endl(ConsoleErr& err) +{ + fprintf_s(stderr, "\n"); + fflush(stderr); + return err; +} + +ConsoleErr& +IceUtilInternal::flush(ConsoleErr& err) +{ + fflush(stderr); + return err; +} + +ConsoleErr& +ConsoleErr::operator<<(ConsoleErr& (*pf)(ConsoleErr&)) +{ + pf(*this); + return *this; +} +#else +std::ostream& IceUtilInternal::consoleOut = cout; +std::ostream& IceUtilInternal::consoleErr = cerr; +#endif diff --git a/cpp/src/IceUtil/StringConverter.cpp b/cpp/src/IceUtil/StringConverter.cpp index 2613efd6fe9..3f45154e90c 100644 --- a/cpp/src/IceUtil/StringConverter.cpp +++ b/cpp/src/IceUtil/StringConverter.cpp @@ -559,3 +559,135 @@ IceUtilInternal::fromUTF32(const vector<unsigned int>& source) } return result; } + +#ifdef _WIN32 + +namespace +{ +// +// Converts to/from UTF-8 using MultiByteToWideChar and WideCharToMultiByte +// +class WindowsStringConverter : public StringConverter +{ +public: + + explicit WindowsStringConverter(unsigned int); + + virtual Byte* toUTF8(const char*, const char*, UTF8Buffer&) const; + + virtual void fromUTF8(const Byte*, const Byte*, string& target) const; + +private: + unsigned int _cp; + WstringConverterPtr _unicodeConverter; + +}; + +WindowsStringConverter::WindowsStringConverter(unsigned int cp) : + _cp(cp), + _unicodeConverter(createUnicodeWstringConverter()) +{ +} + +Byte* +WindowsStringConverter::toUTF8(const char* sourceStart, const char* sourceEnd, UTF8Buffer& buffer) const +{ + // + // First convert to UTF-16 + // + int sourceSize = static_cast<int>(sourceEnd - sourceStart); + if(sourceSize == 0) + { + return buffer.getMoreBytes(1, 0); + } + + int writtenWchar = 0; + wstring wbuffer; + + // + // The following code pages doesn't support MB_ERR_INVALID_CHARS flag + // see http://msdn.microsoft.com/en-us/library/windows/desktop/dd319072(v=vs.85).aspx + // + DWORD flags = + (_cp == 50220 || _cp == 50221 || _cp == 50222 || + _cp == 50225 || _cp == 50227 || _cp == 50229 || + _cp == 65000 || _cp == 42 || (_cp >= 57002 && _cp <= 57011)) ? 0 : MB_ERR_INVALID_CHARS; + + do + { + wbuffer.resize(wbuffer.size() == 0 ? sourceSize + 2 : 2 * wbuffer.size()); + writtenWchar = MultiByteToWideChar(_cp, flags, sourceStart, sourceSize, + const_cast<wchar_t*>(wbuffer.data()), static_cast<int>(wbuffer.size())); + } while(writtenWchar == 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER); + + if(writtenWchar == 0) + { + throw IllegalConversionException(__FILE__, __LINE__, IceUtilInternal::lastErrorToString()); + } + + wbuffer.resize(static_cast<size_t>(writtenWchar)); + + // + // Then convert this UTF-16 wbuffer into UTF-8 + // + return _unicodeConverter->toUTF8(wbuffer.data(), wbuffer.data() + wbuffer.size(), buffer); +} + +void +WindowsStringConverter::fromUTF8(const Byte* sourceStart, const Byte* sourceEnd, string& target) const +{ + if(sourceStart == sourceEnd) + { + target = ""; + return; + } + + if(_cp == CP_UTF8) + { + string tmp(reinterpret_cast<const char*>(sourceStart), sourceEnd - sourceStart); + tmp.swap(target); + return; + } + + // + // First convert to wstring (UTF-16) + // + wstring wtarget; + _unicodeConverter->fromUTF8(sourceStart, sourceEnd, wtarget); + + // + // WC_ERR_INVALID_CHARS conversion flag is only supported with 65001 (UTF-8) and + // 54936 (GB18030 Simplified Chinese) + // + DWORD flags = (_cp == 65001 || _cp == 54936) ? WC_ERR_INVALID_CHARS : 0; + + // + // And then to a multi-byte narrow string + // + int writtenChar = -1; + do + { + target.resize(writtenChar == -1 ? + std::max<size_t>(sourceEnd - sourceStart + 2, target.size()) : + 2 * target.size()); + + writtenChar = WideCharToMultiByte(_cp, flags, wtarget.data(), static_cast<int>(wtarget.size()), + const_cast<char*>(target.data()), static_cast<int>(target.size()), + 0, 0); + } while(writtenChar == 0 && GetLastError() == ERROR_INSUFFICIENT_BUFFER); + + if(writtenChar == 0) + { + throw IllegalConversionException(__FILE__, __LINE__, IceUtilInternal::lastErrorToString()); + } + + target.resize(static_cast<size_t>(writtenChar)); +} +} + +StringConverterPtr +IceUtil::createWindowsStringConverter(unsigned int cp) +{ + return ICE_MAKE_SHARED(WindowsStringConverter, cp); +} +#endif diff --git a/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj b/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj index d86da65daa5..a2e0f10fc22 100644 --- a/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj +++ b/cpp/src/IceUtil/msbuild/iceutil/iceutil.vcxproj @@ -87,6 +87,7 @@ </ClCompile> </ItemDefinitionGroup> <ItemGroup> + <ClCompile Include="..\..\ConsoleUtil.cpp" /> <ClCompile Include="..\..\CtrlCHandler.cpp" /> <ClCompile Include="..\..\OutputUtil.cpp" /> <ClCompile Include="..\..\RecMutex.cpp" /> @@ -106,6 +107,7 @@ <ClInclude Include="..\..\..\..\include\IceUtil\Atomic.h" /> <ClInclude Include="..\..\..\..\include\IceUtil\Cond.h" /> <ClInclude Include="..\..\..\..\include\IceUtil\Config.h" /> + <ClInclude Include="..\..\..\..\include\IceUtil\ConsoleUtil.h" /> <ClInclude Include="..\..\..\..\include\IceUtil\CountDownLatch.h" /> <ClInclude Include="..\..\..\..\include\IceUtil\CtrlCHandler.h" /> <ClInclude Include="..\..\..\..\include\IceUtil\DisableWarnings.h" /> diff --git a/cpp/src/Slice/FileTracker.cpp b/cpp/src/Slice/FileTracker.cpp index e57de914e31..fbba124fc3b 100644 --- a/cpp/src/Slice/FileTracker.cpp +++ b/cpp/src/Slice/FileTracker.cpp @@ -7,7 +7,9 @@ // // ********************************************************************** + #include <Slice/FileTracker.h> +#include <IceUtil/ConsoleUtil.h> #ifdef _WIN32 # include <direct.h> @@ -15,6 +17,7 @@ # include <unistd.h> #endif +using namespace IceUtilInternal; using namespace std; Slice::FileException::FileException(const char* file, int line, const string& r) : @@ -149,30 +152,30 @@ Slice::FileTracker::cleanup() void Slice::FileTracker::dumpxml() { - cout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl; + consoleOut << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl; - cout << "<generated>" << endl; + consoleOut << "<generated>" << endl; for(map<string, string>::const_iterator p = _errors.begin(); p != _errors.end(); ++p) { - cout << " <source name=\"" << p->first << "\""; + consoleOut << " <source name=\"" << p->first << "\""; map<string, list<string> >::const_iterator q = _generated.find(p->first); if(q == _generated.end()) { - cout << " error=\"true\">" << endl; + consoleOut << " error=\"true\">" << endl; } else { - cout << ">" << endl; + consoleOut << ">" << endl; for(list<string>::const_iterator r = q->second.begin(); r != q->second.end(); ++r) { - cout << " <file name=\"" << *r << "\"/>" << endl; + consoleOut << " <file name=\"" << *r << "\"/>" << endl; } } - cout << " <output>" << escape(p->second) << "</output>" << endl; - cout << " </source>" << endl; + consoleOut << " <output>" << escape(p->second) << "</output>" << endl; + consoleOut << " </source>" << endl; } - cout << "</generated>" << endl; + consoleOut << "</generated>" << endl; } string diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp index 2e0192edab9..03815d4b4d6 100644 --- a/cpp/src/Slice/Preprocessor.cpp +++ b/cpp/src/Slice/Preprocessor.cpp @@ -13,6 +13,7 @@ #include <IceUtil/StringConverter.h> #include <IceUtil/FileUtil.h> #include <IceUtil/UUID.h> +#include <IceUtil/ConsoleUtil.h> #include <algorithm> #include <iterator> #include <vector> @@ -27,6 +28,7 @@ using namespace std; using namespace Slice; +using namespace IceUtilInternal; // // mcpp defines @@ -274,10 +276,7 @@ Slice::Preprocessor::preprocess(bool keepComments, const vector<string>& extraAr } else { - ostream& os = getErrorStream(); - os << _path << ": error: could not open temporary file: "; - os << _cppFile; - os << endl; + consoleErr << _path << ": error: could not open temporary file: " << _cppFile << endl; } } @@ -764,14 +763,14 @@ Slice::Preprocessor::checkInputFile() } if(suffix != ".ice") { - getErrorStream() << _path << ": error: input files must end with `.ice'" << endl; + consoleErr << _path << ": error: input files must end with `.ice'" << endl; return false; } ifstream test(IceUtilInternal::streamFilename(_fileName).c_str()); if(!test) { - getErrorStream() << _path << ": error: cannot open `" << _fileName << "' for reading" << endl; + consoleErr << _path << ": error: cannot open `" << _fileName << "' for reading" << endl; return false; } test.close(); diff --git a/cpp/src/Slice/Python.cpp b/cpp/src/Slice/Python.cpp index e5d7ce8760a..6080c23d3c0 100644 --- a/cpp/src/Slice/Python.cpp +++ b/cpp/src/Slice/Python.cpp @@ -14,6 +14,7 @@ #include <IceUtil/CtrlCHandler.h> #include <IceUtil/Mutex.h> #include <IceUtil/MutexPtrLock.h> +#include <IceUtil/ConsoleUtil.h> // BUGFIX: With MSVC2013 if this isn't included you get strange linker errors. #include <IceUtil/FileUtil.h> #include <Slice/Preprocessor.h> @@ -38,6 +39,7 @@ using namespace std; using namespace Slice; using namespace Slice::Python; +using namespace IceUtilInternal; namespace { @@ -383,8 +385,8 @@ PackageVisitor::writeInit(const string& dir, const string& name, const StringLis void usage(const string& n) { - getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; - getErrorStream() << + consoleErr << "Usage: " << n << " [options] slice-files...\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -436,7 +438,7 @@ Slice::Python::compile(const vector<string>& argv) } catch(const IceUtilInternal::BadOptException& e) { - getErrorStream() << argv[0] << ": error: " << e.reason << endl; + consoleErr << argv[0] << ": error: " << e.reason << endl; usage(argv[0]); return EXIT_FAILURE; } @@ -449,7 +451,7 @@ Slice::Python::compile(const vector<string>& argv) if(opts.isSet("version")) { - getErrorStream() << ICE_STRING_VERSION << endl; + consoleErr << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -500,21 +502,21 @@ Slice::Python::compile(const vector<string>& argv) if(args.empty()) { - getErrorStream() << argv[0] << ": error: no input file" << endl; + consoleErr << argv[0] << ": error: no input file" << endl; usage(argv[0]); return EXIT_FAILURE; } if(depend && dependxml) { - getErrorStream() << argv[0] << ": error: cannot specify both --depend and --dependxml" << endl; + consoleErr << argv[0] << ": error: cannot specify both --depend and --dependxml" << endl; usage(argv[0]); return EXIT_FAILURE; } if(noPackage && buildPackage) { - getErrorStream() << argv[0] << ": error: cannot specify both --no-package and --build-package" << endl; + consoleErr << argv[0] << ": error: cannot specify both --no-package and --build-package" << endl; usage(argv[0]); return EXIT_FAILURE; } @@ -526,10 +528,10 @@ Slice::Python::compile(const vector<string>& argv) bool keepComments = true; - DependOutputUtil out(dependFile); + ostringstream os; if(dependxml) { - out.os() << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; + os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; } for(vector<string>::const_iterator i = args.begin(); i != args.end(); ++i) @@ -550,7 +552,6 @@ Slice::Python::compile(const vector<string>& argv) if(cppHandle == 0) { - out.cleanup(); return EXIT_FAILURE; } @@ -560,20 +561,17 @@ Slice::Python::compile(const vector<string>& argv) if(parseStatus == EXIT_FAILURE) { - out.cleanup(); return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(out.os(), depend ? Preprocessor::Python : Preprocessor::SliceXML, + if(!icecpp->printMakefileDependencies(os, depend ? Preprocessor::Python : Preprocessor::SliceXML, includePaths, "-D__SLICE2PY__", "", prefix)) { - out.cleanup(); return EXIT_FAILURE; } if(!icecpp->close()) { - out.cleanup(); return EXIT_FAILURE; } } @@ -687,13 +685,13 @@ Slice::Python::compile(const vector<string>& argv) // FileTracker::instance()->cleanup(); u->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + consoleErr << argv[0] << ": error: " << ex.reason() << endl; return EXIT_FAILURE; } catch(const string& err) { FileTracker::instance()->cleanup(); - getErrorStream() << argv[0] << ": error: " << err << endl; + consoleErr << argv[0] << ": error: " << err << endl; status = EXIT_FAILURE; } } @@ -707,7 +705,6 @@ Slice::Python::compile(const vector<string>& argv) if(interrupted) { - out.cleanup(); FileTracker::instance()->cleanup(); return EXIT_FAILURE; } @@ -716,7 +713,12 @@ Slice::Python::compile(const vector<string>& argv) if(dependxml) { - out.os() << "</dependencies>\n"; + os << "</dependencies>\n"; + } + + if(depend || dependxml) + { + writeDependencies(os.str(), dependFile); } return status; diff --git a/cpp/src/Slice/Ruby.cpp b/cpp/src/Slice/Ruby.cpp index fe0a05ad0e2..d53fc353b5a 100644 --- a/cpp/src/Slice/Ruby.cpp +++ b/cpp/src/Slice/Ruby.cpp @@ -12,6 +12,7 @@ #include <IceUtil/CtrlCHandler.h> #include <IceUtil/Mutex.h> #include <IceUtil/MutexPtrLock.h> +#include <IceUtil/ConsoleUtil.h> #include <Slice/Preprocessor.h> #include <Slice/FileTracker.h> #include <Slice/RubyUtil.h> @@ -22,6 +23,7 @@ using namespace std; using namespace Slice; using namespace Slice::Ruby; +using namespace IceUtilInternal; namespace { @@ -58,8 +60,8 @@ interruptedCallback(int /*signal*/) void usage(const string& n) { - getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; - getErrorStream() << + consoleErr << "Usage: " << n << " [options] slice-files...\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -111,7 +113,7 @@ Slice::Ruby::compile(const vector<string>& argv) } catch(const IceUtilInternal::BadOptException& e) { - getErrorStream() << argv[0] << ": error: " << e.reason << endl; + consoleErr << argv[0] << ": error: " << e.reason << endl; usage(argv[0]); return EXIT_FAILURE; } @@ -124,7 +126,7 @@ Slice::Ruby::compile(const vector<string>& argv) if(opts.isSet("version")) { - getErrorStream() << ICE_STRING_VERSION << endl; + consoleErr << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -169,14 +171,14 @@ Slice::Ruby::compile(const vector<string>& argv) if(args.empty()) { - getErrorStream() << argv[0] << ": error: no input file" << endl; + consoleErr << argv[0] << ": error: no input file" << endl; usage(argv[0]); return EXIT_FAILURE; } if(depend && dependxml) { - getErrorStream() << argv[0] << ": error: cannot specify both --depend and --dependxml" << endl; + consoleErr << argv[0] << ": error: cannot specify both --depend and --dependxml" << endl; usage(argv[0]); return EXIT_FAILURE; } @@ -186,10 +188,10 @@ Slice::Ruby::compile(const vector<string>& argv) IceUtil::CtrlCHandler ctrlCHandler; ctrlCHandler.setCallback(interruptedCallback); - DependOutputUtil out(dependFile); + ostringstream os; if(dependxml) { - out.os() << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; + os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; } for(vector<string>::const_iterator i = args.begin(); i != args.end(); ++i) @@ -210,7 +212,6 @@ Slice::Ruby::compile(const vector<string>& argv) if(cppHandle == 0) { - out.cleanup(); return EXIT_FAILURE; } @@ -220,20 +221,17 @@ Slice::Ruby::compile(const vector<string>& argv) if(parseStatus == EXIT_FAILURE) { - out.cleanup(); return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(out.os(), depend ? Preprocessor::Ruby : Preprocessor::SliceXML, includePaths, + if(!icecpp->printMakefileDependencies(os, depend ? Preprocessor::Ruby : Preprocessor::SliceXML, includePaths, "-D__SLICE2RB__")) { - out.cleanup(); return EXIT_FAILURE; } if(!icecpp->close()) { - out.cleanup(); return EXIT_FAILURE; } } @@ -323,7 +321,7 @@ Slice::Ruby::compile(const vector<string>& argv) // any created files. FileTracker::instance()->cleanup(); u->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + consoleErr << argv[0] << ": error: " << ex.reason() << endl; return EXIT_FAILURE; } } @@ -337,7 +335,6 @@ Slice::Ruby::compile(const vector<string>& argv) if(interrupted) { - out.cleanup(); FileTracker::instance()->cleanup(); return EXIT_FAILURE; } @@ -346,7 +343,12 @@ Slice::Ruby::compile(const vector<string>& argv) if(dependxml) { - out.os() << "</dependencies>\n"; + os << "</dependencies>\n"; + } + + if(depend || dependxml) + { + writeDependencies(os.str(), dependFile); } return status; diff --git a/cpp/src/Slice/SliceUtil.cpp b/cpp/src/Slice/SliceUtil.cpp index 09dd9e312ec..b148b91dea7 100644 --- a/cpp/src/Slice/SliceUtil.cpp +++ b/cpp/src/Slice/SliceUtil.cpp @@ -7,11 +7,15 @@ // // ********************************************************************** +#include <IceUtil/DisableWarnings.h> #include <Slice/Util.h> +#include <Slice/FileTracker.h> #include <IceUtil/FileUtil.h> #include <IceUtil/StringUtil.h> #include <IceUtil/StringConverter.h> +#include <IceUtil/ConsoleUtil.h> #include <climits> +#include <cstring> #ifndef _MSC_VER # include <unistd.h> // For readlink() @@ -19,6 +23,7 @@ using namespace std; using namespace Slice; +using namespace IceUtilInternal; namespace { @@ -210,38 +215,19 @@ Slice::changeInclude(const string& p, const vector<string>& includePaths) return result; } -namespace -{ - -ostream* errorStream = &cerr; - -} - -void -Slice::setErrorStream(ostream& stream) -{ - errorStream = &stream; -} - -ostream& -Slice::getErrorStream() -{ - return *errorStream; -} - void Slice::emitError(const string& file, int line, const string& message) { if(!file.empty()) { - *errorStream << file; + consoleErr << file; if(line != -1) { - *errorStream << ':' << line; + consoleErr << ':' << line; } - *errorStream << ": "; + consoleErr << ": "; } - *errorStream << message << endl; + consoleErr << message << endl; } void @@ -249,14 +235,14 @@ Slice::emitWarning(const string& file, int line, const string& message) { if(!file.empty()) { - *errorStream << file; + consoleErr << file; if(line != -1) { - *errorStream << ':' << line; + consoleErr << ':' << line; } - *errorStream << ": "; + consoleErr << ": "; } - *errorStream << "warning: " << message << endl; + consoleErr << "warning: " << message << endl; } void @@ -264,14 +250,14 @@ Slice::emitError(const string& file, const std::string& line, const string& mess { if(!file.empty()) { - *errorStream << file; + consoleErr << file; if(!line.empty()) { - *errorStream << ':' << line; + consoleErr << ':' << line; } - *errorStream << ": "; + consoleErr << ": "; } - *errorStream << message << endl; + consoleErr << message << endl; } void @@ -279,20 +265,20 @@ Slice::emitWarning(const string& file, const std::string& line, const string& me { if(!file.empty()) { - *errorStream << file; + consoleErr << file; if(!line.empty()) { - *errorStream << ':' << line; + consoleErr << ':' << line; } - *errorStream << ": "; + consoleErr << ": "; } - *errorStream << "warning: " << message << endl; + consoleErr << "warning: " << message << endl; } void Slice::emitRaw(const char* message) { - *errorStream << message << flush; + consoleErr << message << flush; } vector<string> @@ -398,41 +384,27 @@ Slice::printGeneratedHeader(IceUtilInternal::Output& out, const string& path, co out << comment << "\n"; } -Slice::DependOutputUtil::DependOutputUtil(string& file) : _file(file) +void +Slice::writeDependencies(const string& dependencies, const string& dependFile) { - if(!_file.empty()) + if(dependFile.empty()) { - _os.open(file.c_str(), ios::out); + consoleOut << dependencies << flush; } -} - -Slice::DependOutputUtil::~DependOutputUtil() -{ - if(!_file.empty() && _os.is_open()) + else { - _os.close(); - } -} - -void -Slice::DependOutputUtil::cleanup() -{ - if(!_file.empty()) - { - if(_os.is_open()) + ofstream of(IceUtilInternal::streamFilename(dependFile).c_str()); // dependFile is a UTF-8 string + if(!of) { - _os.close(); + ostringstream os; + os << "cannot open file `" << dependFile << "': " << strerror(errno); + throw Slice::FileException(__FILE__, __LINE__, os.str()); } - IceUtilInternal::unlink(_file); + of << dependencies; + of.close(); } } -ostream& -Slice::DependOutputUtil::os() -{ - return _file.empty() ? cout : _os; -} - #ifdef _WIN32 vector<string> Slice::argvToArgs(int argc, wchar_t* argv[]) diff --git a/cpp/src/Slice/Util.h b/cpp/src/Slice/Util.h index 5b23acf389c..783b0973d3e 100644 --- a/cpp/src/Slice/Util.h +++ b/cpp/src/Slice/Util.h @@ -13,16 +13,11 @@ #include <Slice/Parser.h> #include <IceUtil/OutputUtil.h> -#include <ostream> -#include <fstream> - namespace Slice { std::string fullPath(const std::string&); std::string changeInclude(const std::string&, const std::vector<std::string>&); -void setErrorStream(std::ostream&); -std::ostream& getErrorStream(); void emitError(const std::string&, int, const std::string&); void emitWarning(const std::string&, int, const std::string&); void emitError(const std::string&, const std::string&, const std::string&); @@ -53,20 +48,8 @@ std::string toStringLiteral(const std::string&, const std::string&, const std::string&, EscapeMode, unsigned char); -class DependOutputUtil : IceUtil::noncopyable -{ -public: - - DependOutputUtil(std::string& file); - ~DependOutputUtil(); - void cleanup(); - std::ostream& os(); - -private: - - const std::string _file; - std::ofstream _os; -}; +void +writeDependencies(const std::string&, const std::string&); } diff --git a/cpp/src/icegriddb/IceGridDB.cpp b/cpp/src/icegriddb/IceGridDB.cpp index 8426d773d63..8fdabee0f5b 100644 --- a/cpp/src/icegriddb/IceGridDB.cpp +++ b/cpp/src/icegriddb/IceGridDB.cpp @@ -10,6 +10,7 @@ #include <IceUtil/Options.h> #include <IceUtil/FileUtil.h> #include <Ice/Ice.h> +#include <Ice/ConsoleUtil.h> #include <IceDB/IceDB.h> #include <IceGrid/Admin.h> #include <IceGrid/DBTypes.h> @@ -19,6 +20,7 @@ using namespace std; using namespace Ice; +using namespace IceInternal; using namespace IceGrid; namespace @@ -110,7 +112,6 @@ struct StreamReader<IceGrid::ReplicaGroupDescriptor, Ice::InputStream> { static void read(Ice::InputStream* is, IceGrid::ReplicaGroupDescriptor& v) { - // cerr << "Custom read" << endl; is->read(v.id); is->read(v.loadBalancing); is->read(v.proxyOptions); @@ -152,8 +153,8 @@ main(int argc, char* argv[]) void Client::usage() { - cerr << "Usage: " << appName() << " <options>\n"; - cerr << + consoleErr << "Usage: " << appName() << " <options>\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display version.\n" @@ -188,13 +189,13 @@ Client::run(int argc, char* argv[]) } catch(const IceUtilInternal::BadOptException& e) { - cerr << argv[0] << ": " << e.reason << endl; + consoleErr << argv[0] << ": " << e.reason << endl; usage(); return EXIT_FAILURE; } if(!args.empty()) { - cerr << argv[0] << ": too many arguments" << endl; + consoleErr << argv[0] << ": too many arguments" << endl; usage(); return EXIT_FAILURE; } @@ -207,20 +208,20 @@ Client::run(int argc, char* argv[]) if(opts.isSet("version")) { - cout << ICE_STRING_VERSION << endl; + consoleOut << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } if(!(opts.isSet("import") ^ opts.isSet("export"))) { - cerr << argv[0] << ": either --import or --export must be set" << endl; + consoleErr << argv[0] << ": either --import or --export must be set" << endl; usage(); return EXIT_FAILURE; } if(!(opts.isSet("dbhome") ^ opts.isSet("dbpath"))) { - cerr << argv[0] << ": set the database environment directory with either --dbhome or --dbpath" << endl; + consoleErr << argv[0] << ": set the database environment directory with either --dbhome or --dbpath" << endl; usage(); return EXIT_FAILURE; } @@ -253,24 +254,25 @@ Client::run(int argc, char* argv[]) if(import) { - cout << "Importing database to directory `" << dbPath << "' from file `" << dbFile << "'" << endl; + consoleOut << "Importing database to directory `" << dbPath << "' from file `" << dbFile << "'" + << endl; if(!IceUtilInternal::directoryExists(dbPath)) { - cerr << argv[0] << ": output directory does not exist: " << dbPath << endl; + consoleErr << argv[0] << ": output directory does not exist: " << dbPath << endl; return EXIT_FAILURE; } if(!IceUtilInternal::isEmptyDirectory(dbPath)) { - cerr << argv[0] << ": output directory is not empty: " << dbPath << endl; + consoleErr << argv[0] << ": output directory is not empty: " << dbPath << endl; return EXIT_FAILURE; } ifstream fs(IceUtilInternal::streamFilename(dbFile).c_str(), ios::binary); if(fs.fail()) { - cerr << argv[0] << ": could not open input file: " << strerror(errno) << endl; + consoleErr << argv[0] << ": could not open input file: " << strerror(errno) << endl; return EXIT_FAILURE; } fs.unsetf(ios::skipws); @@ -281,7 +283,7 @@ Client::run(int argc, char* argv[]) if(!fileSize) { fs.close(); - cerr << argv[0] << ": empty input file" << endl; + consoleErr << argv[0] << ": empty input file" << endl; return EXIT_FAILURE; } @@ -308,7 +310,7 @@ Client::run(int argc, char* argv[]) stream.read(type); if(type != "IceGrid") { - cerr << argv[0] << ": incorrect input file type: " << type << endl; + consoleErr << argv[0] << ": incorrect input file type: " << type << endl; return EXIT_FAILURE; } stream.read(version); @@ -316,7 +318,7 @@ Client::run(int argc, char* argv[]) { if(debug) { - cout << "Reading Ice 3.5.x data" << endl; + consoleOut << "Reading Ice 3.5.x data" << endl; } skipReplicaGroupFilter = true; } @@ -328,7 +330,7 @@ Client::run(int argc, char* argv[]) if(debug) { - cout << "Writing Applications Map:" << endl; + consoleOut << "Writing Applications Map:" << endl; } IceDB::Dbi<string, ApplicationInfo, IceDB::IceContext, Ice::OutputStream> @@ -338,14 +340,14 @@ Client::run(int argc, char* argv[]) { if(debug) { - cout << " NAME = " << p->descriptor.name << endl; + consoleOut << " NAME = " << p->descriptor.name << endl; } apps.put(txn, p->descriptor.name, *p); } if(debug) { - cout << "Writing Adapters Map:" << endl; + consoleOut << "Writing Adapters Map:" << endl; } IceDB::Dbi<string, AdapterInfo, IceDB::IceContext, Ice::OutputStream> @@ -355,14 +357,14 @@ Client::run(int argc, char* argv[]) { if(debug) { - cout << " NAME = " << p->id << endl; + consoleOut << " NAME = " << p->id << endl; } adpts.put(txn, p->id, *p); } if(debug) { - cout << "Writing Objects Map:" << endl; + consoleOut << "Writing Objects Map:" << endl; } IceDB::Dbi<Identity, ObjectInfo, IceDB::IceContext, Ice::OutputStream> @@ -372,14 +374,15 @@ Client::run(int argc, char* argv[]) { if(debug) { - cout << " NAME = " << communicator()->identityToString(p->proxy->ice_getIdentity()) << endl; + consoleOut << " NAME = " << communicator()->identityToString(p->proxy->ice_getIdentity()) + << endl; } objs.put(txn, p->proxy->ice_getIdentity(), *p); } if(debug) { - cout << "Writing Internal Objects Map:" << endl; + consoleOut << "Writing Internal Objects Map:" << endl; } IceDB::Dbi<Identity, ObjectInfo, IceDB::IceContext, Ice::OutputStream> @@ -390,14 +393,15 @@ Client::run(int argc, char* argv[]) { if(debug) { - cout << " NAME = " << communicator()->identityToString(p->proxy->ice_getIdentity()) << endl; + consoleOut << " NAME = " << communicator()->identityToString(p->proxy->ice_getIdentity()) + << endl; } internalObjs.put(txn, p->proxy->ice_getIdentity(), *p); } if(debug) { - cout << "Writing Serials Map:" << endl; + consoleOut << "Writing Serials Map:" << endl; } IceDB::Dbi<string, Long, IceDB::IceContext, Ice::OutputStream> @@ -407,7 +411,7 @@ Client::run(int argc, char* argv[]) { if(debug) { - cout << " NAME = " << p->first << endl; + consoleOut << " NAME = " << p->first << endl; } srls.put(txn, p->first, p->second); } @@ -418,7 +422,8 @@ Client::run(int argc, char* argv[]) } else { - cout << "Exporting database from directory `" << dbPath << "' to file `" << dbFile << "'" << endl; + consoleOut << "Exporting database from directory `" << dbPath << "' to file `" << dbFile << "'" + << endl; { IceDB::Env env(dbPath, 5); @@ -426,7 +431,7 @@ Client::run(int argc, char* argv[]) if(debug) { - cout << "Reading Application Map:" << endl; + consoleOut << "Reading Application Map:" << endl; } IceDB::Dbi<string, IceGrid::ApplicationInfo, IceDB::IceContext, Ice::OutputStream> @@ -440,7 +445,7 @@ Client::run(int argc, char* argv[]) { if(debug) { - cout << " APPLICATION = " << name << endl; + consoleOut << " APPLICATION = " << name << endl; } data.applications.push_back(application); } @@ -448,7 +453,7 @@ Client::run(int argc, char* argv[]) if(debug) { - cout << "Reading Adapter Map:" << endl; + consoleOut << "Reading Adapter Map:" << endl; } IceDB::Dbi<string, IceGrid::AdapterInfo, IceDB::IceContext, Ice::OutputStream> @@ -461,7 +466,7 @@ Client::run(int argc, char* argv[]) { if(debug) { - cout << " ADAPTER = " << name << endl; + consoleOut << " ADAPTER = " << name << endl; } data.adapters.push_back(adapter); } @@ -469,7 +474,7 @@ Client::run(int argc, char* argv[]) if(debug) { - cout << "Reading Object Map:" << endl; + consoleOut << "Reading Object Map:" << endl; } IceDB::Dbi<Identity, IceGrid::ObjectInfo, IceDB::IceContext, Ice::OutputStream> @@ -483,7 +488,7 @@ Client::run(int argc, char* argv[]) { if(debug) { - cout << " IDENTITY = " << communicator()->identityToString(id) << endl; + consoleOut << " IDENTITY = " << communicator()->identityToString(id) << endl; } data.objects.push_back(object); } @@ -491,7 +496,7 @@ Client::run(int argc, char* argv[]) if(debug) { - cout << "Reading Internal Object Map:" << endl; + consoleOut << "Reading Internal Object Map:" << endl; } IceDB::Dbi<Identity, IceGrid::ObjectInfo, IceDB::IceContext, Ice::OutputStream> @@ -503,7 +508,7 @@ Client::run(int argc, char* argv[]) { if(debug) { - cout << " IDENTITY = " << communicator()->identityToString(id) << endl; + consoleOut << " IDENTITY = " << communicator()->identityToString(id) << endl; } data.internalObjects.push_back(object); } @@ -511,7 +516,7 @@ Client::run(int argc, char* argv[]) if(debug) { - cout << "Reading Serials Map:" << endl; + consoleOut << "Reading Serials Map:" << endl; } IceDB::Dbi<string, Long, IceDB::IceContext, Ice::OutputStream> @@ -524,7 +529,7 @@ Client::run(int argc, char* argv[]) { if(debug) { - cout << " NAME = " << name << endl; + consoleOut << " NAME = " << name << endl; } data.serials.insert(std::make_pair(name, serial)); } @@ -542,7 +547,7 @@ Client::run(int argc, char* argv[]) ofstream fs(IceUtilInternal::streamFilename(dbFile).c_str(), ios::binary); if(fs.fail()) { - cerr << argv[0] << ": could not open output file: " << strerror(errno) << endl; + consoleErr << argv[0] << ": could not open output file: " << strerror(errno) << endl; return EXIT_FAILURE; } fs.write(reinterpret_cast<const char*>(stream.b.begin()), stream.b.size()); @@ -551,7 +556,7 @@ Client::run(int argc, char* argv[]) } catch(const IceUtil::Exception& ex) { - cerr << argv[0] << ": " << (import ? "import" : "export") << " failed:\n" << ex << endl; + consoleErr << argv[0] << ": " << (import ? "import" : "export") << " failed:\n" << ex << endl; return EXIT_FAILURE; } diff --git a/cpp/src/iceserviceinstall/Install.cpp b/cpp/src/iceserviceinstall/Install.cpp index b71b6280ef0..73fe9681895 100644 --- a/cpp/src/iceserviceinstall/Install.cpp +++ b/cpp/src/iceserviceinstall/Install.cpp @@ -8,11 +8,13 @@ // ********************************************************************** #include <Ice/Ice.h> +#include <Ice/ConsoleUtil.h> #include <IceUtil/Options.h> #include <ServiceInstaller.h> using namespace std; using namespace Ice; +using namespace IceInternal; class Install : public Application { @@ -74,7 +76,7 @@ Install::run(int argc, char* argv[]) } catch(const IceUtilInternal::BadOptException& e) { - cerr << "Error:" << e.reason << endl; + consoleErr << "Error:" << e.reason << endl; usage(); return EXIT_FAILURE; } @@ -89,7 +91,7 @@ Install::run(int argc, char* argv[]) } if(opts.isSet("version")) { - cout << ICE_STRING_VERSION << endl; + consoleOut << ICE_STRING_VERSION << endl; _pause = true; return EXIT_SUCCESS; } @@ -112,7 +114,7 @@ Install::run(int argc, char* argv[]) if(serviceType == -1) { - cerr << "Invalid service " << commands[0] << endl; + consoleErr << "Invalid service " << commands[0] << endl; return EXIT_FAILURE; } @@ -145,12 +147,12 @@ Install::run(int argc, char* argv[]) } catch(const string& msg) { - cerr << "Error: " << msg << endl; + consoleErr << "Error: " << msg << endl; return EXIT_FAILURE; } catch(const Ice::Exception& ex) { - cerr << "Error: " << ex << endl; + consoleErr << "Error: " << ex << endl; return EXIT_FAILURE; } return EXIT_SUCCESS; @@ -195,9 +197,9 @@ Install::usage() const #endif defaultImagePath += ".exe"; - cerr << "Usage: " << appName() + consoleErr << "Usage: " << appName() << " [options] service config-file [property] [property]\n"; - cerr << + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-n, --nopause Do not call pause after displaying a message.\n" diff --git a/cpp/src/slice2confluence/ConfluenceOutput.cpp b/cpp/src/slice2confluence/ConfluenceOutput.cpp index a1176f7cc37..cac2dc645e4 100644 --- a/cpp/src/slice2confluence/ConfluenceOutput.cpp +++ b/cpp/src/slice2confluence/ConfluenceOutput.cpp @@ -1,3 +1,13 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <IceUtil/ConsoleUtil.h> #include <ConfluenceOutput.h> #include <iostream> #include <sstream> @@ -795,8 +805,8 @@ Confluence::ConfluenceOutput::getMarkerLimits(const string& str) } else { - cerr << "getEscaperLimits FOUND START OF ESCAPE MARKER WITH NO MATCHING END IN STRING:" << endl - << str.substr(start) << endl; + consoleErr << "getEscaperLimits FOUND START OF ESCAPE MARKER WITH NO MATCHING END IN STRING:" + << endl << str.substr(start) << endl; break; } } diff --git a/cpp/src/slice2confluence/ConfluenceOutput.h b/cpp/src/slice2confluence/ConfluenceOutput.h index a97577c39c5..d7e9e0b4637 100644 --- a/cpp/src/slice2confluence/ConfluenceOutput.h +++ b/cpp/src/slice2confluence/ConfluenceOutput.h @@ -1,3 +1,12 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2016 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + #ifndef CONFLUENCE_OUTPUT #define CONFLUENCE_OUTPUT diff --git a/cpp/src/slice2confluence/Gen.cpp b/cpp/src/slice2confluence/Gen.cpp index b97445781f1..44890c0d368 100644 --- a/cpp/src/slice2confluence/Gen.cpp +++ b/cpp/src/slice2confluence/Gen.cpp @@ -11,6 +11,7 @@ #include <IceUtil/Functional.h> #include <IceUtil/StringUtil.h> #include <IceUtil/FileUtil.h> +#include <IceUtil/ConsoleUtil.h> #include <Slice/FileTracker.h> #include <Gen.h> #include <string.h> @@ -1228,8 +1229,8 @@ Slice::GeneratorBase::getComment(const ContainedPtr& contained, const ContainerP if(_warnOldCommentFiles.find(fileName) == _warnOldCommentFiles.end()) { _warnOldCommentFiles.insert(fileName); - cerr << fileName << ": warning: file contains old-style javadoc link syntax: `[" << literal << "]'" - << endl; + consoleErr << fileName << ": warning: file contains old-style javadoc link syntax: `[" << literal + << "]'" << endl; } } else if(s[i] == '{') @@ -1271,8 +1272,8 @@ Slice::GeneratorBase::getComment(const ContainedPtr& contained, const ContainerP if(summary && _warnSummary && summarySize > _warnSummary) { - cerr << contained->file() << ": warning: summary size (" << summarySize << ") exceeds " << _warnSummary - << " characters: `" << comment << "'" << endl; + consoleErr << contained->file() << ": warning: summary size (" << summarySize << ") exceeds " << _warnSummary + << " characters: `" << comment << "'" << endl; } return trim(_out.convertCommentHTML(removeNewlines(comment))); } @@ -1706,13 +1707,13 @@ Slice::GeneratorBase::warnOldStyleIdent(const string& str, const string& fileNam lastName = newName.substr(pos + 1); } - cerr << fileName << ": warning: file contains old-style javadoc identifier syntax: `" << str << "'." - << " Use `'" << newName << "'"; + consoleErr << fileName << ": warning: file contains old-style javadoc identifier syntax: `" << str << "'." + << " Use `'" << newName << "'"; if(!alternateName.empty()) { - cerr << " or `" << alternateName << "' if `" << lastName << "' is a member"; + consoleErr << " or `" << alternateName << "' if `" << lastName << "' is a member"; } - cerr << endl; + consoleErr << endl; } } diff --git a/cpp/src/slice2confluence/Main.cpp b/cpp/src/slice2confluence/Main.cpp index ad6b22c9307..38a38ff8d87 100644 --- a/cpp/src/slice2confluence/Main.cpp +++ b/cpp/src/slice2confluence/Main.cpp @@ -11,6 +11,7 @@ #include <IceUtil/CtrlCHandler.h> #include <IceUtil/Mutex.h> #include <IceUtil/MutexPtrLock.h> +#include <IceUtil/ConsoleUtil.h> #include <Slice/Preprocessor.h> #include <Slice/FileTracker.h> #include <Slice/Util.h> @@ -19,7 +20,7 @@ using namespace std; using namespace Slice; -using namespace IceUtil; +using namespace IceUtilInternal; namespace { @@ -80,8 +81,8 @@ interruptedCallback(int signal) void usage(const string& n) { - getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; - getErrorStream() << + consoleErr << "Usage: " << n << " [options] slice-files...\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -144,7 +145,7 @@ compile(const vector<string>& argv) } catch(const IceUtilInternal::BadOptException& e) { - getErrorStream() << argv[0] << ": error: " << e.reason << endl; + consoleErr << argv[0] << ": error: " << e.reason << endl; if(!validate) { usage(argv[0]); @@ -160,7 +161,7 @@ compile(const vector<string>& argv) if(opts.isSet("version")) { - getErrorStream() << ICE_STRING_VERSION << endl; + consoleErr << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -207,8 +208,8 @@ compile(const vector<string>& argv) s >> indexCount; if(!s) { - getErrorStream() << argv[0] << ": error: the --index operation requires a positive integer argument" - << endl; + consoleErr << argv[0] << ": error: the --index operation requires a positive integer argument" + << endl; if(!validate) { usage(argv[0]); @@ -231,8 +232,8 @@ compile(const vector<string>& argv) s >> summaryCount; if(!s) { - getErrorStream() << argv[0] << ": error: the --summary operation requires a positive integer argument" - << endl; + consoleErr << argv[0] << ": error: the --summary operation requires a positive integer argument" + << endl; if(!validate) { usage(argv[0]); @@ -249,7 +250,7 @@ compile(const vector<string>& argv) if(args.empty()) { - getErrorStream() << argv[0] << ": error: no input file" << endl; + consoleErr << argv[0] << ": error: no input file" << endl; if(!validate) { usage(argv[0]); @@ -325,19 +326,19 @@ compile(const vector<string>& argv) // created files. FileTracker::instance()->cleanup(); p->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + consoleErr << argv[0] << ": error: " << ex.reason() << endl; return EXIT_FAILURE; } catch(const string& err) { FileTracker::instance()->cleanup(); - getErrorStream() << argv[0] << ": error: " << err << endl; + consoleErr << argv[0] << ": error: " << err << endl; status = EXIT_FAILURE; } catch(const char* err) { FileTracker::instance()->cleanup(); - getErrorStream() << argv[0] << ": error: " << err << endl; + consoleErr << argv[0] << ": error: " << err << endl; status = EXIT_FAILURE; } } @@ -370,22 +371,22 @@ int main(int argc, char* argv[]) } catch(const std::exception& ex) { - getErrorStream() << args[0] << ": error:" << ex.what() << endl; + consoleErr << args[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; + consoleErr << args[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp index 72a549b454e..c082b103c06 100644 --- a/cpp/src/slice2cpp/Main.cpp +++ b/cpp/src/slice2cpp/Main.cpp @@ -11,6 +11,8 @@ #include <IceUtil/CtrlCHandler.h> #include <IceUtil/Mutex.h> #include <IceUtil/MutexPtrLock.h> +#include <IceUtil/ConsoleUtil.h> + #include <Slice/Preprocessor.h> #include <Slice/FileTracker.h> #include <Slice/Util.h> @@ -18,6 +20,7 @@ using namespace std; using namespace Slice; +using namespace IceUtilInternal; namespace { @@ -56,8 +59,8 @@ interruptedCallback(int /*signal*/) void usage(const string& n) { - getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; - getErrorStream() << + consoleErr << "Usage: " << n << " [options] slice-files...\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -123,7 +126,7 @@ compile(const vector<string>& argv) } catch(const IceUtilInternal::BadOptException& e) { - getErrorStream() << argv[0] << ": " << e.reason << endl; + consoleErr << argv[0] << ": " << e.reason << endl; if(!validate) { usage(argv[0]); @@ -139,7 +142,7 @@ compile(const vector<string>& argv) if(opts.isSet("version")) { - getErrorStream() << ICE_STRING_VERSION << endl; + consoleErr << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -196,7 +199,7 @@ compile(const vector<string>& argv) if(args.empty()) { - getErrorStream() << argv[0] << ": error: no input file" << endl; + consoleErr << argv[0] << ": error: no input file" << endl; if(!validate) { usage(argv[0]); @@ -206,7 +209,7 @@ compile(const vector<string>& argv) if(depend && dependxml) { - getErrorStream() << argv[0] << ": error: cannot specify both --depend and --depend-xml" << endl; + consoleErr << argv[0] << ": error: cannot specify both --depend and --depend-xml" << endl; if(!validate) { usage(argv[0]); @@ -216,7 +219,7 @@ compile(const vector<string>& argv) if(implCpp98 && implCpp11) { - getErrorStream() << argv[0] << ": error: cannot specify both --impl-c++98 and --impl-c++11" << endl; + consoleErr << argv[0] << ": error: cannot specify both --impl-c++98 and --impl-c++11" << endl; if(!validate) { usage(argv[0]); @@ -234,10 +237,10 @@ compile(const vector<string>& argv) IceUtil::CtrlCHandler ctrlCHandler; ctrlCHandler.setCallback(interruptedCallback); - DependOutputUtil out(dependFile); + ostringstream os; if(dependxml) { - out.os() << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; + os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; } for(vector<string>::const_iterator i = args.begin(); i != args.end(); ++i) @@ -258,7 +261,6 @@ compile(const vector<string>& argv) if(cppHandle == 0) { - out.cleanup(); return EXIT_FAILURE; } @@ -268,20 +270,17 @@ compile(const vector<string>& argv) if(parseStatus == EXIT_FAILURE) { - out.cleanup(); return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(out.os(), depend ? Preprocessor::CPlusPlus : Preprocessor::SliceXML, + if(!icecpp->printMakefileDependencies(os, depend ? Preprocessor::CPlusPlus : Preprocessor::SliceXML, includePaths, "-D__SLICE2CPP__", sourceExtension, headerExtension)) { - out.cleanup(); return EXIT_FAILURE; } if(!icecpp->close()) { - out.cleanup(); return EXIT_FAILURE; } } @@ -339,7 +338,7 @@ compile(const vector<string>& argv) // cleanup any created files. FileTracker::instance()->cleanup(); u->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + consoleErr << argv[0] << ": error: " << ex.reason() << endl; return EXIT_FAILURE; } } @@ -353,7 +352,6 @@ compile(const vector<string>& argv) if(interrupted) { - out.cleanup(); FileTracker::instance()->cleanup(); return EXIT_FAILURE; } @@ -362,7 +360,12 @@ compile(const vector<string>& argv) if(dependxml) { - out.os() << "</dependencies>\n"; + os << "</dependencies>\n"; + } + + if(depend || dependxml) + { + writeDependencies(os.str(), dependFile); } return status; @@ -381,22 +384,22 @@ int main(int argc, char* argv[]) } catch(const std::exception& ex) { - getErrorStream() << args[0] << ": error:" << ex.what() << endl; + consoleErr << args[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; + consoleErr << args[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } diff --git a/cpp/src/slice2cs/Main.cpp b/cpp/src/slice2cs/Main.cpp index e9a18c20d6a..f4b3e009a68 100644 --- a/cpp/src/slice2cs/Main.cpp +++ b/cpp/src/slice2cs/Main.cpp @@ -11,6 +11,7 @@ #include <IceUtil/CtrlCHandler.h> #include <IceUtil/Mutex.h> #include <IceUtil/MutexPtrLock.h> +#include <IceUtil/ConsoleUtil.h> #include <Slice/Preprocessor.h> #include <Slice/FileTracker.h> #include <Slice/Util.h> @@ -18,6 +19,7 @@ using namespace std; using namespace Slice; +using namespace IceUtilInternal; namespace { @@ -56,8 +58,8 @@ interruptedCallback(int /*signal*/) void usage(const string& n) { - getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; - getErrorStream() << + consoleErr << "Usage: " << n << " [options] slice-files...\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -114,7 +116,7 @@ compile(const vector<string>& argv) } catch(const IceUtilInternal::BadOptException& e) { - getErrorStream() << argv[0] << ": error: " << e.reason << endl; + consoleErr << argv[0] << ": error: " << e.reason << endl; if(!validate) { usage(argv[0]); @@ -130,7 +132,7 @@ compile(const vector<string>& argv) if(opts.isSet("version")) { - getErrorStream() << ICE_STRING_VERSION << endl; + consoleErr << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -179,7 +181,7 @@ compile(const vector<string>& argv) if(args.empty()) { - getErrorStream() << argv[0] << ": error: no input file" << endl; + consoleErr << argv[0] << ": error: no input file" << endl; if(!validate) { usage(argv[0]); @@ -189,7 +191,7 @@ compile(const vector<string>& argv) if(impl && implTie) { - getErrorStream() << argv[0] << ": error: cannot specify both --impl and --impl-tie" << endl; + consoleErr << argv[0] << ": error: cannot specify both --impl and --impl-tie" << endl; if(!validate) { usage(argv[0]); @@ -199,7 +201,7 @@ compile(const vector<string>& argv) if(depend && dependxml) { - getErrorStream() << argv[0] << ": error: cannot specify both --depend and --depend-xml" << endl; + consoleErr << argv[0] << ": error: cannot specify both --depend and --depend-xml" << endl; if(!validate) { usage(argv[0]); @@ -217,10 +219,10 @@ compile(const vector<string>& argv) IceUtil::CtrlCHandler ctrlCHandler; ctrlCHandler.setCallback(interruptedCallback); - DependOutputUtil out(dependFile); + ostringstream os; if(dependxml) { - out.os() << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; + os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; } for(vector<string>::const_iterator i = args.begin(); i != args.end(); ++i) @@ -241,7 +243,6 @@ compile(const vector<string>& argv) if(cppHandle == 0) { - out.cleanup(); return EXIT_FAILURE; } @@ -251,20 +252,17 @@ compile(const vector<string>& argv) if(parseStatus == EXIT_FAILURE) { - out.cleanup(); return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(out.os(), depend ? Preprocessor::CSharp : Preprocessor::SliceXML, includePaths, + if(!icecpp->printMakefileDependencies(os, depend ? Preprocessor::CSharp : Preprocessor::SliceXML, includePaths, "-D__SLICE2CS__")) { - out.cleanup(); return EXIT_FAILURE; } if(!icecpp->close()) { - out.cleanup(); return EXIT_FAILURE; } } @@ -332,7 +330,7 @@ compile(const vector<string>& argv) // cleanup any created files. FileTracker::instance()->cleanup(); p->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + consoleErr << argv[0] << ": error: " << ex.reason() << endl; return EXIT_FAILURE; } } @@ -346,7 +344,6 @@ compile(const vector<string>& argv) if(interrupted) { - out.cleanup(); FileTracker::instance()->cleanup(); return EXIT_FAILURE; } @@ -355,7 +352,12 @@ compile(const vector<string>& argv) if(dependxml) { - out.os() << "</dependencies>\n"; + os << "</dependencies>\n"; + } + + if(depend || dependxml) + { + writeDependencies(os.str(), dependFile); } return status; @@ -374,22 +376,22 @@ int main(int argc, char* argv[]) } catch(const std::exception& ex) { - getErrorStream() << args[0] << ": error:" << ex.what() << endl; + consoleErr << args[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; + consoleErr << args[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } diff --git a/cpp/src/slice2html/Gen.cpp b/cpp/src/slice2html/Gen.cpp index a5e03d6015f..1c4de107d54 100644 --- a/cpp/src/slice2html/Gen.cpp +++ b/cpp/src/slice2html/Gen.cpp @@ -11,6 +11,7 @@ #include <IceUtil/Functional.h> #include <IceUtil/StringUtil.h> #include <IceUtil/FileUtil.h> +#include <IceUtil/ConsoleUtil.h> #include <Slice/FileTracker.h> #include <Gen.h> @@ -1171,8 +1172,8 @@ Slice::GeneratorBase::getComment(const ContainedPtr& contained, const SyntaxTree if(_warnOldCommentFiles.find(fileName) == _warnOldCommentFiles.end()) { _warnOldCommentFiles.insert(fileName); - cerr << fileName << ": warning: file contains old-style link syntax: `[" << literal << "]'" - << endl; + consoleErr << fileName << ": warning: file contains old-style link syntax: `[" << literal << "]'" + << endl; } } else if(s[i] == '{') @@ -1211,8 +1212,8 @@ Slice::GeneratorBase::getComment(const ContainedPtr& contained, const SyntaxTree if(summary && _warnSummary && summarySize > _warnSummary) { - cerr << contained->file() << ": warning: summary size (" << summarySize << ") exceeds " << _warnSummary - << " characters: `" << comment << "'" << endl; + consoleErr << contained->file() << ": warning: summary size (" << summarySize << ") exceeds " << _warnSummary + << " characters: `" << comment << "'" << endl; } return comment; @@ -1480,13 +1481,13 @@ Slice::GeneratorBase::warnOldStyleIdent(const string& str, const string& fileNam lastName = newName.substr(pos + 1); } - cerr << fileName << ": warning: file contains old-style identifier syntax: `" << str << "'." - << " Use `'" << newName << "'"; + consoleErr << fileName << ": warning: file contains old-style identifier syntax: `" << str << "'." + << " Use `'" << newName << "'"; if(!alternateName.empty()) { - cerr << " or `" << alternateName << "' if `" << lastName << "' is a member"; + consoleErr << " or `" << alternateName << "' if `" << lastName << "' is a member"; } - cerr << endl; + consoleErr << endl; } } diff --git a/cpp/src/slice2html/Main.cpp b/cpp/src/slice2html/Main.cpp index 1bc84b6bde9..012f4bffb61 100644 --- a/cpp/src/slice2html/Main.cpp +++ b/cpp/src/slice2html/Main.cpp @@ -11,6 +11,7 @@ #include <IceUtil/CtrlCHandler.h> #include <IceUtil/Mutex.h> #include <IceUtil/MutexPtrLock.h> +#include <IceUtil/ConsoleUtil.h> #include <Slice/Preprocessor.h> #include <Slice/FileTracker.h> #include <Slice/Util.h> @@ -19,7 +20,7 @@ using namespace std; using namespace Slice; -using namespace IceUtil; +using namespace IceUtilInternal; namespace { @@ -58,8 +59,8 @@ interruptedCallback(int /*signal*/) void usage(const string& n) { - getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; - getErrorStream() << + consoleErr << "Usage: " << n << " [options] slice-files...\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -120,7 +121,7 @@ compile(const vector<string>& argv) } catch(const IceUtilInternal::BadOptException& e) { - getErrorStream() << argv[0] << ": error: " << e.reason << endl; + consoleErr << argv[0] << ": error: " << e.reason << endl; if(!validate) { usage(argv[0]); @@ -136,7 +137,7 @@ compile(const vector<string>& argv) if(opts.isSet("version")) { - getErrorStream() << ICE_STRING_VERSION << endl; + consoleErr << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -179,8 +180,8 @@ compile(const vector<string>& argv) s >> indexCount; if(!s) { - getErrorStream() << argv[0] << ": error: the --index operation requires a positive integer argument" - << endl; + consoleErr << argv[0] << ": error: the --index operation requires a positive integer argument" + << endl; if(!validate) { usage(argv[0]); @@ -203,8 +204,8 @@ compile(const vector<string>& argv) s >> summaryCount; if(!s) { - getErrorStream() << argv[0] << ": error: the --summary operation requires a positive integer argument" - << endl; + consoleErr << argv[0] << ": error: the --summary operation requires a positive integer argument" + << endl; if(!validate) { usage(argv[0]); @@ -221,7 +222,7 @@ compile(const vector<string>& argv) if(args.empty()) { - getErrorStream() << argv[0] << ": error: no input file" << endl; + consoleErr << argv[0] << ": error: no input file" << endl; if(!validate) { usage(argv[0]); @@ -297,19 +298,19 @@ compile(const vector<string>& argv) // created files. FileTracker::instance()->cleanup(); p->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + consoleErr << argv[0] << ": error: " << ex.reason() << endl; return EXIT_FAILURE; } catch(const string& err) { FileTracker::instance()->cleanup(); - getErrorStream() << argv[0] << ": error: " << err << endl; + consoleErr << argv[0] << ": error: " << err << endl; status = EXIT_FAILURE; } catch(const char* err) { FileTracker::instance()->cleanup(); - getErrorStream() << argv[0] << ": error: " << err << endl; + consoleErr << argv[0] << ": error: " << err << endl; status = EXIT_FAILURE; } } @@ -342,22 +343,22 @@ int main(int argc, char* argv[]) } catch(const std::exception& ex) { - getErrorStream() << args[0] << ": error:" << ex.what() << endl; + consoleErr << args[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; + consoleErr << args[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp index 198fda6b838..27845a76994 100644 --- a/cpp/src/slice2java/Main.cpp +++ b/cpp/src/slice2java/Main.cpp @@ -11,6 +11,7 @@ #include <IceUtil/CtrlCHandler.h> #include <IceUtil/Mutex.h> #include <IceUtil/MutexPtrLock.h> +#include <IceUtil/ConsoleUtil.h> #include <Slice/Preprocessor.h> #include <Slice/FileTracker.h> #include <Slice/Util.h> @@ -20,6 +21,7 @@ using namespace std; using namespace Slice; +using namespace IceUtilInternal; namespace { @@ -58,8 +60,8 @@ interruptedCallback(int /*signal*/) void usage(const string& n) { - getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; - getErrorStream() << + consoleErr << "Usage: " << n << " [options] slice-files...\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -122,7 +124,7 @@ compile(const vector<string>& argv) } catch(const IceUtilInternal::BadOptException& e) { - getErrorStream() << argv[0] << ": error: " << e.reason << endl; + consoleErr << argv[0] << ": error: " << e.reason << endl; if(!validate) { usage(argv[0]); @@ -138,7 +140,7 @@ compile(const vector<string>& argv) if(opts.isSet("version")) { - getErrorStream() << ICE_STRING_VERSION << endl; + consoleErr << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -193,7 +195,7 @@ compile(const vector<string>& argv) if(args.empty()) { - getErrorStream() << argv[0] << ": error: no input file" << endl; + consoleErr << argv[0] << ": error: no input file" << endl; if(!validate) { usage(argv[0]); @@ -203,7 +205,7 @@ compile(const vector<string>& argv) if(impl && implTie) { - getErrorStream() << argv[0] << ": error: cannot specify both --impl and --impl-tie" << endl; + consoleErr << argv[0] << ": error: cannot specify both --impl and --impl-tie" << endl; if(!validate) { usage(argv[0]); @@ -213,7 +215,7 @@ compile(const vector<string>& argv) if(!compat && (tie || implTie)) { - getErrorStream() << argv[0] << ": error: TIE classes are only supported with the Java-Compat mapping" << endl; + consoleErr << argv[0] << ": error: TIE classes are only supported with the Java-Compat mapping" << endl; if(!validate) { usage(argv[0]); @@ -223,7 +225,7 @@ compile(const vector<string>& argv) if(depend && dependxml) { - getErrorStream() << argv[0] << ": error: cannot specify both --depend and --depend-xml" << endl; + consoleErr << argv[0] << ": error: cannot specify both --depend and --depend-xml" << endl; if(!validate) { usage(argv[0]); @@ -243,10 +245,10 @@ compile(const vector<string>& argv) IceUtil::CtrlCHandler ctrlCHandler; ctrlCHandler.setCallback(interruptedCallback); - DependOutputUtil out(dependFile); + ostringstream os; if(dependxml) { - out.os() << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; + os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; } vector<string> cppOpts; @@ -274,7 +276,6 @@ compile(const vector<string>& argv) if(cppHandle == 0) { - out.cleanup(); return EXIT_FAILURE; } @@ -284,31 +285,23 @@ compile(const vector<string>& argv) if(parseStatus == EXIT_FAILURE) { - out.cleanup(); return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(out.os(), depend ? Preprocessor::Java : Preprocessor::SliceXML, + if(!icecpp->printMakefileDependencies(os, depend ? Preprocessor::Java : Preprocessor::SliceXML, includePaths, cppOpts)) { - out.cleanup(); return EXIT_FAILURE; } if(!icecpp->close()) { - out.cleanup(); return EXIT_FAILURE; } } else { ostringstream os; - if(listGenerated) - { - Slice::setErrorStream(os); - } - FileTracker::instance()->setSource(*i); PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); @@ -316,10 +309,6 @@ compile(const vector<string>& argv) if(cppHandle == 0) { - if(listGenerated) - { - FileTracker::instance()->setOutput(os.str(), true); - } status = EXIT_FAILURE; break; } @@ -353,10 +342,6 @@ compile(const vector<string>& argv) if(parseStatus == EXIT_FAILURE) { p->destroy(); - if(listGenerated) - { - FileTracker::instance()->setOutput(os.str(), true); - } status = EXIT_FAILURE; } else @@ -417,11 +402,7 @@ compile(const vector<string>& argv) // FileTracker::instance()->cleanup(); p->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; - if(listGenerated) - { - FileTracker::instance()->setOutput(os.str(), true); - } + consoleErr << argv[0] << ": error: " << ex.reason() << endl; status = EXIT_FAILURE; break; } @@ -435,7 +416,6 @@ compile(const vector<string>& argv) if(interrupted) { - out.cleanup(); // // If the translator was interrupted then cleanup any files we've already created. // @@ -447,7 +427,12 @@ compile(const vector<string>& argv) if(dependxml) { - out.os() << "</dependencies>\n"; + os << "</dependencies>\n"; + } + + if(depend || dependxml) + { + writeDependencies(os.str(), dependFile); } if(status == EXIT_SUCCESS && !checksumClass.empty() && !dependxml) @@ -462,12 +447,12 @@ compile(const vector<string>& argv) // If a file could not be created, then cleanup any created files. // FileTracker::instance()->cleanup(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + consoleErr << argv[0] << ": error: " << ex.reason() << endl; return EXIT_FAILURE; } } - if(listGenerated) + if(listGenerated && status == EXIT_SUCCESS) { FileTracker::instance()->dumpxml(); } @@ -488,22 +473,22 @@ int main(int argc, char* argv[]) } catch(const std::exception& ex) { - getErrorStream() << args[0] << ": error:" << ex.what() << endl; + consoleErr << args[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; + consoleErr << args[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } diff --git a/cpp/src/slice2js/Main.cpp b/cpp/src/slice2js/Main.cpp index a4d9023395c..158e31efd00 100644 --- a/cpp/src/slice2js/Main.cpp +++ b/cpp/src/slice2js/Main.cpp @@ -11,6 +11,7 @@ #include <IceUtil/CtrlCHandler.h> #include <IceUtil/Mutex.h> #include <IceUtil/MutexPtrLock.h> +#include <IceUtil/ConsoleUtil.h> #include <Slice/Preprocessor.h> #include <Slice/FileTracker.h> #include <Slice/Util.h> @@ -18,6 +19,7 @@ using namespace std; using namespace Slice; +using namespace IceUtilInternal; namespace { @@ -56,8 +58,8 @@ interruptedCallback(int /*signal*/) void usage(const string& n) { - getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; - getErrorStream() << + consoleErr << "Usage: " << n << " [options] slice-files...\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -111,7 +113,7 @@ compile(const vector<string>& argv) } catch(const IceUtilInternal::BadOptException& e) { - getErrorStream() << argv[0] << ": error: " << e.reason << endl; + consoleErr << argv[0] << ": error: " << e.reason << endl; if(!validate) { usage(argv[0]); @@ -127,7 +129,7 @@ compile(const vector<string>& argv) if(opts.isSet("version")) { - getErrorStream() << ICE_STRING_VERSION << endl; + consoleErr << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -172,7 +174,7 @@ compile(const vector<string>& argv) if(args.empty()) { - getErrorStream() << argv[0] << ": error: no input file" << endl; + consoleErr << argv[0] << ": error: no input file" << endl; if(!validate) { usage(argv[0]); @@ -182,7 +184,7 @@ compile(const vector<string>& argv) if(depend && dependJSON) { - getErrorStream() << argv[0] << ": error: cannot specify both --depend and --depend-json" << endl; + consoleErr << argv[0] << ": error: cannot specify both --depend and --depend-json" << endl; if(!validate) { usage(argv[0]); @@ -192,7 +194,7 @@ compile(const vector<string>& argv) if(depend && dependxml) { - getErrorStream() << argv[0] << ": error: cannot specify both --depend and --depend-xml" << endl; + consoleErr << argv[0] << ": error: cannot specify both --depend and --depend-xml" << endl; if(!validate) { usage(argv[0]); @@ -202,7 +204,7 @@ compile(const vector<string>& argv) if(dependxml && dependJSON) { - getErrorStream() << argv[0] << ": error: cannot specify both --depend-xml and --depend-json" << endl; + consoleErr << argv[0] << ": error: cannot specify both --depend-xml and --depend-json" << endl; if(!validate) { usage(argv[0]); @@ -220,14 +222,14 @@ compile(const vector<string>& argv) IceUtil::CtrlCHandler ctrlCHandler; ctrlCHandler.setCallback(interruptedCallback); - DependOutputUtil out(dependFile); + ostringstream os; if(dependJSON) { - out.os() << "{" << endl; + os << "{" << endl; } else if(dependxml) { - out.os() << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; + os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; } // @@ -252,7 +254,6 @@ compile(const vector<string>& argv) if(cppHandle == 0) { - out.cleanup(); return EXIT_FAILURE; } @@ -262,24 +263,21 @@ compile(const vector<string>& argv) if(parseStatus == EXIT_FAILURE) { - out.cleanup(); return EXIT_FAILURE; } bool last = (++i == sources.end()); - if(!icecpp->printMakefileDependencies(out.os(), + if(!icecpp->printMakefileDependencies(os, depend ? Preprocessor::JavaScript : (dependJSON ? Preprocessor::JavaScriptJSON : Preprocessor::SliceXML), includePaths, "-D__SLICE2JS__")) { - out.cleanup(); return EXIT_FAILURE; } if(!icecpp->close()) { - out.cleanup(); return EXIT_FAILURE; } @@ -287,9 +285,9 @@ compile(const vector<string>& argv) { if(!last) { - out.os() << ","; + os << ","; } - out.os() << "\n"; + os << "\n"; } } else @@ -353,7 +351,7 @@ compile(const vector<string>& argv) // FileTracker::instance()->cleanup(); p->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + consoleErr << argv[0] << ": error: " << ex.reason() << endl; return EXIT_FAILURE; } } @@ -368,7 +366,6 @@ compile(const vector<string>& argv) if(interrupted) { - out.cleanup(); FileTracker::instance()->cleanup(); return EXIT_FAILURE; } @@ -377,11 +374,16 @@ compile(const vector<string>& argv) if(dependJSON) { - out.os() << "}" << endl; + os << "}\n"; } else if(dependxml) { - out.os() << "</dependencies>\n"; + os << "</dependencies>\n"; + } + + if(depend || dependJSON || dependxml) + { + writeDependencies(os.str(), dependFile); } return status; @@ -400,22 +402,22 @@ int main(int argc, char* argv[]) } catch(const std::exception& ex) { - getErrorStream() << args[0] << ": error:" << ex.what() << endl; + consoleErr << args[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; + consoleErr << args[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } diff --git a/cpp/src/slice2objc/Main.cpp b/cpp/src/slice2objc/Main.cpp index 4d0df1c8a59..ed999c32067 100644 --- a/cpp/src/slice2objc/Main.cpp +++ b/cpp/src/slice2objc/Main.cpp @@ -13,11 +13,13 @@ #include <IceUtil/CtrlCHandler.h> #include <IceUtil/Mutex.h> #include <IceUtil/MutexPtrLock.h> +#include <IceUtil/ConsoleUtil.h> #include <Slice/Util.h> #include "Gen.h" using namespace std; using namespace Slice; +using namespace IceUtilInternal; namespace { @@ -55,8 +57,8 @@ interruptedCallback(int signal) void usage(const string& n) { - cerr << "Usage: " << n << " [options] slice-files...\n"; - cerr << + consoleErr << "Usage: " << n << " [options] slice-files...\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -113,7 +115,7 @@ compile(const vector<string>& argv) } catch(const IceUtilInternal::BadOptException& e) { - cerr << argv[0] << ": " << e.reason << endl; + consoleErr << argv[0] << ": " << e.reason << endl; if(!validate) { usage(argv[0]); @@ -129,7 +131,7 @@ compile(const vector<string>& argv) if(opts.isSet("version")) { - cout << ICE_STRING_VERSION << endl; + consoleErr << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -173,7 +175,7 @@ compile(const vector<string>& argv) if(args.empty()) { - getErrorStream() << argv[0] << ": no input file" << endl; + consoleErr << argv[0] << ": no input file" << endl; if(!validate) { usage(argv[0]); @@ -183,7 +185,7 @@ compile(const vector<string>& argv) if(depend && dependxml) { - getErrorStream() << argv[0] << ": error: cannot specify both --depend and --depend-xml" << endl; + consoleErr << argv[0] << ": error: cannot specify both --depend and --depend-xml" << endl; if(!validate) { usage(argv[0]); @@ -198,10 +200,10 @@ compile(const vector<string>& argv) int status = EXIT_SUCCESS; - DependOutputUtil out(dependFile); + ostringstream os; if(dependxml) { - out.os() << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; + os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; } IceUtil::CtrlCHandler ctrlCHandler; @@ -216,7 +218,6 @@ compile(const vector<string>& argv) if(cppHandle == 0) { - out.cleanup(); return EXIT_FAILURE; } @@ -226,20 +227,17 @@ compile(const vector<string>& argv) if(parseStatus == EXIT_FAILURE) { - out.cleanup(); return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(out.os(), depend ? Preprocessor::ObjC : Preprocessor::SliceXML, + if(!icecpp->printMakefileDependencies(os, depend ? Preprocessor::ObjC : Preprocessor::SliceXML, includePaths, "-D__SLICE2OBJC__")) { - out.cleanup(); return EXIT_FAILURE; } if(!icecpp->close()) { - out.cleanup(); return EXIT_FAILURE; } } @@ -301,7 +299,7 @@ compile(const vector<string>& argv) // cleanup any created files. FileTracker::instance()->cleanup(); u->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + consoleErr << argv[0] << ": error: " << ex.reason() << endl; return EXIT_FAILURE; } } @@ -315,7 +313,6 @@ compile(const vector<string>& argv) if(interrupted) { - out.cleanup(); FileTracker::instance()->cleanup(); return EXIT_FAILURE; } @@ -324,7 +321,12 @@ compile(const vector<string>& argv) if(dependxml) { - out.os() << "</dependencies>\n"; + os << "</dependencies>\n"; + } + + if(depend || dependxml) + { + writeDependencies(os.str(), dependFile); } return status; @@ -343,22 +345,22 @@ int main(int argc, char* argv[]) } catch(const std::exception& ex) { - getErrorStream() << args[0] << ": error:" << ex.what() << endl; + consoleErr << args[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; + consoleErr << args[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } diff --git a/cpp/src/slice2php/Main.cpp b/cpp/src/slice2php/Main.cpp index dd7b6f66159..1c2cd419296 100644 --- a/cpp/src/slice2php/Main.cpp +++ b/cpp/src/slice2php/Main.cpp @@ -16,6 +16,7 @@ #include <IceUtil/StringUtil.h> #include <IceUtil/Mutex.h> #include <IceUtil/MutexPtrLock.h> +#include <IceUtil/ConsoleUtil.h> #include <Slice/Checksum.h> #include <Slice/Preprocessor.h> #include <Slice/FileTracker.h> @@ -39,7 +40,6 @@ using namespace std; using namespace Slice; using namespace Slice::PHP; -using namespace IceUtil; using namespace IceUtilInternal; namespace @@ -1518,8 +1518,8 @@ interruptedCallback(int /*signal*/) static void usage(const string& n) { - getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; - getErrorStream() << + consoleErr << "Usage: " << n << " [options] slice-files...\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -1575,7 +1575,7 @@ compile(const vector<string>& argv) } catch(const IceUtilInternal::BadOptException& e) { - getErrorStream() << argv[0] << ": error: " << e.reason << endl; + consoleErr << argv[0] << ": error: " << e.reason << endl; if(!validate) { usage(argv[0]); @@ -1591,7 +1591,7 @@ compile(const vector<string>& argv) if(opts.isSet("version")) { - getErrorStream() << ICE_STRING_VERSION << endl; + consoleErr << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -1638,7 +1638,7 @@ compile(const vector<string>& argv) if(args.empty()) { - getErrorStream() << argv[0] << ": error: no input file" << endl; + consoleErr << argv[0] << ": error: no input file" << endl; if(!validate) { usage(argv[0]); @@ -1648,7 +1648,7 @@ compile(const vector<string>& argv) if(depend && dependxml) { - getErrorStream() << argv[0] << ": error: cannot specify both --depend and --depend-xml" << endl; + consoleErr << argv[0] << ": error: cannot specify both --depend and --depend-xml" << endl; if(!validate) { usage(argv[0]); @@ -1666,10 +1666,10 @@ compile(const vector<string>& argv) IceUtil::CtrlCHandler ctrlCHandler; ctrlCHandler.setCallback(interruptedCallback); - DependOutputUtil out(dependFile); + ostringstream os; if(dependxml) { - out.os() << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; + os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl; } for(vector<string>::const_iterator i = args.begin(); i != args.end(); ++i) @@ -1690,7 +1690,6 @@ compile(const vector<string>& argv) if(cppHandle == 0) { - out.cleanup(); return EXIT_FAILURE; } @@ -1700,20 +1699,17 @@ compile(const vector<string>& argv) if(parseStatus == EXIT_FAILURE) { - out.cleanup(); return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(out.os(), depend ? Preprocessor::PHP : Preprocessor::SliceXML, + if(!icecpp->printMakefileDependencies(os, depend ? Preprocessor::PHP : Preprocessor::SliceXML, includePaths, "-D__SLICE2PHP__")) { - out.cleanup(); return EXIT_FAILURE; } if(!icecpp->close()) { - out.cleanup(); return EXIT_FAILURE; } } @@ -1802,13 +1798,13 @@ compile(const vector<string>& argv) // created files. FileTracker::instance()->cleanup(); u->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + consoleErr << argv[0] << ": error: " << ex.reason() << endl; return EXIT_FAILURE; } catch(const string& err) { FileTracker::instance()->cleanup(); - getErrorStream() << argv[0] << ": error: " << err << endl; + consoleErr << argv[0] << ": error: " << err << endl; status = EXIT_FAILURE; } } @@ -1822,7 +1818,6 @@ compile(const vector<string>& argv) if(interrupted) { - out.cleanup(); FileTracker::instance()->cleanup(); return EXIT_FAILURE; } @@ -1831,7 +1826,12 @@ compile(const vector<string>& argv) if(dependxml) { - out.os() << "</dependencies>\n"; + os << "</dependencies>\n"; + } + + if(depend || dependxml) + { + writeDependencies(os.str(), dependFile); } return status; @@ -1850,22 +1850,22 @@ int main(int argc, char* argv[]) } catch(const std::exception& ex) { - getErrorStream() << args[0] << ": error:" << ex.what() << endl; + consoleErr << args[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; + consoleErr << args[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } diff --git a/cpp/src/slice2py/Main.cpp b/cpp/src/slice2py/Main.cpp index 39e103cfb4e..d98fab29725 100644 --- a/cpp/src/slice2py/Main.cpp +++ b/cpp/src/slice2py/Main.cpp @@ -9,10 +9,12 @@ #include <Slice/PythonUtil.h> #include <Slice/Util.h> +#include <IceUtil/ConsoleUtil.h> using namespace std; using namespace Slice; using namespace Slice::Python; +using namespace IceUtilInternal; #ifdef _WIN32 int wmain(int argc, wchar_t* argv[]) @@ -27,22 +29,22 @@ int main(int argc, char* argv[]) } catch(const std::exception& ex) { - getErrorStream() << args[0] << ": error:" << ex.what() << endl; + consoleErr << args[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << args[0] << ": error:" << msg << endl; + consoleErr << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; + consoleErr << args[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } diff --git a/cpp/src/slice2rb/Main.cpp b/cpp/src/slice2rb/Main.cpp index 7b489503f71..8a0be787e8f 100644 --- a/cpp/src/slice2rb/Main.cpp +++ b/cpp/src/slice2rb/Main.cpp @@ -9,10 +9,12 @@ #include <Slice/RubyUtil.h> #include <Slice/Util.h> +#include <IceUtil/ConsoleUtil.h> using namespace std; using namespace Slice; using namespace Slice::Ruby; +using namespace IceUtilInternal; int main(int argc, char* argv[]) @@ -24,22 +26,22 @@ main(int argc, char* argv[]) } catch(const std::exception& ex) { - getErrorStream() << argv[0] << ": error:" << ex.what() << endl; + consoleErr << argv[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << argv[0] << ": error:" << msg << endl; + consoleErr << argv[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << argv[0] << ": error:" << msg << endl; + consoleErr << argv[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << argv[0] << ": error:" << "unknown exception" << endl; + consoleErr << argv[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } |