misc fixes

This commit is contained in:
2021-09-23 23:03:54 +02:00
parent 48f46289d6
commit 7f793bde61
5 changed files with 14 additions and 11 deletions

15
ml.cpp
View File

@@ -2163,7 +2163,7 @@ int main(int argc, char *argv[]) {
// help
if (cmdOptionExists(argv, argv + argc, "-h")) {
std::cout
<< "Usage:\n\t-h print this help\n\t-b skip stdlib loading\n\t-c code - runs code passed on command line\n\t-f source_file - executes code in file\n\t-i runs repl\n\t-p prints profile info at the end\n\t-v prints version string\n\n";
<< "Usage:\n\t-h print this help\n\t-b skip stdlib loading\n\t-c code - runs code passed on command line\n\t-f source_file - executes code in file\n\t-i runs repl\n\t-run used for shebang\n\t-p prints profile info at the end\n\t-v prints version string\n\n";
return 0;
}
// version
@@ -2176,19 +2176,18 @@ int main(int argc, char *argv[]) {
std::vector<std::string> codes = getCmdOption(argv, argc, "-c");
for (size_t i = 0; i < codes.size(); i++)
run(codes[i], env);
// run files
// run files
} else if (cmdOptionExists(argv, argv + argc, "-f")) {
std::vector<std::string> files = getCmdOption(argv, argc, "-f");
for (size_t i = 0; i < files.size(); i++)
run(read_file_contents(files[i]), env);
// just one parameter - filename
} else if (argc == 2 && !cmdOptionExists(argv, argv + argc, "-b")) {
std::string file_content = read_file_contents(argv[1]);
// sheebang
} else if (argc == 3 && cmdOptionExists(argv, argv + argc, "-run")) {
std::string file_content = read_file_contents(argv[2]);
if (file_content.find("#!") == 0) // shebang ?
file_content.erase(0, file_content.find("\n") +
1); // TODO mac osx newline??
file_content.erase(0, file_content.find("\n") + 1); // TODO mac osx newline??
run(file_content, env);
// repl
// repl
} else {
repl(env);
}