pkg: add flags option to pkg_traverse() to optionally control what the depgraph traversal code does

pull/4/head
William Pitcock 2012-05-02 21:44:58 +00:00
parent bea3c202de
commit 5ea52d4cae
3 changed files with 45 additions and 28 deletions

12
main.c
View File

@ -173,7 +173,7 @@ pkg_queue_walk(pkg_queue_t *head)
printf("edge [color=blue len=7.5 fontname=Sans fontsize=8]\n");
printf("node [fontname=Sans fontsize=8]\n");
pkg_traverse(&world, print_digraph_node, NULL, maximum_traverse_depth);
pkg_traverse(&world, print_digraph_node, NULL, maximum_traverse_depth, PKGF_NONE);
printf("}\n");
@ -186,7 +186,7 @@ pkg_queue_walk(pkg_queue_t *head)
want_cflags = 0;
want_libs = 0;
pkg_traverse(&world, print_modversion, NULL, 2);
pkg_traverse(&world, print_modversion, NULL, 2, PKGF_NONE);
}
if (want_variables)
@ -195,7 +195,7 @@ pkg_queue_walk(pkg_queue_t *head)
want_cflags = 0;
want_libs = 0;
pkg_traverse(&world, print_variables, NULL, 2);
pkg_traverse(&world, print_variables, NULL, 2, PKGF_NONE);
}
if (want_requires)
@ -218,19 +218,19 @@ pkg_queue_walk(pkg_queue_t *head)
if (want_cflags)
{
wanted_something++;
pkg_traverse(&world, print_cflags, NULL, maximum_traverse_depth);
pkg_traverse(&world, print_cflags, NULL, maximum_traverse_depth, PKGF_NONE);
}
if (want_libs)
{
wanted_something++;
pkg_traverse(&world, print_libs, NULL, maximum_traverse_depth);
pkg_traverse(&world, print_libs, NULL, maximum_traverse_depth, PKGF_NONE);
}
if (want_variable)
{
wanted_something++;
pkg_traverse(&world, print_variable, NULL, 2);
pkg_traverse(&world, print_variable, NULL, 2, PKGF_NONE);
}
if (wanted_something)

42
pkg.c
View File

@ -292,26 +292,20 @@ pkg_verify_dependency(pkg_dependency_t *pkgdep)
void
pkg_verify_graph(pkg_t *root, int depth)
{
pkg_traverse(root, NULL, NULL, depth);
pkg_traverse(root, NULL, NULL, depth, PKGF_NONE);
}
/*
* pkg_traverse(root, pkg_traverse_func, data, maxdepth)
*
* walk the dependency graph up to maxdepth levels. -1 means infinite recursion.
*/
void
pkg_traverse(pkg_t *root,
static inline void
pkg_walk_list(pkg_t *parent,
pkg_dependency_t *deplist,
void (*pkg_traverse_func)(pkg_t *package, void *data),
void *data,
int maxdepth)
int maxdepth,
unsigned int flags)
{
pkg_dependency_t *node;
if (maxdepth == 0)
return;
foreach_list_entry(root->requires, node)
foreach_list_entry(deplist, node)
{
pkg_t *pkgdep;
@ -328,8 +322,28 @@ pkg_traverse(pkg_t *root,
exit(EXIT_FAILURE);
}
pkg_traverse(pkgdep, pkg_traverse_func, data, maxdepth - 1);
pkg_traverse(pkgdep, pkg_traverse_func, data, maxdepth - 1, flags);
}
}
/*
* pkg_traverse(root, pkg_traverse_func, data, maxdepth)
*
* walk the dependency graph up to maxdepth levels. -1 means infinite recursion.
*/
void
pkg_traverse(pkg_t *root,
void (*pkg_traverse_func)(pkg_t *package, void *data),
void *data,
int maxdepth,
unsigned int flags)
{
pkg_dependency_t *node;
if (maxdepth == 0)
return;
pkg_walk_list(root, root->requires, pkg_traverse_func, data, maxdepth - 1, flags);
if (pkg_traverse_func != NULL)
pkg_traverse_func(root, data);

5
pkg.h
View File

@ -99,8 +99,11 @@ struct pkg_ {
pkg_tuple_t *vars;
};
#define PKGF_NONE 0x0
#define PKGF_SEARCH_PRIVATE 0x1
pkg_t *pkg_find(const char *name);
void pkg_traverse(pkg_t *root, void (*pkg_traverse_func)(pkg_t *package, void *data), void *data, int maxdepth);
void pkg_traverse(pkg_t *root, void (*pkg_traverse_func)(pkg_t *package, void *data), void *data, int maxdepth, unsigned int flags);
void pkg_verify_graph(pkg_t *root, int depth);
int pkg_compare_version(const char *a, const char *b);
pkg_t *pkg_verify_dependency(pkg_dependency_t *pkgdep);