From 0056ba63dc17e4e972d5c0f6c3f13c31779f448a Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sun, 6 May 2012 23:10:41 -0500 Subject: [PATCH] tuple: add global tuple support (issue #5, issue #6, issue #7) --- main.c | 5 ++++- pkg.h | 3 +++ tuple.c | 30 +++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index f216329..088c7ad 100644 --- a/main.c +++ b/main.c @@ -620,5 +620,8 @@ main(int argc, char *argv[]) return EXIT_FAILURE; } - return pkg_queue_walk(pkgq_head); + ret = pkg_queue_walk(pkgq_head); + + pkg_tuple_free_global(); + return ret; } diff --git a/pkg.h b/pkg.h index 457ecda..0453434 100644 --- a/pkg.h +++ b/pkg.h @@ -165,5 +165,8 @@ pkg_tuple_t *pkg_tuple_add(pkg_tuple_t *parent, const char *key, const char *val char *pkg_tuple_find(pkg_tuple_t *head, const char *key); char *pkg_tuple_parse(pkg_tuple_t *vars, const char *value); void pkg_tuple_free(pkg_tuple_t *head); +void pkg_tuple_add_global(const char *key, const char *value); +char *pkg_tuple_find_global(const char *key); +void pkg_tuple_free_global(void); #endif diff --git a/tuple.c b/tuple.c index bdab5fd..e5cf13e 100644 --- a/tuple.c +++ b/tuple.c @@ -24,6 +24,34 @@ #include "pkg.h" #include "bsdstubs.h" +static pkg_tuple_t *pkg_global_var; + +void +pkg_tuple_add_global(const char *key, const char *value) +{ + pkg_global_var = pkg_tuple_add(pkg_global_var, key, value); +} + +char * +pkg_tuple_find_global(const char *key) +{ + pkg_tuple_t *node; + + PKG_FOREACH_LIST_ENTRY(pkg_global_var, node) + { + if (!strcasecmp(node->key, key)) + return node->value; + } + + return NULL; +} + +void +pkg_tuple_free_global(void) +{ + pkg_tuple_free(pkg_global_var); +} + pkg_tuple_t * pkg_tuple_add(pkg_tuple_t *parent, const char *key, const char *value) { @@ -50,7 +78,7 @@ pkg_tuple_find(pkg_tuple_t *head, const char *key) return node->value; } - return NULL; + return pkg_tuple_find_global(key); } char *