From a22ca921972d8acc9a418c2d07d2a6cc1b6a1b9b Mon Sep 17 00:00:00 2001
From: P. J. McDermott <pjm@nac.net>
Date: Wed, 01 Aug 2012 05:23:28 -0400
Subject: Internationalize expect strings in changelog lib.

---
(limited to 'lib')

diff --git a/lib/changelog.sh b/lib/changelog.sh
index 909c955..37ab814 100644
--- a/lib/changelog.sh
+++ b/lib/changelog.sh
@@ -34,22 +34,19 @@ OH_SOURCE_VERSION_ID_RE="${OH_SOURCE_VERSION_ID_RE}"'(-[1-9][0-9]*)?'
 OH_SOURCE_VERSION_ID_RE="${OH_SOURCE_VERSION_ID_RE}"'(\+[a-z0-9]+-[1-9][0-9]*)?'
 OH_SOURCE_VERSION_ID_RE="${OH_SOURCE_VERSION_ID_RE}"'$'
 
-oh_changelog_parse_error()
+_changelog_parse_error()
 {
-	_line_nr="${2}"
-	_error="${3}"
-	_expect_id="${4}"
-
-	case "${_expect_id}" in
-		FIRST_HEADING)      _expect_str='first heading';;
-		NEXT_OR_EOF)        _expect_str='next heading or eof';;
-		START_CHANGES)      _expect_str='start of change data';;
-		CHANGES_OR_TRAILER) _expect_str='more change data or trailer';;
-		*)                  _expect_str='unknown';;
-	esac
+	_line_nr="${1}"
+	_error="${2}"
+	shift 2
 
 	_file_info=$(printf '%20s(l%d):' "${OH_SOURCE_DIR}/changelog" "${_line_nr}")
-	oh_warn "${_file_info} ${_error}" "${_expect_str}"
+	oh_warn "${_file_info} ${_error}" "${@}"
+}
+
+_changelog_get_expect_str()
+{
+	eval echo \$\{oh_str_changelog_expect_"${1}"\}
 }
 
 oh_changelog_parse()
@@ -58,30 +55,32 @@ oh_changelog_parse()
 
 	_cb="${1}"
 
-	_expect=FIRST_HEADING
+	_expect=first_heading
 	_line_nr=0
 	_entries=0
 
 	while IFS= read _line; do
 		_line_nr=$(($_line_nr + 1))
 		if [ -z "${_line}" ]; then
-			if [ "${_expect}" = START_CHANGES ]; then
+			if [ "${_expect}" = start_changes ]; then
 				OH_CHANGELOG_CHANGES="${OH_CHANGELOG_CHANGES}
 ${_line}"
-			elif [ "${_expect}" = NEXT_OR_EOF ]; then
+			elif [ "${_expect}" = next_or_eof ]; then
 				:
-			elif [ "${_expect}" != CHANGES_OR_TRAILER ]; then
-				oh_changelog_parse_error "${_line_nr}" \
-					"${oh_str_changelog_found_blank_line}" "${_expect}"
+			elif [ "${_expect}" != changes_or_trailer ]; then
+				_changelog_parse_error "${_line_nr}" \
+					"${oh_str_changelog_found_blank_line}" \
+					$(_changelog_get_expect_str "${_expect}")
 			else
 				_blank_lines="${_blank_lines}
 ${_line}"
 			fi
 		elif [ "${_line# }" = "${_line}" ]; then
-			if [ "${_expect}" != FIRST_HEADING -a \
-					"${_expect}" != NEXT_OR_EOF ]; then
-				oh_changelog_parse_error "${_line_nr}" \
-					"${oh_str_changelog_found_heading}" "${_expect}"
+			if [ "${_expect}" != first_heading -a \
+					"${_expect}" != next_or_eof ]; then
+				_changelog_parse_error "${_line_nr}" \
+					"${oh_str_changelog_found_heading}" \
+					$(_changelog_get_expect_str "${_expect}")
 			fi
 			_source="${_line%% (*}"
 			_line_="${_line#* (}"
@@ -91,7 +90,7 @@ ${_line}"
 			if [ -z "${_source}" -o -z "${_distribution}" -o \
 					-z "${_version}" -o \
 					"${_version% *}" != "${_version}" ]; then
-				oh_changelog_parse_error "${_line_nr}" \
+				_changelog_parse_error "${_line_nr}" \
 					"${oh_str_changelog_bad_heading}"
 				OH_CHANGELOG_SOURCE=
 				OH_CHANGELOG_VERSION=
