From 150083eea622e2ea31a3202426c0df9b4dfd16f3 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Tue, 23 Apr 2019 22:05:03 -0400 Subject: parse_control(): Rewrite field checking Get rid of the printf and grep pipeline and use a case construct instead of a "[" command with a "${parameter%word}" expansion. Also drop the unused check_fields variable, just added in commit 1e585cb. --- diff --git a/src/control.sh b/src/control.sh index 6a92ff3..e73c842 100644 --- a/src/control.sh +++ b/src/control.sh @@ -43,7 +43,6 @@ parse_control() local field_cb="${2}" local paragraph_cb="${3}" shift 3 - local check_fields= local req_fields= local line_nr= local in_paragraph= @@ -53,11 +52,9 @@ parse_control() local name= local value= - check_fields='false' if [ ${#} -eq 1 ]; then - req_fields="${1}" + req_fields=" ${1} " shift 1 - check_fields='true' fi line_nr=0 @@ -93,8 +90,8 @@ parse_control() "${para_req_fields}" fi fi - para_req_fields="$(printf '%s\n' ${req_fields})" - got_fields="${LF}" + para_req_fields="${req_fields}" + got_fields=' ' name='' value='' ;; @@ -117,23 +114,23 @@ parse_control() "${line_nr}" 'control_bad_nv' continue fi - if [ -n "${para_req_fields}" ]; then - # Remove field from list of required - # fields. - para_req_fields="$(printf '%s' \ - "${para_req_fields}" | \ - grep -Fv "${name}")" - fi - if [ "x${got_fields%${LF}${name}${LF}*}" != \ - "x${got_fields}" ]; then + case "${got_fields}" in *" ${name} "*) # Duplicate field. - _parse_control_error \ + _ob_parse_control_error \ "${file}" "${line_nr}" \ 'control_duplicate_field' \ "${name}" - else - got_fields="${got_fields}${name}${LF}" - fi + continue + esac + got_fields="${got_fields}${name} " + case "${para_req_fields}" in *" ${name} "*) + # Required field: remove from list. + para_req_fields="$(:\ + )${para_req_fields% ${name} *}$( + :\ + ) ${para_req_fields#* ${name} }" + continue + esac ;; ' '*) # Continuation line. in_paragraph='true' -- cgit v0.9.1