From: Pietro Cerutti Date: Mon, 21 Nov 2016 16:55:21 +0000 (+0000) Subject: Hcache backends list up tidying X-Git-Tag: neomutt-20161126~13^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=867c626e9f327de577836ab908d2d3a65e3ee8c7;p=neomutt Hcache backends list up tidying --- diff --git a/hcache.c b/hcache.c index dca6e0c3d..5a7b240b9 100644 --- a/hcache.c +++ b/hcache.c @@ -90,21 +90,18 @@ const hcache_ops_t *hcache_ops[] = { static const hcache_ops_t * hcache_get_backend_ops(const char *backend) { - const char *b = NONULL(backend); - if (!b || !*b) - { - return hcache_ops[0]; - } + const hcache_ops_t **ops = hcache_ops; - for (size_t i = 0; i < sizeof(hcache_ops)/sizeof(*hcache_ops) - 1; ++i) + if (!backend || !*backend) { - if (!strcmp(b, hcache_ops[i]->name)) - { - return hcache_ops[i]; - } + return *ops; } - return NULL; + for (; *ops; ++ops) + if (!strcmp(backend, (*ops)->name)) + break; + + return *ops; } #define hcache_get_ops() hcache_get_backend_ops(HeaderCacheBackend) @@ -905,18 +902,19 @@ mutt_hcache_delete(header_cache_t *h, const char *key, size_t keylen) } const char * -mutt_hcache_backend() +mutt_hcache_backend_list() { char tmp[STRING] = {0}; + const hcache_ops_t **ops = hcache_ops; size_t len = 0; - for (size_t i = 0; i < sizeof(hcache_ops)/sizeof(*hcache_ops) - 1; ++i) + for (; *ops; ++ops) { if (len != 0) { len += snprintf(tmp+len, STRING-len, ", "); } - len += snprintf(tmp+len, STRING-len, "%s", hcache_ops[i]->name); + len += snprintf(tmp+len, STRING-len, "%s", (*ops)->name); } return strdup(tmp); diff --git a/hcache.h b/hcache.h index 56c6f07f7..07d59b6f1 100644 --- a/hcache.h +++ b/hcache.h @@ -127,12 +127,13 @@ int mutt_hcache_delete(header_cache_t *h, const char *key, size_t keylen); /** - * mutt_hcache_backend - get a backend-specific identification string. + * mutt_hcache_backend_list - get a list of backend identification strings. * - * @return String describing the currently used hcache backend. + * @return Comma separated string describing the compiled-in backends. + * @note The returned string must be free'd by the caller. */ const char * -mutt_hcache_backend(void); +mutt_hcache_backend_list(void); /** * mutt_hcache_is_valid_backend diff --git a/version.c b/version.c index ae5e2a091..5d3b95ac0 100644 --- a/version.c +++ b/version.c @@ -42,7 +42,7 @@ const char * mutt_make_version (void); void mutt_print_patchlist (void); /* #include "hcache.h" */ -const char * mutt_hcache_backend (void); +const char * mutt_hcache_backend_list (void); const int SCREEN_WIDTH = 80; @@ -428,7 +428,7 @@ print_version (void) #endif #ifdef USE_HCACHE - const char *backends = mutt_hcache_backend(); + const char *backends = mutt_hcache_backend_list(); printf ("\nhcache backends: %s", backends); FREE(&backends); #endif