1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-06 01:28:57 +00:00

Broadened CPC data disk analysis to spot when there is only one implicitly-runnable file, rather than only one without suffix.

This commit is contained in:
Thomas Harte 2017-08-11 16:23:00 -04:00
parent 09716d4716
commit 23c149368b

View File

@ -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<Storage::Disk::CPM::Catalogue> &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;
}