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

feature/tap-sh
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)

56
pkg.c
View File

@ -292,7 +292,38 @@ 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);
}
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,
unsigned int flags)
{
pkg_dependency_t *node;
foreach_list_entry(deplist, node)
{
pkg_t *pkgdep;
if (*node->package == '\0')
continue;
pkgdep = pkg_verify_dependency(node);
if (pkgdep == NULL)
{
fprintf(stderr, "Package %s was not found in the pkg-config search path.\n", node->package);
fprintf(stderr, "Perhaps you should add the directory containing `%s.pc'\n", node->package);
fprintf(stderr, "to the PKG_CONFIG_PATH environment variable\n");
fprintf(stderr, "No package '%s' found\n", node->package);
exit(EXIT_FAILURE);
}
pkg_traverse(pkgdep, pkg_traverse_func, data, maxdepth - 1, flags);
}
}
/*
@ -304,32 +335,15 @@ void
pkg_traverse(pkg_t *root,
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)
{
pkg_t *pkgdep;
if (*node->package == '\0')
continue;
pkgdep = pkg_verify_dependency(node);
if (pkgdep == NULL)
{
fprintf(stderr, "Package %s was not found in the pkg-config search path.\n", node->package);
fprintf(stderr, "Perhaps you should add the directory containing `%s.pc'\n", node->package);
fprintf(stderr, "to the PKG_CONFIG_PATH environment variable\n");
fprintf(stderr, "No package '%s' found\n", node->package);
exit(EXIT_FAILURE);
}
pkg_traverse(pkgdep, pkg_traverse_func, data, maxdepth - 1);
}
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);