diff options
author | Warren Dukes <warren.dukes@gmail.com> | 2004-11-12 01:44:27 +0000 |
---|---|---|
committer | Warren Dukes <warren.dukes@gmail.com> | 2004-11-12 01:44:27 +0000 |
commit | 1f118ea90dd0a22bd40e76a96900ffb36aa93134 (patch) | |
tree | f1600bdb9ef3d4b9f79091f06bfb9f05e7f6a9bb /src/dbUtils.c | |
parent | 18a2d5ab5a5fc005ddd4549807d083cd33f5b98f (diff) | |
download | mpd-1f118ea90dd0a22bd40e76a96900ffb36aa93134.tar.gz mpd-1f118ea90dd0a22bd40e76a96900ffb36aa93134.tar.xz mpd-1f118ea90dd0a22bd40e76a96900ffb36aa93134.zip |
now more flexible list, search, find, where you can enter pairs of
"conditionals". Note that logical and is implied.
git-svn-id: https://svn.musicpd.org/mpd/trunk@2624 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/dbUtils.c')
-rw-r--r-- | src/dbUtils.c | 136 |
1 files changed, 112 insertions, 24 deletions
diff --git a/src/dbUtils.c b/src/dbUtils.c index dd698789c..9c08c8020 100644 --- a/src/dbUtils.c +++ b/src/dbUtils.c @@ -11,12 +11,17 @@ #define LOCATE_TAG_FILE_TYPE TAG_NUM_OF_ITEM_TYPES+10 #define LOCATE_TAG_FILE_KEY "filename" -typedef struct ListCommandItem { +typedef struct _ListCommandItem { mpd_sint8 tagType; int numConditionals; LocateTagItem * conditionals; } ListCommandItem; +typedef struct _LocateTagItemArray { + int numItems; + LocateTagItem * items; +} LocateTagItemArray; + int getLocateTagItemType(char * str) { int i; @@ -31,21 +36,67 @@ int getLocateTagItemType(char * str) { return -1; } +static int initLocateTagItem(LocateTagItem * item, char * typeStr, + char * needle) +{ + item->tagType = getLocateTagItemType(typeStr); + + if(item->tagType < 0) return -1; + + item->needle = strdup(needle); + + return 0; +} + LocateTagItem * newLocateTagItem(char * typeStr, char * needle) { LocateTagItem * ret = malloc(sizeof(LocateTagItem)); - ret->tagType = getLocateTagItemType(typeStr); - - if(ret->tagType < 0) { + if(initLocateTagItem(ret, typeStr, needle) < 0) { free(ret); - return NULL; + ret = NULL; } - ret->needle = strdup(needle); - return ret; } +void freeLocateTagItemArray(int count, LocateTagItem * array) { + int i; + + for(i = 0; i < count; i++) free(array[i].needle); + + free(array); +} + +int newLocateTagItemArrayFromArgArray(char * argArray[], + int numArgs, + LocateTagItem ** arrayRet) +{ + int i,j; + LocateTagItem * item; + + if(numArgs == 0) return 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; + +fail: + for(j = 0; j < i; j++) { + free((*arrayRet)[j].needle); + } + + free(*arrayRet); + *arrayRet = NULL; + return -1; +} + void freeLocateTagItem(LocateTagItem * item) { free(item->needle); free(item); @@ -96,25 +147,48 @@ static inline int strstrSearchTag(Song * song, int type, char * str) { return ret; } -int searchInDirectory(FILE * fp, Song * song, void * item) { - if(strstrSearchTag(song, ((LocateTagItem *)item)->tagType, - ((LocateTagItem *)item)->needle)) { - printSongInfo(fp, song); +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)) + { + return 0; + } } + + printSongInfo(fp, song); + return 0; } -int searchForSongsIn(FILE * fp, char * name, LocateTagItem * item) { - char * originalNeedle = item->needle; +int searchForSongsIn(FILE * fp, char * name, int numItems, + LocateTagItem * items) +{ int ret = -1; + int i; - item->needle = strDupToUpper(originalNeedle); + char ** originalNeedles = malloc(numItems*sizeof(char *)); + LocateTagItemArray array; - ret = traverseAllIn(fp,name,searchInDirectory, NULL, - (void *)item); + for(i = 0; i < numItems; i++) { + originalNeedles[i] = items[i].needle; + items[i].needle = strDupToUpper(originalNeedles[i]); + } - free(item->needle); - item->needle = originalNeedle; + array.numItems = numItems; + array.items = items; + + ret = traverseAllIn(fp,name,searchInDirectory, NULL, &array); + + for(i = 0; i < numItems; i++) { + free(items[i].needle); + items[i].needle = originalNeedles[i]; + } + + free(originalNeedles); return ret; } @@ -137,17 +211,31 @@ static inline int tagItemFoundAndMatches(Song * song, int type, char * str) { return 0; } -int findInDirectory(FILE * fp, Song * song, void * item) { - if(tagItemFoundAndMatches(song, ((LocateTagItem *)item)->tagType, - ((LocateTagItem *)item)->needle)) { - printSongInfo(fp, song); +int findInDirectory(FILE * fp, Song * song, void * data) { + LocateTagItemArray * array = data; + int i; + + for(i = 0; i < 0; i++) { + if(!tagItemFoundAndMatches(song, array->items[i].tagType, + array->items[i].needle)) + { + return 0; + } } + + printSongInfo(fp, song); + return 0; } -int findSongsIn(FILE * fp, char * name, LocateTagItem * item) { +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 *)item); + (void *)&array); } int printAllIn(FILE * fp, char * name) { |