Blame subr.rtl/rtl_complex.subr

Lucio Andrés Illanes Albornoz c3bcd7
#
8d7a8a
# Copyright (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 LucĂ­a Andrea Illanes Albornoz <lucia@luciaillanes.de>
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() {
e9fa07
	local _rev_unsetfl=0;
e9fa07
e9fa07
	if [ "x${1}" = "x-u" ]; then
e9fa07
		_rev_unsetfl=1; shift;
e9fa07
	fi;
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 ]\
e9fa07
		|| [ "${_rev_unsetfl}" -eq 1 ]; then
e9fa07
			case "${_rev_unsetfl}" in
e9fa07
			0)	rtl_set_var_unsafe "${1}" "${2}";
e9fa07
				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
e9fa07
	return 0;
Lucio Andrés Illanes Albornoz 8a27f9
};
Lucio Andrés Illanes Albornoz 8a27f9
Lucio Andrés Illanes Albornoz c6d6e0
rtl_head() {
e9fa07
	local _rh_pattern="${1}" _rh_s="${2}" _rh_rs_out="${3#\$}";
e9fa07
Lucio Andrés Illanes Albornoz 2b85d0
	while true; do
e9fa07
		if [ "${_rh_s%%${_rh_pattern}}" = "${_rh_s}" ]; then
Lucio Andrés Illanes Albornoz 2b85d0
			break;
Lucio Andrés Illanes Albornoz 2b85d0
		else
e9fa07
			_rh_s="${_rh_s%%${_rh_pattern}}";
Lucio Andrés Illanes Albornoz 2b85d0
		fi;
Lucio Andrés Illanes Albornoz 2b85d0
	done;
e9fa07
e9fa07
	eval ${_rh_rs_out}='${_rh_s}';
e9fa07
	return 0;
Lucio Andrés Illanes Albornoz 2b85d0
};
Lucio Andrés Illanes Albornoz 2b85d0
Lucio Andrés Illanes Albornoz 285301
rtl_percentage() {
e9fa07
	local	_rp_in="${1}" _rp_max="${2}" _rp_rs_out="${3#\$}"	\
e9fa07
		_rp_perc;
e9fa07
e9fa07
	_rp_perc=$((100 * ${_rp_in} + ${_rp_max} / 2));
e9fa07
	_rp_perc=$((${_rp_perc} ? ${_rp_perc} / ${_rp_max} : ${_rp_perc}));
e9fa07
e9fa07
	eval ${_rp_rs_out}='${_rp_perc}';
e9fa07
	return 0;
e9fa07
};
e9fa07
e9fa07
rtl_percentage2() {
e9fa07
	local	_rp_rin="${1#\$}" _rp_rmax="${2#\$}" _rp_rs_out="${3#\$}"	\
e9fa07
		_rp_in=0 _rp_max=0 _rp_perc;
e9fa07
e9fa07
	eval _rp_in=\"\${${_rp_rin}}\";
e9fa07
	eval _rp_max=\"\${${_rp_rmax}}\";
e9fa07
e9fa07
	_rp_perc=$((100 * ${_rp_in} + ${_rp_max} / 2));
e9fa07
	_rp_perc=$((${_rp_perc} ? ${_rp_perc} / ${_rp_max} : ${_rp_perc}));
e9fa07
e9fa07
	eval ${_rp_rs_out}='${_rp_perc}';
e9fa07
	return 0;
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=" 	";
e9fa07
e9fa07
	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}";
e9fa07
e9fa07
	return 0;
Lucio Andrés Illanes Albornoz 3e5303
};
Lucio Andrés Illanes Albornoz 3e5303
64844b
# vim:filetype=sh textwidth=0