summaryrefslogtreecommitdiff
path: root/src/genwidths.py
blob: 0c02a187a3f1b45fd4ba8245dd3b1119d554eac9 (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
32
33
34
35
#!/usr/bin/python
import os, re, string

try:
	unidata = open("EastAsianWidth.txt", "r")
except:
	os.system("wget --passive-ftp -c ftp://ftp.unicode.org/Public/UNIDATA/EastAsianWidth.txt")
	unidata = open("EastAsianWidth.txt", "r")
out = open("uniwidths", "w")
ranges = []
specifics = []
rangere = re.compile("^([0123456789ABCDEF]+)\.\.([0123456789ABCDEF]+);A")
specificre = re.compile("^([0123456789ABCDEF]+);A")
for line in unidata.readlines():
	match = re.match(specificre, line)
	if match:
		if match.groups().__len__() > 0:
			specifics.append(match.groups()[0])
	match = re.match(rangere, line)
	if match:
		if match.groups().__len__() > 1:
			ranges.append((match.groups()[0], match.groups()[1]))

print >> out, "static const struct {"
print >> out, "\tgunichar start, end;"
print >> out, "} _vte_iso2022_ambiguous_ranges[] = {"
for range in ranges:
	print >> out, "\t{0x%x, 0x%x}," % (string.atol(range[0], 16), string.atol(range[1], 16))
print >> out, "};"

print >> out, "static const gunichar _vte_iso2022_ambiguous_chars[] = {"
for specific in specifics:
	print >> out, "\t0x%x," % (string.atol(specific, 16))
print >> out, "};"