import os
import sys
import urllib.request 

srcUri = "https://raw.githubusercontent.com/codebox/homoglyph/master/raw_data/char_codes.txt"
filename,headers = urllib.request.urlretrieve(srcUri, "char_codes.txt")
txt = open(filename, "r").read().split("\n")

outFile = "HomoglyphsTable.cpp"
out = open(outFile, "w")
out.write("// This file is generated by 'gen.py', do not edit.\n" \
		"#include \"lgi/common/Lgi.h\"\n" \
		"LArray<int> HomoglyphsTable[] = {\n")

for l in txt:
	if l[0] != '#':
		p = l.strip().split(",")
		s = ""
		for i in range(len(p)):
			if i == 0 or int(p[0],16) >= 256 or int(p[i],16) > 256:
				if len(s) > 0:
					s = s + ", "
				s = s + "0x" + p[i]

		out.write("\t{ " + s + " },\n")

out.write("\t{}\n};\n")
print("outFile:", outFile)