Files
hackerlibultra/tools/shiftjis_conv.py
2022-03-15 16:44:54 -04:00

59 lines
3.4 KiB
Python
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
import sys
# Converts a file with UTF-8 Japanese glyphs in char literals,
# into one that uses u16 constants
# Follows the layout in the manual page for easier cross reference
sjis_table = {
"": 0x815B, "": 0x82BA, "": 0x82D6, "": 0x8340, "": 0x835C, "": 0x8379,
"": 0x829F, "": 0x82BB, "": 0x82D7, "": 0x8341, "": 0x835D, "": 0x837A,
"": 0x82A0, "": 0x82BC, "": 0x82D8, "": 0x8342, "": 0x835E, "": 0x837B,
"": 0x82A1, "": 0x82BD, "": 0x82D9, "": 0x8343, "": 0x835F, "": 0x837C,
"": 0x82A2, "": 0x82BE, "": 0x82DA, "": 0x8344, "": 0x8360, "": 0x837D,
"": 0x82A3, "": 0x82BF, "": 0x82DB, "": 0x8345, "": 0x8361, "": 0x837E,
"": 0x82A4, "": 0x82C0, "": 0x82DC, "": 0x8346, "": 0x8362, "": 0x8380,
"": 0x82A5, "": 0x82C1, "": 0x82DD, "": 0x8347, "": 0x8363, "": 0x8381,
"": 0x82A6, "": 0x82C2, "": 0x82DE, "": 0x8348, "": 0x8364, "": 0x8382,
"": 0x82A7, "": 0x82C3, "": 0x82DF, "": 0x8349, "": 0x8365, "": 0x8383,
"": 0x82A8, "": 0x82C4, "": 0x82E0, "": 0x834A, "": 0x8366, "": 0x8384,
"": 0x82A9, "": 0x82C5, "": 0x82E1, "": 0x834B, "": 0x8367, "": 0x8385,
"": 0x82AA, "": 0x82C6, "": 0x82E2, "": 0x834C, "": 0x8368, "": 0x8386,
"": 0x82AB, "": 0x82C7, "": 0x82E3, "": 0x834D, "": 0x8369, "": 0x8387,
"": 0x82AC, "": 0x82C8, "": 0x82E4, "": 0x834E, "": 0x836A, "": 0x8388,
"": 0x82AD, "": 0x82C9, "": 0x82E5, "": 0x834F, "": 0x836B, "": 0x8389,
"": 0x82AE, "": 0x82CA, "": 0x82E6, "": 0x8350, "": 0x836C, "": 0x838A,
"": 0x82AF, "": 0x82CB, "": 0x82E7, "": 0x8351, "": 0x836D, "": 0x838B,
"": 0x82B0, "": 0x82CC, "": 0x82E8, "": 0x8352, "": 0x836E, "": 0x838C,
"": 0x82B1, "": 0x82CD, "": 0x82E9, "": 0x8353, "": 0x836F, "": 0x838D,
"": 0x82B2, "": 0x82CE, "": 0x82EA, "": 0x8354, "": 0x8370, "": 0x838E,
"": 0x82B3, "": 0x82CF, "": 0x82EB, "": 0x8355, "": 0x8371, "": 0x838F,
"": 0x82B4, "": 0x82D0, "": 0x82EC, "": 0x8356, "": 0x8372, "": 0x8390,
"": 0x82B5, "": 0x82D1, "": 0x82ED, "": 0x8357, "": 0x8373, "": 0x8391,
"": 0x82B6, "": 0x82D2, "": 0x82EE, "": 0x8358, "": 0x8374, "": 0x8392,
"": 0x82B7, "": 0x82D3, "": 0x82EF, "": 0x8359, "": 0x8375, "": 0x8393,
"": 0x82B8, "": 0x82D4, "": 0x82F0, "": 0x835A, "": 0x8376, "": 0x8394,
"": 0x82B9, "": 0x82D5, "": 0x82F1, "": 0x835B, "": 0x8377, "": 0x8395,
"": 0x8378, "": 0x8396,
}
skipTimer = 0
def sjis_process(buf, outfile):
global skipTimer
for i, char in enumerate(buf):
if skipTimer > 0:
skipTimer -= 1
continue
if char == "'" and buf[i+1] in sjis_table:
if sjis_table[buf[i+1]] == 0:
print("Error: Please map %s in %s" % (buf[i+1], sys.argv[0]))
exit(1)
outfile.write("0x%X" % sjis_table[buf[i+1]])
skipTimer = 2
else:
outfile.write(char)