#!/usr/bin/env zsh if [ -f "${0%/*}/.pacman-init" ];then . "${0%/*}/.pacman-init" else echo "Missing init file" && exit 1 fi # Note: we really need to use an array for this one, so Bourne shells will not # work. _printhelp() { cat </dev/null" | awk -F "$SEP" -v filter="$pacman_deps" \ '$0 ~ filter {gsub(/[>=<][^ ]*/,"",$2) ; gsub(/ +/,"\n",$2) ; print $2}' \ | sort -u else ## Recursive dependencies. ## Store the complete DB into a variable to speed up access. FULLDEPLIST=$(eval "${CMD}" | grep "${pacman_name}\|${pacman_deps}" | sed -n "/${pacman_name}/{s/.*: \(.*\)/\1:/;h;n;s/${pacman_deps}.*: //;s/[>=<][^ ]*//g;H;x;s/\n//;p}") ## Note: using an array is important for Ksh/Zsh compatibility. DEPLIST=() ## Check if argument $1 is in DEPLIST. _not_in_array() { if [ ${#DEPLIST} -eq 0 ]; then return 0 else for j in ${DEPLIST[*]}; do if [ "$j" = "$1" ]; then return 1 fi done return 0 fi } ## This function calls recursively over the dependencies. It stops whenever ## a package has already be handled, or when it has no dependency. Note: ## 'grep | cut' is a little faster than 'sed' for simple stuff. Since it is ## a loop, it is quite a performance boost. _pacman_deps_rec() { SUBDEPLIST=() for i ; do SUBDEPLIST=(${SUBDEPLIST[*]} $(echo "$FULLDEPLIST" | grep "^$i\s*:" | cut -d':' -f2)) done for i in ${SUBDEPLIST[*]} ; do if [ ! "$i" = "$pacman_deps_none" ] && _not_in_array "$i" ; then DEPLIST=(${DEPLIST[*]} "$i") _pacman_deps_rec "$i" fi done } for i ; do _pacman_deps_rec "$@" done ## There might be duplicates, so we remove them with the '-u' parameter of ## sort. echo "${DEPLIST[*]}" | sed 's/ /\n/g' | sort -u fi