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 "tagTracker.h"
|
|
|
|
|
2006-07-16 18:50:54 +02:00
|
|
|
#include "list.h"
|
2004-11-10 22:58:27 +01:00
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2006-07-16 18:50:54 +02:00
|
|
|
static List * tagLists[TAG_NUM_OF_ITEM_TYPES] =
|
2004-11-10 22:58:27 +01:00
|
|
|
{
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct tagTrackerItem {
|
|
|
|
int count;
|
|
|
|
mpd_sint8 visited;
|
|
|
|
} TagTrackerItem;
|
|
|
|
|
|
|
|
char * getTagItemString(int type, char * string) {
|
2006-07-16 18:50:54 +02:00
|
|
|
ListNode * node;
|
|
|
|
int pos;
|
2004-11-14 15:42:07 +01:00
|
|
|
|
2004-11-10 22:58:27 +01:00
|
|
|
if(tagLists[type] == NULL) {
|
2006-07-16 18:50:54 +02:00
|
|
|
tagLists[type] = makeList(free, 1);
|
|
|
|
sortList(tagLists[type]);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-16 18:50:54 +02:00
|
|
|
if(findNodeInList(tagLists[type], string, &node, &pos)) {
|
|
|
|
((TagTrackerItem *)node->data)->count++;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
else {
|
2006-07-16 18:50:54 +02:00
|
|
|
TagTrackerItem * item = malloc(sizeof(TagTrackerItem));
|
2004-11-10 22:58:27 +01:00
|
|
|
item->count = 1;
|
|
|
|
item->visited = 0;
|
2006-07-16 18:50:54 +02:00
|
|
|
node = insertInListBeforeNode(tagLists[type], node, pos,
|
|
|
|
string, item);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-16 18:50:54 +02:00
|
|
|
return node->key;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void removeTagItemString(int type, char * string) {
|
2006-07-16 18:50:54 +02:00
|
|
|
ListNode * node;
|
|
|
|
int pos;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
assert(string);
|
|
|
|
|
2004-11-14 15:58:00 +01:00
|
|
|
assert(tagLists[type]);
|
2004-11-10 22:58:27 +01:00
|
|
|
if(tagLists[type] == NULL) return;
|
|
|
|
|
2006-07-16 18:50:54 +02:00
|
|
|
if(findNodeInList(tagLists[type], string, &node, &pos)) {
|
|
|
|
TagTrackerItem * item = node->data;
|
2004-11-10 22:58:27 +01:00
|
|
|
item->count--;
|
2006-07-16 18:50:54 +02:00
|
|
|
if(item->count <= 0) deleteNodeFromList(tagLists[type], node);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2006-07-16 18:50:54 +02:00
|
|
|
if(tagLists[type]->numberOfNodes == 0) {
|
2004-11-10 22:58:27 +01:00
|
|
|
freeList(tagLists[type]);
|
|
|
|
tagLists[type] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int getNumberOfTagItems(int type) {
|
|
|
|
if(tagLists[type] == NULL) return 0;
|
|
|
|
|
2006-07-16 18:50:54 +02:00
|
|
|
return tagLists[type]->numberOfNodes;
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
2006-07-15 05:34:48 +02:00
|
|
|
|
2004-11-10 22:58:27 +01:00
|
|
|
void printMemorySavedByTagTracker() {
|
|
|
|
int i;
|
2006-07-16 18:50:54 +02:00
|
|
|
ListNode * node;
|
2004-11-10 22:58:27 +01:00
|
|
|
size_t sum = 0;
|
|
|
|
|
|
|
|
for(i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++) {
|
|
|
|
if(!tagLists[i]) continue;
|
|
|
|
|
2006-07-16 18:50:54 +02:00
|
|
|
sum -= sizeof(List);
|
|
|
|
|
|
|
|
node = tagLists[i]->firstNode;
|
|
|
|
|
|
|
|
while(node != NULL) {
|
|
|
|
sum -= sizeof(ListNode);
|
|
|
|
sum -= sizeof(TagTrackerItem);
|
|
|
|
sum -= sizeof(node->key);
|
|
|
|
sum += (strlen(node->key)+1)*(*((int *)node->data));
|
|
|
|
node = node->nextNode;
|
|
|
|
}
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2004-11-11 06:25:05 +01:00
|
|
|
DEBUG("saved memory from tags: %li\n", (long)sum);
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void resetVisitedFlagsInTagTracker(int type) {
|
2006-07-16 18:50:54 +02:00
|
|
|
ListNode * node;
|
2004-11-10 22:58:27 +01:00
|
|
|
|
|
|
|
if(!tagLists[type]) return;
|
|
|
|
|
2006-07-16 18:50:54 +02:00
|
|
|
node = tagLists[type]->firstNode;
|
|
|
|
|
|
|
|
while(node) {
|
|
|
|
((TagTrackerItem *)node->data)->visited = 0;
|
|
|
|
node = node->nextNode;
|
|
|
|
}
|
2004-11-10 22:58:27 +01:00
|
|
|
}
|
|
|
|
|
2004-11-11 14:15:41 +01:00
|
|
|
void visitInTagTracker(int type, char * str) {
|
2006-07-16 18:50:54 +02:00
|
|
|
void * item;
|
2004-11-11 14:15:41 +01:00
|
|
|
|
|
|
|
if(!tagLists[type]) return;
|
|
|
|
|
2006-07-16 18:50:54 +02:00
|
|
|
if(!findInList(tagLists[type], str, &item)) return;
|
2004-11-11 14:15:41 +01:00
|
|
|
|
2006-07-16 18:50:54 +02:00
|
|
|
((TagTrackerItem *)item)->visited = 1;
|
2005-11-16 15:43:04 +01:00
|
|
|
}
|
2004-11-11 14:15:41 +01:00
|
|
|
|
2005-11-16 15:43:04 +01:00
|
|
|
void printVisitedInTagTracker(FILE * fp, int type) {
|
2006-07-16 18:50:54 +02:00
|
|
|
ListNode * node;
|
|
|
|
TagTrackerItem * item;
|
|
|
|
|
2005-11-16 15:43:04 +01:00
|
|
|
if(!tagLists[type]) return;
|
2006-07-16 18:50:54 +02:00
|
|
|
|
|
|
|
node = tagLists[type]->firstNode;
|
|
|
|
|
|
|
|
while(node) {
|
|
|
|
item = node->data;
|
|
|
|
if(item->visited) {
|
|
|
|
myfprintf(fp, "%s: %s\n", mpdTagItemKeys[type],
|
|
|
|
node->key);
|
|
|
|
}
|
|
|
|
node = node->nextNode;
|
|
|
|
}
|
2004-11-11 14:18:44 +01:00
|
|
|
}
|