From 00fa1775a84ffc6327a493e47c3c2301052e3a27 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sat, 05 Jan 2019 09:39:30 -0500 Subject: ob_parse_control(): Replace if construct with case --- diff --git a/lib/control.sh b/lib/control.sh index 9115d7f..bbca4d8 100644 --- a/lib/control.sh +++ b/lib/control.sh @@ -109,64 +109,65 @@ ob_parse_control() while IFS= read -r line; do line_nr=$(($line_nr + 1)) - if [ -z "$(echo ${line})" ]; then - _ob_parse_control_error "${file}" "${line_nr}" \ - 'control_empty_line' - elif [ "${line#\#}" != "${line}" ]; then - # Comment. - : - elif [ "${line# }" = "${line}" ]; then - # "Name: Value" line. - if [ -n "${name}" ]; then - OB_CONTROL_NAME="${name}" - OB_CONTROL_VALUE="${value}" - "${field_cb}" - if [ ${?} -ne 0 ]; then - return 0 - fi - fi - name="${line%%:*}" - value="${line#*:}" - value="${value# }" - if [ -z "${name}" \ - -o "${name}" = "${line}" ]; then - # Badly formatted control field. + case "${line}" in + '') _ob_parse_control_error "${file}" "${line_nr}" \ - '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}" + 'control_empty_line' + ;; + '#'*) # Comment. + ;; + [!\ ]*':'*) # "Name: Value" line. + if [ -n "${name}" ]; then + OB_CONTROL_NAME="${name}" + OB_CONTROL_VALUE="${value}" + "${field_cb}" + if [ ${?} -ne 0 ]; then + return 0 + fi + fi + name="${line%%:*}" + value="${line#*:}" + value="${value# }" + if [ -z "${name}" \ + -o "${name}" = "${line}" ]; then + # Badly formatted control field. + _ob_parse_control_error "${file}" "${line_nr}" \ + '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 + # Duplicate field. + _ob_parse_control_error "${file}" "${line_nr}" \ + 'control_duplicate_field' "${name}" else - # Remove field from list of required fields. - req_fields="$(echo "${req_fields}" | \ - sed "s/${name}//")" + got_fields="${got_fields}${name} " fi - fi - if [ "${got_fields% ${name} *}" != \ - "${got_fields}" ]; then - # Duplicate field. - _ob_parse_control_error "${file}" "${line_nr}" \ - 'control_duplicate_field' "${name}" - else - got_fields="${got_fields}${name} " - fi - else - # Continuation line. - if [ -z "${name}" ]; then - # Expecting a "Name: Value" line. - _ob_parse_control_error "${file}" "${line_nr}" \ - 'control_found_continuation' - continue - fi - value="${value} + ;; + ' '*) # Continuation line. + if [ -z "${name}" ]; then + # Expecting a "Name: Value" line. + _ob_parse_control_error "${file}" "${line_nr}" \ + 'control_found_continuation' + continue + fi + value="${value} ${line# }" - fi + ;; + esac done <<-EOF $(cat "${file}") EOF -- cgit v0.9.1