summaryrefslogtreecommitdiff
path: root/src/libpiano/piano.c
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2013-08-04 18:53:43 +0200
committerLars-Dominik Braun <lars@6xq.net>2013-08-07 17:37:33 +0200
commitee2e73cd7b5a1de68c8316e916c4ef3a88302bed (patch)
treee952d75d075598123d5ecbe92f14838ce75f6db5 /src/libpiano/piano.c
parent36ea2f13f87b9310219790c3cee498201d54f8e0 (diff)
downloadpianobar-ee2e73cd7b5a1de68c8316e916c4ef3a88302bed.tar.gz
pianobar-ee2e73cd7b5a1de68c8316e916c4ef3a88302bed.tar.bz2
pianobar-ee2e73cd7b5a1de68c8316e916c4ef3a88302bed.zip
piano: Generic linked lists
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.
Diffstat (limited to 'src/libpiano/piano.c')
-rw-r--r--src/libpiano/piano.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/libpiano/piano.c b/src/libpiano/piano.c
index 9020a6a..b519f49 100644
--- a/src/libpiano/piano.c
+++ b/src/libpiano/piano.c
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2008-2012
+Copyright (c) 2008-2013
Lars-Dominik Braun <lars@6xq.net>
Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -80,7 +80,7 @@ static void PianoDestroyArtists (PianoArtist_t *artists) {
free (curArtist->musicId);
free (curArtist->seedId);
lastArtist = curArtist;
- curArtist = curArtist->next;
+ curArtist = (PianoArtist_t *) curArtist->head.next;
free (lastArtist);
}
}
@@ -113,7 +113,7 @@ static void PianoDestroyStations (PianoStation_t *stations) {
curStation = stations;
while (curStation != NULL) {
lastStation = curStation;
- curStation = curStation->next;
+ curStation = (PianoStation_t *) curStation->head.next;
PianoDestroyStation (lastStation);
free (lastStation);
}
@@ -141,7 +141,7 @@ void PianoDestroyPlaylist (PianoSong_t *playlist) {
free (curSong->detailUrl);
free (curSong->trackToken);
lastSong = curSong;
- curSong = curSong->next;
+ curSong = (PianoSong_t *) curSong->head.next;
free (lastSong);
}
}
@@ -163,7 +163,7 @@ static void PianoDestroyGenres (PianoGenre_t *genres) {
free (curGenre->name);
free (curGenre->musicId);
lastGenre = curGenre;
- curGenre = curGenre->next;
+ curGenre = (PianoGenre_t *) curGenre->head.next;
free (lastGenre);
}
}
@@ -201,7 +201,7 @@ void PianoDestroy (PianoHandle_t *ph) {
PianoDestroyGenres (curGenreCat->genres);
free (curGenreCat->name);
lastGenreCat = curGenreCat;
- curGenreCat = curGenreCat->next;
+ curGenreCat = (PianoGenreCategory_t *) curGenreCat->head.next;
free (lastGenreCat);
}
memset (ph, 0, sizeof (*ph));
@@ -221,14 +221,17 @@ void PianoDestroyRequest (PianoRequest_t *req) {
* @param search for this
* @return the first station structure matching the given id
*/
-PianoStation_t *PianoFindStationById (PianoStation_t *stations,
- const char *searchStation) {
- while (stations != NULL) {
- if (strcmp (stations->id, searchStation) == 0) {
- return stations;
+PianoStation_t *PianoFindStationById (PianoStation_t * const stations,
+ const char * const searchStation) {
+ assert (searchStation != NULL);
+
+ PianoStation_t *currStation = stations;
+ PianoListForeachP (currStation) {
+ if (strcmp (currStation->id, searchStation) == 0) {
+ return currStation;
}
- stations = stations->next;
}
+
return NULL;
}