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 b9a715
Lucio Andrés Illanes Albornoz 2b85d0
	while [ "${#}" -ge 2 ]; do
Lucio Andrés Illanes Albornoz b9a715
		if [ "${2:+1}" = 1 ]\
Lucio Andrés Illanes Albornoz b9a715
		|| [ "${_unsetfl}" -eq 1 ]; then
Lucio Andrés Illanes Albornoz b9a715
			case "${_unsetfl}" in
Lucio Andrés Illanes Albornoz b9a715
			0)	rtl_set_var_unsafe "${1}" "${2}"; export "${1}"; ;;
Lucio Andrés Illanes Albornoz b9a715
			1)	unset "${1}"; ;;
Lucio Andrés Illanes Albornoz b9a715
			esac;
Lucio Andrés Illanes Albornoz b9a715
		fi; 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 3e5303
rtl_sunset() {
Lucio Andrés Illanes Albornoz 3e5303
	local _rs_rset="${1#\$}" _rs_kname="" IFS=" 	";
Lucio Andrés Illanes Albornoz 3e5303
	eval set -- '${'"${_rs_rset}"'}';
Lucio Andrés Illanes Albornoz 3e5303
	while [ "${#}" -gt 0 ]; do
Lucio Andrés Illanes Albornoz 3e5303
		unset "${_rs_rset}${_rs_kname}"; shift;
Lucio Andrés Illanes Albornoz 3e5303
	done; unset "${_rs_rset}";
Lucio Andrés Illanes Albornoz 3e5303
};
Lucio Andrés Illanes Albornoz 3e5303
Lucio Andrés Illanes Albornoz c3bcd7
# vim:filetype=sh