summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2012-08-01 06:59:37 (EDT)
committer P. J. McDermott <pjm@nac.net>2012-08-01 06:59:37 (EDT)
commitd01d16207d329c2c534d2d0b7ff9da76de97ca7b (patch)
treea4962aa1c3c8fbffa5e478b1d39a20822e825c16
parent3604224ea3d9b213d0b82291f04d00deca847380 (diff)
Write control library file.
-rw-r--r--lib/control.sh126
-rw-r--r--locale/en_US.sh7
2 files changed, 133 insertions, 0 deletions
diff --git a/lib/control.sh b/lib/control.sh
new file mode 100644
index 0000000..a5cdd46
--- /dev/null
+++ b/lib/control.sh
@@ -0,0 +1,126 @@
+#!@@SHELL@@
+#
+# opkhelper
+# lib/control
+# Functions for parsing control files.
+#
+# Copyright (C) 2012 Patrick "P. J." McDermott
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+[ -n "${_OH_CONTROL_SH}" ] && return 0
+_OH_CONTROL_SH=true
+
+. @@LIBDIR@@/messages
+. @@LIBDIR@@/locale
+. @@LIBDIR@@/util
+
+# Constant global parameters:
+OH_CONTROL_SOURCE_FIELDS_REQUIRED='Maintainer'
+OH_CONTROL_SOURCE_FIELDS_OPTIONAL='Build-Depends Homepage'
+OH_CONTROL_BINARY_FIELDS_REQUIRED='Architecture Platform Priority Description'
+OH_CONTROL_BINARY_FIELDS_OPTIONAL='Essential Depends Recommends Suggests '\
+'Pre-Depends Conflicts Provides Replaces'
+OH_CONTROL_SOURCE_FIELD_MAINTAINER=
+OH_CONTROL_SOURCE_FIELD_BUILD_DEPENDS=
+OH_CONTROL_SOURCE_FIELD_HOMEPAGE=
+OH_CONTROL_BINARY_FIELD_ARCHITECTURE=
+OH_CONTROL_BINARY_FIELD_PLATFORM=
+OH_CONTROL_BINARY_FIELD_PRIORITY=
+OH_CONTROL_BINARY_FIELD_DESCRIPTION=
+OH_CONTROL_BINARY_FIELD_ESSENTIAL=
+OH_CONTROL_BINARY_FIELD_DEPENDS=
+OH_CONTROL_BINARY_FIELD_RECOMMENDS=
+OH_CONTROL_BINARY_FIELD_SUGGESTS=
+OH_CONTROL_BINARY_FIELD_PRE_DEPENDS=
+OH_CONTROL_BINARY_FIELD_CONFLICTS=
+OH_CONTROL_BINARY_FIELD_PROVIDES=
+OH_CONTROL_BINARY_FIELD_REPLACES=
+
+oh_control_parse_source()
+{
+ _control_parse "${OH_SOURCE_DIR}/control" 'SOURCE'
+}
+
+oh_control_parse_binary()
+{
+ _control_parse "${OH_SOURCE_DIR}/${1}.pkg/control" 'BINARY'
+}
+
+_control_parse()
+{
+ _control="${1}"
+ _type="${2}"
+ _req=" $(eval echo \$\{OH_CONTROL_"${_type}"_FIELDS_REQUIRED) "
+ _opt=" $(eval echo \$\{OH_CONTROL_"${_type}"_FIELDS_OPTIONAL) "
+ _all="${_req}${_opt}"
+ _got=' '
+
+ # Initialize fields.
+ for _param in ${_all}; do
+ eval "${_param}="
+ done
+ _param=
+
+ while read -r _line; do
+ 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}"
+ continue
+ fi
+ if [ "${_all% ${_name} }" = "${_all}" ]; then
+ # Unknown field.
+ :
+# oh_warn "${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}"
+ else
+ _got="${_got}${_field} "
+ fi
+ _param="OH_CONTROL_${_type}_FIELD_$(LC_CTYPE=C \
+ tr '[:lower:]-' '[:upper:]_')"
+ eval "${_param}=\"${_value}\""
+ else
+ # Continuation line.
+ if [ -z "${_param}" ]; then
+# oh_warn "${oh_str_control_found_continuation}"
+ continue
+ fi
+ _value="${_line# }"
+ eval "${_param}=\"${_param}
+${_value}\""
+ fi
+ done <"${_control}"
+
+ _req="${_req## }"
+ _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')"
+ fi
+}
diff --git a/locale/en_US.sh b/locale/en_US.sh
index 9ad08ad..bd32ab2 100644
--- a/locale/en_US.sh
+++ b/locale/en_US.sh
@@ -17,6 +17,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# lib/control
+oh_str_control_bad_nv='badly formatted control field'
+oh_str_control_unknown_field='unrecognized field "%s"'
+oh_str_control_duplicate_field='duplicate field "%s"'
+oh_str_control_found_continuation='found continuation line where exepected start of field'
+oh_str_control_missing_fields='missing fields: %s'
+
# lib/changelog
oh_str_changelog_expect_first_heading='first heading'
oh_str_changelog_expect_next_or_eof='next heading or eof'