From b8443efbe313b7b32e7e58555139fd6c03a40957 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 29 Sep 2009 22:14:20 +0200 Subject: [PATCH] playlist: make functions const And return const mpd_song objects. --- src/main.c | 2 +- src/mpdclient.c | 2 +- src/mpdclient.h | 2 +- src/playlist.c | 8 ++++---- src/playlist.h | 8 ++++---- src/screen_lyrics.c | 22 +++++++++------------- 6 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/main.c b/src/main.c index 10706a5..fb5de59 100644 --- a/src/main.c +++ b/src/main.c @@ -85,7 +85,7 @@ update_xterm_title(void) static char title[BUFSIZE]; char tmp[BUFSIZE]; struct mpd_status *status = NULL; - struct mpd_song *song = NULL; + const struct mpd_song *song = NULL; if (mpd) { status = mpd->status; diff --git a/src/mpdclient.c b/src/mpdclient.c index ac7fce9..cbc6a91 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -269,7 +269,7 @@ mpdclient_update(struct mpdclient *c) gint mpdclient_cmd_play(struct mpdclient *c, gint idx) { - struct mpd_song *song = playlist_get_song(&c->playlist, idx); + const struct mpd_song *song = playlist_get_song(&c->playlist, idx); if (MPD_ERROR(c)) return -1; diff --git a/src/mpdclient.h b/src/mpdclient.h index 52fcdb4..e2b81c8 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -18,7 +18,7 @@ struct mpdclient { struct mpd_connection *connection; struct mpd_status *status; - struct mpd_song *song; + const struct mpd_song *song; int volume; unsigned updatingdb; diff --git a/src/playlist.c b/src/playlist.c index 562fde6..5fced75 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -60,8 +60,8 @@ mpdclient_playlist_free(struct mpdclient_playlist *playlist) return 0; } -struct mpd_song * -playlist_get_song(struct mpdclient_playlist *playlist, gint idx) +const struct mpd_song * +playlist_get_song(const struct mpdclient_playlist *playlist, gint idx) { if (idx < 0 || (guint)idx >= playlist_length(playlist)) return NULL; @@ -69,8 +69,8 @@ playlist_get_song(struct mpdclient_playlist *playlist, gint idx) return playlist_get(playlist, idx); } -struct mpd_song * -playlist_lookup_song(struct mpdclient_playlist *playlist, unsigned id) +const struct mpd_song * +playlist_lookup_song(const struct mpdclient_playlist *playlist, unsigned id) { for (guint i = 0; i < playlist_length(playlist); ++i) { struct mpd_song *song = playlist_get(playlist, i); diff --git a/src/playlist.h b/src/playlist.h index 580b1c9..cee9100 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -119,11 +119,11 @@ playlist_swap(struct mpdclient_playlist *playlist, guint idx1, guint idx2) g_ptr_array_index(playlist->list, idx2) = song1; } -struct mpd_song * -playlist_lookup_song(struct mpdclient_playlist *playlist, unsigned id); +const struct mpd_song * +playlist_lookup_song(const struct mpdclient_playlist *playlist, unsigned id); -struct mpd_song * -playlist_get_song(struct mpdclient_playlist *playlist, gint index); +const struct mpd_song * +playlist_get_song(const struct mpdclient_playlist *playlist, gint index); gint playlist_get_index(const struct mpdclient_playlist *playlist, diff --git a/src/screen_lyrics.c b/src/screen_lyrics.c index f9fdb81..abf1055 100644 --- a/src/screen_lyrics.c +++ b/src/screen_lyrics.c @@ -202,16 +202,16 @@ lyrics_exit(void) static void lyrics_open(struct mpdclient *c) { - if (next_song == NULL) - next_song = c->song; + const struct mpd_song *next_song_c = + next_song != NULL ? next_song : c->song; - if (next_song != NULL && + if (next_song_c != NULL && (current.song == NULL || - strcmp(mpd_song_get_uri(next_song), + strcmp(mpd_song_get_uri(next_song_c), mpd_song_get_uri(current.song)) != 0)) - screen_lyrics_load(next_song); + screen_lyrics_load(next_song_c); - if (next_song != c->song) + if (next_song != NULL) mpd_song_free(next_song); next_song = NULL; } @@ -222,15 +222,11 @@ lyrics_update(struct mpdclient *c) if (!follow) return; - next_song = c->song; - - if (next_song != NULL && + if (c->song != NULL && (current.song == NULL || - strcmp(mpd_song_get_uri(next_song), + strcmp(mpd_song_get_uri(c->song), mpd_song_get_uri(current.song)) != 0)) - screen_lyrics_load(next_song); - - next_song = NULL; + screen_lyrics_load(c->song); } static const char * -- 2.30.2