Bump libdcp for fix to spacey XSD filenames.
[libsub.git] / src / iso6937.py
1 import urllib2
2 import sys
3
4 DATA = 'http://www.unicode.org/Public/6.0.0/ucd/UnicodeData.txt'
5 OUTPUT = 'src/iso6937_tables'
6
7 data = urllib2.urlopen(DATA).read()
8 # data = open('UnicodeData.txt').read()
9 output_c = open(OUTPUT + '.cc', 'w')
10 output_h = open(OUTPUT + '.h', 'w')
11
12 def find_unicode(n):
13     for line in iter(data.splitlines()):
14         s = line.split(';')
15         if s[1] == n:
16             return s[0]
17
18     print 'Could not find %s' % n
19     sys.exit(1)
20
21 def setup(output_diacritical_name):
22     print>>output_c,'map<char, wchar_t> sub::iso6937::%s;' % output_diacritical_name
23
24 def fill(unicode_diacritical_name, output_diacritical_name, letters):
25
26     print>>output_h,'extern std::map<char, wchar_t> %s;' % output_diacritical_name
27
28     for letter in letters:
29         if letter.isupper():
30             case = 'CAPITAL'
31         else:
32             case = 'SMALL'
33
34         unicode_name = 'LATIN %s LETTER %s WITH %s' % (case, letter.upper(), unicode_diacritical_name)
35         print>>output_c,"\t%s['%s'] = 0x%s;" % (output_diacritical_name, letter, find_unicode(unicode_name))
36
37     print>>output_c,""
38
39 print>>output_c,"""/*
40     Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
41
42     This program is free software; you can redistribute it and/or modify
43     it under the terms of the GNU General Public License as published by
44     the Free Software Foundation; either version 2 of the License, or
45     (at your option) any later version.
46
47     This program is distributed in the hope that it will be useful,
48     but WITHOUT ANY WARRANTY; without even the implied warranty of
49     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
50     GNU General Public License for more details.
51
52     You should have received a copy of the GNU General Public License
53     along with this program; if not, write to the Free Software
54     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
55
56 */
57
58 /* THIS FILE WAS AUTO-GENERATED BY iso6937.py */
59
60 #include <map>
61 #include "iso6937_tables.h"
62
63 using std::map;
64 """
65
66 print>>output_h,"""/*
67     Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
68
69     This program is free software; you can redistribute it and/or modify
70     it under the terms of the GNU General Public License as published by
71     the Free Software Foundation; either version 2 of the License, or
72     (at your option) any later version.
73
74     This program is distributed in the hope that it will be useful,
75     but WITHOUT ANY WARRANTY; without even the implied warranty of
76     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
77     GNU General Public License for more details.
78
79     You should have received a copy of the GNU General Public License
80     along with this program; if not, write to the Free Software
81     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
82
83 */
84
85 /* THIS FILE WAS AUTO-GENERATED BY iso6937.py */
86
87 #include <map>
88
89 namespace sub {
90
91 extern void make_iso6937_tables ();
92
93 namespace iso6937 {
94 """
95
96 groups = [
97     (0xC1, 'GRAVE', 'grave', 'AEIOUaeiou'),
98     (0xC2, 'ACUTE', 'acute', 'ACEILNORSUYZacegilnorsuyz'),
99     (0xC3, 'CIRCUMFLEX', 'circumflex', 'ACEGHIJOSUWYaceghijosuwy'),
100     (0xC4, 'TILDE', 'tilde', 'AINOUainou'),
101     (0xC5, 'MACRON', 'macron', 'AEIOUaeiou'),
102     (0xC6, 'BREVE', 'breve', 'AGUagu'),
103     (0xC7, 'DOT ABOVE', 'dot', 'CEGIZcegz'),
104     (0xC8, 'DIAERESIS', 'diaeresis', 'AEIOUYaeiouy'),
105     (0xCA, 'RING ABOVE', 'ring', 'AUau'),
106     (0xCB, 'CEDILLA', 'cedilla', 'CGKLNRSTcklnrst'),
107     (0xCD, 'DOUBLE ACUTE', 'double_acute', 'OUou'),
108     (0xCE, 'OGONEK', 'ogonek', 'AEIUaeui'),
109     (0xCF, 'CARON', 'caron', 'CDELNRSTZcdelnrstz')
110 ]
111
112 for g in groups:
113     setup(g[2])
114
115 print>>output_c,"map<char, wchar_t> sub::iso6937::main;"
116 print>>output_c,"map<char, map<char, wchar_t> *> sub::iso6937::diacriticals;"
117 print>>output_h,"extern std::map<char, wchar_t> main;"
118 print>>output_h,"extern std::map<char, std::map<char, wchar_t> *> diacriticals;"
119
120 print>>output_c,"""
121 void
122 sub::make_iso6937_tables ()
123 {
124 \tusing namespace sub::iso6937;
125 """
126
127 for g in groups:
128     fill(g[1], g[2], g[3])
129
130 print>>output_c,"\tmain[10] = 0x000A;"
131
132 for i in range(32, 127):
133     if chr(i) == "'" or chr(i) == "\\":
134         print>>output_c,"\tmain['\\%s'] = 0x00%x;" % (chr(i), i)
135     else:
136         print>>output_c,"\tmain['%s'] = 0x00%x;" % (chr(i), i)
137
138 # From Wikipedia
139 # http://en.wikipedia.org/wiki/ISO/IEC_6937
140 print>>output_c,"\tmain[161] = 0x00A1;"
141 print>>output_c,"\tmain[162] = 0x00A2;"
142 print>>output_c,"\tmain[163] = 0x00A3;"
143 # Wikipedia says the dollar is 0x24, but Annotation
144 # Edit (and some other sources) disagree.
145 print>>output_c,"\tmain[164] = 0x0024;"
146 print>>output_c,"\tmain[165] = 0x00A5;"
147 print>>output_c,"\tmain[167] = 0x00A7;"
148 print>>output_c,"\tmain[168] = 0x00A4;"
149 print>>output_c,"\tmain[169] = 0x2018;"
150 print>>output_c,"\tmain[170] = 0x201C;"
151 print>>output_c,"\tmain[171] = 0x00AB;"
152 print>>output_c,"\tmain[172] = 0x2190;"
153 print>>output_c,"\tmain[173] = 0x2191;"
154 print>>output_c,"\tmain[174] = 0x2192;"
155 print>>output_c,"\tmain[175] = 0x2193;"
156 print>>output_c,"\tmain[176] = 0x00B0;"
157 print>>output_c,"\tmain[177] = 0x00B1;"
158 print>>output_c,"\tmain[178] = 0x00B2;"
159 print>>output_c,"\tmain[179] = 0x00B3;"
160 print>>output_c,"\tmain[180] = 0x00D7;"
161 print>>output_c,"\tmain[181] = 0x00B5;"
162 print>>output_c,"\tmain[182] = 0x00B6;"
163 print>>output_c,"\tmain[183] = 0x00B7;"
164 print>>output_c,"\tmain[184] = 0x00F7;"
165 print>>output_c,"\tmain[185] = 0x2019;"
166 print>>output_c,"\tmain[186] = 0x201D;"
167 print>>output_c,"\tmain[187] = 0x00BB;"
168 print>>output_c,"\tmain[188] = 0x00BC;"
169 print>>output_c,"\tmain[189] = 0x00BD;"
170 print>>output_c,"\tmain[190] = 0x00BE;"
171 print>>output_c,"\tmain[191] = 0x00BF;"
172 print>>output_c,"\tmain[193] = 0x0300;"
173 print>>output_c,"\tmain[194] = 0x0301;"
174 print>>output_c,"\tmain[195] = 0x0302;"
175 print>>output_c,"\tmain[196] = 0x0303;"
176 print>>output_c,"\tmain[197] = 0x0304;"
177 print>>output_c,"\tmain[198] = 0x0306;"
178 print>>output_c,"\tmain[199] = 0x0307;"
179 print>>output_c,"\tmain[200] = 0x0308;"
180 print>>output_c,"\tmain[202] = 0x030A;"
181 print>>output_c,"\tmain[203] = 0x0327;"
182 print>>output_c,"\tmain[205] = 0x030B;"
183 print>>output_c,"\tmain[206] = 0x032B;"
184 print>>output_c,"\tmain[207] = 0x030C;"
185 print>>output_c,"\tmain[208] = 0x2015;"
186 print>>output_c,"\tmain[209] = 0x00B9;"
187 print>>output_c,"\tmain[210] = 0x00AE;"
188 print>>output_c,"\tmain[211] = 0x00A9;"
189 print>>output_c,"\tmain[212] = 0x2122;"
190 print>>output_c,"\tmain[213] = 0x266A;"
191 print>>output_c,"\tmain[214] = 0x00AC;"
192 print>>output_c,"\tmain[215] = 0x00A6;"
193 print>>output_c,"\tmain[220] = 0x215B;"
194 print>>output_c,"\tmain[221] = 0x215C;"
195 print>>output_c,"\tmain[222] = 0x215D;"
196 print>>output_c,"\tmain[223] = 0x215E;"
197 print>>output_c,"\tmain[224] = 0x2126;"
198 print>>output_c,"\tmain[225] = 0x00C6;"
199 print>>output_c,"\tmain[226] = 0x0110;"
200 print>>output_c,"\tmain[227] = 0x00AA;"
201 print>>output_c,"\tmain[228] = 0x0126;"
202 print>>output_c,"\tmain[230] = 0x0132;"
203 print>>output_c,"\tmain[231] = 0x013F;"
204 print>>output_c,"\tmain[232] = 0x0141;"
205 print>>output_c,"\tmain[233] = 0x00D8;"
206 print>>output_c,"\tmain[234] = 0x0152;"
207 print>>output_c,"\tmain[235] = 0x00BA;"
208 print>>output_c,"\tmain[236] = 0x00DE;"
209 print>>output_c,"\tmain[237] = 0x0166;"
210 print>>output_c,"\tmain[238] = 0x014A;"
211 print>>output_c,"\tmain[239] = 0x0149;"
212 print>>output_c,"\tmain[240] = 0x0138;"
213 print>>output_c,"\tmain[241] = 0x00E6;"
214 print>>output_c,"\tmain[242] = 0x0111;"
215 print>>output_c,"\tmain[243] = 0x00F0;"
216 print>>output_c,"\tmain[244] = 0x0127;"
217 print>>output_c,"\tmain[245] = 0x0131;"
218 print>>output_c,"\tmain[246] = 0x0133;"
219 print>>output_c,"\tmain[247] = 0x0140;"
220 print>>output_c,"\tmain[248] = 0x0142;"
221 print>>output_c,"\tmain[249] = 0x00F8;"
222 print>>output_c,"\tmain[250] = 0x0153;"
223 print>>output_c,"\tmain[251] = 0x00DF;"
224 print>>output_c,"\tmain[252] = 0x00FE;"
225 print>>output_c,"\tmain[253] = 0x0167;"
226 print>>output_c,"\tmain[254] = 0x014B;"
227 print>>output_c,"\tmain[255] = 0x00AD;"
228 print>>output_c,""
229
230 for g in groups:
231     print>>output_c,"\tdiacriticals[%s] = &%s;" % (hex(g[0]), g[2])
232
233 print>>output_c,"}"
234 print>>output_h,""
235 print>>output_h,"}"
236 print>>output_h,"}"