From 4f94090fe4b8998d03aab02ebc5129e6e8c34623 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 18 Jan 2017 20:25:19 -0600 Subject: [PATCH] libpkgconf: fragment: make pkgconf_fragment_filter() accept userdata (closes #106) --- doc/libpkgconf-fragment.rst | 1 + libpkgconf/fragment.c | 5 +++-- libpkgconf/libpkgconf.h | 4 ++-- main.c | 10 ++++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/doc/libpkgconf-fragment.rst b/doc/libpkgconf-fragment.rst index e9029e8..6a38b37 100644 --- a/doc/libpkgconf-fragment.rst +++ b/doc/libpkgconf-fragment.rst @@ -44,6 +44,7 @@ which is composable, mergeable and reorderable. :param pkgconf_list_t* dest: The destination list. :param pkgconf_list_t* src: The source list. :param pkgconf_fragment_filter_func_t filter_func: The filter function to use. + :param void* data: Optional data to pass to the filter function. :param uint flags: A set of dependency resolver flags. :return: nothing diff --git a/libpkgconf/fragment.c b/libpkgconf/fragment.c index c2f8a44..974d2bd 100644 --- a/libpkgconf/fragment.c +++ b/libpkgconf/fragment.c @@ -355,11 +355,12 @@ pkgconf_fragment_copy(pkgconf_list_t *list, const pkgconf_fragment_t *base, unsi * :param pkgconf_list_t* dest: The destination list. * :param pkgconf_list_t* src: The source list. * :param pkgconf_fragment_filter_func_t filter_func: The filter function to use. + * :param void* data: Optional data to pass to the filter function. * :param uint flags: A set of dependency resolver flags. * :return: nothing */ void -pkgconf_fragment_filter(const pkgconf_client_t *client, pkgconf_list_t *dest, pkgconf_list_t *src, pkgconf_fragment_filter_func_t filter_func, unsigned int flags) +pkgconf_fragment_filter(const pkgconf_client_t *client, pkgconf_list_t *dest, pkgconf_list_t *src, pkgconf_fragment_filter_func_t filter_func, void *data, unsigned int flags) { pkgconf_node_t *node; @@ -367,7 +368,7 @@ pkgconf_fragment_filter(const pkgconf_client_t *client, pkgconf_list_t *dest, pk { pkgconf_fragment_t *frag = node->data; - if (filter_func(client, frag, flags)) + if (filter_func(client, frag, data, flags)) pkgconf_fragment_copy(dest, frag, flags, true); } } diff --git a/libpkgconf/libpkgconf.h b/libpkgconf/libpkgconf.h index f2e6abf..a59b7cd 100644 --- a/libpkgconf/libpkgconf.h +++ b/libpkgconf/libpkgconf.h @@ -227,13 +227,13 @@ int pkgconf_argv_split(const char *src, int *argc, char ***argv); void pkgconf_argv_free(char **argv); /* fragment.c */ -typedef bool (*pkgconf_fragment_filter_func_t)(const pkgconf_client_t *client, const pkgconf_fragment_t *frag, unsigned int flags); +typedef bool (*pkgconf_fragment_filter_func_t)(const pkgconf_client_t *client, const pkgconf_fragment_t *frag, void *data, 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_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_delete(pkgconf_list_t *list, pkgconf_fragment_t *node); void pkgconf_fragment_free(pkgconf_list_t *list); -void pkgconf_fragment_filter(const pkgconf_client_t *client, pkgconf_list_t *dest, pkgconf_list_t *src, pkgconf_fragment_filter_func_t filter_func, unsigned int flags); +void pkgconf_fragment_filter(const pkgconf_client_t *client, pkgconf_list_t *dest, pkgconf_list_t *src, pkgconf_fragment_filter_func_t filter_func, void *data, unsigned int flags); size_t pkgconf_fragment_render_len(const pkgconf_list_t *list); void pkgconf_fragment_render_buf(const pkgconf_list_t *list, char *buf, size_t len); char *pkgconf_fragment_render(const pkgconf_list_t *list); diff --git a/main.c b/main.c index 0bcf79c..b555a9b 100644 --- a/main.c +++ b/main.c @@ -101,10 +101,11 @@ print_package_entry(const pkgconf_pkg_t *entry, void *data) } static bool -filter_cflags(const pkgconf_client_t *client, const pkgconf_fragment_t *frag, unsigned int flags) +filter_cflags(const pkgconf_client_t *client, const pkgconf_fragment_t *frag, void *data, unsigned int flags) { int got_flags = 0; (void) client; + (void) data; (void) flags; if (pkgconf_fragment_has_system_dir(client, frag)) @@ -119,10 +120,11 @@ filter_cflags(const pkgconf_client_t *client, const pkgconf_fragment_t *frag, un } static bool -filter_libs(const pkgconf_client_t *client, const pkgconf_fragment_t *frag, unsigned int flags) +filter_libs(const pkgconf_client_t *client, const pkgconf_fragment_t *frag, void *data, unsigned int flags) { int got_flags = 0; (void) client; + (void) data; (void) flags; if (pkgconf_fragment_has_system_dir(client, frag)) @@ -383,7 +385,7 @@ apply_cflags(pkgconf_client_t *client, pkgconf_pkg_t *world, void *unused, int m if (eflag != PKGCONF_PKG_ERRF_OK) return false; - pkgconf_fragment_filter(client, &filtered_list, &unfiltered_list, filter_cflags, flags); + pkgconf_fragment_filter(client, &filtered_list, &unfiltered_list, filter_cflags, NULL, flags); if (filtered_list.head == NULL) return true; @@ -411,7 +413,7 @@ apply_libs(pkgconf_client_t *client, pkgconf_pkg_t *world, void *unused, int max if (eflag != PKGCONF_PKG_ERRF_OK) return false; - pkgconf_fragment_filter(client, &filtered_list, &unfiltered_list, filter_libs, flags); + pkgconf_fragment_filter(client, &filtered_list, &unfiltered_list, filter_libs, NULL, flags); if (filtered_list.head == NULL) return true;