dmime: Free list when Tempo track is destroyed.
[wine.git] / tools / make_unicode
blob301993340028b45f94f8d579b8a18e9c9aa5ecb4
1 #!/usr/bin/perl -w
3 # Generate code page .c files from ftp.unicode.org descriptions
5 # Copyright 2000 Alexandre Julliard
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 use strict;
24 # base URLs for www.unicode.org files
25 my $MAPPINGS = "http://www.unicode.org/Public/MAPPINGS";
26 my $UNIDATA = "http://www.unicode.org/Public/12.0.0/ucd";
27 my $REPORTS = "http://www.unicode.org/reports";
28 my $RFCS = "http://www.rfc-editor.org/rfc";
30 # Sort keys file
31 my $SORTKEYS = "tr10/allkeys.txt";
33 # RFC3454 (stringprep data)
34 my $STRINGPREP = "rfc3454.txt";
36 # Defaults mapping
37 my $DEFAULTS = "tools/unicode-defaults";
39 # Default char for undefined mappings
40 my $DEF_CHAR = ord '?';
42 my @allfiles =
44 [ 37, "VENDORS/MICSFT/EBCDIC/CP037.TXT", 0, "IBM EBCDIC US Canada", 0, 0x6f ],
45 [ 424, "VENDORS/MISC/CP424.TXT", 0, "IBM EBCDIC Hebrew" ],
46 [ 437, "VENDORS/MICSFT/PC/CP437.TXT", 1, "OEM United States" ],
47 [ 500, "VENDORS/MICSFT/EBCDIC/CP500.TXT", 0, "IBM EBCDIC International", 0, 0x6f ],
48 [ 737, "VENDORS/MICSFT/PC/CP737.TXT", 1, "OEM Greek 437G" ],
49 [ 775, "VENDORS/MICSFT/PC/CP775.TXT", 1, "OEM Baltic" ],
50 [ 850, "VENDORS/MICSFT/PC/CP850.TXT", 1, "OEM Multilingual Latin 1" ],
51 [ 852, "VENDORS/MICSFT/PC/CP852.TXT", 1, "OEM Slovak Latin 2" ],
52 [ 855, "VENDORS/MICSFT/PC/CP855.TXT", 1, "OEM Cyrillic" ],
53 [ 856, "VENDORS/MISC/CP856.TXT", 0, "Hebrew PC" ],
54 [ 857, "VENDORS/MICSFT/PC/CP857.TXT", 1, "OEM Turkish", 0xf8bb ],
55 [ 860, "VENDORS/MICSFT/PC/CP860.TXT", 1, "OEM Portuguese" ],
56 [ 861, "VENDORS/MICSFT/PC/CP861.TXT", 1, "OEM Icelandic" ],
57 [ 862, "VENDORS/MICSFT/PC/CP862.TXT", 1, "OEM Hebrew" ],
58 [ 863, "VENDORS/MICSFT/PC/CP863.TXT", 1, "OEM Canadian French" ],
59 [ 864, "VENDORS/MICSFT/PC/CP864.TXT", 0, "OEM Arabic", 0xf8bb ],
60 [ 865, "VENDORS/MICSFT/PC/CP865.TXT", 1, "OEM Nordic" ],
61 [ 866, "VENDORS/MICSFT/PC/CP866.TXT", 1, "OEM Russian" ],
62 [ 869, "VENDORS/MICSFT/PC/CP869.TXT", 1, "OEM Greek" ],
63 [ 874, "VENDORS/MICSFT/WindowsBestFit/bestfit874.txt", 1, "ANSI/OEM Thai" ],
64 [ 875, "VENDORS/MICSFT/EBCDIC/CP875.TXT", 0, "IBM EBCDIC Greek", 0, 0x6f ],
65 [ 878, "VENDORS/MISC/KOI8-R.TXT", 0, "Russian KOI8" ],
66 [ 932, "VENDORS/MICSFT/WindowsBestFit/bestfit932.txt", 0, "ANSI/OEM Japanese Shift-JIS" ],
67 [ 936, "VENDORS/MICSFT/WindowsBestFit/bestfit936.txt", 0, "ANSI/OEM Simplified Chinese GBK" ],
68 [ 949, "VENDORS/MICSFT/WindowsBestFit/bestfit949.txt", 0, "ANSI/OEM Korean Unified Hangul" ],
69 [ 950, "VENDORS/MICSFT/WindowsBestFit/bestfit950.txt", 0, "ANSI/OEM Traditional Chinese Big5" ],
70 [ 1006, "VENDORS/MISC/CP1006.TXT", 0, "IBM Arabic" ],
71 [ 1026, "VENDORS/MICSFT/EBCDIC/CP1026.TXT", 0, "IBM EBCDIC Latin 5 Turkish", 0, 0x6f ],
72 [ 1250, "VENDORS/MICSFT/WindowsBestFit/bestfit1250.txt", 0, "ANSI Eastern Europe" ],
73 [ 1251, "VENDORS/MICSFT/WindowsBestFit/bestfit1251.txt", 0, "ANSI Cyrillic" ],
74 [ 1252, "VENDORS/MICSFT/WindowsBestFit/bestfit1252.txt", 0, "ANSI Latin 1" ],
75 [ 1253, "VENDORS/MICSFT/WindowsBestFit/bestfit1253.txt", 0, "ANSI Greek" ],
76 [ 1254, "VENDORS/MICSFT/WindowsBestFit/bestfit1254.txt", 0, "ANSI Turkish" ],
77 [ 1255, "VENDORS/MICSFT/WindowsBestFit/bestfit1255.txt", 0, "ANSI Hebrew" ],
78 [ 1256, "VENDORS/MICSFT/WindowsBestFit/bestfit1256.txt", 0, "ANSI Arabic" ],
79 [ 1257, "VENDORS/MICSFT/WindowsBestFit/bestfit1257.txt", 0, "ANSI Baltic" ],
80 [ 1258, "VENDORS/MICSFT/WindowsBestFit/bestfit1258.txt", 0, "ANSI/OEM Viet Nam" ],
81 [ 1361, "VENDORS/MICSFT/WindowsBestFit/bestfit1361.txt", 0, "Korean Johab" ],
82 [ 10000, "VENDORS/MICSFT/MAC/ROMAN.TXT", 0, "Mac Roman" ],
83 [ 10001, "VENDORS/APPLE/JAPANESE.TXT", 0, "Mac Japanese" ],
84 [ 10002, "VENDORS/APPLE/CHINTRAD.TXT", 0, "Mac Traditional Chinese" ],
85 [ 10003, "VENDORS/APPLE/KOREAN.TXT", 0, "Mac Korean", 0xf8e5 ],
86 [ 10004, "VENDORS/APPLE/ARABIC.TXT", 0, "Mac Arabic", 0xf826 ],
87 [ 10005, "VENDORS/APPLE/HEBREW.TXT", 0, "Mac Hebrew", 0xf7fa ],
88 [ 10006, "VENDORS/MICSFT/MAC/GREEK.TXT", 0, "Mac Greek" ],
89 [ 10007, "VENDORS/MICSFT/MAC/CYRILLIC.TXT", 0, "Mac Cyrillic" ],
90 [ 10008, "VENDORS/APPLE/CHINSIMP.TXT", 0, "Mac Simplified Chinese" ],
91 [ 10010, "VENDORS/APPLE/ROMANIAN.TXT", 0, "Mac Romanian" ],
92 [ 10017, "VENDORS/APPLE/CYRILLIC.TXT", 0, "Mac Ukrainian" ],
93 [ 10021, "VENDORS/APPLE/THAI.TXT", 0, "Mac Thai" ],
94 [ 10029, "VENDORS/MICSFT/MAC/LATIN2.TXT", 0, "Mac Latin 2" ],
95 [ 10079, "VENDORS/MICSFT/MAC/ICELAND.TXT", 0, "Mac Icelandic" ],
96 [ 10081, "VENDORS/MICSFT/MAC/TURKISH.TXT", 0, "Mac Turkish", 0xf89f ],
97 [ 10082, "VENDORS/APPLE/CROATIAN.TXT", 0, "Mac Croatian" ],
98 [ 20127, undef, 0, "US-ASCII (7bit)" ],
99 [ 20866, "VENDORS/MISC/KOI8-R.TXT", 0, "Russian KOI8" ],
100 [ 20932, "OBSOLETE/EASTASIA/JIS/JIS0208.TXT", 0, "EUC-JP", 0, 0x3f, 0x30fb ],
101 [ 21866, "VENDORS/MISC/KOI8-U.TXT", 0, "Ukrainian KOI8" ],
102 [ 28591, "ISO8859/8859-1.TXT", 0, "ISO 8859-1 Latin 1" ],
103 [ 28592, "ISO8859/8859-2.TXT", 0, "ISO 8859-2 Latin 2 (East European)" ],
104 [ 28593, "ISO8859/8859-3.TXT", 0, "ISO 8859-3 Latin 3 (South European)", 0xf7f5 ],
105 [ 28594, "ISO8859/8859-4.TXT", 0, "ISO 8859-4 Latin 4 (Baltic old)" ],
106 [ 28595, "ISO8859/8859-5.TXT", 0, "ISO 8859-5 Cyrillic" ],
107 [ 28596, "ISO8859/8859-6.TXT", 0, "ISO 8859-6 Arabic", 0xf7c8 ],
108 [ 28597, "ISO8859/8859-7.TXT", 0, "ISO 8859-7 Greek", 0xf7c5 ],
109 [ 28598, "ISO8859/8859-8.TXT", 0, "ISO 8859-8 Hebrew", 0xf79c ],
110 [ 28599, "ISO8859/8859-9.TXT", 0, "ISO 8859-9 Latin 5 (Turkish)" ],
111 [ 28600, "ISO8859/8859-10.TXT", 0, "ISO 8859-10 Latin 6 (Nordic)" ],
112 [ 28601, "ISO8859/8859-11.TXT", 0, "ISO 8859-11 Latin (Thai)" ],
113 [ 28603, "ISO8859/8859-13.TXT", 0, "ISO 8859-13 Latin 7 (Baltic)" ],
114 [ 28604, "ISO8859/8859-14.TXT", 0, "ISO 8859-14 Latin 8 (Celtic)" ],
115 [ 28605, "ISO8859/8859-15.TXT", 0, "ISO 8859-15 Latin 9 (Euro)" ],
116 [ 28606, "ISO8859/8859-16.TXT", 0, "ISO 8859-16 Latin 10 (Balkan)" ]
120 my %ctype =
122 "upper" => 0x0001,
123 "lower" => 0x0002,
124 "digit" => 0x0004,
125 "space" => 0x0008,
126 "punct" => 0x0010,
127 "cntrl" => 0x0020,
128 "blank" => 0x0040,
129 "xdigit" => 0x0080,
130 "alpha" => 0x0100,
131 "defin" => 0x0200
134 my %bracket_types =
136 "o" => 0x0000,
137 "c" => 0x0001,
140 my %indic_types =
142 "Other" => 0x0000,
143 "Bindu" => 0x0001,
144 "Visarga" => 0x0002,
145 "Avagraha" => 0x0003,
146 "Nukta" => 0x0004,
147 "Virama" => 0x0005,
148 "Vowel_Independent" => 0x0006,
149 "Vowel_Dependent" => 0x0007,
150 "Vowel" => 0x0008,
151 "Consonant_Placeholder" => 0x0009,
152 "Consonant" => 0x000a,
153 "Consonant_Dead" => 0x000b,
154 "Consonant_Succeeding_Repha" => 0x000c,
155 "Consonant_Subjoined" => 0x000d,
156 "Consonant_Medial" => 0x000e,
157 "Consonant_Final" => 0x000f,
158 "Consonant_Head_Letter" => 0x0010,
159 "Modifying_Letter" => 0x0011,
160 "Tone_Letter" => 0x0012,
161 "Tone_Mark" => 0x0013,
162 "Register_Shifter" => 0x0014,
163 "Consonant_Preceding_Repha" => 0x0015,
164 "Pure_Killer" => 0x0016,
165 "Invisible_Stacker" => 0x0017,
166 "Gemination_Mark" => 0x0018,
167 "Cantillation_Mark" => 0x0019,
168 "Non_Joiner" => 0x001a,
169 "Joiner" => 0x001b,
170 "Number_Joiner" => 0x001c,
171 "Number" => 0x001d,
172 "Brahmi_Joining_Number" => 0x001e,
173 "Consonant_With_Stacker" => 0x001f,
174 "Consonant_Prefixed" => 0x0020,
175 "Syllable_Modifier" => 0x0021,
176 "Consonant_Killer" => 0x0022,
177 "Consonant_Initial_Postfixed" => 0x0023,
180 my %matra_types =
182 "Right" => 0x01,
183 "Left" => 0x02,
184 "Visual_Order_Left" => 0x03,
185 "Left_And_Right" => 0x04,
186 "Top" => 0x05,
187 "Bottom" => 0x06,
188 "Top_And_Bottom" => 0x07,
189 "Top_And_Right" => 0x08,
190 "Top_And_Left" => 0x09,
191 "Top_And_Left_And_Right" => 0x0a,
192 "Bottom_And_Right" => 0x0b,
193 "Top_And_Bottom_And_Right" => 0x0c,
194 "Overstruck" => 0x0d,
195 "Invisible" => 0x0e,
196 "Bottom_And_Left" => 0x0f
199 my %nameprep_flags =
201 "unassigned" => 0x01,
202 "prohibited" => 0x02,
203 "bidi_ral" => 0x04,
204 "bidi_l" => 0x08
207 my %break_types =
209 "BK" => 0x0001,
210 "CR" => 0x0002,
211 "LF" => 0x0003,
212 "CM" => 0x0004,
213 "SG" => 0x0005,
214 "GL" => 0x0006,
215 "CB" => 0x0007,
216 "SP" => 0x0008,
217 "ZW" => 0x0009,
218 "NL" => 0x000a,
219 "WJ" => 0x000b,
220 "JL" => 0x000c,
221 "JV" => 0x000d,
222 "JT" => 0x000e,
223 "H2" => 0x000f,
224 "H3" => 0x0010,
225 "XX" => 0x0011,
226 "OP" => 0x0012,
227 "CL" => 0x0013,
228 "CP" => 0x0014,
229 "QU" => 0x0015,
230 "NS" => 0x0016,
231 "EX" => 0x0017,
232 "SY" => 0x0018,
233 "IS" => 0x0019,
234 "PR" => 0x001a,
235 "PO" => 0x001b,
236 "NU" => 0x001c,
237 "AL" => 0x001d,
238 "ID" => 0x001e,
239 "IN" => 0x001f,
240 "HY" => 0x0020,
241 "BB" => 0x0021,
242 "BA" => 0x0022,
243 "SA" => 0x0023,
244 "AI" => 0x0024,
245 "B2" => 0x0025,
246 "HL" => 0x0026,
247 "CJ" => 0x0027,
248 "RI" => 0x0028,
249 "EB" => 0x0029,
250 "EM" => 0x002a,
251 "ZWJ" => 0x002b,
254 my %vertical_types =
256 "R" => 0x0000,
257 "U" => 0x0001,
258 "Tr" => 0x0002,
259 "Tu" => 0x0003,
262 my %categories =
264 "Lu" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"upper"}, # Letter, Uppercase
265 "Ll" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"lower"}, # Letter, Lowercase
266 "Lt" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"upper"}|$ctype{"lower"}, # Letter, Titlecase
267 "Mn" => $ctype{"defin"}, # Mark, Non-Spacing
268 "Mc" => $ctype{"defin"}, # Mark, Spacing Combining
269 "Me" => $ctype{"defin"}, # Mark, Enclosing
270 "Nd" => $ctype{"defin"}|$ctype{"digit"}, # Number, Decimal Digit
271 "Nl" => $ctype{"defin"}|$ctype{"alpha"}, # Number, Letter
272 "No" => $ctype{"defin"}, # Number, Other
273 "Zs" => $ctype{"defin"}|$ctype{"space"}, # Separator, Space
274 "Zl" => $ctype{"defin"}|$ctype{"space"}, # Separator, Line
275 "Zp" => $ctype{"defin"}|$ctype{"space"}, # Separator, Paragraph
276 "Cc" => $ctype{"defin"}|$ctype{"cntrl"}, # Other, Control
277 "Cf" => $ctype{"defin"}|$ctype{"cntrl"}, # Other, Format
278 "Cs" => $ctype{"defin"}, # Other, Surrogate
279 "Co" => $ctype{"defin"}, # Other, Private Use
280 "Cn" => $ctype{"defin"}, # Other, Not Assigned
281 "Lm" => $ctype{"defin"}|$ctype{"alpha"}, # Letter, Modifier
282 "Lo" => $ctype{"defin"}|$ctype{"alpha"}, # Letter, Other
283 "Pc" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Connector
284 "Pd" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Dash
285 "Ps" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Open
286 "Pe" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Close
287 "Pi" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Initial quote
288 "Pf" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Final quote
289 "Po" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Other
290 "Sm" => $ctype{"defin"}, # Symbol, Math
291 "Sc" => $ctype{"defin"}, # Symbol, Currency
292 "Sk" => $ctype{"defin"}, # Symbol, Modifier
293 "So" => $ctype{"defin"} # Symbol, Other
296 # a few characters need additional categories that cannot be determined automatically
297 my %special_categories =
299 "xdigit" => [ ord('0')..ord('9'),ord('A')..ord('F'),ord('a')..ord('f'),
300 0xff10..0xff19, 0xff21..0xff26, 0xff41..0xff46 ],
301 "space" => [ 0x09..0x0d, 0x85 ],
302 "blank" => [ 0x09, 0x20, 0xa0, 0x3000, 0xfeff ],
303 "cntrl" => [ 0x070f, 0x200c, 0x200d,
304 0x200e, 0x200f, 0x202a, 0x202b, 0x202c, 0x202d, 0x202e,
305 0x206a, 0x206b, 0x206c, 0x206d, 0x206e, 0x206f, 0xfeff,
306 0xfff9, 0xfffa, 0xfffb ],
307 "punct" => [ 0x24, 0x2b, 0x3c..0x3e, 0x5e, 0x60, 0x7c, 0x7e, 0xa2..0xbe,
308 0xd7, 0xf7 ],
309 "digit" => [ 0xb2, 0xb3, 0xb9 ],
310 "lower" => [ 0x2071, 0x207f ]
313 my %directions =
315 "L" => 1, # Left-to-Right
316 "R" => 2, # Right-to-Left
317 "AL" => 12, # Right-to-Left Arabic
318 "EN" => 3, # European Number
319 "ES" => 4, # European Number Separator
320 "ET" => 5, # European Number Terminator
321 "AN" => 6, # Arabic Number
322 "CS" => 7, # Common Number Separator
323 "NSM" => 13, # Non-Spacing Mark
324 "BN" => 14, # Boundary Neutral
325 "B" => 8, # Paragraph Separator
326 "S" => 9, # Segment Separator
327 "WS" => 10, # Whitespace
328 "ON" => 11, # Other Neutrals
329 "LRE" => 15, # Left-to-Right Embedding
330 "LRO" => 15, # Left-to-Right Override
331 "RLE" => 15, # Right-to-Left Embedding
332 "RLO" => 15, # Right-to-Left Override
333 "PDF" => 15, # Pop Directional Format
334 "LRI" => 15, # Left-to-Right Isolate
335 "RLI" => 15, # Right-to-Left Isolate
336 "FSI" => 15, # First Strong Isolate
337 "PDI" => 15 # Pop Directional Isolate
340 my %c2_types =
342 "L" => 1, # C2_LEFTTORIGHT
343 "R" => 2, # C2_RIGHTTOLEFT
344 "AL" => 2, # C2_RIGHTTOLEFT
345 "EN" => 3, # C2_EUROPENUMBER
346 "ES" => 4, # C2_EUROPESEPARATOR
347 "ET" => 5, # C2_EUROPETERMINATOR
348 "AN" => 6, # C2_ARABICNUMBER
349 "CS" => 7, # C2_COMMONSEPARATOR
350 "NSM" => 0, # C2_NOTAPPLICABLE
351 "BN" => 0, # C2_NOTAPPLICABLE
352 "B" => 8, # C2_BLOCKSEPARATOR
353 "S" => 9, # C2_SEGMENTSEPARATOR
354 "WS" => 10, # C2_WHITESPACE
355 "ON" => 11, # C2_OTHERNEUTRAL
356 "LRE" => 11, # C2_OTHERNEUTRAL
357 "LRO" => 11, # C2_OTHERNEUTRAL
358 "RLE" => 11, # C2_OTHERNEUTRAL
359 "RLO" => 11, # C2_OTHERNEUTRAL
360 "PDF" => 11, # C2_OTHERNEUTRAL
361 "LRI" => 11, # C2_OTHERNEUTRAL
362 "RLI" => 11, # C2_OTHERNEUTRAL
363 "FSI" => 11, # C2_OTHERNEUTRAL
364 "PDI" => 11 # C2_OTHERNEUTRAL
367 my %bidi_types =
369 "ON" => 0, # Other Neutrals
370 "L" => 1, # Left-to-Right
371 "R" => 2, # Right-to-Left
372 "AN" => 3, # Arabic Number
373 "EN" => 4, # European Number
374 "AL" => 5, # Right-to-Left Arabic
375 "NSM" => 6, # Non-Spacing Mark
376 "CS" => 7, # Common Number Separator
377 "ES" => 8, # European Number Separator
378 "ET" => 9, # European Number Terminator
379 "BN" => 10, # Boundary Neutral
380 "S" => 11, # Segment Separator
381 "WS" => 12, # Whitespace
382 "B" => 13, # Paragraph Separator
383 "RLO" => 14, # Right-to-Left Override
384 "RLE" => 15, # Right-to-Left Embedding
385 "LRO" => 16, # Left-to-Right Override
386 "LRE" => 17, # Left-to-Right Embedding
387 "PDF" => 18, # Pop Directional Format
388 "LRI" => 19, # Left-to-Right Isolate
389 "RLI" => 20, # Right-to-Left Isolate
390 "FSI" => 21, # First Strong Isolate
391 "PDI" => 22 # Pop Directional Isolate
394 my %joining_types =
396 "U" => 0, # Non_Joining
397 "T" => 1, # Transparent
398 "R" => 2, # Right_Joining
399 "L" => 3, # Left_Joining
400 "D" => 4, # Dual_Joining
401 "C" => 5, # Join_Causing
404 my @cp2uni = ();
405 my @lead_bytes = ();
406 my @uni2cp = ();
407 my @unicode_defaults = ();
408 my @unicode_aliases = ();
409 my @tolower_table = ();
410 my @toupper_table = ();
411 my @digitmap_table = ();
412 my @compatmap_table = ();
413 my @category_table = ();
414 my @joining_table = ();
415 my @direction_table = ();
416 my @decomp_table = ();
417 my @compose_table = ();
418 my @combining_class_table = ();
419 my @full_compatmap_table = ();
420 my $default_char;
421 my $default_wchar;
423 my %joining_forms =
425 "isolated" => [],
426 "final" => [],
427 "initial" => [],
428 "medial" => []
431 ################################################################
432 # fetch a unicode.org file and open it
433 sub open_data_file($$)
435 my ($base, $name) = @_;
436 (my $dir = "data/$name") =~ s/\/[^\/]+$//;
437 local *FILE;
438 unless (-f "data/$name")
440 print "Fetching $base/$name...\n";
441 system "mkdir", "-p", $dir;
442 !system "wget", "-q", "-O", "data/$name", "$base/$name" or die "cannot fetch $base/$name";
444 open FILE, "<data/$name" or die "cannot open data/$name";
445 return *FILE;
448 ################################################################
449 # read in the defaults file
450 sub READ_DEFAULTS($)
452 my $filename = shift;
453 my $start;
455 # first setup a few default mappings
457 open DEFAULTS, "$filename" or die "Cannot open $filename";
458 print "Loading $filename\n";
459 while (<DEFAULTS>)
461 next if /^\#/; # skip comments
462 next if /^$/; # skip empty lines
463 if (/^(([0-9a-fA-F]+)(,[0-9a-fA-F]+)*)\s+([0-9a-fA-F]+|'.'|none)\s+(\#.*)?/)
465 my @src = map hex, split /,/,$1;
466 my $dst = $4;
467 my $comment = $5;
468 if ($#src > 0) { push @unicode_aliases, \@src; }
469 next if ($dst eq "none");
470 $dst = ($dst =~ /\'.\'/) ? ord substr($dst,1,1) : hex $dst;
471 foreach my $src (@src)
473 die "Duplicate value" if defined($unicode_defaults[$src]);
474 $unicode_defaults[$src] = $dst;
476 next;
478 die "Unrecognized line $_\n";
480 close DEFAULTS;
482 # now build mappings from the decomposition field of the Unicode database
484 my $UNICODE_DATA = open_data_file( $UNIDATA, "UnicodeData.txt" );
485 while (<$UNICODE_DATA>)
487 # Decode the fields ...
488 my ($code, $name, $cat, $comb, $bidi,
489 $decomp, $dec, $dig, $num, $mirror,
490 $oldname, $comment, $upper, $lower, $title) = split /;/;
491 my $dst;
492 my $src = hex $code;
494 die "unknown category $cat" unless defined $categories{$cat};
495 die "unknown directionality $bidi" unless defined $directions{$bidi};
497 $category_table[$src] = $categories{$cat};
498 $direction_table[$src] = $bidi;
499 $joining_table[$src] = $joining_types{"T"} if $cat eq "Mn" || $cat eq "Me" || $cat eq "Cf";
501 if ($lower ne "")
503 $tolower_table[$src] = hex $lower;
505 if ($upper ne "")
507 $toupper_table[$src] = hex $upper;
509 if ($dec ne "")
511 $category_table[$src] |= $ctype{"digit"};
513 if ($dig ne "")
515 $digitmap_table[$src] = ord $dig;
517 if ($comb ne "")
519 $combining_class_table[$src] = $comb;
522 # copy the category and direction for everything between First/Last pairs
523 if ($name =~ /, First>/) { $start = $src; }
524 if ($name =~ /, Last>/)
526 while ($start < $src)
528 $category_table[$start] = $category_table[$src];
529 $direction_table[$start] = $direction_table[$src];
530 $start++;
534 next if $decomp eq ""; # no decomposition, skip it
536 if ($decomp =~ /^<([a-zA-Z]+)>\s+([0-9a-fA-F]+)/)
538 my @seq = ();
539 for my $ch (split /\s+/, (split /\s+/, $decomp, 2)[1])
541 push @seq, (hex $ch);
543 $full_compatmap_table[$src] = \@seq;
546 if ($decomp =~ /^<([a-zA-Z]+)>\s+([0-9a-fA-F]+)$/)
548 # decomposition of the form "<foo> 1234" -> use char if type is known
549 if (($src >= 0xf900 && $src < 0xfb00) || ($src >= 0xfe30 && $src < 0xfffd))
551 # Single char decomposition in the compatibility range
552 $compatmap_table[$src] = hex $2;
554 if ($1 eq "isolated" || $1 eq "final" || $1 eq "initial" || $1 eq "medial")
556 ${joining_forms{$1}}[hex $2] = $src;
557 next;
559 next unless ($1 eq "font" ||
560 $1 eq "noBreak" ||
561 $1 eq "circle" ||
562 $1 eq "super" ||
563 $1 eq "sub" ||
564 $1 eq "wide" ||
565 $1 eq "narrow" ||
566 $1 eq "compat" ||
567 $1 eq "small");
568 $dst = hex $2;
570 elsif ($decomp =~ /^<compat>\s+0020\s+([0-9a-fA-F]+)/)
572 # decomposition "<compat> 0020 1234" -> combining accent
573 $dst = hex $1;
575 elsif ($decomp =~ /^([0-9a-fA-F]+)/)
577 # decomposition contains only char values without prefix -> use first char
578 $dst = hex $1;
579 $category_table[$src] |= $category_table[$dst] if defined $category_table[$dst];
580 # store decomposition if it contains two chars
581 if ($decomp =~ /^([0-9a-fA-F]+)\s+([0-9a-fA-F]+)$/)
583 $decomp_table[$src] = [ hex $1, hex $2 ];
584 push @compose_table, [ hex $1, hex $2, $src ];
586 elsif ($decomp =~ /^([0-9a-fA-F]+)$/)
588 # Single char decomposition
589 if (hex $1 < 65536)
591 $decomp_table[$src] = [ hex $1, 0 ];
594 if (($src >= 0xf900 && $src < 0xfb00) || ($src >= 0xfe30 && $src < 0xfffd))
596 # Single char decomposition in the compatibility range
597 $compatmap_table[$src] = hex $1;
601 else
603 next;
606 next if defined($unicode_defaults[$src]); # may have been set in the defaults file
608 # check for loops
609 for (my $i = $dst; ; $i = $unicode_defaults[$i])
611 die sprintf("loop detected for %04x -> %04x",$src,$dst) if $i == $src;
612 last unless defined($unicode_defaults[$i]);
614 $unicode_defaults[$src] = $dst;
616 close $UNICODE_DATA;
618 # patch the category of some special characters
620 foreach my $cat (keys %special_categories)
622 my $flag = $ctype{$cat};
623 foreach my $i (@{$special_categories{$cat}}) { $category_table[$i] |= $flag; }
628 ################################################################
629 # define a new lead byte
630 sub add_lead_byte($)
632 my $ch = shift;
633 return if defined $cp2uni[$ch];
634 push @lead_bytes, $ch;
635 $cp2uni[$ch] = 0;
638 ################################################################
639 # define a new char mapping
640 sub add_mapping($$)
642 my ($cp, $uni) = @_;
643 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
644 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
645 if ($cp > 0xff) { add_lead_byte( $cp >> 8 ); }
648 ################################################################
649 # parse a standard codepage file
650 sub read_codepage_file($)
652 my $name = shift;
653 my $INPUT = open_data_file( $MAPPINGS, $name );
655 while (<$INPUT>)
657 next if /^\#/; # skip comments
658 next if /^$/; # skip empty lines
659 next if /\x1a/; # skip ^Z
660 next if (/^0x([0-9a-fA-F]+)\s+\#UNDEFINED/); # undefined char
662 if (/^0x([0-9a-fA-F]+)\s+\#DBCS LEAD BYTE/)
664 add_lead_byte( hex $1 );
665 next;
667 # 0x12 0x3456
668 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
670 add_mapping( hex $1, hex $2 );
671 next;
673 # 0x12 0x3456+0x7890
674 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\+.*\s+(\#.*)?/)
676 add_mapping( hex $1, hex $2 );
677 next;
679 # 0x12 <LR>+0x3456
680 if (/^0x([0-9a-fA-F]+)\s+<LR>\+0x([0-9a-fA-F]+)\s+(\#.*)?/)
682 add_mapping( hex $1, hex $2 );
683 next;
685 # 0x12 <RL>+0x3456
686 if (/^0x([0-9a-fA-F]+)\s+<RL>\+0x([0-9a-fA-F]+)\s+(\#.*)?/)
688 my $uni = hex $2;
689 add_mapping( hex $1, $uni ) if $uni >= 0x80;
690 next;
692 die "$name: Unrecognized line $_\n";
694 close $INPUT;
698 ################################################################
699 # fill input data for the 20127 (us-ascii) codepage
700 sub fill_20127_codepage()
702 for (my $i = 0; $i < 128; $i++) { $cp2uni[$i] = $uni2cp[$i] = $i; }
703 for (my $i = 128; $i < 256; $i++) { $cp2uni[$i] = $i & 0x7f; }
706 ################################################################
707 # get a mapping including glyph chars for MB_USEGLYPHCHARS
709 sub get_glyphs_mapping(@)
711 $_[0x01] = 0x263a; # (WHITE SMILING FACE)
712 $_[0x02] = 0x263b; # (BLACK SMILING FACE)
713 $_[0x03] = 0x2665; # (BLACK HEART SUIT)
714 $_[0x04] = 0x2666; # (BLACK DIAMOND SUIT)
715 $_[0x05] = 0x2663; # (BLACK CLUB SUIT)
716 $_[0x06] = 0x2660; # (BLACK SPADE SUIT)
717 $_[0x07] = 0x2022; # (BULLET)
718 $_[0x08] = 0x25d8; # (INVERSE BULLET)
719 $_[0x09] = 0x25cb; # (WHITE CIRCLE)
720 $_[0x0a] = 0x25d9; # (INVERSE WHITE CIRCLE)
721 $_[0x0b] = 0x2642; # (MALE SIGN)
722 $_[0x0c] = 0x2640; # (FEMALE SIGN)
723 $_[0x0d] = 0x266a; # (EIGHTH NOTE)
724 $_[0x0e] = 0x266b; # (BEAMED EIGHTH NOTES)
725 $_[0x0f] = 0x263c; # (WHITE SUN WITH RAYS)
726 $_[0x10] = 0x25ba; # (BLACK RIGHT-POINTING POINTER)
727 $_[0x11] = 0x25c4; # (BLACK LEFT-POINTING POINTER)
728 $_[0x12] = 0x2195; # (UP DOWN ARROW)
729 $_[0x13] = 0x203c; # (DOUBLE EXCLAMATION MARK)
730 $_[0x14] = 0x00b6; # (PILCROW SIGN)
731 $_[0x15] = 0x00a7; # (SECTION SIGN)
732 $_[0x16] = 0x25ac; # (BLACK RECTANGLE)
733 $_[0x17] = 0x21a8; # (UP DOWN ARROW WITH BASE)
734 $_[0x18] = 0x2191; # (UPWARDS ARROW)
735 $_[0x19] = 0x2193; # (DOWNWARDS ARROW)
736 $_[0x1a] = 0x2192; # (RIGHTWARDS ARROW)
737 $_[0x1b] = 0x2190; # (LEFTWARDS ARROW)
738 $_[0x1c] = 0x221f; # (RIGHT ANGLE)
739 $_[0x1d] = 0x2194; # (LEFT RIGHT ARROW)
740 $_[0x1e] = 0x25b2; # (BLACK UP-POINTING TRIANGLE)
741 $_[0x1f] = 0x25bc; # (BLACK DOWN-POINTING TRIANGLE)
742 $_[0x7f] = 0x2302; # (HOUSE)
743 return @_;
746 ################################################################
747 # build EUC-JP table from the JIS 0208 file
748 # FIXME: for proper EUC-JP we should probably read JIS 0212 too
749 # but this would require 3-byte DBCS characters
750 sub READ_JIS0208_FILE($)
752 my $name = shift;
754 # ASCII chars
755 for (my $i = 0x00; $i <= 0x7f; $i++)
757 $cp2uni[$i] = $i;
758 $uni2cp[$i] = $i;
761 # JIS X 0201 right plane
762 for (my $i = 0xa1; $i <= 0xdf; $i++)
764 $cp2uni[0x8e00 + $i] = 0xfec0 + $i;
765 $uni2cp[0xfec0 + $i] = 0x8e00 + $i;
768 # lead bytes
769 foreach my $i (0x8e, 0x8f, 0xa1 .. 0xfe)
771 add_lead_byte($i);
774 # undefined chars
775 foreach my $i (0x80 .. 0x8d, 0x90 .. 0xa0, 0xff)
777 $cp2uni[$i] = $DEF_CHAR;
780 # Shift-JIS compatibility
781 $uni2cp[0x00a5] = 0x5c;
782 $uni2cp[0x203e] = 0x7e;
784 # Fix backslash conversion
785 $cp2uni[0xa1c0] = 0xff3c;
786 $uni2cp[0xff3c] = 0xa1c0;
788 my $INPUT = open_data_file( $MAPPINGS, $name );
789 while (<$INPUT>)
791 next if /^\#/; # skip comments
792 next if /^$/; # skip empty lines
793 next if /\x1a/; # skip ^Z
794 if (/^0x[0-9a-fA-F]+\s+0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
796 my $cp = 0x8080 + hex $1;
797 my $uni = hex $2;
798 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
799 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
800 next;
802 die "$name: Unrecognized line $_\n";
804 close $INPUT;
808 ################################################################
809 # build the sort keys table
810 sub READ_SORTKEYS_FILE()
812 my @sortkeys = ();
813 for (my $i = 0; $i < 65536; $i++) { $sortkeys[$i] = [ -1, 0, 0, 0, 0 ] };
815 my $INPUT = open_data_file( $REPORTS, $SORTKEYS );
816 while (<$INPUT>)
818 next if /^\#/; # skip comments
819 next if /^$/; # skip empty lines
820 next if /\x1a/; # skip ^Z
821 next if /^\@version/; # skip @version header
822 if (/^([0-9a-fA-F]+)\s+;\s+\[([*.])([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]+)\]/)
824 my ($uni,$variable) = (hex $1, $2);
825 next if $uni > 65535;
826 $sortkeys[$uni] = [ $uni, hex $3, hex $4, hex $5, hex $6 ];
827 next;
829 if (/^([0-9a-fA-F]+\s+)+;\s+\[[*.]([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]+)\]/)
831 # multiple character sequence, ignored for now
832 next;
834 die "$SORTKEYS: Unrecognized line $_\n";
836 close $INPUT;
838 # compress the keys to 32 bit:
839 # key 1 to 16 bits, key 2 to 8 bits, key 3 to 4 bits, key 4 to 1 bit
841 @sortkeys = sort { ${$a}[1] <=> ${$b}[1] or
842 ${$a}[2] <=> ${$b}[2] or
843 ${$a}[3] <=> ${$b}[3] or
844 ${$a}[4] <=> ${$b}[4] or
845 $a cmp $b; } @sortkeys;
847 my ($n2, $n3) = (1, 1);
848 my @keys = (-1, -1, -1, -1, -1 );
849 my @flatkeys = ();
851 for (my $i = 0; $i < 65536; $i++)
853 my @current = @{$sortkeys[$i]};
854 next if $current[0] == -1;
855 if ($current[1] == $keys[1])
857 if ($current[2] == $keys[2])
859 if ($current[3] == $keys[3])
861 # nothing
863 else
865 $keys[3] = $current[3];
866 $n3++;
867 die if ($n3 >= 16);
870 else
872 $keys[2] = $current[2];
873 $keys[3] = $current[3];
874 $n2++;
875 $n3 = 1;
876 die if ($n2 >= 256);
879 else
881 $keys[1] = $current[1];
882 $keys[2] = $current[2];
883 $keys[3] = $current[3];
884 $n2 = 1;
885 $n3 = 1;
888 if ($current[2]) { $current[2] = $n2; }
889 if ($current[3]) { $current[3] = $n3; }
890 if ($current[4]) { $current[4] = 1; }
892 $flatkeys[$current[0]] = ($current[1] << 16) | ($current[2] << 8) | ($current[3] << 4) | $current[4];
894 return @flatkeys;
898 ################################################################
899 # build the sort keys table
900 sub dump_sortkeys($@)
902 my ($filename, @keys) = @_;
904 # count the number of 256-key ranges that contain something
906 my @offsets = ();
907 my $ranges = 2;
908 for (my $i = 0; $i < 256; $i++) { $offsets[$i] = 256; }
909 for (my $i = 0; $i < 65536; $i++)
911 next unless defined $keys[$i];
912 $offsets[$i >> 8] = $ranges * 256;
913 $ranges++;
914 $i |= 255;
917 # output the range offsets
919 open OUTPUT,">$filename.new" or die "Cannot create $filename";
920 printf "Building $filename\n";
921 printf OUTPUT "/* Unicode collation element table */\n";
922 printf OUTPUT "/* generated from %s */\n", "$REPORTS/$SORTKEYS";
923 printf OUTPUT "/* DO NOT EDIT!! */\n\n";
924 print OUTPUT "#include \"windef.h\"\n\n";
926 printf OUTPUT "const unsigned int DECLSPEC_HIDDEN collation_table[%d] =\n{\n", $ranges*256;
927 printf OUTPUT " /* index */\n";
928 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%08x", 0, @offsets );
930 # output the default values
932 printf OUTPUT " /* defaults */\n";
933 printf OUTPUT "%s", DUMP_ARRAY( "0x%08x", 0, (0xffffffff) x 256 );
935 # output all the key ranges
937 for (my $i = 0; $i < 256; $i++)
939 next if $offsets[$i] == 256;
940 printf OUTPUT ",\n /* 0x%02x00 .. 0x%02xff */\n", $i, $i;
941 printf OUTPUT "%s", DUMP_ARRAY( "0x%08x", 0xffffffff, @keys[($i<<8) .. ($i<<8)+255] );
943 printf OUTPUT "\n};\n";
944 close OUTPUT;
945 save_file($filename);
949 ################################################################
950 # add default mappings once the file had been read
951 sub add_default_mappings($)
953 my $first_private = shift;
955 # Apply aliases
957 foreach my $alias (@unicode_aliases)
959 my $target = undef;
960 foreach my $src (@$alias)
962 if (defined($uni2cp[$src]))
964 $target = $uni2cp[$src];
965 last;
968 next unless defined($target);
970 # At least one char of the alias set is defined, set the others to the same value
971 foreach my $src (@$alias)
973 $uni2cp[$src] = $target unless defined($uni2cp[$src]);
977 # For every src -> target mapping in the defaults table,
978 # make uni2cp[src] = uni2cp[target] if uni2cp[target] is defined
980 for (my $src = 0; $src < 65536; $src++)
982 next if defined($uni2cp[$src]); # source has a definition already
983 next unless defined($unicode_defaults[$src]); # no default for this char
984 my $target = $unicode_defaults[$src];
986 # do a recursive mapping until we find a target char that is defined
987 while (!defined($uni2cp[$target]) &&
988 defined($unicode_defaults[$target])) { $target = $unicode_defaults[$target]; }
990 if (defined($uni2cp[$target])) { $uni2cp[$src] = $uni2cp[$target]; }
993 # Add a private char mapping for undefined chars
995 if ($first_private)
997 for (my $i = 32; $i < 256; $i++)
999 next if defined($cp2uni[$i]);
1000 $cp2uni[$i] = $first_private;
1001 $uni2cp[$first_private] = $i;
1002 $first_private++;
1006 # Add an identity mapping for all undefined chars
1008 for (my $i = 0; $i < 256; $i++)
1010 next if defined($cp2uni[$i]);
1011 next if defined($uni2cp[$i]);
1012 $cp2uni[$i] = $uni2cp[$i] = $i;
1016 ################################################################
1017 # dump an array of integers
1018 sub DUMP_ARRAY($$@)
1020 my ($format,$default,@array) = @_;
1021 my $i;
1022 my $ret = " ";
1023 for ($i = 0; $i < $#array; $i++)
1025 $ret .= sprintf($format, defined $array[$i] ? $array[$i] : $default);
1026 $ret .= (($i % 8) != 7) ? ", " : ",\n ";
1028 $ret .= sprintf($format, defined $array[$i] ? $array[$i] : $default);
1029 return $ret;
1033 ################################################################
1034 # dump a unicode->ascii mapping table
1035 sub dump_uni2cp_table($$)
1037 my ($width, $def) = @_;
1039 # count the number of unicode->ascii subtables that contain something
1041 my @lowerbounds;
1042 my @upperbounds;
1043 my $index = 0;
1044 my @filled = (-1) x 256;
1045 for (my $i = 0; $i < 65536; $i++)
1047 next unless defined $uni2cp[$i];
1048 if ($filled[$i >> 8] == -1)
1050 $lowerbounds[$index] = $i & 0xff;
1051 $upperbounds[$index] = 0xff - $lowerbounds[$index];
1052 $filled[$i >> 8] = $index * 256;
1053 $index++;
1055 else
1057 $upperbounds[$index-1] = 0xff - ($i & 0xff);
1061 # add defaults mapping at the end
1062 $filled[256] = $index * 256;
1063 $lowerbounds[$index] = 255;
1064 $upperbounds[$index] = 0;
1065 $index++;
1067 # collapse blocks upwards if possible
1068 my $removed = 0;
1069 $index = 0;
1070 for (my $i = 0; $i < 257; $i++)
1072 next if $filled[$i] == -1;
1073 if ($upperbounds[$index - 1] > $lowerbounds[$index])
1075 $removed += $lowerbounds[$index];
1077 else
1079 $removed += $upperbounds[$index - 1];
1080 $lowerbounds[$index] = $upperbounds[$index - 1];
1082 $filled[$i] -= $removed;
1083 $index++;
1086 # output all the subtables into a single array
1088 printf OUTPUT "static const unsigned %s uni2cp_low[] =\n{\n", $width == 8 ? "char" : "short";
1090 my $format = $width == 8 ? "0x%02x" : "0x%04x";
1091 for (my $i = $index = 0; $i < 257; $i++)
1093 next if $filled[$i] == -1;
1094 my $start = ($i << 8) + $lowerbounds[$index];
1095 my $end = ($i << 8) + 255;
1096 if ($i == 256)
1098 print OUTPUT " /* defaults */\n";
1099 printf OUTPUT "%s\n};\n\n", DUMP_ARRAY( $format, 0, ($def) x ($end - $start + 1) );
1101 else
1103 printf OUTPUT " /* 0x%04x .. 0x%04x */\n", $start, $end;
1104 printf OUTPUT "%s,\n", DUMP_ARRAY( $format, $def, @uni2cp[$start .. $end] );
1106 $index++;
1109 # output a table of the offsets of the subtables in the previous array
1111 for (my $i = 0; $i < 256; $i++)
1113 if ($filled[$i] == -1) { $filled[$i] = $filled[256]; }
1115 printf OUTPUT "static const unsigned short uni2cp_high[256] =\n";
1116 printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%04x", 0, @filled[0..255] );
1119 ################################################################
1120 # dump an SBCS mapping table
1121 sub dump_sbcs_table($$$$$)
1123 my ($codepage, $has_glyphs, $name, $def, $defw) = @_;
1124 my $i;
1126 # output the ascii->unicode table
1128 if ($has_glyphs)
1130 printf OUTPUT "static const WCHAR cp2uni[512] =\n";
1131 printf OUTPUT "{\n%s", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[0 .. 255] );
1132 printf OUTPUT ",\n /* glyphs */\n%s\n};\n\n",
1133 DUMP_ARRAY( "0x%04x", $defw, get_glyphs_mapping(@cp2uni[0 .. 255]) );
1135 else
1137 printf OUTPUT "static const WCHAR cp2uni[256] =\n";
1138 printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[0 .. 255] );
1141 dump_uni2cp_table( 8, $def );
1143 # output the code page descriptor
1145 printf OUTPUT "const struct sbcs_table DECLSPEC_HIDDEN cptable_%03d =\n{\n", $codepage;
1146 printf OUTPUT " { %d, 1, 0x%04x, 0x%04x, \"%s\" },\n",
1147 $codepage, $def, $defw, $name;
1148 printf OUTPUT " cp2uni,\n";
1149 if ($has_glyphs) { printf OUTPUT " cp2uni + 256,\n"; }
1150 else { printf OUTPUT " cp2uni,\n"; }
1151 printf OUTPUT " uni2cp_low,\n";
1152 printf OUTPUT " uni2cp_high\n};\n";
1156 ################################################################
1157 # dump a DBCS mapping table
1158 sub dump_dbcs_table($$$$@)
1160 my ($codepage, $name, $def, $defw, @lb_ranges) = @_;
1162 # build a list of lead bytes that are actually used
1164 my @lblist = ();
1165 LBLOOP: for (my $y = 0; $y <= $#lead_bytes; $y++)
1167 $cp2uni[$lead_bytes[$y]] = $defw;
1168 my $base = $lead_bytes[$y] << 8;
1169 for (my $x = 0; $x < 256; $x++)
1171 if (defined $cp2uni[$base+$x])
1173 push @lblist,$lead_bytes[$y];
1174 next LBLOOP;
1178 my $unused = ($#lead_bytes > $#lblist);
1180 # output the ascii->unicode table for the single byte chars
1182 printf OUTPUT "static const WCHAR cp2uni[%d] =\n", 256 * ($#lblist + 2 + $unused);
1183 printf OUTPUT "{\n%s,\n", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[0 .. 255] );
1185 # output the default table for unused lead bytes
1187 if ($unused)
1189 printf OUTPUT " /* unused lead bytes */\n";
1190 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%04x", 0, ($defw) x 256 );
1193 # output the ascii->unicode table for each DBCS lead byte
1195 for (my $y = 0; $y <= $#lblist; $y++)
1197 my $base = $lblist[$y] << 8;
1198 printf OUTPUT " /* lead byte %02x */\n", $lblist[$y];
1199 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[$base .. $base+255] );
1200 printf OUTPUT ($y < $#lblist) ? ",\n" : "\n};\n\n";
1203 # output the lead byte subtables offsets
1205 my @offsets = (0) x 256;
1206 for (my $x = 0; $x <= $#lblist; $x++) { $offsets[$lblist[$x]] = $x + 1; }
1207 if ($unused)
1209 # increment all lead bytes offset to take into account the unused table
1210 for (my $x = 0; $x <= $#lead_bytes; $x++) { $offsets[$lead_bytes[$x]]++; }
1212 printf OUTPUT "static const unsigned char cp2uni_leadbytes[256] =\n";
1213 printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%02x", 0, @offsets );
1215 dump_uni2cp_table( 16, $def );
1217 # output the code page descriptor
1219 printf OUTPUT "const struct dbcs_table DECLSPEC_HIDDEN cptable_%03d =\n{\n", $codepage;
1220 printf OUTPUT " { %d, 2, 0x%04x, 0x%04x, \"%s\" },\n",
1221 $codepage, $def, $defw, $name;
1222 printf OUTPUT " cp2uni,\n";
1223 printf OUTPUT " cp2uni_leadbytes,\n";
1224 printf OUTPUT " uni2cp_low,\n";
1225 printf OUTPUT " uni2cp_high,\n";
1226 printf OUTPUT " {\n %s\n }\n", DUMP_ARRAY( "0x%02x", 0, @lb_ranges, 0, 0 );
1227 printf OUTPUT "};\n";
1231 ################################################################
1232 # get the list of defined lead byte ranges
1233 sub get_lb_ranges()
1235 my @list = ();
1236 my @ranges = ();
1237 my $i = 0;
1238 foreach $i (@lead_bytes) { $list[$i] = 1; }
1239 my $on = 0;
1240 for (my $i = 0; $i < 256; $i++)
1242 if ($on)
1244 if (!defined $list[$i]) { push @ranges, $i-1; $on = 0; }
1246 else
1248 if ($list[$i]) { push @ranges, $i; $on = 1; }
1251 if ($on) { push @ranges, 0xff; }
1252 return @ranges;
1255 ################################################################
1256 # dump the Indic Syllabic Category table
1257 sub dump_indic($)
1259 my $filename = shift;
1260 my @indic_table;
1262 my $INPUT = open_data_file( $UNIDATA, "IndicSyllabicCategory.txt" );
1263 while (<$INPUT>)
1265 next if /^\#/; # skip comments
1266 next if /^\s*$/; # skip empty lines
1267 next if /\x1a/; # skip ^Z
1268 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*#/)
1270 my $type = $2;
1271 die "unknown indic $type" unless defined $indic_types{$type};
1272 if (hex $1 < 65536)
1274 $indic_table[hex $1] = $indic_types{$type};
1276 next;
1278 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*#/)
1280 my $type = $3;
1281 die "unknown indic $type" unless defined $indic_types{$type};
1282 if (hex $1 < 65536 and hex $2 < 65536)
1284 foreach my $i (hex $1 .. hex $2)
1286 $indic_table[$i] = $indic_types{$type};
1289 next;
1291 die "malformed line $_";
1293 close $INPUT;
1295 $INPUT = open_data_file( $UNIDATA, "IndicPositionalCategory.txt" );
1296 while (<$INPUT>)
1298 next if /^\#/; # skip comments
1299 next if /^\s*$/; # skip empty lines
1300 next if /\x1a/; # skip ^Z
1301 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z]+)\s*#/)
1303 my $type = $2;
1304 die "unknown matra $type" unless defined $matra_types{$type};
1305 $indic_table[hex $1] += $matra_types{$type} << 8;
1306 next;
1308 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*#/)
1310 my $type = $3;
1311 die "unknown matra $type" unless defined $matra_types{$type};
1312 foreach my $i (hex $1 .. hex $2)
1314 $indic_table[$i] += $matra_types{$type} << 8;
1316 next;
1318 die "malformed line $_";
1320 close $INPUT;
1322 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1323 print "Building $filename\n";
1324 print OUTPUT "/* Unicode Indic Syllabic Category */\n";
1325 print OUTPUT "/* generated from $UNIDATA/IndicSyllabicCategory.txt */\n";
1326 print OUTPUT "/* and from $UNIDATA/IndicPositionalCategory.txt */\n";
1327 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1328 print OUTPUT "#include \"windef.h\"\n\n";
1330 dump_two_level_mapping( "indic_syllabic_table", $indic_types{'Other'}, @indic_table );
1332 close OUTPUT;
1333 save_file($filename);
1336 ################################################################
1337 # dump the Line Break Properties table
1338 sub dump_linebreak($)
1340 my $filename = shift;
1341 my @break_table;
1342 my $next_group = 0;
1344 my $INPUT = open_data_file( $UNIDATA, "LineBreak.txt" );
1345 while (<$INPUT>)
1347 next if /^\#/; # skip comments
1348 next if /^\s*$/; # skip empty lines
1349 next if /\x1a/; # skip ^Z
1350 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z][0-9A-Z])+\s*/)
1352 my $type = $2;
1353 die "unknown breaktype $type" unless defined $break_types{$type};
1354 $break_table[hex $1] = $break_types{$type};
1355 next;
1357 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z][0-9A-Z])+\s*/)
1359 my $type = $3;
1360 die "unknown breaktype $type" unless defined $break_types{$type};
1361 foreach my $i (hex $1 .. hex $2)
1363 $break_table[$i] = $break_types{$type};
1365 next;
1367 elsif (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z])+\s*/)
1369 my $type = $2;
1370 die "unknown breaktype $type" unless defined $break_types{$type};
1371 $break_table[hex $1] = $break_types{$type};
1372 next;
1374 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z])+\s*/)
1376 my $type = $3;
1377 die "unknown breaktype $type" unless defined $break_types{$type};
1378 foreach my $i (hex $1 .. hex $2)
1380 $break_table[$i] = $break_types{$type};
1382 next;
1384 die "malformed line $_";
1386 close $INPUT;
1388 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1389 print "Building $filename\n";
1390 print OUTPUT "/* Unicode Line Break Properties */\n";
1391 print OUTPUT "/* generated from $UNIDATA/LineBreak.txt */\n";
1392 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1393 print OUTPUT "#include \"windef.h\"\n\n";
1395 dump_two_level_mapping( "wine_linebreak_table", $break_types{'XX'}, @break_table );
1397 close OUTPUT;
1398 save_file($filename);
1401 my %scripts =
1403 "Unknown" => 0,
1404 "Common" => 1,
1405 "Inherited" => 2,
1406 "Arabic" => 3,
1407 "Armenian" => 4,
1408 "Avestan" => 5,
1409 "Balinese" => 6,
1410 "Bamum" => 7,
1411 "Batak" => 8,
1412 "Bengali" => 9,
1413 "Bopomofo" => 10,
1414 "Brahmi" => 11,
1415 "Braille" => 12,
1416 "Buginese" => 13,
1417 "Buhid" => 14,
1418 "Canadian_Aboriginal" => 15,
1419 "Carian" => 16,
1420 "Cham" => 17,
1421 "Cherokee" => 18,
1422 "Coptic" => 19,
1423 "Cuneiform" => 20,
1424 "Cypriot" => 21,
1425 "Cyrillic" => 22,
1426 "Deseret" => 23,
1427 "Devanagari" => 24,
1428 "Egyptian_Hieroglyphs" => 25,
1429 "Ethiopic" => 26,
1430 "Georgian" => 27,
1431 "Glagolitic" => 28,
1432 "Gothic" => 29,
1433 "Greek" => 30,
1434 "Gujarati" => 31,
1435 "Gurmukhi" => 32,
1436 "Han" => 33,
1437 "Hangul" => 34,
1438 "Hanunoo" => 35,
1439 "Hebrew" => 36,
1440 "Hiragana" => 37,
1441 "Imperial_Aramaic" => 38,
1442 "Inscriptional_Pahlavi" => 39,
1443 "Inscriptional_Parthian" => 40,
1444 "Javanese" => 41,
1445 "Kaithi" => 42,
1446 "Kannada" => 43,
1447 "Katakana" => 44,
1448 "Kayah_Li" => 45,
1449 "Kharoshthi" => 46,
1450 "Khmer" => 47,
1451 "Lao" => 48,
1452 "Latin" => 49,
1453 "Lepcha" => 50,
1454 "Limbu" => 51,
1455 "Linear_B" => 52,
1456 "Lisu" => 53,
1457 "Lycian" => 54,
1458 "Lydian" => 55,
1459 "Malayalam" => 56,
1460 "Mandaic" => 57,
1461 "Meetei_Mayek" => 58,
1462 "Mongolian" => 59,
1463 "Myanmar" => 60,
1464 "New_Tai_Lue" => 61,
1465 "Nko" => 62,
1466 "Ogham" => 63,
1467 "Ol_Chiki" => 64,
1468 "Old_Italic" => 65,
1469 "Old_Persian" => 66,
1470 "Old_South_Arabian" => 67,
1471 "Old_Turkic" => 68,
1472 "Oriya" => 69,
1473 "Osmanya" => 70,
1474 "Phags_Pa" => 71,
1475 "Phoenician" => 72,
1476 "Rejang" => 73,
1477 "Runic" => 74,
1478 "Samaritan" => 75,
1479 "Saurashtra" => 76,
1480 "Shavian" => 77,
1481 "Sinhala" => 78,
1482 "Sundanese" => 79,
1483 "Syloti_Nagri" => 80,
1484 "Syriac" => 81,
1485 "Tagalog" => 82,
1486 "Tagbanwa" => 83,
1487 "Tai_Le" => 84,
1488 "Tai_Tham" => 85,
1489 "Tai_Viet" => 86,
1490 "Tamil" => 87,
1491 "Telugu" => 88,
1492 "Thaana" => 89,
1493 "Thai" => 90,
1494 "Tibetan" => 91,
1495 "Tifinagh" => 92,
1496 "Ugaritic" => 93,
1497 "Vai" => 94,
1498 "Yi" => 95,
1499 # Win8/Win8.1
1500 "Chakma" => 96,
1501 "Meroitic_Cursive" => 97,
1502 "Meroitic_Hieroglyphs" => 98,
1503 "Miao" => 99,
1504 "Sharada" => 100,
1505 "Sora_Sompeng" => 101,
1506 "Takri" => 102,
1507 # Win10
1508 "Bassa_Vah" => 103,
1509 "Caucasian_Albanian" => 104,
1510 "Duployan" => 105,
1511 "Elbasan" => 106,
1512 "Grantha" => 107,
1513 "Khojki" => 108,
1514 "Khudawadi" => 109,
1515 "Linear_A" => 110,
1516 "Mahajani" => 111,
1517 "Manichaean" => 112,
1518 "Mende_Kikakui" => 113,
1519 "Modi" => 114,
1520 "Mro" => 115,
1521 "Nabataean" => 116,
1522 "Old_North_Arabian" => 117,
1523 "Old_Permic" => 118,
1524 "Pahawh_Hmong" => 119,
1525 "Palmyrene" => 120,
1526 "Pau_Cin_Hau" => 121,
1527 "Psalter_Pahlavi" => 122,
1528 "Siddham" => 123,
1529 "Tirhuta" => 124,
1530 "Warang_Citi" => 125,
1531 # Win10 RS1
1532 "Adlam" => 126,
1533 "Ahom" => 127,
1534 "Anatolian_Hieroglyphs" => 128,
1535 "Bhaiksuki" => 129,
1536 "Hatran" => 130,
1537 "Marchen" => 131,
1538 "Multani" => 132,
1539 "Newa" => 133,
1540 "Old_Hungarian" => 134,
1541 "Osage" => 135,
1542 "SignWriting" => 136,
1543 "Tangut" => 137,
1544 # Win10 RS4
1545 "Masaram_Gondi" => 138,
1546 "Nushu" => 139,
1547 "Soyombo" => 140,
1548 "Zanabazar_Square" => 141,
1549 # Win10 1903
1550 "Dogra" => 142,
1551 "Gunjala_Gondi" => 143,
1552 "Hanifi_Rohingya" => 144,
1553 "Makasar" => 145,
1554 "Medefaidrin" => 146,
1555 "Old_Sogdian" => 147,
1556 "Sogdian" => 148,
1559 ################################################################
1560 # dump Script IDs table
1561 sub dump_scripts($)
1563 my $filename = shift;
1564 my $header = $filename;
1565 my @scripts_table;
1566 my $script_index;
1567 my $i;
1569 my $INPUT = open_data_file( $UNIDATA, "Scripts.txt" );
1570 # Fill the table
1571 # Unknown script id is always 0, so undefined scripts are automatically treated as such
1572 while (<$INPUT>)
1574 my $type = "";
1576 next if /^\#/; # skip comments
1577 next if /^\s*$/; # skip empty lines
1578 next if /\x1a/; # skip ^Z
1579 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1581 $type = $2;
1582 if (defined $scripts{$type})
1584 $scripts_table[hex $1] = $scripts{$type};
1586 next;
1588 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1590 $type = $3;
1591 if (defined $scripts{$type})
1593 foreach my $i (hex $1 .. hex $2)
1595 $scripts_table[$i] = $scripts{$type};
1598 next;
1602 close $INPUT;
1604 $header = "$filename.h";
1605 open OUTPUT,">$header.new" or die "Cannot create $header";
1606 print "Building $header\n";
1607 print OUTPUT "/* Unicode Script IDs */\n";
1608 print OUTPUT "/* generated from $UNIDATA/Scripts.txt */\n";
1609 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1611 print OUTPUT "enum unicode_script_id {\n";
1612 foreach my $script (sort { $scripts{$a} <=> $scripts{$b} } keys %scripts)
1614 print OUTPUT " Script_$script = $scripts{$script},\n";
1616 print OUTPUT " Script_LastId = ", (scalar keys %scripts) - 1, "\n";
1617 print OUTPUT "};\n";
1619 close OUTPUT;
1620 save_file($header);
1622 $filename = "$filename.c";
1623 open OUTPUT,">$filename.new" or die "Cannot create $header";
1624 print "Building $filename\n";
1625 print OUTPUT "/* Unicode Script IDs */\n";
1626 print OUTPUT "/* generated from $UNIDATA/Scripts.txt */\n";
1627 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1628 print OUTPUT "#include \"windef.h\"\n\n";
1630 dump_two_level_mapping( "wine_scripts_table", 0, @scripts_table );
1631 close OUTPUT;
1632 save_file($filename);
1635 ################################################################
1636 # dump the BiDi mirroring table
1637 sub dump_mirroring($)
1639 my $filename = shift;
1640 my @mirror_table = ();
1642 my $INPUT = open_data_file( $UNIDATA, "BidiMirroring.txt" );
1643 while (<$INPUT>)
1645 next if /^\#/; # skip comments
1646 next if /^$/; # skip empty lines
1647 next if /\x1a/; # skip ^Z
1648 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9a-fA-F]+)/)
1650 $mirror_table[hex $1] = hex $2;
1651 next;
1653 die "malformed line $_";
1655 close $INPUT;
1657 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1658 print "Building $filename\n";
1659 print OUTPUT "/* Unicode BiDi mirroring */\n";
1660 print OUTPUT "/* generated from $UNIDATA/BidiMirroring.txt */\n";
1661 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1662 print OUTPUT "#include \"windef.h\"\n\n";
1663 dump_case_table( "DECLSPEC_HIDDEN wine_mirror_map", @mirror_table );
1664 close OUTPUT;
1665 save_file($filename);
1668 ################################################################
1669 # dump the Bidi Brackets
1670 sub dump_bracket($)
1672 my $filename = shift;
1673 my @bracket_table;
1675 my $INPUT = open_data_file( $UNIDATA, "BidiBrackets.txt" );
1676 while (<$INPUT>)
1678 next if /^\#/; # skip comments
1679 next if /^\s*$/; # skip empty lines
1680 next if /\x1a/; # skip ^Z
1681 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9a-fA-F]+);\s*([con])/)
1683 my $type = $3;
1684 die "unknown bracket $type" unless defined $bracket_types{$type};
1685 die "characters too distant $1 and $2" if abs(hex($2) - hex($1)) >= 128;
1686 $bracket_table[hex $1] = (hex($2) - hex($1)) % 255;
1687 $bracket_table[hex $1] += $bracket_types{$type} << 8;
1688 next;
1690 die "malformed line $_";
1692 close $INPUT;
1694 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1695 print "Building $filename\n";
1696 print OUTPUT "/* Unicode Bidirectional Bracket table */\n";
1697 print OUTPUT "/* generated from $UNIDATA/BidiBrackets.txt */\n";
1698 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1699 print OUTPUT "#include \"windef.h\"\n\n";
1701 dump_two_level_mapping( "bidi_bracket_table", 0, @bracket_table );
1703 close OUTPUT;
1704 save_file($filename);
1707 ################################################################
1708 # dump the Arabic shaping table
1709 sub dump_shaping($)
1711 my $filename = shift;
1712 my %groups;
1713 my $next_group = 0;
1715 $groups{"No_Joining_Group"} = $next_group++;
1717 my $INPUT = open_data_file( $UNIDATA, "ArabicShaping.txt" );
1718 while (<$INPUT>)
1720 next if /^\#/; # skip comments
1721 next if /^\s*$/; # skip empty lines
1722 next if /\x1a/; # skip ^Z
1723 if (/^\s*([0-9a-fA-F]+)\s*;.*;\s*([RLDCUT])\s*;\s*(\w+)/)
1725 my $type = $2;
1726 my $group = $3;
1727 $groups{$group} = $next_group++ unless defined $groups{$group};
1728 $joining_table[hex $1] = $joining_types{$type} | ($groups{$group} << 8);
1729 next;
1731 die "malformed line $_";
1733 close $INPUT;
1735 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1736 print "Building $filename\n";
1737 print OUTPUT "/* Unicode Arabic shaping */\n";
1738 print OUTPUT "/* generated from $UNIDATA/ArabicShaping.txt */\n";
1739 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1740 print OUTPUT "#include \"windef.h\"\n\n";
1742 dump_two_level_mapping( "wine_shaping_table", 0, @joining_table );
1744 print OUTPUT "\nconst unsigned short DECLSPEC_HIDDEN wine_shaping_forms[256][4] =\n{\n";
1745 for (my $i = 0x600; $i <= 0x6ff; $i++)
1747 printf OUTPUT " { 0x%04x, 0x%04x, 0x%04x, 0x%04x },\n",
1748 ${joining_forms{"isolated"}}[$i] || $i,
1749 ${joining_forms{"final"}}[$i] || $i,
1750 ${joining_forms{"initial"}}[$i] || $i,
1751 ${joining_forms{"medial"}}[$i] || $i;
1753 print OUTPUT "};\n";
1755 close OUTPUT;
1756 save_file($filename);
1759 ################################################################
1760 # dump the Vertical Orientation table
1761 sub dump_vertical($)
1763 my $filename = shift;
1764 my @vertical_table;
1766 my $INPUT = open_data_file( $UNIDATA, "VerticalOrientation.txt" );
1767 while (<$INPUT>)
1769 next if /^\#/; # skip comments
1770 next if /^\s*$/; # skip empty lines
1771 next if /\x1a/; # skip ^Z
1772 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1774 my $type = $2;
1775 die "unknown vertical $type" unless defined $vertical_types{$type};
1776 if (hex $1 < 65536)
1778 $vertical_table[hex $1] = $vertical_types{$type};
1780 next;
1782 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*/)
1784 my $type = $3;
1785 die "unknown vertical $type" unless defined $vertical_types{$type};
1786 foreach my $i (hex $1 .. hex $2)
1788 $vertical_table[$i] = $vertical_types{$type};
1790 next;
1792 die "malformed line $_";
1794 close $INPUT;
1796 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1797 print "Building $filename\n";
1798 print OUTPUT "/* Unicode Vertical Orientation */\n";
1799 print OUTPUT "/* generated from $UNIDATA/VerticalOrientation.txt */\n";
1800 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1801 print OUTPUT "#include \"windef.h\"\n\n";
1803 dump_two_level_mapping( "vertical_orientation_table", $vertical_types{'R'}, @vertical_table );
1805 close OUTPUT;
1806 save_file($filename);
1809 ################################################################
1810 # dump the digit folding tables
1811 sub dump_digit_folding($)
1813 my $filename = shift;
1814 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1815 print "Building $filename\n";
1816 print OUTPUT "/* Unicode digit folding mappings */\n";
1817 print OUTPUT "/* generated from $UNIDATA/UnicodeData.txt */\n";
1818 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1819 print OUTPUT "#include \"windef.h\"\n\n";
1821 dump_case_table( "DECLSPEC_HIDDEN wine_digitmap", @digitmap_table );
1822 print OUTPUT "\n";
1823 dump_case_table( "DECLSPEC_HIDDEN wine_compatmap", @compatmap_table );
1824 close OUTPUT;
1825 save_file($filename);
1829 ################################################################
1830 # dump the case mapping tables
1831 sub dump_case_mappings($)
1833 my $filename = shift;
1834 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1835 print "Building $filename\n";
1836 print OUTPUT "/* Unicode case mappings */\n";
1837 print OUTPUT "/* generated from $UNIDATA/UnicodeData.txt */\n";
1838 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1839 print OUTPUT "#include \"windef.h\"\n\n";
1841 dump_case_table( "wine_casemap_lower", @tolower_table );
1842 print OUTPUT "\n";
1843 dump_case_table( "wine_casemap_upper", @toupper_table );
1844 close OUTPUT;
1845 save_file($filename);
1849 ################################################################
1850 # dump a case mapping table
1851 sub dump_case_table($@)
1853 my ($name,@table) = @_;
1855 # count the number of sub tables that contain something
1856 # also compute the low and upper populated bounds
1858 my @lowerbounds = ( 0, 0 );
1859 my @upperbounds = ( 0, 255 );
1860 my $index = 0;
1861 my @filled = ();
1862 for (my $i = 0; $i < 65536; $i++)
1864 next unless defined $table[$i];
1865 if (!defined $filled[$i >> 8])
1867 $lowerbounds[$index] = $i & 0xff;
1868 $upperbounds[$index] = 0xff - $lowerbounds[$index];
1869 $filled[$i >> 8] = $index * 256 + 512;
1870 $index++;
1872 else
1874 $upperbounds[$index-1] = 0xff - ($i & 0xff);
1876 $table[$i] = ($table[$i] - $i) & 0xffff;
1879 # Collapse blocks upwards if possible
1880 my $removed = 0;
1881 $index = 0;
1882 for (my $i = 0; $i < 256; $i++)
1884 next unless defined $filled[$i];
1885 if ($upperbounds[$index - 1] > $lowerbounds[$index])
1887 $removed = $removed + $lowerbounds[$index];
1889 else
1891 $removed = $removed + $upperbounds[$index - 1];
1892 $lowerbounds[$index] = $upperbounds[$index - 1];
1894 $filled[$i] = $filled[$i] - $removed;
1895 $index++;
1898 # dump the table
1900 printf OUTPUT "const WCHAR %s[%d] =\n", $name, $index * 256 + 512 - $removed;
1901 printf OUTPUT "{\n /* index */\n";
1902 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%04x", 256, @filled );
1903 printf OUTPUT " /* defaults */\n";
1904 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, (0) x 256 );
1905 $index = 0;
1906 for (my $i = 0; $i < 256; $i++)
1908 next unless $filled[$i];
1909 printf OUTPUT ",\n /* 0x%02x%02x .. 0x%02xff */\n", $i, $lowerbounds[$index], $i;
1910 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0,
1911 @table[($i<<8) + $lowerbounds[$index] .. ($i<<8)+255] );
1912 $index++;
1914 printf OUTPUT "\n};\n";
1917 ################################################################
1918 # compress a mapping table by removing identical rows
1919 sub compress_array($$@)
1921 my $rows = shift;
1922 my $def = shift;
1923 my @table = @_;
1924 my $len = @table / $rows;
1925 my @array = (0) x $rows;
1926 my %sequences;
1928 # try to merge table rows
1929 for (my $row = 0; $row < $rows; $row++)
1931 my @table_row = map { defined($_) ? $_ : $def; } @table[($row * $len)..($row * $len + $len - 1)];
1932 my $rowtxt = pack "S*", @table_row;
1933 if (defined($sequences{$rowtxt}))
1935 # reuse an existing row
1936 $array[$row] = $sequences{$rowtxt};
1938 else
1940 # create a new row
1941 $sequences{$rowtxt} = $array[$row] = $#array + 1;
1942 push @array, @table_row;
1945 return @array;
1948 ################################################################
1949 # dump a simple char -> 16-bit value mapping table
1950 sub dump_simple_mapping($$@)
1952 my $name = shift;
1953 my $def = shift;
1954 my @array = compress_array( 256, $def, @_[0..65535] );
1956 printf OUTPUT "const unsigned short %s[%d] =\n{\n", $name, $#array+1;
1957 printf OUTPUT " /* offsets */\n%s,\n", DUMP_ARRAY( "0x%04x", 0, @array[0..255] );
1958 printf OUTPUT " /* values */\n%s\n};\n", DUMP_ARRAY( "0x%04x", 0, @array[256..$#array] );
1961 ################################################################
1962 # dump a char -> 16-bit value mapping table using two-level tables
1963 sub dump_two_level_mapping($$@)
1965 my $name = shift;
1966 my $def = shift;
1967 my @row_array = compress_array( 4096, $def, @_[0..65535] );
1968 my @array = compress_array( 256, 0, @row_array[0..4095] );
1970 for (my $i = 256; $i < @array; $i++) { $array[$i] += @array - 4096; }
1972 printf OUTPUT "const unsigned short DECLSPEC_HIDDEN %s[%d] =\n{\n", $name, @array + @row_array - 4096;
1973 printf OUTPUT " /* level 1 offsets */\n%s,\n", DUMP_ARRAY( "0x%04x", 0, @array[0..255] );
1974 printf OUTPUT " /* level 2 offsets */\n%s,\n", DUMP_ARRAY( "0x%04x", 0, @array[256..$#array] );
1975 printf OUTPUT " /* values */\n%s\n};\n", DUMP_ARRAY( "0x%04x", 0, @row_array[4096..$#row_array] );
1978 ################################################################
1979 # dump a binary case mapping table in l_intl.nls format
1980 sub dump_binary_case_table(@)
1982 my (@table) = @_;
1984 my %difftables_hash = ();
1985 my @difftables;
1986 my %offtables2_hash = ();
1987 my @offtables2 = ();
1989 my @offtable = ();
1990 for (my $i = 0; $i < 256; $i++)
1992 my @offtable2 = ();
1993 for(my $j = 0; $j < 16; $j++) # offset table for xx00-xxFF characters
1995 my @difftable;
1996 for (my $k = 0; $k < 16; $k++) # case map table for xxx0-xxxF characters
1998 my $char = ($i<<8) + ($j<<4) + $k;
1999 $difftable[$k] = (defined $table[$char]) ? (($table[$char]-$char) & 0xffff) : 0;
2002 my $diff_key = pack "S*", @difftable;
2003 my $offset3 = $difftables_hash{$diff_key};
2004 if (!defined $offset3)
2006 $offset3 = scalar @difftables;
2007 $difftables_hash{$diff_key} = $offset3;
2008 push @difftables, @difftable;
2010 $offtable2[$j] = $offset3;
2013 my $offtable2_key = pack "S*", @offtable2;
2014 my $offset2 = $offtables2_hash{$offtable2_key};
2015 if (!defined $offset2)
2017 $offset2 = scalar @offtables2;
2018 $offtables2_hash{$offtable2_key} = $offset2;
2019 push @offtables2, \@offtable2;
2021 $offtable[$i] = $offset2;
2024 my @output;
2025 my $offset = 0x100; # offset of first subtable in words
2026 foreach (@offtable)
2028 push @output, 0x10 * $_ + $offset; # offset of subtable in words
2031 $offset = 0x100 + 0x10 * scalar @offtables2; # offset of first difftable in words
2032 foreach(@offtables2)
2034 my $table = $_;
2035 foreach(@$table)
2037 push @output, $_ + $offset; # offset of difftable in words
2041 my $len = 1 + scalar @output + scalar @difftables;
2042 return pack "S<*", $len, @output, @difftables;
2046 ################################################################
2047 # dump case mappings for l_intl.nls
2048 sub dump_intl_nls($)
2050 my $filename = shift;
2051 open OUTPUT,">$filename.new" or die "Cannot create $filename";
2052 printf "Building $filename\n";
2054 binmode OUTPUT;
2055 print OUTPUT pack "S<", 1; # version
2056 print OUTPUT dump_binary_case_table( @toupper_table );
2057 print OUTPUT dump_binary_case_table( @tolower_table );
2058 close OUTPUT;
2059 save_file($filename);
2063 sub load_nameprep_range_table($$$)
2065 my ($INPUT, $val, $table_ref) = @_;
2067 while (<$INPUT>)
2069 if (/^\s*([0-9a-fA-F]+)-([0-9a-fA-F]+)/)
2071 my $last = hex $2;
2072 $last = 65535 if($last >= 65536);
2073 foreach my $i (hex $1 .. $last)
2075 $table_ref->[$i] |= $val;
2077 next;
2079 elsif (/^\s*([0-9a-fA-F]+)/)
2081 if (hex $1 < 65536)
2083 $table_ref->[hex $1] |= $val;
2085 next;
2088 return if (/End\sTable/);
2092 sub load_nameprep_map_table($$)
2094 my ($INPUT, $table_ref) = @_;
2096 while (<$INPUT>)
2098 if (/^\s*([0-9a-fA-F]+);\s;/)
2100 # special value for map to nothing
2101 $table_ref->[hex $1] = [0xffff, 0xffff, 0xffff];
2102 next;
2104 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+);/)
2106 $table_ref->[hex $1] = [hex $2, 0, 0];
2107 next;
2109 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+)\s([0-9a-fA-F]+);/)
2111 $table_ref->[hex $1] = [hex $2, hex $3, 0];
2112 next;
2114 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+)\s([0-9a-fA-F]+)\s([0-9a-fA-F]+);/)
2116 $table_ref->[hex $1] = [hex $2, hex $3, hex $4];
2117 next;
2120 return if (/End\sTable/);
2124 ################################################################
2125 # dump mapping table, prohibited characters set, unassigned
2126 # characters, bidirectional rules used by nameprep algorithm
2127 sub dump_nameprep($)
2129 my $filename = shift;
2130 my @mapping_table = ();
2131 my @flags_table;
2133 my $INPUT = open_data_file( $RFCS, $STRINGPREP );
2134 while (<$INPUT>)
2136 next unless /Start\sTable/;
2138 load_nameprep_range_table($INPUT, $nameprep_flags{"unassigned"}, \@flags_table) if (/A.1/);
2139 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.1.2/);
2140 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.2.2/);
2141 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.3/);
2142 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.4/);
2143 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.5/);
2144 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.6/);
2145 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.7/);
2146 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.8/);
2147 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.9/);
2148 load_nameprep_range_table($INPUT, $nameprep_flags{"bidi_ral"}, \@flags_table) if (/D.1/);
2149 load_nameprep_range_table($INPUT, $nameprep_flags{"bidi_l"}, \@flags_table) if (/D.2/);
2151 load_nameprep_map_table($INPUT, \@mapping_table) if (/B.1/);
2152 load_nameprep_map_table($INPUT, \@mapping_table) if (/B.2/);
2154 close $INPUT;
2156 open OUTPUT,">$filename.new" or die "Cannot create $filename";
2157 print "Building $filename\n";
2158 print OUTPUT "/* Nameprep algorithm related data */\n";
2159 print OUTPUT "/* generated from $RFCS/$STRINGPREP */\n";
2160 print OUTPUT "/* DO NOT EDIT!! */\n\n";
2161 print OUTPUT "#include \"windef.h\"\n\n";
2163 dump_two_level_mapping( "nameprep_char_type", 0, @flags_table );
2165 ######### mapping table
2166 # first determine all the 16-char subsets that contain something
2167 my @filled = ();
2168 my $pos = 16*3; # for the null subset
2169 for (my $i = 0; $i < 65536; $i++)
2171 next unless defined $mapping_table[$i];
2172 $filled[$i >> 4] = $pos;
2173 $pos += 16*3;
2174 $i |= 15;
2176 my $total = $pos;
2178 # now count the 256-char subsets that contain something
2179 my @filled_idx = (256) x 256;
2180 $pos = 256 + 16;
2181 for (my $i = 0; $i < 4096; $i++)
2183 next unless $filled[$i];
2184 $filled_idx[$i >> 4] = $pos;
2185 $pos += 16;
2186 $i |= 15;
2188 my $null_offset = $pos;
2189 $total += $pos;
2191 # add the index offsets to the subsets positions
2192 for (my $i = 0; $i < 4096; $i++)
2194 next unless $filled[$i];
2195 $filled[$i] += $null_offset;
2198 # dump the main index
2199 printf OUTPUT "const unsigned short DECLSPEC_HIDDEN nameprep_mapping[%d] =\n", $total;
2200 printf OUTPUT "{\n /* index */\n";
2201 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @filled_idx );
2202 printf OUTPUT ",\n /* null sub-index */\n%s", DUMP_ARRAY( "0x%04x", 0, ($null_offset) x 16 );
2204 # dump the second-level indexes
2205 for (my $i = 0; $i < 256; $i++)
2207 next unless ($filled_idx[$i] > 256);
2208 my @table = @filled[($i<<4)..($i<<4)+15];
2209 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
2210 printf OUTPUT ",\n /* sub-index %02x */\n", $i;
2211 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
2214 # dump the 16-char subsets
2215 printf OUTPUT ",\n /* null mapping */\n";
2216 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, (0) x 48 );
2218 for (my $i = 0; $i < 4096; $i++)
2220 next unless $filled[$i];
2221 my @table = (0) x 48;
2222 for (my $j = 0; $j < 16; $j++)
2224 if (defined $mapping_table[($i<<4) + $j])
2226 $table[3 * $j] = ${$mapping_table[($i << 4) + $j]}[0];
2227 $table[3 * $j + 1] = ${$mapping_table[($i << 4) + $j]}[1];
2228 $table[3 * $j + 2] = ${$mapping_table[($i << 4) + $j]}[2];
2231 printf OUTPUT ",\n /* 0x%03x0 .. 0x%03xf */\n", $i, $i;
2232 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
2235 printf OUTPUT "\n};\n";
2237 close OUTPUT;
2238 save_file($filename);
2242 ################################################################
2243 # dump the GetStringTypeW table
2244 sub dump_string_type_table($)
2246 my $filename = shift;
2247 open OUTPUT,">$filename.new" or die "Cannot create $filename";
2248 printf "Building $filename\n";
2249 printf OUTPUT "/* Unicode wctype table */\n";
2250 printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
2251 printf OUTPUT "#include \"windef.h\"\n\n";
2253 my @table = @category_table;
2255 # add the direction in the high 4 bits of the category
2256 for (my $i = 0; $i < 65536; $i++)
2258 $table[$i] |= $c2_types{$direction_table[$i]} << 12 if defined $direction_table[$i];
2261 dump_two_level_mapping( "wctype_table", 0, @table );
2263 close OUTPUT;
2264 save_file($filename);
2268 ################################################################
2269 # dump the bidi direction table
2270 sub dump_bidi_dir_table($)
2272 my $filename = shift;
2273 open OUTPUT,">$filename.new" or die "Cannot create $filename";
2274 printf "Building $filename\n";
2275 printf OUTPUT "/* Unicode BiDi direction table */\n";
2276 printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
2277 printf OUTPUT "#include \"windef.h\"\n\n";
2279 my @table;
2281 for (my $i = 0; $i < 65536; $i++)
2283 $table[$i] = $bidi_types{$direction_table[$i]} if defined $direction_table[$i];
2286 dump_two_level_mapping( "bidi_direction_table", $bidi_types{"L"}, @table );
2288 close OUTPUT;
2289 save_file($filename);
2293 ################################################################
2294 # dump the ctype tables
2295 sub dump_ctype_tables($)
2297 my $filename = shift;
2298 open OUTPUT,">$filename.new" or die "Cannot create $filename";
2299 printf "Building $filename\n";
2300 printf OUTPUT "/* Unicode ctype tables */\n";
2301 printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
2302 printf OUTPUT "#include \"windef.h\"\n\n";
2304 my @table = @category_table;
2306 # add the direction in the high 4 bits of the category
2307 for (my $i = 0; $i < 65536; $i++)
2309 $table[$i] |= $directions{$direction_table[$i]} << 12 if defined $direction_table[$i];
2312 dump_simple_mapping( "wine_wctype_table", 0, @table );
2314 close OUTPUT;
2315 save_file($filename);
2319 ################################################################
2320 # dump the char composition table
2321 sub dump_compose_table($)
2323 my $filename = shift;
2325 open OUTPUT,">$filename.new" or die "Cannot create $filename";
2326 print "Building $filename\n";
2327 print OUTPUT "/* Unicode char composition */\n";
2328 print OUTPUT "/* generated from $UNIDATA/UnicodeData.txt */\n";
2329 print OUTPUT "/* DO NOT EDIT!! */\n\n";
2330 print OUTPUT "#include \"windef.h\"\n\n";
2332 my @filled = ();
2333 foreach my $i (@compose_table)
2335 my @comp = @$i;
2336 push @{$filled[$comp[1]]}, [ $comp[0], $comp[2] ];
2339 # count how many different second chars we have
2341 my $count = 0;
2342 for (my $i = 0; $i < 65536; $i++)
2344 next unless defined $filled[$i];
2345 $count++;
2348 # build the table of second chars and offsets
2350 my $pos = $count + 1;
2351 my @table = ();
2352 for (my $i = 0; $i < 65536; $i++)
2354 next unless defined $filled[$i];
2355 push @table, $i, $pos;
2356 $pos += @{$filled[$i]};
2358 # terminator with last position
2359 push @table, 0, $pos;
2360 printf OUTPUT "static const WCHAR table[0x%x] =\n{\n", 2*$pos;
2361 printf OUTPUT " /* second chars + offsets */\n%s", DUMP_ARRAY( "0x%04x", 0, @table );
2363 # build the table of first chars and mappings
2365 for (my $i = 0; $i < 65536; $i++)
2367 next unless defined $filled[$i];
2368 my @table = ();
2369 my @list = sort { $a->[0] <=> $b->[0] } @{$filled[$i]};
2370 for (my $j = 0; $j <= $#list; $j++)
2372 push @table, $list[$j][0], $list[$j][1];
2374 printf OUTPUT ",\n /* 0x%04x */\n%s", $i, DUMP_ARRAY( "0x%04x", 0, @table );
2376 print OUTPUT "\n};\n\n";
2377 print OUTPUT <<"EOF";
2378 static inline int binary_search( WCHAR ch, int low, int high )
2380 while (low <= high)
2382 int pos = (low + high) / 2;
2383 if (table[2 * pos] < ch) low = pos + 1;
2384 else if (table[2 * pos] > ch) high = pos - 1;
2385 else return pos;
2387 return -1;
2390 WCHAR DECLSPEC_HIDDEN wine_compose( const WCHAR *str )
2392 int pos, idx = 1, start = 0, count = $count;
2393 for (;;)
2395 if ((pos = binary_search( str[idx], start, count - 1 )) == -1) return 0;
2396 if (!idx--) return table[2 * pos + 1];
2397 start = table[2 * pos + 1];
2398 count = table[2 * pos + 3];
2402 close OUTPUT;
2403 save_file($filename);
2406 sub dump_full_compat_table()
2408 # first determine all the 16-char subsets that contain something
2410 my @filled = (0) x 4096;
2411 my $pos = 16; # for the null subset
2412 my $data_total = 0;
2413 for (my $i = 0; $i < 65536; $i++)
2415 next unless defined $full_compatmap_table[$i];
2416 if ($filled[$i >> 4] == 0)
2418 $filled[$i >> 4] = $pos;
2419 $pos += 16;
2421 $data_total += $#{$full_compatmap_table[$i]} + 1;
2423 my $total = $pos;
2425 # now count the 256-char subsets that contain something
2427 my @filled_idx = (256) x 256;
2428 $pos = 256 + 16;
2429 for (my $i = 0; $i < 4096; $i++)
2431 next unless $filled[$i];
2432 $filled_idx[$i >> 4] = $pos;
2433 $pos += 16;
2434 $i |= 15;
2436 my $null_offset = $pos; # null mapping
2437 $total += $pos + 1; # add the offset sentinel
2439 # add the index offsets to the subsets positions
2441 for (my $i = 0; $i < 4096; $i++)
2443 next unless $filled[$i];
2444 $filled[$i] += $null_offset;
2447 # dump the main index
2449 printf OUTPUT "static const WCHAR compatmap_table[%d] =\n", $total + $data_total;
2450 printf OUTPUT "{\n /* index */\n";
2451 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @filled_idx );
2452 printf OUTPUT ",\n /* null sub-index */\n%s", DUMP_ARRAY( "0x%04x", 0, ($null_offset) x 16 );
2454 # dump the second-level indexes
2456 for (my $i = 0; $i < 256; $i++)
2458 next unless ($filled_idx[$i] > 256);
2459 my @table = @filled[($i<<4)..($i<<4)+15];
2460 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
2461 printf OUTPUT ",\n /* sub-index %02x */\n", $i;
2462 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
2465 # dump the 16-char offsets
2467 printf OUTPUT ",\n /* null offsets */\n";
2468 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, ($total) x (16) );
2470 $pos = $total;
2472 my @data;
2473 for (my $i = 0; $i < 4096; $i++)
2475 next unless $filled[$i];
2476 my @table = (0) x (16);
2477 for (my $j = 0; $j < 16; $j++)
2479 $table[$j] = $pos;
2480 if (defined $full_compatmap_table[($i<<4) + $j])
2482 $pos += $#{$full_compatmap_table[($i<<4) + $j]} + 1;
2483 push @data, @{$full_compatmap_table[($i<<4) + $j]};
2486 printf OUTPUT ",\n /* offsets 0x%03x0 .. 0x%03xf */\n", $i, $i;
2487 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
2490 my @sentinel = $pos;
2491 printf OUTPUT ",\n /* offset sentinel */\n";
2492 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @sentinel );
2494 printf OUTPUT ",\n /* data */\n";
2495 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @data );
2497 printf OUTPUT "\n};\n\n";
2500 ################################################################
2501 # dump the char decomposition table
2502 sub dump_decompose_table($)
2504 my $filename = shift;
2506 open OUTPUT,">$filename.new" or die "Cannot create $filename";
2507 print "Building $filename\n";
2508 print OUTPUT "/* Unicode char composition */\n";
2509 print OUTPUT "/* generated from $UNIDATA/UnicodeData.txt */\n";
2510 print OUTPUT "/* DO NOT EDIT!! */\n\n";
2511 print OUTPUT "#include \"wine/unicode.h\"\n\n";
2513 # first determine all the 16-char subsets that contain something
2515 my @filled = (0) x 4096;
2516 my $pos = 16*2; # for the null subset
2517 for (my $i = 0; $i < 65536; $i++)
2519 next unless defined $decomp_table[$i];
2520 $filled[$i >> 4] = $pos;
2521 $pos += 16*2;
2522 $i |= 15;
2524 my $total = $pos;
2526 # now count the 256-char subsets that contain something
2528 my @filled_idx = (256) x 256;
2529 $pos = 256 + 16;
2530 for (my $i = 0; $i < 4096; $i++)
2532 next unless $filled[$i];
2533 $filled_idx[$i >> 4] = $pos;
2534 $pos += 16;
2535 $i |= 15;
2537 my $null_offset = $pos; # null mapping
2538 $total += $pos;
2540 # add the index offsets to the subsets positions
2542 for (my $i = 0; $i < 4096; $i++)
2544 next unless $filled[$i];
2545 $filled[$i] += $null_offset;
2548 # dump the main index
2550 printf OUTPUT "static const WCHAR table[%d] =\n", $total;
2551 printf OUTPUT "{\n /* index */\n";
2552 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @filled_idx );
2553 printf OUTPUT ",\n /* null sub-index */\n%s", DUMP_ARRAY( "0x%04x", 0, ($null_offset) x 16 );
2555 # dump the second-level indexes
2557 for (my $i = 0; $i < 256; $i++)
2559 next unless ($filled_idx[$i] > 256);
2560 my @table = @filled[($i<<4)..($i<<4)+15];
2561 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
2562 printf OUTPUT ",\n /* sub-index %02x */\n", $i;
2563 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
2566 # dump the 16-char subsets
2568 printf OUTPUT ",\n /* null mapping */\n";
2569 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, (0) x 32 );
2571 for (my $i = 0; $i < 4096; $i++)
2573 next unless $filled[$i];
2574 my @table = (0) x 32;
2575 for (my $j = 0; $j < 16; $j++)
2577 if (defined $decomp_table[($i<<4) + $j])
2579 $table[2 * $j] = ${$decomp_table[($i << 4) + $j]}[0];
2580 $table[2 * $j + 1] = ${$decomp_table[($i << 4) + $j]}[1];
2583 printf OUTPUT ",\n /* 0x%03x0 .. 0x%03xf */\n", $i, $i;
2584 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
2587 printf OUTPUT "\n};\n\n";
2589 dump_full_compat_table();
2591 print OUTPUT <<"EOF";
2592 static const WCHAR *get_compatmap_entry( WCHAR ch, unsigned int *len )
2594 unsigned short offset_offs = compatmap_table[compatmap_table[ch >> 8] + ((ch >> 4) & 0xf)] + (ch & 0xf);
2595 unsigned short start = compatmap_table[offset_offs];
2596 unsigned short end = compatmap_table[offset_offs + 1];
2598 if (end > start)
2600 *len = end - start;
2601 return compatmap_table + start;
2604 return NULL;
2607 unsigned int DECLSPEC_HIDDEN wine_decompose( int flags, WCHAR ch, WCHAR *dst, unsigned int dstlen )
2609 const WCHAR *ptr = NULL;
2610 unsigned int res, len, dst_pos = 0;
2612 *dst = ch;
2614 if (flags & WINE_DECOMPOSE_COMPAT)
2615 ptr = get_compatmap_entry( ch, &len );
2617 if (!ptr)
2619 ptr = table + table[table[ch >> 8] + ((ch >> 4) & 0x0f)] + 2 * (ch & 0xf);
2620 len = ptr[1] ? 2 : 1;
2623 if (!*ptr) return 1;
2624 if (dstlen < len) return 0;
2625 /* apply the decomposition recursively */
2626 while (len--)
2628 if (!(res = wine_decompose( flags, *ptr++, dst + dst_pos, dstlen - dst_pos - len ))) return 0;
2629 dst_pos += res;
2632 return dst_pos;
2635 close OUTPUT;
2636 save_file($filename);
2639 ################################################################
2640 # dump the combining class table
2641 sub dump_combining_class($)
2643 my $filename = shift;
2645 open OUTPUT,">$filename.new" or die "Cannot create $filename";
2646 print "Building $filename\n";
2647 print OUTPUT "/* Unicode Combining Classes */\n";
2648 print OUTPUT "/* generated from $UNIDATA/UnicodeData.txt */\n";
2649 print OUTPUT "/* DO NOT EDIT!! */\n\n";
2650 print OUTPUT "#include \"windef.h\"\n\n";
2652 dump_two_level_mapping( "combining_class_table", 0, @combining_class_table );
2653 close OUTPUT;
2654 save_file($filename);
2657 ################################################################
2658 # output a codepage definition file from the global tables
2659 sub output_codepage_file($$$$)
2661 my ($codepage, $filename, $comment, $has_glyphs) = @_;
2663 my $output = sprintf "libs/port/c_%03d.c", $codepage;
2664 open OUTPUT,">$output.new" or die "Cannot create $output";
2666 printf "Building %s from %s (%s)\n", $output, $filename || "hardcoded data", $comment;
2668 # dump all tables
2670 printf OUTPUT "/* code page %03d (%s) */\n", $codepage, $comment;
2671 if ($filename)
2673 print OUTPUT "/* generated from $MAPPINGS/$filename */\n";
2674 print OUTPUT "/* DO NOT EDIT!! */\n\n";
2676 else
2678 printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
2680 printf OUTPUT "#include \"wine/unicode.h\"\n\n";
2682 if (!@lead_bytes) { dump_sbcs_table( $codepage, $has_glyphs, $comment, $default_char, $default_wchar ); }
2683 else { dump_dbcs_table( $codepage, $comment, $default_char, $default_wchar, get_lb_ranges() ); }
2684 close OUTPUT;
2685 save_file($output);
2688 ################################################################
2689 # read a "bestfit" Windows mapping file
2690 sub read_bestfit_file($)
2692 my ($filename) = @_;
2693 my $state = "";
2694 my ($codepage, $width, $count);
2695 my ($lb_cur, $lb_end);
2697 my $INPUT = open_data_file( $MAPPINGS, $filename ) or die "Cannot open $filename";
2699 while (<$INPUT>)
2701 next if /^;/; # skip comments
2702 next if /^\s*$/; # skip empty lines
2703 next if /\x1a/; # skip ^Z
2704 last if /^ENDCODEPAGE/;
2706 if (/^CODEPAGE\s+(\d+)/)
2708 $codepage = $1;
2709 next;
2711 if (/^CPINFO\s+(\d+)\s+0x([0-9a-fA-f]+)\s+0x([0-9a-fA-F]+)/)
2713 $width = $1;
2714 $default_char = hex $2;
2715 $default_wchar = hex $3;
2716 next;
2718 if (/^(MBTABLE|WCTABLE|DBCSRANGE|DBCSTABLE)\s+(\d+)/)
2720 $state = $1;
2721 $count = $2;
2722 next;
2724 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)/)
2726 if ($state eq "MBTABLE")
2728 my $cp = hex $1;
2729 my $uni = hex $2;
2730 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
2731 next;
2733 if ($state eq "WCTABLE")
2735 my $uni = hex $1;
2736 my $cp = hex $2;
2737 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
2738 next;
2740 if ($state eq "DBCSRANGE")
2742 my $start = hex $1;
2743 my $end = hex $2;
2744 for (my $i = $start; $i <= $end; $i++) { add_lead_byte( $i ); }
2745 $lb_cur = $start;
2746 $lb_end = $end;
2747 next;
2749 if ($state eq "DBCSTABLE")
2751 my $mb = hex $1;
2752 my $uni = hex $2;
2753 my $cp = ($lb_cur << 8) | $mb;
2754 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
2755 if (!--$count)
2757 if (++$lb_cur > $lb_end) { $state = "DBCSRANGE"; }
2759 next;
2762 die "$filename: Unrecognized line $_\n";
2764 close $INPUT;
2768 ################################################################
2769 # read an input file and generate the corresponding .c file
2770 sub HANDLE_FILE(@)
2772 my ($codepage,$filename,$has_glyphs,$comment,$first_private,$def,$defw) = @_;
2774 @cp2uni = ();
2775 @lead_bytes = ();
2776 @uni2cp = ();
2777 $default_char = $def || $DEF_CHAR;
2778 $default_wchar = $defw || $DEF_CHAR;
2780 # some codepage files are special
2781 if ($codepage == 20932)
2783 READ_JIS0208_FILE( $filename );
2784 add_default_mappings( $first_private );
2786 elsif ($codepage == 20127)
2788 fill_20127_codepage();
2789 add_default_mappings( $first_private );
2791 elsif ($filename =~ /\/bestfit/)
2793 read_bestfit_file( $filename );
2795 else
2797 read_codepage_file( $filename );
2798 if ($codepage == 10001)
2800 # add Shift-JIS mappings
2801 read_bestfit_file( "VENDORS/MICSFT/WindowsBestFit/bestfit932.txt" );
2803 else
2805 add_default_mappings( $first_private );
2809 output_codepage_file( $codepage, $filename, $comment, $has_glyphs );
2813 ################################################################
2814 # save a file if modified
2815 sub save_file($)
2817 my $file = shift;
2818 if (-f $file && !system "cmp $file $file.new >/dev/null")
2820 unlink "$file.new";
2822 else
2824 rename "$file.new", "$file";
2829 ################################################################
2830 # output the list of codepage tables into the cptable.c file
2831 sub output_cptable($)
2833 my $output = shift;
2834 my @tables_decl = ();
2836 printf "Building %s\n", $output;
2838 foreach my $file (@allfiles)
2840 my ($codepage,$filename) = @$file;
2841 push @tables_decl, sprintf("extern union cptable cptable_%03d;\n",$codepage);
2844 push @tables_decl, sprintf("\nstatic const union cptable * const cptables[%d] =\n{\n",$#allfiles+1);
2845 foreach my $file (@allfiles)
2847 my ($codepage,$filename) = @$file;
2848 push @tables_decl, sprintf(" &cptable_%03d,\n", $codepage);
2850 push @tables_decl, "};";
2851 REPLACE_IN_FILE( $output, @tables_decl );
2854 ################################################################
2855 # replace the contents of a file between ### cpmap ### marks
2857 sub REPLACE_IN_FILE($@)
2859 my $name = shift;
2860 my @data = @_;
2861 my @lines = ();
2862 open(FILE,$name) or die "Can't open $name";
2863 while (<FILE>)
2865 push @lines, $_;
2866 last if /\#\#\# cpmap begin \#\#\#/;
2868 push @lines, @data;
2869 while (<FILE>)
2871 if (/\#\#\# cpmap end \#\#\#/) { push @lines, "\n", $_; last; }
2873 push @lines, <FILE>;
2874 open(FILE,">$name.new") or die "Can't modify $name";
2875 print FILE @lines;
2876 close(FILE);
2877 save_file($name);
2880 ################################################################
2881 # main routine
2883 chdir ".." if -f "./make_unicode";
2884 READ_DEFAULTS( $DEFAULTS );
2885 dump_case_mappings( "libs/port/casemap.c" );
2886 dump_sortkeys( "libs/port/collation.c", READ_SORTKEYS_FILE() );
2887 dump_compose_table( "libs/port/compose.c" );
2888 dump_decompose_table( "libs/port/decompose.c" );
2889 dump_ctype_tables( "libs/port/wctype.c" );
2890 dump_bidi_dir_table( "dlls/gdi32/direction.c" );
2891 dump_bidi_dir_table( "dlls/usp10/direction.c" );
2892 dump_bidi_dir_table( "dlls/dwrite/direction.c" );
2893 dump_string_type_table( "dlls/kernel32/wctype.c" );
2894 dump_digit_folding( "libs/port/digitmap.c" );
2895 dump_combining_class( "libs/port/combclass.c" );
2896 dump_mirroring( "dlls/usp10/mirror.c" );
2897 dump_mirroring( "dlls/dwrite/mirror.c" );
2898 dump_bracket( "dlls/usp10/bracket.c" );
2899 dump_bracket( "dlls/dwrite/bracket.c" );
2900 dump_shaping( "dlls/usp10/shaping.c" );
2901 dump_linebreak( "dlls/usp10/linebreak.c" );
2902 dump_linebreak( "dlls/dwrite/linebreak.c" );
2903 dump_scripts( "dlls/dwrite/scripts" );
2904 dump_indic( "dlls/usp10/indicsyllable.c" );
2905 dump_intl_nls("loader/l_intl.nls");
2906 dump_vertical( "dlls/gdi32/vertical.c" );
2907 dump_vertical( "dlls/wineps.drv/vertical.c" );
2908 dump_nameprep( "dlls/kernel32/nameprep.c" );
2910 foreach my $file (@allfiles) { HANDLE_FILE( @{$file} ); }
2912 output_cptable("libs/port/cptable.c");
2914 exit 0;
2916 # Local Variables:
2917 # compile-command: "./make_unicode"
2918 # End: