~q3cpma/posix-build

9fa28bc39136e8bfcc30485f502202f573e7e29b — q3cpma 7 months ago eecb04c
Sync with util again
1 files changed, 20 insertions(+), 7 deletions(-)

M build_util.sh
M build_util.sh => build_util.sh +20 -7
@@ 24,12 24,6 @@ pecho()
	printf '%s\n' "$*"
}

# Return the value of variable named $1
value()
{
	eval pecho "\"\$$1\""
}

# Print all arguments to stderr and exits with status 1
die()
{


@@ 37,6 31,22 @@ die()
	exit 1
}

# Check if the variable named $1 exists
isset()
{
	eval "[ \"\${$1+x}\" ]"
}

# Return the value of variable named $1, fails if no such variable exists
value()
{
	match "$1" '[0-9]+' &&
		{ pecho "positional parameters can't be used with value()" >&2; return 1; }
	isset "$1" ||
		{ pecho "$var: variable not set" >&2; return 1; }
	eval pecho "\"\$$1\""
}

# Append to variable $1, which need not exists
append()
{


@@ 68,7 78,7 @@ typecheck()
	for var
	do
		match "$var" '[0-9]+' && die "positional parameters can't be used with typecheck"
		val=$(value "$var")
		val=$(value "$var") || exit 1
		case "$type" in
			bool)
				[ "$val" != true ] && [ "$val" != false ] && {


@@ 94,6 104,9 @@ typecheck()
					success=false
				}
				;;
			*)
				die "$type: unknown type"
				;;
		esac
	done
	$success