Project

General

Profile

« Previous | Next » 

Revision 9068

lib/sh/util.sh: moved functions after verbose output so copy_func () can use logging functions in its input checks

View differences:

util.sh
73 73
if self_being_included; then
74 74

  
75 75

  
76
#### functions
77

  
78
func_exists () { declare -f "$1" >/dev/null; }
79

  
80
copy_func () # usage: from=... to=... copy_func
81
# $to must not exist. to get around the no-clobber restriction, use `unset -f`.
82
{
83
	: "${from:?}" "${to:?}"
84
	func_exists "$from" || die "function does not exist: $from"
85
	! func_exists "$to" || die "function already exists: $to"
86
	local from_def="$(declare -f "$from")"
87
	eval "$to${from_def#$from}"
88
}
89

  
90
func_override () # usage: func_override old_name__suffix
91
{ from="${1%%__*}" to="$1" copy_func; }
92

  
93

  
94 76
#### integers
95 77

  
96 78
let! () { let "$@" || true; } # always returns true; safe to use for setting
......
271 253
)"
272 254

  
273 255

  
256
#### functions
257

  
258
func_exists () { declare -f "$1" >/dev/null; }
259

  
260
copy_func () # usage: from=... to=... copy_func
261
# $to must not exist. to get around the no-clobber restriction, use `unset -f`.
262
{
263
	: "${from:?}" "${to:?}"
264
	func_exists "$from" || die "function does not exist: $from"
265
	! func_exists "$to" || die "function already exists: $to"
266
	local from_def="$(declare -f "$from")"
267
	eval "$to${from_def#$from}"
268
}
269

  
270
func_override () # usage: func_override old_name__suffix
271
{ from="${1%%__*}" to="$1" copy_func; }
272

  
273

  
274 274
#### commands
275 275

  
276 276
top_script="$0" # outermost script

Also available in: Unified diff