diff --git a/Makefile b/Makefile index 54d1ed1..690b5cb 100644 --- a/Makefile +++ b/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 diff --git a/main.c b/main.c index 0a0fe4d..bd52b6c 100644 --- a/main.c +++ b/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); diff --git a/parse.c b/parse.c index 0f3a501..a0b0014 100644 --- a/parse.c +++ b/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; diff --git a/pkg.h b/pkg.h index b643578..8f43a91 100644 --- a/pkg.h +++ b/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