summaryrefslogtreecommitdiffstats
path: root/lib/control.sh
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-03-12 19:29:58 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-03-12 19:29:58 (EDT)
commitb14d0b56dd24c705130e76d6f290ee87c1ffe339 (patch)
treea10d167c40ce9428a434694fccd8050747341263 /lib/control.sh
parent735aca5b44e8d731463b8f04b850de2b4b3d2df7 (diff)
ob_parse_control(): Rewrite field checking
Get rid of the echo and sed pipeline and use case constructs instead of "[" commands with "${parameter%word}" expansions. The new logic also will only report duplicate unknown fields once.
Diffstat (limited to 'lib/control.sh')
-rw-r--r--lib/control.sh49
1 files changed, 26 insertions, 23 deletions
diff --git a/lib/control.sh b/lib/control.sh
index 48b71fa..b99a05c 100644
--- a/lib/control.sh
+++ b/lib/control.sh
@@ -75,7 +75,6 @@ ob_parse_control()
local req_fields=
local opt_fields=
local check_fields=
- local all_fields=
local got_fields=
local line_nr=
local line=
@@ -91,10 +90,9 @@ ob_parse_control()
file="${1}"
field_cb="${2}"
user_data="${3}"
- req_fields="${4}"
- opt_fields="${5}"
+ req_fields=" ${4} "
+ opt_fields=" ${5} "
check_fields='true'
- all_fields=" ${req_fields} ${opt_fields} "
else
return 125
fi
@@ -127,26 +125,31 @@ ob_parse_control()
'control_bad_nv'
continue
fi
- if ${check_fields}; then
- if [ "${all_fields% ${name} *}" = \
- "${all_fields}" ]; then
- # Unknown field.
- _ob_parse_control_error \
- "${file}" "${line_nr}" \
- 'control_unknown_field' "${name}"
- else
- # Remove field from list of required fields.
- req_fields="$(echo "${req_fields}" | \
- sed "s/${name}//")"
- fi
- fi
- if [ "${got_fields% ${name} *}" != \
- "${got_fields}" ]; then
+ case "${got_fields}" in *" ${name} "*)
# Duplicate field.
- _ob_parse_control_error "${file}" "${line_nr}" \
- 'control_duplicate_field' "${name}"
- else
- got_fields="${got_fields}${name} "
+ _ob_parse_control_error \
+ "${file}" "${line_nr}" \
+ 'control_duplicate_field' \
+ "${name}"
+ continue
+ esac
+ got_fields="${got_fields}${name} "
+ case "${req_fields}" in *" ${name} "*)
+ # Required field: remove from list.
+ req_fields="${req_fields% ${name} *}$(:\
+ ) ${req#* ${field} }"
+ continue
+ esac
+ if ${check_fields}; then
+ case "${opt_fields}" in *" ${name} "*)
+ # Optional field.
+ continue
+ esac
+ # Unknown field.
+ _ob_parse_control_error \
+ "${file}" "${line_nr}" \
+ 'control_unknown_field' \
+ "${name}"
fi
;;
' '*) # Continuation line.