[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32094] trunk/blender/source/blender/ blenlib: new utility function BLI_testextensie_glob
Campbell Barton
ideasman42 at gmail.com
Fri Sep 24 08:20:44 CEST 2010
Revision: 32094
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32094
Author: campbellbarton
Date: 2010-09-24 08:20:43 +0200 (Fri, 24 Sep 2010)
Log Message:
-----------
new utility function BLI_testextensie_glob
uses fnmatch to match strings like "*.foo;*.bar;*.blend?"
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_path_util.h
trunk/blender/source/blender/blenlib/intern/path_util.c
Modified: trunk/blender/source/blender/blenlib/BLI_path_util.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_path_util.h 2010-09-24 03:48:26 UTC (rev 32093)
+++ trunk/blender/source/blender/blenlib/BLI_path_util.h 2010-09-24 06:20:43 UTC (rev 32094)
@@ -100,6 +100,7 @@
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);
Modified: trunk/blender/source/blender/blenlib/intern/path_util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/path_util.c 2010-09-24 03:48:26 UTC (rev 32093)
+++ trunk/blender/source/blender/blenlib/intern/path_util.c 2010-09-24 06:20:43 UTC (rev 32094)
@@ -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 @@
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;
More information about the Bf-blender-cvs
mailing list