gaboshlib/g_calc.sh aktualisiert

This commit is contained in:
olli 2023-11-06 17:59:12 +01:00
parent fa408ca67f
commit bf4c178ea0

View File

@ -1,34 +1,37 @@
function g_calc { function g_calc {
# Use bc in backround for multiple bc's running much faster # Use bc in backround for multiple bc's running much faster
if [ -z "${g_bc_running}" ] if [ -z "${g_bc_running}" ]
then then
[ -p ${g_tmp}/bc-in ] || mkfifo ${g_tmp}/bc-in g_rnd=$RANDOM
[ -p ${g_tmp}/bc-out ] || mkfifo ${g_tmp}/bc-out mkdir -p ${g_tmp}/${g_rnd}
[ -p ${g_tmp}/bc-sed-in ] || mkfifo ${g_tmp}/bc-sed-in [ -p ${g_tmp}/${g_rnd}/bc-in ] || mkfifo ${g_tmp}/${g_rnd}/bc-in
[ -p ${g_tmp}/bc-sed-out ] || mkfifo ${g_tmp}/bc-sed-out [ -p ${g_tmp}/${g_rnd}/bc-out ] || mkfifo ${g_tmp}/${g_rnd}/bc-out
[ -p ${g_tmp}/${g_rnd}/bc-sed-in ] || mkfifo ${g_tmp}/${g_rnd}/bc-sed-in
[ -p ${g_tmp}/${g_rnd}/bc-sed-out ] || mkfifo ${g_tmp}/${g_rnd}/bc-sed-out
# bc stream channel # bc stream channel
bc -ql <${g_tmp}/bc-in >${g_tmp}/bc-out & bc -ql <${g_tmp}/${g_rnd}/bc-in >${g_tmp}/${g_rnd}/bc-out &
exec 3>${g_tmp}/bc-in 4<${g_tmp}/bc-out exec 3>${g_tmp}/${g_rnd}/bc-in 4<${g_tmp}/${g_rnd}/bc-out
# sed stream channel # sed stream channel
sed -su 's/^\./0./; s/^-\./-0./' <${g_tmp}/bc-sed-in >${g_tmp}/bc-sed-out & sed -su 's/^\./0./; s/^-\./-0./' <${g_tmp}/${g_rnd}/bc-sed-in >${g_tmp}/${g_rnd}/bc-sed-out &
exec 5>${g_tmp}/bc-sed-in 6<${g_tmp}/bc-sed-out exec 5>${g_tmp}/${g_rnd}/bc-sed-in 6<${g_tmp}/${g_rnd}/bc-sed-out
g_bc_running="true" g_bc_running="true"
fi 2>/dev/null fi 2>/dev/null
# do bc # do bc
echo "scale=8; $@" >&3 echo "scale=8; $@" >&3
local g_bc_out local g_bc_out
read g_bc_out <&4 read g_bc_out <&4
# do sed # do sed
echo ${g_bc_out} >&5 echo ${g_bc_out} >&5
local g_sed_out local g_sed_out
read g_sed_out <&6 read g_sed_out <&6
# echo result # echo result
echo ${g_sed_out} echo ${g_sed_out}
} }