diff options
author | Timo Sirainen <cras@irssi.org> | 2000-05-10 13:57:42 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2000-05-10 13:57:42 +0000 |
commit | bb4d7566c29162976f1d47ce51c1ffd1ce2041d6 (patch) | |
tree | 796489749de7f4b7bc5db0376f800df0ad434732 /src/lib-config/parse.c | |
parent | afc4fbc2238f9b76df9e704446ec9be64ee2f57b (diff) | |
download | irssi-bb4d7566c29162976f1d47ce51c1ffd1ce2041d6.zip |
iconfig's caching was a bit buggy - it didn't notice if some config node was
removed.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@213 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/lib-config/parse.c')
-rw-r--r-- | src/lib-config/parse.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/lib-config/parse.c b/src/lib-config/parse.c index 25f9ccec..0032b824 100644 --- a/src/lib-config/parse.c +++ b/src/lib-config/parse.c @@ -20,6 +20,29 @@ #include "module.h" +static int g_istr_equal(gconstpointer v, gconstpointer v2) +{ + return g_strcasecmp((const char *) v, (const char *) v2) == 0; +} + +/* a char* hash function from ASU */ +static unsigned int g_istr_hash(gconstpointer v) +{ + const char *s = (char *) v; + unsigned int h = 0, g; + + while (*s != '\0') { + h = (h << 4) + toupper(*s); + if ((g = h & 0xf0000000)) { + h = h ^ (g >> 24); + h = h ^ g; + } + s++; + } + + return h /* % M */; +} + int config_error(CONFIG_REC *rec, const char *msg) { g_free_and_null(rec->last_error); @@ -138,7 +161,7 @@ static int config_parse_symbol(CONFIG_REC *rec, CONFIG_NODE *node) switch (rec->scanner->token) { case G_TOKEN_STRING: /* value */ - config_node_set_str(node, key, rec->scanner->value.v_string); + config_node_set_str(rec, node, key, rec->scanner->value.v_string); g_free_not_null(key); print_warning = TRUE; @@ -303,7 +326,8 @@ CONFIG_REC *config_open(const char *fname, int create_mode) rec->create_mode = create_mode; rec->mainnode = g_new0(CONFIG_NODE, 1); rec->mainnode->type = NODE_TYPE_BLOCK; - rec->cache = g_hash_table_new((GHashFunc) g_str_hash, (GCompareFunc) g_str_equal); + rec->cache = g_hash_table_new((GHashFunc) g_istr_hash, (GCompareFunc) g_istr_equal); + rec->cache_nodes = g_hash_table_new((GHashFunc) g_direct_hash, (GCompareFunc) g_direct_equal); return rec; } @@ -319,6 +343,7 @@ void config_close(CONFIG_REC *rec) if (rec->handle != -1) close(rec->handle); g_hash_table_foreach(rec->cache, (GHFunc) g_free, NULL); g_hash_table_destroy(rec->cache); + g_hash_table_destroy(rec->cache_nodes); g_free_not_null(rec->last_error); g_free(rec->fname); g_free(rec); |