queue: refactor to use pkg_list_t framework
parent
b475859cfa
commit
ae063d8922
22
iter.h
22
iter.h
|
@ -51,6 +51,28 @@ pkg_node_insert(pkg_node_t *node, void *data, pkg_list_t *list)
|
||||||
list->head = node;
|
list->head = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
pkg_node_insert_tail(pkg_node_t *node, void *data, pkg_list_t *list)
|
||||||
|
{
|
||||||
|
pkg_node_t *tnode;
|
||||||
|
|
||||||
|
node->data = data;
|
||||||
|
|
||||||
|
if (list->head == NULL)
|
||||||
|
{
|
||||||
|
list->head = node;
|
||||||
|
list->tail = node;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tnode = list->tail;
|
||||||
|
|
||||||
|
node->prev = tnode;
|
||||||
|
tnode->next = node;
|
||||||
|
|
||||||
|
list->tail = node;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
pkg_node_delete(pkg_node_t *node, pkg_list_t *list)
|
pkg_node_delete(pkg_node_t *node, pkg_list_t *list)
|
||||||
{
|
{
|
||||||
|
|
40
main.c
40
main.c
|
@ -487,8 +487,7 @@ int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
pkg_queue_t *pkgq = NULL;
|
pkg_list_t pkgq = PKG_LIST_INITIALIZER;
|
||||||
pkg_queue_t *pkgq_head = NULL;
|
|
||||||
char *builddir;
|
char *builddir;
|
||||||
char *required_pkgconfig_version = NULL;
|
char *required_pkgconfig_version = NULL;
|
||||||
char *required_exact_module_version = NULL;
|
char *required_exact_module_version = NULL;
|
||||||
|
@ -750,11 +749,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
if (argv[pkg_optind + 1] == NULL || !PKG_OPERATOR_CHAR(*(argv[pkg_optind + 1])))
|
if (argv[pkg_optind + 1] == NULL || !PKG_OPERATOR_CHAR(*(argv[pkg_optind + 1])))
|
||||||
{
|
{
|
||||||
pkgq = pkg_queue_push(pkgq, package);
|
pkg_queue_push(&pkgq, package);
|
||||||
|
|
||||||
if (pkgq_head == NULL)
|
|
||||||
pkgq_head = pkgq;
|
|
||||||
|
|
||||||
pkg_optind++;
|
pkg_optind++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -764,14 +759,11 @@ main(int argc, char *argv[])
|
||||||
snprintf(packagebuf, sizeof packagebuf, "%s %s %s", package, argv[pkg_optind + 1], argv[pkg_optind + 2]);
|
snprintf(packagebuf, sizeof packagebuf, "%s %s %s", package, argv[pkg_optind + 1], argv[pkg_optind + 2]);
|
||||||
pkg_optind += 3;
|
pkg_optind += 3;
|
||||||
|
|
||||||
pkgq = pkg_queue_push(pkgq, packagebuf);
|
pkg_queue_push(&pkgq, packagebuf);
|
||||||
|
|
||||||
if (pkgq_head == NULL)
|
|
||||||
pkgq_head = pkgq;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pkgq_head == NULL)
|
if (pkgq.head == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Please specify at least one package name on the command line.\n");
|
fprintf(stderr, "Please specify at least one package name on the command line.\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
@ -779,7 +771,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
ret = EXIT_SUCCESS;
|
ret = EXIT_SUCCESS;
|
||||||
|
|
||||||
if (!pkg_queue_validate(pkgq_head, maximum_traverse_depth, global_traverse_flags))
|
if (!pkg_queue_validate(&pkgq, maximum_traverse_depth, global_traverse_flags))
|
||||||
{
|
{
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -788,7 +780,7 @@ main(int argc, char *argv[])
|
||||||
if ((want_flags & PKG_UNINSTALLED) == PKG_UNINSTALLED)
|
if ((want_flags & PKG_UNINSTALLED) == PKG_UNINSTALLED)
|
||||||
{
|
{
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
pkg_queue_apply(pkgq_head, apply_uninstalled, maximum_traverse_depth, global_traverse_flags, &ret);
|
pkg_queue_apply(&pkgq, apply_uninstalled, maximum_traverse_depth, global_traverse_flags, &ret);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -796,7 +788,7 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
|
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
|
||||||
|
|
||||||
if (!pkg_queue_apply(pkgq_head, apply_digraph, maximum_traverse_depth, global_traverse_flags, NULL))
|
if (!pkg_queue_apply(&pkgq, apply_digraph, maximum_traverse_depth, global_traverse_flags, NULL))
|
||||||
{
|
{
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -807,7 +799,7 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
|
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
|
||||||
|
|
||||||
if (!pkg_queue_apply(pkgq_head, apply_simulate, -1, global_traverse_flags, NULL))
|
if (!pkg_queue_apply(&pkgq, apply_simulate, -1, global_traverse_flags, NULL))
|
||||||
{
|
{
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -818,7 +810,7 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
|
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
|
||||||
|
|
||||||
if (!pkg_queue_apply(pkgq_head, apply_modversion, 2, global_traverse_flags, NULL))
|
if (!pkg_queue_apply(&pkgq, apply_modversion, 2, global_traverse_flags, NULL))
|
||||||
{
|
{
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -829,7 +821,7 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
|
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
|
||||||
|
|
||||||
if (!pkg_queue_apply(pkgq_head, apply_variables, 2, global_traverse_flags, NULL))
|
if (!pkg_queue_apply(&pkgq, apply_variables, 2, global_traverse_flags, NULL))
|
||||||
{
|
{
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -840,7 +832,7 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
|
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
|
||||||
|
|
||||||
if (!pkg_queue_apply(pkgq_head, apply_variable, 2, global_traverse_flags | PKGF_SKIP_ROOT_VIRTUAL, want_variable))
|
if (!pkg_queue_apply(&pkgq, apply_variable, 2, global_traverse_flags | PKGF_SKIP_ROOT_VIRTUAL, want_variable))
|
||||||
{
|
{
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -851,7 +843,7 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
|
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
|
||||||
|
|
||||||
if (!pkg_queue_apply(pkgq_head, apply_requires, maximum_traverse_depth, global_traverse_flags, NULL))
|
if (!pkg_queue_apply(&pkgq, apply_requires, maximum_traverse_depth, global_traverse_flags, NULL))
|
||||||
{
|
{
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -862,7 +854,7 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
|
want_flags &= ~(PKG_CFLAGS|PKG_LIBS);
|
||||||
|
|
||||||
if (!pkg_queue_apply(pkgq_head, apply_requires_private, maximum_traverse_depth, global_traverse_flags, NULL))
|
if (!pkg_queue_apply(&pkgq, apply_requires_private, maximum_traverse_depth, global_traverse_flags, NULL))
|
||||||
{
|
{
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -873,7 +865,7 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
pkg_fragment_t *frag_list = NULL;
|
pkg_fragment_t *frag_list = NULL;
|
||||||
|
|
||||||
if (!pkg_queue_apply(pkgq_head, apply_cflags, maximum_traverse_depth, global_traverse_flags, &frag_list))
|
if (!pkg_queue_apply(&pkgq, apply_cflags, maximum_traverse_depth, global_traverse_flags, &frag_list))
|
||||||
{
|
{
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
goto out_println;
|
goto out_println;
|
||||||
|
@ -884,14 +876,14 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
pkg_fragment_t *frag_list = NULL;
|
pkg_fragment_t *frag_list = NULL;
|
||||||
|
|
||||||
if (!pkg_queue_apply(pkgq_head, apply_libs, maximum_traverse_depth, global_traverse_flags, &frag_list))
|
if (!pkg_queue_apply(&pkgq, apply_libs, maximum_traverse_depth, global_traverse_flags, &frag_list))
|
||||||
{
|
{
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
goto out_println;
|
goto out_println;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pkg_queue_free(pkgq_head);
|
pkg_queue_free(&pkgq);
|
||||||
|
|
||||||
out_println:
|
out_println:
|
||||||
if (want_flags & (PKG_CFLAGS|PKG_LIBS))
|
if (want_flags & (PKG_CFLAGS|PKG_LIBS))
|
||||||
|
|
15
pkg.h
15
pkg.h
|
@ -74,11 +74,6 @@ struct pkg_tuple_ {
|
||||||
char *value;
|
char *value;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct pkg_queue_ {
|
|
||||||
struct pkg_queue_ *prev, *next;
|
|
||||||
char *package;
|
|
||||||
} pkg_queue_t;
|
|
||||||
|
|
||||||
#define PKG_PROPF_NONE 0x0
|
#define PKG_PROPF_NONE 0x0
|
||||||
#define PKG_PROPF_VIRTUAL 0x1
|
#define PKG_PROPF_VIRTUAL 0x1
|
||||||
#define PKG_PROPF_CACHED 0x2
|
#define PKG_PROPF_CACHED 0x2
|
||||||
|
@ -186,11 +181,11 @@ void pkg_tuple_define_global(const char *kv);
|
||||||
extern FILE *error_msgout;
|
extern FILE *error_msgout;
|
||||||
|
|
||||||
/* queue.c */
|
/* queue.c */
|
||||||
pkg_queue_t *pkg_queue_push(pkg_queue_t *parent, const char *package);
|
void pkg_queue_push(pkg_list_t *list, const char *package);
|
||||||
bool pkg_queue_compile(pkg_t *world, pkg_queue_t *head);
|
bool pkg_queue_compile(pkg_t *world, pkg_list_t *list);
|
||||||
void pkg_queue_free(pkg_queue_t *head);
|
void pkg_queue_free(pkg_list_t *list);
|
||||||
bool pkg_queue_apply(pkg_queue_t *head, pkg_queue_apply_func_t func, int maxdepth, unsigned int flags, void *data);
|
bool pkg_queue_apply(pkg_list_t *list, pkg_queue_apply_func_t func, int maxdepth, unsigned int flags, void *data);
|
||||||
bool pkg_queue_validate(pkg_queue_t *head, int maxdepth, unsigned int flags);
|
bool pkg_queue_validate(pkg_list_t *list, int maxdepth, unsigned int flags);
|
||||||
|
|
||||||
/* cache.c */
|
/* cache.c */
|
||||||
pkg_t *pkg_cache_lookup(const char *id);
|
pkg_t *pkg_cache_lookup(const char *id);
|
||||||
|
|
44
queue.c
44
queue.c
|
@ -16,29 +16,33 @@
|
||||||
#include "pkg.h"
|
#include "pkg.h"
|
||||||
#include "bsdstubs.h"
|
#include "bsdstubs.h"
|
||||||
|
|
||||||
pkg_queue_t *
|
typedef struct {
|
||||||
pkg_queue_push(pkg_queue_t *parent, const char *package)
|
pkg_node_t iter;
|
||||||
|
char *package;
|
||||||
|
} pkg_queue_t;
|
||||||
|
|
||||||
|
void
|
||||||
|
pkg_queue_push(pkg_list_t *list, const char *package)
|
||||||
{
|
{
|
||||||
pkg_queue_t *pkgq = calloc(sizeof(pkg_queue_t), 1);
|
pkg_queue_t *pkgq = calloc(sizeof(pkg_queue_t), 1);
|
||||||
|
|
||||||
pkgq->package = strdup(package);
|
pkgq->package = strdup(package);
|
||||||
pkgq->prev = parent;
|
pkg_node_insert_tail(&pkgq->iter, pkgq, list);
|
||||||
if (pkgq->prev != NULL)
|
|
||||||
pkgq->prev->next = pkgq;
|
|
||||||
|
|
||||||
return pkgq;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
pkg_queue_compile(pkg_t *world, pkg_queue_t *head)
|
pkg_queue_compile(pkg_t *world, pkg_list_t *list)
|
||||||
{
|
{
|
||||||
pkg_queue_t *pkgq;
|
pkg_node_t *iter;
|
||||||
|
|
||||||
PKG_FOREACH_LIST_ENTRY(head, pkgq)
|
PKG_FOREACH_LIST_ENTRY(list->head, iter)
|
||||||
{
|
{
|
||||||
|
pkg_queue_t *pkgq;
|
||||||
pkg_dependency_t *pkgdep;
|
pkg_dependency_t *pkgdep;
|
||||||
|
|
||||||
|
pkgq = iter->data;
|
||||||
pkgdep = pkg_dependency_parse(world, pkgq->package);
|
pkgdep = pkg_dependency_parse(world, pkgq->package);
|
||||||
|
|
||||||
if (pkgdep != NULL)
|
if (pkgdep != NULL)
|
||||||
world->requires = pkg_dependency_append(world->requires, pkgdep);
|
world->requires = pkg_dependency_append(world->requires, pkgdep);
|
||||||
else
|
else
|
||||||
|
@ -49,28 +53,30 @@ pkg_queue_compile(pkg_t *world, pkg_queue_t *head)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
pkg_queue_free(pkg_queue_t *head)
|
pkg_queue_free(pkg_list_t *list)
|
||||||
{
|
{
|
||||||
pkg_queue_t *pkgq, *next_pkgq;
|
pkg_node_t *node, *tnode;
|
||||||
|
|
||||||
PKG_FOREACH_LIST_ENTRY_SAFE(head, next_pkgq, pkgq)
|
PKG_FOREACH_LIST_ENTRY_SAFE(list->head, tnode, node)
|
||||||
{
|
{
|
||||||
|
pkg_queue_t *pkgq = node->data;
|
||||||
|
|
||||||
free(pkgq->package);
|
free(pkgq->package);
|
||||||
free(pkgq);
|
free(pkgq);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline unsigned int
|
static inline unsigned int
|
||||||
pkg_queue_verify(pkg_t *world, pkg_queue_t *head, int maxdepth, unsigned int flags)
|
pkg_queue_verify(pkg_t *world, pkg_list_t *list, int maxdepth, unsigned int flags)
|
||||||
{
|
{
|
||||||
if (!pkg_queue_compile(world, head))
|
if (!pkg_queue_compile(world, list))
|
||||||
return PKG_ERRF_DEPGRAPH_BREAK;
|
return PKG_ERRF_DEPGRAPH_BREAK;
|
||||||
|
|
||||||
return pkg_verify_graph(world, maxdepth, flags);
|
return pkg_verify_graph(world, maxdepth, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
pkg_queue_apply(pkg_queue_t *head, pkg_queue_apply_func_t func, int maxdepth, unsigned int flags, void *data)
|
pkg_queue_apply(pkg_list_t *list, pkg_queue_apply_func_t func, int maxdepth, unsigned int flags, void *data)
|
||||||
{
|
{
|
||||||
pkg_t world = {
|
pkg_t world = {
|
||||||
.id = "world",
|
.id = "world",
|
||||||
|
@ -82,7 +88,7 @@ pkg_queue_apply(pkg_queue_t *head, pkg_queue_apply_func_t func, int maxdepth, un
|
||||||
if (!maxdepth)
|
if (!maxdepth)
|
||||||
maxdepth = -1;
|
maxdepth = -1;
|
||||||
|
|
||||||
if (pkg_queue_verify(&world, head, maxdepth, flags) != PKG_ERRF_OK)
|
if (pkg_queue_verify(&world, list, maxdepth, flags) != PKG_ERRF_OK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!func(&world, data, maxdepth, flags))
|
if (!func(&world, data, maxdepth, flags))
|
||||||
|
@ -97,7 +103,7 @@ pkg_queue_apply(pkg_queue_t *head, pkg_queue_apply_func_t func, int maxdepth, un
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
pkg_queue_validate(pkg_queue_t *head, int maxdepth, unsigned int flags)
|
pkg_queue_validate(pkg_list_t *list, int maxdepth, unsigned int flags)
|
||||||
{
|
{
|
||||||
bool retval = true;
|
bool retval = true;
|
||||||
pkg_t world = {
|
pkg_t world = {
|
||||||
|
@ -110,7 +116,7 @@ pkg_queue_validate(pkg_queue_t *head, int maxdepth, unsigned int flags)
|
||||||
if (!maxdepth)
|
if (!maxdepth)
|
||||||
maxdepth = -1;
|
maxdepth = -1;
|
||||||
|
|
||||||
if (pkg_queue_verify(&world, head, maxdepth, flags) != PKG_ERRF_OK)
|
if (pkg_queue_verify(&world, list, maxdepth, flags) != PKG_ERRF_OK)
|
||||||
retval = false;
|
retval = false;
|
||||||
|
|
||||||
pkg_free(&world);
|
pkg_free(&world);
|
||||||
|
|
Loading…
Reference in New Issue