main: add pkg_queue for mergemaster operation

pull/1/merge
William Pitcock 2011-07-25 00:19:55 -05:00
parent 3a36809567
commit f79c6780c3
1 changed files with 51 additions and 23 deletions

74
main.c
View File

@ -42,36 +42,60 @@ print_libs(pkg_t *pkg, void *unused)
printf("%s ", pkg->libs); printf("%s ", pkg->libs);
} }
int typedef struct pkg_queue_ {
handle_package(const char *package) struct pkg_queue_ *prev, *next;
const char *package;
} pkg_queue_t;
static pkg_queue_t *
pkg_queue_push(pkg_queue_t *parent, const char *package)
{ {
pkg_t *pkg; pkg_queue_t *pkgq = calloc(sizeof(pkg_queue_t), 1);
pkg = pkg_find(package); pkgq->package = package;
if (pkg) pkgq->prev = parent;
if (pkgq->prev != NULL)
pkgq->prev->next = pkgq;
return pkgq;
}
int
pkg_queue_walk(pkg_queue_t *head)
{
int wanted_something = 0;
pkg_queue_t *pkgq;
foreach_list_entry(head, pkgq)
{ {
int wanted_something = 0; pkg_t *pkg;
if (want_cflags) pkg = pkg_find(pkgq->package);
if (pkg)
{ {
wanted_something++; if (want_cflags)
pkg_traverse(pkg, print_cflags, NULL); {
} wanted_something++;
pkg_traverse(pkg, print_cflags, NULL);
}
if (want_libs) if (want_libs)
{
wanted_something++;
pkg_traverse(pkg, print_libs, NULL);
}
}
else
{ {
wanted_something++; fprintf(stderr, "dependency '%s' could not be satisfied, see PKG_CONFIG_PATH.\n", pkgq->package);
pkg_traverse(pkg, print_libs, NULL); return EXIT_FAILURE;
} }
}
if (wanted_something) if (wanted_something)
printf("\n"); printf("\n");
}
else return EXIT_SUCCESS;
{
fprintf(stderr, "dependency '%s' could not be satisfied, see PKG_CONFIG_PATH.\n", package);
return -1;
}
} }
int int
@ -79,6 +103,8 @@ main(int argc, const char *argv[])
{ {
int ret; int ret;
poptContext opt_context; poptContext opt_context;
pkg_queue_t *pkgq = NULL;
pkg_queue_t *pkgq_head = NULL;
struct poptOption options[] = { struct poptOption options[] = {
{ "libs", 0, POPT_ARG_NONE, &want_libs, 0, "output all linker flags" }, { "libs", 0, POPT_ARG_NONE, &want_libs, 0, "output all linker flags" },
@ -103,10 +129,12 @@ main(int argc, const char *argv[])
if (package == NULL) if (package == NULL)
break; break;
handle_package(package); pkgq = pkg_queue_push(pkgq, package);
if (pkgq_head == NULL)
pkgq_head = pkgq;
} }
poptFreeContext(opt_context); poptFreeContext(opt_context);
return EXIT_SUCCESS; return pkg_queue_walk(pkgq_head);
} }