@@ -101,33 +100,34 @@ ${_line}"
 				echo "${_source}" | \
 					grep -E "${OH_SOURCE_RE}" >/dev/null 2>&1
 				if [ "${?}" -ne 0 ]; then
-					oh_changelog_parse_error "${_line_nr}" \
-						"${oh_str_changelog_bad_source}"
+					_changelog_parse_error "${_line_nr}" \
+						"${oh_str_changelog_bad_source}" "${source}"
 				fi
 				echo "${_version}" | \
 					grep -E "${OH_SOURCE_VERSION_ID_RE}" >/dev/null 2>&1
 				if [ "${?}" -ne 0 ]; then
-					oh_changelog_parse_error "${_line_nr}" \
-						"${oh_str_changelog_bad_source_version}"
+					_changelog_parse_error "${_line_nr}" \
+						"${oh_str_changelog_bad_source_version}" "${_version}"
 				fi
 				OH_CHANGELOG_SOURCE="${_source}"
 				OH_CHANGELOG_VERSION="${_version}"
 				OH_CHANGELOG_DISTRIBUTION="${_distribution}"
 				OH_CHANGELOG_CHANGES="${_line}"
 			fi
-			_expect=START_CHANGES
+			_expect=start_changes
 			_blank_lines=
 		elif [ "${_line# -- }" != "${_line}" ]; then
-			if [ "${_expect}" != CHANGES_OR_TRAILER ]; then
-				oh_changelog_parse_error "${_line_nr}" \
-					"${oh_str_changelog_found_trailer}" "${_expect}"
+			if [ "${_expect}" != changes_or_trailer ]; then
+				_changelog_parse_error "${_line_nr}" \
+					"${oh_str_changelog_found_trailer}" \
+					$(_changelog_get_expect_str "${_expect}")
 			fi
 			_line="${_line# -- }"
 			_maintainer="${_line%%  *}"
 			_date="${_line#*  }"
 			if [ -z "${_maintainer}" -o -z "${_date}" -o \
 					"${_maintainer}" = "${_date}" ]; then
-				oh_changelog_parse_error "${_line_nr}" \
+				_changelog_parse_error "${_line_nr}" \
 					"${oh_str_changelog_bad_trailer}"
 				OH_CHANGELOG_MAINTAINER=
 				OH_CHANGELOG_DATE=
@@ -138,31 +138,33 @@ ${_line}"
 				"${_cb}"
 				[ ${?} -ne 0 ] && return ${_entries}
 			fi
-			_expect=NEXT_OR_EOF
+			_expect=next_or_eof
 			_blank_lines=
 		elif [ "${_line# --}" != "${_line}" ]; then
-			oh_changelog_parse_error "${_line_nr}" \
+			_changelog_parse_error "${_line_nr}" \
 				"${oh_str_changelog_bad_trailer}"
 		elif [ "${_line##  }" != "${_line}" ]; then
-			if [ "${_expect}" != START_CHANGES -a \
-					"${_expect}" != CHANGES_OR_TRAILER ]; then
-				oh_changelog_parse_error "${_line_nr}" \
-					"${oh_str_changelog_found_change}" "${_expect}"
+			if [ "${_expect}" != start_changes -a \
+					"${_expect}" != changes_or_trailer ]; then
+				_changelog_parse_error "${_line_nr}" \
+					"${oh_str_changelog_found_change}" \
+					$(_changelog_get_expect_str "${_expect}")
 			fi
 			OH_CHANGELOG_CHANGES="${OH_CHANGELOG_CHANGES}
 ${_blank_lines}${_line}"
-			_expect=CHANGES_OR_TRAILER
+			_expect=changes_or_trailer
 			_blank_lines=
 		else
-			oh_changelog_parse_error "${_line_nr}" \
+			_changelog_parse_error "${_line_nr}" \
 				"${oh_str_changelog_bad_line}"
 			_blank_lines=
 		fi
 	done <"${OH_SOURCE_DIR}/changelog"
 
-	if [ "${_expect}" != NEXT_OR_EOF ]; then
-		oh_changelog_parse_error "${_line_nr}" \
-			"${oh_str_changelog_found_eof}" "${_expect}"
+	if [ "${_expect}" != next_or_eof ]; then
+		_changelog_parse_error "${_line_nr}" \
+			"${oh_str_changelog_found_eof}" \
+			$(_changelog_get_expect_str "${_expect}")
 	fi
 
 	return ${_entries}
--
cgit v0.9.1