From d2d9b45a8189b7771e1b7dfbe7d5a550fcf400b8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jun 2012 21:09:40 +0200 Subject: decoder_list: add _for_each() macros --- src/cmdline.c | 3 +-- src/decoder_list.c | 15 ++++----------- src/decoder_list.h | 10 ++++++++++ src/decoder_print.c | 5 ++--- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/cmdline.c b/src/cmdline.c index 4b44892f3..a7e1d42fa 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -58,8 +58,7 @@ cmdline_quark(void) static void print_all_decoders(FILE *fp) { - for (unsigned i = 0; decoder_plugins[i] != NULL; ++i) { - const struct decoder_plugin *plugin = decoder_plugins[i]; + decoder_plugins_for_each(plugin) { const char *const*suffixes; fprintf(fp, "[%s]", plugin->name); diff --git a/src/decoder_list.c b/src/decoder_list.c index d76050023..c3fd363c0 100644 --- a/src/decoder_list.c +++ b/src/decoder_list.c @@ -174,12 +174,9 @@ decoder_plugin_from_mime_type(const char *mimeType, unsigned int next) const struct decoder_plugin * decoder_plugin_from_name(const char *name) { - for (unsigned i = 0; decoder_plugins[i] != NULL; ++i) { - const struct decoder_plugin *plugin = decoder_plugins[i]; - if (decoder_plugins_enabled[i] && - strcmp(plugin->name, name) == 0) + decoder_plugins_for_each_enabled(plugin) + if (strcmp(plugin->name, name) == 0) return plugin; - } return NULL; } @@ -227,10 +224,6 @@ void decoder_plugin_init_all(void) void decoder_plugin_deinit_all(void) { - for (unsigned i = 0; decoder_plugins[i] != NULL; ++i) { - const struct decoder_plugin *plugin = decoder_plugins[i]; - - if (decoder_plugins_enabled[i]) - decoder_plugin_finish(plugin); - } + decoder_plugins_for_each_enabled(plugin) + decoder_plugin_finish(plugin); } diff --git a/src/decoder_list.h b/src/decoder_list.h index 7041db0c9..0fb63d401 100644 --- a/src/decoder_list.h +++ b/src/decoder_list.h @@ -27,6 +27,16 @@ struct decoder_plugin; extern const struct decoder_plugin *const decoder_plugins[]; extern bool decoder_plugins_enabled[]; +#define decoder_plugins_for_each(plugin) \ + for (const struct decoder_plugin *plugin, \ + *const*decoder_plugin_iterator = &decoder_plugins[0]; \ + (plugin = *decoder_plugin_iterator) != NULL; \ + ++decoder_plugin_iterator) + +#define decoder_plugins_for_each_enabled(plugin) \ + decoder_plugins_for_each(plugin) \ + if (decoder_plugins_enabled[decoder_plugin_iterator - decoder_plugins]) + /* interface for using plugins */ /** diff --git a/src/decoder_print.c b/src/decoder_print.c index a1c2da2e5..f859afe53 100644 --- a/src/decoder_print.c +++ b/src/decoder_print.c @@ -48,7 +48,6 @@ decoder_plugin_print(struct client *client, void decoder_list_print(struct client *client) { - for (unsigned i = 0; decoder_plugins[i] != NULL; ++i) - if (decoder_plugins_enabled[i]) - decoder_plugin_print(client, decoder_plugins[i]); + decoder_plugins_for_each_enabled(plugin) + decoder_plugin_print(client, plugin); } -- cgit v1.2.3