aboutsummaryrefslogtreecommitdiffstats
path: root/src/locate.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-09-29 13:18:49 +0200
committerMax Kellermann <max@duempel.org>2008-09-29 13:18:49 +0200
commita4019f7d2183b3ab6c2bbef68c7a5259326bc973 (patch)
tree906b150c570c89a4cdbc6299e3325cc30e59831c /src/locate.c
parent5f0ed72c489fd1f0b3c38e3608d27966e1f41f88 (diff)
downloadmpd-a4019f7d2183b3ab6c2bbef68c7a5259326bc973.tar.gz
mpd-a4019f7d2183b3ab6c2bbef68c7a5259326bc973.tar.xz
mpd-a4019f7d2183b3ab6c2bbef68c7a5259326bc973.zip
allow searching for albums with an empty tag
tfing wrote: > I have quite some files with an empty album tag as they do not come > from a particular album. > > If I want to look for those files and browse them, this happens: > :: nc localhost 6600 > OK MPD 0.12.0 > find album "" > ACK [2@0] {find} too few arguments for "find" > > I'd like to be able to browse those files in a client like gmpc. > So these 2 items would have to be developed: > - list album should report that some files have an empty tag > - it should be possible to search for an empty tag with the find command Patch-by: Marc Pavot ref: http://musicpd.org/mantis/view.php?id=464
Diffstat (limited to 'src/locate.c')
-rw-r--r--src/locate.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/locate.c b/src/locate.c
index 2e17f7784..b9e1aa810 100644
--- a/src/locate.c
+++ b/src/locate.c
@@ -127,6 +127,7 @@ static int strstrSearchTag(Song * song, enum tag_type type, char *str)
int i;
char *duplicate;
int ret = 0;
+ mpd_sint8 visitedTypes[TAG_NUM_OF_ITEM_TYPES] = { 0 };
if (type == LOCATE_TAG_FILE_TYPE || type == LOCATE_TAG_ANY_TYPE) {
char path_max_tmp[MPD_PATH_MAX];
@@ -142,17 +143,27 @@ static int strstrSearchTag(Song * song, enum tag_type type, char *str)
return 0;
for (i = 0; i < song->tag->numOfItems && !ret; i++) {
+ visitedTypes[song->tag->items[i]->type] = 1;
if (type != LOCATE_TAG_ANY_TYPE &&
song->tag->items[i]->type != type) {
continue;
}
duplicate = strDupToUpper(song->tag->items[i]->value);
- if (strstr(duplicate, str))
+ if (*str && strstr(duplicate, str))
ret = 1;
free(duplicate);
}
+ /** If the search critieron was not visited during the sweep
+ * through the song's tag, it means this field is absent from
+ * the tag or empty. Thus, if the searched string is also
+ * empty (first char is a \0), then it's a match as well and
+ * we should return 1.
+ */
+ if (!*str && !visitedTypes[type])
+ return 1;
+
return ret;
}
@@ -173,6 +184,7 @@ int strstrSearchTags(Song * song, int numItems, LocateTagItem * items)
static int tagItemFoundAndMatches(Song * song, enum tag_type type, char *str)
{
int i;
+ mpd_sint8 visitedTypes[TAG_NUM_OF_ITEM_TYPES] = { 0 };
if (type == LOCATE_TAG_FILE_TYPE || type == LOCATE_TAG_ANY_TYPE) {
char path_max_tmp[MPD_PATH_MAX];
@@ -186,6 +198,7 @@ static int tagItemFoundAndMatches(Song * song, enum tag_type type, char *str)
return 0;
for (i = 0; i < song->tag->numOfItems; i++) {
+ visitedTypes[song->tag->items[i]->type] = 1;
if (type != LOCATE_TAG_ANY_TYPE &&
song->tag->items[i]->type != type) {
continue;
@@ -195,6 +208,15 @@ static int tagItemFoundAndMatches(Song * song, enum tag_type type, char *str)
return 1;
}
+ /** If the search critieron was not visited during the sweep
+ * through the song's tag, it means this field is absent from
+ * the tag or empty. Thus, if the searched string is also
+ * empty (first char is a \0), then it's a match as well and
+ * we should return 1.
+ */
+ if (!*str && !visitedTypes[type])
+ return 1;
+
return 0;
}