update pactree example

This commit is contained in:
guinux 2015-03-29 16:24:53 +02:00
parent 1058576cce
commit 432526b9d8
1 changed files with 18 additions and 13 deletions

View File

@ -1,7 +1,7 @@
/* /*
* pactree.vala - a simple dependency tree viewer translated in Vala * pactree.vala - a simple dependency tree viewer translated in Vala
* *
* Copyright (C) 2014 Guillaume Benoit <guillaume@manjaro.org> * Copyright (C) 2014-2015 Guillaume Benoit <guillaume@manjaro.org>
* Copyright (c) 2010-2011 Pacman Development Team <pacman-dev@archlinux.org> * Copyright (c) 2010-2011 Pacman Development Team <pacman-dev@archlinux.org>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -37,7 +37,7 @@ string leaf2_color;
string color_off; string color_off;
/* globals */ /* globals */
Handle handle; unowned Handle? handle;
unowned DB localdb; unowned DB localdb;
Alpm.List<string?> walked = null; Alpm.List<string?> walked = null;
Alpm.List<string?> provisions = null; Alpm.List<string?> provisions = null;
@ -127,7 +127,7 @@ static int parse_options(ref unowned string[] args) {
static void local_init() { static void local_init() {
Alpm.Errno error; Alpm.Errno error;
handle = new Handle ("/", dbpath, out error); handle = Handle.new ("/", dbpath, out error);
assert (error == 0); assert (error == 0);
localdb = handle.localdb; localdb = handle.localdb;
assert (localdb != null); assert (localdb != null);
@ -187,19 +187,24 @@ static void walk_reverse_deps(Package pkg, int depth) {
if((max_depth >= 0) && (depth > max_depth)) return; if((max_depth >= 0) && (depth > max_depth)) return;
walked.add(pkg.name); walked.add(pkg.name);
Alpm.List<string?> required_by = pkg.compute_requiredby (); Alpm.List<string?> *required_by = pkg.compute_requiredby();
foreach(string? i in required_by) { int i = 0;
string pkgname = i; while (i < required_by->length) {
string? pkgname = required_by->nth_data(i);
if (walked.find_str(pkgname) != null) { if (walked.find_str(pkgname) != null) {
/* if we've already seen this package, don't print in "unique" output /* if we've already seen this package, don't print in "unique" output
* and don't recurse */ * and don't recurse */
if (!unique) print(pkg.name, pkgname, null, depth); if (!unique) {
print(pkg.name, pkgname, null, depth);
}
} else { } else {
print(pkg.name, pkgname, null, depth); print(pkg.name, pkgname, null, depth);
walk_reverse_deps(localdb.get_pkg(pkgname), depth + 1); walk_reverse_deps(localdb.get_pkg(pkgname), depth + 1);
} }
i++;
} }
Alpm.List.free_all(required_by);
} }
/** /**