Skip to content

Commit

Permalink
Code Review
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonicadvance1 committed Sep 30, 2024
1 parent 2d61439 commit 776df1a
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions Source/Tools/FEXLoader/FEXLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ bool InterpreterHandler(fextl::string* Filename, const fextl::string& RootFS, fe
// Is the file large enough for shebang
if (ReadSize <= 2) {
close(FD);
return true;
return false;
}

// Handle shebang files
Expand All @@ -167,24 +167,26 @@ bool InterpreterHandler(fextl::string* Filename, const fextl::string& RootFS, fe
fextl::vector<std::string_view> ShebangArguments {};

// Shebang line can have a single argument
using namespace std::literals;
auto Begin = InterpreterLine.begin();
auto ArgEnd = Begin;
auto End = InterpreterLine.end();
const auto Delim = " "sv;
for (; ArgEnd != End && Begin != End; Begin = ArgEnd + 1) {
// Find the end
ArgEnd = std::find_first_of(Begin, End, Delim.begin(), Delim.end());
if (Begin != ArgEnd) {
const auto View = std::string_view(Begin, ArgEnd - Begin);
if (!View.empty()) {
ShebangArguments.emplace_back(View);
}
while (ArgEnd != End && Begin != End) {
// The end of an argument ends with a space or the end of the interpreter line.
ArgEnd = std::find(Begin, End, ' ');
if (Begin == ArgEnd) {
break;
}

const auto View = std::string_view(Begin, ArgEnd - Begin);
if (!View.empty()) {
ShebangArguments.emplace_back(View);
}

Begin = ArgEnd + 1;
}

// Executable argument
*Filename = ShebangArguments[0];
*Filename = ShebangArguments.at(0);

// Insert all the arguments at the start
args->insert(args->begin(), ShebangArguments.begin(), ShebangArguments.end());
Expand Down Expand Up @@ -404,9 +406,9 @@ int main(int argc, char** argv, char** const envp) {
FEXCore::Profiler::Init();
FEXCore::Telemetry::Initialize();

// Program.ProgramPath is highly likely to be prefixed with FEX's rootfs. Get rid of that.
if (Program.ProgramPath.starts_with(LDPath())) {
Program.ProgramPath = Program.ProgramPath.substr(LDPath().size());
// From this point on, ProgramPath needs to not have the LDPath prefixed on to it.
Program.ProgramPath.erase(0, LDPath().size());
}

bool ProgramExists = InterpreterHandler(&Program.ProgramPath, LDPath(), &Args);
Expand Down

0 comments on commit 776df1a

Please sign in to comment.