-void cl::ParseCommandLineOptions(int &argc, char **argv,
- const char *Overview = 0) {
- assert((!getOpts().empty() || !getPositionalOpts().empty()) &&
- "No options specified, or ParseCommandLineOptions called more"
- " than once!");
- ProgramName = argv[0]; // Save this away safe and snug
+/// ParseEnvironmentOptions - An alternative entry point to the
+/// CommandLine library, which allows you to read the program's name
+/// from the caller (as PROGNAME) and its command-line arguments from
+/// an environment variable (whose name is given in ENVVAR).
+///
+void cl::ParseEnvironmentOptions(const char *progName, const char *envVar,
+ const char *Overview) {
+ // Check args.
+ assert(progName && "Program name not specified");
+ assert(envVar && "Environment variable name missing");
+
+ // Get the environment variable they want us to parse options out of.
+ 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));
+
+ // 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);
+
+ // Free all the strdup()ed strings.
+ for (std::vector<char*>::iterator i = newArgv.begin(), e = newArgv.end();
+ i != e; ++i)
+ free (*i);
+}
+
+void cl::ParseCommandLineOptions(int argc, char **argv,
+ const char *Overview) {
+ // Process all registered options.
+ std::vector<Option*> PositionalOpts;
+ std::map<std::string, Option*> Opts;
+ GetOptionInfo(PositionalOpts, Opts);
+
+ assert((!Opts.empty() || !PositionalOpts.empty()) &&
+ "No options specified!");
+ sys::Path progname(argv[0]);
+
+ // Copy the program name into ProgName, making sure not to overflow it.
+ std::string ProgName = sys::Path(argv[0]).getLast();
+ if (ProgName.size() > 79) ProgName.resize(79);
+ strcpy(ProgramName, ProgName.c_str());
+