Blame subr.rtl/rtl_complex.subr

Lucio Andrés Illanes Albornoz c3bcd7
#
Lucio Andrés Illanes Albornoz e1d469
# set +o errexit -o noglob -o nounset is assumed.
Lucio Andrés Illanes Albornoz c3bcd7
#
Lucio Andrés Illanes Albornoz c3bcd7
Lucio Andrés Illanes Albornoz c6d6e0
rtl_export_vars() {
Lucio Andrés Illanes Albornoz 2b85d0
	local _unsetfl=0; [ "x${1}" = "x-u" ] && { _unsetfl=1; shift; };
Lucio Andrés Illanes Albornoz 2b85d0
	while [ "${#}" -ge 2 ]; do
Lucio Andrés Illanes Albornoz 2b85d0
		if [ -n "${2}" ]; then
Lucio Andrés Illanes Albornoz 2b85d0
			if [ "${_unsetfl:-0}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz c6d6e0
				rtl_set_var_unsafe "${1}" "${2}"; export "${1}";
Lucio Andrés Illanes Albornoz 2b85d0
			else
Lucio Andrés Illanes Albornoz 2b85d0
				unset "${1}";
Lucio Andrés Illanes Albornoz c3bcd7
			fi;
Lucio Andrés Illanes Albornoz c3bcd7
		fi;
Lucio Andrés Illanes Albornoz 2b85d0
		shift 2;
Lucio Andrés Illanes Albornoz 2b85d0
	done;
Lucio Andrés Illanes Albornoz c3bcd7
};
Lucio Andrés Illanes Albornoz c3bcd7
Lucio Andrés Illanes Albornoz 8a27f9
rtl_filter_vars() {
Lucio Andrés Illanes Albornoz 64c946
	local _fn="${1}" _fnfl=0 _qchar="" _var_spec="" _vars="" _vname="" IFS;
Lucio Andrés Illanes Albornoz 64c946
	rtl_set_IFS_nl;
Lucio Andrés Illanes Albornoz 64c946
	for _var_spec in $(set); do
Lucio Andrés Illanes Albornoz 8a27f9
		case "${_qchar}" in
Lucio Andrés Illanes Albornoz 8a27f9
		"\"")	if [ "${_var_spec%\"}" != "${_var_spec}" ]; then
Lucio Andrés Illanes Albornoz 8a27f9
				_qchar="";
Lucio Andrés Illanes Albornoz 8a27f9
			fi;
Lucio Andrés Illanes Albornoz 8a27f9
			if [ "${_fnfl:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz 8a27f9
				_vars="$(rtl_lconcat "${_vars}" "${_var_spec}" "\n")";
Lucio Andrés Illanes Albornoz 8a27f9
			fi;
Lucio Andrés Illanes Albornoz 8a27f9
			continue; ;;
Lucio Andrés Illanes Albornoz 8a27f9
		"\'")	if [ "${_var_spec%\'}" != "${_var_spec}" ]; then
Lucio Andrés Illanes Albornoz 8a27f9
				_qchar="";
Lucio Andrés Illanes Albornoz 8a27f9
			fi;
Lucio Andrés Illanes Albornoz 8a27f9
			if [ "${_fnfl:-0}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz 8a27f9
				_vars="$(rtl_lconcat "${_vars}" "${_var_spec}" "\n")";
Lucio Andrés Illanes Albornoz 8a27f9
			fi;
Lucio Andrés Illanes Albornoz 8a27f9
			continue; ;;
Lucio Andrés Illanes Albornoz 8a27f9
		*)	case "${_var_spec}" in
Lucio Andrés Illanes Albornoz 8a27f9
			[^=]*=\"*\")	_qchar=""; _vname="${_var_spec%%=\"*}"; ;;
Lucio Andrés Illanes Albornoz 8a27f9
			[^=]*=\"*)	_qchar="\""; _vname="${_var_spec%%=\"*}"; ;;
Lucio Andrés Illanes Albornoz 8a27f9
			[^=]*=\'*\')	_qchar=""; _vname="${_var_spec%%=\'*}"; ;;
Lucio Andrés Illanes Albornoz 8a27f9
			[^=]*=\'*)	_qchar="\'"; _vname="${_var_spec%%=\'*}"; ;;
Lucio Andrés Illanes Albornoz 8a27f9
			[^=]*=*)	_qchar=""; _vname="${_var_spec%%=*}"; ;;
Lucio Andrés Illanes Albornoz 8a27f9
			esac; ;;
Lucio Andrés Illanes Albornoz 8a27f9
		esac;
Lucio Andrés Illanes Albornoz 8a27f9
		if "${_fn}" "${_vname}"; then
Lucio Andrés Illanes Albornoz b6a9a1
			_vars="${_vars:+${_vars}
Lucio Andrés Illanes Albornoz b6a9a1
}${_var_spec}"; _fnfl=1;
Lucio Andrés Illanes Albornoz 8a27f9
		else
Lucio Andrés Illanes Albornoz 8a27f9
			_fnfl=0;
Lucio Andrés Illanes Albornoz 8a27f9
		fi;
Lucio Andrés Illanes Albornoz 8a27f9
	done;
Lucio Andrés Illanes Albornoz b6a9a1
	printf "%s" "${_vars}";
Lucio Andrés Illanes Albornoz 8a27f9
};
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz c6d6e0
rtl_head() {
Lucio Andrés Illanes Albornoz 2b85d0
	local _pattern="${1}" _s="${2}";
Lucio Andrés Illanes Albornoz 2b85d0
	while true; do
Lucio Andrés Illanes Albornoz 2b85d0
		if [ "${_s%%${_pattern}}" = "${_s}" ]; then
Lucio Andrés Illanes Albornoz 2b85d0
			break;
Lucio Andrés Illanes Albornoz 2b85d0
		else
Lucio Andrés Illanes Albornoz 2b85d0
			_s="${_s%%${_pattern}}";
Lucio Andrés Illanes Albornoz 2b85d0
		fi;
Lucio Andrés Illanes Albornoz 2b85d0
	done;
Lucio Andrés Illanes Albornoz b6a9a1
	printf "%s" "${_s}";
Lucio Andrés Illanes Albornoz 2b85d0
};
Lucio Andrés Illanes Albornoz 2b85d0
Lucio Andrés Illanes Albornoz 285301
rtl_percentage() {
Lucio Andrés Illanes Albornoz 285301
	local _in="${1}" _max="${2}" _perc;
Lucio Andrés Illanes Albornoz 285301
	_perc="$((100 * ${_in} + ${_max} / 2))";
Lucio Andrés Illanes Albornoz 285301
	_perc="$((${_perc} ? ${_perc} / ${_max} : ${_perc}))";
Lucio Andrés Illanes Albornoz 285301
	printf "%d\n" "${_perc}";
Lucio Andrés Illanes Albornoz 285301
};
Lucio Andrés Illanes Albornoz 285301
Lucio Andrés Illanes Albornoz c3bcd7
# vim:filetype=sh