blob: f315fd9047405d17bd4b53b4b36fb1af029eb0d3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#
# set +o errexit -o noglob -o nounset is assumed.
#
rtl_export_vars() {
local _unsetfl=0; [ "x${1}" = "x-u" ] && { _unsetfl=1; shift; };
while [ "${#}" -ge 2 ]; do
if [ "${2:+1}" = 1 ]\
|| [ "${_unsetfl}" -eq 1 ]; then
case "${_unsetfl}" in
0) rtl_set_var_unsafe "${1}" "${2}"; export "${1}"; ;;
1) unset "${1}"; ;;
esac;
fi; shift 2;
done;
};
rtl_filter_vars() {
local _fn="${1}" _fnfl=0 _qchar="" _var_spec="" _vars="" _vname="" IFS;
rtl_set_IFS_nl;
for _var_spec in $(set); do
case "${_qchar}" in
"\"") if [ "${_var_spec%\"}" != "${_var_spec}" ]; then
_qchar="";
fi;
if [ "${_fnfl:-0}" -eq 1 ]; then
_vars="$(rtl_lconcat "${_vars}" "${_var_spec}" "\n")";
fi;
continue; ;;
"\'") if [ "${_var_spec%\'}" != "${_var_spec}" ]; then
_qchar="";
fi;
if [ "${_fnfl:-0}" -eq 1 ]; then
_vars="$(rtl_lconcat "${_vars}" "${_var_spec}" "\n")";
fi;
continue; ;;
*) case "${_var_spec}" in
[^=]*=\"*\") _qchar=""; _vname="${_var_spec%%=\"*}"; ;;
[^=]*=\"*) _qchar="\""; _vname="${_var_spec%%=\"*}"; ;;
[^=]*=\'*\') _qchar=""; _vname="${_var_spec%%=\'*}"; ;;
[^=]*=\'*) _qchar="\'"; _vname="${_var_spec%%=\'*}"; ;;
[^=]*=*) _qchar=""; _vname="${_var_spec%%=*}"; ;;
esac; ;;
esac;
if "${_fn}" "${_vname}"; then
_vars="${_vars:+${_vars}
}${_var_spec}"; _fnfl=1;
else
_fnfl=0;
fi;
done;
printf "%s" "${_vars}";
};
rtl_head() {
local _pattern="${1}" _s="${2}";
while true; do
if [ "${_s%%${_pattern}}" = "${_s}" ]; then
break;
else
_s="${_s%%${_pattern}}";
fi;
done;
printf "%s" "${_s}";
};
rtl_percentage() {
local _in="${1}" _max="${2}" _perc;
_perc="$((100 * ${_in} + ${_max} / 2))";
_perc="$((${_perc} ? ${_perc} / ${_max} : ${_perc}))";
printf "%d\n" "${_perc}";
};
rtl_sunset() {
local _rs_rset="${1#\$}" _rs_kname="" IFS=" ";
eval set -- '${'"${_rs_rset}"'}';
while [ "${#}" -gt 0 ]; do
unset "${_rs_rset}${_rs_kname}"; shift;
done; unset "${_rs_rset}";
};
# vim:filetype=sh
|