From c335791caa7fbc320c812a7b7355c9a0e7c3fcdc Mon Sep 17 00:00:00 2001 From: olli Date: Tue, 7 Nov 2023 13:18:32 +0100 Subject: [PATCH] gaboshlib/g_calc.sh aktualisiert --- gaboshlib/g_calc.sh | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/gaboshlib/g_calc.sh b/gaboshlib/g_calc.sh index e421d9d..302fcaf 100644 --- a/gaboshlib/g_calc.sh +++ b/gaboshlib/g_calc.sh @@ -1,6 +1,5 @@ function g_calc { - # Use bc in backround for multiple bc's running much faster if [ -z "${g_bc_running}" ] then @@ -12,31 +11,41 @@ function g_calc { [ -p ${g_tmp}/${g_rnd}/bc-sed-out ] || mkfifo ${g_tmp}/${g_rnd}/bc-sed-out # bc stream channel - bc -ql <${g_tmp}/${g_rnd}/bc-in >${g_tmp}/${g_rnd}/bc-out & + { bc -ql <${g_tmp}/${g_rnd}/bc-in 2>&1 >${g_tmp}/${g_rnd}/bc-out & } 2>/dev/null exec 3>${g_tmp}/${g_rnd}/bc-in 4<${g_tmp}/${g_rnd}/bc-out # sed stream channel - sed -su 's/^\./0./; s/^-\./-0./' <${g_tmp}/${g_rnd}/bc-sed-in >${g_tmp}/${g_rnd}/bc-sed-out & + { sed -su 's/^\./0./; s/^-\./-0./' <${g_tmp}/${g_rnd}/bc-sed-in >${g_tmp}/${g_rnd}/bc-sed-out & } 2>/dev/null exec 5>${g_tmp}/${g_rnd}/bc-sed-in 6<${g_tmp}/${g_rnd}/bc-sed-out g_bc_running="true" - fi 2>/dev/null + fi # do bc echo "scale=8; $@" >&3 local g_bc_out - if ! read -t 0 g_bc_out <&4 + if ! read -t 0.1 g_bc_out <&4 then - g_traceback + g_traceback "$@" + ( exec 3<&- ) 2>/dev/null + ( exec 4<&- ) 2>/dev/null + ( exec 5<&- ) 2>/dev/null + ( exec 6<&- ) 2>/dev/null + unset g_bc_running return 1 - fi + fi # do sed echo ${g_bc_out} >&5 local g_sed_out - if ! read -t 0 g_sed_out <&6 + if ! read -t 0.1 g_sed_out <&6 then - g_traceback + g_traceback "$@" + ( exec 3<&- ) 2>/dev/null + ( exec 4<&- ) 2>/dev/null + ( exec 5<&- ) 2>/dev/null + ( exec 6<&- ) 2>/dev/null + unset g_bc_running return 1 fi