[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50263] trunk/blender/source/blender: code cleanup: add utility function BLI_path_is_rel()
Campbell Barton
ideasman42 at gmail.com
Wed Aug 29 12:32:38 CEST 2012
Revision: 50263
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50263
Author: campbellbarton
Date: 2012-08-29 10:32:38 +0000 (Wed, 29 Aug 2012)
Log Message:
-----------
code cleanup: add utility function BLI_path_is_rel()
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/library.c
trunk/blender/source/blender/blenkernel/intern/pointcache.c
trunk/blender/source/blender/blenlib/BLI_path_util.h
trunk/blender/source/blender/blenlib/intern/bpath.c
trunk/blender/source/blender/blenlib/intern/path_util.c
trunk/blender/source/blender/blenloader/intern/readfile.c
trunk/blender/source/blender/editors/space_file/file_ops.c
trunk/blender/source/blender/editors/space_image/image_ops.c
Modified: trunk/blender/source/blender/blenkernel/intern/library.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/library.c 2012-08-29 09:51:38 UTC (rev 50262)
+++ trunk/blender/source/blender/blenkernel/intern/library.c 2012-08-29 10:32:38 UTC (rev 50263)
@@ -1528,7 +1528,7 @@
/* not essential but set filepath is an absolute copy of value which
* is more useful if its kept in sync */
- if (strncmp(lib->filepath, "//", 2) == 0) {
+ if (BLI_path_is_rel(lib->filepath)) {
/* note that the file may be unsaved, in this case, setting the
* filepath on an indirectly linked path is not allowed from the
* outliner, and its not really supported but allow from here for now
Modified: trunk/blender/source/blender/blenkernel/intern/pointcache.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/pointcache.c 2012-08-29 09:51:38 UTC (rev 50262)
+++ trunk/blender/source/blender/blenkernel/intern/pointcache.c 2012-08-29 10:32:38 UTC (rev 50263)
@@ -1067,8 +1067,9 @@
if (pid->cache->flag & PTCACHE_EXTERNAL) {
strcpy(filename, pid->cache->path);
- if (strncmp(filename, "//", 2)==0)
+ if (BLI_path_is_rel(filename)) {
BLI_path_abs(filename, blendfilename);
+ }
return BLI_add_slash(filename); /* new strlen() */
}
Modified: trunk/blender/source/blender/blenlib/BLI_path_util.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_path_util.h 2012-08-29 09:51:38 UTC (rev 50262)
+++ trunk/blender/source/blender/blenlib/BLI_path_util.h 2012-08-29 10:32:38 UTC (rev 50263)
@@ -154,6 +154,8 @@
int BLI_path_cwd(char *path);
void BLI_path_rel(char *file, const char *relfile);
+int BLI_path_is_rel(const char *path);
+
#ifdef WIN32
# define BLI_path_cmp BLI_strcasecmp
# define BLI_path_ncmp BLI_strncasecmp
Modified: trunk/blender/source/blender/blenlib/intern/bpath.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/bpath.c 2012-08-29 09:51:38 UTC (rev 50262)
+++ trunk/blender/source/blender/blenlib/intern/bpath.c 2012-08-29 10:32:38 UTC (rev 50263)
@@ -113,13 +113,13 @@
data->count_tot++;
- if (strncmp(path_src, "//", 2) == 0) {
+ if (BLI_path_is_rel(path_src)) {
return FALSE; /* already relative */
}
else {
strcpy(path_dst, path_src);
BLI_path_rel(path_dst, data->basedir);
- if (strncmp(path_dst, "//", 2) == 0) {
+ if (BLI_path_is_rel(path_dst)) {
data->count_changed++;
}
else {
@@ -155,13 +155,13 @@
data->count_tot++;
- if (strncmp(path_src, "//", 2) != 0) {
+ if (BLI_path_is_rel(path_src) == FALSE) {
return FALSE; /* already absolute */
}
else {
strcpy(path_dst, path_src);
BLI_path_abs(path_dst, data->basedir);
- if (strncmp(path_dst, "//", 2) != 0) {
+ if (BLI_path_is_rel(path_dst) == FALSE) {
data->count_changed++;
}
else {
@@ -596,7 +596,7 @@
const char *base_new = ((char **)pathbase_v)[0];
const char *base_old = ((char **)pathbase_v)[1];
- if (strncmp(base_old, "//", 2) == 0) {
+ if (BLI_path_is_rel(base_old)) {
printf("%s: error, old base path '%s' is not absolute.\n",
__func__, base_old);
return FALSE;
Modified: trunk/blender/source/blender/blenlib/intern/path_util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/path_util.c 2012-08-29 09:51:38 UTC (rev 50262)
+++ trunk/blender/source/blender/blenlib/intern/path_util.c 2012-08-29 10:32:38 UTC (rev 50263)
@@ -411,6 +411,11 @@
BLI_del_slash(dir);
}
+int BLI_path_is_rel(const char *path)
+{
+ return path[0] == '/' && path[1] == '/';
+}
+
void BLI_path_rel(char *file, const char *relfile)
{
char *lslash;
@@ -418,10 +423,14 @@
char res[FILE_MAX];
/* if file is already relative, bail out */
- if (file[0] == '/' && file[1] == '/') return;
+ if (BLI_path_is_rel(file)) {
+ return;
+ }
/* also bail out if relative path is not set */
- if (relfile[0] == 0) return;
+ if (relfile[0] == '\0') {
+ return;
+ }
#ifdef WIN32
if (BLI_strnlen(relfile, 3) > 2 && relfile[1] != ':') {
@@ -630,7 +639,7 @@
int BLI_path_abs(char *path, const char *basepath)
{
- int wasrelative = (strncmp(path, "//", 2) == 0);
+ int wasrelative = BLI_path_is_rel(path);
char tmp[FILE_MAX];
char base[FILE_MAX];
#ifdef WIN32
Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c 2012-08-29 09:51:38 UTC (rev 50262)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c 2012-08-29 10:32:38 UTC (rev 50263)
@@ -6109,7 +6109,7 @@
* it absolute. This can happen when appending an object with a relative
* link into an unsaved blend file. See [#27405].
* The remap relative option will make it relative again on save - campbell */
- if (strncmp(lib->name, "//", 2) == 0) {
+ if (BLI_path_is_rel(lib->name)) {
BLI_strncpy(lib->name, lib->filepath, sizeof(lib->name));
}
}
@@ -6118,7 +6118,7 @@
for (lib = main->library.first; lib; lib = lib->id.next) {
/* Libraries store both relative and abs paths, recreate relative paths,
* relative to the blend file since indirectly linked libs will be relative to their direct linked library */
- if (strncmp(lib->name, "//", 2) == 0) { /* if this is relative to begin with? */
+ if (BLI_path_is_rel(lib->name)) { /* if this is relative to begin with? */
BLI_strncpy(lib->name, lib->filepath, sizeof(lib->name));
BLI_path_rel(lib->name, basepath);
}
Modified: trunk/blender/source/blender/editors/space_file/file_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_file/file_ops.c 2012-08-29 09:51:38 UTC (rev 50262)
+++ trunk/blender/source/blender/editors/space_file/file_ops.c 2012-08-29 10:32:38 UTC (rev 50263)
@@ -1113,7 +1113,7 @@
if (sfile->params) {
/* TODO, what about // when relbase isn't valid? */
- if (G.relbase_valid && strncmp(sfile->params->dir, "//", 2) == 0) {
+ if (G.relbase_valid && BLI_path_is_rel(sfile->params->dir)) {
BLI_path_abs(sfile->params->dir, G.main->name);
}
else if (sfile->params->dir[0] == '~') {
Modified: trunk/blender/source/blender/editors/space_image/image_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_ops.c 2012-08-29 09:51:38 UTC (rev 50262)
+++ trunk/blender/source/blender/editors/space_image/image_ops.c 2012-08-29 10:32:38 UTC (rev 50263)
@@ -1051,7 +1051,7 @@
return image_replace_exec(C, op);
if (!RNA_struct_property_is_set(op->ptr, "relative_path"))
- RNA_boolean_set(op->ptr, "relative_path", (strncmp(sima->image->name, "//", 2)) == 0);
+ RNA_boolean_set(op->ptr, "relative_path", BLI_path_is_rel(sima->image->name));
image_filesel(C, op, sima->image->name);
More information about the Bf-blender-cvs
mailing list