From e37e5752619499fdd34393e5aae9937d246e3cab Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Tue, 23 Oct 2012 23:02:31 -0400 Subject: Implement ob_set_substvar(). --- diff --git a/lib/control.sh b/lib/control.sh index 12dc8bd..15093a0 100644 --- a/lib/control.sh +++ b/lib/control.sh @@ -139,6 +139,36 @@ ${_obpco_line# }" return ${?} } +ob_set_substvar() +{ + _ob_local _obssv_name _obssv_value + + if [ ${#} -eq 2 ]; then + _obssv_name="${1}" + _obssv_value="${2}" + else + _ob_return 125 + return ${?} + fi + + # Trim leading and trailing whitespace from value. + _obssv_value="$(echo "${_obssv_value}" | sed -n ' + H; # Store each input line in the hold space. + ${ # At the last line of input, … + g; # … restore the hold space into the pattern space, … + s/^[ \t\n]*//; # … remove leading whitespace, … + s/[ \t\n]*$//; # … remove trailing whitespace, and … + p; # … print the results. + }; + ')" + + _obssv_name="$(echo "${_obssv_name}" | tr 'a-z-' 'A-Z_')" + eval "_OB_SUBSTVAR_${_obssv_name}='${_obssv_value}'" + + _ob_return 125 + return ${?} +} + _ob_parse_control_error() { _ob_local _obpcoe_file _obpcoe_line_nr _obpcoe_msg_id \ -- cgit v0.9.1