msvcp100/tests: Fix dynamically loaded functions for platform arm.
[wine/multimedia.git] / tools / make_unicode
blob0db950905a2e5f3a0315663e1a6bdc160a9c7068
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/6.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" ],
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" ],
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" ],
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" ],
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" ],
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" ],
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, "OBSOLETE/EASTASIA/KSC/JOHAB.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" ],
86 [ 10006, "VENDORS/MICSFT/MAC/GREEK.TXT", 0, "Mac Greek" ],
87 [ 10007, "VENDORS/MICSFT/MAC/CYRILLIC.TXT", 0, "Mac Cyrillic" ],
88 [ 10008, "VENDORS/APPLE/CHINSIMP.TXT", 0, "Mac Simplified Chinese" ],
89 [ 10010, "VENDORS/APPLE/ROMANIAN.TXT", 0, "Mac Romanian" ],
90 [ 10017, "VENDORS/APPLE/CYRILLIC.TXT", 0, "Mac Ukrainian" ],
91 [ 10021, "VENDORS/APPLE/THAI.TXT", 0, "Mac Thai" ],
92 [ 10029, "VENDORS/MICSFT/MAC/LATIN2.TXT", 0, "Mac Latin 2" ],
93 [ 10079, "VENDORS/MICSFT/MAC/ICELAND.TXT", 0, "Mac Icelandic" ],
94 [ 10081, "VENDORS/MICSFT/MAC/TURKISH.TXT", 0, "Mac Turkish" ],
95 [ 10082, "VENDORS/APPLE/CROATIAN.TXT", 0, "Mac Croatian" ],
96 [ 20127, undef, 0, "US-ASCII (7bit)" ],
97 [ 20866, "VENDORS/MISC/KOI8-R.TXT", 0, "Russian KOI8" ],
98 [ 20932, "OBSOLETE/EASTASIA/JIS/JIS0208.TXT", 0, "EUC-JP" ],
99 [ 21866, "VENDORS/MISC/KOI8-U.TXT", 0, "Ukrainian KOI8" ],
100 [ 28591, "ISO8859/8859-1.TXT", 0, "ISO 8859-1 Latin 1" ],
101 [ 28592, "ISO8859/8859-2.TXT", 0, "ISO 8859-2 Latin 2 (East European)" ],
102 [ 28593, "ISO8859/8859-3.TXT", 0, "ISO 8859-3 Latin 3 (South European)" ],
103 [ 28594, "ISO8859/8859-4.TXT", 0, "ISO 8859-4 Latin 4 (Baltic old)" ],
104 [ 28595, "ISO8859/8859-5.TXT", 0, "ISO 8859-5 Cyrillic" ],
105 [ 28596, "ISO8859/8859-6.TXT", 0, "ISO 8859-6 Arabic" ],
106 [ 28597, "ISO8859/8859-7.TXT", 0, "ISO 8859-7 Greek" ],
107 [ 28598, "ISO8859/8859-8.TXT", 0, "ISO 8859-8 Hebrew" ],
108 [ 28599, "ISO8859/8859-9.TXT", 0, "ISO 8859-9 Latin 5 (Turkish)" ],
109 [ 28600, "ISO8859/8859-10.TXT", 0, "ISO 8859-10 Latin 6 (Nordic)" ],
110 [ 28603, "ISO8859/8859-13.TXT", 0, "ISO 8859-13 Latin 7 (Baltic)" ],
111 [ 28604, "ISO8859/8859-14.TXT", 0, "ISO 8859-14 Latin 8 (Celtic)" ],
112 [ 28605, "ISO8859/8859-15.TXT", 0, "ISO 8859-15 Latin 9 (Euro)" ],
113 [ 28606, "ISO8859/8859-16.TXT", 0, "ISO 8859-16 Latin 10 (Balkan)" ]
117 my %ctype =
119 "upper" => 0x0001,
120 "lower" => 0x0002,
121 "digit" => 0x0004,
122 "space" => 0x0008,
123 "punct" => 0x0010,
124 "cntrl" => 0x0020,
125 "blank" => 0x0040,
126 "xdigit" => 0x0080,
127 "alpha" => 0x0100,
128 "defin" => 0x0200
131 my %indic_types =
133 "Other" => 0x0000,
134 "Bindu" => 0x0001,
135 "Visarga" => 0x0002,
136 "Avagraha" => 0x0003,
137 "Nukta" => 0x0004,
138 "Virama" => 0x0005,
139 "Vowel_Independent" => 0x0006,
140 "Vowel_Dependent" => 0x0007,
141 "Vowel" => 0x0008,
142 "Consonant_Placeholder" => 0x0009,
143 "Consonant" => 0x000a,
144 "Consonant_Dead" => 0x000b,
145 "Consonant_Repha" => 0x000c,
146 "Consonant_Subjoined" => 0x000d,
147 "Consonant_Medial" => 0x000e,
148 "Consonant_Final" => 0x000f,
149 "Consonant_Head_Letter" => 0x0010,
150 "Modifying_Letter" => 0x0011,
151 "Tone_Letter" => 0x0012,
152 "Tone_Mark" => 0x0013,
153 "Register_Shifter" => 0x0014
156 my %matra_types =
158 "Right" => 0x01,
159 "Left" => 0x02,
160 "Visual_Order_Left" => 0x03,
161 "Left_And_Right" => 0x04,
162 "Top" => 0x05,
163 "Bottom" => 0x06,
164 "Top_And_Bottom" => 0x07,
165 "Top_And_Right" => 0x08,
166 "Top_And_Left" => 0x09,
167 "Top_And_Left_And_Right" => 0x0a,
168 "Bottom_And_Right" => 0x0b,
169 "Top_And_Bottom_And_Right" => 0x0c,
170 "Overstruck" => 0x0d,
171 "Invisible" => 0x0e
174 my %nameprep_flags =
176 "unassigned" => 0x01,
177 "prohibited" => 0x02,
178 "bidi_ral" => 0x04,
179 "bidi_l" => 0x08
182 my %break_types =
184 "BK" => 0x0001,
185 "CR" => 0x0002,
186 "LF" => 0x0003,
187 "CM" => 0x0004,
188 "SG" => 0x0005,
189 "GL" => 0x0006,
190 "CB" => 0x0007,
191 "SP" => 0x0008,
192 "ZW" => 0x0009,
193 "NL" => 0x000a,
194 "WJ" => 0x000b,
195 "JL" => 0x000c,
196 "JV" => 0x000d,
197 "JT" => 0x000e,
198 "H2" => 0x000f,
199 "H3" => 0x0010,
200 "XX" => 0x0011,
201 "OP" => 0x0012,
202 "CL" => 0x0013,
203 "CP" => 0x0014,
204 "QU" => 0x0015,
205 "NS" => 0x0016,
206 "EX" => 0x0017,
207 "SY" => 0x0018,
208 "IS" => 0x0019,
209 "PR" => 0x001a,
210 "PO" => 0x001b,
211 "NU" => 0x001c,
212 "AL" => 0x001d,
213 "ID" => 0x001e,
214 "IN" => 0x001f,
215 "HY" => 0x0020,
216 "BB" => 0x0021,
217 "BA" => 0x0022,
218 "SA" => 0x0023,
219 "AI" => 0x0024,
220 "B2" => 0x0025
223 my %categories =
225 "Lu" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"upper"}, # Letter, Uppercase
226 "Ll" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"lower"}, # Letter, Lowercase
227 "Lt" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"upper"}|$ctype{"lower"}, # Letter, Titlecase
228 "Mn" => $ctype{"defin"}, # Mark, Non-Spacing
229 "Mc" => $ctype{"defin"}, # Mark, Spacing Combining
230 "Me" => $ctype{"defin"}, # Mark, Enclosing
231 "Nd" => $ctype{"defin"}|$ctype{"digit"}, # Number, Decimal Digit
232 "Nl" => $ctype{"defin"}|$ctype{"alpha"}, # Number, Letter
233 "No" => $ctype{"defin"}, # Number, Other
234 "Zs" => $ctype{"defin"}|$ctype{"space"}, # Separator, Space
235 "Zl" => $ctype{"defin"}|$ctype{"space"}, # Separator, Line
236 "Zp" => $ctype{"defin"}|$ctype{"space"}, # Separator, Paragraph
237 "Cc" => $ctype{"defin"}|$ctype{"cntrl"}, # Other, Control
238 "Cf" => $ctype{"defin"}|$ctype{"cntrl"}, # Other, Format
239 "Cs" => $ctype{"defin"}, # Other, Surrogate
240 "Co" => $ctype{"defin"}, # Other, Private Use
241 "Cn" => $ctype{"defin"}, # Other, Not Assigned
242 "Lm" => $ctype{"defin"}|$ctype{"alpha"}, # Letter, Modifier
243 "Lo" => $ctype{"defin"}|$ctype{"alpha"}, # Letter, Other
244 "Pc" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Connector
245 "Pd" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Dash
246 "Ps" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Open
247 "Pe" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Close
248 "Pi" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Initial quote
249 "Pf" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Final quote
250 "Po" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Other
251 "Sm" => $ctype{"defin"}, # Symbol, Math
252 "Sc" => $ctype{"defin"}, # Symbol, Currency
253 "Sk" => $ctype{"defin"}, # Symbol, Modifier
254 "So" => $ctype{"defin"} # Symbol, Other
257 # a few characters need additional categories that cannot be determined automatically
258 my %special_categories =
260 "xdigit" => [ ord('0')..ord('9'),ord('A')..ord('F'),ord('a')..ord('f'),
261 0xff10..0xff19, 0xff21..0xff26, 0xff41..0xff46 ],
262 "space" => [ 0x09..0x0d, 0x85 ],
263 "blank" => [ 0x09, 0x20, 0xa0, 0x3000, 0xfeff ],
264 "cntrl" => [ 0x070f, 0x200c, 0x200d,
265 0x200e, 0x200f, 0x202a, 0x202b, 0x202c, 0x202d, 0x202e,
266 0x206a, 0x206b, 0x206c, 0x206d, 0x206e, 0x206f, 0xfeff,
267 0xfff9, 0xfffa, 0xfffb ],
268 "punct" => [ 0x24, 0x2b, 0x3c..0x3e, 0x5e, 0x60, 0x7c, 0x7e, 0xa2..0xbe,
269 0xd7, 0xf7 ],
270 "digit" => [ 0xb2, 0xb3, 0xb9 ],
271 "lower" => [ 0x2071, 0x207f ]
274 my %directions =
276 "L" => 1, # Left-to-Right
277 "LRE" => 15, # Left-to-Right Embedding
278 "LRO" => 15, # Left-to-Right Override
279 "R" => 2, # Right-to-Left
280 "AL" => 12, # Right-to-Left Arabic
281 "RLE" => 15, # Right-to-Left Embedding
282 "RLO" => 15, # Right-to-Left Override
283 "PDF" => 15, # Pop Directional Format
284 "EN" => 3, # European Number
285 "ES" => 4, # European Number Separator
286 "ET" => 5, # European Number Terminator
287 "AN" => 6, # Arabic Number
288 "CS" => 7, # Common Number Separator
289 "NSM" => 13, # Non-Spacing Mark
290 "BN" => 14, # Boundary Neutral
291 "B" => 8, # Paragraph Separator
292 "S" => 9, # Segment Separator
293 "WS" => 10, # Whitespace
294 "ON" => 11 # Other Neutrals
297 my %joining_types =
299 "U" => 0, # Non_Joining
300 "T" => 1, # Transparent
301 "R" => 2, # Right_Joining
302 "L" => 3, # Left_Joining
303 "D" => 4, # Dual_Joining
304 "C" => 5, # Join_Causing
307 my @cp2uni = ();
308 my @lead_bytes = ();
309 my @uni2cp = ();
310 my @unicode_defaults = ();
311 my @unicode_aliases = ();
312 my @tolower_table = ();
313 my @toupper_table = ();
314 my @digitmap_table = ();
315 my @compatmap_table = ();
316 my @category_table = (0) x 65536;
317 my @joining_table = (0) x 65536;
318 my @direction_table = ();
319 my @decomp_table = ();
320 my @compose_table = ();
321 my $default_char;
322 my $default_wchar;
324 my %joining_forms =
326 "isolated" => [],
327 "final" => [],
328 "initial" => [],
329 "medial" => []
332 ################################################################
333 # fetch a unicode.org file and open it
334 sub open_data_file($$)
336 my ($base, $name) = @_;
337 (my $dir = "data/$name") =~ s/\/[^\/]+$//;
338 local *FILE;
339 unless (-f "data/$name")
341 print "Fetching $base/$name...\n";
342 system "mkdir", "-p", $dir;
343 !system "wget", "-q", "-O", "data/$name", "$base/$name" or die "cannot fetch $base/$name";
345 open FILE, "<data/$name" or die "cannot open data/$name";
346 return *FILE;
349 ################################################################
350 # read in the defaults file
351 sub READ_DEFAULTS($)
353 my $filename = shift;
354 my $start;
356 # first setup a few default mappings
358 open DEFAULTS, "$filename" or die "Cannot open $filename";
359 print "Loading $filename\n";
360 while (<DEFAULTS>)
362 next if /^\#/; # skip comments
363 next if /^$/; # skip empty lines
364 if (/^(([0-9a-fA-F]+)(,[0-9a-fA-F]+)*)\s+([0-9a-fA-F]+|'.'|none)\s+(\#.*)?/)
366 my @src = map hex, split /,/,$1;
367 my $dst = $4;
368 my $comment = $5;
369 if ($#src > 0) { push @unicode_aliases, \@src; }
370 next if ($dst eq "none");
371 $dst = ($dst =~ /\'.\'/) ? ord substr($dst,1,1) : hex $dst;
372 foreach my $src (@src)
374 die "Duplicate value" if defined($unicode_defaults[$src]);
375 $unicode_defaults[$src] = $dst;
377 next;
379 die "Unrecognized line $_\n";
381 close DEFAULTS;
383 # now build mappings from the decomposition field of the Unicode database
385 my $UNICODE_DATA = open_data_file( $UNIDATA, "UnicodeData.txt" );
386 while (<$UNICODE_DATA>)
388 # Decode the fields ...
389 my ($code, $name, $cat, $comb, $bidi,
390 $decomp, $dec, $dig, $num, $mirror,
391 $oldname, $comment, $upper, $lower, $title) = split /;/;
392 my $dst;
393 my $src = hex $code;
395 die "unknown category $cat" unless defined $categories{$cat};
396 die "unknown directionality $bidi" unless defined $directions{$bidi};
398 $category_table[$src] = $categories{$cat};
399 $direction_table[$src] = $directions{$bidi};
400 $joining_table[$src] = $joining_types{"T"} if $cat eq "Mn" || $cat eq "Me" || $cat eq "Cf";
402 if ($lower ne "")
404 $tolower_table[$src] = hex $lower;
406 if ($upper ne "")
408 $toupper_table[$src] = hex $upper;
410 if ($dec ne "")
412 $category_table[$src] |= $ctype{"digit"};
414 if ($dig ne "")
416 $digitmap_table[$src] = ord $dig;
419 # copy the category and direction for everything between First/Last pairs
420 if ($name =~ /, First>/) { $start = $src; }
421 if ($name =~ /, Last>/)
423 while ($start < $src)
425 $category_table[$start] = $category_table[$src];
426 $direction_table[$start] = $direction_table[$src];
427 $start++;
431 next if $decomp eq ""; # no decomposition, skip it
433 if ($decomp =~ /^<([a-zA-Z]+)>\s+([0-9a-fA-F]+)$/)
435 # decomposition of the form "<foo> 1234" -> use char if type is known
436 if (($src >= 0xf900 && $src < 0xfb00) || ($src >= 0xfe30 && $src < 0xfffd))
438 # Single char decomposition in the compatibility range
439 $compatmap_table[$src] = hex $2;
441 if ($1 eq "isolated" || $1 eq "final" || $1 eq "initial" || $1 eq "medial")
443 ${joining_forms{$1}}[hex $2] = $src;
444 next;
446 next unless ($1 eq "font" ||
447 $1 eq "noBreak" ||
448 $1 eq "circle" ||
449 $1 eq "super" ||
450 $1 eq "sub" ||
451 $1 eq "wide" ||
452 $1 eq "narrow" ||
453 $1 eq "compat" ||
454 $1 eq "small");
455 $dst = hex $2;
457 elsif ($decomp =~ /^<compat>\s+0020\s+([0-9a-fA-F]+)/)
459 # decomposition "<compat> 0020 1234" -> combining accent
460 $dst = hex $1;
462 elsif ($decomp =~ /^([0-9a-fA-F]+)/)
464 # decomposition contains only char values without prefix -> use first char
465 $dst = hex $1;
466 $category_table[$src] |= $category_table[$dst] if defined $category_table[$dst];
467 # store decomposition if it contains two chars
468 if ($decomp =~ /^([0-9a-fA-F]+)\s+([0-9a-fA-F]+)$/)
470 $decomp_table[$src] = [ hex $1, hex $2 ];
471 push @compose_table, [ hex $1, hex $2, $src ];
473 elsif ($decomp =~ /^(<[a-z]+>\s)*([0-9a-fA-F]+)$/ &&
474 (($src >= 0xf900 && $src < 0xfb00) || ($src >= 0xfe30 && $src < 0xfffd)))
476 # Single char decomposition in the compatibility range
477 $compatmap_table[$src] = hex $2;
480 else
482 next;
485 next if defined($unicode_defaults[$src]); # may have been set in the defaults file
487 # check for loops
488 for (my $i = $dst; ; $i = $unicode_defaults[$i])
490 die sprintf("loop detected for %04x -> %04x",$src,$dst) if $i == $src;
491 last unless defined($unicode_defaults[$i]);
493 $unicode_defaults[$src] = $dst;
495 close $UNICODE_DATA;
497 # patch the category of some special characters
499 foreach my $cat (keys %special_categories)
501 my $flag = $ctype{$cat};
502 foreach my $i (@{$special_categories{$cat}}) { $category_table[$i] |= $flag; }
507 ################################################################
508 # define a new lead byte
509 sub add_lead_byte($)
511 my $ch = shift;
512 push @lead_bytes, $ch;
513 $cp2uni[$ch] = 0;
516 ################################################################
517 # define a new char mapping
518 sub add_mapping($$)
520 my ($cp, $uni) = @_;
521 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
522 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
523 if ($cp > 0xff && !defined($cp2uni[$cp >> 8]))
525 add_lead_byte( $cp >> 8 );
529 ################################################################
530 # parse a standard codepage file
531 sub read_codepage_file($)
533 my $name = shift;
534 my $INPUT = open_data_file( $MAPPINGS, $name );
536 while (<$INPUT>)
538 next if /^\#/; # skip comments
539 next if /^$/; # skip empty lines
540 next if /\x1a/; # skip ^Z
541 next if (/^0x([0-9a-fA-F]+)\s+\#UNDEFINED/); # undefined char
543 if (/^0x([0-9a-fA-F]+)\s+\#DBCS LEAD BYTE/)
545 add_lead_byte( hex $1 );
546 next;
548 # 0x12 0x3456
549 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
551 add_mapping( hex $1, hex $2 );
552 next;
554 # 0x12 0x3456+0x7890
555 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\+.*\s+(\#.*)?/)
557 add_mapping( hex $1, hex $2 );
558 next;
560 # 0x12 <LR>+0x3456
561 if (/^0x([0-9a-fA-F]+)\s+<[LR]+>\+0x([0-9a-fA-F]+)\s+(\#.*)?/)
563 add_mapping( hex $1, hex $2 );
564 next;
566 die "$name: Unrecognized line $_\n";
568 close $INPUT;
572 ################################################################
573 # fill input data for the 20127 (us-ascii) codepage
574 sub fill_20127_codepage()
576 for (my $i = 0; $i < 128; $i++) { $cp2uni[$i] = $uni2cp[$i] = $i; }
577 for (my $i = 128; $i < 256; $i++) { $cp2uni[$i] = $i & 0x7f; }
580 ################################################################
581 # get a mapping including glyph chars for MB_USEGLYPHCHARS
583 sub get_glyphs_mapping(@)
585 $_[0x01] = 0x263a; # (WHITE SMILING FACE)
586 $_[0x02] = 0x263b; # (BLACK SMILING FACE)
587 $_[0x03] = 0x2665; # (BLACK HEART SUIT)
588 $_[0x04] = 0x2666; # (BLACK DIAMOND SUIT)
589 $_[0x05] = 0x2663; # (BLACK CLUB SUIT)
590 $_[0x06] = 0x2660; # (BLACK SPADE SUIT)
591 $_[0x07] = 0x2022; # (BULLET)
592 $_[0x08] = 0x25d8; # (INVERSE BULLET)
593 $_[0x09] = 0x25cb; # (WHITE CIRCLE)
594 $_[0x0a] = 0x25d9; # (INVERSE WHITE CIRCLE)
595 $_[0x0b] = 0x2642; # (MALE SIGN)
596 $_[0x0c] = 0x2640; # (FEMALE SIGN)
597 $_[0x0d] = 0x266a; # (EIGHTH NOTE)
598 $_[0x0e] = 0x266b; # (BEAMED EIGHTH NOTES)
599 $_[0x0f] = 0x263c; # (WHITE SUN WITH RAYS)
600 $_[0x10] = 0x25ba; # (BLACK RIGHT-POINTING POINTER)
601 $_[0x11] = 0x25c4; # (BLACK LEFT-POINTING POINTER)
602 $_[0x12] = 0x2195; # (UP DOWN ARROW)
603 $_[0x13] = 0x203c; # (DOUBLE EXCLAMATION MARK)
604 $_[0x14] = 0x00b6; # (PILCROW SIGN)
605 $_[0x15] = 0x00a7; # (SECTION SIGN)
606 $_[0x16] = 0x25ac; # (BLACK RECTANGLE)
607 $_[0x17] = 0x21a8; # (UP DOWN ARROW WITH BASE)
608 $_[0x18] = 0x2191; # (UPWARDS ARROW)
609 $_[0x19] = 0x2193; # (DOWNWARDS ARROW)
610 $_[0x1a] = 0x2192; # (RIGHTWARDS ARROW)
611 $_[0x1b] = 0x2190; # (LEFTWARDS ARROW)
612 $_[0x1c] = 0x221f; # (RIGHT ANGLE)
613 $_[0x1d] = 0x2194; # (LEFT RIGHT ARROW)
614 $_[0x1e] = 0x25b2; # (BLACK UP-POINTING TRIANGLE)
615 $_[0x1f] = 0x25bc; # (BLACK DOWN-POINTING TRIANGLE)
616 $_[0x7f] = 0x2302; # (HOUSE)
617 return @_;
620 ################################################################
621 # build EUC-JP table from the JIS 0208 file
622 # FIXME: for proper EUC-JP we should probably read JIS 0212 too
623 # but this would require 3-byte DBCS characters
624 sub READ_JIS0208_FILE($)
626 my $name = shift;
628 # ASCII chars
629 for (my $i = 0x00; $i <= 0x7f; $i++)
631 $cp2uni[$i] = $i;
632 $uni2cp[$i] = $i;
635 # JIS X 0201 right plane
636 for (my $i = 0xa1; $i <= 0xdf; $i++)
638 $cp2uni[0x8e00 + $i] = 0xfec0 + $i;
639 $uni2cp[0xfec0 + $i] = 0x8e00 + $i;
642 # lead bytes
643 foreach my $i (0x8e, 0x8f, 0xa1 .. 0xfe)
645 push @lead_bytes,$i;
646 $cp2uni[$i] = 0;
649 # undefined chars
650 foreach my $i (0x80 .. 0x8d, 0x90 .. 0xa0, 0xff)
652 $cp2uni[$i] = $DEF_CHAR;
655 # Shift-JIS compatibility
656 $uni2cp[0x00a5] = 0x5c;
657 $uni2cp[0x203e] = 0x7e;
659 # Fix backslash conversion
660 $cp2uni[0xa1c0] = 0xff3c;
661 $uni2cp[0xff3c] = 0xa1c0;
663 my $INPUT = open_data_file( $MAPPINGS, $name );
664 while (<$INPUT>)
666 next if /^\#/; # skip comments
667 next if /^$/; # skip empty lines
668 next if /\x1a/; # skip ^Z
669 if (/^0x[0-9a-fA-F]+\s+0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
671 my $cp = 0x8080 + hex $1;
672 my $uni = hex $2;
673 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
674 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
675 next;
677 die "$name: Unrecognized line $_\n";
679 close $INPUT;
683 ################################################################
684 # build the sort keys table
685 sub READ_SORTKEYS_FILE()
687 my @sortkeys = ();
688 for (my $i = 0; $i < 65536; $i++) { $sortkeys[$i] = [ -1, 0, 0, 0, 0 ] };
690 my $INPUT = open_data_file( $REPORTS, $SORTKEYS );
691 while (<$INPUT>)
693 next if /^\#/; # skip comments
694 next if /^$/; # skip empty lines
695 next if /\x1a/; # skip ^Z
696 next if /^\@version/; # skip @version header
697 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]+)\]/)
699 my ($uni,$variable) = (hex $1, $2);
700 next if $uni > 65535;
701 $sortkeys[$uni] = [ $uni, hex $3, hex $4, hex $5, hex $6 ];
702 next;
704 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]+)\]/)
706 # multiple character sequence, ignored for now
707 next;
709 die "$SORTKEYS: Unrecognized line $_\n";
711 close $INPUT;
713 # compress the keys to 32 bit:
714 # key 1 to 16 bits, key 2 to 8 bits, key 3 to 4 bits, key 4 to 1 bit
716 @sortkeys = sort { ${$a}[1] <=> ${$b}[1] or
717 ${$a}[2] <=> ${$b}[2] or
718 ${$a}[3] <=> ${$b}[3] or
719 ${$a}[4] <=> ${$b}[4] or
720 $a cmp $b; } @sortkeys;
722 my ($n2, $n3) = (1, 1);
723 my @keys = (-1, -1, -1, -1, -1 );
724 my @flatkeys = ();
726 for (my $i = 0; $i < 65536; $i++)
728 my @current = @{$sortkeys[$i]};
729 next if $current[0] == -1;
730 if ($current[1] == $keys[1])
732 if ($current[2] == $keys[2])
734 if ($current[3] == $keys[3])
736 # nothing
738 else
740 $keys[3] = $current[3];
741 $n3++;
742 die if ($n3 >= 16);
745 else
747 $keys[2] = $current[2];
748 $keys[3] = $current[3];
749 $n2++;
750 $n3 = 1;
751 die if ($n2 >= 256);
754 else
756 $keys[1] = $current[1];
757 $keys[2] = $current[2];
758 $keys[3] = $current[3];
759 $n2 = 1;
760 $n3 = 1;
763 if ($current[2]) { $current[2] = $n2; }
764 if ($current[3]) { $current[3] = $n3; }
765 if ($current[4]) { $current[4] = 1; }
767 $flatkeys[$current[0]] = ($current[1] << 16) | ($current[2] << 8) | ($current[3] << 4) | $current[4];
769 return @flatkeys;
773 ################################################################
774 # build the sort keys table
775 sub DUMP_SORTKEYS($@)
777 my ($filename, @keys) = @_;
779 # count the number of 256-key ranges that contain something
781 my @offsets = ();
782 my $ranges = 2;
783 for (my $i = 0; $i < 256; $i++) { $offsets[$i] = 256; }
784 for (my $i = 0; $i < 65536; $i++)
786 next unless defined $keys[$i];
787 $offsets[$i >> 8] = $ranges * 256;
788 $ranges++;
789 $i |= 255;
792 # output the range offsets
794 open OUTPUT,">$filename.new" or die "Cannot create $filename";
795 printf "Building $filename\n";
796 printf OUTPUT "/* Unicode collation element table */\n";
797 printf OUTPUT "/* generated from %s */\n", "$REPORTS/$SORTKEYS";
798 printf OUTPUT "/* DO NOT EDIT!! */\n\n";
800 printf OUTPUT "const unsigned int collation_table[%d] =\n{\n", $ranges*256;
801 printf OUTPUT " /* index */\n";
802 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%08x", 0, @offsets );
804 # output the default values
806 printf OUTPUT " /* defaults */\n";
807 printf OUTPUT "%s", DUMP_ARRAY( "0x%08x", 0, (0xffffffff) x 256 );
809 # output all the key ranges
811 for (my $i = 0; $i < 256; $i++)
813 next if $offsets[$i] == 256;
814 printf OUTPUT ",\n /* 0x%02x00 .. 0x%02xff */\n", $i, $i;
815 printf OUTPUT "%s", DUMP_ARRAY( "0x%08x", 0xffffffff, @keys[($i<<8) .. ($i<<8)+255] );
817 printf OUTPUT "\n};\n";
818 close OUTPUT;
819 save_file($filename);
823 ################################################################
824 # add default mappings once the file had been read
825 sub ADD_DEFAULT_MAPPINGS()
827 # Apply aliases
829 foreach my $alias (@unicode_aliases)
831 my $target = undef;
832 foreach my $src (@$alias)
834 if (defined($uni2cp[$src]))
836 $target = $uni2cp[$src];
837 last;
840 next unless defined($target);
842 # At least one char of the alias set is defined, set the others to the same value
843 foreach my $src (@$alias)
845 $uni2cp[$src] = $target unless defined($uni2cp[$src]);
849 # For every src -> target mapping in the defaults table,
850 # make uni2cp[src] = uni2cp[target] if uni2cp[target] is defined
852 for (my $src = 0; $src < 65536; $src++)
854 next if defined($uni2cp[$src]); # source has a definition already
855 next unless defined($unicode_defaults[$src]); # no default for this char
856 my $target = $unicode_defaults[$src];
858 # do a recursive mapping until we find a target char that is defined
859 while (!defined($uni2cp[$target]) &&
860 defined($unicode_defaults[$target])) { $target = $unicode_defaults[$target]; }
862 if (defined($uni2cp[$target])) { $uni2cp[$src] = $uni2cp[$target]; }
865 # Add an identity mapping for all undefined chars
867 for (my $i = 0; $i < 256; $i++)
869 next if defined($cp2uni[$i]);
870 next if defined($uni2cp[$i]);
871 $cp2uni[$i] = $uni2cp[$i] = $i;
875 ################################################################
876 # dump an array of integers
877 sub DUMP_ARRAY($$@)
879 my ($format,$default,@array) = @_;
880 my $i;
881 my $ret = " ";
882 for ($i = 0; $i < $#array; $i++)
884 $ret .= sprintf($format, defined $array[$i] ? $array[$i] : $default);
885 $ret .= (($i % 8) != 7) ? ", " : ",\n ";
887 $ret .= sprintf($format, defined $array[$i] ? $array[$i] : $default);
888 return $ret;
891 ################################################################
892 # dump an SBCS mapping table
893 sub dump_sbcs_table($$$$$)
895 my ($codepage, $has_glyphs, $name, $def, $defw) = @_;
896 my $i;
898 # output the ascii->unicode table
900 if ($has_glyphs)
902 printf OUTPUT "static const WCHAR cp2uni[512] =\n";
903 printf OUTPUT "{\n%s", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[0 .. 255] );
904 printf OUTPUT ",\n /* glyphs */\n%s\n};\n\n",
905 DUMP_ARRAY( "0x%04x", $defw, get_glyphs_mapping(@cp2uni[0 .. 255]) );
907 else
909 printf OUTPUT "static const WCHAR cp2uni[256] =\n";
910 printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[0 .. 255] );
913 # count the number of unicode->ascii subtables that contain something
915 my @filled = ();
916 my $subtables = 1;
917 for (my $i = 0; $i < 65536; $i++)
919 next unless defined $uni2cp[$i];
920 $filled[$i >> 8] = 1;
921 $subtables++;
922 $i |= 255;
925 # output all the subtables into a single array
927 printf OUTPUT "static const unsigned char uni2cp_low[%d] =\n{\n", $subtables*256;
928 for (my $i = 0; $i < 256; $i++)
930 next unless $filled[$i];
931 printf OUTPUT " /* 0x%02x00 .. 0x%02xff */\n", $i, $i;
932 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%02x", $def, @uni2cp[($i<<8) .. ($i<<8)+255] );
934 printf OUTPUT " /* defaults */\n";
935 printf OUTPUT "%s\n};\n\n", DUMP_ARRAY( "0x%02x", 0, ($def) x 256 );
937 # output a table of the offsets of the subtables in the previous array
939 my $pos = 0;
940 my @offsets = ();
941 for (my $i = 0; $i < 256; $i++)
943 if ($filled[$i]) { push @offsets, $pos; $pos += 256; }
944 else { push @offsets, ($subtables-1) * 256; }
946 printf OUTPUT "static const unsigned short uni2cp_high[256] =\n";
947 printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%04x", 0, @offsets );
949 # output the code page descriptor
951 printf OUTPUT "const struct sbcs_table cptable_%03d =\n{\n", $codepage;
952 printf OUTPUT " { %d, 1, 0x%04x, 0x%04x, \"%s\" },\n",
953 $codepage, $def, $defw, $name;
954 printf OUTPUT " cp2uni,\n";
955 if ($has_glyphs) { printf OUTPUT " cp2uni + 256,\n"; }
956 else { printf OUTPUT " cp2uni,\n"; }
957 printf OUTPUT " uni2cp_low,\n";
958 printf OUTPUT " uni2cp_high\n};\n";
962 ################################################################
963 # dump a DBCS mapping table
964 sub dump_dbcs_table($$$$@)
966 my ($codepage, $name, $def, $defw, @lb_ranges) = @_;
968 # build a list of lead bytes that are actually used
970 my @lblist = ();
971 LBLOOP: for (my $y = 0; $y <= $#lead_bytes; $y++)
973 my $base = $lead_bytes[$y] << 8;
974 for (my $x = 0; $x < 256; $x++)
976 if (defined $cp2uni[$base+$x])
978 push @lblist,$lead_bytes[$y];
979 next LBLOOP;
983 my $unused = ($#lead_bytes > $#lblist);
985 # output the ascii->unicode table for the single byte chars
987 printf OUTPUT "static const WCHAR cp2uni[%d] =\n", 256 * ($#lblist + 2 + $unused);
988 printf OUTPUT "{\n%s,\n", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[0 .. 255] );
990 # output the default table for unused lead bytes
992 if ($unused)
994 printf OUTPUT " /* unused lead bytes */\n";
995 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%04x", 0, ($defw) x 256 );
998 # output the ascii->unicode table for each DBCS lead byte
1000 for (my $y = 0; $y <= $#lblist; $y++)
1002 my $base = $lblist[$y] << 8;
1003 printf OUTPUT " /* lead byte %02x */\n", $lblist[$y];
1004 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[$base .. $base+255] );
1005 printf OUTPUT ($y < $#lblist) ? ",\n" : "\n};\n\n";
1008 # output the lead byte subtables offsets
1010 my @offsets = ();
1011 for (my $x = 0; $x < 256; $x++) { $offsets[$x] = 0; }
1012 for (my $x = 0; $x <= $#lblist; $x++) { $offsets[$lblist[$x]] = $x + 1; }
1013 if ($unused)
1015 # increment all lead bytes offset to take into account the unused table
1016 for (my $x = 0; $x <= $#lead_bytes; $x++) { $offsets[$lead_bytes[$x]]++; }
1018 printf OUTPUT "static const unsigned char cp2uni_leadbytes[256] =\n";
1019 printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%02x", 0, @offsets );
1021 # count the number of unicode->ascii subtables that contain something
1023 my @filled = ();
1024 my $subtables = 1;
1025 for (my $i = 0; $i < 65536; $i++)
1027 next unless defined $uni2cp[$i];
1028 $filled[$i >> 8] = 1;
1029 $subtables++;
1030 $i |= 255;
1033 # output all the subtables into a single array
1035 printf OUTPUT "static const unsigned short uni2cp_low[%d] =\n{\n", $subtables*256;
1036 for (my $y = 0; $y < 256; $y++)
1038 next unless $filled[$y];
1039 printf OUTPUT " /* 0x%02x00 .. 0x%02xff */\n", $y, $y;
1040 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%04x", $def, @uni2cp[($y<<8) .. ($y<<8)+255] );
1042 printf OUTPUT " /* defaults */\n";
1043 printf OUTPUT "%s\n};\n\n", DUMP_ARRAY( "0x%04x", 0, ($def) x 256 );
1045 # output a table of the offsets of the subtables in the previous array
1047 my $pos = 0;
1048 @offsets = ();
1049 for (my $y = 0; $y < 256; $y++)
1051 if ($filled[$y]) { push @offsets, $pos; $pos += 256; }
1052 else { push @offsets, ($subtables-1) * 256; }
1054 printf OUTPUT "static const unsigned short uni2cp_high[256] =\n";
1055 printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%04x", 0, @offsets );
1057 # output the code page descriptor
1059 printf OUTPUT "const struct dbcs_table cptable_%03d =\n{\n", $codepage;
1060 printf OUTPUT " { %d, 2, 0x%04x, 0x%04x, \"%s\" },\n",
1061 $codepage, $def, $defw, $name;
1062 printf OUTPUT " cp2uni,\n";
1063 printf OUTPUT " cp2uni_leadbytes,\n";
1064 printf OUTPUT " uni2cp_low,\n";
1065 printf OUTPUT " uni2cp_high,\n";
1066 printf OUTPUT " {\n %s\n }\n", DUMP_ARRAY( "0x%02x", 0, @lb_ranges, 0, 0 );
1067 printf OUTPUT "};\n";
1071 ################################################################
1072 # get the list of defined lead byte ranges
1073 sub get_lb_ranges()
1075 my @list = ();
1076 my @ranges = ();
1077 my $i = 0;
1078 foreach $i (@lead_bytes) { $list[$i] = 1; }
1079 my $on = 0;
1080 for (my $i = 0; $i < 256; $i++)
1082 if ($on)
1084 if (!defined $list[$i]) { push @ranges, $i-1; $on = 0; }
1086 else
1088 if ($list[$i]) { push @ranges, $i; $on = 1; }
1091 if ($on) { push @ranges, 0xff; }
1092 return @ranges;
1095 ################################################################
1096 # dump the Indic Syllabic Category table
1097 sub dump_indic($)
1099 my $filename = shift;
1100 my @indic_table = ($indic_types{'Other'}) x 65536;;
1102 my $INPUT = open_data_file( $UNIDATA, "IndicSyllabicCategory.txt" );
1103 while (<$INPUT>)
1105 next if /^\#/; # skip comments
1106 next if /^\s*$/; # skip empty lines
1107 next if /\x1a/; # skip ^Z
1108 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*#/)
1110 my $type = $2;
1111 die "unknown indic $type" unless defined $indic_types{$type};
1112 if (hex $1 < 65536)
1114 $indic_table[hex $1] = $indic_types{$type};
1116 next;
1118 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*#/)
1120 my $type = $3;
1121 die "unknown indic $type" unless defined $indic_types{$type};
1122 if (hex $1 < 65536 and hex $2 < 6536)
1124 foreach my $i (hex $1 .. hex $2)
1126 $indic_table[$i] = $indic_types{$type};
1129 next;
1131 die "malformed line $_";
1133 close $INPUT;
1135 $INPUT = open_data_file( $UNIDATA, "IndicMatraCategory.txt" );
1136 while (<$INPUT>)
1138 next if /^\#/; # skip comments
1139 next if /^\s*$/; # skip empty lines
1140 next if /\x1a/; # skip ^Z
1141 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z]+)\s*#/)
1143 my $type = $2;
1144 die "unknown matra $type" unless defined $matra_types{$type};
1145 $indic_table[hex $1] += $matra_types{$type} << 8;
1146 next;
1148 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*#/)
1150 my $type = $3;
1151 die "unknown matra $type" unless defined $matra_types{$type};
1152 foreach my $i (hex $1 .. hex $2)
1154 $indic_table[$i] += $matra_types{$type} << 8;
1156 next;
1158 die "malformed line $_";
1160 close $INPUT;
1162 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1163 print "Building $filename\n";
1164 print OUTPUT "/* Unicode Indic Syllabic Category */\n";
1165 print OUTPUT "/* generated from $UNIDATA/IndicSyllabicCategory.txt */\n";
1166 print OUTPUT "/* and from $UNIDATA/IndicMatraCategory.txt */\n";
1167 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1168 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1170 dump_two_level_mapping( "indic_syllabic_table", @indic_table);
1172 close OUTPUT;
1173 save_file($filename);
1176 ################################################################
1177 # dump the Line Break Properties table
1178 sub dump_linebreak($)
1180 my $filename = shift;
1181 my @break_table = ($break_types{'XX'}) x 65536;;
1182 my $next_group = 0;
1184 my $INPUT = open_data_file( $UNIDATA, "LineBreak.txt" );
1185 while (<$INPUT>)
1187 next if /^\#/; # skip comments
1188 next if /^\s*$/; # skip empty lines
1189 next if /\x1a/; # skip ^Z
1190 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z])+\s*/)
1192 my $type = $2;
1193 die "unknown breaktype $type" unless defined $break_types{$type};
1194 $break_table[hex $1] = $break_types{$type};
1195 next;
1197 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z])+\s*/)
1199 my $type = $3;
1200 die "unknown breaktype $type" unless defined $break_types{$type};
1201 foreach my $i (hex $1 .. hex $2)
1203 $break_table[$i] = $break_types{$type};
1205 next;
1207 die "malformed line $_";
1209 close $INPUT;
1211 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1212 print "Building $filename\n";
1213 print OUTPUT "/* Unicode Line Break Properties */\n";
1214 print OUTPUT "/* generated from $UNIDATA/LineBreak.txt */\n";
1215 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1216 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1218 dump_two_level_mapping( "wine_linebreak_table", @break_table);
1220 close OUTPUT;
1221 save_file($filename);
1225 ################################################################
1226 # dump the BiDi mirroring table
1227 sub dump_mirroring($)
1229 my $filename = shift;
1230 my @mirror_table = ();
1232 my $INPUT = open_data_file( $UNIDATA, "BidiMirroring.txt" );
1233 while (<$INPUT>)
1235 next if /^\#/; # skip comments
1236 next if /^$/; # skip empty lines
1237 next if /\x1a/; # skip ^Z
1238 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9a-fA-F]+)/)
1240 $mirror_table[hex $1] = hex $2;
1241 next;
1243 die "malformed line $_";
1245 close $INPUT;
1247 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1248 print "Building $filename\n";
1249 print OUTPUT "/* Unicode BiDi mirroring */\n";
1250 print OUTPUT "/* generated from $UNIDATA/BidiMirroring.txt */\n";
1251 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1252 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1253 DUMP_CASE_TABLE( "wine_mirror_map", @mirror_table );
1254 close OUTPUT;
1255 save_file($filename);
1259 ################################################################
1260 # dump the Arabic shaping table
1261 sub dump_shaping($)
1263 my $filename = shift;
1264 my %groups;
1265 my $next_group = 0;
1267 $groups{"No_Joining_Group"} = $next_group++;
1269 my $INPUT = open_data_file( $UNIDATA, "ArabicShaping.txt" );
1270 while (<$INPUT>)
1272 next if /^\#/; # skip comments
1273 next if /^\s*$/; # skip empty lines
1274 next if /\x1a/; # skip ^Z
1275 if (/^\s*([0-9a-fA-F]+)\s*;.*;\s*([RLDCUT])\s*;\s*(\w+)/)
1277 my $type = $2;
1278 my $group = $3;
1279 $groups{$group} = $next_group++ unless defined $groups{$group};
1280 $joining_table[hex $1] = $joining_types{$type} | ($groups{$group} << 8);
1281 next;
1283 die "malformed line $_";
1285 close $INPUT;
1287 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1288 print "Building $filename\n";
1289 print OUTPUT "/* Unicode Arabic shaping */\n";
1290 print OUTPUT "/* generated from $UNIDATA/ArabicShaping.txt */\n";
1291 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1292 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1294 dump_two_level_mapping( "wine_shaping_table", @joining_table );
1296 print OUTPUT "\nconst unsigned short wine_shaping_forms[256][4] =\n{\n";
1297 for (my $i = 0x600; $i <= 0x6ff; $i++)
1299 printf OUTPUT " { 0x%04x, 0x%04x, 0x%04x, 0x%04x },\n",
1300 ${joining_forms{"isolated"}}[$i] || $i,
1301 ${joining_forms{"final"}}[$i] || $i,
1302 ${joining_forms{"initial"}}[$i] || $i,
1303 ${joining_forms{"medial"}}[$i] || $i;
1305 print OUTPUT "};\n";
1307 close OUTPUT;
1308 save_file($filename);
1312 ################################################################
1313 # dump the case mapping tables
1314 sub DUMP_CASE_MAPPINGS($)
1316 my $filename = shift;
1317 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1318 printf "Building $filename\n";
1319 printf OUTPUT "/* Unicode case mappings */\n";
1320 printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
1321 printf OUTPUT "#include \"wine/unicode.h\"\n\n";
1323 DUMP_CASE_TABLE( "wine_casemap_lower", @tolower_table );
1324 DUMP_CASE_TABLE( "wine_casemap_upper", @toupper_table );
1325 DUMP_CASE_TABLE( "wine_digitmap", @digitmap_table );
1326 DUMP_CASE_TABLE( "wine_compatmap", @compatmap_table );
1327 close OUTPUT;
1328 save_file($filename);
1332 ################################################################
1333 # dump a case mapping table
1334 sub DUMP_CASE_TABLE($@)
1336 my ($name,@table) = @_;
1338 # count the number of sub tables that contain something
1339 # also compute the low and upper populated bounds
1341 my @lowerbounds = ( 0, 0 );
1342 my @upperbounds = ( 0, 255 );
1343 my $index = 0;
1344 my @filled = ();
1345 for (my $i = 0; $i < 65536; $i++)
1347 next unless defined $table[$i];
1348 if (!defined $filled[$i >> 8])
1350 $lowerbounds[$index] = $i & 0xff;
1351 $upperbounds[$index] = 0xff - $lowerbounds[$index];
1352 $filled[$i >> 8] = $index * 256 + 512;
1353 $index++;
1355 else
1357 $upperbounds[$index-1] = 0xff - ($i & 0xff);
1359 $table[$i] = ($table[$i] - $i) & 0xffff;
1362 # Collapse blocks upwards if possible
1363 my $removed = 0;
1364 $index = 0;
1365 for (my $i = 0; $i < 256; $i++)
1367 next unless defined $filled[$i];
1368 if ($upperbounds[$index - 1] > $lowerbounds[$index])
1370 $removed = $removed + $lowerbounds[$index];
1372 else
1374 $removed = $removed + $upperbounds[$index - 1];
1375 $lowerbounds[$index] = $upperbounds[$index - 1];
1377 $filled[$i] = $filled[$i] - $removed;
1378 $index++;
1381 # dump the table
1383 printf OUTPUT "const WCHAR %s[%d] =\n", $name, $index * 256 + 512 - $removed;
1384 printf OUTPUT "{\n /* index */\n";
1385 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%04x", 256, @filled );
1386 printf OUTPUT " /* defaults */\n";
1387 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, (0) x 256 );
1388 $index = 0;
1389 for (my $i = 0; $i < 256; $i++)
1391 next unless $filled[$i];
1392 printf OUTPUT ",\n /* 0x%02x%02x .. 0x%02xff */\n", $i, $lowerbounds[$index], $i;
1393 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0,
1394 @table[($i<<8) + $lowerbounds[$index] .. ($i<<8)+255] );
1395 $index++;
1397 printf OUTPUT "\n};\n";
1400 ################################################################
1401 # compress a mapping table by removing identical rows
1402 sub compress_array($@)
1404 my $rows = shift;
1405 my @table = @_;
1406 my $len = @table / $rows;
1407 my @array = (0) x $rows;
1408 my %sequences;
1410 # try to merge table rows
1411 for (my $row = 0; $row < $rows; $row++)
1413 my $rowtxt = pack "S*", @table[($row * $len)..($row * $len + $len - 1)];
1414 if (defined($sequences{$rowtxt}))
1416 # reuse an existing row
1417 $array[$row] = $sequences{$rowtxt};
1419 else
1421 # create a new row
1422 $sequences{$rowtxt} = $array[$row] = $#array + 1;
1423 push @array, @table[$row * $len..$row * $len + $len - 1];
1426 return @array;
1429 ################################################################
1430 # dump a simple char -> 16-bit value mapping table
1431 sub dump_simple_mapping($@)
1433 my $name = shift;
1434 my @array = compress_array( 256, @_[0..65535] );
1436 printf OUTPUT "const unsigned short %s[%d] =\n{\n", $name, $#array+1;
1437 printf OUTPUT " /* offsets */\n%s,\n", DUMP_ARRAY( "0x%04x", 0, @array[0..255] );
1438 printf OUTPUT " /* values */\n%s\n};\n", DUMP_ARRAY( "0x%04x", 0, @array[256..$#array] );
1441 ################################################################
1442 # dump a char -> 16-bit value mapping table using two-level tables
1443 sub dump_two_level_mapping($@)
1445 my $name = shift;
1446 my @row_array = compress_array( 4096, @_[0..65535] );
1447 my @array = compress_array( 256, @row_array[0..4095] );
1449 for (my $i = 256; $i < @array; $i++) { $array[$i] += @array - 4096; }
1451 printf OUTPUT "const unsigned short %s[%d] =\n{\n", $name, @array + @row_array - 4096;
1452 printf OUTPUT " /* level 1 offsets */\n%s,\n", DUMP_ARRAY( "0x%04x", 0, @array[0..255] );
1453 printf OUTPUT " /* level 2 offsets */\n%s,\n", DUMP_ARRAY( "0x%04x", 0, @array[256..$#array] );
1454 printf OUTPUT " /* values */\n%s\n};\n", DUMP_ARRAY( "0x%04x", 0, @row_array[4096..$#row_array] );
1457 ################################################################
1458 # dump a binary case mapping table in l_intl.nls format
1459 sub dump_binary_case_table(@)
1461 my (@table) = @_;
1463 my %difftables_hash = ();
1464 my @difftables;
1465 my %offtables2_hash = ();
1466 my @offtables2 = ();
1468 my @offtable = ();
1469 for (my $i = 0; $i < 256; $i++)
1471 my @offtable2 = ();
1472 for(my $j = 0; $j < 16; $j++) # offset table for xx00-xxFF characters
1474 my @difftable;
1475 for (my $k = 0; $k < 16; $k++) # case map table for xxx0-xxxF characters
1477 my $char = ($i<<8) + ($j<<4) + $k;
1478 $difftable[$k] = (defined $table[$char]) ? (($table[$char]-$char) & 0xffff) : 0;
1481 my $diff_key = pack "S*", @difftable;
1482 my $offset3 = $difftables_hash{$diff_key};
1483 if (!defined $offset3)
1485 $offset3 = scalar @difftables;
1486 $difftables_hash{$diff_key} = $offset3;
1487 push @difftables, @difftable;
1489 $offtable2[$j] = $offset3;
1492 my $offtable2_key = pack "S*", @offtable2;
1493 my $offset2 = $offtables2_hash{$offtable2_key};
1494 if (!defined $offset2)
1496 $offset2 = scalar @offtables2;
1497 $offtables2_hash{$offtable2_key} = $offset2;
1498 push @offtables2, \@offtable2;
1500 $offtable[$i] = $offset2;
1503 my @output;
1504 my $offset = 0x100; # offset of first subtable in words
1505 foreach (@offtable)
1507 push @output, 0x10 * $_ + $offset; # offset of subtable in words
1510 $offset = 0x100 + 0x10 * scalar @offtables2; # offset of first difftable in words
1511 foreach(@offtables2)
1513 my $table = $_;
1514 foreach(@$table)
1516 push @output, $_ + $offset; # offset of difftable in words
1520 my $len = 1 + scalar @output + scalar @difftables;
1521 return pack "S<*", $len, @output, @difftables;
1525 ################################################################
1526 # dump case mappings for l_intl.nls
1527 sub dump_intl_nls($)
1529 my $filename = shift;
1530 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1531 printf "Building $filename\n";
1533 binmode OUTPUT;
1534 print OUTPUT pack "S<", 1; # version
1535 print OUTPUT dump_binary_case_table( @toupper_table );
1536 print OUTPUT dump_binary_case_table( @tolower_table );
1537 close OUTPUT;
1538 save_file($filename);
1542 sub load_nameprep_range_table($$$)
1544 my ($INPUT, $val, $table_ref) = @_;
1546 while (<$INPUT>)
1548 if (/^\s*([0-9a-fA-F]+)-([0-9a-fA-F]+)/)
1550 my $last = hex $2;
1551 $last = 65535 if($last >= 65536);
1552 foreach my $i (hex $1 .. $last)
1554 $table_ref->[$i] |= $val;
1556 next;
1558 elsif (/^\s*([0-9a-fA-F]+)/)
1560 if (hex $1 < 65536)
1562 $table_ref->[hex $1] |= $val;
1564 next;
1567 return if (/End\sTable/);
1571 sub load_nameprep_map_table($$)
1573 my ($INPUT, $table_ref) = @_;
1575 while (<$INPUT>)
1577 if (/^\s*([0-9a-fA-F]+);\s;/)
1579 # special value for map to nothing
1580 $table_ref->[hex $1] = [0xffff, 0xffff, 0xffff];
1581 next;
1583 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+);/)
1585 $table_ref->[hex $1] = [hex $2, 0, 0];
1586 next;
1588 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+)\s([0-9a-fA-F]+);/)
1590 $table_ref->[hex $1] = [hex $2, hex $3, 0];
1591 next;
1593 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+)\s([0-9a-fA-F]+)\s([0-9a-fA-F]+);/)
1595 $table_ref->[hex $1] = [hex $2, hex $3, hex $4];
1596 next;
1599 return if (/End\sTable/);
1603 ################################################################
1604 # dump mapping table, prohibited characters set, unassigned
1605 # characters, bidirectional rules used by nameprep algorithm
1606 sub dump_nameprep($)
1608 my $filename = shift;
1609 my @mapping_table = ();
1610 my @flags_table = (0) x 65536;
1612 my $INPUT = open_data_file( $RFCS, $STRINGPREP );
1613 while (<$INPUT>)
1615 next unless /Start\sTable/;
1617 load_nameprep_range_table($INPUT, $nameprep_flags{"unassigned"}, \@flags_table) if (/A.1/);
1618 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.1.2/);
1619 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.2.2/);
1620 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.3/);
1621 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.4/);
1622 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.5/);
1623 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.6/);
1624 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.7/);
1625 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.8/);
1626 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.9/);
1627 load_nameprep_range_table($INPUT, $nameprep_flags{"bidi_ral"}, \@flags_table) if (/D.1/);
1628 load_nameprep_range_table($INPUT, $nameprep_flags{"bidi_l"}, \@flags_table) if (/D.2/);
1630 load_nameprep_map_table($INPUT, \@mapping_table) if (/B.1/);
1631 load_nameprep_map_table($INPUT, \@mapping_table) if (/B.2/);
1633 close $INPUT;
1635 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1636 print "Building $filename\n";
1637 print OUTPUT "/* Nameprep algorithm related data */\n";
1638 print OUTPUT "/* generated from $RFCS/$STRINGPREP */\n";
1639 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1640 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1642 dump_two_level_mapping( "nameprep_char_type", @flags_table );
1644 ######### mapping table
1645 # first determine all the 16-char subsets that contain something
1646 my @filled = ();
1647 my $pos = 16*3; # for the null subset
1648 for (my $i = 0; $i < 65536; $i++)
1650 next unless defined $mapping_table[$i];
1651 $filled[$i >> 4] = $pos;
1652 $pos += 16*3;
1653 $i |= 15;
1655 my $total = $pos;
1657 # now count the 256-char subsets that contain something
1658 my @filled_idx = (256) x 256;
1659 $pos = 256 + 16;
1660 for (my $i = 0; $i < 4096; $i++)
1662 next unless $filled[$i];
1663 $filled_idx[$i >> 4] = $pos;
1664 $pos += 16;
1665 $i |= 15;
1667 my $null_offset = $pos;
1668 $total += $pos;
1670 # add the index offsets to the subsets positions
1671 for (my $i = 0; $i < 4096; $i++)
1673 next unless $filled[$i];
1674 $filled[$i] += $null_offset;
1677 # dump the main index
1678 printf OUTPUT "const WCHAR nameprep_mapping[%d] =\n", $total;
1679 printf OUTPUT "{\n /* index */\n";
1680 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @filled_idx );
1681 printf OUTPUT ",\n /* null sub-index */\n%s", DUMP_ARRAY( "0x%04x", 0, ($null_offset) x 16 );
1683 # dump the second-level indexes
1684 for (my $i = 0; $i < 256; $i++)
1686 next unless ($filled_idx[$i] > 256);
1687 my @table = @filled[($i<<4)..($i<<4)+15];
1688 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
1689 printf OUTPUT ",\n /* sub-index %02x */\n", $i;
1690 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
1693 # dump the 16-char subsets
1694 printf OUTPUT ",\n /* null mapping */\n";
1695 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, (0) x 48 );
1697 for (my $i = 0; $i < 4096; $i++)
1699 next unless $filled[$i];
1700 my @table = (0) x 48;
1701 for (my $j = 0; $j < 16; $j++)
1703 if (defined $mapping_table[($i<<4) + $j])
1705 $table[3 * $j] = ${$mapping_table[($i << 4) + $j]}[0];
1706 $table[3 * $j + 1] = ${$mapping_table[($i << 4) + $j]}[1];
1707 $table[3 * $j + 2] = ${$mapping_table[($i << 4) + $j]}[2];
1710 printf OUTPUT ",\n /* 0x%03x0 .. 0x%03xf */\n", $i, $i;
1711 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
1714 printf OUTPUT "\n};\n";
1716 close OUTPUT;
1717 save_file($filename);
1720 ################################################################
1721 # dump the ctype tables
1722 sub DUMP_CTYPE_TABLES($)
1724 my $filename = shift;
1725 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1726 printf "Building $filename\n";
1727 printf OUTPUT "/* Unicode ctype tables */\n";
1728 printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
1729 printf OUTPUT "#include \"wine/unicode.h\"\n\n";
1731 # add the direction in the high 4 bits of the category
1732 for (my $i = 0; $i < 65536; $i++)
1734 $category_table[$i] |= $direction_table[$i] << 12 if defined $direction_table[$i];
1737 dump_simple_mapping( "wine_wctype_table", @category_table );
1739 close OUTPUT;
1740 save_file($filename);
1744 ################################################################
1745 # dump the char composition tables
1746 sub DUMP_COMPOSE_TABLES($)
1748 my $filename = shift;
1750 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1751 printf "Building $filename\n";
1752 printf OUTPUT "/* Unicode char composition */\n";
1753 printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
1754 printf OUTPUT "#include \"wine/unicode.h\"\n\n";
1756 ######### composition table
1758 my @filled = ();
1759 foreach my $i (@compose_table)
1761 my @comp = @$i;
1762 push @{$filled[$comp[1]]}, [ $comp[0], $comp[2] ];
1765 # count how many different second chars we have
1767 my $count = 0;
1768 for (my $i = 0; $i < 65536; $i++)
1770 next unless defined $filled[$i];
1771 $count++;
1774 # build the table of second chars and offsets
1776 my $pos = $count + 1;
1777 my @table = ();
1778 for (my $i = 0; $i < 65536; $i++)
1780 next unless defined $filled[$i];
1781 push @table, $i, $pos;
1782 $pos += @{$filled[$i]};
1784 # terminator with last position
1785 push @table, 0, $pos;
1786 printf OUTPUT "const WCHAR unicode_compose_table[0x%x] =\n{\n", 2*$pos;
1787 printf OUTPUT " /* second chars + offsets */\n%s", DUMP_ARRAY( "0x%04x", 0, @table );
1789 # build the table of first chars and mappings
1791 for (my $i = 0; $i < 65536; $i++)
1793 next unless defined $filled[$i];
1794 my @table = ();
1795 my @list = sort { $a->[0] <=> $b->[0] } @{$filled[$i]};
1796 for (my $j = 0; $j <= $#list; $j++)
1798 push @table, $list[$j][0], $list[$j][1];
1800 printf OUTPUT ",\n /* 0x%04x */\n%s", $i, DUMP_ARRAY( "0x%04x", 0, @table );
1802 printf OUTPUT "\n};\n\nconst unsigned int unicode_compose_table_size = %d;\n\n", $count;
1804 ######### decomposition table
1806 # first determine all the 16-char subsets that contain something
1808 @filled = (0) x 4096;
1809 $pos = 16*2; # for the null subset
1810 for (my $i = 0; $i < 65536; $i++)
1812 next unless defined $decomp_table[$i];
1813 $filled[$i >> 4] = $pos;
1814 $pos += 16*2;
1815 $i |= 15;
1817 my $total = $pos;
1819 # now count the 256-char subsets that contain something
1821 my @filled_idx = (256) x 256;
1822 $pos = 256 + 16;
1823 for (my $i = 0; $i < 4096; $i++)
1825 next unless $filled[$i];
1826 $filled_idx[$i >> 4] = $pos;
1827 $pos += 16;
1828 $i |= 15;
1830 my $null_offset = $pos; # null mapping
1831 $total += $pos;
1833 # add the index offsets to the subsets positions
1835 for (my $i = 0; $i < 4096; $i++)
1837 next unless $filled[$i];
1838 $filled[$i] += $null_offset;
1841 # dump the main index
1843 printf OUTPUT "const WCHAR unicode_decompose_table[%d] =\n", $total;
1844 printf OUTPUT "{\n /* index */\n";
1845 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @filled_idx );
1846 printf OUTPUT ",\n /* null sub-index */\n%s", DUMP_ARRAY( "0x%04x", 0, ($null_offset) x 16 );
1848 # dump the second-level indexes
1850 for (my $i = 0; $i < 256; $i++)
1852 next unless ($filled_idx[$i] > 256);
1853 my @table = @filled[($i<<4)..($i<<4)+15];
1854 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
1855 printf OUTPUT ",\n /* sub-index %02x */\n", $i;
1856 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
1859 # dump the 16-char subsets
1861 printf OUTPUT ",\n /* null mapping */\n";
1862 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, (0) x 32 );
1864 for (my $i = 0; $i < 4096; $i++)
1866 next unless $filled[$i];
1867 my @table = (0) x 32;
1868 for (my $j = 0; $j < 16; $j++)
1870 if (defined $decomp_table[($i<<4) + $j])
1872 $table[2 * $j] = ${$decomp_table[($i << 4) + $j]}[0];
1873 $table[2 * $j + 1] = ${$decomp_table[($i << 4) + $j]}[1];
1876 printf OUTPUT ",\n /* 0x%03x0 .. 0x%03xf */\n", $i, $i;
1877 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
1880 printf OUTPUT "\n};\n";
1881 close OUTPUT;
1882 save_file($filename);
1885 ################################################################
1886 # output a codepage definition file from the global tables
1887 sub output_codepage_file($$$$)
1889 my ($codepage, $filename, $comment, $has_glyphs) = @_;
1891 my $output = sprintf "libs/wine/c_%03d.c", $codepage;
1892 open OUTPUT,">$output.new" or die "Cannot create $output";
1894 printf "Building %s from %s (%s)\n", $output, $filename || "hardcoded data", $comment;
1896 # dump all tables
1898 printf OUTPUT "/* code page %03d (%s) */\n", $codepage, $comment;
1899 if ($filename)
1901 print OUTPUT "/* generated from $MAPPINGS/$filename */\n";
1902 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1904 else
1906 printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
1908 printf OUTPUT "#include \"wine/unicode.h\"\n\n";
1910 if (!@lead_bytes) { dump_sbcs_table( $codepage, $has_glyphs, $comment, $default_char, $default_wchar ); }
1911 else { dump_dbcs_table( $codepage, $comment, $default_char, $default_wchar, get_lb_ranges() ); }
1912 close OUTPUT;
1913 save_file($output);
1916 ################################################################
1917 # read a "bestfit" Windows mapping file
1918 sub read_bestfit_file($)
1920 my ($filename) = @_;
1921 my $state = "";
1922 my ($codepage, $width, $count);
1923 my ($lb_cur, $lb_end);
1925 my $INPUT = open_data_file( $MAPPINGS, $filename ) or die "Cannot open $filename";
1927 while (<$INPUT>)
1929 next if /^;/; # skip comments
1930 next if /^\s*$/; # skip empty lines
1931 next if /\x1a/; # skip ^Z
1932 last if /^ENDCODEPAGE/;
1934 if (/^CODEPAGE\s+(\d+)/)
1936 $codepage = $1;
1937 next;
1939 if (/^CPINFO\s+(\d+)\s+0x([0-9a-fA-f]+)\s+0x([0-9a-fA-F]+)/)
1941 $width = $1;
1942 $default_char = hex $2;
1943 $default_wchar = hex $3;
1944 next;
1946 if (/^(MBTABLE|WCTABLE|DBCSRANGE|DBCSTABLE)\s+(\d+)/)
1948 $state = $1;
1949 $count = $2;
1950 next;
1952 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)/)
1954 if ($state eq "MBTABLE")
1956 my $cp = hex $1;
1957 my $uni = hex $2;
1958 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
1959 next;
1961 if ($state eq "WCTABLE")
1963 my $uni = hex $1;
1964 my $cp = hex $2;
1965 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
1966 next;
1968 if ($state eq "DBCSRANGE")
1970 my $start = hex $1;
1971 my $end = hex $2;
1972 for (my $i = $start; $i <= $end; $i++) { add_lead_byte( $i ); }
1973 $lb_cur = $start;
1974 $lb_end = $end;
1975 next;
1977 if ($state eq "DBCSTABLE")
1979 my $mb = hex $1;
1980 my $uni = hex $2;
1981 my $cp = ($lb_cur << 8) | $mb;
1982 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
1983 if (!--$count)
1985 if (++$lb_cur > $lb_end) { $state = "DBCSRANGE"; }
1987 next;
1990 die "$filename: Unrecognized line $_\n";
1992 close $INPUT;
1996 ################################################################
1997 # read an input file and generate the corresponding .c file
1998 sub HANDLE_FILE(@)
2000 my ($codepage,$filename,$has_glyphs,$comment,$def,$defw) = @_;
2002 @cp2uni = ();
2003 @lead_bytes = ();
2004 @uni2cp = ();
2005 $default_char = $def || $DEF_CHAR;
2006 $default_wchar = $defw || $DEF_CHAR;
2008 # some codepage files are special
2009 if ($codepage == 20932)
2011 READ_JIS0208_FILE( $filename );
2012 ADD_DEFAULT_MAPPINGS();
2014 elsif ($codepage == 20127)
2016 fill_20127_codepage();
2017 ADD_DEFAULT_MAPPINGS();
2019 elsif ($filename =~ /\/bestfit/)
2021 read_bestfit_file( $filename );
2023 elsif ($codepage == 10001)
2025 read_codepage_file( $filename );
2026 # add Shift-JIS mappings
2027 read_bestfit_file( "VENDORS/MICSFT/WindowsBestFit/bestfit932.txt" );
2029 else
2031 read_codepage_file( $filename );
2032 ADD_DEFAULT_MAPPINGS();
2035 output_codepage_file( $codepage, $filename, $comment, $has_glyphs );
2039 ################################################################
2040 # save a file if modified
2041 sub save_file($)
2043 my $file = shift;
2044 if (-f $file && !system "cmp $file $file.new >/dev/null")
2046 unlink "$file.new";
2048 else
2050 rename "$file.new", "$file";
2055 ################################################################
2056 # output the list of codepage tables into the cptable.c file
2057 sub output_cptable($)
2059 my $output = shift;
2060 my @tables_decl = ();
2062 printf "Building %s\n", $output;
2064 foreach my $file (@allfiles)
2066 my ($codepage,$filename,$comment) = @$file;
2067 push @tables_decl, sprintf("extern union cptable cptable_%03d;\n",$codepage);
2070 push @tables_decl, sprintf("\nstatic const union cptable * const cptables[%d] =\n{\n",$#allfiles+1);
2071 foreach my $file (@allfiles)
2073 my ($codepage,$filename,$comment) = @$file;
2074 push @tables_decl, sprintf(" &cptable_%03d,\n", $codepage);
2076 push @tables_decl, "};";
2077 REPLACE_IN_FILE( $output, @tables_decl );
2080 ################################################################
2081 # replace the contents of a file between ### cpmap ### marks
2083 sub REPLACE_IN_FILE($@)
2085 my $name = shift;
2086 my @data = @_;
2087 my @lines = ();
2088 open(FILE,$name) or die "Can't open $name";
2089 while (<FILE>)
2091 push @lines, $_;
2092 last if /\#\#\# cpmap begin \#\#\#/;
2094 push @lines, @data;
2095 while (<FILE>)
2097 if (/\#\#\# cpmap end \#\#\#/) { push @lines, "\n", $_; last; }
2099 push @lines, <FILE>;
2100 open(FILE,">$name.new") or die "Can't modify $name";
2101 print FILE @lines;
2102 close(FILE);
2103 save_file($name);
2106 ################################################################
2107 # main routine
2109 chdir ".." if -f "./make_unicode";
2110 READ_DEFAULTS( $DEFAULTS );
2111 DUMP_CASE_MAPPINGS( "libs/wine/casemap.c" );
2112 DUMP_SORTKEYS( "libs/wine/collation.c", READ_SORTKEYS_FILE() );
2113 DUMP_COMPOSE_TABLES( "libs/wine/compose.c" );
2114 DUMP_CTYPE_TABLES( "libs/wine/wctype.c" );
2115 dump_mirroring( "dlls/usp10/mirror.c" );
2116 dump_shaping( "dlls/usp10/shaping.c" );
2117 dump_linebreak( "dlls/usp10/linebreak.c" );
2118 dump_indic( "dlls/usp10/indicsyllable.c" );
2119 dump_intl_nls("tools/l_intl.nls");
2120 dump_nameprep( "dlls/kernel32/nameprep.c" );
2122 foreach my $file (@allfiles) { HANDLE_FILE( @{$file} ); }
2124 output_cptable("libs/wine/cptable.c");
2126 exit 0;
2128 # Local Variables:
2129 # compile-command: "./make_unicode"
2130 # End: