diff --git a/lib/utils.cc b/lib/utils.cc index f8d14306..3d4ccc37 100644 --- a/lib/utils.cc +++ b/lib/utils.cc @@ -194,7 +194,8 @@ std::string tohex(const std::string& s) bool doesFileExist(const std::string& filename) { - std::ifstream f(filename); - return f.good(); + std::ifstream f(filename); + return f.good(); } + diff --git a/lib/utils.h b/lib/utils.h index ea183d8a..38f5113e 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -20,6 +20,15 @@ extern std::string unhex(const std::string& s); extern std::string tohex(const std::string& s); extern bool doesFileExist(const std::string& filename); +template +std::map reverseMap(const std::map& map) +{ + std::map reverse; + for (const auto& [k, v] : map) + reverse[v] = k; + return reverse; +} + /* If set, any running job will terminate as soon as possible (with an error). */ diff --git a/lib/vfs/lif.cc b/lib/vfs/lif.cc index fd86bdd2..ba806d82 100644 --- a/lib/vfs/lif.cc +++ b/lib/vfs/lif.cc @@ -7,6 +7,64 @@ /* See https://www.hp9845.net/9845/projects/hpdir/#lif_filesystem for * a description. */ +static std::map numberToFileType = { + {0x0001, "TEXT" }, + {0x00ff, "D-LEX" }, + {0xe008, "BIN8x" }, + {0xe010, "DTA8x" }, + {0xe020, "BAS8x" }, + {0xe030, "XM41" }, + {0xe040, "ALL41" }, + {0xe050, "KEY41" }, + {0xe052, "TXT75" }, + {0xe053, "APP75" }, + {0xe058, "DAT75" }, + {0xe060, "STA41" }, + {0xe070, "X-M41" }, + {0xe080, "PGM41" }, + {0xe088, "BAS75" }, + {0xe089, "LEX75" }, + {0xe08a, "WKS75" }, + {0xe08b, "ROM75" }, + {0xe0d0, "SDATA" }, + {0xe0d1, "TEXT_S" }, + {0xe0f0, "DAT71" }, + {0xe0f1, "DAT71_S" }, + {0xe204, "BIN71" }, + {0xe205, "BIN71_S" }, + {0xe206, "BIN71_P" }, + {0xe207, "BIN71_SP"}, + {0xe208, "LEX71" }, + {0xe209, "LEX71_S" }, + {0xe20a, "LEX71_P" }, + {0xe20b, "LEX71_SP"}, + {0xe20c, "KEY71" }, + {0xe20d, "KEY71_S" }, + {0xe214, "BAS71" }, + {0xe215, "BAS71_S" }, + {0xe216, "BAS71_P" }, + {0xe217, "BAS71_SP"}, + {0xe218, "FTH71" }, + {0xe219, "FTH71_S" }, + {0xe21a, "FTH71_P" }, + {0xe21b, "FTH71_SP"}, + {0xe21c, "ROM71" }, + {0xe222, "GRA71" }, + {0xe224, "ADR71" }, + {0xe22e, "SYM71" }, + {0xe942, "SYS9k" }, + {0xe946, "HP-UX" }, + {0xe950, "BAS9k" }, + {0xe961, "BDA9k" }, + {0xe971, "BIN9k" }, + {0xea0a, "DTA9k" }, + {0xea32, "COD9k" }, + {0xea3e, "TXT9k" }, +}; + +static std::map fileTypeToNumber = + reverseMap(numberToFileType); + static void trimZeros(std::string s) { s.erase(std::remove(s.begin(), s.end(), 0), s.end()); @@ -27,7 +85,12 @@ class LifFilesystem : public Filesystem location = br.read_be32(); length = br.read_be32() * config.block_size(); - mode = fmt::format("{:04x}", type); + auto it = numberToFileType.find(type); + if (it != numberToFileType.end()) + mode = it->second; + else + mode = fmt::format("{:04x}", type); + path = {filename}; attributes[Filesystem::FILENAME] = filename;