1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/uconv/tools/unihan2cns.pl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +#!/usr/local/bin/perl -w 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 +use IO::File; 1.10 +my(%tagtofilemap); 1.11 +$tagtofilemap{"kCNS1986-1" } = IO::File->new("|sort> cns1986p1.txt") 1.12 + or die "cannot open cns1986p1.txt"; 1.13 +$tagtofilemap{"kCNS1986-2" } = IO::File->new("|sort> cns1986p2.txt") 1.14 + or die "cannot open cns1986p2.txt"; 1.15 +$tagtofilemap{"kCNS1986-E" } = IO::File->new("|sort> cns1986p14.txt") 1.16 + or die "cannot open cns1986p14.txt"; 1.17 +$tagtofilemap{"kCNS1992-1" } = IO::File->new("|sort> cns1992p1.txt") 1.18 + or die "cannot open cns1992p1.txt"; 1.19 +$tagtofilemap{"kCNS1992-2" } = IO::File->new("|sort> cns1992p2.txt") 1.20 + or die "cannot open cns1992p2.txt"; 1.21 +$tagtofilemap{"kCNS1992-3" } = IO::File->new("|sort> cns1992p3.txt") 1.22 + or die "cannot open cns1992p3.txt"; 1.23 +$tagtofilemap{"kIRG_TSource-1" } = IO::File->new("|sort> cnsIRGTp1.txt") 1.24 + or die "cannot open cnsIRGTp1.txt"; 1.25 +$tagtofilemap{"kIRG_TSource-2" } = IO::File->new("|sort> cnsIRGTp2.txt") 1.26 + or die "cannot open cnsIRGTp2.txt"; 1.27 +$tagtofilemap{"kIRG_TSource-3" } = IO::File->new("|sort> cnsIRGTp3.txt") 1.28 + or die "cannot open cnsIRGTp3.txt"; 1.29 +$tagtofilemap{"kIRG_TSource-4" } = IO::File->new("|sort> cnsIRGTp4.txt") 1.30 + or die "cannot open cnsIRGTp4.txt"; 1.31 +$tagtofilemap{"kIRG_TSource-5" } = IO::File->new("|sort> cnsIRGTp5.txt") 1.32 + or die "cannot open cnsIRGTp5.txt"; 1.33 +$tagtofilemap{"kIRG_TSource-6" } = IO::File->new("|sort> cnsIRGTp6.txt") 1.34 + or die "cannot open cnsIRGTp6.txt"; 1.35 +$tagtofilemap{"kIRG_TSource-7" } = IO::File->new("|sort> cnsIRGTp7.txt") 1.36 + or die "cannot open cnsIRGTp7.txt"; 1.37 +$tagtofilemap{"kIRG_TSource-F" } = IO::File->new("|sort> cnsIRGTp15.txt") 1.38 + or die "cannot open cnsIRGTp15.txt"; 1.39 +$tagtofilemap{"kIRG_TSource-3ExtB" } = IO::File->new("|sort> cnsIRGTp3ExtB.txt") 1.40 + or die "cannot open cnsIRGTp3ExtB.txt"; 1.41 +$tagtofilemap{"kIRG_TSource-4ExtB" } = IO::File->new("|sort> cnsIRGTp4ExtB.txt") 1.42 + or die "cannot open cnsIRGTp4ExtB.txt"; 1.43 +$tagtofilemap{"kIRG_TSource-5ExtB" } = IO::File->new("|sort> cnsIRGTp5ExtB.txt") 1.44 + or die "cannot open cnsIRGTp5ExtB.txt"; 1.45 +$tagtofilemap{"kIRG_TSource-6ExtB" } = IO::File->new("|sort> cnsIRGTp6ExtB.txt") 1.46 + or die "cannot open cnsIRGTp6ExtB.txt"; 1.47 +$tagtofilemap{"kIRG_TSource-7ExtB" } = IO::File->new("|sort> cnsIRGTp7ExtB.txt") 1.48 + or die "cannot open cnsIRGTp7ExtB.txt"; 1.49 +$tagtofilemap{"kIRG_TSource-FExtB" } = IO::File->new("|sort> cnsIRGTp15ExtB.txt") 1.50 + or die "cannot open cnsIRGTp15ExtB.txt"; 1.51 + 1.52 +$nonhan = IO::File->new("< nonhan.txt") 1.53 + or die "cannot open nonhan.txt"; 1.54 + 1.55 +while(defined($line = $nonhan->getline())) 1.56 +{ 1.57 + $tagtofilemap{"kCNS1986-1"}->print($line); 1.58 + $tagtofilemap{"kCNS1992-1"}->print($line); 1.59 + $tagtofilemap{"kIRG_TSource-1"}->print($line); 1.60 +} 1.61 + 1.62 +while(<STDIN>) 1.63 +{ 1.64 + if(/^U/) 1.65 + { 1.66 + chop(); 1.67 + ($u,$tag,$value) = split(/\t/,$_); 1.68 + if($tag =~ m/(kCNS|kIRG_TSource)/) 1.69 + { 1.70 + ($pnum, $cvalue) = split(/-/,$value); 1.71 + $tagkey = $tag . "-" . $pnum; 1.72 + if(length($u) > 6) { 1.73 + $tagkey .= "ExtB"; 1.74 + } 1.75 + $fd = $tagtofilemap{$tagkey}; 1.76 + if(length($u) > 6) { 1.77 + $mapping = substr($u,3,4); # trunkcate 0x2 from 0x2abcd 1.78 + } else { 1.79 + $mapping = substr($u,2,4); # trunkcate 0x from 0xabcd 1.80 + } 1.81 + $fd->print("0x" . $cvalue . "\t0x" . $mapping . "\t# <CJK>\n"); 1.82 + } 1.83 + } 1.84 +} 1.85 +