[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49804] branches/asset-browser/source/ blender: blenlib cleanup:

Andrea Weikert elubie at gmx.net
Sat Aug 11 15:41:59 CEST 2012


Revision: 49804
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49804
Author:   elubie
Date:     2012-08-11 13:41:59 +0000 (Sat, 11 Aug 2012)
Log Message:
-----------
blenlib cleanup:
* moved directory functions into own file 

Modified Paths:
--------------
    branches/asset-browser/source/blender/blenlib/BLI_fileops.h
    branches/asset-browser/source/blender/blenlib/BLI_string.h
    branches/asset-browser/source/blender/blenlib/CMakeLists.txt
    branches/asset-browser/source/blender/blenlib/intern/path_util.c
    branches/asset-browser/source/blender/blenlib/intern/storage.c
    branches/asset-browser/source/blender/editors/interface/interface_icons.c
    branches/asset-browser/source/blender/editors/interface/interface_ops.c
    branches/asset-browser/source/blender/editors/space_buttons/buttons_ops.c
    branches/asset-browser/source/blender/editors/space_file/file_ops.c
    branches/asset-browser/source/blender/editors/space_file/filelist.c
    branches/asset-browser/source/blender/editors/space_file/filesel.c
    branches/asset-browser/source/blender/imbuf/intern/thumbs.c

Added Paths:
-----------
    branches/asset-browser/source/blender/blenlib/BLI_directory.h
    branches/asset-browser/source/blender/blenlib/intern/directory.c

Added: branches/asset-browser/source/blender/blenlib/BLI_directory.h
===================================================================
--- branches/asset-browser/source/blender/blenlib/BLI_directory.h	                        (rev 0)
+++ branches/asset-browser/source/blender/blenlib/BLI_directory.h	2012-08-11 13:41:59 UTC (rev 49804)
@@ -0,0 +1,69 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Blender Foundation, Andrea Weikert.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file BLI_directory.h
+ *  \ingroup bli
+ *  \brief File and directory operations.
+ * */
+
+#ifndef __BLI_DIRECTORY_H__
+#define __BLI_DIRECTORY_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Directories */
+
+/* returns 1 if the given path is a directory, 0 otherwise */
+int    BLI_is_dir(const char *path);
+
+/** returns 1 if the given path exists and is not a directiry */
+int    BLI_is_file(const char *path);
+
+/** recursively create all directories for the given path */
+void   BLI_dir_create_recursive(const char *dir);
+
+/** @return the amount of available space on disk */
+double BLI_dir_free_space(const char *dir);
+
+/** @return the current working dir of the user */
+char  *BLI_current_working_dir(char *dir, const size_t maxlen);
+
+/* --- directory reading ---  */
+
+/* allocates memory that needs to be freed once struct direntry **files is no longer needed 
+   use BLI_dir_dispose for this! */
+void BLI_dir_contents(const char *dirname, struct direntry **files, int *num_files);
+void BLI_dir_dispose(struct direntry *filelist, unsigned int num_files);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+


Property changes on: branches/asset-browser/source/blender/blenlib/BLI_directory.h
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: branches/asset-browser/source/blender/blenlib/BLI_fileops.h
===================================================================
--- branches/asset-browser/source/blender/blenlib/BLI_fileops.h	2012-08-11 13:32:19 UTC (rev 49803)
+++ branches/asset-browser/source/blender/blenlib/BLI_fileops.h	2012-08-11 13:41:59 UTC (rev 49804)
@@ -59,19 +59,8 @@
 
 /* Directories */
 
-struct direntry;
+/* moved to BLI_directory.h ! */
 
