summaryrefslogtreecommitdiffhomepage
path: root/subr.rtl
diff options
context:
space:
mode:
Diffstat (limited to 'subr.rtl')
-rw-r--r--subr.rtl/rtl_fileop.subr19
-rw-r--r--subr.rtl/rtl_list.subr48
2 files changed, 66 insertions, 1 deletions
diff --git a/subr.rtl/rtl_fileop.subr b/subr.rtl/rtl_fileop.subr
index 0f999ad7..9dfc266d 100644
--- a/subr.rtl/rtl_fileop.subr
+++ b/subr.rtl/rtl_fileop.subr
@@ -17,6 +17,12 @@ rtlp_fileop_log() {
};
#
+# Public globals
+#
+
+RTL_FILEOP_SOURCE_FNAME="";
+
+#
# Public subroutines
#
@@ -125,7 +131,7 @@ rtl_fileop() {
touch ${2:+-t "${2}"} -- "${1}"; _rf_rc="${?}";
fi; ;;
- mkdir|mkfifo|rm|source|source_opt|test)
+ mkdir|mkfifo|rm|source|source_with_fnamevar|source_opt|source_opt_with_fnamevar|test)
while [ \( "${?}" -eq 0 \) -a \( ""${#}"" -gt 0 \) ]; do
if [ "${1:+1}" != 1 ]; then
rtl_log_msgV "fatalexit" "${MSG_rtl_fileop_invparm}" "${_rf_op}" "${*}";
@@ -154,11 +160,22 @@ rtl_fileop() {
&& rtlp_fileop_check "${PREFIX:-}" "${1}"; then
rtlp_fileop_log "Sourcing file \`${1}'.";
. "${1}"; _rf_rc="${?}";
+ elif [ "${_rf_op}" = source_with_fnamevar ]\
+ && rtlp_fileop_check "${PREFIX:-}" "${1}"; then
+ rtlp_fileop_log "Sourcing file \`${1}'.";
+ RTL_FILEOP_SOURCE_FNAME="${1}";
+ . "${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}"; _rf_rc="${?}";
+ elif [ "${_rf_op}" = source_opt_with_fnamevar ]\
+ && rtl_fileop test "${1}"\
+ && rtlp_fileop_check "${PREFIX:-}" "${1}"; then
+ rtlp_fileop_log "Sourcing file \`${1}'.";
+ RTL_FILEOP_SOURCE_FNAME="${1}";
+ . "${1}"; _rf_rc="${?}";
elif [ "${_rf_op}" = test ]\
&& rtlp_fileop_check "${PREFIX:-}" "${1}"\
&& ! [ \( -L "${1}" \) -o \( -e "${1}" \) ]; then
diff --git a/subr.rtl/rtl_list.subr b/subr.rtl/rtl_list.subr
index 36bc77e9..0ec53661 100644
--- a/subr.rtl/rtl_list.subr
+++ b/subr.rtl/rtl_list.subr
@@ -222,6 +222,54 @@ rtl_llift2() {
};
#
+# rtl_llift_set() - convert list w/ separator to set
+# @_rlist: in reference to list
+# @_rset_new: out reference to new set
+# @_sep: single non-zero, possibly multi-character, separator
+#
+# Notate bene: all list items in @_rlist must form valid shell parameter name substrings;
+# no list item must be named "__000000__"
+# Returns: zero (0) on success, non-zero (>0) on failure
+#
+rtl_llift_set() {
+ local _rls3_rlist="${1#\$}" _rls3_rset_new="${2#\$}" _rls3_sep="${3:-}" \
+ _rls3_litem="";
+
+ if [ "${_rls3_sep:+1}" = 1 ]; then
+ local IFS="${_rls3_sep}";
+ else
+ local _rls3_sep=" " IFS="${RTL_IFS_ORIG}";
+ fi;
+
+ eval set -- '${'"${_rls3_rlist}"'}';
+ eval "${_rls3_rset_new}___000000__=\${${_rls3_rlist}}";
+ for _rls3_litem in "${@}"; do
+ eval "${_rls3_rset_new}_${_rls3_litem}=1";
+ done;
+ return 0;
+};
+
+#
+# rtl_llift_unset() - unset set previously created w/ rtl_llift_set()
+# @_rset: in reference to set
+#
+# Returns: zero (0) on success, non-zero (>0) on failure
+#
+rtl_llift_unset() {
+ local _rlu_rset="${1#\$}" \
+ _rlu_index="" _rlu_item="";
+
+ if rtl_get_var_unsafe \$_rlu_index "${_rlu_rset}___000000__"; then
+ for _rlu_item in ${_rlu_index}; do
+ unset "${_rlu_rset}_${_rlu_item}";
+ done;
+ unset "${_rlu_rset}___000000__";
+ fi;
+
+ return 0;
+};
+
+#
# rtl_lmatch() - check if item(s) in list
# @_rlist: in reference to list
# @_item: item(s) to search for