Skip to content

Commit

Permalink
Shell: Support extremely naive shell script execution
Browse files Browse the repository at this point in the history
This patch allows passing a script as an argument to the Shell program.
We will read the specified line by line and pass them through the Shell
command interpreter.

This is not very powerful, but it's a start :^)
  • Loading branch information
awesomekling committed Sep 14, 2019
1 parent e1481dc commit b7bedab
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Shell/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,9 @@ static int run_command(const String& cmd)
if (cmd.is_empty())
return 0;

if (cmd.starts_with("#"))
return 0;

auto commands = Parser(cmd).parse();

#ifdef SH_DEBUG
Expand Down Expand Up @@ -642,6 +645,21 @@ int main(int argc, char** argv)
return 0;
}

if (argc == 2 && argv[1][0] != '-') {
CFile file(argv[1]);
if (!file.open(CIODevice::ReadOnly)) {
fprintf(stderr, "Failed to open %s: %s\n", file.filename().characters(), file.error_string());
return 1;
}
for (;;) {
auto line = file.read_line(4096);
if (line.is_null())
break;
run_command(String::copy(line, Chomp));
}
return 0;
}

{
auto* cwd = getcwd(nullptr, 0);
g.cwd = cwd;
Expand Down

0 comments on commit b7bedab

Please sign in to comment.