From 0cded9197f0ca559afd1f51b4200c07e65fa76b1 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sat, 05 Jan 2019 15:32:02 -0500 Subject: Revert "[WIP] ob_parse_control(): Run an error callback" This reverts commit d1f79411c618a7a3d078430450631dfca85c2a07. --- (limited to 'lib/control.sh') diff --git a/lib/control.sh b/lib/control.sh index cb4dfd6..30c6b9c 100644 --- a/lib/control.sh +++ b/lib/control.sh @@ -19,6 +19,35 @@ _OB_SUBSTVARS_MAX_DEPTH=50 +_ob_parse_control_error() +{ + local file= + local line_nr= + local msg_id= + local file_info= + local orig_text_domain= + + file="${1}" + line_nr="${2}" + msg_id="${3}" + shift 3 + + if [ ${line_nr} -eq 0 ]; then + file_info="$(printf '%20s:' "${file}")" + else + file_info="$(printf '%20s(l%d):' "${file}" "${line_nr}")" + fi + + orig_text_domain="$(ob_get_text_domain)" + ob_set_text_domain "${_OB_INTERNAL_TEXT_DOMAIN}" + + ob_warn "${file_info} $(ob_get_msg "${msg_id}")" "${@}" + + ob_set_text_domain "${orig_text_domain}" + + return 0 +} + ## @brief Parse a control file ## @details \fBob_parse_control\fP parses a control file of field names and ## values formatted like RFC 822 (or RFC 2822 or RFC 5322) headers. @@ -35,10 +64,6 @@ _OB_SUBSTVARS_MAX_DEPTH=50 ## @operand field_cb req Callback to run for each field. Must accept three ## arguments: the field name, the field value, and ## \fIuser_data\fP. -## @operand error_cb req Callback to run on errors. Must accept four or more -## arguments: \fIuser_data\fP, the file name, the line -## number, the error ID string, and any arguments for -## formatted output. ## @operand user_data req Data to pass to \fIfield_cb\fP. ## @operand req_fields opt Required fields that must appear in the control file. ## @operand opt_fields opt Optional fields that may appear in the control file. @@ -52,7 +77,6 @@ ob_parse_control() { local file= local field_cb= - local error_cb= local user_data= local req_fields= local opt_fields= @@ -64,19 +88,17 @@ ob_parse_control() local name= local value= - if [ ${#} -eq 4 ]; then + if [ ${#} -eq 3 ]; then file="${1}" field_cb="${2}" - error_cb="${3}" - user_data="${4}" + user_data="${3}" check_fields='false' - elif [ ${#} -eq 6 ]; then + elif [ ${#} -eq 5 ]; then file="${1}" field_cb="${2}" - error_cb="${3}" - user_data="${4}" - req_fields="${5}" - opt_fields="${6}" + user_data="${3}" + req_fields="${4}" + opt_fields="${5}" check_fields='true' all_fields=" ${req_fields} ${opt_fields} " else @@ -91,7 +113,7 @@ ob_parse_control() line_nr=$(($line_nr + 1)) case "${line}" in '') - "${error_cb}" "${user_data}" "${file}" "${line_nr}" \ + _ob_parse_control_error "${file}" "${line_nr}" \ 'control_empty_line' ;; '#'*) # Comment. @@ -107,7 +129,7 @@ ob_parse_control() EOF if [ -z "${name}" ]; then # Badly formatted control field. - "${error_cb}" "${user_data}" "${file}" "${line_nr}" \ + _ob_parse_control_error "${file}" "${line_nr}" \ 'control_bad_nv' continue fi @@ -115,7 +137,7 @@ ob_parse_control() if [ "${all_fields% ${name} *}" = \ "${all_fields}" ]; then # Unknown field. - "${error_cb}" "${user_data}" \ + _ob_parse_control_error \ "${file}" "${line_nr}" \ 'control_unknown_field' "${name}" else @@ -127,7 +149,7 @@ ob_parse_control() if [ "${got_fields% ${name} *}" != \ "${got_fields}" ]; then # Duplicate field. - "${error_cb}" "${user_data}" "${file}" "${line_nr}" \ + _ob_parse_control_error "${file}" "${line_nr}" \ 'control_duplicate_field' "${name}" else got_fields="${got_fields}${name} " @@ -136,7 +158,7 @@ ob_parse_control() ' '*) # Continuation line. if [ -z "${name}" ]; then # Expecting a "Name: Value" line. - "${error_cb}" "${user_data}" "${file}" "${line_nr}" \ + _ob_parse_control_error "${file}" "${line_nr}" \ 'control_found_continuation' continue fi @@ -160,7 +182,7 @@ ob_parse_control() # Missing required control fields. req_fields="$(echo "${req_fields}" | sed 's/ / /g' | \ sed "s/ /$(ob_get_msg 'list_item_separator')/g")" - "${error_cb}" "${user_data}" "${file}" '0' \ + _ob_parse_control_error "${file}" '0' \ 'control_missing_fields' "${req_fields}" fi fi -- cgit v0.9.1