From ee2e73cd7b5a1de68c8316e916c4ef3a88302bed Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sun, 4 Aug 2013 18:53:43 +0200 Subject: piano: Generic linked lists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduces generic linked list structure and functions (like append, delete, …). Removes a lot of copy&pasted code and improves code readability/reusability. Heads up: This change breaks libpiano’s ABI. --- src/ui_act.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) (limited to 'src/ui_act.c') diff --git a/src/ui_act.c b/src/ui_act.c index 270c1f5..8cf6c2b 100644 --- a/src/ui_act.c +++ b/src/ui_act.c @@ -232,7 +232,8 @@ BarUiActCallback(BarUiActDeleteStation) { if (BarUiActDefaultPianoCall (PIANO_REQUEST_DELETE_STATION, selStation) && selStation == app->curStation) { BarUiDoSkipSong (&app->player); - PianoDestroyPlaylist (app->playlist->next); + PianoDestroyPlaylist (PianoListNextP (app->playlist)); + app->playlist->head.next = NULL; BarUiHistoryPrepend (app, app->playlist); app->playlist = NULL; app->curStation = NULL; @@ -283,10 +284,9 @@ BarUiActCallback(BarUiActStationFromGenre) { /* print all available categories */ curCat = app->ph.genreStations; i = 0; - while (curCat != NULL) { + PianoListForeachP (curCat) { BarUiMsg (&app->settings, MSG_LIST, "%2i) %s\n", i, curCat->name); i++; - curCat = curCat->next; } do { @@ -295,20 +295,15 @@ BarUiActCallback(BarUiActStationFromGenre) { if (BarReadlineInt (&i, &app->input) == 0) { return; } - curCat = app->ph.genreStations; - while (curCat != NULL && i > 0) { - curCat = curCat->next; - i--; - } + curCat = PianoListGetP (app->ph.genreStations, i); } while (curCat == NULL); /* print all available stations */ - curGenre = curCat->genres; i = 0; - while (curGenre != NULL) { + curGenre = curCat->genres; + PianoListForeachP (curGenre) { BarUiMsg (&app->settings, MSG_LIST, "%2i) %s\n", i, curGenre->name); i++; - curGenre = curGenre->next; } do { @@ -316,11 +311,7 @@ BarUiActCallback(BarUiActStationFromGenre) { if (BarReadlineInt (&i, &app->input) == 0) { return; } - curGenre = curCat->genres; - while (curGenre != NULL && i > 0) { - curGenre = curGenre->next; - i--; - } + curGenre = PianoListGetP (curCat->genres, i); } while (curGenre == NULL); /* create station */ @@ -477,7 +468,8 @@ BarUiActCallback(BarUiActSelectStation) { BarUiPrintStation (&app->settings, app->curStation); BarUiDoSkipSong (&app->player); if (app->playlist != NULL) { - PianoDestroyPlaylist (app->playlist->next); + PianoDestroyPlaylist (PianoListNextP (app->playlist)); + app->playlist->head.next = NULL; BarUiHistoryPrepend (app, app->playlist); app->playlist = NULL; } @@ -505,7 +497,7 @@ BarUiActCallback(BarUiActTempBanSong) { BarUiActCallback(BarUiActPrintUpcoming) { assert (selSong != NULL); - PianoSong_t *nextSong = selSong->next; + PianoSong_t *nextSong = PianoListNextP (selSong); if (nextSong != NULL) { BarUiListSongs (&app->settings, nextSong, NULL); } else { @@ -527,27 +519,24 @@ static void BarUiActQuickmixCallback (BarApp_t *app, char *buf) { switch (*buf) { case 't': /* toggle */ - while (curStation != NULL) { + PianoListForeachP (curStation) { curStation->useQuickMix = !curStation->useQuickMix; - curStation = curStation->next; } *buf = '\0'; break; case 'a': /* enable all */ - while (curStation != NULL) { + PianoListForeachP (curStation) { curStation->useQuickMix = true; - curStation = curStation->next; } *buf = '\0'; break; case 'n': /* enable none */ - while (curStation != NULL) { + PianoListForeachP (curStation) { curStation->useQuickMix = false; - curStation = curStation->next; } *buf = '\0'; break; -- cgit v1.2.3