2006-07-13 21:20:34 +02:00
|
|
|
/* the Music Player Daemon (MPD)
|
2006-07-14 21:37:45 +02:00
|
|
|
* (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
|
2006-07-13 21:20:34 +02:00
|
|
|
* This project's homepage is: http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2004-11-10 22:58:27 +01:00
|
|
|
#include "dbUtils.h"
|
|
|
|
|
|
|
|
#include "directory.h"
|
|
|
|
#include "myfprintf.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "playlist.h"
|
|
|
|
#include "tag.h"
|
|
|
|
#include "tagTracker.h"
|
2004-11-11 03:36:25 +01:00
|
|
|
#include "log.h"
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2004-11-10 23:12:11 +01:00
|
|
|
#define LOCATE_TAG_FILE_TYPE TAG_NUM_OF_ITEM_TYPES+10
|
|
|
|
#define LOCATE_TAG_FILE_KEY "filename"
|
2005-03-01 00:57:47 +01:00
|
|
|
#define LOCATE_TAG_ANY_TYPE TAG_NUM_OF_ITEM_TYPES+20
|
|
|
|
#define LOCATE_TAG_ANY_KEY "any"
|
|
|
|
|
2004-11-12 02:44:27 +01:00
|
|
|
typedef struct _ListCommandItem {
|
2004-11-10 22:58:27 +01:00
|
|
|
mpd_sint8 tagType;
|
|
|
|
int numConditionals;
|
2006-07-20 18:02:40 +02:00
|
|
|
LocateTagItem *conditionals;
|
2004-11-10 22:58:27 +01:00
|
|
|
} ListCommandItem;
|
|
|
|
|
2004-11-12 02:44:27 +01:00
|
|
|
typedef struct _LocateTagItemArray {
|
|
|
|
int numItems;
|
2006-07-20 18:02:40 +02:00
|
|
|
LocateTagItem *items;
|
2004-11-12 02:44:27 +01:00
|
|
|
} LocateTagItemArray;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
int getLocateTagItemType(char *str)
|
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
int i;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (0 == strcasecmp(str, LOCATE_TAG_FILE_KEY)) {
|
2004-11-10 22:58:27 +01:00
|
|
|
return LOCATE_TAG_FILE_TYPE;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (0 == strcasecmp(str, LOCATE_TAG_ANY_KEY)) {
|
|
|
|
return LOCATE_TAG_ANY_TYPE;
|
2005-03-01 00:57:47 +01:00
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
|
|
|
|
for (i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++) {
|
|
|
|
if (0 == strcasecmp(str, mpdTagItemKeys[i]))
|
|
|
|
return i;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int initLocateTagItem(LocateTagItem * item, char *typeStr, char *needle)
|
2004-11-12 02:44:27 +01:00
|
|
|
{
|
|
|
|
item->tagType = getLocateTagItemType(typeStr);
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (item->tagType < 0)
|
|
|
|
return -1;
|
2004-11-12 02:44:27 +01:00
|
|
|
|
|
|
|
item->needle = strdup(needle);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
LocateTagItem *newLocateTagItem(char *typeStr, char *needle)
|
|
|
|
{
|
|
|
|
LocateTagItem *ret = malloc(sizeof(LocateTagItem));
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (initLocateTagItem(ret, typeStr, needle) < 0) {
|
2004-11-10 22:58:27 +01:00
|
|
|
free(ret);
|
2004-11-12 02:44:27 +01:00
|
|
|
ret = NULL;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void freeLocateTagItemArray(int count, LocateTagItem * array)
|
|
|
|
{
|
2004-11-12 02:44:27 +01:00
|
|
|
int i;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
free(array[i].needle);
|
2004-11-12 02:44:27 +01:00
|
|
|
|
|
|
|
free(array);
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
int newLocateTagItemArrayFromArgArray(char *argArray[],
|
|
|
|
int numArgs, LocateTagItem ** arrayRet)
|
2004-11-12 02:44:27 +01:00
|
|
|
{
|
2006-07-20 18:02:40 +02:00
|
|
|
int i, j;
|
|
|
|
LocateTagItem *item;
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (numArgs == 0)
|
|
|
|
return 0;
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (numArgs % 2 != 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
*arrayRet = malloc(sizeof(LocateTagItem) * numArgs / 2);
|
|
|
|
|
|
|
|
for (i = 0, item = *arrayRet; i < numArgs / 2; i++, item++) {
|
|
|
|
if (initLocateTagItem
|
|
|
|
(item, argArray[i * 2], argArray[i * 2 + 1]) < 0)
|
2004-11-12 02:44:27 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
return numArgs / 2;
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
fail:
|
|
|
|
for (j = 0; j < i; j++) {
|
2004-11-12 02:44:27 +01:00
|
|
|
free((*arrayRet)[j].needle);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(*arrayRet);
|
|
|
|
*arrayRet = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void freeLocateTagItem(LocateTagItem * item)
|
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
free(item->needle);
|
|
|
|
free(item);
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int countSongsInDirectory(FILE * fp, Directory * directory, void *data)
|
|
|
|
{
|
|
|
|
int *count = (int *)data;
|
|
|
|
|
|
|
|
*count += directory->songs->numberOfNodes;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
return 0;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int printDirectoryInDirectory(FILE * fp, Directory * directory,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
if (directory->path) {
|
|
|
|
myfprintf(fp, "directory: %s\n", getDirectoryPath(directory));
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
return 0;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int printSongInDirectory(FILE * fp, Song * song, void *data)
|
|
|
|
{
|
2004-11-11 01:41:28 +01:00
|
|
|
printSongUrl(fp, song);
|
2006-07-20 18:02:40 +02:00
|
|
|
return 0;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int strstrSearchTag(Song * song, int type, char *str)
|
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
int i;
|
2006-07-20 18:02:40 +02:00
|
|
|
char *dup;
|
2004-11-10 22:58:27 +01:00
|
|
|
int ret = 0;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (type == LOCATE_TAG_FILE_TYPE || type == LOCATE_TAG_ANY_TYPE) {
|
2004-11-11 03:36:25 +01:00
|
|
|
dup = strDupToUpper(getSongUrl(song));
|
2006-07-20 18:02:40 +02:00
|
|
|
if (strstr(dup, str))
|
|
|
|
ret = 1;
|
2004-11-10 22:58:27 +01:00
|
|
|
free(dup);
|
2005-03-01 00:57:47 +01:00
|
|
|
if (ret == 1 || type == LOCATE_TAG_FILE_TYPE) {
|
|
|
|
return ret;
|
|
|
|
}
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!song->tag)
|
|
|
|
return 0;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < song->tag->numOfItems && !ret; i++) {
|
|
|
|
if (type != LOCATE_TAG_ANY_TYPE &&
|
|
|
|
song->tag->items[i].type != type) {
|
|
|
|
continue;
|
2005-03-01 00:57:47 +01:00
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2004-11-10 22:58:27 +01:00
|
|
|
dup = strDupToUpper(song->tag->items[i].value);
|
2006-07-20 18:02:40 +02:00
|
|
|
if (strstr(dup, str))
|
|
|
|
ret = 1;
|
2004-11-10 22:58:27 +01:00
|
|
|
free(dup);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int searchInDirectory(FILE * fp, Song * song, void *data)
|
|
|
|
{
|
|
|
|
LocateTagItemArray *array = data;
|
2004-11-12 02:44:27 +01:00
|
|
|
int i;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < array->numItems; i++) {
|
|
|
|
if (!strstrSearchTag(song, array->items[i].tagType,
|
|
|
|
array->items[i].needle)) {
|
2004-11-12 02:44:27 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
2004-11-12 02:44:27 +01:00
|
|
|
|
|
|
|
printSongInfo(fp, song);
|
|
|
|
|
2004-11-10 22:58:27 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
int searchForSongsIn(FILE * fp, char *name, int numItems, LocateTagItem * items)
|
2004-11-12 02:44:27 +01:00
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
int ret = -1;
|
2004-11-12 02:44:27 +01:00
|
|
|
int i;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
char **originalNeedles = malloc(numItems * sizeof(char *));
|
2004-11-12 02:44:27 +01:00
|
|
|
LocateTagItemArray array;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < numItems; i++) {
|
2004-11-12 02:44:27 +01:00
|
|
|
originalNeedles[i] = items[i].needle;
|
|
|
|
items[i].needle = strDupToUpper(originalNeedles[i]);
|
|
|
|
}
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2004-11-12 02:44:27 +01:00
|
|
|
array.numItems = numItems;
|
|
|
|
array.items = items;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
ret = traverseAllIn(fp, name, searchInDirectory, NULL, &array);
|
2004-11-12 02:44:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < numItems; i++) {
|
2004-11-12 02:44:27 +01:00
|
|
|
free(items[i].needle);
|
|
|
|
items[i].needle = originalNeedles[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
free(originalNeedles);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int tagItemFoundAndMatches(Song * song, int type, char *str)
|
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
int i;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (type == LOCATE_TAG_FILE_TYPE) {
|
|
|
|
if (0 == strcmp(str, getSongUrl(song)))
|
|
|
|
return 1;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!song->tag)
|
|
|
|
return 0;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < song->tag->numOfItems; i++) {
|
|
|
|
if (song->tag->items[i].type != type)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (0 == strcmp(str, song->tag->items[i].value))
|
|
|
|
return 1;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int findInDirectory(FILE * fp, Song * song, void *data)
|
|
|
|
{
|
|
|
|
LocateTagItemArray *array = data;
|
2004-11-12 02:44:27 +01:00
|
|
|
int i;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < array->numItems; i++) {
|
|
|
|
if (!tagItemFoundAndMatches(song, array->items[i].tagType,
|
|
|
|
array->items[i].needle)) {
|
2004-11-12 02:44:27 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
2004-11-12 02:44:27 +01:00
|
|
|
|
|
|
|
printSongInfo(fp, song);
|
|
|
|
|
2004-11-10 22:58:27 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
int findSongsIn(FILE * fp, char *name, int numItems, LocateTagItem * items)
|
|
|
|
{
|
2004-11-12 02:44:27 +01:00
|
|
|
LocateTagItemArray array;
|
|
|
|
|
|
|
|
array.numItems = numItems;
|
|
|
|
array.items = items;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
|
|
|
return traverseAllIn(fp, name, findInDirectory, NULL, (void *)&array);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
int printAllIn(FILE * fp, char *name)
|
|
|
|
{
|
|
|
|
return traverseAllIn(fp, name, printSongInDirectory,
|
|
|
|
printDirectoryInDirectory, NULL);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int directoryAddSongToPlaylist(FILE * fp, Song * song, void *data)
|
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
return addSongToPlaylist(fp, song, 0);
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
int addAllIn(FILE * fp, char *name)
|
|
|
|
{
|
|
|
|
return traverseAllIn(fp, name, directoryAddSongToPlaylist, NULL, NULL);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int directoryPrintSongInfo(FILE * fp, Song * song, void *data)
|
|
|
|
{
|
|
|
|
return printSongInfo(fp, song);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int sumSongTime(FILE * fp, Song * song, void *data)
|
|
|
|
{
|
|
|
|
unsigned long *time = (unsigned long *)data;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (song->tag && song->tag->time >= 0)
|
|
|
|
*time += song->tag->time;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
int printInfoForAllIn(FILE * fp, char *name)
|
|
|
|
{
|
|
|
|
return traverseAllIn(fp, name, directoryPrintSongInfo,
|
|
|
|
printDirectoryInDirectory, NULL);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
int countSongsIn(FILE * fp, char *name)
|
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
int count = 0;
|
2006-07-20 18:02:40 +02:00
|
|
|
void *ptr = (void *)&count;
|
|
|
|
|
|
|
|
traverseAllIn(fp, name, NULL, countSongsInDirectory, ptr);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
unsigned long sumSongTimesIn(FILE * fp, char *name)
|
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
unsigned long dbPlayTime = 0;
|
2006-07-20 18:02:40 +02:00
|
|
|
void *ptr = (void *)&dbPlayTime;
|
|
|
|
|
|
|
|
traverseAllIn(fp, name, sumSongTime, NULL, ptr);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
return dbPlayTime;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static ListCommandItem *newListCommandItem(int tagType, int numConditionals,
|
|
|
|
LocateTagItem * conditionals)
|
2004-11-10 22:58:27 +01:00
|
|
|
{
|
2006-07-20 18:02:40 +02:00
|
|
|
ListCommandItem *item = malloc(sizeof(ListCommandItem));
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
item->tagType = tagType;
|
|
|
|
item->numConditionals = numConditionals;
|
|
|
|
item->conditionals = conditionals;
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static void freeListCommandItem(ListCommandItem * item)
|
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
free(item);
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static void visitTag(FILE * fp, Song * song, int tagType)
|
|
|
|
{
|
2004-11-10 22:58:27 +01:00
|
|
|
int i;
|
2006-07-20 18:02:40 +02:00
|
|
|
MpdTag *tag = song->tag;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (tagType == LOCATE_TAG_FILE_TYPE) {
|
2004-11-11 03:36:25 +01:00
|
|
|
printSongUrl(fp, song);
|
2004-11-10 22:58:27 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!tag)
|
|
|
|
return;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < tag->numOfItems; i++) {
|
|
|
|
if (tag->items[i].type == tagType) {
|
2004-11-11 14:15:41 +01:00
|
|
|
visitInTagTracker(tagType, tag->items[i].value);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int listUniqueTagsInDirectory(FILE * fp, Song * song, void *data)
|
|
|
|
{
|
|
|
|
ListCommandItem *item = data;
|
2004-11-10 22:58:27 +01:00
|
|
|
int i;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < item->numConditionals; i++) {
|
|
|
|
if (!tagItemFoundAndMatches(song, item->conditionals[i].tagType,
|
|
|
|
item->conditionals[i].needle)) {
|
2004-11-10 22:58:27 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-11 14:15:41 +01:00
|
|
|
visitTag(fp, song, item->tagType);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
int listAllUniqueTags(FILE * fp, int type, int numConditionals,
|
|
|
|
LocateTagItem * conditionals)
|
2004-11-10 22:58:27 +01:00
|
|
|
{
|
|
|
|
int ret;
|
2006-07-20 18:02:40 +02:00
|
|
|
ListCommandItem *item = newListCommandItem(type, numConditionals,
|
|
|
|
conditionals);
|
|
|
|
|
|
|
|
if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) {
|
2004-11-10 22:58:27 +01:00
|
|
|
resetVisitedFlagsInTagTracker(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = traverseAllIn(fp, NULL, listUniqueTagsInDirectory, NULL,
|
2006-07-20 18:02:40 +02:00
|
|
|
(void *)item);
|
2004-11-10 22:58:27 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) {
|
2004-11-11 14:15:41 +01:00
|
|
|
printVisitedInTagTracker(fp, type);
|
|
|
|
}
|
|
|
|
|
2004-11-10 22:58:27 +01:00
|
|
|
freeListCommandItem(item);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2004-11-11 03:36:25 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int sumSavedFilenameMemoryInDirectory(FILE * fp, Directory * dir,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
int *sum = data;
|
2004-11-11 03:36:25 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!dir->path)
|
|
|
|
return 0;
|
2004-11-11 03:36:25 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
*sum += (strlen(getDirectoryPath(dir)) + 1 - sizeof(Directory *)) *
|
|
|
|
dir->songs->numberOfNodes;
|
2004-11-11 03:59:16 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int sumSavedFilenameMemoryInSong(FILE * fp, Song * song, void *data)
|
|
|
|
{
|
|
|
|
int *sum = data;
|
|
|
|
|
|
|
|
*sum += strlen(song->url) + 1;
|
2004-11-11 03:59:16 +01:00
|
|
|
|
2004-11-11 03:36:25 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void printSavedMemoryFromFilenames(void)
|
|
|
|
{
|
2006-07-13 21:40:14 +02:00
|
|
|
int sum = 0;
|
2004-11-11 06:25:05 +01:00
|
|
|
|
2006-07-13 21:40:14 +02:00
|
|
|
traverseAllIn(stderr, NULL, sumSavedFilenameMemoryInSong,
|
2006-07-20 18:02:40 +02:00
|
|
|
sumSavedFilenameMemoryInDirectory, (void *)&sum);
|
2006-07-13 21:40:14 +02:00
|
|
|
|
|
|
|
DEBUG("saved memory from filenames: %i\n", sum);
|
|
|
|
}
|