From c398a2e974c60d96f135f3c71e8fa08f70a97973 Mon Sep 17 00:00:00 2001 From: fnevgeny Date: Sun, 15 Aug 2004 21:28:31 +0000 Subject: [PATCH] Added dict_get_descr_by_key(). --- include/grace/base.h | 1 + lib/base/dict3.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/grace/base.h b/include/grace/base.h index 750fb5e6..8185670a 100644 --- a/include/grace/base.h +++ b/include/grace/base.h @@ -111,6 +111,7 @@ Dictionary *dict_new_from_array(unsigned int nentries, const DictEntry *entries, int dict_get_key_by_name(const Dictionary *dict, const char *name, int *key); int dict_get_name_by_key(const Dictionary *dict, int key, char **name); +int dict_get_descr_by_key(const Dictionary *dict, int key, char **descr); /* diff --git a/lib/base/dict3.c b/lib/base/dict3.c index a53f0f54..4635eb7e 100644 --- a/lib/base/dict3.c +++ b/lib/base/dict3.c @@ -161,3 +161,23 @@ int dict_get_name_by_key(const Dictionary *dict, int key, char **name) return RETURN_FAILURE; } +int dict_get_descr_by_key(const Dictionary *dict, int key, char **descr) +{ + unsigned int i; + + if (!dict) { + return RETURN_FAILURE; + } + + for (i = 0; i < dict->size; i++) { + DictEntry *e = &dict->entries[i]; + if (e->key == key) { + *descr = e->descr; + return RETURN_SUCCESS; + } + } + + *descr = dict->defaults.descr; + + return RETURN_FAILURE; +} -- 2.11.4.GIT