intl/uconv/tools/jis0212tojdx.pl

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:56054ed2568d
1 #!/user/local/bin/perl
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
6 sub jis0212tonum()
7 {
8 my($jis0212) = (@_);
9 my($first,$second,$jnum);
10 $first = hex(substr($jis0212,2,2));
11 $second = hex(substr($jis0212,4,2));
12 $jnum = (($first - 0x21) * 94);
13 $jnum += $second - 0x21 ;
14 return $jnum;
15 }
16
17 @map = {};
18 sub readtable()
19 {
20 open(JIS0212, "<JIS0212") || die "cannot open JIS0212";
21 while(<JIS0212>)
22 {
23 if(! /^#/) {
24 ($j, $u, $r) = split(/\t/,$_);
25 if(length($j) > 4)
26 {
27 $n = &jis0212tonum($j);
28 $map{$n} = $u;
29 }
30 }
31 }
32 }
33
34 ## add eudc to $map here
35
36 sub printtable()
37 {
38 for($i=0;$i<94;$i++)
39 {
40 printf ( "/* 0x%2XXX */\n", ( $i + 0x21));
41 printf " ";
42 for($j=0;$j<94;$j++)
43 {
44 if("" == ($map{($i * 94 + $j)}))
45 {
46 print "0xFFFD,"
47 }
48 else
49 {
50 print $map{($i * 94 + $j)} . ",";
51 }
52 if( 7 == (($j + 1) % 8))
53 {
54 printf "/* 0x%2X%1X%1X*/\n", $i+0x21, 2+($j/16), (6==($j%16))?0:8;
55 }
56 }
57 printf " /* 0x%2X%1X%1X*/\n", $i+0x21, 2+($j/16),(6==($j%16))?0:8;
58 }
59 }
60 &readtable();
61 &printtable();
62

mercurial