summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-04-12 21:56:51 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-04-12 21:56:51 (EDT)
commitdfe87d16781ec2cc9f2b0924381a87a598e6e15d (patch)
tree6340099fb581842b72813a26abff9929e2e5c3c4 /src
parent5e4420c92ae4e64e9308f618f320db0abf84dd9b (diff)
parse_control(): Drop user_data and require fields args
Diffstat (limited to 'src')
-rw-r--r--src/control.sh58
1 files changed, 22 insertions, 36 deletions
diff --git a/src/control.sh b/src/control.sh
index 283e3d4..f617856 100644
--- a/src/control.sh
+++ b/src/control.sh
@@ -43,9 +43,9 @@ parse_control()
{
local file="${1}"
local field_cb="${2}"
- local user_data="${3}"
- shift 3
- local check_fields=
+ local req_fields=" ${3} "
+ local opt_fields=" ${4} "
+ shift 4
local req_fields=
local opt_fields=
local got_fields=
@@ -55,14 +55,6 @@ parse_control()
local value=
local sep=
- check_fields='false'
- if [ ${#} -eq 2 ]; then
- req_fields=" ${1} "
- opt_fields=" ${2} "
- shift 2
- check_fields='true'
- fi
-
got_fields=' '
line_nr=0
@@ -78,8 +70,8 @@ parse_control()
;;
[!\ ]*':'*) # "Name: Value" line.
if [ -n "${name}" ]; then
- if ! "${field_cb}" "${name}" "${value}"\
- "${user_data}"; then
+ if ! "${field_cb}" "${name}" "${value}"
+ then
return 0
fi
fi
@@ -107,17 +99,14 @@ parse_control()
) ${req_fields#* ${name} }"
continue
esac
- if ${check_fields}; then
- case "${opt_fields}" in *" ${name} "*)
- # Optional field.
- continue
- esac
- # Unknown field.
- _parse_control_error \
- "${file}" "${line_nr}" \
- 'control_unknown_field' \
- "${name}"
- fi
+ case "${opt_fields}" in *" ${name} "*)
+ # Optional field.
+ continue
+ esac
+ # Unknown field.
+ _parse_control_error \
+ "${file}" "${line_nr}" \
+ 'control_unknown_field' "${name}"
;;
' '*) # Continuation line.
if [ -z "${name}" ]; then
@@ -135,22 +124,19 @@ parse_control()
EOF
if [ -n "${name}" ]; then
- if ! "${field_cb}" "${name}" "${value}" "${user_data}"; then
+ if ! "${field_cb}" "${name}" "${value}"; then
return 0
fi
fi
- if ${check_fields}; then
- case "${req_fields}" in *[!\ ]*)
- # Missing required control fields.
- sep="$(get_msg 'list_item_separator')"
- req_fields="$(printf "%s${sep}" ${req_fields}; \
- printf 'x')"
- req_fields="${req_fields%${sep}x}"
- _parse_control_error "${file}" '0' \
- 'control_missing_fields' "${req_fields}"
- esac
- fi
+ case "${req_fields}" in *[!\ ]*)
+ # Missing required control fields.
+ sep="$(get_msg 'list_item_separator')"
+ req_fields="$(printf "%s${sep}" ${req_fields}; printf 'x')"
+ req_fields="${req_fields%${sep}x}"
+ _parse_control_error "${file}" '0' 'control_missing_fields' \
+ "${req_fields}"
+ esac
return 0
}