michael@0: #!/usr/bin/perl 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: michael@0: ###################################################################### michael@0: # michael@0: # Initial global variable michael@0: # michael@0: ###################################################################### michael@0: %utot = (); michael@0: $ui=0; michael@0: $li=0; michael@0: michael@0: ###################################################################### michael@0: # michael@0: # Open the unicode database file michael@0: # michael@0: ###################################################################### michael@0: open ( UNICODATA , "< ../../unicharutil/tools/UnicodeData-Latest.txt") michael@0: || die "cannot find UnicodeData-Latest.txt"; michael@0: michael@0: ###################################################################### michael@0: # michael@0: # Open the JIS X 4051 Class file michael@0: # michael@0: ###################################################################### michael@0: open ( CLASS , "< jisx4051class.txt") michael@0: || die "cannot find jisx4051class.txt"; michael@0: michael@0: ###################################################################### michael@0: # michael@0: # Open the JIS X 4051 Class simplified mapping michael@0: # michael@0: ###################################################################### michael@0: open ( SIMP , "< jisx4051simp.txt") michael@0: || die "cannot find jisx4051simp.txt"; michael@0: michael@0: ###################################################################### michael@0: # michael@0: # Open the output file michael@0: # michael@0: ###################################################################### michael@0: open ( OUT , "> anzx4051.html") michael@0: || die "cannot open output anzx4051.html file"; michael@0: michael@0: ###################################################################### michael@0: # michael@0: # Open the output file michael@0: # michael@0: ###################################################################### michael@0: open ( HEADER , "> ../src/jisx4051class.h") michael@0: || die "cannot open output ../src/jisx4051class.h file"; michael@0: michael@0: ###################################################################### michael@0: # michael@0: # Generate license and header michael@0: # michael@0: ###################################################################### michael@0: $hthmlheader = < michael@0: michael@0: michael@0: michael@0: michael@0: Analysis of JIS X 4051 to Unicode General Category Mapping michael@0: michael@0: michael@0: michael@0:

michael@0: Analysis of JIS X 4051 to Unicode General Category Mapping michael@0:

