securisation globale des fonction et ajout de l'option arret immediat a la fonction shutup

This commit is contained in:
jhechavarria
2018-08-23 05:38:21 +02:00
parent a4a810634f
commit f91955b88d

32
say.sh
View File

@@ -16,11 +16,18 @@ P2WLNGSNAME=( 'English (British)' 'English (US)' 'French' 'German' 'Italian' 'Sp
## Checks if language is supported by synthesiser ## Checks if language is supported by synthesiser
saysupport() saysupport()
{ {
re='^[a-z]{2}\-[A-Z]{2}$';
if [ $# -eq 1 ]; then
if ! [[ $1 =~ $re ]]; then
return 0
fi
for i in "${P2WLNGS[@]}"; do for i in "${P2WLNGS[@]}"; do
if [[ "$i" = "$1" ]]; then if [[ "$i" = "$1" ]]; then
return 1; return 1;
fi fi
done done
fi
return 0; return 0;
} }
@@ -36,17 +43,23 @@ saycfg ()
fi fi
fi fi
if [ $# -ge 2 ]; then if [ $# -ge 2 ]; then
re='^[0-2](\.[0-9])?$'
if [[ $2 =~ $re ]]; then
num=`echo "0 + $2" | bc`; num=`echo "0 + $2" | bc`;
if [ `echo "$num >= 0 && $num <= 2" | bc` -eq 1 ]; then if [ `echo "$num >= 0 && $num <= 2" | bc` -eq 1 ]; then
cfg[1]="$num"; cfg[1]="$num";
fi fi
fi fi
fi
if [ $# -ge 3 ]; then if [ $# -ge 3 ]; then
re='^[0-2](\.[0-9])?$'
if [[ $2 =~ $re ]]; then
num=`echo "0 + $3" | bc`; num=`echo "0 + $3" | bc`;
if [ `echo "$num >= 0.5 && $num <= 1.5" | bc` -eq 1 ]; then if [ `echo "$num >= 0.5 && $num <= 1.5" | bc` -eq 1 ]; then
cfg[2]="$num"; cfg[2]="$num";
fi fi
fi fi
fi
if [ $# -ge 1 ]; then if [ $# -ge 1 ]; then
echo "${cfg[*]}" > $CFGPATH; echo "${cfg[*]}" > $CFGPATH;
fi fi
@@ -74,12 +87,15 @@ saylng ()
sayvol() sayvol()
{ {
cfg=( `cat $CFGPATH` ) cfg=( `cat $CFGPATH` )
if [ $# -ge 1 ]; then if [ $# -eq 1 ]; then
re='^[0-2](\.[0-9])?$'
if [[ $1 =~ $re ]]; then
num=`echo "0 + $1" | bc` num=`echo "0 + $1" | bc`
if [ `echo "$num >= 0 && $num <= 2" | bc` -eq 1 ]; then if [ `echo "$num >= 0 && $num <= 2" | bc` -eq 1 ]; then
cfg[1]="$num" cfg[1]="$num"
echo "${cfg[*]}" > $CFGPATH echo "${cfg[*]}" > $CFGPATH
fi fi
fi
else else
echo "${cfg[1]}" echo "${cfg[1]}"
fi fi
@@ -89,12 +105,15 @@ sayvol()
sayspd() sayspd()
{ {
cfg=( `cat $CFGPATH` ); cfg=( `cat $CFGPATH` );
if [ $# -ge 1 ]; then if [ $# -eq 1 ]; then
re='^[0-2](\.[0-9])?$'
if [[ $1 =~ $re ]]; then
num=`echo "0 + $1" | bc` num=`echo "0 + $1" | bc`
if [ `echo "$num >= 0.5 && $num <= 1.5" | bc` -eq 1 ]; then if [ `echo "$num >= 0.5 && $num <= 1.5" | bc` -eq 1 ]; then
cfg[2]="$num" cfg[2]="$num"
echo "${cfg[*]}" > $CFGPATH echo "${cfg[*]}" > $CFGPATH
fi fi
fi
else else
echo "${cfg[2]}" echo "${cfg[2]}"
fi fi
@@ -104,8 +123,12 @@ sayspd()
saylngindex() saylngindex()
{ {
i=0; i=0;
re='^[a-z]{2}\-[A-Z]{2}$';
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
if ! [[ $1 =~ $re ]]; then
return 0
fi
TEST=$1; TEST=$1;
else else
TEST=`saylng`; TEST=`saylng`;
@@ -123,7 +146,7 @@ saylngindex()
# Stops audio playback # Stops audio playback
shutup () shutup ()
{ {
killall play; killall -9 play;
} }
# Start synthesiser # Start synthesiser
@@ -145,7 +168,7 @@ say ()
done done
fi fi
saysupport $1; saysupport $1;
if [[ "$?" = "1" ]]; then if [[ $? -eq 1 ]]; then
cfg[0]=$1; cfg[0]=$1;
unset text[0]; unset text[0];
fi fi
@@ -223,6 +246,7 @@ elif [ "$1" = "say" ]; then
shutup; shutup;
else else
TEXT=`xsel`; TEXT=`xsel`;
echo "$TEXT";
echo "$TEXT" | say; echo "$TEXT" | say;
fi fi
fi fi