Improve "depends" function

- function will now print the packages at proper depths
- added newline between each result if called with multiple packages
This commit is contained in:
Steven Penny 2014-05-28 23:26:51 -05:00
parent 390024541d
commit c8fb2604da
1 changed files with 28 additions and 9 deletions

31
apt-cyg
View File

@ -185,25 +185,44 @@ apt-depends () {
checkpackages checkpackages
for pkg in $packages for pkg in $packages
do do
(( sq++ )) && echo
awk ' awk '
$1 == "@" { $1 == "@" {
pkg = $2 pkg = $2
} }
$1 == "requires:" { $1 == "requires:" {
for (i=2; i<=NF; i++) for (i=2; i<=NF; i++)
reqs[pkg][$i] reqs[pkg][i-1]=$i
} }
END { END {
setMinDepth(query)
prtPkg(query) prtPkg(query)
} }
function prtPkg(pkg) { function prtPkg(pkg, req, i) {
if (seen[pkg]++) return depth++
if ( depth == mn[pkg] && !seen[pkg]++ ) {
printf "%*s%s\n", indent, "", pkg printf "%*s%s\n", indent, "", pkg
indent++ indent += 2
if (pkg in reqs) if (pkg in reqs)
for (req in reqs[pkg]) for (i=1; i in reqs[pkg]; i++) {
req = reqs[pkg][i]
prtPkg(req) prtPkg(req)
indent-- }
indent -= 2
}
depth--
}
function setMinDepth(pkg, req, i) {
depth++
mn[pkg] = !(pkg in mn) || depth < mn[pkg] ? depth : mn[pkg]
if (depth == mn[pkg]) {
if (pkg in reqs)
for (i=1; i in reqs[pkg]; i++) {
req = reqs[pkg][i]
setMinDepth(req)
}
}
depth--
} }
' query="$pkg" setup.ini ' query="$pkg" setup.ini
done done