| 1 | #!/bin/bash |
| 2 | export LANG=en_US |
| 3 | export LC_ALL=C |
| 4 | |
| 5 | case $# in |
| 6 | 0|1|2) echo "u8myspell - converts MySpell dictionaries to UTF-8 |
| 7 | usage: u8myspell source_name output_name source_charset"; exit 1;; |
| 8 | esac |
| 9 | |
| 10 | i=$1 |
| 11 | o=$2 |
| 12 | charset=$3 |
| 13 | localdir="$(dirname $0)" |
| 14 | |
| 15 | paste <(sed 's#[\t/].*##' $i.dic | iconv -f ${charset} -t UTF-8) <(sed 's#^[^\t/]*##' $i.dic) | |
| 16 | sed "s#`echo -e '\t'`/#/#" | sed -f "$localdir"/l1_u8.sed >$o.tmp |
| 17 | |
| 18 | paste <(sed 's# .*##' $o.tmp) <(sed 's#^[^ ]*##' $o.tmp | iconv -f ${charset} -t UTF-8) | |
| 19 | sed "s#`echo -e '\t'`/#/#;s/ / /" | sed -f "$localdir"/l1_u8.sed >$o.dic |
| 20 | |
| 21 | cat $i.aff | awk ' |
| 22 | /^SET/{ |
| 23 | print "SET UTF-8" >"u8.beg" |
| 24 | print "" >"u8.mid" |
| 25 | print "" >"u8.cont" |
| 26 | print "" >"u8.mid2" |
| 27 | print "" >"u8.morph" |
| 28 | print "" >"u8.end" |
| 29 | next |
| 30 | } |
| 31 | /^(TRY|COMPOUNDSYLLABLE|ACCENT|REP|MAP|CHECKCOMPOUND|KEY|BREAK)/{ |
| 32 | print $1 >"u8.beg" |
| 33 | print $2,$3,$4,$5,$6 >"u8.mid" |
| 34 | print "" >"u8.cont" |
| 35 | print "" >"u8.mid2" |
| 36 | print "" >"u8.morph" |
| 37 | print "" >"u8.end" |
| 38 | next |
| 39 | } |
| 40 | /^[SP]FX/&&(NF>4){print $1,$2 >"u8.beg"; |
| 41 | i=index($4,"/"); |
| 42 | if (!i) print $3,$4 >"u8.mid"; else print $3, substr($4, 1, i) >"u8.mid" |
| 43 | if (i) print substr($4, i) >"u8.cont"; else print "" >"u8.cont"; |
| 44 | print $5 >"u8.mid2"; |
| 45 | print $6 >"u8.morph"; next} |
| 46 | {print >"u8.beg"; |
| 47 | print"" >"u8.mid"; |
| 48 | print"" >"u8.cont"; |
| 49 | print"" >"u8.mid2"; |
| 50 | print"" >"u8.morph"; |
| 51 | print"" >"u8.end"}' |
| 52 | iconv -f ${charset} -t UTF-8 u8.mid >u8.mid3 |
| 53 | iconv -f ${charset} -t UTF-8 u8.mid2 >u8.mid4 |
| 54 | iconv -f ${charset} -t UTF-8 u8.morph >u8.morph2 |
| 55 | paste u8.{beg,mid3,cont,mid4,morph2,end} | sed 's#/ /#/#' | tr '\t' ' ' | |
| 56 | sed -f "$localdir"/l1_u8.sed >$o.aff |
| 57 | rm u8.{beg,mid,cont,mid2,morph,end,mid3,mid4,morph2} $o.tmp |