tpm2_key_protector: Enable build for powerpc_ieee1275
[grub.git] / util / import_unicode.py
blob1f434a06974b7239a24d674de21800143ebbf2b4
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.
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/>.
19 import re
20 import sys
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 ()
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")
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 - begincode + 1, \
134 lastbiditype, \
135 lastcombtype, lastmirrortype, \
136 lastjoin)))
137 if lastcode - begincode + 1 >= 0x200:
138 print ("Too long range")
139 raise
140 begincode = curcode
141 lastcode = curcode
142 lastjoin = curjoin
143 lastbiditype = curbiditype
144 lastcombtype = curcombtype
145 lastmirrortype = curmirrortype
146 if lastbiditype != "L" or lastcombtype != 0 or lastmirrortype:
147 outfile.write (("{0x%x, 0x%x, GRUB_BIDI_TYPE_%s, %d, %d, GRUB_JOIN_TYPE_%s},\n" \
148 % (begincode, lastcode, lastbiditype, lastcombtype, \
149 lastmirrortype, lastjoin)))
150 outfile.write ("{0, 0, 0, 0, 0, 0},\n")
152 outfile.write ("};\n")
154 infile.close ()
156 infile = open (sys.argv[2], "r")
158 outfile.write ("struct grub_unicode_bidi_pair grub_unicode_bidi_pairs[] = {\n")
160 for line in infile:
161 line = re.sub ("#.*$", "", line)
162 line = line.replace ("\n", "")
163 line = line.replace (" ", "")
164 if len (line) == 0 or line[0] == '\n':
165 continue
166 sp = line.split (";")
167 code1 = int (sp[0], 16)
168 code2 = int (sp[1], 16)
169 outfile.write ("{0x%x, 0x%x},\n" % (code1, code2))
170 outfile.write ("{0, 0},\n")
171 outfile.write ("};\n")
173 infile.close ()
175 outfile.write ("struct grub_unicode_arabic_shape grub_unicode_arabic_shapes[] = {\n ")
177 for x in sorted(arabicsubst):
178 try:
179 if arabicsubst[x]['join'] == "DUAL":
180 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]))
181 elif arabicsubst[x]['join'] == "RIGHT":
182 outfile.write ("{0x%x, 0x%x, 0x%x, 0x%x, 0x%x},\n " % (arabicsubst[x][0], arabicsubst[x][1], arabicsubst[x][2], 0, 0))
183 elif arabicsubst[x]['join'] == "LEFT":
184 outfile.write ("{0x%x, 0x%x, 0x%x, 0x%x, 0x%x},\n " % (arabicsubst[x][0], arabicsubst[x][1], 0, 0, arabicsubst[x][4]))
185 except:
186 pass
188 outfile.write ("{0, 0, 0, 0, 0},\n")
189 outfile.write ("};\n")
192 outfile.close ()