#!/bin/sh if [ $1 ] && [ -f $1 ] && [ $2 ]; then slovn2dict_words=`mktemp` slovn2dict_descr=`mktemp` raw_file=`mktemp` slovn2dict_head=`mktemp` cat $1 |\ awk 'BEGIN{x=0;c=""} \ {z=split($0, a, /->/); \ if (z == 2) \ {++x; sub(/^ */,"",a[1]); if (a[1] != c) {print x " " a[1]}; c = a[1]}\ }\ '|iconv -f cp1251 -t utf-8>$slovn2dict_words cat $1 |\ awk 'BEGIN{x=0;c="";ORS="";} \ {z=split($0, a, /->/); \ if (z == 2) \ {++x; sub(/^ */,"",a[1]); sub(/^ */,"",a[2]); sub(/\r/,"",a[2]);\ if (a[1] != c ) {print "\n" x " "}; \ if (a[1] == c ) {print ", "}; \ print a[2]; c = a[1]}\ }\ '>$slovn2dict_descr words=`cat $slovn2dict_words|wc -l|awk '{print $1}'` descr=`cat $slovn2dict_descr|wc -l|awk '{print $1}'` if [ $words != $descr ]; then echo "Sorry, but number of words is $words, and number of descr is $descr. It's is a error" elif [ $words == 0 ]; then echo "Sorry, but number of words is 0. May be you provide incorrect slovnyk* file" else echo Number of words is $words join $slovn2dict_words $slovn2dict_descr |awk '{sub(/^[0123456789]+ /,"",$0); z=split($0,a,/ /); print a[1] "\n" a[2]}'>$raw_file LANGUAGE=ru_RU.CP1251 LC_CTYPE=ru_RU.CP1251 oxford2dic $raw_file size=`stat -c %s oxford.idxdata` cat << EOF > $2.ifo StarDict's dict ifo file version=2.4.2 wordcount=$words idxfilesize=$size bookname=$2 sametypesequence=m EOF cp oxford.idxdata $2.idx cp oxford.dict $2.dict rm -f $slovn2dict_words rm -f $slovn2dict_descr rm -f $raw_file rm -f oxford.idxdata rm -f oxford.dict echo "$2 dictionary succesfully created ($words - wordcount)" fi elif [ $1 ] && [ ! -f $1 ]; then echo "Error: Please specify valid inputfile" echo elif [ $1 ] && [ -f $1 ] && [ ! $2 ]; then echo "Error: Please specify outputfile" echo else echo "Using: slovnyk2stardict.sh inputfile outputfile" echo "where inputfile is dictionary in slovnyk format (cp1251 only)" echo " outputfile is name of stardict dictionary." echo echo "slovnyk dictionaries available here " echo " http://www.slovnyk.org/prg/gszotar/index.html (project page)" echo " http://www.slovnyk.org.ua/prg/gszotar/win1251/ (download page)" fi