summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-01-05 10:53:01 (EST)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-01-05 10:53:01 (EST)
commit837d2a8ad902052d20e2729e7e505d95a593f3b8 (patch)
tree4710c6c97f2d9b3acef3553e42da9bae4c243068
parentddf9028ac7a32f5ac54099e341b059b62da46915 (diff)
ob_parse_control(): Pass field name and value as args
-rw-r--r--lib/control.sh25
-rw-r--r--lib/package/2.sh19
-rwxr-xr-xtests/ob_parse_control.sh27
3 files changed, 42 insertions, 29 deletions
diff --git a/lib/control.sh b/lib/control.sh
index bf3e8fb..da48313 100644
--- a/lib/control.sh
+++ b/lib/control.sh
@@ -1,6 +1,6 @@
# Functions for parsing control files
#
-# Copyright (C) 2012, 2018 Patrick McDermott
+# Copyright (C) 2012, 2018, 2019 Patrick McDermott
#
# This file is part of opkbuild.
#
@@ -19,9 +19,6 @@
_OB_SUBSTVARS_MAX_DEPTH=50
-OB_CONTROL_NAME=
-OB_CONTROL_VALUE=
-
_ob_parse_control_error()
{
local file=
@@ -54,9 +51,8 @@ _ob_parse_control_error()
## @brief Parse a control file
## @details \fBob_parse_control\fP parses a control file of field names and
## values formatted like RFC 822 (or RFC 2822 or RFC 5322) headers.
-## For each field, \fBob_parse_control\fP calls \fIfield_cb\fP after
-## setting \fIOB_CONTROL_NAME\fP to the field name and
-## \fIOB_CONTROL_VALUE\fP to the field value. If \fIreq_fields\fP and
+## For each field, \fBob_parse_control\fP calls \fIfield_cb\fP with the
+## field name and value as arguments. If \fIreq_fields\fP and
## \fIopt_fields\fP are given, \fBob_parse_control\fP verifies that the
## input control file contains all fields listed in \fIreq_fields\fP
## and no fields that are listed in neither \fIreq_fields\fP nor
@@ -70,10 +66,9 @@ _ob_parse_control_error()
## @return Returns 0 after parsing, or 125 if called with an incorrect number of
## arguments.
## @stderr Prints error messages on parse errors.
-## @pure maybe This function sets global variables, but they're only intended
-## for use by \fIfield_cb\fP, which is called during the lifetime of
-## this function. Whether this function is subshell-safe in
-## practice depends on whether \fIfield_cb\fP is subshell-safe.
+## @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=
@@ -118,9 +113,7 @@ ob_parse_control()
;;
[!\ ]*':'*) # "Name: Value" line.
if [ -n "${name}" ]; then
- OB_CONTROL_NAME="${name}"
- OB_CONTROL_VALUE="${value}"
- "${field_cb}"
+ "${field_cb}" "${name}" "${value}"
if [ ${?} -ne 0 ]; then
return 0
fi
@@ -172,9 +165,7 @@ ${line# }"
EOF
if [ -n "${name}" ]; then
- OB_CONTROL_NAME="${name}"
- OB_CONTROL_VALUE="${value}"
- "${field_cb}"
+ "${field_cb}" "${name}" "${value}"
if [ ${?} -ne 0 ]; then
return 0
fi
diff --git a/lib/package/2.sh b/lib/package/2.sh
index c1c37d5..4ca7346 100644
--- a/lib/package/2.sh
+++ b/lib/package/2.sh
@@ -69,7 +69,11 @@ _ob_get_binary_packages_2()
_ob_srcfield_2()
{
- _ob_set_source_parameter "${OB_CONTROL_NAME}" "${OB_CONTROL_VALUE}"
+ local name="${1}"
+ local value="${2}"
+ shift 2
+
+ _ob_set_source_parameter "${name}" "${value}"
return 0
}
@@ -89,8 +93,11 @@ _ob_change_2()
_ob_binfield_2()
{
- _ob_set_binary_parameter "${_OB_CURRENT_PACKAGE_2}" "${OB_CONTROL_NAME}" \
- "${OB_CONTROL_VALUE}"
+ local name="${1}"
+ local value="${2}"
+ shift 2
+
+ _ob_set_binary_parameter "${_OB_CURRENT_PACKAGE_2}" "${name}" "${value}"
return 0
}
@@ -163,7 +170,11 @@ _ob_set_package_substvars_2()
_ob_substvar_2()
{
- ob_set_substvar "${OB_CONTROL_NAME}" "${OB_CONTROL_VALUE}"
+ local name="${1}"
+ local value="${2}"
+ shift 2
+
+ ob_set_substvar "${name}" "${value}"
return 0
}
diff --git a/tests/ob_parse_control.sh b/tests/ob_parse_control.sh
index 90bcb0e..26222f2 100755
--- a/tests/ob_parse_control.sh
+++ b/tests/ob_parse_control.sh
@@ -54,8 +54,12 @@ is()
field_1()
{
- is 'maintainer field name' "${OB_CONTROL_NAME}" 'Maintainer'
- is 'maintainer field value' "${OB_CONTROL_VALUE}" \
+ local name="${1}"
+ local value="${2}"
+ shift 2
+
+ is 'maintainer field name' "${name}" 'Maintainer'
+ is 'maintainer field value' "${value}" \
'"J. Random Hacker" <jrandom@example.com>'
return 0
@@ -63,8 +67,12 @@ field_1()
field_2()
{
- is 'build-depends field name' "${OB_CONTROL_NAME}" 'Build-Depends'
- is 'build-depends field value' "${OB_CONTROL_VALUE}" \
+ local name="${1}"
+ local value="${2}"
+ shift 2
+
+ is 'build-depends field name' "${name}" 'Build-Depends'
+ is 'build-depends field value' "${value}" \
"opkhelper-3.0,${LF}libfoo-dev,${LF} libbar-dev,"
return 0
@@ -72,9 +80,12 @@ field_2()
field_3()
{
- is 'homepage field name' "${OB_CONTROL_NAME}" 'Homepage'
- is 'homepage field value' "${OB_CONTROL_VALUE}" \
- 'http://www.example.com/'
+ local name="${1}"
+ local value="${2}"
+ shift 2
+
+ is 'homepage field name' "${name}" 'Homepage'
+ is 'homepage field value' "${value}" 'http://www.example.com/'
return 0
}
@@ -87,7 +98,7 @@ field_4()
field_cb()
{
field=$((${field} + 1))
- "field_${field}"
+ "field_${field}" "${@}"
}
ob_parse_control - field_cb 'Maintainer' 'Build-Depends Homepage' <<-EOF