summaryrefslogtreecommitdiff
path: root/tools/charmap.py
blob: d318a61c44bf17136e0aa91bd10f8975be096dca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3

from sys import argv

def parse_charmap(file):
    charmap = {}
    constants = {}
    for line in open(file):
        split = line.split("#")[0].split("=")
        if len(split) != 2:
            continue

        char = "=".join(split[0:-1]).strip()
        value = int(split[-1].strip(), 0) & 0xFFFF

        if char.startswith("'") and char.endswith("'"):
            charmap[char[1:-1]] = value
        else:
            constants[char] = value
    return charmap, constants

if __name__ == "__main__":
    charmap, constants = parse_charmap(argv[1])

    for char in charmap:
        value = charmap[char]
        print("charmap \"%s\", %d" % (char, value))

    for constant in constants:
        value = constants[constant]
        print("%s EQU %d" % (constant, value))