generate_header: fix handling of escape sequences
The string in the source file can be C-escaped. We can copy them
directly as-is in the catcomp block (the C compiler will then handle the
escapements), but we have to adjust the length to be the one after the
escapements are processed.
diff --git a/generate_header.py b/generate_header.py
index ea85576..d8083a0 100755
--- a/generate_header.py
+++ b/generate_header.py
@@ -156,14 +156,14 @@
i1 = i >> 16
i2 = i >> 8
i3 = i >> 0
- l = len(string['text']) + 1
+ l = len(string['text'].encode('latin1', 'backslashreplace').decode('unicode-escape')) + 1
odd = False
if (l & 1) != 0:
odd = True
l = l + 1
l0 = l >> 8
l1 = l
- outfile.write(f" \"\\x{i0:02X}\\x{i1:02X}\\x{i2:02X}\\x{i3:02X}\\x{l0:02X}\\x{l1:02X}\"\n")
+ outfile.write(f" \"\\x{i0:02X}\\x{i1:02X}\\x{i2:02X}\\x{i3:02X}\" \"\\x{l0:02X}\\x{l1:02X}\"\n")
if odd:
outfile.write(f" {string['name']}_STR \"\\x00\\x00\"\n")
else: