From dfe87d16781ec2cc9f2b0924381a87a598e6e15d Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Fri, 12 Apr 2019 21:56:51 -0400 Subject: parse_control(): Drop user_data and require fields args --- (limited to 'src') 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 } -- cgit v0.9.1