From a1fbd80adeacca779cc3db1eaec28f755a405ac9 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Wed, 01 Aug 2012 07:20:43 -0400 Subject: Report control file parse errors. --- diff --git a/lib/control.sh b/lib/control.sh index a5cdd46..ca11999 100644 --- a/lib/control.sh +++ b/lib/control.sh @@ -73,30 +73,35 @@ _control_parse() done _param= + _line_nr=0 + while read -r _line; do + _line_nr=$(($_line_nr + 1)) if [ "${_line# }" = "${_line}" ]; then # "Name: Value" line. _name="${_line%%:*}" _value="${_line#*:}" if [ -z "${_name}" -o "${_name}" = "${_line}" \ -o -z "${_value}" ]; then -# oh_warn "${oh_str_control_bad_nv}" + # Badly formatted control field. + _control_parse_error "${_control}" "${_line_nr}" \ + "${oh_str_control_bad_nv}" continue fi if [ "${_all% ${_name} }" = "${_all}" ]; then # Unknown field. - : -# oh_warn "${oh_str_control_unknown_field}" \ -# "${_control}" "${_name}" + _control_parse_error "${_control}" "${_line_nr}" \ + "${oh_str_control_unknown_field}" \ + "${_control}" "${_name}" else # Remove field from list of required fields. _req="$(echo "${_req}" | sed "s/${_name}//")" fi if [ "${_got% ${_name} }" != "${_got}" ]; then # Duplicate field. - : -# oh_warn "${oh_str_control_duplicate_field}" \ -# "${_control}" "${_field}" + _control_parse_error "${_control}" "${_line_nr}" \ + "${oh_str_control_duplicate_field}" \ + "${_control}" "${_field}" else _got="${_got}${_field} " fi @@ -106,7 +111,9 @@ _control_parse() else # Continuation line. if [ -z "${_param}" ]; then -# oh_warn "${oh_str_control_found_continuation}" + # Expecting a "Name: Value" line. + _control_parse_error "${_control}" "${_line_nr}" \ + "${oh_str_control_found_continuation}" continue fi _value="${_line# }" @@ -119,8 +126,23 @@ ${_value}\"" _req="${_req%% }" if [ -n "${_req}" ]; then # Missing required control fields. - : -# oh_error "${oh_str_control_missing_fields}" \ -# "${_control}" "$(echo "${_req}" | sed 's/ / /g' | sed 's/ /,/g')" + _control_parse_error "${_control}" 0 \ + "${oh_str_control_missing_fields}" \ + "$(echo "${_req}" | sed 's/ / /g' | sed 's/ /,/g')" + fi +} + +_control_parse_error() +{ + _file="${1}" + _line_nr="${2}" + _error="${3}" + shift 3 + + if [ "${_line_nr}" -eq 0 ]; then + _file_info=$(printf '%20s:' "${_file}" "${_line_nr}") + else + _file_info=$(printf '%20s(l%d):' "${_file}" "${_line_nr}") fi + oh_warn "${_file_info} ${_error}" "${@}" } -- cgit v0.9.1