From 23c149368bf3886c70e32aa281dfa22f58fb0264 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 11 Aug 2017 16:23:00 -0400 Subject: [PATCH] Broadened CPC data disk analysis to spot when there is only one implicitly-runnable file, rather than only one without suffix. --- StaticAnalyser/AmstradCPC/StaticAnalyser.cpp | 34 ++++++++++++++------ 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/StaticAnalyser/AmstradCPC/StaticAnalyser.cpp b/StaticAnalyser/AmstradCPC/StaticAnalyser.cpp index 354f7f54d..3de7f82e6 100644 --- a/StaticAnalyser/AmstradCPC/StaticAnalyser.cpp +++ b/StaticAnalyser/AmstradCPC/StaticAnalyser.cpp @@ -9,6 +9,16 @@ #include "StaticAnalyser.hpp" #include "../../Storage/Disk/Parsers/CPM.hpp" +static bool strcmp_insensitive(const char *a, const char *b) { + if(strlen(a) != strlen(b)) return false; + while(*a) { + if(tolower(*a) != towlower(*b)) return false; + a++; + b++; + } + return true; +} + static void InspectDataCatalogue( const std::unique_ptr &data_catalogue, StaticAnalyser::Target &target) { @@ -18,12 +28,14 @@ static void InspectDataCatalogue( return; } - // If only one file is [potentially] BASIC, run that one; otherwise if only one has no suffix, - // pick that one. + // If only one file is [potentially] BASIC, run that one; otherwise if only one has a suffix + // that AMSDOS allows to be omitted, pick that one. int basic_files = 0; - int nonsuffixed_files = 0; + int implicit_suffixed_files = 0; + size_t last_basic_file = 0; - size_t last_nonsuffixed_file = 0; + size_t last_implicit_suffixed_file = 0; + for(size_t c = 0; c < data_catalogue->files.size(); c++) { // Check for whether this is [potentially] BASIC. if(!((data_catalogue->files[c].data[18] >> 1) & 7)) { @@ -32,13 +44,17 @@ static void InspectDataCatalogue( } // Check suffix for emptiness. - if(data_catalogue->files[c].type == " ") { - nonsuffixed_files++; - last_nonsuffixed_file = c; + if( + data_catalogue->files[c].type == " " || + strcmp_insensitive(data_catalogue->files[c].type.c_str(), "BAS") || + strcmp_insensitive(data_catalogue->files[c].type.c_str(), "BIN") + ) { + implicit_suffixed_files++; + last_implicit_suffixed_file = c; } } - if(basic_files == 1 || nonsuffixed_files == 1) { - size_t selected_file = (basic_files == 1) ? last_basic_file : last_nonsuffixed_file; + if(basic_files == 1 || implicit_suffixed_files == 1) { + size_t selected_file = (basic_files == 1) ? last_basic_file : last_implicit_suffixed_file; target.loadingCommand = "run\"" + data_catalogue->files[selected_file].name + "\n"; return; }