-
Notifications
You must be signed in to change notification settings - Fork 0
/
findstresses
executable file
·36 lines (27 loc) · 931 Bytes
/
findstresses
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
#!/bin/bash
# Front end for word2stresses and stress2words. Guesses which is wanted.
# If the argument has periods and dashes, then use stress2words.
# If the argument is completely alphabetical, then use word2stresses.
usage() {
cat <<EOF
findstresses zeppelin
findstresses .-.
findstresses a.-
findstresses -f -.-.-
EOF
}
if [[ $# -eq 0 ]]; then usage; exit; fi
bindir=$(dirname "$0")
# Only look at last argument to skip over possible flags, like "-f"
while [[ $# -gt 1 ]]; do args+=($1); shift; done
args+=($1)
if [[ "$1" =~ ^([[:alpha:]]?[-\.~=_])+$ ]]; then
# Optional letter followed by syllable markers
$bindir/stress2words "${args[@]}"
elif [[ $1 =~ ^[[:alpha:]]+$ ]]; then
# Purely alphabetic
$bindir/word2stresses "${args[@]}"
else
# Neither. Probably something like Don't, X-ray, Messr., Zig-Zag, Wi-Fi, Son-in-Law, U.S.A.
$bindir/word2stresses "${args[@]}"
fi