diff --git a/ml.cpp b/ml.cpp index 65d6b4f..4865daa 100644 --- a/ml.cpp +++ b/ml.cpp @@ -2220,8 +2220,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-run used for shebang\n\t-p prints profile info at the end\n\t-d better stacktrace when exception\n\t-v prints version string\n\n"; + 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-run used for shebang\n\t-p prints profile info at the end\n\t-d better stacktrace when exception\n\t-v prints version string\n\n"; return 0; } // version @@ -2236,15 +2235,17 @@ int main(int argc, char *argv[]) { run(codes[i], env); // run files } else if (cmdOptionExists(argv, argv + argc, "-f")) { - std::vector files = getCmdOption(argv, argc, "-f"); - for (size_t i = 0; i < files.size(); i++) - run(read_file_contents(files[i]), env); + for (auto & file : getCmdOption(argv, argc, "-f")) + run(read_file_contents(file), env); // 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?? - run(file_content, env); + } else if (cmdOptionExists(argv, argv + argc, "-run")) { + for (auto & file : getCmdOption(argv, argc, "-run")) { // TODO check only one file is specified ?? + std::string file_content = read_file_contents(file); + if (file_content.find("#!") == 0) // shebang ? + file_content.erase(0, file_content.find("\n") + 1); // TODO mac osx newline?? + + run(file_content, env); + } // repl } else { repl(env);