d3dx9: Handle short parameter in d3dx_set_shader_const_state().
[wine.git] / tools / make_unicode
blobdbf640abe7c8b32001d8141fc802c6bf82d39e48
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 @combining_class_table = ();
364 my @full_compatmap_table = ();
365 my $default_char;
366 my $default_wchar;
368 my %joining_forms =
370 "isolated" => [],
371 "final" => [],
372 "initial" => [],
373 "medial" => []
376 ################################################################
377 # fetch a unicode.org file and open it
378 sub open_data_file($$)
380 my ($base, $name) = @_;
381 (my $dir = "data/$name") =~ s/\/[^\/]+$//;
382 local *FILE;
383 unless (-f "data/$name")
385 print "Fetching $base/$name...\n";
386 system "mkdir", "-p", $dir;
387 !system "wget", "-q", "-O", "data/$name", "$base/$name" or die "cannot fetch $base/$name";
389 open FILE, "<data/$name" or die "cannot open data/$name";
390 return *FILE;
393 ################################################################
394 # read in the defaults file
395 sub READ_DEFAULTS($)
397 my $filename = shift;
398 my $start;
400 # first setup a few default mappings
402 open DEFAULTS, "$filename" or die "Cannot open $filename";
403 print "Loading $filename\n";
404 while (<DEFAULTS>)
406 next if /^\#/; # skip comments
407 next if /^$/; # skip empty lines
408 if (/^(([0-9a-fA-F]+)(,[0-9a-fA-F]+)*)\s+([0-9a-fA-F]+|'.'|none)\s+(\#.*)?/)
410 my @src = map hex, split /,/,$1;
411 my $dst = $4;
412 my $comment = $5;
413 if ($#src > 0) { push @unicode_aliases, \@src; }
414 next if ($dst eq "none");
415 $dst = ($dst =~ /\'.\'/) ? ord substr($dst,1,1) : hex $dst;
416 foreach my $src (@src)
418 die "Duplicate value" if defined($unicode_defaults[$src]);
419 $unicode_defaults[$src] = $dst;
421 next;
423 die "Unrecognized line $_\n";
425 close DEFAULTS;
427 # now build mappings from the decomposition field of the Unicode database
429 my $UNICODE_DATA = open_data_file( $UNIDATA, "UnicodeData.txt" );
430 while (<$UNICODE_DATA>)
432 # Decode the fields ...
433 my ($code, $name, $cat, $comb, $bidi,
434 $decomp, $dec, $dig, $num, $mirror,
435 $oldname, $comment, $upper, $lower, $title) = split /;/;
436 my $dst;
437 my $src = hex $code;
439 die "unknown category $cat" unless defined $categories{$cat};
440 die "unknown directionality $bidi" unless defined $directions{$bidi};
442 $category_table[$src] = $categories{$cat};
443 $direction_table[$src] = $directions{$bidi};
444 $joining_table[$src] = $joining_types{"T"} if $cat eq "Mn" || $cat eq "Me" || $cat eq "Cf";
446 if ($lower ne "")
448 $tolower_table[$src] = hex $lower;
450 if ($upper ne "")
452 $toupper_table[$src] = hex $upper;
454 if ($dec ne "")
456 $category_table[$src] |= $ctype{"digit"};
458 if ($dig ne "")
460 $digitmap_table[$src] = ord $dig;
462 if ($comb ne "")
464 $combining_class_table[$src] = $comb;
467 # copy the category and direction for everything between First/Last pairs
468 if ($name =~ /, First>/) { $start = $src; }
469 if ($name =~ /, Last>/)
471 while ($start < $src)
473 $category_table[$start] = $category_table[$src];
474 $direction_table[$start] = $direction_table[$src];
475 $start++;
479 next if $decomp eq ""; # no decomposition, skip it
481 if ($decomp =~ /^<([a-zA-Z]+)>\s+([0-9a-fA-F]+)/)
483 my @seq = ();
484 for my $ch (split /\s+/, (split /\s+/, $decomp, 2)[1])
486 push @seq, (hex $ch);
488 $full_compatmap_table[$src] = \@seq;
491 if ($decomp =~ /^<([a-zA-Z]+)>\s+([0-9a-fA-F]+)$/)
493 # decomposition of the form "<foo> 1234" -> use char if type is known
494 if (($src >= 0xf900 && $src < 0xfb00) || ($src >= 0xfe30 && $src < 0xfffd))
496 # Single char decomposition in the compatibility range
497 $compatmap_table[$src] = hex $2;
499 if ($1 eq "isolated" || $1 eq "final" || $1 eq "initial" || $1 eq "medial")
501 ${joining_forms{$1}}[hex $2] = $src;
502 next;
504 next unless ($1 eq "font" ||
505 $1 eq "noBreak" ||
506 $1 eq "circle" ||
507 $1 eq "super" ||
508 $1 eq "sub" ||
509 $1 eq "wide" ||
510 $1 eq "narrow" ||
511 $1 eq "compat" ||
512 $1 eq "small");
513 $dst = hex $2;
515 elsif ($decomp =~ /^<compat>\s+0020\s+([0-9a-fA-F]+)/)
517 # decomposition "<compat> 0020 1234" -> combining accent
518 $dst = hex $1;
520 elsif ($decomp =~ /^([0-9a-fA-F]+)/)
522 # decomposition contains only char values without prefix -> use first char
523 $dst = hex $1;
524 $category_table[$src] |= $category_table[$dst] if defined $category_table[$dst];
525 # store decomposition if it contains two chars
526 if ($decomp =~ /^([0-9a-fA-F]+)\s+([0-9a-fA-F]+)$/)
528 $decomp_table[$src] = [ hex $1, hex $2 ];
529 push @compose_table, [ hex $1, hex $2, $src ];
531 elsif ($decomp =~ /^([0-9a-fA-F]+)$/)
533 # Single char decomposition
534 if (hex $1 < 65536)
536 $decomp_table[$src] = [ hex $1, 0 ];
539 if (($src >= 0xf900 && $src < 0xfb00) || ($src >= 0xfe30 && $src < 0xfffd))
541 # Single char decomposition in the compatibility range
542 $compatmap_table[$src] = hex $1;
546 else
548 next;
551 next if defined($unicode_defaults[$src]); # may have been set in the defaults file
553 # check for loops
554 for (my $i = $dst; ; $i = $unicode_defaults[$i])
556 die sprintf("loop detected for %04x -> %04x",$src,$dst) if $i == $src;
557 last unless defined($unicode_defaults[$i]);
559 $unicode_defaults[$src] = $dst;
561 close $UNICODE_DATA;
563 # patch the category of some special characters
565 foreach my $cat (keys %special_categories)
567 my $flag = $ctype{$cat};
568 foreach my $i (@{$special_categories{$cat}}) { $category_table[$i] |= $flag; }
573 ################################################################
574 # define a new lead byte
575 sub add_lead_byte($)
577 my $ch = shift;
578 push @lead_bytes, $ch;
579 $cp2uni[$ch] = 0;
582 ################################################################
583 # define a new char mapping
584 sub add_mapping($$)
586 my ($cp, $uni) = @_;
587 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
588 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
589 if ($cp > 0xff && !defined($cp2uni[$cp >> 8]))
591 add_lead_byte( $cp >> 8 );
595 ################################################################
596 # parse a standard codepage file
597 sub read_codepage_file($)
599 my $name = shift;
600 my $INPUT = open_data_file( $MAPPINGS, $name );
602 while (<$INPUT>)
604 next if /^\#/; # skip comments
605 next if /^$/; # skip empty lines
606 next if /\x1a/; # skip ^Z
607 next if (/^0x([0-9a-fA-F]+)\s+\#UNDEFINED/); # undefined char
609 if (/^0x([0-9a-fA-F]+)\s+\#DBCS LEAD BYTE/)
611 add_lead_byte( hex $1 );
612 next;
614 # 0x12 0x3456
615 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
617 add_mapping( hex $1, hex $2 );
618 next;
620 # 0x12 0x3456+0x7890
621 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\+.*\s+(\#.*)?/)
623 add_mapping( hex $1, hex $2 );
624 next;
626 # 0x12 <LR>+0x3456
627 if (/^0x([0-9a-fA-F]+)\s+<LR>\+0x([0-9a-fA-F]+)\s+(\#.*)?/)
629 add_mapping( hex $1, hex $2 );
630 next;
632 # 0x12 <RL>+0x3456
633 if (/^0x([0-9a-fA-F]+)\s+<RL>\+0x([0-9a-fA-F]+)\s+(\#.*)?/)
635 my $uni = hex $2;
636 add_mapping( hex $1, $uni ) if $uni >= 0x80;
637 next;
639 die "$name: Unrecognized line $_\n";
641 close $INPUT;
645 ################################################################
646 # fill input data for the 20127 (us-ascii) codepage
647 sub fill_20127_codepage()
649 for (my $i = 0; $i < 128; $i++) { $cp2uni[$i] = $uni2cp[$i] = $i; }
650 for (my $i = 128; $i < 256; $i++) { $cp2uni[$i] = $i & 0x7f; }
653 ################################################################
654 # get a mapping including glyph chars for MB_USEGLYPHCHARS
656 sub get_glyphs_mapping(@)
658 $_[0x01] = 0x263a; # (WHITE SMILING FACE)
659 $_[0x02] = 0x263b; # (BLACK SMILING FACE)
660 $_[0x03] = 0x2665; # (BLACK HEART SUIT)
661 $_[0x04] = 0x2666; # (BLACK DIAMOND SUIT)
662 $_[0x05] = 0x2663; # (BLACK CLUB SUIT)
663 $_[0x06] = 0x2660; # (BLACK SPADE SUIT)
664 $_[0x07] = 0x2022; # (BULLET)
665 $_[0x08] = 0x25d8; # (INVERSE BULLET)
666 $_[0x09] = 0x25cb; # (WHITE CIRCLE)
667 $_[0x0a] = 0x25d9; # (INVERSE WHITE CIRCLE)
668 $_[0x0b] = 0x2642; # (MALE SIGN)
669 $_[0x0c] = 0x2640; # (FEMALE SIGN)
670 $_[0x0d] = 0x266a; # (EIGHTH NOTE)
671 $_[0x0e] = 0x266b; # (BEAMED EIGHTH NOTES)
672 $_[0x0f] = 0x263c; # (WHITE SUN WITH RAYS)
673 $_[0x10] = 0x25ba; # (BLACK RIGHT-POINTING POINTER)
674 $_[0x11] = 0x25c4; # (BLACK LEFT-POINTING POINTER)
675 $_[0x12] = 0x2195; # (UP DOWN ARROW)
676 $_[0x13] = 0x203c; # (DOUBLE EXCLAMATION MARK)
677 $_[0x14] = 0x00b6; # (PILCROW SIGN)
678 $_[0x15] = 0x00a7; # (SECTION SIGN)
679 $_[0x16] = 0x25ac; # (BLACK RECTANGLE)
680 $_[0x17] = 0x21a8; # (UP DOWN ARROW WITH BASE)
681 $_[0x18] = 0x2191; # (UPWARDS ARROW)
682 $_[0x19] = 0x2193; # (DOWNWARDS ARROW)
683 $_[0x1a] = 0x2192; # (RIGHTWARDS ARROW)
684 $_[0x1b] = 0x2190; # (LEFTWARDS ARROW)
685 $_[0x1c] = 0x221f; # (RIGHT ANGLE)
686 $_[0x1d] = 0x2194; # (LEFT RIGHT ARROW)
687 $_[0x1e] = 0x25b2; # (BLACK UP-POINTING TRIANGLE)
688 $_[0x1f] = 0x25bc; # (BLACK DOWN-POINTING TRIANGLE)
689 $_[0x7f] = 0x2302; # (HOUSE)
690 return @_;
693 ################################################################
694 # build EUC-JP table from the JIS 0208 file
695 # FIXME: for proper EUC-JP we should probably read JIS 0212 too
696 # but this would require 3-byte DBCS characters
697 sub READ_JIS0208_FILE($)
699 my $name = shift;
701 # ASCII chars
702 for (my $i = 0x00; $i <= 0x7f; $i++)
704 $cp2uni[$i] = $i;
705 $uni2cp[$i] = $i;
708 # JIS X 0201 right plane
709 for (my $i = 0xa1; $i <= 0xdf; $i++)
711 $cp2uni[0x8e00 + $i] = 0xfec0 + $i;
712 $uni2cp[0xfec0 + $i] = 0x8e00 + $i;
715 # lead bytes
716 foreach my $i (0x8e, 0x8f, 0xa1 .. 0xfe)
718 add_lead_byte($i);
721 # undefined chars
722 foreach my $i (0x80 .. 0x8d, 0x90 .. 0xa0, 0xff)
724 $cp2uni[$i] = $DEF_CHAR;
727 # Shift-JIS compatibility
728 $uni2cp[0x00a5] = 0x5c;
729 $uni2cp[0x203e] = 0x7e;
731 # Fix backslash conversion
732 $cp2uni[0xa1c0] = 0xff3c;
733 $uni2cp[0xff3c] = 0xa1c0;
735 my $INPUT = open_data_file( $MAPPINGS, $name );
736 while (<$INPUT>)
738 next if /^\#/; # skip comments
739 next if /^$/; # skip empty lines
740 next if /\x1a/; # skip ^Z
741 if (/^0x[0-9a-fA-F]+\s+0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
743 my $cp = 0x8080 + hex $1;
744 my $uni = hex $2;
745 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
746 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
747 next;
749 die "$name: Unrecognized line $_\n";
751 close $INPUT;
755 ################################################################
756 # build the sort keys table
757 sub READ_SORTKEYS_FILE()
759 my @sortkeys = ();
760 for (my $i = 0; $i < 65536; $i++) { $sortkeys[$i] = [ -1, 0, 0, 0, 0 ] };
762 my $INPUT = open_data_file( $REPORTS, $SORTKEYS );
763 while (<$INPUT>)
765 next if /^\#/; # skip comments
766 next if /^$/; # skip empty lines
767 next if /\x1a/; # skip ^Z
768 next if /^\@version/; # skip @version header
769 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]+)\]/)
771 my ($uni,$variable) = (hex $1, $2);
772 next if $uni > 65535;
773 $sortkeys[$uni] = [ $uni, hex $3, hex $4, hex $5, hex $6 ];
774 next;
776 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]+)\]/)
778 # multiple character sequence, ignored for now
779 next;
781 die "$SORTKEYS: Unrecognized line $_\n";
783 close $INPUT;
785 # compress the keys to 32 bit:
786 # key 1 to 16 bits, key 2 to 8 bits, key 3 to 4 bits, key 4 to 1 bit
788 @sortkeys = sort { ${$a}[1] <=> ${$b}[1] or
789 ${$a}[2] <=> ${$b}[2] or
790 ${$a}[3] <=> ${$b}[3] or
791 ${$a}[4] <=> ${$b}[4] or
792 $a cmp $b; } @sortkeys;
794 my ($n2, $n3) = (1, 1);
795 my @keys = (-1, -1, -1, -1, -1 );
796 my @flatkeys = ();
798 for (my $i = 0; $i < 65536; $i++)
800 my @current = @{$sortkeys[$i]};
801 next if $current[0] == -1;
802 if ($current[1] == $keys[1])
804 if ($current[2] == $keys[2])
806 if ($current[3] == $keys[3])
808 # nothing
810 else
812 $keys[3] = $current[3];
813 $n3++;
814 die if ($n3 >= 16);
817 else
819 $keys[2] = $current[2];
820 $keys[3] = $current[3];
821 $n2++;
822 $n3 = 1;
823 die if ($n2 >= 256);
826 else
828 $keys[1] = $current[1];
829 $keys[2] = $current[2];
830 $keys[3] = $current[3];
831 $n2 = 1;
832 $n3 = 1;
835 if ($current[2]) { $current[2] = $n2; }
836 if ($current[3]) { $current[3] = $n3; }
837 if ($current[4]) { $current[4] = 1; }
839 $flatkeys[$current[0]] = ($current[1] << 16) | ($current[2] << 8) | ($current[3] << 4) | $current[4];
841 return @flatkeys;
845 ################################################################
846 # build the sort keys table
847 sub DUMP_SORTKEYS($@)
849 my ($filename, @keys) = @_;
851 # count the number of 256-key ranges that contain something
853 my @offsets = ();
854 my $ranges = 2;
855 for (my $i = 0; $i < 256; $i++) { $offsets[$i] = 256; }
856 for (my $i = 0; $i < 65536; $i++)
858 next unless defined $keys[$i];
859 $offsets[$i >> 8] = $ranges * 256;
860 $ranges++;
861 $i |= 255;
864 # output the range offsets
866 open OUTPUT,">$filename.new" or die "Cannot create $filename";
867 printf "Building $filename\n";
868 printf OUTPUT "/* Unicode collation element table */\n";
869 printf OUTPUT "/* generated from %s */\n", "$REPORTS/$SORTKEYS";
870 printf OUTPUT "/* DO NOT EDIT!! */\n\n";
872 printf OUTPUT "const unsigned int collation_table[%d] =\n{\n", $ranges*256;
873 printf OUTPUT " /* index */\n";
874 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%08x", 0, @offsets );
876 # output the default values
878 printf OUTPUT " /* defaults */\n";
879 printf OUTPUT "%s", DUMP_ARRAY( "0x%08x", 0, (0xffffffff) x 256 );
881 # output all the key ranges
883 for (my $i = 0; $i < 256; $i++)
885 next if $offsets[$i] == 256;
886 printf OUTPUT ",\n /* 0x%02x00 .. 0x%02xff */\n", $i, $i;
887 printf OUTPUT "%s", DUMP_ARRAY( "0x%08x", 0xffffffff, @keys[($i<<8) .. ($i<<8)+255] );
889 printf OUTPUT "\n};\n";
890 close OUTPUT;
891 save_file($filename);
895 ################################################################
896 # add default mappings once the file had been read
897 sub add_default_mappings($)
899 my $first_private = shift;
901 # Apply aliases
903 foreach my $alias (@unicode_aliases)
905 my $target = undef;
906 foreach my $src (@$alias)
908 if (defined($uni2cp[$src]))
910 $target = $uni2cp[$src];
911 last;
914 next unless defined($target);
916 # At least one char of the alias set is defined, set the others to the same value
917 foreach my $src (@$alias)
919 $uni2cp[$src] = $target unless defined($uni2cp[$src]);
923 # For every src -> target mapping in the defaults table,
924 # make uni2cp[src] = uni2cp[target] if uni2cp[target] is defined
926 for (my $src = 0; $src < 65536; $src++)
928 next if defined($uni2cp[$src]); # source has a definition already
929 next unless defined($unicode_defaults[$src]); # no default for this char
930 my $target = $unicode_defaults[$src];
932 # do a recursive mapping until we find a target char that is defined
933 while (!defined($uni2cp[$target]) &&
934 defined($unicode_defaults[$target])) { $target = $unicode_defaults[$target]; }
936 if (defined($uni2cp[$target])) { $uni2cp[$src] = $uni2cp[$target]; }
939 # Add a private char mapping for undefined chars
941 if ($first_private)
943 for (my $i = 32; $i < 256; $i++)
945 next if defined($cp2uni[$i]);
946 $cp2uni[$i] = $first_private;
947 $uni2cp[$first_private] = $i;
948 $first_private++;
952 # Add an identity mapping for all undefined chars
954 for (my $i = 0; $i < 256; $i++)
956 next if defined($cp2uni[$i]);
957 next if defined($uni2cp[$i]);
958 $cp2uni[$i] = $uni2cp[$i] = $i;
962 ################################################################
963 # dump an array of integers
964 sub DUMP_ARRAY($$@)
966 my ($format,$default,@array) = @_;
967 my $i;
968 my $ret = " ";
969 for ($i = 0; $i < $#array; $i++)
971 $ret .= sprintf($format, defined $array[$i] ? $array[$i] : $default);
972 $ret .= (($i % 8) != 7) ? ", " : ",\n ";
974 $ret .= sprintf($format, defined $array[$i] ? $array[$i] : $default);
975 return $ret;
979 ################################################################
980 # dump a unicode->ascii mapping table
981 sub dump_uni2cp_table($$)
983 my ($width, $def) = @_;
985 # count the number of unicode->ascii subtables that contain something
987 my @lowerbounds;
988 my @upperbounds;
989 my $index = 0;
990 my @filled = (-1) x 256;
991 for (my $i = 0; $i < 65536; $i++)
993 next unless defined $uni2cp[$i];
994 if ($filled[$i >> 8] == -1)
996 $lowerbounds[$index] = $i & 0xff;
997 $upperbounds[$index] = 0xff - $lowerbounds[$index];
998 $filled[$i >> 8] = $index * 256;
999 $index++;
1001 else
1003 $upperbounds[$index-1] = 0xff - ($i & 0xff);
1007 # add defaults mapping at the end
1008 $filled[256] = $index * 256;
1009 $lowerbounds[$index] = 255;
1010 $upperbounds[$index] = 0;
1011 $index++;
1013 # collapse blocks upwards if possible
1014 my $removed = 0;
1015 $index = 0;
1016 for (my $i = 0; $i < 257; $i++)
1018 next if $filled[$i] == -1;
1019 if ($upperbounds[$index - 1] > $lowerbounds[$index])
1021 $removed += $lowerbounds[$index];
1023 else
1025 $removed += $upperbounds[$index - 1];
1026 $lowerbounds[$index] = $upperbounds[$index - 1];
1028 $filled[$i] -= $removed;
1029 $index++;
1032 # output all the subtables into a single array
1034 printf OUTPUT "static const unsigned %s uni2cp_low[%d] =\n{\n",
1035 $width == 8 ? "char" : "short", ($index + 1) * 256 - $removed;
1037 my $format = $width == 8 ? "0x%02x" : "0x%04x";
1038 for (my $i = $index = 0; $i < 257; $i++)
1040 next if $filled[$i] == -1;
1041 my $start = ($i << 8) + $lowerbounds[$index];
1042 my $end = ($i << 8) + 255;
1043 if ($i == 256)
1045 print OUTPUT " /* defaults */\n";
1046 printf OUTPUT "%s\n};\n\n", DUMP_ARRAY( $format, 0, ($def) x ($end - $start + 1) );
1048 else
1050 printf OUTPUT " /* 0x%04x .. 0x%04x */\n", $start, $end;
1051 printf OUTPUT "%s,\n", DUMP_ARRAY( $format, $def, @uni2cp[$start .. $end] );
1053 $index++;
1056 # output a table of the offsets of the subtables in the previous array
1058 for (my $i = 0; $i < 256; $i++)
1060 if ($filled[$i] == -1) { $filled[$i] = $filled[256]; }
1062 printf OUTPUT "static const unsigned short uni2cp_high[256] =\n";
1063 printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%04x", 0, @filled[0..255] );
1066 ################################################################
1067 # dump an SBCS mapping table
1068 sub dump_sbcs_table($$$$$)
1070 my ($codepage, $has_glyphs, $name, $def, $defw) = @_;
1071 my $i;
1073 # output the ascii->unicode table
1075 if ($has_glyphs)
1077 printf OUTPUT "static const WCHAR cp2uni[512] =\n";
1078 printf OUTPUT "{\n%s", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[0 .. 255] );
1079 printf OUTPUT ",\n /* glyphs */\n%s\n};\n\n",
1080 DUMP_ARRAY( "0x%04x", $defw, get_glyphs_mapping(@cp2uni[0 .. 255]) );
1082 else
1084 printf OUTPUT "static const WCHAR cp2uni[256] =\n";
1085 printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[0 .. 255] );
1088 dump_uni2cp_table( 8, $def );
1090 # output the code page descriptor
1092 printf OUTPUT "const struct sbcs_table DECLSPEC_HIDDEN cptable_%03d =\n{\n", $codepage;
1093 printf OUTPUT " { %d, 1, 0x%04x, 0x%04x, \"%s\" },\n",
1094 $codepage, $def, $defw, $name;
1095 printf OUTPUT " cp2uni,\n";
1096 if ($has_glyphs) { printf OUTPUT " cp2uni + 256,\n"; }
1097 else { printf OUTPUT " cp2uni,\n"; }
1098 printf OUTPUT " uni2cp_low,\n";
1099 printf OUTPUT " uni2cp_high\n};\n";
1103 ################################################################
1104 # dump a DBCS mapping table
1105 sub dump_dbcs_table($$$$@)
1107 my ($codepage, $name, $def, $defw, @lb_ranges) = @_;
1109 # build a list of lead bytes that are actually used
1111 my @lblist = ();
1112 LBLOOP: for (my $y = 0; $y <= $#lead_bytes; $y++)
1114 $cp2uni[$lead_bytes[$y]] = $defw;
1115 my $base = $lead_bytes[$y] << 8;
1116 for (my $x = 0; $x < 256; $x++)
1118 if (defined $cp2uni[$base+$x])
1120 push @lblist,$lead_bytes[$y];
1121 next LBLOOP;
1125 my $unused = ($#lead_bytes > $#lblist);
1127 # output the ascii->unicode table for the single byte chars
1129 printf OUTPUT "static const WCHAR cp2uni[%d] =\n", 256 * ($#lblist + 2 + $unused);
1130 printf OUTPUT "{\n%s,\n", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[0 .. 255] );
1132 # output the default table for unused lead bytes
1134 if ($unused)
1136 printf OUTPUT " /* unused lead bytes */\n";
1137 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%04x", 0, ($defw) x 256 );
1140 # output the ascii->unicode table for each DBCS lead byte
1142 for (my $y = 0; $y <= $#lblist; $y++)
1144 my $base = $lblist[$y] << 8;
1145 printf OUTPUT " /* lead byte %02x */\n", $lblist[$y];
1146 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[$base .. $base+255] );
1147 printf OUTPUT ($y < $#lblist) ? ",\n" : "\n};\n\n";
1150 # output the lead byte subtables offsets
1152 my @offsets = (0) x 256;
1153 for (my $x = 0; $x <= $#lblist; $x++) { $offsets[$lblist[$x]] = $x + 1; }
1154 if ($unused)
1156 # increment all lead bytes offset to take into account the unused table
1157 for (my $x = 0; $x <= $#lead_bytes; $x++) { $offsets[$lead_bytes[$x]]++; }
1159 printf OUTPUT "static const unsigned char cp2uni_leadbytes[256] =\n";
1160 printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%02x", 0, @offsets );
1162 dump_uni2cp_table( 16, $def );
1164 # output the code page descriptor
1166 printf OUTPUT "const struct dbcs_table DECLSPEC_HIDDEN cptable_%03d =\n{\n", $codepage;
1167 printf OUTPUT " { %d, 2, 0x%04x, 0x%04x, \"%s\" },\n",
1168 $codepage, $def, $defw, $name;
1169 printf OUTPUT " cp2uni,\n";
1170 printf OUTPUT " cp2uni_leadbytes,\n";
1171 printf OUTPUT " uni2cp_low,\n";
1172 printf OUTPUT " uni2cp_high,\n";
1173 printf OUTPUT " {\n %s\n }\n", DUMP_ARRAY( "0x%02x", 0, @lb_ranges, 0, 0 );
1174 printf OUTPUT "};\n";
1178 ################################################################
1179 # get the list of defined lead byte ranges
1180 sub get_lb_ranges()
1182 my @list = ();
1183 my @ranges = ();
1184 my $i = 0;
1185 foreach $i (@lead_bytes) { $list[$i] = 1; }
1186 my $on = 0;
1187 for (my $i = 0; $i < 256; $i++)
1189 if ($on)
1191 if (!defined $list[$i]) { push @ranges, $i-1; $on = 0; }
1193 else
1195 if ($list[$i]) { push @ranges, $i; $on = 1; }
1198 if ($on) { push @ranges, 0xff; }
1199 return @ranges;
1202 ################################################################
1203 # dump the Indic Syllabic Category table
1204 sub dump_indic($)
1206 my $filename = shift;
1207 my @indic_table;
1209 my $INPUT = open_data_file( $UNIDATA, "IndicSyllabicCategory.txt" );
1210 while (<$INPUT>)
1212 next if /^\#/; # skip comments
1213 next if /^\s*$/; # skip empty lines
1214 next if /\x1a/; # skip ^Z
1215 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*#/)
1217 my $type = $2;
1218 die "unknown indic $type" unless defined $indic_types{$type};
1219 if (hex $1 < 65536)
1221 $indic_table[hex $1] = $indic_types{$type};
1223 next;
1225 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*#/)
1227 my $type = $3;
1228 die "unknown indic $type" unless defined $indic_types{$type};
1229 if (hex $1 < 65536 and hex $2 < 65536)
1231 foreach my $i (hex $1 .. hex $2)
1233 $indic_table[$i] = $indic_types{$type};
1236 next;
1238 die "malformed line $_";
1240 close $INPUT;
1242 $INPUT = open_data_file( $UNIDATA, "IndicPositionalCategory.txt" );
1243 while (<$INPUT>)
1245 next if /^\#/; # skip comments
1246 next if /^\s*$/; # skip empty lines
1247 next if /\x1a/; # skip ^Z
1248 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z]+)\s*#/)
1250 my $type = $2;
1251 die "unknown matra $type" unless defined $matra_types{$type};
1252 $indic_table[hex $1] += $matra_types{$type} << 8;
1253 next;
1255 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*#/)
1257 my $type = $3;
1258 die "unknown matra $type" unless defined $matra_types{$type};
1259 foreach my $i (hex $1 .. hex $2)
1261 $indic_table[$i] += $matra_types{$type} << 8;
1263 next;
1265 die "malformed line $_";
1267 close $INPUT;
1269 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1270 print "Building $filename\n";
1271 print OUTPUT "/* Unicode Indic Syllabic Category */\n";
1272 print OUTPUT "/* generated from $UNIDATA/IndicSyllabicCategory.txt */\n";
1273 print OUTPUT "/* and from $UNIDATA/IndicPositionalCategory.txt */\n";
1274 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1275 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1277 dump_two_level_mapping( "indic_syllabic_table", $indic_types{'Other'}, @indic_table );
1279 close OUTPUT;
1280 save_file($filename);
1283 ################################################################
1284 # dump the Line Break Properties table
1285 sub dump_linebreak($)
1287 my $filename = shift;
1288 my @break_table;
1289 my $next_group = 0;
1291 my $INPUT = open_data_file( $UNIDATA, "LineBreak.txt" );
1292 while (<$INPUT>)
1294 next if /^\#/; # skip comments
1295 next if /^\s*$/; # skip empty lines
1296 next if /\x1a/; # skip ^Z
1297 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z][0-9A-Z])+\s*/)
1299 my $type = $2;
1300 die "unknown breaktype $type" unless defined $break_types{$type};
1301 $break_table[hex $1] = $break_types{$type};
1302 next;
1304 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z][0-9A-Z])+\s*/)
1306 my $type = $3;
1307 die "unknown breaktype $type" unless defined $break_types{$type};
1308 foreach my $i (hex $1 .. hex $2)
1310 $break_table[$i] = $break_types{$type};
1312 next;
1314 elsif (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z])+\s*/)
1316 my $type = $2;
1317 die "unknown breaktype $type" unless defined $break_types{$type};
1318 $break_table[hex $1] = $break_types{$type};
1319 next;
1321 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z])+\s*/)
1323 my $type = $3;
1324 die "unknown breaktype $type" unless defined $break_types{$type};
1325 foreach my $i (hex $1 .. hex $2)
1327 $break_table[$i] = $break_types{$type};
1329 next;
1331 die "malformed line $_";
1333 close $INPUT;
1335 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1336 print "Building $filename\n";
1337 print OUTPUT "/* Unicode Line Break Properties */\n";
1338 print OUTPUT "/* generated from $UNIDATA/LineBreak.txt */\n";
1339 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1340 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1342 dump_two_level_mapping( "wine_linebreak_table", $break_types{'XX'}, @break_table );
1344 close OUTPUT;
1345 save_file($filename);
1348 my %scripts =
1350 "Unknown" => 0,
1351 "Common" => 1,
1352 "Inherited" => 2,
1353 "Arabic" => 3,
1354 "Armenian" => 4,
1355 "Avestan" => 5,
1356 "Balinese" => 6,
1357 "Bamum" => 7,
1358 "Batak" => 8,
1359 "Bengali" => 9,
1360 "Bopomofo" => 10,
1361 "Brahmi" => 11,
1362 "Braille" => 12,
1363 "Buginese" => 13,
1364 "Buhid" => 14,
1365 "Canadian_Aboriginal" => 15,
1366 "Carian" => 16,
1367 "Cham" => 17,
1368 "Cherokee" => 18,
1369 "Coptic" => 19,
1370 "Cuneiform" => 20,
1371 "Cypriot" => 21,
1372 "Cyrillic" => 22,
1373 "Deseret" => 23,
1374 "Devanagari" => 24,
1375 "Egyptian_Hieroglyphs" => 25,
1376 "Ethiopic" => 26,
1377 "Georgian" => 27,
1378 "Glagolitic" => 28,
1379 "Gothic" => 29,
1380 "Greek" => 30,
1381 "Gujarati" => 31,
1382 "Gurmukhi" => 32,
1383 "Han" => 33,
1384 "Hangul" => 34,
1385 "Hanunoo" => 35,
1386 "Hebrew" => 36,
1387 "Hiragana" => 37,
1388 "Imperial_Aramaic" => 38,
1389 "Inscriptional_Pahlavi" => 39,
1390 "Inscriptional_Parthian" => 40,
1391 "Javanese" => 41,
1392 "Kaithi" => 42,
1393 "Kannada" => 43,
1394 "Katakana" => 44,
1395 "Kayah_Li" => 45,
1396 "Kharoshthi" => 46,
1397 "Khmer" => 47,
1398 "Lao" => 48,
1399 "Latin" => 49,
1400 "Lepcha" => 50,
1401 "Limbu" => 51,
1402 "Linear_B" => 52,
1403 "Lisu" => 53,
1404 "Lycian" => 54,
1405 "Lydian" => 55,
1406 "Malayalam" => 56,
1407 "Mandaic" => 57,
1408 "Meetei_Mayek" => 58,
1409 "Mongolian" => 59,
1410 "Myanmar" => 60,
1411 "New_Tai_Lue" => 61,
1412 "Nko" => 62,
1413 "Ogham" => 63,
1414 "Ol_Chiki" => 64,
1415 "Old_Italic" => 65,
1416 "Old_Persian" => 66,
1417 "Old_South_Arabian" => 67,
1418 "Old_Turkic" => 68,
1419 "Oriya" => 69,
1420 "Osmanya" => 70,
1421 "Phags_Pa" => 71,
1422 "Phoenician" => 72,
1423 "Rejang" => 73,
1424 "Runic" => 74,
1425 "Samaritan" => 75,
1426 "Saurashtra" => 76,
1427 "Shavian" => 77,
1428 "Sinhala" => 78,
1429 "Sundanese" => 79,
1430 "Syloti_Nagri" => 80,
1431 "Syriac" => 81,
1432 "Tagalog" => 82,
1433 "Tagbanwa" => 83,
1434 "Tai_Le" => 84,
1435 "Tai_Tham" => 85,
1436 "Tai_Viet" => 86,
1437 "Tamil" => 87,
1438 "Telugu" => 88,
1439 "Thaana" => 89,
1440 "Thai" => 90,
1441 "Tibetan" => 91,
1442 "Tifinagh" => 92,
1443 "Ugaritic" => 93,
1444 "Vai" => 94,
1445 "Yi" => 95,
1446 # Win8/Win8.1
1447 "Chakma" => 96,
1448 "Meroitic_Cursive" => 97,
1449 "Meroitic_Hieroglyphs" => 98,
1450 "Miao" => 99,
1451 "Sharada" => 100,
1452 "Sora_Sompeng" => 101,
1453 "Takri" => 102,
1454 # Win10
1455 "Bassa_Vah" => 103,
1456 "Caucasian_Albanian" => 104,
1457 "Duployan" => 105,
1458 "Elbasan" => 106,
1459 "Grantha" => 107,
1460 "Khojki" => 108,
1461 "Khudawadi" => 109,
1462 "Linear_A" => 110,
1463 "Mahajani" => 111,
1464 "Manichaean" => 112,
1465 "Mende_Kikakui" => 113,
1466 "Modi" => 114,
1467 "Mro" => 115,
1468 "Nabataean" => 116,
1469 "Old_North_Arabian" => 117,
1470 "Old_Permic" => 118,
1471 "Pahawh_Hmong" => 119,
1472 "Palmyrene" => 120,
1473 "Pau_Cin_Hau" => 121,
1474 "Psalter_Pahlavi" => 122,
1475 "Siddham" => 123,
1476 "Tirhuta" => 124,
1477 "Warang_Citi" => 125,
1478 # Win10 RS1
1479 "Adlam" => 126,
1480 "Ahom" => 127,
1481 "Anatolian_Hieroglyphs" => 128,
1482 "Bhaiksuki" => 129,
1483 "Hatran" => 130,
1484 "Marchen" => 131,
1485 "Multani" => 132,
1486 "Newa" => 133,
1487 "Old_Hungarian" => 134,
1488 "Osage" => 135,
1489 "SignWriting" => 136,
1490 "Tangut" => 137,
1491 # Win10 RS4
1492 "Masaram_Gondi" => 138,
1493 "Nushu" => 139,
1494 "Soyombo" => 140,
1495 "Zanabazar_Square" => 141,
1498 ################################################################
1499 # dump Script IDs table
1500 sub dump_scripts($)
1502 my $filename = shift;
1503 my $header = $filename;
1504 my @scripts_table;
1505 my $script_index;
1506 my $i;
1508 my $INPUT = open_data_file( $UNIDATA, "Scripts.txt" );
1509 # Fill the table
1510 # Unknown script id is always 0, so undefined scripts are automatically treated as such
1511 while (<$INPUT>)
1513 my $type = "";
1515 next if /^\#/; # skip comments
1516 next if /^\s*$/; # skip empty lines
1517 next if /\x1a/; # skip ^Z
1518 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1520 $type = $2;
1521 if (defined $scripts{$type})
1523 $scripts_table[hex $1] = $scripts{$type};
1525 next;
1527 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1529 $type = $3;
1530 if (defined $scripts{$type})
1532 foreach my $i (hex $1 .. hex $2)
1534 $scripts_table[$i] = $scripts{$type};
1537 next;
1541 close $INPUT;
1543 $header = "$filename.h";
1544 open OUTPUT,">$header.new" or die "Cannot create $header";
1545 print "Building $header\n";
1546 print OUTPUT "/* Unicode Script IDs */\n";
1547 print OUTPUT "/* generated from $UNIDATA/Scripts.txt */\n";
1548 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1550 print OUTPUT "enum unicode_script_id {\n";
1551 foreach my $script (sort { $scripts{$a} <=> $scripts{$b} } keys %scripts)
1553 print OUTPUT " Script_$script = $scripts{$script},\n";
1555 print OUTPUT " Script_LastId = ", (scalar keys %scripts) - 1, "\n";
1556 print OUTPUT "};\n";
1558 close OUTPUT;
1559 save_file($header);
1561 $filename = "$filename.c";
1562 open OUTPUT,">$filename.new" or die "Cannot create $header";
1563 print "Building $filename\n";
1564 print OUTPUT "/* Unicode Script IDs */\n";
1565 print OUTPUT "/* generated from $UNIDATA/Scripts.txt */\n";
1566 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1567 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1569 dump_two_level_mapping( "wine_scripts_table", 0, @scripts_table );
1570 close OUTPUT;
1571 save_file($filename);
1574 ################################################################
1575 # dump the BiDi mirroring table
1576 sub dump_mirroring($)
1578 my $filename = shift;
1579 my @mirror_table = ();
1581 my $INPUT = open_data_file( $UNIDATA, "BidiMirroring.txt" );
1582 while (<$INPUT>)
1584 next if /^\#/; # skip comments
1585 next if /^$/; # skip empty lines
1586 next if /\x1a/; # skip ^Z
1587 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9a-fA-F]+)/)
1589 $mirror_table[hex $1] = hex $2;
1590 next;
1592 die "malformed line $_";
1594 close $INPUT;
1596 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1597 print "Building $filename\n";
1598 print OUTPUT "/* Unicode BiDi mirroring */\n";
1599 print OUTPUT "/* generated from $UNIDATA/BidiMirroring.txt */\n";
1600 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1601 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1602 DUMP_CASE_TABLE( "DECLSPEC_HIDDEN wine_mirror_map", @mirror_table );
1603 close OUTPUT;
1604 save_file($filename);
1607 ################################################################
1608 # dump the Bidi Brackets
1609 sub dump_bracket($)
1611 my $filename = shift;
1612 my @bracket_table;
1614 my $INPUT = open_data_file( $UNIDATA, "BidiBrackets.txt" );
1615 while (<$INPUT>)
1617 next if /^\#/; # skip comments
1618 next if /^\s*$/; # skip empty lines
1619 next if /\x1a/; # skip ^Z
1620 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9a-fA-F]+);\s*([con])/)
1622 my $type = $3;
1623 die "unknown bracket $type" unless defined $bracket_types{$type};
1624 die "characters too distant $1 and $2" if abs(hex($2) - hex($1)) >= 128;
1625 $bracket_table[hex $1] = (hex($2) - hex($1)) % 255;
1626 $bracket_table[hex $1] += $bracket_types{$type} << 8;
1627 next;
1629 die "malformed line $_";
1631 close $INPUT;
1633 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1634 print "Building $filename\n";
1635 print OUTPUT "/* Unicode Bidirectional Bracket table */\n";
1636 print OUTPUT "/* generated from $UNIDATA/BidiBrackets.txt */\n";
1637 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1638 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1640 dump_two_level_mapping( "bidi_bracket_table", 0, @bracket_table );
1642 close OUTPUT;
1643 save_file($filename);
1646 ################################################################
1647 # dump the Arabic shaping table
1648 sub dump_shaping($)
1650 my $filename = shift;
1651 my %groups;
1652 my $next_group = 0;
1654 $groups{"No_Joining_Group"} = $next_group++;
1656 my $INPUT = open_data_file( $UNIDATA, "ArabicShaping.txt" );
1657 while (<$INPUT>)
1659 next if /^\#/; # skip comments
1660 next if /^\s*$/; # skip empty lines
1661 next if /\x1a/; # skip ^Z
1662 if (/^\s*([0-9a-fA-F]+)\s*;.*;\s*([RLDCUT])\s*;\s*(\w+)/)
1664 my $type = $2;
1665 my $group = $3;
1666 $groups{$group} = $next_group++ unless defined $groups{$group};
1667 $joining_table[hex $1] = $joining_types{$type} | ($groups{$group} << 8);
1668 next;
1670 die "malformed line $_";
1672 close $INPUT;
1674 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1675 print "Building $filename\n";
1676 print OUTPUT "/* Unicode Arabic shaping */\n";
1677 print OUTPUT "/* generated from $UNIDATA/ArabicShaping.txt */\n";
1678 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1679 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1681 dump_two_level_mapping( "wine_shaping_table", 0, @joining_table );
1683 print OUTPUT "\nconst unsigned short DECLSPEC_HIDDEN wine_shaping_forms[256][4] =\n{\n";
1684 for (my $i = 0x600; $i <= 0x6ff; $i++)
1686 printf OUTPUT " { 0x%04x, 0x%04x, 0x%04x, 0x%04x },\n",
1687 ${joining_forms{"isolated"}}[$i] || $i,
1688 ${joining_forms{"final"}}[$i] || $i,
1689 ${joining_forms{"initial"}}[$i] || $i,
1690 ${joining_forms{"medial"}}[$i] || $i;
1692 print OUTPUT "};\n";
1694 close OUTPUT;
1695 save_file($filename);
1698 ################################################################
1699 # dump the Vertical Orientation table
1700 sub dump_vertical($)
1702 my $filename = shift;
1703 my @vertical_table;
1705 my $INPUT = open_data_file( $UNIDATA, "VerticalOrientation.txt" );
1706 while (<$INPUT>)
1708 next if /^\#/; # skip comments
1709 next if /^\s*$/; # skip empty lines
1710 next if /\x1a/; # skip ^Z
1711 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1713 my $type = $2;
1714 die "unknown vertical $type" unless defined $vertical_types{$type};
1715 if (hex $1 < 65536)
1717 $vertical_table[hex $1] = $vertical_types{$type};
1719 next;
1721 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*/)
1723 my $type = $3;
1724 die "unknown vertical $type" unless defined $vertical_types{$type};
1725 foreach my $i (hex $1 .. hex $2)
1727 $vertical_table[$i] = $vertical_types{$type};
1729 next;
1731 die "malformed line $_";
1733 close $INPUT;
1735 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1736 print "Building $filename\n";
1737 print OUTPUT "/* Unicode Vertical Orientation */\n";
1738 print OUTPUT "/* generated from $UNIDATA/VerticalOrientation.txt */\n";
1739 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1740 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1742 dump_two_level_mapping( "vertical_orientation_table", $vertical_types{'R'}, @vertical_table );
1744 close OUTPUT;
1745 save_file($filename);
1748 ################################################################
1749 # dump the digit folding tables
1750 sub dump_digit_folding($)
1752 my $filename = shift;
1753 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1754 print "Building $filename\n";
1755 print OUTPUT "/* Unicode digit folding mappings */\n";
1756 print OUTPUT "/* generated from $UNIDATA/UnicodeData.txt */\n";
1757 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1758 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1760 DUMP_CASE_TABLE( "DECLSPEC_HIDDEN wine_digitmap", @digitmap_table );
1761 print OUTPUT "\n";
1762 DUMP_CASE_TABLE( "DECLSPEC_HIDDEN wine_compatmap", @compatmap_table );
1763 close OUTPUT;
1764 save_file($filename);
1768 ################################################################
1769 # dump the case mapping tables
1770 sub DUMP_CASE_MAPPINGS($)
1772 my $filename = shift;
1773 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1774 print "Building $filename\n";
1775 print OUTPUT "/* Unicode case mappings */\n";
1776 print OUTPUT "/* generated from $UNIDATA/UnicodeData.txt */\n";
1777 print OUTPUT "/* DO NOT EDIT!! */\n\n";
1778 print OUTPUT "#include \"wine/unicode.h\"\n\n";
1780 DUMP_CASE_TABLE( "wine_casemap_lower", @tolower_table );
1781 print OUTPUT "\n";
1782 DUMP_CASE_TABLE( "wine_casemap_upper", @toupper_table );
1783 close OUTPUT;
1784 save_file($filename);
1788 ################################################################
1789 # dump a case mapping table
1790 sub DUMP_CASE_TABLE($@)
1792 my ($name,@table) = @_;
1794 # count the number of sub tables that contain something
1795 # also compute the low and upper populated bounds
1797 my @lowerbounds = ( 0, 0 );
1798 my @upperbounds = ( 0, 255 );
1799 my $index = 0;
1800 my @filled = ();
1801 for (my $i = 0; $i < 65536; $i++)
1803 next unless defined $table[$i];
1804 if (!defined $filled[$i >> 8])
1806 $lowerbounds[$index] = $i & 0xff;
1807 $upperbounds[$index] = 0xff - $lowerbounds[$index];
1808 $filled[$i >> 8] = $index * 256 + 512;
1809 $index++;
1811 else
1813 $upperbounds[$index-1] = 0xff - ($i & 0xff);
1815 $table[$i] = ($table[$i] - $i) & 0xffff;
1818 # Collapse blocks upwards if possible
1819 my $removed = 0;
1820 $index = 0;
1821 for (my $i = 0; $i < 256; $i++)
1823 next unless defined $filled[$i];
1824 if ($upperbounds[$index - 1] > $lowerbounds[$index])
1826 $removed = $removed + $lowerbounds[$index];
1828 else
1830 $removed = $removed + $upperbounds[$index - 1];
1831 $lowerbounds[$index] = $upperbounds[$index - 1];
1833 $filled[$i] = $filled[$i] - $removed;
1834 $index++;
1837 # dump the table
1839 printf OUTPUT "const WCHAR %s[%d] =\n", $name, $index * 256 + 512 - $removed;
1840 printf OUTPUT "{\n /* index */\n";
1841 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%04x", 256, @filled );
1842 printf OUTPUT " /* defaults */\n";
1843 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, (0) x 256 );
1844 $index = 0;
1845 for (my $i = 0; $i < 256; $i++)
1847 next unless $filled[$i];
1848 printf OUTPUT ",\n /* 0x%02x%02x .. 0x%02xff */\n", $i, $lowerbounds[$index], $i;
1849 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0,
1850 @table[($i<<8) + $lowerbounds[$index] .. ($i<<8)+255] );
1851 $index++;
1853 printf OUTPUT "\n};\n";
1856 ################################################################
1857 # compress a mapping table by removing identical rows
1858 sub compress_array($$@)
1860 my $rows = shift;
1861 my $def = shift;
1862 my @table = @_;
1863 my $len = @table / $rows;
1864 my @array = (0) x $rows;
1865 my %sequences;
1867 # try to merge table rows
1868 for (my $row = 0; $row < $rows; $row++)
1870 my @table_row = map { defined($_) ? $_ : $def; } @table[($row * $len)..($row * $len + $len - 1)];
1871 my $rowtxt = pack "S*", @table_row;
1872 if (defined($sequences{$rowtxt}))
1874 # reuse an existing row
1875 $array[$row] = $sequences{$rowtxt};
1877 else
1879 # create a new row
1880 $sequences{$rowtxt} = $array[$row] = $#array + 1;
1881 push @array, @table_row;
1884 return @array;
1887 ################################################################
1888 # dump a simple char -> 16-bit value mapping table
1889 sub dump_simple_mapping($$@)
1891 my $name = shift;
1892 my $def = shift;
1893 my @array = compress_array( 256, $def, @_[0..65535] );
1895 printf OUTPUT "const unsigned short %s[%d] =\n{\n", $name, $#array+1;
1896 printf OUTPUT " /* offsets */\n%s,\n", DUMP_ARRAY( "0x%04x", 0, @array[0..255] );
1897 printf OUTPUT " /* values */\n%s\n};\n", DUMP_ARRAY( "0x%04x", 0, @array[256..$#array] );
1900 ################################################################
1901 # dump a char -> 16-bit value mapping table using two-level tables
1902 sub dump_two_level_mapping($$@)
1904 my $name = shift;
1905 my $def = shift;
1906 my @row_array = compress_array( 4096, $def, @_[0..65535] );
1907 my @array = compress_array( 256, 0, @row_array[0..4095] );
1909 for (my $i = 256; $i < @array; $i++) { $array[$i] += @array - 4096; }
1911 printf OUTPUT "const unsigned short DECLSPEC_HIDDEN %s[%d] =\n{\n", $name, @array + @row_array - 4096;
1912 printf OUTPUT " /* level 1 offsets */\n%s,\n", DUMP_ARRAY( "0x%04x", 0, @array[0..255] );
1913 printf OUTPUT " /* level 2 offsets */\n%s,\n", DUMP_ARRAY( "0x%04x", 0, @array[256..$#array] );
1914 printf OUTPUT " /* values */\n%s\n};\n", DUMP_ARRAY( "0x%04x", 0, @row_array[4096..$#row_array] );
1917 ################################################################
1918 # dump a binary case mapping table in l_intl.nls format
1919 sub dump_binary_case_table(@)
1921 my (@table) = @_;
1923 my %difftables_hash = ();
1924 my @difftables;
1925 my %offtables2_hash = ();
1926 my @offtables2 = ();
1928 my @offtable = ();
1929 for (my $i = 0; $i < 256; $i++)
1931 my @offtable2 = ();
1932 for(my $j = 0; $j < 16; $j++) # offset table for xx00-xxFF characters
1934 my @difftable;
1935 for (my $k = 0; $k < 16; $k++) # case map table for xxx0-xxxF characters
1937 my $char = ($i<<8) + ($j<<4) + $k;
1938 $difftable[$k] = (defined $table[$char]) ? (($table[$char]-$char) & 0xffff) : 0;
1941 my $diff_key = pack "S*", @difftable;
1942 my $offset3 = $difftables_hash{$diff_key};
1943 if (!defined $offset3)
1945 $offset3 = scalar @difftables;
1946 $difftables_hash{$diff_key} = $offset3;
1947 push @difftables, @difftable;
1949 $offtable2[$j] = $offset3;
1952 my $offtable2_key = pack "S*", @offtable2;
1953 my $offset2 = $offtables2_hash{$offtable2_key};
1954 if (!defined $offset2)
1956 $offset2 = scalar @offtables2;
1957 $offtables2_hash{$offtable2_key} = $offset2;
1958 push @offtables2, \@offtable2;
1960 $offtable[$i] = $offset2;
1963 my @output;
1964 my $offset = 0x100; # offset of first subtable in words
1965 foreach (@offtable)
1967 push @output, 0x10 * $_ + $offset; # offset of subtable in words
1970 $offset = 0x100 + 0x10 * scalar @offtables2; # offset of first difftable in words
1971 foreach(@offtables2)
1973 my $table = $_;
1974 foreach(@$table)
1976 push @output, $_ + $offset; # offset of difftable in words
1980 my $len = 1 + scalar @output + scalar @difftables;
1981 return pack "S<*", $len, @output, @difftables;
1985 ################################################################
1986 # dump case mappings for l_intl.nls
1987 sub dump_intl_nls($)
1989 my $filename = shift;
1990 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1991 printf "Building $filename\n";
1993 binmode OUTPUT;
1994 print OUTPUT pack "S<", 1; # version
1995 print OUTPUT dump_binary_case_table( @toupper_table );
1996 print OUTPUT dump_binary_case_table( @tolower_table );
1997 close OUTPUT;
1998 save_file($filename);
2002 sub load_nameprep_range_table($$$)
2004 my ($INPUT, $val, $table_ref) = @_;
2006 while (<$INPUT>)
2008 if (/^\s*([0-9a-fA-F]+)-([0-9a-fA-F]+)/)
2010 my $last = hex $2;
2011 $last = 65535 if($last >= 65536);
2012 foreach my $i (hex $1 .. $last)
2014 $table_ref->[$i] |= $val;
2016 next;
2018 elsif (/^\s*([0-9a-fA-F]+)/)
2020 if (hex $1 < 65536)
2022 $table_ref->[hex $1] |= $val;
2024 next;
2027 return if (/End\sTable/);
2031 sub load_nameprep_map_table($$)
2033 my ($INPUT, $table_ref) = @_;
2035 while (<$INPUT>)
2037 if (/^\s*([0-9a-fA-F]+);\s;/)
2039 # special value for map to nothing
2040 $table_ref->[hex $1] = [0xffff, 0xffff, 0xffff];
2041 next;
2043 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+);/)
2045 $table_ref->[hex $1] = [hex $2, 0, 0];
2046 next;
2048 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+)\s([0-9a-fA-F]+);/)
2050 $table_ref->[hex $1] = [hex $2, hex $3, 0];
2051 next;
2053 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+)\s([0-9a-fA-F]+)\s([0-9a-fA-F]+);/)
2055 $table_ref->[hex $1] = [hex $2, hex $3, hex $4];
2056 next;
2059 return if (/End\sTable/);
2063 ################################################################
2064 # dump mapping table, prohibited characters set, unassigned
2065 # characters, bidirectional rules used by nameprep algorithm
2066 sub dump_nameprep($)
2068 my $filename = shift;
2069 my @mapping_table = ();
2070 my @flags_table;
2072 my $INPUT = open_data_file( $RFCS, $STRINGPREP );
2073 while (<$INPUT>)
2075 next unless /Start\sTable/;
2077 load_nameprep_range_table($INPUT, $nameprep_flags{"unassigned"}, \@flags_table) if (/A.1/);
2078 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.1.2/);
2079 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.2.2/);
2080 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.3/);
2081 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.4/);
2082 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.5/);
2083 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.6/);
2084 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.7/);
2085 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.8/);
2086 load_nameprep_range_table($INPUT, $nameprep_flags{"prohibited"}, \@flags_table) if (/C.9/);
2087 load_nameprep_range_table($INPUT, $nameprep_flags{"bidi_ral"}, \@flags_table) if (/D.1/);
2088 load_nameprep_range_table($INPUT, $nameprep_flags{"bidi_l"}, \@flags_table) if (/D.2/);
2090 load_nameprep_map_table($INPUT, \@mapping_table) if (/B.1/);
2091 load_nameprep_map_table($INPUT, \@mapping_table) if (/B.2/);
2093 close $INPUT;
2095 open OUTPUT,">$filename.new" or die "Cannot create $filename";
2096 print "Building $filename\n";
2097 print OUTPUT "/* Nameprep algorithm related data */\n";
2098 print OUTPUT "/* generated from $RFCS/$STRINGPREP */\n";
2099 print OUTPUT "/* DO NOT EDIT!! */\n\n";
2100 print OUTPUT "#include \"wine/unicode.h\"\n\n";
2102 dump_two_level_mapping( "nameprep_char_type", 0, @flags_table );
2104 ######### mapping table
2105 # first determine all the 16-char subsets that contain something
2106 my @filled = ();
2107 my $pos = 16*3; # for the null subset
2108 for (my $i = 0; $i < 65536; $i++)
2110 next unless defined $mapping_table[$i];
2111 $filled[$i >> 4] = $pos;
2112 $pos += 16*3;
2113 $i |= 15;
2115 my $total = $pos;
2117 # now count the 256-char subsets that contain something
2118 my @filled_idx = (256) x 256;
2119 $pos = 256 + 16;
2120 for (my $i = 0; $i < 4096; $i++)
2122 next unless $filled[$i];
2123 $filled_idx[$i >> 4] = $pos;
2124 $pos += 16;
2125 $i |= 15;
2127 my $null_offset = $pos;
2128 $total += $pos;
2130 # add the index offsets to the subsets positions
2131 for (my $i = 0; $i < 4096; $i++)
2133 next unless $filled[$i];
2134 $filled[$i] += $null_offset;
2137 # dump the main index
2138 printf OUTPUT "const unsigned short DECLSPEC_HIDDEN nameprep_mapping[%d] =\n", $total;
2139 printf OUTPUT "{\n /* index */\n";
2140 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @filled_idx );
2141 printf OUTPUT ",\n /* null sub-index */\n%s", DUMP_ARRAY( "0x%04x", 0, ($null_offset) x 16 );
2143 # dump the second-level indexes
2144 for (my $i = 0; $i < 256; $i++)
2146 next unless ($filled_idx[$i] > 256);
2147 my @table = @filled[($i<<4)..($i<<4)+15];
2148 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
2149 printf OUTPUT ",\n /* sub-index %02x */\n", $i;
2150 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
2153 # dump the 16-char subsets
2154 printf OUTPUT ",\n /* null mapping */\n";
2155 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, (0) x 48 );
2157 for (my $i = 0; $i < 4096; $i++)
2159 next unless $filled[$i];
2160 my @table = (0) x 48;
2161 for (my $j = 0; $j < 16; $j++)
2163 if (defined $mapping_table[($i<<4) + $j])
2165 $table[3 * $j] = ${$mapping_table[($i << 4) + $j]}[0];
2166 $table[3 * $j + 1] = ${$mapping_table[($i << 4) + $j]}[1];
2167 $table[3 * $j + 2] = ${$mapping_table[($i << 4) + $j]}[2];
2170 printf OUTPUT ",\n /* 0x%03x0 .. 0x%03xf */\n", $i, $i;
2171 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
2174 printf OUTPUT "\n};\n";
2176 close OUTPUT;
2177 save_file($filename);
2180 ################################################################
2181 # dump the ctype tables
2182 sub DUMP_CTYPE_TABLES($)
2184 my $filename = shift;
2185 open OUTPUT,">$filename.new" or die "Cannot create $filename";
2186 printf "Building $filename\n";
2187 printf OUTPUT "/* Unicode ctype tables */\n";
2188 printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
2189 printf OUTPUT "#include \"wine/unicode.h\"\n\n";
2191 # add the direction in the high 4 bits of the category
2192 for (my $i = 0; $i < 65536; $i++)
2194 $category_table[$i] |= $direction_table[$i] << 12 if defined $direction_table[$i];
2197 dump_simple_mapping( "wine_wctype_table", 0, @category_table );
2199 close OUTPUT;
2200 save_file($filename);
2204 ################################################################
2205 # dump the char composition table
2206 sub dump_compose_table($)
2208 my $filename = shift;
2210 open OUTPUT,">$filename.new" or die "Cannot create $filename";
2211 print "Building $filename\n";
2212 print OUTPUT "/* Unicode char composition */\n";
2213 print OUTPUT "/* generated from $UNIDATA/UnicodeData.txt */\n";
2214 print OUTPUT "/* DO NOT EDIT!! */\n\n";
2215 print OUTPUT "#include \"wine/unicode.h\"\n\n";
2217 my @filled = ();
2218 foreach my $i (@compose_table)
2220 my @comp = @$i;
2221 push @{$filled[$comp[1]]}, [ $comp[0], $comp[2] ];
2224 # count how many different second chars we have
2226 my $count = 0;
2227 for (my $i = 0; $i < 65536; $i++)
2229 next unless defined $filled[$i];
2230 $count++;
2233 # build the table of second chars and offsets
2235 my $pos = $count + 1;
2236 my @table = ();
2237 for (my $i = 0; $i < 65536; $i++)
2239 next unless defined $filled[$i];
2240 push @table, $i, $pos;
2241 $pos += @{$filled[$i]};
2243 # terminator with last position
2244 push @table, 0, $pos;
2245 printf OUTPUT "static const WCHAR table[0x%x] =\n{\n", 2*$pos;
2246 printf OUTPUT " /* second chars + offsets */\n%s", DUMP_ARRAY( "0x%04x", 0, @table );
2248 # build the table of first chars and mappings
2250 for (my $i = 0; $i < 65536; $i++)
2252 next unless defined $filled[$i];
2253 my @table = ();
2254 my @list = sort { $a->[0] <=> $b->[0] } @{$filled[$i]};
2255 for (my $j = 0; $j <= $#list; $j++)
2257 push @table, $list[$j][0], $list[$j][1];
2259 printf OUTPUT ",\n /* 0x%04x */\n%s", $i, DUMP_ARRAY( "0x%04x", 0, @table );
2261 print OUTPUT "\n};\n\n";
2262 print OUTPUT <<"EOF";
2263 static inline int binary_search( WCHAR ch, int low, int high )
2265 while (low <= high)
2267 int pos = (low + high) / 2;
2268 if (table[2 * pos] < ch) low = pos + 1;
2269 else if (table[2 * pos] > ch) high = pos - 1;
2270 else return pos;
2272 return -1;
2275 WCHAR DECLSPEC_HIDDEN wine_compose( const WCHAR *str )
2277 int pos, idx = 1, start = 0, count = $count;
2278 for (;;)
2280 if ((pos = binary_search( str[idx], start, count - 1 )) == -1) return 0;
2281 if (!idx--) return table[2 * pos + 1];
2282 start = table[2 * pos + 1];
2283 count = table[2 * pos + 3];
2287 close OUTPUT;
2288 save_file($filename);
2291 sub dump_full_compat_table()
2293 # first determine all the 16-char subsets that contain something
2295 my @filled = (0) x 4096;
2296 my $pos = 16; # for the null subset
2297 my $data_total = 0;
2298 for (my $i = 0; $i < 65536; $i++)
2300 next unless defined $full_compatmap_table[$i];
2301 if ($filled[$i >> 4] == 0)
2303 $filled[$i >> 4] = $pos;
2304 $pos += 16;
2306 $data_total += $#{$full_compatmap_table[$i]} + 1;
2308 my $total = $pos;
2310 # now count the 256-char subsets that contain something
2312 my @filled_idx = (256) x 256;
2313 $pos = 256 + 16;
2314 for (my $i = 0; $i < 4096; $i++)
2316 next unless $filled[$i];
2317 $filled_idx[$i >> 4] = $pos;
2318 $pos += 16;
2319 $i |= 15;
2321 my $null_offset = $pos; # null mapping
2322 $total += $pos + 1; # add the offset sentinel
2324 # add the index offsets to the subsets positions
2326 for (my $i = 0; $i < 4096; $i++)
2328 next unless $filled[$i];
2329 $filled[$i] += $null_offset;
2332 # dump the main index
2334 printf OUTPUT "static const WCHAR compatmap_table[%d] =\n", $total + $data_total;
2335 printf OUTPUT "{\n /* index */\n";
2336 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @filled_idx );
2337 printf OUTPUT ",\n /* null sub-index */\n%s", DUMP_ARRAY( "0x%04x", 0, ($null_offset) x 16 );
2339 # dump the second-level indexes
2341 for (my $i = 0; $i < 256; $i++)
2343 next unless ($filled_idx[$i] > 256);
2344 my @table = @filled[($i<<4)..($i<<4)+15];
2345 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
2346 printf OUTPUT ",\n /* sub-index %02x */\n", $i;
2347 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
2350 # dump the 16-char offsets
2352 printf OUTPUT ",\n /* null offsets */\n";
2353 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, ($total) x (16) );
2355 $pos = $total;
2357 my @data;
2358 for (my $i = 0; $i < 4096; $i++)
2360 next unless $filled[$i];
2361 my @table = (0) x (16);
2362 for (my $j = 0; $j < 16; $j++)
2364 $table[$j] = $pos;
2365 if (defined $full_compatmap_table[($i<<4) + $j])
2367 $pos += $#{$full_compatmap_table[($i<<4) + $j]} + 1;
2368 push @data, @{$full_compatmap_table[($i<<4) + $j]};
2371 printf OUTPUT ",\n /* offsets 0x%03x0 .. 0x%03xf */\n", $i, $i;
2372 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
2375 my @sentinel = $pos;
2376 printf OUTPUT ",\n /* offset sentinel */\n";
2377 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @sentinel );
2379 printf OUTPUT ",\n /* data */\n";
2380 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @data );
2382 printf OUTPUT "\n};\n\n";
2385 ################################################################
2386 # dump the char decomposition table
2387 sub dump_decompose_table($)
2389 my $filename = shift;
2391 open OUTPUT,">$filename.new" or die "Cannot create $filename";
2392 print "Building $filename\n";
2393 print OUTPUT "/* Unicode char composition */\n";
2394 print OUTPUT "/* generated from $UNIDATA/UnicodeData.txt */\n";
2395 print OUTPUT "/* DO NOT EDIT!! */\n\n";
2396 print OUTPUT "#include \"wine/unicode.h\"\n\n";
2398 # first determine all the 16-char subsets that contain something
2400 my @filled = (0) x 4096;
2401 my $pos = 16*2; # for the null subset
2402 for (my $i = 0; $i < 65536; $i++)
2404 next unless defined $decomp_table[$i];
2405 $filled[$i >> 4] = $pos;
2406 $pos += 16*2;
2407 $i |= 15;
2409 my $total = $pos;
2411 # now count the 256-char subsets that contain something
2413 my @filled_idx = (256) x 256;
2414 $pos = 256 + 16;
2415 for (my $i = 0; $i < 4096; $i++)
2417 next unless $filled[$i];
2418 $filled_idx[$i >> 4] = $pos;
2419 $pos += 16;
2420 $i |= 15;
2422 my $null_offset = $pos; # null mapping
2423 $total += $pos;
2425 # add the index offsets to the subsets positions
2427 for (my $i = 0; $i < 4096; $i++)
2429 next unless $filled[$i];
2430 $filled[$i] += $null_offset;
2433 # dump the main index
2435 printf OUTPUT "static const WCHAR table[%d] =\n", $total;
2436 printf OUTPUT "{\n /* index */\n";
2437 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @filled_idx );
2438 printf OUTPUT ",\n /* null sub-index */\n%s", DUMP_ARRAY( "0x%04x", 0, ($null_offset) x 16 );
2440 # dump the second-level indexes
2442 for (my $i = 0; $i < 256; $i++)
2444 next unless ($filled_idx[$i] > 256);
2445 my @table = @filled[($i<<4)..($i<<4)+15];
2446 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
2447 printf OUTPUT ",\n /* sub-index %02x */\n", $i;
2448 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
2451 # dump the 16-char subsets
2453 printf OUTPUT ",\n /* null mapping */\n";
2454 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, (0) x 32 );
2456 for (my $i = 0; $i < 4096; $i++)
2458 next unless $filled[$i];
2459 my @table = (0) x 32;
2460 for (my $j = 0; $j < 16; $j++)
2462 if (defined $decomp_table[($i<<4) + $j])
2464 $table[2 * $j] = ${$decomp_table[($i << 4) + $j]}[0];
2465 $table[2 * $j + 1] = ${$decomp_table[($i << 4) + $j]}[1];
2468 printf OUTPUT ",\n /* 0x%03x0 .. 0x%03xf */\n", $i, $i;
2469 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
2472 printf OUTPUT "\n};\n\n";
2474 dump_full_compat_table();
2476 print OUTPUT <<"EOF";
2477 static const WCHAR *get_compatmap_entry( WCHAR ch, unsigned int *len )
2479 unsigned short offset_offs = compatmap_table[compatmap_table[ch >> 8] + ((ch >> 4) & 0xf)] + (ch & 0xf);
2480 unsigned short start = compatmap_table[offset_offs];
2481 unsigned short end = compatmap_table[offset_offs + 1];
2483 if (end > start)
2485 *len = end - start;
2486 return compatmap_table + start;
2489 return NULL;
2492 unsigned int DECLSPEC_HIDDEN wine_decompose( int flags, WCHAR ch, WCHAR *dst, unsigned int dstlen )
2494 const WCHAR *ptr = NULL;
2495 unsigned int res, len, dst_pos = 0;
2497 *dst = ch;
2499 if (flags & WINE_DECOMPOSE_COMPAT)
2500 ptr = get_compatmap_entry( ch, &len );
2502 if (!ptr)
2504 ptr = table + table[table[ch >> 8] + ((ch >> 4) & 0x0f)] + 2 * (ch & 0xf);
2505 len = ptr[1] ? 2 : 1;
2508 if (!*ptr) return 1;
2509 if (dstlen < len) return 0;
2510 /* apply the decomposition recursively */
2511 while (len--)
2513 if (!(res = wine_decompose( flags, *ptr++, dst + dst_pos, dstlen - dst_pos - len ))) return 0;
2514 dst_pos += res;
2517 return dst_pos;
2520 close OUTPUT;
2521 save_file($filename);
2524 ################################################################
2525 # dump the combining class table
2526 sub dump_combining_class($)
2528 my $filename = shift;
2530 open OUTPUT,">$filename.new" or die "Cannot create $filename";
2531 print "Building $filename\n";
2532 print OUTPUT "/* Unicode Combining Classes */\n";
2533 print OUTPUT "/* generated from $UNIDATA/UnicodeData.txt */\n";
2534 print OUTPUT "/* DO NOT EDIT!! */\n\n";
2535 print OUTPUT "#include \"wine/unicode.h\"\n\n";
2537 dump_two_level_mapping( "combining_class_table", 0, @combining_class_table );
2538 close OUTPUT;
2539 save_file($filename);
2542 ################################################################
2543 # output a codepage definition file from the global tables
2544 sub output_codepage_file($$$$)
2546 my ($codepage, $filename, $comment, $has_glyphs) = @_;
2548 my $output = sprintf "libs/port/c_%03d.c", $codepage;
2549 open OUTPUT,">$output.new" or die "Cannot create $output";
2551 printf "Building %s from %s (%s)\n", $output, $filename || "hardcoded data", $comment;
2553 # dump all tables
2555 printf OUTPUT "/* code page %03d (%s) */\n", $codepage, $comment;
2556 if ($filename)
2558 print OUTPUT "/* generated from $MAPPINGS/$filename */\n";
2559 print OUTPUT "/* DO NOT EDIT!! */\n\n";
2561 else
2563 printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
2565 printf OUTPUT "#include \"wine/unicode.h\"\n\n";
2567 if (!@lead_bytes) { dump_sbcs_table( $codepage, $has_glyphs, $comment, $default_char, $default_wchar ); }
2568 else { dump_dbcs_table( $codepage, $comment, $default_char, $default_wchar, get_lb_ranges() ); }
2569 close OUTPUT;
2570 save_file($output);
2573 ################################################################
2574 # read a "bestfit" Windows mapping file
2575 sub read_bestfit_file($)
2577 my ($filename) = @_;
2578 my $state = "";
2579 my ($codepage, $width, $count);
2580 my ($lb_cur, $lb_end);
2582 my $INPUT = open_data_file( $MAPPINGS, $filename ) or die "Cannot open $filename";
2584 while (<$INPUT>)
2586 next if /^;/; # skip comments
2587 next if /^\s*$/; # skip empty lines
2588 next if /\x1a/; # skip ^Z
2589 last if /^ENDCODEPAGE/;
2591 if (/^CODEPAGE\s+(\d+)/)
2593 $codepage = $1;
2594 next;
2596 if (/^CPINFO\s+(\d+)\s+0x([0-9a-fA-f]+)\s+0x([0-9a-fA-F]+)/)
2598 $width = $1;
2599 $default_char = hex $2;
2600 $default_wchar = hex $3;
2601 next;
2603 if (/^(MBTABLE|WCTABLE|DBCSRANGE|DBCSTABLE)\s+(\d+)/)
2605 $state = $1;
2606 $count = $2;
2607 next;
2609 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)/)
2611 if ($state eq "MBTABLE")
2613 my $cp = hex $1;
2614 my $uni = hex $2;
2615 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
2616 next;
2618 if ($state eq "WCTABLE")
2620 my $uni = hex $1;
2621 my $cp = hex $2;
2622 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
2623 next;
2625 if ($state eq "DBCSRANGE")
2627 my $start = hex $1;
2628 my $end = hex $2;
2629 for (my $i = $start; $i <= $end; $i++) { add_lead_byte( $i ); }
2630 $lb_cur = $start;
2631 $lb_end = $end;
2632 next;
2634 if ($state eq "DBCSTABLE")
2636 my $mb = hex $1;
2637 my $uni = hex $2;
2638 my $cp = ($lb_cur << 8) | $mb;
2639 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
2640 if (!--$count)
2642 if (++$lb_cur > $lb_end) { $state = "DBCSRANGE"; }
2644 next;
2647 die "$filename: Unrecognized line $_\n";
2649 close $INPUT;
2653 ################################################################
2654 # read an input file and generate the corresponding .c file
2655 sub HANDLE_FILE(@)
2657 my ($codepage,$filename,$has_glyphs,$comment,$first_private,$def,$defw) = @_;
2659 @cp2uni = ();
2660 @lead_bytes = ();
2661 @uni2cp = ();
2662 $default_char = $def || $DEF_CHAR;
2663 $default_wchar = $defw || $DEF_CHAR;
2665 # some codepage files are special
2666 if ($codepage == 20932)
2668 READ_JIS0208_FILE( $filename );
2669 add_default_mappings( $first_private );
2671 elsif ($codepage == 20127)
2673 fill_20127_codepage();
2674 add_default_mappings( $first_private );
2676 elsif ($filename =~ /\/bestfit/)
2678 read_bestfit_file( $filename );
2680 else
2682 read_codepage_file( $filename );
2683 if ($codepage == 10001)
2685 # add Shift-JIS mappings
2686 read_bestfit_file( "VENDORS/MICSFT/WindowsBestFit/bestfit932.txt" );
2688 else
2690 add_default_mappings( $first_private );
2694 output_codepage_file( $codepage, $filename, $comment, $has_glyphs );
2698 ################################################################
2699 # save a file if modified
2700 sub save_file($)
2702 my $file = shift;
2703 if (-f $file && !system "cmp $file $file.new >/dev/null")
2705 unlink "$file.new";
2707 else
2709 rename "$file.new", "$file";
2714 ################################################################
2715 # output the list of codepage tables into the cptable.c file
2716 sub output_cptable($)
2718 my $output = shift;
2719 my @tables_decl = ();
2721 printf "Building %s\n", $output;
2723 foreach my $file (@allfiles)
2725 my ($codepage,$filename) = @$file;
2726 push @tables_decl, sprintf("extern union cptable cptable_%03d;\n",$codepage);
2729 push @tables_decl, sprintf("\nstatic const union cptable * const cptables[%d] =\n{\n",$#allfiles+1);
2730 foreach my $file (@allfiles)
2732 my ($codepage,$filename) = @$file;
2733 push @tables_decl, sprintf(" &cptable_%03d,\n", $codepage);
2735 push @tables_decl, "};";
2736 REPLACE_IN_FILE( $output, @tables_decl );
2739 ################################################################
2740 # replace the contents of a file between ### cpmap ### marks
2742 sub REPLACE_IN_FILE($@)
2744 my $name = shift;
2745 my @data = @_;
2746 my @lines = ();
2747 open(FILE,$name) or die "Can't open $name";
2748 while (<FILE>)
2750 push @lines, $_;
2751 last if /\#\#\# cpmap begin \#\#\#/;
2753 push @lines, @data;
2754 while (<FILE>)
2756 if (/\#\#\# cpmap end \#\#\#/) { push @lines, "\n", $_; last; }
2758 push @lines, <FILE>;
2759 open(FILE,">$name.new") or die "Can't modify $name";
2760 print FILE @lines;
2761 close(FILE);
2762 save_file($name);
2765 ################################################################
2766 # main routine
2768 chdir ".." if -f "./make_unicode";
2769 READ_DEFAULTS( $DEFAULTS );
2770 DUMP_CASE_MAPPINGS( "libs/wine/casemap.c" );
2771 DUMP_SORTKEYS( "libs/wine/collation.c", READ_SORTKEYS_FILE() );
2772 dump_compose_table( "libs/port/compose.c" );
2773 dump_decompose_table( "libs/port/decompose.c" );
2774 DUMP_CTYPE_TABLES( "libs/wine/wctype.c" );
2775 dump_digit_folding( "libs/port/digitmap.c" );
2776 dump_combining_class( "libs/port/combclass.c" );
2777 dump_mirroring( "dlls/usp10/mirror.c" );
2778 dump_mirroring( "dlls/dwrite/mirror.c" );
2779 dump_bracket( "dlls/usp10/bracket.c" );
2780 dump_bracket( "dlls/dwrite/bracket.c" );
2781 dump_shaping( "dlls/usp10/shaping.c" );
2782 dump_linebreak( "dlls/usp10/linebreak.c" );
2783 dump_linebreak( "dlls/dwrite/linebreak.c" );
2784 dump_scripts( "dlls/dwrite/scripts" );
2785 dump_indic( "dlls/usp10/indicsyllable.c" );
2786 dump_intl_nls("loader/l_intl.nls");
2787 dump_vertical( "dlls/gdi32/vertical.c" );
2788 dump_vertical( "dlls/wineps.drv/vertical.c" );
2789 dump_nameprep( "dlls/kernel32/nameprep.c" );
2791 foreach my $file (@allfiles) { HANDLE_FILE( @{$file} ); }
2793 output_cptable("libs/port/cptable.c");
2795 exit 0;
2797 # Local Variables:
2798 # compile-command: "./make_unicode"
2799 # End: