gaboshlib/g_calc.sh aktualisiert
This commit is contained in:
parent
3e981f64dd
commit
c335791caa
@ -1,6 +1,5 @@
|
|||||||
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
|
||||||
@ -12,31 +11,41 @@ function g_calc {
|
|||||||
[ -p ${g_tmp}/${g_rnd}/bc-sed-out ] || mkfifo ${g_tmp}/${g_rnd}/bc-sed-out
|
[ -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}/${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
|
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}/${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
|
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
|
||||||
|
|
||||||
# do bc
|
# do bc
|
||||||
echo "scale=8; $@" >&3
|
echo "scale=8; $@" >&3
|
||||||
local g_bc_out
|
local g_bc_out
|
||||||
if ! read -t 0 g_bc_out <&4
|
if ! read -t 0.1 g_bc_out <&4
|
||||||
then
|
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
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# do sed
|
# do sed
|
||||||
echo ${g_bc_out} >&5
|
echo ${g_bc_out} >&5
|
||||||
local g_sed_out
|
local g_sed_out
|
||||||
if ! read -t 0 g_sed_out <&6
|
if ! read -t 0.1 g_sed_out <&6
|
||||||
then
|
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
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user