Every source file in ui, app, game, formats, cli, audio and launch that had none now starts with a short English comment: what it implements, what state it owns and how it relates to its neighbours (request/acknowledge flow, pairs of files, random generator use). Comment lines only; the full build and the runnable tests are unchanged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
37 lines
1.2 KiB
C++
37 lines
1.2 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
// Implementation of the basic file helpers declared in binary.hpp: read_file() loads a whole
|
|
// file into a Bytes vector (FormatError if it cannot be opened) and iso646de_to_utf8()
|
|
// converts the game's ISO 646-DE strings ([ \ ] { | } ~ stand for the umlauts and the sharp s)
|
|
// to UTF-8. No state.
|
|
#include "formats/binary.hpp"
|
|
|
|
#include <fstream>
|
|
#include <iterator>
|
|
|
|
namespace bmh {
|
|
|
|
Bytes read_file(const std::filesystem::path& path) {
|
|
std::ifstream in(path, std::ios::binary);
|
|
if (!in) throw FormatError("cannot open " + path.string());
|
|
return Bytes(std::istreambuf_iterator<char>(in), {});
|
|
}
|
|
|
|
std::string iso646de_to_utf8(const char* s, size_t max_len) {
|
|
std::string out;
|
|
for (size_t i = 0; i < max_len && s[i] != '\0'; i++) {
|
|
switch (s[i]) {
|
|
case '[': out += "Ä"; break;
|
|
case '\\': out += "Ö"; break;
|
|
case ']': out += "Ü"; break;
|
|
case '{': out += "ä"; break;
|
|
case '|': out += "ö"; break;
|
|
case '}': out += "ü"; break;
|
|
case '~': out += "ß"; break;
|
|
default: out += s[i];
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
|
|
} // namespace bmh
|