diff options
author | Avuton Olrich <avuton@gmail.com> | 2006-07-20 16:02:40 +0000 |
---|---|---|
committer | Avuton Olrich <avuton@gmail.com> | 2006-07-20 16:02:40 +0000 |
commit | 29a25b9933b32800f58dd73d5d1fc21993071c92 (patch) | |
tree | 4f456a6f8e44d42acc289c35534ea3e59c0aa96f /src/dbUtils.c | |
parent | 099f0e103f7591eef81183292d704b3a77a99018 (diff) | |
download | mpd-29a25b9933b32800f58dd73d5d1fc21993071c92.tar.gz mpd-29a25b9933b32800f58dd73d5d1fc21993071c92.tar.xz mpd-29a25b9933b32800f58dd73d5d1fc21993071c92.zip |
Add mpd-indent.sh
Indent the entire tree, hopefully we can keep
it indented.
git-svn-id: https://svn.musicpd.org/mpd/trunk@4410 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/dbUtils.c')
-rw-r--r-- | src/dbUtils.c | 324 |
1 files changed, 180 insertions, 144 deletions
diff --git a/src/dbUtils.c b/src/dbUtils.c index 0a19ff60d..9d2d993e2 100644 --- a/src/dbUtils.c +++ b/src/dbUtils.c @@ -31,52 +31,54 @@ #define LOCATE_TAG_ANY_TYPE TAG_NUM_OF_ITEM_TYPES+20 #define LOCATE_TAG_ANY_KEY "any" - typedef struct _ListCommandItem { mpd_sint8 tagType; int numConditionals; - LocateTagItem * conditionals; + LocateTagItem *conditionals; } ListCommandItem; typedef struct _LocateTagItemArray { int numItems; - LocateTagItem * items; + LocateTagItem *items; } LocateTagItemArray; -int getLocateTagItemType(char * str) { +int getLocateTagItemType(char *str) +{ int i; - if(0 == strcasecmp(str, LOCATE_TAG_FILE_KEY)) { + if (0 == strcasecmp(str, LOCATE_TAG_FILE_KEY)) { return LOCATE_TAG_FILE_TYPE; } - if(0 == strcasecmp(str, LOCATE_TAG_ANY_KEY)) { - return LOCATE_TAG_ANY_TYPE; + if (0 == strcasecmp(str, LOCATE_TAG_ANY_KEY)) { + return LOCATE_TAG_ANY_TYPE; } - - for(i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++) { - if(0 == strcasecmp(str, mpdTagItemKeys[i])) return i; + + for (i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++) { + if (0 == strcasecmp(str, mpdTagItemKeys[i])) + return i; } return -1; } -static int initLocateTagItem(LocateTagItem * item, char * typeStr, - char * needle) +static int initLocateTagItem(LocateTagItem * item, char *typeStr, char *needle) { item->tagType = getLocateTagItemType(typeStr); - if(item->tagType < 0) return -1; + if (item->tagType < 0) + return -1; item->needle = strdup(needle); return 0; } -LocateTagItem * newLocateTagItem(char * typeStr, char * needle) { - LocateTagItem * ret = malloc(sizeof(LocateTagItem)); +LocateTagItem *newLocateTagItem(char *typeStr, char *needle) +{ + LocateTagItem *ret = malloc(sizeof(LocateTagItem)); - if(initLocateTagItem(ret, typeStr, needle) < 0) { + if (initLocateTagItem(ret, typeStr, needle) < 0) { free(ret); ret = NULL; } @@ -84,36 +86,40 @@ LocateTagItem * newLocateTagItem(char * typeStr, char * needle) { return ret; } -void freeLocateTagItemArray(int count, LocateTagItem * array) { +void freeLocateTagItemArray(int count, LocateTagItem * array) +{ int i; - - for(i = 0; i < count; i++) free(array[i].needle); + + for (i = 0; i < count; i++) + free(array[i].needle); free(array); } -int newLocateTagItemArrayFromArgArray(char * argArray[], - int numArgs, - LocateTagItem ** arrayRet) +int newLocateTagItemArrayFromArgArray(char *argArray[], + int numArgs, LocateTagItem ** arrayRet) { - int i,j; - LocateTagItem * item; - - if(numArgs == 0) return 0; + int i, j; + LocateTagItem *item; - if(numArgs%2 != 0) return -1; - - *arrayRet = malloc(sizeof(LocateTagItem)*numArgs/2); + if (numArgs == 0) + return 0; - for(i = 0, item = *arrayRet; i < numArgs/2; i++, item++) { - if(initLocateTagItem(item, argArray[i*2], argArray[i*2+1]) < 0) + if (numArgs % 2 != 0) + return -1; + + *arrayRet = malloc(sizeof(LocateTagItem) * numArgs / 2); + + for (i = 0, item = *arrayRet; i < numArgs / 2; i++, item++) { + if (initLocateTagItem + (item, argArray[i * 2], argArray[i * 2 + 1]) < 0) goto fail; } - return numArgs/2; + return numArgs / 2; -fail: - for(j = 0; j < i; j++) { + fail: + for (j = 0; j < i; j++) { free((*arrayRet)[j].needle); } @@ -122,70 +128,78 @@ fail: return -1; } -void freeLocateTagItem(LocateTagItem * item) { +void freeLocateTagItem(LocateTagItem * item) +{ free(item->needle); free(item); } -static int countSongsInDirectory(FILE * fp, Directory * directory, void * data) { - int * count = (int *)data; +static int countSongsInDirectory(FILE * fp, Directory * directory, void *data) +{ + int *count = (int *)data; + + *count += directory->songs->numberOfNodes; - *count+=directory->songs->numberOfNodes; - - return 0; + return 0; } -static int printDirectoryInDirectory(FILE * fp, Directory * directory, void * data) { - if(directory->path) { - myfprintf(fp,"directory: %s\n", getDirectoryPath(directory)); +static int printDirectoryInDirectory(FILE * fp, Directory * directory, + void *data) +{ + if (directory->path) { + myfprintf(fp, "directory: %s\n", getDirectoryPath(directory)); } - return 0; + return 0; } -static int printSongInDirectory(FILE * fp, Song * song, void * data) { +static int printSongInDirectory(FILE * fp, Song * song, void *data) +{ printSongUrl(fp, song); - return 0; + return 0; } -static int strstrSearchTag(Song * song, int type, char * str) { +static int strstrSearchTag(Song * song, int type, char *str) +{ int i; - char * dup; + char *dup; int ret = 0; - if(type == LOCATE_TAG_FILE_TYPE || type == LOCATE_TAG_ANY_TYPE) { + if (type == LOCATE_TAG_FILE_TYPE || type == LOCATE_TAG_ANY_TYPE) { dup = strDupToUpper(getSongUrl(song)); - if(strstr(dup, str)) ret = 1; + if (strstr(dup, str)) + ret = 1; free(dup); if (ret == 1 || type == LOCATE_TAG_FILE_TYPE) { return ret; } } - if(!song->tag) return 0; + if (!song->tag) + return 0; - for(i = 0; i < song->tag->numOfItems && !ret; i++) { - if(type != LOCATE_TAG_ANY_TYPE && - song->tag->items[i].type != type) - { - continue; + for (i = 0; i < song->tag->numOfItems && !ret; i++) { + if (type != LOCATE_TAG_ANY_TYPE && + song->tag->items[i].type != type) { + continue; } - + dup = strDupToUpper(song->tag->items[i].value); - if(strstr(dup, str)) ret = 1; + if (strstr(dup, str)) + ret = 1; free(dup); } return ret; } -static int searchInDirectory(FILE * fp, Song * song, void * data) { - LocateTagItemArray * array = data; +static int searchInDirectory(FILE * fp, Song * song, void *data) +{ + LocateTagItemArray *array = data; int i; - for(i = 0; i < array->numItems; i++) { - if(!strstrSearchTag(song, array->items[i].tagType, - array->items[i].needle)) - { + for (i = 0; i < array->numItems; i++) { + if (!strstrSearchTag(song, array->items[i].tagType, + array->items[i].needle)) { return 0; } } @@ -195,16 +209,15 @@ static int searchInDirectory(FILE * fp, Song * song, void * data) { return 0; } -int searchForSongsIn(FILE * fp, char * name, int numItems, - LocateTagItem * items) +int searchForSongsIn(FILE * fp, char *name, int numItems, LocateTagItem * items) { int ret = -1; int i; - char ** originalNeedles = malloc(numItems*sizeof(char *)); + char **originalNeedles = malloc(numItems * sizeof(char *)); LocateTagItemArray array; - for(i = 0; i < numItems; i++) { + for (i = 0; i < numItems; i++) { originalNeedles[i] = items[i].needle; items[i].needle = strDupToUpper(originalNeedles[i]); } @@ -212,9 +225,9 @@ int searchForSongsIn(FILE * fp, char * name, int numItems, array.numItems = numItems; array.items = items; - ret = traverseAllIn(fp,name,searchInDirectory, NULL, &array); + ret = traverseAllIn(fp, name, searchInDirectory, NULL, &array); - for(i = 0; i < numItems; i++) { + for (i = 0; i < numItems; i++) { free(items[i].needle); items[i].needle = originalNeedles[i]; } @@ -224,32 +237,37 @@ int searchForSongsIn(FILE * fp, char * name, int numItems, return ret; } -static int tagItemFoundAndMatches(Song * song, int type, char * str) { +static int tagItemFoundAndMatches(Song * song, int type, char *str) +{ int i; - if(type == LOCATE_TAG_FILE_TYPE) { - if(0 == strcmp(str, getSongUrl(song))) return 1; + if (type == LOCATE_TAG_FILE_TYPE) { + if (0 == strcmp(str, getSongUrl(song))) + return 1; } - if(!song->tag) return 0; + if (!song->tag) + return 0; - for(i = 0; i < song->tag->numOfItems; i++) { - if(song->tag->items[i].type != type) continue; - - if(0 == strcmp(str, song->tag->items[i].value)) return 1; + for (i = 0; i < song->tag->numOfItems; i++) { + if (song->tag->items[i].type != type) + continue; + + if (0 == strcmp(str, song->tag->items[i].value)) + return 1; } return 0; } -static int findInDirectory(FILE * fp, Song * song, void * data) { - LocateTagItemArray * array = data; +static int findInDirectory(FILE * fp, Song * song, void *data) +{ + LocateTagItemArray *array = data; int i; - for(i = 0; i < array->numItems; i++) { - if(!tagItemFoundAndMatches(song, array->items[i].tagType, - array->items[i].needle)) - { + for (i = 0; i < array->numItems; i++) { + if (!tagItemFoundAndMatches(song, array->items[i].tagType, + array->items[i].needle)) { return 0; } } @@ -259,67 +277,77 @@ static int findInDirectory(FILE * fp, Song * song, void * data) { return 0; } -int findSongsIn(FILE * fp, char * name, int numItems, LocateTagItem * items) { +int findSongsIn(FILE * fp, char *name, int numItems, LocateTagItem * items) +{ LocateTagItemArray array; array.numItems = numItems; array.items = items; - - return traverseAllIn(fp, name, findInDirectory, NULL, - (void *)&array); + + return traverseAllIn(fp, name, findInDirectory, NULL, (void *)&array); } -int printAllIn(FILE * fp, char * name) { - return traverseAllIn(fp,name,printSongInDirectory, - printDirectoryInDirectory,NULL); +int printAllIn(FILE * fp, char *name) +{ + return traverseAllIn(fp, name, printSongInDirectory, + printDirectoryInDirectory, NULL); } -static int directoryAddSongToPlaylist(FILE * fp, Song * song, void * data) { +static int directoryAddSongToPlaylist(FILE * fp, Song * song, void *data) +{ return addSongToPlaylist(fp, song, 0); } -int addAllIn(FILE * fp, char * name) { - return traverseAllIn(fp,name,directoryAddSongToPlaylist,NULL,NULL); +int addAllIn(FILE * fp, char *name) +{ + return traverseAllIn(fp, name, directoryAddSongToPlaylist, NULL, NULL); } -static int directoryPrintSongInfo(FILE * fp, Song * song, void * data) { - return printSongInfo(fp,song); +static int directoryPrintSongInfo(FILE * fp, Song * song, void *data) +{ + return printSongInfo(fp, song); } -static int sumSongTime(FILE * fp, Song * song, void * data) { - unsigned long * time = (unsigned long *)data; +static int sumSongTime(FILE * fp, Song * song, void *data) +{ + unsigned long *time = (unsigned long *)data; - if(song->tag && song->tag->time>=0) *time+=song->tag->time; + if (song->tag && song->tag->time >= 0) + *time += song->tag->time; return 0; } -int printInfoForAllIn(FILE * fp, char * name) { - return traverseAllIn(fp,name,directoryPrintSongInfo,printDirectoryInDirectory,NULL); +int printInfoForAllIn(FILE * fp, char *name) +{ + return traverseAllIn(fp, name, directoryPrintSongInfo, + printDirectoryInDirectory, NULL); } -int countSongsIn(FILE * fp, char * name) { +int countSongsIn(FILE * fp, char *name) +{ int count = 0; - void * ptr = (void *)&count; - - traverseAllIn(fp,name,NULL,countSongsInDirectory,ptr); + void *ptr = (void *)&count; + + traverseAllIn(fp, name, NULL, countSongsInDirectory, ptr); return count; } -unsigned long sumSongTimesIn(FILE * fp, char * name) { +unsigned long sumSongTimesIn(FILE * fp, char *name) +{ unsigned long dbPlayTime = 0; - void * ptr = (void *)&dbPlayTime; - - traverseAllIn(fp,name,sumSongTime,NULL,ptr); + void *ptr = (void *)&dbPlayTime; + + traverseAllIn(fp, name, sumSongTime, NULL, ptr); return dbPlayTime; } -static ListCommandItem * newListCommandItem(int tagType, int numConditionals, - LocateTagItem * conditionals) +static ListCommandItem *newListCommandItem(int tagType, int numConditionals, + LocateTagItem * conditionals) { - ListCommandItem * item = malloc(sizeof(ListCommandItem)); + ListCommandItem *item = malloc(sizeof(ListCommandItem)); item->tagType = tagType; item->numConditionals = numConditionals; @@ -328,36 +356,39 @@ static ListCommandItem * newListCommandItem(int tagType, int numConditionals, return item; } -static void freeListCommandItem(ListCommandItem * item) { +static void freeListCommandItem(ListCommandItem * item) +{ free(item); } -static void visitTag(FILE * fp, Song * song, int tagType) { +static void visitTag(FILE * fp, Song * song, int tagType) +{ int i; - MpdTag * tag = song->tag; + MpdTag *tag = song->tag; - if(tagType == LOCATE_TAG_FILE_TYPE) { + if (tagType == LOCATE_TAG_FILE_TYPE) { printSongUrl(fp, song); return; } - if(!tag) return; + if (!tag) + return; - for(i = 0; i < tag->numOfItems; i++) { - if(tag->items[i].type == tagType) { + for (i = 0; i < tag->numOfItems; i++) { + if (tag->items[i].type == tagType) { visitInTagTracker(tagType, tag->items[i].value); } } } -static int listUniqueTagsInDirectory(FILE * fp, Song * song, void * data) { - ListCommandItem * item = data; +static int listUniqueTagsInDirectory(FILE * fp, Song * song, void *data) +{ + ListCommandItem *item = data; int i; - for(i = 0; i < item->numConditionals; i++) { - if(!tagItemFoundAndMatches(song, item->conditionals[i].tagType, - item->conditionals[i].needle)) - { + for (i = 0; i < item->numConditionals; i++) { + if (!tagItemFoundAndMatches(song, item->conditionals[i].tagType, + item->conditionals[i].needle)) { return 0; } } @@ -367,21 +398,21 @@ static int listUniqueTagsInDirectory(FILE * fp, Song * song, void * data) { return 0; } -int listAllUniqueTags(FILE * fp, int type, int numConditionals, - LocateTagItem * conditionals) +int listAllUniqueTags(FILE * fp, int type, int numConditionals, + LocateTagItem * conditionals) { int ret; - ListCommandItem * item = newListCommandItem(type, numConditionals, - conditionals); - - if(type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) { + ListCommandItem *item = newListCommandItem(type, numConditionals, + conditionals); + + if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) { resetVisitedFlagsInTagTracker(type); } ret = traverseAllIn(fp, NULL, listUniqueTagsInDirectory, NULL, - (void *)item); + (void *)item); - if(type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) { + if (type >= 0 && type <= TAG_NUM_OF_ITEM_TYPES) { printVisitedInTagTracker(fp, type); } @@ -390,30 +421,35 @@ int listAllUniqueTags(FILE * fp, int type, int numConditionals, return ret; } -static int sumSavedFilenameMemoryInDirectory(FILE * fp, Directory * dir, void * data) { - int * sum = data; +static int sumSavedFilenameMemoryInDirectory(FILE * fp, Directory * dir, + void *data) +{ + int *sum = data; - if(!dir->path) return 0; + if (!dir->path) + return 0; - *sum += (strlen(getDirectoryPath(dir))+1-sizeof(Directory *))* - dir->songs->numberOfNodes; + *sum += (strlen(getDirectoryPath(dir)) + 1 - sizeof(Directory *)) * + dir->songs->numberOfNodes; return 0; } -static int sumSavedFilenameMemoryInSong(FILE * fp, Song * song, void * data) { - int * sum = data; +static int sumSavedFilenameMemoryInSong(FILE * fp, Song * song, void *data) +{ + int *sum = data; + + *sum += strlen(song->url) + 1; - *sum += strlen(song->url)+1; - return 0; } -void printSavedMemoryFromFilenames(void) { +void printSavedMemoryFromFilenames(void) +{ int sum = 0; traverseAllIn(stderr, NULL, sumSavedFilenameMemoryInSong, - sumSavedFilenameMemoryInDirectory, (void *)&sum); + sumSavedFilenameMemoryInDirectory, (void *)&sum); DEBUG("saved memory from filenames: %i\n", sum); } |