654f269917
This uses the same utility function that mosh-client/mosh-server do. This resolves portability issues with the 'locale' command. This fixes OpenBSD 6.0 and probably Haiku builds.
76 lines
1.1 KiB
Bash
76 lines
1.1 KiB
Bash
#!/bin/sh
|
|
|
|
#
|
|
# This is a library of subroutines mostly intended for test scripts.
|
|
#
|
|
|
|
fail()
|
|
{
|
|
printf "$@" 2>&1
|
|
exit 99
|
|
}
|
|
|
|
sleepf()
|
|
{
|
|
(sleep .1 || sleep 1) > /dev/null 2>&1
|
|
}
|
|
|
|
seq_function()
|
|
{
|
|
if [ $# -lt 1 ] || [ $# -gt 3 ]; then
|
|
echo "bad args" >&2
|
|
fi
|
|
first=$1
|
|
incr=1
|
|
last=0
|
|
case $# in
|
|
3)
|
|
incr=$2
|
|
last=$3
|
|
;;
|
|
2)
|
|
last=$2
|
|
;;
|
|
1)
|
|
;;
|
|
esac
|
|
while :; do
|
|
printf '%d\n' "$first"
|
|
first=$(( first + incr ))
|
|
if [ "$first" -gt "$last" ]; then
|
|
break
|
|
fi
|
|
done
|
|
}
|
|
|
|
if ! seq 1 > /dev/null 2>&1; then
|
|
seq()
|
|
{
|
|
seq_function "$@"
|
|
}
|
|
fi
|
|
|
|
chr()
|
|
{
|
|
printf '%b' "\\0$(printf %03o "$1")"
|
|
}
|
|
|
|
# If the locale is not set to a UTF-8 locale, set it to en_US.UTF-8
|
|
# or C.UTF-8.
|
|
set_locale()
|
|
{
|
|
# Test for a usable locale.
|
|
if ./is-utf8-locale 2> /dev/null; then
|
|
return 0
|
|
fi
|
|
# Attempt to find/set a usable locale.
|
|
for i in en_US.UTF-8 en_US.utf8 C.UTF-8; do
|
|
if env LANG=$i ./is-utf8-locale 2> /dev/null; then
|
|
export LANG=$i LC_ALL=''
|
|
return 0
|
|
fi
|
|
done
|
|
# Fail.
|
|
return 1
|
|
}
|