From e12ebb484bf369ea425e93521d99cc6813996e4e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 18 Nov 2008 21:51:28 +0100 Subject: [PATCH] filelist: filelist_find_song() returns position instead of pointer Making the function return the index makes it more flexible: those who want the pointer can use filelist_get(), and the others may use the index for other purposes. --- src/filelist.c | 6 +++--- src/filelist.h | 2 +- src/screen_browser.c | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/filelist.c b/src/filelist.c index 415eec4..2e07863 100644 --- a/src/filelist.c +++ b/src/filelist.c @@ -118,7 +118,7 @@ filelist_sort(struct filelist *filelist, GCompareFunc compare_func) compare_func); } -struct filelist_entry * +int filelist_find_song(struct filelist *fl, const struct mpd_song *song) { guint i; @@ -133,11 +133,11 @@ filelist_find_song(struct filelist *fl, const struct mpd_song *song) struct mpd_song *song2 = entity->info.song; if (strcmp(song->file, song2->file) == 0) - return entry; + return i; } } - return NULL; + return -1; } int diff --git a/src/filelist.h b/src/filelist.h index d7d4dff..bc467fb 100644 --- a/src/filelist.h +++ b/src/filelist.h @@ -73,7 +73,7 @@ filelist_move(struct filelist *filelist, struct filelist *from); void filelist_sort(struct filelist *filelist, GCompareFunc compare_func); -struct filelist_entry * +int filelist_find_song(struct filelist *flist, const struct mpd_song *song); int diff --git a/src/screen_browser.c b/src/screen_browser.c index b5ce641..6a5bbd2 100644 --- a/src/screen_browser.c +++ b/src/screen_browser.c @@ -56,11 +56,13 @@ clear_highlights(mpdclient_filelist_t *fl) static void set_highlight(mpdclient_filelist_t *fl, mpd_Song *song, int highlight) { - struct filelist_entry *entry = filelist_find_song(fl, song); + int i = filelist_find_song(fl, song); + struct filelist_entry *entry; - if (entry == NULL) + if (i < 0) return; + entry = filelist_get(fl, i); if (highlight) entry->flags |= HIGHLIGHT; else -- 2.30.2