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
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/9.0.0/ucd";
27 my $REPORTS = "http://www.unicode.org/reports";
28 my $RFCS = "http://www.rfc-editor.org/rfc";
29 my $VERTICALDATA = "http://www.unicode.org/Public/vertical/revision-15";
32 my $SORTKEYS = "tr10/allkeys.txt";
34 # RFC3454 (stringprep data)
35 my $STRINGPREP = "rfc3454.txt";
38 my $DEFAULTS = "tools/unicode-defaults";
40 # Default char for undefined mappings
41 my $DEF_CHAR = ord '?';
45 [ 37, "VENDORS/MICSFT/EBCDIC/CP037.TXT", 0, "IBM EBCDIC US Canada", 0, 0x6f ],
46 [ 424, "VENDORS/MISC/CP424.TXT", 0, "IBM EBCDIC Hebrew" ],
47 [ 437, "VENDORS/MICSFT/PC/CP437.TXT", 1, "OEM United States" ],
48 [ 500, "VENDORS/MICSFT/EBCDIC/CP500.TXT", 0, "IBM EBCDIC International", 0, 0x6f ],
49 [ 737, "VENDORS/MICSFT/PC/CP737.TXT", 1, "OEM Greek 437G" ],
50 [ 775, "VENDORS/MICSFT/PC/CP775.TXT", 1, "OEM Baltic" ],
51 [ 850, "VENDORS/MICSFT/PC/CP850.TXT", 1, "OEM Multilingual Latin 1" ],
52 [ 852, "VENDORS/MICSFT/PC/CP852.TXT", 1, "OEM Slovak Latin 2" ],
53 [ 855, "VENDORS/MICSFT/PC/CP855.TXT", 1, "OEM Cyrillic" ],
54 [ 856, "VENDORS/MISC/CP856.TXT", 0, "Hebrew PC" ],
55 [ 857, "VENDORS/MICSFT/PC/CP857.TXT", 1, "OEM Turkish", 0xf8bb ],
56 [ 860, "VENDORS/MICSFT/PC/CP860.TXT", 1, "OEM Portuguese" ],
57 [ 861, "VENDORS/MICSFT/PC/CP861.TXT", 1, "OEM Icelandic" ],
58 [ 862, "VENDORS/MICSFT/PC/CP862.TXT", 1, "OEM Hebrew" ],
59 [ 863, "VENDORS/MICSFT/PC/CP863.TXT", 1, "OEM Canadian French" ],
60 [ 864, "VENDORS/MICSFT/PC/CP864.TXT", 0, "OEM Arabic", 0xf8bb ],
61 [ 865, "VENDORS/MICSFT/PC/CP865.TXT", 1, "OEM Nordic" ],
62 [ 866, "VENDORS/MICSFT/PC/CP866.TXT", 1, "OEM Russian" ],
63 [ 869, "VENDORS/MICSFT/PC/CP869.TXT", 1, "OEM Greek" ],
64 [ 874, "VENDORS/MICSFT/WindowsBestFit/bestfit874.txt", 1, "ANSI/OEM Thai" ],
65 [ 875, "VENDORS/MICSFT/EBCDIC/CP875.TXT", 0, "IBM EBCDIC Greek", 0, 0x6f ],
66 [ 878, "VENDORS/MISC/KOI8-R.TXT", 0, "Russian KOI8" ],
67 [ 932, "VENDORS/MICSFT/WindowsBestFit/bestfit932.txt", 0, "ANSI/OEM Japanese Shift-JIS" ],
68 [ 936, "VENDORS/MICSFT/WindowsBestFit/bestfit936.txt", 0, "ANSI/OEM Simplified Chinese GBK" ],
69 [ 949, "VENDORS/MICSFT/WindowsBestFit/bestfit949.txt", 0, "ANSI/OEM Korean Unified Hangul" ],
70 [ 950, "VENDORS/MICSFT/WindowsBestFit/bestfit950.txt", 0, "ANSI/OEM Traditional Chinese Big5" ],
71 [ 1006, "VENDORS/MISC/CP1006.TXT", 0, "IBM Arabic" ],
72 [ 1026, "VENDORS/MICSFT/EBCDIC/CP1026.TXT", 0, "IBM EBCDIC Latin 5 Turkish", 0, 0x6f ],
73 [ 1250, "VENDORS/MICSFT/WindowsBestFit/bestfit1250.txt", 0, "ANSI Eastern Europe" ],
74 [ 1251, "VENDORS/MICSFT/WindowsBestFit/bestfit1251.txt", 0, "ANSI Cyrillic" ],
75 [ 1252, "VENDORS/MICSFT/WindowsBestFit/bestfit1252.txt", 0, "ANSI Latin 1" ],
76 [ 1253, "VENDORS/MICSFT/WindowsBestFit/bestfit1253.txt", 0, "ANSI Greek" ],
77 [ 1254, "VENDORS/MICSFT/WindowsBestFit/bestfit1254.txt", 0, "ANSI Turkish" ],
78 [ 1255, "VENDORS/MICSFT/WindowsBestFit/bestfit1255.txt", 0, "ANSI Hebrew" ],
79 [ 1256, "VENDORS/MICSFT/WindowsBestFit/bestfit1256.txt", 0, "ANSI Arabic" ],
80 [ 1257, "VENDORS/MICSFT/WindowsBestFit/bestfit1257.txt", 0, "ANSI Baltic" ],
81 [ 1258, "VENDORS/MICSFT/WindowsBestFit/bestfit1258.txt", 0, "ANSI/OEM Viet Nam" ],
82 [ 1361, "VENDORS/MICSFT/WindowsBestFit/bestfit1361.txt", 0, "Korean Johab" ],
83 [ 10000, "VENDORS/MICSFT/MAC/ROMAN.TXT", 0, "Mac Roman" ],
84 [ 10001, "VENDORS/APPLE/JAPANESE.TXT", 0, "Mac Japanese" ],
85 [ 10002, "VENDORS/APPLE/CHINTRAD.TXT", 0, "Mac Traditional Chinese" ],
86 [ 10003, "VENDORS/APPLE/KOREAN.TXT", 0, "Mac Korean", 0xf8e5 ],
87 [ 10004, "VENDORS/APPLE/ARABIC.TXT", 0, "Mac Arabic", 0xf826 ],
88 [ 10005, "VENDORS/APPLE/HEBREW.TXT", 0, "Mac Hebrew", 0xf7fa ],
89 [ 10006, "VENDORS/MICSFT/MAC/GREEK.TXT", 0, "Mac Greek" ],
90 [ 10007, "VENDORS/MICSFT/MAC/CYRILLIC.TXT", 0, "Mac Cyrillic" ],
91 [ 10008, "VENDORS/APPLE/CHINSIMP.TXT", 0, "Mac Simplified Chinese" ],
92 [ 10010, "VENDORS/APPLE/ROMANIAN.TXT", 0, "Mac Romanian" ],
93 [ 10017, "VENDORS/APPLE/CYRILLIC.TXT", 0, "Mac Ukrainian" ],
94 [ 10021, "VENDORS/APPLE/THAI.TXT", 0, "Mac Thai" ],
95 [ 10029, "VENDORS/MICSFT/MAC/LATIN2.TXT", 0, "Mac Latin 2" ],
96 [ 10079, "VENDORS/MICSFT/MAC/ICELAND.TXT", 0, "Mac Icelandic" ],
97 [ 10081, "VENDORS/MICSFT/MAC/TURKISH.TXT", 0, "Mac Turkish", 0xf89f ],
98 [ 10082, "VENDORS/APPLE/CROATIAN.TXT", 0, "Mac Croatian" ],
99 [ 20127, undef, 0, "US-ASCII (7bit)" ],
100 [ 20866, "VENDORS/MISC/KOI8-R.TXT", 0, "Russian KOI8" ],
101 [ 20932, "OBSOLETE/EASTASIA/JIS/JIS0208.TXT", 0, "EUC-JP", 0, 0x3f, 0x30fb ],
102 [ 21866, "VENDORS/MISC/KOI8-U.TXT", 0, "Ukrainian KOI8" ],
103 [ 28591, "ISO8859/8859-1.TXT", 0, "ISO 8859-1 Latin 1" ],
104 [ 28592, "ISO8859/8859-2.TXT", 0, "ISO 8859-2 Latin 2 (East European)" ],
105 [ 28593, "ISO8859/8859-3.TXT", 0, "ISO 8859-3 Latin 3 (South European)", 0xf7f5 ],
106 [ 28594, "ISO8859/8859-4.TXT", 0, "ISO 8859-4 Latin 4 (Baltic old)" ],
107 [ 28595, "ISO8859/8859-5.TXT", 0, "ISO 8859-5 Cyrillic" ],
108 [ 28596, "ISO8859/8859-6.TXT", 0, "ISO 8859-6 Arabic", 0xf7c8 ],
109 [ 28597, "ISO8859/8859-7.TXT", 0, "ISO 8859-7 Greek", 0xf7c5 ],
110 [ 28598, "ISO8859/8859-8.TXT", 0, "ISO 8859-8 Hebrew", 0xf79c ],
111 [ 28599, "ISO8859/8859-9.TXT", 0, "ISO 8859-9 Latin 5 (Turkish)" ],
112 [ 28600, "ISO8859/8859-10.TXT", 0, "ISO 8859-10 Latin 6 (Nordic)" ],
113 [ 28603, "ISO8859/8859-13.TXT", 0, "ISO 8859-13 Latin 7 (Baltic)" ],
114 [ 28604, "ISO8859/8859-14.TXT", 0, "ISO 8859-14 Latin 8 (Celtic)" ],
115 [ 28605, "ISO8859/8859-15.TXT", 0, "ISO 8859-15 Latin 9 (Euro)" ],
116 [ 28606, "ISO8859/8859-16.TXT", 0, "ISO 8859-16 Latin 10 (Balkan)" ]
145 "Avagraha" => 0x0003,
148 "Vowel_Independent" => 0x0006,
149 "Vowel_Dependent" => 0x0007,
151 "Consonant_Placeholder" => 0x0009,
152 "Consonant" => 0x000a,
153 "Consonant_Dead" => 0x000b,
154 "Consonant_Succeeding_Repha" => 0x000c,
155 "Consonant_Subjoined" => 0x000d,
156 "Consonant_Medial" => 0x000e,
157 "Consonant_Final" => 0x000f,
158 "Consonant_Head_Letter" => 0x0010,
159 "Modifying_Letter" => 0x0011,
160 "Tone_Letter" => 0x0012,
161 "Tone_Mark" => 0x0013,
162 "Register_Shifter" => 0x0014,
163 "Consonant_Preceding_Repha" => 0x0015,
164 "Pure_Killer" => 0x0016,
165 "Invisible_Stacker" => 0x0017,
166 "Gemination_Mark" => 0x0018,
167 "Cantillation_Mark" => 0x0019,
168 "Non_Joiner" => 0x001a,
170 "Number_Joiner" => 0x001c,
172 "Brahmi_Joining_Number" => 0x001e,
173 "Consonant_With_Stacker" => 0x001f,
174 "Consonant_Prefixed" => 0x0020,
175 "Syllable_Modifier" => 0x0021,
176 "Consonant_Killer" => 0x0022
183 "Visual_Order_Left" => 0x03,
184 "Left_And_Right" => 0x04,
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,
199 "unassigned" => 0x01,
200 "prohibited" => 0x02,
262 "Lu" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"upper"}, # Letter, Uppercase
263 "Ll" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"lower"}, # Letter, Lowercase
264 "Lt" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"upper"}|$ctype{"lower"}, # Letter, Titlecase
265 "Mn" => $ctype{"defin"}, # Mark, Non-Spacing
266 "Mc" => $ctype{"defin"}, # Mark, Spacing Combining
267 "Me" => $ctype{"defin"}, # Mark, Enclosing
268 "Nd" => $ctype{"defin"}|$ctype{"digit"}, # Number, Decimal Digit
269 "Nl" => $ctype{"defin"}|$ctype{"alpha"}, # Number, Letter
270 "No" => $ctype{"defin"}, # Number, Other
271 "Zs" => $ctype{"defin"}|$ctype{"space"}, # Separator, Space
272 "Zl" => $ctype{"defin"}|$ctype{"space"}, # Separator, Line
273 "Zp" => $ctype{"defin"}|$ctype{"space"}, # Separator, Paragraph
274 "Cc" => $ctype{"defin"}|$ctype{"cntrl"}, # Other, Control
275 "Cf" => $ctype{"defin"}|$ctype{"cntrl"}, # Other, Format
276 "Cs" => $ctype{"defin"}, # Other, Surrogate
277 "Co" => $ctype{"defin"}, # Other, Private Use
278 "Cn" => $ctype{"defin"}, # Other, Not Assigned
279 "Lm" => $ctype{"defin"}|$ctype{"alpha"}, # Letter, Modifier
280 "Lo" => $ctype{"defin"}|$ctype{"alpha"}, # Letter, Other
281 "Pc" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Connector
282 "Pd" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Dash
283 "Ps" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Open
284 "Pe" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Close
285 "Pi" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Initial quote
286 "Pf" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Final quote
287 "Po" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Other
288 "Sm" => $ctype{"defin"}, # Symbol, Math
289 "Sc" => $ctype{"defin"}, # Symbol, Currency
290 "Sk" => $ctype{"defin"}, # Symbol, Modifier
291 "So" => $ctype{"defin"} # Symbol, Other
294 # a few characters need additional categories that cannot be determined automatically
295 my %special_categories =
297 "xdigit" => [ ord('0')..ord('9'),ord('A')..ord('F'),ord('a')..ord('f'),
298 0xff10..0xff19
, 0xff21..0xff26
, 0xff41..0xff46
],
299 "space" => [ 0x09..0x0d
, 0x85 ],
300 "blank" => [ 0x09, 0x20, 0xa0, 0x3000, 0xfeff ],
301 "cntrl" => [ 0x070f, 0x200c, 0x200d,
302 0x200e, 0x200f, 0x202a, 0x202b, 0x202c, 0x202d, 0x202e,
303 0x206a, 0x206b, 0x206c, 0x206d, 0x206e, 0x206f, 0xfeff,
304 0xfff9, 0xfffa, 0xfffb ],
305 "punct" => [ 0x24, 0x2b, 0x3c..0x3e
, 0x5e, 0x60, 0x7c, 0x7e, 0xa2..0xbe
,
307 "digit" => [ 0xb2, 0xb3, 0xb9 ],
308 "lower" => [ 0x2071, 0x207f ]
313 "L" => 1, # Left-to-Right
314 "R" => 2, # Right-to-Left
315 "AL" => 12, # Right-to-Left Arabic
316 "EN" => 3, # European Number
317 "ES" => 4, # European Number Separator
318 "ET" => 5, # European Number Terminator
319 "AN" => 6, # Arabic Number
320 "CS" => 7, # Common Number Separator
321 "NSM" => 13, # Non-Spacing Mark
322 "BN" => 14, # Boundary Neutral
323 "B" => 8, # Paragraph Separator
324 "S" => 9, # Segment Separator
325 "WS" => 10, # Whitespace
326 "ON" => 11, # Other Neutrals
327 "LRE" => 15, # Left-to-Right Embedding
328 "LRO" => 15, # Left-to-Right Override
329 "RLE" => 15, # Right-to-Left Embedding
330 "RLO" => 15, # Right-to-Left Override
331 "PDF" => 15, # Pop Directional Format
332 "LRI" => 15, # Left-to-Right Isolate
333 "RLI" => 15, # Right-to-Left Isolate
334 "FSI" => 15, # First Strong Isolate
335 "PDI" => 15 # Pop Directional Isolate
340 "U" => 0, # Non_Joining
341 "T" => 1, # Transparent
342 "R" => 2, # Right_Joining
343 "L" => 3, # Left_Joining
344 "D" => 4, # Dual_Joining
345 "C" => 5, # Join_Causing
351 my @unicode_defaults = ();
352 my @unicode_aliases = ();
353 my @tolower_table = ();
354 my @toupper_table = ();
355 my @digitmap_table = ();
356 my @compatmap_table = ();
357 my @category_table = ();
358 my @joining_table = ();
359 my @direction_table = ();
360 my @decomp_table = ();
361 my @compose_table = ();
373 ################################################################
374 # fetch a unicode.org file and open it
375 sub open_data_file
($$)
377 my ($base, $name) = @_;
378 (my $dir = "data/$name") =~ s
/\
/[^\/]+$//;
380 unless (-f
"data/$name")
382 print "Fetching $base/$name...\n";
383 system "mkdir", "-p", $dir;
384 !system "wget", "-q", "-O", "data/$name", "$base/$name" or die "cannot fetch $base/$name";
386 open FILE
, "<data/$name" or die "cannot open data/$name";
390 ################################################################
391 # read in the defaults file
394 my $filename = shift;
397 # first setup a few default mappings
399 open DEFAULTS
, "$filename" or die "Cannot open $filename";
400 print "Loading $filename\n";
403 next if /^\#/; # skip comments
404 next if /^$/; # skip empty lines
405 if (/^(([0-9a-fA-F]+)(,[0-9a-fA-F]+)*)\s+([0-9a-fA-F]+|'.'|none)\s+(\#.*)?/)
407 my @src = map hex, split /,/,$1;
410 if ($#src > 0) { push @unicode_aliases, \
@src; }
411 next if ($dst eq "none");
412 $dst = ($dst =~ /\'.\'/) ?
ord substr($dst,1,1) : hex $dst;
413 foreach my $src (@src)
415 die "Duplicate value" if defined($unicode_defaults[$src]);
416 $unicode_defaults[$src] = $dst;
420 die "Unrecognized line $_\n";
424 # now build mappings from the decomposition field of the Unicode database
426 my $UNICODE_DATA = open_data_file
( $UNIDATA, "UnicodeData.txt" );
427 while (<$UNICODE_DATA>)
429 # Decode the fields ...
430 my ($code, $name, $cat, $comb, $bidi,
431 $decomp, $dec, $dig, $num, $mirror,
432 $oldname, $comment, $upper, $lower, $title) = split /;/;
436 die "unknown category $cat" unless defined $categories{$cat};
437 die "unknown directionality $bidi" unless defined $directions{$bidi};
439 $category_table[$src] = $categories{$cat};
440 $direction_table[$src] = $directions{$bidi};
441 $joining_table[$src] = $joining_types{"T"} if $cat eq "Mn" || $cat eq "Me" || $cat eq "Cf";
445 $tolower_table[$src] = hex $lower;
449 $toupper_table[$src] = hex $upper;
453 $category_table[$src] |= $ctype{"digit"};
457 $digitmap_table[$src] = ord $dig;
460 # copy the category and direction for everything between First/Last pairs
461 if ($name =~ /, First>/) { $start = $src; }
462 if ($name =~ /, Last>/)
464 while ($start < $src)
466 $category_table[$start] = $category_table[$src];
467 $direction_table[$start] = $direction_table[$src];
472 next if $decomp eq ""; # no decomposition, skip it
474 if ($decomp =~ /^<([a-zA-Z]+)>\s+([0-9a-fA-F]+)$/)
476 # decomposition of the form "<foo> 1234" -> use char if type is known
477 if (($src >= 0xf900 && $src < 0xfb00) || ($src >= 0xfe30 && $src < 0xfffd))
479 # Single char decomposition in the compatibility range
480 $compatmap_table[$src] = hex $2;
482 if ($1 eq "isolated" || $1 eq "final" || $1 eq "initial" || $1 eq "medial")
484 ${joining_forms
{$1}}[hex $2] = $src;
487 next unless ($1 eq "font" ||
498 elsif ($decomp =~ /^<compat>\s+0020\s+([0-9a-fA-F]+)/)
500 # decomposition "<compat> 0020 1234" -> combining accent
503 elsif ($decomp =~ /^([0-9a-fA-F]+)/)
505 # decomposition contains only char values without prefix -> use first char
507 $category_table[$src] |= $category_table[$dst] if defined $category_table[$dst];
508 # store decomposition if it contains two chars
509 if ($decomp =~ /^([0-9a-fA-F]+)\s+([0-9a-fA-F]+)$/)
511 $decomp_table[$src] = [ hex $1, hex $2 ];
512 push @compose_table, [ hex $1, hex $2, $src ];
514 elsif ($decomp =~ /^(<[a-z]+>\s)*([0-9a-fA-F]+)$/ &&
515 (($src >= 0xf900 && $src < 0xfb00) || ($src >= 0xfe30 && $src < 0xfffd)))
517 # Single char decomposition in the compatibility range
518 $compatmap_table[$src] = hex $2;
526 next if defined($unicode_defaults[$src]); # may have been set in the defaults file
529 for (my $i = $dst; ; $i = $unicode_defaults[$i])
531 die sprintf("loop detected for %04x -> %04x",$src,$dst) if $i == $src;
532 last unless defined($unicode_defaults[$i]);
534 $unicode_defaults[$src] = $dst;
538 # patch the category of some special characters
540 foreach my $cat (keys %special_categories)
542 my $flag = $ctype{$cat};
543 foreach my $i (@
{$special_categories{$cat}}) { $category_table[$i] |= $flag; }
548 ################################################################
549 # define a new lead byte
553 push @lead_bytes, $ch;
557 ################################################################
558 # define a new char mapping
562 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
563 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
564 if ($cp > 0xff && !defined($cp2uni[$cp >> 8]))
566 add_lead_byte
( $cp >> 8 );
570 ################################################################
571 # parse a standard codepage file
572 sub read_codepage_file
($)
575 my $INPUT = open_data_file
( $MAPPINGS, $name );
579 next if /^\#/; # skip comments
580 next if /^$/; # skip empty lines
581 next if /\x1a/; # skip ^Z
582 next if (/^0x([0-9a-fA-F]+)\s+\#UNDEFINED/); # undefined char
584 if (/^0x([0-9a-fA-F]+)\s+\#DBCS LEAD BYTE/)
586 add_lead_byte
( hex $1 );
590 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
592 add_mapping
( hex $1, hex $2 );
596 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\+.*\s+(\#.*)?/)
598 add_mapping
( hex $1, hex $2 );
602 if (/^0x([0-9a-fA-F]+)\s+<LR>\+0x([0-9a-fA-F]+)\s+(\#.*)?/)
604 add_mapping
( hex $1, hex $2 );
608 if (/^0x([0-9a-fA-F]+)\s+<RL>\+0x([0-9a-fA-F]+)\s+(\#.*)?/)
611 add_mapping
( hex $1, $uni ) if $uni >= 0x80;
614 die "$name: Unrecognized line $_\n";
620 ################################################################
621 # fill input data for the 20127 (us-ascii) codepage
622 sub fill_20127_codepage
()
624 for (my $i = 0; $i < 128; $i++) { $cp2uni[$i] = $uni2cp[$i] = $i; }
625 for (my $i = 128; $i < 256; $i++) { $cp2uni[$i] = $i & 0x7f; }
628 ################################################################
629 # get a mapping including glyph chars for MB_USEGLYPHCHARS
631 sub get_glyphs_mapping
(@
)
633 $_[0x01] = 0x263a; # (WHITE SMILING FACE)
634 $_[0x02] = 0x263b; # (BLACK SMILING FACE)
635 $_[0x03] = 0x2665; # (BLACK HEART SUIT)
636 $_[0x04] = 0x2666; # (BLACK DIAMOND SUIT)
637 $_[0x05] = 0x2663; # (BLACK CLUB SUIT)
638 $_[0x06] = 0x2660; # (BLACK SPADE SUIT)
639 $_[0x07] = 0x2022; # (BULLET)
640 $_[0x08] = 0x25d8; # (INVERSE BULLET)
641 $_[0x09] = 0x25cb; # (WHITE CIRCLE)
642 $_[0x0a] = 0x25d9; # (INVERSE WHITE CIRCLE)
643 $_[0x0b] = 0x2642; # (MALE SIGN)
644 $_[0x0c] = 0x2640; # (FEMALE SIGN)
645 $_[0x0d] = 0x266a; # (EIGHTH NOTE)
646 $_[0x0e] = 0x266b; # (BEAMED EIGHTH NOTES)
647 $_[0x0f] = 0x263c; # (WHITE SUN WITH RAYS)
648 $_[0x10] = 0x25ba; # (BLACK RIGHT-POINTING POINTER)
649 $_[0x11] = 0x25c4; # (BLACK LEFT-POINTING POINTER)
650 $_[0x12] = 0x2195; # (UP DOWN ARROW)
651 $_[0x13] = 0x203c; # (DOUBLE EXCLAMATION MARK)
652 $_[0x14] = 0x00b6; # (PILCROW SIGN)
653 $_[0x15] = 0x00a7; # (SECTION SIGN)
654 $_[0x16] = 0x25ac; # (BLACK RECTANGLE)
655 $_[0x17] = 0x21a8; # (UP DOWN ARROW WITH BASE)
656 $_[0x18] = 0x2191; # (UPWARDS ARROW)
657 $_[0x19] = 0x2193; # (DOWNWARDS ARROW)
658 $_[0x1a] = 0x2192; # (RIGHTWARDS ARROW)
659 $_[0x1b] = 0x2190; # (LEFTWARDS ARROW)
660 $_[0x1c] = 0x221f; # (RIGHT ANGLE)
661 $_[0x1d] = 0x2194; # (LEFT RIGHT ARROW)
662 $_[0x1e] = 0x25b2; # (BLACK UP-POINTING TRIANGLE)
663 $_[0x1f] = 0x25bc; # (BLACK DOWN-POINTING TRIANGLE)
664 $_[0x7f] = 0x2302; # (HOUSE)
668 ################################################################
669 # build EUC-JP table from the JIS 0208 file
670 # FIXME: for proper EUC-JP we should probably read JIS 0212 too
671 # but this would require 3-byte DBCS characters
672 sub READ_JIS0208_FILE
($)
677 for (my $i = 0x00; $i <= 0x7f; $i++)
683 # JIS X 0201 right plane
684 for (my $i = 0xa1; $i <= 0xdf; $i++)
686 $cp2uni[0x8e00 + $i] = 0xfec0 + $i;
687 $uni2cp[0xfec0 + $i] = 0x8e00 + $i;
691 foreach my $i (0x8e, 0x8f, 0xa1 .. 0xfe)
697 foreach my $i (0x80 .. 0x8d, 0x90 .. 0xa0, 0xff)
699 $cp2uni[$i] = $DEF_CHAR;
702 # Shift-JIS compatibility
703 $uni2cp[0x00a5] = 0x5c;
704 $uni2cp[0x203e] = 0x7e;
706 # Fix backslash conversion
707 $cp2uni[0xa1c0] = 0xff3c;
708 $uni2cp[0xff3c] = 0xa1c0;
710 my $INPUT = open_data_file
( $MAPPINGS, $name );
713 next if /^\#/; # skip comments
714 next if /^$/; # skip empty lines
715 next if /\x1a/; # skip ^Z
716 if (/^0x[0-9a-fA-F]+\s+0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
718 my $cp = 0x8080 + hex $1;
720 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
721 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
724 die "$name: Unrecognized line $_\n";
730 ################################################################
731 # build the sort keys table
732 sub READ_SORTKEYS_FILE
()
735 for (my $i = 0; $i < 65536; $i++) { $sortkeys[$i] = [ -1, 0, 0, 0, 0 ] };
737 my $INPUT = open_data_file
( $REPORTS, $SORTKEYS );
740 next if /^\#/; # skip comments
741 next if /^$/; # skip empty lines
742 next if /\x1a/; # skip ^Z
743 next if /^\@version/; # skip @version header
744 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]+)\]/)
746 my ($uni,$variable) = (hex $1, $2);
747 next if $uni > 65535;
748 $sortkeys[$uni] = [ $uni, hex $3, hex $4, hex $5, hex $6 ];
751 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]+)\]/)
753 # multiple character sequence, ignored for now
756 die "$SORTKEYS: Unrecognized line $_\n";
760 # compress the keys to 32 bit:
761 # key 1 to 16 bits, key 2 to 8 bits, key 3 to 4 bits, key 4 to 1 bit
763 @sortkeys = sort { ${$a}[1] <=> ${$b}[1] or
764 ${$a}[2] <=> ${$b}[2] or
765 ${$a}[3] <=> ${$b}[3] or
766 ${$a}[4] <=> ${$b}[4] or
767 $a cmp $b; } @sortkeys;
769 my ($n2, $n3) = (1, 1);
770 my @keys = (-1, -1, -1, -1, -1 );
773 for (my $i = 0; $i < 65536; $i++)
775 my @current = @
{$sortkeys[$i]};
776 next if $current[0] == -1;
777 if ($current[1] == $keys[1])
779 if ($current[2] == $keys[2])
781 if ($current[3] == $keys[3])
787 $keys[3] = $current[3];
794 $keys[2] = $current[2];
795 $keys[3] = $current[3];
803 $keys[1] = $current[1];
804 $keys[2] = $current[2];
805 $keys[3] = $current[3];
810 if ($current[2]) { $current[2] = $n2; }
811 if ($current[3]) { $current[3] = $n3; }
812 if ($current[4]) { $current[4] = 1; }
814 $flatkeys[$current[0]] = ($current[1] << 16) | ($current[2] << 8) | ($current[3] << 4) | $current[4];
820 ################################################################
821 # build the sort keys table
822 sub DUMP_SORTKEYS
($@
)
824 my ($filename, @keys) = @_;
826 # count the number of 256-key ranges that contain something
830 for (my $i = 0; $i < 256; $i++) { $offsets[$i] = 256; }
831 for (my $i = 0; $i < 65536; $i++)
833 next unless defined $keys[$i];
834 $offsets[$i >> 8] = $ranges * 256;
839 # output the range offsets
841 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
842 printf "Building $filename\n";
843 printf OUTPUT
"/* Unicode collation element table */\n";
844 printf OUTPUT
"/* generated from %s */\n", "$REPORTS/$SORTKEYS";
845 printf OUTPUT
"/* DO NOT EDIT!! */\n\n";
847 printf OUTPUT
"const unsigned int collation_table[%d] =\n{\n", $ranges*256;
848 printf OUTPUT
" /* index */\n";
849 printf OUTPUT
"%s,\n", DUMP_ARRAY
( "0x%08x", 0, @offsets );
851 # output the default values
853 printf OUTPUT
" /* defaults */\n";
854 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%08x", 0, (0xffffffff) x
256 );
856 # output all the key ranges
858 for (my $i = 0; $i < 256; $i++)
860 next if $offsets[$i] == 256;
861 printf OUTPUT
",\n /* 0x%02x00 .. 0x%02xff */\n", $i, $i;
862 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%08x", 0xffffffff, @keys[($i<<8) .. ($i<<8)+255] );
864 printf OUTPUT
"\n};\n";
866 save_file
($filename);
870 ################################################################
871 # add default mappings once the file had been read
872 sub add_default_mappings
($)
874 my $first_private = shift;
878 foreach my $alias (@unicode_aliases)
881 foreach my $src (@
$alias)
883 if (defined($uni2cp[$src]))
885 $target = $uni2cp[$src];
889 next unless defined($target);
891 # At least one char of the alias set is defined, set the others to the same value
892 foreach my $src (@
$alias)
894 $uni2cp[$src] = $target unless defined($uni2cp[$src]);
898 # For every src -> target mapping in the defaults table,
899 # make uni2cp[src] = uni2cp[target] if uni2cp[target] is defined
901 for (my $src = 0; $src < 65536; $src++)
903 next if defined($uni2cp[$src]); # source has a definition already
904 next unless defined($unicode_defaults[$src]); # no default for this char
905 my $target = $unicode_defaults[$src];
907 # do a recursive mapping until we find a target char that is defined
908 while (!defined($uni2cp[$target]) &&
909 defined($unicode_defaults[$target])) { $target = $unicode_defaults[$target]; }
911 if (defined($uni2cp[$target])) { $uni2cp[$src] = $uni2cp[$target]; }
914 # Add a private char mapping for undefined chars
918 for (my $i = 32; $i < 256; $i++)
920 next if defined($cp2uni[$i]);
921 $cp2uni[$i] = $first_private;
922 $uni2cp[$first_private] = $i;
927 # Add an identity mapping for all undefined chars
929 for (my $i = 0; $i < 256; $i++)
931 next if defined($cp2uni[$i]);
932 next if defined($uni2cp[$i]);
933 $cp2uni[$i] = $uni2cp[$i] = $i;
937 ################################################################
938 # dump an array of integers
941 my ($format,$default,@array) = @_;
944 for ($i = 0; $i < $#array; $i++)
946 $ret .= sprintf($format, defined $array[$i] ?
$array[$i] : $default);
947 $ret .= (($i % 8) != 7) ?
", " : ",\n ";
949 $ret .= sprintf($format, defined $array[$i] ?
$array[$i] : $default);
954 ################################################################
955 # dump a unicode->ascii mapping table
956 sub dump_uni2cp_table
($$)
958 my ($width, $def) = @_;
960 # count the number of unicode->ascii subtables that contain something
965 my @filled = (-1) x
256;
966 for (my $i = 0; $i < 65536; $i++)
968 next unless defined $uni2cp[$i];
969 if ($filled[$i >> 8] == -1)
971 $lowerbounds[$index] = $i & 0xff;
972 $upperbounds[$index] = 0xff - $lowerbounds[$index];
973 $filled[$i >> 8] = $index * 256;
978 $upperbounds[$index-1] = 0xff - ($i & 0xff);
982 # add defaults mapping at the end
983 $filled[256] = $index * 256;
984 $lowerbounds[$index] = 255;
985 $upperbounds[$index] = 0;
988 # collapse blocks upwards if possible
991 for (my $i = 0; $i < 257; $i++)
993 next if $filled[$i] == -1;
994 if ($upperbounds[$index - 1] > $lowerbounds[$index])
996 $removed += $lowerbounds[$index];
1000 $removed += $upperbounds[$index - 1];
1001 $lowerbounds[$index] = $upperbounds[$index - 1];
1003 $filled[$i] -= $removed;
1007 # output all the subtables into a single array
1009 printf OUTPUT
"static const unsigned %s uni2cp_low[%d] =\n{\n",
1010 $width == 8 ?
"char" : "short", ($index + 1) * 256 - $removed;
1012 my $format = $width == 8 ?
"0x%02x" : "0x%04x";
1013 for (my $i = $index = 0; $i < 257; $i++)
1015 next if $filled[$i] == -1;
1016 my $start = ($i << 8) + $lowerbounds[$index];
1017 my $end = ($i << 8) + 255;
1020 print OUTPUT
" /* defaults */\n";
1021 printf OUTPUT
"%s\n};\n\n", DUMP_ARRAY
( $format, 0, ($def) x
($end - $start + 1) );
1025 printf OUTPUT
" /* 0x%04x .. 0x%04x */\n", $start, $end;
1026 printf OUTPUT
"%s,\n", DUMP_ARRAY
( $format, $def, @uni2cp[$start .. $end] );
1031 # output a table of the offsets of the subtables in the previous array
1033 for (my $i = 0; $i < 256; $i++)
1035 if ($filled[$i] == -1) { $filled[$i] = $filled[256]; }
1037 printf OUTPUT
"static const unsigned short uni2cp_high[256] =\n";
1038 printf OUTPUT
"{\n%s\n};\n\n", DUMP_ARRAY
( "0x%04x", 0, @filled[0..255] );
1041 ################################################################
1042 # dump an SBCS mapping table
1043 sub dump_sbcs_table
($$$$$)
1045 my ($codepage, $has_glyphs, $name, $def, $defw) = @_;
1048 # output the ascii->unicode table
1052 printf OUTPUT
"static const WCHAR cp2uni[512] =\n";
1053 printf OUTPUT
"{\n%s", DUMP_ARRAY
( "0x%04x", $defw, @cp2uni[0 .. 255] );
1054 printf OUTPUT
",\n /* glyphs */\n%s\n};\n\n",
1055 DUMP_ARRAY
( "0x%04x", $defw, get_glyphs_mapping
(@cp2uni[0 .. 255]) );
1059 printf OUTPUT
"static const WCHAR cp2uni[256] =\n";
1060 printf OUTPUT
"{\n%s\n};\n\n", DUMP_ARRAY
( "0x%04x", $defw, @cp2uni[0 .. 255] );
1063 dump_uni2cp_table
( 8, $def );
1065 # output the code page descriptor
1067 printf OUTPUT
"const struct sbcs_table DECLSPEC_HIDDEN cptable_%03d =\n{\n", $codepage;
1068 printf OUTPUT
" { %d, 1, 0x%04x, 0x%04x, \"%s\" },\n",
1069 $codepage, $def, $defw, $name;
1070 printf OUTPUT
" cp2uni,\n";
1071 if ($has_glyphs) { printf OUTPUT
" cp2uni + 256,\n"; }
1072 else { printf OUTPUT
" cp2uni,\n"; }
1073 printf OUTPUT
" uni2cp_low,\n";
1074 printf OUTPUT
" uni2cp_high\n};\n";
1078 ################################################################
1079 # dump a DBCS mapping table
1080 sub dump_dbcs_table
($$$$@
)
1082 my ($codepage, $name, $def, $defw, @lb_ranges) = @_;
1084 # build a list of lead bytes that are actually used
1087 LBLOOP
: for (my $y = 0; $y <= $#lead_bytes; $y++)
1089 $cp2uni[$lead_bytes[$y]] = $defw;
1090 my $base = $lead_bytes[$y] << 8;
1091 for (my $x = 0; $x < 256; $x++)
1093 if (defined $cp2uni[$base+$x])
1095 push @lblist,$lead_bytes[$y];
1100 my $unused = ($#lead_bytes > $#lblist);
1102 # output the ascii->unicode table for the single byte chars
1104 printf OUTPUT
"static const WCHAR cp2uni[%d] =\n", 256 * ($#lblist + 2 + $unused);
1105 printf OUTPUT
"{\n%s,\n", DUMP_ARRAY
( "0x%04x", $defw, @cp2uni[0 .. 255] );
1107 # output the default table for unused lead bytes
1111 printf OUTPUT
" /* unused lead bytes */\n";
1112 printf OUTPUT
"%s,\n", DUMP_ARRAY
( "0x%04x", 0, ($defw) x
256 );
1115 # output the ascii->unicode table for each DBCS lead byte
1117 for (my $y = 0; $y <= $#lblist; $y++)
1119 my $base = $lblist[$y] << 8;
1120 printf OUTPUT
" /* lead byte %02x */\n", $lblist[$y];
1121 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", $defw, @cp2uni[$base .. $base+255] );
1122 printf OUTPUT
($y < $#lblist) ?
",\n" : "\n};\n\n";
1125 # output the lead byte subtables offsets
1127 my @offsets = (0) x
256;
1128 for (my $x = 0; $x <= $#lblist; $x++) { $offsets[$lblist[$x]] = $x + 1; }
1131 # increment all lead bytes offset to take into account the unused table
1132 for (my $x = 0; $x <= $#lead_bytes; $x++) { $offsets[$lead_bytes[$x]]++; }
1134 printf OUTPUT
"static const unsigned char cp2uni_leadbytes[256] =\n";
1135 printf OUTPUT
"{\n%s\n};\n\n", DUMP_ARRAY
( "0x%02x", 0, @offsets );
1137 dump_uni2cp_table
( 16, $def );
1139 # output the code page descriptor
1141 printf OUTPUT
"const struct dbcs_table DECLSPEC_HIDDEN cptable_%03d =\n{\n", $codepage;
1142 printf OUTPUT
" { %d, 2, 0x%04x, 0x%04x, \"%s\" },\n",
1143 $codepage, $def, $defw, $name;
1144 printf OUTPUT
" cp2uni,\n";
1145 printf OUTPUT
" cp2uni_leadbytes,\n";
1146 printf OUTPUT
" uni2cp_low,\n";
1147 printf OUTPUT
" uni2cp_high,\n";
1148 printf OUTPUT
" {\n %s\n }\n", DUMP_ARRAY
( "0x%02x", 0, @lb_ranges, 0, 0 );
1149 printf OUTPUT
"};\n";
1153 ################################################################
1154 # get the list of defined lead byte ranges
1160 foreach $i (@lead_bytes) { $list[$i] = 1; }
1162 for (my $i = 0; $i < 256; $i++)
1166 if (!defined $list[$i]) { push @ranges, $i-1; $on = 0; }
1170 if ($list[$i]) { push @ranges, $i; $on = 1; }
1173 if ($on) { push @ranges, 0xff; }
1177 ################################################################
1178 # dump the Indic Syllabic Category table
1181 my $filename = shift;
1184 my $INPUT = open_data_file
( $UNIDATA, "IndicSyllabicCategory.txt" );
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*([a-zA-Z_]+)\s*#/)
1193 die "unknown indic $type" unless defined $indic_types{$type};
1196 $indic_table[hex $1] = $indic_types{$type};
1200 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*#/)
1203 die "unknown indic $type" unless defined $indic_types{$type};
1204 if (hex $1 < 65536 and hex $2 < 65536)
1206 foreach my $i (hex $1 .. hex $2)
1208 $indic_table[$i] = $indic_types{$type};
1213 die "malformed line $_";
1217 $INPUT = open_data_file
( $UNIDATA, "IndicPositionalCategory.txt" );
1220 next if /^\#/; # skip comments
1221 next if /^\s*$/; # skip empty lines
1222 next if /\x1a/; # skip ^Z
1223 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z]+)\s*#/)
1226 die "unknown matra $type" unless defined $matra_types{$type};
1227 $indic_table[hex $1] += $matra_types{$type} << 8;
1230 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*#/)
1233 die "unknown matra $type" unless defined $matra_types{$type};
1234 foreach my $i (hex $1 .. hex $2)
1236 $indic_table[$i] += $matra_types{$type} << 8;
1240 die "malformed line $_";
1244 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1245 print "Building $filename\n";
1246 print OUTPUT
"/* Unicode Indic Syllabic Category */\n";
1247 print OUTPUT
"/* generated from $UNIDATA/IndicSyllabicCategory.txt */\n";
1248 print OUTPUT
"/* and from $UNIDATA/IndicPositionalCategory.txt */\n";
1249 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1250 print OUTPUT
"#include \"wine/unicode.h\"\n\n";
1252 dump_two_level_mapping
( "indic_syllabic_table", $indic_types{'Other'}, @indic_table );
1255 save_file
($filename);
1258 ################################################################
1259 # dump the Line Break Properties table
1260 sub dump_linebreak
($)
1262 my $filename = shift;
1266 my $INPUT = open_data_file
( $UNIDATA, "LineBreak.txt" );
1269 next if /^\#/; # skip comments
1270 next if /^\s*$/; # skip empty lines
1271 next if /\x1a/; # skip ^Z
1272 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z][0-9A-Z])+\s*/)
1275 die "unknown breaktype $type" unless defined $break_types{$type};
1276 $break_table[hex $1] = $break_types{$type};
1279 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z][0-9A-Z])+\s*/)
1282 die "unknown breaktype $type" unless defined $break_types{$type};
1283 foreach my $i (hex $1 .. hex $2)
1285 $break_table[$i] = $break_types{$type};
1289 elsif (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z])+\s*/)
1292 die "unknown breaktype $type" unless defined $break_types{$type};
1293 $break_table[hex $1] = $break_types{$type};
1296 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z])+\s*/)
1299 die "unknown breaktype $type" unless defined $break_types{$type};
1300 foreach my $i (hex $1 .. hex $2)
1302 $break_table[$i] = $break_types{$type};
1306 die "malformed line $_";
1310 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1311 print "Building $filename\n";
1312 print OUTPUT
"/* Unicode Line Break Properties */\n";
1313 print OUTPUT
"/* generated from $UNIDATA/LineBreak.txt */\n";
1314 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1315 print OUTPUT
"#include \"wine/unicode.h\"\n\n";
1317 dump_two_level_mapping
( "wine_linebreak_table", $break_types{'XX'}, @break_table );
1320 save_file
($filename);
1340 "Canadian_Aboriginal" => 15,
1350 "Egyptian_Hieroglyphs" => 25,
1363 "Imperial_Aramaic" => 38,
1364 "Inscriptional_Pahlavi" => 39,
1365 "Inscriptional_Parthian" => 40,
1383 "Meetei_Mayek" => 58,
1386 "New_Tai_Lue" => 61,
1391 "Old_Persian" => 66,
1392 "Old_South_Arabian" => 67,
1405 "Syloti_Nagri" => 80,
1423 "Meroitic_Cursive" => 97,
1424 "Meroitic_Hieroglyphs" => 98,
1427 "Sora_Sompeng" => 101,
1431 "Caucasian_Albanian" => 104,
1439 "Manichaean" => 112,
1440 "Mende_Kikakui" => 113,
1444 "Old_North_Arabian" => 117,
1445 "Old_Permic" => 118,
1446 "Pahawh_Hmong" => 119,
1448 "Pau_Cin_Hau" => 121,
1449 "Psalter_Pahlavi" => 122,
1452 "Warang_Citi" => 125,
1455 ################################################################
1456 # dump Script IDs table
1459 my $filename = shift;
1460 my $header = $filename;
1465 my $INPUT = open_data_file
( $UNIDATA, "Scripts.txt" );
1467 # Unknown script id is always 0, so undefined scripts are automatically treated as such
1472 next if /^\#/; # skip comments
1473 next if /^\s*$/; # skip empty lines
1474 next if /\x1a/; # skip ^Z
1475 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1478 if (defined $scripts{$type})
1480 $scripts_table[hex $1] = $scripts{$type};
1484 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1487 if (defined $scripts{$type})
1489 foreach my $i (hex $1 .. hex $2)
1491 $scripts_table[$i] = $scripts{$type};
1500 $header = "$filename.h";
1501 open OUTPUT
,">$header.new" or die "Cannot create $header";
1502 print "Building $header\n";
1503 print OUTPUT
"/* Unicode Script IDs */\n";
1504 print OUTPUT
"/* generated from $UNIDATA/Scripts.txt */\n";
1505 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1507 print OUTPUT
"enum unicode_script_id {\n";
1508 foreach my $script (sort { $scripts{$a} <=> $scripts{$b} } keys %scripts)
1510 print OUTPUT
" Script_$script = $scripts{$script},\n";
1512 print OUTPUT
" Script_LastId = ", (scalar keys %scripts) - 1, "\n";
1513 print OUTPUT
"};\n";
1518 $filename = "$filename.c";
1519 open OUTPUT
,">$filename.new" or die "Cannot create $header";
1520 print "Building $filename\n";
1521 print OUTPUT
"/* Unicode Script IDs */\n";
1522 print OUTPUT
"/* generated from $UNIDATA/Scripts.txt */\n";
1523 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1524 print OUTPUT
"#include \"wine/unicode.h\"\n\n";
1526 dump_two_level_mapping
( "wine_scripts_table", 0, @scripts_table );
1528 save_file
($filename);
1531 ################################################################
1532 # dump the BiDi mirroring table
1533 sub dump_mirroring
($)
1535 my $filename = shift;
1536 my @mirror_table = ();
1538 my $INPUT = open_data_file
( $UNIDATA, "BidiMirroring.txt" );
1541 next if /^\#/; # skip comments
1542 next if /^$/; # skip empty lines
1543 next if /\x1a/; # skip ^Z
1544 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9a-fA-F]+)/)
1546 $mirror_table[hex $1] = hex $2;
1549 die "malformed line $_";
1553 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1554 print "Building $filename\n";
1555 print OUTPUT
"/* Unicode BiDi mirroring */\n";
1556 print OUTPUT
"/* generated from $UNIDATA/BidiMirroring.txt */\n";
1557 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1558 print OUTPUT
"#include \"wine/unicode.h\"\n\n";
1559 DUMP_CASE_TABLE
( "DECLSPEC_HIDDEN wine_mirror_map", @mirror_table );
1561 save_file
($filename);
1564 ################################################################
1565 # dump the Bidi Brackets
1568 my $filename = shift;
1571 my $INPUT = open_data_file
( $UNIDATA, "BidiBrackets.txt" );
1574 next if /^\#/; # skip comments
1575 next if /^\s*$/; # skip empty lines
1576 next if /\x1a/; # skip ^Z
1577 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9a-fA-F]+);\s*([con])/)
1580 die "unknown bracket $type" unless defined $bracket_types{$type};
1581 die "characters too distant $1 and $2" if abs(hex($2) - hex($1)) >= 128;
1582 $bracket_table[hex $1] = (hex($2) - hex($1)) % 255;
1583 $bracket_table[hex $1] += $bracket_types{$type} << 8;
1586 die "malformed line $_";
1590 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1591 print "Building $filename\n";
1592 print OUTPUT
"/* Unicode Bidirectional Bracket table */\n";
1593 print OUTPUT
"/* generated from $UNIDATA/BidiBrackets.txt */\n";
1594 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1595 print OUTPUT
"#include \"wine/unicode.h\"\n\n";
1597 dump_two_level_mapping
( "bidi_bracket_table", 0, @bracket_table );
1600 save_file
($filename);
1603 ################################################################
1604 # dump the Arabic shaping table
1607 my $filename = shift;
1611 $groups{"No_Joining_Group"} = $next_group++;
1613 my $INPUT = open_data_file
( $UNIDATA, "ArabicShaping.txt" );
1616 next if /^\#/; # skip comments
1617 next if /^\s*$/; # skip empty lines
1618 next if /\x1a/; # skip ^Z
1619 if (/^\s*([0-9a-fA-F]+)\s*;.*;\s*([RLDCUT])\s*;\s*(\w+)/)
1623 $groups{$group} = $next_group++ unless defined $groups{$group};
1624 $joining_table[hex $1] = $joining_types{$type} | ($groups{$group} << 8);
1627 die "malformed line $_";
1631 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1632 print "Building $filename\n";
1633 print OUTPUT
"/* Unicode Arabic shaping */\n";
1634 print OUTPUT
"/* generated from $UNIDATA/ArabicShaping.txt */\n";
1635 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1636 print OUTPUT
"#include \"wine/unicode.h\"\n\n";
1638 dump_two_level_mapping
( "wine_shaping_table", 0, @joining_table );
1640 print OUTPUT
"\nconst unsigned short DECLSPEC_HIDDEN wine_shaping_forms[256][4] =\n{\n";
1641 for (my $i = 0x600; $i <= 0x6ff; $i++)
1643 printf OUTPUT
" { 0x%04x, 0x%04x, 0x%04x, 0x%04x },\n",
1644 ${joining_forms
{"isolated"}}[$i] || $i,
1645 ${joining_forms
{"final"}}[$i] || $i,
1646 ${joining_forms
{"initial"}}[$i] || $i,
1647 ${joining_forms
{"medial"}}[$i] || $i;
1649 print OUTPUT
"};\n";
1652 save_file
($filename);
1655 ################################################################
1656 # dump the Vertical Orientation table
1657 sub dump_vertical
($)
1659 my $filename = shift;
1662 my $INPUT = open_data_file
( $VERTICALDATA, "VerticalOrientation-15.txt" );
1665 next if /^\#/; # skip comments
1666 next if /^\s*$/; # skip empty lines
1667 next if /\x1a/; # skip ^Z
1668 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1671 die "unknown vertical $type" unless defined $vertical_types{$type};
1674 $vertical_table[hex $1] = $vertical_types{$type};
1678 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*/)
1681 die "unknown vertical $type" unless defined $vertical_types{$type};
1682 foreach my $i (hex $1 .. hex $2)
1684 $vertical_table[$i] = $vertical_types{$type};
1688 die "malformed line $_";
1692 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1693 print "Building $filename\n";
1694 print OUTPUT
"/* Unicode Vertical Orientation */\n";
1695 print OUTPUT
"/* generated from $VERTICALDATA/VerticalOrientation-15.txt */\n";
1696 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1697 print OUTPUT
"#include \"wine/unicode.h\"\n\n";
1699 dump_two_level_mapping
( "vertical_orientation_table", $vertical_types{'R'}, @vertical_table );
1702 save_file
($filename);
1705 ################################################################
1706 # dump the digit folding tables
1707 sub dump_digit_folding
($)
1709 my $filename = shift;
1710 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1711 print "Building $filename\n";
1712 print OUTPUT
"/* Unicode digit folding mappings */\n";
1713 print OUTPUT
"/* generated from $UNIDATA/UnicodeData.txt */\n";
1714 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1715 print OUTPUT
"#include \"wine/unicode.h\"\n\n";
1717 DUMP_CASE_TABLE
( "DECLSPEC_HIDDEN wine_digitmap", @digitmap_table );
1719 DUMP_CASE_TABLE
( "DECLSPEC_HIDDEN wine_compatmap", @compatmap_table );
1721 save_file
($filename);
1725 ################################################################
1726 # dump the case mapping tables
1727 sub DUMP_CASE_MAPPINGS
($)
1729 my $filename = shift;
1730 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1731 print "Building $filename\n";
1732 print OUTPUT
"/* Unicode case mappings */\n";
1733 print OUTPUT
"/* generated from $UNIDATA/UnicodeData.txt */\n";
1734 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1735 print OUTPUT
"#include \"wine/unicode.h\"\n\n";
1737 DUMP_CASE_TABLE
( "wine_casemap_lower", @tolower_table );
1739 DUMP_CASE_TABLE
( "wine_casemap_upper", @toupper_table );
1741 save_file
($filename);
1745 ################################################################
1746 # dump a case mapping table
1747 sub DUMP_CASE_TABLE
($@
)
1749 my ($name,@table) = @_;
1751 # count the number of sub tables that contain something
1752 # also compute the low and upper populated bounds
1754 my @lowerbounds = ( 0, 0 );
1755 my @upperbounds = ( 0, 255 );
1758 for (my $i = 0; $i < 65536; $i++)
1760 next unless defined $table[$i];
1761 if (!defined $filled[$i >> 8])
1763 $lowerbounds[$index] = $i & 0xff;
1764 $upperbounds[$index] = 0xff - $lowerbounds[$index];
1765 $filled[$i >> 8] = $index * 256 + 512;
1770 $upperbounds[$index-1] = 0xff - ($i & 0xff);
1772 $table[$i] = ($table[$i] - $i) & 0xffff;
1775 # Collapse blocks upwards if possible
1778 for (my $i = 0; $i < 256; $i++)
1780 next unless defined $filled[$i];
1781 if ($upperbounds[$index - 1] > $lowerbounds[$index])
1783 $removed = $removed + $lowerbounds[$index];
1787 $removed = $removed + $upperbounds[$index - 1];
1788 $lowerbounds[$index] = $upperbounds[$index - 1];
1790 $filled[$i] = $filled[$i] - $removed;
1796 printf OUTPUT
"const WCHAR %s[%d] =\n", $name, $index * 256 + 512 - $removed;
1797 printf OUTPUT
"{\n /* index */\n";
1798 printf OUTPUT
"%s,\n", DUMP_ARRAY
( "0x%04x", 256, @filled );
1799 printf OUTPUT
" /* defaults */\n";
1800 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, (0) x
256 );
1802 for (my $i = 0; $i < 256; $i++)
1804 next unless $filled[$i];
1805 printf OUTPUT
",\n /* 0x%02x%02x .. 0x%02xff */\n", $i, $lowerbounds[$index], $i;
1806 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0,
1807 @table[($i<<8) + $lowerbounds[$index] .. ($i<<8)+255] );
1810 printf OUTPUT
"\n};\n";
1813 ################################################################
1814 # compress a mapping table by removing identical rows
1815 sub compress_array
($$@
)
1820 my $len = @table / $rows;
1821 my @array = (0) x
$rows;
1824 # try to merge table rows
1825 for (my $row = 0; $row < $rows; $row++)
1827 my @table_row = map { defined($_) ?
$_ : $def; } @table[($row * $len)..($row * $len + $len - 1)];
1828 my $rowtxt = pack "S*", @table_row;
1829 if (defined($sequences{$rowtxt}))
1831 # reuse an existing row
1832 $array[$row] = $sequences{$rowtxt};
1837 $sequences{$rowtxt} = $array[$row] = $#array + 1;
1838 push @array, @table_row;
1844 ################################################################
1845 # dump a simple char -> 16-bit value mapping table
1846 sub dump_simple_mapping
($$@
)
1850 my @array = compress_array
( 256, $def, @_[0..65535] );
1852 printf OUTPUT
"const unsigned short %s[%d] =\n{\n", $name, $#array+1;
1853 printf OUTPUT
" /* offsets */\n%s,\n", DUMP_ARRAY
( "0x%04x", 0, @array[0..255] );
1854 printf OUTPUT
" /* values */\n%s\n};\n", DUMP_ARRAY
( "0x%04x", 0, @array[256..$#array] );
1857 ################################################################
1858 # dump a char -> 16-bit value mapping table using two-level tables
1859 sub dump_two_level_mapping
($$@
)
1863 my @row_array = compress_array
( 4096, $def, @_[0..65535] );
1864 my @array = compress_array
( 256, 0, @row_array[0..4095] );
1866 for (my $i = 256; $i < @array; $i++) { $array[$i] += @array - 4096; }
1868 printf OUTPUT
"const unsigned short DECLSPEC_HIDDEN %s[%d] =\n{\n", $name, @array + @row_array - 4096;
1869 printf OUTPUT
" /* level 1 offsets */\n%s,\n", DUMP_ARRAY
( "0x%04x", 0, @array[0..255] );
1870 printf OUTPUT
" /* level 2 offsets */\n%s,\n", DUMP_ARRAY
( "0x%04x", 0, @array[256..$#array] );
1871 printf OUTPUT
" /* values */\n%s\n};\n", DUMP_ARRAY
( "0x%04x", 0, @row_array[4096..$#row_array] );
1874 ################################################################
1875 # dump a binary case mapping table in l_intl.nls format
1876 sub dump_binary_case_table
(@
)
1880 my %difftables_hash = ();
1882 my %offtables2_hash = ();
1883 my @offtables2 = ();
1886 for (my $i = 0; $i < 256; $i++)
1889 for(my $j = 0; $j < 16; $j++) # offset table for xx00-xxFF characters
1892 for (my $k = 0; $k < 16; $k++) # case map table for xxx0-xxxF characters
1894 my $char = ($i<<8) + ($j<<4) + $k;
1895 $difftable[$k] = (defined $table[$char]) ?
(($table[$char]-$char) & 0xffff) : 0;
1898 my $diff_key = pack "S*", @difftable;
1899 my $offset3 = $difftables_hash{$diff_key};
1900 if (!defined $offset3)
1902 $offset3 = scalar @difftables;
1903 $difftables_hash{$diff_key} = $offset3;
1904 push @difftables, @difftable;
1906 $offtable2[$j] = $offset3;
1909 my $offtable2_key = pack "S*", @offtable2;
1910 my $offset2 = $offtables2_hash{$offtable2_key};
1911 if (!defined $offset2)
1913 $offset2 = scalar @offtables2;
1914 $offtables2_hash{$offtable2_key} = $offset2;
1915 push @offtables2, \
@offtable2;
1917 $offtable[$i] = $offset2;
1921 my $offset = 0x100; # offset of first subtable in words
1924 push @output, 0x10 * $_ + $offset; # offset of subtable in words
1927 $offset = 0x100 + 0x10 * scalar @offtables2; # offset of first difftable in words
1928 foreach(@offtables2)
1933 push @output, $_ + $offset; # offset of difftable in words
1937 my $len = 1 + scalar @output + scalar @difftables;
1938 return pack "S<*", $len, @output, @difftables;
1942 ################################################################
1943 # dump case mappings for l_intl.nls
1944 sub dump_intl_nls
($)
1946 my $filename = shift;
1947 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1948 printf "Building $filename\n";
1951 print OUTPUT
pack "S<", 1; # version
1952 print OUTPUT dump_binary_case_table
( @toupper_table );
1953 print OUTPUT dump_binary_case_table
( @tolower_table );
1955 save_file
($filename);
1959 sub load_nameprep_range_table
($$$)
1961 my ($INPUT, $val, $table_ref) = @_;
1965 if (/^\s*([0-9a-fA-F]+)-([0-9a-fA-F]+)/)
1968 $last = 65535 if($last >= 65536);
1969 foreach my $i (hex $1 .. $last)
1971 $table_ref->[$i] |= $val;
1975 elsif (/^\s*([0-9a-fA-F]+)/)
1979 $table_ref->[hex $1] |= $val;
1984 return if (/End\sTable/);
1988 sub load_nameprep_map_table
($$)
1990 my ($INPUT, $table_ref) = @_;
1994 if (/^\s*([0-9a-fA-F]+);\s;/)
1996 # special value for map to nothing
1997 $table_ref->[hex $1] = [0xffff, 0xffff, 0xffff];
2000 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+);/)
2002 $table_ref->[hex $1] = [hex $2, 0, 0];
2005 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+)\s([0-9a-fA-F]+);/)
2007 $table_ref->[hex $1] = [hex $2, hex $3, 0];
2010 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+)\s([0-9a-fA-F]+)\s([0-9a-fA-F]+);/)
2012 $table_ref->[hex $1] = [hex $2, hex $3, hex $4];
2016 return if (/End\sTable/);
2020 ################################################################
2021 # dump mapping table, prohibited characters set, unassigned
2022 # characters, bidirectional rules used by nameprep algorithm
2023 sub dump_nameprep
($)
2025 my $filename = shift;
2026 my @mapping_table = ();
2029 my $INPUT = open_data_file
( $RFCS, $STRINGPREP );
2032 next unless /Start\sTable/;
2034 load_nameprep_range_table
($INPUT, $nameprep_flags{"unassigned"}, \
@flags_table) if (/A.1/);
2035 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.1.2/);
2036 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.2.2/);
2037 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.3/);
2038 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.4/);
2039 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.5/);
2040 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.6/);
2041 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.7/);
2042 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.8/);
2043 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.9/);
2044 load_nameprep_range_table
($INPUT, $nameprep_flags{"bidi_ral"}, \
@flags_table) if (/D.1/);
2045 load_nameprep_range_table
($INPUT, $nameprep_flags{"bidi_l"}, \
@flags_table) if (/D.2/);
2047 load_nameprep_map_table
($INPUT, \
@mapping_table) if (/B.1/);
2048 load_nameprep_map_table
($INPUT, \
@mapping_table) if (/B.2/);
2052 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2053 print "Building $filename\n";
2054 print OUTPUT
"/* Nameprep algorithm related data */\n";
2055 print OUTPUT
"/* generated from $RFCS/$STRINGPREP */\n";
2056 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
2057 print OUTPUT
"#include \"wine/unicode.h\"\n\n";
2059 dump_two_level_mapping
( "nameprep_char_type", 0, @flags_table );
2061 ######### mapping table
2062 # first determine all the 16-char subsets that contain something
2064 my $pos = 16*3; # for the null subset
2065 for (my $i = 0; $i < 65536; $i++)
2067 next unless defined $mapping_table[$i];
2068 $filled[$i >> 4] = $pos;
2074 # now count the 256-char subsets that contain something
2075 my @filled_idx = (256) x
256;
2077 for (my $i = 0; $i < 4096; $i++)
2079 next unless $filled[$i];
2080 $filled_idx[$i >> 4] = $pos;
2084 my $null_offset = $pos;
2087 # add the index offsets to the subsets positions
2088 for (my $i = 0; $i < 4096; $i++)
2090 next unless $filled[$i];
2091 $filled[$i] += $null_offset;
2094 # dump the main index
2095 printf OUTPUT
"const unsigned short DECLSPEC_HIDDEN nameprep_mapping[%d] =\n", $total;
2096 printf OUTPUT
"{\n /* index */\n";
2097 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @filled_idx );
2098 printf OUTPUT
",\n /* null sub-index */\n%s", DUMP_ARRAY
( "0x%04x", 0, ($null_offset) x
16 );
2100 # dump the second-level indexes
2101 for (my $i = 0; $i < 256; $i++)
2103 next unless ($filled_idx[$i] > 256);
2104 my @table = @filled[($i<<4)..($i<<4)+15];
2105 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
2106 printf OUTPUT
",\n /* sub-index %02x */\n", $i;
2107 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @table );
2110 # dump the 16-char subsets
2111 printf OUTPUT
",\n /* null mapping */\n";
2112 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, (0) x
48 );
2114 for (my $i = 0; $i < 4096; $i++)
2116 next unless $filled[$i];
2117 my @table = (0) x
48;
2118 for (my $j = 0; $j < 16; $j++)
2120 if (defined $mapping_table[($i<<4) + $j])
2122 $table[3 * $j] = ${$mapping_table[($i << 4) + $j]}[0];
2123 $table[3 * $j + 1] = ${$mapping_table[($i << 4) + $j]}[1];
2124 $table[3 * $j + 2] = ${$mapping_table[($i << 4) + $j]}[2];
2127 printf OUTPUT
",\n /* 0x%03x0 .. 0x%03xf */\n", $i, $i;
2128 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @table );
2131 printf OUTPUT
"\n};\n";
2134 save_file
($filename);
2137 ################################################################
2138 # dump the ctype tables
2139 sub DUMP_CTYPE_TABLES
($)
2141 my $filename = shift;
2142 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2143 printf "Building $filename\n";
2144 printf OUTPUT
"/* Unicode ctype tables */\n";
2145 printf OUTPUT
"/* Automatically generated; DO NOT EDIT!! */\n\n";
2146 printf OUTPUT
"#include \"wine/unicode.h\"\n\n";
2148 # add the direction in the high 4 bits of the category
2149 for (my $i = 0; $i < 65536; $i++)
2151 $category_table[$i] |= $direction_table[$i] << 12 if defined $direction_table[$i];
2154 dump_simple_mapping
( "wine_wctype_table", 0, @category_table );
2157 save_file
($filename);
2161 ################################################################
2162 # dump the char composition table
2163 sub dump_compose_table
($)
2165 my $filename = shift;
2167 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2168 print "Building $filename\n";
2169 print OUTPUT
"/* Unicode char composition */\n";
2170 print OUTPUT
"/* generated from $UNIDATA/UnicodeData.txt */\n";
2171 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
2172 print OUTPUT
"#include \"wine/unicode.h\"\n\n";
2175 foreach my $i (@compose_table)
2178 push @
{$filled[$comp[1]]}, [ $comp[0], $comp[2] ];
2181 # count how many different second chars we have
2184 for (my $i = 0; $i < 65536; $i++)
2186 next unless defined $filled[$i];
2190 # build the table of second chars and offsets
2192 my $pos = $count + 1;
2194 for (my $i = 0; $i < 65536; $i++)
2196 next unless defined $filled[$i];
2197 push @table, $i, $pos;
2198 $pos += @
{$filled[$i]};
2200 # terminator with last position
2201 push @table, 0, $pos;
2202 printf OUTPUT
"static const WCHAR table[0x%x] =\n{\n", 2*$pos;
2203 printf OUTPUT
" /* second chars + offsets */\n%s", DUMP_ARRAY
( "0x%04x", 0, @table );
2205 # build the table of first chars and mappings
2207 for (my $i = 0; $i < 65536; $i++)
2209 next unless defined $filled[$i];
2211 my @list = sort { $a->[0] <=> $b->[0] } @
{$filled[$i]};
2212 for (my $j = 0; $j <= $#list; $j++)
2214 push @table, $list[$j][0], $list[$j][1];
2216 printf OUTPUT
",\n /* 0x%04x */\n%s", $i, DUMP_ARRAY
( "0x%04x", 0, @table );
2218 print OUTPUT
"\n};\n\n";
2219 print OUTPUT
<<"EOF";
2220 static inline int binary_search( WCHAR ch, int low, int high )
2224 int pos = (low + high) / 2;
2225 if (table[2 * pos] < ch) low = pos + 1;
2226 else if (table[2 * pos] > ch) high = pos - 1;
2232 WCHAR DECLSPEC_HIDDEN wine_compose( const WCHAR *str )
2234 int pos, idx = 1, start = 0, count = $count;
2237 if ((pos = binary_search( str[idx], start, count - 1 )) == -1) return 0;
2238 if (!idx--) return table[2 * pos + 1];
2239 start = table[2 * pos + 1];
2240 count = table[2 * pos + 3];
2245 save_file
($filename);
2248 ################################################################
2249 # dump the char decomposition table
2250 sub dump_decompose_table
($)
2252 my $filename = shift;
2254 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2255 print "Building $filename\n";
2256 print OUTPUT
"/* Unicode char composition */\n";
2257 print OUTPUT
"/* generated from $UNIDATA/UnicodeData.txt */\n";
2258 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
2259 print OUTPUT
"#include \"wine/unicode.h\"\n\n";
2261 # first determine all the 16-char subsets that contain something
2263 my @filled = (0) x
4096;
2264 my $pos = 16*2; # for the null subset
2265 for (my $i = 0; $i < 65536; $i++)
2267 next unless defined $decomp_table[$i];
2268 $filled[$i >> 4] = $pos;
2274 # now count the 256-char subsets that contain something
2276 my @filled_idx = (256) x
256;
2278 for (my $i = 0; $i < 4096; $i++)
2280 next unless $filled[$i];
2281 $filled_idx[$i >> 4] = $pos;
2285 my $null_offset = $pos; # null mapping
2288 # add the index offsets to the subsets positions
2290 for (my $i = 0; $i < 4096; $i++)
2292 next unless $filled[$i];
2293 $filled[$i] += $null_offset;
2296 # dump the main index
2298 printf OUTPUT
"static const WCHAR table[%d] =\n", $total;
2299 printf OUTPUT
"{\n /* index */\n";
2300 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @filled_idx );
2301 printf OUTPUT
",\n /* null sub-index */\n%s", DUMP_ARRAY
( "0x%04x", 0, ($null_offset) x
16 );
2303 # dump the second-level indexes
2305 for (my $i = 0; $i < 256; $i++)
2307 next unless ($filled_idx[$i] > 256);
2308 my @table = @filled[($i<<4)..($i<<4)+15];
2309 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
2310 printf OUTPUT
",\n /* sub-index %02x */\n", $i;
2311 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @table );
2314 # dump the 16-char subsets
2316 printf OUTPUT
",\n /* null mapping */\n";
2317 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, (0) x
32 );
2319 for (my $i = 0; $i < 4096; $i++)
2321 next unless $filled[$i];
2322 my @table = (0) x
32;
2323 for (my $j = 0; $j < 16; $j++)
2325 if (defined $decomp_table[($i<<4) + $j])
2327 $table[2 * $j] = ${$decomp_table[($i << 4) + $j]}[0];
2328 $table[2 * $j + 1] = ${$decomp_table[($i << 4) + $j]}[1];
2331 printf OUTPUT
",\n /* 0x%03x0 .. 0x%03xf */\n", $i, $i;
2332 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @table );
2335 printf OUTPUT
"\n};\n\n";
2336 print OUTPUT
<<"EOF";
2337 unsigned int DECLSPEC_HIDDEN wine_decompose( WCHAR ch, WCHAR *dst, unsigned int dstlen )
2339 const WCHAR *ptr = table + table[table[ch >> 8] + ((ch >> 4) & 0x0f)] + 2 * (ch & 0xf);
2343 if (!*ptr) return 1;
2344 if (dstlen <= 1) return 0;
2345 /* apply the decomposition recursively to the first char */
2346 if ((res = wine_decompose( *ptr, dst, dstlen-1 ))) dst[res++] = ptr[1];
2351 save_file
($filename);
2354 ################################################################
2355 # output a codepage definition file from the global tables
2356 sub output_codepage_file
($$$$)
2358 my ($codepage, $filename, $comment, $has_glyphs) = @_;
2360 my $output = sprintf "libs/port/c_%03d.c", $codepage;
2361 open OUTPUT
,">$output.new" or die "Cannot create $output";
2363 printf "Building %s from %s (%s)\n", $output, $filename || "hardcoded data", $comment;
2367 printf OUTPUT
"/* code page %03d (%s) */\n", $codepage, $comment;
2370 print OUTPUT
"/* generated from $MAPPINGS/$filename */\n";
2371 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
2375 printf OUTPUT
"/* Automatically generated; DO NOT EDIT!! */\n\n";
2377 printf OUTPUT
"#include \"wine/unicode.h\"\n\n";
2379 if (!@lead_bytes) { dump_sbcs_table
( $codepage, $has_glyphs, $comment, $default_char, $default_wchar ); }
2380 else { dump_dbcs_table
( $codepage, $comment, $default_char, $default_wchar, get_lb_ranges
() ); }
2385 ################################################################
2386 # read a "bestfit" Windows mapping file
2387 sub read_bestfit_file
($)
2389 my ($filename) = @_;
2391 my ($codepage, $width, $count);
2392 my ($lb_cur, $lb_end);
2394 my $INPUT = open_data_file
( $MAPPINGS, $filename ) or die "Cannot open $filename";
2398 next if /^;/; # skip comments
2399 next if /^\s*$/; # skip empty lines
2400 next if /\x1a/; # skip ^Z
2401 last if /^ENDCODEPAGE/;
2403 if (/^CODEPAGE\s+(\d+)/)
2408 if (/^CPINFO\s+(\d+)\s+0x([0-9a-fA-f]+)\s+0x([0-9a-fA-F]+)/)
2411 $default_char = hex $2;
2412 $default_wchar = hex $3;
2415 if (/^(MBTABLE|WCTABLE|DBCSRANGE|DBCSTABLE)\s+(\d+)/)
2421 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)/)
2423 if ($state eq "MBTABLE")
2427 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
2430 if ($state eq "WCTABLE")
2434 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
2437 if ($state eq "DBCSRANGE")
2441 for (my $i = $start; $i <= $end; $i++) { add_lead_byte
( $i ); }
2446 if ($state eq "DBCSTABLE")
2450 my $cp = ($lb_cur << 8) | $mb;
2451 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
2454 if (++$lb_cur > $lb_end) { $state = "DBCSRANGE"; }
2459 die "$filename: Unrecognized line $_\n";
2465 ################################################################
2466 # read an input file and generate the corresponding .c file
2469 my ($codepage,$filename,$has_glyphs,$comment,$first_private,$def,$defw) = @_;
2474 $default_char = $def || $DEF_CHAR;
2475 $default_wchar = $defw || $DEF_CHAR;
2477 # some codepage files are special
2478 if ($codepage == 20932)
2480 READ_JIS0208_FILE
( $filename );
2481 add_default_mappings
( $first_private );
2483 elsif ($codepage == 20127)
2485 fill_20127_codepage
();
2486 add_default_mappings
( $first_private );
2488 elsif ($filename =~ /\/bestfit
/)
2490 read_bestfit_file
( $filename );
2494 read_codepage_file
( $filename );
2495 if ($codepage == 10001)
2497 # add Shift-JIS mappings
2498 read_bestfit_file
( "VENDORS/MICSFT/WindowsBestFit/bestfit932.txt" );
2502 add_default_mappings
( $first_private );
2506 output_codepage_file
( $codepage, $filename, $comment, $has_glyphs );
2510 ################################################################
2511 # save a file if modified
2515 if (-f
$file && !system "cmp $file $file.new >/dev/null")
2521 rename "$file.new", "$file";
2526 ################################################################
2527 # output the list of codepage tables into the cptable.c file
2528 sub output_cptable
($)
2531 my @tables_decl = ();
2533 printf "Building %s\n", $output;
2535 foreach my $file (@allfiles)
2537 my ($codepage,$filename) = @
$file;
2538 push @tables_decl, sprintf("extern union cptable cptable_%03d;\n",$codepage);
2541 push @tables_decl, sprintf("\nstatic const union cptable * const cptables[%d] =\n{\n",$#allfiles+1);
2542 foreach my $file (@allfiles)
2544 my ($codepage,$filename) = @
$file;
2545 push @tables_decl, sprintf(" &cptable_%03d,\n", $codepage);
2547 push @tables_decl, "};";
2548 REPLACE_IN_FILE
( $output, @tables_decl );
2551 ################################################################
2552 # replace the contents of a file between ### cpmap ### marks
2554 sub REPLACE_IN_FILE
($@
)
2559 open(FILE
,$name) or die "Can't open $name";
2563 last if /\#\#\# cpmap begin \#\#\#/;
2568 if (/\#\#\# cpmap end \#\#\#/) { push @lines, "\n", $_; last; }
2570 push @lines, <FILE
>;
2571 open(FILE
,">$name.new") or die "Can't modify $name";
2577 ################################################################
2580 chdir ".." if -f
"./make_unicode";
2581 READ_DEFAULTS
( $DEFAULTS );
2582 DUMP_CASE_MAPPINGS
( "libs/wine/casemap.c" );
2583 DUMP_SORTKEYS
( "libs/wine/collation.c", READ_SORTKEYS_FILE
() );
2584 dump_compose_table
( "libs/port/compose.c" );
2585 dump_decompose_table
( "libs/port/decompose.c" );
2586 DUMP_CTYPE_TABLES
( "libs/wine/wctype.c" );
2587 dump_digit_folding
( "libs/port/digitmap.c" );
2588 dump_mirroring
( "dlls/usp10/mirror.c" );
2589 dump_mirroring
( "dlls/dwrite/mirror.c" );
2590 dump_bracket
( "dlls/usp10/bracket.c" );
2591 dump_bracket
( "dlls/dwrite/bracket.c" );
2592 dump_shaping
( "dlls/usp10/shaping.c" );
2593 dump_linebreak
( "dlls/usp10/linebreak.c" );
2594 dump_linebreak
( "dlls/dwrite/linebreak.c" );
2595 dump_scripts
( "dlls/dwrite/scripts" );
2596 dump_indic
( "dlls/usp10/indicsyllable.c" );
2597 dump_intl_nls
("loader/l_intl.nls");
2598 dump_vertical
( "dlls/gdi32/vertical.c" );
2599 dump_vertical
( "dlls/wineps.drv/vertical.c" );
2600 dump_nameprep
( "dlls/kernel32/nameprep.c" );
2602 foreach my $file (@allfiles) { HANDLE_FILE
( @
{$file} ); }
2604 output_cptable
("libs/port/cptable.c");
2609 # compile-command: "./make_unicode"