Project

General

Profile

« Previous | Next » 

Revision 14704

lib/sh/util.sh: moved func_loc() to before debugging section so it can be used by debugging functions

View differences:

util.sh
80 80

  
81 81
err_fd=2 # stderr
82 82

  
83
# usage: local func=...; set_func_loc; use $file, $line
84
alias set_func_loc="$(cat <<'EOF'
85
: "${func:?}"
86
local func_info="$(shopt -s extdebug; declare -F "$func")" # 'func line file'
87
func_info="${func_info#$func }"
88
local line="${func_info%% *}"
89
local file="${func_info#$line }"
90
EOF
91
)"
83 92

  
93
fi # load new aliases
94
if self_being_included; then
95

  
96
func_loc() # gets where function declared in the format file:line
97
{
98
	local func="$1"; set_func_loc
99
	file="$(canon_rel_path "$file")" || return
100
	echo "$file:$line"
101
}
102

  
103

  
84 104
#### debugging
85 105

  
86 106
debug_fd="$err_fd"
......
795 815

  
796 816
## functions
797 817

  
798
# usage: local func=...; set_func_loc; use $file, $line
799
alias set_func_loc="$(cat <<'EOF'
800
: "${func:?}"
801
local func_info="$(shopt -s extdebug; declare -F "$func")" # 'func line file'
802
func_info="${func_info#$func }"
803
local line="${func_info%% *}"
804
local file="${func_info#$line }"
805
EOF
806
)"
807

  
808
fi # load new aliases
809
if self_being_included; then
810

  
811
func_loc() # gets where function declared in the format file:line
812
{
813
	local func="$1"; set_func_loc
814
	file="$(canon_rel_path "$file")" || return
815
	echo "$file:$line"
816
}
817

  
818 818
# usage: func() { echo_func; ... }
819 819
function echo_func()
820 820
# usage: "echo_func" "$FUNCNAME" "$@" && indent || true

Also available in: Unified diff