From 4729d10bb212c9dbcbdd6ac921e4fc824a5f00ec Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 24 Sep 2009 10:14:05 +0200 Subject: decoder/sidplay: moved code to sidplay_load_songlength_db() --- src/decoder/sidplay_plugin.cxx | 65 +++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 29 deletions(-) (limited to 'src/decoder') diff --git a/src/decoder/sidplay_plugin.cxx b/src/decoder/sidplay_plugin.cxx index 55974b428..b182a732d 100644 --- a/src/decoder/sidplay_plugin.cxx +++ b/src/decoder/sidplay_plugin.cxx @@ -41,41 +41,48 @@ static GKeyFile *songlength_database; static bool all_files_are_containers; static unsigned default_songlength; +static GKeyFile * +sidplay_load_songlength_db(const char *path) +{ + GError *error = NULL; + gchar *data; + gsize size; + + if (!g_file_get_contents(path, &data, &size, &error)) { + g_warning("unable to read songlengths file %s: %s", + path, error->message); + g_error_free(error); + return NULL; + } + + /* replace any ; comment characters with # */ + for (gsize i = 0; i < size; i++) + if (data[i] == ';') + data[i] = '#'; + + GKeyFile *db = g_key_file_new(); + if (!g_key_file_load_from_data(db, data, size, + G_KEY_FILE_NONE, &error)) { + g_warning("unable to parse songlengths file %s: %s", + path, error->message); + g_error_free(error); + g_key_file_free(db); + return NULL; + } + + g_key_file_set_list_separator(db, ' '); + g_free(data); + return db; +} + static bool sidplay_init(const struct config_param *param) { - GError *err=NULL; - gchar *songlen_data; - gsize songlen_data_size; - /* read the songlengths database file */ songlength_file=config_get_block_string(param, "songlength_database", NULL); - if(songlength_file) { - if (g_file_get_contents(songlength_file, &songlen_data, - &songlen_data_size, &err)) { - /* replace any ; comment characters with # */ - for(int i=0; imessage); - g_error_free(err); - g_key_file_free(songlength_database); - songlength_database=NULL; - } - g_key_file_set_list_separator(songlength_database, ' '); - g_free(songlen_data); - } else { - g_warning("unable to read songlengths file %s: %s", - songlength_file, err->message); - g_error_free(err); - } - } + if (songlength_file != NULL) + songlength_database = sidplay_load_songlength_db(songlength_file); default_songlength=config_get_block_unsigned(param, "default_songlength", 0); -- cgit v1.2.3