]> git.proxmox.com Git - grub2.git/blame - util/import_unicode.py
Initial integration of hints
[grub2.git] / util / import_unicode.py
CommitLineData
72f12cdc
VS
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
19import re
20import sys
72f12cdc
VS
21
22if len (sys.argv) < 3:
23 print ("Usage: %s SOURCE DESTINATION" % sys.argv[0])
24 exit (0)
03e4ef02
VS
25infile = open (sys.argv[3], "r")
26joining = {}
27for 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":
3f11c713 36 joining[curcode] = "NONJOINING"
03e4ef02 37 elif sp[2] == "L":
3f11c713 38 joining[curcode] = "LEFT"
03e4ef02 39 elif sp[2] == "R":
3f11c713 40 joining[curcode] = "RIGHT"
03e4ef02 41 elif sp[2] == "D":
3f11c713 42 joining[curcode] = "DUAL"
03e4ef02 43 elif sp[2] == "C":
3f11c713 44 joining[curcode] = "CAUSING"
03e4ef02
VS
45 else:
46 print ("Unknown joining type '%s'" % sp[2])
47 exit (1)
48infile.close ()
49
72f12cdc 50infile = open (sys.argv[1], "r")
03e4ef02 51outfile = open (sys.argv[4], "w")
72f12cdc
VS
52outfile.write ("#include <grub/unicode.h>\n")
53outfile.write ("\n")
54outfile.write ("struct grub_unicode_compact_range grub_unicode_compact[] = {\n")
55
56begincode = -2
57lastcode = -2
58lastbiditype = "X"
97ea65d4 59lastmirrortype = False
72f12cdc 60lastcombtype = -1
3f11c713 61arabicsubst = {}
72f12cdc
VS
62for line in infile:
63 sp = line.split (";")
64 curcode = int (sp[0], 16)
72f12cdc 65 curcombtype = int (sp[3], 10)
97ea65d4
VS
66 curbiditype = sp[4]
67 curmirrortype = (sp[9] == "Y")
72f12cdc
VS
68 if curcombtype <= 255 and curcombtype >= 253:
69 print ("UnicodeData.txt uses combination type %d. Conflict." \
70 % curcombtype)
71 raise
521bf301
VS
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])
72f12cdc
VS
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
521bf301
VS
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)
03e4ef02
VS
101 if curcode in joining:
102 curjoin = joining[curcode]
103 elif sp[2] == "Me" or sp[2] == "Mn" or sp[2] == "Cf":
3f11c713 104 curjoin = "TRANSPARENT"
03e4ef02 105 else:
3f11c713
VS
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
72f12cdc 127 if lastcode + 1 != curcode or curbiditype != lastbiditype \
03e4ef02
VS
128 or curcombtype != lastcombtype or curmirrortype != lastmirrortype \
129 or curjoin != lastjoin:
97ea65d4
VS
130 if begincode != -2 and (lastbiditype != "L" or lastcombtype != 0 or \
131 lastmirrortype):
3f11c713 132 outfile.write (("{0x%x, 0x%x, GRUB_BIDI_TYPE_%s, %d, %d, GRUB_JOIN_TYPE_%s},\n" \
72f12cdc 133 % (begincode, lastcode, lastbiditype, \
03e4ef02
VS
134 lastcombtype, lastmirrortype, \
135 lastjoin)))
72f12cdc
VS
136 begincode = curcode
137 lastcode = curcode
03e4ef02 138 lastjoin = curjoin
72f12cdc
VS
139 lastbiditype = curbiditype
140 lastcombtype = curcombtype
97ea65d4
VS
141 lastmirrortype = curmirrortype
142if lastbiditype != "L" or lastcombtype != 0 or lastmirrortype:
3f11c713 143 outfile.write (("{0x%x, 0x%x, GRUB_BIDI_TYPE_%s, %d, %d, GRUB_JOIN_TYPE_%s},\n" \
97ea65d4 144 % (begincode, lastcode, lastbiditype, lastcombtype, \
03e4ef02
VS
145 lastmirrortype, lastjoin)))
146outfile.write ("{0, 0, 0, 0, 0, 0},\n")
72f12cdc 147
6f5568ed
VS
148outfile.write ("};\n")
149
150infile.close ()
151
152infile = open (sys.argv[2], "r")
153
154outfile.write ("struct grub_unicode_bidi_pair grub_unicode_bidi_pairs[] = {\n")
155
156for 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))
166outfile.write ("{0, 0},\n")
167outfile.write ("};\n")
168
3f11c713
VS
169infile.close ()
170
171outfile.write ("struct grub_unicode_arabic_shape grub_unicode_arabic_shapes[] = {\n ")
172
173for 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
184outfile.write ("{0, 0, 0, 0, 0},\n")
185outfile.write ("};\n")
186
187
188outfile.close ()
189