1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-01 11:49:58 +00:00

Gives the FAT parser responsibility for right trims.

This commit is contained in:
Thomas Harte 2021-07-02 19:50:27 -04:00
parent bcf483fb7e
commit bae8bb0c00
2 changed files with 11 additions and 3 deletions

View File

@ -54,7 +54,7 @@ Analyser::Static::TargetList Analyser::Static::Enterprise::GetTargets(const Medi
bool has_exdos_ini = false; bool has_exdos_ini = false;
bool did_pick_file = false; bool did_pick_file = false;
for(const auto &file: (*volume).root_directory) { for(const auto &file: (*volume).root_directory) {
if(insensitive_equal(file.name, "EXDOS ") && insensitive_equal(file.extension, "INI")) { if(insensitive_equal(file.name, "exdos") && insensitive_equal(file.extension, "ini")) {
has_exdos_ini = true; has_exdos_ini = true;
break; break;
} }

View File

@ -32,6 +32,14 @@ int FAT::Volume::sector_for_cluster(uint16_t cluster) const {
namespace { namespace {
template <typename CharT> std::string trim(CharT start, CharT end) {
std::string result(start, end);
result.erase(std::find_if(result.rbegin(), result.rend(), [](unsigned char ch) {
return !std::isspace(ch);
}).base(), result.end());
return result;
}
FAT::Directory directory_from(const std::vector<uint8_t> &contents) { FAT::Directory directory_from(const std::vector<uint8_t> &contents) {
FAT::Directory result; FAT::Directory result;
@ -49,8 +57,8 @@ FAT::Directory directory_from(const std::vector<uint8_t> &contents) {
// Otherwise create and populate a new entry. // Otherwise create and populate a new entry.
result.emplace_back(); result.emplace_back();
result.back().name = std::string(&contents[base], &contents[base+8]); result.back().name = trim(&contents[base], &contents[base+8]);
result.back().extension = std::string(&contents[base+8], &contents[base+11]); result.back().extension = trim(&contents[base+8], &contents[base+11]);
result.back().attributes = contents[base + 11]; result.back().attributes = contents[base + 11];
result.back().time = uint16_t(contents[base+22] | (contents[base+23] << 8)); result.back().time = uint16_t(contents[base+22] | (contents[base+23] << 8));
result.back().date = uint16_t(contents[base+24] | (contents[base+25] << 8)); result.back().date = uint16_t(contents[base+24] | (contents[base+25] << 8));