# ロボワード 岩波国語辞典 第六版変換スクリプト - rwiwakoku.pl
# Copyright (C) 2005 by tiramn
print "<html><head><title>岩波国語辞典 第六版</title></head><body><dl>\n";
while (<>) {
$line = $_;
# HTML特殊文字変換
$line =~ s/\&/\&amp\;/g;
$line =~ s/\</\&lt\;/g;
$line =~ s/\>/\&gt\;/g;
# デフォルトのタグ変換
$line =~ s/\xe1\x46\x30\x30/<half>/g; # 半角文字
$line =~ s/\xe1\x46\x30\x32//g; # <font ?> (捨てる)
$line =~ s/\xe1\x46\x38\x30/<full>/g; # 全角文字
$line =~ s/\xe0\x50\x36//g; # TAB (捨てる)
$line =~ s/\xe0\x54\x31//g; # SPACE (捨てる)
$line =~ s/\xe1\x41(\x6c|\x4c)//g; # </a> (捨てる)
$line =~ s/\xe1\x42\x30\x81\x5d\xe1\x42\x31//g; # <don't need>
$line =~ s/\xe1\x42\x30/<\/bold>/g; # </bold>
$line =~ s/\xe1\x42\x31/<bold>/g; # <bold>
$line =~ s/\xe1\x49\x30/<\/i>/g; # </i>
$line =~ s/\xe1\x49\x31/<i>/g; # <i>
$line =~ s/\xe1\x4c(\x31|\x32|\x33|\x34|\x35)//g; # RANK 1～5 (捨てる)
# $line =~ s/\xe1\x53\x30/<\/sup>/g; # </sup>
# $line =~ s/\xe1\x53\x31/<sup>/g; # <sup>
$line =~ s/\xe0\x50(\x45|\x47)//g; # E0 50 45/47 (捨てる)
$line =~ s/\xe0\x70(\x36|\x45|\x47)//g; # E0 70 36/45/47 (捨てる)
$line =~ s/\xe0\x74\x31//g; # E0 74 31 (捨てる)

# ロボワード特殊文字変換
$line =~ s/\x0c/\"/g; # ^L → 二重引用符

$line =~ s/\xe1\x5a\x34//g;
$line =~ s/\xe1\x7a//g;
$line =~ s/\xe1\x73\x30/\x81\x84/g; # E1 73 30 (>)
$line =~ s/\xe1\x73\x31/\x81\x83/g; # E1 74 31 (<)
$line =~ s/\xe1\x46\x30\x31\x30\x31\x22/\x3c\x2f\x52\x54\x3e/g; # (</RT>)
$line =~ s/\xe1\x46\x30\x31\x30\x31\x2e/\x3c\x52\x54\x3e/g; # (<RT>)
$line =~ s/\xe1\x46\x30\x31\x30\x31\x7c/\x3c\x42\x3e\[/g; # (<B>)
$line =~ s/\xe1\x46\x30\x31\x30\x31\x7d/\]\x3c\x2f\x42\x3e/g; # (</B>)
$line =~ s/\xe1\x46\x30\x31\x30\x31.{1}/\x09/g; # (don't need)
$line =~ s/[\x81\xa8]*\x23[\x81|\xe1]{1}\x45?[0-9|A-F|a-f]+/\[\x8e\x51\x8f\xc6\]/g; # ([reference])
$line =~ s/\xe1\x46\x30\x31\x30\x31(\$|\#|\%)//g; #(don't need)
$line =~ s/\xe1\x53\x31(.*?)\xe1\x53\x30//g; #(<sup> don't need)

if ($line =~ /^<bold><full>(.*?) *<\/bold><RT><full>(.*?)<\/RT><full> *(.*)$/) {
     $yomi = $1;
     $hyoki = $2;
     $other = $3;
     $hyoki =~ s/<RT>//g;
     print "<dt>$yomi【$hyoki】$other</dt>";
     print "<key type=\"\x95\x5c\x8b\x4c\">$hyoki</key>\n<dd>";}
elsif ($line =~ /^<bold><full>(.*?) *<\/bold>.*\x81\x79(.*?)\x81\x7a *(.*)$/) {
     $yomi = $1;
     $hyoki = $2;
     $other = $3;
     $hyoki =~ s/<RT>//g;
     print "<dt>$yomi【$hyoki】$other</dt>";
     print "<key type=\"\x95\x5c\x8b\x4c\">$hyoki</key>\n<dd>";}
elsif ($line =~ /^<bold><full>(.*?) *<\/bold> *(.*)$/) {
     $hyoki = $1;
     $other = $2;
     $hyoki =~ s/<RT>//g;
     $other =~ s/<RT>//g;
     print "<dt>$hyoki  $other</dt>\n<dd>";}
elsif ($line =~ /.+/){
     $line =~ s/<RT>/\(/g;
     $line =~ s/<\/RT>/\)/g;
     print "$line<br>";
}

}
print "</dl></body></html>\n";
