From 41e4386164f0adc879411b2e4c2ddd18fae32868 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 17 Aug 2017 13:21:48 -0400 Subject: [PATCH] Added another "one thing is different" test: one thing has a different file name. Also decided to right-time the type (/extension) as well as the file name. --- StaticAnalyser/AmstradCPC/StaticAnalyser.cpp | 33 +++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/StaticAnalyser/AmstradCPC/StaticAnalyser.cpp b/StaticAnalyser/AmstradCPC/StaticAnalyser.cpp index dc70d5f8f..8cbbca2c0 100644 --- a/StaticAnalyser/AmstradCPC/StaticAnalyser.cpp +++ b/StaticAnalyser/AmstradCPC/StaticAnalyser.cpp @@ -28,19 +28,25 @@ static bool is_implied_extension(const std::string &extension) { strcmp_insensitive(extension.c_str(), "BIN"); } +static void right_trim(std::string &string) { + string.erase(std::find_if(string.rbegin(), string.rend(), [](int ch) { + return !std::isspace(ch); + }).base(), string.end()); +} + static std::string RunCommandFor(const Storage::Disk::CPM::File &file) { // Trim spaces from the name. std::string name = file.name; - name.erase(std::find_if(name.rbegin(), name.rend(), [](int ch) { - return !std::isspace(ch); - }).base(), name.end()); + right_trim(name); // Form the basic command. std::string command = "run\"" + name; // Consider whether the extension is required. if(!is_implied_extension(file.type)) { - command += "." + file.type; + std::string type = file.type; + right_trim(type); + command += "." + type; } // Add a newline and return. @@ -116,6 +122,25 @@ static void InspectDataCatalogue( return; } + // One more guess: if only one remaining candidate file has a different name than the others, + // assume it is intended to stand out. + std::map name_counts; + std::map indices_by_name; + size_t index = 0; + for(auto &file : candidate_files) { + name_counts[file.name]++; + indices_by_name[file.name] = index; + index++; + } + if(name_counts.size() == 2) { + for(auto &pair : name_counts) { + if(pair.second == 1) { + target.loadingCommand = RunCommandFor(candidate_files[indices_by_name[pair.first]]); + return; + } + } + } + // Desperation. target.loadingCommand = "cat\n"; }