diff options
Diffstat (limited to 'cpp')
30 files changed, 264 insertions, 631 deletions
diff --git a/cpp/include/Ice/Application.h b/cpp/include/Ice/Application.h index ff948a6fe0d..3096327efde 100644 --- a/cpp/include/Ice/Application.h +++ b/cpp/include/Ice/Application.h @@ -36,16 +36,6 @@ public: int main(int, char*[], const char*); int main(int, char*[], const char*, const Ice::PropertiesPtr&); int main(int, char*[], const Ice::InitializationData&); - -#ifdef _WIN32 - - int main(int, wchar_t*[]); - int main(int, wchar_t*[], const char*); - int main(int, wchar_t*[], const char*, const Ice::PropertiesPtr&); - int main(int, wchar_t*[], const Ice::InitializationData&); - -#endif - int main(const StringSeq&); int main(const StringSeq&, const char*); int main(const StringSeq&, const char*, const Ice::PropertiesPtr&); diff --git a/cpp/include/Ice/Initialize.h b/cpp/include/Ice/Initialize.h index 58d097b6a18..2d7d83e290e 100644 --- a/cpp/include/Ice/Initialize.h +++ b/cpp/include/Ice/Initialize.h @@ -25,15 +25,6 @@ namespace Ice ICE_API void collectGarbage(); ICE_API StringSeq argsToStringSeq(int, char*[]); - -#ifdef _WIN32 - -ICE_API StringSeq argsToStringSeq(int, wchar_t*[]); - -ICE_API StringSeq argsToStringSeq(int, wchar_t*[], const StringConverterPtr&); - -#endif - // // This function assumes that the string sequence only contains // elements of the argument vector. The function shifts the diff --git a/cpp/include/Ice/Service.h b/cpp/include/Ice/Service.h index 33d9cb73cc5..9afb59498dd 100644 --- a/cpp/include/Ice/Service.h +++ b/cpp/include/Ice/Service.h @@ -60,13 +60,6 @@ public: // EXIT_SUCCESS. // int main(int&, char*[], const InitializationData& = InitializationData()); - -#ifdef _WIN32 - - int main(int&, wchar_t*[], const InitializationData& = InitializationData()); - -#endif - int main(StringSeq&, const InitializationData& = InitializationData()); // diff --git a/cpp/include/IceUtil/FileUtil.h b/cpp/include/IceUtil/FileUtil.h index f68ec32ce03..d081a6a5cba 100644 --- a/cpp/include/IceUtil/FileUtil.h +++ b/cpp/include/IceUtil/FileUtil.h @@ -11,7 +11,6 @@ #define ICE_FILE_UTIL_H #include <IceUtil/Config.h> -#include <sys/stat.h> namespace IceUtilInternal { @@ -21,39 +20,6 @@ namespace IceUtilInternal // ICE_UTIL_API bool isAbsolutePath(const std::string&); -// -// Determine if a file exists. -// -ICE_UTIL_API bool fileExists(const std::string&); - -// -// Determine if a directory exists. -// -ICE_UTIL_API bool directoryExists(const std::string&); - -#ifdef _WIN32 - -typedef struct _stat64i32 structstat; -#ifdef _MSC_VER -# define O_RDONLY _O_RDONLY -# define O_BINARY _O_BINARY - -# define S_ISDIR(mode) ((mode) & _S_IFDIR) -# define S_ISREG(mode) ((mode) & _S_IFREG) -#endif - -#else - -typedef struct stat structstat; -# define O_BINARY 0 - -#endif - -// -// OS stat -// -ICE_UTIL_API int stat(const std::string&, structstat*); - }; #endif diff --git a/cpp/src/FreezeScript/DumpDB.cpp b/cpp/src/FreezeScript/DumpDB.cpp index 784f481f8ef..b528837369c 100644 --- a/cpp/src/FreezeScript/DumpDB.cpp +++ b/cpp/src/FreezeScript/DumpDB.cpp @@ -77,7 +77,7 @@ private: } static void -usage(const string& n) +usage(const char* n) { cerr << "Usage:\n"; cerr << "\n"; @@ -123,7 +123,7 @@ printCatalogData(const string& dbName, const Freeze::CatalogData& data) } static int -run(Ice::StringSeq& args, const Ice::CommunicatorPtr& communicator) +run(int argc, char** argv, const Ice::CommunicatorPtr& communicator) { vector<string> cppArgs; bool debug; @@ -136,7 +136,7 @@ run(Ice::StringSeq& args, const Ice::CommunicatorPtr& communicator) string valueTypeName; string selectExpr; string dbEnvName, dbName; - const string appName = args[0]; + IceUtilInternal::Options opts; opts.addOpt("h", "help"); opts.addOpt("v", "version"); @@ -154,24 +154,24 @@ run(Ice::StringSeq& args, const Ice::CommunicatorPtr& communicator) opts.addOpt("", "select", IceUtilInternal::Options::NeedArg); opts.addOpt("c", "catalog"); - vector<string> noArgs; + vector<string> args; try { #if defined(__BCPLUSPLUS__) && (__BCPLUSPLUS__ >= 0x0600) IceUtil::DummyBCC dummy; #endif - noArgs = opts.parse(args); + args = opts.parse(argc, (const char**)argv); } catch(const IceUtilInternal::BadOptException& e) { - cerr << appName << ": " << e.reason << endl; - usage(appName); + cerr << argv[0] << ": " << e.reason << endl; + usage(argv[0]); return EXIT_FAILURE; } if(opts.isSet("h")) { - usage(appName); + usage(argv[0]); return EXIT_SUCCESS; } if(opts.isSet("version")) @@ -183,19 +183,19 @@ run(Ice::StringSeq& args, const Ice::CommunicatorPtr& communicator) { if(args.empty()) { - cerr << appName << ": no database environment specified." << endl; - usage(appName); + cerr << argv[0] << ": no database environment specified." << endl; + usage(argv[0]); return EXIT_FAILURE; } - else if(noArgs.size() > 2) + else if(args.size() > 2) { - usage(appName); + usage(argv[0]); return EXIT_FAILURE; } try { - FreezeScript::CatalogDataMap catalog = FreezeScript::readCatalog(communicator, noArgs[0]); - if(noArgs.size() == 1) + FreezeScript::CatalogDataMap catalog = FreezeScript::readCatalog(communicator, args[0]); + if(args.size() == 1) { if(catalog.empty()) { @@ -213,10 +213,10 @@ run(Ice::StringSeq& args, const Ice::CommunicatorPtr& communicator) } else { - FreezeScript::CatalogDataMap::const_iterator p = catalog.find(noArgs[1]); + FreezeScript::CatalogDataMap::const_iterator p = catalog.find(args[1]); if(p == catalog.end()) { - cerr << appName << ": database `" << noArgs[1] << "' not found in environment `" << noArgs[0] << "'." + cerr << argv[0] << ": database `" << args[1] << "' not found in environment `" << args[0] << "'." << endl; return EXIT_FAILURE; } @@ -229,7 +229,7 @@ run(Ice::StringSeq& args, const Ice::CommunicatorPtr& communicator) } catch(const FreezeScript::FailureException& ex) { - cerr << appName << ": " << ex.reason() << endl; + cerr << argv[0] << ": " << ex.reason() << endl; return EXIT_FAILURE; } } @@ -291,35 +291,35 @@ run(Ice::StringSeq& args, const Ice::CommunicatorPtr& communicator) selectExpr = opts.optArg("select"); } - if(outputFile.empty() && noArgs.size() != 2) + if(outputFile.empty() && args.size() != 2) { - usage(appName); + usage(argv[0]); return EXIT_FAILURE; } - if(!noArgs.empty()) + if(!args.empty()) { - dbEnvName = noArgs[0]; + dbEnvName = args[0]; } - if(noArgs.size() == 2) + if(args.size() == 2) { - dbName = noArgs[1]; + dbName = args[1]; } else { - usage(appName); + usage(argv[0]); return EXIT_FAILURE; } if(!inputFile.empty() && !selectExpr.empty()) { - cerr << appName << ": an input file cannot be specified with --select" << endl; + cerr << argv[0] << ": an input file cannot be specified with --select" << endl; return EXIT_FAILURE; } Slice::UnitPtr unit = Slice::Unit::createUnit(true, true, ice); FreezeScript::Destroyer<Slice::UnitPtr> unitD(unit); - if(!FreezeScript::parseSlice(appName, unit, slice, cppArgs, debug)) + if(!FreezeScript::parseSlice(argv[0], unit, slice, cppArgs, debug)) { return EXIT_FAILURE; } @@ -337,8 +337,8 @@ run(Ice::StringSeq& args, const Ice::CommunicatorPtr& communicator) if((!keyTypeName.empty() && valueTypeName.empty()) || (keyTypeName.empty() && !valueTypeName.empty())) { - cerr << appName << ": a key type and a value type must be specified" << endl; - usage(appName); + cerr << argv[0] << ": a key type and a value type must be specified" << endl; + usage(argv[0]); return EXIT_FAILURE; } else if(!evictor && keyTypeName.empty() && valueTypeName.empty()) @@ -349,7 +349,7 @@ run(Ice::StringSeq& args, const Ice::CommunicatorPtr& communicator) FreezeScript::CatalogDataMap::iterator p = catalog.find(dbName); if(p == catalog.end()) { - cerr << appName << ": database `" << dbName << "' not found in catalog." << endl; + cerr << argv[0] << ": database `" << dbName << "' not found in catalog." << endl; cerr << "Current catalog databases:" << endl; for(p = catalog.begin(); p != catalog.end(); ++p) { @@ -372,7 +372,7 @@ run(Ice::StringSeq& args, const Ice::CommunicatorPtr& communicator) } catch(const FreezeScript::FailureException& ex) { - cerr << appName << ": " << ex.reason() << endl; + cerr << argv[0] << ": " << ex.reason() << endl; return EXIT_FAILURE; } } @@ -389,7 +389,7 @@ run(Ice::StringSeq& args, const Ice::CommunicatorPtr& communicator) l = unit->lookupType(keyTypeName, false); if(l.empty()) { - cerr << appName << ": unknown key type `" << keyTypeName << "'" << endl; + cerr << argv[0] << ": unknown key type `" << keyTypeName << "'" << endl; return EXIT_FAILURE; } keyType = l.front(); @@ -397,7 +397,7 @@ run(Ice::StringSeq& args, const Ice::CommunicatorPtr& communicator) l = unit->lookupType(valueTypeName, false); if(l.empty()) { - cerr << appName << ": unknown value type `" << valueTypeName << "'" << endl; + cerr << argv[0] << ": unknown value type `" << valueTypeName << "'" << endl; return EXIT_FAILURE; } valueType = l.front(); @@ -419,7 +419,7 @@ run(Ice::StringSeq& args, const Ice::CommunicatorPtr& communicator) ofstream of(outputFile.c_str()); if(!of.good()) { - cerr << appName << ": unable to open file `" << outputFile << "'" << endl; + cerr << argv[0] << ": unable to open file `" << outputFile << "'" << endl; return EXIT_FAILURE; } of << descriptors << endl; @@ -543,7 +543,7 @@ run(Ice::StringSeq& args, const Ice::CommunicatorPtr& communicator) } catch(const DbException& ex) { - cerr << appName << ": database error: " << ex.what() << endl; + cerr << argv[0] << ": database error: " << ex.what() << endl; status = EXIT_FAILURE; } catch(...) @@ -558,7 +558,7 @@ run(Ice::StringSeq& args, const Ice::CommunicatorPtr& communicator) } catch(const DbException& ex) { - cerr << appName << ": database error: " << ex.what() << endl; + cerr << argv[0] << ": database error: " << ex.what() << endl; } throw; } @@ -573,7 +573,7 @@ run(Ice::StringSeq& args, const Ice::CommunicatorPtr& communicator) } catch(const DbException& ex) { - cerr << appName << ": database error: " << ex.what() << endl; + cerr << argv[0] << ": database error: " << ex.what() << endl; status = EXIT_FAILURE; } @@ -581,23 +581,19 @@ run(Ice::StringSeq& args, const Ice::CommunicatorPtr& communicator) } int -mainInternal(Ice::StringSeq& args) +main(int argc, char* argv[]) { - assert(args.size() > 0); - const string appName = args[0]; Ice::CommunicatorPtr communicator; int status = EXIT_SUCCESS; try { - Ice::InitializationData initData; - initData.properties = Ice::createProperties(); - communicator = Ice::initialize(args, initData); - status = run(args, communicator); + communicator = Ice::initialize(argc, argv); + status = run(argc, argv, communicator); } catch(const FreezeScript::FailureException& ex) { string reason = ex.reason(); - cerr << appName << ": " << reason; + cerr << argv[0] << ": " << reason; if(reason[reason.size() - 1] != '\n') { cerr << endl; @@ -606,7 +602,7 @@ mainInternal(Ice::StringSeq& args) } catch(const IceUtil::Exception& ex) { - cerr << appName << ": " << ex << endl; + cerr << argv[0] << ": " << ex << endl; return EXIT_FAILURE; } @@ -618,22 +614,6 @@ mainInternal(Ice::StringSeq& args) return status; } -#ifdef _WIN32 - -int -wmain(int argc, wchar_t* argv[]) - -#else - -int -main(int argc, char* argv[]) - -#endif -{ - Ice::StringSeq args = Ice::argsToStringSeq(argc, argv); - return mainInternal(args); -} - // // SliceVisitor // diff --git a/cpp/src/FreezeScript/transformdb.cpp b/cpp/src/FreezeScript/transformdb.cpp index e2b3e07b76a..5865a89f6f5 100644 --- a/cpp/src/FreezeScript/transformdb.cpp +++ b/cpp/src/FreezeScript/transformdb.cpp @@ -29,8 +29,9 @@ using namespace std; #endif static void -usage(const std::string& n) +usage(const char* n) { + cerr << "Usage:\n"; cerr << "\n"; cerr << n << " -o FILE [-i] [slice-options] [type-options]\n"; @@ -211,7 +212,7 @@ transformDb(bool evictor, const Ice::CommunicatorPtr& communicator, } static int -run(Ice::StringSeq args, const Ice::CommunicatorPtr& communicator) +run(int argc, char** argv, const Ice::CommunicatorPtr& communicator) { vector<string> oldCppArgs; vector<string> newCppArgs; @@ -252,25 +253,24 @@ run(Ice::StringSeq args, const Ice::CommunicatorPtr& communicator) opts.addOpt("", "key", IceUtilInternal::Options::NeedArg); opts.addOpt("", "value", IceUtilInternal::Options::NeedArg); - const string appName = args[0]; - vector<string> noArgs; + vector<string> args; try { #if defined(__BCPLUSPLUS__) && (__BCPLUSPLUS__ >= 0x0600) IceUtil::DummyBCC dummy; #endif - noArgs = opts.parse(args); + args = opts.parse(argc, (const char**)argv); } catch(const IceUtilInternal::BadOptException& e) { - cerr << appName << ": " << e.reason << endl; - usage(appName); + cerr << argv[0] << ": " << e.reason << endl; + usage(argv[0]); return EXIT_FAILURE; } if(opts.isSet("help")) { - usage(appName); + usage(argv[0]); return EXIT_SUCCESS; } if(opts.isSet("version")) @@ -354,77 +354,77 @@ run(Ice::StringSeq args, const Ice::CommunicatorPtr& communicator) if(outputFile.empty()) { - if(noArgs.size() == 2) + if(args.size() == 2) { allDb = true; } - else if(noArgs.size() != 3) + else if(args.size() != 3) { - usage(appName); + usage(argv[0]); return EXIT_FAILURE; } } else { - if(noArgs.size() == 1) + if(args.size() == 1) { allDb = true; } - else if(noArgs.size() != 0) + else if(args.size() != 0) { - usage(appName); + usage(argv[0]); return EXIT_FAILURE; } } if(allDb && (!keyTypeNames.empty() || !valueTypeNames.empty())) { - usage(appName); + usage(argv[0]); return EXIT_FAILURE; } if(inputFile.empty() && !allDb && !evictor && (keyTypeNames.empty() || valueTypeNames.empty())) { - usage(appName); + usage(argv[0]); return EXIT_FAILURE; } - if(noArgs.size() > 0) + if(args.size() > 0) { - dbEnvName = noArgs[0]; + dbEnvName = args[0]; } - if(noArgs.size() > 1) + if(args.size() > 1) { if(allDb) { - dbEnvNameNew = noArgs[1]; + dbEnvNameNew = args[1]; } else { - dbName = noArgs[1]; + dbName = args[1]; } } - if(noArgs.size() > 2) + if(args.size() > 2) { - dbEnvNameNew = noArgs[2]; + dbEnvNameNew = args[2]; } - if(noArgs.size() > 3) + if(args.size() > 3) { - cerr << appName << ": too many arguments" << endl; - usage(appName); + cerr << argv[0] << ": too many arguments" << endl; + usage(argv[0]); return EXIT_FAILURE; } Slice::UnitPtr oldUnit = Slice::Unit::createUnit(true, true, ice); FreezeScript::Destroyer<Slice::UnitPtr> oldD(oldUnit); - if(!FreezeScript::parseSlice(appName, oldUnit, oldSlice, oldCppArgs, debug)) + if(!FreezeScript::parseSlice(argv[0], oldUnit, oldSlice, oldCppArgs, debug)) { return EXIT_FAILURE; } Slice::UnitPtr newUnit = Slice::Unit::createUnit(true, true, ice); FreezeScript::Destroyer<Slice::UnitPtr> newD(newUnit); - if(!FreezeScript::parseSlice(appName, newUnit, newSlice, newCppArgs, debug)) + if(!FreezeScript::parseSlice(argv[0], newUnit, newSlice, newCppArgs, debug)) { return EXIT_FAILURE; } @@ -447,12 +447,12 @@ run(Ice::StringSeq args, const Ice::CommunicatorPtr& communicator) } catch(const FreezeScript::FailureException& ex) { - cerr << appName << ": " << ex.reason() << endl; + cerr << argv[0] << ": " << ex.reason() << endl; return EXIT_FAILURE; } if(catalog.empty()) { - cerr << appName << ": no databases in environment `" << dbEnvName << "'" << endl; + cerr << argv[0] << ": no databases in environment `" << dbEnvName << "'" << endl; return EXIT_FAILURE; } } @@ -499,25 +499,25 @@ run(Ice::StringSeq args, const Ice::CommunicatorPtr& communicator) Slice::TypePtr oldKeyType = findType(oldUnit, keyName); if(!oldKeyType) { - cerr << appName << ": type `" << keyName << "' from database `" << p->first + cerr << argv[0] << ": type `" << keyName << "' from database `" << p->first << "' not found in old Slice definitions" << endl; } Slice::TypePtr newKeyType = findType(newUnit, keyName); if(!newKeyType) { - cerr << appName << ": type `" << keyName << "' from database `" << p->first + cerr << argv[0] << ": type `" << keyName << "' from database `" << p->first << "' not found in new Slice definitions" << endl; } Slice::TypePtr oldValueType = findType(oldUnit, valueName); if(!oldValueType) { - cerr << appName << ": type `" << valueName << "' from database `" << p->first + cerr << argv[0] << ": type `" << valueName << "' from database `" << p->first << "' not found in old Slice definitions" << endl; } Slice::TypePtr newValueType = findType(newUnit, valueName); if(!newValueType) { - cerr << appName << ": type `" << valueName << "' from database `" << p->first + cerr << argv[0] << ": type `" << valueName << "' from database `" << p->first << "' not found in new Slice definitions" << endl; } @@ -553,14 +553,14 @@ run(Ice::StringSeq args, const Ice::CommunicatorPtr& communicator) if(keyTypeNames.empty() || valueTypeNames.empty()) { - usage(appName); + usage(argv[0]); return EXIT_FAILURE; } pos = keyTypeNames.find(','); if(pos == 0 || pos == keyTypeNames.size()) { - usage(appName); + usage(argv[0]); return EXIT_FAILURE; } if(pos == string::npos) @@ -577,7 +577,7 @@ run(Ice::StringSeq args, const Ice::CommunicatorPtr& communicator) pos = valueTypeNames.find(','); if(pos == 0 || pos == valueTypeNames.size()) { - usage(appName); + usage(argv[0]); return EXIT_FAILURE; } if(pos == string::npos) @@ -598,22 +598,22 @@ run(Ice::StringSeq args, const Ice::CommunicatorPtr& communicator) Slice::TypePtr oldKeyType = findType(oldUnit, oldKeyName); if(!oldKeyType) { - cerr << appName << ": type `" << oldKeyName << "' not found in old Slice definitions" << endl; + cerr << argv[0] << ": type `" << oldKeyName << "' not found in old Slice definitions" << endl; } Slice::TypePtr newKeyType = findType(newUnit, newKeyName); if(!newKeyType) { - cerr << appName << ": type `" << newKeyName << "' not found in new Slice definitions" << endl; + cerr << argv[0] << ": type `" << newKeyName << "' not found in new Slice definitions" << endl; } Slice::TypePtr oldValueType = findType(oldUnit, oldValueName); if(!oldValueType) { - cerr << appName << ": type `" << oldValueName << "' not found in old Slice definitions" << endl; + cerr << argv[0] << ": type `" << oldValueName << "' not found in old Slice definitions" << endl; } Slice::TypePtr newValueType = findType(newUnit, newValueName); if(!newValueType) { - cerr << appName << ": type `" << newValueName << "' not found in new Slice definitions" << endl; + cerr << argv[0] << ": type `" << newValueName << "' not found in new Slice definitions" << endl; } // @@ -633,7 +633,7 @@ run(Ice::StringSeq args, const Ice::CommunicatorPtr& communicator) { for(vector<string>::const_iterator p = analyzeErrors.begin(); p != analyzeErrors.end(); ++p) { - cerr << appName << ": " << *p << endl; + cerr << argv[0] << ": " << *p << endl; } } @@ -664,7 +664,7 @@ run(Ice::StringSeq args, const Ice::CommunicatorPtr& communicator) ofstream of(outputFile.c_str()); if(!of.good()) { - cerr << appName << ": unable to open file `" << outputFile << "'" << endl; + cerr << argv[0] << ": unable to open file `" << outputFile << "'" << endl; return EXIT_FAILURE; } of << descriptors; @@ -693,7 +693,7 @@ run(Ice::StringSeq args, const Ice::CommunicatorPtr& communicator) if(dbEnvName == dbEnvNameNew) { - cerr << appName << ": database environment names must be different" << endl; + cerr << argv[0] << ": database environment names must be different" << endl; return EXIT_FAILURE; } @@ -779,7 +779,7 @@ run(Ice::StringSeq args, const Ice::CommunicatorPtr& communicator) } catch(const DbException& ex) { - cerr << appName << ": database error: " << ex.what() << endl; + cerr << argv[0] << ": database error: " << ex.what() << endl; status = EXIT_FAILURE; } catch(...) @@ -819,7 +819,7 @@ run(Ice::StringSeq args, const Ice::CommunicatorPtr& communicator) } catch(const DbException& ex) { - cerr << appName << ": database error: " << ex.what() << endl; + cerr << argv[0] << ": database error: " << ex.what() << endl; } throw; } @@ -851,7 +851,7 @@ run(Ice::StringSeq args, const Ice::CommunicatorPtr& communicator) } catch(const DbException& ex) { - cerr << appName << ": database error: " << ex.what() << endl; + cerr << argv[0] << ": database error: " << ex.what() << endl; status = EXIT_FAILURE; } } @@ -884,23 +884,19 @@ run(Ice::StringSeq args, const Ice::CommunicatorPtr& communicator) } int -mainInternal(Ice::StringSeq& args) +main(int argc, char* argv[]) { - assert(args.size() > 0); - const string appName = args[0]; Ice::CommunicatorPtr communicator; int status = EXIT_SUCCESS; try { - Ice::InitializationData initData; - initData.properties = Ice::createProperties(); - communicator = Ice::initialize(args, initData); - status = run(args, communicator); + communicator = Ice::initialize(argc, argv); + status = run(argc, argv, communicator); } catch(const FreezeScript::FailureException& ex) { string reason = ex.reason(); - cerr << appName << ": " << reason; + cerr << argv[0] << ": " << reason; if(reason[reason.size() - 1] != '\n') { cerr << endl; @@ -909,17 +905,17 @@ mainInternal(Ice::StringSeq& args) } catch(const IceUtil::Exception& ex) { - cerr << appName << ": " << ex << endl; + cerr << argv[0] << ": " << ex << endl; status = EXIT_FAILURE; } catch(const std::exception& ex) { - cerr << appName << ": " << ex.what() << endl; + cerr << argv[0] << ": " << ex.what() << endl; status = EXIT_FAILURE; } catch(...) { - cerr << appName << ": unknown exception" << endl; + cerr << argv[0] << ": unknown exception" << endl; status = EXIT_FAILURE; } @@ -930,20 +926,3 @@ mainInternal(Ice::StringSeq& args) return status; } - -#ifdef _WIN32 - -int -wmain(int argc, wchar_t* argv[]) - -#else - -int -main(int argc, char* argv[]) - -#endif -{ - Ice::StringSeq args = Ice::argsToStringSeq(argc, argv); - return mainInternal(args); -} - diff --git a/cpp/src/Glacier2/Glacier2Router.cpp b/cpp/src/Glacier2/Glacier2Router.cpp index b5ee647e8ad..81f0e9d063e 100644 --- a/cpp/src/Glacier2/Glacier2Router.cpp +++ b/cpp/src/Glacier2/Glacier2Router.cpp @@ -621,17 +621,8 @@ Glacier2::RouterService::usage(const string& appName) print("Usage: " + appName + " [options]\n" + options); } -#ifdef _WIN32 - -int -wmain(int argc, wchar_t* argv[]) - -#else - int main(int argc, char* argv[]) - -#endif { Glacier2::RouterService svc; return svc.main(argc, argv); diff --git a/cpp/src/Ice/Application.cpp b/cpp/src/Ice/Application.cpp index cb411293e5a..cc9a2b1e00d 100644 --- a/cpp/src/Ice/Application.cpp +++ b/cpp/src/Ice/Application.cpp @@ -384,34 +384,6 @@ Ice::Application::main(int argc, char* argv[], const char* configFile, const Ice return mainInternal(argc, argv, initData, overrideProps); } -#ifdef _WIN32 - -int -Ice::Application::main(int argc, wchar_t* argv[]) -{ - return main(argsToStringSeq(argc, argv)); -} - -int -Ice::Application::main(int argc, wchar_t* argv[], const char* config) -{ - return main(argsToStringSeq(argc, argv), config); -} - -int -Ice::Application::main(int argc, wchar_t* argv[], const char* config, const Ice::PropertiesPtr& properties) -{ - return main(argsToStringSeq(argc, argv), config, properties); -} - -int -Ice::Application::main(int argc, wchar_t* argv[], const Ice::InitializationData& initData) -{ - return main(argsToStringSeq(argc, argv, initData.stringConverter), initData); -} - -#endif - int Ice::Application::main(int argc, char* argv[], const InitializationData& initData) { diff --git a/cpp/src/Ice/Initialize.cpp b/cpp/src/Ice/Initialize.cpp index da9027b5061..e950b960bb1 100644 --- a/cpp/src/Ice/Initialize.cpp +++ b/cpp/src/Ice/Initialize.cpp @@ -50,35 +50,6 @@ Ice::argsToStringSeq(int argc, char* argv[]) return result; } -#ifdef _WIN32 - -StringSeq -Ice::argsToStringSeq(int argc, wchar_t* argv[]) -{ - return argsToStringSeq(argc, argv, 0); -} - -StringSeq -Ice::argsToStringSeq(int argc, wchar_t* argv[], const StringConverterPtr& converter) -{ - StringSeq args; - for(int i=0; argv[i] != 0; i++) - { - string value = IceUtil::wstringToString(argv[i]); - if(converter) - { - string tmp; - converter->fromUTF8(reinterpret_cast<const Byte*>(value.data()), - reinterpret_cast<const Byte*>(value.data() + value.size()), tmp); - value.swap(tmp); - } - args.push_back(value); - } - return args; -} - -#endif - void Ice::stringSeqToArgs(const StringSeq& args, int& argc, char* argv[]) { diff --git a/cpp/src/Ice/PropertiesI.cpp b/cpp/src/Ice/PropertiesI.cpp index 56f33473162..0939ee3eada 100644 --- a/cpp/src/Ice/PropertiesI.cpp +++ b/cpp/src/Ice/PropertiesI.cpp @@ -299,115 +299,40 @@ Ice::PropertiesI::load(const std::string& file) } HKEY iceKey; - if(RegOpenKeyExW(key, IceUtil::stringToWstring(file.substr(5)).c_str(), 0, KEY_QUERY_VALUE, &iceKey) != ERROR_SUCCESS) + if(RegOpenKey(key, file.substr(5).c_str(), &iceKey) != ERROR_SUCCESS) { InitializationException ex(__FILE__, __LINE__); ex.reason = "Could not open Windows registry key `" + file + "'"; throw ex; } - DWORD maxValueNameLen; - DWORD maxValueLen; DWORD numValues; - try + if(RegQueryInfoKey(iceKey, NULL, NULL, NULL, NULL, NULL, NULL, &numValues, NULL, NULL, NULL, NULL) == + ERROR_SUCCESS) { - if(RegQueryInfoKey(iceKey, NULL, NULL, NULL, NULL, NULL, NULL, &numValues, &maxValueNameLen, &maxValueLen, - NULL, NULL) == ERROR_SUCCESS && numValues > 0) + if(numValues > 0) { - auto_ptr<wchar_t> keyBuf(new wchar_t[maxValueNameLen + 1]); - auto_ptr<wchar_t> valueBuf(new wchar_t[maxValueLen + 1]); for(DWORD i = 0; i < numValues; ++i) { - DWORD keyBufSize = (maxValueNameLen + 1) * sizeof(wchar_t); - DWORD valueBufSize = (maxValueLen + 1) * sizeof(wchar_t) ; - unsigned int err = RegEnumValueW(iceKey, i, keyBuf.get(), &keyBufSize, NULL, NULL, NULL, NULL); - if(err != ERROR_SUCCESS) + char keyBuf[256]; + DWORD keyBufSize = sizeof(keyBuf); + if(RegEnumValue(iceKey, i, keyBuf, &keyBufSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { - getProcessLogger()->warning("Could not read Windows registry property name, key path: \"" + - file + "\""); - continue; - } - keyBuf.get()[keyBufSize] = L'\0'; - - DWORD keyType; - err = RegQueryValueExW(iceKey, keyBuf.get(), 0, &keyType, (BYTE*)valueBuf.get(), &valueBufSize); - if(err != ERROR_SUCCESS) - { - getProcessLogger()->warning("Could not read Windows registry property value, property name: `" + - IceUtil::wstringToString(wstring(keyBuf.get())) + "' key path: `" + - file + "'"); - continue; - } - valueBuf.get()[valueBufSize] = L'\0'; - - switch(keyType) - { - case REG_SZ: + char valueBuf[256]; + DWORD valueBufSize = sizeof(valueBuf); + DWORD keyType; + if(RegQueryValueEx(iceKey, keyBuf, 0, &keyType, (BYTE*)valueBuf, &valueBufSize) == + ERROR_SUCCESS) { - string name = IceUtil::wstringToString(wstring(keyBuf.get())); - string value = IceUtil::wstringToString(wstring(valueBuf.get())); - if(_converter) + if(keyType == REG_SZ) { - string tmp; - _converter->fromUTF8(reinterpret_cast<const Byte*>(name.data()), - reinterpret_cast<const Byte*>(name.data() + name.size()), tmp); - name.swap(tmp); - - _converter->fromUTF8(reinterpret_cast<const Byte*>(value.data()), - reinterpret_cast<const Byte*>(value.data() + value.size()), tmp); - value.swap(tmp); + setProperty(keyBuf, valueBuf); } - setProperty(name, value); - break; - } - case REG_EXPAND_SZ: - { - unsigned int sz = ExpandEnvironmentStringsW(valueBuf.get(), 0, 0); - auto_ptr<wchar_t> expandValue; - if(sz > 0) - { - valueBufSize = sz; - expandValue = auto_ptr<wchar_t>(new wchar_t[sz + 1]); - sz = ExpandEnvironmentStringsW(valueBuf.get(), expandValue.get(), sz); - } - - if(sz == 0 || sz > valueBufSize || expandValue.get() == 0) - { - getProcessLogger()->warning("Could not expand variables in property value: `" + - IceUtil::wstringToString(wstring(valueBuf.get())) + - "' key path: `" + file + "'"); - continue; - } - - string name = IceUtil::wstringToString(wstring(keyBuf.get())); - string value = IceUtil::wstringToString(wstring(expandValue.get())); - if(_converter) - { - string tmp; - _converter->fromUTF8(reinterpret_cast<const Byte*>(name.data()), - reinterpret_cast<const Byte*>(name.data() + name.size()), tmp); - name.swap(tmp); - - _converter->fromUTF8(reinterpret_cast<const Byte*>(value.data()), - reinterpret_cast<const Byte*>(value.data() + value.size()), tmp); - value.swap(tmp); - } - setProperty(name, value); - break; - } - default: - { - break; } } } } } - catch(...) - { - RegCloseKey(iceKey); - throw; - } RegCloseKey(iceKey); } else @@ -727,28 +652,11 @@ Ice::PropertiesI::loadConfig() if(value.empty() || value == "1") { - #ifdef _WIN32 - DWORD ret = GetEnvironmentVariableW(L"ICE_CONFIG", 0, 0); - if(ret > 0) + const char* s = getenv("ICE_CONFIG"); + if(s && *s != '\0') { - auto_ptr<wchar_t> v(new wchar_t[ret]); - ret = GetEnvironmentVariableW(L"ICE_CONFIG", v.get(), ret); - value = (ret > 0 && ret < sizeof(v.get()) / sizeof(wchar_t)) ? IceUtil::wstringToString(v.get()) : string(""); - if(_converter) - { - string tmp; - _converter->fromUTF8(reinterpret_cast<const Byte*>(value.data()), - reinterpret_cast<const Byte*>(value.data() + value.size()), tmp); - value.swap(tmp); - } + value = s; } -#else - const char* s = getenv("ICE_CONFIG"); - if(s && *s != '\0') - { - value = s; - } -#endif } if(!value.empty()) diff --git a/cpp/src/Ice/Service.cpp b/cpp/src/Ice/Service.cpp index 17e390ec31f..9ee6bf2fe92 100644 --- a/cpp/src/Ice/Service.cpp +++ b/cpp/src/Ice/Service.cpp @@ -719,16 +719,6 @@ Ice::Service::main(int& argc, char* argv[], const InitializationData& initializa return run(argc, argv, initData); } -#ifdef _WIN32 - -int -Ice::Service::main(int& argc, wchar_t* argv[], const InitializationData& initializationData) -{ - return main(Ice::argsToStringSeq(argc, argv, initializationData.stringConverter), initializationData); -} - -#endif - int Ice::Service::main(StringSeq& args, const InitializationData& initData) { diff --git a/cpp/src/IceBox/Admin.cpp b/cpp/src/IceBox/Admin.cpp index f863277c75e..6cd3076b995 100644 --- a/cpp/src/IceBox/Admin.cpp +++ b/cpp/src/IceBox/Admin.cpp @@ -23,20 +23,13 @@ public: virtual int run(int, char*[]); }; -#ifdef _WIN32 - -int -wmain(int argc, wchar_t* argv[]) - -#else - int main(int argc, char* argv[]) - -#endif { Client app; - return app.main(argc, argv); + int rc = app.main(argc, argv); + + return rc; } void diff --git a/cpp/src/IceBox/Service.cpp b/cpp/src/IceBox/Service.cpp index 6149a3dfea5..c98d593636d 100644 --- a/cpp/src/IceBox/Service.cpp +++ b/cpp/src/IceBox/Service.cpp @@ -137,17 +137,8 @@ IceBox::IceBoxService::usage(const string& appName) print("Usage: " + appName + " [options]\n" + options); } -#ifdef _WIN32 - -int -wmain(int argc, wchar_t* argv[]) - -#else - int main(int argc, char* argv[]) - -#endif { IceBox::IceBoxService svc; diff --git a/cpp/src/IceGrid/Client.cpp b/cpp/src/IceGrid/Client.cpp index 2f40e7d83fc..e975172743d 100644 --- a/cpp/src/IceGrid/Client.cpp +++ b/cpp/src/IceGrid/Client.cpp @@ -156,8 +156,8 @@ class Client : public IceUtil::Monitor<IceUtil::Mutex> public: void usage(); - int main(Ice::StringSeq& args); - int run(Ice::StringSeq& args); + int main(int argc, char* argv[]); + int run(int, char*[]); void interrupted(); Ice::CommunicatorPtr communicator() const { return _communicator; } @@ -183,22 +183,11 @@ interruptCallback(int signal) } } -#ifdef _WIN32 - -int -wmain(int argc, wchar_t* argv[]) - -#else - int main(int argc, char* argv[]) - -#endif { Client app; - Ice::StringSeq args = Ice::argsToStringSeq(argc, argv); - int rc = app.main(args); - return rc; + return app.main(argc, argv); } void @@ -219,18 +208,15 @@ Client::usage() ; } - int -Client::main(Ice::StringSeq& args) +Client::main(int argc, char* argv[]) { int status = EXIT_SUCCESS; try { - _appName = args[0].c_str(); - Ice::InitializationData initData; - initData.properties = Ice::createProperties(); - _communicator = Ice::initialize(args, initData); + _appName = argv[0]; + _communicator = Ice::initialize(argc, argv); { IceUtilInternal::MutexPtrLock<IceUtil::Mutex> sync(_staticMutex); @@ -240,7 +226,7 @@ Client::main(Ice::StringSeq& args) try { - status = run(args); + status = run(argc, argv); } catch(const Ice::CommunicatorDestroyedException&) { @@ -324,7 +310,7 @@ Client::interrupted() } int -Client::run(Ice::StringSeq& args) +Client::run(int argc, char* argv[]) { string commands; bool debug; @@ -340,13 +326,13 @@ Client::run(Ice::StringSeq& args) opts.addOpt("s", "server"); opts.addOpt("r", "replica", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::NoRepeat); - vector<string> noArgs; + vector<string> args; try { #if defined(__BCPLUSPLUS__) && (__BCPLUSPLUS__ >= 0x0600) IceUtil::DummyBCC dummy; #endif - noArgs = opts.parse(args); + args = opts.parse(argc, (const char**)argv); } catch(const IceUtilInternal::BadOptException& e) { @@ -354,9 +340,9 @@ Client::run(Ice::StringSeq& args) usage(); return EXIT_FAILURE; } - if(!noArgs.empty()) + if(!args.empty()) { - cerr << _appName << ": too many arguments" << endl; + cerr << argv[0] << ": too many arguments" << endl; usage(); return EXIT_FAILURE; } @@ -433,13 +419,13 @@ Client::run(Ice::StringSeq& args) router = Glacier2::RouterPrx::checkedCast(communicator()->getDefaultRouter()->ice_preferSecure(true)); if(!router) { - cerr << _appName << ": configured router is not a Glacier2 router" << endl; + cerr << argv[0] << ": configured router is not a Glacier2 router" << endl; return EXIT_FAILURE; } } catch(const Ice::LocalException& ex) { - cerr << _appName << ": could not contact the default router:" << endl << ex << endl; + cerr << argv[0] << ": could not contact the default router:" << endl << ex << endl; return EXIT_FAILURE; } @@ -448,7 +434,7 @@ Client::run(Ice::StringSeq& args) session = AdminSessionPrx::uncheckedCast(router->createSessionFromSecureConnection()); if(!session) { - cerr << _appName + cerr << argv[0] << ": Glacier2 returned a null session, please set the Glacier2.SSLSessionManager property" << endl; return EXIT_FAILURE; @@ -472,7 +458,7 @@ Client::run(Ice::StringSeq& args) password = ""; if(!session) { - cerr << _appName + cerr << argv[0] << ": Glacier2 returned a null session, please set the Glacier2.SessionManager property" << endl; return EXIT_FAILURE; @@ -505,14 +491,14 @@ Client::run(Ice::StringSeq& args) locator = IceGrid::LocatorPrx::checkedCast(communicator()->getDefaultLocator()); if(!locator) { - cerr << _appName << ": configured locator is not an IceGrid locator" << endl; + cerr << argv[0] << ": configured locator is not an IceGrid locator" << endl; return EXIT_FAILURE; } localRegistry = locator->getLocalRegistry(); } catch(const Ice::LocalException& ex) { - cerr << _appName << ": could not contact the default locator:" << endl << ex << endl; + cerr << argv[0] << ": could not contact the default locator:" << endl << ex << endl; return EXIT_FAILURE; } @@ -533,19 +519,19 @@ Client::run(Ice::StringSeq& args) registry = RegistryPrx::checkedCast(communicator()->stringToProxy(strId)); if(!registry) { - cerr << _appName << ": could not contact an IceGrid registry" << endl; + cerr << argv[0] << ": could not contact an IceGrid registry" << endl; } } catch(const Ice::NotRegisteredException&) { - cerr << _appName << ": no active registry replica named `" << replica << "'" << endl; + cerr << argv[0] << ": no active registry replica named `" << replica << "'" << endl; return EXIT_FAILURE; } catch(const Ice::LocalException& ex) { if(!replica.empty()) { - cerr << _appName << ": could not contact the registry replica named `" << replica << "':\n"; + cerr << argv[0] << ": could not contact the registry replica named `" << replica << "':\n"; cerr << ex << endl; return EXIT_FAILURE; } @@ -562,7 +548,7 @@ Client::run(Ice::StringSeq& args) { name = name.substr(prefix.size()); } - cerr << _appName << ": warning: could not contact master, using slave `" << name << "'" << endl; + cerr << argv[0] << ": warning: could not contact master, using slave `" << name << "'" << endl; } } } @@ -611,7 +597,7 @@ Client::run(Ice::StringSeq& args) } else // No default locator or router set. { - cerr << _appName << ": could not contact the registry:" << endl; + cerr << argv[0] << ": could not contact the registry:" << endl; cerr << "no default locator or router configured" << endl; return EXIT_FAILURE; } diff --git a/cpp/src/IceGrid/IceGridNode.cpp b/cpp/src/IceGrid/IceGridNode.cpp index e5f7304bd68..a78d45531a7 100644 --- a/cpp/src/IceGrid/IceGridNode.cpp +++ b/cpp/src/IceGrid/IceGridNode.cpp @@ -10,7 +10,6 @@ #include <IceUtil/UUID.h> #include <IceUtil/Timer.h> #include <IceUtil/StringUtil.h> -#include <IceUtil/FileUtil.h> #include <Ice/Ice.h> #include <Ice/Locator.h> #include <Ice/Service.h> @@ -34,7 +33,14 @@ #ifdef _WIN32 # include <direct.h> # include <sys/types.h> +# include <sys/stat.h> # include <winsock2.h> +# ifdef _MSC_VER +# define S_ISDIR(mode) ((mode) & _S_IFDIR) +# define S_ISREG(mode) ((mode) & _S_IFREG) +# endif +#else +# include <sys/stat.h> #endif using namespace std; @@ -363,7 +369,9 @@ NodeService::startImpl(int argc, char* argv[]) } else { - if(!IceUtilInternal::directoryExists(dataPath)) +#ifdef _WIN32 + struct _stat filestat; + if(::_stat(dataPath.c_str(), &filestat) != 0 || !S_ISDIR(filestat.st_mode)) { ostringstream os; FileException ex(__FILE__, __LINE__); @@ -372,7 +380,20 @@ NodeService::startImpl(int argc, char* argv[]) os << ex; error("property `IceGrid.Node.Data' is set to an invalid path:\n" + os.str()); return false; - } + } +#else + struct stat filestat; + if(::stat(dataPath.c_str(), &filestat) != 0 || !S_ISDIR(filestat.st_mode)) + { + ostringstream os; + FileException ex(__FILE__, __LINE__); + ex.path = dataPath; + ex.error = getSystemErrno(); + os << ex; + error("property `IceGrid.Node.Data' is set to an invalid path:\n" + os.str()); + return false; + } +#endif // // Creates subdirectories. @@ -811,19 +832,9 @@ NodeService::usage(const string& appName) print("Usage: " + appName + " [options]\n" + options); } -#ifdef _WIN32 - -int -wmain(int argc, wchar_t* argv[]) - -#else - int main(int argc, char* argv[]) - -#endif { NodeService svc; - int rc = svc.main(argc, argv); - return rc; + return svc.main(argc, argv); } diff --git a/cpp/src/IceGrid/IceGridRegistry.cpp b/cpp/src/IceGrid/IceGridRegistry.cpp index 85ce29eca46..f6b15394f00 100644 --- a/cpp/src/IceGrid/IceGridRegistry.cpp +++ b/cpp/src/IceGrid/IceGridRegistry.cpp @@ -188,19 +188,9 @@ RegistryService::usage(const string& appName) print("Usage: " + appName + " [options]\n" + options); } -#ifdef _WIN32 - -int -wmain(int argc, wchar_t* argv[]) - -#else - int main(int argc, char* argv[]) - -#endif { RegistryService svc; - int rc = svc.main(argc, argv); - return rc; + return svc.main(argc, argv); } diff --git a/cpp/src/IceGrid/NodeI.cpp b/cpp/src/IceGrid/NodeI.cpp index ae3f2bc43cf..bf4c17e72c7 100644 --- a/cpp/src/IceGrid/NodeI.cpp +++ b/cpp/src/IceGrid/NodeI.cpp @@ -8,9 +8,9 @@ // ********************************************************************** #include <IceUtil/Timer.h> -#include <IceUtil/FileUtil.h> #include <Ice/Ice.h> #include <IcePatch2/Util.h> +#include <IcePatch2/OS.h> #include <IcePatch2/ClientUtil.h> #include <IceGrid/NodeI.h> #include <IceGrid/Activator.h> @@ -1153,7 +1153,8 @@ NodeI::removeServer(const ServerIPtr& server, const std::string& application) _serversByApplication.erase(p); string appDir = _dataDir + "/distrib/" + application; - if(IceUtilInternal::directoryExists(appDir)) + OS::structstat buf; + if(OS::osstat(appDir, &buf) != -1 && S_ISDIR(buf.st_mode)) { try { diff --git a/cpp/src/IceGrid/RegistryI.cpp b/cpp/src/IceGrid/RegistryI.cpp index 52086f4651b..73ff0e21a4f 100644 --- a/cpp/src/IceGrid/RegistryI.cpp +++ b/cpp/src/IceGrid/RegistryI.cpp @@ -9,7 +9,6 @@ #include <IceUtil/DisableWarnings.h> #include <IceUtil/UUID.h> -#include <IceUtil/FileUtil.h> #include <Ice/Ice.h> #include <Ice/Network.h> #include <Ice/ProtocolPluginFacade.h> // Just to get the hostname @@ -43,6 +42,7 @@ #include <openssl/des.h> // For crypt() passwords #include <sys/types.h> +#include <sys/stat.h> #ifdef _WIN32 # include <direct.h> @@ -201,7 +201,8 @@ RegistryI::startImpl() } else { - if(!IceUtilInternal::directoryExists(dbPath)) + struct stat filestat; + if(stat(dbPath.c_str(), &filestat) != 0 || !S_ISDIR(filestat.st_mode)) { Error out(_communicator->getLogger()); SyscallException ex(__FILE__, __LINE__); diff --git a/cpp/src/IceGrid/ServerI.cpp b/cpp/src/IceGrid/ServerI.cpp index c1bfc9752e0..901fc5eae30 100644 --- a/cpp/src/IceGrid/ServerI.cpp +++ b/cpp/src/IceGrid/ServerI.cpp @@ -7,9 +7,7 @@ // // ********************************************************************** -#include <IceUtil/FileUtil.h> #include <Ice/Ice.h> -#include <Ice/Instance.h> #include <IceGrid/ServerI.h> #include <IceGrid/TraceLevels.h> #include <IceGrid/Activator.h> @@ -23,6 +21,7 @@ #include <IceUtil/FileUtil.h> #include <sys/types.h> +#include <sys/stat.h> #ifdef _WIN32 # include <direct.h> @@ -98,9 +97,8 @@ chownRecursive(const string& path, uid_t uid, gid_t gid) { name = path + "/" + name; - - IceUtilInternal::structstat buf; - if(IceUtilInternal::stat(name, &buf) == -1) + OS::structstat buf; + if(OS::osstat(name, &buf) == -1) { throw "cannot stat `" + name + "':\n" + IceUtilInternal::lastErrorToString(); } @@ -278,11 +276,6 @@ private: struct EnvironmentEval : std::unary_function<string, string> { - EnvironmentEval(const Ice::StringConverterPtr& converter) - { - this->converter = converter; - } - string operator()(const std::string& value) { @@ -297,7 +290,7 @@ struct EnvironmentEval : std::unary_function<string, string> string::size_type beg = 0; string::size_type end; #ifdef _WIN32 - wchar_t buf[32767]; + char buf[32767]; while((beg = v.find("%", beg)) != string::npos && beg < v.size() - 1) { end = v.find("%", beg + 1); @@ -306,15 +299,8 @@ struct EnvironmentEval : std::unary_function<string, string> break; } string variable = v.substr(beg + 1, end - beg - 1); - DWORD ret = GetEnvironmentVariableW(IceUtil::stringToWstring(variable).c_str(), buf, sizeof(buf)); - string valstr = (ret > 0 && ret < sizeof(buf)) ? IceUtil::wstringToString(buf) : string(""); - if(converter) - { - string tmp; - converter->fromUTF8(reinterpret_cast<const Ice::Byte*>(valstr.data()), - reinterpret_cast<const Ice::Byte*>(valstr.data() + valstr.size()), tmp); - valstr.swap(tmp); - } + DWORD ret = GetEnvironmentVariable(variable.c_str(), buf, sizeof(buf)); + string valstr = (ret > 0 && ret < sizeof(buf)) ? string(buf) : string(""); v.replace(beg, end - beg + 1, valstr); beg += valstr.size(); } @@ -350,8 +336,6 @@ struct EnvironmentEval : std::unary_function<string, string> #endif return value.substr(0, assignment) + "=" + v; } - - Ice::StringConverterPtr converter; }; } @@ -1446,10 +1430,8 @@ ServerI::activate() copy(desc->options.begin(), desc->options.end(), back_inserter(options)); options.push_back("--Ice.Config=" + escapeProperty(_serverDir + "/config/config")); - Ice::StringConverterPtr converter = - IceInternal::getInstance(_node->getCommunicator())->initializationData().stringConverter; Ice::StringSeq envs; - transform(desc->envs.begin(), desc->envs.end(), back_inserter(envs), EnvironmentEval(converter)); + transform(desc->envs.begin(), desc->envs.end(), back_inserter(envs), EnvironmentEval()); // // Clear the adapters direct proxy (this is usefull if the server diff --git a/cpp/src/IcePatch2/Calc.cpp b/cpp/src/IcePatch2/Calc.cpp index 525657e6f7a..5c67f7445ee 100644 --- a/cpp/src/IcePatch2/Calc.cpp +++ b/cpp/src/IcePatch2/Calc.cpp @@ -101,7 +101,7 @@ public: }; void -usage(const string& appName) +usage(const char* appName) { cerr << "Usage: " << appName << " [options] DIR [FILES...]\n"; cerr << @@ -116,10 +116,8 @@ usage(const string& appName) } int -mainInternal(const Ice::StringSeq& args) +main(int argc, char* argv[]) { - assert(args.size() > 0); - const string appName = args[0]; string dataDir; StringSeq fileSeq; int compress = 1; @@ -134,24 +132,24 @@ mainInternal(const Ice::StringSeq& args) opts.addOpt("V", "verbose"); opts.addOpt("i", "case-insensitive"); - vector<string> noArgs; + vector<string> args; try { #if defined(__BCPLUSPLUS__) && (__BCPLUSPLUS__ >= 0x0600) IceUtil::DummyBCC dummy; #endif - noArgs = opts.parse(args); + args = opts.parse(argc, (const char**)argv); } catch(const IceUtilInternal::BadOptException& e) { cerr << e.reason << endl; - usage(appName); + usage(argv[0]); return EXIT_FAILURE; } if(opts.isSet("help")) { - usage(appName); + usage(argv[0]); return EXIT_SUCCESS; } if(opts.isSet("version")) @@ -163,8 +161,8 @@ mainInternal(const Ice::StringSeq& args) bool dontCompress = opts.isSet("no-compress"); if(doCompress && dontCompress) { - cerr << appName << ": only one of -z and -Z are mutually exclusive" << endl; - usage(appName); + cerr << argv[0] << ": only one of -z and -Z are mutually exclusive" << endl; + usage(argv[0]); return EXIT_FAILURE; } if(doCompress) @@ -180,15 +178,15 @@ mainInternal(const Ice::StringSeq& args) if(args.empty()) { - cerr << appName << ": no data directory specified" << endl; - usage(appName); + cerr << argv[0] << ": no data directory specified" << endl; + usage(argv[0]); return EXIT_FAILURE; } - dataDir = simplify(noArgs[0]); + dataDir = simplify(args[0]); - for(vector<string>::size_type i = 1; i < noArgs.size(); ++i) + for(vector<string>::size_type i = 1; i < args.size(); ++i) { - fileSeq.push_back(simplify(noArgs[i])); + fileSeq.push_back(simplify(args[i])); } try @@ -310,30 +308,14 @@ mainInternal(const Ice::StringSeq& args) } catch(const string& ex) { - cerr << appName << ": " << ex << endl; + cerr << argv[0] << ": " << ex << endl; return EXIT_FAILURE; } catch(const char* ex) { - cerr << appName << ": " << ex << endl; + cerr << argv[0] << ": " << ex << endl; return EXIT_FAILURE; } return EXIT_SUCCESS; } - -#ifdef _WIN32 - -int -wmain(int argc, wchar_t* argv[]) - -#else - -int -main(int argc, char* argv[]) - -#endif -{ - int rc = mainInternal(Ice::argsToStringSeq(argc, argv)); - return rc; -} diff --git a/cpp/src/IcePatch2/Client.cpp b/cpp/src/IcePatch2/Client.cpp index 3c5b21a5bad..29cd1516563 100644 --- a/cpp/src/IcePatch2/Client.cpp +++ b/cpp/src/IcePatch2/Client.cpp @@ -333,19 +333,9 @@ Client::usage(const string& appName) cerr << options << endl; } -#ifdef _WIN32 - -int -wmain(int argc, wchar_t* argv[]) - -#else - int main(int argc, char* argv[]) - -#endif { Client app; - int rc = app.main(argc, argv); - return rc; + return app.main(argc, argv); } diff --git a/cpp/src/IcePatch2/OS.cpp b/cpp/src/IcePatch2/OS.cpp index b4944d5bdc4..61decba5332 100644 --- a/cpp/src/IcePatch2/OS.cpp +++ b/cpp/src/IcePatch2/OS.cpp @@ -22,6 +22,11 @@ using namespace std; using namespace OS; #ifdef _WIN32 +int +OS::osstat(const string& path, structstat* buf) +{ + return ::_wstat(IceUtil::stringToWstring(path).c_str(), buf); +} int OS::remove(const string& path) @@ -74,6 +79,12 @@ OS::getcwd(string& cwd) #else int +OS::osstat(const string& path, structstat* buf) +{ + return ::stat(path.c_str(), buf); +} + +int OS::remove(const string& path) { return ::remove(path.c_str()); diff --git a/cpp/src/IcePatch2/OS.h b/cpp/src/IcePatch2/OS.h index 7f4e1e1bd1e..09352685c51 100644 --- a/cpp/src/IcePatch2/OS.h +++ b/cpp/src/IcePatch2/OS.h @@ -11,6 +11,7 @@ #define ICE_PATCH2_OS_H #include <Ice/Config.h> +#include <sys/stat.h> #include <fcntl.h> #include <stdio.h> @@ -25,6 +26,26 @@ namespace OS { +#ifdef _WIN32 + +typedef struct _stat structstat; +#ifdef _MSC_VER +# define O_RDONLY _O_RDONLY +# define O_BINARY _O_BINARY + +# define S_ISDIR(mode) ((mode) & _S_IFDIR) +# define S_ISREG(mode) ((mode) & _S_IFREG) +#endif + +#else + +typedef struct stat structstat; +# define O_BINARY 0 + +#endif + +// BUGFIX: aCC errors if this is stat. +ICE_PATCH2_API int osstat(const std::string&, structstat*); ICE_PATCH2_API int remove(const std::string&); ICE_PATCH2_API int rename(const std::string&, const std::string&); ICE_PATCH2_API int rmdir(const std::string&); diff --git a/cpp/src/IcePatch2/Server.cpp b/cpp/src/IcePatch2/Server.cpp index 75d28cef865..91e71d708aa 100644 --- a/cpp/src/IcePatch2/Server.cpp +++ b/cpp/src/IcePatch2/Server.cpp @@ -213,24 +213,15 @@ IcePatch2::PatcherService::usage(const string& appName) print("Usage: " + appName + " [options] [DIR]\n" + options); } -#ifdef _WIN32 - int -wmain(int argc, wchar_t* argv[]) +main(int argc, char* argv[]) { IcePatch2::PatcherService svc; int status = EXIT_FAILURE; - status = svc.main(argc, argv); - return status; -} +#ifdef _WIN32 + status = svc.main(argc, argv); #else - -int -main(int argc, char* argv[]) -{ - IcePatch2::PatcherService svc; - int status = EXIT_FAILURE; // // For UNIX, force --nochdir option, so the service isn't started // with / as the working directory. That way, if the data @@ -245,6 +236,7 @@ main(int argc, char* argv[]) args.push_back(argv[i]); } status = svc.main(args); +#endif + return status; } -#endif diff --git a/cpp/src/IcePatch2/Util.cpp b/cpp/src/IcePatch2/Util.cpp index 8e5c63dba4c..05d91aa9bec 100644 --- a/cpp/src/IcePatch2/Util.cpp +++ b/cpp/src/IcePatch2/Util.cpp @@ -18,7 +18,6 @@ #include <IceUtil/DisableWarnings.h> #include <IceUtil/IceUtil.h> #include <IceUtil/StringUtil.h> -#include <IceUtil/FileUtil.h> #define ICE_PATCH2_API_EXPORTS #include <IcePatch2/Util.h> #include <openssl/sha.h> @@ -417,8 +416,8 @@ IcePatch2::remove(const string& pa) { const string path = simplify(pa); - IceUtilInternal::structstat buf; - if(IceUtilInternal::stat(path, &buf) == -1) + OS::structstat buf; + if(OS::osstat(path, &buf) == -1) { throw "cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString(); } @@ -448,8 +447,8 @@ IcePatch2::removeRecursive(const string& pa) { const string path = simplify(pa); - IceUtilInternal::structstat buf; - if(IceUtilInternal::stat(path, &buf) == -1) + OS::structstat buf; + if(OS::osstat(path, &buf) == -1) { throw "cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString(); } @@ -630,8 +629,8 @@ IcePatch2::createDirectoryRecursive(const string& pa) if(!isRoot(path + "/")) { - IceUtilInternal::structstat buf; - if(IceUtilInternal::stat(path, &buf) != -1) + OS::structstat buf; + if(OS::osstat(path, &buf) != -1) { if(S_ISDIR(buf.st_mode)) { @@ -730,8 +729,8 @@ IcePatch2::decompressFile(const string& pa) // // The BZ2_bzReadOpen/BZ2_bzRead/BZ2_bzReadClose functions fail with BCC // - IceUtilInternal::structstat buf; - if(IceUtilInternal::stat(pathBZ2, &buf) == -1) + OS::structstat buf; + if(OS::osstat(pathBZ2, &buf) == -1) { throw "cannot stat `" + pathBZ2 + "':\n" + IceUtilInternal::lastErrorToString(); } @@ -855,8 +854,8 @@ IcePatch2::setFileFlags(const string& pa, const FileInfo& info) { #ifndef _WIN32 // Windows doesn't support the executable flag const string path = simplify(pa); - IceUtilInternal::structstat buf; - if(IceUtilInternal::stat(path, &buf) == -1) + OS::structstat buf; + if(OS::osstat(path, &buf) == -1) { throw "cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString(); } @@ -890,8 +889,8 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G } else { - IceUtilInternal::structstat buf; - if(IceUtilInternal::stat(getWithoutSuffix(path), &buf) == -1) + OS::structstat buf; + if(OS::osstat(getWithoutSuffix(path), &buf) == -1) { if(errno == ENOENT) { @@ -921,8 +920,8 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G else { - IceUtilInternal::structstat buf; - if(IceUtilInternal::stat(path, &buf) == -1) + OS::structstat buf; + if(OS::osstat(path, &buf) == -1) { throw "cannot stat `" + path + "':\n" + IceUtilInternal::lastErrorToString(); } @@ -971,7 +970,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G info.executable = buf.st_mode & S_IXUSR; #endif - IceUtilInternal::structstat bufBZ2; + OS::structstat bufBZ2; const string pathBZ2 = path + ".bz2"; bool doCompress = false; if(buf.st_size != 0 && compress > 0) @@ -981,7 +980,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G // compress == 1: Compress if necessary. // compress >= 2: Always compress. // - if(compress >= 2 || IceUtilInternal::stat(pathBZ2, &bufBZ2) == -1 || buf.st_mtime >= bufBZ2.st_mtime) + if(compress >= 2 || OS::osstat(pathBZ2, &bufBZ2) == -1 || buf.st_mtime >= bufBZ2.st_mtime) { if(cb && !cb->compress(relPath)) { @@ -1192,7 +1191,7 @@ getFileInfoSeqInt(const string& basePath, const string& relPath, int compress, G rename(pathBZ2Temp, pathBZ2); - if(IceUtilInternal::stat(pathBZ2, &bufBZ2) == -1) + if(OS::osstat(pathBZ2, &bufBZ2) == -1) { throw "cannot stat `" + pathBZ2 + "':\n" + IceUtilInternal::lastErrorToString(); } diff --git a/cpp/src/IceSSL/Util.cpp b/cpp/src/IceSSL/Util.cpp index 796ca725130..9881cd3cb66 100644 --- a/cpp/src/IceSSL/Util.cpp +++ b/cpp/src/IceSSL/Util.cpp @@ -8,13 +8,19 @@ // ********************************************************************** #include <IceSSL/Util.h> -#include <IceUtil/FileUtil.h> #include <Ice/LocalException.h> #include <Ice/Network.h> #ifdef _WIN32 # include <direct.h> # include <sys/types.h> +# include <sys/stat.h> +# ifdef _MSC_VER +# define S_ISDIR(mode) ((mode) & _S_IFDIR) +# define S_ISREG(mode) ((mode) & _S_IFREG) +# endif +#else +# include <sys/stat.h> #endif #include <openssl/err.h> @@ -280,8 +286,13 @@ IceSSL::checkPath(string& path, const string& defaultDir, bool dir) // argument is modified and true is returned. Otherwise // false is returned. // - IceUtilInternal::structstat st; - int err = IceUtilInternal::stat(path, &st); +#ifdef _WIN32 + struct _stat st; + int err = ::_stat(path.c_str(), &st); +#else + struct stat st; + int err = ::stat(path.c_str(), &st); +#endif if(err == 0) { return dir ? S_ISDIR(st.st_mode) != 0 : S_ISREG(st.st_mode) != 0; @@ -291,10 +302,11 @@ IceSSL::checkPath(string& path, const string& defaultDir, bool dir) { #ifdef _WIN32 string s = defaultDir + "\\" + path; + err = ::_stat(s.c_str(), &st); #else string s = defaultDir + "/" + path; + err = ::stat(s.c_str(), &st); #endif - err = ::IceUtilInternal::stat(s.c_str(), &st); if(err == 0 && ((!dir && S_ISREG(st.st_mode)) || (dir && S_ISDIR(st.st_mode)))) { path = s; diff --git a/cpp/src/IceStorm/Admin.cpp b/cpp/src/IceStorm/Admin.cpp index 1d5d7e927b4..e9eb985191f 100644 --- a/cpp/src/IceStorm/Admin.cpp +++ b/cpp/src/IceStorm/Admin.cpp @@ -27,17 +27,8 @@ public: virtual int run(int, char*[]); }; -#ifdef _WIN32 - -int -wmain(int argc, wchar_t* argv[]) - -#else - int main(int argc, char* argv[]) - -#endif { Client app; int rc = app.main(argc, argv); diff --git a/cpp/src/IceStorm/Migrate.cpp b/cpp/src/IceStorm/Migrate.cpp index 5ffcc7f540c..406e85be881 100644 --- a/cpp/src/IceStorm/Migrate.cpp +++ b/cpp/src/IceStorm/Migrate.cpp @@ -34,17 +34,8 @@ private: void v31migrate(const Freeze::ConnectionPtr&, SubscriberMap&); }; -#ifdef _WIN32 - -int -wmain(int argc, wchar_t* argv[]) - -#else - int main(int argc, char* argv[]) - -#endif { Client app; int rc = app.main(argc, argv); diff --git a/cpp/src/IceUtil/FileUtil.cpp b/cpp/src/IceUtil/FileUtil.cpp index 4486bbd0dd9..ac830069b52 100644 --- a/cpp/src/IceUtil/FileUtil.cpp +++ b/cpp/src/IceUtil/FileUtil.cpp @@ -8,7 +8,6 @@ // ********************************************************************** #include <IceUtil/FileUtil.h> -#include <IceUtil/Unicode.h> using namespace std; @@ -52,44 +51,3 @@ IceUtilInternal::isAbsolutePath(const string& path) return path[i] == '/'; #endif } - -// -// Detemine if a directory exists. -// -bool -IceUtilInternal::directoryExists(const string& path) -{ - IceUtilInternal::structstat st; - if(IceUtilInternal::stat(path, &st) != 0 || !S_ISDIR(st.st_mode)) - { - return false; - } - return true; -} - -// -// Determine if a regular file exists. -// -bool -IceUtilInternal::fileExists(const string& path) -{ - IceUtilInternal::structstat st; - if(IceUtilInternal::stat(path, &st) != 0 || !S_ISREG(st.st_mode)) - { - return false; - } - return true; -} - -// -// Stat -// -int -IceUtilInternal::stat(const string& path, structstat* buffer) -{ -#ifdef _WIN32 - return _wstat(IceUtil::stringToWstring(path).c_str(), buffer); -#else - return stat(path.c_str(), buffer); -#endif -} diff --git a/cpp/src/iceserviceinstall/Install.cpp b/cpp/src/iceserviceinstall/Install.cpp index 8d3859f1d10..78e0614cedc 100644 --- a/cpp/src/iceserviceinstall/Install.cpp +++ b/cpp/src/iceserviceinstall/Install.cpp @@ -35,7 +35,7 @@ private: }; int -main(int argc, wchar_t* argv[]) +main(int argc, char* argv[]) { Install app; int status = app.main(argc, argv); |