blob: 2e97e4dcfaf459ca6b898e8a8c5de95eb4e65b82 (
plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
[ -n "$LIBMAKEPKG_UTIL_PKGBUILD_SH" ] && return
LIBMAKEPKG_UTIL_PKGBUILD_SH=1
have_function() {
declare -f "$1" >/dev/null
}
grep_function() {
{ declare -f "$1" || declare -f package; } 2>/dev/null | grep -E "$2"
}
array_build() {
local dest=$1 src=$2 i keys values
declare -p "$2" &>/dev/null || return 1
eval "keys=(\"\${!$2[@]}\")"
eval "$dest=()"
for i in "${keys[@]}"; do
values+=("printf -v '$dest[$i]' %s \"\${$src[$i]}\";")
done
eval "${values[*]}"
}
extract_global_variable() {
local attr=$1 isarray=$2 outputvar=$3 ref
if (( isarray )); then
array_build ref "$attr"
[[ ${ref[@]} ]] && array_build "$outputvar" "$attr"
else
[[ ${!attr} ]] && printf -v "$outputvar" %s "${!attr}"
fi
}
extract_function_variable() {
local funcname=$1 attr=$2 isarray=$3 outputvar=$4 attr_regex= decl= r=1
if (( isarray )); then
printf -v attr_regex '^[[:space:]]* %s\+?=\(' "$2"
else
printf -v attr_regex '^[[:space:]]* %s\+?=[^(]' "$2"
fi
while read -r; do
decl=${REPLY##*([[:space:]])}
eval "${decl/#$attr/$outputvar}"
r=0
done < <(grep_function "$funcname" "$attr_regex")
return $r
}
get_pkgbuild_attribute() {
local pkgname=$1 attrname=$2 isarray=$3 outputvar=$4
printf -v "$outputvar" %s ''
if [[ $pkgname ]]; then
extract_global_variable "$attrname" "$isarray" "$outputvar"
extract_function_variable "package_$pkgname" "$attrname" "$isarray" "$outputvar"
else
extract_global_variable "$attrname" "$isarray" "$outputvar"
fi
}
|