1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/uconv/tools/jis0212tojdx.pl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,62 @@ 1.4 +#!/user/local/bin/perl 1.5 +# This Source Code Form is subject to the terms of the Mozilla Public 1.6 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.8 + 1.9 +sub jis0212tonum() 1.10 +{ 1.11 + my($jis0212) = (@_); 1.12 + my($first,$second,$jnum); 1.13 + $first = hex(substr($jis0212,2,2)); 1.14 + $second = hex(substr($jis0212,4,2)); 1.15 + $jnum = (($first - 0x21) * 94); 1.16 + $jnum += $second - 0x21 ; 1.17 + return $jnum; 1.18 +} 1.19 + 1.20 +@map = {}; 1.21 +sub readtable() 1.22 +{ 1.23 +open(JIS0212, "<JIS0212") || die "cannot open JIS0212"; 1.24 +while(<JIS0212>) 1.25 +{ 1.26 + if(! /^#/) { 1.27 + ($j, $u, $r) = split(/\t/,$_); 1.28 + if(length($j) > 4) 1.29 + { 1.30 + $n = &jis0212tonum($j); 1.31 + $map{$n} = $u; 1.32 + } 1.33 + } 1.34 +} 1.35 +} 1.36 + 1.37 +## add eudc to $map here 1.38 + 1.39 +sub printtable() 1.40 +{ 1.41 +for($i=0;$i<94;$i++) 1.42 +{ 1.43 + printf ( "/* 0x%2XXX */\n", ( $i + 0x21)); 1.44 + printf " "; 1.45 + for($j=0;$j<94;$j++) 1.46 + { 1.47 + if("" == ($map{($i * 94 + $j)})) 1.48 + { 1.49 + print "0xFFFD," 1.50 + } 1.51 + else 1.52 + { 1.53 + print $map{($i * 94 + $j)} . ","; 1.54 + } 1.55 + if( 7 == (($j + 1) % 8)) 1.56 + { 1.57 + printf "/* 0x%2X%1X%1X*/\n", $i+0x21, 2+($j/16), (6==($j%16))?0:8; 1.58 + } 1.59 + } 1.60 + printf " /* 0x%2X%1X%1X*/\n", $i+0x21, 2+($j/16),(6==($j%16))?0:8; 1.61 +} 1.62 +} 1.63 +&readtable(); 1.64 +&printtable(); 1.65 +