queue: add pkg_queue_apply().

feature/tap-sh
William Pitcock 2012-07-29 04:45:21 -05:00
parent 23b1806f65
commit 17fc01b4e0
2 changed files with 30 additions and 0 deletions

2
pkg.h
View File

@ -121,6 +121,7 @@ struct pkg_ {
typedef void (*pkg_iteration_func_t)(const pkg_t *pkg);
typedef void (*pkg_traverse_func_t)(pkg_t *pkg, void *data, unsigned int flags);
typedef void (*pkg_queue_apply_func_t)(pkg_t *world, void *data, int maxdepth, unsigned int flags);
/* pkg.c */
void pkg_free(pkg_t *pkg);
@ -175,5 +176,6 @@ extern FILE *error_msgout;
pkg_queue_t *pkg_queue_push(pkg_queue_t *parent, const char *package);
bool pkg_queue_compile(pkg_t *world, pkg_queue_t *head);
void pkg_queue_free(pkg_queue_t *head);
bool pkg_queue_apply(pkg_queue_t *head, pkg_queue_apply_func_t func, int maxdepth, unsigned int flags, void *data);
#endif

28
queue.c
View File

@ -59,3 +59,31 @@ pkg_queue_free(pkg_queue_t *head)
free(pkgq);
}
}
bool
pkg_queue_apply(pkg_queue_t *head, pkg_queue_apply_func_t func, int maxdepth, unsigned int flags, void *data)
{
pkg_t world = {
.id = "world",
.realname = "virtual world package",
.flags = PKG_PROPF_VIRTUAL,
};
if (!pkg_queue_compile(&world, head))
return false;
/* if maxdepth is one, then we will not traverse deeper than our virtual package. */
if (!maxdepth)
maxdepth = -1;
else if (maxdepth > 0)
maxdepth++;
if (pkg_verify_graph(&world, maxdepth, flags) != PKG_ERRF_OK)
return false;
func(&world, data, maxdepth, flags);
pkg_free(&world);
return true;
}