diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-03-11 18:18:16 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-03-11 18:34:38 (EDT) |
commit | 71736e27476d44569d64e7a1f4bf2416dacc4955 (patch) | |
tree | 4fc41df5db0ce016f4344ad52b1be786ce129238 /lib | |
parent | b42e1fbec636def4f6acf8bd6dec94048e042660 (diff) |
ob_parse_changelog(): Replace if construct with case
Diffstat (limited to 'lib')
-rw-r--r-- | lib/changelog.sh | 183 |
1 files changed, 95 insertions, 88 deletions
diff --git a/lib/changelog.sh b/lib/changelog.sh index a679db0..0fc07b5 100644 --- a/lib/changelog.sh +++ b/lib/changelog.sh @@ -115,100 +115,107 @@ ob_parse_changelog() while IFS= read line; do line_nr=$(($line_nr + 1)) - if [ -z "${line}" ]; then - if [ "${expect}" = 'start_changes' ]; then - OB_CHANGELOG_CHANGES="${OB_CHANGELOG_CHANGES}${_OB_LF}${line}" - elif [ "${expect}" = 'next_or_eof' ]; then - : - elif [ "${expect}" != 'changes_or_trailer' ]; then - _ob_parse_changelog_error "${file}" "${line_nr}" \ - 'changelog_found_blank_line' \ - "$(_ob_get_changelog_expect_str "${expect}")" - else - blank_lines="${blank_lines}${_OB_LF}${line}" - fi - elif [ "${line# }" = "${line}" ]; then - if [ "${expect}" != 'first_heading' -a \ - "${expect}" != 'next_or_eof' ]; then - _ob_parse_changelog_error "${file}" "${line_nr}" \ - 'changelog_found_heading' \ - "$(_ob_get_changelog_expect_str "${expect}")" - fi - source="${line%% (*}" - line_="${line#* (}" - distribution="${line_##*) }" - line_="${line_%) *}" - version="${line_}" - if [ -z "${source}" -o -z "${distribution}" -o \ - -z "${version}" -o \ - "${version% *}" != "${version}" ]; then - _ob_parse_changelog_error "${file}" "${line_nr}" \ - 'changelog_bad_heading' - OB_CHANGELOG_SOURCE= - OB_CHANGELOG_VERSION= - OB_CHANGELOG_DISTRIBUTION= - OB_CHANGELOG_CHANGES= - else - if ! ob_validate_source_name "${source}"; then - _ob_parse_changelog_error \ - "${file}" "${line_nr}" \ - 'changelog_bad_source' "${source}" + case "${line}" in + '') + if [ "${expect}" = 'start_changes' ]; then + OB_CHANGELOG_CHANGES="${OB_CHANGELOG_CHANGES}${_OB_LF}${line}" + elif [ "${expect}" = 'next_or_eof' ]; then + : + elif [ "${expect}" != 'changes_or_trailer' ]; then + _ob_parse_changelog_error "${file}" "${line_nr}" \ + 'changelog_found_blank_line' \ + "$(_ob_get_changelog_expect_str "${expect}")" + else + blank_lines="${blank_lines}${_OB_LF}${line}" fi - if ! ob_parse_version "${version}"; then - _ob_parse_changelog_error \ - "${file}" "${line_nr}" \ - 'changelog_bad_source_version' "${version}" + ;; + [!\ ]*) + if [ "${expect}" != 'first_heading' -a \ + "${expect}" != 'next_or_eof' ]; then + _ob_parse_changelog_error "${file}" "${line_nr}" \ + 'changelog_found_heading' \ + "$(_ob_get_changelog_expect_str "${expect}")" fi - OB_CHANGELOG_SOURCE="${source}" - OB_CHANGELOG_VERSION="${version}" - OB_CHANGELOG_DISTRIBUTION="${distribution}" - OB_CHANGELOG_CHANGES="${line}" - fi - expect='start_changes' - blank_lines= - elif [ "${line# -- }" != "${line}" ]; then - if [ "${expect}" != 'changes_or_trailer' ]; then - _ob_parse_changelog_error "${file}" "${line_nr}" \ - 'changelog_found_trailer' \ - "$(_ob_get_changelog_expect_str "${expect}")" - fi - line="${line# -- }" - maintainer="${line%% *}" - date="${line#* }" - if [ -z "${maintainer}" -o -z "${date}" -o \ - "${maintainer}" = "${date}" ]; then + source="${line%% (*}" + line_="${line#* (}" + distribution="${line_##*) }" + line_="${line_%) *}" + version="${line_}" + if [ -z "${source}" -o -z "${distribution}" -o \ + -z "${version}" -o \ + "${version% *}" != "${version}" ]; then + _ob_parse_changelog_error "${file}" "${line_nr}" \ + 'changelog_bad_heading' + OB_CHANGELOG_SOURCE= + OB_CHANGELOG_VERSION= + OB_CHANGELOG_DISTRIBUTION= + OB_CHANGELOG_CHANGES= + else + if ! ob_validate_source_name "${source}"; then + _ob_parse_changelog_error \ + "${file}" "${line_nr}" \ + 'changelog_bad_source' "${source}" + fi + if ! ob_parse_version "${version}"; then + _ob_parse_changelog_error \ + "${file}" "${line_nr}" \ + 'changelog_bad_source_version' "${version}" + fi + OB_CHANGELOG_SOURCE="${source}" + OB_CHANGELOG_VERSION="${version}" + OB_CHANGELOG_DISTRIBUTION="${distribution}" + OB_CHANGELOG_CHANGES="${line}" + fi + expect='start_changes' + blank_lines= + ;; + ' -- '*) + if [ "${expect}" != 'changes_or_trailer' ]; then + _ob_parse_changelog_error "${file}" "${line_nr}" \ + 'changelog_found_trailer' \ + "$(_ob_get_changelog_expect_str "${expect}")" + fi + line="${line# -- }" + maintainer="${line%% *}" + date="${line#* }" + if [ -z "${maintainer}" -o -z "${date}" -o \ + "${maintainer}" = "${date}" ]; then + _ob_parse_changelog_error "${file}" "${line_nr}" \ + 'changelog_bad_trailer' + OB_CHANGELOG_MAINTAINER= + OB_CHANGELOG_DATE= + elif [ -n "${OB_CHANGELOG_SOURCE}" ]; then + OB_CHANGELOG_MAINTAINER="${maintainer}" + OB_CHANGELOG_DATE="${date}" + "${entry_cb}" + if [ ${?} -ne 0 ]; then + return 0 + fi + fi + expect='next_or_eof' + blank_lines= + ;; + ' --'*) _ob_parse_changelog_error "${file}" "${line_nr}" \ 'changelog_bad_trailer' - OB_CHANGELOG_MAINTAINER= - OB_CHANGELOG_DATE= - elif [ -n "${OB_CHANGELOG_SOURCE}" ]; then - OB_CHANGELOG_MAINTAINER="${maintainer}" - OB_CHANGELOG_DATE="${date}" - "${entry_cb}" - if [ ${?} -ne 0 ]; then - return 0 + ;; + ' '*) + if [ "${expect}" != 'start_changes' -a \ + "${expect}" != 'changes_or_trailer' ]; then + _ob_parse_changelog_error "${file}" "${line_nr}" \ + 'changelog_found_change' \ + "$(_ob_get_changelog_expect_str "${expect}")" fi - fi - expect='next_or_eof' - blank_lines= - elif [ "${line# --}" != "${line}" ]; then - _ob_parse_changelog_error "${file}" "${line_nr}" \ - 'changelog_bad_trailer' - elif [ "${line## }" != "${line}" ]; then - if [ "${expect}" != 'start_changes' -a \ - "${expect}" != 'changes_or_trailer' ]; then + OB_CHANGELOG_CHANGES="${OB_CHANGELOG_CHANGES}${_OB_LF}${blank_lines}${line}" + expect='changes_or_trailer' + blank_lines= + ;; + *) _ob_parse_changelog_error "${file}" "${line_nr}" \ - 'changelog_found_change' \ - "$(_ob_get_changelog_expect_str "${expect}")" - fi - OB_CHANGELOG_CHANGES="${OB_CHANGELOG_CHANGES}${_OB_LF}${blank_lines}${line}" - expect='changes_or_trailer' - blank_lines= - else - _ob_parse_changelog_error "${file}" "${line_nr}" \ - 'changelog_bad_line' - blank_lines= - fi + 'changelog_bad_line' + blank_lines= + ;; + esac done <<-EOF $(cat "${file}") EOF |