summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-01-05 09:39:30 (EST)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-01-05 09:39:30 (EST)
commit00fa1775a84ffc6327a493e47c3c2301052e3a27 (patch)
treeea7265fcb9c490c981c761a0150d174e0ab044e9 /lib
parent146d06fbe738cf9adaabc2f00f4101d5b074af56 (diff)
ob_parse_control(): Replace if construct with case
Diffstat (limited to 'lib')
-rw-r--r--lib/control.sh109
1 files changed, 55 insertions, 54 deletions
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