confz

git mirror of https://ccx.te2000.cz/bzr/confz
git clone https://ccx.te2000.cz/git/confz
Log | Files | Refs

commit 22ef3df006ec928a55c133942c2d55d5b13edb64
parent 96df8713b2125769b16eece5919329ba54828568
Author: Jan Pobrislo <ccx@webprojekty.cz>
Date:   Tue, 21 Nov 2017 17:16:11 +0100

variable matching and unification
Diffstat:
Mbin/confz | 24++++++++++++++++++++++++
1 file changed, 24 insertions(+), 0 deletions(-)

diff --git a/bin/confz b/bin/confz @@ -67,6 +67,30 @@ checkvars() { (( $#empty )) && die "required parameters are empty: ${(@q)empty}" } +# check if given arguments (as name value pairs) match current $vars +matchvars() { + local name value + for name value in "$@"; do + if (($+vars[$name])); then + [[ $value == $vars[$name] ]] || return 1 + fi + done + return 0 +} + +# unify given arguments (as name value pairs) with current $vars +unify() { + local name value + for name value in "$@"; do + if (($+vars[$name])); then + [[ $value == $vars[$name] ]] \ + || die "Unified variable $name has value ${(qqq)vars[$name]} not matching ${(qqq)value}" + else + vars[$name]=$value + fi + done +} + # autoload all relevant functions and run confz_*_init confz_load() { local func