#include "llvm/Config/config.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/System/Path.h"
#include <algorithm>
#include <functional>
#include <map>
#include <cerrno>
#include <cstring>
using namespace llvm;
-
using namespace cl;
+//===----------------------------------------------------------------------===//
+// Template instantiations and anchors.
+//
+TEMPLATE_INSTANTIATION(class basic_parser<bool>);
+TEMPLATE_INSTANTIATION(class basic_parser<int>);
+TEMPLATE_INSTANTIATION(class basic_parser<unsigned>);
+TEMPLATE_INSTANTIATION(class basic_parser<double>);
+TEMPLATE_INSTANTIATION(class basic_parser<float>);
+TEMPLATE_INSTANTIATION(class basic_parser<std::string>);
+
+TEMPLATE_INSTANTIATION(class opt<unsigned>);
+TEMPLATE_INSTANTIATION(class opt<int>);
+TEMPLATE_INSTANTIATION(class opt<std::string>);
+TEMPLATE_INSTANTIATION(class opt<bool>);
+
+void Option::anchor() {}
+void basic_parser_impl::anchor() {}
+void parser<bool>::anchor() {}
+void parser<int>::anchor() {}
+void parser<unsigned>::anchor() {}
+void parser<double>::anchor() {}
+void parser<float>::anchor() {}
+void parser<std::string>::anchor() {}
+
+//===----------------------------------------------------------------------===//
+
// Globals for name and overview of program
-static const char *ProgramName = "<unknown>";
+static std::string ProgramName = "<premain>";
static const char *ProgramOverview = 0;
// This collects additional help to be printed.
}
//===----------------------------------------------------------------------===//
-// Basic, shared command line option processing machinery...
+// Basic, shared command line option processing machinery.
//
// Return the global command line option vector. Making it a function scoped
/// using strdup (), so it is the caller's responsibility to free ()
/// them later.
///
-static void ParseCStringVector (std::vector<char *> &output,
- const char *input) {
+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";
assert(envVar && "Environment variable name missing");
// Get the environment variable they want us to parse options out of.
- const char *envValue = getenv (envVar);
+ const char *envValue = getenv(envVar);
if (!envValue)
return;
// Get program's "name", which we wouldn't know without the caller
// telling us.
- std::vector<char *> newArgv;
- newArgv.push_back (strdup (progName));
+ std::vector<char*> newArgv;
+ newArgv.push_back(strdup(progName));
// Parse the value of the environment variable into a "command line"
// and hand it off to ParseCommandLineOptions().
- ParseCStringVector (newArgv, envValue);
- int newArgc = newArgv.size ();
- ParseCommandLineOptions (newArgc, &newArgv[0], Overview);
+ ParseCStringVector(newArgv, envValue);
+ int newArgc = newArgv.size();
+ ParseCommandLineOptions(newArgc, &newArgv[0], Overview);
// Free all the strdup()ed strings.
- for (std::vector<char *>::iterator i = newArgv.begin (), e = newArgv.end ();
- i != e; ++i) {
+ for (std::vector<char*>::iterator i = newArgv.begin(), e = newArgv.end();
+ i != e; ++i)
free (*i);
- }
}
/// LookupOption - Lookup the option specified by the specified option on the
assert((!getOpts().empty() || !getPositionalOpts().empty()) &&
"No options specified, or ParseCommandLineOptions called more"
" than once!");
- ProgramName = argv[0]; // Save this away safe and snug
+ sys::Path progname(argv[0]);
+ ProgramName = sys::Path(argv[0]).getLast();
ProgramOverview = Overview;
bool ErrorParsing = false;
}
if (Handler == 0) {
- if (ProgramName)
- std::cerr << ProgramName << ": Unknown command line argument '"
+ std::cerr << ProgramName << ": Unknown command line argument '"
<< argv[i] << "'. Try: '" << argv[0] << " --help'\n";
- else
- std::cerr << "Unknown command line argument '" << argv[i] << "'.\n";
ErrorParsing = true;
continue;
}
// Check and handle positional arguments now...
if (NumPositionalRequired > PositionalVals.size()) {
- if (ProgramName)
- std::cerr << ProgramName
- << ": Not enough positional command line arguments specified!\n"
- << "Must specify at least " << NumPositionalRequired
- << " positional arguments: See: " << argv[0] << " --help\n";
- else
- std::cerr << "Not enough positional command line arguments specified!\n"
- << "Must specify at least " << NumPositionalRequired
- << " positional arguments.";
+ std::cerr << ProgramName
+ << ": Not enough positional command line arguments specified!\n"
+ << "Must specify at least " << NumPositionalRequired
+ << " positional arguments: See: " << argv[0] << " --help\n";
ErrorParsing = true;
} else if (!HasUnlimitedPositionals
&& PositionalVals.size() > PositionalOpts.size()) {
- if (ProgramName)
- std::cerr << ProgramName
- << ": Too many positional arguments specified!\n"
- << "Can specify at most " << PositionalOpts.size()
- << " positional arguments: See: " << argv[0] << " --help\n";
- else
- std::cerr << "Too many positional arguments specified!\n"
- << "Can specify at most " << PositionalOpts.size()
- << " positional arguments.\n";
+ std::cerr << ProgramName
+ << ": Too many positional arguments specified!\n"
+ << "Can specify at most " << PositionalOpts.size()
+ << " positional arguments: See: " << argv[0] << " --help\n";
ErrorParsing = true;
} else if (ConsumeAfterOpt == 0) {
std::cerr << HelpStr; // Be nice for positional arguments
else
std::cerr << ProgramName << ": for the -" << ArgName;
+
std::cerr << " option: " << Message << "\n";
return true;
}