diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dbUtils.c | 103 | ||||
-rw-r--r-- | src/directory.c | 23 | ||||
-rw-r--r-- | src/directory.h | 4 | ||||
-rw-r--r-- | src/tagTracker.c | 2 |
4 files changed, 81 insertions, 51 deletions
diff --git a/src/dbUtils.c b/src/dbUtils.c index c330f2ce2..efce0f4aa 100644 --- a/src/dbUtils.c +++ b/src/dbUtils.c @@ -45,7 +45,7 @@ typedef struct _SearchStats { unsigned long playTime; } SearchStats; -static int countSongsInDirectory(mpd_unused int fd, Directory * directory, +static int countSongsInDirectory(Directory * directory, void *data) { int *count = (int *)data; @@ -55,24 +55,32 @@ static int countSongsInDirectory(mpd_unused int fd, Directory * directory, return 0; } -static int printDirectoryInDirectory(int fd, Directory * directory, - mpd_unused void *data) +static int printDirectoryInDirectory(Directory * directory, void *data) { + int fd = (int)(size_t)data; if (directory->path) { fdprintf(fd, "directory: %s\n", getDirectoryPath(directory)); } return 0; } -static int printSongInDirectory(int fd, Song * song, mpd_unused void *data) +static int printSongInDirectory(Song * song, mpd_unused void *data) { + int fd = (int)(size_t)data; printSongUrl(fd, song); return 0; } -static int searchInDirectory(int fd, Song * song, void *data) +struct search_data { + int fd; + LocateTagItemArray array; +}; + +static int searchInDirectory(Song * song, void *_data) { - LocateTagItemArray *array = data; + struct search_data *data = _data; + int fd = data->fd; + LocateTagItemArray *array = &data->array; if (strstrSearchTags(song, array->numItems, array->items)) printSongInfo(fd, song); @@ -87,17 +95,18 @@ int searchForSongsIn(int fd, const char *name, int numItems, int i; char **originalNeedles = xmalloc(numItems * sizeof(char *)); - LocateTagItemArray array; + struct search_data data; for (i = 0; i < numItems; i++) { originalNeedles[i] = items[i].needle; items[i].needle = strDupToUpper(originalNeedles[i]); } - array.numItems = numItems; - array.items = items; + data.fd = fd; + data.array.numItems = numItems; + data.array.items = items; - ret = traverseAllIn(fd, name, searchInDirectory, NULL, &array); + ret = traverseAllIn(fd, name, searchInDirectory, NULL, &data); for (i = 0; i < numItems; i++) { free(items[i].needle); @@ -109,9 +118,11 @@ int searchForSongsIn(int fd, const char *name, int numItems, return ret; } -static int findInDirectory(int fd, Song * song, void *data) +static int findInDirectory(Song * song, void *_data) { - LocateTagItemArray *array = data; + struct search_data *data = _data; + int fd = data->fd; + LocateTagItemArray *array = &data->array; if (tagItemsFoundAndMatches(song, array->numItems, array->items)) printSongInfo(fd, song); @@ -121,12 +132,13 @@ static int findInDirectory(int fd, Song * song, void *data) int findSongsIn(int fd, const char *name, int numItems, LocateTagItem * items) { - LocateTagItemArray array; + struct search_data data; - array.numItems = numItems; - array.items = items; + data.fd = fd; + data.array.numItems = numItems; + data.array.items = items; - return traverseAllIn(fd, name, findInDirectory, NULL, (void *)&array); + return traverseAllIn(fd, name, findInDirectory, NULL, &data); } static void printSearchStats(int fd, SearchStats *stats) @@ -135,7 +147,7 @@ static void printSearchStats(int fd, SearchStats *stats) fdprintf(fd, "playtime: %li\n", stats->playTime); } -static int searchStatsInDirectory(mpd_unused int fd, Song * song, void *data) +static int searchStatsInDirectory(Song * song, void *data) { SearchStats *stats = data; @@ -170,19 +182,25 @@ int searchStatsForSongsIn(int fd, const char *name, int numItems, int printAllIn(int fd, const char *name) { return traverseAllIn(fd, name, printSongInDirectory, - printDirectoryInDirectory, NULL); + printDirectoryInDirectory, (void*)(size_t)fd); } -static int directoryAddSongToPlaylist(mpd_unused int fd, Song * song, - mpd_unused void *data) +static int directoryAddSongToPlaylist(Song * song, mpd_unused void *data) { return addSongToPlaylist(song, NULL); } -static int directoryAddSongToStoredPlaylist(mpd_unused int fd, Song *song, - void *data) +struct add_data { + const char *path; +}; + +static int directoryAddSongToStoredPlaylist(Song *song, void *_data) { - return appendSongToStoredPlaylistByPath((char *)data, song); + struct add_data *data = _data; + + if (appendSongToStoredPlaylistByPath(data->path, song) != 0) + return -1; + return 0; } int addAllIn(int fd, const char *name) @@ -192,16 +210,22 @@ int addAllIn(int fd, const char *name) int addAllInToStoredPlaylist(int fd, const char *name, const char *utf8file) { + struct add_data data = { + .path = utf8file, + }; + return traverseAllIn(fd, name, directoryAddSongToStoredPlaylist, NULL, - (void *)utf8file); + &data); } -static int directoryPrintSongInfo(int fd, Song * song, mpd_unused void *data) +static int directoryPrintSongInfo(Song * song, void *data) { + int fd = (int)(size_t)data; + return printSongInfo(fd, song); } -static int sumSongTime(mpd_unused int fd, Song * song, void *data) +static int sumSongTime(Song * song, void *data) { unsigned long *sum_time = (unsigned long *)data; @@ -214,7 +238,7 @@ static int sumSongTime(mpd_unused int fd, Song * song, void *data) int printInfoForAllIn(int fd, const char *name) { return traverseAllIn(fd, name, directoryPrintSongInfo, - printDirectoryInDirectory, NULL); + printDirectoryInDirectory, (void*)(size_t)fd); } int countSongsIn(int fd, const char *name) @@ -274,13 +298,19 @@ static void visitTag(int fd, Song * song, enum tag_type tagType) } } -static int listUniqueTagsInDirectory(int fd, Song * song, void *data) +struct list_tags_data { + int fd; + ListCommandItem *item; +}; + +static int listUniqueTagsInDirectory(Song * song, void *_data) { - ListCommandItem *item = data; + struct list_tags_data *data = _data; + ListCommandItem *item = data->item; if (tagItemsFoundAndMatches(song, item->numConditionals, item->conditionals)) { - visitTag(fd, song, item->tagType); + visitTag(data->fd, song, item->tagType); } return 0; @@ -292,13 +322,17 @@ int listAllUniqueTags(int fd, int type, int numConditionals, int ret; ListCommandItem *item = newListCommandItem(type, numConditionals, conditionals); + struct list_tags_data data = { + .fd = fd, + .item = item, + }; if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) { resetVisitedFlagsInTagTracker(type); } ret = traverseAllIn(fd, NULL, listUniqueTagsInDirectory, NULL, - (void *)item); + &data); if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) { printVisitedInTagTracker(fd, type); @@ -309,9 +343,7 @@ int listAllUniqueTags(int fd, int type, int numConditionals, return ret; } -static int sumSavedFilenameMemoryInDirectory(mpd_unused int fd, - Directory * dir, - void *data) +static int sumSavedFilenameMemoryInDirectory(Directory * dir, void *data) { int *sum = data; @@ -324,8 +356,7 @@ static int sumSavedFilenameMemoryInDirectory(mpd_unused int fd, return 0; } -static int sumSavedFilenameMemoryInSong(mpd_unused int fd, Song * song, - void *data) +static int sumSavedFilenameMemoryInSong(Song * song, void *data) { int *sum = data; diff --git a/src/directory.c b/src/directory.c index 32db02a9b..48d3249ce 100644 --- a/src/directory.c +++ b/src/directory.c @@ -1180,11 +1180,10 @@ void updateMp3Directory(void) return; } -static int traverseAllInSubDirectory(int fd, Directory * directory, - int (*forEachSong) (int, Song *, - void *), - int (*forEachDir) (int, Directory *, - void *), void *data) +static int traverseAllInSubDirectory(Directory * directory, + int (*forEachSong) (Song *, void *), + int (*forEachDir) (Directory *, void *), + void *data) { ListNode *node = directory->songs->firstNode; Song *song; @@ -1192,7 +1191,7 @@ static int traverseAllInSubDirectory(int fd, Directory * directory, int errFlag = 0; if (forEachDir) { - errFlag = forEachDir(fd, directory, data); + errFlag = forEachDir(directory, data); if (errFlag) return errFlag; } @@ -1200,7 +1199,7 @@ static int traverseAllInSubDirectory(int fd, Directory * directory, if (forEachSong) { while (node != NULL && !errFlag) { song = (Song *) node->data; - errFlag = forEachSong(fd, song, data); + errFlag = forEachSong(song, data); node = node->nextNode; } if (errFlag) @@ -1211,7 +1210,7 @@ static int traverseAllInSubDirectory(int fd, Directory * directory, while (node != NULL && !errFlag) { dir = (Directory *) node->data; - errFlag = traverseAllInSubDirectory(fd, dir, forEachSong, + errFlag = traverseAllInSubDirectory(dir, forEachSong, forEachDir, data); node = node->nextNode; } @@ -1220,22 +1219,22 @@ static int traverseAllInSubDirectory(int fd, Directory * directory, } int traverseAllIn(int fd, const char *name, - int (*forEachSong) (int, Song *, void *), - int (*forEachDir) (int, Directory *, void *), void *data) + int (*forEachSong) (Song *, void *), + int (*forEachDir) (Directory *, void *), void *data) { Directory *directory; if ((directory = getDirectory(name)) == NULL) { Song *song; if ((song = getSongFromDB(name)) && forEachSong) { - return forEachSong(fd, song, data); + return forEachSong(song, data); } commandError(fd, ACK_ERROR_NO_EXIST, "directory or file not found"); return -1; } - return traverseAllInSubDirectory(fd, directory, forEachSong, forEachDir, + return traverseAllInSubDirectory(directory, forEachSong, forEachDir, data); } diff --git a/src/directory.h b/src/directory.h index 00b902510..02a6b22d4 100644 --- a/src/directory.h +++ b/src/directory.h @@ -65,8 +65,8 @@ Song *getSongFromDB(const char *file); time_t getDbModTime(void); int traverseAllIn(int fd, const char *name, - int (*forEachSong) (int, Song *, void *), - int (*forEachDir) (int, Directory *, void *), void *data); + int (*forEachSong) (Song *, void *), + int (*forEachDir) (Directory *, void *), void *data); #define getDirectoryPath(dir) ((dir && dir->path) ? dir->path : "") diff --git a/src/tagTracker.c b/src/tagTracker.c index bea58ae4c..e470f85ea 100644 --- a/src/tagTracker.c +++ b/src/tagTracker.c @@ -38,7 +38,7 @@ struct visited { static struct visited *visited_heads[TAG_NUM_OF_ITEM_TYPES]; static unsigned num_visited[TAG_NUM_OF_ITEM_TYPES]; -static int visit_tag_items(int fd mpd_unused, Song *song, void *data) +static int visit_tag_items(Song *song, void *data) { enum tag_type type = (enum tag_type)(size_t)data; unsigned i; |