-int    BLI_is_dir(const char *path);
-int    BLI_is_file(const char *path);
-void   BLI_dir_create_recursive(const char *dir);
-double BLI_dir_free_space(const char *dir);
-char  *BLI_current_working_dir(char *dir, const size_t maxlen);
-
-/* allocates memory that needs to be freed once struct direntry **files is no longer needed 
-   use BLI_dir_dispose for this! */
-void BLI_dir_contents(const char *dirname, struct direntry **files, int* num_files);
-void BLI_dir_dispose(struct direntry *filelist, unsigned int num_files);
-
 /* Files */
 
 FILE  *BLI_fopen(const char *filename, const char *mode);

Modified: branches/asset-browser/source/blender/blenlib/BLI_string.h
===================================================================
--- branches/asset-browser/source/blender/blenlib/BLI_string.h	2012-08-11 13:32:19 UTC (rev 49803)
+++ branches/asset-browser/source/blender/blenlib/BLI_string.h	2012-08-11 13:41:59 UTC (rev 49804)
@@ -31,6 +31,7 @@
 /** \file BLI_string.h
  *  \ingroup bli
  */
+#include <stdlib.h>
 
 #ifdef __cplusplus
 extern "C" {

Modified: branches/asset-browser/source/blender/blenlib/CMakeLists.txt
===================================================================
--- branches/asset-browser/source/blender/blenlib/CMakeLists.txt	2012-08-11 13:32:19 UTC (rev 49803)
+++ branches/asset-browser/source/blender/blenlib/CMakeLists.txt	2012-08-11 13:41:59 UTC (rev 49804)
@@ -54,6 +54,7 @@
 	intern/bpath.c
 	intern/callbacks.c
 	intern/cpu.c
+	intern/directory.c
 	intern/dynlib.c
 	intern/edgehash.c
 	intern/fileops.c
@@ -101,6 +102,7 @@
 	BLI_bpath.h
 	BLI_callbacks.h
 	BLI_cpu.h
+	BLI_directory.h
 	BLI_dlrbTree.h
 	BLI_dynlib.h
 	BLI_dynstr.h

Added: branches/asset-browser/source/blender/blenlib/intern/directory.c
===================================================================
--- branches/asset-browser/source/blender/blenlib/intern/directory.c	                        (rev 0)
+++ branches/asset-browser/source/blender/blenlib/intern/directory.c	2012-08-11 13:41:59 UTC (rev 49804)
@@ -0,0 +1,426 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ * Reorganised mar-01 nzc
+ * Some really low-level file thingies.
+ */
+
+/** \file blender/blenlib/intern/storage.c
+ *  \ingroup bli
+ */
+
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>	
+
+#ifndef WIN32
+#include <dirent.h>
+#endif
+
+#include <time.h>
+#include <sys/stat.h>
+
+#if defined(__sun__) || defined(__sun) || defined(__NetBSD__)
+#include <sys/statvfs.h> /* Other modern unix os's should probably use this also */
+#elif !defined(__FreeBSD__) && !defined(linux) && (defined(__sparc) || defined(__sparc__))
+#include <sys/statfs.h>
+#endif
+
+#if defined(__FreeBSD__) || defined(__OpenBSD__)
+#include <sys/param.h>
+#include <sys/mount.h>
+#endif
+
+#if defined(linux) || defined(__CYGWIN32__) || defined(__hpux) || defined(__GNU__) || defined(__GLIBC__)
+#include <sys/vfs.h>
+#endif
+
+#ifdef __APPLE__
+/* For statfs */
+#include <sys/param.h>
+#include <sys/mount.h>
+#endif /* __APPLE__ */
+
+
+#include <fcntl.h>
+#include <string.h>  /* strcpy etc.. */
+
+#ifdef WIN32
+#  include <io.h>
+#  include <direct.h>
+#  include "BLI_winstuff.h"
+#  include "utfconv.h"
+#else
+#  include <sys/ioctl.h>
+#  include <unistd.h>
+#  include <pwd.h>
+#endif
+
+/* lib includes */
+#include "MEM_guardedalloc.h"
+
+#include "DNA_listBase.h"
+
+#include "BLI_listbase.h"
+#include "BLI_linklist.h"
+#include "BLI_fileops.h"
+
+#include "BLI_fileops_types.h"
+#include "BLI_string.h"
+#include "BLI_directory.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+
+#include "BKE_utildefines.h"
+
+#include "IMB_imbuf.h"
+#include "IMB_imbuf_types.h"
+
+/* vars: */
+
+
+/* can return NULL when the size is not big enough */
+char *BLI_current_working_dir(char *dir, const size_t maxncpy)
+{
+	const char *pwd = getenv("PWD");
+	if (pwd) {
+		BLI_strncpy(dir, pwd, maxncpy);
+		return dir;
+	}
+
+	return getcwd(dir, maxncpy);
+}
+
+
+double BLI_dir_free_space(const char *dir)
+{
+#ifdef WIN32
+	DWORD sectorspc, bytesps, freec, clusters;
+	char tmp[4];
+	
+	tmp[0] = '\\'; tmp[1] = 0; /* Just a failsafe */
+	if (dir[0] == '/' || dir[0] == '\\') {
+		tmp[0] = '\\';
+		tmp[1] = 0;
+	}
+	else if (dir[1] == ':') {
+		tmp[0] = dir[0];
+		tmp[1] = ':';
+		tmp[2] = '\\';
+		tmp[3] = 0;
+	}
+
+	GetDiskFreeSpace(tmp, &sectorspc, &bytesps, &freec, &clusters);
+
+	return (double) (freec * bytesps * sectorspc);
+#else
+
+#if defined(__sun__) || defined(__sun) || defined(__NetBSD__)
+	struct statvfs disk;
+#else
+	struct statfs disk;
+#endif
+	char name[FILE_MAXDIR], *slash;
+	int len = strlen(dir);
+	
+	if (len >= FILE_MAXDIR) /* path too long */
+		return -1;
+	
+	strcpy(name, dir);
+
+	if (len) {
+		slash = strrchr(name, '/');
+		if (slash) slash[1] = 0;
+	}
+	else strcpy(name, "/");
+
+#if defined(__FreeBSD__) || defined(linux) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__GNU__) || defined(__GLIBC__)
+	if (statfs(name, &disk)) return(-1);
+#endif
+
+#if defined(__sun__) || defined(__sun) || defined(__NetBSD__)
+	if (statvfs(name, &disk)) return(-1);	
+#elif !defined(__FreeBSD__) && !defined(linux) && (defined(__sparc) || defined(__sparc__))
+	/* WARNING - This may not be supported by geeneric unix os's - Campbell */
+	if (statfs(name, &disk, sizeof(struct statfs), 0)) return(-1);
+#endif
+
+	return ( ((double) disk.f_bsize) * ((double) disk.f_bfree));
+#endif
+}
+
+static int bli_compare(struct direntry *entry1, struct direntry *entry2)
+{
+	/* type is equal to stat.st_mode */
+
+	if (S_ISDIR(entry1->type)) {
+		if (S_ISDIR(entry2->type) == 0) return (-1);
+	}
+	else {
+		if (S_ISDIR(entry2->type)) return (1);
+	}
+	if (S_ISREG(entry1->type)) {
+		if (S_ISREG(entry2->type) == 0) return (-1);
+	}
+	else {
+		if (S_ISREG(entry2->type)) return (1);
+	}
+	if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1);
+	if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1);
+	
+	/* make sure "." and ".." are always first */
+	if (strcmp(entry1->relname, ".") == 0) return (-1);
+	if (strcmp(entry2->relname, ".") == 0) return (1);
+	if (strcmp(entry1->relname, "..") == 0) return (-1);
+	if (strcmp(entry2->relname, "..") == 0) return (1);
+
+	return (BLI_natstrcmp(entry1->relname, entry2->relname));
+}
+
+static void bli_adddirstrings(struct direntry* files, int num_files);
+
+void BLI_dir_contents(const char *dirname, struct direntry **files, int *num_files)
+{
+	int totnum= 0,actnum= 0;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list