diff options
author | Max Kellermann <max@duempel.org> | 2012-06-12 21:09:40 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2012-06-12 21:15:46 +0200 |
commit | d2d9b45a8189b7771e1b7dfbe7d5a550fcf400b8 (patch) | |
tree | 6e1653ab8cd563dd2e6c326d99fecda34d202fe6 /src | |
parent | 9ebbdb9b0b288164ce956ba34bc0c38f94868110 (diff) |
decoder_list: add _for_each() macros
Diffstat (limited to 'src')
-rw-r--r-- | src/cmdline.c | 3 | ||||
-rw-r--r-- | src/decoder_list.c | 15 | ||||
-rw-r--r-- | src/decoder_list.h | 10 | ||||
-rw-r--r-- | 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); } |