shell32: Add network icon.
[wine.git] / tools / make_unicode
blob56d190565677399562a0826614367a7a9f80c19b
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/11.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 [ 28603, "ISO8859/8859-13.TXT", 0, "ISO 8859-13 Latin 7 (Baltic)" ],
113 [ 28604, "ISO8859/8859-14.TXT", 0, "ISO 8859-14 Latin 8 (Celtic)" ],
114 [ 28605, "ISO8859/8859-15.TXT", 0, "ISO 8859-15 Latin 9 (Euro)" ],
115 [ 28606, "ISO8859/8859-16.TXT", 0, "ISO 8859-16 Latin 10 (Balkan)" ]
119 my %ctype =
121 "upper" => 0x0001,
122 "lower" => 0x0002,
123 "digit" => 0x0004,
124 "space" => 0x0008,
125 "punct" => 0x0010,
126 "cntrl" => 0x0020,
127 "blank" => 0x0040,
128 "xdigit" => 0x0080,
129 "alpha" => 0x0100,
130 "defin" => 0x0200
133 my %bracket_types =
135 "o" => 0x0000,
136 "c" => 0x0001,
139 my %indic_types =
141 "Other" => 0x0000,
142 "Bindu" => 0x0001,
143 "Visarga" => 0x0002,
144 "Avagraha" => 0x0003,
145 "Nukta" => 0x0004,
146 "Virama" => 0x0005,
147 "Vowel_Independent" => 0x0006,
148 "Vowel_Dependent" => 0x0007,
149 "Vowel" => 0x0008,
150 "Consonant_Placeholder" => 0x0009,
151 "Consonant" => 0x000a,
152 "Consonant_Dead" => 0x000b,
153 "Consonant_Succeeding_Repha" => 0x000c,
154 "Consonant_Subjoined" => 0x000d,
155 "Consonant_Medial" => 0x000e,
156 "Consonant_Final" => 0x000f,
157 "Consonant_Head_Letter" => 0x0010,
158 "Modifying_Letter" => 0x0011,
159 "Tone_Letter" => 0x0012,
160 "Tone_Mark" => 0x0013,
161 "Register_Shifter" => 0x0014,
162 "Consonant_Preceding_Repha" => 0x0015,
163 "Pure_Killer" => 0x0016,
164 "Invisible_Stacker" => 0x0017,
165 "Gemination_Mark" => 0x0018,
166 "Cantillation_Mark" => 0x0019,
167 "Non_Joiner" => 0x001a,
168 "Joiner" => 0x001b,
169 "Number_Joiner" => 0x001c,
170 "Number" => 0x001d,
171 "Brahmi_Joining_Number" => 0x001e,
172 "Consonant_With_Stacker" => 0x001f,
173 "Consonant_Prefixed" => 0x0020,
174 "Syllable_Modifier" => 0x0021,
175 "Consonant_Killer" => 0x0022,
176 "Consonant_Initial_Postfixed" => 0x0023,
179 my %matra_types =
181 "Right" => 0x01,
182 "Left" => 0x02,
183 "Visual_Order_Left" => 0x03,
184 "Left_And_Right" => 0x04,
185 "Top" => 0x05,
186 "Bottom" => 0x06,
187 "Top_And_Bottom" => 0x07,
188 "Top_And_Right" => 0x08,
189 "Top_And_Left" => 0x09,
190 "Top_And_Left_And_Right" => 0x0a,
191 "Bottom_And_Right" => 0x0b,
192 "Top_And_Bottom_And_Right" => 0x0c,
193 "Overstruck" => 0x0d,
194 "Invisible" => 0x0e,
195 "Bottom_And_Left" => 0x0f
198 my %nameprep_flags =
200 "unassigned" => 0x01,
201 "prohibited" => 0x02,
202 "bidi_ral" => 0x04,
203 "bidi_l" => 0x08
206 my %break_types =
208 "BK" => 0x0001,
209 "CR" => 0x0002,
210 "LF" => 0x0003,
211 "CM" => 0x0004,
212 "SG" => 0x0005,
213 "GL" => 0x0006,
214 "CB" => 0x0007,
215 "SP" => 0x0008,
216 "ZW" => 0x0009,
217 "NL" => 0x000a,
218 "WJ" => 0x000b,
219 "JL" => 0x000c,
220 "JV" => 0x000d,
221 "JT" => 0x000e,
222 "H2" => 0x000f,
223 "H3" => 0x0010,
224 "XX" => 0x0011,
225 "OP" => 0x0012,
226 "CL" => 0x0013,
227 "CP" => 0x0014,
228 "QU" => 0x0015,
229 "NS" => 0x0016,
230 "EX" => 0x0017,
231 "SY" => 0x0018,
232 "IS" => 0x0019,
233 "PR" => 0x001a,
234 "PO" => 0x001b,
235 "NU" => 0x001c,
236 "AL" => 0x001d,
237 "ID" => 0x001e,
238 "IN" => 0x001f,
239 "HY" => 0x0020,
240 "BB" => 0x0021,
241 "BA" => 0x0022,
242 "SA" => 0x0023,
243 "AI" => 0x0024,
244 "B2" => 0x0025,
245 "HL" => 0x0026,
246 "CJ" => 0x0027,
247 "RI" => 0x0028,
248 "EB" => 0x0029,
249 "EM" => 0x002a,
250 "ZWJ" => 0x002b,
253 my %vertical_types =
255 "R" => 0x0000,
256 "U" => 0x0001,
257 "Tr" => 0x0002,
258 "Tu" => 0x0003,
261 my %categories =
263 "Lu" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"upper"}, # Letter, Uppercase
264 "Ll" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"lower"}, # Letter, Lowercase
265 "Lt" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"upper"}|$ctype{"lower"}, # Letter, Titlecase
266 "Mn" => $ctype{"defin"}, # Mark, Non-Spacing
267 "Mc" => $ctype{"defin"}, # Mark, Spacing Combining
268 "Me" => $ctype{"defin"}, # Mark, Enclosing
269 "Nd" => $ctype{"defin"}|$ctype{"digit"}, # Number, Decimal Digit
270 "Nl" => $ctype{"defin"}|$ctype{"alpha"}, # Number, Letter
271 "No" => $ctype{"defin"}, # Number, Other
272 "Zs" => $ctype{"defin"}|$ctype{"space"}, # Separator, Space
273 "Zl" => $ctype{"defin"}|$ctype{"space"}, # Separator, Line
274 "Zp" => $ctype{"defin"}|$ctype{"space"}, # Separator, Paragraph
275 "Cc" => $ctype{"defin"}|$ctype{"cntrl"}, # Other, Control
276 "Cf" => $ctype{"defin"}|$ctype{"cntrl"}, # Other, Format
277 "Cs" => $ctype{"defin"}, # Other, Surrogate
278 "Co" => $ctype{"defin"}, # Other, Private Use
279 "Cn" => $ctype{"defin"}, # Other, Not Assigned
280 "Lm" => $ctype{"defin"}|$ctype{"alpha"}, # Letter, Modifier
281 "Lo" => $ctype{"defin"}|$ctype{"alpha"}, # Letter, Other
282 "Pc" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Connector
283 "Pd" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Dash
284 "Ps" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Open
285 "Pe" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Close
286 "Pi" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Initial quote
287 "Pf" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Final quote
288 "Po" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Other
289 "Sm" => $ctype{"defin"}, # Symbol, Math
290 "Sc" => $ctype{"defin"}, # Symbol, Currency
291 "Sk" => $ctype{"defin"}, # Symbol, Modifier
292 "So" => $ctype{"defin"} # Symbol, Other
295 # a few characters need additional categories that cannot be determined automatically
296 my %special_categories =
298 "xdigit" => [ ord('0')..ord('9'),ord('A')..ord('F'),ord('a')..ord('f'),
299 0xff10..0xff19, 0xff21..0xff26, 0xff41..0xff46 ],
300 "space" => [ 0x09..0x0d, 0x85 ],
301 "blank" => [ 0x09, 0x20, 0xa0, 0x3000, 0xfeff ],
302 "cntrl" => [ 0x070f, 0x200c, 0x200d,
303 0x200e, 0x200f, 0x202a, 0x202b, 0x202c, 0x202d, 0x202e,
304 0x206a, 0x206b, 0x206c, 0x206d, 0x206e, 0x206f, 0xfeff,
305 0xfff9, 0xfffa, 0xfffb ],
306 "punct" => [ 0x24, 0x2b, 0x3c..0x3e, 0x5e, 0x60, 0x7c, 0x7e, 0xa2..0xbe,
307 0xd7, 0xf7 ],
308 "digit" => [ 0xb2, 0xb3, 0xb9 ],
309 "lower" => [ 0x2071, 0x207f ]
312 my %directions =
314 "L" => 1, # Left-to-Right
315 "R" => 2, # Right-to-Left
316 "AL" => 12, # Right-to-Left Arabic
317 "EN" => 3, # European Number
318 "ES" => 4, # European Number Separator
319 "ET" => 5, # European Number Terminator
320 "AN" => 6, # Arabic Number
321 "CS" => 7, # Common Number Separator
322 "NSM" => 13, # Non-Spacing Mark
323 "BN" => 14, # Boundary Neutral
324 "B" => 8, # Paragraph Separator
325 "S" => 9, # Segment Separator
326 "WS" => 10, # Whitespace
327 "ON" => 11, # Other Neutrals
328 "LRE" => 15, # Left-to-Right Embedding
329 "LRO" => 15, # Left-to-Right Override
330 "RLE" => 15, # Right-to-Left Embedding
331 "RLO" => 15, # Right-to-Left Override
332 "PDF" => 15, # Pop Directional Format
333 "LRI" => 15, # Left-to-Right Isolate
334 "RLI" => 15, # Right-to-Left Isolate
335 "FSI" => 15, # First Strong Isolate
336 "PDI" => 15 # Pop Directional Isolate
339 my %joining_types =
341 "U" => 0, # Non_Joining
342 "T" => 1, # Transparent
343 "R" => 2, # Right_Joining
344 "L" => 3, # Left_Joining
345 "D" => 4, # Dual_Joining
346 "C" => 5, # Join_Causing
349 my @cp2uni = ();
350 my @lead_bytes = ();
351 my @uni2cp = ();
352 my @unicode_defaults = ();
353 my @unicode_aliases = ();
354 my @tolower_table = ();
355 my @toupper_table = ();
356 my @digitmap_table = ();
357 my @compatmap_table = ();
358 my @category_table = ();
359 my @joining_table = ();
360 my @direction_table = ();
361 my @decomp_table = ();
362 my @compose_table = ();
363 my $default_char;
364 my $default_wchar;
366 my %joining_forms =
368 "isolated" => [],
369 "final" => [],
370 "initial" => [],
371 "medial" => []
374 ################################################################
375 # fetch a unicode.org file and open it
376 sub open_data_file($$)
378 my ($base, $name) = @_;
379 (my $dir = "data/$name") =~ s/\/[^\/]+$//;
380 local *FILE;
381 unless (-f "data/$name")
383 print "Fetching $base/$name...\n";
384 system "mkdir", "-p", $dir;
385 !system "wget", "-q", "-O", "data/$name", "$base/$name" or die "cannot fetch $base/$name";
387 open FILE, "<data/$name" or die "cannot open data/$name";
388 return *FILE;
391 ################################################################
392 # read in the defaults file
393 sub READ_DEFAULTS($)
395 my $filename = shift;
396 my $start;
398 # first setup a few default mappings
400 open DEFAULTS, "$filename" or die "Cannot open $filename";
401 print "Loading $filename\n";
402 while (<DEFAULTS>)
404 next if /^\#/; # skip comments
405 next if /^$/; # skip empty lines
406 if (/^(([0-9a-fA-F]+)(,[0-9a-fA-F]+)*)\s+([0-9a-fA-F]+|'.'|none)\s+(\#.*)?/)
408 my @src = map hex, split /,/,$1;
409 my $dst = $4;
410 my $comment = $5;
411 if ($#src > 0) { push @unicode_aliases, \@src; }
412 next if ($dst eq "none");
413 $dst = ($dst =~ /\'.\'/) ? ord substr($dst,1,1) : hex $dst;
414 foreach my $src (@src)
416 die "Duplicate value" if defined($unicode_defaults[$src]);
417 $unicode_defaults[$src] = $dst;
419 next;
421 die "Unrecognized line $_\n";
423 close DEFAULTS;
425 # now build mappings from the decomposition field of the Unicode database
427 my $UNICODE_DATA = open_data_file( $UNIDATA, "UnicodeData.txt" );
428 while (<$UNICODE_DATA>)
430 # Decode the fields ...
431 my ($code, $name, $cat, $comb, $bidi,
432 $decomp, $dec, $dig, $num, $mirror,
433 $oldname, $comment, $upper, $lower, $title) = split /;/;
434 my $dst;
435 my $src = hex $code;
437 die "unknown category $cat" unless defined $categories{$cat};
438 die "unknown directionality $bidi" unless defined $directions{$bidi};
440 $category_table[$src] = $categories{$cat};
441 $direction_table[$src] = $directions{$bidi};
442 $joining_table[$src] = $joining_types{"T"} if $cat eq "Mn" || $cat eq "Me" || $cat eq "Cf";
444 if ($lower ne "")
446 $tolower_table[$src] = hex $lower;
448 if ($upper ne "")
450 $toupper_table[$src] = hex $upper;
452 if ($dec ne "")
454 $category_table[$src] |= $ctype{"digit"};
456 if ($dig ne "")
458 $digitmap_table[$src] = ord $dig;
461 # copy the category and direction for everything between First/Last pairs
462 if ($name =~ /, First>/) { $start = $src; }
463 if ($name =~ /, Last>/)
465 while ($start < $src)
467 $category_table[$start] = $category_table[$src];
468 $direction_table[$start] = $direction_table[$src];
469 $start++;
473 next if $decomp eq ""; # no decomposition, skip it
475 if ($decomp =~ /^<([a-zA-Z]+)>\s+([0-9a-fA-F]+)$/)
477 # decomposition of the form "<foo> 1234" -> use char if type is known
478 if (($src >= 0xf900 && $src < 0xfb00) || ($src >= 0xfe30 && $src < 0xfffd))
480 # Single char decomposition in the compatibility range
481 $compatmap_table[$src] = hex $2;
483 if ($1 eq "isolated" || $1 eq "final" || $1 eq "initial" || $1 eq "medial")
485 ${joining_forms{$1}}[hex $2] = $src;
486 next;
488 next unless ($1 eq "font" ||
489 $1 eq "noBreak" ||
490 $1 eq "circle" ||
491 $1 eq "super" ||
492 $1 eq "sub" ||
493 $1 eq "wide" ||
494 $1 eq "narrow" ||
495 $1 eq "compat" ||
496 $1 eq "small");
497 $dst = hex $2;
499 elsif ($decomp =~ /^<compat>\s+0020\s+([0-9a-fA-F]+)/)
501 # decomposition "<compat> 0020 1234" -> combining accent
502 $dst = hex $1;
504 elsif ($decomp =~ /^([0-9a-fA-F]+)/)
506 # decomposition contains only char values without prefix -> use first char
507 $dst = hex $1;
508 $category_table[$src] |= $category_table[$dst] if defined $category_table[$dst];
509 # store decomposition if it contains two chars
510 if ($decomp =~ /^([0-9a-fA-F]+)\s+([0-9a-fA-F]+)$/)
512 $decomp_table[$src] = [ hex $1, hex $2 ];
513 push @compose_table, [ hex $1, hex $2, $src ];
515 elsif ($decomp =~ /^(<[a-z]+>\s)*([0-9a-fA-F]+)$/ &&
516 (($src >= 0xf900 && $src < 0xfb00) || ($src >= 0xfe30 && $src < 0xfffd)))
518 # Single char decomposition in the compatibility range
519 $compatmap_table[$src] = hex $2;
522 else
524 next;
527 next if defined($unicode_defaults[$src]); # may have been set in the defaults file
529 # check for loops
530 for (my $i = $dst; ; $i = $unicode_defaults[$i])
532 die sprintf("loop detected for %04x -> %04x",$src,$dst) if $i == $src;
533 last unless defined($unicode_defaults[$i]);
535 $unicode_defaults[$src] = $dst;
537 close $UNICODE_DATA;
539 # patch the category of some special characters
541 foreach my $cat (keys %special_categories)
543 my $flag = $ctype{$cat};
544 foreach my $i (@{$special_categories{$cat}}) { $category_table[$i] |= $flag; }
549 ################################################################
550 # define a new lead byte
551 sub add_lead_byte($)
553 my $ch = shift;
554 push @lead_bytes, $ch;
555 $cp2uni[$ch] = 0;
558 ################################################################
559 # define a new char mapping
560 sub add_mapping($$)
562 my ($cp, $uni) = @_;
563 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
564 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
565 if ($cp > 0xff && !defined($cp2uni[$cp >> 8]))
567 add_lead_byte( $cp >> 8 );
571 ################################################################
572 # parse a standard codepage file
573 sub read_codepage_file($)
575 my $name = shift;
576 my $INPUT = open_data_file( $MAPPINGS, $name );
578 while (<$INPUT>)
580 next if /^\#/; # skip comments
581 next if /^$/; # skip empty lines
582 next if /\x1a/; # skip ^Z
583 next if (/^0x([0-9a-fA-F]+)\s+\#UNDEFINED/); # undefined char
585 if (/^0x([0-9a-fA-F]+)\s+\#DBCS LEAD BYTE/)
587 add_lead_byte( hex $1 );
588 next;
590 # 0x12 0x3456
591 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
593 add_mapping( hex $1, hex $2 );
594 next;
596 # 0x12 0x3456+0x7890
597 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\+.*\s+(\#.*)?/)
599 add_mapping( hex $1, hex $2 );
600 next;
602 # 0x12 <LR>+0x3456
603 if (/^0x([0-9a-fA-F]+)\s+<LR>\+0x([0-9a-fA-F]+)\s+(\#.*)?/)
605 add_mapping( hex $1, hex $2 );
606 next;
608 # 0x12 <RL>+0x3456
609 if (/^0x([0-9a-fA-F]+)\s+<RL>\+0x([0-9a-fA-F]+)\s+(\#.*)?/)
611 my $uni = hex $2;
612 add_mapping( hex $1, $uni ) if $uni >= 0x80;
613 next;
615 die "$name: Unrecognized line $_\n";
617 close $INPUT;
621 ################################################################
622 # fill input data for the 20127 (us-ascii) codepage
623 sub fill_20127_codepage()
625 for (my $i = 0; $i < 128; $i++) { $cp2uni[$i] = $uni2cp[$i] = $i; }
626 for (my $i = 128; $i < 256; $i++) { $cp2uni[$i] = $i & 0x7f; }
629 ################################################################
630 # get a mapping including glyph chars for MB_USEGLYPHCHARS
632 sub get_glyphs_mapping(@)
634 $_[0x01] = 0x263a; # (WHITE SMILING FACE)
635 $_[0x02] = 0x263b; # (BLACK SMILING FACE)
636 $_[0x03] = 0x2665; # (BLACK HEART SUIT)
637 $_[0x04] = 0x2666; # (BLACK DIAMOND SUIT)
638 $_[0x05] = 0x2663; # (BLACK CLUB SUIT)
639 $_[0x06] = 0x2660; # (BLACK SPADE SUIT)
640 $_[0x07] = 0x2022; # (BULLET)
641 $_[0x08] = 0x25d8; # (INVERSE BULLET)
642 $_[0x09] = 0x25cb; # (WHITE CIRCLE)
643 $_[0x0a] = 0x25d9; # (INVERSE WHITE CIRCLE)
644 $_[0x0b] = 0x2642; # (MALE SIGN)
645 $_[0x0c] = 0x2640; # (FEMALE SIGN)
646 $_[0x0d] = 0x266a; # (EIGHTH NOTE)
647 $_[0x0e] = 0x266b; # (BEAMED EIGHTH NOTES)
648 $_[0x0f] = 0x263c; # (WHITE SUN WITH RAYS)
649 $_[0x10] = 0x25ba; # (BLACK RIGHT-POINTING POINTER)
650 $_[0x11] = 0x25c4; # (BLACK LEFT-POINTING POINTER)
651 $_[0x12] = 0x2195; # (UP DOWN ARROW)
652 $_[0x13] = 0x203c; # (DOUBLE EXCLAMATION MARK)
653 $_[0x14] = 0x00b6; # (PILCROW SIGN)
654 $_[0x15] = 0x00a7; # (SECTION SIGN)
655 $_[0x16] = 0x25ac; # (BLACK RECTANGLE)
656 $_[0x17] = 0x21a8; # (UP DOWN ARROW WITH BASE)
657 $_[0x18] = 0x2191; # (UPWARDS ARROW)
658 $_[0x19] = 0x2193; # (DOWNWARDS ARROW)
659 $_[0x1a] = 0x2192; # (RIGHTWARDS ARROW)
660 $_[0x1b] = 0x2190; # (LEFTWARDS ARROW)
661 $_[0x1c] = 0x221f; # (RIGHT ANGLE)
662 $_[0x1d] = 0x2194; # (LEFT RIGHT ARROW)
663 $_[0x1e] = 0x25b2; # (BLACK UP-POINTING TRIANGLE)
664 $_[0x1f] = 0x25bc; # (BLACK DOWN-POINTING TRIANGLE)
665 $_[0x7f] = 0x2302; # (HOUSE)
666 return @_;
669 ################################################################
670 # build EUC-JP table from the JIS 0208 file
671 # FIXME: for proper EUC-JP we should probably read JIS 0212 too
672 # but this would require 3-byte DBCS characters
673 sub READ_JIS0208_FILE($)
675 my $name = shift;
677 # ASCII chars
678 for (my $i = 0x00; $i <= 0x7f; $i++)
680 $cp2uni[$i] = $i;
681 $uni2cp[$i] = $i;
684 # JIS X 0201 right plane
685 for (my $i = 0xa1; $i <= 0xdf; $i++)
687 $cp2uni[0x8e00 + $i] = 0xfec0 + $i;
688 $uni2cp[0xfec0 + $i] = 0x8e00 + $i;
691 # lead bytes
692 foreach my $i (0x8e, 0x8f, 0xa1 .. 0xfe)
694 add_lead_byte($i);
697 # undefined chars
698 foreach my $i (0x80 .. 0x8d, 0x90 .. 0xa0, 0xff)
700 $cp2uni[$i] = $DEF_CHAR;
703 # Shift-JIS compatibility
704 $uni2cp[0x00a5] = 0x5c;
705 $uni2cp[0x203e] = 0x7e;
707 # Fix backslash conversion
708 $cp2uni[0xa1c0] = 0xff3c;
709 $uni2cp[0xff3c] = 0xa1c0;
711 my $INPUT = open_data_file( $MAPPINGS, $name );
712 while (<$INPUT>)
714 next if /^\#/; # skip comments
715 next if /^$/; # skip empty lines
716 next if /\x1a/; # skip ^Z
717 if (/^0x[0-9a-fA-F]+\s+0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
719 my $cp = 0x8080 + hex $1;
720 my $uni = hex $2;
721 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
722 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
723 next;
725 die "$name: Unrecognized line $_\n";
727 close $INPUT;
731 ################################################################
732 # build the sort keys table
733 sub READ_SORTKEYS_FILE()
735 my @sortkeys = ();
736 for (my $i = 0; $i < 65536; $i++) { $sortkeys[$i] = [ -1, 0, 0, 0, 0 ] };
738 my $INPUT = open_data_file( $REPORTS, $SORTKEYS );
739 while (<$INPUT>)
741 next if /^\#/; # skip comments
742 next if /^$/; # skip empty lines
743 next if /\x1a/; # skip ^Z
744 next if /^\@version/; # skip @version header
745 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]+)\]/)
747 my ($uni,$variable) = (hex $1, $2);
748 next if $uni > 65535;
749 $sortkeys[$uni] = [ $uni, hex $3, hex $4, hex $5, hex $6 ];
750 next;
752 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]+)\]/)
754 # multiple character sequence, ignored for now
755 next;
757 die "$SORTKEYS: Unrecognized line $_\n";
759 close $INPUT;
761 # compress the keys to 32 bit:
762 # key 1 to 16 bits, key 2 to 8 bits, key 3 to 4 bits, key 4 to 1 bit
764 @sortkeys = sort { ${$a}[1] <=> ${$b}[1] or
765 ${$a}[2] <=> ${$b}[2] or
766 ${$a}[3] <=> ${$b}[3] or
767 ${$a}[4] <=> ${$b}[4] or
768 $a cmp $b; } @sortkeys;
770 my ($n2, $n3) = (1, 1);
771 my @keys = (-1, -1, -1, -1, -1 );
772 my @flatkeys = ();
774 for (my $i = 0; $i < 65536; $i++)
776 my @current = @{$sortkeys[$i]};
777 next if $current[0] == -1;
778 if ($current[1] == $keys[1])
780 if ($current[2] == $keys[2])
782 if ($current[3] == $keys[3])
784 # nothing
786 else
788 $keys[3] = $current[3];
789 $n3++;
790 die if ($n3 >= 16);
793 else
795 $keys[2] = $current[2];
796 $keys[3] = $current[3];
797 $n2++;
798 $n3 = 1;
799 die if ($n2 >= 256);
802 else
804 $keys[1] = $current[1];
805 $keys[2] = $current[2];
806 $keys[3] = $current[3];
807 $n2 = 1;
808 $n3 = 1;
811 if ($current[2]) { $current[2] = $n2; }
812 if ($current[3]) { $current[3] = $n3; }
813 if ($current[4]) { $current[4] = 1; }
815 $flatkeys[$current[0]] = ($current[1] << 16) | ($current[2] << 8) | ($current[3] << 4) | $current[4];
817 return @flatkeys;
821 ################################################################
822 # build the sort keys table
823 sub DUMP_SORTKEYS($@)
825 my ($filename, @keys) = @_;
827 # count the number of 256-key ranges that contain something
829 my @offsets = ();
830 my $ranges = 2;
831 for (my $i = 0; $i < 256; $i++) { $offsets[$i] = 256; }
832 for (my $i = 0; $i < 65536; $i++)
834 next unless defined $keys[$i];
835 $offsets[$i >> 8] = $ranges * 256;
836 $ranges++;
837 $i |= 255;
840 # output the range offsets
842 open OUTPUT,">$filename.new" or die "Cannot create $filename";
843 printf "Building $filename\n";
844 printf OUTPUT "/* Unicode collation element table */\n";
845 printf OUTPUT "/* generated from %s */\n", "$REPORTS/$SORTKEYS";
846 printf OUTPUT "/* DO NOT EDIT!! */\n\n";
848 printf OUTPUT "const unsigned int collation_table[%d] =\n{\n", $ranges*256;
849 printf OUTPUT " /* index */\n";
850 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%08x", 0, @offsets );
852 # output the default values
854 printf OUTPUT " /* defaults */\n";
855 printf OUTPUT "%s", DUMP_ARRAY( "0x%08x", 0, (0xffffffff) x 256 );
857 # output all the key ranges
859 for (my $i = 0; $i < 256; $i++)
861 next if $offsets[$i] == 256;
862 printf OUTPUT ",\n /* 0x%02x00 .. 0x%02xff */\n", $i, $i;
863 printf OUTPUT "%s", DUMP_ARRAY( "0x%08x", 0xffffffff, @keys[($i<<8) .. ($i<<8)+255] );
865 printf OUTPUT "\n};\n";
866 close OUTPUT;
867 save_file($filename);
871 ################################################################
872 # add default mappings once the file had been read
873 sub add_default_mappings($)
875 my $first_private = shift;
877 # Apply aliases
879 foreach my $alias (@unicode_aliases)
881 my $target = undef;
882 foreach my $src (@$alias)
884 if (defined($uni2cp[$src]))
886 $target = $uni2cp[$src];
887 last;
890 next unless defined($target);
892 # At least one char of the alias set is defined, set the others to the same value
893 foreach my $src (@$alias)
895 $uni2cp[$src] = $target unless defined($uni2cp[$src]);
899 # For every src -> target mapping in the defaults table,
900 # make uni2cp[src] = uni2cp[target] if uni2cp[target] is defined
902 for (my $src = 0; $src < 65536; $src++)
904 next if defined($uni2cp[$src]); # source has a definition already
905 next unless defined($unicode_defaults[$src]); # no default for this char
906 my $target = $unicode_defaults[$src];
908 # do a recursive mapping until we find a target char that is defined
909 while (!defined($uni2cp[$target]) &&
910 defined($unicode_defaults[$target])) { $target = $unicode_defaults[$target]; }
912 if (defined($uni2cp[$target])) { $uni2cp[$src] = $uni2cp[$target]; }
915 # Add a private char mapping for undefined chars
917 if ($first_private)
919 for (my $i = 32; $i < 256; $i++)
921 next if defined($cp2uni[$i]);
922 $cp2uni[$i] = $first_private;
923 $uni2cp[$first_private] = $i;
924 $first_private++;
928 # Add an identity mapping for all undefined chars
930 for (my $i = 0; $i < 256; $i++)
932 next if defined($cp2uni[$i]);
933 next if defined($uni2cp[$i]);
934 $cp2uni[$i] = $uni2cp[$i] = $i;
938 ################################################################
939 # dump an array of integers
940 sub DUMP_ARRAY($$@)
942 my ($format,$default,@array) = @_;
943 my $i;
944 my $ret = " ";
945 for ($i = 0; $i < $#array; $i++)
947 $ret .= sprintf($format, defined $array[$i] ? $array[$i] : $default);
948 $ret .= (($i % 8) != 7) ? ", " : ",\n ";
950 $ret .= sprintf($format, defined $array[$i] ? $array[$i] : $default);
951 return $ret;
955 ################################################################
956 # dump a unicode->ascii mapping table
957 sub dump_uni2cp_table($$)
959 my ($width, $def) = @_;
961 # count the number of unicode->ascii subtables that contain something
963 my @lowerbounds;
964 my @upperbounds;
965 my $index = 0;
966 my @filled = (-1) x 256;
967 for (my $i = 0; $i < 65536; $i++)
969 next unless defined $uni2cp[$i];
970 if ($filled[$i >> 8] == -1)
972 $lowerbounds[$index] = $i & 0xff;
973 $upperbounds[$index] = 0xff - $lowerbounds[$index];
974 $filled[$i >> 8] = $index * 256;
975 $index++;
977 else
979 $upperbounds[$index-1] = 0xff - ($i & 0xff);
983 # add defaults mapping at the end
984 $filled[256] = $index * 256;
985 $lowerbounds[$index] = 255;
986 $upperbounds[$index] = 0;
987 $index++;
989 # collapse blocks upwards if possible
990 my $removed = 0;
991 $index = 0;
992 for (my $i = 0; $i < 257; $i++)
994 next if $filled[$i] == -1;
995 if ($upperbounds[$index - 1] > $lowerbounds[$index])
997 $removed += $lowerbounds[$index];
999 else
1001 $removed += $upperbounds[$index - 1];
1002 $lowerbounds[$index] = $upperbounds[$index - 1];
1004 $filled[$i] -= $removed;
1005 $index++;
1008 # output all the subtables into a single array
1010 printf OUTPUT "static const unsigned %s uni2cp_low[%d] =\n{\n",
1011 $width == 8 ? "char" : "short", ($index + 1) * 256 - $removed;
1013 my $format = $width == 8 ? "0x%02x" : "0x%04x";
1014 for (my $i = $index = 0; $i < 257; $i++)
1016 next if $filled[$i] == -1;
1017 my $start = ($i << 8) + $lowerbounds[$index];
1018 my $end = ($i << 8) + 255;
1019 if ($i == 256)
1021 print OUTPUT " /* defaults */\n";
1022 printf OUTPUT "%s\n};\n\n", DUMP_ARRAY( $format, 0, ($def) x ($end - $start + 1) );
1024 else
1026 printf OUTPUT " /* 0x%04x .. 0x%04x */\n", $start, $end;
1027 printf OUTPUT "%s,\n", DUMP_ARRAY( $format, $def, @uni2cp[$start .. $end] );
1029 $index++;
1032 # output a table of the offsets of the subtables in the previous array
1034 for (my $i = 0; $i < 256; $i++)
1036 if ($filled[$i] == -1) { $filled[$i] = $filled[256]; }
1038 printf OUTPUT "static const unsigned short uni2cp_high[256] =\n";
1039 printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%04x", 0, @filled[0..255] );
1042 ################################################################
1043 # dump an SBCS mapping table
1044 sub dump_sbcs_table($$$$$)
1046 my ($codepage, $has_glyphs, $name, $def, $defw) = @_;
1047 my $i;
1049 # output the ascii->unicode table
1051 if ($has_glyphs)
1053 printf OUTPUT "static const WCHAR cp2uni[512] =\n";
1054 printf OUTPUT "{\n%s", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[0 .. 255] );
1055 printf OUTPUT ",\n /* glyphs */\n%s\n};\n\n",
1056 DUMP_ARRAY( "0x%04x", $defw, get_glyphs_mapping(@cp2uni[0 .. 255]) );
1058 else
1060 printf OUTPUT "static const WCHAR cp2uni[256] =\n";
1061 printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[0 .. 255] );
1064 dump_uni2cp_table( 8, $def );
1066 # output the code page descriptor
1068 printf OUTPUT "const struct sbcs_table DECLSPEC_HIDDEN cptable_%03d =\n{\n", $codepage;
1069 printf OUTPUT " { %d, 1, 0x%04x, 0x%04x, \"%s\" },\n",
1070 $codepage, $def, $defw, $name;
1071 printf OUTPUT " cp2uni,\n";
1072 if ($has_glyphs) { printf OUTPUT " cp2uni + 256,\n"; }
1073 else { printf OUTPUT " cp2uni,\n"; }
1074 printf OUTPUT " uni2cp_low,\n";
1075 printf OUTPUT " uni2cp_high\n};\n";
1079 ################################################################
1080 # dump a DBCS mapping table
1081 sub dump_dbcs_table($$$$@)
1083 my ($codepage, $name, $def, $defw, @lb_ranges) = @_;
1085 # build a list of lead bytes that are actually used
1087 my @lblist = ();
1088 LBLOOP: for (my $y = 0; $y <= $#lead_bytes; $y++)
1090 $cp2uni[$lead_bytes[$y]] = $defw;
1091 my $base = $lead_bytes[$y] << 8;
1092 for (my $x = 0; $x < 256; $x++)
1094 if (defined $cp2uni[$base+$x])
1096 push @lblist,$lead_bytes[$y];
1097 next LBLOOP;
1101 my $unused = ($#lead_bytes > $#lblist);
1103 # output the ascii->unicode table for the single byte chars
1105 printf OUTPUT "static const WCHAR cp2uni[%d] =\n", 256 * ($#lblist + 2 + $unused);
1106 printf OUTPUT "{\n%s,\n", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[0 .. 255] );
1108 # output the default table for unused lead bytes
1110 if ($unused)
1112 printf OUTPUT " /* unused lead bytes */\n";
1113 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%04x", 0, ($defw) x 256 );
1116 # output the ascii->unicode table for each DBCS lead byte
1118 for (my $y = 0; $y <= $#lblist; $y++)
1120 my $base = $lblist[$y] << 8;
1121 printf OUTPUT " /* lead byte %02x */\n", $lblist[$y];
1122 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[$base .. $base+255] );
1123 printf OUTPUT ($y < $#lblist) ? ",\n" : "\n};\n\n";
1126 # output the lead byte subtables offsets
1128 my @offsets = (0) x 256;
1129 for (my $x = 0; $x <= $#lblist; $x++) { $offsets[$lblist[$x]] = $x + 1; }
1130 if ($unused)
1132 # increment all lead bytes offset to take into account the unused table
1133 for (my $x = 0; $x <= $#lead_bytes; $x++) { $offsets[$lead_bytes[$x]]++; }
1135 printf OUTPUT "static const unsigned char cp2uni_leadbytes[256] =\n";
1136 printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%02x", 0, @offsets );
1138 dump_uni2cp_table( 16, $def );
1140 # output the code page descriptor
1142 printf OUTPUT "const struct dbcs_table DECLSPEC_HIDDEN cptable_%03d =\n{\n", $codepage;
1143 printf OUTPUT " { %d, 2, 0x%04x, 0x%04x, \"%s\" },\n",
1144 $codepage, $def, $defw, $name;
1145 printf OUTPUT " cp2uni,\n";
1146 printf OUTPUT " cp2uni_leadbytes,\n";
1147 printf OUTPUT " uni2cp_low,\n";
1148 printf OUTPUT " uni2cp_high,\n";
1149 printf OUTPUT " {\n %s\n }\n", DUMP_ARRAY( "0x%02x", 0, @lb_ranges, 0, 0 );
1150 printf OUTPUT "};\n";
1154 ################################################################
1155 # get the list of defined lead byte ranges
1156 sub get_lb_ranges()
1158 my @list = ();
1159 my @ranges = ();
1160 my $i = 0;
1161 foreach $i (@lead_bytes) { $list[$i] = 1; }
1162 my $on = 0;
1163 for (my $i = 0; $i < 256; $i++)
1165 if ($on)
1167 if (!defined $list[$i]) { push @ranges, $i-1; $on = 0; }
1169 else
1171 if ($list[$i]) { push @ranges, $i; $on = 1; }
1174 if ($on) { push @ranges, 0xff; }
1175 return @ranges;
1178 ################################################################
1179 # dump the Indic Syllabic Category table
1180 sub dump_indic($)
1182 my $filename = shift;
1183 my @indic_table;
1185 my $INPUT = open_data_file( $UNIDATA, "IndicSyllabicCategory.txt" );
1186 while (<$INPUT>)
1188 next if /^\#/; # skip comments
1189 next if /^\s*$/; # skip empty lines
1190 next if /\x1a/; # skip ^Z
1191 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*#/)
1193 my $type = $2;
1194 die "unknown indic $type" unless defined $indic_types{$type};
1195 if (hex $1 < 65536)
1197 $indic_table[hex $1] = $indic_types{$type};
1199 next;
1201 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*#/)
1203 my $type = $3;
1204 die "unknown indic $type" unless defined $indic_types{$type};
1205 if (hex $1 < 65536 and hex $2 < 65536)
1207 foreach my $i (hex $1 .. hex $2)
1209 $indic_table[$i] = $indic_types{$type};
1212 next;
1214 die "malformed line $_";
1216 close $INPUT;
1218 $INPUT = open_data_file( $UNIDATA, "IndicPositionalCategory.txt" );
1219 while (<$INPUT>)
1221 next if /^\#/; # skip comments
1222 next if /^\s*$/; # skip empty lines
1223 next if /\x1a/; # skip ^Z
1224 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z]+)\s*#/)
1226 my $type = $2;
1227 die "unknown matra $type" unless defined $matra_types{$type};
1228 $indic_table[hex $1] += $matra_types{$type} << 8;
1229 next;
1231 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*#/)
1233 my $type = $3;
1234 die "unknown matra $type" unless defined $matra_types{$type};
1235 foreach my $i (hex $1 .. hex $2)
1237 $indic_table[$i] += $matra_types{$type} << 8;
1239 next;
1241 die "malformed line $_";
1243 close $INPUT;
1245 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1246 print "Building $filename\n";
1247 print OUTPUT "/* Unicode Indic Syllabic Category */\n";
1248 print OUTPUT "/* generated from $UNIDATA/IndicSyllabicCategory.txt */\n";
1249 print OUTPUT "/* and from $UNIDATA/IndicPositionalCategory.txt */\n";
1250 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1251 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1253 dump_two_level_mapping( "indic_syllabic_table", $indic_types{'Other'}, @indic_table );
1255 close OUTPUT;
1256 save_file($filename);
1259 ################################################################
1260 # dump the Line Break Properties table
1261 sub dump_linebreak($)
1263 my $filename = shift;
1264 my @break_table;
1265 my $next_group = 0;
1267 my $INPUT = open_data_file( $UNIDATA, "LineBreak.txt" );
1268 while (<$INPUT>)
1270 next if /^\#/; # skip comments
1271 next if /^\s*$/; # skip empty lines
1272 next if /\x1a/; # skip ^Z
1273 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z][0-9A-Z])+\s*/)
1275 my $type = $2;
1276 die "unknown breaktype $type" unless defined $break_types{$type};
1277 $break_table[hex $1] = $break_types{$type};
1278 next;
1280 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z][0-9A-Z])+\s*/)
1282 my $type = $3;
1283 die "unknown breaktype $type" unless defined $break_types{$type};
1284 foreach my $i (hex $1 .. hex $2)
1286 $break_table[$i] = $break_types{$type};
1288 next;
1290 elsif (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z])+\s*/)
1292 my $type = $2;
1293 die "unknown breaktype $type" unless defined $break_types{$type};
1294 $break_table[hex $1] = $break_types{$type};
1295 next;
1297 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z])+\s*/)
1299 my $type = $3;
1300 die "unknown breaktype $type" unless defined $break_types{$type};
1301 foreach my $i (hex $1 .. hex $2)
1303 $break_table[$i] = $break_types{$type};
1305 next;
1307 die "malformed line $_";
1309 close $INPUT;
1311 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1312 print "Building $filename\n";
1313 print OUTPUT "/* Unicode Line Break Properties */\n";
1314 print OUTPUT "/* generated from $UNIDATA/LineBreak.txt */\n";
1315 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1316 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1318 dump_two_level_mapping( "wine_linebreak_table", $break_types{'XX'}, @break_table );
1320 close OUTPUT;
1321 save_file($filename);
1324 my %scripts =
1326 "Unknown" => 0,
1327 "Common" => 1,
1328 "Inherited" => 2,
1329 "Arabic" => 3,
1330 "Armenian" => 4,
1331 "Avestan" => 5,
1332 "Balinese" => 6,
1333 "Bamum" => 7,
1334 "Batak" => 8,
1335 "Bengali" => 9,
1336 "Bopomofo" => 10,
1337 "Brahmi" => 11,
1338 "Braille" => 12,
1339 "Buginese" => 13,
1340 "Buhid" => 14,
1341 "Canadian_Aboriginal" => 15,
1342 "Carian" => 16,
1343 "Cham" => 17,
1344 "Cherokee" => 18,
1345 "Coptic" => 19,
1346 "Cuneiform" => 20,
1347 "Cypriot" => 21,
1348 "Cyrillic" => 22,
1349 "Deseret" => 23,
1350 "Devanagari" => 24,
1351 "Egyptian_Hieroglyphs" => 25,
1352 "Ethiopic" => 26,
1353 "Georgian" => 27,
1354 "Glagolitic" => 28,
1355 "Gothic" => 29,
1356 "Greek" => 30,
1357 "Gujarati" => 31,
1358 "Gurmukhi" => 32,
1359 "Han" => 33,
1360 "Hangul" => 34,
1361 "Hanunoo" => 35,
1362 "Hebrew" => 36,
1363 "Hiragana" => 37,
1364 "Imperial_Aramaic" => 38,
1365 "Inscriptional_Pahlavi" => 39,
1366 "Inscriptional_Parthian" => 40,
1367 "Javanese" => 41,
1368 "Kaithi" => 42,
1369 "Kannada" => 43,
1370 "Katakana" => 44,
1371 "Kayah_Li" => 45,
1372 "Kharoshthi" => 46,
1373 "Khmer" => 47,
1374 "Lao" => 48,
1375 "Latin" => 49,
1376 "Lepcha" => 50,
1377 "Limbu" => 51,
1378 "Linear_B" => 52,
1379 "Lisu" => 53,
1380 "Lycian" => 54,
1381 "Lydian" => 55,
1382 "Malayalam" => 56,
1383 "Mandaic" => 57,
1384 "Meetei_Mayek" => 58,
1385 "Mongolian" => 59,
1386 "Myanmar" => 60,
1387 "New_Tai_Lue" => 61,
1388 "Nko" => 62,
1389 "Ogham" => 63,
1390 "Ol_Chiki" => 64,
1391 "Old_Italic" => 65,
1392 "Old_Persian" => 66,
1393 "Old_South_Arabian" => 67,
1394 "Old_Turkic" => 68,
1395 "Oriya" => 69,
1396 "Osmanya" => 70,
1397 "Phags_Pa" => 71,
1398 "Phoenician" => 72,
1399 "Rejang" => 73,
1400 "Runic" => 74,
1401 "Samaritan" => 75,
1402 "Saurashtra" => 76,
1403 "Shavian" => 77,
1404 "Sinhala" => 78,
1405 "Sundanese" => 79,
1406 "Syloti_Nagri" => 80,
1407 "Syriac" => 81,
1408 "Tagalog" => 82,
1409 "Tagbanwa" => 83,
1410 "Tai_Le" => 84,
1411 "Tai_Tham" => 85,
1412 "Tai_Viet" => 86,
1413 "Tamil" => 87,
1414 "Telugu" => 88,
1415 "Thaana" => 89,
1416 "Thai" => 90,
1417 "Tibetan" => 91,
1418 "Tifinagh" => 92,
1419 "Ugaritic" => 93,
1420 "Vai" => 94,
1421 "Yi" => 95,
1422 # Win8/Win8.1
1423 "Chakma" => 96,
1424 "Meroitic_Cursive" => 97,
1425 "Meroitic_Hieroglyphs" => 98,
1426 "Miao" => 99,
1427 "Sharada" => 100,
1428 "Sora_Sompeng" => 101,
1429 "Takri" => 102,
1430 # Win10
1431 "Bassa_Vah" => 103,
1432 "Caucasian_Albanian" => 104,
1433 "Duployan" => 105,
1434 "Elbasan" => 106,
1435 "Grantha" => 107,
1436 "Khojki" => 108,
1437 "Khudawadi" => 109,
1438 "Linear_A" => 110,
1439 "Mahajani" => 111,
1440 "Manichaean" => 112,
1441 "Mende_Kikakui" => 113,
1442 "Modi" => 114,
1443 "Mro" => 115,
1444 "Nabataean" => 116,
1445 "Old_North_Arabian" => 117,
1446 "Old_Permic" => 118,
1447 "Pahawh_Hmong" => 119,
1448 "Palmyrene" => 120,
1449 "Pau_Cin_Hau" => 121,
1450 "Psalter_Pahlavi" => 122,
1451 "Siddham" => 123,
1452 "Tirhuta" => 124,
1453 "Warang_Citi" => 125,
1454 # Win10 RS1
1455 "Adlam" => 126,
1456 "Ahom" => 127,
1457 "Anatolian_Hieroglyphs" => 128,
1458 "Bhaiksuki" => 129,
1459 "Hatran" => 130,
1460 "Marchen" => 131,
1461 "Multani" => 132,
1462 "Newa" => 133,
1463 "Old_Hungarian" => 134,
1464 "Osage" => 135,
1465 "SignWriting" => 136,
1466 "Tangut" => 137,
1467 # Win10 RS4
1468 "Masaram_Gondi" => 138,
1469 "Nushu" => 139,
1470 "Soyombo" => 140,
1471 "Zanabazar_Square" => 141,
1474 ################################################################
1475 # dump Script IDs table
1476 sub dump_scripts($)
1478 my $filename = shift;
1479 my $header = $filename;
1480 my @scripts_table;
1481 my $script_index;
1482 my $i;
1484 my $INPUT = open_data_file( $UNIDATA, "Scripts.txt" );
1485 # Fill the table
1486 # Unknown script id is always 0, so undefined scripts are automatically treated as such
1487 while (<$INPUT>)
1489 my $type = "";
1491 next if /^\#/; # skip comments
1492 next if /^\s*$/; # skip empty lines
1493 next if /\x1a/; # skip ^Z
1494 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1496 $type = $2;
1497 if (defined $scripts{$type})
1499 $scripts_table[hex $1] = $scripts{$type};
1501 next;
1503 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1505 $type = $3;
1506 if (defined $scripts{$type})
1508 foreach my $i (hex $1 .. hex $2)
1510 $scripts_table[$i] = $scripts{$type};
1513 next;
1517 close $INPUT;
1519 $header = "$filename.h";
1520 open OUTPUT,">$header.new" or die "Cannot create $header";
1521 print "Building $header\n";
1522 print OUTPUT "/* Unicode Script IDs */\n";
1523 print OUTPUT "/* generated from $UNIDATA/Scripts.txt */\n";
1524 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1526 print OUTPUT "enum unicode_script_id {\n";
1527 foreach my $script (sort { $scripts{$a} <=> $scripts{$b} } keys %scripts)
1529 print OUTPUT " Script_$script = $scripts{$script},\n";
1531 print OUTPUT " Script_LastId = ", (scalar keys %scripts) - 1, "\n";
1532 print OUTPUT "};\n";
1534 close OUTPUT;
1535 save_file($header);
1537 $filename = "$filename.c";
1538 open OUTPUT,">$filename.new" or die "Cannot create $header";
1539 print "Building $filename\n";
1540 print OUTPUT "/* Unicode Script IDs */\n";
1541 print OUTPUT "/* generated from $UNIDATA/Scripts.txt */\n";
1542 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1543 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1545 dump_two_level_mapping( "wine_scripts_table", 0, @scripts_table );
1546 close OUTPUT;
1547 save_file($filename);
1550 ################################################################
1551 # dump the BiDi mirroring table
1552 sub dump_mirroring($)
1554 my $filename = shift;
1555 my @mirror_table = ();
1557 my $INPUT = open_data_file( $UNIDATA, "BidiMirroring.txt" );
1558 while (<$INPUT>)
1560 next if /^\#/; # skip comments
1561 next if /^$/; # skip empty lines
1562 next if /\x1a/; # skip ^Z
1563 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9a-fA-F]+)/)
1565 $mirror_table[hex $1] = hex $2;
1566 next;
1568 die "malformed line $_";
1570 close $INPUT;
1572 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1573 print "Building $filename\n";
1574 print OUTPUT "/* Unicode BiDi mirroring */\n";
1575 print OUTPUT "/* generated from $UNIDATA/BidiMirroring.txt */\n";
1576 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1577 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1578 DUMP_CASE_TABLE( "DECLSPEC_HIDDEN wine_mirror_map", @mirror_table );
1579 close OUTPUT;
1580 save_file($filename);
1583 ################################################################
1584 # dump the Bidi Brackets
1585 sub dump_bracket($)
1587 my $filename = shift;
1588 my @bracket_table;
1590 my $INPUT = open_data_file( $UNIDATA, "BidiBrackets.txt" );
1591 while (<$INPUT>)
1593 next if /^\#/; # skip comments
1594 next if /^\s*$/; # skip empty lines
1595 next if /\x1a/; # skip ^Z
1596 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9a-fA-F]+);\s*([con])/)
1598 my $type = $3;
1599 die "unknown bracket $type" unless defined $bracket_types{$type};
1600 die "characters too distant $1 and $2" if abs(hex($2) - hex($1)) >= 128;
1601 $bracket_table[hex $1] = (hex($2) - hex($1)) % 255;
1602 $bracket_table[hex $1] += $bracket_types{$type} << 8;
1603 next;
1605 die "malformed line $_";
1607 close $INPUT;
1609 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1610 print "Building $filename\n";
1611 print OUTPUT "/* Unicode Bidirectional Bracket table */\n";
1612 print OUTPUT "/* generated from $UNIDATA/BidiBrackets.txt */\n";
1613 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1614 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1616 dump_two_level_mapping( "bidi_bracket_table", 0, @bracket_table );
1618 close OUTPUT;
1619 save_file($filename);
1622 ################################################################
1623 # dump the Arabic shaping table
1624 sub dump_shaping($)
1626 my $filename = shift;
1627 my %groups;
1628 my $next_group = 0;
1630 $groups{"No_Joining_Group"} = $next_group++;
1632 my $INPUT = open_data_file( $UNIDATA, "ArabicShaping.txt" );
1633 while (<$INPUT>)
1635 next if /^\#/; # skip comments
1636 next if /^\s*$/; # skip empty lines
1637 next if /\x1a/; # skip ^Z
1638 if (/^\s*([0-9a-fA-F]+)\s*;.*;\s*([RLDCUT])\s*;\s*(\w+)/)
1640 my $type = $2;
1641 my $group = $3;
1642 $groups{$group} = $next_group++ unless defined $groups{$group};
1643 $joining_table[hex $1] = $joining_types{$type} | ($groups{$group} << 8);
1644 next;
1646 die "malformed line $_";
1648 close $INPUT;
1650 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1651 print "Building $filename\n";
1652 print OUTPUT "/* Unicode Arabic shaping */\n";
1653 print OUTPUT "/* generated from $UNIDATA/ArabicShaping.txt */\n";
1654 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1655 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1657 dump_two_level_mapping( "wine_shaping_table", 0, @joining_table );
1659 print OUTPUT "\nconst unsigned short DECLSPEC_HIDDEN wine_shaping_forms[256][4] =\n{\n";
1660 for (my $i = 0x600; $i <= 0x6ff; $i++)
1662 printf OUTPUT " { 0x%04x, 0x%04x, 0x%04x, 0x%04x },\n",
1663 ${joining_forms{"isolated"}}[$i] || $i,
1664 ${joining_forms{"final"}}[$i] || $i,
1665 ${joining_forms{"initial"}}[$i] || $i,
1666 ${joining_forms{"medial"}}[$i] || $i;
1668 print OUTPUT "};\n";
1670 close OUTPUT;
1671 save_file($filename);
1674 ################################################################
1675 # dump the Vertical Orientation table
1676 sub dump_vertical($)
1678 my $filename = shift;
1679 my @vertical_table;
1681 my $INPUT = open_data_file( $UNIDATA, "VerticalOrientation.txt" );
1682 while (<$INPUT>)
1684 next if /^\#/; # skip comments
1685 next if /^\s*$/; # skip empty lines
1686 next if /\x1a/; # skip ^Z
1687 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1689 my $type = $2;
1690 die "unknown vertical $type" unless defined $vertical_types{$type};
1691 if (hex $1 < 65536)
1693 $vertical_table[hex $1] = $vertical_types{$type};
1695 next;
1697 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*/)
1699 my $type = $3;
1700 die "unknown vertical $type" unless defined $vertical_types{$type};
1701 foreach my $i (hex $1 .. hex $2)
1703 $vertical_table[$i] = $vertical_types{$type};
1705 next;
1707 die "malformed line $_";
1709 close $INPUT;
1711 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1712 print "Building $filename\n";
1713 print OUTPUT "/* Unicode Vertical Orientation */\n";
1714 print OUTPUT "/* generated from $UNIDATA/VerticalOrientation.txt */\n";
1715 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1716 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1718 dump_two_level_mapping( "vertical_orientation_table", $vertical_types{'R'}, @vertical_table );
1720 close OUTPUT;
1721 save_file($filename);
1724 ################################################################
1725 # dump the digit folding tables
1726 sub dump_digit_folding($)
1728 my $filename = shift;
1729 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1730 print "Building $filename\n";
1731 print OUTPUT "/* Unicode digit folding mappings */\n";
1732 print OUTPUT "/* generated from $UNIDATA/UnicodeData.txt */\n";
1733 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1734 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1736 DUMP_CASE_TABLE( "DECLSPEC_HIDDEN wine_digitmap", @digitmap_table );
1737 print OUTPUT "\n";
1738 DUMP_CASE_TABLE( "DECLSPEC_HIDDEN wine_compatmap", @compatmap_table );
1739 close OUTPUT;
1740 save_file($filename);
1744 ################################################################
1745 # dump the case mapping tables
1746 sub DUMP_CASE_MAPPINGS($)
1748 my $filename = shift;
1749 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1750 print "Building $filename\n";
1751 print OUTPUT "/* Unicode case mappings */\n";
1752 print OUTPUT "/* generated from $UNIDATA/UnicodeData.txt */\n";
1753 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1754 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1756 DUMP_CASE_TABLE( "wine_casemap_lower", @tolower_table );
1757 print OUTPUT "\n";
1758 DUMP_CASE_TABLE( "wine_casemap_upper", @toupper_table );
1759 close OUTPUT;
1760 save_file($filename);
1764 ################################################################
1765 # dump a case mapping table
1766 sub DUMP_CASE_TABLE($@)
1768 my ($name,@table) = @_;
1770 # count the number of sub tables that contain something
1771 # also compute the low and upper populated bounds
1773 my @lowerbounds = ( 0, 0 );
1774 my @upperbounds = ( 0, 255 );
1775 my $index = 0;
1776 my @filled = ();
1777 for (my $i = 0; $i < 65536; $i++)
1779 next unless defined $table[$i];
1780 if (!defined $filled[$i >> 8])
1782 $lowerbounds[$index] = $i & 0xff;
1783 $upperbounds[$index] = 0xff - $lowerbounds[$index];
1784 $filled[$i >> 8] = $index * 256 + 512;
1785 $index++;
1787 else
1789 $upperbounds[$index-1] = 0xff - ($i & 0xff);
1791 $table[$i] = ($table[$i] - $i) & 0xffff;
1794 # Collapse blocks upwards if possible
1795 my $removed = 0;
1796 $index = 0;
1797 for (my $i = 0; $i < 256; $i++)
1799 next unless defined $filled[$i];
1800 if ($upperbounds[$index - 1] > $lowerbounds[$index])
1802 $removed = $removed + $lowerbounds[$index];
1804 else
1806 $removed = $removed + $upperbounds[$index - 1];
1807 $lowerbounds[$index] = $upperbounds[$index - 1];
1809 $filled[$i] = $filled[$i] - $removed;
1810 $index++;
1813 # dump the table
1815 printf OUTPUT "const WCHAR %s[%d] =\n", $name, $index * 256 + 512 - $removed;
1816 printf OUTPUT "{\n /* index */\n";
1817 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%04x", 256, @filled );
1818 printf OUTPUT " /* defaults */\n";
1819 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, (0) x 256 );
1820 $index = 0;
1821 for (my $i = 0; $i < 256; $i++)
1823 next unless $filled[$i];
1824 printf OUTPUT ",\n /* 0x%02x%02x .. 0x%02xff */\n", $i, $lowerbounds[$index], $i;
1825 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0,
1826 @table[($i<<8) + $lowerbounds[$index] .. ($i<<8)+255] );
1827 $index++;
1829 printf OUTPUT "\n};\n";
1832 ################################################################
1833 # compress a mapping table by removing identical rows
1834 sub compress_array($$@)
1836 my $rows = shift;
1837 my $def = shift;
1838 my @table = @_;
1839 my $len = @table / $rows;
1840 my @array = (0) x $rows;
1841 my %sequences;
1843 # try to merge table rows
1844 for (my $row = 0; $row < $rows; $row++)
1846 my @table_row = map { defined($_) ? $_ : $def; } @table[($row * $len)..($row * $len + $len - 1)];
1847 my $rowtxt = pack "S*", @table_row;
1848 if (defined($sequences{$rowtxt}))
1850 # reuse an existing row
1851 $array[$row] = $sequences{$rowtxt};
1853 else
1855 # create a new row
1856 $sequences{$rowtxt} = $array[$row] = $#array + 1;
1857 push @array, @table_row;
1860 return @array;
1863 ################################################################
1864 # dump a simple char -> 16-bit value mapping table
1865 sub dump_simple_mapping($$@)
1867 my $name = shift;
1868 my $def = shift;
1869 my @array = compress_array( 256, $def, @_[0..65535] );
1871 printf OUTPUT "const unsigned short %s[%d] =\n{\n", $name, $#array+1;
1872 printf OUTPUT " /* offsets */\n%s,\n", DUMP_ARRAY( "0x%04x", 0, @array[0..255] );
1873 printf OUTPUT " /* values */\n%s\n};\n", DUMP_ARRAY( "0x%04x", 0, @array[256..$#array] );
1876 ################################################################
1877 # dump a char -> 16-bit value mapping table using two-level tables
1878 sub dump_two_level_mapping($$@)
1880 my $name = shift;
1881 my $def = shift;
1882 my @row_array = compress_array( 4096, $def, @_[0..65535] );
1883 my @array = compress_array( 256, 0, @row_array[0..4095] );
1885 for (my $i = 256; $i < @array; $i++) { $array[$i] += @array - 4096; }
1887 printf OUTPUT "const unsigned short DECLSPEC_HIDDEN %s[%d] =\n{\n", $name, @array + @row_array - 4096;
1888 printf OUTPUT " /* level 1 offsets */\n%s,\n", DUMP_ARRAY( "0x%04x", 0, @array[0..255] );
1889 printf OUTPUT " /* level 2 offsets */\n%s,\n", DUMP_ARRAY( "0x%04x", 0, @array[256..$#array] );
1890 printf OUTPUT " /* values */\n%s\n};\n", DUMP_ARRAY( "0x%04x", 0, @row_array[4096..$#row_array] );
1893 ################################################################
1894 # dump a binary case mapping table in l_intl.nls format
1895 sub dump_binary_case_table(@)
1897 my (@table) = @_;
1899 my %difftables_hash = ();
1900 my @difftables;
1901 my %offtables2_hash = ();
1902 my @offtables2 = ();
1904 my @offtable = ();
1905 for (my $i = 0; $i < 256; $i++)
1907 my @offtable2 = ();
1908 for(my $j = 0; $j < 16; $j++) # offset table for xx00-xxFF characters
1910 my @difftable;
1911 for (my $k = 0; $k < 16; $k++) # case map table for xxx0-xxxF characters
1913 my $char = ($i<<8) + ($j<<4) + $k;
1914 $difftable[$k] = (defined $table[$char]) ? (($table[$char]-$char) & 0xffff) : 0;
1917 my $diff_key = pack "S*", @difftable;
1918 my $offset3 = $difftables_hash{$diff_key};
1919 if (!defined $offset3)
1921 $offset3 = scalar @difftables;
1922 $difftables_hash{$diff_key} = $offset3;
1923 push @difftables, @difftable;
1925 $offtable2[$j] = $offset3;
1928 my $offtable2_key = pack "S*", @offtable2;
1929 my $offset2 = $offtables2_hash{$offtable2_key};
1930 if (!defined $offset2)
1932 $offset2 = scalar @offtables2;
1933 $offtables2_hash{$offtable2_key} = $offset2;
1934 push @offtables2, \@offtable2;
1936 $offtable[$i] = $offset2;
1939 my @output;
1940 my $offset = 0x100; # offset of first subtable in words
1941 foreach (@offtable)
1943 push @output, 0x10 * $_ + $offset; # offset of subtable in words
1946 $offset = 0x100 + 0x10 * scalar @offtables2; # offset of first difftable in words
1947 foreach(@offtables2)
1949 my $table = $_;
1950 foreach(@$table)
1952 push @output, $_ + $offset; # offset of difftable in words
1956 my $len = 1 + scalar @output + scalar @difftables;
1957 return pack "S<*", $len, @output, @difftables;
1961 ################################################################
1962 # dump case mappings for l_intl.nls
1963 sub dump_intl_nls($)
1965 my $filename = shift;
1966 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1967 printf "Building $filename\n";
1969 binmode OUTPUT;
1970 print OUTPUT pack "S<", 1; # version
1971 print OUTPUT dump_binary_case_table( @toupper_table );
1972 print OUTPUT dump_binary_case_table( @tolower_table );
1973 close OUTPUT;
1974 save_file($filename);
1978 sub load_nameprep_range_table($$$)
1980 my ($INPUT, $val, $table_ref) = @_;
1982 while (<$INPUT>)
1984 if (/^\s*([0-9a-fA-F]+)-([0-9a-fA-F]+)/)
1986 my $last = hex $2;
1987 $last = 65535 if($last >= 65536);
1988 foreach my $i (hex $1 .. $last)
1990 $table_ref->[$i] |= $val;
1992 next;
1994 elsif (/^\s*([0-9a-fA-F]+)/)
1996 if (hex $1 < 65536)
1998 $table_ref->[hex $1] |= $val;
2000 next;
2003 return if (/End\sTable/);
2007 sub load_nameprep_map_table($$)
2009 my ($INPUT, $table_ref) = @_;
2011 while (<$INPUT>)
2013 if (/^\s*([0-9a-fA-F]+);\s;/)
2015 # special value for map to nothing
2016 $table_ref->[hex $1] = [0xffff, 0xffff, 0xffff];
2017 next;
2019 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+);/)
2021 $table_ref->[hex $1] = [hex $2, 0, 0];
2022 next;
2024 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+)\s([0-9a-fA-F]+);/)
2026 $table_ref->[hex $1] = [hex $2, hex $3, 0];
2027 next;
2029 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+)\s([0-9a-fA-F]+)\s([0-9a-fA-F]+);/)
2031 $table_ref->[hex $1] = [hex $2, hex $3, hex $4];
2032 next;
2035 return if (/End\sTable/);
2039 ################################################################
2040 # dump mapping table, prohibited characters set, unassigned
2041 # characters, bidirectional rules used by nameprep algorithm
2042 sub dump_nameprep($)
2044 my $filename = shift;
2045 my @mapping_table = ();
2046 my @flags_table;
2048 my $INPUT = open_data_file( $RFCS, $STRINGPREP );
2049 while (<$INPUT>)
2051 next unless /Start\sTable/;
2053 load_nameprep_range_table($INPUT, $nameprep_flags{"unassigned"}, \@flags_table) if (/A.1/);
2054 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.1.2/);
2055 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.2.2/);
2056 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.3/);
2057 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.4/);
2058 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.5/);
2059 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.6/);
2060 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.7/);
2061 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.8/);
2062 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.9/);
2063 load_nameprep_range_table($INPUT, $nameprep_flags{"bidi_ral"}, \@flags_table) if (/D.1/);
2064 load_nameprep_range_table($INPUT, $nameprep_flags{"bidi_l"}, \@flags_table) if (/D.2/);
2066 load_nameprep_map_table($INPUT, \@mapping_table) if (/B.1/);
2067 load_nameprep_map_table($INPUT, \@mapping_table) if (/B.2/);
2069 close $INPUT;
2071 open OUTPUT,">$filename.new" or die "Cannot create $filename";
2072 print "Building $filename\n";
2073 print OUTPUT "/* Nameprep algorithm related data */\n";
2074 print OUTPUT "/* generated from $RFCS/$STRINGPREP */\n";
2075 print OUTPUT "/* DO NOT EDIT!! */\n\n";
2076 print OUTPUT "#include \"wine/unicode.h\"\n\n";
2078 dump_two_level_mapping( "nameprep_char_type", 0, @flags_table );
2080 ######### mapping table
2081 # first determine all the 16-char subsets that contain something
2082 my @filled = ();
2083 my $pos = 16*3; # for the null subset
2084 for (my $i = 0; $i < 65536; $i++)
2086 next unless defined $mapping_table[$i];
2087 $filled[$i >> 4] = $pos;
2088 $pos += 16*3;
2089 $i |= 15;
2091 my $total = $pos;
2093 # now count the 256-char subsets that contain something
2094 my @filled_idx = (256) x 256;
2095 $pos = 256 + 16;
2096 for (my $i = 0; $i < 4096; $i++)
2098 next unless $filled[$i];
2099 $filled_idx[$i >> 4] = $pos;
2100 $pos += 16;
2101 $i |= 15;
2103 my $null_offset = $pos;
2104 $total += $pos;
2106 # add the index offsets to the subsets positions
2107 for (my $i = 0; $i < 4096; $i++)
2109 next unless $filled[$i];
2110 $filled[$i] += $null_offset;
2113 # dump the main index
2114 printf OUTPUT "const unsigned short DECLSPEC_HIDDEN nameprep_mapping[%d] =\n", $total;
2115 printf OUTPUT "{\n /* index */\n";
2116 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @filled_idx );
2117 printf OUTPUT ",\n /* null sub-index */\n%s", DUMP_ARRAY( "0x%04x", 0, ($null_offset) x 16 );
2119 # dump the second-level indexes
2120 for (my $i = 0; $i < 256; $i++)
2122 next unless ($filled_idx[$i] > 256);
2123 my @table = @filled[($i<<4)..($i<<4)+15];
2124 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
2125 printf OUTPUT ",\n /* sub-index %02x */\n", $i;
2126 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
2129 # dump the 16-char subsets
2130 printf OUTPUT ",\n /* null mapping */\n";
2131 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, (0) x 48 );
2133 for (my $i = 0; $i < 4096; $i++)
2135 next unless $filled[$i];
2136 my @table = (0) x 48;
2137 for (my $j = 0; $j < 16; $j++)
2139 if (defined $mapping_table[($i<<4) + $j])
2141 $table[3 * $j] = ${$mapping_table[($i << 4) + $j]}[0];
2142 $table[3 * $j + 1] = ${$mapping_table[($i << 4) + $j]}[1];
2143 $table[3 * $j + 2] = ${$mapping_table[($i << 4) + $j]}[2];
2146 printf OUTPUT ",\n /* 0x%03x0 .. 0x%03xf */\n", $i, $i;
2147 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
2150 printf OUTPUT "\n};\n";
2152 close OUTPUT;
2153 save_file($filename);
2156 ################################################################
2157 # dump the ctype tables
2158 sub DUMP_CTYPE_TABLES($)
2160 my $filename = shift;
2161 open OUTPUT,">$filename.new" or die "Cannot create $filename";
2162 printf "Building $filename\n";
2163 printf OUTPUT "/* Unicode ctype tables */\n";
2164 printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
2165 printf OUTPUT "#include \"wine/unicode.h\"\n\n";
2167 # add the direction in the high 4 bits of the category
2168 for (my $i = 0; $i < 65536; $i++)
2170 $category_table[$i] |= $direction_table[$i] << 12 if defined $direction_table[$i];
2173 dump_simple_mapping( "wine_wctype_table", 0, @category_table );
2175 close OUTPUT;
2176 save_file($filename);
2180 ################################################################
2181 # dump the char composition table
2182 sub dump_compose_table($)
2184 my $filename = shift;
2186 open OUTPUT,">$filename.new" or die "Cannot create $filename";
2187 print "Building $filename\n";
2188 print OUTPUT "/* Unicode char composition */\n";
2189 print OUTPUT "/* generated from $UNIDATA/UnicodeData.txt */\n";
2190 print OUTPUT "/* DO NOT EDIT!! */\n\n";
2191 print OUTPUT "#include \"wine/unicode.h\"\n\n";
2193 my @filled = ();
2194 foreach my $i (@compose_table)
2196 my @comp = @$i;
2197 push @{$filled[$comp[1]]}, [ $comp[0], $comp[2] ];
2200 # count how many different second chars we have
2202 my $count = 0;
2203 for (my $i = 0; $i < 65536; $i++)
2205 next unless defined $filled[$i];
2206 $count++;
2209 # build the table of second chars and offsets
2211 my $pos = $count + 1;
2212 my @table = ();
2213 for (my $i = 0; $i < 65536; $i++)
2215 next unless defined $filled[$i];
2216 push @table, $i, $pos;
2217 $pos += @{$filled[$i]};
2219 # terminator with last position
2220 push @table, 0, $pos;
2221 printf OUTPUT "static const WCHAR table[0x%x] =\n{\n", 2*$pos;
2222 printf OUTPUT " /* second chars + offsets */\n%s", DUMP_ARRAY( "0x%04x", 0, @table );
2224 # build the table of first chars and mappings
2226 for (my $i = 0; $i < 65536; $i++)
2228 next unless defined $filled[$i];
2229 my @table = ();
2230 my @list = sort { $a->[0] <=> $b->[0] } @{$filled[$i]};
2231 for (my $j = 0; $j <= $#list; $j++)
2233 push @table, $list[$j][0], $list[$j][1];
2235 printf OUTPUT ",\n /* 0x%04x */\n%s", $i, DUMP_ARRAY( "0x%04x", 0, @table );
2237 print OUTPUT "\n};\n\n";
2238 print OUTPUT <<"EOF";
2239 static inline int binary_search( WCHAR ch, int low, int high )
2241 while (low <= high)
2243 int pos = (low + high) / 2;
2244 if (table[2 * pos] < ch) low = pos + 1;
2245 else if (table[2 * pos] > ch) high = pos - 1;
2246 else return pos;
2248 return -1;
2251 WCHAR DECLSPEC_HIDDEN wine_compose( const WCHAR *str )
2253 int pos, idx = 1, start = 0, count = $count;
2254 for (;;)
2256 if ((pos = binary_search( str[idx], start, count - 1 )) == -1) return 0;
2257 if (!idx--) return table[2 * pos + 1];
2258 start = table[2 * pos + 1];
2259 count = table[2 * pos + 3];
2263 close OUTPUT;
2264 save_file($filename);
2267 ################################################################
2268 # dump the char decomposition table
2269 sub dump_decompose_table($)
2271 my $filename = shift;
2273 open OUTPUT,">$filename.new" or die "Cannot create $filename";
2274 print "Building $filename\n";
2275 print OUTPUT "/* Unicode char composition */\n";
2276 print OUTPUT "/* generated from $UNIDATA/UnicodeData.txt */\n";
2277 print OUTPUT "/* DO NOT EDIT!! */\n\n";
2278 print OUTPUT "#include \"wine/unicode.h\"\n\n";
2280 # first determine all the 16-char subsets that contain something
2282 my @filled = (0) x 4096;
2283 my $pos = 16*2; # for the null subset
2284 for (my $i = 0; $i < 65536; $i++)
2286 next unless defined $decomp_table[$i];
2287 $filled[$i >> 4] = $pos;
2288 $pos += 16*2;
2289 $i |= 15;
2291 my $total = $pos;
2293 # now count the 256-char subsets that contain something
2295 my @filled_idx = (256) x 256;
2296 $pos = 256 + 16;
2297 for (my $i = 0; $i < 4096; $i++)
2299 next unless $filled[$i];
2300 $filled_idx[$i >> 4] = $pos;
2301 $pos += 16;
2302 $i |= 15;
2304 my $null_offset = $pos; # null mapping
2305 $total += $pos;
2307 # add the index offsets to the subsets positions
2309 for (my $i = 0; $i < 4096; $i++)
2311 next unless $filled[$i];
2312 $filled[$i] += $null_offset;
2315 # dump the main index
2317 printf OUTPUT "static const WCHAR table[%d] =\n", $total;
2318 printf OUTPUT "{\n /* index */\n";
2319 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @filled_idx );
2320 printf OUTPUT ",\n /* null sub-index */\n%s", DUMP_ARRAY( "0x%04x", 0, ($null_offset) x 16 );
2322 # dump the second-level indexes
2324 for (my $i = 0; $i < 256; $i++)
2326 next unless ($filled_idx[$i] > 256);
2327 my @table = @filled[($i<<4)..($i<<4)+15];
2328 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
2329 printf OUTPUT ",\n /* sub-index %02x */\n", $i;
2330 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
2333 # dump the 16-char subsets
2335 printf OUTPUT ",\n /* null mapping */\n";
2336 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, (0) x 32 );
2338 for (my $i = 0; $i < 4096; $i++)
2340 next unless $filled[$i];
2341 my @table = (0) x 32;
2342 for (my $j = 0; $j < 16; $j++)
2344 if (defined $decomp_table[($i<<4) + $j])
2346 $table[2 * $j] = ${$decomp_table[($i << 4) + $j]}[0];
2347 $table[2 * $j + 1] = ${$decomp_table[($i << 4) + $j]}[1];
2350 printf OUTPUT ",\n /* 0x%03x0 .. 0x%03xf */\n", $i, $i;
2351 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
2354 printf OUTPUT "\n};\n\n";
2355 print OUTPUT <<"EOF";
2356 unsigned int DECLSPEC_HIDDEN wine_decompose( WCHAR ch, WCHAR *dst, unsigned int dstlen )
2358 const WCHAR *ptr = table + table[table[ch >> 8] + ((ch >> 4) & 0x0f)] + 2 * (ch & 0xf);
2359 unsigned int res;
2361 *dst = ch;
2362 if (!*ptr) return 1;
2363 if (dstlen <= 1) return 0;
2364 /* apply the decomposition recursively to the first char */
2365 if ((res = wine_decompose( *ptr, dst, dstlen-1 ))) dst[res++] = ptr[1];
2366 return res;
2369 close OUTPUT;
2370 save_file($filename);
2373 ################################################################
2374 # output a codepage definition file from the global tables
2375 sub output_codepage_file($$$$)
2377 my ($codepage, $filename, $comment, $has_glyphs) = @_;
2379 my $output = sprintf "libs/port/c_%03d.c", $codepage;
2380 open OUTPUT,">$output.new" or die "Cannot create $output";
2382 printf "Building %s from %s (%s)\n", $output, $filename || "hardcoded data", $comment;
2384 # dump all tables
2386 printf OUTPUT "/* code page %03d (%s) */\n", $codepage, $comment;
2387 if ($filename)
2389 print OUTPUT "/* generated from $MAPPINGS/$filename */\n";
2390 print OUTPUT "/* DO NOT EDIT!! */\n\n";
2392 else
2394 printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
2396 printf OUTPUT "#include \"wine/unicode.h\"\n\n";
2398 if (!@lead_bytes) { dump_sbcs_table( $codepage, $has_glyphs, $comment, $default_char, $default_wchar ); }
2399 else { dump_dbcs_table( $codepage, $comment, $default_char, $default_wchar, get_lb_ranges() ); }
2400 close OUTPUT;
2401 save_file($output);
2404 ################################################################
2405 # read a "bestfit" Windows mapping file
2406 sub read_bestfit_file($)
2408 my ($filename) = @_;
2409 my $state = "";
2410 my ($codepage, $width, $count);
2411 my ($lb_cur, $lb_end);
2413 my $INPUT = open_data_file( $MAPPINGS, $filename ) or die "Cannot open $filename";
2415 while (<$INPUT>)
2417 next if /^;/; # skip comments
2418 next if /^\s*$/; # skip empty lines
2419 next if /\x1a/; # skip ^Z
2420 last if /^ENDCODEPAGE/;
2422 if (/^CODEPAGE\s+(\d+)/)
2424 $codepage = $1;
2425 next;
2427 if (/^CPINFO\s+(\d+)\s+0x([0-9a-fA-f]+)\s+0x([0-9a-fA-F]+)/)
2429 $width = $1;
2430 $default_char = hex $2;
2431 $default_wchar = hex $3;
2432 next;
2434 if (/^(MBTABLE|WCTABLE|DBCSRANGE|DBCSTABLE)\s+(\d+)/)
2436 $state = $1;
2437 $count = $2;
2438 next;
2440 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)/)
2442 if ($state eq "MBTABLE")
2444 my $cp = hex $1;
2445 my $uni = hex $2;
2446 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
2447 next;
2449 if ($state eq "WCTABLE")
2451 my $uni = hex $1;
2452 my $cp = hex $2;
2453 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
2454 next;
2456 if ($state eq "DBCSRANGE")
2458 my $start = hex $1;
2459 my $end = hex $2;
2460 for (my $i = $start; $i <= $end; $i++) { add_lead_byte( $i ); }
2461 $lb_cur = $start;
2462 $lb_end = $end;
2463 next;
2465 if ($state eq "DBCSTABLE")
2467 my $mb = hex $1;
2468 my $uni = hex $2;
2469 my $cp = ($lb_cur << 8) | $mb;
2470 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
2471 if (!--$count)
2473 if (++$lb_cur > $lb_end) { $state = "DBCSRANGE"; }
2475 next;
2478 die "$filename: Unrecognized line $_\n";
2480 close $INPUT;
2484 ################################################################
2485 # read an input file and generate the corresponding .c file
2486 sub HANDLE_FILE(@)
2488 my ($codepage,$filename,$has_glyphs,$comment,$first_private,$def,$defw) = @_;
2490 @cp2uni = ();
2491 @lead_bytes = ();
2492 @uni2cp = ();
2493 $default_char = $def || $DEF_CHAR;
2494 $default_wchar = $defw || $DEF_CHAR;
2496 # some codepage files are special
2497 if ($codepage == 20932)
2499 READ_JIS0208_FILE( $filename );
2500 add_default_mappings( $first_private );
2502 elsif ($codepage == 20127)
2504 fill_20127_codepage();
2505 add_default_mappings( $first_private );
2507 elsif ($filename =~ /\/bestfit/)
2509 read_bestfit_file( $filename );
2511 else
2513 read_codepage_file( $filename );
2514 if ($codepage == 10001)
2516 # add Shift-JIS mappings
2517 read_bestfit_file( "VENDORS/MICSFT/WindowsBestFit/bestfit932.txt" );
2519 else
2521 add_default_mappings( $first_private );
2525 output_codepage_file( $codepage, $filename, $comment, $has_glyphs );
2529 ################################################################
2530 # save a file if modified
2531 sub save_file($)
2533 my $file = shift;
2534 if (-f $file && !system "cmp $file $file.new >/dev/null")
2536 unlink "$file.new";
2538 else
2540 rename "$file.new", "$file";
2545 ################################################################
2546 # output the list of codepage tables into the cptable.c file
2547 sub output_cptable($)
2549 my $output = shift;
2550 my @tables_decl = ();
2552 printf "Building %s\n", $output;
2554 foreach my $file (@allfiles)
2556 my ($codepage,$filename) = @$file;
2557 push @tables_decl, sprintf("extern union cptable cptable_%03d;\n",$codepage);
2560 push @tables_decl, sprintf("\nstatic const union cptable * const cptables[%d] =\n{\n",$#allfiles+1);
2561 foreach my $file (@allfiles)
2563 my ($codepage,$filename) = @$file;
2564 push @tables_decl, sprintf(" &cptable_%03d,\n", $codepage);
2566 push @tables_decl, "};";
2567 REPLACE_IN_FILE( $output, @tables_decl );
2570 ################################################################
2571 # replace the contents of a file between ### cpmap ### marks
2573 sub REPLACE_IN_FILE($@)
2575 my $name = shift;
2576 my @data = @_;
2577 my @lines = ();
2578 open(FILE,$name) or die "Can't open $name";
2579 while (<FILE>)
2581 push @lines, $_;
2582 last if /\#\#\# cpmap begin \#\#\#/;
2584 push @lines, @data;
2585 while (<FILE>)
2587 if (/\#\#\# cpmap end \#\#\#/) { push @lines, "\n", $_; last; }
2589 push @lines, <FILE>;
2590 open(FILE,">$name.new") or die "Can't modify $name";
2591 print FILE @lines;
2592 close(FILE);
2593 save_file($name);
2596 ################################################################
2597 # main routine
2599 chdir ".." if -f "./make_unicode";
2600 READ_DEFAULTS( $DEFAULTS );
2601 DUMP_CASE_MAPPINGS( "libs/wine/casemap.c" );
2602 DUMP_SORTKEYS( "libs/wine/collation.c", READ_SORTKEYS_FILE() );
2603 dump_compose_table( "libs/port/compose.c" );
2604 dump_decompose_table( "libs/port/decompose.c" );
2605 DUMP_CTYPE_TABLES( "libs/wine/wctype.c" );
2606 dump_digit_folding( "libs/port/digitmap.c" );
2607 dump_mirroring( "dlls/usp10/mirror.c" );
2608 dump_mirroring( "dlls/dwrite/mirror.c" );
2609 dump_bracket( "dlls/usp10/bracket.c" );
2610 dump_bracket( "dlls/dwrite/bracket.c" );
2611 dump_shaping( "dlls/usp10/shaping.c" );
2612 dump_linebreak( "dlls/usp10/linebreak.c" );
2613 dump_linebreak( "dlls/dwrite/linebreak.c" );
2614 dump_scripts( "dlls/dwrite/scripts" );
2615 dump_indic( "dlls/usp10/indicsyllable.c" );
2616 dump_intl_nls("loader/l_intl.nls");
2617 dump_vertical( "dlls/gdi32/vertical.c" );
2618 dump_vertical( "dlls/wineps.drv/vertical.c" );
2619 dump_nameprep( "dlls/kernel32/nameprep.c" );
2621 foreach my $file (@allfiles) { HANDLE_FILE( @{$file} ); }
2623 output_cptable("libs/port/cptable.c");
2625 exit 0;
2627 # Local Variables:
2628 # compile-command: "./make_unicode"
2629 # End: