aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/archive_list.c42
-rw-r--r--src/archive_list.h8
2 files changed, 25 insertions, 25 deletions
diff --git a/src/archive_list.c b/src/archive_list.c
index 686498117..39eaf4d69 100644
--- a/src/archive_list.c
+++ b/src/archive_list.c
@@ -28,7 +28,7 @@
#include <string.h>
#include <glib.h>
-static const struct archive_plugin *const archive_plugins[] = {
+const struct archive_plugin *const archive_plugins[] = {
#ifdef HAVE_BZ2
&bz2_archive_plugin,
#endif
@@ -44,44 +44,38 @@ static const struct archive_plugin *const archive_plugins[] = {
/** which plugins have been initialized successfully? */
static bool archive_plugins_enabled[G_N_ELEMENTS(archive_plugins) - 1];
+#define archive_plugins_for_each_enabled(plugin) \
+ archive_plugins_for_each(plugin) \
+ if (archive_plugins_enabled[archive_plugin_iterator - archive_plugins])
+
const struct archive_plugin *
archive_plugin_from_suffix(const char *suffix)
{
if (suffix == NULL)
return NULL;
- for (unsigned i = 0; archive_plugins[i] != NULL; ++i) {
- const struct archive_plugin *plugin = archive_plugins[i];
- if (archive_plugins_enabled[i] &&
- plugin->suffixes != NULL &&
- string_array_contains(plugin->suffixes, suffix)) {
- ++i;
+ archive_plugins_for_each_enabled(plugin)
+ if (plugin->suffixes != NULL &&
+ string_array_contains(plugin->suffixes, suffix))
return plugin;
- }
- }
+
return NULL;
}
const struct archive_plugin *
archive_plugin_from_name(const char *name)
{
- for (unsigned i = 0; archive_plugins[i] != NULL; ++i) {
- const struct archive_plugin *plugin = archive_plugins[i];
- if (archive_plugins_enabled[i] &&
- strcmp(plugin->name, name) == 0)
+ archive_plugins_for_each_enabled(plugin)
+ if (strcmp(plugin->name, name) == 0)
return plugin;
- }
+
return NULL;
}
void archive_plugin_print_all_suffixes(FILE * fp)
{
- const char *const*suffixes;
-
- for (unsigned i = 0; archive_plugins[i] != NULL; ++i) {
- const struct archive_plugin *plugin = archive_plugins[i];
-
- suffixes = plugin->suffixes;
+ archive_plugins_for_each(plugin) {
+ const char *const*suffixes = plugin->suffixes;
while (suffixes && *suffixes) {
fprintf(fp, "%s ", *suffixes);
suffixes++;
@@ -102,10 +96,8 @@ void archive_plugin_init_all(void)
void archive_plugin_deinit_all(void)
{
- for (unsigned i = 0; archive_plugins[i] != NULL; ++i) {
- const struct archive_plugin *plugin = archive_plugins[i];
- if (archive_plugins_enabled[i] && plugin->finish != NULL)
- archive_plugins[i]->finish();
- }
+ archive_plugins_for_each_enabled(plugin)
+ if (plugin->finish != NULL)
+ plugin->finish();
}
diff --git a/src/archive_list.h b/src/archive_list.h
index b65245ce9..ec2ccc1e1 100644
--- a/src/archive_list.h
+++ b/src/archive_list.h
@@ -24,6 +24,14 @@
struct archive_plugin;
+extern const struct archive_plugin *const archive_plugins[];
+
+#define archive_plugins_for_each(plugin) \
+ for (const struct archive_plugin *plugin, \
+ *const*archive_plugin_iterator = &archive_plugins[0]; \
+ (plugin = *archive_plugin_iterator) != NULL; \
+ ++archive_plugin_iterator)
+
/* interface for using plugins */
const struct archive_plugin *