gboolean file_visible_in_filter(Tfilter * filter, const gchar * mime_type, const gchar * filename) { DEBUG_MSG("file_visible_in_filter, filter=%p, mime_type=%s, filename=%s\n", filter, mime_type, filename); if (filter) { return (((mime_type && filter->filetypes && GPOINTER_TO_INT(g_hash_table_lookup(filter->filetypes, mime_type))) || (filter->patterns && filename && filename_match(filter, filename))) ? filter->mode : !filter->mode); } return TRUE; }
TCOD_list_t TCOD_sys_get_directory_content(const char *path, const char *pattern) { TCOD_list_t list=TCOD_list_new(); #ifdef TCOD_WINDOWS WIN32_FIND_DATA FileData; HANDLE hList; char dname[ 512 ]; sprintf(dname, "%s\\*",path); hList = FindFirstFile(dname, &FileData); if (hList == INVALID_HANDLE_VALUE) { return list; } do { if ( ! (strcmp(FileData.cFileName,".") == 0 || strcmp(FileData.cFileName,"..") == 0 ) ) { if ( filename_match(FileData.cFileName,pattern) ) TCOD_list_push(list,TCOD_strdup(FileData.cFileName)); } } while ( FindNextFile(hList, &FileData) ); FindClose(hList); #else DIR *dir = opendir(path); struct dirent *dirent = NULL; if ( ! dir ) return list; while ( ( dirent = readdir(dir) ) ) { if ( ! (strcmp(dirent->d_name,".") == 0 || strcmp(dirent->d_name,"..") == 0 ) ) { if ( filename_match(dirent->d_name,pattern) ) TCOD_list_push(list,strdup(dirent->d_name)); } } closedir(dir); #endif return list; }