diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2025-02-01 20:37:32 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2025-02-21 18:11:26 +0100 |
commit | 7b2a17216ec5cb97eeb517863d7336cc04852b43 (patch) | |
tree | 36f90d6f2cdbe8b893c9b5138460ffbdc9a129d8 /src/util.cc | |
parent | dbacf0029104780556af5791f2c6a45edc7a5ec4 (diff) |
WIP
Diffstat (limited to 'src/util.cc')
-rw-r--r-- | src/util.cc | 53 |
1 files changed, 43 insertions, 10 deletions
diff --git a/src/util.cc b/src/util.cc index 6fc650a..20dea71 100644 --- a/src/util.cc +++ b/src/util.cc @@ -8,10 +8,17 @@ #include <algorithm> #include <sstream> +namespace { +char to_lower_c(char ch) +{ + return static_cast<char>(::tolower(ch)); +} +} + std::string to_lower(const std::string& str) { std::string out{str}; - std::transform(out.begin(), out.end(), out.begin(), ::tolower); + std::transform(out.begin(), out.end(), out.begin(), to_lower_c); return out; } @@ -20,13 +27,18 @@ std::string readFile(const std::string& fileName) std::ifstream ifs(fileName.c_str(), std::ios::in | std::ios::binary | std::ios::ate); - std::ifstream::pos_type fileSize = ifs.tellg(); + auto tell = ifs.tellg(); + if(tell < 0) + { + return {}; + } + auto fileSize = static_cast<std::size_t>(tell); ifs.seekg(0, std::ios::beg); - std::vector<char> bytes(static_cast<std::size_t>(fileSize)); - ifs.read(bytes.data(), fileSize); + std::vector<char> bytes(fileSize); + ifs.read(bytes.data(), static_cast<long>(bytes.size())); - return {bytes.data(), static_cast<std::size_t>(fileSize)}; + return { bytes.data(), bytes.size() }; } ctor::language languageFromExtension(const std::filesystem::path& file) @@ -71,7 +83,7 @@ namespace { bool isClean(char c) { - return c != '.' && c != '/'; + return c != '.' && c != '/' && c != '\\'; } } @@ -170,15 +182,36 @@ std::string locate(const std::string& prog, } } + if(std::filesystem::exists(program + ".exe")) + { + if(check_executable(program + ".exe")) + { + return program + ".exe"; + } + } + for(const auto& path_str : paths) { std::filesystem::path path(path_str); - auto prog_path = path / program; - if(std::filesystem::exists(prog_path)) { - if(check_executable(prog_path)) + auto prog_path = path / program; + if(std::filesystem::exists(prog_path)) + { + if(check_executable(prog_path)) + { + return prog_path.string(); + } + } + } + + { + auto prog_path = path / (program + ".exe"); + if(std::filesystem::exists(prog_path)) { - return prog_path.string(); + if(check_executable(prog_path)) + { + return prog_path.string(); + } } } } |