]> git.proxmox.com Git - grub2.git/blob - util/import_unicode.py
Put recheck back
[grub2.git] / util / import_unicode.py
1 #*
2 #* GRUB -- GRand Unified Bootloader
3 #* Copyright (C) 2010 Free Software Foundation, Inc.
4 #*
5 #* GRUB is free software: you can redistribute it and/or modify
6 #* it under the terms of the GNU General Public License as published by
7 #* the Free Software Foundation, either version 3 of the License, or
8 #* (at your option) any later version.
9 #*
10 #* GRUB is distributed in the hope that it will be useful,
11 #* but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 #* GNU General Public License for more details.
14 #*
15 #* You should have received a copy of the GNU General Public License
16 #* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
17 #*
18
19 import re
20 import sys
21
22 if len (sys.argv) < 3:
23 print ("Usage: %s SOURCE DESTINATION" % sys.argv[0])
24 exit (0)
25 infile = open (sys.argv[3], "r")
26 joining = {}
27 for line in infile:
28 line = re.sub ("#.*$", "", line)
29 line = line.replace ("\n", "")
30 line = line.replace (" ", "")
31 if len (line) == 0 or line[0] == '\n':
32 continue
33 sp = line.split (";")
34 curcode = int (sp[0], 16)
35 if sp[2] == "U":
36 joining[curcode] = "NONJOINING"
37 elif sp[2] == "L":
38 joining[curcode] = "LEFT"
39 elif sp[2] == "R":
40 joining[curcode] = "RIGHT"
41 elif sp[2] == "D":
42 joining[curcode] = "DUAL"
43 elif sp[2] == "C":
44 joining[curcode] = "CAUSING"
45 else:
46 print ("Unknown joining type '%s'" % sp[2])
47 exit (1)
48 infile.close ()
49
50 infile = open (sys.argv[1], "r")
51 outfile = open (sys.argv[4], "w")
52 outfile.write ("#include <grub/unicode.h>\n")
53 outfile.write ("\n")
54 outfile.write ("struct grub_unicode_compact_range grub_unicode_compact[] = {\n")
55
56 begincode = -2
57 lastcode = -2
58 lastbiditype = "X"
59 lastmirrortype = False
60 lastcombtype = -1
61 arabicsubst = {}
62 for line in infile:
63 sp = line.split (";")
64 curcode = int (sp[0], 16)
65 curcombtype = int (sp[3], 10)
66 curbiditype = sp[4]
67 curmirrortype = (sp[9] == "Y")
68 if curcombtype <= 255 and curcombtype >= 253:
69 print ("UnicodeData.txt uses combination type %d. Conflict." \
70 % curcombtype)
71 raise
72 if sp[2] != "Lu" and sp[2] != "Ll" and sp[2] != "Lt" and sp[2] != "Lm" \
73 and sp[2] != "Lo"\
74 and sp[2] != "Me" and sp[2] != "Mc" and sp[2] != "Mn" \
75 and sp[2] != "Nd" and sp[2] != "Nl" and sp[2] != "No" \
76 and sp[2] != "Pc" and sp[2] != "Pd" and sp[2] != "Ps" \
77 and sp[2] != "Pe" and sp[2] != "Pi" and sp[2] != "Pf" \
78 and sp[2] != "Po" \
79 and sp[2] != "Sm" and sp[2] != "Sc" and sp[2] != "Sk" \
80 and sp[2] != "So"\
81 and sp[2] != "Zs" and sp[2] != "Zl" and sp[2] != "Zp" \
82 and sp[2] != "Cc" and sp[2] != "Cf" and sp[2] != "Cs" \
83 and sp[2] != "Co":
84 print ("WARNING: Unknown type %s" % sp[2])
85 if curcombtype == 0 and sp[2] == "Me":
86 curcombtype = 253
87 if curcombtype == 0 and sp[2] == "Mc":
88 curcombtype = 254
89 if curcombtype == 0 and sp[2] == "Mn":
90 curcombtype = 255
91 if (curcombtype >= 2 and curcombtype <= 6) \
92 or (curcombtype >= 37 and curcombtype != 84 and curcombtype != 91 and curcombtype != 103 and curcombtype != 107 and curcombtype != 118 and curcombtype != 122 and curcombtype != 129 and curcombtype != 130 and curcombtype != 132 and curcombtype != 202 and \
93 curcombtype != 214 and curcombtype != 216 and \
94 curcombtype != 218 and curcombtype != 220 and \
95 curcombtype != 222 and curcombtype != 224 and curcombtype != 226 and curcombtype != 228 and \
96 curcombtype != 230 and curcombtype != 232 and curcombtype != 233 and \
97 curcombtype != 234 and \
98 curcombtype != 240 and curcombtype != 253 and \
99 curcombtype != 254 and curcombtype != 255):
100 print ("WARNING: Unknown combining type %d" % curcombtype)
101 if curcode in joining:
102 curjoin = joining[curcode]
103 elif sp[2] == "Me" or sp[2] == "Mn" or sp[2] == "Cf":
104 curjoin = "TRANSPARENT"
105 else:
106 curjoin = "NONJOINING"
107 if sp[1].startswith ("ARABIC LETTER "):
108 arabname = sp[1][len ("ARABIC LETTER "):]
109 form = 0
110 if arabname.endswith (" ISOLATED FORM"):
111 arabname = arabname[0:len (arabname) - len (" ISOLATED FORM")]
112 form = 1
113 if arabname.endswith (" FINAL FORM"):
114 arabname = arabname[0:len (arabname) - len (" FINAL FORM")]
115 form = 2
116 if arabname.endswith (" MEDIAL FORM"):
117 arabname = arabname[0:len (arabname) - len (" MEDIAL FORM")]
118 form = 3
119 if arabname.endswith (" INITIAL FORM"):
120 arabname = arabname[0:len (arabname) - len (" INITIAL FORM")]
121 form = 4
122 if arabname not in arabicsubst:
123 arabicsubst[arabname]={}
124 arabicsubst[arabname][form] = curcode;
125 if form == 0:
126 arabicsubst[arabname]['join'] = curjoin
127 if lastcode + 1 != curcode or curbiditype != lastbiditype \
128 or curcombtype != lastcombtype or curmirrortype != lastmirrortype \
129 or curjoin != lastjoin:
130 if begincode != -2 and (lastbiditype != "L" or lastcombtype != 0 or \
131 lastmirrortype):
132 outfile.write (("{0x%x, 0x%x, GRUB_BIDI_TYPE_%s, %d, %d, GRUB_JOIN_TYPE_%s},\n" \
133 % (begincode, lastcode, lastbiditype, \
134 lastcombtype, lastmirrortype, \
135 lastjoin)))
136 begincode = curcode
137 lastcode = curcode
138 lastjoin = curjoin
139 lastbiditype = curbiditype
140 lastcombtype = curcombtype
141 lastmirrortype = curmirrortype
142 if lastbiditype != "L" or lastcombtype != 0 or lastmirrortype:
143 outfile.write (("{0x%x, 0x%x, GRUB_BIDI_TYPE_%s, %d, %d, GRUB_JOIN_TYPE_%s},\n" \
144 % (begincode, lastcode, lastbiditype, lastcombtype, \
145 lastmirrortype, lastjoin)))
146 outfile.write ("{0, 0, 0, 0, 0, 0},\n")
147
148 outfile.write ("};\n")
149
150 infile.close ()
151
152 infile = open (sys.argv[2], "r")
153
154 outfile.write ("struct grub_unicode_bidi_pair grub_unicode_bidi_pairs[] = {\n")
155
156 for line in infile:
157 line = re.sub ("#.*$", "", line)
158 line = line.replace ("\n", "")
159 line = line.replace (" ", "")
160 if len (line) == 0 or line[0] == '\n':
161 continue
162 sp = line.split (";")
163 code1 = int (sp[0], 16)
164 code2 = int (sp[1], 16)
165 outfile.write ("{0x%x, 0x%x},\n" % (code1, code2))
166 outfile.write ("{0, 0},\n")
167 outfile.write ("};\n")
168
169 infile.close ()
170
171 outfile.write ("struct grub_unicode_arabic_shape grub_unicode_arabic_shapes[] = {\n ")
172
173 for x in arabicsubst:
174 try:
175 if arabicsubst[x]['join'] == "DUAL":
176 outfile.write ("{0x%x, 0x%x, 0x%x, 0x%x, 0x%x},\n " % (arabicsubst[x][0], arabicsubst[x][1], arabicsubst[x][2], arabicsubst[x][3], arabicsubst[x][4]))
177 elif arabicsubst[x]['join'] == "RIGHT":
178 outfile.write ("{0x%x, 0x%x, 0x%x, 0x%x, 0x%x},\n " % (arabicsubst[x][0], arabicsubst[x][1], arabicsubst[x][2], 0, 0))
179 elif arabicsubst[x]['join'] == "LEFT":
180 outfile.write ("{0x%x, 0x%x, 0x%x, 0x%x, 0x%x},\n " % (arabicsubst[x][0], arabicsubst[x][1], 0, 0, arabicsubst[x][4]))
181 except:
182 pass
183
184 outfile.write ("{0, 0, 0, 0, 0},\n")
185 outfile.write ("};\n")
186
187
188 outfile.close ()
189