From d44d31a8f786d39b59827048de6cbb9143e49550 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sat, 05 Jan 2019 11:01:42 -0500 Subject: ob_parse_control(): Add a user_data operand --- diff --git a/lib/control.sh b/lib/control.sh index da48313..0bdf77c 100644 --- a/lib/control.sh +++ b/lib/control.sh @@ -61,6 +61,7 @@ _ob_parse_control_error() ## without verifying that all required fields were found. ## @operand file req The control file to parse, or "-" for standard input. ## @operand field_cb req Callback to run for each field. +## @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 @@ -73,6 +74,7 @@ ob_parse_control() { local file= local field_cb= + local user_data= local req_fields= local opt_fields= local check_fields= @@ -83,15 +85,17 @@ ob_parse_control() local name= local value= - if [ ${#} -eq 2 ]; then + if [ ${#} -eq 3 ]; then file="${1}" field_cb="${2}" + user_data="${3}" check_fields='false' - elif [ ${#} -eq 4 ]; then + elif [ ${#} -eq 5 ]; then file="${1}" field_cb="${2}" - req_fields="${3}" - opt_fields="${4}" + user_data="${3}" + req_fields="${4}" + opt_fields="${5}" check_fields='true' all_fields=" ${req_fields} ${opt_fields} " else @@ -113,7 +117,7 @@ ob_parse_control() ;; [!\ ]*':'*) # "Name: Value" line. if [ -n "${name}" ]; then - "${field_cb}" "${name}" "${value}" + "${field_cb}" "${name}" "${value}" "${user_data}" if [ ${?} -ne 0 ]; then return 0 fi @@ -165,7 +169,7 @@ ${line# }" EOF if [ -n "${name}" ]; then - "${field_cb}" "${name}" "${value}" + "${field_cb}" "${name}" "${value}" "${user_data}" if [ ${?} -ne 0 ]; then return 0 fi diff --git a/lib/package/2.sh b/lib/package/2.sh index 4ca7346..c1d61be 100644 --- a/lib/package/2.sh +++ b/lib/package/2.sh @@ -22,20 +22,18 @@ _OB_SOURCE_FIELDS_OPTIONAL_2='Build-Depends Homepage' _OB_BINARY_FIELDS_REQUIRED_2='Architecture Platform Description' _OB_BINARY_FIELDS_OPTIONAL_2='Essential Depends Recommends Suggests '\ 'Pre-Depends Conflicts Provides Replaces' -_OB_CURRENT_PACKAGE_2= _ob_parse_package_metadata_2() { local pkg= - ob_parse_control "${_OB_PACKAGE_DIR}/control" _ob_srcfield_2 \ + ob_parse_control "${_OB_PACKAGE_DIR}/control" _ob_srcfield_2 '' \ "${_OB_SOURCE_FIELDS_REQUIRED_2}" "${_OB_SOURCE_FIELDS_OPTIONAL_2}" ob_parse_changelog "${_OB_PACKAGE_DIR}/changelog" _ob_change_2 for pkg in $(ob_get_binary_packages); do - _OB_CURRENT_PACKAGE_2="${pkg}" ob_parse_control "${_OB_PACKAGE_DIR}/${pkg}.pkg/control" \ - _ob_binfield_2 \ + _ob_binfield_2 "${pkg}" \ "${_OB_BINARY_FIELDS_REQUIRED_2}" "${_OB_BINARY_FIELDS_OPTIONAL_2}" done @@ -71,7 +69,8 @@ _ob_srcfield_2() { local name="${1}" local value="${2}" - shift 2 + local user_data="${3}" + shift 3 _ob_set_source_parameter "${name}" "${value}" @@ -95,9 +94,10 @@ _ob_binfield_2() { local name="${1}" local value="${2}" - shift 2 + local pkg="${3}" + shift 3 - _ob_set_binary_parameter "${_OB_CURRENT_PACKAGE_2}" "${name}" "${value}" + _ob_set_binary_parameter "${pkg}" "${name}" "${value}" return 0 } @@ -157,7 +157,8 @@ _ob_set_package_substvars_2() fi if [ -f "${_OB_PACKAGE_DIR}/substvars" ]; then - ob_parse_control "${_OB_PACKAGE_DIR}/substvars" _ob_substvar_2 + ob_parse_control "${_OB_PACKAGE_DIR}/substvars" \ + _ob_substvar_2 '' fi ob_set_substvar 'Source-Version' "$(ob_get_source_parameter 'Version')" @@ -172,7 +173,8 @@ _ob_substvar_2() { local name="${1}" local value="${2}" - shift 2 + local user_data="${3}" + shift 3 ob_set_substvar "${name}" "${value}" diff --git a/tests/ob_parse_control.sh b/tests/ob_parse_control.sh index 26222f2..c9e4289 100755 --- a/tests/ob_parse_control.sh +++ b/tests/ob_parse_control.sh @@ -56,7 +56,8 @@ field_1() { local name="${1}" local value="${2}" - shift 2 + local user_data="${3}" + shift 3 is 'maintainer field name' "${name}" 'Maintainer' is 'maintainer field value' "${value}" \ @@ -69,7 +70,8 @@ field_2() { local name="${1}" local value="${2}" - shift 2 + local user_data="${3}" + shift 3 is 'build-depends field name' "${name}" 'Build-Depends' is 'build-depends field value' "${value}" \ @@ -82,7 +84,8 @@ field_3() { local name="${1}" local value="${2}" - shift 2 + local user_data="${3}" + shift 3 is 'homepage field name' "${name}" 'Homepage' is 'homepage field value' "${value}" 'http://www.example.com/' @@ -101,7 +104,7 @@ field_cb() "field_${field}" "${@}" } -ob_parse_control - field_cb 'Maintainer' 'Build-Depends Homepage' <<-EOF +ob_parse_control - field_cb '' 'Maintainer' 'Build-Depends Homepage' <<-EOF ${CONTROL} EOF -- cgit v0.9.1