Added pow() forward.
[wine.git] / tools / unimap.pl
blobd613c25a48013688e232027d8fb8bebeeda17029
1 #!/usr/bin/perl
3 # Reads the Unicode 2.0 "unidata2.txt" file and selects encodings
4 # for case pairs, then builds an include file "casemap.h" for the
5 # case conversion routines.
7 use integer
9 $INFILE = "UnicodeData.txt";
10 $OUT = ">casemap.h";
11 $TEST = ">allcodes";
13 # Open the data file ...
14 open INFILE or die "Can't open input file $INFILE!\n";
15 open OUT or die "Can't open output file $OUT!\n";
16 open TEST or die "Can't open output file $OUT!\n";
18 #Initialize the upper and lower hashes
19 %lwrtable = ();
20 %uprtable = ();
21 @low = ("0") x 256;
22 @upr = ("0") x 256;
24 while ($line = <INFILE> )
26 # Decode the fields ...
27 ($code, $name, $cat, $comb, $bidi,
28 $decomp, $dec, $dig, $num, $mirror,
29 $oldname, $comment, $upper, $lower, $title) = split /;/, $line;
31 #Get the high byte of the code
32 $high = substr $code, 0, 2;
33 if ($lower ne "") {
34 $low[hex $high] = "lblk" . $high;
35 $lwrtable{$code} = $lower;
37 if ($upper ne "") {
38 $upr[hex $high] = "ublk" . $high;
39 $uprtable{$code} = $upper;
41 #Write everything to the test file
42 printf TEST "%s %s %s\n", $code,
43 $upper ne "" ? $upper : "0000",
44 $lower ne "" ? $lower : "0000";
47 close(FILE);
48 close TEST;
50 #Generate the header file
51 print OUT "/*\n";
52 print OUT " * Automatically generated file -- do not edit!\n";
53 print OUT " * (Use tools/unimap.pl for generation)\n";
54 print OUT " *\n";
55 print OUT " * Mapping tables for Unicode case conversion\n";
56 print OUT " */\n";
57 print OUT "\n";
58 print OUT "#ifndef __WINE_CASEMAP_H\n";
59 print OUT "#define __WINE_CASEMAP_H\n";
60 print OUT "\n";
61 print OUT "#include \"windef.h\"\n";
62 print OUT "\n";
64 #Write out the non-trivial mappings
65 for ($high = 0; $high < 256; $high++) {
66 #Check whether the table is needed
67 if (length $low[$high] < 6) {
68 next;
70 printf OUT "/* Lowercase mappings %02X00 - %02XFF */\n",
71 $high, $high;
72 printf OUT "static const WCHAR lblk%02X[256] = {\n", $high;
73 for ($low = 0; $low < 256; $low += 8) {
74 @patch = ();
75 for ($i = 0; $i < 8; $i++) {
76 $code = sprintf "%02X%02X", $high, $low + $i;
77 $map = $lwrtable{$code};
78 if ($map eq "") {
79 $map = $code;
81 $patch[$i] = "0x" . $map;
83 printf OUT "\t%s, %s, %s, %s, %s, %s, %s, %s,\n",
84 @patch;
86 print OUT "};\n\n";
88 print OUT "static const WCHAR * const lwrtable[256] = {\n";
89 for ($i = 0; $i < 256; $i += 8) {
90 @patch = @low[$i+0 .. $i+7];
91 printf OUT "\t%06s, %06s, %06s, %06s, %06s, %06s, %06s, %06s,\n",
92 @patch;
94 print OUT "};\n\n";
96 for ($high = 0; $high < 256; $high++) {
97 #Check whether the table is needed
98 if (length $upr[$high] < 6) {
99 next;
101 printf OUT "/* Uppercase mappings %02X00 - %02XFF */\n",
102 $high, $high;
103 printf OUT "static const WCHAR ublk%02X[256] = {\n", $high;
104 for ($low = 0; $low < 256; $low += 8) {
105 @patch = ();
106 for ($i = 0; $i < 8; $i++) {
107 $code = sprintf "%02X%02X", $high, $low + $i;
108 $map = $uprtable{$code};
109 if ($map eq "") {
110 $map = $code;
112 $patch[$i] = "0x" . $map;
114 printf OUT "\t%s, %s, %s, %s, %s, %s, %s, %s,\n",
115 @patch;
117 print OUT "};\n\n";
119 print OUT "static const WCHAR * const uprtable[256] = {\n";
120 for ($i = 0; $i < 256; $i += 8) {
121 @patch = @upr[$i+0 .. $i+7];
122 printf OUT "\t%06s, %06s, %06s, %06s, %06s, %06s, %06s, %06s,\n",
123 @patch;
125 print OUT "};\n";
126 print OUT "\n";
127 print OUT "#endif /* !defined(__WINE_CASEMAP_H) */\n";
129 close(OUT);