summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2013-11-30 21:13:16 (EST)
committer P. J. McDermott <pjm@nac.net>2013-11-30 21:13:16 (EST)
commit78d8d171c2bd91d52256467791ea7ea54fc1849a (patch)
tree6eaf431b9ed5ce2f6030d9a9b1f9836f04b7d076 /lib
parent7c588c3e4fbf6999bd1e63b16b7d8a86a8ff9460 (diff)
lib/feed.sh: Rewrite to use parse_control().
Diffstat (limited to 'lib')
-rw-r--r--lib/feed.sh117
1 files changed, 72 insertions, 45 deletions
diff --git a/lib/feed.sh b/lib/feed.sh
index 46c4cc2..6a68ecd 100644
--- a/lib/feed.sh
+++ b/lib/feed.sh
@@ -21,6 +21,15 @@
_FEED_SM=1
use fd
+use control
+
+feed_pkg_cb=
+feed_dep_fields=
+feed_pkgs=
+feed_deps_fd=
+feed_pkg_include=
+feed_pkg=
+feed_deps=
feed_download()
{
@@ -33,58 +42,76 @@ feed_download()
feed_find_pkgs()
{
- local deps_file="${1}"
- local line=
- local deps_fd=
- local pkg=
- local deps=
- local all_deps=
- local dep=
- local pkgs=
- local new_deps=
+ local pkg_cb="${1}"
+ local dep_fields="${2}"
+ local deps_file="${3}"
+
+ feed_pkg_cb="${pkg_cb}"
+ feed_dep_fields=" $(printf '%s ' ${dep_fields})"
+ feed_pkgs=''
fopen "${deps_file}" 'w'
- deps_fd=${FD}
+ feed_deps_fd=${FD}
+
+ feed_pkg_include='false'
+ feed_pkg=''
+ feed_deps=''
+
+ parse_control '-' feed_field_cb feed_para_cb 'Package'
+
+ fclose ${feed_deps_fd}
+
+ printf '%s\n' "${feed_pkgs# }"
+
+ return 0
+}
+
+feed_field_cb()
+{
+ local name="${1}"
+ local value="${2}"
+
+ if [ "x${name}" = 'xPackage' ]; then
+ feed_pkg="${value}"
+ elif [ "x${feed_dep_fields#* ${name} }" != "x${feed_dep_fields}" ]; then
+ feed_deps="${feed_deps}${value}, "
+ fi
+
+ if ${feed_pkg_cb} ${name} ${value}; then
+ feed_pkg_include='true'
+ fi
+
+ return 0
+}
- pkg=''
- all_deps=''
- IFS=''
- while read -r line; do
+feed_para_cb()
+{
+ local new_deps=
+ local dep=
+
+ if ${feed_pkg_include}; then
+ feed_pkgs="${feed_pkgs} ${feed_pkg}"
+ fi
+
+ new_deps=''
+ IFS=','
+ for dep in ${feed_deps%, }; do
unset IFS
- if [ "x${line}" != 'x' ]; then
- case "${line}" in
- 'Package:'*)
- pkg="${line#Package:}"
- pkg="${pkg## }"
- ;;
- *'Depends:'*)
- deps="${line#*Depends:}"
- deps="${deps## }"
- all_deps="${all_deps}${deps}, "
- ;;
- esac
- else
- if profile_include_pkg "${pkg}"; then
- pkgs="${pkgs} ${pkg}"
- fi
- new_deps=''
- IFS=", ${HT}${LF}"
- for dep in ${all_deps}; do
- unset IFS
- # Trim off " |.*$" and " (.*$" (versions and
- # disjunctions).
- dep="$(printf '%s ' ${dep} | cut -d ' ' -f 1)"
- new_deps="${new_deps} ${dep}"
- done
- unset IFS
- printf '%s%s\n' "${pkg}" "${new_deps}" >&${deps_fd}
- pkg=''
- all_deps=''
- fi
+ # Trim off versions and disjunctions.
+ dep="${dep%%(*}"
+ dep="${dep%%|*}"
+ # Trim whitespace.
+ dep="${dep##[ ${HT}${LF}]}"
+ dep="${dep%%[ ${HT}${LF}]}"
+ new_deps="${new_deps} ${dep}"
done
unset IFS
- fclose ${deps_fd}
+ printf '%s%s\n' "${feed_pkg}" "${new_deps}" >&${feed_deps_fd}
+
+ feed_pkg_include='false'
+ feed_pkg=''
+ feed_deps=''
return 0
}