VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/cpmap.pl@ 21731

Last change on this file since 21731 was 21731, checked in by vboxsync, 16 years ago

crOpenGL: update to wine 1.1.26

  • Property svn:eol-style set to native
File size: 47.3 KB
Line 
1#!/usr/bin/perl -w
2#
3# Generate code page .c files from ftp.unicode.org descriptions
4#
5# Copyright 2000 Alexandre Julliard
6#
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.
11#
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.
16#
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
20#
21
22#
23# Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
24# other than GPL or LGPL is available it will apply instead, Sun elects to use only
25# the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
26# a choice of LGPL license versions is made available with the language indicating
27# that LGPLv2 or any later version may be used, or where a choice of which version
28# of the LGPL is applied is otherwise unspecified.
29#
30
31#
32# Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
33# other than GPL or LGPL is available it will apply instead, Sun elects to use only
34# the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
35# a choice of LGPL license versions is made available with the language indicating
36# that LGPLv2 or any later version may be used, or where a choice of which version
37# of the LGPL is applied is otherwise unspecified.
38#
39
40use strict;
41
42# base directory for ftp.unicode.org files
43my $BASEDIR = "ftp.unicode.org/Public/";
44my $MAPPREFIX = $BASEDIR . "MAPPINGS/";
45
46# UnicodeData file
47my $UNICODEDATA = $BASEDIR . "UNIDATA/UnicodeData.txt";
48
49# Sort keys file
50my $SORTKEYS = "www.unicode.org/reports/tr10/allkeys.txt";
51
52# Defaults mapping
53my $DEFAULTS = "./defaults";
54
55# Default char for undefined mappings
56my $DEF_CHAR = ord '?';
57
58my @allfiles =
59(
60 [ 37, "VENDORS/MICSFT/EBCDIC/CP037.TXT", 0, "IBM EBCDIC US Canada" ],
61 [ 424, "VENDORS/MISC/CP424.TXT", 0, "IBM EBCDIC Hebrew" ],
62 [ 437, "VENDORS/MICSFT/PC/CP437.TXT", 1, "OEM United States" ],
63 [ 500, "VENDORS/MICSFT/EBCDIC/CP500.TXT", 0, "IBM EBCDIC International" ],
64 [ 737, "VENDORS/MICSFT/PC/CP737.TXT", 1, "OEM Greek 437G" ],
65 [ 775, "VENDORS/MICSFT/PC/CP775.TXT", 1, "OEM Baltic" ],
66 [ 850, "VENDORS/MICSFT/PC/CP850.TXT", 1, "OEM Multilingual Latin 1" ],
67 [ 852, "VENDORS/MICSFT/PC/CP852.TXT", 1, "OEM Slovak Latin 2" ],
68 [ 855, "VENDORS/MICSFT/PC/CP855.TXT", 1, "OEM Cyrillic" ],
69 [ 856, "VENDORS/MISC/CP856.TXT", 0, "Hebrew PC" ],
70 [ 857, "VENDORS/MICSFT/PC/CP857.TXT", 1, "OEM Turkish" ],
71 [ 860, "VENDORS/MICSFT/PC/CP860.TXT", 1, "OEM Portuguese" ],
72 [ 861, "VENDORS/MICSFT/PC/CP861.TXT", 1, "OEM Icelandic" ],
73 [ 862, "VENDORS/MICSFT/PC/CP862.TXT", 1, "OEM Hebrew" ],
74 [ 863, "VENDORS/MICSFT/PC/CP863.TXT", 1, "OEM Canadian French" ],
75 [ 864, "VENDORS/MICSFT/PC/CP864.TXT", 0, "OEM Arabic" ],
76 [ 865, "VENDORS/MICSFT/PC/CP865.TXT", 1, "OEM Nordic" ],
77 [ 866, "VENDORS/MICSFT/PC/CP866.TXT", 1, "OEM Russian" ],
78 [ 869, "VENDORS/MICSFT/PC/CP869.TXT", 1, "OEM Greek" ],
79 [ 874, "VENDORS/MICSFT/WindowsBestFit/bestfit874.txt", 1, "ANSI/OEM Thai" ],
80 [ 875, "VENDORS/MICSFT/EBCDIC/CP875.TXT", 0, "IBM EBCDIC Greek" ],
81 [ 878, "VENDORS/MISC/KOI8-R.TXT", 0, "Russian KOI8" ],
82 [ 932, "VENDORS/MICSFT/WindowsBestFit/bestfit932.txt", 0, "ANSI/OEM Japanese Shift-JIS" ],
83 [ 936, "VENDORS/MICSFT/WindowsBestFit/bestfit936.txt", 0, "ANSI/OEM Simplified Chinese GBK" ],
84 [ 949, "VENDORS/MICSFT/WindowsBestFit/bestfit949.txt", 0, "ANSI/OEM Korean Unified Hangul" ],
85 [ 950, "VENDORS/MICSFT/WindowsBestFit/bestfit950.txt", 0, "ANSI/OEM Traditional Chinese Big5" ],
86 [ 1006, "VENDORS/MISC/CP1006.TXT", 0, "IBM Arabic" ],
87 [ 1026, "VENDORS/MICSFT/EBCDIC/CP1026.TXT", 0, "IBM EBCDIC Latin 5 Turkish" ],
88 [ 1250, "VENDORS/MICSFT/WindowsBestFit/bestfit1250.txt", 0, "ANSI Eastern Europe" ],
89 [ 1251, "VENDORS/MICSFT/WindowsBestFit/bestfit1251.txt", 0, "ANSI Cyrillic" ],
90 [ 1252, "VENDORS/MICSFT/WindowsBestFit/bestfit1252.txt", 0, "ANSI Latin 1" ],
91 [ 1253, "VENDORS/MICSFT/WindowsBestFit/bestfit1253.txt", 0, "ANSI Greek" ],
92 [ 1254, "VENDORS/MICSFT/WindowsBestFit/bestfit1254.txt", 0, "ANSI Turkish" ],
93 [ 1255, "VENDORS/MICSFT/WindowsBestFit/bestfit1255.txt", 0, "ANSI Hebrew" ],
94 [ 1256, "VENDORS/MICSFT/WindowsBestFit/bestfit1256.txt", 0, "ANSI Arabic" ],
95 [ 1257, "VENDORS/MICSFT/WindowsBestFit/bestfit1257.txt", 0, "ANSI Baltic" ],
96 [ 1258, "VENDORS/MICSFT/WindowsBestFit/bestfit1258.txt", 0, "ANSI/OEM Viet Nam" ],
97 [ 1361, "OBSOLETE/EASTASIA/KSC/JOHAB.TXT", 0, "Korean Johab" ],
98 [ 10000, "VENDORS/MICSFT/MAC/ROMAN.TXT", 0, "Mac Roman" ],
99 [ 10006, "VENDORS/MICSFT/MAC/GREEK.TXT", 0, "Mac Greek" ],
100 [ 10007, "VENDORS/MICSFT/MAC/CYRILLIC.TXT", 0, "Mac Cyrillic" ],
101 [ 10029, "VENDORS/MICSFT/MAC/LATIN2.TXT", 0, "Mac Latin 2" ],
102 [ 10079, "VENDORS/MICSFT/MAC/ICELAND.TXT", 0, "Mac Icelandic" ],
103 [ 10081, "VENDORS/MICSFT/MAC/TURKISH.TXT", 0, "Mac Turkish" ],
104 [ 20127, undef, 0, "US-ASCII (7bit)" ],
105 [ 20866, "VENDORS/MISC/KOI8-R.TXT", 0, "Russian KOI8" ],
106 [ 20932, "OBSOLETE/EASTASIA/JIS/JIS0208.TXT", 0, "EUC-JP" ],
107 [ 21866, "VENDORS/MISC/KOI8-U.TXT", 0, "Ukrainian KOI8" ],
108 [ 28591, "ISO8859/8859-1.TXT", 0, "ISO 8859-1 Latin 1" ],
109 [ 28592, "ISO8859/8859-2.TXT", 0, "ISO 8859-2 Latin 2 (East European)" ],
110 [ 28593, "ISO8859/8859-3.TXT", 0, "ISO 8859-3 Latin 3 (South European)" ],
111 [ 28594, "ISO8859/8859-4.TXT", 0, "ISO 8859-4 Latin 4 (Baltic old)" ],
112 [ 28595, "ISO8859/8859-5.TXT", 0, "ISO 8859-5 Cyrillic" ],
113 [ 28596, "ISO8859/8859-6.TXT", 0, "ISO 8859-6 Arabic" ],
114 [ 28597, "ISO8859/8859-7.TXT", 0, "ISO 8859-7 Greek" ],
115 [ 28598, "ISO8859/8859-8.TXT", 0, "ISO 8859-8 Hebrew" ],
116 [ 28599, "ISO8859/8859-9.TXT", 0, "ISO 8859-9 Latin 5 (Turkish)" ],
117 [ 28600, "ISO8859/8859-10.TXT", 0, "ISO 8859-10 Latin 6 (Nordic)" ],
118 [ 28603, "ISO8859/8859-13.TXT", 0, "ISO 8859-13 Latin 7 (Baltic)" ],
119 [ 28604, "ISO8859/8859-14.TXT", 0, "ISO 8859-14 Latin 8 (Celtic)" ],
120 [ 28605, "ISO8859/8859-15.TXT", 0, "ISO 8859-15 Latin 9 (Euro)" ],
121 [ 28606, "ISO8859/8859-16.TXT", 0, "ISO 8859-16 Latin 10 (Balkan)" ]
122);
123
124
125my %ctype =
126(
127 "upper" => 0x0001,
128 "lower" => 0x0002,
129 "digit" => 0x0004,
130 "space" => 0x0008,
131 "punct" => 0x0010,
132 "cntrl" => 0x0020,
133 "blank" => 0x0040,
134 "xdigit" => 0x0080,
135 "alpha" => 0x0100
136);
137
138my %categories =
139(
140 "Lu" => $ctype{"alpha"}|$ctype{"upper"}, # Letter, Uppercase
141 "Ll" => $ctype{"alpha"}|$ctype{"lower"}, # Letter, Lowercase
142 "Lt" => $ctype{"alpha"}, # Letter, Titlecase
143 "Mn" => $ctype{"punct"}, # Mark, Non-Spacing
144 "Mc" => $ctype{"punct"}, # Mark, Spacing Combining
145 "Me" => $ctype{"punct"}, # Mark, Enclosing
146 "Nd" => $ctype{"digit"}, # Number, Decimal Digit
147 "Nl" => $ctype{"punct"}, # Number, Letter
148 "No" => $ctype{"punct"}, # Number, Other
149 "Zs" => $ctype{"space"}, # Separator, Space
150 "Zl" => $ctype{"space"}, # Separator, Line
151 "Zp" => $ctype{"space"}, # Separator, Paragraph
152 "Cc" => $ctype{"cntrl"}, # Other, Control
153 "Cf" => 0, # Other, Format
154 "Cs" => 0, # Other, Surrogate
155 "Co" => 0, # Other, Private Use
156 "Cn" => 0, # Other, Not Assigned
157 "Lm" => $ctype{"punct"}, # Letter, Modifier
158 "Lo" => $ctype{"alpha"}, # Letter, Other
159 "Pc" => $ctype{"punct"}, # Punctuation, Connector
160 "Pd" => $ctype{"punct"}, # Punctuation, Dash
161 "Ps" => $ctype{"punct"}, # Punctuation, Open
162 "Pe" => $ctype{"punct"}, # Punctuation, Close
163 "Pi" => $ctype{"punct"}, # Punctuation, Initial quote
164 "Pf" => $ctype{"punct"}, # Punctuation, Final quote
165 "Po" => $ctype{"punct"}, # Punctuation, Other
166 "Sm" => $ctype{"punct"}, # Symbol, Math
167 "Sc" => $ctype{"punct"}, # Symbol, Currency
168 "Sk" => $ctype{"punct"}, # Symbol, Modifier
169 "So" => $ctype{"punct"} # Symbol, Other
170);
171
172# a few characters need additional categories that cannot be determined automatically
173my %special_categories =
174(
175 "xdigit" => [ ord('0')..ord('9'),ord('A')..ord('F'),ord('a')..ord('f'),
176 0xff10..0xff19, 0xff21..0xff26, 0xff41..0xff46 ],
177 "space" => [ 0x09..0x0d, 0x85 ],
178 "blank" => [ 0x09, 0x20, 0xa0, 0x3000, 0xfeff ],
179 "cntrl" => [ 0x070f, 0x180b, 0x180c, 0x180d, 0x180e, 0x200c, 0x200d,
180 0x200e, 0x200f, 0x202a, 0x202b, 0x202c, 0x202d, 0x202e,
181 0x206a, 0x206b, 0x206c, 0x206d, 0x206e, 0x206f, 0xfeff,
182 0xfff9, 0xfffa, 0xfffb ]
183);
184
185my %directions =
186(
187 "L" => 1, # Left-to-Right
188 "LRE" => 11, # Left-to-Right Embedding
189 "LRO" => 11, # Left-to-Right Override
190 "R" => 2, # Right-to-Left
191 "AL" => 2, # Right-to-Left Arabic
192 "RLE" => 11, # Right-to-Left Embedding
193 "RLO" => 11, # Right-to-Left Override
194 "PDF" => 11, # Pop Directional Format
195 "EN" => 3, # European Number
196 "ES" => 4, # European Number Separator
197 "ET" => 5, # European Number Terminator
198 "AN" => 6, # Arabic Number
199 "CS" => 7, # Common Number Separator
200 "NSM" => 0, # Non-Spacing Mark
201 "BN" => 0, # Boundary Neutral
202 "B" => 8, # Paragraph Separator
203 "S" => 9, # Segment Separator
204 "WS" => 10, # Whitespace
205 "ON" => 11 # Other Neutrals
206);
207
208my @cp2uni = ();
209my @lead_bytes = ();
210my @uni2cp = ();
211my @unicode_defaults = ();
212my @unicode_aliases = ();
213my @tolower_table = ();
214my @toupper_table = ();
215my @digitmap_table = ();
216my @compatmap_table = ();
217my @category_table = (0) x 65536;
218my @direction_table = ();
219my @decomp_table = ();
220my @compose_table = ();
221
222
223################################################################
224# read in the defaults file
225sub READ_DEFAULTS($)
226{
227 my $filename = shift;
228 my $start;
229
230 # first setup a few default mappings
231
232 open DEFAULTS, "$filename" or die "Cannot open $filename";
233 print "Loading $filename\n";
234 while (<DEFAULTS>)
235 {
236 next if /^\#/; # skip comments
237 next if /^$/; # skip empty lines
238 if (/^(([0-9a-fA-F]+)(,[0-9a-fA-F]+)*)\s+([0-9a-fA-F]+|'.'|none)\s+(\#.*)?/)
239 {
240 my @src = map hex, split /,/,$1;
241 my $dst = $4;
242 my $comment = $5;
243 if ($#src > 0) { push @unicode_aliases, \@src; }
244 next if ($dst eq "none");
245 $dst = ($dst =~ /\'.\'/) ? ord substr($dst,1,1) : hex $dst;
246 foreach my $src (@src)
247 {
248 die "Duplicate value" if defined($unicode_defaults[$src]);
249 $unicode_defaults[$src] = $dst;
250 }
251 next;
252 }
253 die "Unrecognized line $_\n";
254 }
255
256 # now build mappings from the decomposition field of the Unicode database
257
258 open UNICODEDATA, "$UNICODEDATA" or die "Cannot open $UNICODEDATA";
259 print "Loading $UNICODEDATA\n";
260 while (<UNICODEDATA>)
261 {
262 # Decode the fields ...
263 my ($code, $name, $cat, $comb, $bidi,
264 $decomp, $dec, $dig, $num, $mirror,
265 $oldname, $comment, $upper, $lower, $title) = split /;/;
266 my $dst;
267 my $src = hex $code;
268
269 die "unknown category $cat" unless defined $categories{$cat};
270 die "unknown directionality $bidi" unless defined $directions{$bidi};
271
272 $category_table[$src] = $categories{$cat};
273 $direction_table[$src] = $directions{$bidi};
274
275 if ($lower ne "")
276 {
277 $tolower_table[$src] = hex $lower;
278 $category_table[$src] |= $ctype{"upper"}|$ctype{"alpha"};
279 }
280 if ($upper ne "")
281 {
282 $toupper_table[$src] = hex $upper;
283 $category_table[$src] |= $ctype{"lower"}|$ctype{"alpha"};
284 }
285 if ($dec ne "")
286 {
287 $category_table[$src] |= $ctype{"digit"};
288 }
289 if ($dig ne "")
290 {
291 $digitmap_table[$src] = ord $dig;
292 }
293
294 # copy the category and direction for everything between First/Last pairs
295 if ($name =~ /, First>/) { $start = $src; }
296 if ($name =~ /, Last>/)
297 {
298 while ($start < $src)
299 {
300 $category_table[$start] = $category_table[$src];
301 $direction_table[$start] = $direction_table[$src];
302 $start++;
303 }
304 }
305
306 next if $decomp eq ""; # no decomposition, skip it
307
308 if ($decomp =~ /^<([a-zA-Z]+)>\s+([0-9a-fA-F]+)$/)
309 {
310 # decomposition of the form "<foo> 1234" -> use char if type is known
311 if (($src >= 0xf900 && $src < 0xfb00) || ($src >= 0xfe30 && $src < 0xfffd))
312 {
313 # Single char decomposition in the compatibility range
314 $compatmap_table[$src] = hex $2;
315 }
316 next unless ($1 eq "font" ||
317 $1 eq "noBreak" ||
318 $1 eq "circle" ||
319 $1 eq "super" ||
320 $1 eq "sub" ||
321 $1 eq "wide" ||
322 $1 eq "narrow" ||
323 $1 eq "compat" ||
324 $1 eq "small");
325 $dst = hex $2;
326 }
327 elsif ($decomp =~ /^<compat>\s+0020\s+([0-9a-fA-F]+)/)
328 {
329 # decomposition "<compat> 0020 1234" -> combining accent
330 $dst = hex $1;
331 }
332 elsif ($decomp =~ /^([0-9a-fA-F]+)/)
333 {
334 # decomposition contains only char values without prefix -> use first char
335 $dst = hex $1;
336 $category_table[$src] |= $category_table[$dst] if defined $category_table[$dst];
337 # store decomposition if it contains two chars
338 if ($decomp =~ /^([0-9a-fA-F]+)\s+([0-9a-fA-F]+)$/)
339 {
340 $decomp_table[$src] = [ hex $1, hex $2 ];
341 push @compose_table, [ hex $1, hex $2, $src ];
342 }
343 elsif ($decomp =~ /^(<[a-z]+>\s)*([0-9a-fA-F]+)$/ &&
344 (($src >= 0xf900 && $src < 0xfb00) || ($src >= 0xfe30 && $src < 0xfffd)))
345 {
346 # Single char decomposition in the compatibility range
347 $compatmap_table[$src] = hex $2;
348 }
349 }
350 else
351 {
352 next;
353 }
354
355 next if defined($unicode_defaults[$src]); # may have been set in the defaults file
356
357 # check for loops
358 for (my $i = $dst; ; $i = $unicode_defaults[$i])
359 {
360 die sprintf("loop detected for %04x -> %04x",$src,$dst) if $i == $src;
361 last unless defined($unicode_defaults[$i]);
362 }
363 $unicode_defaults[$src] = $dst;
364 }
365
366 # patch the category of some special characters
367
368 foreach my $cat (keys %special_categories)
369 {
370 my $flag = $ctype{$cat};
371 foreach my $i (@{$special_categories{$cat}}) { $category_table[$i] |= $flag; }
372 }
373}
374
375
376################################################################
377# parse the input file
378sub READ_FILE($)
379{
380 my $name = shift;
381 open INPUT,$name or die "Cannot open $name";
382
383 while (<INPUT>)
384 {
385 next if /^\#/; # skip comments
386 next if /^$/; # skip empty lines
387 next if /\x1a/; # skip ^Z
388 next if (/^0x([0-9a-fA-F]+)\s+\#UNDEFINED/); # undefined char
389
390 if (/^0x([0-9a-fA-F]+)\s+\#DBCS LEAD BYTE/)
391 {
392 my $cp = hex $1;
393 push @lead_bytes,$cp;
394 $cp2uni[$cp] = 0;
395 next;
396 }
397 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
398 {
399 my $cp = hex $1;
400 my $uni = hex $2;
401 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
402 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
403 if ($cp > 0xff && !defined($cp2uni[$cp >> 8]))
404 {
405 push @lead_bytes,$cp >> 8;
406 $cp2uni[$cp >> 8] = 0;
407 }
408 next;
409 }
410 die "$name: Unrecognized line $_\n";
411 }
412}
413
414
415################################################################
416# fill input data for the 20127 (us-ascii) codepage
417sub fill_20127_codepage()
418{
419 for (my $i = 0; $i < 128; $i++) { $cp2uni[$i] = $uni2cp[$i] = $i; }
420 for (my $i = 128; $i < 256; $i++) { $cp2uni[$i] = $i & 0x7f; }
421}
422
423################################################################
424# get a mapping including glyph chars for MB_USEGLYPHCHARS
425
426sub get_glyphs_mapping(@)
427{
428 $_[0x01] = 0x263a; # (WHITE SMILING FACE)
429 $_[0x02] = 0x263b; # (BLACK SMILING FACE)
430 $_[0x03] = 0x2665; # (BLACK HEART SUIT)
431 $_[0x04] = 0x2666; # (BLACK DIAMOND SUIT)
432 $_[0x05] = 0x2663; # (BLACK CLUB SUIT)
433 $_[0x06] = 0x2660; # (BLACK SPADE SUIT)
434 $_[0x07] = 0x2022; # (BULLET)
435 $_[0x08] = 0x25d8; # (INVERSE BULLET)
436 $_[0x09] = 0x25cb; # (WHITE CIRCLE)
437 $_[0x0a] = 0x25d9; # (INVERSE WHITE CIRCLE)
438 $_[0x0b] = 0x2642; # (MALE SIGN)
439 $_[0x0c] = 0x2640; # (FEMALE SIGN)
440 $_[0x0d] = 0x266a; # (EIGHTH NOTE)
441 $_[0x0e] = 0x266b; # (BEAMED EIGHTH NOTES)
442 $_[0x0f] = 0x263c; # (WHITE SUN WITH RAYS)
443 $_[0x10] = 0x25ba; # (BLACK RIGHT-POINTING POINTER)
444 $_[0x11] = 0x25c4; # (BLACK LEFT-POINTING POINTER)
445 $_[0x12] = 0x2195; # (UP DOWN ARROW)
446 $_[0x13] = 0x203c; # (DOUBLE EXCLAMATION MARK)
447 $_[0x14] = 0x00b6; # (PILCROW SIGN)
448 $_[0x15] = 0x00a7; # (SECTION SIGN)
449 $_[0x16] = 0x25ac; # (BLACK RECTANGLE)
450 $_[0x17] = 0x21a8; # (UP DOWN ARROW WITH BASE)
451 $_[0x18] = 0x2191; # (UPWARDS ARROW)
452 $_[0x19] = 0x2193; # (DOWNWARDS ARROW)
453 $_[0x1a] = 0x2192; # (RIGHTWARDS ARROW)
454 $_[0x1b] = 0x2190; # (LEFTWARDS ARROW)
455 $_[0x1c] = 0x221f; # (RIGHT ANGLE)
456 $_[0x1d] = 0x2194; # (LEFT RIGHT ARROW)
457 $_[0x1e] = 0x25b2; # (BLACK UP-POINTING TRIANGLE)
458 $_[0x1f] = 0x25bc; # (BLACK DOWN-POINTING TRIANGLE)
459 $_[0x7f] = 0x2302; # (HOUSE)
460 return @_;
461}
462
463################################################################
464# build EUC-JP table from the JIS 0208 file
465# FIXME: for proper EUC-JP we should probably read JIS 0212 too
466# but this would require 3-byte DBCS characters
467sub READ_JIS0208_FILE($)
468{
469 my $name = shift;
470
471 # ASCII chars
472 for (my $i = 0x00; $i <= 0x7f; $i++)
473 {
474 $cp2uni[$i] = $i;
475 $uni2cp[$i] = $i;
476 }
477
478 # JIS X 0201 right plane
479 for (my $i = 0xa1; $i <= 0xdf; $i++)
480 {
481 $cp2uni[0x8e00 + $i] = 0xfec0 + $i;
482 $uni2cp[0xfec0 + $i] = 0x8e00 + $i;
483 }
484
485 # lead bytes
486 foreach my $i (0x8e, 0x8f, 0xa1 .. 0xfe)
487 {
488 push @lead_bytes,$i;
489 $cp2uni[$i] = 0;
490 }
491
492 # undefined chars
493 foreach my $i (0x80 .. 0x8d, 0x90 .. 0xa0, 0xff)
494 {
495 $cp2uni[$i] = $DEF_CHAR;
496 }
497
498 # Shift-JIS compatibility
499 $uni2cp[0x00a5] = 0x5c;
500 $uni2cp[0x203e] = 0x7e;
501
502 # Fix backslash conversion
503 $cp2uni[0xa1c0] = 0xff3c;
504 $uni2cp[0xff3c] = 0xa1c0;
505
506 open INPUT, "$name" or die "Cannot open $name";
507 while (<INPUT>)
508 {
509 next if /^\#/; # skip comments
510 next if /^$/; # skip empty lines
511 next if /\x1a/; # skip ^Z
512 if (/^0x[0-9a-fA-F]+\s+0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)\s+(\#.*)?/)
513 {
514 my $cp = 0x8080 + hex $1;
515 my $uni = hex $2;
516 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
517 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
518 next;
519 }
520 die "$name: Unrecognized line $_\n";
521 }
522}
523
524
525################################################################
526# build the sort keys table
527sub READ_SORTKEYS_FILE()
528{
529 my @sortkeys = ();
530 for (my $i = 0; $i < 65536; $i++) { $sortkeys[$i] = [ -1, 0, 0, 0, 0 ] };
531
532 open INPUT, "$SORTKEYS" or die "Cannot open $SORTKEYS";
533 print "Loading $SORTKEYS\n";
534 while (<INPUT>)
535 {
536 next if /^\#/; # skip comments
537 next if /^$/; # skip empty lines
538 next if /\x1a/; # skip ^Z
539 next if /^\@version/; # skip @version header
540 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]+)\]/)
541 {
542 my ($uni,$variable) = (hex $1, $2);
543 next if $uni > 65535;
544 $sortkeys[$uni] = [ $uni, hex $3, hex $4, hex $5, hex $6 ];
545 next;
546 }
547 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]+)\]/)
548 {
549 # multiple character sequence, ignored for now
550 next;
551 }
552 die "$SORTKEYS: Unrecognized line $_\n";
553 }
554 close INPUT;
555
556 # compress the keys to 32 bit:
557 # key 1 to 16 bits, key 2 to 8 bits, key 3 to 4 bits, key 4 to 1 bit
558
559 @sortkeys = sort { ${$a}[1] <=> ${$b}[1] or
560 ${$a}[2] <=> ${$b}[2] or
561 ${$a}[3] <=> ${$b}[3] or
562 ${$a}[4] <=> ${$b}[4] or
563 $a cmp $b; } @sortkeys;
564
565 my ($n2, $n3) = (1, 1);
566 my @keys = (-1, -1, -1, -1, -1 );
567 my @flatkeys = ();
568
569 for (my $i = 0; $i < 65536; $i++)
570 {
571 my @current = @{$sortkeys[$i]};
572 next if $current[0] == -1;
573 if ($current[1] == $keys[1])
574 {
575 if ($current[2] == $keys[2])
576 {
577 if ($current[3] == $keys[3])
578 {
579 # nothing
580 }
581 else
582 {
583 $keys[3] = $current[3];
584 $n3++;
585 die if ($n3 >= 16);
586 }
587 }
588 else
589 {
590 $keys[2] = $current[2];
591 $keys[3] = $current[3];
592 $n2++;
593 $n3 = 1;
594 die if ($n2 >= 256);
595 }
596 }
597 else
598 {
599 $keys[1] = $current[1];
600 $keys[2] = $current[2];
601 $keys[3] = $current[3];
602 $n2 = 1;
603 $n3 = 1;
604 }
605
606 if ($current[2]) { $current[2] = $n2; }
607 if ($current[3]) { $current[3] = $n3; }
608 if ($current[4]) { $current[4] = 1; }
609
610 $flatkeys[$current[0]] = ($current[1] << 16) | ($current[2] << 8) | ($current[3] << 4) | $current[4];
611 }
612 return @flatkeys;
613}
614
615
616################################################################
617# build the sort keys table
618sub DUMP_SORTKEYS($@)
619{
620 my ($filename, @keys) = @_;
621
622 # count the number of 256-key ranges that contain something
623
624 my @offsets = ();
625 my $ranges = 2;
626 for (my $i = 0; $i < 256; $i++) { $offsets[$i] = 256; }
627 for (my $i = 0; $i < 65536; $i++)
628 {
629 next unless defined $keys[$i];
630 $offsets[$i >> 8] = $ranges * 256;
631 $ranges++;
632 $i |= 255;
633 }
634
635 # output the range offsets
636
637 open OUTPUT,">$filename.new" or die "Cannot create $filename";
638 printf "Building $filename\n";
639 printf OUTPUT "/* Unicode collation element table */\n";
640 printf OUTPUT "/* generated from %s */\n", $SORTKEYS;
641 printf OUTPUT "/* DO NOT EDIT!! */\n\n";
642
643 printf OUTPUT "const unsigned int collation_table[%d] =\n{\n", $ranges*256;
644 printf OUTPUT " /* index */\n";
645 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%08x", 0, @offsets );
646
647 # output the default values
648
649 printf OUTPUT " /* defaults */\n";
650 printf OUTPUT "%s", DUMP_ARRAY( "0x%08x", 0, (0xffffffff) x 256 );
651
652 # output all the key ranges
653
654 for (my $i = 0; $i < 256; $i++)
655 {
656 next if $offsets[$i] == 256;
657 printf OUTPUT ",\n /* 0x%02x00 .. 0x%02xff */\n", $i, $i;
658 printf OUTPUT "%s", DUMP_ARRAY( "0x%08x", 0xffffffff, @keys[($i<<8) .. ($i<<8)+255] );
659 }
660 printf OUTPUT "\n};\n";
661 close OUTPUT;
662 save_file($filename);
663}
664
665
666################################################################
667# add default mappings once the file had been read
668sub ADD_DEFAULT_MAPPINGS()
669{
670 # Apply aliases
671
672 foreach my $alias (@unicode_aliases)
673 {
674 my $target = undef;
675 foreach my $src (@$alias)
676 {
677 if (defined($uni2cp[$src]))
678 {
679 $target = $uni2cp[$src];
680 last;
681 }
682 }
683 next unless defined($target);
684
685 # At least one char of the alias set is defined, set the others to the same value
686 foreach my $src (@$alias)
687 {
688 $uni2cp[$src] = $target unless defined($uni2cp[$src]);
689 }
690 }
691
692 # For every src -> target mapping in the defaults table,
693 # make uni2cp[src] = uni2cp[target] if uni2cp[target] is defined
694
695 for (my $src = 0; $src < 65536; $src++)
696 {
697 next if defined($uni2cp[$src]); # source has a definition already
698 next unless defined($unicode_defaults[$src]); # no default for this char
699 my $target = $unicode_defaults[$src];
700
701 # do a recursive mapping until we find a target char that is defined
702 while (!defined($uni2cp[$target]) &&
703 defined($unicode_defaults[$target])) { $target = $unicode_defaults[$target]; }
704
705 if (defined($uni2cp[$target])) { $uni2cp[$src] = $uni2cp[$target]; }
706 }
707
708 # Add an identity mapping for all undefined chars
709
710 for (my $i = 0; $i < 256; $i++)
711 {
712 next if defined($cp2uni[$i]);
713 next if defined($uni2cp[$i]);
714 $cp2uni[$i] = $uni2cp[$i] = $i;
715 }
716}
717
718################################################################
719# dump an array of integers
720sub DUMP_ARRAY($$@)
721{
722 my ($format,$default,@array) = @_;
723 my $i;
724 my $ret = " ";
725 for ($i = 0; $i < $#array; $i++)
726 {
727 $ret .= sprintf($format, defined $array[$i] ? $array[$i] : $default);
728 $ret .= (($i % 8) != 7) ? ", " : ",\n ";
729 }
730 $ret .= sprintf($format, defined $array[$i] ? $array[$i] : $default);
731 return $ret;
732}
733
734################################################################
735# dump an SBCS mapping table
736sub dump_sbcs_table($$$$$)
737{
738 my ($codepage, $has_glyphs, $name, $def, $defw) = @_;
739 my $i;
740
741 # output the ascii->unicode table
742
743 if ($has_glyphs)
744 {
745 printf OUTPUT "static const WCHAR cp2uni[512] =\n";
746 printf OUTPUT "{\n%s", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[0 .. 255] );
747 printf OUTPUT ",\n /* glyphs */\n%s\n};\n\n",
748 DUMP_ARRAY( "0x%04x", $defw, get_glyphs_mapping(@cp2uni[0 .. 255]) );
749 }
750 else
751 {
752 printf OUTPUT "static const WCHAR cp2uni[256] =\n";
753 printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[0 .. 255] );
754 }
755
756 # count the number of unicode->ascii subtables that contain something
757
758 my @filled = ();
759 my $subtables = 1;
760 for (my $i = 0; $i < 65536; $i++)
761 {
762 next unless defined $uni2cp[$i];
763 $filled[$i >> 8] = 1;
764 $subtables++;
765 $i |= 255;
766 }
767
768 # output all the subtables into a single array
769
770 printf OUTPUT "static const unsigned char uni2cp_low[%d] =\n{\n", $subtables*256;
771 for (my $i = 0; $i < 256; $i++)
772 {
773 next unless $filled[$i];
774 printf OUTPUT " /* 0x%02x00 .. 0x%02xff */\n", $i, $i;
775 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%02x", $def, @uni2cp[($i<<8) .. ($i<<8)+255] );
776 }
777 printf OUTPUT " /* defaults */\n";
778 printf OUTPUT "%s\n};\n\n", DUMP_ARRAY( "0x%02x", 0, ($def) x 256 );
779
780 # output a table of the offsets of the subtables in the previous array
781
782 my $pos = 0;
783 my @offsets = ();
784 for (my $i = 0; $i < 256; $i++)
785 {
786 if ($filled[$i]) { push @offsets, $pos; $pos += 256; }
787 else { push @offsets, ($subtables-1) * 256; }
788 }
789 printf OUTPUT "static const unsigned short uni2cp_high[256] =\n";
790 printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%04x", 0, @offsets );
791
792 # output the code page descriptor
793
794 printf OUTPUT "const struct sbcs_table cptable_%03d =\n{\n", $codepage;
795 printf OUTPUT " { %d, 1, 0x%04x, 0x%04x, \"%s\" },\n",
796 $codepage, $def, $defw, $name;
797 printf OUTPUT " cp2uni,\n";
798 if ($has_glyphs) { printf OUTPUT " cp2uni + 256,\n"; }
799 else { printf OUTPUT " cp2uni,\n"; }
800 printf OUTPUT " uni2cp_low,\n";
801 printf OUTPUT " uni2cp_high\n};\n";
802}
803
804
805################################################################
806# dump a DBCS mapping table
807sub dump_dbcs_table($$$$@)
808{
809 my ($codepage, $name, $def, $defw, @lb_ranges) = @_;
810
811 # build a list of lead bytes that are actually used
812
813 my @lblist = ();
814 LBLOOP: for (my $y = 0; $y <= $#lead_bytes; $y++)
815 {
816 my $base = $lead_bytes[$y] << 8;
817 for (my $x = 0; $x < 256; $x++)
818 {
819 if (defined $cp2uni[$base+$x])
820 {
821 push @lblist,$lead_bytes[$y];
822 next LBLOOP;
823 }
824 }
825 }
826 my $unused = ($#lead_bytes > $#lblist);
827
828 # output the ascii->unicode table for the single byte chars
829
830 printf OUTPUT "static const WCHAR cp2uni[%d] =\n", 256 * ($#lblist + 2 + $unused);
831 printf OUTPUT "{\n%s,\n", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[0 .. 255] );
832
833 # output the default table for unused lead bytes
834
835 if ($unused)
836 {
837 printf OUTPUT " /* unused lead bytes */\n";
838 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%04x", 0, ($defw) x 256 );
839 }
840
841 # output the ascii->unicode table for each DBCS lead byte
842
843 for (my $y = 0; $y <= $#lblist; $y++)
844 {
845 my $base = $lblist[$y] << 8;
846 printf OUTPUT " /* lead byte %02x */\n", $lblist[$y];
847 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", $defw, @cp2uni[$base .. $base+255] );
848 printf OUTPUT ($y < $#lblist) ? ",\n" : "\n};\n\n";
849 }
850
851 # output the lead byte subtables offsets
852
853 my @offsets = ();
854 for (my $x = 0; $x < 256; $x++) { $offsets[$x] = 0; }
855 for (my $x = 0; $x <= $#lblist; $x++) { $offsets[$lblist[$x]] = $x + 1; }
856 if ($unused)
857 {
858 # increment all lead bytes offset to take into account the unused table
859 for (my $x = 0; $x <= $#lead_bytes; $x++) { $offsets[$lead_bytes[$x]]++; }
860 }
861 printf OUTPUT "static const unsigned char cp2uni_leadbytes[256] =\n";
862 printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%02x", 0, @offsets );
863
864 # count the number of unicode->ascii subtables that contain something
865
866 my @filled = ();
867 my $subtables = 1;
868 for (my $i = 0; $i < 65536; $i++)
869 {
870 next unless defined $uni2cp[$i];
871 $filled[$i >> 8] = 1;
872 $subtables++;
873 $i |= 255;
874 }
875
876 # output all the subtables into a single array
877
878 printf OUTPUT "static const unsigned short uni2cp_low[%d] =\n{\n", $subtables*256;
879 for (my $y = 0; $y < 256; $y++)
880 {
881 next unless $filled[$y];
882 printf OUTPUT " /* 0x%02x00 .. 0x%02xff */\n", $y, $y;
883 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%04x", $def, @uni2cp[($y<<8) .. ($y<<8)+255] );
884 }
885 printf OUTPUT " /* defaults */\n";
886 printf OUTPUT "%s\n};\n\n", DUMP_ARRAY( "0x%04x", 0, ($def) x 256 );
887
888 # output a table of the offsets of the subtables in the previous array
889
890 my $pos = 0;
891 @offsets = ();
892 for (my $y = 0; $y < 256; $y++)
893 {
894 if ($filled[$y]) { push @offsets, $pos; $pos += 256; }
895 else { push @offsets, ($subtables-1) * 256; }
896 }
897 printf OUTPUT "static const unsigned short uni2cp_high[256] =\n";
898 printf OUTPUT "{\n%s\n};\n\n", DUMP_ARRAY( "0x%04x", 0, @offsets );
899
900 # output the code page descriptor
901
902 printf OUTPUT "const struct dbcs_table cptable_%03d =\n{\n", $codepage;
903 printf OUTPUT " { %d, 2, 0x%04x, 0x%04x, \"%s\" },\n",
904 $codepage, $def, $defw, $name;
905 printf OUTPUT " cp2uni,\n";
906 printf OUTPUT " cp2uni_leadbytes,\n";
907 printf OUTPUT " uni2cp_low,\n";
908 printf OUTPUT " uni2cp_high,\n";
909 printf OUTPUT " {\n %s\n }\n", DUMP_ARRAY( "0x%02x", 0, @lb_ranges, 0, 0 );
910 printf OUTPUT "};\n";
911}
912
913
914################################################################
915# get the list of defined lead byte ranges
916sub get_lb_ranges()
917{
918 my @list = ();
919 my @ranges = ();
920 my $i = 0;
921 foreach $i (@lead_bytes) { $list[$i] = 1; }
922 my $on = 0;
923 for (my $i = 0; $i < 256; $i++)
924 {
925 if ($on)
926 {
927 if (!defined $list[$i]) { push @ranges, $i-1; $on = 0; }
928 }
929 else
930 {
931 if ($list[$i]) { push @ranges, $i; $on = 1; }
932 }
933 }
934 if ($on) { push @ranges, 0xff; }
935 return @ranges;
936}
937
938
939################################################################
940# dump the case mapping tables
941sub DUMP_CASE_MAPPINGS($)
942{
943 my $filename = shift;
944 open OUTPUT,">$filename.new" or die "Cannot create $filename";
945 printf "Building $filename\n";
946 printf OUTPUT "/* Unicode case mappings */\n";
947 printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
948 printf OUTPUT "#include \"wine/unicode.h\"\n\n";
949
950 DUMP_CASE_TABLE( "wine_casemap_lower", @tolower_table );
951 DUMP_CASE_TABLE( "wine_casemap_upper", @toupper_table );
952 DUMP_CASE_TABLE( "wine_digitmap", @digitmap_table );
953 DUMP_CASE_TABLE( "wine_compatmap", @compatmap_table );
954 close OUTPUT;
955 save_file($filename);
956}
957
958
959################################################################
960# dump a case mapping table
961sub DUMP_CASE_TABLE($@)
962{
963 my ($name,@table) = @_;
964
965 # count the number of sub tables that contain something
966 # also compute the low and upper populated bounds
967
968 my @lowerbounds = ( 0, 0 );
969 my @upperbounds = ( 0, 255 );
970 my $index = 0;
971 my @filled = ();
972 for (my $i = 0; $i < 65536; $i++)
973 {
974 next unless defined $table[$i];
975 if (!defined $filled[$i >> 8])
976 {
977 $lowerbounds[$index] = $i & 0xff;
978 $upperbounds[$index] = 0xff - $lowerbounds[$index];
979 $filled[$i >> 8] = $index * 256 + 512;
980 $index++;
981 }
982 else
983 {
984 $upperbounds[$index-1] = 0xff - ($i & 0xff);
985 }
986 $table[$i] = ($table[$i] - $i) & 0xffff;
987 }
988
989 # Collapse blocks upwards if possible
990 my $removed = 0;
991 $index = 0;
992 for (my $i = 0; $i < 256; $i++)
993 {
994 next unless defined $filled[$i];
995 if ($upperbounds[$index - 1] > $lowerbounds[$index])
996 {
997 $removed = $removed + $lowerbounds[$index];
998 }
999 else
1000 {
1001 $removed = $removed + $upperbounds[$index - 1];
1002 $lowerbounds[$index] = $upperbounds[$index - 1];
1003 }
1004 $filled[$i] = $filled[$i] - $removed;
1005 $index++;
1006 }
1007
1008 # dump the table
1009
1010 printf OUTPUT "const WCHAR %s[%d] =\n", $name, $index * 256 + 512 - $removed;
1011 printf OUTPUT "{\n /* index */\n";
1012 printf OUTPUT "%s,\n", DUMP_ARRAY( "0x%04x", 256, @filled );
1013 printf OUTPUT " /* defaults */\n";
1014 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, (0) x 256 );
1015 $index = 0;
1016 for (my $i = 0; $i < 256; $i++)
1017 {
1018 next unless $filled[$i];
1019 printf OUTPUT ",\n /* 0x%02x%02x .. 0x%02xff */\n", $i, $lowerbounds[$index], $i;
1020 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0,
1021 @table[($i<<8) + $lowerbounds[$index] .. ($i<<8)+255] );
1022 $index++;
1023 }
1024 printf OUTPUT "\n};\n";
1025}
1026
1027
1028################################################################
1029# dump the ctype tables
1030sub DUMP_CTYPE_TABLES($)
1031{
1032 my $filename = shift;
1033 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1034 printf "Building $filename\n";
1035 printf OUTPUT "/* Unicode ctype tables */\n";
1036 printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
1037 printf OUTPUT "#include \"wine/unicode.h\"\n\n";
1038
1039 my @array = (0) x 256;
1040 my %sequences;
1041
1042 # add the direction in the high 4 bits of the category
1043 for (my $i = 0; $i < 65536; $i++)
1044 {
1045 $category_table[$i] |= $direction_table[$i] << 12 if defined $direction_table[$i];
1046 }
1047
1048 # try to merge table rows
1049 for (my $row = 0; $row < 256; $row++)
1050 {
1051 my $rowtxt = sprintf "%04x" x 256, @category_table[($row<<8)..($row<<8)+255];
1052 if (defined($sequences{$rowtxt}))
1053 {
1054 # reuse an existing row
1055 $array[$row] = $sequences{$rowtxt};
1056 }
1057 else
1058 {
1059 # create a new row
1060 $sequences{$rowtxt} = $array[$row] = $#array + 1;
1061 push @array, @category_table[($row<<8)..($row<<8)+255];
1062 }
1063 }
1064
1065 printf OUTPUT "const unsigned short wine_wctype_table[%d] =\n{\n", $#array+1;
1066 printf OUTPUT " /* offsets */\n%s,\n", DUMP_ARRAY( "0x%04x", 0, @array[0..255] );
1067 printf OUTPUT " /* values */\n%s\n};\n", DUMP_ARRAY( "0x%04x", 0, @array[256..$#array] );
1068
1069 close OUTPUT;
1070 save_file($filename);
1071}
1072
1073
1074################################################################
1075# dump the char composition tables
1076sub DUMP_COMPOSE_TABLES($)
1077{
1078 my $filename = shift;
1079
1080 open OUTPUT,">$filename.new" or die "Cannot create $filename";
1081 printf "Building $filename\n";
1082 printf OUTPUT "/* Unicode char composition */\n";
1083 printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
1084 printf OUTPUT "#include \"wine/unicode.h\"\n\n";
1085
1086 ######### composition table
1087
1088 my @filled = ();
1089 foreach my $i (@compose_table)
1090 {
1091 my @comp = @$i;
1092 push @{$filled[$comp[1]]}, [ $comp[0], $comp[2] ];
1093 }
1094
1095 # count how many different second chars we have
1096
1097 my $count = 0;
1098 for (my $i = 0; $i < 65536; $i++)
1099 {
1100 next unless defined $filled[$i];
1101 $count++;
1102 }
1103
1104 # build the table of second chars and offsets
1105
1106 my $pos = $count + 1;
1107 my @table = ();
1108 for (my $i = 0; $i < 65536; $i++)
1109 {
1110 next unless defined $filled[$i];
1111 push @table, $i, $pos;
1112 $pos += @{$filled[$i]};
1113 }
1114 # terminator with last position
1115 push @table, 0, $pos;
1116 printf OUTPUT "const WCHAR unicode_compose_table[0x%x] =\n{\n", 2*$pos;
1117 printf OUTPUT " /* second chars + offsets */\n%s", DUMP_ARRAY( "0x%04x", 0, @table );
1118
1119 # build the table of first chars and mappings
1120
1121 for (my $i = 0; $i < 65536; $i++)
1122 {
1123 next unless defined $filled[$i];
1124 my @table = ();
1125 my @list = sort { $a->[0] <=> $b->[0] } @{$filled[$i]};
1126 for (my $j = 0; $j <= $#list; $j++)
1127 {
1128 push @table, $list[$j][0], $list[$j][1];
1129 }
1130 printf OUTPUT ",\n /* 0x%04x */\n%s", $i, DUMP_ARRAY( "0x%04x", 0, @table );
1131 }
1132 printf OUTPUT "\n};\n\nconst unsigned int unicode_compose_table_size = %d;\n\n", $count;
1133
1134 ######### decomposition table
1135
1136 # first determine all the 16-char subsets that contain something
1137
1138 @filled = (0) x 4096;
1139 $pos = 16*2; # for the null subset
1140 for (my $i = 0; $i < 65536; $i++)
1141 {
1142 next unless defined $decomp_table[$i];
1143 $filled[$i >> 4] = $pos;
1144 $pos += 16*2;
1145 $i |= 15;
1146 }
1147 my $total = $pos;
1148
1149 # now count the 256-char subsets that contain something
1150
1151 my @filled_idx = (256) x 256;
1152 $pos = 256 + 16;
1153 for (my $i = 0; $i < 4096; $i++)
1154 {
1155 next unless $filled[$i];
1156 $filled_idx[$i >> 4] = $pos;
1157 $pos += 16;
1158 $i |= 15;
1159 }
1160 my $null_offset = $pos; # null mapping
1161 $total += $pos;
1162
1163 # add the index offsets to the subsets positions
1164
1165 for (my $i = 0; $i < 4096; $i++)
1166 {
1167 next unless $filled[$i];
1168 $filled[$i] += $null_offset;
1169 }
1170
1171 # dump the main index
1172
1173 printf OUTPUT "const WCHAR unicode_decompose_table[%d] =\n", $total;
1174 printf OUTPUT "{\n /* index */\n";
1175 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @filled_idx );
1176 printf OUTPUT ",\n /* null sub-index */\n%s", DUMP_ARRAY( "0x%04x", 0, ($null_offset) x 16 );
1177
1178 # dump the second-level indexes
1179
1180 for (my $i = 0; $i < 256; $i++)
1181 {
1182 next unless ($filled_idx[$i] > 256);
1183 my @table = @filled[($i<<4)..($i<<4)+15];
1184 for (my $j = 0; $j < 16; $j++) { $table[$j] ||= $null_offset; }
1185 printf OUTPUT ",\n /* sub-index %02x */\n", $i;
1186 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
1187 }
1188
1189 # dump the 16-char subsets
1190
1191 printf OUTPUT ",\n /* null mapping */\n";
1192 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, (0) x 32 );
1193
1194 for (my $i = 0; $i < 4096; $i++)
1195 {
1196 next unless $filled[$i];
1197 my @table = (0) x 32;
1198 for (my $j = 0; $j < 16; $j++)
1199 {
1200 if (defined $decomp_table[($i<<4) + $j])
1201 {
1202 $table[2 * $j] = ${$decomp_table[($i << 4) + $j]}[0];
1203 $table[2 * $j + 1] = ${$decomp_table[($i << 4) + $j]}[1];
1204 }
1205 }
1206 printf OUTPUT ",\n /* 0x%03x0 .. 0x%03xf */\n", $i, $i;
1207 printf OUTPUT "%s", DUMP_ARRAY( "0x%04x", 0, @table );
1208 }
1209
1210 printf OUTPUT "\n};\n";
1211 close OUTPUT;
1212 save_file($filename);
1213}
1214
1215
1216################################################################
1217# handle a "bestfit" Windows mapping file
1218
1219sub handle_bestfit_file($$$)
1220{
1221 my ($filename, $has_glyphs, $comment) = @_;
1222 my $state = "";
1223 my ($codepage, $width, $def, $defw, $count);
1224 my ($lb_cur, $lb_end);
1225 my @lb_ranges = ();
1226
1227 open INPUT,$MAPPREFIX . $filename or die "Cannot open $filename";
1228
1229 while (<INPUT>)
1230 {
1231 next if /^;/; # skip comments
1232 next if /^\s*$/; # skip empty lines
1233 next if /\x1a/; # skip ^Z
1234 last if /^ENDCODEPAGE/;
1235
1236 if (/^CODEPAGE\s+(\d+)/)
1237 {
1238 $codepage = $1;
1239 next;
1240 }
1241 if (/^CPINFO\s+(\d+)\s+0x([0-9a-fA-f]+)\s+0x([0-9a-fA-F]+)/)
1242 {
1243 $width = $1;
1244 $def = hex $2;
1245 $defw = hex $3;
1246 next;
1247 }
1248 if (/^(MBTABLE|WCTABLE|DBCSRANGE|DBCSTABLE)\s+(\d+)/)
1249 {
1250 $state = $1;
1251 $count = $2;
1252 next;
1253 }
1254 if (/^0x([0-9a-fA-F]+)\s+0x([0-9a-fA-F]+)/)
1255 {
1256 if ($state eq "MBTABLE")
1257 {
1258 my $cp = hex $1;
1259 my $uni = hex $2;
1260 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
1261 next;
1262 }
1263 if ($state eq "WCTABLE")
1264 {
1265 my $uni = hex $1;
1266 my $cp = hex $2;
1267 $uni2cp[$uni] = $cp unless defined($uni2cp[$uni]);
1268 next;
1269 }
1270 if ($state eq "DBCSRANGE")
1271 {
1272 my $start = hex $1;
1273 my $end = hex $2;
1274 push @lb_ranges, $start, $end;
1275 for (my $i = $start; $i <= $end; $i++)
1276 {
1277 push @lead_bytes, $i;
1278 $cp2uni[$i] = 0;
1279 }
1280 $lb_cur = $start;
1281 $lb_end = $end;
1282 next;
1283 }
1284 if ($state eq "DBCSTABLE")
1285 {
1286 my $mb = hex $1;
1287 my $uni = hex $2;
1288 my $cp = ($lb_cur << 8) | $mb;
1289 $cp2uni[$cp] = $uni unless defined($cp2uni[$cp]);
1290 if (!--$count)
1291 {
1292 if (++$lb_cur > $lb_end) { $state = "DBCSRANGE"; }
1293 }
1294 next;
1295 }
1296 }
1297 die "$filename: Unrecognized line $_\n";
1298 }
1299 close INPUT;
1300
1301 my $output = sprintf "c_%03d.c", $codepage;
1302 open OUTPUT,">$output.new" or die "Cannot create $output";
1303
1304 printf "Building %s from %s (%s)\n", $output, $filename, $comment;
1305
1306 # dump all tables
1307
1308 printf OUTPUT "/* code page %03d (%s) */\n", $codepage, $comment;
1309 printf OUTPUT "/* generated from %s */\n", $MAPPREFIX . $filename;
1310 printf OUTPUT "/* DO NOT EDIT!! */\n\n";
1311 printf OUTPUT "#include \"wine/unicode.h\"\n\n";
1312
1313 if ($width == 1) { dump_sbcs_table( $codepage, $has_glyphs, $comment, $def, $defw ); }
1314 else { dump_dbcs_table( $codepage, $comment, $def, $defw, @lb_ranges ); }
1315 close OUTPUT;
1316 save_file($output);
1317}
1318
1319
1320################################################################
1321# read an input file and generate the corresponding .c file
1322sub HANDLE_FILE(@)
1323{
1324 my ($codepage,$filename,$has_glyphs,$comment) = @_;
1325
1326 @cp2uni = ();
1327 @lead_bytes = ();
1328 @uni2cp = ();
1329
1330 # symbol codepage file is special
1331 if ($codepage == 20932) { READ_JIS0208_FILE($MAPPREFIX . $filename); }
1332 elsif ($codepage == 20127) { fill_20127_codepage(); }
1333 elsif ($filename =~ /\/bestfit/)
1334 {
1335 handle_bestfit_file( $filename, $has_glyphs, $comment );
1336 return;
1337 }
1338 else { READ_FILE($MAPPREFIX . $filename); }
1339
1340 ADD_DEFAULT_MAPPINGS();
1341
1342 my $output = sprintf "c_%03d.c", $codepage;
1343 open OUTPUT,">$output.new" or die "Cannot create $output";
1344
1345 printf "Building %s from %s (%s)\n", $output, $filename || "hardcoded data", $comment;
1346
1347 # dump all tables
1348
1349 printf OUTPUT "/* code page %03d (%s) */\n", $codepage, $comment;
1350 if ($filename)
1351 {
1352 printf OUTPUT "/* generated from %s */\n", $MAPPREFIX . $filename;
1353 printf OUTPUT "/* DO NOT EDIT!! */\n\n";
1354 }
1355 else
1356 {
1357 printf OUTPUT "/* Automatically generated; DO NOT EDIT!! */\n\n";
1358 }
1359 printf OUTPUT "#include \"wine/unicode.h\"\n\n";
1360
1361 if (!@lead_bytes) { dump_sbcs_table( $codepage, $has_glyphs, $comment, $DEF_CHAR, $DEF_CHAR ); }
1362 else { dump_dbcs_table( $codepage, $comment, $DEF_CHAR, $DEF_CHAR, get_lb_ranges() ); }
1363 close OUTPUT;
1364 save_file($output);
1365}
1366
1367
1368################################################################
1369# save a file if modified
1370sub save_file($)
1371{
1372 my $file = shift;
1373 if (-f $file && !system "cmp $file $file.new >/dev/null")
1374 {
1375 unlink "$file.new";
1376 }
1377 else
1378 {
1379 rename "$file.new", "$file";
1380 }
1381}
1382
1383
1384################################################################
1385# output the list of codepage tables into the cptable.c file
1386sub OUTPUT_CPTABLE()
1387{
1388 my @tables_decl = ();
1389
1390 foreach my $file (@allfiles)
1391 {
1392 my ($codepage,$filename,$comment) = @$file;
1393 push @tables_decl, sprintf("extern union cptable cptable_%03d;\n",$codepage);
1394 }
1395
1396 push @tables_decl, sprintf("\nstatic const union cptable * const cptables[%d] =\n{\n",$#allfiles+1);
1397 foreach my $file (@allfiles)
1398 {
1399 my ($codepage,$filename,$comment) = @$file;
1400 push @tables_decl, sprintf(" &cptable_%03d,\n", $codepage);
1401 }
1402 push @tables_decl, "};";
1403 REPLACE_IN_FILE( "cptable.c", @tables_decl );
1404}
1405
1406################################################################
1407# replace the contents of a file between ### cpmap ### marks
1408
1409sub REPLACE_IN_FILE($@)
1410{
1411 my $name = shift;
1412 my @data = @_;
1413 my @lines = ();
1414 open(FILE,$name) or die "Can't open $name";
1415 while (<FILE>)
1416 {
1417 push @lines, $_;
1418 last if /\#\#\# cpmap begin \#\#\#/;
1419 }
1420 push @lines, @data;
1421 while (<FILE>)
1422 {
1423 if (/\#\#\# cpmap end \#\#\#/) { push @lines, "\n", $_; last; }
1424 }
1425 push @lines, <FILE>;
1426 open(FILE,">$name.new") or die "Can't modify $name";
1427 print FILE @lines;
1428 close(FILE);
1429 save_file($name);
1430}
1431
1432################################################################
1433# main routine
1434
1435READ_DEFAULTS( $DEFAULTS );
1436DUMP_CASE_MAPPINGS( "casemap.c" );
1437DUMP_SORTKEYS( "collation.c", READ_SORTKEYS_FILE() );
1438DUMP_COMPOSE_TABLES( "compose.c" );
1439DUMP_CTYPE_TABLES( "wctype.c" );
1440
1441foreach my $file (@allfiles) { HANDLE_FILE( @{$file} ); }
1442
1443OUTPUT_CPTABLE();
1444
1445exit 0;
1446
1447# Local Variables:
1448# compile-command: "./cpmap.pl && make -k"
1449# End:
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette