summaryrefslogtreecommitdiff
path: root/cpp/src/IceUtil/Options.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/IceUtil/Options.cpp')
-rwxr-xr-xcpp/src/IceUtil/Options.cpp1210
1 files changed, 605 insertions, 605 deletions
diff --git a/cpp/src/IceUtil/Options.cpp b/cpp/src/IceUtil/Options.cpp
index c8fc3635177..9fe71cc1311 100755
--- a/cpp/src/IceUtil/Options.cpp
+++ b/cpp/src/IceUtil/Options.cpp
@@ -36,7 +36,7 @@ IceUtil::APIException::ice_print(ostream& out) const
Exception::ice_print(out);
if(!reason.empty())
{
- out << ": " << reason;
+ out << ": " << reason;
}
}
@@ -82,7 +82,7 @@ IceUtil::BadOptException::ice_print(ostream& out) const
Exception::ice_print(out);
if(!reason.empty())
{
- out << ": " << reason;
+ out << ": " << reason;
}
}
@@ -120,51 +120,51 @@ IceUtil::Options::checkArgs(const string& shortOpt, const string& longOpt, bool
if(!shortOpt.empty())
{
- if(shortOpt.size() != 1)
- {
- string err = "`";
- err += shortOpt;
- err += "': a short option cannot specify more than one option";
- throw IllegalArgumentException(__FILE__, __LINE__, err);
- }
- if(shortOpt.find_first_of(" \t\n\r\f\v") != string::npos)
- {
- string err = "`";
- err += shortOpt;
- err += "': a short option cannot be whitespace";
- throw IllegalArgumentException(__FILE__, __LINE__, err);
- }
- if(shortOpt[0] == '-')
- {
- string err = "`";
- err += shortOpt;
- err += "': a short option cannot be `-'";
- throw IllegalArgumentException(__FILE__, __LINE__, err);
- }
+ if(shortOpt.size() != 1)
+ {
+ string err = "`";
+ err += shortOpt;
+ err += "': a short option cannot specify more than one option";
+ throw IllegalArgumentException(__FILE__, __LINE__, err);
+ }
+ if(shortOpt.find_first_of(" \t\n\r\f\v") != string::npos)
+ {
+ string err = "`";
+ err += shortOpt;
+ err += "': a short option cannot be whitespace";
+ throw IllegalArgumentException(__FILE__, __LINE__, err);
+ }
+ if(shortOpt[0] == '-')
+ {
+ string err = "`";
+ err += shortOpt;
+ err += "': a short option cannot be `-'";
+ throw IllegalArgumentException(__FILE__, __LINE__, err);
+ }
}
if(!longOpt.empty())
{
- if(longOpt.find_first_of(" \t\n\r\f\v") != string::npos)
- {
- string err = "`";
- err += longOpt;
- err += "': a long option cannot contain whitespace";
- throw IllegalArgumentException(__FILE__, __LINE__, err);
- }
- if(longOpt[0] == '-')
- {
- string err = "`";
- err += longOpt;
- err += "': a long option must not contain a leading `-'";
- throw IllegalArgumentException(__FILE__, __LINE__, err);
- }
+ if(longOpt.find_first_of(" \t\n\r\f\v") != string::npos)
+ {
+ string err = "`";
+ err += longOpt;
+ err += "': a long option cannot contain whitespace";
+ throw IllegalArgumentException(__FILE__, __LINE__, err);
+ }
+ if(longOpt[0] == '-')
+ {
+ string err = "`";
+ err += longOpt;
+ err += "': a long option must not contain a leading `-'";
+ throw IllegalArgumentException(__FILE__, __LINE__, err);
+ }
}
if(!needArg && !dflt.empty())
{
- throw IllegalArgumentException(__FILE__, __LINE__,
- "a default value can be specified only for options requiring an argument");
+ throw IllegalArgumentException(__FILE__, __LINE__,
+ "a default value can be specified only for options requiring an argument");
}
}
@@ -175,7 +175,7 @@ IceUtil::Options::addOpt(const string& shortOpt, const string& longOpt, ArgType
if(parseCalled)
{
- throw APIException(__FILE__, __LINE__, "cannot add options after parse() was called");
+ throw APIException(__FILE__, __LINE__, "cannot add options after parse() was called");
}
checkArgs(shortOpt, longOpt, at == NeedArg, dflt);
@@ -217,361 +217,361 @@ IceUtil::Options::split(const string& line)
for(string::size_type i = 0; i < l.size(); ++i)
{
- char c = l[i];
+ char c = l[i];
switch(state)
- {
- case Normal:
- {
- switch(c)
- {
- case '\\':
- {
- //
- // Ignore a backslash at the end of the string,
- // and strip backslash-newline pairs. If a
- // backslash is followed by a space, single quote,
- // double quote, or dollar sign, we drop the backslash
- // and write the space, single quote, double quote,
- // or dollar sign. This is necessary to allow quotes
- // to be escaped. Dropping the backslash preceding a
- // space deviates from bash quoting rules, but is
- // necessary so we don't drop backslashes from Windows
- // path names.)
- //
- if(i < l.size() - 1 && l[++i] != '\n')
- {
- switch(l[i])
- {
- case ' ':
- case '$':
- case '\'':
- case '"':
- {
- arg.push_back(l[i]);
- break;
- }
- default:
- {
- arg.push_back('\\');
- arg.push_back(l[i]);
- break;
- }
- }
- }
- break;
- }
- case '\'':
- {
- state = SingleQuote;
- break;
- }
- case '"':
- {
- state = DoubleQuote;
- break;
- }
- case '$':
- {
- if(i < l.size() - 1 && l[i + 1] == '\'')
- {
- state = ANSIQuote; // Bash uses $'<text>' to allow ANSI escape sequences within <text>.
- ++i;
- }
- else
- {
- arg.push_back('$');
- }
- break;
- }
- default:
- {
- if(IFS.find(l[i]) != string::npos)
- {
- vec.push_back(arg);
- arg.clear();
-
- //
- // Move to start of next argument.
- //
- while(++i < l.size() && IFS.find(l[i]) != string::npos)
- {
- ;
- }
- --i;
- }
- else
- {
- arg.push_back(l[i]);
- }
- break;
- }
- }
- break;
- }
- case DoubleQuote:
- {
- //
- // Within double quotes, only backslash retains its special
- // meaning, and only if followed by double quote, backslash,
- // or newline. If not followed by one of these characters,
- // both the backslash and the character are preserved.
- //
- if(c == '\\' && i < l.size() - 1)
- {
- switch(c = l[++i])
- {
- case '"':
- case '\\':
- case '\n':
- {
- arg.push_back(c);
- break;
- }
- default:
- {
- arg.push_back('\\');
- arg.push_back(c);
- break;
- }
- }
- }
- else if(c == '"') // End of double-quote mode.
- {
- state = Normal;
- }
- else
- {
- arg.push_back(c); // Everything else is taken literally.
- }
- break;
- }
- case SingleQuote:
- {
- if(c == '\'') // End of single-quote mode.
- {
- state = Normal;
- }
- else
- {
- arg.push_back(c); // Everything else is taken literally.
- }
- break;
- }
- case ANSIQuote:
- {
- switch(c)
- {
- case '\\':
- {
- if(i == l.size() - 1)
- {
- break;
- }
- switch(c = l[++i])
- {
- //
- // Single-letter escape sequences.
- //
- case 'a':
- {
- arg.push_back('\a');
- break;
- }
- case 'b':
- {
- arg.push_back('\b');
- break;
- }
- case 'f':
- {
- arg.push_back('\f');
- break;
- }
- case 'n':
- {
- arg.push_back('\n');
- break;
- }
- case 'r':
- {
- arg.push_back('\r');
- break;
- }
- case 't':
- {
- arg.push_back('\t');
- break;
- }
- case 'v':
- {
- arg.push_back('\v');
- break;
- }
- case '\\':
- {
- arg.push_back('\\');
- break;
- }
- case '\'':
- {
- arg.push_back('\'');
- break;
- }
- case 'e': // Not ANSI-C, but used by bash.
- {
- arg.push_back('\033');
- break;
- }
-
- //
- // Process up to three octal digits.
- //
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- {
- static string octalDigits = "01234567";
- unsigned short us = 0;
- string::size_type j;
- for(j = i;
- j < i + 3 && j < l.size() && octalDigits.find_first_of(c = l[j]) != string::npos;
- ++j)
- {
- us = us * 8 + c - '0';
- }
- i = j - 1;
- arg.push_back(static_cast<char>(us));
- break;
- }
-
- //
- // Process up to two hex digits.
- //
- case 'x':
- {
- if(i < l.size() - 1 && !isxdigit(l[i + 1]))
- {
- arg.push_back('\\');
- arg.push_back('x');
- break;
- }
-
- IceUtil::Int64 ull = 0;
- string::size_type j;
- for(j = i + 1; j < i + 3 && j < l.size() && isxdigit(c = l[j]); ++j)
- {
- ull *= 16;
- if(isdigit(c))
- {
- ull += c - '0';
- }
- else if(islower(c))
- {
- ull += c - 'a' + 10;
- }
- else
- {
- ull += c - 'A' + 10;
- }
- }
- i = j - 1;
- arg.push_back(static_cast<char>(ull));
- break;
- }
-
- //
- // Process control-chars.
- //
- case 'c':
- {
- c = l[++i];
- if(isalpha(c) || c == '@' || (c >= '[' && c <= '_'))
- {
- arg.push_back(static_cast<char>(toupper(c) - '@'));
- }
- else
- {
- //
- // Bash does not define what should happen if a \c
- // is not followed by a recognized control character.
- // We simply treat this case like other unrecognized
- // escape sequences, that is, we preserve the escape
- // sequence unchanged.
- //
- arg.push_back('\\');
- arg.push_back('c');
- arg.push_back(c);
- }
- break;
- }
-
- //
- // If inside an ANSI-quoted string, a backslash isn't followed by
- // one of the recognized characters, both the backslash and the
- // character are preserved.
- //
- default:
- {
- arg.push_back('\\');
- arg.push_back(c);
- break;
- }
- }
- break;
- }
- case '\'': // End of ANSI-quote mode.
- {
- state = Normal;
- break;
- }
- default:
- {
- arg.push_back(c); // Everything else is taken literally.
- break;
- }
- }
- break;
- }
- default:
- {
- assert(!"Impossible parse state");
- break;
- }
- }
+ {
+ case Normal:
+ {
+ switch(c)
+ {
+ case '\\':
+ {
+ //
+ // Ignore a backslash at the end of the string,
+ // and strip backslash-newline pairs. If a
+ // backslash is followed by a space, single quote,
+ // double quote, or dollar sign, we drop the backslash
+ // and write the space, single quote, double quote,
+ // or dollar sign. This is necessary to allow quotes
+ // to be escaped. Dropping the backslash preceding a
+ // space deviates from bash quoting rules, but is
+ // necessary so we don't drop backslashes from Windows
+ // path names.)
+ //
+ if(i < l.size() - 1 && l[++i] != '\n')
+ {
+ switch(l[i])
+ {
+ case ' ':
+ case '$':
+ case '\'':
+ case '"':
+ {
+ arg.push_back(l[i]);
+ break;
+ }
+ default:
+ {
+ arg.push_back('\\');
+ arg.push_back(l[i]);
+ break;
+ }
+ }
+ }
+ break;
+ }
+ case '\'':
+ {
+ state = SingleQuote;
+ break;
+ }
+ case '"':
+ {
+ state = DoubleQuote;
+ break;
+ }
+ case '$':
+ {
+ if(i < l.size() - 1 && l[i + 1] == '\'')
+ {
+ state = ANSIQuote; // Bash uses $'<text>' to allow ANSI escape sequences within <text>.
+ ++i;
+ }
+ else
+ {
+ arg.push_back('$');
+ }
+ break;
+ }
+ default:
+ {
+ if(IFS.find(l[i]) != string::npos)
+ {
+ vec.push_back(arg);
+ arg.clear();
+
+ //
+ // Move to start of next argument.
+ //
+ while(++i < l.size() && IFS.find(l[i]) != string::npos)
+ {
+ ;
+ }
+ --i;
+ }
+ else
+ {
+ arg.push_back(l[i]);
+ }
+ break;
+ }
+ }
+ break;
+ }
+ case DoubleQuote:
+ {
+ //
+ // Within double quotes, only backslash retains its special
+ // meaning, and only if followed by double quote, backslash,
+ // or newline. If not followed by one of these characters,
+ // both the backslash and the character are preserved.
+ //
+ if(c == '\\' && i < l.size() - 1)
+ {
+ switch(c = l[++i])
+ {
+ case '"':
+ case '\\':
+ case '\n':
+ {
+ arg.push_back(c);
+ break;
+ }
+ default:
+ {
+ arg.push_back('\\');
+ arg.push_back(c);
+ break;
+ }
+ }
+ }
+ else if(c == '"') // End of double-quote mode.
+ {
+ state = Normal;
+ }
+ else
+ {
+ arg.push_back(c); // Everything else is taken literally.
+ }
+ break;
+ }
+ case SingleQuote:
+ {
+ if(c == '\'') // End of single-quote mode.
+ {
+ state = Normal;
+ }
+ else
+ {
+ arg.push_back(c); // Everything else is taken literally.
+ }
+ break;
+ }
+ case ANSIQuote:
+ {
+ switch(c)
+ {
+ case '\\':
+ {
+ if(i == l.size() - 1)
+ {
+ break;
+ }
+ switch(c = l[++i])
+ {
+ //
+ // Single-letter escape sequences.
+ //
+ case 'a':
+ {
+ arg.push_back('\a');
+ break;
+ }
+ case 'b':
+ {
+ arg.push_back('\b');
+ break;
+ }
+ case 'f':
+ {
+ arg.push_back('\f');
+ break;
+ }
+ case 'n':
+ {
+ arg.push_back('\n');
+ break;
+ }
+ case 'r':
+ {
+ arg.push_back('\r');
+ break;
+ }
+ case 't':
+ {
+ arg.push_back('\t');
+ break;
+ }
+ case 'v':
+ {
+ arg.push_back('\v');
+ break;
+ }
+ case '\\':
+ {
+ arg.push_back('\\');
+ break;
+ }
+ case '\'':
+ {
+ arg.push_back('\'');
+ break;
+ }
+ case 'e': // Not ANSI-C, but used by bash.
+ {
+ arg.push_back('\033');
+ break;
+ }
+
+ //
+ // Process up to three octal digits.
+ //
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ {
+ static string octalDigits = "01234567";
+ unsigned short us = 0;
+ string::size_type j;
+ for(j = i;
+ j < i + 3 && j < l.size() && octalDigits.find_first_of(c = l[j]) != string::npos;
+ ++j)
+ {
+ us = us * 8 + c - '0';
+ }
+ i = j - 1;
+ arg.push_back(static_cast<char>(us));
+ break;
+ }
+
+ //
+ // Process up to two hex digits.
+ //
+ case 'x':
+ {
+ if(i < l.size() - 1 && !isxdigit(l[i + 1]))
+ {
+ arg.push_back('\\');
+ arg.push_back('x');
+ break;
+ }
+
+ IceUtil::Int64 ull = 0;
+ string::size_type j;
+ for(j = i + 1; j < i + 3 && j < l.size() && isxdigit(c = l[j]); ++j)
+ {
+ ull *= 16;
+ if(isdigit(c))
+ {
+ ull += c - '0';
+ }
+ else if(islower(c))
+ {
+ ull += c - 'a' + 10;
+ }
+ else
+ {
+ ull += c - 'A' + 10;
+ }
+ }
+ i = j - 1;
+ arg.push_back(static_cast<char>(ull));
+ break;
+ }
+
+ //
+ // Process control-chars.
+ //
+ case 'c':
+ {
+ c = l[++i];
+ if(isalpha(c) || c == '@' || (c >= '[' && c <= '_'))
+ {
+ arg.push_back(static_cast<char>(toupper(c) - '@'));
+ }
+ else
+ {
+ //
+ // Bash does not define what should happen if a \c
+ // is not followed by a recognized control character.
+ // We simply treat this case like other unrecognized
+ // escape sequences, that is, we preserve the escape
+ // sequence unchanged.
+ //
+ arg.push_back('\\');
+ arg.push_back('c');
+ arg.push_back(c);
+ }
+ break;
+ }
+
+ //
+ // If inside an ANSI-quoted string, a backslash isn't followed by
+ // one of the recognized characters, both the backslash and the
+ // character are preserved.
+ //
+ default:
+ {
+ arg.push_back('\\');
+ arg.push_back(c);
+ break;
+ }
+ }
+ break;
+ }
+ case '\'': // End of ANSI-quote mode.
+ {
+ state = Normal;
+ break;
+ }
+ default:
+ {
+ arg.push_back(c); // Everything else is taken literally.
+ break;
+ }
+ }
+ break;
+ }
+ default:
+ {
+ assert(!"Impossible parse state");
+ break;
+ }
+ }
}
switch(state)
{
- case Normal:
- {
- vec.push_back(arg);
- break;
- }
- case SingleQuote:
- {
- throw BadOptException(__FILE__, __LINE__, "missing closing single quote");
- break;
- }
- case DoubleQuote:
- {
- throw BadOptException(__FILE__, __LINE__, "missing closing double quote");
- break;
- }
- case ANSIQuote:
- {
- throw BadOptException(__FILE__, __LINE__, "unterminated $' quote");
- break;
- }
- default:
- {
- assert(!"Impossible parse state");
- break;
- }
+ case Normal:
+ {
+ vec.push_back(arg);
+ break;
+ }
+ case SingleQuote:
+ {
+ throw BadOptException(__FILE__, __LINE__, "missing closing single quote");
+ break;
+ }
+ case DoubleQuote:
+ {
+ throw BadOptException(__FILE__, __LINE__, "missing closing double quote");
+ break;
+ }
+ case ANSIQuote:
+ {
+ throw BadOptException(__FILE__, __LINE__, "unterminated $' quote");
+ break;
+ }
+ default:
+ {
+ assert(!"Impossible parse state");
+ break;
+ }
}
return vec;
@@ -592,7 +592,7 @@ IceUtil::Options::parse(const StringVector& args)
if(parseCalled)
{
- throw APIException(__FILE__, __LINE__, "cannot call parse() more than once on the same Option instance");
+ throw APIException(__FILE__, __LINE__, "cannot call parse() more than once on the same Option instance");
}
parseCalled = true;
@@ -603,133 +603,133 @@ IceUtil::Options::parse(const StringVector& args)
string::size_type i;
for(i = 1; i < args.size(); ++i)
{
- if(args[i] == "-" || args[i] == "--")
- {
- ++i;
- break; // "-" and "--" indicate end of options.
- }
-
- string opt;
- ValidOpts::iterator pos;
+ if(args[i] == "-" || args[i] == "--")
+ {
+ ++i;
+ break; // "-" and "--" indicate end of options.
+ }
+
+ string opt;
+ ValidOpts::iterator pos;
bool argDone = false;
- if(args[i].compare(0, 2, "--") == 0)
- {
- //
- // Long option. If the option has an argument, it can either be separated by '='
- // or appear as a separate argument. For example, "--name value" is the same
- // as "--name=value".
- //
- string::size_type p = args[i].find('=', 2);
- if(p != string::npos)
- {
- opt = args[i].substr(2, p - 2);
- }
- else
- {
- opt = args[i].substr(2);
- }
-
- pos = checkOpt(opt, LongOpt);
-
- if(pos->second->repeat == NoRepeat)
- {
- set<string>::iterator seenPos = seenNonRepeatableOpts.find(opt);
- if(seenPos != seenNonRepeatableOpts.end())
- {
- string err = "`--";
- err += opt + ":' option cannot be repeated";
- throw BadOptException(__FILE__, __LINE__, err);
- }
- seenNonRepeatableOpts.insert(seenPos, opt);
- string synonym = getSynonym(opt);
- if(!synonym.empty())
- {
- seenNonRepeatableOpts.insert(synonym);
- }
- }
-
- if(p != string::npos)
- {
- if(pos->second->arg == NoArg && p != args[i].size() - 1)
- {
- string err = "`";
- err += args[i];
- err += "': option does not take an argument";
- throw BadOptException(__FILE__, __LINE__, err);
- }
- setOpt(opt, "", args[i].substr(p + 1), pos->second->repeat);
- argDone = true;
- }
- }
- else if(!args[i].empty() && args[i][0] == '-')
- {
- //
- // Short option.
- //
- for(string::size_type p = 1; p < args[i].size(); ++p)
- {
- opt.clear();
- opt.push_back(args[i][p]);
- pos = checkOpt(opt, ShortOpt);
-
- if(pos->second->repeat == NoRepeat)
- {
- set<string>::iterator seenPos = seenNonRepeatableOpts.find(opt);
- if(seenPos != seenNonRepeatableOpts.end())
- {
- string err = "`-";
- err += opt + ":' option cannot be repeated";
- throw BadOptException(__FILE__, __LINE__, err);
- }
- seenNonRepeatableOpts.insert(seenPos, opt);
- string synonym = getSynonym(opt);
- if(!synonym.empty())
- {
- seenNonRepeatableOpts.insert(synonym);
- }
- }
-
- if(pos->second->arg == NeedArg && p != args[i].size() - 1)
- {
- string optArg = args[i].substr(p + 1);
- setOpt(opt, "", optArg, pos->second->repeat);
- argDone = true;
- break;
- }
- }
- }
- else
- {
- //
- // Not an option or option argument.
- //
- result.push_back(args[i]);
- argDone = true;
- }
-
- if(!argDone)
- {
- if(pos->second->arg == NeedArg) // Need an argument that is separated by whitespace.
- {
- if(i == args.size() - 1)
- {
- string err = "`-";
- if(opt.size() != 1)
- {
- err += "-";
- }
- err += opt;
- err += "' option requires an argument";
- throw BadOptException(__FILE__, __LINE__, err);
- }
- setOpt(opt, "", args[++i], pos->second->repeat);
- }
- else
- {
- setOpt(opt, "", "1", pos->second->repeat);
- }
- }
+ if(args[i].compare(0, 2, "--") == 0)
+ {
+ //
+ // Long option. If the option has an argument, it can either be separated by '='
+ // or appear as a separate argument. For example, "--name value" is the same
+ // as "--name=value".
+ //
+ string::size_type p = args[i].find('=', 2);
+ if(p != string::npos)
+ {
+ opt = args[i].substr(2, p - 2);
+ }
+ else
+ {
+ opt = args[i].substr(2);
+ }
+
+ pos = checkOpt(opt, LongOpt);
+
+ if(pos->second->repeat == NoRepeat)
+ {
+ set<string>::iterator seenPos = seenNonRepeatableOpts.find(opt);
+ if(seenPos != seenNonRepeatableOpts.end())
+ {
+ string err = "`--";
+ err += opt + ":' option cannot be repeated";
+ throw BadOptException(__FILE__, __LINE__, err);
+ }
+ seenNonRepeatableOpts.insert(seenPos, opt);
+ string synonym = getSynonym(opt);
+ if(!synonym.empty())
+ {
+ seenNonRepeatableOpts.insert(synonym);
+ }
+ }
+
+ if(p != string::npos)
+ {
+ if(pos->second->arg == NoArg && p != args[i].size() - 1)
+ {
+ string err = "`";
+ err += args[i];
+ err += "': option does not take an argument";
+ throw BadOptException(__FILE__, __LINE__, err);
+ }
+ setOpt(opt, "", args[i].substr(p + 1), pos->second->repeat);
+ argDone = true;
+ }
+ }
+ else if(!args[i].empty() && args[i][0] == '-')
+ {
+ //
+ // Short option.
+ //
+ for(string::size_type p = 1; p < args[i].size(); ++p)
+ {
+ opt.clear();
+ opt.push_back(args[i][p]);
+ pos = checkOpt(opt, ShortOpt);
+
+ if(pos->second->repeat == NoRepeat)
+ {
+ set<string>::iterator seenPos = seenNonRepeatableOpts.find(opt);
+ if(seenPos != seenNonRepeatableOpts.end())
+ {
+ string err = "`-";
+ err += opt + ":' option cannot be repeated";
+ throw BadOptException(__FILE__, __LINE__, err);
+ }
+ seenNonRepeatableOpts.insert(seenPos, opt);
+ string synonym = getSynonym(opt);
+ if(!synonym.empty())
+ {
+ seenNonRepeatableOpts.insert(synonym);
+ }
+ }
+
+ if(pos->second->arg == NeedArg && p != args[i].size() - 1)
+ {
+ string optArg = args[i].substr(p + 1);
+ setOpt(opt, "", optArg, pos->second->repeat);
+ argDone = true;
+ break;
+ }
+ }
+ }
+ else
+ {
+ //
+ // Not an option or option argument.
+ //
+ result.push_back(args[i]);
+ argDone = true;
+ }
+
+ if(!argDone)
+ {
+ if(pos->second->arg == NeedArg) // Need an argument that is separated by whitespace.
+ {
+ if(i == args.size() - 1)
+ {
+ string err = "`-";
+ if(opt.size() != 1)
+ {
+ err += "-";
+ }
+ err += opt;
+ err += "' option requires an argument";
+ throw BadOptException(__FILE__, __LINE__, err);
+ }
+ setOpt(opt, "", args[++i], pos->second->repeat);
+ }
+ else
+ {
+ setOpt(opt, "", "1", pos->second->repeat);
+ }
+ }
}
_synonyms.clear(); // Don't need the contents anymore.
@@ -765,7 +765,7 @@ IceUtil::Options::isSet(const string& opt) const
if(!parseCalled)
{
- throw APIException(__FILE__, __LINE__, "cannot lookup options before calling parse()");
+ throw APIException(__FILE__, __LINE__, "cannot lookup options before calling parse()");
}
ValidOpts::const_iterator pos = checkOptIsValid(opt);
@@ -779,21 +779,21 @@ IceUtil::Options::optArg(const string& opt) const
if(!parseCalled)
{
- throw APIException(__FILE__, __LINE__, "cannot lookup options before calling parse()");
+ throw APIException(__FILE__, __LINE__, "cannot lookup options before calling parse()");
}
ValidOpts::const_iterator pos = checkOptHasArg(opt);
if(pos->second->repeat == Repeat)
{
- string err = "`-";
- if(pos->second->length == LongOpt)
- {
- err.push_back('-');
- }
- err += opt;
- err += "': is a repeating option -- use argVec() to get its arguments";
- throw IllegalArgumentException(__FILE__, __LINE__, err);
+ string err = "`-";
+ if(pos->second->length == LongOpt)
+ {
+ err.push_back('-');
+ }
+ err += opt;
+ err += "': is a repeating option -- use argVec() to get its arguments";
+ throw IllegalArgumentException(__FILE__, __LINE__, err);
}
Opts::const_iterator p = _opts.find(opt);
@@ -811,20 +811,20 @@ IceUtil::Options::argVec(const string& opt) const
if(!parseCalled)
{
- throw APIException(__FILE__, __LINE__, "cannot lookup options before calling parse()");
+ throw APIException(__FILE__, __LINE__, "cannot lookup options before calling parse()");
}
ValidOpts::const_iterator pos = checkOptHasArg(opt);
if(pos->second->repeat == NoRepeat)
{
- string err = "`-";
- if(pos->second->length == LongOpt)
- {
- err.push_back('-');
- }
- err += opt + "': is a non-repeating option -- use optArg() to get its argument";
- throw IllegalArgumentException(__FILE__, __LINE__, err);
+ string err = "`-";
+ if(pos->second->length == LongOpt)
+ {
+ err.push_back('-');
+ }
+ err += opt + "': is a non-repeating option -- use optArg() to get its argument";
+ throw IllegalArgumentException(__FILE__, __LINE__, err);
}
ROpts::const_iterator p = _ropts.find(opt);
@@ -837,17 +837,17 @@ IceUtil::Options::addValidOpt(const string& shortOpt, const string& longOpt,
{
if(!shortOpt.empty() && _validOpts.find(shortOpt) != _validOpts.end())
{
- string err = "`";
- err += shortOpt;
- err += "': duplicate option";
- throw IllegalArgumentException(__FILE__, __LINE__, err);
+ string err = "`";
+ err += shortOpt;
+ err += "': duplicate option";
+ throw IllegalArgumentException(__FILE__, __LINE__, err);
}
if(!longOpt.empty() && _validOpts.find(longOpt) != _validOpts.end())
{
- string err = "`";
- err += longOpt;
- err += "': duplicate option";
- throw IllegalArgumentException(__FILE__, __LINE__, err);
+ string err = "`";
+ err += longOpt;
+ err += "': duplicate option";
+ throw IllegalArgumentException(__FILE__, __LINE__, err);
}
ODPtr odp = new OptionDetails;
@@ -857,12 +857,12 @@ IceUtil::Options::addValidOpt(const string& shortOpt, const string& longOpt,
if(!shortOpt.empty())
{
- odp->length = ShortOpt;
- _validOpts[shortOpt] = odp;
+ odp->length = ShortOpt;
+ _validOpts[shortOpt] = odp;
}
if(!longOpt.empty())
{
- odp->length = LongOpt;
+ odp->length = LongOpt;
_validOpts[longOpt] = odp;
}
@@ -870,7 +870,7 @@ IceUtil::Options::addValidOpt(const string& shortOpt, const string& longOpt,
if(at == NeedArg && !dflt.empty())
{
- setOpt(shortOpt, longOpt, dflt, rt);
+ setOpt(shortOpt, longOpt, dflt, rt);
}
}
@@ -880,14 +880,14 @@ IceUtil::Options::checkOpt(const string& opt, LengthType lt)
ValidOpts::iterator pos = _validOpts.find(opt);
if(pos == _validOpts.end())
{
- string err = "invalid option: `-";
- if(lt == LongOpt)
- {
- err.push_back('-');
- }
- err += opt;
- err.push_back('\'');
- throw BadOptException(__FILE__, __LINE__, err);
+ string err = "invalid option: `-";
+ if(lt == LongOpt)
+ {
+ err.push_back('-');
+ }
+ err += opt;
+ err.push_back('\'');
+ throw BadOptException(__FILE__, __LINE__, err);
}
return pos;
}
@@ -902,13 +902,13 @@ IceUtil::Options::setOpt(const string& opt1, const string& opt2, const string& v
if(rt == NoRepeat)
{
- setNonRepeatingOpt(opt1, val);
- setNonRepeatingOpt(opt2, val);
+ setNonRepeatingOpt(opt1, val);
+ setNonRepeatingOpt(opt2, val);
}
else
{
- setRepeatingOpt(opt1, val);
- setRepeatingOpt(opt2, val);
+ setRepeatingOpt(opt1, val);
+ setRepeatingOpt(opt2, val);
}
}
@@ -933,7 +933,7 @@ IceUtil::Options::setNonRepeatingOpt(const string& opt, const string& val)
const string synonym = getSynonym(opt);
if(!synonym.empty())
{
- _opts[synonym] = ovp;
+ _opts[synonym] = ovp;
}
}
@@ -954,45 +954,45 @@ IceUtil::Options::setRepeatingOpt(const string& opt, const string& val)
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);
- }
+ 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())
{
- 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)
- {
- spos->second->vals[0] = val;
- vpos->second->hasDefault = false;
- }
- else
- {
- spos->second->vals.push_back(val);
- }
+ 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)
+ {
+ spos->second->vals[0] = val;
+ vpos->second->hasDefault = false;
+ }
+ else
+ {
+ spos->second->vals.push_back(val);
+ }
}
else
{
- OVecPtr ovp = new OptionValueVector;
- ovp->vals.push_back(val);
- _ropts[opt] = ovp;
- if(!synonym.empty())
- {
- _ropts[synonym] = ovp;
- }
+ OVecPtr ovp = new OptionValueVector;
+ ovp->vals.push_back(val);
+ _ropts[opt] = ovp;
+ if(!synonym.empty())
+ {
+ _ropts[synonym] = ovp;
+ }
}
}
@@ -1002,10 +1002,10 @@ IceUtil::Options::checkOptIsValid(const string& opt) const
ValidOpts::const_iterator pos = _validOpts.find(opt);
if(pos == _validOpts.end())
{
- string err = "`";
- err += opt;
- err += "': invalid option";
- throw IllegalArgumentException(__FILE__, __LINE__, err);
+ string err = "`";
+ err += opt;
+ err += "': invalid option";
+ throw IllegalArgumentException(__FILE__, __LINE__, err);
}
return pos;
}
@@ -1016,14 +1016,14 @@ IceUtil::Options::checkOptHasArg(const string& opt) const
ValidOpts::const_iterator pos = checkOptIsValid(opt);
if(pos->second->arg == NoArg)
{
- string err = "`-";
- if(pos->second->length == LongOpt)
- {
- err.push_back('-');
- }
- err += opt;
- err += "': option does not take arguments";
- throw IllegalArgumentException(__FILE__, __LINE__, err);
+ string err = "`-";
+ if(pos->second->length == LongOpt)
+ {
+ err.push_back('-');
+ }
+ err += opt;
+ err += "': option does not take arguments";
+ throw IllegalArgumentException(__FILE__, __LINE__, err);
}
return pos;
}
@@ -1034,7 +1034,7 @@ IceUtil::Options::updateSynonyms(const ::std::string& shortOpt, const ::std::str
if(!shortOpt.empty() && !longOpt.empty())
{
_synonyms[shortOpt] = longOpt;
- _synonyms[longOpt] = shortOpt;
+ _synonyms[longOpt] = shortOpt;
}
}