From 5313345853cc41eaecd0043795287e118ca31269 Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 31 Dec 2018 13:48:37 +0100 Subject: [PATCH] Added shebang detection --- src/main.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 587bea2..d4e0e54 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -158,9 +158,15 @@ int main(int argc, char *argv[]) if (out.is_open()) { string buf; - std::getline(in, buf); // Shebang + std::getline(in, buf); - if (buf.substr(0, 16).compare("//compilescript:") == 0) + if (!(buf.substr(0, 2) == "#!")) + { + out << buf << endl; + } + + std::getline(in, buf); + if (buf.substr(0, 16) == "//compilescript:") { compiler_arguments = buf.substr(16); } @@ -168,24 +174,26 @@ int main(int argc, char *argv[]) { out << buf << endl; } + while (!in.eof()) { std::getline(in, buf); out << buf << endl; } + in.close(); out.close(); } else { cerr << "ERROR: Could not open file: " << source << endl; - std::exit(1); + return 1; } } else { cerr << "ERROR: Could not open file: " << original << endl; - std::exit(1); + return 1; } std::system((compiler + " " + source.string() + " " + compiler_arguments