-D command-line defines.

This commit is contained in:
Kelvin Sherlock 2016-02-02 22:15:31 -05:00
parent 87e586d39b
commit bfd1e353e5
1 changed files with 42 additions and 0 deletions

View File

@ -134,11 +134,53 @@ int interactive(phase1 &p) {
return 0;
}
void help() {
}
void define(Environment &env, const std::string &s) {
auto pos = s.find('=');
if (pos == s.npos) env.set(s, "1");
else {
std::string k = s.substr(0, pos);
std::string v = s.substr(pos+1);
env.set(k, v);
}
}
int main(int argc, char **argv) {
Environment e;
init(e);
int c;
while ((c = getopt(argc, argv, "D:v:h")) != -1) {
switch (c) {
case 'D':
// -Dname or -Dname=value
define(e, optarg);
break;
case 'v':
// -v verbose
e.set("echo", "1");
break;
case 'h':
help();
exit(0);
default:
help();
exit(EX_USAGE);
}
}
phase1 p1;
phase2 p2;