summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-03-18 16:09:11 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-03-18 16:11:43 (EDT)
commit80de8da80a237261b6a2d9881f1a6c2f9eff1537 (patch)
treed2b7a8e0f749d2b898e984aed0e854deba2b84e3 /lib
parent7f93ffb1839c39e16495c8feb450e9ae00a3777f (diff)
ob_set_binary_substvar(): New function
Diffstat (limited to 'lib')
-rw-r--r--lib/control.sh34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/control.sh b/lib/control.sh
index d25527f..75a59d5 100644
--- a/lib/control.sh
+++ b/lib/control.sh
@@ -216,6 +216,40 @@ ob_set_source_substvar()
return 0
}
+## @brief Set a binary package substitution variable
+## @details \fBob_set_source_substvar\fP() sets a binary package substitution
+## variable for later use by \fBob_substvars\fP(3).
+## @operand name req The name of the substitution variable. May only consist
+## of uppercase and lowercase Latin letters, digits, and
+## hyphens and must be at least one character long.
+## @operand value req The value of the substitution variable.
+## @operand package req The package for which to set the substitution variable.
+## @return Returns 0 on success, or 1 if \fIname\fP is empty or contains invalid
+## characters.
+## @pure no This function sets an internal global variable.
+ob_set_binary_substvar()
+{
+ local name="${1}"
+ local value="${2}"
+ local package="${3}"
+ shift 3 || _ob_abort
+
+ # Convert variable name to uppercase and validate.
+ case "${name}" in *[!A-Za-z0-9-]* | '')
+ return 1
+ esac
+ name="$(printf '%s' "${name}" | tr 'a-z-' 'A-Z_')"
+
+ # Trim leading and trailing whitespace from value.
+ value="$(printf '%s' "${value}" | sed -n "${_OB_SUBSTVAR_TRIM_SED}")"
+
+ # TODO: Maybe disallow variable names beginning with hyphens, and/or
+ # otherwise make this safer.
+ eval "_OB_SUBSTVAR_BIN_${package}__${name}=\"\${value}\""
+
+ return 0
+}
+
## @brief Substitute variables in text
## @details \fBob_substvars\fP() substitutes variables previously set with
## \fBob_set_source_substvar\fP(3) in a string. The format for