aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-11-11 02:59:16 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-11-11 02:59:16 +0000
commitd6a87f538d2347cd4610962a0004052c0c6ba8de (patch)
tree3bc0d5b0f93eb14d520f37607eec51fe456aafd0
parent4ec3df033954d01663087011efecfca37749f965 (diff)
downloadmpd-d6a87f538d2347cd4610962a0004052c0c6ba8de.tar.gz
mpd-d6a87f538d2347cd4610962a0004052c0c6ba8de.tar.xz
mpd-d6a87f538d2347cd4610962a0004052c0c6ba8de.zip
ok, now song->url is only the filename, not the full path to the song
git-svn-id: https://svn.musicpd.org/mpd/trunk@2602 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r--src/audioOutput.c2
-rw-r--r--src/command.c6
-rw-r--r--src/conf.c4
-rw-r--r--src/dbUtils.c15
-rw-r--r--src/directory.c4
-rw-r--r--src/inputPlugin.c2
-rw-r--r--src/interface.c10
-rw-r--r--src/list.c32
-rw-r--r--src/list.h4
-rw-r--r--src/ls.c2
-rw-r--r--src/permission.c2
-rw-r--r--src/song.c9
-rw-r--r--src/tagTracker.c2
13 files changed, 57 insertions, 37 deletions
diff --git a/src/audioOutput.c b/src/audioOutput.c
index 7c3b8dbb4..83616d37a 100644
--- a/src/audioOutput.c
+++ b/src/audioOutput.c
@@ -24,7 +24,7 @@ void unloadAudioOutputPlugin(AudioOutputPlugin * audioOutputPlugin) {
}
void initAudioOutputPlugins() {
- audioOutputPluginList = makeList(NULL);
+ audioOutputPluginList = makeList(NULL, 0);
}
void finishAudioOutputPlugins() {
diff --git a/src/command.c b/src/command.c
index 5b3616a40..e2bf84460 100644
--- a/src/command.c
+++ b/src/command.c
@@ -486,7 +486,7 @@ int listHandleUpdate(FILE * fp, unsigned int * permission, int argArrayLength,
CommandEntry * nextCmd = NULL;
ListNode * nextNode = commandNode->nextNode;;
- if(!pathList) pathList = makeList(NULL);
+ if(!pathList) pathList = makeList(NULL, 1);
if(argArrayLength==2) insertInList(pathList,argArray[1],NULL);
else insertInList(pathList,"",NULL);
@@ -511,7 +511,7 @@ int handleUpdate(FILE * fp, unsigned int * permission, int argArrayLength,
{
if(argArrayLength==2) {
int ret;
- List * pathList = makeList(NULL);
+ List * pathList = makeList(NULL, 1);
insertInList(pathList,argArray[1],NULL);
ret = updateInit(fp,pathList);
freeList(pathList);
@@ -881,7 +881,7 @@ int handleCommands(FILE * fp, unsigned int * permission, int argArrayLength,
}
void initCommands() {
- commandList = makeList(free);
+ commandList = makeList(free, 1);
addCommand(COMMAND_PLAY ,PERMISSION_CONTROL, 0, 1,handlePlay,NULL);
addCommand(COMMAND_PLAYID ,PERMISSION_CONTROL, 0, 1,handlePlayId,NULL);
diff --git a/src/conf.c b/src/conf.c
index 856740038..77ef13ba4 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -86,7 +86,7 @@ ConfigEntry * newConfigEntry(int repeatable, int block) {
ConfigEntry * ret = malloc(sizeof(ConfigEntry));
ret->mask = 0;
- ret->configParamList = makeList((ListFreeDataFunc *)freeConfigParam);
+ ret->configParamList = makeList((ListFreeDataFunc *)freeConfigParam, 1);
if(repeatable) ret->mask |= CONF_REPEATABLE_MASK;
if(block) ret->mask |= CONF_BLOCK_MASK;
@@ -113,7 +113,7 @@ void registerConfigParam(char * name, int repeatable, int block) {
}
void initConf() {
- configEntriesList = makeList((ListFreeDataFunc *)freeConfigEntry);
+ configEntriesList = makeList((ListFreeDataFunc *)freeConfigEntry, 1);
registerConfigParam(CONF_PORT, 0, 0);
registerConfigParam(CONF_MUSIC_DIR, 0, 0);
diff --git a/src/dbUtils.c b/src/dbUtils.c
index 55791653f..3699ab72a 100644
--- a/src/dbUtils.c
+++ b/src/dbUtils.c
@@ -277,6 +277,17 @@ int sumSavedMemoryInDirectory(FILE * fp, Directory * dir, void * data) {
*sum += (strlen(dir->utf8name)+1-sizeof(Directory *))*
dir->songs->numberOfNodes;
+
+ /**sum += (strlen(dir->utf8name)+1)*
+ dir->subDirectories->numberOfNodes;*/
+
+ return 0;
+}
+
+int sumSavedMemoryInSong(FILE * fp, Song * song, void * data) {
+ int * sum = data;
+
+ *sum += strlen(song->url)+1;
return 0;
}
@@ -284,8 +295,8 @@ int sumSavedMemoryInDirectory(FILE * fp, Directory * dir, void * data) {
void printSavedMemoryFromFilenames() {
int sum;
- traverseAllIn(stderr, NULL, NULL, sumSavedMemoryInDirectory,
- (void *)&sum);
+ traverseAllIn(stderr, NULL, sumSavedMemoryInSong,
+ sumSavedMemoryInDirectory, (void *)&sum);
DEBUG("saved memory from filenames: %i\n", sum);
}
diff --git a/src/directory.c b/src/directory.c
index 18c0b7c92..b41bd914b 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -269,7 +269,7 @@ void freeDirectory(Directory * directory) {
}
DirectoryList * newDirectoryList() {
- return makeList((ListFreeDataFunc *)freeDirectory);
+ return makeList((ListFreeDataFunc *)freeDirectory, 1);
}
void freeDirectoryList(DirectoryList * directoryList) {
@@ -352,7 +352,7 @@ int removeDeletedFromDirectory(Directory * directory, DIR * dir) {
char cwd[2];
struct dirent * ent;
char * dirname = directory->utf8name;
- List * entList = makeList(free);
+ List * entList = makeList(free, 1);
void * name;
char * s;
char * utf8;
diff --git a/src/inputPlugin.c b/src/inputPlugin.c
index 029f589f0..83ba2e38f 100644
--- a/src/inputPlugin.c
+++ b/src/inputPlugin.c
@@ -117,7 +117,7 @@ extern InputPlugin aacPlugin;
extern InputPlugin modPlugin;
void initInputPlugins() {
- inputPlugin_list = makeList(NULL);
+ inputPlugin_list = makeList(NULL, 1);
/* load plugins here */
loadInputPlugin(&mp3Plugin);
diff --git a/src/interface.c b/src/interface.c
index d2ae43a8d..b9b8df5f6 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -288,7 +288,8 @@ int interfaceReadInput(Interface * interface) {
if(strcmp(interface->buffer,
INTERFACE_LIST_MODE_BEGIN)==0)
{
- interface->commandList = makeList(free);
+ interface->commandList = makeList(free,
+ 1);
interface->commandListSize =
sizeof(List);
interface->commandListOK = 0;
@@ -298,7 +299,8 @@ int interfaceReadInput(Interface * interface) {
INTERFACE_LIST_OK_MODE_BEGIN)
==0)
{
- interface->commandList = makeList(free);
+ interface->commandList = makeList(free,
+ 1);
interface->commandListSize =
sizeof(List);
interface->commandListOK = 1;
@@ -654,7 +656,7 @@ void printInterfaceOutBuffer(Interface * interface) {
memcpy(buffer,interface->outBuffer,
interface->outBuflen);
buffer[interface->outBuflen] = '\0';
- interface->bufferList = makeList(free);
+ interface->bufferList = makeList(free, 1);
insertInListWithoutKey(interface->bufferList,
(void *)buffer);
}
@@ -670,7 +672,7 @@ void printInterfaceOutBuffer(Interface * interface) {
memcpy(buffer,interface->outBuffer+ret,
interface->outBuflen-ret);
buffer[interface->outBuflen-ret] = '\0';
- interface->bufferList = makeList(free);
+ interface->bufferList = makeList(free, 1);
insertInListWithoutKey(interface->bufferList,buffer);
}
/* if we needed to create buffer, initialize bufferSize info */
diff --git a/src/list.c b/src/list.c
index 48f1e1c62..f0d30d802 100644
--- a/src/list.c
+++ b/src/list.c
@@ -42,7 +42,7 @@ void freeListNodesArray(List * list) {
list->nodesArray = NULL;
}
-List * makeList(ListFreeDataFunc * freeDataFunc) {
+List * makeList(ListFreeDataFunc * freeDataFunc, int strdupKeys) {
List * list = malloc(sizeof(List));
assert(list!=NULL);
@@ -52,6 +52,7 @@ List * makeList(ListFreeDataFunc * freeDataFunc) {
list->freeDataFunc = freeDataFunc;
list->numberOfNodes = 0;
list->nodesArray = NULL;
+ list->strdupKeys = strdupKeys;
return list;
}
@@ -93,10 +94,12 @@ int insertInListBeforeNode(List * list, ListNode * beforeNode, char * key,
}
beforeNode->prevNode = node;
}
-
- node->key = malloc((strlen(key)+1)*sizeof(char));
+
+ if(list->strdupKeys) node->key = strdup(key);
+ else node->key = key;
+
assert(node->key!=NULL);
- strcpy(node->key,key);
+
node->data = data;
list->numberOfNodes++;
@@ -104,7 +107,7 @@ int insertInListBeforeNode(List * list, ListNode * beforeNode, char * key,
return 1;
}
-ListNode * insertInList(List * list,char * key,void * data) {
+ListNode * insertInList(List * list, char * key, void * data) {
ListNode * node;
assert(list!=NULL);
@@ -125,10 +128,10 @@ ListNode * insertInList(List * list,char * key,void * data) {
assert(list->lastNode->nextNode==NULL);
list->lastNode->nextNode = node;
}
-
- node->key = malloc((strlen(key)+1)*sizeof(char));
- assert(node->key!=NULL);
- strcpy(node->key,key);
+
+ if(list->strdupKeys) node->key = strdup(key);
+ else node->key = key;
+
node->data = data;
node->nextNode = NULL;
node->prevNode = list->lastNode;
@@ -267,7 +270,8 @@ void deleteNodeFromList(List * list,ListNode * node) {
if(list->freeDataFunc) {
list->freeDataFunc(node->data);
}
- free(node->key);
+
+ if(list->strdupKeys) free(node->key);
free(node);
list->numberOfNodes--;
@@ -290,7 +294,7 @@ void freeList(void * list) {
while(tmpNode!=NULL) {
tmpNode2 = tmpNode->nextNode;
- free(tmpNode->key);
+ if(((List *)list)->strdupKeys) free(tmpNode->key);
if(((List *)list)->freeDataFunc) {
((List *)list)->freeDataFunc(tmpNode->data);
}
@@ -311,7 +315,7 @@ void clearList(List * list) {
while(tmpNode!=NULL) {
tmpNode2 = tmpNode->nextNode;
- free(tmpNode->key);
+ if(list->strdupKeys) free(tmpNode->key);
if(((List *)list)->freeDataFunc) {
((List *)list)->freeDataFunc(tmpNode->data);
}
@@ -400,8 +404,8 @@ void quickSort(ListNode ** nodesArray, long start, long end) {
ListNode * pivotNode;
char * pivotKey;
- List * startList = makeList(free);
- List * endList = makeList(free);
+ List * startList = makeList(free, 0);
+ List * endList = makeList(free, 0);
long * startPtr = malloc(sizeof(long));
long * endPtr = malloc(sizeof(long));
*startPtr = start;
diff --git a/src/list.h b/src/list.h
index 86f4a239a..6ea43fbef 100644
--- a/src/list.h
+++ b/src/list.h
@@ -52,6 +52,8 @@ typedef struct _List {
long numberOfNodes;
/* array for searching when list is sorted */
ListNode ** nodesArray;
+ /* weather to strdup() key's on insertion */
+ int strdupKeys;
} List;
/* allocates memory for a new list and initializes it
@@ -59,7 +61,7 @@ typedef struct _List {
* DEFAULT_FREE_DATAFUNC to use free()
* returns pointer to new list if successful, NULL otherwise
*/
-List * makeList(ListFreeDataFunc * freeDataFunc);
+List * makeList(ListFreeDataFunc * freeDataFunc, int strdupKeys);
/* inserts a node into _list_ with _key_ and _data_
* _list_ -> list the data will be inserted in
diff --git a/src/ls.c b/src/ls.c
index c0ff6e87c..1220d370c 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -152,7 +152,7 @@ int lsPlaylists(FILE * fp, char * utf8path) {
strncpy(s+actlen,ent->d_name,maxlen);
if(stat(s,&st)==0) {
if(S_ISREG(st.st_mode)) {
- if(list==NULL) list = makeList(NULL);
+ if(list==NULL) list = makeList(NULL, 1);
dup = strdup(ent->d_name);
dup[suff] = '\0';
if((utf8 = fsCharsetToUtf8(dup))) {
diff --git a/src/permission.c b/src/permission.c
index 5a87f75b1..00b754555 100644
--- a/src/permission.c
+++ b/src/permission.c
@@ -75,7 +75,7 @@ void initPermissions() {
unsigned int * permission;
ConfigParam * param;
- permission_passwords = makeList(free);
+ permission_passwords = makeList(free, 1);
permission_default = PERMISSION_READ | PERMISSION_ADD |
PERMISSION_CONTROL | PERMISSION_ADMIN;
diff --git a/src/song.c b/src/song.c
index 5e35ecb2c..63310b2ff 100644
--- a/src/song.c
+++ b/src/song.c
@@ -86,7 +86,7 @@ void freeJustSong(Song * song) {
}
SongList * newSongList() {
- return makeList((ListFreeDataFunc *)freeSong);
+ return makeList((ListFreeDataFunc *)freeSong, 0);
}
Song * addSongToList(SongList * list, char * url, char * utf8path,
@@ -107,7 +107,7 @@ Song * addSongToList(SongList * list, char * url, char * utf8path,
if(song==NULL) return NULL;
- insertInList(list, url, (void *)song);
+ insertInList(list, song->url, (void *)song);
return song;
}
@@ -174,7 +174,7 @@ void insertSongIntoList(SongList * list, ListNode ** nextSongNode, char * key,
}
if(!(*nextSongNode)) {
- insertInList(list,key,(void *)song);
+ insertInList(list, song->url, (void *)song);
}
else if(cmpRet == 0) {
Song * tempSong = (Song *)((*nextSongNode)->data);
@@ -188,7 +188,8 @@ void insertSongIntoList(SongList * list, ListNode ** nextSongNode, char * key,
*nextSongNode = (*nextSongNode)->nextNode;
}
else {
- insertInListBeforeNode(list,*nextSongNode,key,(void *)song);
+ insertInListBeforeNode(list, *nextSongNode, song->url,
+ (void *)song);
}
}
diff --git a/src/tagTracker.c b/src/tagTracker.c
index 30ae7641b..1fe599d79 100644
--- a/src/tagTracker.c
+++ b/src/tagTracker.c
@@ -27,7 +27,7 @@ char * getTagItemString(int type, char * string) {
if(type == TAG_ITEM_TITLE) return strdup(string);
if(tagLists[type] == NULL) {
- tagLists[type] = makeList(free);
+ tagLists[type] = makeList(free, 1);
}
if((node = findNodeInList(tagLists[type], string))) {