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.0.0/ucd";
27 my $REPORTS = "http://www.unicode.org/reports";
28 my $RFCS = "http://www.rfc-editor.org/rfc";
31 my $SORTKEYS = "tr10/allkeys.txt";
33 # RFC3454 (stringprep data)
34 my $STRINGPREP = "rfc3454.txt";
37 my $DEFAULTS = "tools/unicode-defaults";
39 # Default char for undefined mappings
40 my $DEF_CHAR = ord '?';
44 [ 37, "VENDORS/MICSFT/EBCDIC/CP037.TXT", 0, "IBM EBCDIC US Canada", 0, 0x6f ],
45 [ 424, "VENDORS/MISC/CP424.TXT", 0, "IBM EBCDIC Hebrew" ],
46 [ 437, "VENDORS/MICSFT/PC/CP437.TXT", 1, "OEM United States" ],
47 [ 500, "VENDORS/MICSFT/EBCDIC/CP500.TXT", 0, "IBM EBCDIC International", 0, 0x6f ],
48 [ 737, "VENDORS/MICSFT/PC/CP737.TXT", 1, "OEM Greek 437G" ],
49 [ 775, "VENDORS/MICSFT/PC/CP775.TXT", 1, "OEM Baltic" ],
50 [ 850, "VENDORS/MICSFT/PC/CP850.TXT", 1, "OEM Multilingual Latin 1" ],
51 [ 852, "VENDORS/MICSFT/PC/CP852.TXT", 1, "OEM Slovak Latin 2" ],
52 [ 855, "VENDORS/MICSFT/PC/CP855.TXT", 1, "OEM Cyrillic" ],
53 [ 856, "VENDORS/MISC/CP856.TXT", 0, "Hebrew PC" ],
54 [ 857, "VENDORS/MICSFT/PC/CP857.TXT", 1, "OEM Turkish", 0xf8bb ],
55 [ 860, "VENDORS/MICSFT/PC/CP860.TXT", 1, "OEM Portuguese" ],
56 [ 861, "VENDORS/MICSFT/PC/CP861.TXT", 1, "OEM Icelandic" ],
57 [ 862, "VENDORS/MICSFT/PC/CP862.TXT", 1, "OEM Hebrew" ],
58 [ 863, "VENDORS/MICSFT/PC/CP863.TXT", 1, "OEM Canadian French" ],
59 [ 864, "VENDORS/MICSFT/PC/CP864.TXT", 0, "OEM Arabic", 0xf8bb ],
60 [ 865, "VENDORS/MICSFT/PC/CP865.TXT", 1, "OEM Nordic" ],
61 [ 866, "VENDORS/MICSFT/PC/CP866.TXT", 1, "OEM Russian" ],
62 [ 869, "VENDORS/MICSFT/PC/CP869.TXT", 1, "OEM Greek" ],
63 [ 874, "VENDORS/MICSFT/WindowsBestFit/bestfit874.txt", 1, "ANSI/OEM Thai" ],
64 [ 875, "VENDORS/MICSFT/EBCDIC/CP875.TXT", 0, "IBM EBCDIC Greek", 0, 0x6f ],
65 [ 878, "VENDORS/MISC/KOI8-R.TXT", 0, "Russian KOI8" ],
66 [ 932, "VENDORS/MICSFT/WindowsBestFit/bestfit932.txt", 0, "ANSI/OEM Japanese Shift-JIS" ],
67 [ 936, "VENDORS/MICSFT/WindowsBestFit/bestfit936.txt", 0, "ANSI/OEM Simplified Chinese GBK" ],
68 [ 949, "VENDORS/MICSFT/WindowsBestFit/bestfit949.txt", 0, "ANSI/OEM Korean Unified Hangul" ],
69 [ 950, "VENDORS/MICSFT/WindowsBestFit/bestfit950.txt", 0, "ANSI/OEM Traditional Chinese Big5" ],
70 [ 1006, "VENDORS/MISC/CP1006.TXT", 0, "IBM Arabic" ],
71 [ 1026, "VENDORS/MICSFT/EBCDIC/CP1026.TXT", 0, "IBM EBCDIC Latin 5 Turkish", 0, 0x6f ],
72 [ 1250, "VENDORS/MICSFT/WindowsBestFit/bestfit1250.txt", 0, "ANSI Eastern Europe" ],
73 [ 1251, "VENDORS/MICSFT/WindowsBestFit/bestfit1251.txt", 0, "ANSI Cyrillic" ],
74 [ 1252, "VENDORS/MICSFT/WindowsBestFit/bestfit1252.txt", 0, "ANSI Latin 1" ],
75 [ 1253, "VENDORS/MICSFT/WindowsBestFit/bestfit1253.txt", 0, "ANSI Greek" ],
76 [ 1254, "VENDORS/MICSFT/WindowsBestFit/bestfit1254.txt", 0, "ANSI Turkish" ],
77 [ 1255, "VENDORS/MICSFT/WindowsBestFit/bestfit1255.txt", 0, "ANSI Hebrew" ],
78 [ 1256, "VENDORS/MICSFT/WindowsBestFit/bestfit1256.txt", 0, "ANSI Arabic" ],
79 [ 1257, "VENDORS/MICSFT/WindowsBestFit/bestfit1257.txt", 0, "ANSI Baltic" ],
80 [ 1258, "VENDORS/MICSFT/WindowsBestFit/bestfit1258.txt", 0, "ANSI/OEM Viet Nam" ],
81 [ 1361, "VENDORS/MICSFT/WindowsBestFit/bestfit1361.txt", 0, "Korean Johab" ],
82 [ 10000, "VENDORS/MICSFT/MAC/ROMAN.TXT", 0, "Mac Roman" ],
83 [ 10001, "VENDORS/APPLE/JAPANESE.TXT", 0, "Mac Japanese" ],
84 [ 10002, "VENDORS/APPLE/CHINTRAD.TXT", 0, "Mac Traditional Chinese" ],
85 [ 10003, "VENDORS/APPLE/KOREAN.TXT", 0, "Mac Korean", 0xf8e5 ],
86 [ 10004, "VENDORS/APPLE/ARABIC.TXT", 0, "Mac Arabic", 0xf826 ],
87 [ 10005, "VENDORS/APPLE/HEBREW.TXT", 0, "Mac Hebrew", 0xf7fa ],
88 [ 10006, "VENDORS/MICSFT/MAC/GREEK.TXT", 0, "Mac Greek" ],
89 [ 10007, "VENDORS/MICSFT/MAC/CYRILLIC.TXT", 0, "Mac Cyrillic" ],
90 [ 10008, "VENDORS/APPLE/CHINSIMP.TXT", 0, "Mac Simplified Chinese" ],
91 [ 10010, "VENDORS/APPLE/ROMANIAN.TXT", 0, "Mac Romanian" ],
92 [ 10017, "VENDORS/APPLE/CYRILLIC.TXT", 0, "Mac Ukrainian" ],
93 [ 10021, "VENDORS/APPLE/THAI.TXT", 0, "Mac Thai" ],
94 [ 10029, "VENDORS/MICSFT/MAC/LATIN2.TXT", 0, "Mac Latin 2" ],
95 [ 10079, "VENDORS/MICSFT/MAC/ICELAND.TXT", 0, "Mac Icelandic" ],
96 [ 10081, "VENDORS/MICSFT/MAC/TURKISH.TXT", 0, "Mac Turkish", 0xf89f ],
97 [ 10082, "VENDORS/APPLE/CROATIAN.TXT", 0, "Mac Croatian" ],
98 [ 20127, undef, 0, "US-ASCII (7bit)" ],
99 [ 20866, "VENDORS/MISC/KOI8-R.TXT", 0, "Russian KOI8" ],
100 [ 20932, "OBSOLETE/EASTASIA/JIS/JIS0208.TXT", 0, "EUC-JP", 0, 0x3f, 0x30fb ],
101 [ 21866, "VENDORS/MISC/KOI8-U.TXT", 0, "Ukrainian KOI8" ],
102 [ 28591, "ISO8859/8859-1.TXT", 0, "ISO 8859-1 Latin 1" ],
103 [ 28592, "ISO8859/8859-2.TXT", 0, "ISO 8859-2 Latin 2 (East European)" ],
104 [ 28593, "ISO8859/8859-3.TXT", 0, "ISO 8859-3 Latin 3 (South European)", 0xf7f5 ],
105 [ 28594, "ISO8859/8859-4.TXT", 0, "ISO 8859-4 Latin 4 (Baltic old)" ],
106 [ 28595, "ISO8859/8859-5.TXT", 0, "ISO 8859-5 Cyrillic" ],
107 [ 28596, "ISO8859/8859-6.TXT", 0, "ISO 8859-6 Arabic", 0xf7c8 ],
108 [ 28597, "ISO8859/8859-7.TXT", 0, "ISO 8859-7 Greek", 0xf7c5 ],
109 [ 28598, "ISO8859/8859-8.TXT", 0, "ISO 8859-8 Hebrew", 0xf79c ],
110 [ 28599, "ISO8859/8859-9.TXT", 0, "ISO 8859-9 Latin 5 (Turkish)" ],
111 [ 28600, "ISO8859/8859-10.TXT", 0, "ISO 8859-10 Latin 6 (Nordic)" ],
112 [ 28603, "ISO8859/8859-13.TXT", 0, "ISO 8859-13 Latin 7 (Baltic)" ],
113 [ 28604, "ISO8859/8859-14.TXT", 0, "ISO 8859-14 Latin 8 (Celtic)" ],
114 [ 28605, "ISO8859/8859-15.TXT", 0, "ISO 8859-15 Latin 9 (Euro)" ],
115 [ 28606, "ISO8859/8859-16.TXT", 0, "ISO 8859-16 Latin 10 (Balkan)" ]
144 "Avagraha" => 0x0003,
147 "Vowel_Independent" => 0x0006,
148 "Vowel_Dependent" => 0x0007,
150 "Consonant_Placeholder" => 0x0009,
151 "Consonant" => 0x000a,
152 "Consonant_Dead" => 0x000b,
153 "Consonant_Succeeding_Repha" => 0x000c,
154 "Consonant_Subjoined" => 0x000d,
155 "Consonant_Medial" => 0x000e,
156 "Consonant_Final" => 0x000f,
157 "Consonant_Head_Letter" => 0x0010,
158 "Modifying_Letter" => 0x0011,
159 "Tone_Letter" => 0x0012,
160 "Tone_Mark" => 0x0013,
161 "Register_Shifter" => 0x0014,
162 "Consonant_Preceding_Repha" => 0x0015,
163 "Pure_Killer" => 0x0016,
164 "Invisible_Stacker" => 0x0017,
165 "Gemination_Mark" => 0x0018,
166 "Cantillation_Mark" => 0x0019,
167 "Non_Joiner" => 0x001a,
169 "Number_Joiner" => 0x001c,
171 "Brahmi_Joining_Number" => 0x001e,
172 "Consonant_With_Stacker" => 0x001f,
173 "Consonant_Prefixed" => 0x0020,
174 "Syllable_Modifier" => 0x0021,
175 "Consonant_Killer" => 0x0022,
176 "Consonant_Initial_Postfixed" => 0x0023,
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,
195 "Bottom_And_Left" => 0x0f
200 "unassigned" => 0x01,
201 "prohibited" => 0x02,
263 "Lu" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"upper"}, # Letter, Uppercase
264 "Ll" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"lower"}, # Letter, Lowercase
265 "Lt" => $ctype{"defin"}|$ctype{"alpha"}|$ctype{"upper"}|$ctype{"lower"}, # Letter, Titlecase
266 "Mn" => $ctype{"defin"}, # Mark, Non-Spacing
267 "Mc" => $ctype{"defin"}, # Mark, Spacing Combining
268 "Me" => $ctype{"defin"}, # Mark, Enclosing
269 "Nd" => $ctype{"defin"}|$ctype{"digit"}, # Number, Decimal Digit
270 "Nl" => $ctype{"defin"}|$ctype{"alpha"}, # Number, Letter
271 "No" => $ctype{"defin"}, # Number, Other
272 "Zs" => $ctype{"defin"}|$ctype{"space"}, # Separator, Space
273 "Zl" => $ctype{"defin"}|$ctype{"space"}, # Separator, Line
274 "Zp" => $ctype{"defin"}|$ctype{"space"}, # Separator, Paragraph
275 "Cc" => $ctype{"defin"}|$ctype{"cntrl"}, # Other, Control
276 "Cf" => $ctype{"defin"}|$ctype{"cntrl"}, # Other, Format
277 "Cs" => $ctype{"defin"}, # Other, Surrogate
278 "Co" => $ctype{"defin"}, # Other, Private Use
279 "Cn" => $ctype{"defin"}, # Other, Not Assigned
280 "Lm" => $ctype{"defin"}|$ctype{"alpha"}, # Letter, Modifier
281 "Lo" => $ctype{"defin"}|$ctype{"alpha"}, # Letter, Other
282 "Pc" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Connector
283 "Pd" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Dash
284 "Ps" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Open
285 "Pe" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Close
286 "Pi" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Initial quote
287 "Pf" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Final quote
288 "Po" => $ctype{"defin"}|$ctype{"punct"}, # Punctuation, Other
289 "Sm" => $ctype{"defin"}, # Symbol, Math
290 "Sc" => $ctype{"defin"}, # Symbol, Currency
291 "Sk" => $ctype{"defin"}, # Symbol, Modifier
292 "So" => $ctype{"defin"} # Symbol, Other
295 # a few characters need additional categories that cannot be determined automatically
296 my %special_categories =
298 "xdigit" => [ ord('0')..ord('9'),ord('A')..ord('F'),ord('a')..ord('f'),
299 0xff10..0xff19
, 0xff21..0xff26
, 0xff41..0xff46
],
300 "space" => [ 0x09..0x0d
, 0x85 ],
301 "blank" => [ 0x09, 0x20, 0xa0, 0x3000, 0xfeff ],
302 "cntrl" => [ 0x070f, 0x200c, 0x200d,
303 0x200e, 0x200f, 0x202a, 0x202b, 0x202c, 0x202d, 0x202e,
304 0x206a, 0x206b, 0x206c, 0x206d, 0x206e, 0x206f, 0xfeff,
305 0xfff9, 0xfffa, 0xfffb ],
306 "punct" => [ 0x24, 0x2b, 0x3c..0x3e
, 0x5e, 0x60, 0x7c, 0x7e, 0xa2..0xbe
,
308 "digit" => [ 0xb2, 0xb3, 0xb9 ],
309 "lower" => [ 0x2071, 0x207f ]
314 "L" => 1, # Left-to-Right
315 "R" => 2, # Right-to-Left
316 "AL" => 12, # Right-to-Left Arabic
317 "EN" => 3, # European Number
318 "ES" => 4, # European Number Separator
319 "ET" => 5, # European Number Terminator
320 "AN" => 6, # Arabic Number
321 "CS" => 7, # Common Number Separator
322 "NSM" => 13, # Non-Spacing Mark
323 "BN" => 14, # Boundary Neutral
324 "B" => 8, # Paragraph Separator
325 "S" => 9, # Segment Separator
326 "WS" => 10, # Whitespace
327 "ON" => 11, # Other Neutrals
328 "LRE" => 15, # Left-to-Right Embedding
329 "LRO" => 15, # Left-to-Right Override
330 "RLE" => 15, # Right-to-Left Embedding
331 "RLO" => 15, # Right-to-Left Override
332 "PDF" => 15, # Pop Directional Format
333 "LRI" => 15, # Left-to-Right Isolate
334 "RLI" => 15, # Right-to-Left Isolate
335 "FSI" => 15, # First Strong Isolate
336 "PDI" => 15 # Pop Directional Isolate
341 "L" => 1, # C2_LEFTTORIGHT
342 "R" => 2, # C2_RIGHTTOLEFT
343 "AL" => 2, # C2_RIGHTTOLEFT
344 "EN" => 3, # C2_EUROPENUMBER
345 "ES" => 4, # C2_EUROPESEPARATOR
346 "ET" => 5, # C2_EUROPETERMINATOR
347 "AN" => 6, # C2_ARABICNUMBER
348 "CS" => 7, # C2_COMMONSEPARATOR
349 "NSM" => 0, # C2_NOTAPPLICABLE
350 "BN" => 0, # C2_NOTAPPLICABLE
351 "B" => 8, # C2_BLOCKSEPARATOR
352 "S" => 9, # C2_SEGMENTSEPARATOR
353 "WS" => 10, # C2_WHITESPACE
354 "ON" => 11, # C2_OTHERNEUTRAL
355 "LRE" => 11, # C2_OTHERNEUTRAL
356 "LRO" => 11, # C2_OTHERNEUTRAL
357 "RLE" => 11, # C2_OTHERNEUTRAL
358 "RLO" => 11, # C2_OTHERNEUTRAL
359 "PDF" => 11, # C2_OTHERNEUTRAL
360 "LRI" => 11, # C2_OTHERNEUTRAL
361 "RLI" => 11, # C2_OTHERNEUTRAL
362 "FSI" => 11, # C2_OTHERNEUTRAL
363 "PDI" => 11 # C2_OTHERNEUTRAL
368 "ON" => 0, # Other Neutrals
369 "L" => 1, # Left-to-Right
370 "R" => 2, # Right-to-Left
371 "AN" => 3, # Arabic Number
372 "EN" => 4, # European Number
373 "AL" => 5, # Right-to-Left Arabic
374 "NSM" => 6, # Non-Spacing Mark
375 "CS" => 7, # Common Number Separator
376 "ES" => 8, # European Number Separator
377 "ET" => 9, # European Number Terminator
378 "BN" => 10, # Boundary Neutral
379 "S" => 11, # Segment Separator
380 "WS" => 12, # Whitespace
381 "B" => 13, # Paragraph Separator
382 "RLO" => 14, # Right-to-Left Override
383 "RLE" => 15, # Right-to-Left Embedding
384 "LRO" => 16, # Left-to-Right Override
385 "LRE" => 17, # Left-to-Right Embedding
386 "PDF" => 18, # Pop Directional Format
387 "LRI" => 19, # Left-to-Right Isolate
388 "RLI" => 20, # Right-to-Left Isolate
389 "FSI" => 21, # First Strong Isolate
390 "PDI" => 22 # Pop Directional Isolate
395 "U" => 0, # Non_Joining
396 "T" => 1, # Transparent
397 "R" => 2, # Right_Joining
398 "L" => 3, # Left_Joining
399 "D" => 4, # Dual_Joining
400 "C" => 5, # Join_Causing
406 my @unicode_defaults = ();
407 my @unicode_aliases = ();
408 my @tolower_table = ();
409 my @toupper_table = ();
410 my @digitmap_table = ();
411 my @compatmap_table = ();
412 my @category_table = ();
413 my @joining_table = ();
414 my @direction_table = ();
415 my @decomp_table = ();
416 my @compose_table = ();
417 my @combining_class_table = ();
418 my @full_compatmap_table = ();
430 ################################################################
431 # fetch a unicode.org file and open it
432 sub open_data_file
($$)
434 my ($base, $name) = @_;
435 (my $dir = "data/$name") =~ s
/\
/[^\/]+$//;
437 unless (-f
"data/$name")
439 print "Fetching $base/$name...\n";
440 system "mkdir", "-p", $dir;
441 !system "wget", "-q", "-O", "data/$name", "$base/$name" or die "cannot fetch $base/$name";
443 open FILE
, "<data/$name" or die "cannot open data/$name";
447 ################################################################
448 # read in the defaults file
451 my $filename = shift;
454 # first setup a few default mappings
456 open DEFAULTS
, "$filename" or die "Cannot open $filename";
457 print "Loading $filename\n";
460 next if /^\#/; # skip comments
461 next if /^$/; # skip empty lines
462 if (/^(([0-9a-fA-F]+)(,[0-9a-fA-F]+)*)\s+([0-9a-fA-F]+|'.'|none)\s+(\#.*)?/)
464 my @src = map hex, split /,/,$1;
467 if ($#src > 0) { push @unicode_aliases, \
@src; }
468 next if ($dst eq "none");
469 $dst = ($dst =~ /\'.\'/) ?
ord substr($dst,1,1) : hex $dst;
470 foreach my $src (@src)
472 die "Duplicate value" if defined($unicode_defaults[$src]);
473 $unicode_defaults[$src] = $dst;
477 die "Unrecognized line $_\n";
481 # now build mappings from the decomposition field of the Unicode database
483 my $UNICODE_DATA = open_data_file
( $UNIDATA, "UnicodeData.txt" );
484 while (<$UNICODE_DATA>)
486 # Decode the fields ...
487 my ($code, $name, $cat, $comb, $bidi,
488 $decomp, $dec, $dig, $num, $mirror,
489 $oldname, $comment, $upper, $lower, $title) = split /;/;
493 die "unknown category $cat" unless defined $categories{$cat};
494 die "unknown directionality $bidi" unless defined $directions{$bidi};
496 $category_table[$src] = $categories{$cat};
497 $direction_table[$src] = $bidi;
498 $joining_table[$src] = $joining_types{"T"} if $cat eq "Mn" || $cat eq "Me" || $cat eq "Cf";
502 $tolower_table[$src] = hex $lower;
506 $toupper_table[$src] = hex $upper;
510 $category_table[$src] |= $ctype{"digit"};
514 $digitmap_table[$src] = ord $dig;
518 $combining_class_table[$src] = $comb;
521 # copy the category and direction for everything between First/Last pairs
522 if ($name =~ /, First>/) { $start = $src; }
523 if ($name =~ /, Last>/)
525 while ($start < $src)
527 $category_table[$start] = $category_table[$src];
528 $direction_table[$start] = $direction_table[$src];
533 next if $decomp eq ""; # no decomposition, skip it
535 if ($decomp =~ /^<([a-zA-Z]+)>\s+([0-9a-fA-F]+)/)
538 for my $ch (split /\s+/, (split /\s+/, $decomp, 2)[1])
540 push @seq, (hex $ch);
542 $full_compatmap_table[$src] = \
@seq;
545 if ($decomp =~ /^<([a-zA-Z]+)>\s+([0-9a-fA-F]+)$/)
547 # decomposition of the form "<foo> 1234" -> use char if type is known
548 if (($src >= 0xf900 && $src < 0xfb00) || ($src >= 0xfe30 && $src < 0xfffd))
550 # Single char decomposition in the compatibility range
551 $compatmap_table[$src] = hex $2;
553 if ($1 eq "isolated" || $1 eq "final" || $1 eq "initial" || $1 eq "medial")
555 ${joining_forms
{$1}}[hex $2] = $src;
558 next unless ($1 eq "font" ||
569 elsif ($decomp =~ /^<compat>\s+0020\s+([0-9a-fA-F]+)/)
571 # decomposition "<compat> 0020 1234" -> combining accent
574 elsif ($decomp =~ /^([0-9a-fA-F]+)/)
576 # decomposition contains only char values without prefix -> use first char
578 $category_table[$src] |= $category_table[$dst] if defined $category_table[$dst];
579 # store decomposition if it contains two chars
580 if ($decomp =~ /^([0-9a-fA-F]+)\s+([0-9a-fA-F]+)$/)
582 $decomp_table[$src] = [ hex $1, hex $2 ];
583 push @compose_table, [ hex $1, hex $2, $src ];
585 elsif ($decomp =~ /^([0-9a-fA-F]+)$/)
587 # Single char decomposition
590 $decomp_table[$src] = [ hex $1, 0 ];
593 if (($src >= 0xf900 && $src < 0xfb00) || ($src >= 0xfe30 && $src < 0xfffd))
595 # Single char decomposition in the compatibility range
596 $compatmap_table[$src] = hex $1;
605 next if defined($unicode_defaults[$src]); # may have been set in the defaults file
608 for (my $i = $dst; ; $i = $unicode_defaults[$i])
610 die sprintf("loop detected for %04x -> %04x",$src,$dst) if $i == $src;
611 last unless defined($unicode_defaults[$i]);
613 $unicode_defaults[$src] = $dst;
617 # patch the category of some special characters
619 foreach my $cat (keys %special_categories)
621 my $flag = $ctype{$cat};
622 foreach my $i (@
{$special_categories{$cat}}) { $category_table[$i] |= $flag; }
627 ################################################################
628 # define a new lead byte
632 push @lead_bytes, $ch;
636 ################################################################
637 # define a new char mapping
641 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
642 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
643 if ($cp > 0xff && !defined($cp2uni[$cp >> 8]))
645 add_lead_byte
( $cp >> 8 );
649 ################################################################
650 # parse a standard codepage file
651 sub read_codepage_file
($)
654 my $INPUT = open_data_file
( $MAPPINGS, $name );
658 next if /^\#/; # skip comments
659 next if /^$/; # skip empty lines
660 next if /\x1a/; # skip ^Z
661 next if (/^0x([0-9a-fA-F]+)\s+\#UNDEFINED/); # undefined char
663 if (/^0x([0-9a-fA-F]+)\s+\#DBCS LEAD BYTE/)
665 add_lead_byte
( hex $1 );
669 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
671 add_mapping
( hex $1, hex $2 );
675 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\+.*\s+(\#.*)?/)
677 add_mapping
( hex $1, hex $2 );
681 if (/^0x([0-9a-fA-F]+)\s+<LR>\+0x([0-9a-fA-F]+)\s+(\#.*)?/)
683 add_mapping
( hex $1, hex $2 );
687 if (/^0x([0-9a-fA-F]+)\s+<RL>\+0x([0-9a-fA-F]+)\s+(\#.*)?/)
690 add_mapping
( hex $1, $uni ) if $uni >= 0x80;
693 die "$name: Unrecognized line $_\n";
699 ################################################################
700 # fill input data for the 20127 (us-ascii) codepage
701 sub fill_20127_codepage
()
703 for (my $i = 0; $i < 128; $i++) { $cp2uni[$i] = $uni2cp[$i] = $i; }
704 for (my $i = 128; $i < 256; $i++) { $cp2uni[$i] = $i & 0x7f; }
707 ################################################################
708 # get a mapping including glyph chars for MB_USEGLYPHCHARS
710 sub get_glyphs_mapping
(@
)
712 $_[0x01] = 0x263a; # (WHITE SMILING FACE)
713 $_[0x02] = 0x263b; # (BLACK SMILING FACE)
714 $_[0x03] = 0x2665; # (BLACK HEART SUIT)
715 $_[0x04] = 0x2666; # (BLACK DIAMOND SUIT)
716 $_[0x05] = 0x2663; # (BLACK CLUB SUIT)
717 $_[0x06] = 0x2660; # (BLACK SPADE SUIT)
718 $_[0x07] = 0x2022; # (BULLET)
719 $_[0x08] = 0x25d8; # (INVERSE BULLET)
720 $_[0x09] = 0x25cb; # (WHITE CIRCLE)
721 $_[0x0a] = 0x25d9; # (INVERSE WHITE CIRCLE)
722 $_[0x0b] = 0x2642; # (MALE SIGN)
723 $_[0x0c] = 0x2640; # (FEMALE SIGN)
724 $_[0x0d] = 0x266a; # (EIGHTH NOTE)
725 $_[0x0e] = 0x266b; # (BEAMED EIGHTH NOTES)
726 $_[0x0f] = 0x263c; # (WHITE SUN WITH RAYS)
727 $_[0x10] = 0x25ba; # (BLACK RIGHT-POINTING POINTER)
728 $_[0x11] = 0x25c4; # (BLACK LEFT-POINTING POINTER)
729 $_[0x12] = 0x2195; # (UP DOWN ARROW)
730 $_[0x13] = 0x203c; # (DOUBLE EXCLAMATION MARK)
731 $_[0x14] = 0x00b6; # (PILCROW SIGN)
732 $_[0x15] = 0x00a7; # (SECTION SIGN)
733 $_[0x16] = 0x25ac; # (BLACK RECTANGLE)
734 $_[0x17] = 0x21a8; # (UP DOWN ARROW WITH BASE)
735 $_[0x18] = 0x2191; # (UPWARDS ARROW)
736 $_[0x19] = 0x2193; # (DOWNWARDS ARROW)
737 $_[0x1a] = 0x2192; # (RIGHTWARDS ARROW)
738 $_[0x1b] = 0x2190; # (LEFTWARDS ARROW)
739 $_[0x1c] = 0x221f; # (RIGHT ANGLE)
740 $_[0x1d] = 0x2194; # (LEFT RIGHT ARROW)
741 $_[0x1e] = 0x25b2; # (BLACK UP-POINTING TRIANGLE)
742 $_[0x1f] = 0x25bc; # (BLACK DOWN-POINTING TRIANGLE)
743 $_[0x7f] = 0x2302; # (HOUSE)
747 ################################################################
748 # build EUC-JP table from the JIS 0208 file
749 # FIXME: for proper EUC-JP we should probably read JIS 0212 too
750 # but this would require 3-byte DBCS characters
751 sub READ_JIS0208_FILE
($)
756 for (my $i = 0x00; $i <= 0x7f; $i++)
762 # JIS X 0201 right plane
763 for (my $i = 0xa1; $i <= 0xdf; $i++)
765 $cp2uni[0x8e00 + $i] = 0xfec0 + $i;
766 $uni2cp[0xfec0 + $i] = 0x8e00 + $i;
770 foreach my $i (0x8e, 0x8f, 0xa1 .. 0xfe)
776 foreach my $i (0x80 .. 0x8d, 0x90 .. 0xa0, 0xff)
778 $cp2uni[$i] = $DEF_CHAR;
781 # Shift-JIS compatibility
782 $uni2cp[0x00a5] = 0x5c;
783 $uni2cp[0x203e] = 0x7e;
785 # Fix backslash conversion
786 $cp2uni[0xa1c0] = 0xff3c;
787 $uni2cp[0xff3c] = 0xa1c0;
789 my $INPUT = open_data_file
( $MAPPINGS, $name );
792 next if /^\#/; # skip comments
793 next if /^$/; # skip empty lines
794 next if /\x1a/; # skip ^Z
795 if (/^0x[0-9a-fA-F]+\s+0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
797 my $cp = 0x8080 + hex $1;
799 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
800 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
803 die "$name: Unrecognized line $_\n";
809 ################################################################
810 # build the sort keys table
811 sub READ_SORTKEYS_FILE
()
814 for (my $i = 0; $i < 65536; $i++) { $sortkeys[$i] = [ -1, 0, 0, 0, 0 ] };
816 my $INPUT = open_data_file
( $REPORTS, $SORTKEYS );
819 next if /^\#/; # skip comments
820 next if /^$/; # skip empty lines
821 next if /\x1a/; # skip ^Z
822 next if /^\@version/; # skip @version header
823 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]+)\]/)
825 my ($uni,$variable) = (hex $1, $2);
826 next if $uni > 65535;
827 $sortkeys[$uni] = [ $uni, hex $3, hex $4, hex $5, hex $6 ];
830 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]+)\]/)
832 # multiple character sequence, ignored for now
835 die "$SORTKEYS: Unrecognized line $_\n";
839 # compress the keys to 32 bit:
840 # key 1 to 16 bits, key 2 to 8 bits, key 3 to 4 bits, key 4 to 1 bit
842 @sortkeys = sort { ${$a}[1] <=> ${$b}[1] or
843 ${$a}[2] <=> ${$b}[2] or
844 ${$a}[3] <=> ${$b}[3] or
845 ${$a}[4] <=> ${$b}[4] or
846 $a cmp $b; } @sortkeys;
848 my ($n2, $n3) = (1, 1);
849 my @keys = (-1, -1, -1, -1, -1 );
852 for (my $i = 0; $i < 65536; $i++)
854 my @current = @
{$sortkeys[$i]};
855 next if $current[0] == -1;
856 if ($current[1] == $keys[1])
858 if ($current[2] == $keys[2])
860 if ($current[3] == $keys[3])
866 $keys[3] = $current[3];
873 $keys[2] = $current[2];
874 $keys[3] = $current[3];
882 $keys[1] = $current[1];
883 $keys[2] = $current[2];
884 $keys[3] = $current[3];
889 if ($current[2]) { $current[2] = $n2; }
890 if ($current[3]) { $current[3] = $n3; }
891 if ($current[4]) { $current[4] = 1; }
893 $flatkeys[$current[0]] = ($current[1] << 16) | ($current[2] << 8) | ($current[3] << 4) | $current[4];
899 ################################################################
900 # build the sort keys table
901 sub dump_sortkeys
($@
)
903 my ($filename, @keys) = @_;
905 # count the number of 256-key ranges that contain something
909 for (my $i = 0; $i < 256; $i++) { $offsets[$i] = 256; }
910 for (my $i = 0; $i < 65536; $i++)
912 next unless defined $keys[$i];
913 $offsets[$i >> 8] = $ranges * 256;
918 # output the range offsets
920 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
921 printf "Building $filename\n";
922 printf OUTPUT
"/* Unicode collation element table */\n";
923 printf OUTPUT
"/* generated from %s */\n", "$REPORTS/$SORTKEYS";
924 printf OUTPUT
"/* DO NOT EDIT!! */\n\n";
925 print OUTPUT
"#include \"windef.h\"\n\n";
927 printf OUTPUT
"const unsigned int DECLSPEC_HIDDEN collation_table[%d] =\n{\n", $ranges*256;
928 printf OUTPUT
" /* index */\n";
929 printf OUTPUT
"%s,\n", DUMP_ARRAY
( "0x%08x", 0, @offsets );
931 # output the default values
933 printf OUTPUT
" /* defaults */\n";
934 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%08x", 0, (0xffffffff) x
256 );
936 # output all the key ranges
938 for (my $i = 0; $i < 256; $i++)
940 next if $offsets[$i] == 256;
941 printf OUTPUT
",\n /* 0x%02x00 .. 0x%02xff */\n", $i, $i;
942 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%08x", 0xffffffff, @keys[($i<<8) .. ($i<<8)+255] );
944 printf OUTPUT
"\n};\n";
946 save_file
($filename);
950 ################################################################
951 # add default mappings once the file had been read
952 sub add_default_mappings
($)
954 my $first_private = shift;
958 foreach my $alias (@unicode_aliases)
961 foreach my $src (@
$alias)
963 if (defined($uni2cp[$src]))
965 $target = $uni2cp[$src];
969 next unless defined($target);
971 # At least one char of the alias set is defined, set the others to the same value
972 foreach my $src (@
$alias)
974 $uni2cp[$src] = $target unless defined($uni2cp[$src]);
978 # For every src -> target mapping in the defaults table,
979 # make uni2cp[src] = uni2cp[target] if uni2cp[target] is defined
981 for (my $src = 0; $src < 65536; $src++)
983 next if defined($uni2cp[$src]); # source has a definition already
984 next unless defined($unicode_defaults[$src]); # no default for this char
985 my $target = $unicode_defaults[$src];
987 # do a recursive mapping until we find a target char that is defined
988 while (!defined($uni2cp[$target]) &&
989 defined($unicode_defaults[$target])) { $target = $unicode_defaults[$target]; }
991 if (defined($uni2cp[$target])) { $uni2cp[$src] = $uni2cp[$target]; }
994 # Add a private char mapping for undefined chars
998 for (my $i = 32; $i < 256; $i++)
1000 next if defined($cp2uni[$i]);
1001 $cp2uni[$i] = $first_private;
1002 $uni2cp[$first_private] = $i;
1007 # Add an identity mapping for all undefined chars
1009 for (my $i = 0; $i < 256; $i++)
1011 next if defined($cp2uni[$i]);
1012 next if defined($uni2cp[$i]);
1013 $cp2uni[$i] = $uni2cp[$i] = $i;
1017 ################################################################
1018 # dump an array of integers
1021 my ($format,$default,@array) = @_;
1024 for ($i = 0; $i < $#array; $i++)
1026 $ret .= sprintf($format, defined $array[$i] ?
$array[$i] : $default);
1027 $ret .= (($i % 8) != 7) ?
", " : ",\n ";
1029 $ret .= sprintf($format, defined $array[$i] ?
$array[$i] : $default);
1034 ################################################################
1035 # dump a unicode->ascii mapping table
1036 sub dump_uni2cp_table
($$)
1038 my ($width, $def) = @_;
1040 # count the number of unicode->ascii subtables that contain something
1045 my @filled = (-1) x
256;
1046 for (my $i = 0; $i < 65536; $i++)
1048 next unless defined $uni2cp[$i];
1049 if ($filled[$i >> 8] == -1)
1051 $lowerbounds[$index] = $i & 0xff;
1052 $upperbounds[$index] = 0xff - $lowerbounds[$index];
1053 $filled[$i >> 8] = $index * 256;
1058 $upperbounds[$index-1] = 0xff - ($i & 0xff);
1062 # add defaults mapping at the end
1063 $filled[256] = $index * 256;
1064 $lowerbounds[$index] = 255;
1065 $upperbounds[$index] = 0;
1068 # collapse blocks upwards if possible
1071 for (my $i = 0; $i < 257; $i++)
1073 next if $filled[$i] == -1;
1074 if ($upperbounds[$index - 1] > $lowerbounds[$index])
1076 $removed += $lowerbounds[$index];
1080 $removed += $upperbounds[$index - 1];
1081 $lowerbounds[$index] = $upperbounds[$index - 1];
1083 $filled[$i] -= $removed;
1087 # output all the subtables into a single array
1089 printf OUTPUT
"static const unsigned %s uni2cp_low[] =\n{\n", $width == 8 ?
"char" : "short";
1091 my $format = $width == 8 ?
"0x%02x" : "0x%04x";
1092 for (my $i = $index = 0; $i < 257; $i++)
1094 next if $filled[$i] == -1;
1095 my $start = ($i << 8) + $lowerbounds[$index];
1096 my $end = ($i << 8) + 255;
1099 print OUTPUT
" /* defaults */\n";
1100 printf OUTPUT
"%s\n};\n\n", DUMP_ARRAY
( $format, 0, ($def) x
($end - $start + 1) );
1104 printf OUTPUT
" /* 0x%04x .. 0x%04x */\n", $start, $end;
1105 printf OUTPUT
"%s,\n", DUMP_ARRAY
( $format, $def, @uni2cp[$start .. $end] );
1110 # output a table of the offsets of the subtables in the previous array
1112 for (my $i = 0; $i < 256; $i++)
1114 if ($filled[$i] == -1) { $filled[$i] = $filled[256]; }
1116 printf OUTPUT
"static const unsigned short uni2cp_high[256] =\n";
1117 printf OUTPUT
"{\n%s\n};\n\n", DUMP_ARRAY
( "0x%04x", 0, @filled[0..255] );
1120 ################################################################
1121 # dump an SBCS mapping table
1122 sub dump_sbcs_table
($$$$$)
1124 my ($codepage, $has_glyphs, $name, $def, $defw) = @_;
1127 # output the ascii->unicode table
1131 printf OUTPUT
"static const WCHAR cp2uni[512] =\n";
1132 printf OUTPUT
"{\n%s", DUMP_ARRAY
( "0x%04x", $defw, @cp2uni[0 .. 255] );
1133 printf OUTPUT
",\n /* glyphs */\n%s\n};\n\n",
1134 DUMP_ARRAY
( "0x%04x", $defw, get_glyphs_mapping
(@cp2uni[0 .. 255]) );
1138 printf OUTPUT
"static const WCHAR cp2uni[256] =\n";
1139 printf OUTPUT
"{\n%s\n};\n\n", DUMP_ARRAY
( "0x%04x", $defw, @cp2uni[0 .. 255] );
1142 dump_uni2cp_table
( 8, $def );
1144 # output the code page descriptor
1146 printf OUTPUT
"const struct sbcs_table DECLSPEC_HIDDEN cptable_%03d =\n{\n", $codepage;
1147 printf OUTPUT
" { %d, 1, 0x%04x, 0x%04x, \"%s\" },\n",
1148 $codepage, $def, $defw, $name;
1149 printf OUTPUT
" cp2uni,\n";
1150 if ($has_glyphs) { printf OUTPUT
" cp2uni + 256,\n"; }
1151 else { printf OUTPUT
" cp2uni,\n"; }
1152 printf OUTPUT
" uni2cp_low,\n";
1153 printf OUTPUT
" uni2cp_high\n};\n";
1157 ################################################################
1158 # dump a DBCS mapping table
1159 sub dump_dbcs_table
($$$$@
)
1161 my ($codepage, $name, $def, $defw, @lb_ranges) = @_;
1163 # build a list of lead bytes that are actually used
1166 LBLOOP
: for (my $y = 0; $y <= $#lead_bytes; $y++)
1168 $cp2uni[$lead_bytes[$y]] = $defw;
1169 my $base = $lead_bytes[$y] << 8;
1170 for (my $x = 0; $x < 256; $x++)
1172 if (defined $cp2uni[$base+$x])
1174 push @lblist,$lead_bytes[$y];
1179 my $unused = ($#lead_bytes > $#lblist);
1181 # output the ascii->unicode table for the single byte chars
1183 printf OUTPUT
"static const WCHAR cp2uni[%d] =\n", 256 * ($#lblist + 2 + $unused);
1184 printf OUTPUT
"{\n%s,\n", DUMP_ARRAY
( "0x%04x", $defw, @cp2uni[0 .. 255] );
1186 # output the default table for unused lead bytes
1190 printf OUTPUT
" /* unused lead bytes */\n";
1191 printf OUTPUT
"%s,\n", DUMP_ARRAY
( "0x%04x", 0, ($defw) x
256 );
1194 # output the ascii->unicode table for each DBCS lead byte
1196 for (my $y = 0; $y <= $#lblist; $y++)
1198 my $base = $lblist[$y] << 8;
1199 printf OUTPUT
" /* lead byte %02x */\n", $lblist[$y];
1200 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", $defw, @cp2uni[$base .. $base+255] );
1201 printf OUTPUT
($y < $#lblist) ?
",\n" : "\n};\n\n";
1204 # output the lead byte subtables offsets
1206 my @offsets = (0) x
256;
1207 for (my $x = 0; $x <= $#lblist; $x++) { $offsets[$lblist[$x]] = $x + 1; }
1210 # increment all lead bytes offset to take into account the unused table
1211 for (my $x = 0; $x <= $#lead_bytes; $x++) { $offsets[$lead_bytes[$x]]++; }
1213 printf OUTPUT
"static const unsigned char cp2uni_leadbytes[256] =\n";
1214 printf OUTPUT
"{\n%s\n};\n\n", DUMP_ARRAY
( "0x%02x", 0, @offsets );
1216 dump_uni2cp_table
( 16, $def );
1218 # output the code page descriptor
1220 printf OUTPUT
"const struct dbcs_table DECLSPEC_HIDDEN cptable_%03d =\n{\n", $codepage;
1221 printf OUTPUT
" { %d, 2, 0x%04x, 0x%04x, \"%s\" },\n",
1222 $codepage, $def, $defw, $name;
1223 printf OUTPUT
" cp2uni,\n";
1224 printf OUTPUT
" cp2uni_leadbytes,\n";
1225 printf OUTPUT
" uni2cp_low,\n";
1226 printf OUTPUT
" uni2cp_high,\n";
1227 printf OUTPUT
" {\n %s\n }\n", DUMP_ARRAY
( "0x%02x", 0, @lb_ranges, 0, 0 );
1228 printf OUTPUT
"};\n";
1232 ################################################################
1233 # get the list of defined lead byte ranges
1239 foreach $i (@lead_bytes) { $list[$i] = 1; }
1241 for (my $i = 0; $i < 256; $i++)
1245 if (!defined $list[$i]) { push @ranges, $i-1; $on = 0; }
1249 if ($list[$i]) { push @ranges, $i; $on = 1; }
1252 if ($on) { push @ranges, 0xff; }
1256 ################################################################
1257 # dump the Indic Syllabic Category table
1260 my $filename = shift;
1263 my $INPUT = open_data_file
( $UNIDATA, "IndicSyllabicCategory.txt" );
1266 next if /^\#/; # skip comments
1267 next if /^\s*$/; # skip empty lines
1268 next if /\x1a/; # skip ^Z
1269 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*#/)
1272 die "unknown indic $type" unless defined $indic_types{$type};
1275 $indic_table[hex $1] = $indic_types{$type};
1279 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*#/)
1282 die "unknown indic $type" unless defined $indic_types{$type};
1283 if (hex $1 < 65536 and hex $2 < 65536)
1285 foreach my $i (hex $1 .. hex $2)
1287 $indic_table[$i] = $indic_types{$type};
1292 die "malformed line $_";
1296 $INPUT = open_data_file
( $UNIDATA, "IndicPositionalCategory.txt" );
1299 next if /^\#/; # skip comments
1300 next if /^\s*$/; # skip empty lines
1301 next if /\x1a/; # skip ^Z
1302 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z]+)\s*#/)
1305 die "unknown matra $type" unless defined $matra_types{$type};
1306 $indic_table[hex $1] += $matra_types{$type} << 8;
1309 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*#/)
1312 die "unknown matra $type" unless defined $matra_types{$type};
1313 foreach my $i (hex $1 .. hex $2)
1315 $indic_table[$i] += $matra_types{$type} << 8;
1319 die "malformed line $_";
1323 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1324 print "Building $filename\n";
1325 print OUTPUT
"/* Unicode Indic Syllabic Category */\n";
1326 print OUTPUT
"/* generated from $UNIDATA/IndicSyllabicCategory.txt */\n";
1327 print OUTPUT
"/* and from $UNIDATA/IndicPositionalCategory.txt */\n";
1328 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1329 print OUTPUT
"#include \"windef.h\"\n\n";
1331 dump_two_level_mapping
( "indic_syllabic_table", $indic_types{'Other'}, @indic_table );
1334 save_file
($filename);
1337 ################################################################
1338 # dump the Line Break Properties table
1339 sub dump_linebreak
($)
1341 my $filename = shift;
1345 my $INPUT = open_data_file
( $UNIDATA, "LineBreak.txt" );
1348 next if /^\#/; # skip comments
1349 next if /^\s*$/; # skip empty lines
1350 next if /\x1a/; # skip ^Z
1351 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z][0-9A-Z])+\s*/)
1354 die "unknown breaktype $type" unless defined $break_types{$type};
1355 $break_table[hex $1] = $break_types{$type};
1358 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z][0-9A-Z])+\s*/)
1361 die "unknown breaktype $type" unless defined $break_types{$type};
1362 foreach my $i (hex $1 .. hex $2)
1364 $break_table[$i] = $break_types{$type};
1368 elsif (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z])+\s*/)
1371 die "unknown breaktype $type" unless defined $break_types{$type};
1372 $break_table[hex $1] = $break_types{$type};
1375 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([0-9A-Z][0-9A-Z])+\s*/)
1378 die "unknown breaktype $type" unless defined $break_types{$type};
1379 foreach my $i (hex $1 .. hex $2)
1381 $break_table[$i] = $break_types{$type};
1385 die "malformed line $_";
1389 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1390 print "Building $filename\n";
1391 print OUTPUT
"/* Unicode Line Break Properties */\n";
1392 print OUTPUT
"/* generated from $UNIDATA/LineBreak.txt */\n";
1393 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1394 print OUTPUT
"#include \"windef.h\"\n\n";
1396 dump_two_level_mapping
( "wine_linebreak_table", $break_types{'XX'}, @break_table );
1399 save_file
($filename);
1419 "Canadian_Aboriginal" => 15,
1429 "Egyptian_Hieroglyphs" => 25,
1442 "Imperial_Aramaic" => 38,
1443 "Inscriptional_Pahlavi" => 39,
1444 "Inscriptional_Parthian" => 40,
1462 "Meetei_Mayek" => 58,
1465 "New_Tai_Lue" => 61,
1470 "Old_Persian" => 66,
1471 "Old_South_Arabian" => 67,
1484 "Syloti_Nagri" => 80,
1502 "Meroitic_Cursive" => 97,
1503 "Meroitic_Hieroglyphs" => 98,
1506 "Sora_Sompeng" => 101,
1510 "Caucasian_Albanian" => 104,
1518 "Manichaean" => 112,
1519 "Mende_Kikakui" => 113,
1523 "Old_North_Arabian" => 117,
1524 "Old_Permic" => 118,
1525 "Pahawh_Hmong" => 119,
1527 "Pau_Cin_Hau" => 121,
1528 "Psalter_Pahlavi" => 122,
1531 "Warang_Citi" => 125,
1535 "Anatolian_Hieroglyphs" => 128,
1541 "Old_Hungarian" => 134,
1543 "SignWriting" => 136,
1546 "Masaram_Gondi" => 138,
1549 "Zanabazar_Square" => 141,
1552 ################################################################
1553 # dump Script IDs table
1556 my $filename = shift;
1557 my $header = $filename;
1562 my $INPUT = open_data_file
( $UNIDATA, "Scripts.txt" );
1564 # Unknown script id is always 0, so undefined scripts are automatically treated as such
1569 next if /^\#/; # skip comments
1570 next if /^\s*$/; # skip empty lines
1571 next if /\x1a/; # skip ^Z
1572 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1575 if (defined $scripts{$type})
1577 $scripts_table[hex $1] = $scripts{$type};
1581 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1584 if (defined $scripts{$type})
1586 foreach my $i (hex $1 .. hex $2)
1588 $scripts_table[$i] = $scripts{$type};
1597 $header = "$filename.h";
1598 open OUTPUT
,">$header.new" or die "Cannot create $header";
1599 print "Building $header\n";
1600 print OUTPUT
"/* Unicode Script IDs */\n";
1601 print OUTPUT
"/* generated from $UNIDATA/Scripts.txt */\n";
1602 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1604 print OUTPUT
"enum unicode_script_id {\n";
1605 foreach my $script (sort { $scripts{$a} <=> $scripts{$b} } keys %scripts)
1607 print OUTPUT
" Script_$script = $scripts{$script},\n";
1609 print OUTPUT
" Script_LastId = ", (scalar keys %scripts) - 1, "\n";
1610 print OUTPUT
"};\n";
1615 $filename = "$filename.c";
1616 open OUTPUT
,">$filename.new" or die "Cannot create $header";
1617 print "Building $filename\n";
1618 print OUTPUT
"/* Unicode Script IDs */\n";
1619 print OUTPUT
"/* generated from $UNIDATA/Scripts.txt */\n";
1620 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1621 print OUTPUT
"#include \"windef.h\"\n\n";
1623 dump_two_level_mapping
( "wine_scripts_table", 0, @scripts_table );
1625 save_file
($filename);
1628 ################################################################
1629 # dump the BiDi mirroring table
1630 sub dump_mirroring
($)
1632 my $filename = shift;
1633 my @mirror_table = ();
1635 my $INPUT = open_data_file
( $UNIDATA, "BidiMirroring.txt" );
1638 next if /^\#/; # skip comments
1639 next if /^$/; # skip empty lines
1640 next if /\x1a/; # skip ^Z
1641 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9a-fA-F]+)/)
1643 $mirror_table[hex $1] = hex $2;
1646 die "malformed line $_";
1650 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1651 print "Building $filename\n";
1652 print OUTPUT
"/* Unicode BiDi mirroring */\n";
1653 print OUTPUT
"/* generated from $UNIDATA/BidiMirroring.txt */\n";
1654 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1655 print OUTPUT
"#include \"windef.h\"\n\n";
1656 dump_case_table
( "DECLSPEC_HIDDEN wine_mirror_map", @mirror_table );
1658 save_file
($filename);
1661 ################################################################
1662 # dump the Bidi Brackets
1665 my $filename = shift;
1668 my $INPUT = open_data_file
( $UNIDATA, "BidiBrackets.txt" );
1671 next if /^\#/; # skip comments
1672 next if /^\s*$/; # skip empty lines
1673 next if /\x1a/; # skip ^Z
1674 if (/^\s*([0-9a-fA-F]+)\s*;\s*([0-9a-fA-F]+);\s*([con])/)
1677 die "unknown bracket $type" unless defined $bracket_types{$type};
1678 die "characters too distant $1 and $2" if abs(hex($2) - hex($1)) >= 128;
1679 $bracket_table[hex $1] = (hex($2) - hex($1)) % 255;
1680 $bracket_table[hex $1] += $bracket_types{$type} << 8;
1683 die "malformed line $_";
1687 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1688 print "Building $filename\n";
1689 print OUTPUT
"/* Unicode Bidirectional Bracket table */\n";
1690 print OUTPUT
"/* generated from $UNIDATA/BidiBrackets.txt */\n";
1691 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1692 print OUTPUT
"#include \"windef.h\"\n\n";
1694 dump_two_level_mapping
( "bidi_bracket_table", 0, @bracket_table );
1697 save_file
($filename);
1700 ################################################################
1701 # dump the Arabic shaping table
1704 my $filename = shift;
1708 $groups{"No_Joining_Group"} = $next_group++;
1710 my $INPUT = open_data_file
( $UNIDATA, "ArabicShaping.txt" );
1713 next if /^\#/; # skip comments
1714 next if /^\s*$/; # skip empty lines
1715 next if /\x1a/; # skip ^Z
1716 if (/^\s*([0-9a-fA-F]+)\s*;.*;\s*([RLDCUT])\s*;\s*(\w+)/)
1720 $groups{$group} = $next_group++ unless defined $groups{$group};
1721 $joining_table[hex $1] = $joining_types{$type} | ($groups{$group} << 8);
1724 die "malformed line $_";
1728 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1729 print "Building $filename\n";
1730 print OUTPUT
"/* Unicode Arabic shaping */\n";
1731 print OUTPUT
"/* generated from $UNIDATA/ArabicShaping.txt */\n";
1732 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1733 print OUTPUT
"#include \"windef.h\"\n\n";
1735 dump_two_level_mapping
( "wine_shaping_table", 0, @joining_table );
1737 print OUTPUT
"\nconst unsigned short DECLSPEC_HIDDEN wine_shaping_forms[256][4] =\n{\n";
1738 for (my $i = 0x600; $i <= 0x6ff; $i++)
1740 printf OUTPUT
" { 0x%04x, 0x%04x, 0x%04x, 0x%04x },\n",
1741 ${joining_forms
{"isolated"}}[$i] || $i,
1742 ${joining_forms
{"final"}}[$i] || $i,
1743 ${joining_forms
{"initial"}}[$i] || $i,
1744 ${joining_forms
{"medial"}}[$i] || $i;
1746 print OUTPUT
"};\n";
1749 save_file
($filename);
1752 ################################################################
1753 # dump the Vertical Orientation table
1754 sub dump_vertical
($)
1756 my $filename = shift;
1759 my $INPUT = open_data_file
( $UNIDATA, "VerticalOrientation.txt" );
1762 next if /^\#/; # skip comments
1763 next if /^\s*$/; # skip empty lines
1764 next if /\x1a/; # skip ^Z
1765 if (/^\s*([0-9a-fA-F]+)\s*;\s*([a-zA-Z_]+)\s*/)
1768 die "unknown vertical $type" unless defined $vertical_types{$type};
1771 $vertical_table[hex $1] = $vertical_types{$type};
1775 elsif (/^\s*([0-9a-fA-F]+)..\s*([0-9a-fA-F]+)\s*;\s*([A-Za-z_]+)\s*/)
1778 die "unknown vertical $type" unless defined $vertical_types{$type};
1779 foreach my $i (hex $1 .. hex $2)
1781 $vertical_table[$i] = $vertical_types{$type};
1785 die "malformed line $_";
1789 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1790 print "Building $filename\n";
1791 print OUTPUT
"/* Unicode Vertical Orientation */\n";
1792 print OUTPUT
"/* generated from $UNIDATA/VerticalOrientation.txt */\n";
1793 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1794 print OUTPUT
"#include \"windef.h\"\n\n";
1796 dump_two_level_mapping
( "vertical_orientation_table", $vertical_types{'R'}, @vertical_table );
1799 save_file
($filename);
1802 ################################################################
1803 # dump the digit folding tables
1804 sub dump_digit_folding
($)
1806 my $filename = shift;
1807 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1808 print "Building $filename\n";
1809 print OUTPUT
"/* Unicode digit folding mappings */\n";
1810 print OUTPUT
"/* generated from $UNIDATA/UnicodeData.txt */\n";
1811 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1812 print OUTPUT
"#include \"windef.h\"\n\n";
1814 dump_case_table
( "DECLSPEC_HIDDEN wine_digitmap", @digitmap_table );
1816 dump_case_table
( "DECLSPEC_HIDDEN wine_compatmap", @compatmap_table );
1818 save_file
($filename);
1822 ################################################################
1823 # dump the case mapping tables
1824 sub dump_case_mappings
($)
1826 my $filename = shift;
1827 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
1828 print "Building $filename\n";
1829 print OUTPUT
"/* Unicode case mappings */\n";
1830 print OUTPUT
"/* generated from $UNIDATA/UnicodeData.txt */\n";
1831 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
1832 print OUTPUT
"#include \"windef.h\"\n\n";
1834 dump_case_table
( "wine_casemap_lower", @tolower_table );
1836 dump_case_table
( "wine_casemap_upper", @toupper_table );
1838 save_file
($filename);
1842 ################################################################
1843 # dump a case mapping table
1844 sub dump_case_table
($@
)
1846 my ($name,@table) = @_;
1848 # count the number of sub tables that contain something
1849 # also compute the low and upper populated bounds
1851 my @lowerbounds = ( 0, 0 );
1852 my @upperbounds = ( 0, 255 );
1855 for (my $i = 0; $i < 65536; $i++)
1857 next unless defined $table[$i];
1858 if (!defined $filled[$i >> 8])
1860 $lowerbounds[$index] = $i & 0xff;
1861 $upperbounds[$index] = 0xff - $lowerbounds[$index];
1862 $filled[$i >> 8] = $index * 256 + 512;
1867 $upperbounds[$index-1] = 0xff - ($i & 0xff);
1869 $table[$i] = ($table[$i] - $i) & 0xffff;
1872 # Collapse blocks upwards if possible
1875 for (my $i = 0; $i < 256; $i++)
1877 next unless defined $filled[$i];
1878 if ($upperbounds[$index - 1] > $lowerbounds[$index])
1880 $removed = $removed + $lowerbounds[$index];
1884 $removed = $removed + $upperbounds[$index - 1];
1885 $lowerbounds[$index] = $upperbounds[$index - 1];
1887 $filled[$i] = $filled[$i] - $removed;
1893 printf OUTPUT
"const WCHAR %s[%d] =\n", $name, $index * 256 + 512 - $removed;
1894 printf OUTPUT
"{\n /* index */\n";
1895 printf OUTPUT
"%s,\n", DUMP_ARRAY
( "0x%04x", 256, @filled );
1896 printf OUTPUT
" /* defaults */\n";
1897 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, (0) x
256 );
1899 for (my $i = 0; $i < 256; $i++)
1901 next unless $filled[$i];
1902 printf OUTPUT
",\n /* 0x%02x%02x .. 0x%02xff */\n", $i, $lowerbounds[$index], $i;
1903 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0,
1904 @table[($i<<8) + $lowerbounds[$index] .. ($i<<8)+255] );
1907 printf OUTPUT
"\n};\n";
1910 ################################################################
1911 # compress a mapping table by removing identical rows
1912 sub compress_array
($$@
)
1917 my $len = @table / $rows;
1918 my @array = (0) x
$rows;
1921 # try to merge table rows
1922 for (my $row = 0; $row < $rows; $row++)
1924 my @table_row = map { defined($_) ?
$_ : $def; } @table[($row * $len)..($row * $len + $len - 1)];
1925 my $rowtxt = pack "S*", @table_row;
1926 if (defined($sequences{$rowtxt}))
1928 # reuse an existing row
1929 $array[$row] = $sequences{$rowtxt};
1934 $sequences{$rowtxt} = $array[$row] = $#array + 1;
1935 push @array, @table_row;
1941 ################################################################
1942 # dump a simple char -> 16-bit value mapping table
1943 sub dump_simple_mapping
($$@
)
1947 my @array = compress_array
( 256, $def, @_[0..65535] );
1949 printf OUTPUT
"const unsigned short %s[%d] =\n{\n", $name, $#array+1;
1950 printf OUTPUT
" /* offsets */\n%s,\n", DUMP_ARRAY
( "0x%04x", 0, @array[0..255] );
1951 printf OUTPUT
" /* values */\n%s\n};\n", DUMP_ARRAY
( "0x%04x", 0, @array[256..$#array] );
1954 ################################################################
1955 # dump a char -> 16-bit value mapping table using two-level tables
1956 sub dump_two_level_mapping
($$@
)
1960 my @row_array = compress_array
( 4096, $def, @_[0..65535] );
1961 my @array = compress_array
( 256, 0, @row_array[0..4095] );
1963 for (my $i = 256; $i < @array; $i++) { $array[$i] += @array - 4096; }
1965 printf OUTPUT
"const unsigned short DECLSPEC_HIDDEN %s[%d] =\n{\n", $name, @array + @row_array - 4096;
1966 printf OUTPUT
" /* level 1 offsets */\n%s,\n", DUMP_ARRAY
( "0x%04x", 0, @array[0..255] );
1967 printf OUTPUT
" /* level 2 offsets */\n%s,\n", DUMP_ARRAY
( "0x%04x", 0, @array[256..$#array] );
1968 printf OUTPUT
" /* values */\n%s\n};\n", DUMP_ARRAY
( "0x%04x", 0, @row_array[4096..$#row_array] );
1971 ################################################################
1972 # dump a binary case mapping table in l_intl.nls format
1973 sub dump_binary_case_table
(@
)
1977 my %difftables_hash = ();
1979 my %offtables2_hash = ();
1980 my @offtables2 = ();
1983 for (my $i = 0; $i < 256; $i++)
1986 for(my $j = 0; $j < 16; $j++) # offset table for xx00-xxFF characters
1989 for (my $k = 0; $k < 16; $k++) # case map table for xxx0-xxxF characters
1991 my $char = ($i<<8) + ($j<<4) + $k;
1992 $difftable[$k] = (defined $table[$char]) ?
(($table[$char]-$char) & 0xffff) : 0;
1995 my $diff_key = pack "S*", @difftable;
1996 my $offset3 = $difftables_hash{$diff_key};
1997 if (!defined $offset3)
1999 $offset3 = scalar @difftables;
2000 $difftables_hash{$diff_key} = $offset3;
2001 push @difftables, @difftable;
2003 $offtable2[$j] = $offset3;
2006 my $offtable2_key = pack "S*", @offtable2;
2007 my $offset2 = $offtables2_hash{$offtable2_key};
2008 if (!defined $offset2)
2010 $offset2 = scalar @offtables2;
2011 $offtables2_hash{$offtable2_key} = $offset2;
2012 push @offtables2, \
@offtable2;
2014 $offtable[$i] = $offset2;
2018 my $offset = 0x100; # offset of first subtable in words
2021 push @output, 0x10 * $_ + $offset; # offset of subtable in words
2024 $offset = 0x100 + 0x10 * scalar @offtables2; # offset of first difftable in words
2025 foreach(@offtables2)
2030 push @output, $_ + $offset; # offset of difftable in words
2034 my $len = 1 + scalar @output + scalar @difftables;
2035 return pack "S<*", $len, @output, @difftables;
2039 ################################################################
2040 # dump case mappings for l_intl.nls
2041 sub dump_intl_nls
($)
2043 my $filename = shift;
2044 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2045 printf "Building $filename\n";
2048 print OUTPUT
pack "S<", 1; # version
2049 print OUTPUT dump_binary_case_table
( @toupper_table );
2050 print OUTPUT dump_binary_case_table
( @tolower_table );
2052 save_file
($filename);
2056 sub load_nameprep_range_table
($$$)
2058 my ($INPUT, $val, $table_ref) = @_;
2062 if (/^\s*([0-9a-fA-F]+)-([0-9a-fA-F]+)/)
2065 $last = 65535 if($last >= 65536);
2066 foreach my $i (hex $1 .. $last)
2068 $table_ref->[$i] |= $val;
2072 elsif (/^\s*([0-9a-fA-F]+)/)
2076 $table_ref->[hex $1] |= $val;
2081 return if (/End\sTable/);
2085 sub load_nameprep_map_table
($$)
2087 my ($INPUT, $table_ref) = @_;
2091 if (/^\s*([0-9a-fA-F]+);\s;/)
2093 # special value for map to nothing
2094 $table_ref->[hex $1] = [0xffff, 0xffff, 0xffff];
2097 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+);/)
2099 $table_ref->[hex $1] = [hex $2, 0, 0];
2102 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+)\s([0-9a-fA-F]+);/)
2104 $table_ref->[hex $1] = [hex $2, hex $3, 0];
2107 elsif (/^\s*([0-9a-fA-F]+);\s([0-9a-fA-F]+)\s([0-9a-fA-F]+)\s([0-9a-fA-F]+);/)
2109 $table_ref->[hex $1] = [hex $2, hex $3, hex $4];
2113 return if (/End\sTable/);
2117 ################################################################
2118 # dump mapping table, prohibited characters set, unassigned
2119 # characters, bidirectional rules used by nameprep algorithm
2120 sub dump_nameprep
($)
2122 my $filename = shift;
2123 my @mapping_table = ();
2126 my $INPUT = open_data_file
( $RFCS, $STRINGPREP );
2129 next unless /Start\sTable/;
2131 load_nameprep_range_table
($INPUT, $nameprep_flags{"unassigned"}, \
@flags_table) if (/A.1/);
2132 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.1.2/);
2133 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.2.2/);
2134 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.3/);
2135 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.4/);
2136 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.5/);
2137 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.6/);
2138 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.7/);
2139 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.8/);
2140 load_nameprep_range_table
($INPUT, $nameprep_flags{"prohibited"}, \
@flags_table) if (/C.9/);
2141 load_nameprep_range_table
($INPUT, $nameprep_flags{"bidi_ral"}, \
@flags_table) if (/D.1/);
2142 load_nameprep_range_table
($INPUT, $nameprep_flags{"bidi_l"}, \
@flags_table) if (/D.2/);
2144 load_nameprep_map_table
($INPUT, \
@mapping_table) if (/B.1/);
2145 load_nameprep_map_table
($INPUT, \
@mapping_table) if (/B.2/);
2149 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2150 print "Building $filename\n";
2151 print OUTPUT
"/* Nameprep algorithm related data */\n";
2152 print OUTPUT
"/* generated from $RFCS/$STRINGPREP */\n";
2153 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
2154 print OUTPUT
"#include \"windef.h\"\n\n";
2156 dump_two_level_mapping
( "nameprep_char_type", 0, @flags_table );
2158 ######### mapping table
2159 # first determine all the 16-char subsets that contain something
2161 my $pos = 16*3; # for the null subset
2162 for (my $i = 0; $i < 65536; $i++)
2164 next unless defined $mapping_table[$i];
2165 $filled[$i >> 4] = $pos;
2171 # now count the 256-char subsets that contain something
2172 my @filled_idx = (256) x
256;
2174 for (my $i = 0; $i < 4096; $i++)
2176 next unless $filled[$i];
2177 $filled_idx[$i >> 4] = $pos;
2181 my $null_offset = $pos;
2184 # add the index offsets to the subsets positions
2185 for (my $i = 0; $i < 4096; $i++)
2187 next unless $filled[$i];
2188 $filled[$i] += $null_offset;
2191 # dump the main index
2192 printf OUTPUT
"const unsigned short DECLSPEC_HIDDEN nameprep_mapping[%d] =\n", $total;
2193 printf OUTPUT
"{\n /* index */\n";
2194 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @filled_idx );
2195 printf OUTPUT
",\n /* null sub-index */\n%s", DUMP_ARRAY
( "0x%04x", 0, ($null_offset) x
16 );
2197 # dump the second-level indexes
2198 for (my $i = 0; $i < 256; $i++)
2200 next unless ($filled_idx[$i] > 256);
2201 my @table = @filled[($i<<4)..($i<<4)+15];
2202 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
2203 printf OUTPUT
",\n /* sub-index %02x */\n", $i;
2204 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @table );
2207 # dump the 16-char subsets
2208 printf OUTPUT
",\n /* null mapping */\n";
2209 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, (0) x
48 );
2211 for (my $i = 0; $i < 4096; $i++)
2213 next unless $filled[$i];
2214 my @table = (0) x
48;
2215 for (my $j = 0; $j < 16; $j++)
2217 if (defined $mapping_table[($i<<4) + $j])
2219 $table[3 * $j] = ${$mapping_table[($i << 4) + $j]}[0];
2220 $table[3 * $j + 1] = ${$mapping_table[($i << 4) + $j]}[1];
2221 $table[3 * $j + 2] = ${$mapping_table[($i << 4) + $j]}[2];
2224 printf OUTPUT
",\n /* 0x%03x0 .. 0x%03xf */\n", $i, $i;
2225 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @table );
2228 printf OUTPUT
"\n};\n";
2231 save_file
($filename);
2235 ################################################################
2236 # dump the GetStringTypeW table
2237 sub dump_string_type_table
($)
2239 my $filename = shift;
2240 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2241 printf "Building $filename\n";
2242 printf OUTPUT
"/* Unicode wctype table */\n";
2243 printf OUTPUT
"/* Automatically generated; DO NOT EDIT!! */\n\n";
2244 printf OUTPUT
"#include \"windef.h\"\n\n";
2246 my @table = @category_table;
2248 # add the direction in the high 4 bits of the category
2249 for (my $i = 0; $i < 65536; $i++)
2251 $table[$i] |= $c2_types{$direction_table[$i]} << 12 if defined $direction_table[$i];
2254 dump_two_level_mapping
( "wctype_table", 0, @table );
2257 save_file
($filename);
2261 ################################################################
2262 # dump the bidi direction table
2263 sub dump_bidi_dir_table
($)
2265 my $filename = shift;
2266 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2267 printf "Building $filename\n";
2268 printf OUTPUT
"/* Unicode BiDi direction table */\n";
2269 printf OUTPUT
"/* Automatically generated; DO NOT EDIT!! */\n\n";
2270 printf OUTPUT
"#include \"windef.h\"\n\n";
2274 for (my $i = 0; $i < 65536; $i++)
2276 $table[$i] = $bidi_types{$direction_table[$i]} if defined $direction_table[$i];
2279 dump_two_level_mapping
( "bidi_direction_table", $bidi_types{"L"}, @table );
2282 save_file
($filename);
2286 ################################################################
2287 # dump the ctype tables
2288 sub dump_ctype_tables
($)
2290 my $filename = shift;
2291 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2292 printf "Building $filename\n";
2293 printf OUTPUT
"/* Unicode ctype tables */\n";
2294 printf OUTPUT
"/* Automatically generated; DO NOT EDIT!! */\n\n";
2295 printf OUTPUT
"#include \"windef.h\"\n\n";
2297 my @table = @category_table;
2299 # add the direction in the high 4 bits of the category
2300 for (my $i = 0; $i < 65536; $i++)
2302 $table[$i] |= $directions{$direction_table[$i]} << 12 if defined $direction_table[$i];
2305 dump_simple_mapping
( "wine_wctype_table", 0, @table );
2308 save_file
($filename);
2312 ################################################################
2313 # dump the char composition table
2314 sub dump_compose_table
($)
2316 my $filename = shift;
2318 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2319 print "Building $filename\n";
2320 print OUTPUT
"/* Unicode char composition */\n";
2321 print OUTPUT
"/* generated from $UNIDATA/UnicodeData.txt */\n";
2322 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
2323 print OUTPUT
"#include \"windef.h\"\n\n";
2326 foreach my $i (@compose_table)
2329 push @
{$filled[$comp[1]]}, [ $comp[0], $comp[2] ];
2332 # count how many different second chars we have
2335 for (my $i = 0; $i < 65536; $i++)
2337 next unless defined $filled[$i];
2341 # build the table of second chars and offsets
2343 my $pos = $count + 1;
2345 for (my $i = 0; $i < 65536; $i++)
2347 next unless defined $filled[$i];
2348 push @table, $i, $pos;
2349 $pos += @
{$filled[$i]};
2351 # terminator with last position
2352 push @table, 0, $pos;
2353 printf OUTPUT
"static const WCHAR table[0x%x] =\n{\n", 2*$pos;
2354 printf OUTPUT
" /* second chars + offsets */\n%s", DUMP_ARRAY
( "0x%04x", 0, @table );
2356 # build the table of first chars and mappings
2358 for (my $i = 0; $i < 65536; $i++)
2360 next unless defined $filled[$i];
2362 my @list = sort { $a->[0] <=> $b->[0] } @
{$filled[$i]};
2363 for (my $j = 0; $j <= $#list; $j++)
2365 push @table, $list[$j][0], $list[$j][1];
2367 printf OUTPUT
",\n /* 0x%04x */\n%s", $i, DUMP_ARRAY
( "0x%04x", 0, @table );
2369 print OUTPUT
"\n};\n\n";
2370 print OUTPUT
<<"EOF";
2371 static inline int binary_search( WCHAR ch, int low, int high )
2375 int pos = (low + high) / 2;
2376 if (table[2 * pos] < ch) low = pos + 1;
2377 else if (table[2 * pos] > ch) high = pos - 1;
2383 WCHAR DECLSPEC_HIDDEN wine_compose( const WCHAR *str )
2385 int pos, idx = 1, start = 0, count = $count;
2388 if ((pos = binary_search( str[idx], start, count - 1 )) == -1) return 0;
2389 if (!idx--) return table[2 * pos + 1];
2390 start = table[2 * pos + 1];
2391 count = table[2 * pos + 3];
2396 save_file
($filename);
2399 sub dump_full_compat_table
()
2401 # first determine all the 16-char subsets that contain something
2403 my @filled = (0) x
4096;
2404 my $pos = 16; # for the null subset
2406 for (my $i = 0; $i < 65536; $i++)
2408 next unless defined $full_compatmap_table[$i];
2409 if ($filled[$i >> 4] == 0)
2411 $filled[$i >> 4] = $pos;
2414 $data_total += $#{$full_compatmap_table[$i]} + 1;
2418 # now count the 256-char subsets that contain something
2420 my @filled_idx = (256) x
256;
2422 for (my $i = 0; $i < 4096; $i++)
2424 next unless $filled[$i];
2425 $filled_idx[$i >> 4] = $pos;
2429 my $null_offset = $pos; # null mapping
2430 $total += $pos + 1; # add the offset sentinel
2432 # add the index offsets to the subsets positions
2434 for (my $i = 0; $i < 4096; $i++)
2436 next unless $filled[$i];
2437 $filled[$i] += $null_offset;
2440 # dump the main index
2442 printf OUTPUT
"static const WCHAR compatmap_table[%d] =\n", $total + $data_total;
2443 printf OUTPUT
"{\n /* index */\n";
2444 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @filled_idx );
2445 printf OUTPUT
",\n /* null sub-index */\n%s", DUMP_ARRAY
( "0x%04x", 0, ($null_offset) x
16 );
2447 # dump the second-level indexes
2449 for (my $i = 0; $i < 256; $i++)
2451 next unless ($filled_idx[$i] > 256);
2452 my @table = @filled[($i<<4)..($i<<4)+15];
2453 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
2454 printf OUTPUT
",\n /* sub-index %02x */\n", $i;
2455 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @table );
2458 # dump the 16-char offsets
2460 printf OUTPUT
",\n /* null offsets */\n";
2461 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, ($total) x
(16) );
2466 for (my $i = 0; $i < 4096; $i++)
2468 next unless $filled[$i];
2469 my @table = (0) x
(16);
2470 for (my $j = 0; $j < 16; $j++)
2473 if (defined $full_compatmap_table[($i<<4) + $j])
2475 $pos += $#{$full_compatmap_table[($i<<4) + $j]} + 1;
2476 push @data, @
{$full_compatmap_table[($i<<4) + $j]};
2479 printf OUTPUT
",\n /* offsets 0x%03x0 .. 0x%03xf */\n", $i, $i;
2480 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @table );
2483 my @sentinel = $pos;
2484 printf OUTPUT
",\n /* offset sentinel */\n";
2485 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @sentinel );
2487 printf OUTPUT
",\n /* data */\n";
2488 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @data );
2490 printf OUTPUT
"\n};\n\n";
2493 ################################################################
2494 # dump the char decomposition table
2495 sub dump_decompose_table
($)
2497 my $filename = shift;
2499 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2500 print "Building $filename\n";
2501 print OUTPUT
"/* Unicode char composition */\n";
2502 print OUTPUT
"/* generated from $UNIDATA/UnicodeData.txt */\n";
2503 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
2504 print OUTPUT
"#include \"wine/unicode.h\"\n\n";
2506 # first determine all the 16-char subsets that contain something
2508 my @filled = (0) x
4096;
2509 my $pos = 16*2; # for the null subset
2510 for (my $i = 0; $i < 65536; $i++)
2512 next unless defined $decomp_table[$i];
2513 $filled[$i >> 4] = $pos;
2519 # now count the 256-char subsets that contain something
2521 my @filled_idx = (256) x
256;
2523 for (my $i = 0; $i < 4096; $i++)
2525 next unless $filled[$i];
2526 $filled_idx[$i >> 4] = $pos;
2530 my $null_offset = $pos; # null mapping
2533 # add the index offsets to the subsets positions
2535 for (my $i = 0; $i < 4096; $i++)
2537 next unless $filled[$i];
2538 $filled[$i] += $null_offset;
2541 # dump the main index
2543 printf OUTPUT
"static const WCHAR table[%d] =\n", $total;
2544 printf OUTPUT
"{\n /* index */\n";
2545 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @filled_idx );
2546 printf OUTPUT
",\n /* null sub-index */\n%s", DUMP_ARRAY
( "0x%04x", 0, ($null_offset) x
16 );
2548 # dump the second-level indexes
2550 for (my $i = 0; $i < 256; $i++)
2552 next unless ($filled_idx[$i] > 256);
2553 my @table = @filled[($i<<4)..($i<<4)+15];
2554 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
2555 printf OUTPUT
",\n /* sub-index %02x */\n", $i;
2556 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @table );
2559 # dump the 16-char subsets
2561 printf OUTPUT
",\n /* null mapping */\n";
2562 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, (0) x
32 );
2564 for (my $i = 0; $i < 4096; $i++)
2566 next unless $filled[$i];
2567 my @table = (0) x
32;
2568 for (my $j = 0; $j < 16; $j++)
2570 if (defined $decomp_table[($i<<4) + $j])
2572 $table[2 * $j] = ${$decomp_table[($i << 4) + $j]}[0];
2573 $table[2 * $j + 1] = ${$decomp_table[($i << 4) + $j]}[1];
2576 printf OUTPUT
",\n /* 0x%03x0 .. 0x%03xf */\n", $i, $i;
2577 printf OUTPUT
"%s", DUMP_ARRAY
( "0x%04x", 0, @table );
2580 printf OUTPUT
"\n};\n\n";
2582 dump_full_compat_table
();
2584 print OUTPUT
<<"EOF";
2585 static const WCHAR *get_compatmap_entry( WCHAR ch, unsigned int *len )
2587 unsigned short offset_offs = compatmap_table[compatmap_table[ch >> 8] + ((ch >> 4) & 0xf)] + (ch & 0xf);
2588 unsigned short start = compatmap_table[offset_offs];
2589 unsigned short end = compatmap_table[offset_offs + 1];
2594 return compatmap_table + start;
2600 unsigned int DECLSPEC_HIDDEN wine_decompose( int flags, WCHAR ch, WCHAR *dst, unsigned int dstlen )
2602 const WCHAR *ptr = NULL;
2603 unsigned int res, len, dst_pos = 0;
2607 if (flags & WINE_DECOMPOSE_COMPAT)
2608 ptr = get_compatmap_entry( ch, &len );
2612 ptr = table + table[table[ch >> 8] + ((ch >> 4) & 0x0f)] + 2 * (ch & 0xf);
2613 len = ptr[1] ? 2 : 1;
2616 if (!*ptr) return 1;
2617 if (dstlen < len) return 0;
2618 /* apply the decomposition recursively */
2621 if (!(res = wine_decompose( flags, *ptr++, dst + dst_pos, dstlen - dst_pos - len ))) return 0;
2629 save_file
($filename);
2632 ################################################################
2633 # dump the combining class table
2634 sub dump_combining_class
($)
2636 my $filename = shift;
2638 open OUTPUT
,">$filename.new" or die "Cannot create $filename";
2639 print "Building $filename\n";
2640 print OUTPUT
"/* Unicode Combining Classes */\n";
2641 print OUTPUT
"/* generated from $UNIDATA/UnicodeData.txt */\n";
2642 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
2643 print OUTPUT
"#include \"windef.h\"\n\n";
2645 dump_two_level_mapping
( "combining_class_table", 0, @combining_class_table );
2647 save_file
($filename);
2650 ################################################################
2651 # output a codepage definition file from the global tables
2652 sub output_codepage_file
($$$$)
2654 my ($codepage, $filename, $comment, $has_glyphs) = @_;
2656 my $output = sprintf "libs/port/c_%03d.c", $codepage;
2657 open OUTPUT
,">$output.new" or die "Cannot create $output";
2659 printf "Building %s from %s (%s)\n", $output, $filename || "hardcoded data", $comment;
2663 printf OUTPUT
"/* code page %03d (%s) */\n", $codepage, $comment;
2666 print OUTPUT
"/* generated from $MAPPINGS/$filename */\n";
2667 print OUTPUT
"/* DO NOT EDIT!! */\n\n";
2671 printf OUTPUT
"/* Automatically generated; DO NOT EDIT!! */\n\n";
2673 printf OUTPUT
"#include \"wine/unicode.h\"\n\n";
2675 if (!@lead_bytes) { dump_sbcs_table
( $codepage, $has_glyphs, $comment, $default_char, $default_wchar ); }
2676 else { dump_dbcs_table
( $codepage, $comment, $default_char, $default_wchar, get_lb_ranges
() ); }
2681 ################################################################
2682 # read a "bestfit" Windows mapping file
2683 sub read_bestfit_file
($)
2685 my ($filename) = @_;
2687 my ($codepage, $width, $count);
2688 my ($lb_cur, $lb_end);
2690 my $INPUT = open_data_file
( $MAPPINGS, $filename ) or die "Cannot open $filename";
2694 next if /^;/; # skip comments
2695 next if /^\s*$/; # skip empty lines
2696 next if /\x1a/; # skip ^Z
2697 last if /^ENDCODEPAGE/;
2699 if (/^CODEPAGE\s+(\d+)/)
2704 if (/^CPINFO\s+(\d+)\s+0x([0-9a-fA-f]+)\s+0x([0-9a-fA-F]+)/)
2707 $default_char = hex $2;
2708 $default_wchar = hex $3;
2711 if (/^(MBTABLE|WCTABLE|DBCSRANGE|DBCSTABLE)\s+(\d+)/)
2717 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)/)
2719 if ($state eq "MBTABLE")
2723 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
2726 if ($state eq "WCTABLE")
2730 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
2733 if ($state eq "DBCSRANGE")
2737 for (my $i = $start; $i <= $end; $i++) { add_lead_byte
( $i ); }
2742 if ($state eq "DBCSTABLE")
2746 my $cp = ($lb_cur << 8) | $mb;
2747 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
2750 if (++$lb_cur > $lb_end) { $state = "DBCSRANGE"; }
2755 die "$filename: Unrecognized line $_\n";
2761 ################################################################
2762 # read an input file and generate the corresponding .c file
2765 my ($codepage,$filename,$has_glyphs,$comment,$first_private,$def,$defw) = @_;
2770 $default_char = $def || $DEF_CHAR;
2771 $default_wchar = $defw || $DEF_CHAR;
2773 # some codepage files are special
2774 if ($codepage == 20932)
2776 READ_JIS0208_FILE
( $filename );
2777 add_default_mappings
( $first_private );
2779 elsif ($codepage == 20127)
2781 fill_20127_codepage
();
2782 add_default_mappings
( $first_private );
2784 elsif ($filename =~ /\/bestfit
/)
2786 read_bestfit_file
( $filename );
2790 read_codepage_file
( $filename );
2791 if ($codepage == 10001)
2793 # add Shift-JIS mappings
2794 read_bestfit_file
( "VENDORS/MICSFT/WindowsBestFit/bestfit932.txt" );
2798 add_default_mappings
( $first_private );
2802 output_codepage_file
( $codepage, $filename, $comment, $has_glyphs );
2806 ################################################################
2807 # save a file if modified
2811 if (-f
$file && !system "cmp $file $file.new >/dev/null")
2817 rename "$file.new", "$file";
2822 ################################################################
2823 # output the list of codepage tables into the cptable.c file
2824 sub output_cptable
($)
2827 my @tables_decl = ();
2829 printf "Building %s\n", $output;
2831 foreach my $file (@allfiles)
2833 my ($codepage,$filename) = @
$file;
2834 push @tables_decl, sprintf("extern union cptable cptable_%03d;\n",$codepage);
2837 push @tables_decl, sprintf("\nstatic const union cptable * const cptables[%d] =\n{\n",$#allfiles+1);
2838 foreach my $file (@allfiles)
2840 my ($codepage,$filename) = @
$file;
2841 push @tables_decl, sprintf(" &cptable_%03d,\n", $codepage);
2843 push @tables_decl, "};";
2844 REPLACE_IN_FILE
( $output, @tables_decl );
2847 ################################################################
2848 # replace the contents of a file between ### cpmap ### marks
2850 sub REPLACE_IN_FILE
($@
)
2855 open(FILE
,$name) or die "Can't open $name";
2859 last if /\#\#\# cpmap begin \#\#\#/;
2864 if (/\#\#\# cpmap end \#\#\#/) { push @lines, "\n", $_; last; }
2866 push @lines, <FILE
>;
2867 open(FILE
,">$name.new") or die "Can't modify $name";
2873 ################################################################
2876 chdir ".." if -f
"./make_unicode";
2877 READ_DEFAULTS
( $DEFAULTS );
2878 dump_case_mappings
( "libs/port/casemap.c" );
2879 dump_sortkeys
( "libs/port/collation.c", READ_SORTKEYS_FILE
() );
2880 dump_compose_table
( "libs/port/compose.c" );
2881 dump_decompose_table
( "libs/port/decompose.c" );
2882 dump_ctype_tables
( "libs/port/wctype.c" );
2883 dump_bidi_dir_table
( "dlls/gdi32/direction.c" );
2884 dump_bidi_dir_table
( "dlls/usp10/direction.c" );
2885 dump_bidi_dir_table
( "dlls/dwrite/direction.c" );
2886 dump_string_type_table
( "dlls/kernel32/wctype.c" );
2887 dump_digit_folding
( "libs/port/digitmap.c" );
2888 dump_combining_class
( "libs/port/combclass.c" );
2889 dump_mirroring
( "dlls/usp10/mirror.c" );
2890 dump_mirroring
( "dlls/dwrite/mirror.c" );
2891 dump_bracket
( "dlls/usp10/bracket.c" );
2892 dump_bracket
( "dlls/dwrite/bracket.c" );
2893 dump_shaping
( "dlls/usp10/shaping.c" );
2894 dump_linebreak
( "dlls/usp10/linebreak.c" );
2895 dump_linebreak
( "dlls/dwrite/linebreak.c" );
2896 dump_scripts
( "dlls/dwrite/scripts" );
2897 dump_indic
( "dlls/usp10/indicsyllable.c" );
2898 dump_intl_nls
("loader/l_intl.nls");
2899 dump_vertical
( "dlls/gdi32/vertical.c" );
2900 dump_vertical
( "dlls/wineps.drv/vertical.c" );
2901 dump_nameprep
( "dlls/kernel32/nameprep.c" );
2903 foreach my $file (@allfiles) { HANDLE_FILE
( @
{$file} ); }
2905 output_cptable
("libs/port/cptable.c");
2910 # compile-command: "./make_unicode"