bugfix, esthetic cleanup, better comments, version bump

This commit is contained in:
Geoffray Levasseur-Brandin
2024-06-21 16:19:44 +02:00
parent 9e49e3e4d7
commit bef205ae84
18 changed files with 634 additions and 571 deletions

View File

@@ -1,3 +1,4 @@
#!/bin/bash
# ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details.
@@ -36,16 +37,16 @@
# ------------------------------------------------------------------------------
# Display a backtrace
# ------------------------------------------------------------------------------
function backtrace ()
function backtrace()
{
echo "========= Call stack ========="
typeset -i i=0
local func=
for func in "${FUNCNAME[@]}"; do
if [[ $i -ne 0 ]]; then
printf '%15s() %s:%d\n' \
"$func" "${BASH_SOURCE[$i]}" "${BASH_LINENO[ (( $i - 1)) ]}"
"$func" "${BASH_SOURCE[$i]}" "${BASH_LINENO[(($i - 1))]}"
fi
let i++ || true
done
@@ -56,52 +57,54 @@ function backtrace ()
# ------------------------------------------------------------------------------
# Function to be trapped for errors investigation
# ------------------------------------------------------------------------------
function error ()
function error()
{
local errcode=$?
backtrace
return $errcode
}
# ------------------------------------------------------------------------------
# Activate or deactivate error trapping to display backtrace
# ------------------------------------------------------------------------------
settrace ()
settrace()
{
local status="off"
[[ $(trap -p ERR) ]] && status="on"
#trap -p ERR
for opt in $@ ; do
for opt in $@; do
case $opt in
"-h"|"--help")
echo "Try to activate backtrace display for script debugging."
echo
echo "Options:"
echo " --on Activate backtrace generation"
echo " --off Deactivate backtrace generation"
echo
echo "That function active a trap event on error. If the script you want to"
echo "debug overload the ERR bash trap, it will not work."
echo
;;
"--on")
if [[ $status == "on" ]]; then
disp W "ERR signal trap is already set, replacing previous trap!"
fi
trap "error" ERR
;;
"--off")
if [[ $status != "on" ]]; then
disp W "ERR signal trap is already unset!"
fi
trap - ERR
;;
"--status")
disp "ERR trap signal is ${status}."
;;
esac
"-h" | "--help")
echo "Try to activate backtrace display for script debugging."
echo
echo "Options:"
echo " --on Activate backtrace generation"
echo " --off Deactivate backtrace generation"
echo
echo "That function active a trap event on error. If the script you want to"
echo "debug overload the ERR bash trap, it will not work."
echo
;;
"--on")
if [[ $status == "on" ]]; then
disp W "ERR signal trap is already set, replacing previous trap!"
fi
trap "error" ERR
;;
"--off")
if [[ $status != "on" ]]; then
disp W "ERR signal trap is already unset!"
fi
trap - ERR
;;
"--status")
disp "ERR trap signal is ${status}."
;;
esac
done
unset status
}
export -f settrace
# ------------------------------------------------------------------------------
# EOF