michael@0: END_OF_HTML michael@0: print OUT $hthmlheader; michael@0: michael@0: ###################################################################### michael@0: # michael@0: # Generate license and header michael@0: # michael@0: ###################################################################### michael@0: $npl = <) { michael@0: chop; michael@0: ###################################################################### michael@0: # michael@0: # Get value from fields michael@0: # michael@0: ###################################################################### michael@0: @f = split(/;/ , $_); michael@0: $c = $f[0]; # The unicode value michael@0: $g = $f[2]; michael@0: $d = substr($g, 0, 1); michael@0: michael@0: $gcat{$c} = $g; michael@0: $dcat{$c} = $d; michael@0: $gcount{$g}++; michael@0: $dcount{$d}++; michael@0: } michael@0: close(UNIDATA); michael@0: michael@0: while() { michael@0: chop; michael@0: ###################################################################### michael@0: # michael@0: # Get value from fields michael@0: # michael@0: ###################################################################### michael@0: @f = split(/;/ , $_); michael@0: michael@0: $simp{$f[0]} = $f[1]; michael@0: $sccount{$f[1]}++; michael@0: } michael@0: close(SIMP); michael@0: michael@0: sub GetClass{ michael@0: my ($u) = @_; michael@0: my $hex = DecToHex($u); michael@0: $g = $gcat{$hex}; michael@0: if($g ne "") { michael@0: return $g; michael@0: } elsif (( 0x3400 <= $u) && ( $u <= 0x9fa5 ) ) { michael@0: return "Han"; michael@0: } elsif (( 0xac00 <= $u) && ( $u <= 0xd7a3 ) ) { michael@0: return "Lo"; michael@0: } elsif (( 0xd800 <= $u) && ( $u <= 0xdb7f ) ) { michael@0: return "Cs"; michael@0: } elsif (( 0xdb80 <= $u) && ( $u <= 0xdbff ) ) { michael@0: return "Cs"; michael@0: } elsif (( 0xdc00 <= $u) && ( $u <= 0xdfff ) ) { michael@0: return "Cs"; michael@0: } elsif (( 0xe000 <= $u) && ( $u <= 0xf8ff ) ) { michael@0: return "Co"; michael@0: } else { michael@0: printf "WARNING !!!! Cannot find General Category for U+%s \n" , $hex; michael@0: } michael@0: } michael@0: sub GetDClass{ michael@0: my ($u) = @_; michael@0: my $hex = DecToHex($u); michael@0: $g = $dcat{$hex}; michael@0: if($g ne "") { michael@0: return $g; michael@0: } elsif (( 0x3400 <= $u) && ( $u <= 0x9fa5 ) ) { michael@0: return "Han"; michael@0: } elsif (( 0xac00 <= $u) && ( $u <= 0xd7a3 ) ) { michael@0: return "L"; michael@0: } elsif (( 0xd800 <= $u) && ( $u <= 0xdb7f ) ) { michael@0: return "C"; michael@0: } elsif (( 0xdb80 <= $u) && ( $u <= 0xdbff ) ) { michael@0: return "C"; michael@0: } elsif (( 0xdc00 <= $u) && ( $u <= 0xdfff ) ) { michael@0: return "C"; michael@0: } elsif (( 0xe000 <= $u) && ( $u <= 0xf8ff ) ) { michael@0: return "C"; michael@0: } else { michael@0: printf "WARNING !!!! Cannot find Detailed General Category for U+%s \n" , $hex; michael@0: } michael@0: } michael@0: sub DecToHex{ michael@0: my ($d) = @_; michael@0: return sprintf("%04X", $d); michael@0: } michael@0: %gtotal = (); michael@0: %dtotal = (); michael@0: while() { michael@0: chop; michael@0: ###################################################################### michael@0: # michael@0: # Get value from fields michael@0: # michael@0: ###################################################################### michael@0: @f = split(/;/ , $_); michael@0: michael@0: if( substr($f[2], 0, 1) ne "a") michael@0: { michael@0: $sc = $simp{$f[2]}; michael@0: $l = hex($f[0]); michael@0: if($f[1] eq "") michael@0: { michael@0: $h = $l; michael@0: } else { michael@0: $h = hex($f[1]); michael@0: } michael@0: for($k = $l; $k <= $h ; $k++) michael@0: { michael@0: if( exists($occ{$k})) michael@0: { michael@0: # printf "WARNING !! Conflict defination!!! U+%s -> [%s] [%s | %s]\n", michael@0: # DecToHex($k), $occ{$k} , $f[2] , $sc; michael@0: } michael@0: else michael@0: { michael@0: $occ{$k} = $sc . " | " . $f[2]; michael@0: $gclass = GetClass($k); michael@0: $dclass = GetDClass($k); michael@0: $gtotal{$sc . $gclass}++; michael@0: $dtotal{$sc . $dclass}++; michael@0: $u = DecToHex($k); michael@0: $rk = " " . substr($u,0,2) . ":" . $sc; michael@0: $rangecount{$rk}++; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: #print %gtotal; michael@0: #print %dtotal; michael@0: michael@0: sub printreport michael@0: { michael@0: print OUT "\n"; michael@0: print OUT "\n"; michael@0: } michael@0: michael@0: print OUT "\n"; michael@0: foreach $g (sort(keys %gcount)) { michael@0: print OUT "\n"; michael@0: } michael@0: print OUT "\n"; michael@0: foreach $sc (sort(keys %sccount)) { michael@0: michael@0: print OUT "\n"; michael@0: } michael@0: michael@0: print OUT "\n"; michael@0: michael@0: foreach $g (sort(keys %gcount)) { michael@0: $count = $gtotal{$sc . $g}; michael@0: print OUT "\n"; michael@0: } michael@0: michael@0: michael@0: print OUT "\n"; michael@0: } michael@0: print OUT "
\n"; michael@0: michael@0: foreach $d (sort(keys %dcount)) { michael@0: print OUT "$dTotal$g
$sc\n"; michael@0: michael@0: $total = 0; michael@0: foreach $d (sort (keys %dcount)) { michael@0: $count = $dtotal{$sc . $d}; michael@0: $total += $count; michael@0: print OUT "$count$total$count
\n"; michael@0: michael@0: michael@0: print OUT "\n"; michael@0: print OUT "\n"; michael@0: } michael@0: michael@0: print OUT "\n"; michael@0: michael@0: michael@0: for($rr = 0; $rr < 0x4f; $rr++) michael@0: { michael@0: $empty = 0; michael@0: $r = sprintf("%02X" , $rr) ; michael@0: $tmp = "\n", $count); michael@0: $empty += $count; michael@0: } michael@0: michael@0: $tmp .= "\n"; michael@0: michael@0: if($empty ne 0) michael@0: { michael@0: print OUT $tmp; michael@0: } michael@0: } michael@0: print OUT "
\n"; michael@0: michael@0: foreach $sc (sort(keys %sccount)) michael@0: { michael@0: print OUT "$sc
" . $r . "\n"; michael@0: michael@0: foreach $sc (sort(keys %sccount)) { michael@0: $count = $rangecount{ " " .$r . ":" .$sc}; michael@0: $tmp .= sprintf("%s
\n"; michael@0: michael@0: } michael@0: printreport(); michael@0: michael@0: sub printarray michael@0: { michael@0: my($r, $def) = @_; michael@0: printf "[%s || %s]\n", $r, $def; michael@0: $k = hex($r) * 256; michael@0: printf HEADER "static const uint32_t gLBClass%s[32] = {\n", $r; michael@0: for($i = 0 ; $i < 256; $i+= 8) michael@0: { michael@0: for($j = 7 ; $j >= 0; $j-- ) michael@0: { michael@0: $v = $k + $i + $j; michael@0: if( exists($occ{$v})) michael@0: { michael@0: $p = substr($occ{$v}, 1,1); michael@0: } else { michael@0: $p = $def; michael@0: } michael@0: michael@0: if($j eq 7 ) michael@0: { michael@0: printf HEADER "0x%s" , $p; michael@0: } else { michael@0: printf HEADER "%s", $p ; michael@0: } michael@0: } michael@0: printf HEADER ", // U+%04X - U+%04X\n", $k + $i ,( $k + $i + 7); michael@0: } michael@0: print HEADER "};\n\n"; michael@0: } michael@0: printarray("00", "7"); michael@0: printarray("20", "7"); michael@0: printarray("21", "7"); michael@0: printarray("30", "5"); michael@0: printarray("0E", "8"); michael@0: printarray("17", "7"); michael@0: michael@0: #print %rangecount; michael@0: michael@0: ###################################################################### michael@0: # michael@0: # Close files michael@0: # michael@0: ###################################################################### michael@0: close(HEADER); michael@0: close(CLASS); michael@0: close(OUT); michael@0: