michael@0: #!/user/local/bin/perl michael@0: # -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: $rowwidth = ((0xff - 0x80)+(0x7f - 0x40)); michael@0: sub cp936tonum() michael@0: { michael@0: my($cp936) = (@_); michael@0: my($first,$second,$jnum); michael@0: $first = hex(substr($cp936,2,2)); michael@0: $second = hex(substr($cp936,4,2)); michael@0: $jnum = ($first - 0x81 ) * $rowwidth; michael@0: if($second >= 0x80) michael@0: { michael@0: $jnum += $second - 0x80 + (0x7f-0x40); michael@0: } michael@0: else michael@0: { michael@0: $jnum += $second - 0x40; michael@0: } michael@0: return $jnum; michael@0: } michael@0: michael@0: @map = {}; michael@0: sub readtable() michael@0: { michael@0: open(CP936, ") michael@0: { michael@0: if(! /^#/) { michael@0: chop(); michael@0: ($j, $u, $r) = split(/\t/,$_); michael@0: if(length($j) > 4) michael@0: { michael@0: $n = &cp936tonum($j); michael@0: $map{$n} = $u; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: michael@0: sub printtable() michael@0: { michael@0: for($i=0;$i<126;$i++) michael@0: { michael@0: printf ( "/* 0x%2XXX */\n", ( $i + 0x81)); michael@0: for($j=0;$j<(0x7f-0x40);$j++) michael@0: { michael@0: if("" eq ($map{($i * $rowwidth + $j)})) michael@0: { michael@0: printf "0xFFFD," michael@0: } michael@0: else michael@0: { michael@0: printf $map{($i * $rowwidth + $j)} . ","; michael@0: } michael@0: if( 0 == (($j + 1) % 8)) michael@0: { michael@0: printf "/* 0x%2X%1X%1X*/\n", $i+0x81, 4+($j/16), (7==($j%16))?0:8; michael@0: } michael@0: } michael@0: michael@0: print "0xFFFD,"; michael@0: michael@0: printf "/* 0x%2X%1X%1X*/\n", $i+0x81, 4+($j/16),(7==($j%16))?0:8; michael@0: for($j=0;$j < (0xff-0x80);$j++) michael@0: { michael@0: if("" eq ($map{($i * $rowwidth + $j + 0x3f)})) # user defined chars map to 0xFFFD michael@0: { michael@0: michael@0: if ( ( $i == 125 ) and ( $j == (0xff - 0x80 - 1 ))) michael@0: { michael@0: printf "0xFFFD"; #has no ',' followed last item michael@0: } michael@0: else michael@0: { michael@0: printf "0xFFFD,"; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: if ( ( $i == 125 ) and ( $j == (0xff - 0x80 - 1 ))) michael@0: { michael@0: printf $map{($i * $rowwidth + $j + 0x3f)}; #has no ',' followed last item michael@0: } michael@0: else michael@0: { michael@0: printf $map{($i * $rowwidth + $j + 0x3f)} . ","; michael@0: } michael@0: } michael@0: michael@0: if( 0 == (($j + 1) % 8)) michael@0: { michael@0: printf "/* 0x%2X%1X%1X*/\n", $i+0x81, 8+($j/16), (7==($j%16))?0:8; michael@0: } michael@0: } michael@0: printf " /* 0x%2X%1X%1X*/\n", $i+0x81, 8+($j/16),(7==($j%16))?0:8; michael@0: } michael@0: } michael@0: sub printnpl() michael@0: { michael@0: $npl = < ../ucvcn/cp936map.h michael@0: If you have question, mailto:ftan\@netscape.com michael@0: */ michael@0: END_OF_DONT_MODIFY michael@0: print $dont_modify; michael@0: } michael@0: michael@0: &readtable(); michael@0: &printnpl(); michael@0: &printdontmodify(); michael@0: &printtable(); michael@0: