Added shebang detection

This commit is contained in:
tastytea 2018-12-31 13:48:37 +01:00
parent f4d39e4dfc
commit 5313345853
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 12 additions and 4 deletions

View File

@ -158,9 +158,15 @@ int main(int argc, char *argv[])
if (out.is_open()) if (out.is_open())
{ {
string buf; string buf;
std::getline(in, buf); // Shebang
std::getline(in, buf); 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); compiler_arguments = buf.substr(16);
} }
@ -168,24 +174,26 @@ int main(int argc, char *argv[])
{ {
out << buf << endl; out << buf << endl;
} }
while (!in.eof()) while (!in.eof())
{ {
std::getline(in, buf); std::getline(in, buf);
out << buf << endl; out << buf << endl;
} }
in.close(); in.close();
out.close(); out.close();
} }
else else
{ {
cerr << "ERROR: Could not open file: " << source << endl; cerr << "ERROR: Could not open file: " << source << endl;
std::exit(1); return 1;
} }
} }
else else
{ {
cerr << "ERROR: Could not open file: " << original << endl; cerr << "ERROR: Could not open file: " << original << endl;
std::exit(1); return 1;
} }
std::system((compiler + " " + source.string() + " " + compiler_arguments std::system((compiler + " " + source.string() + " " + compiler_arguments