From 80de8da80a237261b6a2d9881f1a6c2f9eff1537 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Mon, 18 Mar 2019 16:09:11 -0400 Subject: ob_set_binary_substvar(): New function --- 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 diff --git a/man/local.mk b/man/local.mk index ee94e1d..f88baf3 100644 --- a/man/local.mk +++ b/man/local.mk @@ -52,6 +52,7 @@ man3_MANS = \ %reldir%/ob_plat_is_concerned.3 \ %reldir%/ob_get_system_path.3 \ %reldir%/ob_parse_control.3 \ + %reldir%/ob_set_binary_substvar.3 \ %reldir%/ob_set_source_substvar.3 \ %reldir%/ob_substvars.3 \ %reldir%/ob_parse_changelog.3 \ -- cgit v0.9.1