From 50cfb997ccbbebd6387f2f2cfbc3279d8426020f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jun 2012 19:21:26 +0200 Subject: gcc.h: backport GCC_CHECK_VERSION() from v0.17.x --- src/gcc.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gcc.h b/src/gcc.h index 085a8a5f6..6f3330b74 100644 --- a/src/gcc.h +++ b/src/gcc.h @@ -20,13 +20,18 @@ #ifndef MPD_GCC_H #define MPD_GCC_H +#define GCC_CHECK_VERSION(major, minor) \ + (defined(__GNUC__) && \ + (__GNUC__ > (major) || \ + (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))) + /* this allows us to take advantage of special gcc features while still * allowing other compilers to compile: * * example taken from: http://rlove.org/log/2005102601 */ -#if defined(__GNUC__) && (__GNUC__ >= 3) +#if GCC_CHECK_VERSION(3,0) # define mpd_must_check __attribute__ ((warn_unused_result)) # define mpd_packed __attribute__ ((packed)) /* these are very useful for type checking */ -- cgit v1.2.3 From 055257a210015a623062ad3ad3cb8a40fbc6839f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jun 2012 19:21:53 +0200 Subject: audio-parser, output_thread: work around -Wmaybe-uninitialized False positives in gcc 4.7. --- src/audio_parser.c | 11 +++++++++++ src/output_thread.c | 5 +++++ 2 files changed, 16 insertions(+) (limited to 'src') diff --git a/src/audio_parser.c b/src/audio_parser.c index 139cf1c04..908230cb2 100644 --- a/src/audio_parser.c +++ b/src/audio_parser.c @@ -26,6 +26,7 @@ #include "audio_parser.h" #include "audio_format.h" #include "audio_check.h" +#include "gcc.h" #include #include @@ -160,6 +161,11 @@ audio_format_parse(struct audio_format *dest, const char *src, /* parse sample rate */ +#if GCC_CHECK_VERSION(4,7) + /* workaround -Wmaybe-uninitialized false positive */ + rate = 0; +#endif + if (!parse_sample_rate(src, mask, &rate, &src, error_r)) return false; @@ -171,6 +177,11 @@ audio_format_parse(struct audio_format *dest, const char *src, /* parse sample format */ +#if GCC_CHECK_VERSION(4,7) + /* workaround -Wmaybe-uninitialized false positive */ + sample_format = SAMPLE_FORMAT_UNDEFINED; +#endif + if (!parse_sample_format(src, mask, &sample_format, &src, error_r)) return false; diff --git a/src/output_thread.c b/src/output_thread.c index bf56ca971..4f3ab3e49 100644 --- a/src/output_thread.c +++ b/src/output_thread.c @@ -29,6 +29,7 @@ #include "filter/convert_filter_plugin.h" #include "filter/replay_gain_filter_plugin.h" #include "mpd_error.h" +#include "gcc.h" #include @@ -438,6 +439,10 @@ ao_play_chunk(struct audio_output *ao, const struct music_chunk *chunk) } size_t size; +#if GCC_CHECK_VERSION(4,7) + /* workaround -Wmaybe-uninitialized false positive */ + size = 0; +#endif const char *data = ao_filter_chunk(ao, chunk, &size); if (data == NULL) { ao_close(ao, false); -- cgit v1.2.3 From 25d053cbf288fb966526c554bea6158ef5c38202 Mon Sep 17 00:00:00 2001 From: Denis Krjuchkov Date: Sun, 3 Jun 2012 13:00:11 +0600 Subject: Work around incorrect g_file_test() behavior on Win32 g_file_test is redefined to be g_file_test_utf8 and thus can't handle non-ASCII characters. This fix adds simple wrapper (taken from glib) that fixes encoding and calls g_file_test_utf8. All required inclusions of glib_compat.h are added as well. --- src/cmdline.c | 1 + src/decoder/wildmidi_decoder_plugin.c | 1 + src/glib_compat.h | 28 ++++++++++++++++++++++++++++ src/playlist_save.c | 1 + src/update_walk.c | 1 + 5 files changed, 32 insertions(+) (limited to 'src') diff --git a/src/cmdline.c b/src/cmdline.c index d986c8eb8..b1482c350 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -27,6 +27,7 @@ #include "output_list.h" #include "ls.h" #include "mpd_error.h" +#include "glib_compat.h" #ifdef ENABLE_ENCODER #include "encoder_list.h" diff --git a/src/decoder/wildmidi_decoder_plugin.c b/src/decoder/wildmidi_decoder_plugin.c index 66e6c61cf..5eb0638da 100644 --- a/src/decoder/wildmidi_decoder_plugin.c +++ b/src/decoder/wildmidi_decoder_plugin.c @@ -19,6 +19,7 @@ #include "config.h" #include "decoder_api.h" +#include "glib_compat.h" #include diff --git a/src/glib_compat.h b/src/glib_compat.h index 4d0e7040d..0b96a662d 100644 --- a/src/glib_compat.h +++ b/src/glib_compat.h @@ -74,4 +74,32 @@ g_uri_parse_scheme(const char *uri) #endif +#if defined(G_OS_WIN32) && defined(g_file_test) + +/* Modern GLib on Win32 likes to use UTF-8 for file names. +It redefines g_file_test() to be g_file_test_utf8(). +This gives incorrect results for non-ASCII files. +Old g_file_test() is available for *binary compatibility*, +but symbol is hidden from linker, we copy-paste its definition here */ + +#undef g_file_test + +static inline gboolean +g_file_test(const gchar *filename, GFileTest test) +{ + gchar *utf8_filename = g_locale_to_utf8(filename, -1, NULL, NULL, NULL); + gboolean retval; + + if (utf8_filename == NULL) + return FALSE; + + retval = g_file_test_utf8(utf8_filename, test); + + g_free(utf8_filename); + + return retval; +} + +#endif + #endif diff --git a/src/playlist_save.c b/src/playlist_save.c index 8ddc93ec9..d290d889c 100644 --- a/src/playlist_save.c +++ b/src/playlist_save.c @@ -26,6 +26,7 @@ #include "uri.h" #include "database.h" #include "idle.h" +#include "glib_compat.h" #include diff --git a/src/update_walk.c b/src/update_walk.c index 5d2f778ff..b93c9c453 100644 --- a/src/update_walk.c +++ b/src/update_walk.c @@ -29,6 +29,7 @@ #include "decoder_list.h" #include "decoder_plugin.h" #include "playlist_list.h" +#include "glib_compat.h" #include "conf.h" #ifdef ENABLE_ARCHIVE -- cgit v1.2.3 From 9604e0aad2abf1e564766f039cb21da9849d1ac4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jun 2012 19:55:30 +0200 Subject: cmdline: update copyright year --- src/cmdline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/cmdline.c b/src/cmdline.c index b1482c350..10f0a3572 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -80,7 +80,7 @@ static void version(void) puts(PACKAGE " (MPD: Music Player Daemon) " VERSION " \n" "\n" "Copyright (C) 2003-2007 Warren Dukes \n" - "Copyright (C) 2008-2010 Max Kellermann \n" + "Copyright (C) 2008-2012 Max Kellermann \n" "This is free software; see the source for copying conditions. There is NO\n" "warranty; not even MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" "\n" -- cgit v1.2.3 From 8aa29d5a66e127b4b14ef439d77250051ccddea0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jun 2012 20:22:35 +0200 Subject: output_list: simplify audio_output_plugins_for_each() call --- src/output_list.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/output_list.c b/src/output_list.c index 8238f581b..bc5e7d749 100644 --- a/src/output_list.c +++ b/src/output_list.c @@ -99,8 +99,8 @@ audio_output_plugin_get(const char *name) const struct audio_output_plugin *plugin; audio_output_plugins_for_each(plugin, i) - if (strcmp(audio_output_plugins[i]->name, name) == 0) - return audio_output_plugins[i]; + if (strcmp(plugin->name, name) == 0) + return plugin; return NULL; } -- cgit v1.2.3 From ed915fed9253c23755fda6cc48ece61fa8f5d3b0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jun 2012 20:30:55 +0200 Subject: output_list: make the list truly "const" --- src/output_list.c | 2 +- src/output_list.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/output_list.c b/src/output_list.c index bc5e7d749..07f2fa555 100644 --- a/src/output_list.c +++ b/src/output_list.c @@ -39,7 +39,7 @@ extern const struct audio_output_plugin recorder_output_plugin; extern const struct audio_output_plugin winmm_output_plugin; extern const struct audio_output_plugin ffado_output_plugin; -const struct audio_output_plugin *audio_output_plugins[] = { +const struct audio_output_plugin *const audio_output_plugins[] = { #ifdef HAVE_SHOUT &shoutPlugin, #endif diff --git a/src/output_list.h b/src/output_list.h index d72bc224b..ee5102218 100644 --- a/src/output_list.h +++ b/src/output_list.h @@ -22,7 +22,7 @@ #include -extern const struct audio_output_plugin *audio_output_plugins[]; +extern const struct audio_output_plugin *const audio_output_plugins[]; const struct audio_output_plugin * audio_output_plugin_get(const char *name); -- cgit v1.2.3 From 992c2fa2d4f0b3fae9bd26144c14e6a4e0ce9a75 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jun 2012 20:29:47 +0200 Subject: output_list: declare variables inside _plugins_for_each() Don't require the caller to provide them. --- src/output_init.c | 5 +---- src/output_list.c | 10 ++-------- src/output_list.h | 6 ++++-- 3 files changed, 7 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/output_init.c b/src/output_init.c index 96f87f512..5bf8b93c0 100644 --- a/src/output_init.c +++ b/src/output_init.c @@ -49,12 +49,9 @@ static const struct audio_output_plugin * audio_output_detect(GError **error) { - const struct audio_output_plugin *plugin; - unsigned i; - g_warning("Attempt to detect audio output device"); - audio_output_plugins_for_each(plugin, i) { + audio_output_plugins_for_each(plugin) { if (plugin->test_default_device == NULL) continue; diff --git a/src/output_list.c b/src/output_list.c index 07f2fa555..bc7a6abd8 100644 --- a/src/output_list.c +++ b/src/output_list.c @@ -95,10 +95,7 @@ const struct audio_output_plugin *const audio_output_plugins[] = { const struct audio_output_plugin * audio_output_plugin_get(const char *name) { - unsigned int i; - const struct audio_output_plugin *plugin; - - audio_output_plugins_for_each(plugin, i) + audio_output_plugins_for_each(plugin) if (strcmp(plugin->name, name) == 0) return plugin; @@ -107,10 +104,7 @@ audio_output_plugin_get(const char *name) void audio_output_plugin_print_all_types(FILE * fp) { - unsigned i; - const struct audio_output_plugin *plugin; - - audio_output_plugins_for_each(plugin, i) + audio_output_plugins_for_each(plugin) fprintf(fp, "%s ", plugin->name); fprintf(fp, "\n"); diff --git a/src/output_list.h b/src/output_list.h index ee5102218..85497a6c6 100644 --- a/src/output_list.h +++ b/src/output_list.h @@ -29,7 +29,9 @@ audio_output_plugin_get(const char *name); void audio_output_plugin_print_all_types(FILE * fp); -#define audio_output_plugins_for_each(plugin, i) \ - for (i = 0; (plugin = audio_output_plugins[i]) != NULL; ++i) +#define audio_output_plugins_for_each(plugin) \ + for (const struct audio_output_plugin *plugin, \ + *const*output_plugin_iterator = &audio_output_plugins[0]; \ + (plugin = *output_plugin_iterator) != NULL; ++output_plugin_iterator) #endif -- cgit v1.2.3 From 90709a6de4dbfc25c86ec1bb9249836720dc07b8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jun 2012 20:36:53 +0200 Subject: encoder_list: make the list truly "const" --- src/encoder_list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/encoder_list.c b/src/encoder_list.c index f49ad48f7..dea72650c 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 *encoder_plugins[] = { +static const struct encoder_plugin *const encoder_plugins[] = { &null_encoder_plugin, #ifdef ENABLE_VORBIS_ENCODER &vorbis_encoder_plugin, -- cgit v1.2.3 From edbfa46cbc01bfbb1f7f1b624aaeae635408528c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jun 2012 20:39:53 +0200 Subject: encoder_list: add macro _for_each() --- src/encoder_list.c | 12 ++++++------ src/encoder_list.h | 8 ++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'src') 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. * -- cgit v1.2.3 From 48da345e79a0b690aa7d6d59ba8b50875988243b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jun 2012 20:52:04 +0200 Subject: cmdline: don't initalise archive plugins for --version Dump all archive plugins, even those that fail to initialise. --- src/archive_list.c | 2 -- src/cmdline.c | 1 - 2 files changed, 3 deletions(-) (limited to 'src') diff --git a/src/archive_list.c b/src/archive_list.c index 2656726b5..686498117 100644 --- a/src/archive_list.c +++ b/src/archive_list.c @@ -80,8 +80,6 @@ void archive_plugin_print_all_suffixes(FILE * fp) for (unsigned i = 0; archive_plugins[i] != NULL; ++i) { const struct archive_plugin *plugin = archive_plugins[i]; - if (!archive_plugins_enabled[i]) - continue; suffixes = plugin->suffixes; while (suffixes && *suffixes) { diff --git a/src/cmdline.c b/src/cmdline.c index 10f0a3572..4b44892f3 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -102,7 +102,6 @@ static void version(void) #ifdef ENABLE_ARCHIVE puts("\n" "Supported archives:\n"); - archive_plugin_init_all(); archive_plugin_print_all_suffixes(stdout); #endif -- cgit v1.2.3 From 9ebbdb9b0b288164ce956ba34bc0c38f94868110 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jun 2012 20:50:51 +0200 Subject: archive_list: add _for_each() macros --- src/archive_list.c | 42 +++++++++++++++++------------------------- src/archive_list.h | 8 ++++++++ 2 files changed, 25 insertions(+), 25 deletions(-) (limited to 'src') 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 #include -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 * -- cgit v1.2.3 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(-) (limited to 'src') 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 From d5b9be03938a5081d65adf71b15de0899f7ce103 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jun 2012 19:59:25 +0200 Subject: cmdline: change --version formatting --- src/cmdline.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/cmdline.c b/src/cmdline.c index a7e1d42fa..b2ed8d0db 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -83,29 +83,29 @@ static void version(void) "This is free software; see the source for copying conditions. There is NO\n" "warranty; not even MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" "\n" - "Supported decoders:\n"); + "* Decoders plugins:\n"); print_all_decoders(stdout); puts("\n" - "Supported outputs:\n"); + "Output plugins:\n"); audio_output_plugin_print_all_types(stdout); #ifdef ENABLE_ENCODER puts("\n" - "Supported encoders:\n"); + "Encoder plugins:\n"); encoder_plugin_print_all_types(stdout); #endif #ifdef ENABLE_ARCHIVE puts("\n" - "Supported archives:\n"); + "Archive plugins:\n"); archive_plugin_print_all_suffixes(stdout); #endif puts("\n" - "Supported protocols:\n"); + "Protocols:\n"); print_supported_uri_schemes_to_fp(stdout); exit(EXIT_SUCCESS); -- cgit v1.2.3 From 5665de5ee7282801da54de36f9b1212bc173dede Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jun 2012 22:12:06 +0200 Subject: playlist_list: add _for_each() macros --- src/playlist_list.c | 31 +++++++++++++------------------ src/playlist_list.h | 8 ++++++++ 2 files changed, 21 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/playlist_list.c b/src/playlist_list.c index 019654bfc..8dfd2823d 100644 --- a/src/playlist_list.c +++ b/src/playlist_list.c @@ -40,7 +40,7 @@ #include #include -static const struct playlist_plugin *const playlist_plugins[] = { +const struct playlist_plugin *const playlist_plugins[] = { &extm3u_playlist_plugin, &m3u_playlist_plugin, &xspf_playlist_plugin, @@ -62,6 +62,10 @@ static const struct playlist_plugin *const playlist_plugins[] = { /** which plugins have been initialized successfully? */ static bool playlist_plugins_enabled[G_N_ELEMENTS(playlist_plugins)]; +#define playlist_plugins_for_each_enabled(plugin) \ + playlist_plugins_for_each(plugin) \ + if (playlist_plugins_enabled[playlist_plugin_iterator - playlist_plugins]) + /** * Find the "playlist" configuration block for the specified plugin. * @@ -109,9 +113,8 @@ playlist_list_global_init(void) void playlist_list_global_finish(void) { - for (unsigned i = 0; playlist_plugins[i] != NULL; ++i) - if (playlist_plugins_enabled[i]) - playlist_plugin_finish(playlist_plugins[i]); + playlist_plugins_for_each_enabled(plugin) + playlist_plugin_finish(plugin); } static struct playlist_provider * @@ -200,11 +203,8 @@ playlist_list_open_stream_mime2(struct input_stream *is, const char *mime) assert(is != NULL); assert(mime != NULL); - for (unsigned i = 0; playlist_plugins[i] != NULL; ++i) { - const struct playlist_plugin *plugin = playlist_plugins[i]; - - if (playlist_plugins_enabled[i] && - plugin->open_stream != NULL && + playlist_plugins_for_each_enabled(plugin) { + if (plugin->open_stream != NULL && plugin->mime_types != NULL && string_array_contains(plugin->mime_types, mime)) { /* rewind the stream, so each plugin gets a @@ -248,11 +248,8 @@ playlist_list_open_stream_suffix(struct input_stream *is, const char *suffix) assert(is != NULL); assert(suffix != NULL); - for (unsigned i = 0; playlist_plugins[i] != NULL; ++i) { - const struct playlist_plugin *plugin = playlist_plugins[i]; - - if (playlist_plugins_enabled[i] && - plugin->open_stream != NULL && + playlist_plugins_for_each_enabled(plugin) { + if (plugin->open_stream != NULL && plugin->suffixes != NULL && string_array_contains(plugin->suffixes, suffix)) { /* rewind the stream, so each plugin gets a @@ -306,10 +303,8 @@ playlist_suffix_supported(const char *suffix) { assert(suffix != NULL); - for (unsigned i = 0; playlist_plugins[i] != NULL; ++i) { - const struct playlist_plugin *plugin = playlist_plugins[i]; - - if (playlist_plugins_enabled[i] && plugin->suffixes != NULL && + playlist_plugins_for_each_enabled(plugin) { + if (plugin->suffixes != NULL && string_array_contains(plugin->suffixes, suffix)) return true; } diff --git a/src/playlist_list.h b/src/playlist_list.h index 3710589a2..08e8cbd76 100644 --- a/src/playlist_list.h +++ b/src/playlist_list.h @@ -25,6 +25,14 @@ struct playlist_provider; struct input_stream; +extern const struct playlist_plugin *const playlist_plugins[]; + +#define playlist_plugins_for_each(plugin) \ + for (const struct playlist_plugin *plugin, \ + *const*playlist_plugin_iterator = &playlist_plugins[0]; \ + (plugin = *playlist_plugin_iterator) != NULL; \ + ++playlist_plugin_iterator) + /** * Initializes all playlist plugins. */ -- cgit v1.2.3 From 5b217420954ad1962b822faa1e2881570f803992 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jun 2012 19:59:03 +0200 Subject: cmdline: dump list of playlist plugins --- src/cmdline.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/cmdline.c b/src/cmdline.c index b2ed8d0db..b419d746c 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -25,6 +25,8 @@ #include "decoder_list.h" #include "decoder_plugin.h" #include "output_list.h" +#include "playlist_list.h" +#include "playlist_plugin.h" #include "ls.h" #include "mpd_error.h" #include "glib_compat.h" @@ -105,6 +107,11 @@ static void version(void) #endif puts("\n" + "Playlist plugins:"); + playlist_plugins_for_each(plugin) + printf(" %s", plugin->name); + + puts("\n\n" "Protocols:\n"); print_supported_uri_schemes_to_fp(stdout); -- cgit v1.2.3 From e60141b4dd726d78f3c33bb02e53d1c0f9e670a5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jun 2012 22:21:48 +0200 Subject: input_registry: add _for_each() macros --- src/input_init.c | 7 +++---- src/input_registry.h | 10 ++++++++++ src/input_stream.c | 6 +----- 3 files changed, 14 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/input_init.c b/src/input_init.c index 1438c3e52..de418845c 100644 --- a/src/input_init.c +++ b/src/input_init.c @@ -93,8 +93,7 @@ input_stream_global_init(GError **error_r) void input_stream_global_finish(void) { - for (unsigned i = 0; input_plugins[i] != NULL; ++i) - if (input_plugins_enabled[i] && - input_plugins[i]->finish != NULL) - input_plugins[i]->finish(); + input_plugins_for_each_enabled(plugin) + if (plugin->finish != NULL) + plugin->finish(); } diff --git a/src/input_registry.h b/src/input_registry.h index e85d6be8e..c57b8296c 100644 --- a/src/input_registry.h +++ b/src/input_registry.h @@ -32,4 +32,14 @@ extern const struct input_plugin *const input_plugins[]; extern bool input_plugins_enabled[]; +#define input_plugins_for_each(plugin) \ + for (const struct input_plugin *plugin, \ + *const*input_plugin_iterator = &input_plugins[0]; \ + (plugin = *input_plugin_iterator) != NULL; \ + ++input_plugin_iterator) + +#define input_plugins_for_each_enabled(plugin) \ + input_plugins_for_each(plugin) \ + if (input_plugins_enabled[input_plugin_iterator - input_plugins]) + #endif diff --git a/src/input_stream.c b/src/input_stream.c index e769adb92..311d05cfc 100644 --- a/src/input_stream.c +++ b/src/input_stream.c @@ -39,13 +39,9 @@ input_stream_open(const char *url, GError **error_r) assert(error_r == NULL || *error_r == NULL); - for (unsigned i = 0; input_plugins[i] != NULL; ++i) { - const struct input_plugin *plugin = input_plugins[i]; + input_plugins_for_each_enabled(plugin) { struct input_stream *is; - if (!input_plugins_enabled[i]) - continue; - is = plugin->open(url, &error); if (is != NULL) { assert(is->plugin != NULL); -- cgit v1.2.3 From eda7410f4c87e29e0c77950963a7b9ccf7069097 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jun 2012 22:24:42 +0200 Subject: cmdline: dump list of input plugins --- src/cmdline.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/cmdline.c b/src/cmdline.c index b419d746c..c93a34cc6 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -25,6 +25,8 @@ #include "decoder_list.h" #include "decoder_plugin.h" #include "output_list.h" +#include "input_registry.h" +#include "input_plugin.h" #include "playlist_list.h" #include "playlist_plugin.h" #include "ls.h" @@ -107,6 +109,11 @@ static void version(void) #endif puts("\n" + "Input plugins:"); + input_plugins_for_each(plugin) + printf(" %s", plugin->name); + + puts("\n\n" "Playlist plugins:"); playlist_plugins_for_each(plugin) printf(" %s", plugin->name); -- cgit v1.2.3 From ae70875f45c6d7f1bb0f703179035709d909978a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jun 2012 22:29:04 +0200 Subject: cmdline: consistent plugin listings --- src/archive_list.c | 13 ------------ src/archive_list.h | 4 ---- src/cmdline.c | 62 ++++++++++++++++++++++++++++++------------------------ src/encoder_list.c | 10 --------- src/encoder_list.h | 5 ----- src/ls.c | 4 ++-- src/output_list.c | 9 -------- src/output_list.h | 4 ---- 8 files changed, 36 insertions(+), 75 deletions(-) (limited to 'src') diff --git a/src/archive_list.c b/src/archive_list.c index 39eaf4d69..6c1079c1a 100644 --- a/src/archive_list.c +++ b/src/archive_list.c @@ -72,19 +72,6 @@ archive_plugin_from_name(const char *name) return NULL; } -void archive_plugin_print_all_suffixes(FILE * fp) -{ - archive_plugins_for_each(plugin) { - const char *const*suffixes = plugin->suffixes; - while (suffixes && *suffixes) { - fprintf(fp, "%s ", *suffixes); - suffixes++; - } - } - fprintf(fp, "\n"); - fflush(fp); -} - void archive_plugin_init_all(void) { for (unsigned i = 0; archive_plugins[i] != NULL; ++i) { diff --git a/src/archive_list.h b/src/archive_list.h index ec2ccc1e1..2c03b0680 100644 --- a/src/archive_list.h +++ b/src/archive_list.h @@ -20,8 +20,6 @@ #ifndef MPD_ARCHIVE_LIST_H #define MPD_ARCHIVE_LIST_H -#include - struct archive_plugin; extern const struct archive_plugin *const archive_plugins[]; @@ -40,8 +38,6 @@ archive_plugin_from_suffix(const char *suffix); const struct archive_plugin * archive_plugin_from_name(const char *name); -void archive_plugin_print_all_suffixes(FILE * fp); - /* this is where we "load" all the "plugins" ;-) */ void archive_plugin_init_all(void); diff --git a/src/cmdline.c b/src/cmdline.c index c93a34cc6..907b64c10 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -25,6 +25,7 @@ #include "decoder_list.h" #include "decoder_plugin.h" #include "output_list.h" +#include "output_plugin.h" #include "input_registry.h" #include "input_plugin.h" #include "playlist_list.h" @@ -35,10 +36,12 @@ #ifdef ENABLE_ENCODER #include "encoder_list.h" +#include "encoder_plugin.h" #endif #ifdef ENABLE_ARCHIVE #include "archive_list.h" +#include "archive_plugin.h" #endif #include @@ -59,24 +62,6 @@ cmdline_quark(void) return g_quark_from_static_string("cmdline"); } -static void -print_all_decoders(FILE *fp) -{ - decoder_plugins_for_each(plugin) { - const char *const*suffixes; - - fprintf(fp, "[%s]", plugin->name); - - for (suffixes = plugin->suffixes; - suffixes != NULL && *suffixes != NULL; - ++suffixes) { - fprintf(fp, " %s", *suffixes); - } - - fprintf(fp, "\n"); - } -} - G_GNUC_NORETURN static void version(void) { @@ -87,25 +72,46 @@ static void version(void) "This is free software; see the source for copying conditions. There is NO\n" "warranty; not even MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" "\n" - "* Decoders plugins:\n"); + "Decoders plugins:"); - print_all_decoders(stdout); + decoder_plugins_for_each(plugin) { + printf(" [%s]", plugin->name); + + const char *const*suffixes = plugin->suffixes; + if (suffixes != NULL) + for (; *suffixes != NULL; ++suffixes) + printf(" %s", *suffixes); + + puts(""); + } puts("\n" - "Output plugins:\n"); - audio_output_plugin_print_all_types(stdout); + "Output plugins:"); + audio_output_plugins_for_each(plugin) + printf(" %s", plugin->name); + puts(""); #ifdef ENABLE_ENCODER puts("\n" - "Encoder plugins:\n"); - encoder_plugin_print_all_types(stdout); + "Encoder plugins:"); + encoder_plugins_for_each(plugin) + printf(" %s", plugin->name); + puts(""); #endif - #ifdef ENABLE_ARCHIVE puts("\n" - "Archive plugins:\n"); - archive_plugin_print_all_suffixes(stdout); + "Archive plugins:"); + archive_plugins_for_each(plugin) { + printf(" [%s]", plugin->name); + + const char *const*suffixes = plugin->suffixes; + if (suffixes != NULL) + for (; *suffixes != NULL; ++suffixes) + printf(" %s", *suffixes); + + puts(""); + } #endif puts("\n" @@ -119,7 +125,7 @@ static void version(void) printf(" %s", plugin->name); puts("\n\n" - "Protocols:\n"); + "Protocols:"); print_supported_uri_schemes_to_fp(stdout); exit(EXIT_SUCCESS); diff --git a/src/encoder_list.c b/src/encoder_list.c index da1bec5ef..d7190f6dc 100644 --- a/src/encoder_list.c +++ b/src/encoder_list.c @@ -59,13 +59,3 @@ encoder_plugin_get(const char *name) return NULL; } - -void -encoder_plugin_print_all_types(FILE * fp) -{ - 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 4fe87e16c..4f77ce2c9 100644 --- a/src/encoder_list.h +++ b/src/encoder_list.h @@ -20,8 +20,6 @@ #ifndef MPD_ENCODER_LIST_H #define MPD_ENCODER_LIST_H -#include - struct encoder_plugin; extern const struct encoder_plugin *const encoder_plugins[]; @@ -42,7 +40,4 @@ extern const struct encoder_plugin *const encoder_plugins[]; const struct encoder_plugin * encoder_plugin_get(const char *name); -void -encoder_plugin_print_all_types(FILE * fp); - #endif diff --git a/src/ls.c b/src/ls.c index c30765c62..0346dabfb 100644 --- a/src/ls.c +++ b/src/ls.c @@ -57,10 +57,10 @@ void print_supported_uri_schemes_to_fp(FILE *fp) const char **prefixes = remoteUrlPrefixes; #ifdef HAVE_UN - fprintf(fp, "file:// "); + fprintf(fp, " file://"); #endif while (*prefixes) { - fprintf(fp, "%s ", *prefixes); + fprintf(fp, " %s", *prefixes); prefixes++; } fprintf(fp,"\n"); diff --git a/src/output_list.c b/src/output_list.c index bc7a6abd8..aac05c212 100644 --- a/src/output_list.c +++ b/src/output_list.c @@ -101,12 +101,3 @@ audio_output_plugin_get(const char *name) return NULL; } - -void audio_output_plugin_print_all_types(FILE * fp) -{ - audio_output_plugins_for_each(plugin) - fprintf(fp, "%s ", plugin->name); - - fprintf(fp, "\n"); - fflush(fp); -} diff --git a/src/output_list.h b/src/output_list.h index 85497a6c6..855b90edf 100644 --- a/src/output_list.h +++ b/src/output_list.h @@ -20,15 +20,11 @@ #ifndef MPD_OUTPUT_LIST_H #define MPD_OUTPUT_LIST_H -#include - extern const struct audio_output_plugin *const audio_output_plugins[]; const struct audio_output_plugin * audio_output_plugin_get(const char *name); -void audio_output_plugin_print_all_types(FILE * fp); - #define audio_output_plugins_for_each(plugin) \ for (const struct audio_output_plugin *plugin, \ *const*output_plugin_iterator = &audio_output_plugins[0]; \ -- cgit v1.2.3