diff options
author | Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de> | 2020-05-15 10:18:14 +0100 |
---|---|---|
committer | Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de> | 2020-05-15 10:18:14 +0100 |
commit | 0875f53f8892f65bda62caa0d35d1b8dd44c6efc (patch) | |
tree | 4275404fa50ce151c0cd79c17494e74f6971858f /subr/rtl_list.subr | |
parent | 64c9461a9513839bae0b1e30013febc26fad1cec (diff) | |
download | midipix_build-0875f53f8892f65bda62caa0d35d1b8dd44c6efc.tar.bz2 midipix_build-0875f53f8892f65bda62caa0d35d1b8dd44c6efc.tar.xz |
subr/rtl_list.subr:rtl_l{assign,first}(): initial implementation.
subr/pkg_install.subr:pkg_install(): use rtl_lassign().
Diffstat (limited to 'subr/rtl_list.subr')
-rw-r--r-- | subr/rtl_list.subr | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/subr/rtl_list.subr b/subr/rtl_list.subr index 515681bc..369d3b46 100644 --- a/subr/rtl_list.subr +++ b/subr/rtl_list.subr @@ -2,6 +2,20 @@ # set +o errexit -o noglob -o nounset is assumed. # +rtl_lassign() { + local _vnames="${1}" _sep="${2}" _vname="" _vval=""\ + IFS RTL_LFIRST_HEAD="" RTL_LFIRST_TAIL=""; + IFS="${_sep}"; shift 2; + for _vval in ${@}; do + if ! rtl_lfirst "${_vnames}" " "; then + return 1; + else + _vname="${RTL_LFIRST_HEAD}"; _vnames="${RTL_LFIRST_TAIL}"; + rtl_set_var_unsafe "${_vname}" "${_vval}"; + fi; + done; +}; + rtl_lconcat() { local _list="${1}" _litem_new="${2}" _sep="${3:- }" IFS="${3:-${IFS:- }}"; if [ -n "${_list}" ]; then @@ -30,6 +44,16 @@ rtl_lfilter() { printf "%s" "${_lnew}"; }; +rtl_lfirst() { + local _list="${1}" _sep="${2}" IFS; IFS="${_sep}"; + set -- ${_list}; RTL_LFIRST_HEAD="${1}"; + if [ "${#}" -ge 0 ]; then + shift; RTL_LFIRST_TAIL="${*}"; + else + RTL_LFIRST_TAIL=""; + fi; +}; + rtl_llength() { local _list="${1}" _sep="${2:- }" IFS="${2:-${IFS:- }}" _litem="" _llength=0; for _litem in ${_list}; do |