1 /* the Music Player Daemon (MPD)
2 * Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
3 * This project's homepage is: http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "tagTracker.h"
24 #include "myfprintf.h"
29 static Tree *tagTrees[TAG_NUM_OF_ITEM_TYPES];
31 typedef struct tagTrackerItem {
36 char *getTagItemString(int type, char *string)
40 if (tagTrees[type] == NULL)
42 tagTrees[type] = MakeTree((TreeCompareKeyFunction)strcmp,
43 (TreeFreeFunction)free,
44 (TreeFreeFunction)free);
47 if (FindInTree(tagTrees[type], string, &iter))
49 ((TagTrackerItem *)GetTreeKeyData(&iter).data)->count++;
50 return (char *)GetTreeKeyData(&iter).key;
54 TagTrackerItem *item = xmalloc(sizeof(TagTrackerItem));
55 char *key = xstrdup(string);
58 InsertInTree(tagTrees[type], key, item);
63 void removeTagItemString(int type, char *string)
69 assert(tagTrees[type]);
70 if (tagTrees[type] == NULL)
73 if (FindInTree(tagTrees[type], string, &iter))
75 TagTrackerItem * item =
76 (TagTrackerItem *)GetTreeKeyData(&iter).data;
79 RemoveFromTreeByIterator(tagTrees[type], &iter);
82 if (GetTreeSize(tagTrees[type]) == 0)
84 FreeTree(tagTrees[type]);
85 tagTrees[type] = NULL;
89 int getNumberOfTagItems(int type)
91 if (tagTrees[type] == NULL)
94 return GetTreeSize(tagTrees[type]);
97 void resetVisitedFlagsInTagTracker(int type)
104 for (SetTreeIteratorToBegin(tagTrees[type], &iter);
105 !IsTreeIteratorAtEnd(&iter);
106 IncrementTreeIterator(&iter))
108 ((TagTrackerItem *)GetTreeKeyData(&iter).data)->visited = 0;
112 void visitInTagTracker(int type, char *str)
119 if (!FindInTree(tagTrees[type], str, &iter))
122 ((TagTrackerItem *)GetTreeKeyData(&iter).data)->visited = 1;
125 void printVisitedInTagTracker(int fd, int type)
128 TagTrackerItem * item;
133 for (SetTreeIteratorToBegin(tagTrees[type], &iter);
134 !IsTreeIteratorAtEnd(&iter);
135 IncrementTreeIterator(&iter))
137 item = ((TagTrackerItem *)GetTreeKeyData(&iter).data);
143 mpdTagItemKeys[type],
144 (char *)GetTreeKeyData(&iter).key);