mirror of
https://github.com/ksherlock/mpw-shell.git
synced 2024-06-07 03:29:32 +00:00
-D command-line defines.
This commit is contained in:
parent
87e586d39b
commit
bfd1e353e5
|
@ -134,11 +134,53 @@ int interactive(phase1 &p) {
|
||||||
return 0;
|
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) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
Environment e;
|
Environment e;
|
||||||
init(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;
|
phase1 p1;
|
||||||
phase2 p2;
|
phase2 p2;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user