tuple: add global tuple support (issue #5, issue #6, issue #7)

feature/tap-sh
William Pitcock 2012-05-06 23:10:41 -05:00
parent 688c07890a
commit 0056ba63dc
3 changed files with 36 additions and 2 deletions

5
main.c
View File

@ -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;
}

3
pkg.h
View File

@ -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

30
tuple.c
View File

@ -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 *