summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2006-08-25 07:58:01 +0000
committerMichi Henning <michi@zeroc.com>2006-08-25 07:58:01 +0000
commita3443505bc1f80a5264d31c79bd6120e10da815c (patch)
treed850eedf58d7a5a50a0314d9aa96eb0cd2cf2c50 /cpp
parentuse zero-copy API for primitive sequence types (diff)
downloadice-a3443505bc1f80a5264d31c79bd6120e10da815c.tar.bz2
ice-a3443505bc1f80a5264d31c79bd6120e10da815c.tar.xz
ice-a3443505bc1f80a5264d31c79bd6120e10da815c.zip
Bug 1325.
Diffstat (limited to 'cpp')
-rw-r--r--cpp/CHANGES39
-rwxr-xr-xcpp/include/IceUtil/Options.h40
-rw-r--r--cpp/src/FreezeScript/DumpDB.cpp6
-rw-r--r--cpp/src/FreezeScript/transformdb.cpp6
-rw-r--r--cpp/src/Glacier2/Glacier2Router.cpp4
-rw-r--r--cpp/src/IceBox/Admin.cpp4
-rw-r--r--cpp/src/IceBox/Service.cpp4
-rw-r--r--cpp/src/IceGrid/Client.cpp8
-rw-r--r--cpp/src/IceGrid/IceGridRegistry.cpp4
-rw-r--r--cpp/src/IceGrid/Parser.cpp6
-rw-r--r--cpp/src/IcePatch2/Calc.cpp12
-rw-r--r--cpp/src/IcePatch2/Client.cpp6
-rw-r--r--cpp/src/IcePatch2/Server.cpp4
-rw-r--r--cpp/src/IceStorm/Admin.cpp6
-rwxr-xr-xcpp/src/IceUtil/Options.cpp252
-rw-r--r--cpp/src/slice2cpp/Main.cpp6
-rw-r--r--cpp/src/slice2cppe/Main.cpp6
-rw-r--r--cpp/src/slice2cs/Main.cpp6
-rw-r--r--cpp/src/slice2docbook/Main.cpp8
-rw-r--r--cpp/src/slice2freeze/Main.cpp6
-rw-r--r--cpp/src/slice2freezej/Main.cpp6
-rw-r--r--cpp/src/slice2java/Main.cpp6
-rw-r--r--cpp/src/slice2javae/Main.cpp6
-rw-r--r--cpp/src/slice2py/Main.cpp6
-rw-r--r--cpp/src/slice2rb/Main.cpp6
-rw-r--r--cpp/src/slice2vb/Main.cpp6
26 files changed, 327 insertions, 142 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES
index 18a52b53898..c8fb71e02a8 100644
--- a/cpp/CHANGES
+++ b/cpp/CHANGES
@@ -3,6 +3,45 @@ NOTE: Please keep changes in the appropriate section for HEAD or 3.1.
Changes since version 3.1.1 (HEAD)
---------------------------
+- Changed IceUtil::Options to allow testing for synonyms without
+ having to check both the short and long options. For example:
+
+ IceUtil::Options opts;
+ opts.addOpt("v", "version");
+ opts.parse();
+
+ Previously, to test whether the -v or --version option was set, you
+ had to write:
+
+ if(opts.isSet("v" || opts.isSet("version")
+ // show version...
+
+ With the new behavior, you can test for either "v" or "version",
+ and the test returns true if either the long or short option
+ was set:
+
+ if(opts.isSet("version")
+ // show version...
+
+ or:
+
+ if(opts.isSet("v")
+ // show version...
+
+ Either test works correctly, regardless of of whether the actual
+ option passed to the executable was -v or --version.
+
+ Note that, for this to work, you must add both long and short option
+ in a single call to addOpt():
+
+ opts.addOpt("v", "version"); // -v and --version are synonyms
+
+ If you add the options in separate calls, they are not recognized
+ as synonyms:
+
+ opts.addOpt("v"); // --version is considered a separate option from --version
+ opts.addOpt("", "version"); // --version is considered a separate option from -v
+
- Added zero-copy functions to the stream classes.
- Added the NullSSLPermissionsVerifier to the IceGrid registry.
diff --git a/cpp/include/IceUtil/Options.h b/cpp/include/IceUtil/Options.h
index 8efe5aad08e..9f03c48366b 100755
--- a/cpp/include/IceUtil/Options.h
+++ b/cpp/include/IceUtil/Options.h
@@ -12,10 +12,11 @@
#include <IceUtil/Config.h>
#include <IceUtil/RecMutex.h>
+#include <IceUtil/Shared.h>
+#include <IceUtil/Handle.h>
#include <string>
#include <vector>
#include <map>
-#include <set>
namespace IceUtil
{
@@ -28,6 +29,10 @@ public:
{
Error(const ::std::string& r) : reason(r) {}
::std::string reason;
+
+ protected:
+
+ Error() {} // This struct is an abstract base.
};
struct APIError : public Error
@@ -62,25 +67,46 @@ public:
private:
- struct OptionDetails
+ struct OptionDetails : public IceUtil::Shared
{
LengthType length;
ArgType arg;
RepeatType repeat;
+ bool hasDefault;
+ };
+ typedef IceUtil::Handle<OptionDetails> ODPtr;
+
+ struct OptionValue : public IceUtil::Shared
+ {
+ ::std::string val;
};
- typedef ::std::map< ::std::string, OptionDetails> ValidOpts; // Valid options and their details.
- typedef ::std::map< ::std::string, ::std::string> Opts; // Value of non-repeating options.
- typedef ::std::map< ::std::string, ::std::vector< ::std::string> > ROpts; // Value of repeating options.
+ typedef IceUtil::Handle<OptionValue> OValPtr;
+
+ struct OptionValueVector : public IceUtil::Shared
+ {
+ ::std::vector< ::std::string> vals;
+ };
+ typedef IceUtil::Handle<OptionValueVector> OVecPtr;
+
+ typedef ::std::map< ::std::string, ODPtr> ValidOpts; // Valid options and their details.
+ typedef ::std::map< ::std::string, OValPtr> Opts; // Value of non-repeating options.
+ typedef ::std::map< ::std::string, OVecPtr> ROpts; // Value of repeating options.
+ typedef ::std::map< ::std::string, ::std::string> Synonyms; // Map from short to long option and vice versa.
- void addValidOpt(const ::std::string&, LengthType, ArgType, const ::std::string&, RepeatType);
+ void addValidOpt(const ::std::string&, const ::std::string&, ArgType, const ::std::string&, RepeatType);
ValidOpts::iterator checkOpt(const ::std::string&, LengthType);
- void setOpt(const ::std::string&, const ::std::string&, RepeatType);
+ void setOpt(const ::std::string&, const ::std::string&, const ::std::string&, RepeatType);
+ void setNonRepeatingOpt(const ::std::string&, const ::std::string&);
+ void setRepeatingOpt(const ::std::string&, const ::std::string&);
ValidOpts::const_iterator checkOptIsValid(const ::std::string&) const;
ValidOpts::const_iterator checkOptHasArg(const ::std::string&) const;
+ void updateSynonyms(const ::std::string&, const ::std::string&);
+ ::std::string getSynonym(const ::std::string&) const;
ValidOpts _validOpts;
Opts _opts;
ROpts _ropts;
+ Synonyms _synonyms;
bool parseCalled;
diff --git a/cpp/src/FreezeScript/DumpDB.cpp b/cpp/src/FreezeScript/DumpDB.cpp
index 2076bb05676..c779b6c2b0f 100644
--- a/cpp/src/FreezeScript/DumpDB.cpp
+++ b/cpp/src/FreezeScript/DumpDB.cpp
@@ -145,12 +145,12 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
return EXIT_FAILURE;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("h"))
{
usage(argv[0]);
return EXIT_SUCCESS;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
cout << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
@@ -179,7 +179,7 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
cppArgs += " -I" + *i;
}
}
- debug = opts.isSet("d") || opts.isSet("debug");
+ debug = opts.isSet("debug");
// No need to set --ice option here -- it is always true.
diff --git a/cpp/src/FreezeScript/transformdb.cpp b/cpp/src/FreezeScript/transformdb.cpp
index a3f6468529f..0464449f096 100644
--- a/cpp/src/FreezeScript/transformdb.cpp
+++ b/cpp/src/FreezeScript/transformdb.cpp
@@ -244,12 +244,12 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
return EXIT_FAILURE;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage(argv[0]);
return EXIT_SUCCESS;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
cout << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
@@ -272,7 +272,7 @@ run(int argc, char** argv, const Ice::CommunicatorPtr& communicator)
newCppArgs += " -U" + *i;
}
}
- debug = opts.isSet("d") || opts.isSet("debug");
+ debug = opts.isSet("debug");
// No need to set --ice here, it is always true.
diff --git a/cpp/src/Glacier2/Glacier2Router.cpp b/cpp/src/Glacier2/Glacier2Router.cpp
index 749e6554f3b..70cb7be0156 100644
--- a/cpp/src/Glacier2/Glacier2Router.cpp
+++ b/cpp/src/Glacier2/Glacier2Router.cpp
@@ -88,12 +88,12 @@ Glacier2::RouterService::start(int argc, char* argv[])
return false;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage(argv[0]);
return false;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
print(ICE_STRING_VERSION);
return false;
diff --git a/cpp/src/IceBox/Admin.cpp b/cpp/src/IceBox/Admin.cpp
index 4259cd7816b..18ea8a003ec 100644
--- a/cpp/src/IceBox/Admin.cpp
+++ b/cpp/src/IceBox/Admin.cpp
@@ -65,12 +65,12 @@ Client::run(int argc, char* argv[])
return EXIT_FAILURE;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage();
return EXIT_SUCCESS;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
cout << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
diff --git a/cpp/src/IceBox/Service.cpp b/cpp/src/IceBox/Service.cpp
index 52aa9dd2bc4..4b7cfedef20 100644
--- a/cpp/src/IceBox/Service.cpp
+++ b/cpp/src/IceBox/Service.cpp
@@ -61,12 +61,12 @@ IceBox::IceBoxService::start(int argc, char* argv[])
return false;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage(argv[0]);
return false;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
print(ICE_STRING_VERSION);
return false;
diff --git a/cpp/src/IceGrid/Client.cpp b/cpp/src/IceGrid/Client.cpp
index 1b9616ee54c..fe44b4b1949 100644
--- a/cpp/src/IceGrid/Client.cpp
+++ b/cpp/src/IceGrid/Client.cpp
@@ -81,18 +81,18 @@ Client::run(int argc, char* argv[])
return EXIT_FAILURE;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage();
return EXIT_SUCCESS;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
cout << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
}
- if(opts.isSet("s") || opts.isSet("server"))
+ if(opts.isSet("server"))
{
ObjectAdapterPtr adapter = communicator()->createObjectAdapterWithEndpoints("FileParser", "tcp -h localhost");
adapter->activate();
@@ -136,7 +136,7 @@ Client::run(int argc, char* argv[])
commands += *i + ";";
}
}
- debug = opts.isSet("d") || opts.isSet("debug");
+ debug = opts.isSet("debug");
if(!args.empty() && !commands.empty())
{
diff --git a/cpp/src/IceGrid/IceGridRegistry.cpp b/cpp/src/IceGrid/IceGridRegistry.cpp
index 961eef75e08..ba2c2d3c619 100644
--- a/cpp/src/IceGrid/IceGridRegistry.cpp
+++ b/cpp/src/IceGrid/IceGridRegistry.cpp
@@ -73,12 +73,12 @@ RegistryService::start(int argc, char* argv[])
return false;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage(argv[0]);
return false;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
print(ICE_STRING_VERSION);
return false;
diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp
index 2cbad583ffe..82ef87efc80 100644
--- a/cpp/src/IceGrid/Parser.cpp
+++ b/cpp/src/IceGrid/Parser.cpp
@@ -175,7 +175,7 @@ Parser::addApplication(const list<string>& origArgs)
ApplicationDescriptor app = DescriptorParser::parseDescriptor(desc, targets, vars, _communicator, _admin);
_admin->addApplication(app);
- if(!opts.isSet("n") && !opts.isSet("no-patch"))
+ if(!opts.isSet("no-patch"))
{
//
// Patch the application.
@@ -363,7 +363,7 @@ Parser::patchApplication(const list<string>& origArgs)
{
vector<string>::const_iterator p = args.begin();
string name = *p++;
- _admin->patchApplication(name, opts.isSet("f") || opts.isSet("force"));
+ _admin->patchApplication(name, opts.isSet("force"));
}
catch(const Ice::Exception& ex)
{
@@ -730,7 +730,7 @@ Parser::patchServer(const list<string>& origArgs)
try
{
- _admin->patchServer(args.front(), opts.isSet("f") || opts.isSet("force"));
+ _admin->patchServer(args.front(), opts.isSet("force"));
}
catch(const Ice::Exception& ex)
{
diff --git a/cpp/src/IcePatch2/Calc.cpp b/cpp/src/IcePatch2/Calc.cpp
index dfe342c7018..a061a4e6526 100644
--- a/cpp/src/IcePatch2/Calc.cpp
+++ b/cpp/src/IcePatch2/Calc.cpp
@@ -141,18 +141,18 @@ main(int argc, char* argv[])
return EXIT_FAILURE;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage(argv[0]);
return EXIT_SUCCESS;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
cout << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
}
- bool doCompress = opts.isSet("z") || opts.isSet("compress");
- bool dontCompress = opts.isSet("Z") || opts.isSet("no-compress");
+ bool doCompress = opts.isSet("compress");
+ bool dontCompress = opts.isSet("no-compress");
if(doCompress && dontCompress)
{
cerr << argv[0] << ": only one of -z and -Z are mutually exclusive" << endl;
@@ -167,8 +167,8 @@ main(int argc, char* argv[])
{
compress = 0;
}
- verbose = opts.isSet("V") || opts.isSet("verbose");
- caseInsensitive = opts.isSet("i") || opts.isSet("case-insensitive");
+ verbose = opts.isSet("verbose");
+ caseInsensitive = opts.isSet("case-insensitive");
if(args.empty())
{
diff --git a/cpp/src/IcePatch2/Client.cpp b/cpp/src/IcePatch2/Client.cpp
index 7cb8243d55d..e83a6b43fa5 100644
--- a/cpp/src/IcePatch2/Client.cpp
+++ b/cpp/src/IcePatch2/Client.cpp
@@ -254,17 +254,17 @@ Client::run(int argc, char* argv[])
return EXIT_FAILURE;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage(argv[0]);
return EXIT_SUCCESS;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
cout << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
}
- if(opts.isSet("t") || opts.isSet("thorough"))
+ if(opts.isSet("thorough"))
{
properties->setProperty("IcePatch2.Thorough", "1");
}
diff --git a/cpp/src/IcePatch2/Server.cpp b/cpp/src/IcePatch2/Server.cpp
index 76030e75f64..7201cec74c2 100644
--- a/cpp/src/IcePatch2/Server.cpp
+++ b/cpp/src/IcePatch2/Server.cpp
@@ -83,12 +83,12 @@ IcePatch2::PatcherService::start(int argc, char* argv[])
return false;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage(argv[0]);
return false;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
print(ICE_STRING_VERSION);
return false;
diff --git a/cpp/src/IceStorm/Admin.cpp b/cpp/src/IceStorm/Admin.cpp
index aa94afbb525..19e189cf7e3 100644
--- a/cpp/src/IceStorm/Admin.cpp
+++ b/cpp/src/IceStorm/Admin.cpp
@@ -80,12 +80,12 @@ Client::run(int argc, char* argv[])
return EXIT_FAILURE;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage();
return EXIT_SUCCESS;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
cout << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
@@ -122,7 +122,7 @@ Client::run(int argc, char* argv[])
commands += *i + ";";
}
}
- debug = opts.isSet("d") || opts.isSet("debug");
+ debug = opts.isSet("debug");
if(!args.empty() && !commands.empty())
{
diff --git a/cpp/src/IceUtil/Options.cpp b/cpp/src/IceUtil/Options.cpp
index ccbf4b462e3..93ca0973ee4 100755
--- a/cpp/src/IceUtil/Options.cpp
+++ b/cpp/src/IceUtil/Options.cpp
@@ -9,6 +9,7 @@
#include <IceUtil/Options.h>
#include <iostream>
+#include <set>
using namespace std;
@@ -86,11 +87,9 @@ IceUtil::Options::addOpt(const string& shortOpt, const string& longOpt, ArgType
checkArgs(shortOpt, longOpt, at == NeedArg, dflt);
- addValidOpt(shortOpt, ShortOpt, at, dflt, rt);
- addValidOpt(longOpt, LongOpt, at, dflt, rt);
+ addValidOpt(shortOpt, longOpt, at, dflt, rt);
}
-
//
// Split a command line into argv-style arguments, applying
// bash quoting rules. The return value is the arguments
@@ -113,6 +112,7 @@ IceUtil::Options::split(const string& line)
}
string::size_type end = line.find_last_not_of(IFS);
assert(end != string::npos);
+
string l(line, start, end - start + 1);
vector<string> vec;
@@ -539,29 +539,34 @@ IceUtil::Options::parse(const vector<string>& args)
pos = checkOpt(opt, LongOpt);
- if(p != string::npos)
+ if(pos->second->repeat == NoRepeat)
{
- if(pos->second.arg == NoArg && p != args[i].size() - 1)
+ set<string>::iterator seenPos = seenNonRepeatableOpts.find(opt);
+ if(seenPos != seenNonRepeatableOpts.end())
{
- string err = "`";
- err += args[i];
- err += "': option does not take an argument";
+ string err = "`--";
+ err += opt + ":' option cannot be repeated";
throw BadOpt(err);
}
- setOpt(opt, args[i].substr(p + 1), pos->second.repeat);
- argDone = true;
+ seenNonRepeatableOpts.insert(seenPos, opt);
+ string synonym = getSynonym(opt);
+ if(!synonym.empty())
+ {
+ seenNonRepeatableOpts.insert(synonym);
+ }
}
- if(pos->second.repeat == NoRepeat)
+ if(p != string::npos)
{
- set<string>::iterator seenPos = seenNonRepeatableOpts.find(opt);
- if(seenPos != seenNonRepeatableOpts.end())
+ if(pos->second->arg == NoArg && p != args[i].size() - 1)
{
- string err = "`--";
- err += opt + ":' option cannot be repeated";
+ string err = "`";
+ err += args[i];
+ err += "': option does not take an argument";
throw BadOpt(err);
}
- seenNonRepeatableOpts.insert(seenPos, opt);
+ setOpt(opt, "", args[i].substr(p + 1), pos->second->repeat);
+ argDone = true;
}
}
else if(!args[i].empty() && args[i][0] == '-')
@@ -574,25 +579,31 @@ IceUtil::Options::parse(const vector<string>& args)
opt.clear();
opt.push_back(args[i][p]);
pos = checkOpt(opt, ShortOpt);
- if(pos->second.arg == NeedArg && p != args[i].size() - 1)
+
+ if(pos->second->repeat == NoRepeat)
{
- string optArg = args[i].substr(p + 1);
- setOpt(opt, optArg, pos->second.repeat);
- argDone = true;
- break;
+ set<string>::iterator seenPos = seenNonRepeatableOpts.find(opt);
+ if(seenPos != seenNonRepeatableOpts.end())
+ {
+ string err = "`-";
+ err += opt + ":' option cannot be repeated";
+ throw BadOpt(err);
+ }
+ seenNonRepeatableOpts.insert(seenPos, opt);
+ string synonym = getSynonym(opt);
+ if(!synonym.empty())
+ {
+ seenNonRepeatableOpts.insert(synonym);
+ }
}
- }
- if(pos->second.repeat == NoRepeat)
- {
- set<string>::iterator seenPos = seenNonRepeatableOpts.find(opt);
- if(seenPos != seenNonRepeatableOpts.end())
+ if(pos->second->arg == NeedArg && p != args[i].size() - 1)
{
- string err = "`-";
- err += opt + ":' option cannot be repeated";
- throw BadOpt(err);
+ string optArg = args[i].substr(p + 1);
+ setOpt(opt, "", optArg, pos->second->repeat);
+ argDone = true;
+ break;
}
- seenNonRepeatableOpts.insert(seenPos, opt);
}
}
else
@@ -606,7 +617,7 @@ IceUtil::Options::parse(const vector<string>& args)
if(!argDone)
{
- if(pos->second.arg == NeedArg) // Need an argument that is separated by whitespace.
+ if(pos->second->arg == NeedArg) // Need an argument that is separated by whitespace.
{
if(i == args.size() - 1)
{
@@ -619,15 +630,17 @@ IceUtil::Options::parse(const vector<string>& args)
err += "' option requires an argument";
throw BadOpt(err);
}
- setOpt(opt, args[++i], pos->second.repeat);
+ setOpt(opt, "", args[++i], pos->second->repeat);
}
else
{
- setOpt(opt, "1", pos->second.repeat);
+ setOpt(opt, "", "1", pos->second->repeat);
}
}
}
+ _synonyms.clear(); // Don't need the contents anymore.
+
while(i < args.size())
{
result.push_back(args[i++]);
@@ -663,7 +676,7 @@ IceUtil::Options::isSet(const string& opt) const
}
ValidOpts::const_iterator pos = checkOptIsValid(opt);
- return pos->second.repeat == NoRepeat ? _opts.find(opt) != _opts.end() : _ropts.find(opt) != _ropts.end();
+ return pos->second->repeat == NoRepeat ? _opts.find(opt) != _opts.end() : _ropts.find(opt) != _ropts.end();
}
string
@@ -678,10 +691,10 @@ IceUtil::Options::optArg(const string& opt) const
ValidOpts::const_iterator pos = checkOptHasArg(opt);
- if(pos->second.repeat == Repeat)
+ if(pos->second->repeat == Repeat)
{
string err = "`-";
- if(pos->second.length == LongOpt)
+ if(pos->second->length == LongOpt)
{
err.push_back('-');
}
@@ -690,12 +703,12 @@ IceUtil::Options::optArg(const string& opt) const
throw APIError(err);
}
- map<string, string>::const_iterator p = _opts.find(opt);
+ Opts::const_iterator p = _opts.find(opt);
if(p == _opts.end())
{
return "";
}
- return p->second;
+ return p->second->val;
}
vector<string>
@@ -710,10 +723,10 @@ IceUtil::Options::argVec(const string& opt) const
ValidOpts::const_iterator pos = checkOptHasArg(opt);
- if(pos->second.repeat == NoRepeat)
+ if(pos->second->repeat == NoRepeat)
{
string err = "`-";
- if(pos->second.length == LongOpt)
+ if(pos->second->length == LongOpt)
{
err.push_back('-');
}
@@ -721,37 +734,50 @@ IceUtil::Options::argVec(const string& opt) const
throw APIError(err);
}
- map<string, vector<string> >::const_iterator p = _ropts.find(opt);
- return p == _ropts.end() ? vector<string>() : p->second;
+ ROpts::const_iterator p = _ropts.find(opt);
+ return p == _ropts.end() ? vector<string>() : p->second->vals;
}
void
-IceUtil::Options::addValidOpt(const string& opt, LengthType lt, ArgType at, const string& dflt, RepeatType rt)
+IceUtil::Options::addValidOpt(const string& shortOpt, const string& longOpt,
+ ArgType at, const string& dflt, RepeatType rt)
{
- if(opt.empty())
+ if(!shortOpt.empty() && _validOpts.find(shortOpt) != _validOpts.end())
{
- return;
+ string err = "`";
+ err += shortOpt;
+ err += "': duplicate option";
+ throw APIError(err);
}
-
- ValidOpts::iterator pos = _validOpts.find(opt);
- if(pos != _validOpts.end())
+ if(!longOpt.empty() && _validOpts.find(longOpt) != _validOpts.end())
{
string err = "`";
- err += opt;
+ err += longOpt;
err += "': duplicate option";
throw APIError(err);
}
- OptionDetails od;
- od.length = lt;
- od.arg = at;
- od.repeat = rt;
+ ODPtr odp = new OptionDetails;
+ odp->arg = at;
+ odp->repeat = rt;
+ odp->hasDefault = !dflt.empty();
+
+ if(!shortOpt.empty())
+ {
+ odp->length = ShortOpt;
+ _validOpts[shortOpt] = odp;
+ }
+ if(!longOpt.empty())
+ {
+ odp->length = LongOpt;
+ _validOpts[longOpt] = odp;
+ }
- _validOpts.insert(pos, ValidOpts::value_type(opt, od));
+ updateSynonyms(shortOpt, longOpt);
if(at == NeedArg && !dflt.empty())
{
- setOpt(opt, dflt, rt);
+ setOpt(shortOpt, longOpt, dflt, rt);
}
}
@@ -774,25 +800,102 @@ IceUtil::Options::checkOpt(const string& opt, LengthType lt)
}
void
-IceUtil::Options::setOpt(const string& opt, const string& val, RepeatType rt)
+IceUtil::Options::setOpt(const string& opt1, const string& opt2, const string& val, RepeatType rt)
+{
+ //
+ // opt1 and opt2 (short and long opt) can't both be empty.
+ //
+ assert(!(opt1.empty() && opt2.empty()));
+
+ if(rt == NoRepeat)
+ {
+ setNonRepeatingOpt(opt1, val);
+ setNonRepeatingOpt(opt2, val);
+ }
+ else
+ {
+ setRepeatingOpt(opt1, val);
+ setRepeatingOpt(opt2, val);
+ }
+}
+
+void
+IceUtil::Options::setNonRepeatingOpt(const string& opt, const string& val)
+{
+ if(opt.empty())
+ {
+ return;
+ }
+
+ assert(_opts.find(opt) == _opts.end());
+
+ OValPtr ovp = new OptionValue;
+ ovp->val = val;
+ _opts[opt] = ovp;
+
+ const string synonym = getSynonym(opt);
+ if(!synonym.empty())
+ {
+ _opts[synonym] = ovp;
+ }
+}
+
+void
+IceUtil::Options::setRepeatingOpt(const string& opt, const string& val)
{
- if(rt == Repeat)
+ if(opt.empty())
+ {
+ return;
+ }
+
+ ValidOpts::const_iterator vpos = _validOpts.find(opt);
+ assert(vpos != _validOpts.end());
+
+ ROpts::iterator pos = _ropts.find(opt);
+ const string synonym = getSynonym(opt);
+ ROpts::iterator spos = _ropts.find(synonym);
+
+ if(pos != _ropts.end())
+ {
+ assert(_validOpts.find(opt) != _validOpts.end());
+ assert(vpos->second->repeat == Repeat);
+
+ _ropts[opt] = pos->second;
+ if(vpos->second->hasDefault && pos->second->vals.size() == 1)
+ {
+ pos->second->vals[0] = val;
+ vpos->second->hasDefault = false;
+ }
+ else
+ {
+ pos->second->vals.push_back(val);
+ }
+ }
+ else if(spos != _ropts.end())
{
- ROpts::iterator pos = _ropts.find(opt);
- if(pos != _ropts.end())
+ assert(_validOpts.find(synonym) != _validOpts.end());
+ assert(_validOpts.find(synonym)->second->repeat == Repeat);
+
+ _ropts[synonym] = spos->second;
+ if(vpos->second->hasDefault && spos->second->vals.size() == 1)
{
- pos->second.push_back(val);
+ spos->second->vals[0] = val;
+ vpos->second->hasDefault = false;
}
else
{
- vector<string> vec;
- vec.push_back(val);
- _ropts.insert(pos, ROpts::value_type(opt, vec));
+ spos->second->vals.push_back(val);
}
}
else
{
- _opts[opt] = val;
+ OVecPtr ovp = new OptionValueVector;
+ ovp->vals.push_back(val);
+ _ropts[opt] = ovp;
+ if(!synonym.empty())
+ {
+ _ropts[synonym] = ovp;
+ }
}
}
@@ -814,10 +917,10 @@ IceUtil::Options::ValidOpts::const_iterator
IceUtil::Options::checkOptHasArg(const string& opt) const
{
ValidOpts::const_iterator pos = checkOptIsValid(opt);
- if(pos->second.arg == NoArg)
+ if(pos->second->arg == NoArg)
{
string err = "`-";
- if(pos->second.length == LongOpt)
+ if(pos->second->length == LongOpt)
{
err.push_back('-');
}
@@ -827,3 +930,20 @@ IceUtil::Options::checkOptHasArg(const string& opt) const
}
return pos;
}
+
+void
+IceUtil::Options::updateSynonyms(const ::std::string& shortOpt, const ::std::string& longOpt)
+{
+ if(!shortOpt.empty() && !longOpt.empty())
+ {
+ _synonyms[shortOpt] = longOpt;
+ _synonyms[longOpt] = shortOpt;
+ }
+}
+
+string
+IceUtil::Options::getSynonym(const ::std::string& optName) const
+{
+ Synonyms::const_iterator pos = _synonyms.find(optName);
+ return pos != _synonyms.end() ? pos->second : "";
+}
diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp
index 645bce922dd..fdc7e5f89d7 100644
--- a/cpp/src/slice2cpp/Main.cpp
+++ b/cpp/src/slice2cpp/Main.cpp
@@ -93,12 +93,12 @@ main(int argc, char* argv[])
return EXIT_FAILURE;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage(argv[0]);
return EXIT_SUCCESS;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
cout << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
@@ -148,7 +148,7 @@ main(int argc, char* argv[])
}
impl = opts.isSet("impl");
depend = opts.isSet("depend");
- debug = opts.isSet("d") || opts.isSet("debug");
+ debug = opts.isSet("debug");
ice = opts.isSet("ice");
checksum = opts.isSet("checksum");
stream = opts.isSet("stream");
diff --git a/cpp/src/slice2cppe/Main.cpp b/cpp/src/slice2cppe/Main.cpp
index 3d0f7a69850..895b201ad9d 100644
--- a/cpp/src/slice2cppe/Main.cpp
+++ b/cpp/src/slice2cppe/Main.cpp
@@ -87,12 +87,12 @@ main(int argc, char* argv[])
return EXIT_FAILURE;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage(argv[0]);
return EXIT_SUCCESS;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
cout << ICEE_STRING_VERSION << endl;
return EXIT_SUCCESS;
@@ -142,7 +142,7 @@ main(int argc, char* argv[])
}
impl = opts.isSet("impl");
depend = opts.isSet("depend");
- debug = opts.isSet("d") || opts.isSet("debug");
+ debug = opts.isSet("debug");
ice = opts.isSet("ice");
caseSensitive = opts.isSet("case-sensitive");
diff --git a/cpp/src/slice2cs/Main.cpp b/cpp/src/slice2cs/Main.cpp
index ec201f48641..2ced83b65a6 100644
--- a/cpp/src/slice2cs/Main.cpp
+++ b/cpp/src/slice2cs/Main.cpp
@@ -87,12 +87,12 @@ main(int argc, char* argv[])
return EXIT_FAILURE;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage(argv[0]);
return EXIT_SUCCESS;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
cout << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
@@ -130,7 +130,7 @@ main(int argc, char* argv[])
impl = opts.isSet("impl");
implTie = opts.isSet("impl-tie");
depend = opts.isSet("depend");
- debug = opts.isSet("d") || opts.isSet("debug");
+ debug = opts.isSet("debug");
ice = opts.isSet("ice");
checksum = opts.isSet("checksum");
stream = opts.isSet("stream");
diff --git a/cpp/src/slice2docbook/Main.cpp b/cpp/src/slice2docbook/Main.cpp
index 228ed36ff16..3d11ac9684c 100644
--- a/cpp/src/slice2docbook/Main.cpp
+++ b/cpp/src/slice2docbook/Main.cpp
@@ -82,12 +82,12 @@ main(int argc, char* argv[])
return EXIT_FAILURE;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage(argv[0]);
return EXIT_SUCCESS;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
cout << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
@@ -117,12 +117,12 @@ main(int argc, char* argv[])
}
}
preprocess = opts.isSet("E");
- standAlone = opts.isSet("s") || opts.isSet("stand-alone");
+ standAlone = opts.isSet("stand-alone");
noGlobals = opts.isSet("no-globals");
chapter = opts.isSet("chapter");
noIndex = opts.isSet("noindex");
sortFields = opts.isSet("sort-fields");
- debug = opts.isSet("d") || opts.isSet("debug");
+ debug = opts.isSet("debug");
ice = opts.isSet("ice");
caseSensitive = opts.isSet("case-sensitive");
diff --git a/cpp/src/slice2freeze/Main.cpp b/cpp/src/slice2freeze/Main.cpp
index 12e31fd74aa..d54ac3abb32 100644
--- a/cpp/src/slice2freeze/Main.cpp
+++ b/cpp/src/slice2freeze/Main.cpp
@@ -1222,12 +1222,12 @@ main(int argc, char* argv[])
return EXIT_FAILURE;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage(argv[0]);
return EXIT_SUCCESS;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
cout << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
@@ -1609,7 +1609,7 @@ main(int argc, char* argv[])
{
output = opts.optArg("output-dir");
}
- debug = opts.isSet("d") || opts.isSet("debug");
+ debug = opts.isSet("debug");
ice = opts.isSet("ice");
caseSensitive = opts.isSet("case-sensitive");
diff --git a/cpp/src/slice2freezej/Main.cpp b/cpp/src/slice2freezej/Main.cpp
index 70d31cc442f..a2c03a98492 100644
--- a/cpp/src/slice2freezej/Main.cpp
+++ b/cpp/src/slice2freezej/Main.cpp
@@ -1116,12 +1116,12 @@ main(int argc, char* argv[])
return EXIT_FAILURE;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage(argv[0]);
return EXIT_SUCCESS;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
cout << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
@@ -1360,7 +1360,7 @@ main(int argc, char* argv[])
output = opts.optArg("output-dir");
}
depend = opts.isSet("depend");
- debug = opts.isSet("d") || opts.isSet("debug");
+ debug = opts.isSet("debug");
ice = opts.isSet("ice");
if(opts.isSet("meta"))
{
diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp
index 4b65540c5f4..91e6b85ae91 100644
--- a/cpp/src/slice2java/Main.cpp
+++ b/cpp/src/slice2java/Main.cpp
@@ -94,12 +94,12 @@ main(int argc, char* argv[])
return EXIT_FAILURE;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage(argv[0]);
return EXIT_SUCCESS;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
cout << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
@@ -137,7 +137,7 @@ main(int argc, char* argv[])
impl = opts.isSet("impl");
implTie = opts.isSet("impl-tie");
depend = opts.isSet("depend");
- debug = opts.isSet("d") || opts.isSet("debug");
+ debug = opts.isSet("debug");
ice = opts.isSet("ice");
if(opts.isSet("checksum"))
{
diff --git a/cpp/src/slice2javae/Main.cpp b/cpp/src/slice2javae/Main.cpp
index b9c05a9f0d7..1a54166671b 100644
--- a/cpp/src/slice2javae/Main.cpp
+++ b/cpp/src/slice2javae/Main.cpp
@@ -81,12 +81,12 @@ main(int argc, char* argv[])
return EXIT_FAILURE;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage(argv[0]);
return EXIT_SUCCESS;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
cout << ICEE_STRING_VERSION << endl;
return EXIT_SUCCESS;
@@ -124,7 +124,7 @@ main(int argc, char* argv[])
impl = opts.isSet("impl");
implTie = opts.isSet("impl-tie");
depend = opts.isSet("depend");
- debug = opts.isSet("d") || opts.isSet("debug");
+ debug = opts.isSet("debug");
ice = opts.isSet("ice");
caseSensitive = opts.isSet("case-sensitive");
diff --git a/cpp/src/slice2py/Main.cpp b/cpp/src/slice2py/Main.cpp
index 921448ba32b..7ec3ed3bc66 100644
--- a/cpp/src/slice2py/Main.cpp
+++ b/cpp/src/slice2py/Main.cpp
@@ -424,12 +424,12 @@ main(int argc, char* argv[])
return EXIT_FAILURE;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage(argv[0]);
return EXIT_SUCCESS;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
cout << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
@@ -463,7 +463,7 @@ main(int argc, char* argv[])
{
output = opts.optArg("output-dir");
}
- debug = opts.isSet("d") || opts.isSet("debug");
+ debug = opts.isSet("debug");
ice = opts.isSet("ice");
all = opts.isSet("all");
noPackage = opts.isSet("no-package");
diff --git a/cpp/src/slice2rb/Main.cpp b/cpp/src/slice2rb/Main.cpp
index a125e4b27d1..f5d33190fd7 100644
--- a/cpp/src/slice2rb/Main.cpp
+++ b/cpp/src/slice2rb/Main.cpp
@@ -90,12 +90,12 @@ main(int argc, char* argv[])
return EXIT_FAILURE;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage(argv[0]);
return EXIT_SUCCESS;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
cout << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
@@ -129,7 +129,7 @@ main(int argc, char* argv[])
{
output = opts.optArg("output-dir");
}
- debug = opts.isSet("d") || opts.isSet("debug");
+ debug = opts.isSet("debug");
ice = opts.isSet("ice");
all = opts.isSet("all");
checksum = opts.isSet("checksum");
diff --git a/cpp/src/slice2vb/Main.cpp b/cpp/src/slice2vb/Main.cpp
index 42f42d57f46..e53dbd198ce 100644
--- a/cpp/src/slice2vb/Main.cpp
+++ b/cpp/src/slice2vb/Main.cpp
@@ -87,12 +87,12 @@ main(int argc, char* argv[])
return EXIT_FAILURE;
}
- if(opts.isSet("h") || opts.isSet("help"))
+ if(opts.isSet("help"))
{
usage(argv[0]);
return EXIT_SUCCESS;
}
- if(opts.isSet("v") || opts.isSet("version"))
+ if(opts.isSet("version"))
{
cout << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
@@ -130,7 +130,7 @@ main(int argc, char* argv[])
impl = opts.isSet("impl");
implTie = opts.isSet("impl-tie");
depend = opts.isSet("depend");
- debug = opts.isSet("d") || opts.isSet("debug");
+ debug = opts.isSet("debug");
ice = opts.isSet("ice");
checksum = opts.isSet("checksum");
stream = opts.isSet("stream");