#!/bin/bash
# verze 20101011
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
Help() {
echo "slovnik.cz CLI napsal David Watzke http://www.watzke.cz/"
${1:+echo "Chyba: $@"}
echo "Argumenty:"
echo -e "\t-f --from [cz|en|ge|fr|it|la|ru|sp] vstupni jazyk, vychozi cz"
echo -e "\t-t --to [cz|en|ge|fr|it|la|ru|sp] vystupni jazyk, vychozi cz"
echo -e "\t-r --results [5-50] pocet vysledku, vychozi 15"
echo -e "\t-T --timeout [sekundy] timeout pripojeni ke slovnik.cz"
echo "Poznamky:"
echo -e "\tBud vstupni nebo vystupni jazyk musi byt cestina (cz)."
echo -e "\tRetezec k prelozeni musi byt za prepinaci jako jeden argument."
echo -e "\tChyby hlaste na vyse uvedeny e-mail."
}
if [[ $# -eq 0 ]]
then
Help
exit 0
fi
for arg in "$@"
do
shift
case "$arg"
in -f|--from)
from=$1 ;;
-t|--to)
to=$1 ;;
-T|--timeout)
T=$1 ;;
-r|--results)
lines=$1 ;;
-*)
Help "Spatne argumenty!" >&2
exit 1 ;;
esac
done
from=${from:-cz}
to=${to:-cz}
if [[ "$from" == "$to" ]]
then
Help "Vstupni a vystupni jazyk nesmi byt stejny." >&2
exit 1
fi
phrase="$arg"
for lang in "$from" "$to"
do
case "$lang"
in en|ge|fr|it|la|ru|sp)
true ;;
cz)
if ${translatable:-false}
then
translatable=false
else
translatable=true
fi ;;
*)
Help "slovnik.cz nepodporuje jazyk: $lang." >&2
exit 1 ;;
esac
done
if ! ${translatable:-false}
then
Help "slovnik.cz nepodporuje preklad z $from do $to." >&2
exit 1
fi
if [[ "$from" == "cz" ]]
then
dictdir="$to$from"
else
dictdir="$from$to"
fi
dictdir="$dictdir.${from/cz/cz_d}"
URL="http://www.slovnik.cz/bin/mld.fpl?vcb=${phrase// /+}&dictdir=${dictdir}&lines=$lines"
wget ${T:+-T $T} -qO- "$URL" | sed -e '/pair/!d' -e 's/^ *//' -e 's/<[^>]*>//g'
if [[ "${PIPESTATUS[@]}" != "0 0" ]]
then
echo "Doslo k nejake chybe (vypadek pripojeni k siti? chybejici/nekompatibilni wget/sed?)" >&2
exit 1
fi
exit 0