aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Bo ├śrsted Andresen <bo.andresen@zlin.dk> 2009-02-11 11:13:35 +0100
committerAvatar Bo ├śrsted Andresen <bo.andresen@zlin.dk> 2009-02-11 21:37:58 +0100
commita2a5757fd022a82591e0028538f07bf75912ad58 (patch)
treee6d349b3c10539384e8ea4fe80f16577acaa2579
parent1098fbd8cc2de00ace465a1d9679b1020b057f7f (diff)
downloadpaludis-a2a5757fd022a82591e0028538f07bf75912ad58.tar.gz
paludis-a2a5757fd022a82591e0028538f07bf75912ad58.tar.xz
To access an exlib array now use exparam foo[@] rather than exparam foo. Add -v to assign to variable or array instead of printing to stdout.
- exparam foo is now equivalent to exparam foo[0] - var=$(exparam foo) is now equivalent to exparam -v var foo except that the latter works outside global space too since it keeps exparam out of any subshells - array=( $(exparam foo[@]) ) is now done properly with exparam -v array foo[@]
-rwxr-xr-xpaludis/repositories/e/e_repository_TEST_exlibs_setup.sh36
-rw-r--r--paludis/repositories/e/ebuild/exheres-0/exlib_functions.bash60
2 files changed, 56 insertions, 40 deletions
diff --git a/paludis/repositories/e/e_repository_TEST_exlibs_setup.sh b/paludis/repositories/e/e_repository_TEST_exlibs_setup.sh
index b25158b..e0a4690 100755
--- a/paludis/repositories/e/e_repository_TEST_exlibs_setup.sh
+++ b/paludis/repositories/e/e_repository_TEST_exlibs_setup.sh
@@ -215,7 +215,13 @@ check_foo() {
exparam bar[1] | grep -q ^2$ || die "Bad bar[1]"
exparam bar[2] | grep -q ^3$ || die "Bad bar[2]"
exparam bar[3] | grep -q ^$ || die "Bad bar[3]"
- exparam bar FOO
+ exparam -v FOOA bar[@]
+ exparam -v FOO bar
+ exparam -v FOO0 bar[0]
+ exparam -v FOO1 bar[1]
+ exparam -v FOO2 bar[2]
+ exparam -v FOO3 bar[3]
+ exparam -v FOOC bar[#]
}
END
cat <<'END' > packages/cat/exarray/exarray-1.ebuild || exit 1
@@ -224,11 +230,17 @@ PLATFORMS="test"
pkg_setup() {
check_foo || die "check_foo returned errror"
- [[ ${#FOO[@]} -eq 3 ]] || die "Wrong number of elements in FOO[@]"
- [[ ${FOO[0]} == 1 ]] || die "Bad FOO[0]"
- [[ ${FOO[1]} == 2 ]] || die "Bad FOO[1]"
- [[ ${FOO[2]} == 3 ]] || die "Bad FOO[2]"
- [[ ${FOO[@]} == "1 2 3" ]] || die "FOO[@] != 1 2 3"
+ [[ ${#FOOA[@]} -eq 3 ]] || die "Wrong number of elements, ${#FOOA[@]} in FOOA[@]"
+ [[ ${FOOA[0]} == 1 ]] || die "Bad FOOA[0]"
+ [[ ${FOOA[1]} == 2 ]] || die "Bad FOOA[1]"
+ [[ ${FOOA[2]} == 3 ]] || die "Bad FOOA[2]"
+ [[ ${FOOA[@]} == "1 2 3" ]] || die "FOOA[@] != 1 2 3"
+ [[ ${FOO} == 1 ]] || die "Bad FOO"
+ [[ ${FOO0} == 1 ]] || die "Bad FOO0"
+ [[ ${FOO1} == 2 ]] || die "Bad FOO1"
+ [[ ${FOO2} == 3 ]] || die "Bad FOO2"
+ [[ -z ${FOO3} ]] || die "Bad FOO3"
+ [[ ${FOOC} -eq 3 ]] || die "Bad FOOC"
}
END
mkdir -p "packages/cat/exarray-spaces"
@@ -241,7 +253,7 @@ check_foo() {
exparam bar[1] | grep -q '^2 2$' || die "Bad bar[1]"
exparam bar[2] | grep -q '^3 3$' || die "Bad bar[2]"
exparam bar[3] | grep -q ^$ || die "Bad bar[3]"
- exparam bar FOO
+ exparam -v FOO bar[@]
}
END
cat <<'END' > packages/cat/exarray-spaces/exarray-spaces-1.ebuild || exit 1
@@ -250,7 +262,7 @@ PLATFORMS="test"
pkg_setup() {
check_foo || die "check_foo returned errror"
- [[ ${#FOO[@]} -eq 3 ]] || die "Wrong number of elements in FOO[@]"
+ [[ ${#FOO[@]} -eq 3 ]] || die "Wrong number of elements, ${#FOO[@]} in FOO[@]"
[[ ${FOO[0]} == "1 1" ]] || die "Bad FOO[0]"
[[ ${FOO[1]} == "2 2" ]] || die "Bad FOO[1]"
[[ ${FOO[2]} == "3 3" ]] || die "Bad FOO[2]"
@@ -267,7 +279,7 @@ check_foo() {
exparam bar[1] | grep -q ^2$ || die "Bad bar[1]"
exparam bar[2] | grep -q ^3$ || die "Bad bar[2]"
exparam bar[3] | grep -q ^$ || die "Bad bar[3]"
- exparam bar FOO
+ exparam -v FOO bar[@]
}
END
cat <<'END' > packages/cat/exarray-default/exarray-default-1.ebuild || exit 1
@@ -276,7 +288,7 @@ PLATFORMS="test"
pkg_setup() {
check_foo || die "check_foo returned errror"
- [[ ${#FOO[@]} -eq 3 ]] || die "Wrong number of elements in FOO[@]"
+ [[ ${#FOO[@]} -eq 3 ]] || die "Wrong number of elements, ${#FOO[@]} in FOO[@]"
[[ ${FOO[0]} == 1 ]] || die "Bad FOO[0]"
[[ ${FOO[1]} == 2 ]] || die "Bad FOO[1]"
[[ ${FOO[2]} == 3 ]] || die "Bad FOO[2]"
@@ -293,7 +305,7 @@ check_foo() {
exparam bar[1] | grep -q '^2 2$' || die "Bad bar[1]"
exparam bar[2] | grep -q '^3 3$' || die "Bad bar[2]"
exparam bar[3] | grep -q ^$ || die "Bad bar[3]"
- exparam bar FOO
+ exparam -v FOO bar[@]
}
END
cat <<'END' > packages/cat/exarray-default-spaces/exarray-default-spaces-1.ebuild || exit 1
@@ -302,7 +314,7 @@ PLATFORMS="test"
pkg_setup() {
check_foo || die "check_foo returned errror"
- [[ ${#FOO[@]} -eq 3 ]] || die "Wrong number of elements in FOO[@]"
+ [[ ${#FOO[@]} -eq 3 ]] || die "Wrong number of elements, ${#FOO[@]} in FOO[@]"
[[ ${FOO[0]} == "1 1" ]] || die "Bad FOO[0]"
[[ ${FOO[1]} == "2 2" ]] || die "Bad FOO[1]"
[[ ${FOO[2]} == "3 3" ]] || die "Bad FOO[2]"
diff --git a/paludis/repositories/e/ebuild/exheres-0/exlib_functions.bash b/paludis/repositories/e/ebuild/exheres-0/exlib_functions.bash
index 571fd57..f47524d 100644
--- a/paludis/repositories/e/ebuild/exheres-0/exlib_functions.bash
+++ b/paludis/repositories/e/ebuild/exheres-0/exlib_functions.bash
@@ -40,37 +40,41 @@ exparam_var_name()
echo EXPARAMVAR_${1//-/__dash__}
}
+exparam_print()
+{
+ case "${1}" in
+ -a) eval "${2}=( \"\${${3}}\" )" ;;
+ -v) eval "${2}=\"\${${3}}\"" ;;
+ *) eval "echo \"\${${1}}\"" ;;
+ esac
+}
+
exparam_internal()
{
- local v=$(exparam_var_name ${1})__ALLDECLS__
- if [[ ${2} == *\[*\] ]]; then
- [[ ${#} -eq 2 ]] || die "exparam with an index requires exactly one argument"
- has "${2%\[*}[]" ${!v} || die "${1}.exlib has no ${2%\[*} array"
- v=$(exparam_var_name ${1})_${2%\[*}
- local i=${2%\]}
- i=${i#*\[}
- if [[ ${i} == "#" ]]; then
- eval "echo \"\${#${v}[*]}\""
- elif [[ ${i} == "*" ]]; then
- eval "echo \"\${${v}[*]}\""
- elif [[ ${i} == +([[:digit:]]) ]]; then
- eval "echo \"\${${v}[${i}]}\""
- else
- die "Invalid index in exparam ${2}"
- fi
+ local i e=${1} a to_var v a_v=$(exparam_var_name ${1})__ALLDECLS__
+ shift
+ if [[ ${1} == -v ]]; then
+ [[ ${#} -eq 3 ]] || die "exparam ${1} requires exactly three arguments"
+ a=${1}
+ to_var=${2}
+ shift 2
else
- [[ ${#} -eq 2 || ${#} -eq 3 ]] || die "exparam requires exactly one or two arguments"
- if [[ ${#} -eq 3 ]]; then
- has "${2%\[*}[]" ${!v} || die "${1}.exlib has no ${2%\[*} array"
- else
- has ${2%\[*} ${!v} || die "${1}.exlib has no ${2%\[*} parameter"
- fi
- v=$(exparam_var_name ${1})_${2}
- if [[ -n ${3} ]]; then
- eval "${3}=( \"\${${v}[@]}\" )"
- else
- echo "${!v}"
- fi
+ [[ ${#} -eq 1 ]] || die "exparam requires exactly one argument"
+ fi
+ v=$(exparam_var_name ${e})_${1%\[*}
+ if [[ ${1} == *\[*\] ]]; then
+ has "${1%\[*}[]" ${!a_v} || die "${e}.exlib has no ${1%\[*} array"
+ i=${1#*\[}
+ i=${i%\]}
+ case "${i}" in
+ "#") exparam_print ${to_var:+-v "${to_var}"} "#${v}[*]" ;;
+ "*"|"@") exparam_print ${to_var:+-a "${to_var}"} "${v}[${i}]" ;;
+ +([[:digit:]])) exparam_print ${to_var:+-v "${to_var}"} "${v}[${i}]" ;;
+ *) die "Invalid index in exparam ${1}" ;;
+ esac
+ else
+ has "${1}" ${!a_v%\[\]} || die "${e}.exlib has no ${1} parameter"
+ exparam_print ${to_var:+-v "${to_var}"} "${v}"
fi
}