From f504cf65a1b2fd74614eea99666528845cec773a Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Tue, 23 Apr 2019 15:49:53 -0400 Subject: parse_control_error(): Accept file and line_nr args --- (limited to 'src') 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 # . -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 } -- cgit v0.9.1