forked from ariadne/pkgconf
main: use pkgconf_fragment_filter() instead of crazy stuff
parent
0232ee52a3
commit
2b5d763e31
|
@ -227,7 +227,7 @@ int pkgconf_argv_split(const char *src, int *argc, char ***argv);
|
||||||
void pkgconf_argv_free(char **argv);
|
void pkgconf_argv_free(char **argv);
|
||||||
|
|
||||||
/* fragment.c */
|
/* fragment.c */
|
||||||
typedef bool (*pkgconf_fragment_filter_func_t)(const pkgconf_client_t *client, pkgconf_fragment_t *frag, unsigned int flags);
|
typedef bool (*pkgconf_fragment_filter_func_t)(const pkgconf_client_t *client, const pkgconf_fragment_t *frag, unsigned int flags);
|
||||||
void pkgconf_fragment_parse(const pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_list_t *vars, const char *value);
|
void pkgconf_fragment_parse(const pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_list_t *vars, const char *value);
|
||||||
void pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *string);
|
void pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *string);
|
||||||
void pkgconf_fragment_copy(pkgconf_list_t *list, const pkgconf_fragment_t *base, unsigned int flags, bool is_private);
|
void pkgconf_fragment_copy(pkgconf_list_t *list, const pkgconf_fragment_t *base, unsigned int flags, bool is_private);
|
||||||
|
|
85
main.c
85
main.c
|
@ -110,6 +110,15 @@ print_fragment(pkgconf_fragment_t *frag)
|
||||||
printf("%s ", frag->data);
|
printf("%s ", frag->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_fragment_list(pkgconf_list_t *list)
|
||||||
|
{
|
||||||
|
pkgconf_node_t *node;
|
||||||
|
|
||||||
|
PKGCONF_FOREACH_LIST_ENTRY(list->head, node)
|
||||||
|
print_fragment(node->data);
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
print_list_entry(const pkgconf_pkg_t *entry, void *data)
|
print_list_entry(const pkgconf_pkg_t *entry, void *data)
|
||||||
{
|
{
|
||||||
|
@ -136,37 +145,27 @@ print_package_entry(const pkgconf_pkg_t *entry, void *data)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static bool
|
||||||
print_cflags(pkgconf_list_t *list)
|
filter_cflags(const pkgconf_client_t *client, const pkgconf_fragment_t *frag, unsigned int flags)
|
||||||
{
|
{
|
||||||
pkgconf_node_t *node;
|
|
||||||
|
|
||||||
PKGCONF_FOREACH_LIST_ENTRY(list->head, node)
|
|
||||||
{
|
|
||||||
pkgconf_fragment_t *frag = node->data;
|
|
||||||
int got_flags = 0;
|
int got_flags = 0;
|
||||||
|
(void) client;
|
||||||
|
(void) flags;
|
||||||
|
|
||||||
if (frag->type == 'I')
|
if (frag->type == 'I')
|
||||||
got_flags = PKG_CFLAGS_ONLY_I;
|
got_flags = PKG_CFLAGS_ONLY_I;
|
||||||
else
|
else
|
||||||
got_flags = PKG_CFLAGS_ONLY_OTHER;
|
got_flags = PKG_CFLAGS_ONLY_OTHER;
|
||||||
|
|
||||||
if ((want_flags & got_flags) == 0)
|
return (want_flags & got_flags) != 0;
|
||||||
continue;
|
|
||||||
|
|
||||||
print_fragment(frag);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static bool
|
||||||
print_libs(pkgconf_list_t *list)
|
filter_libs(const pkgconf_client_t *client, const pkgconf_fragment_t *frag, unsigned int flags)
|
||||||
{
|
{
|
||||||
pkgconf_node_t *node;
|
|
||||||
|
|
||||||
PKGCONF_FOREACH_LIST_ENTRY(list->head, node)
|
|
||||||
{
|
|
||||||
pkgconf_fragment_t *frag = node->data;
|
|
||||||
int got_flags = 0;
|
int got_flags = 0;
|
||||||
|
(void) client;
|
||||||
|
(void) flags;
|
||||||
|
|
||||||
switch (frag->type)
|
switch (frag->type)
|
||||||
{
|
{
|
||||||
|
@ -175,11 +174,7 @@ print_libs(pkgconf_list_t *list)
|
||||||
default: got_flags = PKG_LIBS_ONLY_OTHER; break;
|
default: got_flags = PKG_LIBS_ONLY_OTHER; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((want_flags & got_flags) == 0)
|
return (want_flags & got_flags) != 0;
|
||||||
continue;
|
|
||||||
|
|
||||||
print_fragment(frag);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -392,41 +387,51 @@ apply_variable(pkgconf_client_t *client, pkgconf_pkg_t *world, void *variable, i
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
apply_cflags(pkgconf_client_t *client, pkgconf_pkg_t *world, void *list_head, int maxdepth, unsigned int flags)
|
apply_cflags(pkgconf_client_t *client, pkgconf_pkg_t *world, void *unused, int maxdepth, unsigned int flags)
|
||||||
{
|
{
|
||||||
pkgconf_list_t *list = list_head;
|
pkgconf_list_t unfiltered_list = PKGCONF_LIST_INITIALIZER;
|
||||||
|
pkgconf_list_t filtered_list = PKGCONF_LIST_INITIALIZER;
|
||||||
int eflag;
|
int eflag;
|
||||||
|
(void) unused;
|
||||||
|
|
||||||
eflag = pkgconf_pkg_cflags(client, world, list, maxdepth, flags | PKGCONF_PKG_PKGF_SEARCH_PRIVATE);
|
eflag = pkgconf_pkg_cflags(client, world, &unfiltered_list, maxdepth, flags | PKGCONF_PKG_PKGF_SEARCH_PRIVATE);
|
||||||
if (eflag != PKGCONF_PKG_ERRF_OK)
|
if (eflag != PKGCONF_PKG_ERRF_OK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (list->head == NULL)
|
pkgconf_fragment_filter(client, &filtered_list, &unfiltered_list, filter_cflags, flags);
|
||||||
|
|
||||||
|
if (filtered_list.head == NULL)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
print_cflags(list);
|
print_fragment_list(&filtered_list);
|
||||||
|
|
||||||
pkgconf_fragment_free(list);
|
pkgconf_fragment_free(&unfiltered_list);
|
||||||
|
pkgconf_fragment_free(&filtered_list);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
apply_libs(pkgconf_client_t *client, pkgconf_pkg_t *world, void *list_head, int maxdepth, unsigned int flags)
|
apply_libs(pkgconf_client_t *client, pkgconf_pkg_t *world, void *unused, int maxdepth, unsigned int flags)
|
||||||
{
|
{
|
||||||
pkgconf_list_t *list = list_head;
|
pkgconf_list_t unfiltered_list = PKGCONF_LIST_INITIALIZER;
|
||||||
|
pkgconf_list_t filtered_list = PKGCONF_LIST_INITIALIZER;
|
||||||
int eflag;
|
int eflag;
|
||||||
|
(void) unused;
|
||||||
|
|
||||||
eflag = pkgconf_pkg_libs(client, world, list, maxdepth, flags);
|
eflag = pkgconf_pkg_libs(client, world, &unfiltered_list, maxdepth, flags);
|
||||||
if (eflag != PKGCONF_PKG_ERRF_OK)
|
if (eflag != PKGCONF_PKG_ERRF_OK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (list->head == NULL)
|
pkgconf_fragment_filter(client, &filtered_list, &unfiltered_list, filter_libs, flags);
|
||||||
|
|
||||||
|
if (filtered_list.head == NULL)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
print_libs(list);
|
print_fragment_list(&filtered_list);
|
||||||
|
|
||||||
pkgconf_fragment_free(list);
|
pkgconf_fragment_free(&unfiltered_list);
|
||||||
|
pkgconf_fragment_free(&filtered_list);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1065,9 +1070,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
if ((want_flags & PKG_CFLAGS))
|
if ((want_flags & PKG_CFLAGS))
|
||||||
{
|
{
|
||||||
pkgconf_list_t frag_list = PKGCONF_LIST_INITIALIZER;
|
if (!pkgconf_queue_apply(&pkg_client, &pkgq, apply_cflags, maximum_traverse_depth, global_traverse_flags, NULL))
|
||||||
|
|
||||||
if (!pkgconf_queue_apply(&pkg_client, &pkgq, apply_cflags, maximum_traverse_depth, global_traverse_flags, &frag_list))
|
|
||||||
{
|
{
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
goto out_println;
|
goto out_println;
|
||||||
|
@ -1076,9 +1079,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
if ((want_flags & PKG_LIBS))
|
if ((want_flags & PKG_LIBS))
|
||||||
{
|
{
|
||||||
pkgconf_list_t frag_list = PKGCONF_LIST_INITIALIZER;
|
if (!pkgconf_queue_apply(&pkg_client, &pkgq, apply_libs, maximum_traverse_depth, global_traverse_flags, NULL))
|
||||||
|
|
||||||
if (!pkgconf_queue_apply(&pkg_client, &pkgq, apply_libs, maximum_traverse_depth, global_traverse_flags, &frag_list))
|
|
||||||
{
|
{
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
goto out_println;
|
goto out_println;
|
||||||
|
|
Loading…
Reference in New Issue