From e9fa0774ed2e7e030a68f5b0ae51fe6dd69fe492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luc=C3=ADa=20Andrea=20Illanes=20Albornoz?= Date: Fri, 17 Feb 2023 19:29:28 +0100 Subject: Make everything a bit faster. 0) Issues several prayers and sacrifices to Enki under threat of a terrible deluge sent down by Ellil 1) Convert fork-write/read exprs to be non-forking 2) Pass mostly everything by reference 3) Don't bother cleaning the variable namespace because Bourne shell is an abomination 4) Removes broken ./pkgtool.sh -s, --restart-at, --update-diff & ./build.sh --dump-{in,on-abort} 5) Cleanup --- subr.rtl/rtl.subr | 18 +- subr.rtl/rtl_complex.subr | 92 +++--- subr.rtl/rtl_fetch.subr | 101 +++---- subr.rtl/rtl_fetch_git.subr | 132 +++++---- subr.rtl/rtl_fetch_wget.subr | 79 ++++++ subr.rtl/rtl_fileop.subr | 120 ++++---- subr.rtl/rtl_filepath.subr | 121 +++++--- subr.rtl/rtl_install.subr | 78 ++--- subr.rtl/rtl_install_v2.subr | 663 +++++++++++++++++++++++-------------------- subr.rtl/rtl_list.subr | 313 +++++++++++++------- subr.rtl/rtl_log.subr | 78 +++-- subr.rtl/rtl_platform.subr | 172 ++++++----- subr.rtl/rtl_state.subr | 55 ++-- subr.rtl/rtl_string.subr | 204 +++++++------ 14 files changed, 1328 insertions(+), 898 deletions(-) create mode 100644 subr.rtl/rtl_fetch_wget.subr (limited to 'subr.rtl') diff --git a/subr.rtl/rtl.subr b/subr.rtl/rtl.subr index 532cb514..7a72b89c 100644 --- a/subr.rtl/rtl.subr +++ b/subr.rtl/rtl.subr @@ -2,12 +2,20 @@ # set +o errexit -o noglob -o nounset is assumed. # -rtl_date() { command date "+${1:-${DEFAULT_TIMESTAMP_FMT:-"%Y/%m/%d %H:%M:%S"}}"; }; -rtl_set_IFS_nl() { IFS=" -"; }; -rtl_set_var_unsafe() { [ -n "${2}" ] && eval ${1}=\"${2}\" || return 0; }; +# +RTL_IFS_ORIG=" +"; + +# +RTL_NL=" +"; + +rtl_date() { local _rdate="${1#\$}"; shift; eval ${_rdate}=\"\$\(command date \"+\${1:-\${DEFAULT_TIMESTAMP_FMT:-\"%Y/%m/%d %H:%M:%S\"}}\"\)\"; }; +rtl_set_IFS_nl() { IFS="${RTL_NL}"; }; +rtl_set_var_unsafe() { [ "${2:+1}" = 1 ] && eval ${1}=\"${2}\" || return 0; }; rtl_test_cmd() { command -v "${1}" >/dev/null; }; rtl_uniq() { if [ "${#}" -gt 0 ]; then printf "%s" "${*}" | sed 's/ /\n/g' | awk '!x[$0]++' | paste -s -d" "; fi; }; +rtl_uniq2() { eval set -- \${${1#\$}}; if [ "${#}" -gt 0 ]; then printf "%s" "${*}" | sed 's/ /\n/g' | awk '!x[$0]++' | paste -s -d" "; fi; }; rtl_unset_vars() { while [ ${#} -gt 0 ]; do unset "${1}"; shift; done; }; -# vim:filetype=sh +# vim:filetype=sh textwidth=0 diff --git a/subr.rtl/rtl_complex.subr b/subr.rtl/rtl_complex.subr index 1e13fce7..859fd8e5 100644 --- a/subr.rtl/rtl_complex.subr +++ b/subr.rtl/rtl_complex.subr @@ -3,81 +3,75 @@ # rtl_export_vars() { - local _unsetfl=0; [ "x${1}" = "x-u" ] && { _unsetfl=1; shift; }; + local _rev_unsetfl=0; + + if [ "x${1}" = "x-u" ]; then + _rev_unsetfl=1; shift; + fi; while [ "${#}" -ge 2 ]; do if [ "${2:+1}" = 1 ]\ - || [ "${_unsetfl}" -eq 1 ]; then - case "${_unsetfl}" in - 0) rtl_set_var_unsafe "${1}" "${2}"; export "${1}"; ;; + || [ "${_rev_unsetfl}" -eq 1 ]; then + case "${_rev_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}"; + return 0; }; rtl_head() { - local _pattern="${1}" _s="${2}"; + local _rh_pattern="${1}" _rh_s="${2}" _rh_rs_out="${3#\$}"; + while true; do - if [ "${_s%%${_pattern}}" = "${_s}" ]; then + if [ "${_rh_s%%${_rh_pattern}}" = "${_rh_s}" ]; then break; else - _s="${_s%%${_pattern}}"; + _rh_s="${_rh_s%%${_rh_pattern}}"; fi; done; - printf "%s" "${_s}"; + + eval ${_rh_rs_out}='${_rh_s}'; + return 0; }; rtl_percentage() { - local _in="${1}" _max="${2}" _perc; - _perc="$((100 * ${_in} + ${_max} / 2))"; - _perc="$((${_perc} ? ${_perc} / ${_max} : ${_perc}))"; - printf "%d\n" "${_perc}"; + local _rp_in="${1}" _rp_max="${2}" _rp_rs_out="${3#\$}" \ + _rp_perc; + + _rp_perc=$((100 * ${_rp_in} + ${_rp_max} / 2)); + _rp_perc=$((${_rp_perc} ? ${_rp_perc} / ${_rp_max} : ${_rp_perc})); + + eval ${_rp_rs_out}='${_rp_perc}'; + return 0; +}; + +rtl_percentage2() { + local _rp_rin="${1#\$}" _rp_rmax="${2#\$}" _rp_rs_out="${3#\$}" \ + _rp_in=0 _rp_max=0 _rp_perc; + + eval _rp_in=\"\${${_rp_rin}}\"; + eval _rp_max=\"\${${_rp_rmax}}\"; + + _rp_perc=$((100 * ${_rp_in} + ${_rp_max} / 2)); + _rp_perc=$((${_rp_perc} ? ${_rp_perc} / ${_rp_max} : ${_rp_perc})); + + eval ${_rp_rs_out}='${_rp_perc}'; + return 0; }; rtl_sunset() { local _rs_rset="${1#\$}" _rs_kname="" IFS=" "; - eval set -- '${'"${_rs_rset}"'}'; + + eval set -- "\${${_rs_rset}}"; while [ "${#}" -gt 0 ]; do unset "${_rs_rset}${_rs_kname}"; shift; done; unset "${_rs_rset}"; + + return 0; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_fetch.subr b/subr.rtl/rtl_fetch.subr index 5f557320..b40d11ba 100644 --- a/subr.rtl/rtl_fetch.subr +++ b/subr.rtl/rtl_fetch.subr @@ -2,66 +2,53 @@ # set +o errexit -o noglob -o nounset is assumed. # -# N.B. URLs ($1) may contain `?' or '&' characters. -rtl_fetch_url_wget() { - local _urls="${1}" _sha256sum_src="${2}" _target_dname="${3}" _target_fname="${4}" _target_name="${5}" _mirrors="${6:-}"\ - _rc=0 _sha256sum_target="" _target_fname_full="" _url="" _url_base="" _urls_count=0 _urls_full=""; +rtl_fetch_clean_dlcache() { + local _pfdcd_dlcachedir="${1}" _pfdcd_pkg_name="${2}" \ + _pfdcd_pkg_fname="${3}" _pfdcd_pkg_urls_git="${4}" \ + _pfdcd_fname="" _pfdcd_skipfl=0 _pfdcd_url_spec="" \ + _pfdcd_url_subdir=""; - _urls_full="${_urls}"; - for _url_base in ${_mirrors}; do - _urls_full="$(rtl_lconcat "${_urls_full}" "${_url_base%/}/${_target_name}/${_target_fname}")"; - done; - _urls_count="$(rtl_llength "${_urls_full}")"; - for _url in ${_urls_full}; do - if [ -z "${_target_fname}" ]; then - _target_fname="$(rtl_basename "${_url}")"; - fi; - _target_fname_full="${_target_dname}/${_target_fname}"; - (set +o errexit -o noglob -o nounset; - rtl_flock_acquire 4 || exit 1; - trap "_rc=\"\${?}\"; rm -f \"${_target_fname_full}.fetching\"; exit \"\${_rc}\";" EXIT; - if [ -z "${_sha256sum_src}" ]\ - || ! rtl_check_digest_file "${_target_fname_full}" "${_sha256sum_src}" "${_target_fname_full}.fetched"; then - wget ${DEFAULT_WGET_ARGS} -O "${_target_fname_full}" "${_url}"; _rc="${?}"; - if [ "${_rc}" -ne 0 ]; then - exit $((${_rc}+2)); - elif [ -n "${_sha256sum_src}" ]\ - && ! rtl_check_digest "${_target_fname_full}" "${_sha256sum_src}"; then - exit 2; - else - printf "%s" "${RTL_CHECK_DIGEST_DIGEST}" > "${_target_fname_full}.fetched"; exit 0; + for _pfdcd_fname in \ + $(cd "${_pfdcd_dlcachedir}/${_pfdcd_pkg_name}" 2>/dev/null && + find -maxdepth 1 -mindepth 1 \ + ${_pfdcd_pkg_fname:+-not -name "${_pfdcd_pkg_fname}"} \ + ${_pfdcd_pkg_fname:+-not -name "${_pfdcd_pkg_fname}.fetched"}); + do + _pfdcd_fname="${_pfdcd_fname#./}"; _pfdcd_skipfl=0; + + for _pfdcd_url_spec in ${_pfdcd_pkg_urls_git}; do + _pfdcd_url_subdir="${_pfdcd_url_spec%%=*}"; _pfdcd_url_subdir="${_pfdcd_url_subdir##*/}"; + if [ "${_pfdcd_fname%.git}" = "${_pfdcd_url_subdir}" ]; then + _pfdcd_skipfl=1; break; fi; - else - exit 0; - fi;) 4<>"${_target_fname_full}.fetching"; _rc="${?}"; : $((_urls_count-=1)); - case "${_rc}" in - 0) break; ;; - 1) if [ "${_urls_count}" -ge 1 ]; then - rtl_log_msg "warning" "${MSG_rtl_fetch_lockfail_retryurl}" "${_url}"; - else - rtl_log_msg "fatal" "${MSG_rtl_fetch_lockfail}" "${_url}"; - rtl_fileop rm "${_target_fname_full}"; break; - fi; ;; - 2) if [ "${_urls_count}" -ge 1 ]; then - rtl_log_msg "warning" "${MSG_rtl_fetch_hashfail_retryurl}" "${_url}" "${_sha256sum_src}"; - else - if _sha256sum_target="$(sha256sum "${_target_fname_full}" |\ - awk '{print $1}' 2>/dev/null)"; then - rtl_log_msg "fatal" "${MSG_rtl_fetch_hashfail1}" "${_url}" "${_sha256sum_src}" "${_sha256sum_target}"; - else - rtl_log_msg "fatal" "${MSG_rtl_fetch_hashfail2}" "${_url}" "${_sha256sum_src}"; - fi; - rtl_fileop rm "${_target_fname_full}"; break; - fi; ;; - *) if [ "${_urls_count}" -ge 1 ]; then - rtl_log_msg "warning" "${MSG_rtl_fetch_fail_retryurl}" "${_url}" "$((${_rc}-2))"; - else - rtl_log_msg "fatal" "${MSG_rtl_fetch_fail}" "${_url}" "$((${_rc}-2))"; - rtl_fileop rm "${_target_fname_full}"; break; - fi; ;; - esac; + done; + + if [ "${_pfdcd_skipfl}" -eq 0 ]; then + _pfdcd_fname="${_pfdcd_dlcachedir}/${_pfdcd_pkg_name}/${_pfdcd_fname}"; + rtl_log_msg "verbose" "${MSG_rtl_fetch_rm_redundant}" "${_pfdcd_fname}" "${_pfdcd_pkg_name}"; + rtl_fileop rm "${_pfdcd_fname}"; + fi; done; - return "${_rc}"; + + return 0; +}; + +rtl_fetch_dlcache_subdir() { + local _rfds_dlcache_dir="${1}" _rfds_name="${2}" _rfds_pkg_inherit_from="${3}"; + + if [ "${_rfds_pkg_inherit_from:+1}" = 1 ]\ + && ! [ -e "${_rfds_dlcache_dir}/${_rfds_name}" ]\ + && ! rtl_fileop ln_symbolic "${_rfds_pkg_inherit_from}" "${_rfds_dlcache_dir}/${_rfds_name}"; + then + return 1; + elif [ "${_rfds_pkg_inherit_from:+1}" != 1 ]\ + && ! [ -e "${_rfds_dlcache_dir}/${_rfds_name}" ]\ + && ! rtl_fileop mkdir "${_rfds_dlcache_dir}/${_rfds_name}"; + then + return 1; + else + return 0; + fi; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_fetch_git.subr b/subr.rtl/rtl_fetch_git.subr index d86db0de..bacb555c 100644 --- a/subr.rtl/rtl_fetch_git.subr +++ b/subr.rtl/rtl_fetch_git.subr @@ -3,68 +3,71 @@ # rtlp_fetch_url_git() { - local _cache_dname="${1}" _git_args="${2}" _git_branch="${3}" _mirrors="${4}" \ - _pkg_name="${5}" _subdir="${6}" _tgtdir="${7}" _url="${8}" _cache_dname_full="" \ - _clonefl=0 _git_pull_log_fname="" _oldpwd="" _url_base=""; + local _rpfug_cache_dname="${1}" _rpfug_git_args="${2}" _rpfug_git_branch="${3}" \ + _rpfug_mirrors="${4}" _rpfug_pkg_name="${5}" _rpfug_subdir="${6}" \ + _rpfug_tgtdir="${7}" _rpfug_url="${8}" \ + _rpfug_cache_dname_full="" _rpfug_clonefl=0 _rpfug_dname="" \ + _rpfug_git_pull_log_fname="" _rpfug_oldpwd="" _rpfug_url_base=""; - _cache_dname_full="${_cache_dname}/${_subdir##*/}"; + _rpfug_cache_dname_full="${_rpfug_cache_dname}/${_rpfug_subdir##*/}"; (set -o errexit -o noglob -o nounset; rtl_flock_acquire 4 || exit "${?}"; - trap "rm -f \"${_cache_dname_full%%[/]}.fetching\"" EXIT; - if [ -e "${_cache_dname_full}" ]; then - (rtl_fileop cd "${_cache_dname_full}" || exit 1; - _git_pull_log_fname="$(mktemp)" || exit 1; - trap 'rm -f "${_git_pull_log_fname}" 2>/dev/null' EXIT HUP INT TERM USR1 USR2; - if ! git pull ${_git_args} origin "${_git_branch:-main}" >"${_git_pull_log_fname}" 2>&1; then - if grep -q '^fatal: refusing to merge unrelated histories$' "${_git_pull_log_fname}"; then - cat "${_git_pull_log_fname}"; printf "Detected forced push(es).\n"; - elif grep -q '^Automatic merge failed; fix conflicts and then commit the result.$' "${_git_pull_log_fname}"; then - cat "${_git_pull_log_fname}"; printf "Detected forced push(es).\n"; git merge --abort; + trap "rm -f \"${_rpfug_cache_dname_full%%[/]}.fetching\"" EXIT; + if [ -e "${_rpfug_cache_dname_full}" ]; then + (rtl_fileop cd "${_rpfug_cache_dname_full}" || exit 1; + _rpfug_git_pull_log_fname="$(mktemp)" || exit 1; + trap 'rm -f "${_rpfug_git_pull_log_fname}" 2>/dev/null' EXIT HUP INT TERM USR1 USR2; + if ! git pull ${_rpfug_git_args} origin "${_rpfug_git_branch:-main}" >"${_rpfug_git_pull_log_fname}" 2>&1; then + if grep -q '^fatal: refusing to merge unrelated histories$' "${_rpfug_git_pull_log_fname}"; then + cat "${_rpfug_git_pull_log_fname}"; printf "Detected forced push(es).\n"; + elif grep -q '^Automatic merge failed; fix conflicts and then commit the result.$' "${_rpfug_git_pull_log_fname}"; then + cat "${_rpfug_git_pull_log_fname}"; printf "Detected forced push(es).\n"; git merge --abort; else - cat "${_git_pull_log_fname}"; exit 1; + cat "${_rpfug_git_pull_log_fname}"; exit 1; fi; while true; do printf "Attempting git-reset(1) --hard HEAD^ and git-pull(1)...\n"; if ! git reset --hard "HEAD^"; then exit 1; - elif git pull ${_git_args} origin "${_git_branch:-main}"; then + elif git pull ${_rpfug_git_args} origin "${_rpfug_git_branch:-main}"; then exit 0; fi; done; else - cat "${_git_pull_log_fname}"; exit 0; + cat "${_rpfug_git_pull_log_fname}"; exit 0; fi;) || return 1; - (rtl_fileop cd "${_cache_dname_full}" &&\ + (rtl_fileop cd "${_rpfug_cache_dname_full}" &&\ git submodule update) || return 1; - else if git clone ${_git_args} -b "${_git_branch:-main}" "${_url}" "${_cache_dname_full}"; then - _clonefl=1; - elif [ "${_mirrors}" = "skip" ]; then + else if git clone ${_rpfug_git_args} -b "${_rpfug_git_branch:-main}" "${_rpfug_url}" "${_rpfug_cache_dname_full}"; then + _rpfug_clonefl=1; + elif [ "${_rpfug_mirrors}" = "skip" ]; then return 1; - else for _url_base in ${_mirrors}; do - if git clone ${_git_args} -b "${_git_branch:-main}" "${_url_base}/${_pkg_name}/${_subdir}" "${_cache_dname_full}"; then - _clonefl=1; break; + else for _rpfug_url_base in ${_rpfug_mirrors}; do + if git clone ${_rpfug_git_args} -b "${_rpfug_git_branch:-main}" "${_rpfug_url_base}/${_rpfug_pkg_name}/${_rpfug_subdir}" "${_rpfug_cache_dname_full}"; then + _rpfug_clonefl=1; break; fi; done; fi; - if [ "${_clonefl}" -eq 0 ]; then + if [ "${_rpfug_clonefl}" -eq 0 ]; then return 1; - else if [ -n "${_git_branch}" ]; then - (rtl_fileop cd "${_cache_dname_full}" &&\ - git checkout "${_git_branch}") || return 1; + else if [ "${_rpfug_git_branch:+1}" = 1 ]; then + (rtl_fileop cd "${_rpfug_cache_dname_full}" &&\ + git checkout "${_rpfug_git_branch}") || return 1; fi; - (rtl_fileop cd "${_cache_dname_full}" &&\ + (rtl_fileop cd "${_rpfug_cache_dname_full}" &&\ git submodule update --init) || return 1; fi; fi; - if [ "${_cache_dname}" != "${_tgtdir}" ]; then - _oldpwd="${PWD}"; rtl_fileop cd "${_tgtdir}" || return 1; - rtl_fileop rm "${_tgtdir}/${_subdir}" || return 1; - if [ ! -e "$(rtl_dirname "${_tgtdir}/${_subdir}")" ]; then - rtl_fileop mkdir "$(rtl_dirname "${_tgtdir}/${_subdir}")"; + if [ "${_rpfug_cache_dname}" != "${_rpfug_tgtdir}" ]; then + _rpfug_oldpwd="${PWD}"; rtl_fileop cd "${_rpfug_tgtdir}" || return 1; + rtl_fileop rm "${_rpfug_tgtdir}/${_rpfug_subdir}" || return 1; + _rpfug_dname="${_rpfug_tgtdir}/${_rpfug_subdir}"; rtl_dirname \$_rpfug_dname; + if ! [ -e "${_rpfug_dname}" ]; then + rtl_fileop mkdir "${_rpfug_dname}"; fi; - rtl_fileop cp "${_cache_dname_full}" "${_tgtdir}/${_subdir}" || return 1; - rtl_fileop cd "${_oldpwd}" || return 1; - fi) 4<>"${_cache_dname_full%%[/]}.fetching"; + rtl_fileop cp "${_rpfug_cache_dname_full}" "${_rpfug_tgtdir}/${_rpfug_subdir}" || return 1; + rtl_fileop cd "${_rpfug_oldpwd}" || return 1; + fi) 4<>"${_rpfug_cache_dname_full%%[/]}.fetching"; if [ "${?}" -eq 0 ]; then cd "$(pwd)"; @@ -74,43 +77,56 @@ rtlp_fetch_url_git() { }; rtl_fetch_mirror_urls_git() { - local _git_args="${1}" _tgtdir="${2}" _rc=0 _repo_dname="" _subdir="" _url="" _url_spec=""; shift 2; + local _rfmug_git_args="${1}" _rfmug_tgtdir="${2}" \ + _rfmug_dname="" _rfmug_rc=0 _rfmug_repo_dname="" _rfmug_subdir="" \ + _rfmug_url="" _rfmug_url_spec=""; shift 2; - for _url_spec in "${@}"; do - _subdir="${_url_spec%=*}"; _subdir="${_subdir##*/}"; _url="${_url_spec#*=}"; _url="${_url%@*}"; - _repo_dname="${_subdir}"; [ "${_repo_dname%.git}" = "${_repo_dname}" ] && _repo_dname="${_repo_dname}.git"; + for _rfmug_url_spec in "${@}"; do + _rfmug_subdir="${_rfmug_url_spec%=*}"; _rfmug_subdir="${_rfmug_subdir##*/}"; _rfmug_url="${_rfmug_url_spec#*=}"; _rfmug_url="${_rfmug_url%@*}"; + _rfmug_repo_dname="${_rfmug_subdir}"; [ "${_rfmug_repo_dname%.git}" = "${_rfmug_repo_dname}" ] && _rfmug_repo_dname="${_rfmug_repo_dname}.git"; - if [ ! -e "$(rtl_dirname "${_tgtdir}")" ]; then - rtl_fileop mkdir "$(rtl_dirname "${_tgtdir}")"; + _rfmug_dname="${_rfmug_tgdir}"; rtl_dirname \$_rfmug_dname; + if ! [ -e "${_rfmug_dname}" ]; then + rtl_fileop mkdir "${_rfmug_dname}"; fi; (set -o errexit -o noglob -o nounset; rtl_flock_acquire 4 || exit "${?}"; - trap "rm -f \"${_tgtdir}/.fetching\"" EXIT; - if [ -e "${_tgtdir}/${_repo_dname}" ]; then - (rtl_fileop cd "${_tgtdir}/${_repo_dname}" && git fetch ${_git_args} --all) || return 1; - else (rtl_fileop cd "${_tgtdir}" && git clone ${_git_args} --mirror "${_url}" "${_repo_dname}") || return 1; - fi) 4<>"${_tgtdir}/.fetching"; + trap "rm -f \"${_rfmug_tgtdir}/.fetching\"" EXIT; + if [ -e "${_rfmug_tgtdir}/${_rfmug_repo_dname}" ]; then + (rtl_fileop cd "${_rfmug_tgtdir}/${_rfmug_repo_dname}" && git fetch ${_rfmug_git_args} --all) || return 1; + else (rtl_fileop cd "${_rfmug_tgtdir}" && git clone ${_rfmug_git_args} --mirror "${_rfmug_url}" "${_rfmug_repo_dname}") || return 1; + fi) 4<>"${_rfmug_tgtdir}/.fetching"; if [ "${?}" -ne 0 ]; then - _rc=1; + _rfmug_rc=1; fi; - done; return "${_rc}"; + done; + + return "${_rfmug_rc}"; }; rtl_fetch_urls_git() { - local _cache_dname="${1}" _git_args="${2}" _tgtdir="${3}" _pkg_name="${4}" _mirrors="${5}"\ - _git_branch="" _subdir="" _url="" _url_spec=""; shift 5; + local _rfug_cache_dname="${1}" _rfug_git_args="${2}" _rfug_tgtdir="${3}" \ + _rfug_pkg_name="${4}" _rfug_mirrors="${5}" \ + _rfug_git_branch="" _rfug_subdir="" _rfug_url="" _rfug_url_spec=""; shift 5; - for _url_spec in "${@}"; do - _subdir="${_url_spec%=*}"; _url="${_url_spec#*=}"; _url="${_url%@*}"; - if [ "${_url_spec#*@}" != "${_url_spec}" ]; then - _git_branch=${_url_spec#*@}; + for _rfug_url_spec in "${@}"; do + _rfug_subdir="${_rfug_url_spec%=*}"; + _rfug_url="${_rfug_url_spec#*=}"; + _rfug_url="${_rfug_url%@*}"; + if [ "${_rfug_url_spec#*@}" != "${_rfug_url_spec}" ]; then + _rfug_git_branch=${_rfug_url_spec#*@}; fi; if ! rtlp_fetch_url_git \ - "${_cache_dname}" "${_git_args}" "${_git_branch}" "${_mirrors}"\ - "${_pkg_name}" "${_subdir}" "${_tgtdir}" "${_url}"; then + "${_rfug_cache_dname}" "${_rfug_git_args}" \ + "${_rfug_git_branch}" "${_rfug_mirrors}" \ + "${_rfug_pkg_name}" "${_rfug_subdir}" \ + "${_rfug_tgtdir}" "${_rfug_url}"; + then return 1; fi; done; + + return 0; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_fetch_wget.subr b/subr.rtl/rtl_fetch_wget.subr new file mode 100644 index 00000000..e5a60677 --- /dev/null +++ b/subr.rtl/rtl_fetch_wget.subr @@ -0,0 +1,79 @@ +# +# set +o errexit -o noglob -o nounset is assumed. +# + +# N.B. URLs ($1) may contain `?' or '&' characters. +rtl_fetch_url_wget() { + local _rfuw_urls="${1}" _rfuw_sha256sum_src="${2}" _rfuw_target_dname="${3}" \ + _rfuw_target_fname="${4}" _rfuw_target_name="${5}" _rfuw_mirrors="${6:-}" \ + _rfuw_rc=0 _rfuw_sha256sum_target="" _rfuw_target_fname_full="" _rfuw_url="" \ + _rfuw_url_base="" _rfuw_urls_count=0 _rfuw_urls_full=""; + + _rfuw_urls_full="${_rfuw_urls}"; + for _rfuw_url_base in ${_rfuw_mirrors}; do + rtl_lconcat \$_rfuw_urls_full "${_rfuw_url_base%/}/${_rfuw_target_name}/${_rfuw_target_fname}"; + done; + rtl_llength \$_rfuw_urls_count \$_rfuw_urls_full; + + for _rfuw_url in ${_rfuw_urls_full}; do + if [ "${_rfuw_target_fname:+1}" != 1 ]; then + rtl_basename2 \$_rfuw_url \$_rfuw_target_fname; + fi; + _rfuw_target_fname_full="${_rfuw_target_dname}/${_rfuw_target_fname}"; + + (set +o errexit -o noglob -o nounset; + rtl_flock_acquire 4 || exit 1; + trap "_rfuw_rc=\"\${?}\"; rm -f \"${_rfuw_target_fname_full}.fetching\"; exit \"\${_rfuw_rc}\";" EXIT; + + if [ "${_rfuw_sha256sum_src:+1}" != 1 ]\ + || ! rtl_check_digest_file "${_rfuw_target_fname_full}" "${_rfuw_sha256sum_src}" "${_rfuw_target_fname_full}.fetched"; then + wget ${DEFAULT_WGET_ARGS} -O "${_rfuw_target_fname_full}" "${_rfuw_url}"; _rfuw_rc="${?}"; + if [ "${_rfuw_rc}" -ne 0 ]; then + exit $((${_rfuw_rc}+2)); + elif [ "${_rfuw_sha256sum_src:+1}" = 1 ]\ + && ! rtl_check_digest \$_digest "${_rfuw_target_fname_full}" "${_rfuw_sha256sum_src}"; then + exit 2; + else + printf "%s" "${_digest}" > "${_rfuw_target_fname_full}.fetched"; exit 0; + fi; + else + exit 0; + fi;) 4<>"${_rfuw_target_fname_full}.fetching"; _rfuw_rc="${?}"; : $((_rfuw_urls_count-=1)); + + case "${_rfuw_rc}" in + + 0) break; ;; + + 1) if [ "${_rfuw_urls_count}" -ge 1 ]; then + rtl_log_msg "warning" "${MSG_rtl_fetch_lockfail_retryurl}" "${_rfuw_url}"; + else + rtl_log_msg "fatal" "${MSG_rtl_fetch_lockfail}" "${_rfuw_url}"; + rtl_fileop rm "${_rfuw_target_fname_full}"; break; + fi; ;; + + 2) if [ "${_rfuw_urls_count}" -ge 1 ]; then + rtl_log_msg "warning" "${MSG_rtl_fetch_hashfail_retryurl}" "${_rfuw_url}" "${_rfuw_sha256sum_src}"; + else + if _rfuw_sha256sum_target="$(sha256sum "${_rfuw_target_fname_full}" |\ + awk '{print $1}' 2>/dev/null)"; then + rtl_log_msg "fatal" "${MSG_rtl_fetch_hashfail1}" "${_rfuw_url}" "${_rfuw_sha256sum_src}" "${_rfuw_sha256sum_target}"; + else + rtl_log_msg "fatal" "${MSG_rtl_fetch_hashfail2}" "${_rfuw_url}" "${_rfuw_sha256sum_src}"; + fi; + rtl_fileop rm "${_rfuw_target_fname_full}"; break; + fi; ;; + + *) if [ "${_rfuw_urls_count}" -ge 1 ]; then + rtl_log_msg "warning" "${MSG_rtl_fetch_fail_retryurl}" "${_rfuw_url}" "$((${_rfuw_rc}-2))"; + else + rtl_log_msg "fatal" "${MSG_rtl_fetch_fail}" "${_rfuw_url}" "$((${_rfuw_rc}-2))"; + rtl_fileop rm "${_rfuw_target_fname_full}"; break; + fi; ;; + + esac; + done; + + return "${_rfuw_rc}"; +}; + +# vim:filetype=sh diff --git a/subr.rtl/rtl_fileop.subr b/subr.rtl/rtl_fileop.subr index 6d258f5e..f6eae8fc 100644 --- a/subr.rtl/rtl_fileop.subr +++ b/subr.rtl/rtl_fileop.subr @@ -7,10 +7,8 @@ # rtlp_fileop_check() { - local _prefix="${1}" _pname="" _rname=""; shift; - while [ "${#}" -gt 0 ]; do - return 0; - shift; done; + local _rpfc_prefix="${1}" _rpfc_pname="" _rpfc_rname=""; shift; + return 0; }; rtlp_fileop_log() { @@ -22,65 +20,78 @@ rtlp_fileop_log() { # rtl_fileop() { - local _op="${1}" _dst="" _group="" _install_args="" _mode="" _owner="" _rc=0 _src=""; shift; - case "${_op}" in - cd) if [ \( -z "${1}" \) -o ! \( -L "${1}" -o -e "${1}" \) ]; then + local _rf_op="${1}" \ + _rf_dst="" _rf_group="" _rf_install_args="" \ + _rf_mode="" _rf_owner="" _rf_rc=0 _rf_src=""; shift; + + case "${_rf_op}" in + + cd) if [ \( "${1:+1}" != 1 \) -o ! \( -L "${1}" -o -e "${1}" \) ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invalid_dir}" "${1}"; elif rtlp_fileop_check "${PREFIX:-}" "${1}"; then rtlp_fileop_log "Changing working directory to \`${1}'."; - cd -- "${1}"; _rc="${?}"; + cd -- "${1}"; _rf_rc="${?}"; fi; ;; + chmod) if [ "${#}" -lt 2 ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_chmod}" "${*}"; - elif _mode="${1}" && shift\ + elif _rf_mode="${1}" && shift\ && rtlp_fileop_check "${PREFIX:-}" "${*}"; then - rtlp_fileop_log "Changing file mode bits of \`${*}' to \`${_mode}'."; - chmod -- "${_mode}" "${@}"; _rc="${?}"; + rtlp_fileop_log "Changing file mode bits of \`${*}' to \`${_rf_mode}'."; + chmod -- "${_rf_mode}" "${@}"; _rf_rc="${?}"; fi; ;; + chgrp) if [ "${#}" -lt 2 ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_chgrp}" "${*}"; - elif _group="${1}" && shift\ + elif _rf_group="${1}" && shift\ && rtlp_fileop_check "${PREFIX:-}" "${*}"; then - rtlp_fileop_log "Changing file group of \`${*}' to \`${_group}'."; - chgrp -- "${_group}" "${@}"; _rc="${?}"; + rtlp_fileop_log "Changing file group of \`${*}' to \`${_rf_group}'."; + chgrp -- "${_rf_group}" "${@}"; _rf_rc="${?}"; fi; ;; + chown) if [ "${#}" -lt 2 ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_chown}" "${*}"; - elif _owner="${1}" && shift\ + elif _rf_owner="${1}" && shift\ && rtlp_fileop_check "${PREFIX:-}" "${*}"; then - rtlp_fileop_log "Changing file owner of \`${*}' to \`${_owner}'."; - chown -- "${_owner}" "${@}"; _rc="${?}"; + rtlp_fileop_log "Changing file owner of \`${*}' to \`${_rf_owner}'."; + chown -- "${_rf_owner}" "${@}"; _rf_rc="${?}"; fi; ;; + cp_follow) if [ "${#}" -lt 2 ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_cp_follow}" "${*}"; elif rtlp_fileop_check "${PREFIX:-}" "${*}"; then - _src="${*}"; _src="${_src% *}"; - _dst="${*}"; _dst="${_dst##* }"; - rtlp_fileop_log "Copying \`${_src}' into \`${_dst}' w/ -pLR."; - cp -pLR -- "${@}"; _rc="${?}"; + _rf_src="${*}"; _rf_src="${_rf_src% *}"; + _rf_dst="${*}"; _rf_dst="${_rf_dst##* }"; + rtlp_fileop_log "Copying \`${_rf_src}' into \`${_rf_dst}' w/ -pLR."; + cp -pLR -- "${@}"; _rf_rc="${?}"; fi; ;; + cp) if [ "${#}" -lt 2 ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_cp}" "${*}"; elif rtlp_fileop_check "${PREFIX:-}" "${*}"; then - _src="${*}"; _src="${_src% *}"; - _dst="${*}"; _dst="${_dst##* }"; - rtlp_fileop_log "Copying \`${_src}' into \`${_dst}' w/ -pPR."; - cp -pPR -- "${@}"; _rc="${?}"; + _rf_src="${*}"; _rf_src="${_rf_src% *}"; + _rf_dst="${*}"; _rf_dst="${_rf_dst##* }"; + rtlp_fileop_log "Copying \`${_rf_src}' into \`${_rf_dst}' w/ -pPR."; + cp -pPR -- "${@}"; _rf_rc="${?}"; fi; ;; + install) if [ "${#}" -lt 2 ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_install}" "${*}"; - else _dst="$(while [ ""${#}"" -gt 2 ]; do shift; done; printf "%s" "${2}")"; - _install_args="$(while [ ""${#}"" -gt 2 ]; do printf "%s" "${1}"; shift; done)"; - _src="$(while [ ""${#}"" -gt 2 ]; do shift; done; printf "%s" "${1}")"; - if rtlp_fileop_check "${PREFIX:-}" "${_dst}" "${_src}"; then - rtlp_fileop_log "Installing \`${_src}' into \`${_dst}' w/ ${_install_args}."; - install "${@}"; _rc="${?}"; + else + rtl_lindexV \$_rf_dst -1 "${@}"; + rtl_lrangeV \$_rf_install_args 0 1 "${@}"; + rtl_lindexV \$_rf_install_args -2 "${@}"; + + if rtlp_fileop_check "${PREFIX:-}" "${_rf_dst}" "${_rf_src}"; then + rtlp_fileop_log "Installing \`${_rf_src}' into \`${_rf_dst}' w/ ${_rf_install_args}."; + install "${@}"; _rf_rc="${?}"; fi; fi; ;; + ln_symbolic) - if [ \( -z "${1}" \) -o \( -z "${2}" \) ]; then + if [ \( "${1:+1}" != 1 \) -o \( "${2:+1}" != 1 \) ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_ln_symbolic}" "${*}"; elif rtlp_fileop_check "${PREFIX:-}" "${2}"; then if rtl_fileop test "${2}"; then @@ -88,63 +99,70 @@ rtl_fileop() { fi; if [ "${?}" -eq 0 ]; then rtlp_fileop_log "Linking \`${1}' to \`${2}' w/ -fs"; - ln -fs -- "${1}" "${2}"; _rc="${?}"; + ln -fs -- "${1}" "${2}"; _rf_rc="${?}"; fi; fi; ;; - mv) if [ \( -z "${1}" \) -o \( -z "${2}" \) ]; then + + mv) if [ \( "${1:+1}" != 1 \) -o \( "${2:+1}" != 1 \) ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_mv}" "${*}"; elif rtlp_fileop_check "${PREFIX:-}" "${1}" "${2}"; then rtlp_fileop_log "Moving \`${1}' to \`${2}' w/ -fs"; - mv -f -- "${1}" "${2}"; _rc="${?}"; + mv -f -- "${1}" "${2}"; _rf_rc="${?}"; fi; ;; - touch) if [ -z "${1}" ]; then + + touch) if [ "${1:+1}" != 1 ]; then rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_touch}" "${*}"; elif rtlp_fileop_check "${PREFIX:-}" "${1}"; then rtlp_fileop_log "Touching file \`${1}'${2:+ w/ timestamp \`${2}\'}."; - touch ${2:+-t "${2}"} -- "${1}"; _rc="${?}"; + touch ${2:+-t "${2}"} -- "${1}"; _rf_rc="${?}"; fi; ;; + mkdir|mkfifo|rm|source|source_opt|test) while [ \( "${?}" -eq 0 \) -a \( ""${#}"" -gt 0 \) ]; do - if [ -z "${1}" ]; then - rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm}" "${_op}" "${*}"; - elif [ "${_op}" = mkdir ]\ + if [ "${1:+1}" != 1 ]; then + rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm}" "${_rf_op}" "${*}"; + elif [ "${_rf_op}" = mkdir ]\ && [ ! -d "${1}" ]\ && rtlp_fileop_check "${PREFIX:-}" "${1}"; then if rtl_fileop test "${1}"; then rtl_fileop rm "${1}"; fi; rtlp_fileop_log "Making directory \`${1}'."; - mkdir -p -- "${1}"; _rc="${?}"; - elif [ "${_op}" = mkfifo ]\ + mkdir -p -- "${1}"; _rf_rc="${?}"; + elif [ "${_rf_op}" = mkfifo ]\ && rtlp_fileop_check "${PREFIX:-}" "${1}"; then if rtl_fileop test "${1}"; then rtl_fileop rm "${1}"; fi; rtlp_fileop_log "Creating FIFO \`${1}'."; rtlp_fileop_check "${PREFIX:-}" "${1}"; - mkfifo -- "${1}"; _rc="${?}"; - elif [ "${_op}" = rm ]\ + mkfifo -- "${1}"; _rf_rc="${?}"; + elif [ "${_rf_op}" = rm ]\ && rtl_fileop test "${1}"\ && rtlp_fileop_check "${PREFIX:-}" "${1}"; then rtlp_fileop_log "Removing directory or file \`${1}'."; - rm -rf -- "${1}"; _rc="${?}"; - elif [ "${_op}" = source ]\ + rm -rf -- "${1}"; _rf_rc="${?}"; + elif [ "${_rf_op}" = source ]\ && rtlp_fileop_check "${PREFIX:-}" "${1}"; then rtlp_fileop_log "Sourcing file \`${1}'."; - . "${1}"; _rc="${?}"; - elif [ "${_op}" = source_opt ]\ + . "${1}"; _rf_rc="${?}"; + elif [ "${_rf_op}" = source_opt ]\ && rtl_fileop test "${1}"\ && rtlp_fileop_check "${PREFIX:-}" "${1}"; then rtlp_fileop_log "Sourcing file \`${1}'."; - . "${1}"; _rc="${?}"; - elif [ "${_op}" = test ]\ + . "${1}"; _rf_rc="${?}"; + elif [ "${_rf_op}" = test ]\ && rtlp_fileop_check "${PREFIX:-}" "${1}"\ && ! [ \( -L "${1}" \) -o \( -e "${1}" \) ]; then return 1; fi; shift; done; ;; + *) rtl_log_msg "fatalexit" "${MSG_rtl_fileop_invparm_fileop}" "${*}"; ;; - esac; return "${_rc}"; + + esac; + + return "${_rf_rc}"; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_filepath.subr b/subr.rtl/rtl_filepath.subr index 671f8534..a2b5bf41 100644 --- a/subr.rtl/rtl_filepath.subr +++ b/subr.rtl/rtl_filepath.subr @@ -3,16 +3,28 @@ # rtl_basename() { - local _fname="${1##*/}"; printf "%s" "${_fname}"; + rtl_basename2 "${1}" "${1}"; +}; + +rtl_basename2() { + local _rb2_rfname="${1#\$}" _rb2_rfname_out="${2#\$}" \ + _rb2_fname=""; + + eval _rb2_fname="\${${_rb2_rfname}}"; + eval ${_rb2_rfname_out}='${_rb2_fname##*/}'; + return 0; }; rtl_check_digest() { - local _fname="${1}" _digest_check="${2}" _digest=""; RTL_CHECK_DIGEST_DIGEST=""; - if ! [ -e "${_fname}" ]; then + local _rcd_rdigest="${1#\$}" _rcd_fname="${2}" _rcd_digest_check="${3}" \ + _rcd_digest=""; + + if ! [ -e "${_rcd_fname}" ]; then return 1; - else set -- $(sha256sum "${_fname}"); - RTL_CHECK_DIGEST_DIGEST="${1}"; - if [ "${RTL_CHECK_DIGEST_DIGEST}" = "${_digest_check}" ]; then + else set -- $(sha256sum "${_rcd_fname}"); + _rcd_digest="${1}"; + eval ${_rcd_rdigest}='${_rcd_digest}'; + if [ "${_rcd_digest}" = "${_rcd_digest_check}" ]; then return 0; else return 1; @@ -21,57 +33,88 @@ rtl_check_digest() { }; rtl_check_digest_file() { - local _fname="${1}" _digest_check="${2}" _digest_fname="${3}" _digest="" RTL_CHECK_DIGEST_DIGEST=""; - if ! [ -e "${_digest_fname}" ]; then + local _rcdf_fname="${1}" _rcdf_digest_check="${2}" _rcdf_digest_fname="${3}" \ + _rcdf_digest="" _rcdf_digest_file=""; + + if ! [ -e "${_rcdf_digest_fname}" ]; then return 1; - else _digest="$(cat "${_digest_fname}")"; - if [ "${_digest}" != "${_digest_check}" ]\ - || ! rtl_check_digest "${_fname}" "${_digest_check}"; then + else _rcdf_digest_file="$(cat "${_rcdf_digest_fname}")"; + if [ "${_rcdf_digest_file}" != "${_rcdf_digest_check}" ]\ + || ! rtl_check_digest \$_rcdf_digest "${_rcdf_fname}" \ + "${_rcdf_digest_check}"; + then return 1; + else + return 0; fi; fi; }; rtl_check_path_vars() { - local _vnames="${1}" _rc=0 _vname="" _vname_val=""; _status=""; - for _vname in ${_vnames}; do - _vname_val="$(rtl_get_var_unsafe "${_vname}")"; - if [ -z "${_vname_val}" ]; then - _rc=1; _status="Error: variable \`${_vname}' is empty or unset."; break; - elif [ "${_vname_val#* *}" != "${_vname_val}" ]; then - _rc=2; _status="Error: variable \`${_vname}' contains one or more whitespace characters."; break; + local _rcpv_rstatus="${1#\$}" _rcpv_vnames="${2}" \ + _rcpv_rc=0 _rcpv_vname="" _rcpv_vname_val=""; + + for _rcpv_vname in ${_rcpv_vnames}; do + rtl_get_var_unsafe \$_rcpv_vname_val "${_rcpv_vname}"; + if [ "${_rcpv_vname_val:+1}" != 1 ]; then + _rcpv_rc=1; + rtl_setrstatus "${_rcpv_rstatus}" 'Error: variable \`'"${_rcpv_vname}'"' is empty or unset.'; + break; + elif [ "${_rcpv_vname_val#* *}" != "${_rcpv_vname_val}" ]; then + _rcpv_rc=2; + rtl_setrstatus "${_rcpv_rstatus}" 'Error: variable \`'"${_rcpv_vname}'"' contains one or more whitespace characters.'; + break; fi; done; - return "${_rc}"; + return "${_rcpv_rc}"; }; rtl_dirname() { - local _dname="${1%/*}"; - case "${_dname}" in - "") _dname="."; ;; - *) while rtl_matchr "${_dname}" "*/"; do - _dname="${_dname%/}"; + rtl_dirname2 "${1}" "${1}"; +}; + +rtl_dirname2() { + local _rdname="${1#\$}" _rdname_out="${2#\$}" \ + _rd2_dname=""; + + eval _rd2_dname="\${${_rdname}}"; + _rd2_dname="${_rd2_dname%/*}"; + + case "${_rd2_dname}" in + "") _rd2_dname="."; ;; + *) while rtl_matchr "${_rd2_dname}" "*/"; do + _rd2_dname="${_rd2_dname%/}"; done; ;; - esac; printf "%s" "${_dname:-/}"; + esac; + + eval ${_rdname_out}='${_rd2_dname}'; + return 0; }; rtl_exists_any() { - local _subdir="${1}"; shift; + local _rea_subdir="${1}"; shift; + while [ "${#}" -gt 0 ]; do - if [ -e "${_subdir}/${1}" ]; then + if [ -e "${_rea_subdir}/${1}" ]; then return 0; else shift; fi; - done; return 1; + done; + return 1; }; rtl_flock_acquire() { - local _fd="${1}" _conflict_exit_code="${2:-253}" _wait="${3:-3600}" + local _rfa_fd="${1}" _rfa_conflict_exit_code="${2:-253}" _rfa_wait="${3:-3600}"; + while true; do - if flock -E "${_conflict_exit_code}" -w "${_wait}" "${_fd}"; then - break; - elif [ "${?}" -eq "${_conflict_exit_code}" ]; then + if flock \ + -E "${_rfa_conflict_exit_code}" \ + -w "${_rfa_wait}" \ + "${_rfa_fd}"; + then + return 0; + elif [ "${?}" -eq "${_rfa_conflict_exit_code}" ]; then continue; else return "${?}"; @@ -80,12 +123,16 @@ rtl_flock_acquire() { }; rtl_is_newer() { - local _new_fname="${1}" _old_fname="${2}" _new_ts="" _old_ts=""; - if ! [ -e "${_old_fname}" ]; then + local _ris_new_fname="${1}" _ris_old_fname="${2}" \ + _ris_new_ts="" _ris_old_ts=""; + + if ! [ -e "${_ris_old_fname}" ]; then return 0; - else _new_ts="$(stat -c %Y "${_new_fname}" 2>/dev/null)"; - _old_ts="$(stat -c %Y "${_old_fname}" 2>/dev/null)"; - if [ "${_new_ts:-0}" -gt "${_old_ts:-0}" ]; then + else + _ris_new_ts="$(stat -c %Y "${_ris_new_fname}" 2>/dev/null)"; + _ris_old_ts="$(stat -c %Y "${_ris_old_fname}" 2>/dev/null)"; + + if [ "${_ris_new_ts:-0}" -gt "${_ris_old_ts:-0}" ]; then return 0; else return 1; diff --git a/subr.rtl/rtl_install.subr b/subr.rtl/rtl_install.subr index db305cd0..36f5f28c 100644 --- a/subr.rtl/rtl_install.subr +++ b/subr.rtl/rtl_install.subr @@ -3,81 +3,89 @@ # rtl_install() { - local _verbose="" _prefix="" _chmod_mode="" _dname="" _file_fname_dst="" \ - _file_fname_src="" _fname="" _ln_fname="" _ln_target="" _owner_spec="" \ - _pname=""; - [ "${1}" = "-v" ] && { _verbose=1; shift; }; _prefix="${1}"; shift; + local _ri_verbose="" _ri_prefix="" \ + _ri_chmod_mode="" _ri_dname="" _ri_file_fname_dst="" _ri_file_fname_src="" \ + _ri_fname="" _ri_ln_fname="" _ri_ln_target="" _ri_owner_spec="" _ri_pname=""; + + if [ "${1}" = "-v" ]; then + _ri_verbose=1; shift; + fi; + _ri_prefix="${1}"; shift; while [ ${#} -gt 0 ]; do case "${1}" in + -*) - _pname="${1#-}"; - if [ "${_pname#/}" = "${_pname}" ]; then - _pname="${_prefix:+${_prefix}/}${_pname}"; + _ri_pname="${1#-}"; + if [ "${_ri_pname#/}" = "${_ri_pname}" ]; then + _ri_pname="${_ri_prefix:+${_ri_prefix}/}${_ri_pname}"; fi; - if ! rtl_fileop rm "${_pname}"; then + if ! rtl_fileop rm "${_ri_pname}"; then return 1; fi; ;; !*=*) - _file_fname_src="${1#!}"; _file_fname_src="${_file_fname_src%=*}"; - _file_fname_dst="${1#!}"; _file_fname_dst="${_file_fname_dst#*=}"; - if [ "${_file_fname_src#/}" = "${_file_fname_src}" ]; then - _file_fname_src="${_prefix:+${_prefix}/}${_file_fname_src}"; + _ri_file_fname_src="${1#!}"; _ri_file_fname_src="${_ri_file_fname_src%=*}"; + _ri_file_fname_dst="${1#!}"; _ri_file_fname_dst="${_ri_file_fname_dst#*=}"; + if [ "${_ri_file_fname_src#/}" = "${_ri_file_fname_src}" ]; then + _ri_file_fname_src="${_ri_prefix:+${_ri_prefix}/}${_ri_file_fname_src}"; fi; - if [ "${_file_fname_dst#/}" = "${_file_fname_dst}" ]; then - _file_fname_dst="${_prefix:+${_prefix}/}${_file_fname_dst}"; + if [ "${_ri_file_fname_dst#/}" = "${_ri_file_fname_dst}" ]; then + _ri_file_fname_dst="${_ri_prefix:+${_ri_prefix}/}${_ri_file_fname_dst}"; fi; - if ! rtl_fileop mv "${_file_fname_src}" "${_file_fname_dst}"; then + if ! rtl_fileop mv "${_ri_file_fname_src}" "${_ri_file_fname_dst}"; then return 1; fi; ;; /=*) - _dname="${1#/=}"; - if [ "${_dname#/}" = "${_dname}" ]; then - _dname="${_prefix:+${_prefix}/}${_dname}"; + _ri_dname="${1#/=}"; + if [ "${_ri_dname#/}" = "${_ri_dname}" ]; then + _ri_dname="${_ri_prefix:+${_ri_prefix}/}${_ri_dname}"; fi; - if ! rtl_fileop mkdir "${_dname}"; then + if ! rtl_fileop mkdir "${_ri_dname}"; then return 1; fi; ;; @*=*) - _ln_target="${1%=*}"; _ln_target="${_ln_target#@}"; _ln_fname="${1#*=}"; - if [ "${_ln_fname#/}" = "${_ln_fname}" ]; then - _ln_fname="${_prefix:+${_prefix}/}${_ln_fname}"; + _ri_ln_target="${1%=*}"; _ri_ln_target="${_ri_ln_target#@}"; _ri_ln_fname="${1#*=}"; + if [ "${_ri_ln_fname#/}" = "${_ri_ln_fname}" ]; then + _ri_ln_fname="${_ri_prefix:+${_ri_prefix}/}${_ri_ln_fname}"; fi; - if [ -e "${_ln_fname}" ]; then - rtl_fileop rm "${_ln_fname}"; + if [ -e "${_ri_ln_fname}" ]; then + rtl_fileop rm "${_ri_ln_fname}"; fi; - if ! rtl_fileop ln_symbolic "${_ln_target}" "${_ln_fname}"; then + if ! rtl_fileop ln_symbolic "${_ri_ln_target}" "${_ri_ln_fname}"; then return 1; fi; ;; m[0-7][0-7][0-7][0-7]=*) - _fname="${1#m[0-7][0-7][0-7][0-7]=}"; _chmod_mode="${1%%=*}"; _chmod_mode="${_chmod_mode#m}"; - if ! rtl_fileop chmod "${_chmod_mode}" "${_fname}"; then + _ri_fname="${1#m[0-7][0-7][0-7][0-7]=}"; _ri_chmod_mode="${1%%=*}"; _ri_chmod_mode="${_ri_chmod_mode#m}"; + if ! rtl_fileop chmod "${_ri_chmod_mode}" "${_ri_fname}"; then return 1; fi; ;; o*=*) - _fname="${1#o*=}"; _owner_spec="${1%%=*}"; _owner_spec="${_owner_spec#o}"; - if ! rtl_fileop chown "${_owner_spec}" "${_fname}"; then + _ri_fname="${1#o*=}"; _ri_owner_spec="${1%%=*}"; _ri_owner_spec="${_ri_owner_spec#o}"; + if ! rtl_fileop chown "${_ri_owner_spec}" "${_ri_fname}"; then return 1; fi; ;; *=*) - _file_fname_src="${1%=*}"; _file_fname_dst="${1#*=}"; - if [ "${_file_fname_src#/}" = "${_file_fname_src}" ]; then - _file_fname_src="${_prefix:+${_prefix}/}${_file_fname_src}"; + _ri_file_fname_src="${1%=*}"; _ri_file_fname_dst="${1#*=}"; + if [ "${_ri_file_fname_src#/}" = "${_ri_file_fname_src}" ]; then + _ri_file_fname_src="${_ri_prefix:+${_ri_prefix}/}${_ri_file_fname_src}"; fi; - if [ "${_file_fname_dst#/}" = "${_file_fname_dst}" ]; then - _file_fname_dst="${_prefix:+${_prefix}/}${_file_fname_dst}"; + if [ "${_ri_file_fname_dst#/}" = "${_ri_file_fname_dst}" ]; then + _ri_file_fname_dst="${_ri_prefix:+${_ri_prefix}/}${_ri_file_fname_dst}"; fi; - if ! rtl_fileop cp "${_file_fname_src}" "${_file_fname_dst}"; then + if ! rtl_fileop cp "${_ri_file_fname_src}" "${_ri_file_fname_dst}"; then return 1; fi; ;; + esac; shift; done; + + return 0; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_install_v2.subr b/subr.rtl/rtl_install_v2.subr index 0efeaac4..d4982556 100644 --- a/subr.rtl/rtl_install_v2.subr +++ b/subr.rtl/rtl_install_v2.subr @@ -2,7 +2,7 @@ # set +o errexit -o noglob -o nounset is assumed. # -RTLP_INSTALL_NL=" +RTL_NL=" "; # XXX optimise @@ -14,264 +14,305 @@ RTLP_INSTALL_NL=" # # DSL functor implementation # -# {{{ rtlp_install_fmap($_rparams, $_prefix, $_spec, $_fn, [$_param[...], --, [$_spec[...]]]) -rtlp_install_fmap() { - local _rif_rparams="${1#\$}" _rif_prefix="${2}" _rif_spec="${3}" \ - _rif_fn="${4}" _rif_IFS0="${IFS:- }" _rif_paramsc=0 \ - _rif_spec_cur="" _rif_spec_list="" _rif_spec0="" _rif_specsc=0 \ - _rif_nspec=0 _rif_rc=0 IFS; shift 4; +# {{{ rtlp_install_v2_fmap($_rstatus, $_rparams, $_prefix, $_spec, $_fn, [$_param[...], --, [$_spec[...]]]) +rtlp_install_v2_fmap() { + local _ri2f_rstatus="${1#\$}" _ri2f_rparams="${2#\$}" _ri2f_prefix="${3}" _ri2f_spec="${4}" _ri2f_fn="${5}" \ + _ri2f_IFS0="${IFS:- }" _ri2f_paramsc=0 _ri2f_spec_cur="" _ri2f_spec_list="" _ri2f_spec0="" \ + _ri2f_specsc=0 _ri2f_nspec=0 _ri2f_rc=0 IFS; + shift 5; + while [ "${#}" -gt 0 ] && [ "x${1}" != "x--" ]; do - : $((_rif_paramsc+=1)); local "${_rif_rparams}${_rif_paramsc}=${1}"; shift; + : $((_ri2f_paramsc+=1)); local "${_ri2f_rparams}${_ri2f_paramsc}=${1}"; shift; done; shift; while [ "${#}" -gt 0 ] && [ "x${1}" != "x--" ]; do - : $((_rif_specsc+=1)); local "_rif_specs${_rif_specsc}=${1}"; shift; + : $((_ri2f_specsc+=1)); local "_ri2f_specs${_ri2f_specsc}=${1}"; shift; done; - if rtlp_install_fmap_params "${_rif_rparams}" \$_rif_spec ""\ - && rtlp_install_fmap_patterns "${_rif_rparams}" "${_rif_prefix}" "${_rif_spec}" \$_rif_spec_list; then - IFS="${RTLP_INSTALL_NL}"; for _rif_spec_cur in ${_rif_spec_list}; do - IFS="${_rif_IFS0}"; set --; - _rif_nspec=1; while [ "${_rif_nspec}" -le "${_rif_specsc}" ]; do - eval _rif_spec0=\"\${_rif_specs${_rif_nspec}}\"; - rtlp_install_fmap_params \ - "${_rif_rparams}" \ - \$_rif_spec0 "${_rif_spec_cur}"; - eval set -- '"${@}"' '"${_rif_spec0}"'; : $((_rif_nspec+=1)); + if rtlp_install_v2_fmap_params "${_ri2f_rstatus}" "${_ri2f_rparams}" \$_ri2f_spec ""\ + && rtlp_install_v2_fmap_patterns "${_ri2f_rstatus}" "${_ri2f_rparams}" "${_ri2f_prefix}" "${_ri2f_spec}" \$_ri2f_spec_list; then + IFS="${RTL_NL}"; for _ri2f_spec_cur in ${_ri2f_spec_list}; do + IFS="${_ri2f_IFS0}"; set --; + _ri2f_nspec=1; while [ "${_ri2f_nspec}" -le "${_ri2f_specsc}" ]; do + eval _ri2f_spec0=\"\${_ri2f_specs${_ri2f_nspec}}\"; + rtlp_install_v2_fmap_params \ + "${_ri2f_rstatus}" \ + "${_ri2f_rparams}" \ + \$_ri2f_spec0 "${_ri2f_spec_cur}"; + eval set -- '"${@}"' '"${_ri2f_spec0}"'; : $((_ri2f_nspec+=1)); done; - eval "${_rif_fn}" \"\$\{@\}\"; _rif_rc=$((${?} ? ${?} : ${_rif_rc})); - [ "${_rif_rc}" -ne 0 ] && break; - done; IFS="${_rif_IFS0}"; + eval "${_ri2f_fn}" \"\$\{@\}\"; _ri2f_rc=$((${?} ? ${?} : ${_ri2f_rc})); + [ "${_ri2f_rc}" -ne 0 ] && break; + done; IFS="${_ri2f_IFS0}"; else - _rif_rc=1; + _ri2f_rc=1; fi; - return "${_rif_rc}"; + return "${_ri2f_rc}"; }; # }}} -# {{{ rtlp_install_fmap_params($_rparams, $_rspec, $_item) +# {{{ rtlp_install_v2_fmap_params($_rstatus, $_rparams, $_rspec, $_item) RTLP_INSTALL_FMAP_PARAMS_LEVEL=0; -rtlp_install_fmap_params() { - local _rifp_rparams="${1#\$}" _rifp_rspec="${2#\$}" _rifp_item="${3}" \ - _rifp_expr="" _rifp_expr_="" _rifp_expr_sub="" _rifp_expr_op="" \ - _rifp_lhs="" _rifp_rc=0 _rifp_rhs="" _rifp_subexpr=""; _status=""; - eval _rifp_lhs='${'"${_rifp_rspec}"'}'\; ${_rifp_rspec}=; +rtlp_install_v2_fmap_params() { + local _ri2fp_rstatus="${1#\$}" _ri2fp_rparams="${2#\$}" _ri2fp_rspec="${3#\$}" _ri2fp_item="${4}" \ + _ri2fp_expr="" _ri2fp_expr_="" _ri2fp_expr_sub="" _ri2fp_expr_op="" _ri2fp_lhs="" _ri2fp_rc=0 \ + _ri2fp_rhs="" _ri2fp_subexpr=""; + eval _ri2fp_lhs='${'"${_ri2fp_rspec}"'}'\; ${_ri2fp_rspec}=; while true; do - if ! rtlp_install_splitl_ref \$_rifp_expr \$_rifp_lhs \$_rifp_rhs '%[' ']'; then - eval ${_rifp_rspec}='${'"${_rifp_rspec}"'}${_rifp_lhs}'; break; - else case "${_rifp_expr}" in + if ! rtlp_install_v2_splitl_ref \$_ri2fp_expr \$_ri2fp_lhs \$_ri2fp_rhs '%[' ']'; then + eval ${_ri2fp_rspec}='${'"${_ri2fp_rspec}"'}${_ri2fp_lhs}'; break; + else + case "${_ri2fp_expr}" in + [0-9]*) - eval _rifp_expr='${'"${_rifp_rparams}${_rifp_expr}"'}'; ;; + eval _ri2fp_expr='${'"${_ri2fp_rparams}${_ri2fp_expr}"'}'; ;; + @[0-9]*) : $((RTLP_INSTALL_FMAP_PARAMS_LEVEL+=1)); - eval _rifp_expr${RTLP_INSTALL_FMAP_PARAMS_LEVEL}='${'"${_rifp_rparams}${_rifp_expr#@}"'}'; - rtlp_install_fmap_params "${_rifp_rparams}" \ - \$_rifp_expr${RTLP_INSTALL_FMAP_PARAMS_LEVEL} \ - "${_rifp_item}"; _rifp_rc="${?}"; - eval _rifp_expr='${_rifp_expr'"${RTLP_INSTALL_FMAP_PARAMS_LEVEL}"'}'; + eval _ri2fp_expr${RTLP_INSTALL_FMAP_PARAMS_LEVEL}='${'"${_ri2fp_rparams}${_ri2fp_expr#@}"'}'; + rtlp_install_v2_fmap_params "${_ri2fp_rstatus}" "${_ri2fp_rparams}" \ + \$_ri2fp_expr${RTLP_INSTALL_FMAP_PARAMS_LEVEL} \ + "${_ri2fp_item}"; _ri2fp_rc="${?}"; + eval _ri2fp_expr='${_ri2fp_expr'"${RTLP_INSTALL_FMAP_PARAMS_LEVEL}"'}'; + unset '_ri2fp_expr'"${RTLP_INSTALL_FMAP_PARAMS_LEVEL}"; : $((RTLP_INSTALL_FMAP_PARAMS_LEVEL-=1)); - [ "${_rifp_rc}" -eq 1 ] && break; ;; + [ "${_ri2fp_rc}" -eq 1 ] && break; ;; [_0-9a-zA-Z]*) - case "${_rifp_expr}" in - DNAME*) _rifp_subexpr="${_rifp_expr#DNAME}"; _rifp_expr="${_rifp_item%/*}"; ;; - FNAME*) _rifp_subexpr="${_rifp_expr#FNAME}"; _rifp_expr="${_rifp_item##*/}"; ;; - ITEM*) _rifp_subexpr="${_rifp_expr#ITEM}"; _rifp_expr="${_rifp_item}"; ;; - "") _rifp_rc=1; _status="zero-length parameter name in expression"; ;; + case "${_ri2fp_expr}" in + + DNAME*) _ri2fp_subexpr="${_ri2fp_expr#DNAME}"; _ri2fp_expr="${_ri2fp_item%/*}"; ;; + FNAME*) _ri2fp_subexpr="${_ri2fp_expr#FNAME}"; _ri2fp_expr="${_ri2fp_item##*/}"; ;; + ITEM*) _ri2fp_subexpr="${_ri2fp_expr#ITEM}"; _ri2fp_expr="${_ri2fp_item}"; ;; + + "") _ri2fp_rc=1; + rtl_setrstatus "${_ri2fp_rstatus}" 'zero-length parameter name in expression'; + ;; + *) - _rifp_expr_="${_rifp_expr%%[!_0-9a-zA-Z]*}"; - _rifp_subexpr="${_rifp_expr#${_rifp_expr_}}"; - _rifp_expr="${_rifp_expr_}"; - if eval [ '"${'"${_rifp_rparams}${_rifp_expr}"':+1}"' = 1 ]; then - eval _rifp_expr='${'"${_rifp_rparams}${_rifp_expr}"'}'; - else _rifp_rc=1; _status="unknown parameter name \`${_rifp_expr}' in expression"; - fi; ;; + _ri2fp_expr_="${_ri2fp_expr%%[!_0-9a-zA-Z]*}"; + _ri2fp_subexpr="${_ri2fp_expr#${_ri2fp_expr_}}"; + _ri2fp_expr="${_ri2fp_expr_}"; + if eval [ '"${'"${_ri2fp_rparams}${_ri2fp_expr}"':+1}"' = 1 ]; then + eval _ri2fp_expr='${'"${_ri2fp_rparams}${_ri2fp_expr}"'}'; + else _ri2fp_rc=1; + rtl_setrstatus "${_ri2fp_rstatus}" 'unknown parameter name \`'"${_ri2fp_expr}"''\'' in expression'; + fi; + ;; + esac; - if [ "${_rifp_rc}" -eq 0 ]; then + if [ "${_ri2fp_rc}" -eq 0 ]; then while true; do - if ! rtlp_install_splitl_subexpr \ - \$_rifp_subexpr_ \ - \$_rifp_subexpr \ + if ! rtlp_install_v2_splitl_subexpr \ + \$_ri2fp_subexpr_ \ + \$_ri2fp_subexpr \ '## # %% %'; then break; - else case "${_rifp_subexpr_}" in + else case "${_ri2fp_subexpr_}" in + /*) ;; - \#\#*) _rifp_expr="${_rifp_expr##${_rifp_subexpr_#\#\#}}"; ;; - \#*) _rifp_expr="${_rifp_expr#${_rifp_subexpr_#\#}}"; ;; - %%*) _rifp_expr="${_rifp_expr%%${_rifp_subexpr_#%%}}"; ;; - %*) _rifp_expr="${_rifp_expr%${_rifp_subexpr_#%}}"; ;; - "") _rifp_rc=1; _status="zero-length subexpression in expression"; ;; - *) _rifp_rc=1; _status="invalid subexpression \`${_rifp_subexpr_}' in expression"; ;; + \#\#*) _ri2fp_expr="${_ri2fp_expr##${_ri2fp_subexpr_#\#\#}}"; ;; + \#*) _ri2fp_expr="${_ri2fp_expr#${_ri2fp_subexpr_#\#}}"; ;; + %%*) _ri2fp_expr="${_ri2fp_expr%%${_ri2fp_subexpr_#%%}}"; ;; + %*) _ri2fp_expr="${_ri2fp_expr%${_ri2fp_subexpr_#%}}"; ;; + + "") _ri2fp_rc=1; + rtl_setrstatus "${_ri2fp_rstatus}" 'zero-length subexpression in expression'; + ;; + + *) _ri2fp_rc=1; + rtl_setrstatus "${_ri2fp_rstatus}" 'invalid subexpression \`'"${_ri2fp_subexpr_}"''\'' in expression'; + ;; + esac; fi; done; fi; ;; - "") _rifp_rc=1; _status="zero-length expression"; break; ;; - *) _rifp_rc=1; _status="invalid expression \`${_rifp_expr}'"; break; ;; + "") _ri2fp_rc=1; + rtl_setrstatus "${_ri2fp_rstatus}" 'zero-length expression'; + break; ;; + + *) _ri2fp_rc=1; + rtl_setrstatus "${_ri2fp_rstatus}" 'invalid expression \`'"${_ri2fp_expr}"''\'; + break; ;; + esac; fi; - eval ${_rifp_rspec}='${'"${_rifp_rspec}"'}${_rifp_lhs}${_rifp_expr}'; _rifp_lhs="${_rifp_rhs}"; - done; return "${_rifp_rc}"; + + eval ${_ri2fp_rspec}='${'"${_ri2fp_rspec}"'}${_ri2fp_lhs}${_ri2fp_expr}'; _ri2fp_lhs="${_ri2fp_rhs}"; + done; + + return "${_ri2fp_rc}"; }; # }}} -# {{{ rtlp_install_fmap_patterns($_rparams, $_prefix, $_spec, $_rspec_list) -rtlp_install_fmap_patterns() { - local _rifp2_rparams="${1#\$}" _rifp2_prefix="${2}" _rifp2_spec="${3}" \ - _rifp2_rspec_list="${4#\$}" _rifp2_expr="" _rifp2_lhs="" _rifp2_rc=0 \ - _rifp2_rhs="" IFS="${RTLP_INSTALL_NL}"; _status=""; - _rifp2_lhs="${_rifp2_spec}"; +# {{{ rtlp_install_v2_fmap_patterns($_rstatus, $_rparams, $_prefix, $_spec, $_rspec_list) +rtlp_install_v2_fmap_patterns() { + local _ri2fp2_rstatus="${1#\$}" _ri2fp2_rparams="${2#\$}" _ri2fp2_prefix="${3}" \ + _ri2fp2_spec="${4}" _ri2fp2_rspec_list="${5#\$}" \ + _ri2fp2_expr="" _ri2fp2_lhs="" _ri2fp2_rc=0 _ri2fp2_rhs="" \ + IFS="${RTL_NL}"; + _ri2fp2_lhs="${_ri2fp2_spec}"; while true; do - if rtlp_install_splitl_ref \$_rifp2_expr \$_rifp2_lhs \$_rifp2_rhs '%<' '>'; then - case "${_rifp2_expr}" in + if rtlp_install_v2_splitl_ref \$_ri2fp2_expr \$_ri2fp2_lhs \$_ri2fp2_rhs '%<' '>'; then + case "${_ri2fp2_expr}" in + *\**) - if [ "${_rifp2_lhs#/}" = "${_rifp2_lhs}" ]; then - _rifp2_lhs_full="${_rifp2_prefix:+${_rifp2_prefix%}/}${_rifp2_lhs:+${_rifp2_lhs%/}/}"; + if [ "${_ri2fp2_lhs#/}" = "${_ri2fp2_lhs}" ]; then + _ri2fp2_lhs_full="${_ri2fp2_prefix:+${_ri2fp2_prefix%}/}${_ri2fp2_lhs:+${_ri2fp2_lhs%/}/}"; else - _rifp2_lhs_full="${_rifp2_lhs:+${_rifp2_lhs%/}/}"; + _ri2fp2_lhs_full="${_ri2fp2_lhs:+${_ri2fp2_lhs%/}/}"; fi; - set +o noglob; for _rifp2_pname in ${_rifp2_lhs_full}${_rifp2_expr}; do - set -o noglob; _rifp2_pname="${_rifp2_pname%/}${_rifp2_rhs:+/${_rifp2_rhs}}"; - if [ -e "${_rifp2_pname}" ]; then - eval ${_rifp2_rspec_list}='${'"${_rifp2_rspec_list}"':+${'"${_rifp2_rspec_list}"'}${RTLP_INSTALL_NL}}${_rifp2_pname}'; + set +o noglob; for _ri2fp2_pname in ${_ri2fp2_lhs_full}${_ri2fp2_expr}; do + set -o noglob; _ri2fp2_pname="${_ri2fp2_pname%/}${_ri2fp2_rhs:+/${_ri2fp2_rhs}}"; + if [ -e "${_ri2fp2_pname}" ]; then + eval ${_ri2fp2_rspec_list}='${'"${_ri2fp2_rspec_list}"':+${'"${_ri2fp2_rspec_list}"'}${RTL_NL}}${_ri2fp2_pname}'; fi; done; set -o noglob; ;; - "") _rifp2_rc=1; _status="zero-length pattern"; break; ;; - *) _rifp2_rc=1; _status="invalid pattern \`${_rifp2_expr}'"; break; ;; - esac; _rifp2_lhs="${_rifp2_rhs}"; + "") _ri2fp2_rc=1; + rtl_setrstatus "${_ri2fp2_rstatus}" 'zero-length pattern'; + break; ;; + + *) _ri2fp2_rc=1; + rtl_setrstatus "${_ri2fp2_rstatus}" 'invalid pattern \`'"${_ri2fp2_expr}"''\'; + break; ;; + + esac; _ri2fp2_lhs="${_ri2fp2_rhs}"; else - eval ${_rifp2_rspec_list}='${'"${_rifp2_rspec_list}"':+${'"${_rifp2_rspec_list}"'}${RTLP_INSTALL_NL}}${_rifp2_lhs}'; + eval ${_ri2fp2_rspec_list}='${'"${_ri2fp2_rspec_list}"':+${'"${_ri2fp2_rspec_list}"'}${RTL_NL}}${_ri2fp2_lhs}'; break; fi; - done; return "${_rifp2_rc}"; + done; + + return "${_ri2fp2_rc}"; }; # }}} # # Install OPeration functions # -# {{{ rtlp_install_op_chmod($_nflag, $_prefix, $_vflag, $_fname, $_mode) -rtlp_install_op_chmod() { - local _rioc_nflag="${1}" _rioc_prefix="${2}" _rioc_vflag="${3}" _rioc_fname="${4}" _rioc_mode="${5}"; +# {{{ rtlp_install_v2_op_chmod($_nflag, $_prefix, $_vflag, $_fname, $_mode) +rtlp_install_v2_op_chmod() { + local _ri2oc_nflag="${1}" _ri2oc_prefix="${2}" _ri2oc_vflag="${3}" _ri2oc_fname="${4}" _ri2oc_mode="${5}"; - rtlp_install_fixup_fname \$_rioc_fname "${_rioc_prefix}"; - rtlp_install_rc "${_rioc_nflag}" "${_rioc_vflag}" rtl_fileop chmod "${_rioc_mode}" "${_rioc_fname}"; + rtlp_install_v2_fixup_fname \$_ri2oc_fname "${_ri2oc_prefix}"; + rtlp_install_v2_rc "${_ri2oc_nflag}" "${_ri2oc_vflag}" rtl_fileop chmod "${_ri2oc_mode}" "${_ri2oc_fname}"; }; # }}} -# {{{ rtlp_install_op_chgrp($_nflag, $_prefix, $_vflag, $_fname, $_group) -rtlp_install_op_chgrp() { - local _rioc2_nflag="${1}" _rioc2_prefix="${2}" _rioc2_vflag="${3}" _rioc2_fname="${4}" _rioc2_group="${5}"; +# {{{ rtlp_install_v2_op_chgrp($_nflag, $_prefix, $_vflag, $_fname, $_group) +rtlp_install_v2_op_chgrp() { + local _ri2oc2_nflag="${1}" _ri2oc2_prefix="${2}" _ri2oc2_vflag="${3}" _ri2oc2_fname="${4}" _ri2oc2_group="${5}"; - rtlp_install_fixup_fname \$_rioc2_fname "${_rioc2_prefix}"; - rtlp_install_rc "${_rioc2_nflag}" "${_rioc2_vflag}" rtl_fileop chgrp "${_rioc2_group}" "${_rioc2_fname}"; + rtlp_install_v2_fixup_fname \$_ri2oc2_fname "${_ri2oc2_prefix}"; + rtlp_install_v2_rc "${_ri2oc2_nflag}" "${_ri2oc2_vflag}" rtl_fileop chgrp "${_ri2oc2_group}" "${_ri2oc2_fname}"; }; # }}} -# {{{ rtlp_install_op_chown($_nflag, $_prefix, $_vflag, $_fname, $_owner) -rtlp_install_op_chown() { - local _rioc3_nflag="${1}" _rioc3_prefix="${2}" _rioc3_vflag="${3}" _rioc3_fname="${4}" _rioc3_owner="${5}"; +# {{{ rtlp_install_v2_op_chown($_nflag, $_prefix, $_vflag, $_fname, $_owner) +rtlp_install_v2_op_chown() { + local _ri2oc3_nflag="${1}" _ri2oc3_prefix="${2}" _ri2oc3_vflag="${3}" _ri2oc3_fname="${4}" _ri2oc3_owner="${5}"; - rtlp_install_fixup_fname \$_rioc3_fname "${_rioc3_prefix}"; - rtlp_install_rc "${_rioc3_nflag}" "${_rioc3_vflag}" rtl_fileop chown "${_rioc3_owner}" "${_rioc3_fname}"; + rtlp_install_v2_fixup_fname \$_ri2oc3_fname "${_ri2oc3_prefix}"; + rtlp_install_v2_rc "${_ri2oc3_nflag}" "${_ri2oc3_vflag}" rtl_fileop chown "${_ri2oc3_owner}" "${_ri2oc3_fname}"; }; # }}} -# {{{ rtlp_install_op_cp($_nflag, $_prefix, $_vflag, $_file_fname_dst, $_file_fname_src) -rtlp_install_op_cp() { - local _rioc4_nflag="${1}" _rioc4_prefix="${2}" _rioc4_vflag="${3}" _rioc4_fname_dst="${4}" _rioc4_fname_src="${5}"; +# {{{ rtlp_install_v2_op_cp($_nflag, $_prefix, $_vflag, $_file_fname_dst, $_file_fname_src) +rtlp_install_v2_op_cp() { + local _ri2oc4_nflag="${1}" _ri2oc4_prefix="${2}" _ri2oc4_vflag="${3}" _ri2oc4_fname_dst="${4}" _ri2oc4_fname_src="${5}"; - rtlp_install_fixup_fname \$_rioc4_fname_dst "${_rioc4_prefix}"; - rtlp_install_fixup_fname \$_rioc4_fname_src "${_rioc4_prefix}"; - rtlp_install_rc "${_rioc4_nflag}" "${_rioc4_vflag}" rtl_fileop cp "${_rioc4_fname_src}" "${_rioc4_fname_dst}"; + rtlp_install_v2_fixup_fname \$_ri2oc4_fname_dst "${_ri2oc4_prefix}"; + rtlp_install_v2_fixup_fname \$_ri2oc4_fname_src "${_ri2oc4_prefix}"; + rtlp_install_v2_rc "${_ri2oc4_nflag}" "${_ri2oc4_vflag}" rtl_fileop cp "${_ri2oc4_fname_src}" "${_ri2oc4_fname_dst}"; }; # }}} -# {{{ rtlp_install_op_cp_follow_if_newer($_nflag, $_prefix, $_vflag, $_file_fname_dst, $_file_fname_src) -rtlp_install_op_cp_follow_if_newer() { - local _riocfin_nflag="${1}" _riocfin_prefix="${2}" _riocfin_vflag="${3}" _riocfin_fname_dst="${4}" _riocfin_fname_src="${5}"; - - rtlp_install_fixup_fname \$_riocfin_fname_dst "${_riocfin_prefix}"; - rtlp_install_fixup_fname \$_riocfin_fname_src "${_riocfin_prefix}"; - if [ -e "${_riocfin_fname_dst}" ]\ - && rtl_is_newer "${_riocfin_fname_src}" "${_riocfin_fname_dst}"; then +# {{{ rtlp_install_v2_op_cp_follow_if_newer($_nflag, $_prefix, $_vflag, $_file_fname_dst, $_file_fname_src) +rtlp_install_v2_op_cp_follow_if_newer() { + local _ri2ocfin_nflag="${1}" _ri2ocfin_prefix="${2}" _ri2ocfin_vflag="${3}" _ri2ocfin_fname_dst="${4}" _ri2ocfin_fname_src="${5}"; + + rtlp_install_v2_fixup_fname \$_ri2ocfin_fname_dst "${_ri2ocfin_prefix}"; + rtlp_install_v2_fixup_fname \$_ri2ocfin_fname_src "${_ri2ocfin_prefix}"; + if [ -e "${_ri2ocfin_fname_dst}" ]\ + && rtl_is_newer "${_ri2ocfin_fname_src}" "${_ri2ocfin_fname_dst}"; then return 0; else - rtlp_install_rc "${_riocfin_nflag}" "${_riocfin_vflag}" rtl_fileop cp_follow "${_riocfin_fname_src}" "${_riocfin_fname_dst}"; + rtlp_install_v2_rc "${_ri2ocfin_nflag}" "${_ri2ocfin_vflag}" rtl_fileop cp_follow "${_ri2ocfin_fname_src}" "${_ri2ocfin_fname_dst}"; fi; }; # }}} -# {{{ rtlp_install_op_ln_symbolic($_nflag, $_prefix, $_vflag, $_ln_fname, $_ln_target) -rtlp_install_op_ln_symbolic() { - local _riols_nflag="${1}" _riols_prefix="${2}" _riols_vflag="${3}" _riols_ln_fname="${4}" _riols_ln_target="${5}"; +# {{{ rtlp_install_v2_op_ln_symbolic($_nflag, $_prefix, $_vflag, $_ln_fname, $_ln_target) +rtlp_install_v2_op_ln_symbolic() { + local _ri2ols_nflag="${1}" _ri2ols_prefix="${2}" _ri2ols_vflag="${3}" _ri2ols_ln_fname="${4}" _ri2ols_ln_target="${5}"; - rtlp_install_fixup_fname \$_riols_ln_fname "${_riols_prefix}"; - if [ -e "${_riols_ln_fname}" ]; then - rtlp_install_rc "${_riols_nflag}" "${_riols_vflag}" rtl_fileop rm "${_riols_ln_fname}"; + rtlp_install_v2_fixup_fname \$_ri2ols_ln_fname "${_ri2ols_prefix}"; + if [ -e "${_ri2ols_ln_fname}" ]; then + rtlp_install_v2_rc "${_ri2ols_nflag}" "${_ri2ols_vflag}" rtl_fileop rm "${_ri2ols_ln_fname}"; fi; - rtlp_install_rc "${_riols_nflag}" "${_riols_vflag}" rtl_fileop ln_symbolic "${_riols_ln_target}" "${_riols_ln_fname}"; + rtlp_install_v2_rc "${_ri2ols_nflag}" "${_ri2ols_vflag}" rtl_fileop ln_symbolic "${_ri2ols_ln_target}" "${_ri2ols_ln_fname}"; }; # }}} -# {{{ rtlp_install_op_mkdir($_nflag, $_prefix, $_vflag, $_dname) -rtlp_install_op_mkdir() { - local _riom_nflag="${1}" _riom_prefix="${2}" _riom_vflag="${3}" _riom_dname="${4}"; +# {{{ rtlp_install_v2_op_mkdir($_nflag, $_prefix, $_vflag, $_dname) +rtlp_install_v2_op_mkdir() { + local _ri2om_nflag="${1}" _ri2om_prefix="${2}" _ri2om_vflag="${3}" _ri2om_dname="${4}"; - rtlp_install_fixup_fname \$_riom_dname "${_riom_prefix}"; - rtlp_install_rc "${_riom_nflag}" "${_riom_vflag}" rtl_fileop mkdir "${_riom_dname}"; + rtlp_install_v2_fixup_fname \$_ri2om_dname "${_ri2om_prefix}"; + rtlp_install_v2_rc "${_ri2om_nflag}" "${_ri2om_vflag}" rtl_fileop mkdir "${_ri2om_dname}"; }; # }}} -# {{{ rtlp_install_op_mv($_nflag, $_prefix, $_vflag, $_file_fname_dst, $_file_fname_src) -rtlp_install_op_mv() { - local _riom2_nflag="${1}" _riom2_prefix="${2}" _riom2_vflag="${3}" _riom2_fname_dst="${4}" _riom2_fname_src="${5}"; +# {{{ rtlp_install_v2_op_mv($_nflag, $_prefix, $_vflag, $_file_fname_dst, $_file_fname_src) +rtlp_install_v2_op_mv() { + local _ri2om2_nflag="${1}" _ri2om2_prefix="${2}" _ri2om2_vflag="${3}" _ri2om2_fname_dst="${4}" _ri2om2_fname_src="${5}"; - rtlp_install_fixup_fname \$_riom2_fname_dst "${_riom2_prefix}"; - rtlp_install_fixup_fname \$_riom2_fname_src "${_riom2_prefix}"; - rtlp_install_rc "${_riom2_nflag}" "${_riom2_vflag}" rtl_fileop mv "${_riom2_fname_src}" "${_riom2_fname_dst}"; + rtlp_install_v2_fixup_fname \$_ri2om2_fname_dst "${_ri2om2_prefix}"; + rtlp_install_v2_fixup_fname \$_ri2om2_fname_src "${_ri2om2_prefix}"; + rtlp_install_v2_rc "${_ri2om2_nflag}" "${_ri2om2_vflag}" rtl_fileop mv "${_ri2om2_fname_src}" "${_ri2om2_fname_dst}"; }; # }}} -# {{{ rtlp_install_op_rm($_nflag, $_prefix, $_vflag, $_pname) -rtlp_install_op_rm() { - local _rior_nflag="${1}" _rior_prefix="${2}" _rior_vflag="${3}" _rior_pname="${4}"; +# {{{ rtlp_install_v2_op_rm($_nflag, $_prefix, $_vflag, $_pname) +rtlp_install_v2_op_rm() { + local _ri2or_nflag="${1}" _ri2or_prefix="${2}" _ri2or_vflag="${3}" _ri2or_pname="${4}"; - rtlp_install_fixup_fname \$_rior_pname "${_rior_prefix}"; - rtlp_install_rc "${_rior_nflag}" "${_rior_vflag}" rtl_fileop rm "${_rior_pname}"; + rtlp_install_v2_fixup_fname \$_ri2or_pname "${_ri2or_prefix}"; + rtlp_install_v2_rc "${_ri2or_nflag}" "${_ri2or_vflag}" rtl_fileop rm "${_ri2or_pname}"; }; # }}} -# {{{ rtlp_install_op_touch($_nflag, $_prefix, $_vflag, $_fname, $_ts) -rtlp_install_op_touch() { - local _riot_nflag="${1}" _riot_prefix="${2}" _riot_vflag="${3}" _riot_fname="${4}" _riot_ts="${5:-}"; +# {{{ rtlp_install_v2_op_touch($_nflag, $_prefix, $_vflag, $_fname, $_ts) +rtlp_install_v2_op_touch() { + local _ri2ot_nflag="${1}" _ri2ot_prefix="${2}" _ri2ot_vflag="${3}" _ri2ot_fname="${4}" _ri2ot_ts="${5:-}"; - rtlp_install_fixup_fname \$_riot_fname "${_riot_prefix}"; - rtlp_install_rc "${_riot_nflag}" "${_riot_vflag}" rtl_fileop touch "${_riot_fname}" "${_riot_ts}"; + rtlp_install_v2_fixup_fname \$_ri2ot_fname "${_ri2ot_prefix}"; + rtlp_install_v2_rc "${_ri2ot_nflag}" "${_ri2ot_vflag}" rtl_fileop touch "${_ri2ot_fname}" "${_ri2ot_ts}"; }; # }}} # # Ancillary functions # -# {{{ rtlp_install_fixup_fname($_rfname, $_prefix) -rtlp_install_fixup_fname() { - local _riff_rfname="${1#\$}" __riff_prefix="${2}" _riff_fname=""; - eval _riff_fname='${'"${_riff_rfname}"'}'; +# {{{ rtlp_install_v2_fixup_fname($_rfname, $_prefix) +rtlp_install_v2_fixup_fname() { + local _ri2ff_rfname="${1#\$}" _ri2ff_prefix="${2}" _ri2ff_fname=""; + eval _ri2ff_fname='${'"${_ri2ff_rfname}"'}'; - if [ "${_riff_fname#/}" = "${_riff_fname}" ]; then - eval ${_riff_rfname}='${__riff_prefix:+${__riff_prefix}/}${_riff_fname}'; + if [ "${_ri2ff_fname#/}" = "${_ri2ff_fname}" ]; then + eval ${_ri2ff_rfname}='${_ri2ff_prefix:+${_ri2ff_prefix}/}${_ri2ff_fname}'; fi; }; # }}} -# {{{ rtlp_install_rc($_nflag, $_vflag, $_fn, [...]) -rtlp_install_rc() { - local _rir_nflag="${1}" _rir_vflag="${2}" _rir_fn="${3}" _rir_rc=0; shift 3; +# {{{ rtlp_install_v2_rc($_nflag, $_vflag, $_fn, [...]) +rtlp_install_v2_rc() { + local _ri2r_nflag="${1}" _ri2r_vflag="${2}" _ri2r_fn="${3}" _ri2r_rc=0; shift 3; - if [ "${_rir_nflag}" -eq 1 ]\ - || [ "${_rir_vflag}" -gt 0 ]; then - rtl_log_msg "install" "${MSG_rtl_install_v2_rc}" "${_rir_fn}${_rir_fn:+ ${*}}"; + if [ "${_ri2r_nflag}" -eq 1 ]\ + || [ "${_ri2r_vflag}" -gt 0 ]; then + rtl_log_msg "install" "${MSG_rtl_install_v2_rc}" "${_ri2r_fn}${_ri2r_fn:+ ${*}}"; fi; - if [ "${_rir_nflag}" -eq 0 ]; then - "${_rir_fn}" "${@}"; _rir_rc="${?}"; + if [ "${_ri2r_nflag}" -eq 0 ]; then + "${_ri2r_fn}" "${@}"; _ri2r_rc="${?}"; fi; - return "${_rir_rc}"; + return "${_ri2r_rc}"; }; # }}} -# {{{ rtlp_install_splitl($_rlhs, $_rrhs, $_sep) +# {{{ rtlp_install_v2_splitl($_rlhs, $_rrhs, $_sep) # -# rtlp_install_splitl() +# rtlp_install_v2_splitl() # Split @_rlhs from left-hand side into left-hand and right-hand side # according to @_sep w/ backslash escaping # @@ -283,29 +324,30 @@ rtlp_install_rc() { # Notate bene: @_sep is a shell pattern # Returns: zero (0) on success, non-zero (>0) on absence of unescaped @_sep in @_rlhs # -rtlp_install_splitl() { - local _ris_rlhs="${1#\$}" _ris_rrhs="${2#\$}" _ris_sep="${3}" _ris_lhs="" \ - _ris_lhs_new="" _ris_rc=1 _ris_rhs="" _ris_rhs_new=""; - - eval _ris_rhs='${'"${_ris_rlhs}"'}'; - while [ "${_ris_rhs:+1}" = 1 ]; do - _ris_lhs_new="${_ris_rhs%%${_ris_sep}*}"; - if [ "${_ris_lhs_new}" != "${_ris_rhs}" ]; then - _ris_rhs_new="${_ris_rhs#*${_ris_sep}}"; - if [ "${_ris_lhs_new%\\}" = "${_ris_lhs_new}" ]; then - eval ${_ris_rlhs}='${_ris_lhs}${_ris_lhs_new}' \ - ${_ris_rrhs}='${_ris_rhs_new}'; _ris_rc=0; break; +rtlp_install_v2_splitl() { + local _ri2s_rlhs="${1#\$}" _ri2s_rrhs="${2#\$}" _ri2s_sep="${3}" _ri2s_lhs="" \ + _ri2s_lhs_new="" _ri2s_rc=1 _ri2s_rhs="" _ri2s_rhs_new=""; + + eval _ri2s_rhs='${'"${_ri2s_rlhs}"'}'; + while [ "${_ri2s_rhs:+1}" = 1 ]; do + _ri2s_lhs_new="${_ri2s_rhs%%${_ri2s_sep}*}"; + if [ "${_ri2s_lhs_new}" != "${_ri2s_rhs}" ]; then + _ri2s_rhs_new="${_ri2s_rhs#*${_ri2s_sep}}"; + if [ "${_ri2s_lhs_new%\\}" = "${_ri2s_lhs_new}" ]; then + eval ${_ri2s_rlhs}='${_ri2s_lhs}${_ri2s_lhs_new}' \ + ${_ri2s_rrhs}='${_ri2s_rhs_new}'; _ri2s_rc=0; break; else - _ris_lhs="${_ris_lhs}${_ris_lhs_new%\\}${_ris_sep}"; - _ris_rhs="${_ris_rhs_new}"; + _ri2s_lhs="${_ri2s_lhs}${_ri2s_lhs_new%\\}${_ri2s_sep}"; + _ri2s_rhs="${_ri2s_rhs_new}"; fi; else break; fi; - done; return "${_ris_rc}"; + done; + return "${_ri2s_rc}"; }; # }}} -# {{{ rtlp_install_splitl_ref($_ritem, $_rlhs, $_rrhs, $_sepl, $_sepr) +# {{{ rtlp_install_v2_splitl_ref($_ritem, $_rlhs, $_rrhs, $_sepl, $_sepr) # -# rtlp_install_splitl_ref() +# rtlp_install_v2_splitl_ref() # Split @_rlhs from left-hand side into left-hand, reference, and # right-hand side according to left-hand (beginning) and right-hand # (ending) side separators w/ backslash escaping @@ -320,48 +362,48 @@ rtlp_install_splitl() { # Notate bene: @_sepl and @_sepr are shell patterns # Returns: zero (0) on success, non-zero (>0) on absence of unescaped references in @_rlhs # -rtlp_install_splitl_ref() { - local _risr_rref="${1#\$}" _risr_rlhs="${2#\$}" _risr_rrhs="${3#\$}" _risr_sepl="${4}" \ - _risr_sepr="${5}" _risr_item="" _risr_item_lhs="" _risr_item_lhs_new="" \ - _risr_item_rhs="" _risr_item_rhs_new="" _risr_lhs="" _risr_lhs_new="" _risr_rc=1 \ - _risr_rhs="" _risr_rhs_new=""; - - eval _risr_rhs='${'"${_risr_rlhs}"'}'; - while [ "${_risr_rhs:+1}" = 1 ]; do - _risr_lhs_new="${_risr_rhs%%${_risr_sepl}*}"; - if [ "${_risr_lhs_new}" != "${_risr_rhs}" ]; then - _risr_rhs_new="${_risr_rhs#*${_risr_sepl}}"; - if [ "${_risr_lhs_new%\\}" = "${_risr_lhs_new}" ]; then - _risr_item=""; _risr_item_lhs=""; _risr_item_rhs="${_risr_rhs_new}"; - while [ "${_risr_item_rhs:+1}" = 1 ]; do - _risr_item_lhs_new="${_risr_item_rhs%%${_risr_sepr}*}"; - if [ "${_risr_item_lhs_new}" != "${_risr_item_rhs}" ]; then - _risr_item_rhs_new="${_risr_item_rhs#*${_risr_sepr}}"; - if [ "${_risr_item_lhs_new%\\}" = "${_risr_item_lhs_new}" ]; then - _risr_item="${_risr_item_lhs}${_risr_item_lhs_new}"; - _risr_item_rhs="${_risr_item_rhs_new}"; - _risr_rc=0; break; +rtlp_install_v2_splitl_ref() { + local _ri2sr_rref="${1#\$}" _ri2sr_rlhs="${2#\$}" _ri2sr_rrhs="${3#\$}" _ri2sr_sepl="${4}" \ + _ri2sr_sepr="${5}" _ri2sr_item="" _ri2sr_item_lhs="" _ri2sr_item_lhs_new="" \ + _ri2sr_item_rhs="" _ri2sr_item_rhs_new="" _ri2sr_lhs="" _ri2sr_lhs_new="" _ri2sr_rc=1 \ + _ri2sr_rhs="" _ri2sr_rhs_new=""; + + eval _ri2sr_rhs='${'"${_ri2sr_rlhs}"'}'; + while [ "${_ri2sr_rhs:+1}" = 1 ]; do + _ri2sr_lhs_new="${_ri2sr_rhs%%${_ri2sr_sepl}*}"; + if [ "${_ri2sr_lhs_new}" != "${_ri2sr_rhs}" ]; then + _ri2sr_rhs_new="${_ri2sr_rhs#*${_ri2sr_sepl}}"; + if [ "${_ri2sr_lhs_new%\\}" = "${_ri2sr_lhs_new}" ]; then + _ri2sr_item=""; _ri2sr_item_lhs=""; _ri2sr_item_rhs="${_ri2sr_rhs_new}"; + while [ "${_ri2sr_item_rhs:+1}" = 1 ]; do + _ri2sr_item_lhs_new="${_ri2sr_item_rhs%%${_ri2sr_sepr}*}"; + if [ "${_ri2sr_item_lhs_new}" != "${_ri2sr_item_rhs}" ]; then + _ri2sr_item_rhs_new="${_ri2sr_item_rhs#*${_ri2sr_sepr}}"; + if [ "${_ri2sr_item_lhs_new%\\}" = "${_ri2sr_item_lhs_new}" ]; then + _ri2sr_item="${_ri2sr_item_lhs}${_ri2sr_item_lhs_new}"; + _ri2sr_item_rhs="${_ri2sr_item_rhs_new}"; + _ri2sr_rc=0; break; else - _risr_item_lhs="${_risr_item_lhs}${_risr_item_lhs_new%\\}${_risr_sepr}"; - _risr_item_rhs="${_risr_item_rhs_new}"; + _ri2sr_item_lhs="${_ri2sr_item_lhs}${_ri2sr_item_lhs_new%\\}${_ri2sr_sepr}"; + _ri2sr_item_rhs="${_ri2sr_item_rhs_new}"; fi; else break; fi; done; break; else - _risr_lhs="${_risr_lhs}${_risr_lhs_new%\\}${_risr_sepl}"; _risr_rhs="${_risr_rhs_new}"; + _ri2sr_lhs="${_ri2sr_lhs}${_ri2sr_lhs_new%\\}${_ri2sr_sepl}"; _ri2sr_rhs="${_ri2sr_rhs_new}"; fi; else break; fi; done; - eval ${_risr_rref}='${_risr_item}' \ - ${_risr_rlhs}='${_risr_lhs}${_risr_lhs_new}' \ - ${_risr_rrhs}='${_risr_item_rhs}'; - return "${_risr_rc}"; + eval ${_ri2sr_rref}='${_ri2sr_item}' \ + ${_ri2sr_rlhs}='${_ri2sr_lhs}${_ri2sr_lhs_new}' \ + ${_ri2sr_rrhs}='${_ri2sr_item_rhs}'; + return "${_ri2sr_rc}"; }; # }}} -# {{{ rtlp_install_splitl_subexpr($_rexpr, $_rlhs, $_lsep) +# {{{ rtlp_install_v2_splitl_subexpr($_rexpr, $_rlhs, $_lsep) # -# rtlp_install_splitl_subexpr() +# rtlp_install_v2_splitl_subexpr() # Split @_rlhs from left-hand side into left-hand (subexpression) and right-hand # side according to list of expression operator prefixes w/ backslash escaping # @@ -373,69 +415,77 @@ rtlp_install_splitl_ref() { # Notate bene: @_lsep list items are shell patterns # Returns: zero (0) on success, non-zero (>0) on absence of unescaped expressions in @_rlhs # -rtlp_install_splitl_subexpr() { - local _riss_rexpr="${1#\$}" _riss_rlhs="${2#\$}" _riss_lsep="${3}" _riss_lhs="" \ - _riss_matchfl="" _riss_nsep="" _riss_rc=1 _riss_sep="" _riss_sexpr="" \ - _riss_sexpr_lhs="" _riss_sexpr_lhs_new="" _riss_sexpr_rhs="" \ - _riss_sexpr_rhs_new="" _riss_sexpr_rhs_new_min="" _riss_sexpr_rhs_new_min_new="" \ - _riss_sexpr_sep="" _riss_sexpr_sep_new="" - - eval _riss_lhs='${'"${_riss_rlhs}"'}'; set -- ${_riss_lsep}; - if [ "${_riss_lhs:+1}" = 1 ]; then - _riss_matchfl=0; _riss_nsep=1; while [ "${_riss_nsep}" -le "${#}" ]; do - eval _riss_sep='${'"${_riss_nsep}"'}'; - case "${_riss_lhs}" in - ${_riss_sep}*) _riss_matchfl=1; break; ;; - *) : $((_riss_nsep+=1)); ;; +rtlp_install_v2_splitl_subexpr() { + local _ri2ss_rexpr="${1#\$}" _ri2ss_rlhs="${2#\$}" _ri2ss_lsep="${3}" _ri2ss_lhs="" \ + _ri2ss_matchfl="" _ri2ss_nsep="" _ri2ss_rc=1 _ri2ss_sep="" _ri2ss_sexpr="" \ + _ri2ss_sexpr_lhs="" _ri2ss_sexpr_lhs_new="" _ri2ss_sexpr_rhs="" \ + _ri2ss_sexpr_rhs_new="" _ri2ss_sexpr_rhs_new_min="" _ri2ss_sexpr_rhs_new_min_new="" \ + _ri2ss_sexpr_sep="" _ri2ss_sexpr_sep_new="" + + eval _ri2ss_lhs='${'"${_ri2ss_rlhs}"'}'; set -- ${_ri2ss_lsep}; + + if [ "${_ri2ss_lhs:+1}" = 1 ]; then + _ri2ss_matchfl=0; _ri2ss_nsep=1; while [ "${_ri2ss_nsep}" -le "${#}" ]; do + eval _ri2ss_sep='${'"${_ri2ss_nsep}"'}'; + case "${_ri2ss_lhs}" in + ${_ri2ss_sep}*) _ri2ss_matchfl=1; break; ;; + *) : $((_ri2ss_nsep+=1)); ;; esac; done; - if [ "${_riss_matchfl}" -eq 1 ]; then - _riss_sexpr=""; _riss_sexpr_lhs="${_riss_sep}"; - _riss_sexpr_rhs="${_riss_lhs#${_riss_sep}}"; - while [ "${_riss_sexpr_rhs:+1}" = 1 ]; do - _riss_sexpr_rhs_new_min=-1; _riss_sexpr_sep=""; _riss_nsep=1; - while [ "${_riss_nsep}" -le "${#}" ]; do - eval _riss_sexpr_sep_new='${'"${_riss_nsep}"'}'; - _riss_sexpr_rhs_new="${_riss_sexpr_rhs%%${_riss_sexpr_sep_new}*}"; - if [ "${_riss_sexpr_rhs_new}" != "${_riss_sexpr_rhs}" ]; then - _riss_sexpr_rhs_new_min_new="${#_riss_sexpr_rhs_new}"; - if [ "${_riss_sexpr_rhs_new_min_new}" -le "${_riss_sexpr_rhs_new_min}" ]\ - || [ "${_riss_sexpr_rhs_new_min}" -eq -1 ]; then - _riss_sexpr_rhs_new_min="${_riss_sexpr_rhs_new_min_new}"; - _riss_sexpr_sep="${_riss_sexpr_sep_new}"; + + if [ "${_ri2ss_matchfl}" -eq 1 ]; then + _ri2ss_sexpr=""; _ri2ss_sexpr_lhs="${_ri2ss_sep}"; + _ri2ss_sexpr_rhs="${_ri2ss_lhs#${_ri2ss_sep}}"; + + while [ "${_ri2ss_sexpr_rhs:+1}" = 1 ]; do + _ri2ss_sexpr_rhs_new_min=-1; _ri2ss_sexpr_sep=""; _ri2ss_nsep=1; + while [ "${_ri2ss_nsep}" -le "${#}" ]; do + eval _ri2ss_sexpr_sep_new='${'"${_ri2ss_nsep}"'}'; + _ri2ss_sexpr_rhs_new="${_ri2ss_sexpr_rhs%%${_ri2ss_sexpr_sep_new}*}"; + if [ "${_ri2ss_sexpr_rhs_new}" != "${_ri2ss_sexpr_rhs}" ]; then + _ri2ss_sexpr_rhs_new_min_new="${#_ri2ss_sexpr_rhs_new}"; + if [ "${_ri2ss_sexpr_rhs_new_min_new}" -le "${_ri2ss_sexpr_rhs_new_min}" ]\ + || [ "${_ri2ss_sexpr_rhs_new_min}" -eq -1 ]; then + _ri2ss_sexpr_rhs_new_min="${_ri2ss_sexpr_rhs_new_min_new}"; + _ri2ss_sexpr_sep="${_ri2ss_sexpr_sep_new}"; fi; - fi; : $((_riss_nsep+=1)); + fi; : $((_ri2ss_nsep+=1)); done; - if [ "${_riss_sexpr_sep:+1}" = 1 ]; then - _riss_sexpr_lhs_new="${_riss_sexpr_rhs%%${_riss_sexpr_sep}*}"; - if [ "${_riss_sexpr_lhs_new%\\}" = "${_riss_sexpr_lhs_new}" ]; then - _riss_sexpr_lhs="${_riss_sexpr_lhs}${_riss_sexpr_lhs_new}"; - _riss_sexpr_rhs="${_riss_sexpr_sep}${_riss_sexpr_rhs#*${_riss_sexpr_sep}}"; break; + if [ "${_ri2ss_sexpr_sep:+1}" = 1 ]; then + _ri2ss_sexpr_lhs_new="${_ri2ss_sexpr_rhs%%${_ri2ss_sexpr_sep}*}"; + if [ "${_ri2ss_sexpr_lhs_new%\\}" = "${_ri2ss_sexpr_lhs_new}" ]; then + _ri2ss_sexpr_lhs="${_ri2ss_sexpr_lhs}${_ri2ss_sexpr_lhs_new}"; + _ri2ss_sexpr_rhs="${_ri2ss_sexpr_sep}${_ri2ss_sexpr_rhs#*${_ri2ss_sexpr_sep}}"; break; else - _riss_sexpr_lhs="${_riss_sexpr_lhs}${_riss_sexpr_rhs%%\\${_riss_sexpr_sep}*}${_riss_sexpr_sep}"; - _riss_sexpr_rhs="${_riss_sexpr_rhs#*\\${_riss_sexpr_sep}}"; + _ri2ss_sexpr_lhs="${_ri2ss_sexpr_lhs}${_ri2ss_sexpr_rhs%%\\${_ri2ss_sexpr_sep}*}${_ri2ss_sexpr_sep}"; + _ri2ss_sexpr_rhs="${_ri2ss_sexpr_rhs#*\\${_ri2ss_sexpr_sep}}"; fi; else - _riss_sexpr_lhs="${_riss_sexpr_lhs}${_riss_sexpr_rhs}"; _riss_sexpr_rhs=""; break; + _ri2ss_sexpr_lhs="${_ri2ss_sexpr_lhs}${_ri2ss_sexpr_rhs}"; _ri2ss_sexpr_rhs=""; break; fi; done; - eval ${_riss_rexpr}='${_riss_sexpr_lhs}' ${_riss_rlhs}='${_riss_sexpr_rhs}'; _riss_rc=0; + + eval ${_ri2ss_rexpr}='${_ri2ss_sexpr_lhs}' ${_ri2ss_rlhs}='${_ri2ss_sexpr_rhs}'; _ri2ss_rc=0; fi; - fi; return "${_riss_rc}"; + fi; + + return "${_ri2ss_rc}"; }; # }}} rtl_install_v2() { - local _ri_prefix="" _ri_spec_flag="" _ri_spec_list="" _ri_iflag=0 _ri_IFS="${IFS:- }" \ - _ri_nflag=0 _ri_paramsc=0 _ri_vflag=0 _ri_IFS0 _ri_nparam=0 _ri_opt="" _ri_param="" \ - _ri_rc=0 _ri_spec="" _ri_spec_dst="" _ri_spec_src="" IFS OPTARG="" OPTIND=1; _status=""; + local _ri2_rstatus="${1#\$}" \ + _ri2_prefix="" _ri2_spec_flag="" _ri2_spec_list="" _ri2_iflag=0 _ri2_IFS="${IFS:- }" \ + _ri2_nflag=0 _ri2_paramsc=0 _ri2_vflag=0 _ri2_IFS0 _ri2_nparam=0 _ri2_opt="" _ri2_param="" \ + _ri2_rc=0 _ri2_spec="" _ri2_spec_dst="" _ri2_spec_src="" IFS OPTARG="" OPTIND=1; + shift; while true; do if [ "${1:-}" = "--" ]; then : $((OPTIND+=1)); break; - elif ! getopts hiI:np:v _ri_opt; then + elif ! getopts hiI:np:v _ri2_opt; then break; - else case "${_ri_opt}" in + else case "${_ri2_opt}" in h) printf "usage: rtl_install [-i] [-I ifs] [-n] [-p name=val] [-v] prefix spec_list\n" >&2; printf " -i...........: continue on soft errors\n" >&2; printf " -I ifs.......: process spec_list with ifs instead of NL\n" >&2; @@ -444,102 +494,107 @@ rtl_install_v2() { printf " -v...........: increase verbosity\n" >&2; printf " prefix.......: pathname prefix\n" >&2; printf " spec_list....: ifs-separated list of specs\n" >&2; return 1; ;; - i) _ri_iflag=1; ;; - I) _ri_IFS="${OPTARG}"; ;; - n) _ri_nflag=1; ;; - p) : $((_ri_paramsc+=1)); local _ri_params${OPTARG%%=*}="${OPTARG#*=}"; ;; - v) : $((_ri_vflag+=1)); ;; + i) _ri2_iflag=1; ;; + I) _ri2_IFS="${OPTARG}"; ;; + n) _ri2_nflag=1; ;; + p) : $((_ri2_paramsc+=1)); local _ri2_params${OPTARG%%=*}="${OPTARG#*=}"; ;; + v) : $((_ri2_vflag+=1)); ;; *) return 1; ;; esac; fi; done; shift $((${OPTIND}-1)); - _ri_prefix="${1:-}"; _ri_spec_list="${2:-}"; shift 2; - _ri_IFS0="${IFS:- }"; IFS="${_ri_IFS}"; set -- ${_ri_spec_list}; IFS="${_ri_IFS0}"; + _ri2_prefix="${1:-}"; _ri2_spec_list="${2:-}"; shift 2; + _ri2_IFS0="${IFS:- }"; IFS="${_ri2_IFS}"; set -- ${_ri2_spec_list}; IFS="${_ri2_IFS0}"; while [ ${#} -gt 0 ]; do - _ri_spec_src="${1}"; - case "${_ri_spec_src}" in - \?*) _ri_spec_flag="?"; ;; - *) _ri_spec_flag=""; ;; + _ri2_spec_src="${1}"; + case "${_ri2_spec_src}" in + \?*) _ri2_spec_flag="?"; ;; + *) _ri2_spec_flag=""; ;; esac; - if ! rtlp_install_splitl \$_ri_spec_src \$_ri_spec_dst "="; then - _ri_rc=1; _status="zero-length or invalid specification \`${1}'"; - else case "${_ri_spec_src}" in + if ! rtlp_install_v2_splitl \$_ri2_spec_src \$_ri2_spec_dst "="; then + _ri2_rc=1; + rtl_setrstatus "${_ri2_rstatus}" 'zero-length or invalid specification \`'"${1}"''\'; + else case "${_ri2_spec_src}" in + -) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_dst}" \ - rtlp_install_op_rm "${_ri_nflag}" "${_ri_prefix}" "${_ri_vflag}" \ - "" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_dst}" \ + rtlp_install_v2_op_rm "${_ri2_nflag}" "${_ri2_prefix}" "${_ri2_vflag}" \ + "" \ -- "%[1]" "%[2]" "%[3]" "%[ITEM]"; ;; /) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_dst}" \ - rtlp_install_op_mkdir "${_ri_nflag}" "${_ri_prefix}" "${_ri_vflag}" \ - "" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_dst}" \ + rtlp_install_v2_op_mkdir "${_ri2_nflag}" "${_ri2_prefix}" "${_ri2_vflag}" \ + "" \ -- "%[1]" "%[2]" "%[3]" "%[ITEM]"; ;; t*) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_dst}" \ - rtlp_install_op_touch "${_ri_nflag}" "${_ri_prefix}" "${_ri_vflag}" \ - "" "" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_dst}" \ + rtlp_install_v2_op_touch "${_ri2_nflag}" "${_ri2_prefix}" "${_ri2_vflag}" \ + "" "" \ -- "%[1]" "%[2]" "%[3]" "%[ITEM]" "%[5]"; ;; :*) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_src#:}" \ - rtlp_install_op_cp "${_ri_nflag}" "${_ri_prefix}" "${_ri_vflag}" \ - "${_ri_spec_dst}" "" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_src#:}" \ + rtlp_install_v2_op_cp "${_ri2_nflag}" "${_ri2_prefix}" "${_ri2_vflag}" \ + "${_ri2_spec_dst}" "" \ -- "%[1]" "%[2]" "%[3]" "%[@4]" "%[ITEM]"; ;; !*) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_src#!}" \ - rtlp_install_op_mv "${_ri_nflag}" "${_ri_prefix}" "${_ri_vflag}" \ - "${_ri_spec_dst}" "" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_src#!}" \ + rtlp_install_v2_op_mv "${_ri2_nflag}" "${_ri2_prefix}" "${_ri2_vflag}" \ + "${_ri2_spec_dst}" "" \ -- "%[1]" "%[2]" "%[3]" "%[@4]" "%[ITEM]"; ;; @*) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_dst}" \ - rtlp_install_op_ln_symbolic "${_ri_nflag}" "${_ri_prefix}" \ - "${_ri_vflag}" "" "${_ri_spec_src#@}" "" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_dst}" \ + rtlp_install_v2_op_ln_symbolic "${_ri2_nflag}" "${_ri2_prefix}" \ + "${_ri2_vflag}" "" "${_ri2_spec_src#@}" "" \ -- "%[1]" "%[2]" "%[3]" "%[ITEM]" "%[@5]"; ;; +*) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_src#+}" \ - rtlp_install_op_cp_follow_if_newer "${_ri_nflag}" "${_ri_prefix}" \ - "${_ri_vflag}" "${_ri_spec_dst}" "" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_src#+}" \ + rtlp_install_v2_op_cp_follow_if_newer "${_ri2_nflag}" "${_ri2_prefix}" \ + "${_ri2_vflag}" "${_ri2_spec_dst}" "" \ -- "%[1]" "%[2]" "%[3]" "%[@4]" "%[ITEM]"; ;; g*) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_dst}" \ - rtlp_install_op_chgrp "${_ri_nflag}" "${_ri_prefix}" "${_ri_vflag}" \ - "" "${_ri_spec_src#g}" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_dst}" \ + rtlp_install_v2_op_chgrp "${_ri2_nflag}" "${_ri2_prefix}" "${_ri2_vflag}" \ + "" "${_ri2_spec_src#g}" \ -- "%[1]" "%[2]" "%[3]" "%[ITEM]" "%[5]"; ;; m[0-7][0-7][0-7][0-7]) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_dst}" \ - rtlp_install_op_chmod "${_ri_nflag}" "${_ri_prefix}" "${_ri_vflag}" \ - "" "${_ri_spec_src#m}" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_dst}" \ + rtlp_install_v2_op_chmod "${_ri2_nflag}" "${_ri2_prefix}" "${_ri2_vflag}" \ + "" "${_ri2_spec_src#m}" \ -- "%[1]" "%[2]" "%[3]" "%[ITEM]" "%[5]"; ;; o*) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_dst}" \ - rtlp_install_op_chown "${_ri_nflag}" "${_ri_prefix}" "${_ri_vflag}" \ - "" "${_ri_spec_src#o}" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_dst}" \ + rtlp_install_v2_op_chown "${_ri2_nflag}" "${_ri2_prefix}" "${_ri2_vflag}" \ + "" "${_ri2_spec_src#o}" \ -- "%[1]" "%[2]" "%[3]" "%[ITEM]" "%[5]"; ;; T*) - rtlp_install_fmap \$_ri_params "${_ri_prefix}" "${_ri_spec_dst}" \ - rtlp_install_op_touch "${_ri_nflag}" "${_ri_prefix}" "${_ri_vflag}" \ - "" "${_ri_spec_src#T}" \ + rtlp_install_v2_fmap "${_ri2_rstatus}" \$_ri2_params "${_ri2_prefix}" "${_ri2_spec_dst}" \ + rtlp_install_v2_op_touch "${_ri2_nflag}" "${_ri2_prefix}" "${_ri2_vflag}" \ + "" "${_ri2_spec_src#T}" \ -- "%[1]" "%[2]" "%[3]" "%[ITEM]" "%[5]"; ;; \#*|"") ;; - esac; _ri_rc="${?}"; fi; + + esac; _ri2_rc="${?}"; fi; shift; - if [ "${_ri_rc}" -ne 0 ]\ - && [ "${_ri_iflag}" -eq 0 ]; then + + if [ "${_ri2_rc}" -ne 0 ]\ + && [ "${_ri2_iflag}" -eq 0 ]; then break; fi; done; - return "${_ri_rc}"; + + return "${_ri2_rc}"; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_list.subr b/subr.rtl/rtl_list.subr index 07d401b8..5b518dad 100644 --- a/subr.rtl/rtl_list.subr +++ b/subr.rtl/rtl_list.subr @@ -5,173 +5,280 @@ # 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 + local _rla_vnames="${1}" _rla_sep="${2}" \ + _rla_head="" _rla_tail="" _rla_vname="" _rla_vval="" IFS; + IFS="${_rla_sep}"; shift 2; + + for _rla_vval in ${@}; do + if ! rtl_lfirst \$_rla_head \$_rla_tail "${_rla_vnames}" " "; then return 1; else - _vname="${RTL_LFIRST_HEAD}"; _vnames="${RTL_LFIRST_TAIL}"; - rtl_set_var_unsafe "${_vname}" "${_vval}"; + _rla_vname="${_rla_head}"; _rla_vnames="${_rla_tail}"; + rtl_set_var_unsafe "${_rla_vname}" "${_rla_vval}"; fi; done; + return 0; }; rtl_lconcat() { - local _list="${1}" _litem_new="${2}" _sep="${3:- }" IFS="${3:-${IFS:- }}"; - if [ -n "${_list}" ]; then - printf "%s%s%s" "${_list}" "${_sep}" "${_litem_new}"; + rtl_lconcat2 "${1}" "${1}" "${2}" "${3:-}"; +}; + +rtl_lconcat2() { + local _rlc2_rlist_new="${1#\$}" _rlc2_rlist="${2#\$}" _rlc2_litem_new="${3}" \ + _rlc2_sep="${4:- }" IFS="${4:-${IFS:- }}"; + + if eval [ \"'${'${_rlc2_rlist}':+1}'\" = 1 ]; then + eval ${_rlc2_rlist_new}='${'"${_rlc2_rlist}"'}${_rlc2_sep}${_rlc2_litem_new}'; else - printf "%s" "${_litem_new}"; + eval ${_rlc2_rlist_new}='${_rlc2_litem_new}'; fi; + return 0; }; rtl_lfilter() { - local _list="${1}" _filter="${2}" _sep="${3:- }" IFS="${3:-${IFS:- }}"\ - _filterfl="" _litem="" _litem_filter="" _lnew=""; - if [ -z "${_filter}" ]; then - printf "%s" "${_list}"; return 0; - else for _litem in ${_list}; do - _filterfl=0; - for _litem_filter in ${_filter}; do - if [ "${_litem_filter}" = "${_litem}" ]; then - _filterfl=1; break; - fi; - done; - if [ "${_filterfl:-0}" -eq 0 ]; then - _lnew="${_lnew:+${_lnew}${_sep}}${_litem}"; - fi; - done; fi; - printf "%s" "${_lnew}"; + rtl_lfilter2 "${1}" "${1}" "${2}" "${3:-}"; }; rtl_lfilter2() { - local _rlist="${1#\$}" _rlist_new="${2#\$}" _filter="${3}" _sep="${4:- }" IFS="${4:-${IFS:- }}"\ - _filterfl="" _litem="" _litem_filter="" _lnew=""; - - if [ "${_filter:+1}" != 1 ]; then - eval ${_rlist_new}=; return 0; - else eval set -- '${'"${_rlist}"'}'\; ${_rlist_new}=; - while [ "${#}" -gt 0 ]; do - _litem="${1}"; shift; _filterfl=0; - for _litem_filter in ${_filter}; do - if [ "${_litem_filter}" = "${_litem}" ]; then - _filterfl=1; break; + local _rlf2_rlist="${1#\$}" _rlf2_rlist_new="${2#\$}" _rlf2_filter="${3}" _rlf2_sep="${4:-}"\ + _rlf2_filterfl="" _rlf2_list="" _rlf2_litem="" _rlf2_litem_filter="" _rlf2_lnew=""; + + if [ "${_rlf2_sep:+1}" = 1 ]; then + local IFS="${_rlf2_sep}"; + else + local _rlf2_sep=" " IFS="${RTL_IFS_ORIG}"; + fi; + + if [ "${_rlf2_filter:+1}" != 1 ]; then + eval ${_rlf2_rlist_new}=; + else + eval _rlf2_list='${'"${_rlf2_rlist}"'}'; + eval ${_rlf2_rlist_new}=; + for _rlf2_litem in ${_rlf2_list}; do + _rlf2_filterfl=0; + for _rlf2_litem_filter in ${_rlf2_filter}; do + if [ "${_rlf2_litem_filter}" = "${_rlf2_litem}" ]; then + _rlf2_filterfl=1; break; fi; done; - if [ "${_filterfl:-0}" -eq 0 ]; then - eval ${_rlist_new}='${'"${_rlist_new}"':+${'"${_rlist_new}"'}${_sep}}${_litem}'; + if [ "${_rlf2_filterfl:-0}" -eq 0 ]; then + eval ${_rlf2_rlist_new}='${'"${_rlf2_rlist_new}"':+${'"${_rlf2_rlist_new}"'}${_rlf2_sep}}${_rlf2_litem}'; fi; done; fi; -}; - -rtl_lfilter3() { - rtl_lfilter2 "${1}" "${1}" "${2}" "${3:-}"; + return 0; }; rtl_lfirst() { - local _list="${1}" _sep="${2}" IFS; IFS="${_sep}"; - set -- ${_list}; RTL_LFIRST_HEAD="${1}"; + local _rlf_rhead="${1#\$}" _rlf_rtail="${2#\$}" _rlf_list="${3}" _rlf_sep="${4}" IFS="${4}"; + + set -- ${_rlf_list}; eval ${_rlf_rhead}='${1}'; if [ "${#}" -ge 0 ]; then - shift; RTL_LFIRST_TAIL="${*}"; + shift; eval ${_rlf_rtail}=\"'${*}'\"; else - RTL_LFIRST_TAIL=""; + eval ${_rlf_rtail}=; fi; + return 0; }; -rtl_llength() { - local _list="${1}" _sep="${2:- }" IFS="${2:-${IFS:- }}" _litem="" _llength=0; - for _litem in ${_list}; do - : $((_llength+=1)); - done; - printf "%s" "${_llength}"; +rtl_lindexV() { + local _rliV_rlout="${1#\$}" _rliV_idx="${2}" \ + _rliV_limit=0; shift 2; + + if [ "${_rliV_idx#-}" != "${_rliV_idx}" ]; then + _rliV_idx="${_rliV_idx#-}"; + while [ "${#}" -gt "${_rliV_idx}" ]; do + shift; + done; + _rliV_limit=$((${#} + 1)); + else + _rliV_limit="${#}"; + shift "${_rliV_idx}"; + fi; + + if [ "${#}" -ge 1 ]\ + && [ "${_rliV_idx}" -lt "${_rliV_limit}" ]; then + eval ${_rliV_rlout}='${1}'; + else + eval ${_rliV_rlout}=; + fi; + return 0; }; -rtl_llength2() { - local _rlist="${1#\$}" _rlen="${2#\$}" _sep="${3:- }" IFS="${3:-${IFS:- }}"; - eval set -- '${'"${_rlist}"'}'\; ${_rlen}='${#}'; +rtl_llength() { + local _rll_rlen="${1#\$}" _rll_rlist="${2#\$}" _rll_sep="${3:- }" IFS="${3:-${IFS:- }}"; + + eval set -- '${'"${_rll_rlist}"'}'\; ${_rll_rlen}='${#}'; + return 0; }; rtl_llift() { - local _list="${1}" _sep="${2}" _sep_new="${3}" IFS; IFS="${_sep}"; - set -- ${_list}; IFS="${_sep_new}"; - printf "%s" "${*}"; + rtl_llift2 "${1}" "${1}" "${2}" "${3}"; }; rtl_llift2() { - local _rlist="${1#\$}" _rlist_new="${2#\$}" _sep="${3}" \ - _sep_new="${4}" IFS; IFS="${_sep}"; + local _rl2_rlist="${1#\$}" _rl2_rlist_new="${2#\$}" _rl2_sep="${3:-}" \ + _rl2_sep_new="${4}"; - eval set -- '${'"${_rlist}"'}'; IFS="${_sep_new}"; - eval ${_rlist_new}='"${*}"'; -}; + if [ "${_rl2_sep:+1}" = 1 ]; then + local IFS="${_rl2_sep}"; + else + local _rl2_sep=" " IFS="${RTL_IFS_ORIG}"; + fi; -rtl_llift3() { - rtl_llift2 "${1}" "${1}" "${2}" "${3}"; + eval set -- '${'"${_rl2_rlist}"'}'; IFS="${_rl2_sep_new}"; + eval ${_rl2_rlist_new}='"${*}"'; + return 0; }; rtl_lmatch() { - local _list="${1}" _item="${2}" _sep="${3:- }"; - [ -n "$(rtl_lsearch "${_list}" "${_item}" "${_sep}")" ]; + local _rlm_rlist="${1#\$}" _rlm_item="${2}" _rlm_sep="${3:-}" _rlm_list_=""; + + rtl_lsearch2 "${_rlm_rlist}" \$_rlm_list_ "${_rlm_item}" "${_rlm_sep}"; + [ "${_rlm_list_:+1}" = 1 ]; }; rtl_lmax() { - local _len=0 _len_max=0; + local _rlm2_rlist="${1#\$}" _rlm2_rmax="${2#\$}" \ + _rlm2_len=0 _rlm2_len_max=0; + + eval set -- '${'"${_rlm2_rlist}"'}'; while [ "${#}" -gt 0 ]; do - _len="${#1}"; - if [ "${_len}" -gt "${_len_max}" ]; then - _len_max="${_len}"; + _rlm2_len="${#1}"; + if [ "${_rlm2_len}" -gt "${_rlm2_len_max}" ]; then + _rlm2_len_max="${_rlm2_len}"; fi; shift; - done; printf "%s" "${_len_max}"; + done; + eval ${_rlm2_rmax}='${_rlm2_len_max}'; + return 0; +}; + +rtl_lrangeV() { + local _rlrV_rlout="${1#\$}" _rlrV_idx0="${2}" _rlrV_idx1="${3}" _rlrV_sep="${4}" \ + _rlrV_limit=0; shift 4; + + if [ "${_rlrV_idx0#-}" != "${_rlrV_idx0}" ]; then + eval ${_rlrV_rlout}=; + + return 1; + elif [ "${_rlrV_idx1#-}" != "${_rlrV_idx1}" ]; then + _rlrV_idx1="${_rlrV_idx1#-}"; + + _rlrV_limit="${#}"; + shift "${_rlrV_idx0}"; + + eval ${_rlrV_rlout}=; + while [ "${#}" -gt 0 ]\ + && [ "${_rlrV_idx1}" -lt "${#}" ]; + do + eval ${_rlrV_rlout}='${'"${_rlrV_rlout}"':+${'"${_rlrV_rlout}"'}${_rlrV_sep}}${1}'; + shift; + done; + + return 0; + elif [ "${_rlrV_idx1}" -ge "${_rlrV_idx0}" ]; then + _rlrV_limit="${#}"; + shift "${_rlrV_idx0}"; + : $((_rlrV_idx1 -= ${_rlrV_idx0})); + : $((_rlrV_idx1 += 1)); + + eval ${_rlrV_rlout}=; + while [ "${_rlrV_idx1}" -gt 0 ]\ + && [ "${#}" -gt 0 ]; + do + eval ${_rlrV_rlout}='${'"${_rlrV_rlout}"':+${'"${_rlrV_rlout}"'}${_rlrV_sep}}${1}'; + : $((_rlrV_idx1 -= 1)); + shift; + done; + + return 0; + fi; }; rtl_lsearch() { - local _list="${1}" _filter="${2}" _sep="${3:- }" IFS="${3:-${IFS:- }}"\ - _litem="" _litem_filter="" _lnew=""; - if [ -z "${_filter}" ]; then - printf "%s" "${_list}"; return 0; - else for _litem in ${_list}; do - for _litem_filter in ${_filter}; do - if [ "${_litem_filter}" = "${_litem}" ]; then - _lnew="${_lnew:+${_lnew}${_sep}}${_litem}"; - break; - fi; + rtl_lsearch2 "${1}" "${1}" "${2}" "${3:-}"; +} + +rtl_lsearch2() { + local _rls2_rlist="${1#\$}" _rls2_rlist_new="${2#\$}" \ + _rls2_filter="${3}" _rls2_sep="${4:-}" \ + _rls2_list="" _rls2_litem="" _rls2_litem_filter="" \ + _rls2_lnew=""; + + if [ "${_rls2_sep:+1}" = 1 ]; then + local IFS="${_rls2_sep}"; + else + local _rls2_sep=" " IFS="${RTL_IFS_ORIG}"; + fi; + if [ "${_rls2_filter:+1}" != 1 ]; then + eval ${_rls2_rlist_new}='${_rls2_list}'; return 0; + else + eval _rls2_list='${'"${_rls2_rlist}"'}'; + for _rls2_litem in ${_rls2_list}; do + for _rls2_litem_filter in ${_rls2_filter}; do + if [ "${_rls2_litem_filter}" = "${_rls2_litem}" ]; then + _rls2_lnew="${_rls2_lnew:+${_rls2_lnew}${_rls2_sep}}${_rls2_litem}"; + break; + fi; + done; done; - done; fi; - printf "%s" "${_lnew}"; + fi; + + eval ${_rls2_rlist_new}='${_rls2_lnew}'; + return 0; }; rtl_lsearch_patternl() { - local _list="${1}" _pattern="${2}" _sep="${3:- }" IFS="${3:-${IFS:- }}"\ - _litem="" _lnew=""; - if [ -n "${_pattern}" ]; then - for _litem in ${_list}; do - if [ "${_litem#${_pattern}}" != "${_litem}" ]; then - _lnew="${_lnew:+${_lnew}${_sep}}${_litem}"; + rtl_lsearch_patternl2 "${1}" "${1}" "${2}" "${3:-}"; +}; + +rtl_lsearch_patternl2() { + local _rlsp2_rlist="${1#\$}" _rlsp2_rlist_new="${2#\$}" \ + _rlsp2_pattern="${3}" _rlsp2_sep="${4:- }" \ + IFS="${4:-${IFS:- }}" \ + _rlsp2_litem="" _rlsp2_lnew=""; + + if [ "${_rlsp2_pattern:+1}" = 1 ]; then + eval _rlsp2_list='${'"${_rlsp2_rlist}"'}'; + for _rlsp2_litem in ${_rlsp2_list}; do + if [ "${_rlsp2_litem#${_rlsp2_pattern}}" != "${_rlsp2_litem}" ]; then + _rlsp2_lnew="${_rlsp2_lnew:+${_rlsp2_lnew}${_rlsp2_sep}}${_rlsp2_litem}"; fi; done; fi; - printf "%s" "${_lnew}"; + eval ${_rlsp2_rlist_new}='${_rlsp2_lnew}'; + return 0; }; rtl_lsort() { - local _list="${1}" _sep="${2:- }"; - printf "%s" "${_list}" | tr "${_sep}" "\n" | sort | paste -s -d "${_sep}"; + printf "%s" "${*}" | tr " " "\n" | sort | paste -s -d " "; + return 0; }; +RTL_LUNFOLD_DEPENDS_LEVEL=0; rtl_lunfold_depends() { - local _vname_template="${1}" _depends="" _name="" _names=""; shift; - for _name in "${@}"; do - if _depends="$(rtl_get_var_unsafe -u "$(eval printf \"%s\" \""${_vname_template}"\")")"\ - && [ -n "${_depends}" ]; then - _depends="$(rtl_lunfold_depends "${_vname_template}" ${_depends})"; - _names="$(rtl_lconcat "${_names}" "${_depends}")"; + local _rld_vname_template="${1}" _rld_rlist="${2#\$}" \ + _rld_depends="" _rld_list="" _rld_name="" _rld_names="" \ + _rld_vname_template_=""; + shift 2; + + for _rld_name in "${@}"; do + eval _rld_vname_template_=\"${_rld_vname_template}\"; + if rtl_get_var_unsafe \$_rld_depends -u "${_rld_vname_template_}"\ + && [ "${_rld_depends:+1}" = 1 ]; then + : $((RTL_LUNFOLD_DEPENDS_LEVEL+=1)); + eval _rld_depends${RTL_LUNFOLD_DEPENDS_LEVEL}='${_rld_depends}'; + rtl_lunfold_depends "${_rld_vname_template}" \$_rld_depends${RTL_LUNFOLD_DEPENDS_LEVEL} ${_rld_depends}; + eval _rld_depends='${_rld_depends'"${RTL_LUNFOLD_DEPENDS_LEVEL}"'}'; + unset '_rld_depends'"${RTL_LUNFOLD_DEPENDS_LEVEL}"; + : $((RTL_LUNFOLD_DEPENDS_LEVEL-=1)); + rtl_lconcat \$_rld_names "${_rld_depends}"; fi; - _names="$(rtl_lconcat "${_names}" "${_name}")"; + rtl_lconcat \$_rld_names "${_rld_name}"; done; - printf "%s" "${_names}"; + eval ${_rld_rlist}='${_rld_names}'; + return 0; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_log.subr b/subr.rtl/rtl_log.subr index 3a7560a5..3e224e8e 100644 --- a/subr.rtl/rtl_log.subr +++ b/subr.rtl/rtl_log.subr @@ -11,24 +11,28 @@ RTLP_LOG_NO_ATTR=0; RTLP_LOG_TAGS=""; rtlp_log_printf() { - local _attr="${1}" _fmt_pfx="${2}" _fmt="${3#*;}" _fmt_argc="${3%%;*}"; shift 3; - if [ "${#}" -ne "${_fmt_argc}" ]; then - if [ "${_fmt_argc}" -eq 0 ]; then + local _rplp_attr="${1}" _rplp_fmt_pfx="${2}" \ + _rplp_fmt="${3#*;}" _rplp_fmt_argc="${3%%;*}"; + shift 3; + + if [ "${#}" -ne "${_rplp_fmt_argc}" ]; then + if [ "${_rplp_fmt_argc}" -eq 0 ]; then shift "${#}"; else rtlp_log_printf "" "" "0;==> FIXME TODO XXX MESSAGE STRING ARGUMENT COUNT MISMATCH\n"; fi; fi; - _msg="$(printf "${_fmt_pfx}${_fmt}" "${@}")"; + _rplp_msg="$(printf "${_rplp_fmt_pfx}${_rplp_fmt}" "${@}")"; - if [ -n "${RTLP_LOG_FNAME}" ]; then - printf "%s\n" "${_msg}" >> "${RTLP_LOG_FNAME}"; + if [ "${RTLP_LOG_FNAME:+1}" = 1 ]; then + printf "%s\n" "${_rplp_msg}" >> "${RTLP_LOG_FNAME}"; fi; if [ "${RTLP_LOG_NO_ATTR:-0}" -eq 0 ]; then - printf "\033[0m\033[${_attr}m%s\033[0m\n" "${_msg}"; + printf "\033[0m\033[${_rplp_attr}m%s\033[0m\n" "${_rplp_msg}"; else - printf "%s\n" "${_msg}"; - fi; return 0; + printf "%s\n" "${_rplp_msg}"; + fi; + return 0; }; # @@ -41,48 +45,64 @@ rtl_log_clear_tags() { rtl_log_enable_tags() { local IFS=","; set -- ${*}; + while [ "${#}" -gt 0 ]; do - if ! rtl_lmatch "${RTLP_LOG_TAGS}" "${1}" ","; then + if ! rtl_lmatch \$RTLP_LOG_TAGS "${1}" ","; then RTLP_LOG_TAGS="${RTLP_LOG_TAGS:+${RTLP_LOG_TAGS},}${1}"; fi; shift; - done; return 0; + done; + return 0; }; rtl_log_env_vars() { - local _tag="${1}" _type="${2}" _arg_len_max=0; shift 2; + local _rlev_tag="${1}" _rlev_type="${2}" \ + _rlev_arg_len_max=0 _rlev_list="" _rlev_msg="" _rlev_msg_=""; + shift 2; - rtl_log_msg "${_tag}" "${MSG_rtl_log_vars_header}" "${_type}"; - _arg_len_max="$(rtl_lmax "${@}")"; + rtl_log_msg "${_rlev_tag}" "${MSG_rtl_log_vars_header}" "${_rlev_type}"; + _rlev_list="${@}"; rtl_lmax \$_rlev_list \$_rlev_arg_len_max; while [ "${#}" -gt 0 ]; do - rtl_log_msg "${_tag}" \ - "2;%${_arg_len_max}.${_arg_len_max}s=%s" \ - "${1%%=*}" "$(rtl_get_var_unsafe "${1#*=}")"; + rtl_get_var_unsafe \$_rlev_msg "${1#*=}"; + rtl_llift2 \$_rlev_msg \$_rlev_msg_ "" " "; + rtl_log_msg "${_rlev_tag}" \ + "2;%${_rlev_arg_len_max}.${_rlev_arg_len_max}s=%s" \ + "${1%%=*}" "${_rlev_msg_}"; shift; - done; return 0; + done; + return 0; }; rtl_log_msg() { - local _tag="${1}" _fmt="${2}" _attr="" _exitfl=0; shift 2; + local _rlm3_tag="${1}" _rlm3_fmt="${2}" \ + _rlm3_attr="" _rlm3_date_now=0 _rlm3_exitfl=0; + shift 2; - [ "x${_tag}" = "xfatalexit" ] && { _tag="fatal"; _exitfl=1; }; - if rtl_lmatch "${RTLP_LOG_TAGS}" "${_tag}" ","; then - eval _attr='${LOG_TAG_'"${_tag}"':-}'; - if [ "${#_attr}" -eq 0 ]; then - rtlp_log_printf "" "" "0;==> FIXME TODO XXX UNKNOWN TAG \`${_tag}' PASSED TO rtl_log_msg()\n"; + if [ "x${_rlm3_tag}" = "xfatalexit" ]; then + _rlm3_tag="fatal"; _rlm3_exitfl=1; + fi; + + if rtl_lmatch \$RTLP_LOG_TAGS "${_rlm3_tag}" ","; then + eval _rlm3_attr='${LOG_TAG_'"${_rlm3_tag}"':-}'; + if [ "${#_rlm3_attr}" -eq 0 ]; then + rtlp_log_printf "" "" "0;==> FIXME TODO XXX UNKNOWN TAG \`${_rlm3_tag}' PASSED TO rtl_log_msg()\n"; fi; - rtlp_log_printf "${_attr}" "==> $(rtl_date) " "${_fmt}" "${@}"; - if [ "${_exitfl}" -eq 1 ]; then + rtl_date \$_rlm3_date_now; + rtlp_log_printf "${_rlm3_attr}" "==> ${_rlm3_date_now} " "${_rlm3_fmt}" "${@}"; + if [ "${_rlm3_exitfl}" -eq 1 ]; then exit 1; fi; - fi; return 0; + fi; + return 0; }; rtl_log_set_fname() { - RTLP_LOG_FNAME="${1}"; return 0; + RTLP_LOG_FNAME="${1}"; + return 0; }; rtl_log_set_no_attr() { - RTLP_LOG_NO_ATTR="${1}"; return 0; + RTLP_LOG_NO_ATTR="${1}"; + return 0; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_platform.subr b/subr.rtl/rtl_platform.subr index dd50852b..25805219 100644 --- a/subr.rtl/rtl_platform.subr +++ b/subr.rtl/rtl_platform.subr @@ -3,122 +3,164 @@ # rtl_check_prereqs() { - local _cmd="" _cmds_missing="" _rc=0; _status=""; - for _cmd in "${@}"; do - if ! which "${_cmd}" >/dev/null 2>&1; then - _cmds_missing="${_cmds_missing:+${_cmds_missing} }${_cmd}"; + local _rcp_rstatus="${1#\$}" \ + _rcp_cmd="" _rcp_cmds_missing="" _rcp_rc=0; + shift; + + for _rcp_cmd in "${@}"; do + if ! which "${_rcp_cmd}" >/dev/null 2>&1; then + _rcp_cmds_missing="${_rcp_cmds_missing:+${_rcp_cmds_missing} }${_rcp_cmd}"; fi; done; - if [ -n "${_cmds_missing}" ]; then - _rc=1; _status="Error: missing prerequisite package(s): ${_cmds_missing}"; + if [ "${_rcp_cmds_missing:+1}" = 1 ]; then + _rcp_rc=1; + rtl_setrstatus "${_rcp_rstatus}" 'Error: missing prerequisite package(s): '"${_rcp_cmds_missing}"; fi; - return "${_rc}"; + return "${_rcp_rc}"; }; rtl_clean_env() { - local _env_vars_except="${1}" _env_var="" _env_vars=""; - _env_vars="$(export | sed -ne '/^export/{s/^export //;s/=.*$//p}')"; - for _env_var in ${_env_vars}; do - if [ "${_env_var#DEFAULT_}" != "${_env_var}" ]\ - || [ "${_env_var#PKG_}" != "${_env_var}" ]; then - _env_vars_except="$(rtl_lconcat "${_env_vars_except}" "${_env_var}")"; + local _rce_env_vars_except="${1}" \ + _rce_env_var="" _rce_env_vars="" _rce_env_vars_unset=""; + + _rce_env_vars="$(export | sed -ne '/^export/{s/^export //;s/=.*$//p}')"; + + for _rce_env_var in ${_rce_env_vars}; do + if [ "${_rce_env_var#DEFAULT_}" != "${_rce_env_var}" ]\ + || [ "${_rce_env_var#PKG_}" != "${_rce_env_var}" ]; then + rtl_lconcat \$_rce_env_vars_except "${_rce_env_var}"; fi; done; - rtl_unset_vars $(rtl_lfilter "${_env_vars}" "${_env_vars_except}"); + rtl_lfilter2 \$_rce_env_vars \$_rce_env_vars_unset "${_rce_env_vars_except}"; + rtl_unset_vars ${_rce_env_vars_unset}; + + return 0; }; rtl_get_cpu_count() { - local _line="" _ncpus=0 _rc=0 _sname="$(uname -s 2>/dev/null)"; _status=""; - case "${_sname}" in + local _rgcc_rstatus="${1#\$}" _rgcc_rcount="${2#\$}" \ + _rgcc_line="" _rgcc_ncpus=0 _rgcc_rc=0 _rgcc_sname=""; + + _rgcc_sname="$(uname -s 2>/dev/null)" || return 1; + case "${_rgcc_sname}" in + Linux) if [ ! -e "/proc/cpuinfo" ]; then - _rc=1; _status="Error: /proc/cpuinfo non-existent."; - else while read -r _line; do - if rtl_match "${_line}" "processor*:"; then - : $((_ncpus+=1)); + _rgcc_rc=1; + rtl_setrstatus "${_rgcc_rstatus}" 'Error: /proc/cpuinfo non-existent.'; + else while read -r _rgcc_line; do + if rtl_match "${_rgcc_line}" "processor*:"; then + : $((_rgcc_ncpus+=1)); fi; - done < /proc/cpuinfo; printf "%s" "${_ncpus}"; + done < /proc/cpuinfo; + _rgcc_rc=0; + rtl_setrstatus "${_rgcc_rstatus}" ""; fi; ;; - *) _rc=1; _status="Error: unknown platform \`${_sname}'."; ;; - esac; return "${_rc}"; + + *) _rgcc_rc=1; + rtl_setrstatus "${_rgcc_rstatus}" 'Error: unknown platform \`'"${_rgcc_sname}"''\''.'; + ;; + + esac; + eval ${_rgcc_rcount}='${_rgcc_ncpus}'; + return "${_rgcc_rc}"; }; rtl_get_var_unsafe() { - local _vname=""; + local _rgvu_rvname_out="${1#\$}" \ + _rgvu_vname=""; + shift; + if [ "x${1}" = "x-u" ]; then - shift; _vname="$(rtl_toupper "${1}")"; + shift; _rgvu_vname="${1}"; rtl_toupper \$_rgvu_vname; else - _vname="${1}"; + _rgvu_vname="${1}"; fi; - eval echo \${${_vname}} 2>/dev/null; + eval ${_rgvu_rvname_out}="\${${_rgvu_vname}:-}"; + return 0; }; rtl_get_vars_fast() { - local _pattern="${1}"; - set | awk -F= '/'"${_pattern}"'/{print $1}' | sort; + local _rgvf_pattern="${1}"; + + set | awk -F= '/'"${_rgvf_pattern}"'/{print $1}' | sort; + return 0; }; rtl_kill_tree() { - local _pid="${1}" _signal="${2:-TERM}" _pid_child="" _pids=""; - if _pids="$(pgrep -P "${_pid}")"\ - && [ -n "${_pids}" ]; then - for _pid_child in ${_pids}; do - rtl_kill_tree "${_pid_child}" "${_signal}"; + local _rkt_rpids="${1#\$}" _rkt_pid="${2}" _rkt_signal="${3:-TERM}" \ + _rkt_pid_child="" _rkt_pids=""; + + if _rkt_pids="$(pgrep -P "${_rkt_pid}")"\ + && [ "${_rkt_pids:+1}" = 1 ]; then + for _rkt_pid_child in ${_rkt_pids}; do + rtl_kill_tree "${_rkt_rpids}" "${_rkt_pid_child}" "${_rkt_signal}"; done; fi; - if [ "${_pid:-0}" -ne "${$}" ]\ - && kill "-${_signal}" "${_pid}" 2>/dev/null; then - RTL_KILL_TREE_PIDS="$(rtl_lconcat "${RTL_KILL_TREE_PIDS}" "${_pid}")"; + if [ "${_rkt_pid:-0}" -ne "${$}" ]\ + && kill "-${_rkt_signal}" "${_rkt_pid}" 2>/dev/null; then + rtl_lconcat "${_rkt_rpids}" "${_rkt_pid}"; fi; + return 0; }; rtl_prompt() { - local _fmt="${1}" _choice=""; shift; - printf "${_fmt}? (y|N) " "${@}"; - read -r _choice; - case "${_choice}" in - [yY]) _choice=1; ;; - *) _choice=0; ;; + local rp_fmt="${1}" rp_choice=""; shift; + + printf "${rp_fmt}? (y|N) " "${@}"; + read -r rp_choice; + case "${rp_choice}" in + [yY]) rp_choice=1; ;; + *) rp_choice=0; ;; esac; - return "${_choice}"; + return "${rp_choice}"; }; rtl_rc() { - local _nflag="${1}" _cmd="${2}"; shift 2; - case "${_nflag}" in + local _rr_nflag="${1}" _rr_cmd="${2}"; + shift 2; + + case "${_rr_nflag}" in 1) if [ "${#}" -gt 0 ]; then - rtl_log_msg "verbose" "${MSG_rtl_platform_rc1}" "${_cmd}" "${*}"; + rtl_log_msg "verbose" "${MSG_rtl_platform_rc1}" "${_rr_cmd}" "${*}"; else - rtl_log_msg "verbose" "${MSG_rtl_platform_rc2}" "${_cmd}"; + rtl_log_msg "verbose" "${MSG_rtl_platform_rc2}" "${_rr_cmd}"; fi; ;; - *) "${_cmd}" "${@}"; + *) "${_rr_cmd}" "${@}"; ;; esac; + return 0; }; rtl_run_cmd_unsplit() { - local _cmd="${1}" _cmdline="" _rc="" IFS; shift; + local _rrcu_cmd="${1}" \ + _rrcu_cmdline="" _rrcu_rc="" IFS; + shift; + while [ ${#} -gt 0 ]; do - [ -n "${1}" ] &&\ - _cmdline="${_cmdline:+${_cmdline}:}${1}"; + [ "${1:+1}" = 1 ] &&\ + _rrcu_cmdline="${_rrcu_cmdline:+${_rrcu_cmdline}:}${1}"; shift; done; - IFS=:; ${_cmd} ${_cmdline}; _rc=$?; - return ${_rc}; + IFS=:; ${_rrcu_cmd} ${_rrcu_cmdline}; _rrcu_rc=$?; + return ${_rrcu_rc}; }; rtl_set_vars() { - local _vars_set_vname="${1}" _vname_dst="${2}" _vname_src_tmpls="${3}" \ - _vars_set_old="" _vars_set_tmp="" _vname_src=""; - - for _vname_src in $(rtl_toupper "${_vname_src_tmpls}"); do - _vname_src="${_vname_src}_${_vname_dst}"; - eval _vval_src='${'"${_vname_src}"':-}'; - if [ "${_vval_src:+1}" = 1 ]; then - eval PKG_${_vname_dst}='${_vval_src}'; - _vars_set_tmp="${_vars_set_tmp:+${_vars_set_tmp} }PKG_${_vname_dst}"; + local _rsv_vars_set_vname="${1}" _rsv_vname_dst="${2}" _rsv_vname_src_tmpls="${3}" \ + _rsv_vars_set_old="" _rsv_vars_set_tmp="" _rsv_vname_src="" _rsv_vnames_src=""; + + rtl_toupper2 \$_rsv_vname_src_tmpls \$_rsv_vnames_src; + for _rsv_vname_src in ${_rsv_vnames_src}; do + _rsv_vname_src="${_rsv_vname_src}_${_rsv_vname_dst}"; + eval _rsv_vval_src="\${${_rsv_vname_src}:-}"; + if [ "${_rsv_vval_src:+1}" = 1 ]; then + eval PKG_${_rsv_vname_dst}='${_rsv_vval_src}'; + _rsv_vars_set_tmp="${_rsv_vars_set_tmp:+${_rsv_vars_set_tmp} }PKG_${_rsv_vname_dst}"; fi; done; - eval _vars_set_old='${'"${_vars_set_vname}"'}'; - rtl_set_var_unsafe "${_vars_set_vname}" "${_vars_set_old:+${_vars_set_old} }${_vars_set_tmp}"; + eval _rsv_vars_set_old="\${${_rsv_vars_set_vname}}"; + rtl_set_var_unsafe "${_rsv_vars_set_vname}" "${_rsv_vars_set_old:+${_rsv_vars_set_old} }${_rsv_vars_set_tmp}"; + + return 0; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_state.subr b/subr.rtl/rtl_state.subr index da091e9c..fdf58a67 100644 --- a/subr.rtl/rtl_state.subr +++ b/subr.rtl/rtl_state.subr @@ -3,42 +3,53 @@ # rtl_state_clear() { - local _workdir="${1}" _pkg_name="${2}" _pkg_fname=""; - for _pkg_fname in $(find "${_workdir}" \ - -maxdepth 1 -mindepth 1 -name .${_pkg_name}.\* -type f); do - rtl_fileop rm "${_pkg_fname}"; + local _rsc_workdir="${1}" _rsc_pkg_name="${2}" \ + _rsc_pkg_fname=""; + + for _rsc_pkg_fname in $( + find "${_rsc_workdir}" \ + -maxdepth 1 \ + -mindepth 1 \ + -name .${_rsc_pkg_name}.\* \ + -type f); + do + rtl_fileop rm "${_rsc_pkg_fname}"; done; + return 0; }; rtl_state_set() { - local _workdir="${1}" _pkg_fname="${2}" _build_step="${3}" \ - _done_fname_pfx="${1}/.${2}"; shift 3; + local _rss_workdir="${1}" _rss_pkg_fname="${2}" _rss_build_step="${3}" \ + _rss_done_fname_pfx="${1}/.${2}"; + shift 3; - rtl_fileop touch "${_done_fname_pfx}.${_build_step}"; + rtl_fileop touch "${_rss_done_fname_pfx}.${_rss_build_step}"; while [ ${#} -ge 1 ]; do if [ "${#1}" -gt 0 ]; then - rtl_fileop rm "${_done_fname_pfx}.${1}"; + rtl_fileop rm "${_rss_done_fname_pfx}.${1}"; fi; shift; done; + return 0; }; rtl_state_test() { - local _workdir="${1}" _pkg_name="${2}" _build_steps="${3}" \ - _restart_at="${4:-}" _build_step="" _done_fname="" \ - IFS="," _rc=0; + local _rst_workdir="${1}" _rst_pkg_name="${2}" _rst_build_steps="${3}" \ + _rst_restart_at="${4:-}" _rst_build_step="" _rst_done_fname="" \ + IFS="," _rst_rc=0; - for _build_step in ${_build_steps}; do - _done_fname="${_workdir}/.${_pkg_name}.${_build_step}"; - if [ "${_restart_at:+1}" != 1 ]\ - || [ "${_restart_at}" = "LAST" ]; then - rtl_fileop test "${_done_fname}"; _rc="${?}"; - elif [ "${_restart_at}" = "ALL" ]; then - _rc=1; + for _rst_build_step in ${_rst_build_steps}; do + _rst_done_fname="${_rst_workdir}/.${_rst_pkg_name}.${_rst_build_step}"; + if [ "${_rst_restart_at:+1}" != 1 ]\ + || [ "${_rst_restart_at}" = "LAST" ]; then + rtl_fileop test "${_rst_done_fname}"; _rst_rc="${?}"; + elif [ "${_rst_restart_at}" = "ALL" ]; then + _rst_rc=1; else - rtl_lmatch "${_restart_at}" "${_build_step}" ","; - _rc=$((${?} ? 0 : 1)); - fi; [ "${_rc}" -eq 0 ] && break; - done; return "${_rc}"; + rtl_lmatch \$_rst_restart_at "${_rst_build_step}" ","; + _rst_rc=$((${?} ? 0 : 1)); + fi; [ "${_rst_rc}" -eq 0 ] && break; + done; + return "${_rst_rc}"; }; # vim:filetype=sh diff --git a/subr.rtl/rtl_string.subr b/subr.rtl/rtl_string.subr index e3e98601..75c5169a 100644 --- a/subr.rtl/rtl_string.subr +++ b/subr.rtl/rtl_string.subr @@ -3,18 +3,22 @@ # rtl_isnumber() { - local _s="${1}" _rc=0; - while [ -n "${_s}" ]; do - case "${_s}" in - [0-9]*) _s="${_s#[0-9]}"; ;; - *) _rc=1; break; ;; + local _ri_s="${1}" \ + _ri_rc=0; + + while [ "${_ri_s:+1}" = 1 ]; do + case "${_ri_s}" in + [0-9]*) _ri_s="${_ri_s#[0-9]}"; ;; + *) _ri_rc=1; break; ;; esac; done; - return "${_rc}"; + + return "${_ri_rc}"; }; rtl_match() { - local _s="${1}" _find="${2}"; - if [ "${_s#${_find}}" != "${_s}" ]; then + local _rm_s="${1}" _rm_find="${2}"; + + if [ "${_rm_s#${_rm_find}}" != "${_rm_s}" ]; then return 0; else return 1; @@ -22,101 +26,135 @@ rtl_match() { }; rtl_matchr() { - local _s="${1}" _find="${2}"; - if [ "${_s%${_find}}" != "${_s}" ]; then + local _rmr_s="${1}" _rmr_find="${2}"; + + if [ "${_rmr_s%${_rmr_find}}" != "${_rmr_s}" ]; then return 0; else return 1; fi; }; +rtl_setrstatus() { + local _rsrs_rstatus="${1#\$}" _rsrs_status="${2}"; + eval ${_rsrs_rstatus}=\"${_rsrs_status}\"; + return 0; +}; + rtl_subst() { - local _s="${1}" _find="${2}" _replace="${3}" _prefix="" _s_new=""; - while [ -n "${_s}" ]; do - case "${_s}" in - *${_find}*) _prefix="${_s%%${_find}*}"; _s="${_s#*${_find}}"; - _s_new="${_s_new:+${_s_new}}${_prefix}${_replace}"; ;; - *) _s_new="${_s_new:+${_s_new}}${_s}"; _s=""; ;; + rtl_subst2 "${1}" "${1}" "${2}" "${3}"; +}; + +rtl_subst2() { + local _rs2_rs="${1#\$}" _rs2_rs_out="${2#\$}" _rs2_find="${3}" _rs2_replace="${4}" \ + _rs2_prefix="" _rs2_s="" _rs2_s_new=""; + + eval _rs2_s="\${${_rs2_rs}}"; + while [ "${_rs2_s:+1}" = 1 ]; do + case "${_rs2_s}" in + *${_rs2_find}*) _rs2_prefix="${_rs2_s%%${_rs2_find}*}"; _rs2_s="${_rs2_s#*${_rs2_find}}"; + _rs2_s_new="${_rs2_s_new:+${_rs2_s_new}}${_rs2_prefix}${_rs2_replace}"; ;; + *) _rs2_s_new="${_rs2_s_new:+${_rs2_s_new}}${_rs2_s}"; _rs2_s=""; ;; esac; done; - printf "%s" "${_s_new}"; + eval ${_rs2_rs_out}='${_rs2_s_new}'; + return 0; }; rtl_tolower() { - local _s="${1}" _s_new=""; - while [ -n "${_s}" ]; do - case "${_s}" in - A*) _s_new="${_s_new:+${_s_new}}a"; _s="${_s#A}"; ;; - B*) _s_new="${_s_new:+${_s_new}}b"; _s="${_s#B}"; ;; - C*) _s_new="${_s_new:+${_s_new}}c"; _s="${_s#C}"; ;; - D*) _s_new="${_s_new:+${_s_new}}d"; _s="${_s#D}"; ;; - E*) _s_new="${_s_new:+${_s_new}}e"; _s="${_s#E}"; ;; - F*) _s_new="${_s_new:+${_s_new}}f"; _s="${_s#F}"; ;; - G*) _s_new="${_s_new:+${_s_new}}g"; _s="${_s#G}"; ;; - H*) _s_new="${_s_new:+${_s_new}}h"; _s="${_s#H}"; ;; - I*) _s_new="${_s_new:+${_s_new}}i"; _s="${_s#I}"; ;; - J*) _s_new="${_s_new:+${_s_new}}j"; _s="${_s#J}"; ;; - K*) _s_new="${_s_new:+${_s_new}}k"; _s="${_s#K}"; ;; - L*) _s_new="${_s_new:+${_s_new}}l"; _s="${_s#L}"; ;; - M*) _s_new="${_s_new:+${_s_new}}m"; _s="${_s#M}"; ;; - N*) _s_new="${_s_new:+${_s_new}}n"; _s="${_s#N}"; ;; - O*) _s_new="${_s_new:+${_s_new}}o"; _s="${_s#O}"; ;; - P*) _s_new="${_s_new:+${_s_new}}p"; _s="${_s#P}"; ;; - Q*) _s_new="${_s_new:+${_s_new}}q"; _s="${_s#Q}"; ;; - R*) _s_new="${_s_new:+${_s_new}}r"; _s="${_s#R}"; ;; - S*) _s_new="${_s_new:+${_s_new}}s"; _s="${_s#S}"; ;; - T*) _s_new="${_s_new:+${_s_new}}t"; _s="${_s#T}"; ;; - U*) _s_new="${_s_new:+${_s_new}}u"; _s="${_s#U}"; ;; - V*) _s_new="${_s_new:+${_s_new}}v"; _s="${_s#V}"; ;; - W*) _s_new="${_s_new:+${_s_new}}w"; _s="${_s#W}"; ;; - X*) _s_new="${_s_new:+${_s_new}}x"; _s="${_s#X}"; ;; - Y*) _s_new="${_s_new:+${_s_new}}y"; _s="${_s#Y}"; ;; - Z*) _s_new="${_s_new:+${_s_new}}z"; _s="${_s#Z}"; ;; + rtl_tolower2 "${1}" "${1}"; +}; + +rtl_tolower2() { + local _rtl2_rs="${1#\$}" _rtl2_rs_out="${2#\$}" \ + _rtl2_s="" _rtl2_s_new=""; + + eval _rtl2_s="\${${_rtl2_rs}}"; + + while [ "${_rtl2_s:+1}" = 1 ]; do + case "${_rtl2_s}" in + A*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}a"; _rtl2_s="${_rtl2_s#A}"; ;; + B*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}b"; _rtl2_s="${_rtl2_s#B}"; ;; + C*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}c"; _rtl2_s="${_rtl2_s#C}"; ;; + D*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}d"; _rtl2_s="${_rtl2_s#D}"; ;; + E*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}e"; _rtl2_s="${_rtl2_s#E}"; ;; + F*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}f"; _rtl2_s="${_rtl2_s#F}"; ;; + G*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}g"; _rtl2_s="${_rtl2_s#G}"; ;; + H*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}h"; _rtl2_s="${_rtl2_s#H}"; ;; + I*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}i"; _rtl2_s="${_rtl2_s#I}"; ;; + J*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}j"; _rtl2_s="${_rtl2_s#J}"; ;; + K*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}k"; _rtl2_s="${_rtl2_s#K}"; ;; + L*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}l"; _rtl2_s="${_rtl2_s#L}"; ;; + M*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}m"; _rtl2_s="${_rtl2_s#M}"; ;; + N*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}n"; _rtl2_s="${_rtl2_s#N}"; ;; + O*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}o"; _rtl2_s="${_rtl2_s#O}"; ;; + P*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}p"; _rtl2_s="${_rtl2_s#P}"; ;; + Q*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}q"; _rtl2_s="${_rtl2_s#Q}"; ;; + R*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}r"; _rtl2_s="${_rtl2_s#R}"; ;; + S*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}s"; _rtl2_s="${_rtl2_s#S}"; ;; + T*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}t"; _rtl2_s="${_rtl2_s#T}"; ;; + U*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}u"; _rtl2_s="${_rtl2_s#U}"; ;; + V*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}v"; _rtl2_s="${_rtl2_s#V}"; ;; + W*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}w"; _rtl2_s="${_rtl2_s#W}"; ;; + X*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}x"; _rtl2_s="${_rtl2_s#X}"; ;; + Y*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}y"; _rtl2_s="${_rtl2_s#Y}"; ;; + Z*) _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}z"; _rtl2_s="${_rtl2_s#Z}"; ;; [!ABCDEFGHIJKLMNOPQRSTUVWXYZ]*) - _s_new="${_s_new:+${_s_new}}${_s%%[ABCDEFGHIJKLMNOPQRSTUVWXYZ]*}"; - while [ "${_s#[!ABCDEFGHIJKLMNOPQRSTUVWXYZ]}" != "${_s}" ]; do - _s="${_s#[!ABCDEFGHIJKLMNOPQRSTUVWXYZ]}"; + _rtl2_s_new="${_rtl2_s_new:+${_rtl2_s_new}}${_rtl2_s%%[ABCDEFGHIJKLMNOPQRSTUVWXYZ]*}"; + while [ "${_rtl2_s#[!ABCDEFGHIJKLMNOPQRSTUVWXYZ]}" != "${_rtl2_s}" ]; do + _rtl2_s="${_rtl2_s#[!ABCDEFGHIJKLMNOPQRSTUVWXYZ]}"; done; ;; esac; done; - printf "%s" "${_s_new}"; + eval ${_rtl2_rs_out}='${_rtl2_s_new}'; + + return 0; }; rtl_toupper() { - local _s="${1}" _s_new=""; - while [ -n "${_s}" ]; do - case "${_s}" in - a*) _s_new="${_s_new:+${_s_new}}A"; _s="${_s#a}"; ;; - b*) _s_new="${_s_new:+${_s_new}}B"; _s="${_s#b}"; ;; - c*) _s_new="${_s_new:+${_s_new}}C"; _s="${_s#c}"; ;; - d*) _s_new="${_s_new:+${_s_new}}D"; _s="${_s#d}"; ;; - e*) _s_new="${_s_new:+${_s_new}}E"; _s="${_s#e}"; ;; - f*) _s_new="${_s_new:+${_s_new}}F"; _s="${_s#f}"; ;; - g*) _s_new="${_s_new:+${_s_new}}G"; _s="${_s#g}"; ;; - h*) _s_new="${_s_new:+${_s_new}}H"; _s="${_s#h}"; ;; - i*) _s_new="${_s_new:+${_s_new}}I"; _s="${_s#i}"; ;; - j*) _s_new="${_s_new:+${_s_new}}J"; _s="${_s#j}"; ;; - k*) _s_new="${_s_new:+${_s_new}}K"; _s="${_s#k}"; ;; - l*) _s_new="${_s_new:+${_s_new}}L"; _s="${_s#l}"; ;; - m*) _s_new="${_s_new:+${_s_new}}M"; _s="${_s#m}"; ;; - n*) _s_new="${_s_new:+${_s_new}}N"; _s="${_s#n}"; ;; - o*) _s_new="${_s_new:+${_s_new}}O"; _s="${_s#o}"; ;; - p*) _s_new="${_s_new:+${_s_new}}P"; _s="${_s#p}"; ;; - q*) _s_new="${_s_new:+${_s_new}}Q"; _s="${_s#q}"; ;; - r*) _s_new="${_s_new:+${_s_new}}R"; _s="${_s#r}"; ;; - s*) _s_new="${_s_new:+${_s_new}}S"; _s="${_s#s}"; ;; - t*) _s_new="${_s_new:+${_s_new}}T"; _s="${_s#t}"; ;; - u*) _s_new="${_s_new:+${_s_new}}U"; _s="${_s#u}"; ;; - v*) _s_new="${_s_new:+${_s_new}}V"; _s="${_s#v}"; ;; - w*) _s_new="${_s_new:+${_s_new}}W"; _s="${_s#w}"; ;; - x*) _s_new="${_s_new:+${_s_new}}X"; _s="${_s#x}"; ;; - y*) _s_new="${_s_new:+${_s_new}}Y"; _s="${_s#y}"; ;; - z*) _s_new="${_s_new:+${_s_new}}Z"; _s="${_s#z}"; ;; + rtl_toupper2 "${1}" "${1}"; +}; + +rtl_toupper2() { + local _rtu2_rs="${1#\$}" _rtu2_rs_out="${2#\$}" _rtu2_s="" _rtu2_s_new=""; + + eval _rtu2_s="\${${_rtu2_rs}}"; + + while [ "${_rtu2_s:+1}" = 1 ]; do + case "${_rtu2_s}" in + a*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}A"; _rtu2_s="${_rtu2_s#a}"; ;; + b*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}B"; _rtu2_s="${_rtu2_s#b}"; ;; + c*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}C"; _rtu2_s="${_rtu2_s#c}"; ;; + d*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}D"; _rtu2_s="${_rtu2_s#d}"; ;; + e*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}E"; _rtu2_s="${_rtu2_s#e}"; ;; + f*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}F"; _rtu2_s="${_rtu2_s#f}"; ;; + g*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}G"; _rtu2_s="${_rtu2_s#g}"; ;; + h*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}H"; _rtu2_s="${_rtu2_s#h}"; ;; + i*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}I"; _rtu2_s="${_rtu2_s#i}"; ;; + j*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}J"; _rtu2_s="${_rtu2_s#j}"; ;; + k*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}K"; _rtu2_s="${_rtu2_s#k}"; ;; + l*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}L"; _rtu2_s="${_rtu2_s#l}"; ;; + m*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}M"; _rtu2_s="${_rtu2_s#m}"; ;; + n*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}N"; _rtu2_s="${_rtu2_s#n}"; ;; + o*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}O"; _rtu2_s="${_rtu2_s#o}"; ;; + p*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}P"; _rtu2_s="${_rtu2_s#p}"; ;; + q*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}Q"; _rtu2_s="${_rtu2_s#q}"; ;; + r*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}R"; _rtu2_s="${_rtu2_s#r}"; ;; + s*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}S"; _rtu2_s="${_rtu2_s#s}"; ;; + t*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}T"; _rtu2_s="${_rtu2_s#t}"; ;; + u*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}U"; _rtu2_s="${_rtu2_s#u}"; ;; + v*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}V"; _rtu2_s="${_rtu2_s#v}"; ;; + w*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}W"; _rtu2_s="${_rtu2_s#w}"; ;; + x*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}X"; _rtu2_s="${_rtu2_s#x}"; ;; + y*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}Y"; _rtu2_s="${_rtu2_s#y}"; ;; + z*) _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}Z"; _rtu2_s="${_rtu2_s#z}"; ;; [!abcdefghijklmnopqrstuvwxyz]*) - _s_new="${_s_new:+${_s_new}}${_s%%[abcdefghijklmnopqrstuvwxyz]*}"; - while [ "${_s#[!abcdefghijklmnopqrstuvwxyz]}" != "${_s}" ]; do - _s="${_s#[!abcdefghijklmnopqrstuvwxyz]}"; + _rtu2_s_new="${_rtu2_s_new:+${_rtu2_s_new}}${_rtu2_s%%[abcdefghijklmnopqrstuvwxyz]*}"; + while [ "${_rtu2_s#[!abcdefghijklmnopqrstuvwxyz]}" != "${_rtu2_s}" ]; do + _rtu2_s="${_rtu2_s#[!abcdefghijklmnopqrstuvwxyz]}"; done; ;; esac; done; - printf "%s" "${_s_new}"; + eval ${_rtu2_rs_out}='${_rtu2_s_new}'; + + return 0; }; # vim:filetype=sh -- cgit v1.2.3