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
|
|
|
*/
|
|
|
|
|
2015-09-06 14:35:08 +00:00
|
|
|
#include <libpkgconf/libpkgconf.h>
|
2012-05-07 03:32:53 +00:00
|
|
|
|
|
|
|
/*
|
2015-09-06 15:38:30 +00:00
|
|
|
* pkgconf_dependency_parse(pkg, depends)
|
2012-05-07 03:32:53 +00:00
|
|
|
*
|
|
|
|
* Add requirements to a .pc file.
|
|
|
|
* Commas are counted as whitespace, as to allow:
|
|
|
|
* @SUBSTVAR@, zlib
|
|
|
|
* getting substituted to:
|
|
|
|
* , zlib.
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
|
2015-09-06 15:38:30 +00:00
|
|
|
static inline pkgconf_dependency_t *
|
2016-08-27 04:40:15 +00:00
|
|
|
pkgconf_dependency_addraw(pkgconf_list_t *list, const char *package, size_t package_sz, const char *version, size_t version_sz, pkgconf_pkg_comparator_t compare)
|
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);
|
2012-08-14 15:13:28 +00:00
|
|
|
dep->package = strndup(package, package_sz);
|
2012-05-07 03:32:53 +00:00
|
|
|
|
2012-08-14 15:13:28 +00:00
|
|
|
if (version_sz != 0)
|
|
|
|
dep->version = strndup(version, version_sz);
|
2012-05-07 03:32:53 +00:00
|
|
|
|
|
|
|
dep->compare = compare;
|
|
|
|
|
2015-09-06 15:31:21 +00:00
|
|
|
pkgconf_node_insert_tail(&dep->iter, dep, list);
|
2012-05-07 03:32:53 +00:00
|
|
|
|
|
|
|
return dep;
|
|
|
|
}
|
|
|
|
|
2016-08-27 04:40:15 +00:00
|
|
|
pkgconf_dependency_t *
|
|
|
|
pkgconf_dependency_add(pkgconf_list_t *list, const char *package, const char *version, pkgconf_pkg_comparator_t compare)
|
|
|
|
{
|
|
|
|
if (version != NULL)
|
|
|
|
return pkgconf_dependency_addraw(list, package, strlen(package), version, strlen(version), compare);
|
|
|
|
|
|
|
|
return pkgconf_dependency_addraw(list, package, strlen(package), NULL, 0, compare);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2013-03-01 17:36:21 +00:00
|
|
|
if (dep->package != NULL)
|
|
|
|
free(dep->package);
|
2012-05-07 03:32:53 +00:00
|
|
|
|
2013-03-01 17:36:21 +00:00
|
|
|
if (dep->version != NULL)
|
|
|
|
free(dep->version);
|
|
|
|
|
|
|
|
free(dep);
|
2012-05-07 03:32:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-01 17:36:21 +00:00
|
|
|
void
|
2015-09-06 15:38:30 +00:00
|
|
|
pkgconf_dependency_parse_str(pkgconf_list_t *deplist_head, const char *depends)
|
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;
|
2015-09-06 16:29:56 +00:00
|
|
|
char cmpname[PKGCONF_BUFSIZE];
|
|
|
|
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;
|
|
|
|
|
|
|
|
memset(cmpname, '\0', sizeof cmpname);
|
2012-05-07 03:32:53 +00:00
|
|
|
|
2012-07-02 02:44:30 +00:00
|
|
|
strlcpy(buf, depends, sizeof buf);
|
2012-05-07 03:32:53 +00:00
|
|
|
strlcat(buf, " ", sizeof buf);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2016-08-27 04:40:15 +00:00
|
|
|
pkgconf_dependency_addraw(deplist_head, package, package_sz, NULL, 0, compare);
|
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;
|
|
|
|
version_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;
|
2013-02-24 13:41:18 +00:00
|
|
|
*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
|
|
|
}
|
2013-02-24 13:41:18 +00:00
|
|
|
else
|
|
|
|
*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;
|
|
|
|
|
2016-08-27 04:40:15 +00:00
|
|
|
pkgconf_dependency_addraw(deplist_head, package, package_sz, version, version_sz, compare);
|
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;
|
|
|
|
version_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
|
|
|
|
2013-03-01 17:36:21 +00:00
|
|
|
void
|
2016-12-01 21:05:03 +00:00
|
|
|
pkgconf_dependency_parse(const pkgconf_client_t *client, pkgconf_pkg_t *pkg, pkgconf_list_t *deplist, const char *depends)
|
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
|
|
|
|
2015-09-06 15:38:30 +00:00
|
|
|
pkgconf_dependency_parse_str(deplist, kvdepends);
|
2012-07-02 02:44:30 +00:00
|
|
|
free(kvdepends);
|
|
|
|
}
|