diff options
author | Greg Clayton <gclayton@apple.com> | 2012-12-04 00:32:51 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2012-12-04 00:32:51 +0000 |
commit | 3bcdfc0ec19df671655eeedb10da2ff9399b8b65 (patch) | |
tree | 53fa965c5bbacdfccbef6aff6e5db359ad8fa668 /lldb/source/Interpreter/Args.cpp | |
parent | 1dd82dd3fc608ee600652a8bf34f6c345354e3b0 (diff) | |
download | bcm5719-llvm-3bcdfc0ec19df671655eeedb10da2ff9399b8b65.tar.gz bcm5719-llvm-3bcdfc0ec19df671655eeedb10da2ff9399b8b65.zip |
<rdar://problem/12798131>
Cleaned up the option parsing code to always pass around the short options as integers. Previously we cast this down to "char" and lost some information. I recently added an assert that would detect duplicate short character options which was firing during the test suite.
This fix does the following:
- make sure all short options are treated as "int"
- make sure that short options can be non-printable values when a short option is not required or when an option group is mixed into many commands and a short option is not desired
- fix the help printing to "do the right thing" in all cases. Previously if there were duplicate short character options, it would just not emit help for the duplicates
- fix option parsing when there are duplicates to parse options correctly. Previously the option parsing, when done for an OptionGroup, would just start parsing options incorrectly by omitting table entries and it would end up setting the wrong option value
llvm-svn: 169189
Diffstat (limited to 'lldb/source/Interpreter/Args.cpp')
-rw-r--r-- | lldb/source/Interpreter/Args.cpp | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/lldb/source/Interpreter/Args.cpp b/lldb/source/Interpreter/Args.cpp index 1518968bd61..dde546c687b 100644 --- a/lldb/source/Interpreter/Args.cpp +++ b/lldb/source/Interpreter/Args.cpp @@ -625,13 +625,16 @@ Args::ParseOptions (Options &options) { if (long_options[i].flag == NULL) { - sstr << (char)long_options[i].val; - switch (long_options[i].has_arg) + if (isprint(long_options[i].val)) { - default: - case no_argument: break; - case required_argument: sstr << ':'; break; - case optional_argument: sstr << "::"; break; + sstr << (char)long_options[i].val; + switch (long_options[i].has_arg) + { + default: + case no_argument: break; + case required_argument: sstr << ':'; break; + case optional_argument: sstr << "::"; break; + } } } } @@ -645,7 +648,10 @@ Args::ParseOptions (Options &options) while (1) { int long_options_index = -1; - val = ::getopt_long(GetArgumentCount(), GetArgumentVector(), sstr.GetData(), long_options, + val = ::getopt_long(GetArgumentCount(), + GetArgumentVector(), + sstr.GetData(), + long_options, &long_options_index); if (val == -1) break; @@ -1092,7 +1098,7 @@ Args::FindArgumentIndexForOption (struct option *long_options, int long_options_ { char short_buffer[3]; char long_buffer[255]; - ::snprintf (short_buffer, sizeof (short_buffer), "-%c", (char) long_options[long_options_index].val); + ::snprintf (short_buffer, sizeof (short_buffer), "-%c", long_options[long_options_index].val); ::snprintf (long_buffer, sizeof (long_buffer), "--%s", long_options[long_options_index].name); size_t end = GetArgumentCount (); size_t idx = 0; @@ -1216,7 +1222,7 @@ Args::ParseAliasOptions (Options &options, if (long_options_index >= 0) { StreamString option_str; - option_str.Printf ("-%c", (char) val); + option_str.Printf ("-%c", val); switch (long_options[long_options_index].has_arg) { @@ -1256,16 +1262,14 @@ Args::ParseAliasOptions (Options &options, } break; default: - result.AppendErrorWithFormat - ("error with options table; invalid value in has_arg field for option '%c'.\n", - (char) val); + result.AppendErrorWithFormat ("error with options table; invalid value in has_arg field for option '%c'.\n", val); result.SetStatus (eReturnStatusFailed); break; } } else { - result.AppendErrorWithFormat ("Invalid option with value '%c'.\n", (char) val); + result.AppendErrorWithFormat ("Invalid option with value '%c'.\n", val); result.SetStatus (eReturnStatusFailed); } |