3 # cut input text to given duration,
4 # or calculate total duration (if duration is missing or 0)
6 # args: speed/WpM, [duration/sec]
7 # stdin: standardized text
8 # stdout: duration/sec | cut text
10 # Morse character table, generated by chargen.sh
11 chartab
=`dirname $0`/chartab.txt
12 # speedbase: VVVVV=64, CODEX=60, PARIS=50
13 speedbase
=${SPEEDBASE:-50}
15 # calculate duration/ditunits of characters
16 # (one character per argument)
20 # loop through characters
23 # search character in chartab, remove first and third column
24 cd=`grep -F "_$1" $chartab`
27 # echo : $1 : cd=$cd >&2
28 # empty if not found, then set duration 0
30 # and add to word total
34 #echo : $1 : wd=$wd >&2
39 then echo "$0 : missing speed/WpM" >&2
43 # speed in dit units per minute
44 ditspeed
=`expr $speedbase '*' $1`
45 #echo : ditspeed $ditspeed
46 # set duration to 0 if empty, i.e calculate duration
49 # convert from seconds into ditunits
50 duration
=`expr $duration '*' $ditspeed / 60`
51 #echo : $duration ditunits
53 # separate words into lines, then characters by space, and remove empty lines
54 sed -e 's/[ _ ][ _ ]*/\
55 /g;s/\(.\)/ \1/g;/^[ _ ]*$/d' |
{
58 # calculate duration of word including inter-word pause (_)
59 do total
="$total + `wordduration $word _`"
60 # echo :: total = $total >&2
62 # duration>0, then echo input text until duration reached
63 if test $duration -gt 0
64 then if test $duration -lt $total
66 # again remove separating spaces from word
67 else echo "$word" |
sed -e 's/ //g'
72 # duration<=0, then report duration
73 if test $duration -le 0
74 # convert from ditunits back into seconds
75 then expr $total '*' 60 / $ditspeed