diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/control.sh | 34 |
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 |