From 98e84c9120946b10bad831d3fb75fb40a9b0e771 Mon Sep 17 00:00:00 2001 From: ketmar Date: Fri, 4 Jul 2014 00:47:25 +0000 Subject: [PATCH] driver: don't list specials that was appeared in path FossilOrigin-Name: 1d983f9dc59b7f96f4bcaa28cbf1decdf5e27e8f2b672fdb4f1de6f67b49ae98 --- src/search.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/search.c b/src/search.c index 4a8f080..4a36df6 100644 --- a/src/search.c +++ b/src/search.c @@ -217,6 +217,17 @@ static inline int zdifsign (uint32_t n0, uint32_t n1) { } +static inline int has_dir (const char *path, const char *dir) { + int dlen = strlen(dir); + for (;;) { + const char *p = strstr(path, dir); + if (p == NULL) return 0; + if ((p == path || p[-1] == '/') && (p[dlen] == '/' || p[dlen] == 0)) return 1; + path = p+dlen; + } +} + + // /tag/tag/tag/ // /:artist/name/:album/name/ static dirinfo_t *list_dir_simple (const char *path) { @@ -279,20 +290,30 @@ static dirinfo_t *list_dir_simple (const char *path) { } } // + char has_flags[ARRAYLEN(spec_dirs)]; + int spdcnt = 0; + for (int f = 0; f < ARRAYLEN(spec_dirs); ++f) has_flags[f] = has_dir(path, spec_dirs[f].name); + // album, oalbum, year + if (has_flags[1] || has_flags[3] || has_flags[5]) has_flags[1] = has_flags[3] = has_flags[5] = 1; + for (int f = 0; f < ARRAYLEN(spec_dirs); ++f) if (!has_flags[f]) ++spdcnt; + // di = calloc(1, sizeof(*di)); // if (strcmp(path, "/") == 0 || strcmp(path, "/:ttags") == 0 || strcmp(path, "/:otags/:ttags") == 0) { doroot: // wow! list ALL TAGS here! di = calloc(1, sizeof(*di)); - di->fcount = t_tag_count+ARRAYLEN(spec_dirs)+2; + di->fcount = t_tag_count+spdcnt+2; di->items = calloc(di->fcount, sizeof(di->items[0])); // di->items[pos++].name = ":files"; di->items[pos++].name = ":otags"; // - for (int f = 0; f < ARRAYLEN(spec_dirs); ++f) if (spec_dirs[f].type == SPT_TRANS || spec_dirs[f].type == SPT_ANY) { - di->items[pos++].name = spec_dirs[f].name; + for (int f = 0; f < ARRAYLEN(spec_dirs); ++f) { + if (has_flags[f]) continue; + if (spec_dirs[f].type == SPT_TRANS || spec_dirs[f].type == SPT_ANY) { + di->items[pos++].name = spec_dirs[f].name; + } } for (uint32_t f = 0; f < t_tag_count; ++f) { if (get_str(get_tv(taglistt_data[f])->value)[0] == 0) { @@ -315,14 +336,17 @@ doroot: if (strcmp(path, "/:otags") == 0 || strcmp(path, "/:otags/:ttags") == 0) { // wow! list ALL TAGS here! di = calloc(1, sizeof(*di)); - di->fcount = o_tag_count+ARRAYLEN(spec_dirs)+2; + di->fcount = o_tag_count+spdcnt+2; di->items = calloc(di->fcount, sizeof(di->items[0])); // di->items[pos++].name = ":files"; di->items[pos++].name = ":ttags"; // - for (int f = 0; f < ARRAYLEN(spec_dirs); ++f) if (spec_dirs[f].type == SPT_ORIG || spec_dirs[f].type == SPT_ANY) { - di->items[pos++].name = spec_dirs[f].name; + for (int f = 0; f < ARRAYLEN(spec_dirs); ++f) { + if (has_flags[f]) continue; + if (spec_dirs[f].type == SPT_ORIG || spec_dirs[f].type == SPT_ANY) { + di->items[pos++].name = spec_dirs[f].name; + } } for (uint32_t f = 0; f < o_tag_count; ++f) di->items[pos++].name = get_str(get_tv(taglisto_data[f])->value); di->fcount = pos; @@ -425,7 +449,7 @@ doroot: ++di->fcount; // :files if (!onlyfiles) { // specials - di->fcount += ARRAYLEN(spec_dirs); + di->fcount += spdcnt; if (sdi == NULL) { // path ends with tag value // build tag list @@ -486,6 +510,7 @@ doroot: // specials di->items[pos++].name = ":files"; for (size_t f = 0; f < ARRAYLEN(spec_dirs); ++f) { + if (has_flags[f]) continue; if (sptype == SPT_ANY || spec_dirs[f].type == SPT_ANY || spec_dirs[f].type == sptype) { di->items[pos++].name = spec_dirs[f].name; } -- 2.11.4.GIT