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
This commit is contained in:
Warren Dukes 2004-11-11 02:59:16 +00:00
parent 4ec3df0339
commit d6a87f538d
13 changed files with 57 additions and 37 deletions

View File

@ -24,7 +24,7 @@ void unloadAudioOutputPlugin(AudioOutputPlugin * audioOutputPlugin) {
}
void initAudioOutputPlugins() {
audioOutputPluginList = makeList(NULL);
audioOutputPluginList = makeList(NULL, 0);
}
void finishAudioOutputPlugins() {

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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;

View File

@ -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);

View File

@ -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 */

View File

@ -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;

View File

@ -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

View File

@ -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))) {

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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))) {