2012-05-03 20:22:19 +00:00
|
|
|
/*
|
|
|
|
* fragment.c
|
|
|
|
* Management of fragment lists.
|
|
|
|
*
|
2013-12-27 11:41:23 +00:00
|
|
|
* Copyright (c) 2012, 2013, 2014 pkgconf authors (see AUTHORS).
|
2012-05-03 20:22:19 +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-03 20:22:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "pkg.h"
|
|
|
|
#include "bsdstubs.h"
|
|
|
|
|
2013-03-01 17:10:43 +00:00
|
|
|
void
|
|
|
|
pkg_fragment_add(pkg_list_t *list, const char *string)
|
2012-05-03 20:22:19 +00:00
|
|
|
{
|
|
|
|
pkg_fragment_t *frag;
|
|
|
|
|
2013-03-15 22:29:07 +00:00
|
|
|
if (*string == '-' && strncmp(string, "-lib:", 5) && strncmp(string, "-framework", 10))
|
2012-05-03 20:22:19 +00:00
|
|
|
{
|
2013-12-27 11:37:24 +00:00
|
|
|
frag = calloc(sizeof(pkg_fragment_t), 1);
|
|
|
|
|
2012-05-03 20:22:19 +00:00
|
|
|
frag->type = *(string + 1);
|
|
|
|
frag->data = strdup(string + 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-27 11:37:24 +00:00
|
|
|
if (list->tail != NULL && list->tail->data != NULL)
|
|
|
|
{
|
|
|
|
pkg_fragment_t *parent = list->tail->data;
|
|
|
|
|
|
|
|
if (!strncmp(parent->data, "-framework", 10))
|
|
|
|
{
|
|
|
|
size_t len = strlen(parent->data) + strlen(string) + 2;
|
|
|
|
char *newdata;
|
|
|
|
|
|
|
|
newdata = malloc(len);
|
|
|
|
strlcpy(newdata, parent->data, len);
|
|
|
|
strlcat(newdata, " ", len);
|
|
|
|
strlcat(newdata, string, len);
|
|
|
|
|
|
|
|
free(parent->data);
|
|
|
|
parent->data = newdata;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
frag = calloc(sizeof(pkg_fragment_t), 1);
|
|
|
|
|
2012-05-03 20:22:19 +00:00
|
|
|
frag->type = 0;
|
|
|
|
frag->data = strdup(string);
|
|
|
|
}
|
|
|
|
|
2013-03-01 17:10:43 +00:00
|
|
|
pkg_node_insert_tail(&frag->iter, frag, list);
|
2012-05-03 20:22:19 +00:00
|
|
|
}
|
2012-05-03 20:27:19 +00:00
|
|
|
|
2012-08-09 22:06:09 +00:00
|
|
|
static inline pkg_fragment_t *
|
2013-03-01 17:10:43 +00:00
|
|
|
pkg_fragment_lookup(pkg_list_t *list, pkg_fragment_t *base)
|
2012-05-03 20:43:09 +00:00
|
|
|
{
|
2013-03-01 17:10:43 +00:00
|
|
|
pkg_node_t *node;
|
2012-05-03 20:43:09 +00:00
|
|
|
|
2013-03-01 17:10:43 +00:00
|
|
|
PKG_FOREACH_LIST_ENTRY(list->head, node)
|
2012-05-03 20:43:09 +00:00
|
|
|
{
|
2013-03-01 17:10:43 +00:00
|
|
|
pkg_fragment_t *frag = node->data;
|
|
|
|
|
|
|
|
if (base->type != frag->type)
|
2012-05-03 20:43:09 +00:00
|
|
|
continue;
|
|
|
|
|
2013-03-01 17:10:43 +00:00
|
|
|
if (!strcmp(base->data, frag->data))
|
|
|
|
return frag;
|
2012-05-03 20:43:09 +00:00
|
|
|
}
|
|
|
|
|
2012-08-09 22:06:09 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-15 22:29:07 +00:00
|
|
|
static inline bool
|
2013-08-23 03:44:33 +00:00
|
|
|
pkg_fragment_can_merge_back(pkg_fragment_t *base, unsigned int flags)
|
2013-03-15 22:29:07 +00:00
|
|
|
{
|
2013-08-23 03:44:33 +00:00
|
|
|
if ((flags & PKGF_MERGE_PRIVATE_FRAGMENTS) && base->type == 'l')
|
|
|
|
return false;
|
|
|
|
|
2013-03-15 22:29:07 +00:00
|
|
|
if (base->type == 'F')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
2013-08-23 03:44:33 +00:00
|
|
|
pkg_fragment_can_merge(pkg_fragment_t *base, unsigned int flags)
|
2013-03-15 22:29:07 +00:00
|
|
|
{
|
2013-08-23 03:44:33 +00:00
|
|
|
(void) flags;
|
|
|
|
|
2013-03-15 22:29:07 +00:00
|
|
|
if (!strncmp(base->data, "-framework", 10))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline pkg_fragment_t *
|
2013-08-23 03:44:33 +00:00
|
|
|
pkg_fragment_exists(pkg_list_t *list, pkg_fragment_t *base, unsigned int flags)
|
2012-08-09 22:06:09 +00:00
|
|
|
{
|
2013-08-23 03:44:33 +00:00
|
|
|
if (!pkg_fragment_can_merge_back(base, flags))
|
2013-03-15 22:29:07 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-08-23 03:44:33 +00:00
|
|
|
if (!pkg_fragment_can_merge(base, flags))
|
2013-03-15 22:29:07 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return pkg_fragment_lookup(list, base);
|
2012-05-03 20:43:09 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 17:10:43 +00:00
|
|
|
void
|
2013-08-23 03:44:33 +00:00
|
|
|
pkg_fragment_copy(pkg_list_t *list, pkg_fragment_t *base, unsigned int flags)
|
2012-05-03 20:31:33 +00:00
|
|
|
{
|
|
|
|
pkg_fragment_t *frag;
|
|
|
|
|
2013-08-23 03:44:33 +00:00
|
|
|
if ((frag = pkg_fragment_exists(list, base, flags)) != NULL)
|
2013-03-01 17:10:43 +00:00
|
|
|
pkg_fragment_delete(list, frag);
|
2013-08-23 03:44:33 +00:00
|
|
|
else if (!pkg_fragment_can_merge_back(base, flags) && (pkg_fragment_lookup(list, base) != NULL))
|
2013-03-15 22:29:07 +00:00
|
|
|
return;
|
2012-05-03 20:43:09 +00:00
|
|
|
|
2012-05-03 20:31:33 +00:00
|
|
|
frag = calloc(sizeof(pkg_fragment_t), 1);
|
|
|
|
|
|
|
|
frag->type = base->type;
|
|
|
|
frag->data = strdup(base->data);
|
|
|
|
|
2013-03-01 17:10:43 +00:00
|
|
|
pkg_node_insert_tail(&frag->iter, frag, list);
|
2012-05-03 20:31:33 +00:00
|
|
|
}
|
|
|
|
|
2012-05-03 20:27:19 +00:00
|
|
|
void
|
2013-03-01 17:10:43 +00:00
|
|
|
pkg_fragment_delete(pkg_list_t *list, pkg_fragment_t *node)
|
2012-05-03 20:27:19 +00:00
|
|
|
{
|
2013-03-01 17:10:43 +00:00
|
|
|
pkg_node_delete(&node->iter, list);
|
2012-05-03 20:27:19 +00:00
|
|
|
|
|
|
|
free(node->data);
|
|
|
|
free(node);
|
|
|
|
}
|
2012-05-07 01:26:09 +00:00
|
|
|
|
|
|
|
void
|
2013-03-01 17:10:43 +00:00
|
|
|
pkg_fragment_free(pkg_list_t *list)
|
2012-05-07 01:26:09 +00:00
|
|
|
{
|
2013-03-01 17:10:43 +00:00
|
|
|
pkg_node_t *node, *next;
|
2012-05-07 01:26:09 +00:00
|
|
|
|
2013-03-01 17:10:43 +00:00
|
|
|
PKG_FOREACH_LIST_ENTRY_SAFE(list->head, next, node)
|
|
|
|
{
|
|
|
|
pkg_fragment_t *frag = node->data;
|
|
|
|
|
|
|
|
free(frag->data);
|
|
|
|
free(frag);
|
|
|
|
}
|
2012-05-07 01:26:09 +00:00
|
|
|
}
|
2012-05-07 03:29:59 +00:00
|
|
|
|
2013-03-01 17:10:43 +00:00
|
|
|
void
|
|
|
|
pkg_fragment_parse(pkg_list_t *list, pkg_list_t *vars, const char *value)
|
2012-05-07 03:29:59 +00:00
|
|
|
{
|
|
|
|
int i, argc;
|
|
|
|
char **argv;
|
|
|
|
char *repstr = pkg_tuple_parse(vars, value);
|
|
|
|
|
|
|
|
pkg_argv_split(repstr, &argc, &argv);
|
|
|
|
|
|
|
|
for (i = 0; i < argc; i++)
|
2013-03-01 17:10:43 +00:00
|
|
|
pkg_fragment_add(list, argv[i]);
|
2012-05-07 03:29:59 +00:00
|
|
|
|
|
|
|
pkg_argv_free(argv);
|
|
|
|
free(repstr);
|
|
|
|
}
|