//
// The LLVM Compiler Infrastructure
//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
#include <cstdlib>
#include <cerrno>
#include <cstring>
+#include <climits>
using namespace llvm;
using namespace cl;
/// GetOptionInfo - Scan the list of registered options, turning them into data
/// structures that are easier to handle.
static void GetOptionInfo(std::vector<Option*> &PositionalOpts,
+ std::vector<Option*> &SinkOpts,
std::map<std::string, Option*> &OptionsMap) {
std::vector<const char*> OptionNames;
Option *CAOpt = 0; // The ConsumeAfter option if it exists.
// Remember information about positional options.
if (O->getFormattingFlag() == cl::Positional)
PositionalOpts.push_back(O);
+ else if (O->getMiscFlags() & cl::Sink) // Remember sink options
+ SinkOpts.push_back(O);
else if (O->getNumOccurrencesFlag() == cl::ConsumeAfter) {
if (CAOpt)
O->error("Cannot specify more than one option with cl::ConsumeAfter!");
static void ParseCStringVector(std::vector<char *> &output,
const char *input) {
// Characters which will be treated as token separators:
- static const char *delims = " \v\f\t\r\n";
+ static const char *const delims = " \v\f\t\r\n";
std::string work (input);
// Skip past any delims at head of input string.
free (*i);
}
-void cl::ParseCommandLineOptions(int &argc, char **argv,
+void cl::ParseCommandLineOptions(int argc, char **argv,
const char *Overview) {
// Process all registered options.
std::vector<Option*> PositionalOpts;
+ std::vector<Option*> SinkOpts;
std::map<std::string, Option*> Opts;
- GetOptionInfo(PositionalOpts, Opts);
+ GetOptionInfo(PositionalOpts, SinkOpts, Opts);
assert((!Opts.empty() || !PositionalOpts.empty()) &&
"No options specified!");
// response to things like -load, etc. If this happens, rescan the options.
if (OptionListChanged) {
PositionalOpts.clear();
+ SinkOpts.clear();
Opts.clear();
- GetOptionInfo(PositionalOpts, Opts);
+ GetOptionInfo(PositionalOpts, SinkOpts, Opts);
OptionListChanged = false;
}
}
if (Handler == 0) {
- cerr << ProgramName << ": Unknown command line argument '"
- << argv[i] << "'. Try: '" << argv[0] << " --help'\n";
- ErrorParsing = true;
+ if (SinkOpts.empty()) {
+ cerr << ProgramName << ": Unknown command line argument '"
+ << argv[i] << "'. Try: '" << argv[0] << " --help'\n";
+ ErrorParsing = true;
+ } else {
+ for (std::vector<Option*>::iterator I = SinkOpts.begin(),
+ E = SinkOpts.end(); I != E ; ++I)
+ (*I)->addOccurrence(i, "", argv[i]);
+ }
continue;
}
}
public:
- HelpPrinter(bool showHidden) : ShowHidden(showHidden) {
+ explicit HelpPrinter(bool showHidden) : ShowHidden(showHidden) {
EmptyArg = 0;
}
// Get all the options.
std::vector<Option*> PositionalOpts;
+ std::vector<Option*> SinkOpts;
std::map<std::string, Option*> OptMap;
- GetOptionInfo(PositionalOpts, OptMap);
+ GetOptionInfo(PositionalOpts, SinkOpts, OptMap);
// Copy Options into a vector so we can sort them as we like...
std::vector<std::pair<std::string, Option*> > Opts;