remove the glib library dependency
We never used many features from it, so there's no point in keeping it and forcing people to install a non-standard library. It may be standard on many GNU/Linux distributions, but there are many other UNIXes out there. This makes life much easier for people cross-compiling (like me :) git-svn-id: https://svn.musicpd.org/mpd/trunk@4361 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
@@ -89,9 +89,6 @@ AC_CHECK_LIB(nsl,gethostbyname,MPD_LIBS="$MPD_LIBS -lnsl",)
|
|||||||
AC_CHECK_LIB(m,exp,MPD_LIBS="$MPD_LIBS -lm",)
|
AC_CHECK_LIB(m,exp,MPD_LIBS="$MPD_LIBS -lm",)
|
||||||
AC_CHECK_FUNCS(setenv)
|
AC_CHECK_FUNCS(setenv)
|
||||||
|
|
||||||
PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.0, [MPD_LIBS="$MPD_LIBS $GLIB_LIBS" MPD_CFLAGS="$MPD_CFLAGS $GLIB_CFLAGS"],[echo "";echo "** ERROR:Unable to find glib-2.0 of version 2.0 or above **" ; exit 1])
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
dnl doesn't work for systems that don't have CODESET like OpenBSD
|
dnl doesn't work for systems that don't have CODESET like OpenBSD
|
||||||
dnl AC_CHECK_HEADER(langinfo.h,[enable_langinfo=yes;AC_DEFINE(HAVE_LANGINFO,1,[Define if nl_langinfo.h is present])],enable_langinfo=no)
|
dnl AC_CHECK_HEADER(langinfo.h,[enable_langinfo=yes;AC_DEFINE(HAVE_LANGINFO,1,[Define if nl_langinfo.h is present])],enable_langinfo=no)
|
||||||
|
@@ -775,7 +775,6 @@ static int addToDirectory(Directory * directory, char * shortname, char * name)
|
|||||||
|
|
||||||
void closeMp3Directory() {
|
void closeMp3Directory() {
|
||||||
freeDirectory(mp3rootDirectory);
|
freeDirectory(mp3rootDirectory);
|
||||||
destroyTagTracker();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Directory * findSubDirectory(Directory * directory,char * name) {
|
static Directory * findSubDirectory(Directory * directory,char * name) {
|
||||||
|
@@ -195,7 +195,7 @@ int insertInListWithoutKey(List * list, void * data) {
|
|||||||
|
|
||||||
/* if _key_ is not found, *_node_ is assigned to the node before which
|
/* if _key_ is not found, *_node_ is assigned to the node before which
|
||||||
the info would be found */
|
the info would be found */
|
||||||
static int findNodeInList(List * list, char * key, ListNode ** node, int * pos) {
|
int findNodeInList(List * list, char * key, ListNode ** node, int * pos) {
|
||||||
long high;
|
long high;
|
||||||
long low;
|
long low;
|
||||||
long cur;
|
long cur;
|
||||||
|
@@ -97,6 +97,9 @@ void deleteNodeFromList(List * list,ListNode * node);
|
|||||||
*/
|
*/
|
||||||
int findInList(List * list, char * key, void ** data);
|
int findInList(List * list, char * key, void ** data);
|
||||||
|
|
||||||
|
/* if _key_ is not found, *_node_ is assigned to the node before which
|
||||||
|
the info would be found */
|
||||||
|
int findNodeInList(List * list, char * key, ListNode ** node, int * pos);
|
||||||
|
|
||||||
/* frees memory malloc'd for list and its nodes
|
/* frees memory malloc'd for list and its nodes
|
||||||
* _list_ -> List to be free'd
|
* _list_ -> List to be free'd
|
||||||
|
124
src/tagTracker.c
124
src/tagTracker.c
@@ -18,13 +18,12 @@
|
|||||||
|
|
||||||
#include "tagTracker.h"
|
#include "tagTracker.h"
|
||||||
|
|
||||||
|
#include "list.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#include <glib/gtree.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
static GTree * tagLists[TAG_NUM_OF_ITEM_TYPES] =
|
static List * tagLists[TAG_NUM_OF_ITEM_TYPES] =
|
||||||
{
|
{
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
@@ -40,124 +39,117 @@ typedef struct tagTrackerItem {
|
|||||||
mpd_sint8 visited;
|
mpd_sint8 visited;
|
||||||
} TagTrackerItem;
|
} TagTrackerItem;
|
||||||
|
|
||||||
static int keyCompare(const void *a, const void *b, void *data) {
|
|
||||||
return strcmp(a,b);
|
|
||||||
}
|
|
||||||
|
|
||||||
char * getTagItemString(int type, char * string) {
|
char * getTagItemString(int type, char * string) {
|
||||||
TagTrackerItem * item;
|
ListNode * node;
|
||||||
TagTrackerItem ** itemPointer = &item;
|
int pos;
|
||||||
char *key;
|
|
||||||
char **keyPointer = &key;
|
|
||||||
|
|
||||||
if(tagLists[type] == NULL) {
|
if(tagLists[type] == NULL) {
|
||||||
tagLists[type] = g_tree_new_full(keyCompare, NULL, free, free);
|
tagLists[type] = makeList(free, 1);
|
||||||
|
sortList(tagLists[type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((TagTrackerItem *)g_tree_lookup_extended(tagLists[type], string, (void**)keyPointer, (void**)itemPointer )) {
|
if(findNodeInList(tagLists[type], string, &node, &pos)) {
|
||||||
item->count++;
|
((TagTrackerItem *)node->data)->count++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
item = malloc(sizeof(TagTrackerItem));
|
TagTrackerItem * item = malloc(sizeof(TagTrackerItem));
|
||||||
item->count = 1;
|
item->count = 1;
|
||||||
item->visited = 0;
|
item->visited = 0;
|
||||||
key = strdup(string);
|
node = insertInListBeforeNode(tagLists[type], node, pos,
|
||||||
g_tree_insert(tagLists[type], key, item);
|
string, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
return key;
|
return node->key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void removeTagItemString(int type, char * string) {
|
void removeTagItemString(int type, char * string) {
|
||||||
TagTrackerItem *item;
|
ListNode * node;
|
||||||
|
int pos;
|
||||||
|
|
||||||
assert(string);
|
assert(string);
|
||||||
|
|
||||||
assert(tagLists[type]);
|
assert(tagLists[type]);
|
||||||
if(tagLists[type] == NULL) return;
|
if(tagLists[type] == NULL) return;
|
||||||
|
|
||||||
if((item = g_tree_lookup(tagLists[type], string))) {
|
if(findNodeInList(tagLists[type], string, &node, &pos)) {
|
||||||
|
TagTrackerItem * item = node->data;
|
||||||
item->count--;
|
item->count--;
|
||||||
if(item->count <= 0) g_tree_remove(tagLists[type], string);
|
if(item->count <= 0) deleteNodeFromList(tagLists[type], node);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* why would this be done??? free it when mpd quits...
|
if(tagLists[type]->numberOfNodes == 0) {
|
||||||
if(tagLists[type]->numberOfNodes == 0) {
|
|
||||||
freeList(tagLists[type]);
|
freeList(tagLists[type]);
|
||||||
tagLists[type] = NULL;
|
tagLists[type] = NULL;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
void destroyTagTracker() {
|
|
||||||
int type;
|
|
||||||
for (type=0; type < TAG_NUM_OF_ITEM_TYPES; type ++)
|
|
||||||
if (tagLists[type])
|
|
||||||
g_tree_destroy(tagLists[type]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int getNumberOfTagItems(int type) {
|
int getNumberOfTagItems(int type) {
|
||||||
if(tagLists[type] == NULL) return 0;
|
if(tagLists[type] == NULL) return 0;
|
||||||
|
|
||||||
return g_tree_nnodes(tagLists[type]);
|
return tagLists[type]->numberOfNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int calcSavedMemory(char *key, TagTrackerItem* value, int* sum) {
|
|
||||||
*sum -= sizeof(int) + 4*sizeof(void*); /* sizeof(_GTreeNode) */
|
|
||||||
*sum -= sizeof(TagTrackerItem);
|
|
||||||
*sum += (strlen(key)+1)*value->count;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void printMemorySavedByTagTracker() {
|
void printMemorySavedByTagTracker() {
|
||||||
int i;
|
int i;
|
||||||
|
ListNode * node;
|
||||||
size_t sum = 0;
|
size_t sum = 0;
|
||||||
|
|
||||||
for(i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++) {
|
for(i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++) {
|
||||||
if(!tagLists[i]) continue;
|
if(!tagLists[i]) continue;
|
||||||
|
|
||||||
sum -= 5*sizeof(void*);/* sizeof(_GTree) */
|
sum -= sizeof(List);
|
||||||
g_tree_foreach(tagLists[i], (GTraverseFunc)calcSavedMemory, &sum);
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG("saved memory from tags: %li\n", (long)sum);
|
DEBUG("saved memory from tags: %li\n", (long)sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int resetVisitedFlag(char *key, TagTrackerItem *value, void *data) {
|
|
||||||
value->visited = 0;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void resetVisitedFlagsInTagTracker(int type) {
|
void resetVisitedFlagsInTagTracker(int type) {
|
||||||
|
ListNode * node;
|
||||||
|
|
||||||
if(!tagLists[type]) return;
|
if(!tagLists[type]) return;
|
||||||
|
|
||||||
g_tree_foreach(tagLists[type], (GTraverseFunc)resetVisitedFlag, NULL);
|
node = tagLists[type]->firstNode;
|
||||||
|
|
||||||
|
while(node) {
|
||||||
|
((TagTrackerItem *)node->data)->visited = 0;
|
||||||
|
node = node->nextNode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void visitInTagTracker(int type, char * str) {
|
void visitInTagTracker(int type, char * str) {
|
||||||
|
void * item;
|
||||||
|
|
||||||
|
if(!tagLists[type]) return;
|
||||||
|
|
||||||
|
if(!findInList(tagLists[type], str, &item)) return;
|
||||||
|
|
||||||
|
((TagTrackerItem *)item)->visited = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void printVisitedInTagTracker(FILE * fp, int type) {
|
||||||
|
ListNode * node;
|
||||||
TagTrackerItem * item;
|
TagTrackerItem * item;
|
||||||
|
|
||||||
if(!tagLists[type]) return;
|
if(!tagLists[type]) return;
|
||||||
|
|
||||||
if(!(item = g_tree_lookup(tagLists[type], str))) return;
|
node = tagLists[type]->firstNode;
|
||||||
|
|
||||||
item->visited = 1;
|
while(node) {
|
||||||
}
|
item = node->data;
|
||||||
|
if(item->visited) {
|
||||||
struct _PrintVisitedUserdata {
|
myfprintf(fp, "%s: %s\n", mpdTagItemKeys[type],
|
||||||
FILE *fp;
|
node->key);
|
||||||
char *type;
|
}
|
||||||
};
|
node = node->nextNode;
|
||||||
|
}
|
||||||
static int printVisitedFlag(char *key, TagTrackerItem* value, struct _PrintVisitedUserdata *data) {
|
|
||||||
if(value->visited) myfprintf(data->fp, "%s: %s\n", data->type, key);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void printVisitedInTagTracker(FILE * fp, int type) {
|
|
||||||
struct _PrintVisitedUserdata data = {fp, mpdTagItemKeys[type]};
|
|
||||||
if(!tagLists[type]) return;
|
|
||||||
g_tree_foreach( tagLists[type], (GTraverseFunc)printVisitedFlag, (void*)&data);
|
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,6 @@
|
|||||||
char * getTagItemString(int type, char * string);
|
char * getTagItemString(int type, char * string);
|
||||||
|
|
||||||
void removeTagItemString(int type, char * string);
|
void removeTagItemString(int type, char * string);
|
||||||
void destroyTagTracker();
|
|
||||||
|
|
||||||
int getNumberOfTagItems(int type);
|
int getNumberOfTagItems(int type);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user