diff options
Diffstat (limited to 'cpp/src')
35 files changed, 372 insertions, 316 deletions
diff --git a/cpp/src/Glacier2/SessionRouterI.cpp b/cpp/src/Glacier2/SessionRouterI.cpp index a63f700e342..91b5e05db6f 100644 --- a/cpp/src/Glacier2/SessionRouterI.cpp +++ b/cpp/src/Glacier2/SessionRouterI.cpp @@ -80,7 +80,7 @@ public: // Close the connection otherwise the peer has no way to know that // the session has gone. // - _connection->close(false); + _connection->close(true); _router->destroySession(_connection); } } @@ -922,7 +922,7 @@ SessionRouterI::refreshSession(const Ice::ConnectionPtr& con) // Close the connection otherwise the peer has no way to know that the // session has gone. // - con->close(false); + con->close(true); throw SessionNotExistException(); } } diff --git a/cpp/src/Ice/DynamicLibrary.cpp b/cpp/src/Ice/DynamicLibrary.cpp index 8cb221fbfce..d70e14bd74a 100644 --- a/cpp/src/Ice/DynamicLibrary.cpp +++ b/cpp/src/Ice/DynamicLibrary.cpp @@ -15,6 +15,10 @@ # include <dlfcn.h> #endif +#if defined(ICE_CPP11) && defined(__GNUC__) && (__GNUC__ < 6) && defined(__GLIBCXX__) +# define ICE_LIBSUFFIX "++11" +#endif + using namespace Ice; using namespace IceInternal; using namespace std; diff --git a/cpp/src/Ice/PropertyNames.cpp b/cpp/src/Ice/PropertyNames.cpp index 412e8e0ca8c..c1a1cde9335 100644 --- a/cpp/src/Ice/PropertyNames.cpp +++ b/cpp/src/Ice/PropertyNames.cpp @@ -6,7 +6,7 @@ // ICE_LICENSE file included in this distribution. // // ********************************************************************** -// Generated by makeprops.py from file ./config/PropertyNames.xml, Thu Aug 18 20:28:56 2016 +// Generated by makeprops.py from file ../config/PropertyNames.xml, Wed Oct 5 19:04:47 2016 // IMPORTANT: Do not edit this file -- any edits made here will be lost! @@ -1008,7 +1008,7 @@ const IceInternal::Property IceSSLPropsData[] = IceInternal::Property("IceSSL.DHParams", false, 0), IceInternal::Property("IceSSL.EntropyDaemon", false, 0), IceInternal::Property("IceSSL.FindCert", false, 0), - IceInternal::Property("IceSSL.FindCert.*", true, "IceSSL.FindCert"), + IceInternal::Property("IceSSL.FindCert.*", true, 0), IceInternal::Property("IceSSL.InitOpenSSL", false, 0), IceInternal::Property("IceSSL.KeyFile", true, 0), IceInternal::Property("IceSSL.Keychain", false, 0), diff --git a/cpp/src/Ice/PropertyNames.h b/cpp/src/Ice/PropertyNames.h index ee9c805955c..52e12f92225 100644 --- a/cpp/src/Ice/PropertyNames.h +++ b/cpp/src/Ice/PropertyNames.h @@ -6,7 +6,7 @@ // ICE_LICENSE file included in this distribution. // // ********************************************************************** -// Generated by makeprops.py from file ./config/PropertyNames.xml, Thu Aug 18 20:28:56 2016 +// Generated by makeprops.py from file ../config/PropertyNames.xml, Wed Oct 5 19:04:47 2016 // IMPORTANT: Do not edit this file -- any edits made here will be lost! diff --git a/cpp/src/IceGrid/Util.cpp b/cpp/src/IceGrid/Util.cpp index de544ef43b1..8c0d04cd911 100644 --- a/cpp/src/IceGrid/Util.cpp +++ b/cpp/src/IceGrid/Util.cpp @@ -16,7 +16,7 @@ using namespace std; using namespace Ice; using namespace IceGrid; -string +string IceGrid::toString(const vector<string>& v, const string& sep) { ostringstream os; @@ -61,7 +61,7 @@ IceGrid::toString(const Ice::Exception& exception) string IceGrid::getProperty(const PropertyDescriptorSeq& properties, const string& name, const string& def) -{ +{ string result; for(PropertyDescriptorSeq::const_iterator q = properties.begin(); q != properties.end(); ++q) { @@ -79,7 +79,7 @@ IceGrid::getProperty(const PropertyDescriptorSeq& properties, const string& name int IceGrid::getPropertyAsInt(const PropertyDescriptorSeq& properties, const string& name, int def) -{ +{ string strVal; for(PropertyDescriptorSeq::const_iterator q = properties.begin(); q != properties.end(); ++q) { @@ -88,7 +88,7 @@ IceGrid::getPropertyAsInt(const PropertyDescriptorSeq& properties, const string& strVal = q->value; } } - + int result = def; if(!strVal.empty()) @@ -104,7 +104,7 @@ IceGrid::getPropertyAsInt(const PropertyDescriptorSeq& properties, const string& bool IceGrid::hasProperty(const PropertyDescriptorSeq& properties, const string& name) -{ +{ for(PropertyDescriptorSeq::const_iterator q = properties.begin(); q != properties.end(); ++q) { if(q->name == name) @@ -156,7 +156,7 @@ IceGrid::escapeProperty(const string& s, bool escapeEqual) previousCharIsEscape = false; break; } - + case '\\': case '#': case '=': @@ -212,7 +212,7 @@ IceGrid::toObjectInfo(const Ice::CommunicatorPtr& communicator, const ObjectDesc { proxyStr << ' ' << obj.proxyOptions; } - proxyStr << " @ " << adapterId; + proxyStr << " @ \"" << adapterId << "\""; try { info.proxy = communicator->stringToProxy(proxyStr.str()); @@ -220,7 +220,7 @@ IceGrid::toObjectInfo(const Ice::CommunicatorPtr& communicator, const ObjectDesc catch(const Ice::ProxyParseException&) { ostringstream fallbackProxyStr; - fallbackProxyStr << "\"" << identityToString(obj.id) << "\"" << " @ " << adapterId; + fallbackProxyStr << "\"" << identityToString(obj.id) << "\"" << " @ \"" << adapterId << "\""; info.proxy = communicator->stringToProxy(fallbackProxyStr.str()); } return info; @@ -246,7 +246,7 @@ IceGrid::setupThreadPool(const PropertiesPtr& properties, const string& name, in { sizeMax = size * 10; } - + ostringstream os; os << sizeMax; properties->setProperty(name + ".SizeMax", os.str()); @@ -277,7 +277,7 @@ IceGrid::getMMVersion(const string& o) } if(patchPos != string::npos) - { + { if((minorPos == 1 && patchPos != 3 && patchPos != 4) || (minorPos == 2 && patchPos != 4 && patchPos != 5)) { return -1; @@ -326,6 +326,6 @@ IceGrid::getMMVersion(const string& o) // } // ver += v; // } - + return ver; } diff --git a/cpp/src/IcePatch2Lib/ClientUtil.cpp b/cpp/src/IcePatch2Lib/ClientUtil.cpp index 07c30450029..66d315f8a6b 100644 --- a/cpp/src/IcePatch2Lib/ClientUtil.cpp +++ b/cpp/src/IcePatch2Lib/ClientUtil.cpp @@ -863,8 +863,14 @@ PatcherI::updateFilesInternal(const LargeFileInfoSeq& files, const DecompressorP throw ": cannot write `" + pathBZ2 + "':\n" + IceUtilInternal::lastErrorToString(); } - pos += bytes.size(); - updated += bytes.size(); + // 'bytes' is always returned with size '_chunkSize'. When a file is smaller than '_chunkSize' + // or we are reading the last chunk of a file, 'bytes' will be larger than necessary. In this + // case we calculate the current position and updated size based on the known file size. + size_t size = (pos + bytes.size()) > static_cast<size_t>(p->size) ? + static_cast<size_t>(p->size - pos) : bytes.size(); + + pos += size; + updated += size; if(!_feedback->patchProgress(pos, p->size, updated, total)) { diff --git a/cpp/src/IceSSL/OpenSSLEngine.cpp b/cpp/src/IceSSL/OpenSSLEngine.cpp index 5fc4de1604b..84238614220 100644 --- a/cpp/src/IceSSL/OpenSSLEngine.cpp +++ b/cpp/src/IceSSL/OpenSSLEngine.cpp @@ -474,37 +474,6 @@ OpenSSLEngine::initialize() } } - if(!file && !dir) - { - // Deprecated properties - path = properties->getProperty(propPrefix + "CertAuthFile"); - if(!path.empty()) - { - if(!checkPath(path, defaultDir, false, resolved)) - { - throw PluginInitializationException(__FILE__, __LINE__, - "IceSSL: CA certificate file not found:\n" + path); - } - path = resolved; - file = path.c_str(); - } - else - { - path = properties->getProperty(propPrefix + "CertAuthDir"); - if(!path.empty()) - { - if(!checkPath(path, defaultDir, true, resolved)) - { - throw PluginInitializationException(__FILE__, __LINE__, - "IceSSL: CA certificate directory not found:\n" + - path); - } - path = resolved; - dir = path.c_str(); - } - } - } - if(file || dir) { // diff --git a/cpp/src/IceStorm/IceStormInternal.ice b/cpp/src/IceStorm/IceStormInternal.ice index 32b010fe87d..bafb51717fa 100644 --- a/cpp/src/IceStorm/IceStormInternal.ice +++ b/cpp/src/IceStorm/IceStormInternal.ice @@ -39,6 +39,10 @@ module IceStorm Ice::Context context; }; +local exception SendQueueSizeMaxReached +{ +}; + /** A sequence of EventData. */ ["cpp:type:std::deque< ::IceStorm::EventDataPtr>"] sequence<EventData> EventDataSeq; diff --git a/cpp/src/IceStorm/Instance.cpp b/cpp/src/IceStorm/Instance.cpp index 5dd876da63e..6d8334cab4d 100644 --- a/cpp/src/IceStorm/Instance.cpp +++ b/cpp/src/IceStorm/Instance.cpp @@ -17,6 +17,7 @@ #include <Ice/InstrumentationI.h> #include <Ice/Communicator.h> #include <Ice/Properties.h> +#include <Ice/TraceUtil.h> using namespace std; using namespace IceStorm; @@ -110,6 +111,8 @@ Instance::Instance( name + ".Flush.Timeout", 1000))), // default one second. // default one minute. _sendTimeout(communicator->getProperties()->getPropertyAsIntWithDefault(name + ".Send.Timeout", 60 * 1000)), + _sendQueueSizeMax(communicator->getProperties()->getPropertyAsIntWithDefault(name + ".Send.QueueSizeMax", -1)), + _sendQueueSizeMaxPolicy(RemoveSubscriber), _topicReaper(new TopicReaper()) { try @@ -134,6 +137,21 @@ Instance::Instance( _batchFlusher = new IceUtil::Timer(); _timer = new IceUtil::Timer(); + string policy = properties->getProperty(name + ".Send.QueueSizeMaxPolicy"); + if(policy == "RemoveSubscriber") + { + const_cast<SendQueueSizeMaxPolicy&>(_sendQueueSizeMaxPolicy) = RemoveSubscriber; + } + else if(policy == "DropEvents") + { + const_cast<SendQueueSizeMaxPolicy&>(_sendQueueSizeMaxPolicy) = DropEvents; + } + else if(!policy.empty()) + { + Ice::Warning warn(_traceLevels->logger); + warn << "invalid value `" << policy << "' for `" << name << ".Send.QueueSizeMaxPolicy'"; + } + // // If an Ice metrics observer is setup on the communicator, also // enable metrics for IceStorm. @@ -287,6 +305,18 @@ Instance::sendTimeout() const return _sendTimeout; } +int +Instance::sendQueueSizeMax() const +{ + return _sendQueueSizeMax; +} + +Instance::SendQueueSizeMaxPolicy +Instance::sendQueueSizeMaxPolicy() const +{ + return _sendQueueSizeMaxPolicy; +} + void Instance::shutdown() { @@ -320,7 +350,7 @@ Instance::destroy() _node = 0; // // The observer instance must be cleared as it holds the - // TopicManagerImpl which hodlds the instance causing a + // TopicManagerImpl which hodlds the instance causing a // cyclic reference. // _observer = 0; diff --git a/cpp/src/IceStorm/Instance.h b/cpp/src/IceStorm/Instance.h index e7e5814a598..11d1372e1b8 100644 --- a/cpp/src/IceStorm/Instance.h +++ b/cpp/src/IceStorm/Instance.h @@ -61,6 +61,12 @@ class Instance : public IceUtil::Shared { public: + enum SendQueueSizeMaxPolicy + { + RemoveSubscriber, + DropEvents + }; + 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(); @@ -88,6 +94,8 @@ public: IceUtil::Time discardInterval() const; IceUtil::Time flushInterval() const; int sendTimeout() const; + int sendQueueSizeMax() const; + SendQueueSizeMaxPolicy sendQueueSizeMaxPolicy() const; void shutdown(); virtual void destroy(); @@ -105,6 +113,8 @@ private: const IceUtil::Time _discardInterval; const IceUtil::Time _flushInterval; const int _sendTimeout; + const int _sendQueueSizeMax; + const SendQueueSizeMaxPolicy _sendQueueSizeMaxPolicy; const Ice::ObjectPrx _topicReplicaProxy; const Ice::ObjectPrx _publisherReplicaProxy; const TopicReaperPtr _topicReaper; diff --git a/cpp/src/IceStorm/Service.cpp b/cpp/src/IceStorm/Service.cpp index 9d925c9bff1..3f78ad37a25 100644 --- a/cpp/src/IceStorm/Service.cpp +++ b/cpp/src/IceStorm/Service.cpp @@ -535,6 +535,8 @@ ServiceI::validateProperties(const string& name, const PropertiesPtr& properties "Trace.Topic", "Trace.TopicManager", "Send.Timeout", + "Send.QueueSizeMax", + "Send.QueueSizeMaxPolicy", "Discard.Interval", "LMDB.Path", "LMDB.MapSize" diff --git a/cpp/src/IceStorm/Subscriber.cpp b/cpp/src/IceStorm/Subscriber.cpp index a4b89d09e1b..529461f0f03 100644 --- a/cpp/src/IceStorm/Subscriber.cpp +++ b/cpp/src/IceStorm/Subscriber.cpp @@ -227,7 +227,7 @@ void SubscriberBatch::doFlush() { IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(_lock); - + // // If the subscriber isn't online we're done. // @@ -239,7 +239,7 @@ SubscriberBatch::doFlush() EventDataSeq v; v.swap(_events); assert(!v.empty()); - + if(_observer) { _outstandingCount = static_cast<Ice::Int>(v.size()); @@ -255,7 +255,7 @@ SubscriberBatch::doFlush() } Ice::AsyncResultPtr result = _obj->begin_ice_flushBatchRequests( - Ice::newCallback_Object_ice_flushBatchRequests(this, + Ice::newCallback_Object_ice_flushBatchRequests(this, &SubscriberBatch::exception, &SubscriberBatch::sent)); if(result->sentSynchronously()) @@ -278,7 +278,7 @@ SubscriberBatch::doFlush() { _lock.notify(); } - + // This is significantly faster than the async version, but it can // block the calling thread. Bad news! @@ -294,7 +294,7 @@ SubscriberBatch::sent(bool sentSynchronously) } IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(_lock); - + // Decrement the _outstanding count. --_outstanding; assert(_outstanding == 0); @@ -334,7 +334,7 @@ void SubscriberOneway::flush() { IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(_lock); - + // // If the subscriber isn't online we're done. // @@ -360,7 +360,7 @@ SubscriberOneway::flush() try { Ice::AsyncResultPtr result = _obj->begin_ice_invoke( - e->op, e->mode, e->data, e->context, Ice::newCallback_Object_ice_invoke(this, + e->op, e->mode, e->data, e->context, Ice::newCallback_Object_ice_invoke(this, &SubscriberOneway::exception, &SubscriberOneway::sent)); if(!result->sentSynchronously()) @@ -394,7 +394,7 @@ SubscriberOneway::sent(bool sentSynchronously) } IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(_lock); - + // Decrement the _outstanding count. --_outstanding; assert(_outstanding >= 0 && _outstanding < _maxOutstanding); @@ -481,7 +481,7 @@ void SubscriberLink::flush() { IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(_lock); - + if(_state != SubscriberStateOnline || _outstanding > 0) { return; @@ -673,23 +673,40 @@ Subscriber::queue(bool forwarded, const EventDataSeq& events) { break; } - + // // State transition to online. // setState(SubscriberStateOnline); // fall through } - + case SubscriberStateOnline: - copy(events.begin(), events.end(), back_inserter(_events)); + { + for(EventDataSeq::const_iterator p = events.begin(); p != events.end(); ++p) + { + if(static_cast<int>(_events.size()) == _instance->sendQueueSizeMax()) + { + if(_instance->sendQueueSizeMaxPolicy() == Instance::RemoveSubscriber) + { + error(false, IceStorm::SendQueueSizeMaxReached(__FILE__, __LINE__)); + return false; + } + else // DropEvents + { + _events.pop_front(); + } + } + _events.push_back(*p); + } + if(_observer) { _observer->queued(static_cast<Ice::Int>(events.size())); } flush(); break; - + } case SubscriberStateError: return false; @@ -768,10 +785,24 @@ Subscriber::error(bool dec, const Ice::Exception& e) assert(_outstanding >= 0 && _outstanding < _maxOutstanding); } + // + // It's possible to be already in the error state if the queue maximum size + // has been reached or if an ObjectNotExistException occured before. + // + if(_state >= SubscriberStateError) + { + if(_shutdown) + { + _lock.notify(); + } + return; + } + // A hard error is an ObjectNotExistException or // NotRegisteredException. bool hardError = dynamic_cast<const Ice::ObjectNotExistException*>(&e) || - dynamic_cast<const Ice::NotRegisteredException*>(&e); + dynamic_cast<const Ice::NotRegisteredException*>(&e) || + dynamic_cast<const IceStorm::SendQueueSizeMaxReached*>(&e); // // A twoway subscriber can queue multiple send events and @@ -834,7 +865,7 @@ Subscriber::error(bool dec, const Ice::Exception& e) { _events.clear(); setState(SubscriberStateError); - + TraceLevelsPtr traceLevels = _instance->traceLevels(); if(traceLevels->subscriber > 0) { @@ -871,13 +902,13 @@ Subscriber::completed(const Ice::AsyncResultPtr& result) { _observer->delivered(_outstandingCount); } - + // // A successful response means we're no longer retrying, we're // back active. // _currentRetry = 0; - + if(_events.empty() && _outstanding == 0 && _shutdown) { _lock.notify(); @@ -893,7 +924,7 @@ Subscriber::completed(const Ice::AsyncResultPtr& result) } } - + void Subscriber::shutdown() { @@ -954,7 +985,7 @@ Subscriber::Subscriber( rec.topicName, rec.obj, rec.theQoS, - rec.theTopic, + rec.theTopic, toSubscriberState(_state), 0)); } @@ -992,7 +1023,7 @@ Subscriber::setState(Subscriber::SubscriberState state) if(traceLevels->subscriber > 1) { Ice::Trace out(traceLevels->logger, traceLevels->subscriberCat); - out << "endpoints: " << IceStormInternal::describeEndpoints(_rec.obj) + out << "endpoints: " << IceStormInternal::describeEndpoints(_rec.obj) << " transition from: " << stateToString(_state) << " to: " << stateToString(state); } _state = state; diff --git a/cpp/src/IceUtil/OutputUtil.cpp b/cpp/src/IceUtil/OutputUtil.cpp index 3e21011e511..587c720aa97 100644 --- a/cpp/src/IceUtil/OutputUtil.cpp +++ b/cpp/src/IceUtil/OutputUtil.cpp @@ -95,7 +95,7 @@ IceUtilInternal::OutputBase::open(const string& s) // mismatches on case-insensitive OSs. // IceUtilInternal::unlink(s); - _fout.open(s.c_str()); + _fout.open(IceUtilInternal::streamFilename(s).c_str()); } void @@ -172,13 +172,13 @@ IceUtilInternal::OutputBase::currIndent() return _indent; } -void +void IceUtilInternal::OutputBase::setIndent(int indentSize) { - _indentSize = indentSize; + _indentSize = indentSize; } -void +void IceUtilInternal::OutputBase::setUseTab(bool useTab) { _useTab = useTab; @@ -554,7 +554,7 @@ IceUtilInternal::StartElement::StartElement(const string& name) : _name(name) { } - + const string& IceUtilInternal::StartElement::getName() const { diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp index 52c72714619..ad8d3628d65 100644 --- a/cpp/src/Slice/JavaUtil.cpp +++ b/cpp/src/Slice/JavaUtil.cpp @@ -13,9 +13,9 @@ #include <Slice/Util.h> #include <Slice/MD5.h> #include <IceUtil/Functional.h> +#include <IceUtil/FileUtil.h> #include <sys/types.h> -#include <sys/stat.h> #include <string.h> #ifdef _WIN32 @@ -644,10 +644,8 @@ Slice::JavaOutput::openClass(const string& cls, const string& prefix, const stri path += dir.substr(start); } - struct stat st; - int result; - result = stat(path.c_str(), &st); - if(result == 0) + IceUtilInternal::structstat st; + if(!IceUtilInternal::stat(path, &st)) { if(!(st.st_mode & S_IFDIR)) { @@ -658,12 +656,8 @@ Slice::JavaOutput::openClass(const string& cls, const string& prefix, const stri } continue; } -#ifdef _WIN32 - result = _mkdir(path.c_str()); -#else - result = ::mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); -#endif - if(result != 0) + + if(IceUtilInternal::mkdir(path, 0777) != 0) { ostringstream os; os << "cannot create directory `" << path << "': " << strerror(errno); diff --git a/cpp/src/Slice/Preprocessor.cpp b/cpp/src/Slice/Preprocessor.cpp index 6a32037af44..c8e49029f25 100644 --- a/cpp/src/Slice/Preprocessor.cpp +++ b/cpp/src/Slice/Preprocessor.cpp @@ -741,7 +741,7 @@ Slice::Preprocessor::checkInputFile() return false; } - ifstream test(_fileName.c_str()); + ifstream test(IceUtilInternal::streamFilename(_fileName).c_str()); if(!test) { getErrorStream() << _path << ": error: cannot open `" << _fileName << "' for reading" << endl; diff --git a/cpp/src/Slice/Python.cpp b/cpp/src/Slice/Python.cpp index 4343456efb2..73a470260c4 100644 --- a/cpp/src/Slice/Python.cpp +++ b/cpp/src/Slice/Python.cpp @@ -187,10 +187,8 @@ PackageVisitor::visitModuleEnd(const ModulePtr& p) void PackageVisitor::createDirectory(const string& dir) { - struct stat st; - int result; - result = stat(dir.c_str(), &st); - if(result == 0) + IceUtilInternal::structstat st; + if(!IceUtilInternal::stat(dir, &st)) { if(!(st.st_mode & S_IFDIR)) { @@ -201,13 +199,8 @@ PackageVisitor::createDirectory(const string& dir) } return; } -#ifdef _WIN32 - result = _mkdir(dir.c_str()); -#else - result = mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); -#endif - if(result != 0) + if(IceUtilInternal::mkdir(dir, 0777) != 0) { ostringstream os; os << "cannot create directory `" << dir << "': " << strerror(errno); @@ -254,10 +247,10 @@ PackageVisitor::readInit(const string& dir, StringList& modules, StringList& sub { string initPath = dir + "/__init__.py"; - struct stat st; - if(stat(initPath.c_str(), &st) == 0) + IceUtilInternal::structstat st; + if(!IceUtilInternal::stat(initPath, &st)) { - ifstream in(initPath.c_str()); + ifstream in(IceUtilInternal::streamFilename(initPath).c_str()); if(!in) { ostringstream os; @@ -358,7 +351,7 @@ PackageVisitor::writeInit(const string& dir, const string& name, const StringLis { string initPath = dir + "/__init__.py"; - ofstream os(initPath.c_str()); + ofstream os(IceUtilInternal::streamFilename(initPath).c_str()); if(!os) { ostringstream os; @@ -388,7 +381,7 @@ PackageVisitor::writeInit(const string& dir, const string& name, const StringLis } void -usage(const char* n) +usage(const string& n) { getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; getErrorStream() << @@ -416,7 +409,7 @@ usage(const char* n) } int -Slice::Python::compile(int argc, char* argv[]) +Slice::Python::compile(const vector<string>& argv) { IceUtilInternal::Options opts; opts.addOpt("h", "help"); @@ -441,7 +434,7 @@ Slice::Python::compile(int argc, char* argv[]) vector<string> args; try { - args = opts.parse(argc, const_cast<const char**>(argv)); + args = opts.parse(argv); } catch(const IceUtilInternal::BadOptException& e) { diff --git a/cpp/src/Slice/PythonUtil.h b/cpp/src/Slice/PythonUtil.h index 807fcfa1561..9d48b3d3871 100644 --- a/cpp/src/Slice/PythonUtil.h +++ b/cpp/src/Slice/PythonUtil.h @@ -56,7 +56,7 @@ std::string getAbsolute(const Slice::ContainedPtr&, const std::string& = "", con // void printHeader(IceUtilInternal::Output&); -int compile(int, char*[]); +int compile(const std::vector<std::string>&); } } diff --git a/cpp/src/Slice/Ruby.cpp b/cpp/src/Slice/Ruby.cpp index 209711a679d..799e72c264b 100644 --- a/cpp/src/Slice/Ruby.cpp +++ b/cpp/src/Slice/Ruby.cpp @@ -56,10 +56,10 @@ interruptedCallback(int /*signal*/) } void -usage(const char* n) +usage(const string& n) { getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; - getErrorStream() << + getErrorStream() << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -83,7 +83,7 @@ usage(const char* n) } int -Slice::Ruby::compile(int argc, char* argv[]) +Slice::Ruby::compile(const vector<string>& argv) { IceUtilInternal::Options opts; opts.addOpt("h", "help"); @@ -101,11 +101,11 @@ Slice::Ruby::compile(int argc, char* argv[]) opts.addOpt("", "underscore"); opts.addOpt("", "all"); opts.addOpt("", "checksum"); - + vector<string> args; try { - args = opts.parse(argc, const_cast<const char**>(argv)); + args = opts.parse(argv); } catch(const IceUtilInternal::BadOptException& e) { @@ -222,7 +222,7 @@ Slice::Ruby::compile(int argc, char* argv[]) return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(out.os(), depend ? Preprocessor::Ruby : Preprocessor::SliceXML, includePaths, + if(!icecpp->printMakefileDependencies(out.os(), depend ? Preprocessor::Ruby : Preprocessor::SliceXML, includePaths, "-D__SLICE2RB__")) { out.cleanup(); diff --git a/cpp/src/Slice/RubyUtil.h b/cpp/src/Slice/RubyUtil.h index 3acae195d9c..e67ecd1b623 100644 --- a/cpp/src/Slice/RubyUtil.h +++ b/cpp/src/Slice/RubyUtil.h @@ -46,7 +46,7 @@ std::string getAbsolute(const Slice::ContainedPtr&, IdentStyle, const std::strin // void printHeader(IceUtilInternal::Output&); -int compile(int, char*[]); +int compile(const std::vector<std::string>&); } } diff --git a/cpp/src/Slice/SliceUtil.cpp b/cpp/src/Slice/SliceUtil.cpp index e0c490fa937..cdef47244c6 100644 --- a/cpp/src/Slice/SliceUtil.cpp +++ b/cpp/src/Slice/SliceUtil.cpp @@ -431,3 +431,27 @@ Slice::DependOutputUtil::os() { return _file.empty() ? cout : _os; } + +#ifdef _WIN32 +vector<string> +Slice::argvToArgs(int argc, wchar_t* argv[]) +{ + vector<string> args; + for(int i = 0; i < argc; i++) + { + args.push_back(IceUtil::wstringToString(argv[i])); + } + return args; +} +#else +vector<string> +Slice::argvToArgs(int argc, char* argv[]) +{ + vector<string> args; + for(int i = 0; i < argc; i++) + { + args.push_back(argv[i]); + } + return args; +} +#endif diff --git a/cpp/src/Slice/Util.h b/cpp/src/Slice/Util.h index a2ec69a87a2..fdf84a1290e 100644 --- a/cpp/src/Slice/Util.h +++ b/cpp/src/Slice/Util.h @@ -30,6 +30,12 @@ void emitWarning(const std::string&, const std::string&, const std::string&); void emitRaw(const char*); std::vector<std::string> filterMcppWarnings(const std::string&); void printGeneratedHeader(IceUtilInternal::Output& out, const std::string&, const std::string& commentStyle = "//"); +#ifdef _WIN32 +std::vector<std::string> argvToArgs(int argc, wchar_t* argv[]); +#else +std::vector<std::string> argvToArgs(int argc, char* argv[]); +#endif + class DependOutputUtil : IceUtil::noncopyable { diff --git a/cpp/src/slice2confluence/Gen.cpp b/cpp/src/slice2confluence/Gen.cpp index f62bd1f6fb8..dd7175133f1 100644 --- a/cpp/src/slice2confluence/Gen.cpp +++ b/cpp/src/slice2confluence/Gen.cpp @@ -9,16 +9,16 @@ #include <IceUtil/Functional.h> #include <IceUtil/StringUtil.h> +#include <IceUtil/FileUtil.h> #include <Slice/FileTracker.h> #include <Gen.h> #include <string.h> #include <sys/types.h> -#include <sys/stat.h> #ifdef _WIN32 -#include <direct.h> +# include <direct.h> #else -#include <unistd.h> +# include <unistd.h> #endif #include <iterator> @@ -1780,8 +1780,7 @@ void Slice::GeneratorBase::makeDir(const string& dir) { struct stat st; - int rc = stat(dir.c_str(), &st); - if(rc == 0) + if(!IceUtilInternal::stat(dir, &st)) { if(!(st.st_mode & S_IFDIR)) { @@ -1793,12 +1792,7 @@ Slice::GeneratorBase::makeDir(const string& dir) return; } -#ifdef _WIN32 - rc = _mkdir(dir.c_str()); -#else - rc = mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); -#endif - if(rc != 0) + if(IceUtilInternal::mkdir(dir, 0777) != 0) { ostringstream os; os << "cannot create directory `" << dir << "': " << strerror(errno); diff --git a/cpp/src/slice2confluence/Main.cpp b/cpp/src/slice2confluence/Main.cpp index 885c58819ab..8bf3cd85ba5 100644 --- a/cpp/src/slice2confluence/Main.cpp +++ b/cpp/src/slice2confluence/Main.cpp @@ -78,7 +78,7 @@ interruptedCallback(int signal) } void -usage(const char* n) +usage(const string& n) { getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; getErrorStream() << @@ -109,7 +109,7 @@ usage(const char* n) } int -compile(int argc, char* argv[]) +compile(const vector<string>& argv) { IceUtilInternal::Options opts; opts.addOpt("h", "help"); @@ -134,20 +134,11 @@ compile(int argc, char* argv[]) opts.addOpt("", "ice"); opts.addOpt("", "underscore"); - bool validate = false; - for(int i = 0; i < argc; ++i) - { - if(string(argv[i]) == "--validate") - { - validate = true; - break; - } - } - + bool validate = find(argv.begin(), argv.end(), "--validate") != argv.end(); vector<string> args; try { - args = opts.parse(argc, (const char**)argv); + args = opts.parse(argv); } catch(const IceUtilInternal::BadOptException& e) { @@ -364,31 +355,35 @@ compile(int argc, char* argv[]) return status; } -int -main(int argc, char* argv[]) +#ifdef _WIN32 +int wmain(int argc, wchar_t* argv[]) +#else +int main(int argc, char* argv[]) +#endif { + vector<string> args = Slice::argvToArgs(argc, argv); try { - return compile(argc, argv); + return compile(args); } catch(const std::exception& ex) { - getErrorStream() << argv[0] << ": error:" << ex.what() << endl; + getErrorStream() << args[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << argv[0] << ": error:" << msg << endl; + getErrorStream() << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << argv[0] << ": error:" << msg << endl; + getErrorStream() << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << argv[0] << ": error:" << "unknown exception" << endl; + getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index ca06c64219c..140438eb37e 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -18,10 +18,9 @@ #include <IceUtil/StringUtil.h> #include <Slice/Checksum.h> #include <Slice/FileTracker.h> +#include <IceUtil/FileUtil.h> #include <limits> - -#include <sys/stat.h> #include <string.h> using namespace std; @@ -725,14 +724,14 @@ Slice::Gen::generate(const UnitPtr& p) fileImplC = _dir + '/' + fileImplC; } - struct stat st; - if(stat(fileImplH.c_str(), &st) == 0) + IceUtilInternal::structstat st; + if(!IceUtilInternal::stat(fileImplH, &st)) { ostringstream os; os << fileImplH << "' already exists - will not overwrite"; throw FileException(__FILE__, __LINE__, os.str()); } - if(stat(fileImplC.c_str(), &st) == 0) + if(!IceUtilInternal::stat(fileImplC, &st)) { ostringstream os; os << fileImplC << "' already exists - will not overwrite"; diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp index 66e9bcf2269..27376433b57 100644 --- a/cpp/src/slice2cpp/Main.cpp +++ b/cpp/src/slice2cpp/Main.cpp @@ -54,7 +54,7 @@ interruptedCallback(int /*signal*/) } void -usage(const char* n) +usage(const string& n) { getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; getErrorStream() << @@ -86,7 +86,7 @@ usage(const char* n) } int -compile(int argc, char* argv[]) +compile(const vector<string>& argv) { IceUtilInternal::Options opts; opts.addOpt("h", "help"); @@ -112,20 +112,11 @@ compile(int argc, char* argv[]) opts.addOpt("", "underscore"); opts.addOpt("", "checksum"); - bool validate = false; - for(int i = 0; i < argc; ++i) - { - if(string(argv[i]) == "--validate") - { - validate = true; - break; - } - } - + bool validate = find(argv.begin(), argv.end(), "--validate") != argv.end(); vector<string> args; try { - args = opts.parse(argc, const_cast<const char**>(argv)); + args = opts.parse(argv); } catch(const IceUtilInternal::BadOptException& e) { @@ -374,31 +365,35 @@ compile(int argc, char* argv[]) return status; } -int -main(int argc, char* argv[]) +#ifdef _WIN32 +int wmain(int argc, wchar_t* argv[]) +#else +int main(int argc, char* argv[]) +#endif { + vector<string> args = Slice::argvToArgs(argc, argv); try { - return compile(argc, argv); + return compile(args); } catch(const std::exception& ex) { - getErrorStream() << argv[0] << ": error:" << ex.what() << endl; + getErrorStream() << args[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << argv[0] << ": error:" << msg << endl; + getErrorStream() << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << argv[0] << ": error:" << msg << endl; + getErrorStream() << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << argv[0] << ": error:" << "unknown exception" << endl; + getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 5fa82827c4f..313c04ea229 100644 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -11,15 +11,14 @@ #include <IceUtil/Functional.h> #include <IceUtil/StringUtil.h> #include <IceUtil/InputUtil.h> +#include <IceUtil/FileUtil.h> #include <Gen.h> #include <limits> -#include <sys/stat.h> - #ifndef _WIN32 -# include <unistd.h> +# include <unistd.h> #else -# include <direct.h> +# include <direct.h> #endif #include <IceUtil/Iterator.h> @@ -2165,8 +2164,8 @@ Slice::Gen::Gen(const string& base, const vector<string>& includePaths, const st if(impl || implTie) { - struct stat st; - if(stat(fileImpl.c_str(), &st) == 0) + IceUtilInternal::structstat st; + if(!IceUtilInternal::stat(fileImpl, &st)) { ostringstream os; os << "`" << fileImpl << "' already exists - will not overwrite"; @@ -5684,7 +5683,7 @@ Slice::Gen::ImplVisitor::visitClassDefStart(const ClassDefPtr& p) string name = p->name(); - _out << sp << nl << "public sealed class " << name << 'I'; + _out << sp << nl << "public class " << name << 'I'; if(p->isInterface()) { if(p->isLocal()) diff --git a/cpp/src/slice2cs/Main.cpp b/cpp/src/slice2cs/Main.cpp index 73a9027689b..2268eb1fa0a 100644 --- a/cpp/src/slice2cs/Main.cpp +++ b/cpp/src/slice2cs/Main.cpp @@ -54,7 +54,7 @@ interruptedCallback(int /*signal*/) } void -usage(const char* n) +usage(const string& n) { getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; getErrorStream() << @@ -82,7 +82,7 @@ usage(const char* n) } int -compile(int argc, char* argv[]) +compile(const vector<string>& argv) { IceUtilInternal::Options opts; opts.addOpt("h", "help"); @@ -104,20 +104,11 @@ compile(int argc, char* argv[]) opts.addOpt("", "underscore"); opts.addOpt("", "checksum"); - bool validate = false; - for(int i = 0; i < argc; ++i) - { - if(string(argv[i]) == "--validate") - { - validate = true; - break; - } - } - + bool validate = find(argv.begin(), argv.end(), "--validate") != argv.end(); vector<string> args; try { - args = opts.parse(argc, const_cast<const char**>(argv)); + args = opts.parse(argv); } catch(const IceUtilInternal::BadOptException& e) { @@ -372,31 +363,35 @@ compile(int argc, char* argv[]) return status; } -int -main(int argc, char* argv[]) +#ifdef _WIN32 +int wmain(int argc, wchar_t* argv[]) +#else +int main(int argc, char* argv[]) +#endif { + vector<string> args = Slice::argvToArgs(argc, argv); try { - return compile(argc, argv); + return compile(args); } catch(const std::exception& ex) { - getErrorStream() << argv[0] << ": error:" << ex.what() << endl; + getErrorStream() << args[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << argv[0] << ": error:" << msg << endl; + getErrorStream() << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << argv[0] << ": error:" << msg << endl; + getErrorStream() << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << argv[0] << ": error:" << "unknown exception" << endl; + getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } diff --git a/cpp/src/slice2html/Gen.cpp b/cpp/src/slice2html/Gen.cpp index 03e87cefec9..a5e03d6015f 100644 --- a/cpp/src/slice2html/Gen.cpp +++ b/cpp/src/slice2html/Gen.cpp @@ -10,20 +10,19 @@ #include <IceUtil/DisableWarnings.h> #include <IceUtil/Functional.h> #include <IceUtil/StringUtil.h> +#include <IceUtil/FileUtil.h> #include <Slice/FileTracker.h> #include <Gen.h> #include <sys/types.h> -#include <sys/stat.h> #ifdef _WIN32 -#include <direct.h> +# include <direct.h> #else -#include <unistd.h> +# include <unistd.h> #endif #include <iterator> - #include <string.h> using namespace std; @@ -352,7 +351,7 @@ Slice::GeneratorBase::printComment(const ContainedPtr& p, const SyntaxTreeBasePt { item = q->substr(pos); } - + start("dt", "Symbol"); _out << term; end(); @@ -393,7 +392,7 @@ Slice::GeneratorBase::printComment(const ContainedPtr& p, const SyntaxTreeBasePt { item = q->substr(pos); } - + start("dt", "Symbol"); _out << getURL(toSliceID(term, source->definitionContext()->filename()), source, false); end(); @@ -1316,14 +1315,14 @@ Slice::GeneratorBase::getTagged(const string& tag, string& comment) { return result; } - + string::size_type pos1 = comment.find_first_not_of(" \t\r\n", begin + tag.size() + 1); if(pos1 == string::npos) { comment.erase(begin); return result; } - + string::size_type pos2 = comment.find('@', pos1); string line = comment.substr(pos1, pos2 - pos1); comment.erase(begin, pos2 - 1 - begin); @@ -1357,7 +1356,7 @@ Slice::GeneratorBase::getScopedMinimized(const SyntaxTreeBasePtr& target, const { return scoped.substr(2); } - + do { string scoped2 = s->scoped(); @@ -1559,9 +1558,8 @@ Slice::GeneratorBase::toStringList(const string& scoped) void Slice::GeneratorBase::makeDir(const string& dir) { - struct stat st; - int rc = stat(dir.c_str(), &st); - if(rc == 0) + IceUtilInternal::structstat st; + if(!IceUtilInternal::stat(dir, &st)) { if(!(st.st_mode & S_IFDIR)) { @@ -1573,12 +1571,7 @@ Slice::GeneratorBase::makeDir(const string& dir) return; } -#ifdef _WIN32 - rc = _mkdir(dir.c_str()); -#else - rc = mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); -#endif - if(rc != 0) + if(IceUtilInternal::mkdir(dir, 0777) != 0) { ostringstream os; os << "cannot create directory `" << dir << "': " << strerror(errno); @@ -1590,7 +1583,7 @@ Slice::GeneratorBase::makeDir(const string& dir) string Slice::GeneratorBase::readFile(const string& file) { - ifstream in(file.c_str()); + ifstream in(streamFilename(file).c_str()); if(!in) { ostringstream os; @@ -1606,7 +1599,7 @@ Slice::GeneratorBase::readFile(const string& file) result << line << '\n'; getline(in, line); } - + return result.str(); } @@ -1664,7 +1657,7 @@ Slice::GeneratorBase::getFooter(const string& footer) void Slice::GeneratorBase::readFile(const string& file, string& part1, string& part2) { - ifstream in(file.c_str()); + ifstream in(streamFilename(file).c_str()); if(!in) { ostringstream os; @@ -2568,7 +2561,7 @@ Slice::ExceptionGenerator::generate(const ExceptionPtr& e) } end(); } - + _out << nl << "<hr>"; printHeaderFooter(e); @@ -2894,7 +2887,7 @@ Slice::StructGenerator::generate(const StructPtr& s) } end(); } - + _out << nl << "<hr>"; printHeaderFooter(s); @@ -2973,7 +2966,7 @@ Slice::EnumGenerator::generate(const EnumPtr& e) } end(); } - + closeDoc(); _out << nl << "<hr>"; diff --git a/cpp/src/slice2html/Main.cpp b/cpp/src/slice2html/Main.cpp index 0b9a0b24590..818882ceb61 100644 --- a/cpp/src/slice2html/Main.cpp +++ b/cpp/src/slice2html/Main.cpp @@ -56,7 +56,7 @@ interruptedCallback(int /*signal*/) } void -usage(const char* n) +usage(const string& n) { getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; getErrorStream() << @@ -86,7 +86,7 @@ usage(const char* n) } int -compile(int argc, char* argv[]) +compile(const vector<string>& argv) { IceUtilInternal::Options opts; opts.addOpt("h", "help"); @@ -110,20 +110,11 @@ compile(int argc, char* argv[]) opts.addOpt("", "ice"); opts.addOpt("", "underscore"); - bool validate = false; - for(int i = 0; i < argc; ++i) - { - if(string(argv[i]) == "--validate") - { - validate = true; - break; - } - } - + bool validate = find(argv.begin(), argv.end(), "--validate") != argv.end(); vector<string> args; try { - args = opts.parse(argc, const_cast<const char**>(argv)); + args = opts.parse(argv); } catch(const IceUtilInternal::BadOptException& e) { @@ -336,31 +327,35 @@ compile(int argc, char* argv[]) return status; } -int -main(int argc, char* argv[]) +#ifdef _WIN32 +int wmain(int argc, wchar_t* argv[]) +#else +int main(int argc, char* argv[]) +#endif { + vector<string> args = argvToArgs(argc, argv); try { - return compile(argc, argv); + return compile(args); } catch(const std::exception& ex) { - getErrorStream() << argv[0] << ": error:" << ex.what() << endl; + getErrorStream() << args[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << argv[0] << ": error:" << msg << endl; + getErrorStream() << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << argv[0] << ": error:" << msg << endl; + getErrorStream() << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << argv[0] << ": error:" << "unknown exception" << endl; + getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp index c92a4264d71..d864279a544 100644 --- a/cpp/src/slice2java/Main.cpp +++ b/cpp/src/slice2java/Main.cpp @@ -56,7 +56,7 @@ interruptedCallback(int /*signal*/) } void -usage(const char* n) +usage(const string& n) { getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; getErrorStream() << @@ -87,7 +87,7 @@ usage(const char* n) } int -compile(int argc, char* argv[]) +compile(const vector<string>& argv) { IceUtilInternal::Options opts; opts.addOpt("h", "help"); @@ -112,19 +112,11 @@ compile(int argc, char* argv[]) opts.addOpt("", "meta", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); opts.addOpt("", "compat"); - bool validate = false; - for(int i = 0; i < argc; ++i) - { - if(string(argv[i]) == "--validate") - { - validate = true; - break; - } - } + bool validate = find(argv.begin(), argv.end(), "--validate") != argv.end(); vector<string>args; try { - args = opts.parse(argc, const_cast<const char**>(argv)); + args = opts.parse(argv); } catch(const IceUtilInternal::BadOptException& e) { @@ -485,31 +477,35 @@ compile(int argc, char* argv[]) return status; } -int -main(int argc, char* argv[]) +#ifdef _WIN32 +int wmain(int argc, wchar_t* argv[]) +#else +int main(int argc, char* argv[]) +#endif { + vector<string> args = argvToArgs(argc, argv); try { - return compile(argc, argv); + return compile(args); } catch(const std::exception& ex) { - getErrorStream() << argv[0] << ": error:" << ex.what() << endl; + getErrorStream() << args[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << argv[0] << ": error:" << msg << endl; + getErrorStream() << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << argv[0] << ": error:" << msg << endl; + getErrorStream() << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << argv[0] << ": error:" << "unknown exception" << endl; + getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } diff --git a/cpp/src/slice2js/Main.cpp b/cpp/src/slice2js/Main.cpp index da15f8b1064..862e1343e02 100644 --- a/cpp/src/slice2js/Main.cpp +++ b/cpp/src/slice2js/Main.cpp @@ -54,7 +54,7 @@ interruptedCallback(int /*signal*/) } void -usage(const char* n) +usage(const string& n) { getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; getErrorStream() << @@ -80,7 +80,7 @@ usage(const char* n) } int -compile(int argc, char* argv[]) +compile(const vector<string>& argv) { IceUtilInternal::Options opts; opts.addOpt("h", "help"); @@ -100,20 +100,12 @@ compile(int argc, char* argv[]) opts.addOpt("", "ice"); opts.addOpt("", "underscore"); - bool validate = false; - for(int i = 0; i < argc; ++i) - { - if(string(argv[i]) == "--validate") - { - validate = true; - break; - } - } + bool validate = find(argv.begin(), argv.end(), "--validate") != argv.end(); vector<string> args; try { - args = opts.parse(argc, const_cast<const char**>(argv)); + args = opts.parse(argv); } catch(const IceUtilInternal::BadOptException& e) { @@ -393,31 +385,35 @@ compile(int argc, char* argv[]) return status; } -int -main(int argc, char* argv[]) +#ifdef _WIN32 +int wmain(int argc, wchar_t* argv[]) +#else +int main(int argc, char* argv[]) +#endif { + vector<string> args = Slice::argvToArgs(argc, argv); try { - return compile(argc, argv); + return compile(args); } catch(const std::exception& ex) { - getErrorStream() << argv[0] << ": error:" << ex.what() << endl; + getErrorStream() << args[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << argv[0] << ": error:" << msg << endl; + getErrorStream() << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << argv[0] << ": error:" << msg << endl; + getErrorStream() << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << argv[0] << ": error:" << "unknown exception" << endl; + getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } diff --git a/cpp/src/slice2objc/Main.cpp b/cpp/src/slice2objc/Main.cpp index 1a766772ef0..c8d68d39bf1 100644 --- a/cpp/src/slice2objc/Main.cpp +++ b/cpp/src/slice2objc/Main.cpp @@ -53,7 +53,7 @@ interruptedCallback(int signal) } void -usage(const char* n) +usage(const string& n) { cerr << "Usage: " << n << " [options] slice-files...\n"; cerr << @@ -80,7 +80,7 @@ usage(const char* n) } int -main(int argc, char* argv[]) +compile(const vector<string>& argv) { IceUtilInternal::Options opts; opts.addOpt("h", "help"); @@ -101,20 +101,12 @@ main(int argc, char* argv[]) opts.addOpt("", "underscore"); opts.addOpt("", "case-sensitive"); - bool validate = false; - for(int i = 0; i < argc; ++i) - { - if(string(argv[i]) == "--validate") - { - validate = true; - break; - } - } + bool validate = find(argv.begin(), argv.end(), "--validate") != argv.end(); vector<string> args; try { - args = opts.parse(argc, (const char**)argv); + args = opts.parse(argv); } catch(const IceUtilInternal::BadOptException& e) { @@ -334,3 +326,36 @@ main(int argc, char* argv[]) return status; } + +#ifdef _WIN32 +int wmain(int argc, wchar_t* argv[]) +#else +int main(int argc, char* argv[]) +#endif +{ + vector<string> args = Slice::argvToArgs(argc, argv); + try + { + return compile(args); + } + catch(const std::exception& ex) + { + getErrorStream() << args[0] << ": error:" << ex.what() << endl; + return EXIT_FAILURE; + } + catch(const std::string& msg) + { + getErrorStream() << args[0] << ": error:" << msg << endl; + return EXIT_FAILURE; + } + catch(const char* msg) + { + getErrorStream() << args[0] << ": error:" << msg << endl; + return EXIT_FAILURE; + } + catch(...) + { + getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; + return EXIT_FAILURE; + } +} diff --git a/cpp/src/slice2php/Main.cpp b/cpp/src/slice2php/Main.cpp index e6676731cdc..b0f4b4ec7cb 100644 --- a/cpp/src/slice2php/Main.cpp +++ b/cpp/src/slice2php/Main.cpp @@ -1627,7 +1627,7 @@ interruptedCallback(int /*signal*/) } static void -usage(const char* n) +usage(const string& n) { getErrorStream() << "Usage: " << n << " [options] slice-files...\n"; getErrorStream() << @@ -1654,7 +1654,7 @@ usage(const char* n) } int -compile(int argc, char* argv[]) +compile(const vector<string>& argv) { IceUtilInternal::Options opts; opts.addOpt("h", "help"); @@ -1675,20 +1675,12 @@ compile(int argc, char* argv[]) opts.addOpt("", "checksum"); opts.addOpt("n", "namespace"); - bool validate = false; - for(int i = 0; i < argc; ++i) - { - if(string(argv[i]) == "--validate") - { - validate = true; - break; - } - } + bool validate = find(argv.begin(), argv.end(), "--validate") != argv.end(); vector<string> args; try { - args = opts.parse(argc, const_cast<const char**>(argv)); + args = opts.parse(argv); } catch(const IceUtilInternal::BadOptException& e) { @@ -1954,31 +1946,35 @@ compile(int argc, char* argv[]) return status; } -int -main(int argc, char* argv[]) +#ifdef _WIN32 +int wmain(int argc, wchar_t* argv[]) +#else +int main(int argc, char* argv[]) +#endif { + vector<string> args = Slice::argvToArgs(argc, argv); try { - return compile(argc, argv); + return compile(args); } catch(const std::exception& ex) { - getErrorStream() << argv[0] << ": error:" << ex.what() << endl; + getErrorStream() << args[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << argv[0] << ": error:" << msg << endl; + getErrorStream() << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << argv[0] << ": error:" << msg << endl; + getErrorStream() << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << argv[0] << ": error:" << "unknown exception" << endl; + getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } diff --git a/cpp/src/slice2py/Main.cpp b/cpp/src/slice2py/Main.cpp index ab22e73a5b0..39e103cfb4e 100644 --- a/cpp/src/slice2py/Main.cpp +++ b/cpp/src/slice2py/Main.cpp @@ -14,31 +14,35 @@ using namespace std; using namespace Slice; using namespace Slice::Python; -int -main(int argc, char* argv[]) +#ifdef _WIN32 +int wmain(int argc, wchar_t* argv[]) +#else +int main(int argc, char* argv[]) +#endif { + vector<string> args = Slice::argvToArgs(argc, argv); try { - return Slice::Python::compile(argc, argv); + return Slice::Python::compile(args); } catch(const std::exception& ex) { - getErrorStream() << argv[0] << ": error:" << ex.what() << endl; + getErrorStream() << args[0] << ": error:" << ex.what() << endl; return EXIT_FAILURE; } catch(const std::string& msg) { - getErrorStream() << argv[0] << ": error:" << msg << endl; + getErrorStream() << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(const char* msg) { - getErrorStream() << argv[0] << ": error:" << msg << endl; + getErrorStream() << args[0] << ": error:" << msg << endl; return EXIT_FAILURE; } catch(...) { - getErrorStream() << argv[0] << ": error:" << "unknown exception" << endl; + getErrorStream() << args[0] << ": error:" << "unknown exception" << endl; return EXIT_FAILURE; } } diff --git a/cpp/src/slice2rb/Main.cpp b/cpp/src/slice2rb/Main.cpp index 8c38a8bd60b..7b489503f71 100644 --- a/cpp/src/slice2rb/Main.cpp +++ b/cpp/src/slice2rb/Main.cpp @@ -17,9 +17,10 @@ using namespace Slice::Ruby; int main(int argc, char* argv[]) { + vector<string> args = Slice::argvToArgs(argc, argv); try { - return Slice::Ruby::compile(argc, argv); + return Slice::Ruby::compile(args); } catch(const std::exception& ex) { |