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/8.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-11";
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,
259 "Lu" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"upper"}, # Letter, Uppercase
260 "Ll" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"lower"}, # Letter, Lowercase
261 "Lt" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"upper"}|$ctype{"lower"}, # Letter, Titlecase
262 "Mn" => $ctype{"defin"}, # Mark, Non-Spacing
263 "Mc" => $ctype{"defin"}, # Mark, Spacing Combining
264 "Me" => $ctype{"defin"}, # Mark, Enclosing
265 "Nd" => $ctype{"defin"}|$ctype{"digit"}, # Number, Decimal Digit
266 "Nl" => $ctype{"defin"}|$ctype{"alpha"}, # Number, Letter
267 "No" => $ctype{"defin"}, # Number, Other
268 "Zs" => $ctype{"defin"}|$ctype{"space"}, # Separator, Space
269 "Zl" => $ctype{"defin"}|$ctype{"space"}, # Separator, Line
270 "Zp" => $ctype{"defin"}|$ctype{"space"}, # Separator, Paragraph
271 "Cc" => $ctype{"defin"}|$ctype{"cntrl"}, # Other, Control
272 "Cf" => $ctype{"defin"}|$ctype{"cntrl"}, # Other, Format
273 "Cs" => $ctype{"defin"}, # Other, Surrogate
274 "Co" => $ctype{"defin"}, # Other, Private Use
275 "Cn" => $ctype{"defin"}, # Other, Not Assigned
276 "Lm" => $ctype{"defin"}|$ctype{"alpha"}, # Letter, Modifier
277 "Lo" => $ctype{"defin"}|$ctype{"alpha"}, # Letter, Other
278 "Pc" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Connector
279 "Pd" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Dash
280 "Ps" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Open
281 "Pe" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Close
282 "Pi" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Initial quote
283 "Pf" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Final quote
284 "Po" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Other
285 "Sm" => $ctype{"defin"}, # Symbol, Math
286 "Sc" => $ctype{"defin"}, # Symbol, Currency
287 "Sk" => $ctype{"defin"}, # Symbol, Modifier
288 "So" => $ctype{"defin"} # Symbol, Other
291 # a few characters need additional categories that cannot be determined automatically
292 my %special_categories =
294 "xdigit" => [ ord('0')..ord('9'),ord('A')..ord('F'),ord('a')..ord('f'),
295 0xff10..0xff19
, 0xff21..0xff26
, 0xff41..0xff46
],
296 "space" => [ 0x09..0x0d
, 0x85 ],
297 "blank" => [ 0x09, 0x20, 0xa0, 0x3000, 0xfeff ],
298 "cntrl" => [ 0x070f, 0x200c, 0x200d,
299 0x200e, 0x200f, 0x202a, 0x202b, 0x202c, 0x202d, 0x202e,
300 0x206a, 0x206b, 0x206c, 0x206d, 0x206e, 0x206f, 0xfeff,
301 0xfff9, 0xfffa, 0xfffb ],
302 "punct" => [ 0x24, 0x2b, 0x3c..0x3e
, 0x5e, 0x60, 0x7c, 0x7e, 0xa2..0xbe
,
304 "digit" => [ 0xb2, 0xb3, 0xb9 ],
305 "lower" => [ 0x2071, 0x207f ]
310 "L" => 1, # Left-to-Right
311 "R" => 2, # Right-to-Left
312 "AL" => 12, # Right-to-Left Arabic
313 "EN" => 3, # European Number
314 "ES" => 4, # European Number Separator
315 "ET" => 5, # European Number Terminator
316 "AN" => 6, # Arabic Number
317 "CS" => 7, # Common Number Separator
318 "NSM" => 13, # Non-Spacing Mark
319 "BN" => 14, # Boundary Neutral
320 "B" => 8, # Paragraph Separator
321 "S" => 9, # Segment Separator
322 "WS" => 10, # Whitespace
323 "ON" => 11, # Other Neutrals
324 "LRE" => 15, # Left-to-Right Embedding
325 "LRO" => 15, # Left-to-Right Override
326 "RLE" => 15, # Right-to-Left Embedding
327 "RLO" => 15, # Right-to-Left Override
328 "PDF" => 15, # Pop Directional Format
329 "LRI" => 15, # Left-to-Right Isolate
330 "RLI" => 15, # Right-to-Left Isolate
331 "FSI" => 15, # First Strong Isolate
332 "PDI" => 15 # Pop Directional Isolate
337 "U" => 0, # Non_Joining
338 "T" => 1, # Transparent
339 "R" => 2, # Right_Joining
340 "L" => 3, # Left_Joining
341 "D" => 4, # Dual_Joining
342 "C" => 5, # Join_Causing
348 my @unicode_defaults = ();
349 my @unicode_aliases = ();
350 my @tolower_table = ();
351 my @toupper_table = ();
352 my @digitmap_table = ();
353 my @compatmap_table = ();
354 my @category_table = (0) x
65536;
355 my @joining_table = (0) x
65536;
356 my @direction_table = ();
357 my @decomp_table = ();
358 my @compose_table = ();
370 ################################################################
371 # fetch a unicode.org file and open it
372 sub open_data_file
($$)
374 my ($base, $name) = @_;
375 (my $dir = "data/$name") =~ s
/\
/[^\/]+$//;
377 unless (-f
"data/$name")
379 print "Fetching $base/$name...\n";
380 system "mkdir", "-p", $dir;
381 !system "wget", "-q", "-O", "data/$name", "$base/$name" or die "cannot fetch $base/$name";
383 open FILE
, "<data/$name" or die "cannot open data/$name";
387 ################################################################
388 # read in the defaults file
391 my $filename = shift;
394 # first setup a few default mappings
396 open DEFAULTS
, "$filename" or die "Cannot open $filename";
397 print "Loading $filename\n";
400 next if /^\#/; # skip comments
401 next if /^$/; # skip empty lines
402 if (/^(([0-9a-fA-F]+)(,[0-9a-fA-F]+)*)\s+([0-9a-fA-F]+|'.'|none)\s+(\#.*)?/)
404 my @src = map hex, split /,/,$1;
407 if ($#src > 0) { push @unicode_aliases, \
@src; }
408 next if ($dst eq "none");
409 $dst = ($dst =~ /\'.\'/) ?
ord substr($dst,1,1) : hex $dst;
410 foreach my $src (@src)
412 die "Duplicate value" if defined($unicode_defaults[$src]);
413 $unicode_defaults[$src] = $dst;
417 die "Unrecognized line $_\n";
421 # now build mappings from the decomposition field of the Unicode database
423 my $UNICODE_DATA = open_data_file
( $UNIDATA, "UnicodeData.txt" );
424 while (<$UNICODE_DATA>)
426 # Decode the fields ...
427 my ($code, $name, $cat, $comb, $bidi,
428 $decomp, $dec, $dig, $num, $mirror,
429 $oldname, $comment, $upper, $lower, $title) = split /;/;
433 die "unknown category $cat" unless defined $categories{$cat};
434 die "unknown directionality $bidi" unless defined $directions{$bidi};
436 $category_table[$src] = $categories{$cat};
437 $direction_table[$src] = $directions{$bidi};
438 $joining_table[$src] = $joining_types{"T"} if $cat eq "Mn" || $cat eq "Me" || $cat eq "Cf";
442 $tolower_table[$src] = hex $lower;
446 $toupper_table[$src] = hex $upper;
450 $category_table[$src] |= $ctype{"digit"};
454 $digitmap_table[$src] = ord $dig;
457 # copy the category and direction for everything between First/Last pairs
458 if ($name =~ /, First>/) { $start = $src; }
459 if ($name =~ /, Last>/)
461 while ($start < $src)
463 $category_table[$start] = $category_table[$src];
464 $direction_table[$start] = $direction_table[$src];
469 next if $decomp eq ""; # no decomposition, skip it
471 if ($decomp =~ /^<([a-zA-Z]+)>\s+([0-9a-fA-F]+)$/)
473 # decomposition of the form "<foo> 1234" -> use char if type is known
474 if (($src >= 0xf900 && $src < 0xfb00) || ($src >= 0xfe30 && $src < 0xfffd))
476 # Single char decomposition in the compatibility range
477 $compatmap_table[$src] = hex $2;
479 if ($1 eq "isolated" || $1 eq "final" || $1 eq "initial" || $1 eq "medial")
481 ${joining_forms
{$1}}[hex $2] = $src;
484 next unless ($1 eq "font" ||
495 elsif ($decomp =~ /^<compat>\s+0020\s+([0-9a-fA-F]+)/)
497 # decomposition "<compat> 0020 1234" -> combining accent
500 elsif ($decomp =~ /^([0-9a-fA-F]+)/)
502 # decomposition contains only char values without prefix -> use first char
504 $category_table[$src] |= $category_table[$dst] if defined $category_table[$dst];
505 # store decomposition if it contains two chars
506 if ($decomp =~ /^([0-9a-fA-F]+)\s+([0-9a-fA-F]+)$/)
508 $decomp_table[$src] = [ hex $1, hex $2 ];
509 push @compose_table, [ hex $1, hex $2, $src ];
511 elsif ($decomp =~ /^(<[a-z]+>\s)*([0-9a-fA-F]+)$/ &&
512 (($src >= 0xf900 && $src < 0xfb00) || ($src >= 0xfe30 && $src < 0xfffd)))
514 # Single char decomposition in the compatibility range
515 $compatmap_table[$src] = hex $2;
523 next if defined($unicode_defaults[$src]); # may have been set in the defaults file
526 for (my $i = $dst; ; $i = $unicode_defaults[$i])
528 die sprintf("loop detected for %04x -> %04x",$src,$dst) if $i == $src;
529 last unless defined($unicode_defaults[$i]);
531 $unicode_defaults[$src] = $dst;
535 # patch the category of some special characters
537 foreach my $cat (keys %special_categories)
539 my $flag = $ctype{$cat};
540 foreach my $i (@
{$special_categories{$cat}}) { $category_table[$i] |= $flag; }
545 ################################################################
546 # define a new lead byte
550 push @lead_bytes, $ch;
554 ################################################################
555 # define a new char mapping
559 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
560 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
561 if ($cp > 0xff && !defined($cp2uni[$cp >> 8]))
563 add_lead_byte
( $cp >> 8 );
567 ################################################################
568 # parse a standard codepage file
569 sub read_codepage_file
($)
572 my $INPUT = open_data_file
( $MAPPINGS, $name );
576 next if /^\#/; # skip comments
577 next if /^$/; # skip empty lines
578 next if /\x1a/; # skip ^Z
579 next if (/^0x([0-9a-fA-F]+)\s+\#UNDEFINED/); # undefined char
581 if (/^0x([0-9a-fA-F]+)\s+\#DBCS LEAD BYTE/)
583 add_lead_byte
( hex $1 );
587 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
589 add_mapping
( hex $1, hex $2 );
593 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\+.*\s+(\#.*)?/)
595 add_mapping
( hex $1, hex $2 );
599 if (/^0x([0-9a-fA-F]+)\s+<LR>\+0x([0-9a-fA-F]+)\s+(\#.*)?/)
601 add_mapping
( hex $1, hex $2 );
605 if (/^0x([0-9a-fA-F]+)\s+<RL>\+0x([0-9a-fA-F]+)\s+(\#.*)?/)
608 add_mapping
( hex $1, $uni ) if $uni >= 0x80;
611 die "$name: Unrecognized line $_\n";
617 ################################################################
618 # fill input data for the 20127 (us-ascii) codepage
619 sub fill_20127_codepage
()
621 for (my $i = 0; $i < 128; $i++) { $cp2uni[$i] = $uni2cp[$i] = $i; }
622 for (my $i = 128; $i < 256; $i++) { $cp2uni[$i] = $i & 0x7f; }
625 ################################################################
626 # get a mapping including glyph chars for MB_USEGLYPHCHARS
628 sub get_glyphs_mapping
(@
)
630 $_[0x01] = 0x263a; # (WHITE SMILING FACE)
631 $_[0x02] = 0x263b; # (BLACK SMILING FACE)
632 $_[0x03] = 0x2665; # (BLACK HEART SUIT)
633 $_[0x04] = 0x2666; # (BLACK DIAMOND SUIT)
634 $_[0x05] = 0x2663; # (BLACK CLUB SUIT)
635 $_[0x06] = 0x2660; # (BLACK SPADE SUIT)
636 $_[0x07] = 0x2022; # (BULLET)
637 $_[0x08] = 0x25d8; # (INVERSE BULLET)
638 $_[0x09] = 0x25cb; # (WHITE CIRCLE)
639 $_[0x0a] = 0x25d9; # (INVERSE WHITE CIRCLE)
640 $_[0x0b] = 0x2642; # (MALE SIGN)
641 $_[0x0c] = 0x2640; # (FEMALE SIGN)
642 $_[0x0d] = 0x266a; # (EIGHTH NOTE)
643 $_[0x0e] = 0x266b; # (BEAMED EIGHTH NOTES)
644 $_[0x0f] = 0x263c; # (WHITE SUN WITH RAYS)
645 $_[0x10] = 0x25ba; # (BLACK RIGHT-POINTING POINTER)
646 $_[0x11] = 0x25c4; # (BLACK LEFT-POINTING POINTER)
647 $_[0x12] = 0x2195; # (UP DOWN ARROW)
648 $_[0x13] = 0x203c; # (DOUBLE EXCLAMATION MARK)
649 $_[0x14] = 0x00b6; # (PILCROW SIGN)
650 $_[0x15] = 0x00a7; # (SECTION SIGN)
651 $_[0x16] = 0x25ac; # (BLACK RECTANGLE)
652 $_[0x17] = 0x21a8; # (UP DOWN ARROW WITH BASE)
653 $_[0x18] = 0x2191; # (UPWARDS ARROW)
654 $_[0x19] = 0x2193; # (DOWNWARDS ARROW)
655 $_[0x1a] = 0x2192; # (RIGHTWARDS ARROW)
656 $_[0x1b] = 0x2190; # (LEFTWARDS ARROW)
657 $_[0x1c] = 0x221f; # (RIGHT ANGLE)
658 $_[0x1d] = 0x2194; # (LEFT RIGHT ARROW)
659 $_[0x1e] = 0x25b2; # (BLACK UP-POINTING TRIANGLE)
660 $_[0x1f] = 0x25bc; # (BLACK DOWN-POINTING TRIANGLE)
661 $_[0x7f] = 0x2302; # (HOUSE)
665 ################################################################
666 # build EUC-JP table from the JIS 0208 file
667 # FIXME: for proper EUC-JP we should probably read JIS 0212 too
668 # but this would require 3-byte DBCS characters
669 sub READ_JIS0208_FILE
($)
674 for (my $i = 0x00; $i <= 0x7f; $i++)
680 # JIS X 0201 right plane
681 for (my $i = 0xa1; $i <= 0xdf; $i++)
683 $cp2uni[0x8e00 + $i] = 0xfec0 + $i;
684 $uni2cp[0xfec0 + $i] = 0x8e00 + $i;
688 foreach my $i (0x8e, 0x8f, 0xa1 .. 0xfe)
695 foreach my $i (0x80 .. 0x8d, 0x90 .. 0xa0, 0xff)
697 $cp2uni[$i] = $DEF_CHAR;
700 # Shift-JIS compatibility
701 $uni2cp[0x00a5] = 0x5c;
702 $uni2cp[0x203e] = 0x7e;
704 # Fix backslash conversion
705 $cp2uni[0xa1c0] = 0xff3c;
706 $uni2cp[0xff3c] = 0xa1c0;
708 my $INPUT = open_data_file
( $MAPPINGS, $name );
711 next if /^\#/; # skip comments
712 next if /^$/; # skip empty lines
713 next if /\x1a/; # skip ^Z
714 if (/^0x[0-9a-fA-F]+\s+0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
716 my $cp = 0x8080 + hex $1;
718 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
719 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
722 die "$name: Unrecognized line $_\n";
728 ################################################################
729 # build the sort keys table
730 sub READ_SORTKEYS_FILE
()
733 for (my $i = 0; $i < 65536; $i++) { $sortkeys[$i] = [ -1, 0, 0, 0, 0 ] };
735 my $INPUT = open_data_file
( $REPORTS, $SORTKEYS );
738 next if /^\#/; # skip comments
739 next if /^$/; # skip empty lines
740 next if /\x1a/; # skip ^Z
741 next if /^\@version/; # skip @version header
742 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]+)\]/)
744 my ($uni,$variable) = (hex $1, $2);
745 next if $uni > 65535;
746 $sortkeys[$uni] = [ $uni, hex $3, hex $4, hex $5, hex $6 ];
749 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]+)\]/)
751 # multiple character sequence, ignored for now
754 die "$SORTKEYS: Unrecognized line $_\n";
758 # compress the keys to 32 bit:
759 # key 1 to 16 bits, key 2 to 8 bits, key 3 to 4 bits, key 4 to 1 bit
761 @sortkeys = sort { ${$a}[1] <=> ${$b}[1] or
762 ${$a}[2] <=> ${$b}[2] or
763 ${$a}[3] <=> ${$b}[3] or
764 ${$a}[4] <=> ${$b}[4] or
765 $a cmp $b; } @sortkeys;
767 my ($n2, $n3) = (1, 1);
768 my @keys = (-1, -1, -1, -1, -1 );
771 for (my $i = 0; $i < 65536; $i++)
773 my @current = @
{$sortkeys[$i]};
774 next if $current[0] == -1;
775 if ($current[1] == $keys[1])
777 if ($current[2] == $keys[2])
779 if ($current[3] == $keys[3])
785 $keys[3] = $current[3];
792 $keys[2] = $current[2];
793 $keys[3] = $current[3];
801 $keys[1] = $current[1];
802 $keys[2] = $current[2];
803 $keys[3] = $current[3];
808 if ($current[2]) { $current[2] = $n2; }
809 if ($current[3]) { $current[3] = $n3; }
810 if ($current[4]) { $current[4] = 1; }
812 $flatkeys[$current[0]] = ($current[1] << 16) | ($current[2] << 8) | ($current[3] << 4) | $current[4];
818 ################################################################
819 # build the sort keys table
820 sub DUMP_SORTKEYS
($@
)
822 my ($filename, @keys) = @_;
824 # count the number of 256-key ranges that contain something
828 for (my $i = 0; $i < 256; $i++) { $offsets[$i] = 256; }
829 for (my $i = 0; $i < 65536; $i++)
831 next unless defined $keys[$i];
832 $offsets[$i >> 8] = $ranges * 256;
837 # output the range offsets
839 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
840 printf "Building $filename\n";
841 printf OUTPUT
"/* Unicode collation element table */\n";
842 printf OUTPUT
"/* generated from %s */\n", "$REPORTS/$SORTKEYS";
843 printf OUTPUT
"/* DO NOT EDIT!! */\n\n";
845 printf OUTPUT
"const unsigned int collation_table[%d] =\n{\n", $ranges*256;
846 printf OUTPUT
" /* index */\n";
847 printf OUTPUT
"%s,\n", DUMP_ARRAY
( "0x%08x", 0, @offsets );
849 # output the default values
851 printf OUTPUT
" /* defaults */\n";
852 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%08x", 0, (0xffffffff) x
256 );
854 # output all the key ranges
856 for (my $i = 0; $i < 256; $i++)
858 next if $offsets[$i] == 256;
859 printf OUTPUT
",\n /* 0x%02x00 .. 0x%02xff */\n", $i, $i;
860 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%08x", 0xffffffff, @keys[($i<<8) .. ($i<<8)+255] );
862 printf OUTPUT
"\n};\n";
864 save_file
($filename);
868 ################################################################
869 # add default mappings once the file had been read
870 sub add_default_mappings
($)
872 my $first_private = shift;
876 foreach my $alias (@unicode_aliases)
879 foreach my $src (@
$alias)
881 if (defined($uni2cp[$src]))
883 $target = $uni2cp[$src];
887 next unless defined($target);
889 # At least one char of the alias set is defined, set the others to the same value
890 foreach my $src (@
$alias)
892 $uni2cp[$src] = $target unless defined($uni2cp[$src]);
896 # For every src -> target mapping in the defaults table,
897 # make uni2cp[src] = uni2cp[target] if uni2cp[target] is defined
899 for (my $src = 0; $src < 65536; $src++)
901 next if defined($uni2cp[$src]); # source has a definition already
902 next unless defined($unicode_defaults[$src]); # no default for this char
903 my $target = $unicode_defaults[$src];
905 # do a recursive mapping until we find a target char that is defined
906 while (!defined($uni2cp[$target]) &&
907 defined($unicode_defaults[$target])) { $target = $unicode_defaults[$target]; }
909 if (defined($uni2cp[$target])) { $uni2cp[$src] = $uni2cp[$target]; }
912 # Add a private char mapping for undefined chars
916 for (my $i = 32; $i < 256; $i++)
918 next if defined($cp2uni[$i]);
919 $cp2uni[$i] = $first_private;
920 $uni2cp[$first_private] = $i;
925 # Add an identity mapping for all undefined chars
927 for (my $i = 0; $i < 256; $i++)
929 next if defined($cp2uni[$i]);
930 next if defined($uni2cp[$i]);
931 $cp2uni[$i] = $uni2cp[$i] = $i;
935 ################################################################
936 # dump an array of integers
939 my ($format,$default,@array) = @_;
942 for ($i = 0; $i < $#array; $i++)
944 $ret .= sprintf($format, defined $array[$i] ?
$array[$i] : $default);
945 $ret .= (($i % 8) != 7) ?
", " : ",\n ";
947 $ret .= sprintf($format, defined $array[$i] ?
$array[$i] : $default);
952 ################################################################
953 # dump a unicode->ascii mapping table
954 sub dump_uni2cp_table
($$)
956 my ($width, $def) = @_;
958 # count the number of unicode->ascii subtables that contain something
963 my @filled = (-1) x
256;
964 for (my $i = 0; $i < 65536; $i++)
966 next unless defined $uni2cp[$i];
967 if ($filled[$i >> 8] == -1)
969 $lowerbounds[$index] = $i & 0xff;
970 $upperbounds[$index] = 0xff - $lowerbounds[$index];
971 $filled[$i >> 8] = $index * 256;
976 $upperbounds[$index-1] = 0xff - ($i & 0xff);
980 # add defaults mapping at the end
981 $filled[256] = $index * 256;
982 $lowerbounds[$index] = 255;
983 $upperbounds[$index] = 0;
986 # collapse blocks upwards if possible
989 for (my $i = 0; $i < 257; $i++)
991 next if $filled[$i] == -1;
992 if ($upperbounds[$index - 1] > $lowerbounds[$index])
994 $removed += $lowerbounds[$index];
998 $removed += $upperbounds[$index - 1];
999 $lowerbounds[$index] = $upperbounds[$index - 1];
1001 $filled[$i] -= $removed;
1005 # output all the subtables into a single array
1007 printf OUTPUT
"static const unsigned %s uni2cp_low[%d] =\n{\n",
1008 $width == 8 ?
"char" : "short", ($index + 1) * 256 - $removed;
1010 my $format = $width == 8 ?
"0x%02x" : "0x%04x";
1011 for (my $i = $index = 0; $i < 257; $i++)
1013 next if $filled[$i] == -1;
1014 my $start = ($i << 8) + $lowerbounds[$index];
1015 my $end = ($i << 8) + 255;
1018 print OUTPUT
" /* defaults */\n";
1019 printf OUTPUT
"%s\n};\n\n", DUMP_ARRAY
( $format, 0, ($def) x
($end - $start + 1) );
1023 printf OUTPUT
" /* 0x%04x .. 0x%04x */\n", $start, $end;
1024 printf OUTPUT
"%s,\n", DUMP_ARRAY
( $format, $def, @uni2cp[$start .. $end] );
1029 # output a table of the offsets of the subtables in the previous array
1031 for (my $i = 0; $i < 256; $i++)
1033 if ($filled[$i] == -1) { $filled[$i] = $filled[256]; }
1035 printf OUTPUT
"static const unsigned short uni2cp_high[256] =\n";
1036 printf OUTPUT
"{\n%s\n};\n\n", DUMP_ARRAY
( "0x%04x", 0, @filled[0..255] );
1039 ################################################################
1040 # dump an SBCS mapping table
1041 sub dump_sbcs_table
($$$$$)
1043 my ($codepage, $has_glyphs, $name, $def, $defw) = @_;
1046 # output the ascii->unicode table
1050 printf OUTPUT
"static const WCHAR cp2uni[512] =\n";
1051 printf OUTPUT
"{\n%s", DUMP_ARRAY
( "0x%04x", $defw, @cp2uni[0 .. 255] );
1052 printf OUTPUT
",\n /* glyphs */\n%s\n};\n\n",
1053 DUMP_ARRAY
( "0x%04x", $defw, get_glyphs_mapping
(@cp2uni[0 .. 255]) );
1057 printf OUTPUT
"static const WCHAR cp2uni[256] =\n";
1058 printf OUTPUT
"{\n%s\n};\n\n", DUMP_ARRAY
( "0x%04x", $defw, @cp2uni[0 .. 255] );
1061 dump_uni2cp_table
( 8, $def );
1063 # output the code page descriptor
1065 printf OUTPUT
"const struct sbcs_table cptable_%03d =\n{\n", $codepage;
1066 printf OUTPUT
" { %d, 1, 0x%04x, 0x%04x, \"%s\" },\n",
1067 $codepage, $def, $defw, $name;
1068 printf OUTPUT
" cp2uni,\n";
1069 if ($has_glyphs) { printf OUTPUT
" cp2uni + 256,\n"; }
1070 else { printf OUTPUT
" cp2uni,\n"; }
1071 printf OUTPUT
" uni2cp_low,\n";
1072 printf OUTPUT
" uni2cp_high\n};\n";
1076 ################################################################
1077 # dump a DBCS mapping table
1078 sub dump_dbcs_table
($$$$@
)
1080 my ($codepage, $name, $def, $defw, @lb_ranges) = @_;
1082 # build a list of lead bytes that are actually used
1085 LBLOOP
: for (my $y = 0; $y <= $#lead_bytes; $y++)
1087 my $base = $lead_bytes[$y] << 8;
1088 for (my $x = 0; $x < 256; $x++)
1090 if (defined $cp2uni[$base+$x])
1092 push @lblist,$lead_bytes[$y];
1097 my $unused = ($#lead_bytes > $#lblist);
1099 # output the ascii->unicode table for the single byte chars
1101 printf OUTPUT
"static const WCHAR cp2uni[%d] =\n", 256 * ($#lblist + 2 + $unused);
1102 printf OUTPUT
"{\n%s,\n", DUMP_ARRAY
( "0x%04x", $defw, @cp2uni[0 .. 255] );
1104 # output the default table for unused lead bytes
1108 printf OUTPUT
" /* unused lead bytes */\n";
1109 printf OUTPUT
"%s,\n", DUMP_ARRAY
( "0x%04x", 0, ($defw) x
256 );
1112 # output the ascii->unicode table for each DBCS lead byte
1114 for (my $y = 0; $y <= $#lblist; $y++)
1116 my $base = $lblist[$y] << 8;
1117 printf OUTPUT
" /* lead byte %02x */\n", $lblist[$y];
1118 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", $defw, @cp2uni[$base .. $base+255] );
1119 printf OUTPUT
($y < $#lblist) ?
",\n" : "\n};\n\n";
1122 # output the lead byte subtables offsets
1124 my @offsets = (0) x
256;
1125 for (my $x = 0; $x <= $#lblist; $x++) { $offsets[$lblist[$x]] = $x + 1; }
1128 # increment all lead bytes offset to take into account the unused table
1129 for (my $x = 0; $x <= $#lead_bytes; $x++) { $offsets[$lead_bytes[$x]]++; }
1131 printf OUTPUT
"static const unsigned char cp2uni_leadbytes[256] =\n";
1132 printf OUTPUT
"{\n%s\n};\n\n", DUMP_ARRAY
( "0x%02x", 0, @offsets );
1134 dump_uni2cp_table
( 16, $def );
1136 # output the code page descriptor
1138 printf OUTPUT
"const struct dbcs_table cptable_%03d =\n{\n", $codepage;
1139 printf OUTPUT
" { %d, 2, 0x%04x, 0x%04x, \"%s\" },\n",
1140 $codepage, $def, $defw, $name;
1141 printf OUTPUT
" cp2uni,\n";
1142 printf OUTPUT
" cp2uni_leadbytes,\n";
1143 printf OUTPUT
" uni2cp_low,\n";
1144 printf OUTPUT
" uni2cp_high,\n";
1145 printf OUTPUT
" {\n %s\n }\n", DUMP_ARRAY
( "0x%02x", 0, @lb_ranges, 0, 0 );
1146 printf OUTPUT
"};\n";
1150 ################################################################
1151 # get the list of defined lead byte ranges
1157 foreach $i (@lead_bytes) { $list[$i] = 1; }
1159 for (my $i = 0; $i < 256; $i++)
1163 if (!defined $list[$i]) { push @ranges, $i-1; $on = 0; }
1167 if ($list[$i]) { push @ranges, $i; $on = 1; }
1170 if ($on) { push @ranges, 0xff; }
1174 ################################################################
1175 # dump the Indic Syllabic Category table
1178 my $filename = shift;
1179 my @indic_table = ($indic_types{'Other'}) x
65536;
1181 my $INPUT = open_data_file
( $UNIDATA, "IndicSyllabicCategory.txt" );
1184 next if /^\#/; # skip comments
1185 next if /^\s*$/; # skip empty lines
1186 next if /\x1a/; # skip ^Z
1187 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*#/)
1190 die "unknown indic $type" unless defined $indic_types{$type};
1193 $indic_table[hex $1] = $indic_types{$type};
1197 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*#/)
1200 die "unknown indic $type" unless defined $indic_types{$type};
1201 if (hex $1 < 65536 and hex $2 < 6536)
1203 foreach my $i (hex $1 .. hex $2)
1205 $indic_table[$i] = $indic_types{$type};
1210 die "malformed line $_";
1214 $INPUT = open_data_file
( $UNIDATA, "IndicPositionalCategory.txt" );
1217 next if /^\#/; # skip comments
1218 next if /^\s*$/; # skip empty lines
1219 next if /\x1a/; # skip ^Z
1220 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z]+)\s*#/)
1223 die "unknown matra $type" unless defined $matra_types{$type};
1224 $indic_table[hex $1] += $matra_types{$type} << 8;
1227 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*#/)
1230 die "unknown matra $type" unless defined $matra_types{$type};
1231 foreach my $i (hex $1 .. hex $2)
1233 $indic_table[$i] += $matra_types{$type} << 8;
1237 die "malformed line $_";
1241 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1242 print "Building $filename\n";
1243 print OUTPUT
"/* Unicode Indic Syllabic Category */\n";
1244 print OUTPUT
"/* generated from $UNIDATA/IndicSyllabicCategory.txt */\n";
1245 print OUTPUT
"/* and from $UNIDATA/IndicPositionalCategory.txt */\n";
1246 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1248 dump_two_level_mapping
( "indic_syllabic_table", @indic_table);
1251 save_file
($filename);
1254 ################################################################
1255 # dump the Line Break Properties table
1256 sub dump_linebreak
($)
1258 my $filename = shift;
1259 my @break_table = ($break_types{'XX'}) x
65536;
1262 my $INPUT = open_data_file
( $UNIDATA, "LineBreak.txt" );
1265 next if /^\#/; # skip comments
1266 next if /^\s*$/; # skip empty lines
1267 next if /\x1a/; # skip ^Z
1268 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z])+\s*/)
1271 die "unknown breaktype $type" unless defined $break_types{$type};
1272 $break_table[hex $1] = $break_types{$type};
1275 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z])+\s*/)
1278 die "unknown breaktype $type" unless defined $break_types{$type};
1279 foreach my $i (hex $1 .. hex $2)
1281 $break_table[$i] = $break_types{$type};
1285 die "malformed line $_";
1289 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1290 print "Building $filename\n";
1291 print OUTPUT
"/* Unicode Line Break Properties */\n";
1292 print OUTPUT
"/* generated from $UNIDATA/LineBreak.txt */\n";
1293 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1295 dump_two_level_mapping
( "wine_linebreak_table", @break_table);
1298 save_file
($filename);
1301 ################################################################
1302 # dump Script IDs table
1305 my $filename = shift;
1306 my $header = $filename;
1307 my @scripts_table = (0) x
65536; # 0 means unknown script
1312 my $INPUT = open_data_file
( $UNIDATA, "Scripts.txt" );
1317 next if /^\#/; # skip comments
1318 next if /^\s*$/; # skip empty lines
1319 next if /\x1a/; # skip ^Z
1320 if (/^\s*([0-9a-fA-F]+)\s*;\s*([_a-zA-Z]+)\s*/)
1324 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([_a-zA-Z]+)\s*/)
1330 die "malformed line $_";
1333 # ignore some scripts
1334 if ($type eq "" || $type eq "Common" || $type eq "Inherited")
1339 $scripts{$type} = -1;
1343 foreach my $script (sort keys %scripts) {
1344 $scripts{$script} = ++$script_index;
1353 next if /^\#/; # skip comments
1354 next if /^\s*$/; # skip empty lines
1355 next if /\x1a/; # skip ^Z
1356 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z]+)\s*/)
1359 if (defined $scripts{$type})
1361 $scripts_table[hex $1] = $scripts{$type};
1365 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z]+)\s*/)
1368 if (defined $scripts{$type})
1370 foreach my $i (hex $1 .. hex $2)
1372 $scripts_table[$i] = $scripts{$type};
1381 $header = "$filename.h";
1382 open OUTPUT
,">$header.new" or die "Cannot create $header";
1383 print "Building $header\n";
1384 print OUTPUT
"/* Unicode Script IDs */\n";
1385 print OUTPUT
"/* generated from $UNIDATA/Scripts.txt */\n";
1386 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1388 # reserve Unknown and Common ids
1389 print OUTPUT
"enum unicode_script_id {\n";
1390 print OUTPUT
" Script_Unknown = 0,\n";
1391 print OUTPUT
" Script_Common = 1,\n";
1392 foreach my $script (sort keys %scripts)
1394 print OUTPUT
" Script_$script = $scripts{$script},\n";
1396 print OUTPUT
" Script_LastId = $script_index\n";
1397 print OUTPUT
"};\n";
1402 $filename = "$filename.c";
1403 open OUTPUT
,">$filename.new" or die "Cannot create $header";
1404 print "Building $filename\n";
1405 print OUTPUT
"/* Unicode Script IDs */\n";
1406 print OUTPUT
"/* generated from $UNIDATA/Scripts.txt */\n";
1407 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1409 dump_two_level_mapping
( "wine_scripts_table", @scripts_table);
1411 save_file
($filename);
1414 ################################################################
1415 # dump the BiDi mirroring table
1416 sub dump_mirroring
($)
1418 my $filename = shift;
1419 my @mirror_table = ();
1421 my $INPUT = open_data_file
( $UNIDATA, "BidiMirroring.txt" );
1424 next if /^\#/; # skip comments
1425 next if /^$/; # skip empty lines
1426 next if /\x1a/; # skip ^Z
1427 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9a-fA-F]+)/)
1429 $mirror_table[hex $1] = hex $2;
1432 die "malformed line $_";
1436 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1437 print "Building $filename\n";
1438 print OUTPUT
"/* Unicode BiDi mirroring */\n";
1439 print OUTPUT
"/* generated from $UNIDATA/BidiMirroring.txt */\n";
1440 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1441 print OUTPUT
"#include \"wine/unicode.h\"\n\n";
1442 DUMP_CASE_TABLE
( "wine_mirror_map", @mirror_table );
1444 save_file
($filename);
1447 ################################################################
1448 # dump the Bidi Brackets
1451 my $filename = shift;
1452 my @bracket_table = (0) x
65536;
1454 my $INPUT = open_data_file
( $UNIDATA, "BidiBrackets.txt" );
1457 next if /^\#/; # skip comments
1458 next if /^\s*$/; # skip empty lines
1459 next if /\x1a/; # skip ^Z
1460 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9a-fA-F]+);\s*([con])/)
1463 die "unknown bracket $type" unless defined $bracket_types{$type};
1464 die "characters too distant $1 and $2" if abs(hex($2) - hex($1)) >= 128;
1465 $bracket_table[hex $1] = (hex($2) - hex($1)) % 255;
1466 $bracket_table[hex $1] += $bracket_types{$type} << 8;
1469 die "malformed line $_";
1473 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1474 print "Building $filename\n";
1475 print OUTPUT
"/* Unicode Bidirectional Bracket table */\n";
1476 print OUTPUT
"/* generated from $UNIDATA/BidiBrackets.txt */\n";
1477 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1479 dump_two_level_mapping
( "bidi_bracket_table", @bracket_table);
1482 save_file
($filename);
1485 ################################################################
1486 # dump the Arabic shaping table
1489 my $filename = shift;
1493 $groups{"No_Joining_Group"} = $next_group++;
1495 my $INPUT = open_data_file
( $UNIDATA, "ArabicShaping.txt" );
1498 next if /^\#/; # skip comments
1499 next if /^\s*$/; # skip empty lines
1500 next if /\x1a/; # skip ^Z
1501 if (/^\s*([0-9a-fA-F]+)\s*;.*;\s*([RLDCUT])\s*;\s*(\w+)/)
1505 $groups{$group} = $next_group++ unless defined $groups{$group};
1506 $joining_table[hex $1] = $joining_types{$type} | ($groups{$group} << 8);
1509 die "malformed line $_";
1513 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1514 print "Building $filename\n";
1515 print OUTPUT
"/* Unicode Arabic shaping */\n";
1516 print OUTPUT
"/* generated from $UNIDATA/ArabicShaping.txt */\n";
1517 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1519 dump_two_level_mapping
( "wine_shaping_table", @joining_table );
1521 print OUTPUT
"\nconst unsigned short wine_shaping_forms[256][4] =\n{\n";
1522 for (my $i = 0x600; $i <= 0x6ff; $i++)
1524 printf OUTPUT
" { 0x%04x, 0x%04x, 0x%04x, 0x%04x },\n",
1525 ${joining_forms
{"isolated"}}[$i] || $i,
1526 ${joining_forms
{"final"}}[$i] || $i,
1527 ${joining_forms
{"initial"}}[$i] || $i,
1528 ${joining_forms
{"medial"}}[$i] || $i;
1530 print OUTPUT
"};\n";
1533 save_file
($filename);
1536 ################################################################
1537 # dump the Vertical Orientation table
1538 sub dump_vertical
($)
1540 my $filename = shift;
1541 my @vertical_table = ($vertical_types{'R'}) x
65536;
1543 my $INPUT = open_data_file
( $VERTICALDATA, "VerticalOrientation-11.txt" );
1546 next if /^\#/; # skip comments
1547 next if /^\s*$/; # skip empty lines
1548 next if /\x1a/; # skip ^Z
1549 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1552 die "unknown vertical $type" unless defined $vertical_types{$type};
1555 $vertical_table[hex $1] = $vertical_types{$type};
1559 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*/)
1562 die "unknown vertical $type" unless defined $vertical_types{$type};
1563 foreach my $i (hex $1 .. hex $2)
1565 $vertical_table[$i] = $vertical_types{$type};
1569 die "malformed line $_";
1573 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1574 print "Building $filename\n";
1575 print OUTPUT
"/* Unicode Vertical Orientation */\n";
1576 print OUTPUT
"/* generated from $VERTICALDATA/VerticalOrientation-11.txt */\n";
1577 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1579 dump_two_level_mapping
( "vertical_orientation_table", @vertical_table);
1582 save_file
($filename);
1585 ################################################################
1586 # dump the case mapping tables
1587 sub DUMP_CASE_MAPPINGS
($)
1589 my $filename = shift;
1590 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1591 printf "Building $filename\n";
1592 printf OUTPUT
"/* Unicode case mappings */\n";
1593 printf OUTPUT
"/* Automatically generated; DO NOT EDIT!! */\n\n";
1594 printf OUTPUT
"#include \"wine/unicode.h\"\n\n";
1596 DUMP_CASE_TABLE
( "wine_casemap_lower", @tolower_table );
1597 DUMP_CASE_TABLE
( "wine_casemap_upper", @toupper_table );
1598 DUMP_CASE_TABLE
( "wine_digitmap", @digitmap_table );
1599 DUMP_CASE_TABLE
( "wine_compatmap", @compatmap_table );
1601 save_file
($filename);
1605 ################################################################
1606 # dump a case mapping table
1607 sub DUMP_CASE_TABLE
($@
)
1609 my ($name,@table) = @_;
1611 # count the number of sub tables that contain something
1612 # also compute the low and upper populated bounds
1614 my @lowerbounds = ( 0, 0 );
1615 my @upperbounds = ( 0, 255 );
1618 for (my $i = 0; $i < 65536; $i++)
1620 next unless defined $table[$i];
1621 if (!defined $filled[$i >> 8])
1623 $lowerbounds[$index] = $i & 0xff;
1624 $upperbounds[$index] = 0xff - $lowerbounds[$index];
1625 $filled[$i >> 8] = $index * 256 + 512;
1630 $upperbounds[$index-1] = 0xff - ($i & 0xff);
1632 $table[$i] = ($table[$i] - $i) & 0xffff;
1635 # Collapse blocks upwards if possible
1638 for (my $i = 0; $i < 256; $i++)
1640 next unless defined $filled[$i];
1641 if ($upperbounds[$index - 1] > $lowerbounds[$index])
1643 $removed = $removed + $lowerbounds[$index];
1647 $removed = $removed + $upperbounds[$index - 1];
1648 $lowerbounds[$index] = $upperbounds[$index - 1];
1650 $filled[$i] = $filled[$i] - $removed;
1656 printf OUTPUT
"const WCHAR %s[%d] =\n", $name, $index * 256 + 512 - $removed;
1657 printf OUTPUT
"{\n /* index */\n";
1658 printf OUTPUT
"%s,\n", DUMP_ARRAY
( "0x%04x", 256, @filled );
1659 printf OUTPUT
" /* defaults */\n";
1660 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, (0) x
256 );
1662 for (my $i = 0; $i < 256; $i++)
1664 next unless $filled[$i];
1665 printf OUTPUT
",\n /* 0x%02x%02x .. 0x%02xff */\n", $i, $lowerbounds[$index], $i;
1666 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0,
1667 @table[($i<<8) + $lowerbounds[$index] .. ($i<<8)+255] );
1670 printf OUTPUT
"\n};\n";
1673 ################################################################
1674 # compress a mapping table by removing identical rows
1675 sub compress_array
($@
)
1679 my $len = @table / $rows;
1680 my @array = (0) x
$rows;
1683 # try to merge table rows
1684 for (my $row = 0; $row < $rows; $row++)
1686 my $rowtxt = pack "S*", @table[($row * $len)..($row * $len + $len - 1)];
1687 if (defined($sequences{$rowtxt}))
1689 # reuse an existing row
1690 $array[$row] = $sequences{$rowtxt};
1695 $sequences{$rowtxt} = $array[$row] = $#array + 1;
1696 push @array, @table[$row * $len..$row * $len + $len - 1];
1702 ################################################################
1703 # dump a simple char -> 16-bit value mapping table
1704 sub dump_simple_mapping
($@
)
1707 my @array = compress_array
( 256, @_[0..65535] );
1709 printf OUTPUT
"const unsigned short %s[%d] =\n{\n", $name, $#array+1;
1710 printf OUTPUT
" /* offsets */\n%s,\n", DUMP_ARRAY
( "0x%04x", 0, @array[0..255] );
1711 printf OUTPUT
" /* values */\n%s\n};\n", DUMP_ARRAY
( "0x%04x", 0, @array[256..$#array] );
1714 ################################################################
1715 # dump a char -> 16-bit value mapping table using two-level tables
1716 sub dump_two_level_mapping
($@
)
1719 my @row_array = compress_array
( 4096, @_[0..65535] );
1720 my @array = compress_array
( 256, @row_array[0..4095] );
1722 for (my $i = 256; $i < @array; $i++) { $array[$i] += @array - 4096; }
1724 printf OUTPUT
"const unsigned short %s[%d] =\n{\n", $name, @array + @row_array - 4096;
1725 printf OUTPUT
" /* level 1 offsets */\n%s,\n", DUMP_ARRAY
( "0x%04x", 0, @array[0..255] );
1726 printf OUTPUT
" /* level 2 offsets */\n%s,\n", DUMP_ARRAY
( "0x%04x", 0, @array[256..$#array] );
1727 printf OUTPUT
" /* values */\n%s\n};\n", DUMP_ARRAY
( "0x%04x", 0, @row_array[4096..$#row_array] );
1730 ################################################################
1731 # dump a binary case mapping table in l_intl.nls format
1732 sub dump_binary_case_table
(@
)
1736 my %difftables_hash = ();
1738 my %offtables2_hash = ();
1739 my @offtables2 = ();
1742 for (my $i = 0; $i < 256; $i++)
1745 for(my $j = 0; $j < 16; $j++) # offset table for xx00-xxFF characters
1748 for (my $k = 0; $k < 16; $k++) # case map table for xxx0-xxxF characters
1750 my $char = ($i<<8) + ($j<<4) + $k;
1751 $difftable[$k] = (defined $table[$char]) ?
(($table[$char]-$char) & 0xffff) : 0;
1754 my $diff_key = pack "S*", @difftable;
1755 my $offset3 = $difftables_hash{$diff_key};
1756 if (!defined $offset3)
1758 $offset3 = scalar @difftables;
1759 $difftables_hash{$diff_key} = $offset3;
1760 push @difftables, @difftable;
1762 $offtable2[$j] = $offset3;
1765 my $offtable2_key = pack "S*", @offtable2;
1766 my $offset2 = $offtables2_hash{$offtable2_key};
1767 if (!defined $offset2)
1769 $offset2 = scalar @offtables2;
1770 $offtables2_hash{$offtable2_key} = $offset2;
1771 push @offtables2, \
@offtable2;
1773 $offtable[$i] = $offset2;
1777 my $offset = 0x100; # offset of first subtable in words
1780 push @output, 0x10 * $_ + $offset; # offset of subtable in words
1783 $offset = 0x100 + 0x10 * scalar @offtables2; # offset of first difftable in words
1784 foreach(@offtables2)
1789 push @output, $_ + $offset; # offset of difftable in words
1793 my $len = 1 + scalar @output + scalar @difftables;
1794 return pack "S<*", $len, @output, @difftables;
1798 ################################################################
1799 # dump case mappings for l_intl.nls
1800 sub dump_intl_nls
($)
1802 my $filename = shift;
1803 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1804 printf "Building $filename\n";
1807 print OUTPUT
pack "S<", 1; # version
1808 print OUTPUT dump_binary_case_table
( @toupper_table );
1809 print OUTPUT dump_binary_case_table
( @tolower_table );
1811 save_file
($filename);
1815 sub load_nameprep_range_table
($$$)
1817 my ($INPUT, $val, $table_ref) = @_;
1821 if (/^\s*([0-9a-fA-F]+)-([0-9a-fA-F]+)/)
1824 $last = 65535 if($last >= 65536);
1825 foreach my $i (hex $1 .. $last)
1827 $table_ref->[$i] |= $val;
1831 elsif (/^\s*([0-9a-fA-F]+)/)
1835 $table_ref->[hex $1] |= $val;
1840 return if (/End\sTable/);
1844 sub load_nameprep_map_table
($$)
1846 my ($INPUT, $table_ref) = @_;
1850 if (/^\s*([0-9a-fA-F]+);\s;/)
1852 # special value for map to nothing
1853 $table_ref->[hex $1] = [0xffff, 0xffff, 0xffff];
1856 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+);/)
1858 $table_ref->[hex $1] = [hex $2, 0, 0];
1861 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+)\s([0-9a-fA-F]+);/)
1863 $table_ref->[hex $1] = [hex $2, hex $3, 0];
1866 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+)\s([0-9a-fA-F]+)\s([0-9a-fA-F]+);/)
1868 $table_ref->[hex $1] = [hex $2, hex $3, hex $4];
1872 return if (/End\sTable/);
1876 ################################################################
1877 # dump mapping table, prohibited characters set, unassigned
1878 # characters, bidirectional rules used by nameprep algorithm
1879 sub dump_nameprep
($)
1881 my $filename = shift;
1882 my @mapping_table = ();
1883 my @flags_table = (0) x
65536;
1885 my $INPUT = open_data_file
( $RFCS, $STRINGPREP );
1888 next unless /Start\sTable/;
1890 load_nameprep_range_table
($INPUT, $nameprep_flags{"unassigned"}, \
@flags_table) if (/A.1/);
1891 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.1.2/);
1892 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.2.2/);
1893 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.3/);
1894 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.4/);
1895 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.5/);
1896 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.6/);
1897 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.7/);
1898 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.8/);
1899 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.9/);
1900 load_nameprep_range_table
($INPUT, $nameprep_flags{"bidi_ral"}, \
@flags_table) if (/D.1/);
1901 load_nameprep_range_table
($INPUT, $nameprep_flags{"bidi_l"}, \
@flags_table) if (/D.2/);
1903 load_nameprep_map_table
($INPUT, \
@mapping_table) if (/B.1/);
1904 load_nameprep_map_table
($INPUT, \
@mapping_table) if (/B.2/);
1908 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1909 print "Building $filename\n";
1910 print OUTPUT
"/* Nameprep algorithm related data */\n";
1911 print OUTPUT
"/* generated from $RFCS/$STRINGPREP */\n";
1912 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1914 dump_two_level_mapping
( "nameprep_char_type", @flags_table );
1916 ######### mapping table
1917 # first determine all the 16-char subsets that contain something
1919 my $pos = 16*3; # for the null subset
1920 for (my $i = 0; $i < 65536; $i++)
1922 next unless defined $mapping_table[$i];
1923 $filled[$i >> 4] = $pos;
1929 # now count the 256-char subsets that contain something
1930 my @filled_idx = (256) x
256;
1932 for (my $i = 0; $i < 4096; $i++)
1934 next unless $filled[$i];
1935 $filled_idx[$i >> 4] = $pos;
1939 my $null_offset = $pos;
1942 # add the index offsets to the subsets positions
1943 for (my $i = 0; $i < 4096; $i++)
1945 next unless $filled[$i];
1946 $filled[$i] += $null_offset;
1949 # dump the main index
1950 printf OUTPUT
"const unsigned short nameprep_mapping[%d] =\n", $total;
1951 printf OUTPUT
"{\n /* index */\n";
1952 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @filled_idx );
1953 printf OUTPUT
",\n /* null sub-index */\n%s", DUMP_ARRAY
( "0x%04x", 0, ($null_offset) x
16 );
1955 # dump the second-level indexes
1956 for (my $i = 0; $i < 256; $i++)
1958 next unless ($filled_idx[$i] > 256);
1959 my @table = @filled[($i<<4)..($i<<4)+15];
1960 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
1961 printf OUTPUT
",\n /* sub-index %02x */\n", $i;
1962 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @table );
1965 # dump the 16-char subsets
1966 printf OUTPUT
",\n /* null mapping */\n";
1967 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, (0) x
48 );
1969 for (my $i = 0; $i < 4096; $i++)
1971 next unless $filled[$i];
1972 my @table = (0) x
48;
1973 for (my $j = 0; $j < 16; $j++)
1975 if (defined $mapping_table[($i<<4) + $j])
1977 $table[3 * $j] = ${$mapping_table[($i << 4) + $j]}[0];
1978 $table[3 * $j + 1] = ${$mapping_table[($i << 4) + $j]}[1];
1979 $table[3 * $j + 2] = ${$mapping_table[($i << 4) + $j]}[2];
1982 printf OUTPUT
",\n /* 0x%03x0 .. 0x%03xf */\n", $i, $i;
1983 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @table );
1986 printf OUTPUT
"\n};\n";
1989 save_file
($filename);
1992 ################################################################
1993 # dump the ctype tables
1994 sub DUMP_CTYPE_TABLES
($)
1996 my $filename = shift;
1997 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1998 printf "Building $filename\n";
1999 printf OUTPUT
"/* Unicode ctype tables */\n";
2000 printf OUTPUT
"/* Automatically generated; DO NOT EDIT!! */\n\n";
2001 printf OUTPUT
"#include \"wine/unicode.h\"\n\n";
2003 # add the direction in the high 4 bits of the category
2004 for (my $i = 0; $i < 65536; $i++)
2006 $category_table[$i] |= $direction_table[$i] << 12 if defined $direction_table[$i];
2009 dump_simple_mapping
( "wine_wctype_table", @category_table );
2012 save_file
($filename);
2016 ################################################################
2017 # dump the char composition tables
2018 sub DUMP_COMPOSE_TABLES
($)
2020 my $filename = shift;
2022 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2023 printf "Building $filename\n";
2024 printf OUTPUT
"/* Unicode char composition */\n";
2025 printf OUTPUT
"/* Automatically generated; DO NOT EDIT!! */\n\n";
2026 printf OUTPUT
"#include \"wine/unicode.h\"\n\n";
2028 ######### composition table
2031 foreach my $i (@compose_table)
2034 push @
{$filled[$comp[1]]}, [ $comp[0], $comp[2] ];
2037 # count how many different second chars we have
2040 for (my $i = 0; $i < 65536; $i++)
2042 next unless defined $filled[$i];
2046 # build the table of second chars and offsets
2048 my $pos = $count + 1;
2050 for (my $i = 0; $i < 65536; $i++)
2052 next unless defined $filled[$i];
2053 push @table, $i, $pos;
2054 $pos += @
{$filled[$i]};
2056 # terminator with last position
2057 push @table, 0, $pos;
2058 printf OUTPUT
"const WCHAR unicode_compose_table[0x%x] =\n{\n", 2*$pos;
2059 printf OUTPUT
" /* second chars + offsets */\n%s", DUMP_ARRAY
( "0x%04x", 0, @table );
2061 # build the table of first chars and mappings
2063 for (my $i = 0; $i < 65536; $i++)
2065 next unless defined $filled[$i];
2067 my @list = sort { $a->[0] <=> $b->[0] } @
{$filled[$i]};
2068 for (my $j = 0; $j <= $#list; $j++)
2070 push @table, $list[$j][0], $list[$j][1];
2072 printf OUTPUT
",\n /* 0x%04x */\n%s", $i, DUMP_ARRAY
( "0x%04x", 0, @table );
2074 printf OUTPUT
"\n};\n\nconst unsigned int unicode_compose_table_size = %d;\n\n", $count;
2076 ######### decomposition table
2078 # first determine all the 16-char subsets that contain something
2080 @filled = (0) x
4096;
2081 $pos = 16*2; # for the null subset
2082 for (my $i = 0; $i < 65536; $i++)
2084 next unless defined $decomp_table[$i];
2085 $filled[$i >> 4] = $pos;
2091 # now count the 256-char subsets that contain something
2093 my @filled_idx = (256) x
256;
2095 for (my $i = 0; $i < 4096; $i++)
2097 next unless $filled[$i];
2098 $filled_idx[$i >> 4] = $pos;
2102 my $null_offset = $pos; # null mapping
2105 # add the index offsets to the subsets positions
2107 for (my $i = 0; $i < 4096; $i++)
2109 next unless $filled[$i];
2110 $filled[$i] += $null_offset;
2113 # dump the main index
2115 printf OUTPUT
"const WCHAR unicode_decompose_table[%d] =\n", $total;
2116 printf OUTPUT
"{\n /* index */\n";
2117 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @filled_idx );
2118 printf OUTPUT
",\n /* null sub-index */\n%s", DUMP_ARRAY
( "0x%04x", 0, ($null_offset) x
16 );
2120 # dump the second-level indexes
2122 for (my $i = 0; $i < 256; $i++)
2124 next unless ($filled_idx[$i] > 256);
2125 my @table = @filled[($i<<4)..($i<<4)+15];
2126 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
2127 printf OUTPUT
",\n /* sub-index %02x */\n", $i;
2128 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @table );
2131 # dump the 16-char subsets
2133 printf OUTPUT
",\n /* null mapping */\n";
2134 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, (0) x
32 );
2136 for (my $i = 0; $i < 4096; $i++)
2138 next unless $filled[$i];
2139 my @table = (0) x
32;
2140 for (my $j = 0; $j < 16; $j++)
2142 if (defined $decomp_table[($i<<4) + $j])
2144 $table[2 * $j] = ${$decomp_table[($i << 4) + $j]}[0];
2145 $table[2 * $j + 1] = ${$decomp_table[($i << 4) + $j]}[1];
2148 printf OUTPUT
",\n /* 0x%03x0 .. 0x%03xf */\n", $i, $i;
2149 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @table );
2152 printf OUTPUT
"\n};\n";
2154 save_file
($filename);
2157 ################################################################
2158 # output a codepage definition file from the global tables
2159 sub output_codepage_file
($$$$)
2161 my ($codepage, $filename, $comment, $has_glyphs) = @_;
2163 my $output = sprintf "libs/wine/c_%03d.c", $codepage;
2164 open OUTPUT
,">$output.new" or die "Cannot create $output";
2166 printf "Building %s from %s (%s)\n", $output, $filename || "hardcoded data", $comment;
2170 printf OUTPUT
"/* code page %03d (%s) */\n", $codepage, $comment;
2173 print OUTPUT
"/* generated from $MAPPINGS/$filename */\n";
2174 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
2178 printf OUTPUT
"/* Automatically generated; DO NOT EDIT!! */\n\n";
2180 printf OUTPUT
"#include \"wine/unicode.h\"\n\n";
2182 if (!@lead_bytes) { dump_sbcs_table
( $codepage, $has_glyphs, $comment, $default_char, $default_wchar ); }
2183 else { dump_dbcs_table
( $codepage, $comment, $default_char, $default_wchar, get_lb_ranges
() ); }
2188 ################################################################
2189 # read a "bestfit" Windows mapping file
2190 sub read_bestfit_file
($)
2192 my ($filename) = @_;
2194 my ($codepage, $width, $count);
2195 my ($lb_cur, $lb_end);
2197 my $INPUT = open_data_file
( $MAPPINGS, $filename ) or die "Cannot open $filename";
2201 next if /^;/; # skip comments
2202 next if /^\s*$/; # skip empty lines
2203 next if /\x1a/; # skip ^Z
2204 last if /^ENDCODEPAGE/;
2206 if (/^CODEPAGE\s+(\d+)/)
2211 if (/^CPINFO\s+(\d+)\s+0x([0-9a-fA-f]+)\s+0x([0-9a-fA-F]+)/)
2214 $default_char = hex $2;
2215 $default_wchar = hex $3;
2218 if (/^(MBTABLE|WCTABLE|DBCSRANGE|DBCSTABLE)\s+(\d+)/)
2224 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)/)
2226 if ($state eq "MBTABLE")
2230 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
2233 if ($state eq "WCTABLE")
2237 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
2240 if ($state eq "DBCSRANGE")
2244 for (my $i = $start; $i <= $end; $i++) { add_lead_byte
( $i ); }
2249 if ($state eq "DBCSTABLE")
2253 my $cp = ($lb_cur << 8) | $mb;
2254 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
2257 if (++$lb_cur > $lb_end) { $state = "DBCSRANGE"; }
2262 die "$filename: Unrecognized line $_\n";
2268 ################################################################
2269 # read an input file and generate the corresponding .c file
2272 my ($codepage,$filename,$has_glyphs,$comment,$first_private,$def,$defw) = @_;
2277 $default_char = $def || $DEF_CHAR;
2278 $default_wchar = $defw || $DEF_CHAR;
2280 # some codepage files are special
2281 if ($codepage == 20932)
2283 READ_JIS0208_FILE
( $filename );
2284 add_default_mappings
( $first_private );
2286 elsif ($codepage == 20127)
2288 fill_20127_codepage
();
2289 add_default_mappings
( $first_private );
2291 elsif ($filename =~ /\/bestfit
/)
2293 read_bestfit_file
( $filename );
2297 read_codepage_file
( $filename );
2298 if ($codepage == 10001)
2300 # add Shift-JIS mappings
2301 read_bestfit_file
( "VENDORS/MICSFT/WindowsBestFit/bestfit932.txt" );
2305 add_default_mappings
( $first_private );
2309 output_codepage_file
( $codepage, $filename, $comment, $has_glyphs );
2313 ################################################################
2314 # save a file if modified
2318 if (-f
$file && !system "cmp $file $file.new >/dev/null")
2324 rename "$file.new", "$file";
2329 ################################################################
2330 # output the list of codepage tables into the cptable.c file
2331 sub output_cptable
($)
2334 my @tables_decl = ();
2336 printf "Building %s\n", $output;
2338 foreach my $file (@allfiles)
2340 my ($codepage,$filename) = @
$file;
2341 push @tables_decl, sprintf("extern union cptable cptable_%03d;\n",$codepage);
2344 push @tables_decl, sprintf("\nstatic const union cptable * const cptables[%d] =\n{\n",$#allfiles+1);
2345 foreach my $file (@allfiles)
2347 my ($codepage,$filename) = @
$file;
2348 push @tables_decl, sprintf(" &cptable_%03d,\n", $codepage);
2350 push @tables_decl, "};";
2351 REPLACE_IN_FILE
( $output, @tables_decl );
2354 ################################################################
2355 # replace the contents of a file between ### cpmap ### marks
2357 sub REPLACE_IN_FILE
($@
)
2362 open(FILE
,$name) or die "Can't open $name";
2366 last if /\#\#\# cpmap begin \#\#\#/;
2371 if (/\#\#\# cpmap end \#\#\#/) { push @lines, "\n", $_; last; }
2373 push @lines, <FILE
>;
2374 open(FILE
,">$name.new") or die "Can't modify $name";
2380 ################################################################
2383 chdir ".." if -f
"./make_unicode";
2384 READ_DEFAULTS
( $DEFAULTS );
2385 DUMP_CASE_MAPPINGS
( "libs/wine/casemap.c" );
2386 DUMP_SORTKEYS
( "libs/wine/collation.c", READ_SORTKEYS_FILE
() );
2387 DUMP_COMPOSE_TABLES
( "libs/wine/compose.c" );
2388 DUMP_CTYPE_TABLES
( "libs/wine/wctype.c" );
2389 dump_mirroring
( "dlls/usp10/mirror.c" );
2390 dump_mirroring
( "dlls/dwrite/mirror.c" );
2391 dump_bracket
( "dlls/usp10/bracket.c" );
2392 dump_bracket
( "dlls/dwrite/bracket.c" );
2393 dump_shaping
( "dlls/usp10/shaping.c" );
2394 dump_linebreak
( "dlls/usp10/linebreak.c" );
2395 dump_linebreak
( "dlls/dwrite/linebreak.c" );
2396 dump_scripts
( "dlls/dwrite/scripts" );
2397 dump_indic
( "dlls/usp10/indicsyllable.c" );
2398 dump_intl_nls
("loader/l_intl.nls");
2399 dump_vertical
( "dlls/gdi32/vertical.c" );
2400 dump_vertical
( "dlls/wineps.drv/vertical.c" );
2401 dump_nameprep
( "dlls/kernel32/nameprep.c" );
2403 foreach my $file (@allfiles) { HANDLE_FILE
( @
{$file} ); }
2405 output_cptable
("libs/wine/cptable.c");
2410 # compile-command: "./make_unicode"