blob: 08e54db75496722ad207d917d048035580e393e4 [file] [log] [blame]
Behdad Esfahbod3eb936f2010-10-05 18:36:58 -04001#!/usr/bin/python
2
3import sys
4
Behdad Esfahbod88e7f372010-12-21 14:18:24 -05005header = sys.stdin.readline (), sys.stdin.readline ()
6while sys.stdin.readline ().find ('##################') < 0:
7 pass
Behdad Esfahbod3eb936f2010-10-05 18:36:58 -04008
Behdad Esfahbod14d78412010-11-17 16:52:58 -05009
10print "/* == Start of generated table == */"
11print "/*"
12print " * The following table is generated by running:"
13print " *"
14print " * ./gen-arabic-joining-table.py < ArabicShaping.txt"
15print " *"
16print " * on the ArabicShaping.txt file with the header:"
17print " *"
Behdad Esfahbod3eb936f2010-10-05 18:36:58 -040018for line in header:
Behdad Esfahbod14d78412010-11-17 16:52:58 -050019 print " * %s" % (line.strip())
20print " */"
21
Behdad Esfahbod88e7f372010-12-21 14:18:24 -050022print "static const uint8_t joining_table[] ="
Behdad Esfahbod14d78412010-11-17 16:52:58 -050023print "{"
24
Behdad Esfahbod88e7f372010-12-21 14:18:24 -050025
26min_u = 0x110000
27max_u = 0
28num = 0
29last = -1
30block = ''
31for line in sys.stdin:
32
33 if line[0] == '#':
34 if line.find (" characters"):
35 block = line[2:].strip ()
36 continue
37
38 fields = [x.strip () for x in line.split (';')]
39 if len (fields) == 1:
40 continue
41
42 u = int (fields[0], 16)
43 if u == 0x200C or u == 0x200D:
44 continue
45 if u < last:
46 raise Exception ("Input data character not sorted", u)
47 min_u = min (min_u, u)
48 max_u = max (max_u, u)
49 num += 1
50
51 if block:
52 print "\n /* %s */\n" % block
53 block = ''
54
55 if last != -1:
56 last += 1
57 while last < u:
58 print " JOINING_TYPE_X, /* %04X */" % last
59 last += 1
Behdad Esfahbod3eb936f2010-10-05 18:36:58 -040060 else:
Behdad Esfahbod88e7f372010-12-21 14:18:24 -050061 last = u
62
63 if fields[3] in ["ALAPH", "DALATH RISH"]:
64 value = "JOINING_GROUP_" + fields[3].replace(' ', '_')
65 else:
66 value = "JOINING_TYPE_" + fields[2]
67 print " %s, /* %s */" % (value, '; '.join(fields))
68
69print
Behdad Esfahbod14d78412010-11-17 16:52:58 -050070print " JOINING_TYPE_X /* dummy */"
71print "};"
Behdad Esfahbod88e7f372010-12-21 14:18:24 -050072print
73
74print "#define JOINING_TABLE_FIRST 0x%04x" % min_u
75print "#define JOINING_TABLE_LAST 0x%04x" % max_u
76print
77
Behdad Esfahbod14d78412010-11-17 16:52:58 -050078print "/* == End of generated table == */"
Behdad Esfahbod88e7f372010-12-21 14:18:24 -050079
80occupancy = num * 100 / (max_u - min_u + 1)
81# Maintain at least 40% occupancy in the table */
82if occupancy < 40:
83 raise Exception ("Table too sparse, please investigate: ", occupancy)