forked from baskerville/plato
-
Notifications
You must be signed in to change notification settings - Fork 2
/
convert-dictionary.sh
executable file
·27 lines (19 loc) · 868 Bytes
/
convert-dictionary.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#! /bin/sh
# Converts a StarDict dictionary to the dictd format.
# The first argument must be the path to the IFO file.
trap 'exit 1' ERR
base=${1%.*}
bindir=bin/utils
short_name=$(grep '^bookname=' "$1" | cut -d '=' -f 2)
url=$(grep '^website=' "$1" | cut -d '=' -f 2)
echo "Converting ${short_name} (${1})."
[ -e "${base}.dict.dz" ] && "$bindir"/dictzip -d "${base}.dict.dz"
args="${base}.dict"
[ -e "${base}.syn" ] && args="$args ${base}.syn"
# shellcheck disable=SC2086
"$bindir"/sdunpack $args < "${base}.idx" > "${base}.txt"
[ "${short_name%% *}" = "Wiktionary" ] && sed -i 's/^\(\\.*\)/<p>\1<\/p>/' "${base}.txt"
"$bindir"/dictfmt --quiet --utf8 --index-keep-orig --headword-separator '|' -s "$short_name" -u "$url" -t "$base" < "${base}.txt"
"$bindir"/dictzip "${base}.dict"
rm "$1" "${base}.idx" "${base}.txt"
[ -e "${base}.syn" ] && rm "${base}.syn"