-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfunctions.functions
66 lines (52 loc) · 1.63 KB
/
functions.functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# This file is part of shellfire core. It is subject to the licence terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/shellfire-dev/core/master/COPYRIGHT. No part of shellfire core, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
# Copyright © 2014-2015 The developers of shellfire core. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/shellfire-dev/core/master/COPYRIGHT.
core_usesIn core compatibility
core_usesIn core/variable array
core_functions_register()
{
local functionsVariableName="$1"
shift 1
core_variable_array_append "$functionsVariableName" "$@"
core_dependency_declaresAsArray "$functionsVariableName"
}
core_functions_execute()
{
local functionsVariableName="$1"
shift 1
if core_variable_isSet "$functionsVariableName"; then
core_variable_array_iterateAsCallbacks "$functionsVariableName" "$@"
fi
}
# Not perfect by any means; an expanded environment variable with content of 'a shell function', say, could fail this test
core_functions_exists()
{
local functionName="$1"
if ! type "$functionName" 1>/dev/null 2>/dev/null; then
return 1
fi
local arg0
local arg1
local arg2
local arg3
local arg4
IFS=' ' read -r arg0 arg1 arg2 arg3 arg4 <<-EOF
$(type "$functionName")
EOF
case "$arg3" in
# dash
shell)
if [ "$arg4" = 'function' ]; then
return 0
fi
;;
# bash
function)
return 0
;;
# AIX shell
'function.')
return 0
;;
esac
return 1
}