summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/control.sh36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/control.sh b/src/control.sh
index c8d742c..f4d1498 100644
--- a/src/control.sh
+++ b/src/control.sh
@@ -18,9 +18,6 @@
# along with the ProteanOS Development Kit. If not, see
# <http://www.gnu.org/licenses/>.
-control_file=
-control_line_nr=
-
parse_control()
{
local field_cb="${2}"
@@ -33,13 +30,13 @@ parse_control()
local name=
local value=
- control_file="${1}"
- control_line_nr=0
+ file="${1}"
+ line_nr=0
in_paragraph='false'
while IFS='' read -r line; do
- control_line_nr=$((${control_line_nr} + 1))
+ line_nr=$((${line_nr} + 1))
if [ "x$(echo ${line})" = 'x' ]; then
# Paragraph end.
if ${in_paragraph}; then
@@ -60,6 +57,7 @@ parse_control()
'list_item_separator')" \
${para_req_fields})"
parse_control_error \
+ "${file}" "${line_nr}" \
'control_missing_fields' \
"${para_req_fields}"
fi
@@ -83,7 +81,8 @@ parse_control()
value="${line#*:}"
value="${value# }"
if [ "x${name}" = 'x' -o "x${name}" = "x${line}" ]; then
- parse_control_error 'control_bad_nv'
+ parse_control_error "${file}" "${line_nr}" \
+ 'control_bad_nv'
continue
fi
if [ "x${para_req_fields}" != 'x' ]; then
@@ -94,7 +93,8 @@ parse_control()
if [ "x${got_fields%${LF}${name}${LF}*}" != \
"x${got_fields}" ]; then
# Duplicate field.
- parse_control_error 'control_duplicate_field' \
+ parse_control_error "${file}" "${line_nr}" \
+ 'control_duplicate_field' \
"${name}"
else
got_fields="${got_fields}${name}${LF}"
@@ -104,14 +104,15 @@ parse_control()
in_paragraph='true'
if [ "x${name}" = 'x' ]; then
# Expecting a "Name: Value" line.
- parse_control_error 'control_found_continuation'
+ parse_control_error "${file}" "${line_nr}" \
+ 'control_found_continuation'
continue
fi
value="${value}${LF}${line# }"
fi
done <<-EOF
- $(cat "${control_file}")
+ $(cat "${file}")
EOF
# The first blank line above triggers the paragraph end code to
@@ -130,18 +131,19 @@ parse_control()
parse_control_error()
{
- local msgid="${1}"
- local file_info=
+ local file="${1}"
+ local line_nr="${2}"
+ local msg_id="${3}"
shift 1
+ local file_info=
- if [ ${control_line_nr} -eq 0 ]; then
- file_info="$(printf '%20s:' "${control_file}")"
+ if [ ${line_nr} -eq 0 ]; then
+ file_info="$(printf '%20s:' "${file}")"
else
- file_info="$(printf '%20s(l%d):' "${control_file}" \
- "${control_line_nr}")"
+ file_info="$(printf '%20s(l%d):' "${file}" "${line_nr}")"
fi
- warn "${file_info} $(get_msg "${msgid}")" "${@}"
+ warn "${file_info} $(get_msg "${msg_id}")" "${@}"
return 0
}