diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/control.sh | 58 |
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 } |