Index: library.c =================================================================== --- library.c (revision 3268) +++ library.c (revision 3269) @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include @@ -50,3 +52,42 @@ free(path); return rp; } + +void csch_lib_fs_map(rnd_hidlib_t *hl, csch_lib_backend_t *be, csch_lib_t *parent, gds_t *path, csch_lib_type_t (*type_cb)(rnd_hidlib_t *, const char *fn)) +{ + DIR *dir; + struct dirent *de; + long save = path->used, restore; + csch_lib_t *newent; + + dir = rnd_opendir(hl, path->array); + if (dir == NULL) + return; + + gds_append(path, '/'); + restore = path->used; + + while((de = rnd_readdir(dir)) != NULL) { + if (*de->d_name == '.') continue; + + gds_append_str(path, de->d_name); + + if (rnd_is_dir(hl, path->array)) { + newent = csch_lib_alloc_append(be, parent, rnd_strdup(de->d_name), CSCH_SLIB_DIR); + csch_lib_fs_map(hl, be, newent, path, type_cb); + } + else { + csch_lib_type_t type = type_cb(hl, path->array); + if (type != CSCH_SLIB_invalid) + newent = csch_lib_alloc_append(be, parent, rnd_strdup(de->d_name), type); + else + newent = NULL; + } + if (newent != NULL) + newent->realpath = rnd_strdup(path->array); + path->used = restore; + } + + path->used = save; + rnd_closedir(dir); +}