2 #* GRUB -- GRand Unified Bootloader
3 #* Copyright (C) 2010 Free Software Foundation, Inc.
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.
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/>.
22 if len (sys
.argv
) < 3:
23 print ("Usage: %s SOURCE DESTINATION" % sys
.argv
[0])
25 infile
= open (sys
.argv
[3], "r")
28 line
= re
.sub ("#.*$", "", line
)
29 line
= line
.replace ("\n", "")
30 line
= line
.replace (" ", "")
31 if len (line
) == 0 or line
[0] == '\n':
34 curcode
= int (sp
[0], 16)
36 joining
[curcode
] = "NONJOINING"
38 joining
[curcode
] = "LEFT"
40 joining
[curcode
] = "RIGHT"
42 joining
[curcode
] = "DUAL"
44 joining
[curcode
] = "CAUSING"
46 print ("Unknown joining type '%s'" % sp
[2])
50 infile
= open (sys
.argv
[1], "r")
51 outfile
= open (sys
.argv
[4], "w")
52 outfile
.write ("#include <grub/unicode.h>\n")
54 outfile
.write ("struct grub_unicode_compact_range grub_unicode_compact[] = {\n")
59 lastmirrortype
= False
64 curcode
= int (sp
[0], 16)
65 curcombtype
= int (sp
[3], 10)
67 curmirrortype
= (sp
[9] == "Y")
68 if curcombtype
<= 255 and curcombtype
>= 253:
69 print ("UnicodeData.txt uses combination type %d. Conflict." \
72 if sp
[2] != "Lu" and sp
[2] != "Ll" and sp
[2] != "Lt" and sp
[2] != "Lm" \
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" \
79 and sp
[2] != "Sm" and sp
[2] != "Sc" and sp
[2] != "Sk" \
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" \
84 print ("WARNING: Unknown type %s" % sp
[2])
85 if curcombtype
== 0 and sp
[2] == "Me":
87 if curcombtype
== 0 and sp
[2] == "Mc":
89 if curcombtype
== 0 and sp
[2] == "Mn":
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"
106 curjoin
= "NONJOINING"
107 if sp
[1].startswith ("ARABIC LETTER "):
108 arabname
= sp
[1][len ("ARABIC LETTER "):]
110 if arabname
.endswith (" ISOLATED FORM"):
111 arabname
= arabname
[0:len (arabname
) - len (" ISOLATED FORM")]
113 if arabname
.endswith (" FINAL FORM"):
114 arabname
= arabname
[0:len (arabname
) - len (" FINAL FORM")]
116 if arabname
.endswith (" MEDIAL FORM"):
117 arabname
= arabname
[0:len (arabname
) - len (" MEDIAL FORM")]
119 if arabname
.endswith (" INITIAL FORM"):
120 arabname
= arabname
[0:len (arabname
) - len (" INITIAL FORM")]
122 if arabname
not in arabicsubst
:
123 arabicsubst
[arabname
]={}
124 arabicsubst
[arabname
][form
] = curcode
;
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 \
132 outfile
.write (("{0x%x, 0x%x, GRUB_BIDI_TYPE_%s, %d, %d, GRUB_JOIN_TYPE_%s},\n" \
133 % (begincode
, lastcode
- begincode
+ 1, \
135 lastcombtype
, lastmirrortype
, \
137 if lastcode
- begincode
+ 1 >= 0x200:
138 print ("Too long range")
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")
156 infile
= open (sys
.argv
[2], "r")
158 outfile
.write ("struct grub_unicode_bidi_pair grub_unicode_bidi_pairs[] = {\n")
161 line
= re
.sub ("#.*$", "", line
)
162 line
= line
.replace ("\n", "")
163 line
= line
.replace (" ", "")
164 if len (line
) == 0 or line
[0] == '\n':
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")
175 outfile
.write ("struct grub_unicode_arabic_shape grub_unicode_arabic_shapes[] = {\n ")
177 for x
in sorted(arabicsubst
):
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]))
188 outfile
.write ("{0, 0, 0, 0, 0},\n")
189 outfile
.write ("};\n")