Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenlib/intern/path_util.c')
-rw-r--r--source/blender/blenlib/intern/path_util.c106
1 files changed, 75 insertions, 31 deletions
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 5f66a1b9cb3..6a8be3fe107 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -104,7 +104,9 @@ int BLI_stringdec(const char *string, char *head, char *tail, ushort *r_num_len)
}
}
else {
- if (found_digit) break;
+ if (found_digit) {
+ break;
+ }
}
}
@@ -192,7 +194,9 @@ void BLI_cleanup_path(const char *relabase, char *path)
eind = start + strlen("\\..\\") - 1;
a = start - path - 1;
while (a > 0) {
- if (path[a] == '\\') break;
+ if (path[a] == '\\') {
+ break;
+ }
a--;
}
if (a < 0) {
@@ -308,7 +312,9 @@ bool BLI_filename_make_safe(char *fname)
}
/* Forbid only dots. */
- for (fn = fname; *fn == '.'; fn++);
+ for (fn = fname; *fn == '.'; fn++) {
+ /* pass */
+ }
if (*fn == '\0') {
*fname = '_';
changed = true;
@@ -442,7 +448,9 @@ static bool BLI_path_is_abs(const char *name)
static wchar_t *next_slash(wchar_t *path)
{
wchar_t *slash = path;
- while (*slash && *slash != L'\\') slash++;
+ while (*slash && *slash != L'\\') {
+ slash++;
+ }
return slash;
}
@@ -555,11 +563,13 @@ void BLI_path_rel(char *file, const char *relfile)
int off;
int slash = 0;
for (off = 0; temp[off] && slash < 4; off++) {
- if (temp[off] != file[off])
+ if (temp[off] != file[off]) {
return;
+ }
- if (temp[off] == '\\')
+ if (temp[off] == '\\') {
slash++;
+ }
}
}
else if (temp[1] == ':' && file[1] == ':' && temp[0] != file[0]) {
@@ -620,7 +630,9 @@ void BLI_path_rel(char *file, const char *relfile)
* We count the number of directories we need to go up in the
* hierarchy to arrive at the common 'prefix' of the path
*/
- if (p < temp) p = temp;
+ if (p < temp) {
+ p = temp;
+ }
while (p && p < lslash) {
if (*p == '/') {
r += BLI_strcpy_rlen(r, "../");
@@ -662,8 +674,9 @@ bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char
char extension[FILE_MAX];
bool has_extension = false;
- if (string_len + sep_len + suffix_len >= maxlen)
+ if (string_len + sep_len + suffix_len >= maxlen) {
return false;
+ }
for (a = string_len - 1; a >= 0; a--) {
if (string[a] == '.') {
@@ -675,8 +688,9 @@ bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char
}
}
- if (!has_extension)
+ if (!has_extension) {
a = string_len;
+ }
BLI_strncpy(extension, string + a, sizeof(extension));
sprintf(string + a, "%s%s%s", sep, suffix, extension);
@@ -750,8 +764,9 @@ static void ensure_digits(char *path, int digits)
{
char *file = (char *)BLI_last_slash(path);
- if (file == NULL)
+ if (file == NULL) {
file = path;
+ }
if (strrchr(file, '#') == NULL) {
int len = strlen(file);
@@ -771,8 +786,9 @@ bool BLI_path_frame(char *path, int frame, int digits)
{
int ch_sta, ch_end;
- if (digits)
+ if (digits) {
ensure_digits(path, digits);
+ }
if (stringframe_chars(path, &ch_sta, &ch_end)) { /* warning, ch_end is the last # +1 */
char tmp[FILE_MAX];
@@ -794,8 +810,9 @@ bool BLI_path_frame_range(char *path, int sta, int end, int digits)
{
int ch_sta, ch_end;
- if (digits)
+ if (digits) {
ensure_digits(path, digits);
+ }
if (stringframe_chars(path, &ch_sta, &ch_end)) { /* warning, ch_end is the last # +1 */
char tmp[FILE_MAX];
@@ -820,8 +837,9 @@ bool BLI_path_frame_get(char *path, int *r_frame, int *r_numdigits)
numdigits = *r_numdigits = 0;
- if (file == NULL)
+ if (file == NULL) {
file = path;
+ }
/* first get the extension part */
len = strlen(file);
@@ -873,8 +891,9 @@ void BLI_path_frame_strip(char *path, char *r_ext)
int len;
int numdigits = 0;
- if (file == NULL)
+ if (file == NULL) {
file = path;
+ }
/* first get the extension part */
len = strlen(file);
@@ -1092,11 +1111,13 @@ bool BLI_path_cwd(char *path, const size_t maxlen)
const int filelen = strlen(path);
#ifdef WIN32
- if ((filelen >= 3 && BLI_path_is_abs(path)) || BLI_path_is_unc(path))
+ if ((filelen >= 3 && BLI_path_is_abs(path)) || BLI_path_is_unc(path)) {
wasrelative = false;
+ }
#else
- if (filelen >= 2 && path[0] == '/')
+ if (filelen >= 2 && path[0] == '/') {
wasrelative = false;
+ }
#endif
if (wasrelative) {
@@ -1239,10 +1260,12 @@ void BLI_setenv(const char *env, const char *val)
#else
/* linux/osx/bsd */
- if (val)
+ if (val) {
setenv(env, val, 1);
- else
+ }
+ else {
unsetenv(env);
+ }
#endif
}
@@ -1255,8 +1278,9 @@ void BLI_setenv(const char *env, const char *val)
*/
void BLI_setenv_if_new(const char *env, const char *val)
{
- if (BLI_getenv(env) == NULL)
+ if (BLI_getenv(env) == NULL) {
BLI_setenv(env, val);
+ }
}
/**
@@ -1266,10 +1290,12 @@ const char *BLI_getenv(const char *env)
{
#ifdef _MSC_VER
static char buffer[32767]; /* 32767 is the total size of the environment block on windows*/
- if (GetEnvironmentVariableA(env, buffer, sizeof(buffer)))
+ if (GetEnvironmentVariableA(env, buffer, sizeof(buffer))) {
return buffer;
- else
+ }
+ else {
return NULL;
+ }
#else
return getenv(env);
#endif
@@ -1285,7 +1311,9 @@ void BLI_make_exist(char *dir)
bool valid_path = true;
/* Loop as long as cur path is not a dir, and we can get a parent path. */
- while ((BLI_access(dir, R_OK) != 0) && (valid_path = BLI_parent_dir(dir)));
+ while ((BLI_access(dir, R_OK) != 0) && (valid_path = BLI_parent_dir(dir))) {
+ /* pass */
+ }
/* If we could not find an existing dir, use default root... */
if (!valid_path || !dir[0]) {
@@ -1344,7 +1372,9 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, c
strcpy(string, relabase);
lslash = (char *)BLI_last_slash(string);
- if (lslash) *(lslash + 1) = 0;
+ if (lslash) {
+ *(lslash + 1) = 0;
+ }
dir += 2; /* Skip over the relative reference */
}
@@ -1369,7 +1399,9 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, c
}
/* ignore leading slashes */
- while (*dir == '/' || *dir == '\\') dir++;
+ while (*dir == '/' || *dir == '\\') {
+ dir++;
+ }
}
}
#endif
@@ -1386,8 +1418,10 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, c
/* since we've now removed all slashes, put back one slash at the end. */
strcat(string, "/");
- while (*file && (*file == '/' || *file == '\\')) /* Trim slashes from the front of file */
+ while (*file && (*file == '/' || *file == '\\')) {
+ /* Trim slashes from the front of file */
file++;
+ }
strcat(string, file);
@@ -1537,8 +1571,9 @@ bool BLI_path_extension_replace(char *path, size_t maxlen, const char *ext)
a = path_len;
}
- if (a + ext_len >= maxlen)
+ if (a + ext_len >= maxlen) {
return false;
+ }
memcpy(path + a, ext, ext_len + 1);
return true;
@@ -1571,8 +1606,9 @@ bool BLI_path_extension_ensure(char *path, size_t maxlen, const char *ext)
}
a++;
- if (a + ext_len >= maxlen)
+ if (a + ext_len >= maxlen) {
return false;
+ }
memcpy(path + a, ext, ext_len + 1);
return true;
@@ -1869,8 +1905,12 @@ const char *BLI_first_slash(const char *string)
const char * const ffslash = strchr(string, '/');
const char * const fbslash = strchr(string, '\\');
- if (!ffslash) return fbslash;
- else if (!fbslash) return ffslash;
+ if (!ffslash) {
+ return fbslash;
+ }
+ else if (!fbslash) {
+ return ffslash;
+ }
return (ffslash < fbslash) ? ffslash : fbslash;
}
@@ -1883,8 +1923,12 @@ const char *BLI_last_slash(const char *string)
const char * const lfslash = strrchr(string, '/');
const char * const lbslash = strrchr(string, '\\');
- if (!lfslash) return lbslash;
- else if (!lbslash) return lfslash;
+ if (!lfslash) {
+ return lbslash;
+ }
+ else if (!lbslash) {
+ return lfslash;
+ }
return (lfslash > lbslash) ? lfslash : lbslash;
}