|
1 #!/user/local/bin/perl |
|
2 # -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
3 # |
|
4 # This Source Code Form is subject to the terms of the Mozilla Public |
|
5 # License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
7 $rowwidth = ((0xff - 0x80)+(0x7f - 0x40)); |
|
8 sub cp936tonum() |
|
9 { |
|
10 my($cp936) = (@_); |
|
11 my($first,$second,$jnum); |
|
12 $first = hex(substr($cp936,2,2)); |
|
13 $second = hex(substr($cp936,4,2)); |
|
14 $jnum = ($first - 0x81 ) * $rowwidth; |
|
15 if($second >= 0x80) |
|
16 { |
|
17 $jnum += $second - 0x80 + (0x7f-0x40); |
|
18 } |
|
19 else |
|
20 { |
|
21 $jnum += $second - 0x40; |
|
22 } |
|
23 return $jnum; |
|
24 } |
|
25 |
|
26 @map = {}; |
|
27 sub readtable() |
|
28 { |
|
29 open(CP936, "<gbkcommon.txt") || die "cannot open gbkcommon.txt"; |
|
30 while(<CP936>) |
|
31 { |
|
32 if(! /^#/) { |
|
33 chop(); |
|
34 ($j, $u, $r) = split(/\t/,$_); |
|
35 if(length($j) > 4) |
|
36 { |
|
37 $n = &cp936tonum($j); |
|
38 $map{$n} = $u; |
|
39 } |
|
40 } |
|
41 } |
|
42 } |
|
43 |
|
44 |
|
45 sub printtable() |
|
46 { |
|
47 for($i=0;$i<126;$i++) |
|
48 { |
|
49 printf ( "/* 0x%2XXX */\n", ( $i + 0x81)); |
|
50 for($j=0;$j<(0x7f-0x40);$j++) |
|
51 { |
|
52 if("" eq ($map{($i * $rowwidth + $j)})) |
|
53 { |
|
54 printf "0xFFFD," |
|
55 } |
|
56 else |
|
57 { |
|
58 printf $map{($i * $rowwidth + $j)} . ","; |
|
59 } |
|
60 if( 0 == (($j + 1) % 8)) |
|
61 { |
|
62 printf "/* 0x%2X%1X%1X*/\n", $i+0x81, 4+($j/16), (7==($j%16))?0:8; |
|
63 } |
|
64 } |
|
65 |
|
66 print "0xFFFD,"; |
|
67 |
|
68 printf "/* 0x%2X%1X%1X*/\n", $i+0x81, 4+($j/16),(7==($j%16))?0:8; |
|
69 for($j=0;$j < (0xff-0x80);$j++) |
|
70 { |
|
71 if("" eq ($map{($i * $rowwidth + $j + 0x3f)})) # user defined chars map to 0xFFFD |
|
72 { |
|
73 |
|
74 if ( ( $i == 125 ) and ( $j == (0xff - 0x80 - 1 ))) |
|
75 { |
|
76 printf "0xFFFD"; #has no ',' followed last item |
|
77 } |
|
78 else |
|
79 { |
|
80 printf "0xFFFD,"; |
|
81 } |
|
82 } |
|
83 else |
|
84 { |
|
85 if ( ( $i == 125 ) and ( $j == (0xff - 0x80 - 1 ))) |
|
86 { |
|
87 printf $map{($i * $rowwidth + $j + 0x3f)}; #has no ',' followed last item |
|
88 } |
|
89 else |
|
90 { |
|
91 printf $map{($i * $rowwidth + $j + 0x3f)} . ","; |
|
92 } |
|
93 } |
|
94 |
|
95 if( 0 == (($j + 1) % 8)) |
|
96 { |
|
97 printf "/* 0x%2X%1X%1X*/\n", $i+0x81, 8+($j/16), (7==($j%16))?0:8; |
|
98 } |
|
99 } |
|
100 printf " /* 0x%2X%1X%1X*/\n", $i+0x81, 8+($j/16),(7==($j%16))?0:8; |
|
101 } |
|
102 } |
|
103 sub printnpl() |
|
104 { |
|
105 $npl = <<END_OF_NPL; |
|
106 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
107 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
108 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
109 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
110 END_OF_NPL |
|
111 print $npl; |
|
112 } |
|
113 sub printdontmodify() |
|
114 { |
|
115 $dont_modify = <<END_OF_DONT_MODIFY; |
|
116 /* |
|
117 This file is generated by mozilla/intl/uconv/tools/cp936tocdx.pl |
|
118 Please do not modify this file by hand |
|
119 Instead, you should download CP936.TXT from |
|
120 http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/ |
|
121 and put under mozilla/intl/uconv/toools |
|
122 and run perl cp936tocdx.pl > ../ucvcn/cp936map.h |
|
123 If you have question, mailto:ftan\@netscape.com |
|
124 */ |
|
125 END_OF_DONT_MODIFY |
|
126 print $dont_modify; |
|
127 } |
|
128 |
|
129 &readtable(); |
|
130 &printnpl(); |
|
131 &printdontmodify(); |
|
132 &printtable(); |
|
133 |