-static int compare_track_for_qsort(const void *a, const void *b) {
- return compare_path(*(char **)a, *(char **)b);
-}
-
-/* Return true iff FILE is a child of DIR */
-static int is_child(const char *dir, const char *file) {
- const size_t dlen = strlen(dir);
-
- return (!strncmp(file, dir, dlen)
- && file[dlen] == '/'
- && strchr(file + dlen + 1, '/') == 0);
-}
-
-/* Return true iff FILE is a descendant of DIR */
-static int is_descendant(const char *dir, const char *file) {
- const size_t dlen = strlen(dir);
-
- return !strncmp(file, dir, dlen) && file[dlen] == '/';
-}
-
-/* Called to fill a node in the search results tree */
-static void fill_search_node(struct choosenode *cn) {
- int n;
- const size_t plen = strlen(cn->path);
- const char *s;
- char *dir, *last = 0;
-
- D(("fill_search_node %s", cn->path));
- /* We depend on the search results being sorted as by compare_path(). */
- cn->children.nvec = 0;
- for(n = 0; n < nsearchresults; ++n) {
- /* We only care about descendants of CN */
- if(!is_descendant(cn->path, searchresults[n]))
- continue;
- s = strchr(searchresults[n] + plen + 1, '/');
- if(s) {
- /* We've identified a subdirectory of CN. */
- dir = xstrndup(searchresults[n], s - searchresults[n]);
- if(!last || strcmp(dir, last)) {
- /* Not a duplicate */
- last = dir;
- newnode(cn, dir,
- trackname_transform("dir", dir, "display"),
- trackname_transform("dir", dir, "sort"),
- CN_EXPANDABLE, fill_search_node);
- }
- } else {
- /* We've identified a file in CN */
- newnode(cn, searchresults[n],
- trackname_transform("track", searchresults[n], "display"),
- trackname_transform("track", searchresults[n], "sort"),
- 0/*flags*/, 0/*fill*/);
- }
- }
- updated_node(cn, 1);