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/12.1.0/ucd/UCD.zip";
27 my $REPORTS = "http://www.unicode.org/reports";
28 my $RFCS = "http://www.rfc-editor.org/rfc";
29 my $MSDATA = "https://download.microsoft.com/download/C/F/7/CF713A5E-9FBC-4FD6-9246-275F65C0E498";
30 my $MSCODEPAGES = "$MSDATA/Windows Supported Code Page Data Files.zip";
33 my $SORTKEYS = "tr10/allkeys.txt";
35 # RFC3454 (stringprep data)
36 my $STRINGPREP = "rfc3454.txt";
38 # Default char for undefined mappings
39 my $DEF_CHAR = ord '?';
43 [ 37, "CodpageFiles/037.txt", "IBM EBCDIC US Canada" ],
44 [ 437, "CodpageFiles/437.txt", "OEM United States" ],
45 [ 500, "CodpageFiles/500.txt", "IBM EBCDIC International" ],
46 [ 737, "CodpageFiles/737.txt", "OEM Greek 437G" ],
47 [ 775, "CodpageFiles/775.txt", "OEM Baltic" ],
48 [ 850, "CodpageFiles/850.txt", "OEM Multilingual Latin 1" ],
49 [ 852, "CodpageFiles/852.txt", "OEM Slovak Latin 2" ],
50 [ 855, "CodpageFiles/855.txt", "OEM Cyrillic" ],
51 [ 857, "CodpageFiles/857.txt", "OEM Turkish" ],
52 [ 860, "CodpageFiles/860.txt", "OEM Portuguese" ],
53 [ 861, "CodpageFiles/861.txt", "OEM Icelandic" ],
54 [ 862, "CodpageFiles/862.txt", "OEM Hebrew" ],
55 [ 863, "CodpageFiles/863.txt", "OEM Canadian French" ],
56 [ 864, "CodpageFiles/864.txt", "OEM Arabic" ],
57 [ 865, "CodpageFiles/865.txt", "OEM Nordic" ],
58 [ 866, "CodpageFiles/866.txt", "OEM Russian" ],
59 [ 869, "CodpageFiles/869.txt", "OEM Greek" ],
60 [ 874, "CodpageFiles/874.txt", "ANSI/OEM Thai" ],
61 [ 875, "CodpageFiles/875.txt", "IBM EBCDIC Greek" ],
62 [ 932, "CodpageFiles/932.txt", "ANSI/OEM Japanese Shift-JIS" ],
63 [ 936, "CodpageFiles/936.txt", "ANSI/OEM Simplified Chinese GBK" ],
64 [ 949, "CodpageFiles/949.txt", "ANSI/OEM Korean Unified Hangul" ],
65 [ 950, "CodpageFiles/950.txt", "ANSI/OEM Traditional Chinese Big5" ],
66 [ 1026, "CodpageFiles/1026.txt", "IBM EBCDIC Latin 5 Turkish" ],
67 [ 1250, "CodpageFiles/1250.txt", "ANSI Eastern Europe" ],
68 [ 1251, "CodpageFiles/1251.txt", "ANSI Cyrillic" ],
69 [ 1252, "CodpageFiles/1252.txt", "ANSI Latin 1" ],
70 [ 1253, "CodpageFiles/1253.txt", "ANSI Greek" ],
71 [ 1254, "CodpageFiles/1254.txt", "ANSI Turkish" ],
72 [ 1255, "CodpageFiles/1255.txt", "ANSI Hebrew" ],
73 [ 1256, "CodpageFiles/1256.txt", "ANSI Arabic" ],
74 [ 1257, "CodpageFiles/1257.txt", "ANSI Baltic" ],
75 [ 1258, "CodpageFiles/1258.txt", "ANSI/OEM Viet Nam" ],
76 [ 1361, "CodpageFiles/1361.txt", "Korean Johab" ],
77 [ 10000, "CodpageFiles/10000.txt", "Mac Roman" ],
78 [ 10001, "CodpageFiles/10001.txt", "Mac Japanese" ],
79 [ 10002, "CodpageFiles/10002.txt", "Mac Traditional Chinese" ],
80 [ 10003, "CodpageFiles/10003.txt", "Mac Korean" ],
81 [ 10004, "CodpageFiles/10004.txt", "Mac Arabic" ],
82 [ 10005, "CodpageFiles/10005.txt", "Mac Hebrew" ],
83 [ 10006, "CodpageFiles/10006.txt", "Mac Greek" ],
84 [ 10007, "CodpageFiles/10007.txt", "Mac Cyrillic" ],
85 [ 10008, "CodpageFiles/10008.txt", "Mac Simplified Chinese" ],
86 [ 10010, "CodpageFiles/10010.txt", "Mac Romanian" ],
87 [ 10017, "CodpageFiles/10017.txt", "Mac Ukrainian" ],
88 [ 10021, "CodpageFiles/10021.txt", "Mac Thai" ],
89 [ 10029, "CodpageFiles/10029.txt", "Mac Latin 2" ],
90 [ 10079, "CodpageFiles/10079.txt", "Mac Icelandic" ],
91 [ 10081, "CodpageFiles/10081.txt", "Mac Turkish" ],
92 [ 10082, "CodpageFiles/10082.txt", "Mac Croatian" ],
93 [ 20127, "CodpageFiles/20127.txt", "US-ASCII (7bit)" ],
94 [ 20866, "CodpageFiles/20866.txt", "Russian KOI8" ],
95 [ 20932, "OBSOLETE/EASTASIA/JIS", "EUC-JP" ],
96 [ 21866, "CodpageFiles/21866.txt", "Ukrainian KOI8" ],
97 [ 28591, "CodpageFiles/28591.txt", "ISO 8859-1 Latin 1" ],
98 [ 28592, "CodpageFiles/28592.txt", "ISO 8859-2 Latin 2 (East European)" ],
99 [ 28593, "CodpageFiles/28593.txt", "ISO 8859-3 Latin 3 (South European)" ],
100 [ 28594, "CodpageFiles/28594.txt", "ISO 8859-4 Latin 4 (Baltic old)" ],
101 [ 28595, "CodpageFiles/28595.txt", "ISO 8859-5 Cyrillic" ],
102 [ 28596, "CodpageFiles/28596.txt", "ISO 8859-6 Arabic" ],
103 [ 28597, "CodpageFiles/28597.txt", "ISO 8859-7 Greek" ],
104 [ 28598, "CodpageFiles/28598.txt", "ISO 8859-8 Hebrew" ],
105 [ 28599, "CodpageFiles/28599.txt", "ISO 8859-9 Latin 5 (Turkish)" ],
106 [ 28603, "CodpageFiles/28603.txt", "ISO 8859-13 Latin 7 (Baltic)" ],
107 [ 28605, "CodpageFiles/28605.txt", "ISO 8859-15 Latin 9 (Euro)" ],
136 "Avagraha" => 0x0003,
139 "Vowel_Independent" => 0x0006,
140 "Vowel_Dependent" => 0x0007,
142 "Consonant_Placeholder" => 0x0009,
143 "Consonant" => 0x000a,
144 "Consonant_Dead" => 0x000b,
145 "Consonant_Succeeding_Repha" => 0x000c,
146 "Consonant_Subjoined" => 0x000d,
147 "Consonant_Medial" => 0x000e,
148 "Consonant_Final" => 0x000f,
149 "Consonant_Head_Letter" => 0x0010,
150 "Modifying_Letter" => 0x0011,
151 "Tone_Letter" => 0x0012,
152 "Tone_Mark" => 0x0013,
153 "Register_Shifter" => 0x0014,
154 "Consonant_Preceding_Repha" => 0x0015,
155 "Pure_Killer" => 0x0016,
156 "Invisible_Stacker" => 0x0017,
157 "Gemination_Mark" => 0x0018,
158 "Cantillation_Mark" => 0x0019,
159 "Non_Joiner" => 0x001a,
161 "Number_Joiner" => 0x001c,
163 "Brahmi_Joining_Number" => 0x001e,
164 "Consonant_With_Stacker" => 0x001f,
165 "Consonant_Prefixed" => 0x0020,
166 "Syllable_Modifier" => 0x0021,
167 "Consonant_Killer" => 0x0022,
168 "Consonant_Initial_Postfixed" => 0x0023,
175 "Visual_Order_Left" => 0x03,
176 "Left_And_Right" => 0x04,
179 "Top_And_Bottom" => 0x07,
180 "Top_And_Right" => 0x08,
181 "Top_And_Left" => 0x09,
182 "Top_And_Left_And_Right" => 0x0a,
183 "Bottom_And_Right" => 0x0b,
184 "Top_And_Bottom_And_Right" => 0x0c,
185 "Overstruck" => 0x0d,
187 "Bottom_And_Left" => 0x0f
192 "unassigned" => 0x01,
193 "prohibited" => 0x02,
255 "Lu" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"upper"}, # Letter, Uppercase
256 "Ll" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"lower"}, # Letter, Lowercase
257 "Lt" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"upper"}|$ctype{"lower"}, # Letter, Titlecase
258 "Mn" => $ctype{"defin"}, # Mark, Non-Spacing
259 "Mc" => $ctype{"defin"}, # Mark, Spacing Combining
260 "Me" => $ctype{"defin"}, # Mark, Enclosing
261 "Nd" => $ctype{"defin"}|$ctype{"digit"}, # Number, Decimal Digit
262 "Nl" => $ctype{"defin"}|$ctype{"alpha"}, # Number, Letter
263 "No" => $ctype{"defin"}, # Number, Other
264 "Zs" => $ctype{"defin"}|$ctype{"space"}, # Separator, Space
265 "Zl" => $ctype{"defin"}|$ctype{"space"}, # Separator, Line
266 "Zp" => $ctype{"defin"}|$ctype{"space"}, # Separator, Paragraph
267 "Cc" => $ctype{"defin"}|$ctype{"cntrl"}, # Other, Control
268 "Cf" => $ctype{"defin"}|$ctype{"cntrl"}, # Other, Format
269 "Cs" => $ctype{"defin"}, # Other, Surrogate
270 "Co" => $ctype{"defin"}, # Other, Private Use
271 "Cn" => $ctype{"defin"}, # Other, Not Assigned
272 "Lm" => $ctype{"defin"}|$ctype{"alpha"}, # Letter, Modifier
273 "Lo" => $ctype{"defin"}|$ctype{"alpha"}, # Letter, Other
274 "Pc" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Connector
275 "Pd" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Dash
276 "Ps" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Open
277 "Pe" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Close
278 "Pi" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Initial quote
279 "Pf" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Final quote
280 "Po" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Other
281 "Sm" => $ctype{"defin"}, # Symbol, Math
282 "Sc" => $ctype{"defin"}, # Symbol, Currency
283 "Sk" => $ctype{"defin"}, # Symbol, Modifier
284 "So" => $ctype{"defin"} # Symbol, Other
287 # a few characters need additional categories that cannot be determined automatically
288 my %special_categories =
290 "xdigit" => [ ord('0')..ord('9'),ord('A')..ord('F'),ord('a')..ord('f'),
291 0xff10..0xff19
, 0xff21..0xff26
, 0xff41..0xff46
],
292 "space" => [ 0x09..0x0d
, 0x85 ],
293 "blank" => [ 0x09, 0x20, 0xa0, 0x3000, 0xfeff ],
294 "cntrl" => [ 0x070f, 0x200c, 0x200d,
295 0x200e, 0x200f, 0x202a, 0x202b, 0x202c, 0x202d, 0x202e,
296 0x206a, 0x206b, 0x206c, 0x206d, 0x206e, 0x206f, 0xfeff,
297 0xfff9, 0xfffa, 0xfffb ],
298 "punct" => [ 0x24, 0x2b, 0x3c..0x3e
, 0x5e, 0x60, 0x7c, 0x7e, 0xa2..0xbe
,
300 "digit" => [ 0xb2, 0xb3, 0xb9 ],
301 "lower" => [ 0x2071, 0x207f ]
306 "L" => 1, # Left-to-Right
307 "R" => 2, # Right-to-Left
308 "AL" => 12, # Right-to-Left Arabic
309 "EN" => 3, # European Number
310 "ES" => 4, # European Number Separator
311 "ET" => 5, # European Number Terminator
312 "AN" => 6, # Arabic Number
313 "CS" => 7, # Common Number Separator
314 "NSM" => 13, # Non-Spacing Mark
315 "BN" => 14, # Boundary Neutral
316 "B" => 8, # Paragraph Separator
317 "S" => 9, # Segment Separator
318 "WS" => 10, # Whitespace
319 "ON" => 11, # Other Neutrals
320 "LRE" => 15, # Left-to-Right Embedding
321 "LRO" => 15, # Left-to-Right Override
322 "RLE" => 15, # Right-to-Left Embedding
323 "RLO" => 15, # Right-to-Left Override
324 "PDF" => 15, # Pop Directional Format
325 "LRI" => 15, # Left-to-Right Isolate
326 "RLI" => 15, # Right-to-Left Isolate
327 "FSI" => 15, # First Strong Isolate
328 "PDI" => 15 # Pop Directional Isolate
333 "L" => 1, # C2_LEFTTORIGHT
334 "R" => 2, # C2_RIGHTTOLEFT
335 "AL" => 2, # C2_RIGHTTOLEFT
336 "EN" => 3, # C2_EUROPENUMBER
337 "ES" => 4, # C2_EUROPESEPARATOR
338 "ET" => 5, # C2_EUROPETERMINATOR
339 "AN" => 6, # C2_ARABICNUMBER
340 "CS" => 7, # C2_COMMONSEPARATOR
341 "NSM" => 0, # C2_NOTAPPLICABLE
342 "BN" => 0, # C2_NOTAPPLICABLE
343 "B" => 8, # C2_BLOCKSEPARATOR
344 "S" => 9, # C2_SEGMENTSEPARATOR
345 "WS" => 10, # C2_WHITESPACE
346 "ON" => 11, # C2_OTHERNEUTRAL
347 "LRE" => 11, # C2_OTHERNEUTRAL
348 "LRO" => 11, # C2_OTHERNEUTRAL
349 "RLE" => 11, # C2_OTHERNEUTRAL
350 "RLO" => 11, # C2_OTHERNEUTRAL
351 "PDF" => 11, # C2_OTHERNEUTRAL
352 "LRI" => 11, # C2_OTHERNEUTRAL
353 "RLI" => 11, # C2_OTHERNEUTRAL
354 "FSI" => 11, # C2_OTHERNEUTRAL
355 "PDI" => 11 # C2_OTHERNEUTRAL
360 "ON" => 0, # Other Neutrals
361 "L" => 1, # Left-to-Right
362 "R" => 2, # Right-to-Left
363 "AN" => 3, # Arabic Number
364 "EN" => 4, # European Number
365 "AL" => 5, # Right-to-Left Arabic
366 "NSM" => 6, # Non-Spacing Mark
367 "CS" => 7, # Common Number Separator
368 "ES" => 8, # European Number Separator
369 "ET" => 9, # European Number Terminator
370 "BN" => 10, # Boundary Neutral
371 "S" => 11, # Segment Separator
372 "WS" => 12, # Whitespace
373 "B" => 13, # Paragraph Separator
374 "RLO" => 14, # Right-to-Left Override
375 "RLE" => 15, # Right-to-Left Embedding
376 "LRO" => 16, # Left-to-Right Override
377 "LRE" => 17, # Left-to-Right Embedding
378 "PDF" => 18, # Pop Directional Format
379 "LRI" => 19, # Left-to-Right Isolate
380 "RLI" => 20, # Right-to-Left Isolate
381 "FSI" => 21, # First Strong Isolate
382 "PDI" => 22 # Pop Directional Isolate
387 "U" => 0, # Non_Joining
388 "T" => 1, # Transparent
389 "R" => 2, # Right_Joining
390 "L" => 3, # Left_Joining
391 "D" => 4, # Dual_Joining
392 "C" => 5, # Join_Causing
399 my @tolower_table = ();
400 my @toupper_table = ();
401 my @digitmap_table = ();
402 my @category_table = ();
403 my @joining_table = ();
404 my @direction_table = ();
405 my @decomp_table = ();
406 my @compose_table = ();
407 my @combining_class_table = ();
408 my @decomp_compat_table = ();
423 return $ch if ($ch < 0x10000);
425 return ( 0xd800 | ($ch >> 10), 0xdc00 | ($ch & 0x3ff) );
428 ################################################################
429 # fetch a unicode.org file and open it
430 sub open_data_file
($$)
432 my ($base, $name) = @_;
433 (my $dir = "data/$name") =~ s
/\
/[^\/]+$//;
435 unless (-f
"data/$name")
437 system "mkdir", "-p", $dir;
438 if ($base =~ /.*\/([^\
/]+\.zip)$/)
441 unless (-f
"data/$zip")
443 print "Fetching $base...\n";
444 !system "wget", "-q", "-O", "data/$zip", "$base" or die "cannot fetch $base";
446 !system "unzip", "-q", "-d", "data", "data/$zip", $name or die "cannot extract $name from $zip";
450 print "Fetching $base/$name...\n";
451 !system "wget", "-q", "-O", "data/$name", "$base/$name" or die "cannot fetch $base/$name";
454 open FILE
, "<data/$name" or die "cannot open data/$name";
458 ################################################################
459 # recursively get the decomposition for a character
460 sub get_decomposition
($$);
461 sub get_decomposition
($$)
463 my ($char, $table) = @_;
466 return get_utf16
($char) unless defined ${$table}[$char];
467 foreach my $ch (@
{${$table}[$char]})
469 push @ret, get_decomposition
( $ch, $table );
474 ################################################################
475 # recursively build decompositions
476 sub build_decompositions
(@
)
481 for (my $i = 0; $i < 65536; $i++)
483 next unless defined $src[$i];
484 my @decomp = get_decomposition
( $i, \
@src );
490 ################################################################
491 # read in the Unicode database files
496 # now build mappings from the decomposition field of the Unicode database
498 my $UNICODE_DATA = open_data_file
( $UNIDATA, "UnicodeData.txt" );
499 while (<$UNICODE_DATA>)
501 # Decode the fields ...
502 my ($code, $name, $cat, $comb, $bidi,
503 $decomp, $dec, $dig, $num, $mirror,
504 $oldname, $comment, $upper, $lower, $title) = split /;/;
508 die "unknown category $cat" unless defined $categories{$cat};
509 die "unknown directionality $bidi" unless defined $directions{$bidi};
511 $category_table[$src] = $categories{$cat};
512 $direction_table[$src] = $bidi;
513 $joining_table[$src] = $joining_types{"T"} if $cat eq "Mn" || $cat eq "Me" || $cat eq "Cf";
517 $tolower_table[$src] = hex $lower;
521 $toupper_table[$src] = hex $upper;
525 $category_table[$src] |= $ctype{"digit"};
529 $digitmap_table[$src] = ord $dig;
533 $combining_class_table[$src] = $comb;
536 # copy the category and direction for everything between First/Last pairs
537 if ($name =~ /, First>/) { $start = $src; }
538 if ($name =~ /, Last>/)
540 while ($start < $src)
542 $category_table[$start] = $category_table[$src];
543 $direction_table[$start] = $direction_table[$src];
548 next if $decomp eq ""; # no decomposition, skip it
550 if ($decomp =~ /^<([a-zA-Z]+)>\s+([0-9a-fA-F]+)/)
552 my @seq = map { hex $_; } (split /\s+/, (split /\s+/, $decomp, 2)[1]);
553 $decomp_compat_table[$src] = \
@seq;
556 if ($decomp =~ /^<([a-zA-Z]+)>\s+([0-9a-fA-F]+)$/)
558 # decomposition of the form "<foo> 1234" -> use char if type is known
559 if ($1 eq "isolated" || $1 eq "final" || $1 eq "initial" || $1 eq "medial")
561 ${joining_forms
{$1}}[hex $2] = $src;
564 next unless ($1 eq "font" ||
575 elsif ($decomp =~ /^<compat>\s+0020\s+([0-9a-fA-F]+)/)
577 # decomposition "<compat> 0020 1234" -> combining accent
580 elsif ($decomp =~ /^([0-9a-fA-F]+)/)
582 # decomposition contains only char values without prefix -> use first char
584 $category_table[$src] |= $category_table[$dst] if defined $category_table[$dst];
585 # store decomposition if it contains two chars
586 if ($decomp =~ /^([0-9a-fA-F]+)\s+([0-9a-fA-F]+)$/)
588 $decomp_table[$src] = $decomp_compat_table[$src] = [ hex $1, hex $2 ];
589 push @compose_table, [ hex $1, hex $2, $src ];
591 elsif ($decomp =~ /^([0-9a-fA-F]+)$/)
593 # Single char decomposition
594 $decomp_table[$src] = $decomp_compat_table[$src] = [ hex $1 ];
604 # patch the category of some special characters
606 foreach my $cat (keys %special_categories)
608 my $flag = $ctype{$cat};
609 foreach my $i (@
{$special_categories{$cat}}) { $category_table[$i] |= $flag; }
612 # remove case mappings that don't round-trip
614 for (my $i = 0; $i < @toupper_table; $i++)
616 next unless defined $toupper_table[$i];
617 my $ch = $toupper_table[$i];
618 $toupper_table[$i] = undef unless defined $tolower_table[$ch] && $tolower_table[$ch] == $i;
620 for (my $i = 0; $i < @tolower_table; $i++)
622 next unless defined $tolower_table[$i];
623 my $ch = $tolower_table[$i];
624 $tolower_table[$i] = undef unless defined $toupper_table[$ch] && $toupper_table[$ch] == $i;
629 ################################################################
630 # define a new lead byte
634 return if defined $cp2uni[$ch];
635 push @lead_bytes, $ch;
639 ################################################################
640 # define a new char mapping
644 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
645 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
646 if ($cp > 0xff) { add_lead_byte
( $cp >> 8 ); }
649 ################################################################
650 # get a mapping including glyph chars for MB_USEGLYPHCHARS
651 sub get_glyphs_mapping
(@
)
655 for (my $i = 0; $i < @glyph2uni; $i++)
657 $table[$i] = $glyph2uni[$i] if defined $glyph2uni[$i];
662 ################################################################
663 # build EUC-JP table from the JIS 0208/0212 files
664 sub output_eucjp_codepage
($$)
666 my ($dir, $comment) = @_;
668 $default_char = $DEF_CHAR;
669 $default_wchar = 0x30fb;
672 foreach my $i (0x00 .. 0x7f) { add_mapping
( $i, $i ); }
675 foreach my $i (0x8e, 0xa1 .. 0xfe) { add_lead_byte
($i); }
677 # JIS X 0201 right plane
678 foreach my $i (0xa1 .. 0xdf) { add_mapping
( 0x8e00 + $i, 0xfec0 + $i ); }
681 foreach my $i (0x80 .. 0x8d, 0x8f .. 0x9f) { $cp2uni[$i] = $i; }
682 $cp2uni[0xa0] = 0xf8f0;
683 $cp2uni[0xff] = 0xf8f3;
685 # Fix backslash conversion
686 add_mapping
( 0xa1c0, 0xff3c );
688 # Add private mappings for rows undefined in JIS 0208/0212
689 my $private = 0xe000;
690 foreach my $hi (0xf5 .. 0xfe)
692 foreach my $lo (0xa1 .. 0xfe)
694 add_mapping
( ($hi << 8) + $lo, $private++ );
697 foreach my $hi (0xf5 .. 0xfe)
699 foreach my $lo (0x21 .. 0x7e)
701 add_mapping
( ($hi << 8) + $lo, $private++ );
705 my $name = "$dir/JIS0208.TXT";
706 my $INPUT = open_data_file
( $MAPPINGS, $name );
709 next if /^\#/; # skip comments
710 next if /^$/; # skip empty lines
711 next if /\x1a/; # skip ^Z
712 if (/^0x[0-9a-fA-F]+\s+0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
714 add_mapping
( 0x8080 + hex $1, hex $2 );
717 die "$name: Unrecognized line $_\n";
721 $name = "$dir/JIS0212.TXT";
722 $INPUT = open_data_file
( $MAPPINGS, $name );
725 next if /^\#/; # skip comments
726 next if /^$/; # skip empty lines
727 next if /\x1a/; # skip ^Z
728 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
730 add_mapping
( 0x8000 + hex $1, hex $2 );
733 die "$name: Unrecognized line $_\n";
737 output_codepage_file
( 20932, "$MAPPINGS/$dir", $comment );
741 ################################################################
742 # build the sort keys table
745 my $filename = shift;
748 my $INPUT = open_data_file
( $REPORTS, $SORTKEYS );
751 next if /^\#/; # skip comments
752 next if /^$/; # skip empty lines
753 next if /\x1a/; # skip ^Z
754 next if /^\@version/; # skip @version header
755 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]+)\]/)
757 my ($uni,$variable) = (hex $1, $2);
758 next if $uni > 65535;
759 $sortkeys[$uni] = [ $uni, hex $3, hex $4, hex $5, hex $6 ];
762 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]+)\]/)
764 # multiple character sequence, ignored for now
767 die "$SORTKEYS: Unrecognized line $_\n";
771 # compress the keys to 32 bit:
772 # key 1 to 16 bits, key 2 to 8 bits, key 3 to 4 bits, key 4 to 1 bit
774 @sortkeys = sort { ${$a}[1] <=> ${$b}[1] or
775 ${$a}[2] <=> ${$b}[2] or
776 ${$a}[3] <=> ${$b}[3] or
777 ${$a}[4] <=> ${$b}[4] or
778 $a cmp $b; } @sortkeys;
780 my ($n2, $n3) = (1, 1);
781 my @keys = (-1, -1, -1, -1, -1 );
784 for (my $i = 0; $i < @sortkeys; $i++)
786 next unless defined $sortkeys[$i];
787 my @current = @
{$sortkeys[$i]};
788 if ($current[1] == $keys[1])
790 if ($current[2] == $keys[2])
792 if ($current[3] == $keys[3])
798 $keys[3] = $current[3];
805 $keys[2] = $current[2];
806 $keys[3] = $current[3];
814 $keys[1] = $current[1];
815 $keys[2] = $current[2];
816 $keys[3] = $current[3];
821 if ($current[2]) { $current[2] = $n2; }
822 if ($current[3]) { $current[3] = $n3; }
823 if ($current[4]) { $current[4] = 1; }
825 $flatkeys[$current[0]] = ($current[1] << 16) | ($current[2] << 8) | ($current[3] << 4) | $current[4];
828 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
829 printf "Building $filename\n";
830 printf OUTPUT
"/* Unicode collation element table */\n";
831 printf OUTPUT
"/* generated from %s */\n", "$REPORTS/$SORTKEYS";
832 printf OUTPUT
"/* DO NOT EDIT!! */\n\n";
833 print OUTPUT
"#include \"windef.h\"\n\n";
835 dump_two_level_mapping
( "collation_table", 0xffffffff, 32, @flatkeys );
838 save_file
($filename);
842 ################################################################
843 # dump an array of integers
846 my ($bit_width, $default, @array) = @_;
847 my $format = sprintf "0x%%0%ux", $bit_width / 4;
850 for ($i = 0; $i < $#array; $i++)
852 $ret .= sprintf($format, defined $array[$i] ?
$array[$i] : $default);
853 $ret .= (($i % 8) != 7) ?
", " : ",\n ";
855 $ret .= sprintf($format, defined $array[$i] ?
$array[$i] : $default);
860 ################################################################
861 # dump a unicode->ascii mapping table
862 sub dump_uni2cp_table
($$)
864 my ($width, $def) = @_;
866 # count the number of unicode->ascii subtables that contain something
871 my @filled = (-1) x
256;
872 for (my $i = 0; $i < 65536; $i++)
874 next unless defined $uni2cp[$i];
875 if ($filled[$i >> 8] == -1)
877 $lowerbounds[$index] = $i & 0xff;
878 $upperbounds[$index] = 0xff - $lowerbounds[$index];
879 $filled[$i >> 8] = $index * 256;
884 $upperbounds[$index-1] = 0xff - ($i & 0xff);
888 # add defaults mapping at the end
889 $filled[256] = $index * 256;
890 $lowerbounds[$index] = 255;
891 $upperbounds[$index] = 0;
894 # collapse blocks upwards if possible
897 for (my $i = 0; $i < 257; $i++)
899 next if $filled[$i] == -1;
900 if ($upperbounds[$index - 1] > $lowerbounds[$index])
902 $removed += $lowerbounds[$index];
906 $removed += $upperbounds[$index - 1];
907 $lowerbounds[$index] = $upperbounds[$index - 1];
909 $filled[$i] -= $removed;
913 # output all the subtables into a single array
915 printf OUTPUT
"static const unsigned %s uni2cp_low[] =\n{\n", $width == 8 ?
"char" : "short";
917 for (my $i = $index = 0; $i < 257; $i++)
919 next if $filled[$i] == -1;
920 my $start = ($i << 8) + $lowerbounds[$index];
921 my $end = ($i << 8) + 255;
924 print OUTPUT
" /* defaults */\n";
925 printf OUTPUT
"%s\n};\n\n", dump_array
( $width, 0, ($def) x
($end - $start + 1) );
929 printf OUTPUT
" /* 0x%04x .. 0x%04x */\n", $start, $end;
930 printf OUTPUT
"%s,\n", dump_array
( $width, $def, @uni2cp[$start .. $end] );
935 # output a table of the offsets of the subtables in the previous array
937 for (my $i = 0; $i < 256; $i++)
939 if ($filled[$i] == -1) { $filled[$i] = $filled[256]; }
941 printf OUTPUT
"static const unsigned short uni2cp_high[256] =\n";
942 printf OUTPUT
"{\n%s\n};\n\n", dump_array
( 16, 0, @filled[0..255] );
945 ################################################################
946 # dump an SBCS mapping table
947 sub dump_sbcs_table
($$$$)
949 my ($codepage, $name, $def, $defw) = @_;
952 # output the ascii->unicode table
956 printf OUTPUT
"static const WCHAR cp2uni[512] =\n";
957 printf OUTPUT
"{\n%s", dump_array
( 16, $defw, @cp2uni[0 .. 255] );
958 printf OUTPUT
",\n /* glyphs */\n%s\n};\n\n",
959 dump_array
( 16, $defw, get_glyphs_mapping
(@cp2uni[0 .. 255]) );
963 printf OUTPUT
"static const WCHAR cp2uni[256] =\n";
964 printf OUTPUT
"{\n%s\n};\n\n", dump_array
( 16, $defw, @cp2uni[0 .. 255] );
967 dump_uni2cp_table
( 8, $def );
969 # output the code page descriptor
971 printf OUTPUT
"const struct sbcs_table DECLSPEC_HIDDEN cptable_%03d =\n{\n", $codepage;
972 printf OUTPUT
" { %d, 1, 0x%04x, 0x%04x, \"%s\" },\n",
973 $codepage, $def, $defw, $name;
974 printf OUTPUT
" cp2uni,\n";
975 if (@glyph2uni) { printf OUTPUT
" cp2uni + 256,\n"; }
976 else { printf OUTPUT
" cp2uni,\n"; }
977 printf OUTPUT
" uni2cp_low,\n";
978 printf OUTPUT
" uni2cp_high\n};\n";
982 ################################################################
983 # dump a DBCS mapping table
984 sub dump_dbcs_table
($$$$@
)
986 my ($codepage, $name, $def, $defw, @lb_ranges) = @_;
988 # build a list of lead bytes that are actually used
991 LBLOOP
: for (my $y = 0; $y <= $#lead_bytes; $y++)
993 $cp2uni[$lead_bytes[$y]] = $defw;
994 my $base = $lead_bytes[$y] << 8;
995 for (my $x = 0; $x < 256; $x++)
997 if (defined $cp2uni[$base+$x])
999 push @lblist,$lead_bytes[$y];
1004 my $unused = ($#lead_bytes > $#lblist);
1006 # output the ascii->unicode table for the single byte chars
1008 printf OUTPUT
"static const WCHAR cp2uni[%d] =\n", 256 * ($#lblist + 2 + $unused);
1009 printf OUTPUT
"{\n%s,\n", dump_array
( 16, $defw, @cp2uni[0 .. 255] );
1011 # output the default table for unused lead bytes
1015 printf OUTPUT
" /* unused lead bytes */\n";
1016 printf OUTPUT
"%s,\n", dump_array
( 16, 0, ($defw) x
256 );
1019 # output the ascii->unicode table for each DBCS lead byte
1021 for (my $y = 0; $y <= $#lblist; $y++)
1023 my $base = $lblist[$y] << 8;
1024 printf OUTPUT
" /* lead byte %02x */\n", $lblist[$y];
1025 printf OUTPUT
"%s", dump_array
( 16, $defw, @cp2uni[$base .. $base+255] );
1026 printf OUTPUT
($y < $#lblist) ?
",\n" : "\n};\n\n";
1029 # output the lead byte subtables offsets
1031 my @offsets = (0) x
256;
1032 for (my $x = 0; $x <= $#lblist; $x++) { $offsets[$lblist[$x]] = $x + 1; }
1035 # increment all lead bytes offset to take into account the unused table
1036 for (my $x = 0; $x <= $#lead_bytes; $x++) { $offsets[$lead_bytes[$x]]++; }
1038 printf OUTPUT
"static const unsigned char cp2uni_leadbytes[256] =\n";
1039 printf OUTPUT
"{\n%s\n};\n\n", dump_array
( 8, 0, @offsets );
1041 dump_uni2cp_table
( 16, $def );
1043 # output the code page descriptor
1045 printf OUTPUT
"const struct dbcs_table DECLSPEC_HIDDEN cptable_%03d =\n{\n", $codepage;
1046 printf OUTPUT
" { %d, 2, 0x%04x, 0x%04x, \"%s\" },\n",
1047 $codepage, $def, $defw, $name;
1048 printf OUTPUT
" cp2uni,\n";
1049 printf OUTPUT
" cp2uni_leadbytes,\n";
1050 printf OUTPUT
" uni2cp_low,\n";
1051 printf OUTPUT
" uni2cp_high,\n";
1052 printf OUTPUT
" {\n %s\n }\n", dump_array
( 8, 0, @lb_ranges, 0, 0 );
1053 printf OUTPUT
"};\n";
1057 ################################################################
1058 # dump an SBCS mapping table in binary format
1059 sub dump_binary_sbcs_table
($)
1061 my $codepage = shift;
1063 my @header = ( 13, $codepage, 1, $default_char, $default_wchar, $cp2uni[$default_char], $uni2cp[$default_wchar] );
1064 my $wc_offset = 256 + 3 + (@glyph2uni ?
256 : 0);
1066 print OUTPUT
pack "S<*", @header;
1067 print OUTPUT
pack "C12", (0) x
12;
1068 print OUTPUT
pack "S<*", $wc_offset, map { $_ || 0; } @cp2uni[0 .. 255];
1072 print OUTPUT
pack "S<*", 256, get_glyphs_mapping
(@cp2uni[0 .. 255]);
1076 print OUTPUT
pack "S<*", 0;
1079 print OUTPUT
pack "S<*", 0, 0;
1081 print OUTPUT
pack "C*", map { defined $_ ?
$_ : $default_char; } @uni2cp[0 .. 65535];
1085 ################################################################
1086 # dump a DBCS mapping table in binary format
1087 sub dump_binary_dbcs_table
($)
1089 my $codepage = shift;
1090 my @lb_ranges = get_lb_ranges
();
1091 my @header = ( 13, $codepage, 2, $default_char, $default_wchar, $cp2uni[$default_char], $uni2cp[$default_wchar] );
1093 my @offsets = (0) x
256;
1095 foreach my $i (@lead_bytes)
1097 $offsets[$i] = ($pos += 256);
1101 my $wc_offset = 256 + 3 + 256 * (1 + scalar @lead_bytes);
1103 print OUTPUT
pack "S<*", @header;
1104 print OUTPUT
pack "C12", @lb_ranges, 0 x
12;
1105 print OUTPUT
pack "S<*", $wc_offset, map { $_ || 0; } @cp2uni[0 .. 255];
1106 print OUTPUT
pack "S<*", 0, scalar @lb_ranges / 2, @offsets;
1108 foreach my $i (@lead_bytes)
1111 print OUTPUT
pack "S<*", map { defined $_ ?
$_ : $default_wchar; } @cp2uni[$base .. $base + 255];
1114 print OUTPUT
pack "S<", 4;
1115 print OUTPUT
pack "S<*", map { defined $_ ?
$_ : $default_char; } @uni2cp[0 .. 65535];
1119 ################################################################
1120 # get the list of defined lead byte ranges
1126 foreach my $i (@lead_bytes) { $list[$i] = 1; }
1128 for (my $i = 0; $i < 256; $i++)
1132 if (!defined $list[$i]) { push @ranges, $i-1; $on = 0; }
1136 if ($list[$i]) { push @ranges, $i; $on = 1; }
1139 if ($on) { push @ranges, 0xff; }
1143 ################################################################
1144 # dump the Indic Syllabic Category table
1147 my $filename = shift;
1150 my $INPUT = open_data_file
( $UNIDATA, "IndicSyllabicCategory.txt" );
1153 next if /^\#/; # skip comments
1154 next if /^\s*$/; # skip empty lines
1155 next if /\x1a/; # skip ^Z
1156 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*#/)
1159 die "unknown indic $type" unless defined $indic_types{$type};
1162 $indic_table[hex $1] = $indic_types{$type};
1166 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*#/)
1169 die "unknown indic $type" unless defined $indic_types{$type};
1170 if (hex $1 < 65536 and hex $2 < 65536)
1172 foreach my $i (hex $1 .. hex $2)
1174 $indic_table[$i] = $indic_types{$type};
1179 die "malformed line $_";
1183 $INPUT = open_data_file
( $UNIDATA, "IndicPositionalCategory.txt" );
1186 next if /^\#/; # skip comments
1187 next if /^\s*$/; # skip empty lines
1188 next if /\x1a/; # skip ^Z
1189 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z]+)\s*#/)
1192 die "unknown matra $type" unless defined $matra_types{$type};
1193 $indic_table[hex $1] += $matra_types{$type} << 8;
1196 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*#/)
1199 die "unknown matra $type" unless defined $matra_types{$type};
1200 foreach my $i (hex $1 .. hex $2)
1202 $indic_table[$i] += $matra_types{$type} << 8;
1206 die "malformed line $_";
1210 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1211 print "Building $filename\n";
1212 print OUTPUT
"/* Unicode Indic Syllabic Category */\n";
1213 print OUTPUT
"/* generated from $UNIDATA:IndicSyllabicCategory.txt */\n";
1214 print OUTPUT
"/* and from $UNIDATA:IndicPositionalCategory.txt */\n";
1215 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1216 print OUTPUT
"#include \"windef.h\"\n\n";
1218 dump_two_level_mapping
( "indic_syllabic_table", $indic_types{'Other'}, 16, @indic_table );
1221 save_file
($filename);
1224 ################################################################
1225 # dump the Line Break Properties table
1226 sub dump_linebreak
($)
1228 my $filename = shift;
1232 my $INPUT = open_data_file
( $UNIDATA, "LineBreak.txt" );
1235 next if /^\#/; # skip comments
1236 next if /^\s*$/; # skip empty lines
1237 next if /\x1a/; # skip ^Z
1238 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z][0-9A-Z])+\s*/)
1241 die "unknown breaktype $type" unless defined $break_types{$type};
1242 $break_table[hex $1] = $break_types{$type};
1245 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z][0-9A-Z])+\s*/)
1248 die "unknown breaktype $type" unless defined $break_types{$type};
1249 foreach my $i (hex $1 .. hex $2)
1251 $break_table[$i] = $break_types{$type};
1255 elsif (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z])+\s*/)
1258 die "unknown breaktype $type" unless defined $break_types{$type};
1259 $break_table[hex $1] = $break_types{$type};
1262 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z])+\s*/)
1265 die "unknown breaktype $type" unless defined $break_types{$type};
1266 foreach my $i (hex $1 .. hex $2)
1268 $break_table[$i] = $break_types{$type};
1272 die "malformed line $_";
1276 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1277 print "Building $filename\n";
1278 print OUTPUT
"/* Unicode Line Break Properties */\n";
1279 print OUTPUT
"/* generated from $UNIDATA:LineBreak.txt */\n";
1280 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1281 print OUTPUT
"#include \"windef.h\"\n\n";
1283 dump_two_level_mapping
( "wine_linebreak_table", $break_types{'XX'}, 16, @break_table );
1286 save_file
($filename);
1306 "Canadian_Aboriginal" => 15,
1316 "Egyptian_Hieroglyphs" => 25,
1329 "Imperial_Aramaic" => 38,
1330 "Inscriptional_Pahlavi" => 39,
1331 "Inscriptional_Parthian" => 40,
1349 "Meetei_Mayek" => 58,
1352 "New_Tai_Lue" => 61,
1357 "Old_Persian" => 66,
1358 "Old_South_Arabian" => 67,
1371 "Syloti_Nagri" => 80,
1389 "Meroitic_Cursive" => 97,
1390 "Meroitic_Hieroglyphs" => 98,
1393 "Sora_Sompeng" => 101,
1397 "Caucasian_Albanian" => 104,
1405 "Manichaean" => 112,
1406 "Mende_Kikakui" => 113,
1410 "Old_North_Arabian" => 117,
1411 "Old_Permic" => 118,
1412 "Pahawh_Hmong" => 119,
1414 "Pau_Cin_Hau" => 121,
1415 "Psalter_Pahlavi" => 122,
1418 "Warang_Citi" => 125,
1422 "Anatolian_Hieroglyphs" => 128,
1428 "Old_Hungarian" => 134,
1430 "SignWriting" => 136,
1433 "Masaram_Gondi" => 138,
1436 "Zanabazar_Square" => 141,
1439 "Gunjala_Gondi" => 143,
1440 "Hanifi_Rohingya" => 144,
1442 "Medefaidrin" => 146,
1443 "Old_Sogdian" => 147,
1447 ################################################################
1448 # dump Script IDs table
1451 my $filename = shift;
1452 my $header = $filename;
1457 my $INPUT = open_data_file
( $UNIDATA, "Scripts.txt" );
1459 # Unknown script id is always 0, so undefined scripts are automatically treated as such
1464 next if /^\#/; # skip comments
1465 next if /^\s*$/; # skip empty lines
1466 next if /\x1a/; # skip ^Z
1467 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1470 if (defined $scripts{$type})
1472 $scripts_table[hex $1] = $scripts{$type};
1476 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1479 if (defined $scripts{$type})
1481 foreach my $i (hex $1 .. hex $2)
1483 $scripts_table[$i] = $scripts{$type};
1492 $header = "$filename.h";
1493 open OUTPUT
,">$header.new" or die "Cannot create $header";
1494 print "Building $header\n";
1495 print OUTPUT
"/* Unicode Script IDs */\n";
1496 print OUTPUT
"/* generated from $UNIDATA:Scripts.txt */\n";
1497 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1499 print OUTPUT
"enum unicode_script_id {\n";
1500 foreach my $script (sort { $scripts{$a} <=> $scripts{$b} } keys %scripts)
1502 print OUTPUT
" Script_$script = $scripts{$script},\n";
1504 print OUTPUT
" Script_LastId = ", (scalar keys %scripts) - 1, "\n";
1505 print OUTPUT
"};\n";
1510 $filename = "$filename.c";
1511 open OUTPUT
,">$filename.new" or die "Cannot create $header";
1512 print "Building $filename\n";
1513 print OUTPUT
"/* Unicode Script IDs */\n";
1514 print OUTPUT
"/* generated from $UNIDATA:Scripts.txt */\n";
1515 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1516 print OUTPUT
"#include \"windef.h\"\n\n";
1518 dump_two_level_mapping
( "wine_scripts_table", 0, 16, @scripts_table );
1520 save_file
($filename);
1523 ################################################################
1524 # dump the BiDi mirroring table
1525 sub dump_mirroring
($)
1527 my $filename = shift;
1528 my @mirror_table = ();
1530 my $INPUT = open_data_file
( $UNIDATA, "BidiMirroring.txt" );
1533 next if /^\#/; # skip comments
1534 next if /^$/; # skip empty lines
1535 next if /\x1a/; # skip ^Z
1536 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9a-fA-F]+)/)
1538 $mirror_table[hex $1] = hex $2;
1541 die "malformed line $_";
1545 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1546 print "Building $filename\n";
1547 print OUTPUT
"/* Unicode BiDi mirroring */\n";
1548 print OUTPUT
"/* generated from $UNIDATA:BidiMirroring.txt */\n";
1549 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1550 print OUTPUT
"#include \"windef.h\"\n\n";
1551 dump_two_level_mapping
( "wine_mirror_map", 0, 16, @mirror_table );
1553 save_file
($filename);
1556 ################################################################
1557 # dump the Bidi Brackets
1560 my $filename = shift;
1563 my $INPUT = open_data_file
( $UNIDATA, "BidiBrackets.txt" );
1566 next if /^\#/; # skip comments
1567 next if /^\s*$/; # skip empty lines
1568 next if /\x1a/; # skip ^Z
1569 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9a-fA-F]+);\s*([con])/)
1572 die "unknown bracket $type" unless defined $bracket_types{$type};
1573 die "characters too distant $1 and $2" if abs(hex($2) - hex($1)) >= 128;
1574 $bracket_table[hex $1] = (hex($2) - hex($1)) % 255;
1575 $bracket_table[hex $1] += $bracket_types{$type} << 8;
1578 die "malformed line $_";
1582 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1583 print "Building $filename\n";
1584 print OUTPUT
"/* Unicode Bidirectional Bracket table */\n";
1585 print OUTPUT
"/* generated from $UNIDATA:BidiBrackets.txt */\n";
1586 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1587 print OUTPUT
"#include \"windef.h\"\n\n";
1589 dump_two_level_mapping
( "bidi_bracket_table", 0, 16, @bracket_table );
1592 save_file
($filename);
1595 ################################################################
1596 # dump the Arabic shaping table
1599 my $filename = shift;
1603 $groups{"No_Joining_Group"} = $next_group++;
1605 my $INPUT = open_data_file
( $UNIDATA, "ArabicShaping.txt" );
1608 next if /^\#/; # skip comments
1609 next if /^\s*$/; # skip empty lines
1610 next if /\x1a/; # skip ^Z
1611 if (/^\s*([0-9a-fA-F]+)\s*;.*;\s*([RLDCUT])\s*;\s*(\w+)/)
1615 $groups{$group} = $next_group++ unless defined $groups{$group};
1616 $joining_table[hex $1] = $joining_types{$type} | ($groups{$group} << 8);
1619 die "malformed line $_";
1623 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1624 print "Building $filename\n";
1625 print OUTPUT
"/* Unicode Arabic shaping */\n";
1626 print OUTPUT
"/* generated from $UNIDATA:ArabicShaping.txt */\n";
1627 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1628 print OUTPUT
"#include \"windef.h\"\n\n";
1630 dump_two_level_mapping
( "wine_shaping_table", 0, 16, @joining_table );
1632 print OUTPUT
"\nconst unsigned short DECLSPEC_HIDDEN wine_shaping_forms[256][4] =\n{\n";
1633 for (my $i = 0x600; $i <= 0x6ff; $i++)
1635 printf OUTPUT
" { 0x%04x, 0x%04x, 0x%04x, 0x%04x },\n",
1636 ${joining_forms
{"isolated"}}[$i] || $i,
1637 ${joining_forms
{"final"}}[$i] || $i,
1638 ${joining_forms
{"initial"}}[$i] || $i,
1639 ${joining_forms
{"medial"}}[$i] || $i;
1641 print OUTPUT
"};\n";
1644 save_file
($filename);
1647 ################################################################
1648 # dump the Vertical Orientation table
1649 sub dump_vertical
($)
1651 my $filename = shift;
1654 my $INPUT = open_data_file
( $UNIDATA, "VerticalOrientation.txt" );
1657 next if /^\#/; # skip comments
1658 next if /^\s*$/; # skip empty lines
1659 next if /\x1a/; # skip ^Z
1660 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1663 die "unknown vertical $type" unless defined $vertical_types{$type};
1666 $vertical_table[hex $1] = $vertical_types{$type};
1670 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*/)
1673 die "unknown vertical $type" unless defined $vertical_types{$type};
1674 foreach my $i (hex $1 .. hex $2)
1676 $vertical_table[$i] = $vertical_types{$type};
1680 die "malformed line $_";
1684 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1685 print "Building $filename\n";
1686 print OUTPUT
"/* Unicode Vertical Orientation */\n";
1687 print OUTPUT
"/* generated from $UNIDATA:VerticalOrientation.txt */\n";
1688 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1689 print OUTPUT
"#include \"windef.h\"\n\n";
1691 dump_two_level_mapping
( "vertical_orientation_table", $vertical_types{'R'}, 16, @vertical_table );
1694 save_file
($filename);
1697 ################################################################
1698 # dump the digit folding tables
1699 sub dump_digit_folding
($)
1701 my ($filename) = shift;
1702 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1703 print "Building $filename\n";
1704 print OUTPUT
"/* Unicode digit folding mappings */\n";
1705 print OUTPUT
"/* generated from $UNIDATA:UnicodeData.txt */\n";
1706 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1707 print OUTPUT
"#include \"windef.h\"\n\n";
1709 dump_two_level_mapping
( "wine_digitmap", 0, 16, @digitmap_table );
1711 save_file
($filename);
1715 ################################################################
1716 # dump the case mapping tables
1717 sub dump_case_mappings
($)
1719 my $filename = shift;
1720 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1721 print "Building $filename\n";
1722 print OUTPUT
"/* Unicode case mappings */\n";
1723 print OUTPUT
"/* generated from $UNIDATA:UnicodeData.txt */\n";
1724 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1725 print OUTPUT
"#include \"windef.h\"\n\n";
1727 dump_case_table
( "wine_casemap_lower", @tolower_table );
1729 dump_case_table
( "wine_casemap_upper", @toupper_table );
1731 save_file
($filename);
1735 ################################################################
1736 # dump a case mapping table
1737 sub dump_case_table
($@
)
1739 my ($name,@table) = @_;
1741 # count the number of sub tables that contain something
1742 # also compute the low and upper populated bounds
1744 my @lowerbounds = ( 0, 0 );
1745 my @upperbounds = ( 0, 255 );
1748 for (my $i = 0; $i < 65536; $i++)
1750 next unless defined $table[$i];
1751 if (!defined $filled[$i >> 8])
1753 $lowerbounds[$index] = $i & 0xff;
1754 $upperbounds[$index] = 0xff - $lowerbounds[$index];
1755 $filled[$i >> 8] = $index * 256 + 512;
1760 $upperbounds[$index-1] = 0xff - ($i & 0xff);
1762 $table[$i] = ($table[$i] - $i) & 0xffff;
1765 # Collapse blocks upwards if possible
1768 for (my $i = 0; $i < 256; $i++)
1770 next unless defined $filled[$i];
1771 if ($upperbounds[$index - 1] > $lowerbounds[$index])
1773 $removed = $removed + $lowerbounds[$index];
1777 $removed = $removed + $upperbounds[$index - 1];
1778 $lowerbounds[$index] = $upperbounds[$index - 1];
1780 $filled[$i] = $filled[$i] - $removed;
1786 printf OUTPUT
"const WCHAR %s[%d] =\n", $name, $index * 256 + 512 - $removed;
1787 printf OUTPUT
"{\n /* index */\n";
1788 printf OUTPUT
"%s,\n", dump_array
( 16, 256, @filled );
1789 printf OUTPUT
" /* defaults */\n";
1790 printf OUTPUT
"%s", dump_array
( 16, 0, (0) x
256 );
1792 for (my $i = 0; $i < 256; $i++)
1794 next unless $filled[$i];
1795 printf OUTPUT
",\n /* 0x%02x%02x .. 0x%02xff */\n", $i, $lowerbounds[$index], $i;
1796 printf OUTPUT
"%s", dump_array
( 16, 0, @table[($i<<8) + $lowerbounds[$index] .. ($i<<8)+255] );
1799 printf OUTPUT
"\n};\n";
1802 ################################################################
1803 # compress a mapping table by removing identical rows
1804 sub compress_array
($$@
)
1809 my $len = @table / $rows;
1813 # try to merge table rows
1814 for (my $row = 0; $row < $rows; $row++)
1816 my $rowtxt = pack "U*", map { defined($_) ?
$_ : $def; } @table[($row * $len)..(($row + 1) * $len - 1)];
1817 my $pos = index $data, $rowtxt;
1820 # check if the tail of the data can match the start of the new row
1821 my $first = substr( $rowtxt, 0, 1 );
1822 for (my $i = length($data) - 1; $i > 0; $i--)
1824 $pos = index( substr( $data, -$i ), $first );
1827 next unless substr( $data, -$i ) eq substr( $rowtxt, 0, $i );
1828 substr( $data, -$i ) = "";
1831 $pos = length $data;
1834 $array[$row] = $rows + $pos;
1836 return @array, unpack "U*", $data;
1839 ################################################################
1840 # dump a simple char -> 16-bit value mapping table
1841 sub dump_simple_mapping
($$@
)
1845 my @array = compress_array
( 256, $def, @_[0..65535] );
1847 printf OUTPUT
"const unsigned short %s[%d] =\n{\n", $name, $#array+1;
1848 printf OUTPUT
" /* offsets */\n%s,\n", dump_array
( 16, 0, @array[0..255] );
1849 printf OUTPUT
" /* values */\n%s\n};\n", dump_array
( 16, 0, @array[256..$#array] );
1852 ################################################################
1853 # dump a char -> 16-bit value mapping table using two-level tables
1854 sub dump_two_level_mapping
($$@
)
1859 my $type = $size == 16 ?
"unsigned short" : "unsigned int";
1860 my @row_array = compress_array
( 4096, $def, @_[0..65535] );
1861 my @array = compress_array
( 256, 0, @row_array[0..4095] );
1863 for (my $i = 256; $i < @array; $i++) { $array[$i] += @array - 4096; }
1865 printf OUTPUT
"const %s DECLSPEC_HIDDEN %s[%d] =\n{\n", $type, $name, @array + @row_array - 4096;
1866 printf OUTPUT
" /* level 1 offsets */\n%s,\n", dump_array
( $size, 0, @array[0..255] );
1867 printf OUTPUT
" /* level 2 offsets */\n%s,\n", dump_array
( $size, 0, @array[256..$#array] );
1868 printf OUTPUT
" /* values */\n%s\n};\n", dump_array
( $size, 0, @row_array[4096..$#row_array] );
1871 ################################################################
1872 # dump a binary case mapping table in l_intl.nls format
1873 sub dump_binary_case_table
(@
)
1876 my $max_char = 0x10000;
1877 my $level1 = $max_char / 16;
1878 my $level2 = $level1 / 16;
1881 for (my $i = 0; $i < @table; $i++)
1883 next unless defined $table[$i];
1884 $difftable[$i] = ($table[$i] - $i) & 0xffff;
1887 my @row_array = compress_array
( $level1, 0, @difftable[0..$max_char-1] );
1888 my @array = compress_array
( $level2, 0, @row_array[0..$level1-1] );
1889 for (my $i = $level2; $i < @array; $i++) { $array[$i] += @array - $level1; }
1890 return @array, @row_array[$level1..$#row_array];
1894 ################################################################
1895 # dump case mappings for l_intl.nls
1896 sub dump_intl_nls
($)
1898 my @upper = dump_binary_case_table
( @toupper_table );
1899 my @lower = dump_binary_case_table
( @tolower_table );
1901 my $filename = shift;
1902 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1903 printf "Building $filename\n";
1906 print OUTPUT
pack "S<", 1; # version
1907 print OUTPUT
pack "S<*", 1 + scalar @upper, @upper;
1908 print OUTPUT
pack "S<*", 1 + scalar @lower, @lower;
1910 save_file
($filename);
1914 sub load_nameprep_range_table
($$$)
1916 my ($INPUT, $val, $table_ref) = @_;
1920 if (/^\s*([0-9a-fA-F]+)-([0-9a-fA-F]+)/)
1923 $last = 65535 if($last >= 65536);
1924 foreach my $i (hex $1 .. $last)
1926 $table_ref->[$i] |= $val;
1930 elsif (/^\s*([0-9a-fA-F]+)/)
1934 $table_ref->[hex $1] |= $val;
1939 return if (/End\sTable/);
1943 sub load_nameprep_map_table
($$)
1945 my ($INPUT, $table_ref) = @_;
1949 if (/^\s*([0-9a-fA-F]+);\s;/)
1951 # special value for map to nothing
1952 $table_ref->[hex $1] = [0xffff, 0xffff, 0xffff];
1955 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+);/)
1957 $table_ref->[hex $1] = [hex $2, 0, 0];
1960 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+)\s([0-9a-fA-F]+);/)
1962 $table_ref->[hex $1] = [hex $2, hex $3, 0];
1965 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+)\s([0-9a-fA-F]+)\s([0-9a-fA-F]+);/)
1967 $table_ref->[hex $1] = [hex $2, hex $3, hex $4];
1971 return if (/End\sTable/);
1975 ################################################################
1976 # dump mapping table, prohibited characters set, unassigned
1977 # characters, bidirectional rules used by nameprep algorithm
1978 sub dump_nameprep
($)
1980 my $filename = shift;
1981 my @mapping_table = ();
1984 my $INPUT = open_data_file
( $RFCS, $STRINGPREP );
1987 next unless /Start\sTable/;
1989 load_nameprep_range_table
($INPUT, $nameprep_flags{"unassigned"}, \
@flags_table) if (/A.1/);
1990 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.1.2/);
1991 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.2.2/);
1992 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.3/);
1993 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.4/);
1994 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.5/);
1995 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.6/);
1996 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.7/);
1997 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.8/);
1998 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.9/);
1999 load_nameprep_range_table
($INPUT, $nameprep_flags{"bidi_ral"}, \
@flags_table) if (/D.1/);
2000 load_nameprep_range_table
($INPUT, $nameprep_flags{"bidi_l"}, \
@flags_table) if (/D.2/);
2002 load_nameprep_map_table
($INPUT, \
@mapping_table) if (/B.1/);
2003 load_nameprep_map_table
($INPUT, \
@mapping_table) if (/B.2/);
2007 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2008 print "Building $filename\n";
2009 print OUTPUT
"/* Nameprep algorithm related data */\n";
2010 print OUTPUT
"/* generated from $RFCS/$STRINGPREP */\n";
2011 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
2012 print OUTPUT
"#include \"windef.h\"\n\n";
2014 dump_two_level_mapping
( "nameprep_char_type", 0, 16, @flags_table );
2016 ######### mapping table
2017 # first determine all the 16-char subsets that contain something
2019 my $pos = 16*3; # for the null subset
2020 for (my $i = 0; $i < 65536; $i++)
2022 next unless defined $mapping_table[$i];
2023 $filled[$i >> 4] = $pos;
2029 # now count the 256-char subsets that contain something
2030 my @filled_idx = (256) x
256;
2032 for (my $i = 0; $i < 4096; $i++)
2034 next unless $filled[$i];
2035 $filled_idx[$i >> 4] = $pos;
2039 my $null_offset = $pos;
2042 # add the index offsets to the subsets positions
2043 for (my $i = 0; $i < 4096; $i++)
2045 next unless $filled[$i];
2046 $filled[$i] += $null_offset;
2049 # dump the main index
2050 printf OUTPUT
"const unsigned short DECLSPEC_HIDDEN nameprep_mapping[%d] =\n", $total;
2051 printf OUTPUT
"{\n /* index */\n";
2052 printf OUTPUT
"%s", dump_array
( 16, 0, @filled_idx );
2053 printf OUTPUT
",\n /* null sub-index */\n%s", dump_array
( 16, 0, ($null_offset) x
16 );
2055 # dump the second-level indexes
2056 for (my $i = 0; $i < 256; $i++)
2058 next unless ($filled_idx[$i] > 256);
2059 my @table = @filled[($i<<4)..($i<<4)+15];
2060 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
2061 printf OUTPUT
",\n /* sub-index %02x */\n", $i;
2062 printf OUTPUT
"%s", dump_array
( 16, 0, @table );
2065 # dump the 16-char subsets
2066 printf OUTPUT
",\n /* null mapping */\n";
2067 printf OUTPUT
"%s", dump_array
( 16, 0, (0) x
48 );
2069 for (my $i = 0; $i < 4096; $i++)
2071 next unless $filled[$i];
2072 my @table = (0) x
48;
2073 for (my $j = 0; $j < 16; $j++)
2075 if (defined $mapping_table[($i<<4) + $j])
2077 $table[3 * $j] = ${$mapping_table[($i << 4) + $j]}[0];
2078 $table[3 * $j + 1] = ${$mapping_table[($i << 4) + $j]}[1];
2079 $table[3 * $j + 2] = ${$mapping_table[($i << 4) + $j]}[2];
2082 printf OUTPUT
",\n /* 0x%03x0 .. 0x%03xf */\n", $i, $i;
2083 printf OUTPUT
"%s", dump_array
( 16, 0, @table );
2086 printf OUTPUT
"\n};\n";
2089 save_file
($filename);
2093 ################################################################
2094 # dump the GetStringTypeW table
2095 sub dump_string_type_table
($)
2097 my $filename = shift;
2098 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2099 printf "Building $filename\n";
2100 printf OUTPUT
"/* Unicode wctype table */\n";
2101 printf OUTPUT
"/* Automatically generated; DO NOT EDIT!! */\n\n";
2102 printf OUTPUT
"#include \"windef.h\"\n\n";
2104 my @table = @category_table;
2106 # add the direction in the high 4 bits of the category
2107 for (my $i = 0; $i < 65536; $i++)
2109 $table[$i] |= $c2_types{$direction_table[$i]} << 12 if defined $direction_table[$i];
2112 dump_two_level_mapping
( "wctype_table", 0, 16, @table );
2115 save_file
($filename);
2119 ################################################################
2120 # dump the bidi direction table
2121 sub dump_bidi_dir_table
($)
2123 my $filename = shift;
2124 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2125 printf "Building $filename\n";
2126 printf OUTPUT
"/* Unicode BiDi direction table */\n";
2127 printf OUTPUT
"/* Automatically generated; DO NOT EDIT!! */\n\n";
2128 printf OUTPUT
"#include \"windef.h\"\n\n";
2132 for (my $i = 0; $i < 65536; $i++)
2134 $table[$i] = $bidi_types{$direction_table[$i]} if defined $direction_table[$i];
2137 dump_two_level_mapping
( "bidi_direction_table", $bidi_types{"L"}, 16, @table );
2140 save_file
($filename);
2144 ################################################################
2145 # dump the ctype tables
2146 sub dump_ctype_tables
($)
2148 my $filename = shift;
2149 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2150 printf "Building $filename\n";
2151 printf OUTPUT
"/* Unicode ctype tables */\n";
2152 printf OUTPUT
"/* Automatically generated; DO NOT EDIT!! */\n\n";
2153 printf OUTPUT
"#include \"windef.h\"\n\n";
2155 my @table = @category_table;
2157 # add the direction in the high 4 bits of the category
2158 for (my $i = 0; $i < 65536; $i++)
2160 $table[$i] |= $directions{$direction_table[$i]} << 12 if defined $direction_table[$i];
2163 dump_simple_mapping
( "wine_wctype_table", 0, @table );
2166 save_file
($filename);
2170 ################################################################
2171 # dump the char composition table
2172 sub dump_compose_table
($)
2174 my $filename = shift;
2176 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2177 print "Building $filename\n";
2178 print OUTPUT
"/* Unicode char composition */\n";
2179 print OUTPUT
"/* generated from $UNIDATA:UnicodeData.txt */\n";
2180 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
2181 print OUTPUT
"#include \"windef.h\"\n\n";
2184 foreach my $i (@compose_table)
2187 push @
{$filled[$comp[1]]}, [ $comp[0], $comp[2] ];
2190 # count how many different second chars we have
2193 for (my $i = 0; $i < 65536; $i++)
2195 next unless defined $filled[$i];
2199 # build the table of second chars and offsets
2201 my $pos = $count + 1;
2203 for (my $i = 0; $i < 65536; $i++)
2205 next unless defined $filled[$i];
2206 push @table, $i, $pos;
2207 $pos += @
{$filled[$i]};
2209 # terminator with last position
2210 push @table, 0, $pos;
2211 printf OUTPUT
"static const WCHAR table[0x%x] =\n{\n", 2*$pos;
2212 printf OUTPUT
" /* second chars + offsets */\n%s", dump_array
( 16, 0, @table );
2214 # build the table of first chars and mappings
2216 for (my $i = 0; $i < 65536; $i++)
2218 next unless defined $filled[$i];
2220 my @list = sort { $a->[0] <=> $b->[0] } @
{$filled[$i]};
2221 for (my $j = 0; $j <= $#list; $j++)
2223 push @table, $list[$j][0], $list[$j][1];
2225 printf OUTPUT
",\n /* 0x%04x */\n%s", $i, dump_array
( 16, 0, @table );
2227 print OUTPUT
"\n};\n\n";
2228 print OUTPUT
<<"EOF";
2229 static inline int binary_search( WCHAR ch, int low, int high )
2233 int pos = (low + high) / 2;
2234 if (table[2 * pos] < ch) low = pos + 1;
2235 else if (table[2 * pos] > ch) high = pos - 1;
2241 WCHAR DECLSPEC_HIDDEN wine_compose( const WCHAR *str )
2243 int pos, idx = 1, start = 0, count = $count;
2246 if ((pos = binary_search( str[idx], start, count - 1 )) == -1) return 0;
2247 if (!idx--) return table[2 * pos + 1];
2248 start = table[2 * pos + 1];
2249 count = table[2 * pos + 3];
2254 save_file
($filename);
2257 ################################################################
2258 # dump a decomposition table
2259 sub dump_decompositions
($@
)
2261 my ($name, @decomp) = @_;
2263 # first determine all the 16-char subsets that contain something
2265 my @filled = (0) x
4096;
2266 my $pos = 16; # for the null subset
2268 for (my $i = 0; $i < 65536; $i++)
2270 next unless defined $decomp[$i];
2271 if ($filled[$i >> 4] == 0)
2273 $filled[$i >> 4] = $pos;
2276 $data_total += @
{$decomp[$i]};
2280 # now count the 256-char subsets that contain something
2282 my @filled_idx = (256) x
256;
2284 for (my $i = 0; $i < 4096; $i++)
2286 next unless $filled[$i];
2287 $filled_idx[$i >> 4] = $pos;
2291 my $null_offset = $pos; # null mapping
2292 $total += $pos + 1; # add the offset sentinel
2294 # add the index offsets to the subsets positions
2296 for (my $i = 0; $i < 4096; $i++)
2298 next unless $filled[$i];
2299 $filled[$i] += $null_offset;
2302 # dump the main index
2304 printf OUTPUT
"\nconst WCHAR DECLSPEC_HIDDEN %s[%d] =\n", $name, $total + $data_total;
2305 printf OUTPUT
"{\n /* index */\n";
2306 printf OUTPUT
"%s", dump_array
( 16, 0, @filled_idx );
2307 printf OUTPUT
",\n /* null sub-index */\n%s", dump_array
( 16, 0, ($null_offset) x
16 );
2309 # dump the second-level indexes
2311 for (my $i = 0; $i < 256; $i++)
2313 next unless ($filled_idx[$i] > 256);
2314 my @table = @filled[($i<<4)..($i<<4)+15];
2315 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
2316 printf OUTPUT
",\n /* sub-index %02x */\n", $i;
2317 printf OUTPUT
"%s", dump_array
( 16, 0, @table );
2320 # dump the 16-char offsets
2322 printf OUTPUT
",\n /* null offsets */\n";
2323 printf OUTPUT
"%s", dump_array
( 16, 0, ($total) x
(16) );
2328 for (my $i = 0; $i < 4096; $i++)
2330 next unless $filled[$i];
2331 my @table = (0) x
(16);
2332 for (my $j = 0; $j < 16; $j++)
2335 if (defined $decomp[($i<<4) + $j])
2337 $pos += $#{$decomp[($i<<4) + $j]} + 1;
2338 push @data, @
{$decomp[($i<<4) + $j]};
2341 printf OUTPUT
",\n /* offsets 0x%03x0 .. 0x%03xf */\n", $i, $i;
2342 printf OUTPUT
"%s", dump_array
( 16, 0, @table );
2345 my @sentinel = $pos;
2346 printf OUTPUT
",\n /* offset sentinel */\n";
2347 printf OUTPUT
"%s", dump_array
( 16, 0, @sentinel );
2349 printf OUTPUT
",\n /* data */\n";
2350 printf OUTPUT
"%s", dump_array
( 16, 0, @data );
2352 printf OUTPUT
"\n};\n";
2355 ################################################################
2356 # dump the char decomposition table
2357 sub dump_decompose_table
($$)
2359 my ($filename, $compat) = @_;
2361 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2362 print "Building $filename\n";
2363 print OUTPUT
"/* Unicode char composition */\n";
2364 print OUTPUT
"/* generated from $UNIDATA:UnicodeData.txt */\n";
2365 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
2366 print OUTPUT
"#include \"windef.h\"\n";
2368 dump_decompositions
( "nfd_table", build_decompositions
( @decomp_table ));
2369 dump_decompositions
( "nfkd_table", build_decompositions
( @decomp_compat_table )) if $compat;
2372 save_file
($filename);
2375 ################################################################
2376 # dump the combining class table
2377 sub dump_combining_class
($)
2379 my $filename = shift;
2381 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2382 print "Building $filename\n";
2383 print OUTPUT
"/* Unicode Combining Classes */\n";
2384 print OUTPUT
"/* generated from $UNIDATA:UnicodeData.txt */\n";
2385 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
2386 print OUTPUT
"#include \"windef.h\"\n\n";
2388 dump_two_level_mapping
( "combining_class_table", 0, 16, @combining_class_table );
2390 save_file
($filename);
2393 ################################################################
2394 # output a codepage definition file from the global tables
2395 sub output_codepage_file
($$$)
2397 my ($codepage, $filename, $comment) = @_;
2399 my $output = sprintf "libs/port/c_%03d.c", $codepage;
2400 open OUTPUT
,">$output.new" or die "Cannot create $output";
2402 printf "Building %s (%s)\n", $output, $comment;
2406 printf OUTPUT
"/* code page %03d (%s) */\n", $codepage, $comment;
2407 print OUTPUT
"/* generated from $filename */\n";
2408 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
2409 printf OUTPUT
"#include \"wine/unicode.h\"\n\n";
2411 if (!@lead_bytes) { dump_sbcs_table
( $codepage, $comment, $default_char, $default_wchar ); }
2412 else { dump_dbcs_table
( $codepage, $comment, $default_char, $default_wchar, get_lb_ranges
() ); }
2416 # same thing in binary format
2418 $output = sprintf "nls/c_%03d.nls", $codepage;
2419 open OUTPUT
,">$output.new" or die "Cannot create $output";
2421 printf "Building %s\n", $output;
2422 if (!@lead_bytes) { dump_binary_sbcs_table
( $codepage ); }
2423 else { dump_binary_dbcs_table
( $codepage ); }
2429 ################################################################
2430 # output a codepage table from a Microsoft-style mapping file
2431 sub output_msdata_codepage
($$)
2433 my ($filename, $comment) = @_;
2435 my ($codepage, $width, $count);
2436 my ($lb_cur, $lb_end);
2438 my $INPUT = open_data_file
( $MSCODEPAGES, $filename ) or die "Cannot open $filename";
2442 next if /^;/; # skip comments
2443 next if /^\s*$/; # skip empty lines
2444 next if /\x1a/; # skip ^Z
2445 last if /^ENDCODEPAGE/;
2447 if (/^CODEPAGE\s+(\d+)/)
2452 if (/^CPINFO\s+(\d+)\s+0x([0-9a-fA-f]+)\s+0x([0-9a-fA-F]+)/)
2455 $default_char = hex $2;
2456 $default_wchar = hex $3;
2459 if (/^(MBTABLE|GLYPHTABLE|WCTABLE|DBCSRANGE|DBCSTABLE)\s+(\d+)/)
2465 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)/)
2467 if ($state eq "MBTABLE")
2471 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
2474 if ($state eq "GLYPHTABLE")
2478 $glyph2uni[$cp] = $uni unless defined($glyph2uni[$cp]);
2481 if ($state eq "WCTABLE")
2485 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
2488 if ($state eq "DBCSRANGE")
2492 for (my $i = $start; $i <= $end; $i++) { add_lead_byte
( $i ); }
2497 if ($state eq "DBCSTABLE")
2501 my $cp = ($lb_cur << 8) | $mb;
2502 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
2505 if (++$lb_cur > $lb_end) { $state = "DBCSRANGE"; }
2510 die "$filename: Unrecognized line $_\n";
2514 output_codepage_file
( $codepage, "$MSCODEPAGES:$filename", $comment );
2518 ################################################################
2519 # read an input file and generate the corresponding .c file
2520 sub handle_codepage_file
(@
)
2522 my ($codepage, $filename, $comment) = @_;
2528 $default_char = $DEF_CHAR;
2529 $default_wchar = $DEF_CHAR;
2531 # some codepage files are special
2532 if ($codepage == 20932)
2534 output_eucjp_codepage
( $filename, $comment );
2538 output_msdata_codepage
( $filename, $comment );
2543 ################################################################
2544 # save a file if modified
2548 if (-f
$file && !system "cmp $file $file.new >/dev/null")
2554 rename "$file.new", "$file";
2559 ################################################################
2560 # replace the contents of a file between ### cpmap ### marks
2562 sub REPLACE_IN_FILE
($@
)
2567 open(FILE
,$name) or die "Can't open $name";
2571 last if /\#\#\# cpmap begin \#\#\#/;
2576 if (/\#\#\# cpmap end \#\#\#/) { push @lines, "\n", $_; last; }
2578 push @lines, <FILE
>;
2579 open(FILE
,">$name.new") or die "Can't modify $name";
2585 ################################################################
2588 chdir ".." if -f
"./make_unicode";
2590 dump_case_mappings
( "libs/port/casemap.c" );
2591 dump_sortkeys
( "dlls/kernelbase/collation.c" );
2592 dump_compose_table
( "libs/port/compose.c" );
2593 dump_compose_table
( "dlls/kernelbase/compose.c" );
2594 dump_decompose_table
( "libs/port/decompose.c", 1 );
2595 dump_decompose_table
( "dlls/kernelbase/decompose.c", 0 );
2596 dump_ctype_tables
( "libs/port/wctype.c" );
2597 dump_bidi_dir_table
( "dlls/gdi32/direction.c" );
2598 dump_bidi_dir_table
( "dlls/usp10/direction.c" );
2599 dump_bidi_dir_table
( "dlls/dwrite/direction.c" );
2600 dump_string_type_table
( "dlls/kernelbase/wctype.c" );
2601 dump_digit_folding
( "dlls/kernelbase/digitmap.c" );
2602 dump_combining_class
( "dlls/ntdll/combclass.c" );
2603 dump_mirroring
( "dlls/usp10/mirror.c" );
2604 dump_mirroring
( "dlls/dwrite/mirror.c" );
2605 dump_bracket
( "dlls/usp10/bracket.c" );
2606 dump_bracket
( "dlls/dwrite/bracket.c" );
2607 dump_shaping
( "dlls/usp10/shaping.c" );
2608 dump_linebreak
( "dlls/usp10/linebreak.c" );
2609 dump_linebreak
( "dlls/dwrite/linebreak.c" );
2610 dump_scripts
( "dlls/dwrite/scripts" );
2611 dump_indic
( "dlls/usp10/indicsyllable.c" );
2612 dump_vertical
( "dlls/gdi32/vertical.c" );
2613 dump_vertical
( "dlls/wineps.drv/vertical.c" );
2614 dump_nameprep
( "dlls/kernel32/nameprep.c" );
2615 dump_intl_nls
("nls/l_intl.nls");
2617 foreach my $file (@allfiles) { handle_codepage_file
( @
{$file} ); }
2622 # compile-command: "./make_unicode"