2012-05-07 03:32:53 +00:00
|
|
|
/*
|
|
|
|
* dependency.c
|
|
|
|
* dependency parsing and management
|
|
|
|
*
|
2013-02-24 14:21:36 +00:00
|
|
|
* Copyright (c) 2011, 2012, 2013 pkgconf authors (see AUTHORS).
|
2012-05-07 03:32:53 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
2012-07-20 19:29:58 +00:00
|
|
|
* This software is provided 'as is' and without any warranty, express or
|
|
|
|
* implied. In no event shall the authors be liable for any damages arising
|
|
|
|
* from the use of this software.
|
2012-05-07 03:32:53 +00:00
|
|
|
*/
|
|
|
|
|
2017-09-18 04:38:25 +00:00
|
|
|
#include <libpkgconf/stdinc.h>
|
2015-09-06 14:35:08 +00:00
|
|
|
#include <libpkgconf/libpkgconf.h>
|
2012-05-07 03:32:53 +00:00
|
|
|
|
|
|
|
/*
|
2016-12-11 01:57:26 +00:00
|
|
|
* !doc
|
2012-05-07 03:32:53 +00:00
|
|
|
*
|
2016-12-11 01:57:26 +00:00
|
|
|
* libpkgconf `dependency` module
|
|
|
|
* ==============================
|
|
|
|
*
|
|
|
|
* The `dependency` module provides support for building `dependency lists` (the basic component of the overall `dependency graph`) and
|
|
|
|
* `dependency nodes` which store dependency information.
|
2012-05-07 03:32:53 +00:00
|
|
|
*/
|
2016-12-11 01:57:26 +00:00
|
|
|
|
2012-05-07 03:32:53 +00:00
|
|
|
typedef enum {
|
|
|
|
OUTSIDE_MODULE = 0,
|
|
|
|
INSIDE_MODULE_NAME = 1,
|
|
|
|
BEFORE_OPERATOR = 2,
|
|
|
|
INSIDE_OPERATOR = 3,
|
|
|
|
AFTER_OPERATOR = 4,
|
|
|
|
INSIDE_VERSION = 5
|
|
|
|
} parse_state_t;
|
|
|
|
|
|
|
|
#define DEBUG_PARSE 0
|
|
|
|
|
2017-09-09 00:53:52 +00:00
|
|
|
static const char *
|
|
|
|
dependency_to_str(const pkgconf_dependency_t *dep, char *buf, size_t buflen)
|
2017-02-25 22:04:55 +00:00
|
|
|
{
|
2017-09-09 00:53:52 +00:00
|
|
|
pkgconf_strlcpy(buf, dep->package, buflen);
|
2017-02-25 22:04:55 +00:00
|
|
|
if (dep->version != NULL)
|
|
|
|
{
|
2017-09-09 00:53:52 +00:00
|
|
|
pkgconf_strlcat(buf, " ", buflen);
|
|
|
|
pkgconf_strlcat(buf, pkgconf_pkg_get_comparator(dep), buflen);
|
|
|
|
pkgconf_strlcat(buf, " ", buflen);
|
|
|
|
pkgconf_strlcat(buf, dep->version, buflen);
|
2017-02-25 22:04:55 +00:00
|
|
|
}
|
|
|
|
|
2017-09-09 00:53:52 +00:00
|
|
|
return buf;
|
2017-02-25 22:04:55 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 00:03:18 +00:00
|
|
|
/* find a colliding dependency that is coloured differently */
|
|
|
|
static inline pkgconf_dependency_t *
|
|
|
|
find_colliding_dependency(const pkgconf_dependency_t *dep, const pkgconf_list_t *list)
|
|
|
|
{
|
|
|
|
const pkgconf_node_t *n;
|
|
|
|
|
|
|
|
PKGCONF_FOREACH_LIST_ENTRY(list->head, n)
|
|
|
|
{
|
|
|
|
pkgconf_dependency_t *dep2 = n->data;
|
|
|
|
|
|
|
|
if (strcmp(dep->package, dep2->package))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (dep->flags != dep2->flags)
|
|
|
|
return dep2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline pkgconf_dependency_t *
|
2021-10-06 17:52:18 +00:00
|
|
|
add_or_replace_dependency_node(pkgconf_client_t *client, pkgconf_dependency_t *dep, pkgconf_list_t *list)
|
2018-03-19 00:03:18 +00:00
|
|
|
{
|
|
|
|
char depbuf[PKGCONF_ITEM_SIZE];
|
|
|
|
pkgconf_dependency_t *dep2 = find_colliding_dependency(dep, list);
|
|
|
|
|
|
|
|
/* there is already a node in the graph which describes this dependency */
|
|
|
|
if (dep2 != NULL)
|
|
|
|
{
|
|
|
|
char depbuf2[PKGCONF_ITEM_SIZE];
|
|
|
|
|
|
|
|
PKGCONF_TRACE(client, "dependency collision: [%s/%x] -- [%s/%x]",
|
|
|
|
dependency_to_str(dep, depbuf, sizeof depbuf), dep->flags,
|
|
|
|
dependency_to_str(dep2, depbuf2, sizeof depbuf2), dep2->flags);
|
|
|
|
|
|
|
|
/* prefer the uncoloured node, either dep or dep2 */
|
|
|
|
if (dep->flags && dep2->flags == 0)
|
|
|
|
{
|
|
|
|
PKGCONF_TRACE(client, "dropping dependency [%s]@%p because of collision", depbuf, dep);
|
|
|
|
|
2021-10-06 17:48:13 +00:00
|
|
|
pkgconf_dependency_unref(dep->owner, dep);
|
2018-03-19 00:03:18 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else if (dep2->flags && dep->flags == 0)
|
|
|
|
{
|
|
|
|
PKGCONF_TRACE(client, "dropping dependency [%s]@%p because of collision", depbuf2, dep2);
|
|
|
|
|
|
|
|
pkgconf_node_delete(&dep2->iter, list);
|
2021-10-06 17:48:13 +00:00
|
|
|
pkgconf_dependency_unref(dep2->owner, dep2);
|
2018-03-19 00:03:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
/* If both dependencies have equal strength, we keep both, because of situations like:
|
|
|
|
* Requires: foo > 1, foo < 3
|
|
|
|
*
|
|
|
|
* If the situation is that both dependencies are literally equal, it is still harmless because
|
|
|
|
* fragment deduplication will handle the excessive fragments.
|
|
|
|
*/
|
|
|
|
PKGCONF_TRACE(client, "keeping both dependencies (harmless)");
|
|
|
|
}
|
|
|
|
|
|
|
|
PKGCONF_TRACE(client, "added dependency [%s] to list @%p; flags=%x", dependency_to_str(dep, depbuf, sizeof depbuf), list, dep->flags);
|
|
|
|
pkgconf_node_insert_tail(&dep->iter, dep, list);
|
|
|
|
|
2021-10-06 17:48:13 +00:00
|
|
|
return pkgconf_dependency_ref(dep->owner, dep);
|
2018-03-19 00:03:18 +00:00
|
|
|
}
|
|
|
|
|
2015-09-06 15:38:30 +00:00
|
|
|
static inline pkgconf_dependency_t *
|
2021-10-06 17:52:18 +00:00
|
|
|
pkgconf_dependency_addraw(pkgconf_client_t *client, pkgconf_list_t *list, const char *package, size_t package_sz, const char *version, size_t version_sz, pkgconf_pkg_comparator_t compare, unsigned int flags)
|
2012-05-07 03:32:53 +00:00
|
|
|
{
|
2015-09-06 15:38:30 +00:00
|
|
|
pkgconf_dependency_t *dep;
|
2012-05-07 03:32:53 +00:00
|
|
|
|
2015-09-06 15:38:30 +00:00
|
|
|
dep = calloc(sizeof(pkgconf_dependency_t), 1);
|
2016-12-10 22:19:40 +00:00
|
|
|
dep->package = pkgconf_strndup(package, package_sz);
|
2012-05-07 03:32:53 +00:00
|
|
|
|
2012-08-14 15:13:28 +00:00
|
|
|
if (version_sz != 0)
|
2016-12-10 22:19:40 +00:00
|
|
|
dep->version = pkgconf_strndup(version, version_sz);
|
2012-05-07 03:32:53 +00:00
|
|
|
|
|
|
|
dep->compare = compare;
|
2018-03-18 23:01:59 +00:00
|
|
|
dep->flags = flags;
|
2021-10-06 17:48:13 +00:00
|
|
|
dep->owner = client;
|
|
|
|
dep->refcount = 0;
|
2012-05-07 03:32:53 +00:00
|
|
|
|
2018-03-19 00:03:18 +00:00
|
|
|
return add_or_replace_dependency_node(client, dep, list);
|
2012-05-07 03:32:53 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 01:57:26 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: pkgconf_dependency_t *pkgconf_dependency_add(pkgconf_list_t *list, const char *package, const char *version, pkgconf_pkg_comparator_t compare)
|
|
|
|
*
|
|
|
|
* Adds a parsed dependency to a dependency list as a dependency node.
|
|
|
|
*
|
2017-02-25 22:04:55 +00:00
|
|
|
* :param pkgconf_client_t* client: The client object that owns the package this dependency list belongs to.
|
2016-12-11 01:57:26 +00:00
|
|
|
* :param pkgconf_list_t* list: The dependency list to add a dependency node to.
|
|
|
|
* :param char* package: The package `atom` to set on the dependency node.
|
|
|
|
* :param char* version: The package `version` to set on the dependency node.
|
|
|
|
* :param pkgconf_pkg_comparator_t compare: The comparison operator to set on the dependency node.
|
2018-03-18 23:01:59 +00:00
|
|
|
* :param uint flags: Any flags to attach to the dependency node.
|
2016-12-11 01:57:26 +00:00
|
|
|
* :return: A dependency node.
|
|
|
|
* :rtype: pkgconf_dependency_t *
|
|
|
|
*/
|
2016-08-27 04:40:15 +00:00
|
|
|
pkgconf_dependency_t *
|
2021-10-06 17:52:18 +00:00
|
|
|
pkgconf_dependency_add(pkgconf_client_t *client, pkgconf_list_t *list, const char *package, const char *version, pkgconf_pkg_comparator_t compare, unsigned int flags)
|
2016-08-27 04:40:15 +00:00
|
|
|
{
|
|
|
|
if (version != NULL)
|
2018-03-18 23:01:59 +00:00
|
|
|
return pkgconf_dependency_addraw(client, list, package, strlen(package), version, strlen(version), compare, flags);
|
2016-08-27 04:40:15 +00:00
|
|
|
|
2018-03-18 23:01:59 +00:00
|
|
|
return pkgconf_dependency_addraw(client, list, package, strlen(package), NULL, 0, compare, flags);
|
2016-08-27 04:40:15 +00:00
|
|
|
}
|
|
|
|
|
2016-12-11 01:57:26 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_dependency_append(pkgconf_list_t *list, pkgconf_dependency_t *tail)
|
|
|
|
*
|
|
|
|
* Adds a dependency node to a pre-existing dependency list.
|
|
|
|
*
|
|
|
|
* :param pkgconf_list_t* list: The dependency list to add a dependency node to.
|
|
|
|
* :param pkgconf_dependency_t* tail: The dependency node to add to the tail of the dependency list.
|
|
|
|
* :return: nothing
|
|
|
|
*/
|
2013-03-01 17:36:21 +00:00
|
|
|
void
|
2015-09-06 15:38:30 +00:00
|
|
|
pkgconf_dependency_append(pkgconf_list_t *list, pkgconf_dependency_t *tail)
|
2012-05-07 03:32:53 +00:00
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_insert_tail(&tail->iter, tail, list);
|
2012-05-07 03:32:53 +00:00
|
|
|
}
|
|
|
|
|
2021-10-06 17:29:18 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_dependency_free_one(pkgconf_dependency_t *dep)
|
|
|
|
*
|
|
|
|
* Frees a dependency node.
|
|
|
|
*
|
|
|
|
* :param pkgconf_dependency_t* dep: The dependency node to free.
|
|
|
|
* :return: nothing
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pkgconf_dependency_free_one(pkgconf_dependency_t *dep)
|
|
|
|
{
|
|
|
|
if (dep->match != NULL)
|
|
|
|
pkgconf_pkg_unref(dep->match->owner, dep->match);
|
|
|
|
|
|
|
|
if (dep->package != NULL)
|
|
|
|
free(dep->package);
|
|
|
|
|
|
|
|
if (dep->version != NULL)
|
|
|
|
free(dep->version);
|
|
|
|
|
|
|
|
free(dep);
|
|
|
|
}
|
|
|
|
|
2021-10-06 17:48:13 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: pkgconf_dependency_t *pkgconf_dependency_ref(pkgconf_client_t *owner, pkgconf_dependency_t *dep)
|
|
|
|
*
|
|
|
|
* Increases a dependency node's refcount.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* owner: The client object which owns the memory of this dependency node.
|
|
|
|
* :param pkgconf_dependency_t* dep: The dependency to increase the refcount of.
|
|
|
|
* :return: the dependency node on success, else NULL
|
|
|
|
*/
|
|
|
|
pkgconf_dependency_t *
|
|
|
|
pkgconf_dependency_ref(pkgconf_client_t *client, pkgconf_dependency_t *dep)
|
|
|
|
{
|
|
|
|
if (client != dep->owner)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
dep->refcount++;
|
|
|
|
return dep;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_dependency_unref(pkgconf_client_t *owner, pkgconf_dependency_t *dep)
|
|
|
|
*
|
|
|
|
* Decreases a dependency node's refcount and frees it if necessary.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* owner: The client object which owns the memory of this dependency node.
|
|
|
|
* :param pkgconf_dependency_t* dep: The dependency to decrease the refcount of.
|
|
|
|
* :return: nothing
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
pkgconf_dependency_unref(pkgconf_client_t *client, pkgconf_dependency_t *dep)
|
|
|
|
{
|
|
|
|
if (client != dep->owner)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (--dep->refcount <= 0)
|
|
|
|
pkgconf_dependency_free_one(dep);
|
|
|
|
}
|
|
|
|
|
2016-12-11 01:57:26 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_dependency_free(pkgconf_list_t *list)
|
|
|
|
*
|
|
|
|
* Release a dependency list and it's child dependency nodes.
|
|
|
|
*
|
|
|
|
* :param pkgconf_list_t* list: The dependency list to release.
|
|
|
|
* :return: nothing
|
|
|
|
*/
|
2012-05-07 03:32:53 +00:00
|
|
|
void
|
2015-09-06 15:38:30 +00:00
|
|
|
pkgconf_dependency_free(pkgconf_list_t *list)
|
2012-05-07 03:32:53 +00:00
|
|
|
{
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_t *node, *next;
|
2012-05-07 03:32:53 +00:00
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
PKGCONF_FOREACH_LIST_ENTRY_SAFE(list->head, next, node)
|
2012-05-07 03:32:53 +00:00
|
|
|
{
|
2015-09-06 15:38:30 +00:00
|
|
|
pkgconf_dependency_t *dep = node->data;
|
2012-05-07 03:32:53 +00:00
|
|
|
|
2021-10-06 17:29:18 +00:00
|
|
|
pkgconf_node_delete(&dep->iter, list);
|
2021-10-06 17:48:13 +00:00
|
|
|
pkgconf_dependency_unref(dep->owner, dep);
|
2012-05-07 03:32:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-11 01:57:26 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_dependency_parse_str(pkgconf_list_t *deplist_head, const char *depends)
|
|
|
|
*
|
|
|
|
* Parse a dependency declaration into a dependency list.
|
|
|
|
* Commas are counted as whitespace to allow for constructs such as ``@SUBSTVAR@, zlib`` being processed
|
|
|
|
* into ``, zlib``.
|
|
|
|
*
|
2017-02-25 22:04:55 +00:00
|
|
|
* :param pkgconf_client_t* client: The client object that owns the package this dependency list belongs to.
|
2016-12-11 01:57:26 +00:00
|
|
|
* :param pkgconf_list_t* deplist_head: The dependency list to populate with dependency nodes.
|
|
|
|
* :param char* depends: The dependency data to parse.
|
2018-03-18 23:01:59 +00:00
|
|
|
* :param uint flags: Any flags to attach to the dependency nodes.
|
2016-12-11 01:57:26 +00:00
|
|
|
* :return: nothing
|
|
|
|
*/
|
2013-03-01 17:36:21 +00:00
|
|
|
void
|
2021-10-06 17:52:18 +00:00
|
|
|
pkgconf_dependency_parse_str(pkgconf_client_t *client, pkgconf_list_t *deplist_head, const char *depends, unsigned int flags)
|
2012-05-07 03:32:53 +00:00
|
|
|
{
|
|
|
|
parse_state_t state = OUTSIDE_MODULE;
|
2015-09-06 16:34:09 +00:00
|
|
|
pkgconf_pkg_comparator_t compare = PKGCONF_CMP_ANY;
|
2017-10-16 17:56:19 +00:00
|
|
|
char cmpname[PKGCONF_ITEM_SIZE];
|
2015-09-06 16:29:56 +00:00
|
|
|
char buf[PKGCONF_BUFSIZE];
|
2012-08-19 19:43:15 +00:00
|
|
|
size_t package_sz = 0, version_sz = 0;
|
2012-05-07 03:32:53 +00:00
|
|
|
char *start = buf;
|
|
|
|
char *ptr = buf;
|
|
|
|
char *vstart = NULL;
|
2012-08-14 15:13:28 +00:00
|
|
|
char *package = NULL, *version = NULL;
|
2013-02-24 13:41:18 +00:00
|
|
|
char *cnameptr = cmpname;
|
2020-05-26 19:42:13 +00:00
|
|
|
char *cnameend = cmpname + PKGCONF_ITEM_SIZE - 1;
|
2013-02-24 13:41:18 +00:00
|
|
|
|
|
|
|
memset(cmpname, '\0', sizeof cmpname);
|
2012-05-07 03:32:53 +00:00
|
|
|
|
2016-12-10 22:19:40 +00:00
|
|
|
pkgconf_strlcpy(buf, depends, sizeof buf);
|
|
|
|
pkgconf_strlcat(buf, " ", sizeof buf);
|
2012-05-07 03:32:53 +00:00
|
|
|
|
|
|
|
while (*ptr)
|
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case OUTSIDE_MODULE:
|
2015-09-06 16:39:55 +00:00
|
|
|
if (!PKGCONF_IS_MODULE_SEPARATOR(*ptr))
|
2012-05-07 03:32:53 +00:00
|
|
|
state = INSIDE_MODULE_NAME;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INSIDE_MODULE_NAME:
|
2015-12-02 13:59:51 +00:00
|
|
|
if (isspace((unsigned int)*ptr))
|
2012-05-07 03:32:53 +00:00
|
|
|
{
|
|
|
|
const char *sptr = ptr;
|
|
|
|
|
2015-12-02 13:59:51 +00:00
|
|
|
while (*sptr && isspace((unsigned int)*sptr))
|
2012-05-07 03:32:53 +00:00
|
|
|
sptr++;
|
|
|
|
|
|
|
|
if (*sptr == '\0')
|
|
|
|
state = OUTSIDE_MODULE;
|
2015-09-06 16:39:55 +00:00
|
|
|
else if (PKGCONF_IS_MODULE_SEPARATOR(*sptr))
|
2012-05-07 03:32:53 +00:00
|
|
|
state = OUTSIDE_MODULE;
|
2015-09-06 16:39:55 +00:00
|
|
|
else if (PKGCONF_IS_OPERATOR_CHAR(*sptr))
|
2012-05-07 03:32:53 +00:00
|
|
|
state = BEFORE_OPERATOR;
|
|
|
|
else
|
|
|
|
state = OUTSIDE_MODULE;
|
|
|
|
}
|
2015-09-06 16:39:55 +00:00
|
|
|
else if (PKGCONF_IS_MODULE_SEPARATOR(*ptr))
|
2012-05-07 03:32:53 +00:00
|
|
|
state = OUTSIDE_MODULE;
|
|
|
|
else if (*(ptr + 1) == '\0')
|
|
|
|
{
|
|
|
|
ptr++;
|
|
|
|
state = OUTSIDE_MODULE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state != INSIDE_MODULE_NAME && start != ptr)
|
|
|
|
{
|
|
|
|
char *iter = start;
|
|
|
|
|
2015-09-06 16:39:55 +00:00
|
|
|
while (PKGCONF_IS_MODULE_SEPARATOR(*iter))
|
2012-05-07 03:32:53 +00:00
|
|
|
iter++;
|
|
|
|
|
2012-08-14 15:13:28 +00:00
|
|
|
package = iter;
|
|
|
|
package_sz = ptr - iter;
|
2012-05-07 03:32:53 +00:00
|
|
|
start = ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state == OUTSIDE_MODULE)
|
|
|
|
{
|
2018-03-18 23:01:59 +00:00
|
|
|
pkgconf_dependency_addraw(client, deplist_head, package, package_sz, NULL, 0, compare, flags);
|
2012-05-07 03:32:53 +00:00
|
|
|
|
2015-09-06 16:34:09 +00:00
|
|
|
compare = PKGCONF_CMP_ANY;
|
2012-08-19 19:43:15 +00:00
|
|
|
package_sz = 0;
|
2012-05-07 03:32:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BEFORE_OPERATOR:
|
2015-09-06 16:39:55 +00:00
|
|
|
if (PKGCONF_IS_OPERATOR_CHAR(*ptr))
|
2012-05-07 03:32:53 +00:00
|
|
|
{
|
|
|
|
state = INSIDE_OPERATOR;
|
2020-05-26 19:42:13 +00:00
|
|
|
if (cnameptr < cnameend)
|
|
|
|
*cnameptr++ = *ptr;
|
2012-05-07 03:32:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INSIDE_OPERATOR:
|
2015-09-06 16:39:55 +00:00
|
|
|
if (!PKGCONF_IS_OPERATOR_CHAR(*ptr))
|
2012-05-07 03:32:53 +00:00
|
|
|
{
|
2013-02-24 13:41:18 +00:00
|
|
|
state = AFTER_OPERATOR;
|
2015-09-06 15:57:26 +00:00
|
|
|
compare = pkgconf_pkg_comparator_lookup_by_name(cmpname);
|
2012-05-07 03:32:53 +00:00
|
|
|
}
|
2020-05-26 19:42:13 +00:00
|
|
|
else if (cnameptr < cnameend)
|
2013-02-24 13:41:18 +00:00
|
|
|
*cnameptr++ = *ptr;
|
2012-05-07 03:32:53 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AFTER_OPERATOR:
|
2015-12-02 13:59:51 +00:00
|
|
|
if (!isspace((unsigned int)*ptr))
|
2012-05-07 03:32:53 +00:00
|
|
|
{
|
|
|
|
vstart = ptr;
|
|
|
|
state = INSIDE_VERSION;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INSIDE_VERSION:
|
2015-09-06 16:39:55 +00:00
|
|
|
if (PKGCONF_IS_MODULE_SEPARATOR(*ptr) || *(ptr + 1) == '\0')
|
2012-05-07 03:32:53 +00:00
|
|
|
{
|
2012-08-14 15:13:28 +00:00
|
|
|
version = vstart;
|
|
|
|
version_sz = ptr - vstart;
|
2012-05-07 03:32:53 +00:00
|
|
|
state = OUTSIDE_MODULE;
|
|
|
|
|
2018-03-18 23:01:59 +00:00
|
|
|
pkgconf_dependency_addraw(client, deplist_head, package, package_sz, version, version_sz, compare, flags);
|
2012-05-07 03:32:53 +00:00
|
|
|
|
2015-09-06 16:34:09 +00:00
|
|
|
compare = PKGCONF_CMP_ANY;
|
2013-03-16 00:44:11 +00:00
|
|
|
cnameptr = cmpname;
|
|
|
|
memset(cmpname, 0, sizeof cmpname);
|
2012-08-19 19:43:15 +00:00
|
|
|
package_sz = 0;
|
2012-05-07 03:32:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (state == OUTSIDE_MODULE)
|
|
|
|
start = ptr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
}
|
2012-07-02 02:44:30 +00:00
|
|
|
|
2016-12-11 01:57:26 +00:00
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: void pkgconf_dependency_parse(const pkgconf_client_t *client, pkgconf_pkg_t *pkg, pkgconf_list_t *deplist, const char *depends)
|
|
|
|
*
|
|
|
|
* Preprocess dependency data and then process that dependency declaration into a dependency list.
|
|
|
|
* Commas are counted as whitespace to allow for constructs such as ``@SUBSTVAR@, zlib`` being processed
|
|
|
|
* into ``, zlib``.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The client object that owns the package this dependency list belongs to.
|
|
|
|
* :param pkgconf_pkg_t* pkg: The package object that owns this dependency list.
|
|
|
|
* :param pkgconf_list_t* deplist: The dependency list to populate with dependency nodes.
|
|
|
|
* :param char* depends: The dependency data to parse.
|
2018-03-18 23:01:59 +00:00
|
|
|
* :param uint flags: Any flags to attach to the dependency nodes.
|
2016-12-11 01:57:26 +00:00
|
|
|
* :return: nothing
|
|
|
|
*/
|
2013-03-01 17:36:21 +00:00
|
|
|
void
|
2021-10-06 17:52:18 +00:00
|
|
|
pkgconf_dependency_parse(pkgconf_client_t *client, pkgconf_pkg_t *pkg, pkgconf_list_t *deplist, const char *depends, unsigned int flags)
|
2012-07-02 02:44:30 +00:00
|
|
|
{
|
2016-12-01 21:05:03 +00:00
|
|
|
char *kvdepends = pkgconf_tuple_parse(client, &pkg->vars, depends);
|
2012-07-02 02:44:30 +00:00
|
|
|
|
2018-03-18 23:01:59 +00:00
|
|
|
pkgconf_dependency_parse_str(client, deplist, kvdepends, flags);
|
2012-07-02 02:44:30 +00:00
|
|
|
free(kvdepends);
|
|
|
|
}
|
2021-10-06 19:13:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* !doc
|
|
|
|
*
|
|
|
|
* .. c:function:: pkgconf_dependency_t *pkgconf_dependency_copy(pkgconf_client_t *client, const pkgconf_dependency_t *dep)
|
|
|
|
*
|
|
|
|
* Copies a dependency node to a new one.
|
|
|
|
*
|
|
|
|
* :param pkgconf_client_t* client: The client object that will own this dependency.
|
|
|
|
* :param pkgconf_dependency_t* dep: The dependency node to copy.
|
|
|
|
* :return: a pointer to a new dependency node, else NULL
|
|
|
|
*/
|
|
|
|
pkgconf_dependency_t *
|
|
|
|
pkgconf_dependency_copy(pkgconf_client_t *client, const pkgconf_dependency_t *dep)
|
|
|
|
{
|
|
|
|
pkgconf_dependency_t *new_dep;
|
|
|
|
|
|
|
|
new_dep = calloc(sizeof(pkgconf_dependency_t), 1);
|
|
|
|
new_dep->package = strdup(dep->package);
|
|
|
|
|
|
|
|
if (dep->version != NULL)
|
|
|
|
new_dep->version = strdup(dep->version);
|
|
|
|
|
|
|
|
new_dep->compare = dep->compare;
|
|
|
|
new_dep->flags = dep->flags;
|
|
|
|
new_dep->owner = client;
|
|
|
|
new_dep->refcount = 0;
|
|
|
|
|
|
|
|
return pkgconf_dependency_ref(client, new_dep);
|
|
|
|
}
|