Initial revision
authorKoichi KAMICHI <kamichi@fonts.jp>
Tue, 24 Jan 2006 12:42:18 +0000 (12:42 +0000)
committerKoichi KAMICHI <kamichi@fonts.jp>
Tue, 24 Jan 2006 12:42:18 +0000 (12:42 +0000)
linkmap/map.cgi [new file with mode: 0755]
linkmap/map.pl [new file with mode: 0755]

diff --git a/linkmap/map.cgi b/linkmap/map.cgi
new file mode 100755 (executable)
index 0000000..03edaab
--- /dev/null
@@ -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(<FH>){
+  $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 (executable)
index 0000000..e9e63b1
--- /dev/null
@@ -0,0 +1,372 @@
+#-----------------------------------------------------------------------------\r
+use utf8;\r
+binmode STDOUT, ":utf8";\r
+require 'chiseperl.pl';\r
+use Encode;\r
+\r
+$rate = 0.75;\r
+$x = -10;\r
+$y = 14;\r
+%char = ();\r
+%link = ();\r
+%family = ();\r
+%object = ();\r
+@list= ();\r
+#$file = "map";\r
+$file= @ARGV[1];\r
+$txt = "txt";\r
+$png = "png";\r
+$svg = "svg";\r
+#$graphviz = '"C:\Program Files\ATT\Graphviz\bin\dot.exe"';\r
+$graphviz = '/usr/local/bin/dot';\r
+$html = "html";\r
+$fontGB = "SimSun";\r
+$fontJP = "'MS 明朝'";\r
+$fontUCS = "'MS 明朝', SimSun, 'SimSun (Founder Extended)'";\r
+$fontBIG5 = "MingLiU";\r
+$fontKS = "BatangChe";\r
+\r
+#-----------------------------------------------------------------------------\r
+&init_chise;\r
+\r
+foreach(@chise_feature){\r
+  if($_ !~ m/sources/){\r
+    push(@list, $_);\r
+  }\r
+}\r
+\r
+&process(eval('0x'.$ARGV[0]));\r
+\r
+#-----------------------------------------------------------------------------\r
+\r
+# create txt\r
+open FH, ">:utf8", "$file.$txt";\r
+print FH "digraph g{\r\n";\r
+print FH "\trankdir = \"LR\";\r\n";\r
+$be_child = ",".join(",", values(%family)).",";\r
+foreach(sort(keys %family)){\r
+  if($be_child =~ m/,$_,/){\r
+    next;\r
+  }\r
+  &ireko($_,1);\r
+}\r
+foreach(sort(keys %char)){\r
+  printf FH "\t\"%X\" [ label = \"$char{$_}\", shape = \"record\" ];\r\n", $_;\r
+  #printf FH "\t\"%X\" [ label = \"$char{$_}\", shape = \"record\", fontname = \"simhei.ttf\" ];\r\n", $_;\r
+}\r
+foreach(sort(keys %link)){\r
+  @temp = split(/-/, $_);\r
+  printf FH "\t\"%X\" -> \"%X\" [ label = \"$link{$_}\" ];\r\n", $temp[0], $temp[1];\r
+}\r
+print FH "}\r\n";\r
+close FH;\r
+\r
+#create png\r
+$dummy = `$graphviz -Tpng -o$file.$png $file.$txt`;\r
+\r
+#create svg\r
+$dummy = `$graphviz -Tsvg -o$file.$svg $file.$txt`;\r
+\r
+#create html\r
+open FH, "<:utf8", "$file.$svg";\r
+open FH2, ">:utf8", "$file.$html";\r
+print FH2 <<EOT;\r
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">\r
+<head>\r
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\r
+</head>\r
+<body>\r
+<img src="$file.$png" usemap="#object" border="0">\r
+EOT\r
+foreach(<FH>){\r
+  if(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=cns11643\&\#45\;([1-9])\:([0-9A-F]{4})/){\r
+    $left = int($1 / $rate) + $x;\r
+    $top = int($2 / $rate) + $y;\r
+    print FH2 "<div style=\"position: absolute; top: $top; left: $left;\">";\r
+    print FH2 "<img src=\"http://mousai.kanji.zinbun.kyoto-u.ac.jp/glyphs/CNS$3/$4.gif\">\r\n";\r
+    print FH2 "</div>";\r
+  } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=jef\&\#45\;china3\:([0-9A-F]{4})/){\r
+    $left = int($1 / $rate) + $x;\r
+    $top = int($2 / $rate) + $y;\r
+    $target = $3;\r
+    $target =~ tr/A-F/a-f/;\r
+    print FH2 "<div style=\"position: absolute; top: $top; left: $left;\">";\r
+    print FH2 "<img src=\"http://kanji.zinbun.kyoto-u.ac.jp/db/CHINA3/Gaiji/$target.gif\" width=\"40\" height=\"40\">\r\n";\r
+    print FH2 "</div>";\r
+  #} elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=gb2312\:([0-9A-F]{4})/){\r
+  #  $left = int($1 / $rate) + $x;\r
+  #  $top = int($2 / $rate) + $y;\r
+  #  print FH2 "<div style=\"position: absolute; top: $top; left: $left;\">";\r
+  #  $ku = int(eval('0x'.$3) / 0x100) - 0x20;\r
+  #  $ten = sprintf "%02d", eval('0x'.$3) % 0x100 - 0x20;\r
+  #  print FH2 "<img src=\"http://mousai.kanji.zinbun.kyoto-u.ac.jp/glyphs/GB0/$ku-$ten.gif\">\r\n";\r
+  #  print FH2 "</div>";\r
+  } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=gb2312\:([0-9A-F]{4})/){\r
+    $left = int($1 / $rate) + $x;\r
+    $top = int($2 / $rate) + $y;\r
+    print FH2 "<div style=\"position: absolute; top: $top; left: $left; font-family: $fontGB; font-size: 40px;\">";\r
+    $char = $3;\r
+    $char =~ s/([0-9A-F]{2})/pack('H2', $1)/eg;\r
+    Encode::from_to($char, 'gb2312-raw', 'utf-8');\r
+    utf8::decode($char);\r
+    print FH2 "$char\r\n";\r
+    print FH2 "</div>";\r
+  } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=jis\&\#45\;x0208\@19(78|83|90|97)\:([0-9A-F]{4})/){\r
+    $left = int($1 / $rate) + $x;\r
+    $top = int($2 / $rate) + $y;\r
+    print FH2 "<div style=\"position: absolute; top: $top; left: $left;\">";\r
+    $ku = int(eval('0x'.$4) / 0x100) - 0x20;\r
+    $ten = sprintf "%02d", eval('0x'.$4) % 0x100 - 0x20;\r
+    print FH2 "<img src=\"http://mousai.kanji.zinbun.kyoto-u.ac.jp/glyphs/JIS-$3/$ku-$ten.gif\">\r\n";\r
+    print FH2 "</div>";\r
+  } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=jis\&\#45\;x0212\:([0-9A-F]{4})/){\r
+    $left = int($1 / $rate) + $x;\r
+    $top = int($2 / $rate) + $y;\r
+    print FH2 "<div style=\"position: absolute; top: $top; left: $left;\">";\r
+    $ku = int(eval('0x'.$3) / 0x100) - 0x20;\r
+    $ten = sprintf "%02d", eval('0x'.$3) % 0x100 - 0x20;\r
+    print FH2 "<img src=\"http://mousai.kanji.zinbun.kyoto-u.ac.jp/glyphs/JIS-SP/$ku-$ten.gif\">\r\n";\r
+    print FH2 "</div>";\r
+  } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=zinbun\&\#45;oracle\:([0-9A-F]{1,4})/){\r
+    $left = int($1 / $rate) + $x - 20;\r
+    $top = int($2 / $rate) + $y;\r
+    my $number = sprintf "%04d", eval('0x'.$3);\r
+    print FH2 "<img style=\"position: absolute; top: $top; left: $left;\" src=\"http://mousai.kanji.zinbun.kyoto-u.ac.jp/glyphs/ZOB-1968/$number.png\" width=\"80\" height=\"80\">";\r
+    print FH2 "</div>";\r
+  } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=ucs\:([0-9A-F]{4,6})/){\r
+    $left = int($1 / $rate) + $x - 20;\r
+    $top = int($2 / $rate) + $y;\r
+    print FH2 "<div style=\"position: absolute; top: $top; left: $left; font-family: $fontUCS; font-size: 40px;\">";\r
+    print FH2 "[".pack('U',eval('0x'.$3))."]\r\n";\r
+    print FH2 "</div>";\r
+  } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=big5\:([0-9A-F]{4,6})/){\r
+    $left = int($1 / $rate) + $x;\r
+    $top = int($2 / $rate) + $y;\r
+    print FH2 "<div style=\"position: absolute; top: $top; left: $left; font-family: $fontBIG5; font-size: 40px;\">";\r
+    $char = $3;\r
+    $char =~ s/([0-9A-F]{2})/pack('H2', $1)/eg;\r
+    Encode::from_to($char, 'big5', 'utf-8');\r
+    utf8::decode($char);\r
+    print FH2 "$char\r\n";\r
+    print FH2 "</div>";\r
+  #} elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=hanziku\&\#45\;([0-9]{1,2})\:([0-9A-F]{4})/){\r
+  #  $left = int($1 / $rate) + $x;\r
+  #  $top = int($2 / $rate) + $y;\r
+  #  #$number = sprintf "%02d", $3;\r
+  #  $number = $3;\r
+  #  $numberk = $3;\r
+  #  $numberk =~ tr/12345678/一二三四五六七八/;\r
+  #  #print FH2 "<div style=\"position: absolute; top: $top; left: $left; font-family: 'hzk${number}u'; font-size: 40px;\">";\r
+  #  print FH2 "<div style=\"position: absolute; top: $top; left: $left; font-family: '細明體外字集$numberk'; font-size: 40px;\">";\r
+  #  #printf FH2 pack('U', chise::chise_ds_decode_char($chise_ds, chise_tools::get_uchar("=hanziku-$number"), eval('0x'.$4)));\r
+  #  #printf FH2 pack('U', chise::chise_ds_decode_char($chise_ds, chise_tools::get_uchar("=big5"), eval('0x'.$4)));\r
+  #  $char = $4;\r
+  #  $char =~ s/([0-9A-F]{2})/pack('H2', $1)/eg;\r
+  #  Encode::from_to($char, 'big5', 'utf-8');\r
+  #  utf8::decode($char);\r
+  #  print FH2 "$char\r\n";\r
+  #  print FH2 "</div>";\r
+  } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=big5\&\#45\;cdp\:([0-9A-F]{4,6})/){\r
+    $left = int($1 / $rate) + $x;\r
+    $top = int($2 / $rate) + $y;\r
+    print FH2 "<div style=\"position: absolute; top: $top; left: $left; font-family: EUDC; font-size: 40px;\">";\r
+    printf FH2 pack('U', chise::chise_ds_decode_char($chise_ds, chise_tools::get_uchar('=big5-pua'), eval('0x'.$3)));\r
+    print FH2 "</div>";\r
+  } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=jis\&\#45\;x0208\:([0-9A-F]{4,6})/){\r
+    $left = int($1 / $rate) + $x;\r
+    $top = int($2 / $rate) + $y;\r
+    print FH2 "<div style=\"position: absolute; top: $top; left: $left; font-family: $fontJP; font-size: 40px;\">";\r
+    $char = $3;\r
+    $char =~ s/([0-9A-F]{2})/pack('H2', $1)/eg;\r
+    Encode::from_to($char, 'jis0208-raw', 'utf-8');\r
+    utf8::decode($char);\r
+    print FH2 "$char\r\n";\r
+    print FH2 "</div>";\r
+  } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=ks\&\#45\;x1001\:([0-9A-F]{4,6})/){\r
+    $left = int($1 / $rate) + $x;\r
+    $top = int($2 / $rate) + $y;\r
+    print FH2 "<div style=\"position: absolute; top: $top; left: $left; font-family: $fontKS; font-size: 40px;\">";\r
+    $char = $3;\r
+    $char =~ s/([0-9A-F]{2})/pack('H2', $1)/eg;\r
+    Encode::from_to($char, 'ksc5601-raw', 'utf-8');\r
+    utf8::decode($char);\r
+    print FH2 "$char\r\n";\r
+    print FH2 "</div>";\r
+  } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=gt\&\#45\;pj\&\#45\;([0-9]{1,2}):([0-9A-F]{4})/){\r
+    $left = int($1 / $rate) + $x;\r
+    $top = int($2 / $rate) + $y;\r
+    $number = sprintf("%02d", $3);\r
+    print FH2 "<div style=\"position: absolute; top: $top; left: $left; font-family: GT2000-$number; font-size: 40px;\">";\r
+    $char = $4;\r
+    $char =~ s/([0-9A-F]{2})/pack('H2', $1)/eg;\r
+    Encode::from_to($char, 'jis0208-raw', 'utf-8');\r
+    utf8::decode($char);\r
+    print FH2 "$char\r\n";\r
+    print FH2 "</div>";\r
+  } elsif(m/x\=\"([0-9]+)\" y\=\"([0-9]+)\"\>\=gt\&\#45\;pj\&\#45\;(k[12]):([0-9A-F]{4})/){\r
+    $left = int($1 / $rate) + $x;\r
+    $top = int($2 / $rate) + $y;\r
+    print FH2 "<div style=\"position: absolute; top: $top; left: $left; font-family: GT2000-$3; font-size: 40px;\">";\r
+    $char = $4;\r
+    $char =~ s/([0-9A-F]{2})/pack('H2', $1)/eg;\r
+    Encode::from_to($char, 'jis0208-raw', 'utf-8');\r
+    utf8::decode($char);\r
+    print FH2 "$char\r\n";\r
+    print FH2 "</div>";\r
+  }\r
+}\r
+\r
+print FH2 "<map name=\"object\">\n";\r
+seek FH, 0, 0;\r
+$i = 0;\r
+foreach(<FH>){\r
+  if($i == 1){\r
+    m/points=\"[0-9]+,[0-9]+ ([0-9]+),([0-9]+) [0-9]+,[0-9]+ ([0-9]+),([0-9]+) /;\r
+    print FH2 "<area href=\"http://mousai.kanji.zinbun.kyoto-u.ac.jp/char-desc?char=%26u-$target%3B\" shape=\"rect\" coords=\"".int($3 / $rate).", ".int($4 / $rate).", ".int($1 / $rate).", ".int($2 / $rate)."\">\n";\r
+    $i = 0;\r
+  }\r
+  elsif(m/^<g id=\"node[0-9]+\" class=\"node\"><title>(2{0,1}[0-9A-F]{4})<\/title>\n$/){\r
+    $target = $1;\r
+    $i = 1;\r
+  }\r
+}\r
+print FH2 "</map>\n";\r
+close FH;\r
+\r
+print FH2 <<EOT;\r
+</body>\r
+</html>\r
+EOT\r
+close FH2;\r
+\r
+&close_chise;\r
+\r
+#-----------------------------------------------------------------------------\r
+sub process{\r
+  my ($buffer, @buffer, $feature);\r
+  if(exists($char{$_[0]})){\r
+    return;\r
+  }\r
+  \r
+  #S-exporession\r
+  if($_[0] =~ m/^\(\(/){\r
+    $char{$_[0]} .= "$_[0]\\n";\r
+    next;\r
+  }\r
+  \r
+  #ccs-feature\r
+  foreach(@list){\r
+    if((substr($_,0,1) eq '=' && substr($_,1,1) ne '>') || $_ eq "morohashi-daikanwa"){\r
+      $buffer = get_feature_value($_, $_[0]);\r
+      if($buffer ne ""){\r
+        if($_ eq "=daikanwa" || $_ eq "=gt" || $_ eq "=gt-k"){\r
+          $char{$_[0]} .= sprintf("$_:%05d\\n", $buffer);\r
+        #} 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)$/){\r
+        } 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)$/){\r
+          $char{$_[0]} .= sprintf("$_:%X\\n \\n \\n", $buffer);\r
+        } elsif($_ =~ m/^\=(zinbun-oracle)$/){\r
+          $char{$_[0]} .= sprintf("$_:%X\\n \\n \\n \\n \\n", $buffer);\r
+        } elsif($_ eq "morohashi-daikanwa"){\r
+          $char{$_[0]} .= "$_:$buffer\\n";\r
+        } else {\r
+          $char{$_[0]} .= sprintf("$_:%X\\n", $buffer);\r
+        }\r
+      }\r
+    }\r
+  }\r
+  #goto-feature\r
+  foreach(@list){\r
+    if(substr($_,0,2) eq '->'){\r
+      $buffer = get_feature_value($_, $_[0]);\r
+      if($buffer ne ""){\r
+        $feature = $_;\r
+        @buffer = &parse($buffer);\r
+        if(scalar(@buffer) == 0){\r
+          next;\r
+        }\r
+        foreach(@buffer){\r
+          if($feature eq "->subsumptive" || $feature eq "->denotational"){\r
+            $family{$_[0]} .= "$_,";\r
+            &process($_);\r
+          } else {\r
+            $feature =~ s/->//;\r
+            $link{$_[0]."-".$_} .= $feature."\\n";\r
+            &process($_);\r
+          }\r
+        }\r
+      }\r
+    }\r
+  }\r
+  #comefrom-feature\r
+  foreach(@list){\r
+    if(substr($_,0,2) eq '<-'){\r
+      $buffer = get_feature_value($_, $_[0]);\r
+      if($buffer ne ""){\r
+        $feature = $_;\r
+        @buffer = &parse($buffer);\r
+        if(scalar(@buffer) == 0){\r
+          next;\r
+        }\r
+        foreach(@buffer){\r
+          #$link{$_."-".$_[0]} .= $feature."\\n";\r
+          &process($_);\r
+        }\r
+      }\r
+    }\r
+  }\r
+  #nearlyequal-feature\r
+  foreach(@list){\r
+    if(substr($_,0,2) eq '=>'){\r
+      $buffer = get_feature_value($_, $_[0]);\r
+      if($buffer ne ""){\r
+        $feature = $_;\r
+        @buffer = &parse($buffer);\r
+        if(scalar(@buffer) == 0){\r
+          next;\r
+        }\r
+        foreach(@buffer){\r
+          $link{$_."-".$_[0]} .= $feature."\\n";\r
+          &process($_);\r
+        }\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+sub parse{\r
+  my $target = $_[0];\r
+  my (@temp, @temp2);\r
+  utf8::decode($target);\r
+  if(substr($target,0,1) eq '('){\r
+    if(substr($target,0,2) eq '(('){ # feature is S-expression\r
+      push(@temp2, substr($target,1,length($substr)-1));\r
+    } else {\r
+      @temp = split(/ /, substr($target, 1, length($target) - 2));\r
+      foreach(@temp){\r
+        push(@temp2, unpack('U*', substr($_, 1)));\r
+      }\r
+    }\r
+    return @temp2;\r
+  } else{\r
+  }\r
+}\r
+\r
+sub ireko{\r
+  my @temp = split(/,/, $family{$_[0]});\r
+  printf FH "\t"x$_[1]."subgraph cluster%X\ {\n", $_[0];\r
+  if($_[1] == 1){\r
+    printf FH "\t\t\"%X\" [ color = white ];\n", $_[0];\r
+  } else { \r
+    printf FH "\t"x($_[1] + 1)."style = filled; color = gray%d;\n", 100 - ($_[1] - 1) * 20;\r
+    printf FH "\t"x($_[1] + 1)."\"%X\" [ color = gray%d ];\n", $_[0], 100 - ($_[1] - 1) * 20;\r
+  }\r
+  foreach(@temp){\r
+    if(exists($family{$_})){\r
+      &ireko($_, $_[1]+1);\r
+    } else{\r
+      printf FH "\t"x($_[1] + 1)."\"%X\";\n", $_;\r
+    }\r
+  }\r
+  print FH "\t"x$_[1]."}\n";\r
+}\r
+#-----------------------------------------------------------------------------\r