diff options
Diffstat (limited to 'lib/control.sh')
-rw-r--r-- | lib/control.sh | 67 |
1 files changed, 21 insertions, 46 deletions
diff --git a/lib/control.sh b/lib/control.sh index 58bf68b..c29d4a0 100644 --- a/lib/control.sh +++ b/lib/control.sh @@ -21,15 +21,11 @@ _OB_SUBSTVARS_MAX_DEPTH=50 _ob_parse_control_error() { - local file= - local line_nr= - local msg_id= - local file_info= - file="${1}" line_nr="${2}" msg_id="${3}" - shift 3 + shift 3 || _ob_abort + local file_info= if [ ${line_nr} -eq 0 ]; then file_info="$(printf '%20s' "${file}")" @@ -61,20 +57,20 @@ _ob_parse_control_error() ## @operand user_data req Data to pass to \fIfield_cb\fP. ## @operand req_fields opt Required fields that must appear in the control file. ## @operand opt_fields opt Optional fields that may appear in the control file. -## @return Returns 0 after parsing, or 125 if called with an incorrect number of -## arguments. +## @return Returns 0 after parsing. ## @stderr Prints error messages on parse errors. ## @pure maybe This function has no side effects. Whether this function is ## subshell-safe in practice depends on whether \fIfield_cb\fP is ## subshell-safe. ob_parse_control() { - local file= - local field_cb= - local user_data= + local file="${1}" + local field_cb="${2}" + local user_data="${3}" + shift 3 || _ob_abort + local check_fields= local req_fields= local opt_fields= - local check_fields= local got_fields= local line_nr= local line= @@ -82,20 +78,11 @@ ob_parse_control() local value= local sep= - if [ ${#} -eq 3 ]; then - file="${1}" - field_cb="${2}" - user_data="${3}" - check_fields='false' - elif [ ${#} -eq 5 ]; then - file="${1}" - field_cb="${2}" - user_data="${3}" - req_fields=" ${4} " - opt_fields=" ${5} " + check_fields='false' + if [ ${#} -eq 2 ]; then + req_fields=" ${1} " + opt_fields=" ${2} " check_fields='true' - else - return 125 fi got_fields=' ' @@ -195,24 +182,18 @@ ob_parse_control() ## 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. -## @return Returns 0 on success, or 125 if called with an incorrect number of -## arguments or if \fIname\fP is empty or contains invalid characters. +## @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_substvar() { - local name= - local value= - - if [ ${#} -eq 2 ]; then - name="${1}" - value="${2}" - else - return 125 - fi + local name="${1}" + local value="${2}" + shift 2 || _ob_abort # Convert variable name to uppercase and validate. case "${name}" in *[!A-Za-z0-9-]* | '') - return 125 + return 1 esac name="$(tr 'a-z-' 'A-Z_' <<-EOF ${name} @@ -234,13 +215,13 @@ ob_set_substvar() ## \fBob_set_substvar\fP(3) in a string. The format for variable ## substitutions is \fI${var}\fP, and substitutions can be nested. ## @operand string req The string in which to substitute variables. -## @return Returns 0 on success, 1 on possible recursion, or 125 if called with -## an incorrect number of arguments. +## @return Returns 0 on success or 1 on possible recursion. ## @stderr Prints a warning on possible recursion. ## @pure yes This function has no side effects. ob_substvars() { - local string= + local string="${1}" + shift 1 || _ob_abort local depth= local lhs= local name= @@ -248,12 +229,6 @@ ob_substvars() local old_rhs= local value= - if [ ${#} -eq 1 ]; then - string="${1}" - else - return 125 - fi - # Logic inspired by that of dpkg's Dpkg::Substvars::substvars() subroutine. depth=0 |