new utility function BLI_testextensie_glob
uses fnmatch to match strings like "*.foo;*.bar;*.blend?"
This commit is contained in:
@@ -100,6 +100,7 @@ int BKE_rebase_path(char *abs, int abs_size, char *rel, int rel_size, const char
|
||||
void BLI_getlastdir(const char* dir, char *last, int maxlen);
|
||||
int BLI_testextensie(const char *str, const char *ext);
|
||||
int BLI_testextensie_array(const char *str, const char **ext_array);
|
||||
int BLI_testextensie_glob(const char *str, const char *ext_fnmatch);
|
||||
int BLI_replace_extension(char *path, int maxlen, const char *ext);
|
||||
void BLI_uniquename(struct ListBase *list, void *vlink, const char defname[], char delim, short name_offs, short len);
|
||||
void BLI_newname(char * name, int add);
|
||||
|
||||
@@ -48,6 +48,12 @@
|
||||
|
||||
#include "GHOST_Path-api.h"
|
||||
|
||||
#if defined WIN32 && !defined _LIBC
|
||||
# include "BLI_fnmatch.h" /* use fnmatch included in blenlib */
|
||||
#else
|
||||
# define _GNU_SOURCE
|
||||
# include <fnmatch.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#include <io.h>
|
||||
@@ -1285,6 +1291,36 @@ int BLI_testextensie_array(const char *str, const char **ext_array)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* semicolon separated wildcards, eg:
|
||||
* '*.zip;*.py;*.exe' */
|
||||
int BLI_testextensie_glob(const char *str, const char *ext_fnmatch)
|
||||
{
|
||||
const char *ext_step= ext_fnmatch;
|
||||
char pattern[16];
|
||||
|
||||
while(ext_step[0]) {
|
||||
char *ext_next;
|
||||
int len_ext;
|
||||
|
||||
if((ext_next=strchr(ext_step, ';'))) {
|
||||
len_ext= (int)(ext_next - ext_step) + 1;
|
||||
}
|
||||
else {
|
||||
len_ext= sizeof(pattern);
|
||||
}
|
||||
|
||||
BLI_strncpy(pattern, ext_step, len_ext);
|
||||
|
||||
if(fnmatch(pattern, str, FNM_CASEFOLD)==0) {
|
||||
return 1;
|
||||
}
|
||||
ext_step += len_ext;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int BLI_replace_extension(char *path, int maxlen, const char *ext)
|
||||
{
|
||||
int a;
|
||||
|
||||
Reference in New Issue
Block a user