]> git.tdb.fi Git - libs/core.git/blob - jis.py
Drop copyright and license notices from source files
[libs/core.git] / jis.py
1 #!/usr/bin/python
2 # $Id$
3
4 import sys
5 import os
6
7 in_fn=sys.argv[1]
8 out_fn=os.path.splitext(in_fn)[0]+".table"
9
10 data=[]
11 for line in file(in_fn):
12         line=line.strip()
13         if line[0]=='#':
14                 continue
15         parts=line.split(None, 3)
16         code=eval(parts[1])-0x2020
17         code2=(code&0xFF)+((code>>8)&0xFF)*94-95
18         data.append((code, eval(parts[2]), code2))
19
20 out=file(out_fn, "w")
21 out.write("namespace {\n\n")
22
23 data.sort(lambda x,y: cmp(x[0],y[0]))
24 out.write("const unsigned short jisx0208_to_ucs_table[94*94] =\n{\n\t")
25 i=0
26 for code in xrange(94*94):
27         if code>0:
28                 out.write(", ")
29                 if (code%94%12)==0 or (code%94)==0:
30                         out.write("\n\t")
31         if i<len(data) and data[i][2]==code:
32                 out.write("0x%04X"%data[i][1])
33                 i+=1
34         else:
35                 out.write("0     ")
36 out.write("\n};\n\n")
37
38 data.sort(lambda x,y: cmp(x[1],y[1]))
39 out.write("struct UcsToJis\n{\n\tunsigned short ucs;\n\tunsigned short jis;\n};\nconst UcsToJis ucs_to_jisx0208_table[] =\n{\n\t")
40 for i in xrange(len(data)):
41         if i>0:
42                 out.write(", ")
43                 if (i%6)==0:
44                         out.write("\n\t")
45         out.write("{ 0x%04X, 0x%04X }"%(data[i][1], data[i][0]))
46 out.write("\n};\n\n")
47
48 out.write("unsigned ucs_to_jisx0208_table_size=%d;\n\n"%len(data))
49
50 out.write("}\n")