aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-06-12 20:39:53 +0200
committerMax Kellermann <max@duempel.org>2012-06-12 20:39:53 +0200
commitedbfa46cbc01bfbb1f7f1b624aaeae635408528c (patch)
treeea82a05865eed99a9e82ba7ab2585ef8f3e46fc3
parent90709a6de4dbfc25c86ec1bb9249836720dc07b8 (diff)
downloadmpd-edbfa46cbc01bfbb1f7f1b624aaeae635408528c.tar.gz
mpd-edbfa46cbc01bfbb1f7f1b624aaeae635408528c.tar.xz
mpd-edbfa46cbc01bfbb1f7f1b624aaeae635408528c.zip
encoder_list: add macro _for_each()
Diffstat (limited to '')
-rw-r--r--src/encoder_list.c12
-rw-r--r--src/encoder_list.h8
2 files changed, 14 insertions, 6 deletions
diff --git a/src/encoder_list.c b/src/encoder_list.c
index dea72650c..da1bec5ef 100644
--- a/src/encoder_list.c
+++ b/src/encoder_list.c
@@ -30,7 +30,7 @@ extern const struct encoder_plugin twolame_encoder_plugin;
extern const struct encoder_plugin wave_encoder_plugin;
extern const struct encoder_plugin flac_encoder_plugin;
-static const struct encoder_plugin *const encoder_plugins[] = {
+const struct encoder_plugin *const encoder_plugins[] = {
&null_encoder_plugin,
#ifdef ENABLE_VORBIS_ENCODER
&vorbis_encoder_plugin,
@@ -53,9 +53,9 @@ static const struct encoder_plugin *const encoder_plugins[] = {
const struct encoder_plugin *
encoder_plugin_get(const char *name)
{
- for (unsigned i = 0; encoder_plugins[i] != NULL; ++i)
- if (strcmp(encoder_plugins[i]->name, name) == 0)
- return encoder_plugins[i];
+ encoder_plugins_for_each(plugin)
+ if (strcmp(plugin->name, name) == 0)
+ return plugin;
return NULL;
}
@@ -63,8 +63,8 @@ encoder_plugin_get(const char *name)
void
encoder_plugin_print_all_types(FILE * fp)
{
- for (unsigned i = 0; encoder_plugins[i] != NULL; ++i)
- fprintf(fp, "%s ", encoder_plugins[i]->name);
+ encoder_plugins_for_each(plugin)
+ fprintf(fp, "%s ", plugin->name);
fprintf(fp, "\n");
fflush(fp);
diff --git a/src/encoder_list.h b/src/encoder_list.h
index 95f853004..4fe87e16c 100644
--- a/src/encoder_list.h
+++ b/src/encoder_list.h
@@ -24,6 +24,14 @@
struct encoder_plugin;
+extern const struct encoder_plugin *const encoder_plugins[];
+
+#define encoder_plugins_for_each(plugin) \
+ for (const struct encoder_plugin *plugin, \
+ *const*encoder_plugin_iterator = &encoder_plugins[0]; \
+ (plugin = *encoder_plugin_iterator) != NULL; \
+ ++encoder_plugin_iterator)
+
/**
* Looks up an encoder plugin by its name.
*