fix: char reserved word

This commit is contained in:
2026-11-05 22:57:14 +01:00
parent fa83ce19c9
commit 4b3a639d58
4 changed files with 30 additions and 20 deletions
+27 -17
View File
@@ -10,6 +10,23 @@ CP437_FILE = PROJECT_PATH / "project" / "inc_cp437.glsl"
SENTENCES_FILE = PROJECT_PATH / "sentences.txt"
BACKUP_SENTENCES_FILE = PROJECT_PATH / "sentences.example.txt"
FILE_CONTENT = """
#ifndef INC_SENTENCES
#define INC_SENTENCES
#define SENTENCE_COUNT {0}
#define SENTENCE_MAX_LENGTH {1}
const int sentences[] = int[SENTENCE_COUNT * SENTENCE_MAX_LENGTH](
{2}
);
const int lengths[] = int[SENTENCE_COUNT](
{3}
);
#endif
"""
log = logging.getLogger(__name__)
def read_mapping() -> dict[str, str]:
@@ -44,25 +61,18 @@ def main():
max_len = max(len(sentence) for sentence in sentences)
with TARGET_FILE.open("w") as file:
file.write("#ifndef INC_SENTENCES\n")
file.write("#define INC_SENTENCES\n\n")
file.write(f"#define SENTENCE_COUNT {len(sentences)}\n")
file.write(f"#define SENTENCE_MAX_LENGTH {max_len}\n\n")
file.write(
"const int sentences[] = int[SENTENCE_COUNT * SENTENCE_MAX_LENGTH](\n"
)
file.writelines(
" " + convert(sentence, mapping, max_len) + ("," if i < len(sentences) - 1 else " ") + f" // {sentence}\n"
for i, sentence in enumerate(sentences)
)
file.write(");\n\n")
file.write("const int lengths[] = int[SENTENCE_COUNT](\n")
file.write(
TARGET_FILE.write_text(
FILE_CONTENT.format(
len(sentences),
max_len,
"".join(
" " + convert(sentence, mapping, max_len) + ("," if i < len(sentences) - 1 else " ") + f" // {sentence}\n"
for i, sentence in enumerate(sentences)
),
" " + ", ".join(str(len(sentence)) for sentence in sentences) + "\n"
)
file.write(");\n")
file.write("#endif")
)
log.info(f"Wrote {len(sentences)} sentences to {TARGET_FILE}")