From 174db1a17ad11091bba0c5a2c53bbdd14ba74b73 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Mon, 5 Aug 2024 14:27:13 -0700 Subject: [PATCH] fragment: add pkgconf_fragment_insert() --- libpkgconf/fragment.c | 32 ++++++++++++++++++++++++++++++++ libpkgconf/libpkgconf.h | 1 + 2 files changed, 33 insertions(+) diff --git a/libpkgconf/fragment.c b/libpkgconf/fragment.c index c6bcac8..357f787 100644 --- a/libpkgconf/fragment.c +++ b/libpkgconf/fragment.c @@ -120,6 +120,38 @@ pkgconf_fragment_copy_munged(const pkgconf_client_t *client, const char *source, return strdup(mungebuf); } +/* + * !doc + * + * .. c:function:: void pkgconf_fragment_insert(const pkgconf_client_t *client, pkgconf_list_t *list, char type, const char *data, bool tail) + * + * Adds a `fragment` of text to a `fragment list` directly without interpreting it. + * + * :param pkgconf_client_t* client: The pkgconf client being accessed. + * :param pkgconf_list_t* list: The fragment list. + * :param char type: The type of the fragment. + * :param char* data: The data of the fragment. + * :param bool tail: Whether to place the fragment at the beginning of the list or the end. + * :return: nothing + */ +void +pkgconf_fragment_insert(const pkgconf_client_t *client, pkgconf_list_t *list, char type, const char *data, bool tail) +{ + pkgconf_fragment_t *frag; + + frag = calloc(1, sizeof(pkgconf_fragment_t)); + frag->type = type; + frag->data = pkgconf_fragment_copy_munged(client, data, 0); + + if (tail) + { + pkgconf_node_insert_tail(&frag->iter, frag, list); + return; + } + + pkgconf_node_insert(&frag->iter, frag, list); +} + /* * !doc * diff --git a/libpkgconf/libpkgconf.h b/libpkgconf/libpkgconf.h index f99c7c6..43d8085 100644 --- a/libpkgconf/libpkgconf.h +++ b/libpkgconf/libpkgconf.h @@ -367,6 +367,7 @@ typedef struct pkgconf_fragment_render_ops_ { typedef bool (*pkgconf_fragment_filter_func_t)(const pkgconf_client_t *client, const pkgconf_fragment_t *frag, void *data); PKGCONF_API bool pkgconf_fragment_parse(const pkgconf_client_t *client, pkgconf_list_t *list, pkgconf_list_t *vars, const char *value, unsigned int flags); +PKGCONF_API void pkgconf_fragment_insert(const pkgconf_client_t *client, pkgconf_list_t *list, char type, const char *data, bool tail); PKGCONF_API void pkgconf_fragment_add(const pkgconf_client_t *client, pkgconf_list_t *list, const char *string, unsigned int flags); PKGCONF_API void pkgconf_fragment_copy(const pkgconf_client_t *client, pkgconf_list_t *list, const pkgconf_fragment_t *base, bool is_private); PKGCONF_API void pkgconf_fragment_copy_list(const pkgconf_client_t *client, pkgconf_list_t *list, const pkgconf_list_t *base);