-c support

This commit is contained in:
Kelvin Sherlock 2016-02-02 22:39:06 -05:00
parent bfd1e353e5
commit 69476fd0e0

View File

@ -154,9 +154,15 @@ int main(int argc, char **argv) {
Environment e; Environment e;
init(e); init(e);
const char *cflag = nullptr;
int c; int c;
while ((c = getopt(argc, argv, "D:v:h")) != -1) { while ((c = getopt(argc, argv, "c:D:v:h")) != -1) {
switch (c) { switch (c) {
case 'c':
// -c command
cflag = optarg;
break;
case 'D': case 'D':
// -Dname or -Dname=value // -Dname or -Dname=value
define(e, optarg); define(e, optarg);
@ -205,17 +211,25 @@ int main(int argc, char **argv) {
} }
}; };
fprintf(stdout, "MPW Shell 0.0\n"); if (!cflag) fprintf(stdout, "MPW Shell 0.0\n");
e.startup(true); e.startup(true);
read_file(p1, "/Users/kelvin/mpw/Startup"); read_file(p1, "/Users/kelvin/mpw/Startup");
//p2.finish(); //p2.finish();
e.startup(false); e.startup(false);
if (cflag) {
std::string s(cflag);
s.push_back('\n');
p1.process(s.data(), s.data() + s.length(), true);
p2.finish();
exit(e.status());
}
if (isatty(STDIN_FILENO)) if (isatty(STDIN_FILENO))
interactive(p1); interactive(p1);
else else
read_fd(p1, STDIN_FILENO); read_fd(p1, STDIN_FILENO);
p2.finish(); p2.finish();
return 0; exit(e.status());
} }