#! /usr/bin/perl

## @file
##
## $Id: cedict2kvtml.pl,v 1.1 2005/05/18 12:34:52 marc Exp $
##
## $Date: 2005/05/18 12:34:52 $
## $Author: marc $
##
## @copy &copy; Marc W&auml;ckerlin
## @license LGPL, see file <a href="license.html">COPYING</a>
##
## This program reads an UTF-8 WADOKUJT file from
## http://www.mandarintools.com/cedict.html on STDIN and writes a
## KVTML XML file for use e.g. in Linux KDE KWordQuiz to STDOUT.
##
## $Log: cedict2kvtml.pl,v $
## Revision 1.1  2005/05/18 12:34:52  marc
## initial release
##
##
##       1         2         3         4         5         6         7         8
## 45678901234567890123456789012345678901234567890123456789012345678901234567890

print '<?xml version="1.0"?>
<!DOCTYPE kvtml SYSTEM "kvoctrain.dtd">
<kvtml
    encoding="UTF-8"
    generator="wadokujt2kvtml.pl"
    title="日本語"
    author="。。。">
  <lesson>
    <desc no="1">日本語</desc>
  </lesson>
';
while (<>) {
  s/&/&amp;/g;
  s/</&lt;/g;
  s/>/&gt;/g;
  if (/^\s*(\S+)\s+\[(\S*)\]\s+\/(.+)\/\s*$/) {
    my ($japanese, $spell, @german) =
      ($1, $2, split(/\//, $3));
    print '
  <e m="1" s="1">
    <o l="日本語" p="'.$spell.'">'.$japanese."\n".'['.$spell.']</o>
    <t l="Deutsch" p="'.$spell.'">'.join('; ', @german).'</t>
  </e>
    ';
  }
}
print '
</kvtml>
';
