forked from ariadne/pkgconf
parse: split out tuple API and make public
parent
1752b75ac9
commit
4ea25d56f4
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
|||
PROG = pkgconf${PROG_SUFFIX}
|
||||
SRCS = main.c parse.c pkg.c bsdstubs.c getopt_long.c fragment.c argvsplit.c fileio.c
|
||||
SRCS = main.c parse.c pkg.c bsdstubs.c getopt_long.c fragment.c argvsplit.c fileio.c tuple.c
|
||||
|
||||
include buildsys.mk
|
||||
|
||||
|
|
2
main.c
2
main.c
|
@ -169,7 +169,7 @@ print_variable(pkg_t *pkg, void *unused)
|
|||
const char *variable_tmpl;
|
||||
(void) unused;
|
||||
|
||||
variable_tmpl = tuple_find(pkg->vars, want_variable);
|
||||
variable_tmpl = pkg_tuple_find(pkg->vars, want_variable);
|
||||
if (variable_tmpl != NULL)
|
||||
{
|
||||
char *var = strdup_parse(pkg, variable_tmpl);
|
||||
|
|
33
parse.c
33
parse.c
|
@ -24,35 +24,6 @@
|
|||
#include "pkg.h"
|
||||
#include "bsdstubs.h"
|
||||
|
||||
static pkg_tuple_t *
|
||||
tuple_add(pkg_tuple_t *parent, const char *key, const char *value)
|
||||
{
|
||||
pkg_tuple_t *tuple = calloc(sizeof(pkg_tuple_t), 1);
|
||||
|
||||
tuple->key = strdup(key);
|
||||
tuple->value = strdup(value);
|
||||
|
||||
tuple->next = parent;
|
||||
if (tuple->next != NULL)
|
||||
tuple->next->prev = tuple;
|
||||
|
||||
return tuple;
|
||||
}
|
||||
|
||||
char *
|
||||
tuple_find(pkg_tuple_t *head, const char *key)
|
||||
{
|
||||
pkg_tuple_t *node;
|
||||
|
||||
foreach_list_entry(head, node)
|
||||
{
|
||||
if (!strcasecmp(node->key, key))
|
||||
return node->value;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *
|
||||
strdup_parse(pkg_t *pkg, const char *value)
|
||||
{
|
||||
|
@ -85,7 +56,7 @@ strdup_parse(pkg_t *pkg, const char *value)
|
|||
}
|
||||
|
||||
ptr += (pptr - ptr);
|
||||
kv = tuple_find(pkg->vars, varname);
|
||||
kv = pkg_tuple_find(pkg->vars, varname);
|
||||
|
||||
if (kv != NULL)
|
||||
{
|
||||
|
@ -437,7 +408,7 @@ parse_file(const char *filename, FILE *f)
|
|||
pkg->conflicts = parse_deplist(pkg, value);
|
||||
break;
|
||||
case '=':
|
||||
pkg->vars = tuple_add(pkg->vars, key, value);
|
||||
pkg->vars = pkg_tuple_add(pkg->vars, key, value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
5
pkg.h
5
pkg.h
|
@ -135,7 +135,6 @@ const char *pkg_get_comparator(pkg_dependency_t *pkgdep);
|
|||
|
||||
/* parse.c */
|
||||
pkg_t *parse_file(const char *path, FILE *f);
|
||||
char *tuple_find(pkg_tuple_t *head, const char *key);
|
||||
pkg_dependency_t *parse_deplist(pkg_t *pkg, const char *depends);
|
||||
pkg_dependency_t *pkg_dependency_append(pkg_dependency_t *head, pkg_dependency_t *tail);
|
||||
char *strdup_parse(pkg_t *pkg, const char *value);
|
||||
|
@ -153,4 +152,8 @@ bool pkg_fragment_exists(pkg_fragment_t *head, pkg_fragment_t *base);
|
|||
/* fileio.c */
|
||||
char *pkg_fgetline(char *line, size_t size, FILE *stream);
|
||||
|
||||
/* tuple.c */
|
||||
pkg_tuple_t *pkg_tuple_add(pkg_tuple_t *parent, const char *key, const char *value);
|
||||
char *pkg_tuple_find(pkg_tuple_t *head, const char *key);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue