-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzhottp
executable file
·54 lines (51 loc) · 1.33 KB
/
zhottp
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
_ABOUT="Zhongwen Text to Phonetic"
_USAGE="Usage: zhottp [-h] CHARACTERS"
_DATAFILE="/usr/share/zhotools/zhottp.sqlite" #modified from tsi.src of libchewing
_MAXLENGTH=$(sqlite3 $_DATAFILE "SELECT mixlength FROM mixlength ;")
if test -z "$1" -o "$1" == "-h" ; then
echo "$_ABOUT"
echo "$_USAGE"
exit
else
_INPUT="$1"
fi
function _match {
_MAXLENGTH=$2
if test "$1" ; then
_BESTI=0
_BESTJ=0
_BESTNOTE=""
_MAXI=$((${#1}-1))
for i in `seq 0 $_MAXI` ; do
_MAXJ=$((${#1}-$i))
if test $_MAXJ -gt $_MAXLENGTH ; then _MAXJ=$_MAXLENGTH ; fi
_MINJ=$(($_BESTJ+1))
for j in `seq $_MAXJ -1 $_MINJ` ; do
_CHARS=${1:$i:$j}
_NOTE=$(sqlite3 $_DATAFILE "SELECT phonetic FROM txt2pho WHERE text = '$_CHARS';")
if test "$_NOTE" ; then
_BESTI=$i
_BESTJ=$j
_BESTNOTE="$_NOTE"
break
fi
done
if test $_BESTJ -eq $_MAXLENGTH ; then break ; fi
done
if test $_BESTJ -eq 0 ; then
echo -n "$1"
else
if test "${1:0:$_BESTI}" ; then
echo -n `_match "${1:0:$_BESTI}" $(($_BESTJ-1))`" "
fi
echo -n "$_BESTNOTE"
if test "${1:$_BESTI+$_BESTJ}" ; then
echo -n " "`_match "${1:$_BESTI+$_BESTJ}" $_BESTJ`
fi
fi
else
echo -n
fi
}
echo `_match "$_INPUT" $_MAXLENGTH`