Commit d2d9b45a authored by Max Kellermann's avatar Max Kellermann

decoder_list: add _for_each() macros

parent 9ebbdb9b
......@@ -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);
......
......@@ -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);
}
......@@ -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 */
/**
......
......@@ -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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment