summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-04-23 22:05:03 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-04-23 22:05:03 (EDT)
commit150083eea622e2ea31a3202426c0df9b4dfd16f3 (patch)
tree5bbed062c4a022ac52bd337bbca1b6960b7c44c7 /src
parent175eaf0d16890ceaf8faed75691850f600339175 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/control.sh35
1 files changed, 16 insertions, 19 deletions
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'