From: Andre Noll Date: Sun, 23 Sep 2007 15:56:39 +0000 (+0200) Subject: playlist.c: Cleanups. X-Git-Tag: v0.3.0~373 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=782375e0897199259d6666c4c2ec7f963210a953;p=paraslash.git playlist.c: Cleanups. Avoid using the global playlist variable where possible. Change the name of the global static playlist struct to current_playlist. --- diff --git a/playlist.c b/playlist.c index 6f952e65..272f25ac 100644 --- a/playlist.c +++ b/playlist.c @@ -13,7 +13,7 @@ struct playlist_info { /** The number of entries currently in the playlist. */ unsigned length; }; -static struct playlist_info playlist; +static struct playlist_info current_playlist; /** * Re-insert an audio file into the tree of admissible files. @@ -28,10 +28,10 @@ int playlist_update_audio_file(struct osl_row *aft_row) return score_update(aft_row, 0); } -static int add_playlist_entry(char *line, void *private_data) +static int add_playlist_entry(char *line, void *data) { + struct playlist_info *playlist = data; struct osl_row *aft_row; - struct playlist_info *pli = private_data; int ret = aft_get_row_of_path(line, &aft_row); if (ret < 0) { @@ -39,16 +39,16 @@ static int add_playlist_entry(char *line, void *private_data) line); return 1; } - ret = score_add(aft_row, -pli->length); + ret = score_add(aft_row, -playlist->length); if (ret < 0) { PARA_ERROR_LOG("failed to add %s: %d\n", line, ret); return ret; } - pli->length++; + playlist->length++; return 1; } -static int load_playlist(struct osl_row *row) +static int load_playlist(struct osl_row *row, struct playlist_info *playlist) { struct osl_object obj; int ret; @@ -56,31 +56,32 @@ static int load_playlist(struct osl_row *row) ret = osl_get_object(playlists_table, row, BLOBCOL_NAME, &obj); if (ret < 0) return ret; - playlist.name = para_strdup(obj.data); - playlist.length = 0; + playlist->name = para_strdup(obj.data); + playlist->length = 0; ret = osl_open_disk_object(playlists_table, row, BLOBCOL_DEF, &obj); if (ret < 0) goto err; ret = for_each_line_ro(obj.data, obj.size, add_playlist_entry, - &playlist); + playlist); osl_close_disk_object(&obj); if (ret < 0) goto err; ret = -E_PLAYLIST_EMPTY; - if (!playlist.length) + if (!playlist->length) goto err; - PARA_NOTICE_LOG("loaded playlist %s (%u files)\n", playlist.name, - playlist.length); + PARA_NOTICE_LOG("loaded playlist %s (%u files)\n", playlist->name, + playlist->length); return 1; err: - free(playlist.name); + free(playlist->name); return ret; } /* returns -E_PLAYLIST_LOADED on _success_ to terminate the loop */ -static int playlist_loop(struct osl_row *row, __a_unused void *private_data) +static int playlist_loop(struct osl_row *row, void *data) { - int ret = load_playlist(row); + struct playlist_info *playlist = data; + int ret = load_playlist(row, playlist); if (ret < 0) { if (ret != -E_DUMMY_ROW) PARA_NOTICE_LOG("unable to load playlist, trying next\n"); @@ -89,9 +90,9 @@ static int playlist_loop(struct osl_row *row, __a_unused void *private_data) return -E_PLAYLIST_LOADED; } -static int load_first_available_playlist(void) +static int load_first_available_playlist(struct playlist_info *playlist) { - int ret = osl_rbtree_loop(playlists_table, BLOBCOL_NAME, NULL, + int ret = osl_rbtree_loop(playlists_table, BLOBCOL_NAME, playlist, playlist_loop); if (ret == -E_PLAYLIST_LOADED) /* success */ return 1; @@ -108,8 +109,8 @@ static int load_first_available_playlist(void) */ void playlist_close(void) { - free(playlist.name); - playlist.name = NULL; + free(current_playlist.name); + current_playlist.name = NULL; } /** @@ -131,7 +132,7 @@ int playlist_open(char *name) struct osl_row *row; if (!name) - return load_first_available_playlist(); + return load_first_available_playlist(¤t_playlist); obj.data = name; obj.size = strlen(obj.data); ret = osl_get_row(playlists_table, BLOBCOL_NAME, &obj, &row); @@ -139,5 +140,5 @@ int playlist_open(char *name) PARA_NOTICE_LOG("failed to load playlist %s\n", name); return ret; } - return load_playlist(row); + return load_playlist(row, ¤t_playlist); }