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