pkg: add support for fragment lists.

pull/15/head
William Pitcock 2012-05-03 19:25:33 +00:00
parent c74b749c65
commit 82420d0c5c
2 changed files with 68 additions and 0 deletions

60
parse.c
View File

@ -104,6 +104,66 @@ strdup_parse(pkg_t *pkg, const char *value)
return strdup(buf);
}
static pkg_fragment_t *
pkg_fragment_append(pkg_fragment_t *head, pkg_fragment_t *tail)
{
pkg_fragment_t *node;
if (head == NULL)
return tail;
/* skip to end of list */
foreach_list_entry(head, node)
{
if (node->next == NULL)
break;
}
node->next = tail;
tail->prev = node;
return head;
}
static pkg_fragment_t *
pkg_fragment_add(pkg_fragment_t *head, const char *string)
{
pkg_fragment_t *frag;
frag = calloc(sizeof(pkg_fragment_t), 1);
if (*string == '-' && !strncmp(string, "-lib:", 5))
{
frag->type = *(string + 1);
frag->data = strdup(string + 2);
}
else
{
frag->type = 0;
frag->data = strdup(string);
}
return pkg_fragment_append(head, frag);
}
static pkg_fragment_t *
parse_fragment_list(pkg_t *pkg, pkg_fragment_t *list, const char *string)
{
int i, argc;
char **argv;
char *repstr = strdup_parse(pkg, string);
pkg_fragment_t *head = list;
argv_split(repstr, &argc, &argv);
for (i = 0; i < argc; argc++)
head = pkg_fragment_add(head, argv[i]);
free(repstr);
return head;
}
/*
* parse_deplist(pkg, depends)
*

8
pkg.h
View File

@ -51,6 +51,7 @@ typedef enum {
typedef struct pkg_ pkg_t;
typedef struct dependency_ pkg_dependency_t;
typedef struct tuple_ pkg_tuple_t;
typedef struct fragment_ pkg_fragment_t;
#define foreach_list_entry(head, value) \
for ((value) = (head); (value) != NULL; (value) = (value)->next)
@ -66,6 +67,13 @@ typedef struct tuple_ pkg_tuple_t;
# define MAX(a,b) (((a) > (b)) ? (a) : (b))
#endif
struct fragment_ {
struct fragment_ *prev, *next;
char type;
char *data;
};
struct dependency_ {
struct dependency_ *prev, *next;