#!/bin/sh
#  Created: Sun Mar 21 18:11:17 CET 1999 by heinrich@zaphod.wh9.tu-dresden.de
# Copyright (C) 1999  Heinrich Langos 
# 
# ----------------------- BEGIN LEGAL STUFF ---------------------------
#
#This program is free software; you can redistribute it and/or modify it
#under the terms of the GNU Library General Public License as published
#by the Free Software Foundation; either version 2 of the License, or (at
#your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#Library General Public License for more details.
#
#You should have received a copy of the GNU Library General Public
#License along with this library; if not, write to the Free
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ----------------------- END LEGAL STUFF ---------------------------
#
# ok .. here is a short script that will transform the dictionary files
# from the Internet Dictionary Project (http://www.june29.com/IDP/)
# to dictd (http://www.dict.org/) readable format.
# 
# you need to get the dicts.zip file from 
# http://www.june29.com/IDP/files/dicts.zip
# copy it (and this little script) to an empty directory
# "unzip -L dicts.zip" (I hate UPCASE filenames)
# set the pathes to dictzip (part of the dictd package) and
# dictfmt (found e.g. in dict-misc-1.5.tar.gz) below
#
# BUGS: 
# the conversion doesnt handle the accent format of IDP yet and I'm very 
# lazy about correction such blemishes. 
# if you have a correction for it drop me a note and i will put it in.
# if you really need correct accents and can't do it yourself drop me a 
# mail and talk me into it :-)
#
#


dictfmt="../../dictfmt"
dictzip="../../dictzip"

all_targets=""
for x in *.txt ; do
  target=idp_`echo $x | cut -f1 -d.`
  all_targets=$all_targets" "$target
  echo '%h 00-database-info' > $target
  echo '%d' >> $target
  grep '^#' $x >> $target
  grep -v '^#' $x | awk 'BEGIN{FS="\t"}{print "%h "$1; print "%d" ; print "\t"$2"\n" }' >> $target
done

for x in $all_targets ; do
  $dictfmt -p -u http://www.june29.com/IDP/  -s "Internet Dictionary Project"  $x < $x
  $dictzip  $x'.dict'
done

