From 8be8c6f4ca93bccbc7f2a036dea95d56a8c36e6e Mon Sep 17 00:00:00 2001 From: Koichi KAMICHI Date: Tue, 24 Jan 2006 12:42:18 +0000 Subject: [PATCH] Initial revision --- linkmap/map.cgi | 18 +++ linkmap/map.pl | 372 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 390 insertions(+) create mode 100755 linkmap/map.cgi create mode 100755 linkmap/map.pl diff --git a/linkmap/map.cgi b/linkmap/map.cgi new file mode 100755 index 0000000..03edaab --- /dev/null +++ b/linkmap/map.cgi @@ -0,0 +1,18 @@ +#!/usr/bin/perl + +$random = sprintf "%05X", int(rand()*0x100000); + +use CGI; +$cgi = new CGI; +$target = $cgi->param('code'); +$dummy = `/usr/bin/perl /home/kamichi/chiseperl/map.pl $target $random 2>/dev/null`; + +$buffer = ""; +open FH, "<$random.html"; +foreach(){ + $buffer .= $_; +} +close FH; + +print "Content-type: text/html\n\n"; +print $buffer; diff --git a/linkmap/map.pl b/linkmap/map.pl new file mode 100755 index 0000000..e9e63b1 --- /dev/null +++ b/linkmap/map.pl @@ -0,0 +1,372 @@ +#----------------------------------------------------------------------------- +use utf8; +binmode STDOUT, ":utf8"; +require 'chiseperl.pl'; +use Encode; + +$rate = 0.75; +$x = -10; +$y = 14; +%char = (); +%link = (); +%family = (); +%object = (); +@list= (); +#$file = "map"; +$file= @ARGV[1]; +$txt = "txt"; +$png = "png"; +$svg = "svg"; +#$graphviz = '"C:\Program Files\ATT\Graphviz\bin\dot.exe"'; +$graphviz = '/usr/local/bin/dot'; +$html = "html"; +$fontGB = "SimSun"; +$fontJP = "'MS 明朝'"; +$fontUCS = "'MS 明朝', SimSun, 'SimSun (Founder Extended)'"; +$fontBIG5 = "MingLiU"; +$fontKS = "BatangChe"; + +#----------------------------------------------------------------------------- +&init_chise; + +foreach(@chise_feature){ + if($_ !~ m/sources/){ + push(@list, $_); + } +} + +&process(eval('0x'.$ARGV[0])); + +#----------------------------------------------------------------------------- + +# create txt +open FH, ">:utf8", "$file.$txt"; +print FH "digraph g{\r\n"; +print FH "\trankdir = \"LR\";\r\n"; +$be_child = ",".join(",", values(%family)).","; +foreach(sort(keys %family)){ + if($be_child =~ m/,$_,/){ + next; + } + &ireko($_,1); +} +foreach(sort(keys %char)){ + printf FH "\t\"%X\" [ label = \"$char{$_}\", shape = \"record\" ];\r\n", $_; + #printf FH "\t\"%X\" [ label = \"$char{$_}\", shape = \"record\", fontname = \"simhei.ttf\" ];\r\n", $_; +} +foreach(sort(keys %link)){ + @temp = split(/-/, $_); + printf FH "\t\"%X\" -> \"%X\" [ label = \"$link{$_}\" ];\r\n", $temp[0], $temp[1]; +} +print FH "}\r\n"; +close FH; + +#create png +$dummy = `$graphviz -Tpng -o$file.$png $file.$txt`; + +#create svg +$dummy = `$graphviz -Tsvg -o$file.$svg $file.$txt`; + +#create html +open FH, "<:utf8", "$file.$svg"; +open FH2, ">:utf8", "$file.$html"; +print FH2 < + + + + + +EOT +foreach(){ + if(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=cns11643\&\#45\;([1-9])\:([0-9A-F]{4})/){ + $left = int($1 / $rate) + $x; + $top = int($2 / $rate) + $y; + print FH2 "
"; + print FH2 "\r\n"; + print FH2 "
"; + } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=jef\&\#45\;china3\:([0-9A-F]{4})/){ + $left = int($1 / $rate) + $x; + $top = int($2 / $rate) + $y; + $target = $3; + $target =~ tr/A-F/a-f/; + print FH2 "
"; + print FH2 "\r\n"; + print FH2 "
"; + #} elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=gb2312\:([0-9A-F]{4})/){ + # $left = int($1 / $rate) + $x; + # $top = int($2 / $rate) + $y; + # print FH2 "
"; + # $ku = int(eval('0x'.$3) / 0x100) - 0x20; + # $ten = sprintf "%02d", eval('0x'.$3) % 0x100 - 0x20; + # print FH2 "\r\n"; + # print FH2 "
"; + } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=gb2312\:([0-9A-F]{4})/){ + $left = int($1 / $rate) + $x; + $top = int($2 / $rate) + $y; + print FH2 "
"; + $char = $3; + $char =~ s/([0-9A-F]{2})/pack('H2', $1)/eg; + Encode::from_to($char, 'gb2312-raw', 'utf-8'); + utf8::decode($char); + print FH2 "$char\r\n"; + print FH2 "
"; + } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=jis\&\#45\;x0208\@19(78|83|90|97)\:([0-9A-F]{4})/){ + $left = int($1 / $rate) + $x; + $top = int($2 / $rate) + $y; + print FH2 "
"; + $ku = int(eval('0x'.$4) / 0x100) - 0x20; + $ten = sprintf "%02d", eval('0x'.$4) % 0x100 - 0x20; + print FH2 "\r\n"; + print FH2 "
"; + } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=jis\&\#45\;x0212\:([0-9A-F]{4})/){ + $left = int($1 / $rate) + $x; + $top = int($2 / $rate) + $y; + print FH2 "
"; + $ku = int(eval('0x'.$3) / 0x100) - 0x20; + $ten = sprintf "%02d", eval('0x'.$3) % 0x100 - 0x20; + print FH2 "\r\n"; + print FH2 "
"; + } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=zinbun\&\#45;oracle\:([0-9A-F]{1,4})/){ + $left = int($1 / $rate) + $x - 20; + $top = int($2 / $rate) + $y; + my $number = sprintf "%04d", eval('0x'.$3); + print FH2 ""; + print FH2 ""; + } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=ucs\:([0-9A-F]{4,6})/){ + $left = int($1 / $rate) + $x - 20; + $top = int($2 / $rate) + $y; + print FH2 "
"; + print FH2 "[".pack('U',eval('0x'.$3))."]\r\n"; + print FH2 "
"; + } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=big5\:([0-9A-F]{4,6})/){ + $left = int($1 / $rate) + $x; + $top = int($2 / $rate) + $y; + print FH2 "
"; + $char = $3; + $char =~ s/([0-9A-F]{2})/pack('H2', $1)/eg; + Encode::from_to($char, 'big5', 'utf-8'); + utf8::decode($char); + print FH2 "$char\r\n"; + print FH2 "
"; + #} elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=hanziku\&\#45\;([0-9]{1,2})\:([0-9A-F]{4})/){ + # $left = int($1 / $rate) + $x; + # $top = int($2 / $rate) + $y; + # #$number = sprintf "%02d", $3; + # $number = $3; + # $numberk = $3; + # $numberk =~ tr/12345678/一二三四五六七八/; + # #print FH2 "
"; + # print FH2 "
"; + # #printf FH2 pack('U', chise::chise_ds_decode_char($chise_ds, chise_tools::get_uchar("=hanziku-$number"), eval('0x'.$4))); + # #printf FH2 pack('U', chise::chise_ds_decode_char($chise_ds, chise_tools::get_uchar("=big5"), eval('0x'.$4))); + # $char = $4; + # $char =~ s/([0-9A-F]{2})/pack('H2', $1)/eg; + # Encode::from_to($char, 'big5', 'utf-8'); + # utf8::decode($char); + # print FH2 "$char\r\n"; + # print FH2 "
"; + } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=big5\&\#45\;cdp\:([0-9A-F]{4,6})/){ + $left = int($1 / $rate) + $x; + $top = int($2 / $rate) + $y; + print FH2 "
"; + printf FH2 pack('U', chise::chise_ds_decode_char($chise_ds, chise_tools::get_uchar('=big5-pua'), eval('0x'.$3))); + print FH2 "
"; + } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=jis\&\#45\;x0208\:([0-9A-F]{4,6})/){ + $left = int($1 / $rate) + $x; + $top = int($2 / $rate) + $y; + print FH2 "
"; + $char = $3; + $char =~ s/([0-9A-F]{2})/pack('H2', $1)/eg; + Encode::from_to($char, 'jis0208-raw', 'utf-8'); + utf8::decode($char); + print FH2 "$char\r\n"; + print FH2 "
"; + } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=ks\&\#45\;x1001\:([0-9A-F]{4,6})/){ + $left = int($1 / $rate) + $x; + $top = int($2 / $rate) + $y; + print FH2 "
"; + $char = $3; + $char =~ s/([0-9A-F]{2})/pack('H2', $1)/eg; + Encode::from_to($char, 'ksc5601-raw', 'utf-8'); + utf8::decode($char); + print FH2 "$char\r\n"; + print FH2 "
"; + } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=gt\&\#45\;pj\&\#45\;([0-9]{1,2}):([0-9A-F]{4})/){ + $left = int($1 / $rate) + $x; + $top = int($2 / $rate) + $y; + $number = sprintf("%02d", $3); + print FH2 "
"; + $char = $4; + $char =~ s/([0-9A-F]{2})/pack('H2', $1)/eg; + Encode::from_to($char, 'jis0208-raw', 'utf-8'); + utf8::decode($char); + print FH2 "$char\r\n"; + print FH2 "
"; + } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=gt\&\#45\;pj\&\#45\;(k[12]):([0-9A-F]{4})/){ + $left = int($1 / $rate) + $x; + $top = int($2 / $rate) + $y; + print FH2 "
"; + $char = $4; + $char =~ s/([0-9A-F]{2})/pack('H2', $1)/eg; + Encode::from_to($char, 'jis0208-raw', 'utf-8'); + utf8::decode($char); + print FH2 "$char\r\n"; + print FH2 "
"; + } +} + +print FH2 "\n"; +seek FH, 0, 0; +$i = 0; +foreach(){ + if($i == 1){ + m/points=\"[0-9]+,[0-9]+ ([0-9]+),([0-9]+) [0-9]+,[0-9]+ ([0-9]+),([0-9]+) /; + print FH2 "\n"; + $i = 0; + } + elsif(m/^(2{0,1}[0-9A-F]{4})<\/title>\n$/){ + $target = $1; + $i = 1; + } +} +print FH2 "</map>\n"; +close FH; + +print FH2 <<EOT; +</body> +</html> +EOT +close FH2; + +&close_chise; + +#----------------------------------------------------------------------------- +sub process{ + my ($buffer, @buffer, $feature); + if(exists($char{$_[0]})){ + return; + } + + #S-exporession + if($_[0] =~ m/^\(\(/){ + $char{$_[0]} .= "$_[0]\\n"; + next; + } + + #ccs-feature + foreach(@list){ + if((substr($_,0,1) eq '=' && substr($_,1,1) ne '>') || $_ eq "morohashi-daikanwa"){ + $buffer = get_feature_value($_, $_[0]); + if($buffer ne ""){ + if($_ eq "=daikanwa" || $_ eq "=gt" || $_ eq "=gt-k"){ + $char{$_[0]} .= sprintf("$_:%05d\\n", $buffer); + #} elsif($_ =~ m/^\=(gt-pj-[0-9]{1,2}|gt-pj-k[12]|big5|big5-cdp|jis-x0208|ks-x1001|ucs|cns11643-[1-9]|gb2312|jis-x0208\@1978|jis-x0208\@1983|jis-x0208\@1990|jis-x0208\@1997|jis-x0212|hanziku-[1-8]|jef-china3)$/){ + } elsif($_ =~ m/^\=(gt-pj-[0-9]{1,2}|gt-pj-k[12]|big5|big5-cdp|jis-x0208|ks-x1001|ucs|cns11643-[1-9]|gb2312|jis-x0208\@1978|jis-x0208\@1983|jis-x0208\@1990|jis-x0208\@1997|jis-x0212|jef-china3)$/){ + $char{$_[0]} .= sprintf("$_:%X\\n \\n \\n", $buffer); + } elsif($_ =~ m/^\=(zinbun-oracle)$/){ + $char{$_[0]} .= sprintf("$_:%X\\n \\n \\n \\n \\n", $buffer); + } elsif($_ eq "morohashi-daikanwa"){ + $char{$_[0]} .= "$_:$buffer\\n"; + } else { + $char{$_[0]} .= sprintf("$_:%X\\n", $buffer); + } + } + } + } + #goto-feature + foreach(@list){ + if(substr($_,0,2) eq '->'){ + $buffer = get_feature_value($_, $_[0]); + if($buffer ne ""){ + $feature = $_; + @buffer = &parse($buffer); + if(scalar(@buffer) == 0){ + next; + } + foreach(@buffer){ + if($feature eq "->subsumptive" || $feature eq "->denotational"){ + $family{$_[0]} .= "$_,"; + &process($_); + } else { + $feature =~ s/->//; + $link{$_[0]."-".$_} .= $feature."\\n"; + &process($_); + } + } + } + } + } + #comefrom-feature + foreach(@list){ + if(substr($_,0,2) eq '<-'){ + $buffer = get_feature_value($_, $_[0]); + if($buffer ne ""){ + $feature = $_; + @buffer = &parse($buffer); + if(scalar(@buffer) == 0){ + next; + } + foreach(@buffer){ + #$link{$_."-".$_[0]} .= $feature."\\n"; + &process($_); + } + } + } + } + #nearlyequal-feature + foreach(@list){ + if(substr($_,0,2) eq '=>'){ + $buffer = get_feature_value($_, $_[0]); + if($buffer ne ""){ + $feature = $_; + @buffer = &parse($buffer); + if(scalar(@buffer) == 0){ + next; + } + foreach(@buffer){ + $link{$_."-".$_[0]} .= $feature."\\n"; + &process($_); + } + } + } + } +} + +sub parse{ + my $target = $_[0]; + my (@temp, @temp2); + utf8::decode($target); + if(substr($target,0,1) eq '('){ + if(substr($target,0,2) eq '(('){ # feature is S-expression + push(@temp2, substr($target,1,length($substr)-1)); + } else { + @temp = split(/ /, substr($target, 1, length($target) - 2)); + foreach(@temp){ + push(@temp2, unpack('U*', substr($_, 1))); + } + } + return @temp2; + } else{ + } +} + +sub ireko{ + my @temp = split(/,/, $family{$_[0]}); + printf FH "\t"x$_[1]."subgraph cluster%X\ {\n", $_[0]; + if($_[1] == 1){ + printf FH "\t\t\"%X\" [ color = white ];\n", $_[0]; + } else { + printf FH "\t"x($_[1] + 1)."style = filled; color = gray%d;\n", 100 - ($_[1] - 1) * 20; + printf FH "\t"x($_[1] + 1)."\"%X\" [ color = gray%d ];\n", $_[0], 100 - ($_[1] - 1) * 20; + } + foreach(@temp){ + if(exists($family{$_})){ + &ireko($_, $_[1]+1); + } else{ + printf FH "\t"x($_[1] + 1)."\"%X\";\n", $_; + } + } + print FH "\t"x$_[1]."}\n"; +} +#----------------------------------------------------------------------------- -- 1.7.10.4