main: add pkg_queue for mergemaster operation

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

50
main.c
View File

@ -42,16 +42,37 @@ print_libs(pkg_t *pkg, void *unused)
printf("%s ", pkg->libs); printf("%s ", pkg->libs);
} }
typedef struct pkg_queue_ {
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_queue_t *pkgq = calloc(sizeof(pkg_queue_t), 1);
pkgq->package = package;
pkgq->prev = parent;
if (pkgq->prev != NULL)
pkgq->prev->next = pkgq;
return pkgq;
}
int int
handle_package(const char *package) pkg_queue_walk(pkg_queue_t *head)
{
int wanted_something = 0;
pkg_queue_t *pkgq;
foreach_list_entry(head, pkgq)
{ {
pkg_t *pkg; pkg_t *pkg;
pkg = pkg_find(package); pkg = pkg_find(pkgq->package);
if (pkg) if (pkg)
{ {
int wanted_something = 0;
if (want_cflags) if (want_cflags)
{ {
wanted_something++; wanted_something++;
@ -63,22 +84,27 @@ handle_package(const char *package)
wanted_something++; wanted_something++;
pkg_traverse(pkg, print_libs, NULL); pkg_traverse(pkg, print_libs, NULL);
} }
if (wanted_something)
printf("\n");
} }
else else
{ {
fprintf(stderr, "dependency '%s' could not be satisfied, see PKG_CONFIG_PATH.\n", package); fprintf(stderr, "dependency '%s' could not be satisfied, see PKG_CONFIG_PATH.\n", pkgq->package);
return -1; return EXIT_FAILURE;
} }
} }
if (wanted_something)
printf("\n");
return EXIT_SUCCESS;
}
int int
main(int argc, const char *argv[]) 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);
} }