summaryrefslogtreecommitdiff
path: root/cpp/src/FreezeScript/transformdb.cpp
diff options
context:
space:
mode:
authorJose <jose@zeroc.com>2009-07-29 21:50:06 +0200
committerJose <jose@zeroc.com>2009-07-29 21:50:06 +0200
commitdb9adf0e14f01d0aa8eb288a172995847c006f57 (patch)
tree9690b02e0f0c85377c0feedb18b3a203d73928fb /cpp/src/FreezeScript/transformdb.cpp
parentbug 4003 - update bindist READMEs for bzip2 (diff)
downloadice-db9adf0e14f01d0aa8eb288a172995847c006f57.tar.bz2
ice-db9adf0e14f01d0aa8eb288a172995847c006f57.tar.xz
ice-db9adf0e14f01d0aa8eb288a172995847c006f57.zip
Changes for bug 3962 and 4714
Diffstat (limited to 'cpp/src/FreezeScript/transformdb.cpp')
-rw-r--r--cpp/src/FreezeScript/transformdb.cpp129
1 files changed, 75 insertions, 54 deletions
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);
+}
+