From b14d0b56dd24c705130e76d6f290ee87c1ffe339 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Tue, 12 Mar 2019 19:29:58 -0400 Subject: 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. --- (limited to 'lib/control.sh') 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. -- cgit v0.9.1