#!/usr/bin/python

from sys import argv
import numpy

jed  = open(argv[1]).read()
cmds = [c for c in jed.replace('\r\n', '').split('*') if c[0] in ('L','G', 'Q')]
deft = bool(int([c for c in cmds if c[0] == 'G'][0][1]))
size = int([c for c in cmds if c[:2] == 'QF'][0][2:])
mtrx = numpy.ones(size, dtype=bool) * deft
for cmd in [c for c in cmds if c[0] == 'L']:
	ofst, bstr = cmd[1:].split(' ')
	mtrx[int(ofst):int(ofst)+len(bstr)] = [bool(int(b)) for b in list(bstr)]

main = mtrx[:5808].reshape((132, 44)).T
olmc = numpy.fliplr(mtrx[5808:5828].reshape(10, 2)).reshape((20,))

head = open(argv[1] + ".hpp", "w")
head.write("const uint8_t atf_main[44][132] = { " + ",\n".join(
	["{ " + ", ".join(['1' if b else '0' for b in r]) + " }" for r in main]
) + " };\n")
head.write("const uint8_t atf_olmc[20] = { " + ", ".join(['1' if b else '0' for b in olmc]) + " };\n")
head.close()
