2N/A#*
2N/A#* GRUB -- GRand Unified Bootloader
2N/A#* Copyright (C) 2010 Free Software Foundation, Inc.
2N/A#*
2N/A#* GRUB is free software: you can redistribute it and/or modify
2N/A#* it under the terms of the GNU General Public License as published by
2N/A#* the Free Software Foundation, either version 3 of the License, or
2N/A#* (at your option) any later version.
2N/A#*
2N/A#* GRUB is distributed in the hope that it will be useful,
2N/A#* but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A#* GNU General Public License for more details.
2N/A#*
2N/A#* You should have received a copy of the GNU General Public License
2N/A#* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A#*
2N/A
2N/Aimport re
2N/Aimport sys
2N/A
2N/Aif len (sys.argv) < 3:
2N/A print ("Usage: %s SOURCE DESTINATION" % sys.argv[0])
2N/A exit (0)
2N/Ainfile = open (sys.argv[3], "r")
2N/Ajoining = {}
2N/Afor line in infile:
2N/A line = re.sub ("#.*$", "", line)
2N/A line = line.replace ("\n", "")
2N/A line = line.replace (" ", "")
2N/A if len (line) == 0 or line[0] == '\n':
2N/A continue
2N/A sp = line.split (";")
2N/A curcode = int (sp[0], 16)
2N/A if sp[2] == "U":
2N/A joining[curcode] = "NONJOINING"
2N/A elif sp[2] == "L":
2N/A joining[curcode] = "LEFT"
2N/A elif sp[2] == "R":
2N/A joining[curcode] = "RIGHT"
2N/A elif sp[2] == "D":
2N/A joining[curcode] = "DUAL"
2N/A elif sp[2] == "C":
2N/A joining[curcode] = "CAUSING"
2N/A else:
2N/A print ("Unknown joining type '%s'" % sp[2])
2N/A exit (1)
2N/Ainfile.close ()
2N/A
2N/Ainfile = open (sys.argv[1], "r")
2N/Aoutfile = open (sys.argv[4], "w")
2N/Aoutfile.write ("#include <grub/unicode.h>\n")
2N/Aoutfile.write ("\n")
2N/Aoutfile.write ("struct grub_unicode_compact_range grub_unicode_compact[] = {\n")
2N/A
2N/Abegincode = -2
2N/Alastcode = -2
2N/Alastbiditype = "X"
2N/Alastmirrortype = False
2N/Alastcombtype = -1
2N/Aarabicsubst = {}
2N/Afor line in infile:
2N/A sp = line.split (";")
2N/A curcode = int (sp[0], 16)
2N/A curcombtype = int (sp[3], 10)
2N/A curbiditype = sp[4]
2N/A curmirrortype = (sp[9] == "Y")
2N/A if curcombtype <= 255 and curcombtype >= 253:
2N/A print ("UnicodeData.txt uses combination type %d. Conflict." \
2N/A % curcombtype)
2N/A raise
2N/A if sp[2] != "Lu" and sp[2] != "Ll" and sp[2] != "Lt" and sp[2] != "Lm" \
2N/A and sp[2] != "Lo"\
2N/A and sp[2] != "Me" and sp[2] != "Mc" and sp[2] != "Mn" \
2N/A and sp[2] != "Nd" and sp[2] != "Nl" and sp[2] != "No" \
2N/A and sp[2] != "Pc" and sp[2] != "Pd" and sp[2] != "Ps" \
2N/A and sp[2] != "Pe" and sp[2] != "Pi" and sp[2] != "Pf" \
2N/A and sp[2] != "Po" \
2N/A and sp[2] != "Sm" and sp[2] != "Sc" and sp[2] != "Sk" \
2N/A and sp[2] != "So"\
2N/A and sp[2] != "Zs" and sp[2] != "Zl" and sp[2] != "Zp" \
2N/A and sp[2] != "Cc" and sp[2] != "Cf" and sp[2] != "Cs" \
2N/A and sp[2] != "Co":
2N/A print ("WARNING: Unknown type %s" % sp[2])
2N/A if curcombtype == 0 and sp[2] == "Me":
2N/A curcombtype = 253
2N/A if curcombtype == 0 and sp[2] == "Mc":
2N/A curcombtype = 254
2N/A if curcombtype == 0 and sp[2] == "Mn":
2N/A curcombtype = 255
2N/A if (curcombtype >= 2 and curcombtype <= 6) \
2N/A 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 \
2N/A curcombtype != 214 and curcombtype != 216 and \
2N/A curcombtype != 218 and curcombtype != 220 and \
2N/A curcombtype != 222 and curcombtype != 224 and curcombtype != 226 and curcombtype != 228 and \
2N/A curcombtype != 230 and curcombtype != 232 and curcombtype != 233 and \
2N/A curcombtype != 234 and \
2N/A curcombtype != 240 and curcombtype != 253 and \
2N/A curcombtype != 254 and curcombtype != 255):
2N/A print ("WARNING: Unknown combining type %d" % curcombtype)
2N/A if curcode in joining:
2N/A curjoin = joining[curcode]
2N/A elif sp[2] == "Me" or sp[2] == "Mn" or sp[2] == "Cf":
2N/A curjoin = "TRANSPARENT"
2N/A else:
2N/A curjoin = "NONJOINING"
2N/A if sp[1].startswith ("ARABIC LETTER "):
2N/A arabname = sp[1][len ("ARABIC LETTER "):]
2N/A form = 0
2N/A if arabname.endswith (" ISOLATED FORM"):
2N/A arabname = arabname[0:len (arabname) - len (" ISOLATED FORM")]
2N/A form = 1
2N/A if arabname.endswith (" FINAL FORM"):
2N/A arabname = arabname[0:len (arabname) - len (" FINAL FORM")]
2N/A form = 2
2N/A if arabname.endswith (" MEDIAL FORM"):
2N/A arabname = arabname[0:len (arabname) - len (" MEDIAL FORM")]
2N/A form = 3
2N/A if arabname.endswith (" INITIAL FORM"):
2N/A arabname = arabname[0:len (arabname) - len (" INITIAL FORM")]
2N/A form = 4
2N/A if arabname not in arabicsubst:
2N/A arabicsubst[arabname]={}
2N/A arabicsubst[arabname][form] = curcode;
2N/A if form == 0:
2N/A arabicsubst[arabname]['join'] = curjoin
2N/A if lastcode + 1 != curcode or curbiditype != lastbiditype \
2N/A or curcombtype != lastcombtype or curmirrortype != lastmirrortype \
2N/A or curjoin != lastjoin:
2N/A if begincode != -2 and (lastbiditype != "L" or lastcombtype != 0 or \
2N/A lastmirrortype):
2N/A outfile.write (("{0x%x, 0x%x, GRUB_BIDI_TYPE_%s, %d, %d, GRUB_JOIN_TYPE_%s},\n" \
2N/A % (begincode, lastcode - begincode + 1, \
2N/A lastbiditype, \
2N/A lastcombtype, lastmirrortype, \
2N/A lastjoin)))
2N/A if lastcode - begincode + 1 >= 0x200:
2N/A print "Too long range"
2N/A raise
2N/A begincode = curcode
2N/A lastcode = curcode
2N/A lastjoin = curjoin
2N/A lastbiditype = curbiditype
2N/A lastcombtype = curcombtype
2N/A lastmirrortype = curmirrortype
2N/Aif lastbiditype != "L" or lastcombtype != 0 or lastmirrortype:
2N/A outfile.write (("{0x%x, 0x%x, GRUB_BIDI_TYPE_%s, %d, %d, GRUB_JOIN_TYPE_%s},\n" \
2N/A % (begincode, lastcode, lastbiditype, lastcombtype, \
2N/A lastmirrortype, lastjoin)))
2N/Aoutfile.write ("{0, 0, 0, 0, 0, 0},\n")
2N/A
2N/Aoutfile.write ("};\n")
2N/A
2N/Ainfile.close ()
2N/A
2N/Ainfile = open (sys.argv[2], "r")
2N/A
2N/Aoutfile.write ("struct grub_unicode_bidi_pair grub_unicode_bidi_pairs[] = {\n")
2N/A
2N/Afor line in infile:
2N/A line = re.sub ("#.*$", "", line)
2N/A line = line.replace ("\n", "")
2N/A line = line.replace (" ", "")
2N/A if len (line) == 0 or line[0] == '\n':
2N/A continue
2N/A sp = line.split (";")
2N/A code1 = int (sp[0], 16)
2N/A code2 = int (sp[1], 16)
2N/A outfile.write ("{0x%x, 0x%x},\n" % (code1, code2))
2N/Aoutfile.write ("{0, 0},\n")
2N/Aoutfile.write ("};\n")
2N/A
2N/Ainfile.close ()
2N/A
2N/Aoutfile.write ("struct grub_unicode_arabic_shape grub_unicode_arabic_shapes[] = {\n ")
2N/A
2N/Afor x in arabicsubst:
2N/A try:
2N/A if arabicsubst[x]['join'] == "DUAL":
2N/A 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]))
2N/A elif arabicsubst[x]['join'] == "RIGHT":
2N/A outfile.write ("{0x%x, 0x%x, 0x%x, 0x%x, 0x%x},\n " % (arabicsubst[x][0], arabicsubst[x][1], arabicsubst[x][2], 0, 0))
2N/A elif arabicsubst[x]['join'] == "LEFT":
2N/A outfile.write ("{0x%x, 0x%x, 0x%x, 0x%x, 0x%x},\n " % (arabicsubst[x][0], arabicsubst[x][1], 0, 0, arabicsubst[x][4]))
2N/A except:
2N/A pass
2N/A
2N/Aoutfile.write ("{0, 0, 0, 0, 0},\n")
2N/Aoutfile.write ("};\n")
2N/A
2N/A
2N/Aoutfile.close ()
2N/A