2011-02-18 13:58:08 +00:00
|
|
|
/*
|
2008-12-20 10:02:00 +00:00
|
|
|
* ***** 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-20 10:02:00 +00:00
|
|
|
*
|
|
|
|
* 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 *****
|
|
|
|
*/
|
2012-02-17 18:59:41 +00:00
|
|
|
#ifndef __BLI_PATH_UTIL_H__
|
|
|
|
#define __BLI_PATH_UTIL_H__
|
2008-12-20 10:02:00 +00:00
|
|
|
|
2011-02-18 13:58:08 +00:00
|
|
|
/** \file BLI_path_util.h
|
|
|
|
* \ingroup bli
|
|
|
|
*/
|
|
|
|
|
2010-07-04 16:20:42 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2013-09-01 15:01:15 +00:00
|
|
|
#include "BLI_compiler_attrs.h"
|
|
|
|
|
2008-12-20 10:02:00 +00:00
|
|
|
struct ListBase;
|
|
|
|
|
2010-10-27 06:41:48 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#define SEP '\\'
|
|
|
|
#define ALTSEP '/'
|
|
|
|
#else
|
|
|
|
#define SEP '/'
|
|
|
|
#define ALTSEP '\\'
|
|
|
|
#endif
|
|
|
|
|
2014-01-31 03:09:01 +11:00
|
|
|
void BLI_setenv(const char *env, const char *val) ATTR_NONNULL(1);
|
|
|
|
void BLI_setenv_if_new(const char *env, const char *val) ATTR_NONNULL(1);
|
2009-04-11 02:18:24 +00:00
|
|
|
|
2008-12-20 10:02:00 +00:00
|
|
|
void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file);
|
|
|
|
void BLI_make_exist(char *dir);
|
2010-11-16 14:40:46 +00:00
|
|
|
void BLI_make_existing_file(const char *name);
|
2013-03-17 18:30:31 +00:00
|
|
|
void BLI_split_dirfile(const char *string, char *dir, char *file, const size_t dirlen, const size_t filelen);
|
|
|
|
void BLI_split_dir_part(const char *string, char *dir, const size_t dirlen);
|
|
|
|
void BLI_split_file_part(const char *string, char *file, const size_t filelen);
|
2013-07-24 21:25:06 +00:00
|
|
|
void BLI_path_append(char *__restrict dst, const size_t maxlen,
|
2013-09-01 15:01:15 +00:00
|
|
|
const char *__restrict file) ATTR_NONNULL();
|
2013-07-24 21:25:06 +00:00
|
|
|
void BLI_join_dirfile(char *__restrict string, const size_t maxlen,
|
2013-09-01 15:01:15 +00:00
|
|
|
const char *__restrict dir, const char *__restrict file) ATTR_NONNULL();
|
2014-01-31 03:09:01 +11:00
|
|
|
const char *BLI_path_basename(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
|
2012-06-22 15:38:49 +00:00
|
|
|
|
2014-05-19 00:00:59 +10:00
|
|
|
#if 0
|
2012-06-22 15:38:49 +00:00
|
|
|
typedef enum bli_rebase_state {
|
|
|
|
BLI_REBASE_NO_SRCDIR = 0,
|
|
|
|
BLI_REBASE_OK = 1,
|
|
|
|
BLI_REBASE_IDENTITY = 2
|
|
|
|
} bli_rebase_state;
|
|
|
|
|
|
|
|
int BLI_rebase_path(char *abs, size_t abs_len, char *rel, size_t rel_len, const char *base_dir, const char *src_dir, const char *dest_dir);
|
2014-05-19 00:00:59 +10:00
|
|
|
#endif
|
2012-06-22 15:38:49 +00:00
|
|
|
|
2014-01-31 03:09:01 +11:00
|
|
|
const char *BLI_last_slash(const char *string) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
|
|
|
|
int BLI_add_slash(char *string) ATTR_NONNULL();
|
|
|
|
void BLI_del_slash(char *string) ATTR_NONNULL();
|
|
|
|
const char *BLI_first_slash(const char *string) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
|
2014-07-31 01:40:05 +10:00
|
|
|
void BLI_path_native_slash(char *path) ATTR_NONNULL();
|
2010-10-27 06:41:48 +00:00
|
|
|
|
2013-03-17 18:30:31 +00:00
|
|
|
void BLI_getlastdir(const char *dir, char *last, const size_t maxlen);
|
2014-01-31 03:09:01 +11:00
|
|
|
bool BLI_testextensie(const char *str, const char *ext) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
|
|
|
|
bool BLI_testextensie_n(const char *str, ...) ATTR_NONNULL(1) ATTR_SENTINEL(0);
|
|
|
|
bool BLI_testextensie_array(const char *str, const char **ext_array) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
|
|
|
|
bool BLI_testextensie_glob(const char *str, const char *ext_fnmatch) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
|
|
|
|
bool BLI_replace_extension(char *path, size_t maxlen, const char *ext) ATTR_NONNULL();
|
|
|
|
bool BLI_ensure_extension(char *path, size_t maxlen, const char *ext) ATTR_NONNULL();
|
2014-02-01 00:51:53 +11:00
|
|
|
bool BLI_ensure_filename(char *filepath, size_t maxlen, const char *filename) ATTR_NONNULL();
|
2015-02-13 13:44:13 +05:00
|
|
|
bool BLI_uniquename(struct ListBase *list, void *vlink, const char *defname, char delim, int name_offs, int len);
|
2013-03-26 07:29:01 +00:00
|
|
|
bool BLI_uniquename_cb(bool (*unique_check)(void *arg, const char *name),
|
2013-11-24 16:20:04 +11:00
|
|
|
void *arg, const char *defname, char delim, char *name, int name_len);
|
2012-05-12 20:39:39 +00:00
|
|
|
void BLI_newname(char *name, int add);
|
2010-04-23 23:01:50 +00:00
|
|
|
int BLI_stringdec(const char *string, char *head, char *start, unsigned short *numlen);
|
|
|
|
void BLI_stringenc(char *string, const char *head, const char *tail, unsigned short numlen, int pic);
|
2013-03-17 18:30:31 +00:00
|
|
|
int BLI_split_name_num(char *left, int *nr, const char *name, const char delim);
|
2008-12-20 10:02:00 +00:00
|
|
|
|
|
|
|
/**
|
2012-03-03 20:19:11 +00:00
|
|
|
* dir can be any input, like from buttons, and this function
|
|
|
|
* converts it to a regular full path.
|
|
|
|
* Also removes garbage from directory paths, like /../ or double slashes etc
|
|
|
|
*/
|
2014-01-31 03:09:01 +11:00
|
|
|
|
|
|
|
/* removes trailing slash */
|
|
|
|
void BLI_cleanup_file(const char *relabase, char *path) ATTR_NONNULL(2);
|
|
|
|
/* same as above but adds a trailing slash */
|
|
|
|
void BLI_cleanup_dir(const char *relabase, char *dir) ATTR_NONNULL(2);
|
|
|
|
/* doesn't touch trailing slash */
|
|
|
|
void BLI_cleanup_path(const char *relabase, char *path) ATTR_NONNULL(2);
|
2008-12-20 10:02:00 +00:00
|
|
|
|
2015-01-16 18:48:59 +01:00
|
|
|
void BLI_filename_make_safe(char *fname) ATTR_NONNULL(1);
|
|
|
|
|
2008-12-20 10:02:00 +00:00
|
|
|
/* go back one directory */
|
2014-01-31 03:09:01 +11:00
|
|
|
bool BLI_parent_dir(char *path) ATTR_NONNULL();
|
2008-12-20 10:02:00 +00:00
|
|
|
|
2012-03-03 20:19:11 +00:00
|
|
|
/**
|
|
|
|
* Blender's path code replacement function.
|
|
|
|
* Bases \a path strings leading with "//" by the
|
|
|
|
* directory \a basepath, and replaces instances of
|
|
|
|
* '#' with the \a framenum. Results are written
|
|
|
|
* back into \a path.
|
|
|
|
*
|
|
|
|
* \a path The path to convert
|
|
|
|
* \a basepath The directory to base relative paths with.
|
|
|
|
* \a framenum The framenumber to replace the frame code with.
|
|
|
|
* \retval Returns true if the path was relative (started with "//").
|
|
|
|
*/
|
2014-02-01 00:51:53 +11:00
|
|
|
bool BLI_path_abs(char *path, const char *basepath) ATTR_NONNULL();
|
|
|
|
bool BLI_path_frame(char *path, int frame, int digits) ATTR_NONNULL();
|
|
|
|
bool BLI_path_frame_range(char *path, int sta, int end, int digits) ATTR_NONNULL();
|
|
|
|
bool BLI_path_frame_check_chars(const char *path) ATTR_NONNULL();
|
|
|
|
bool BLI_path_cwd(char *path) ATTR_NONNULL();
|
|
|
|
void BLI_path_rel(char *file, const char *relfile) ATTR_NONNULL();
|
|
|
|
|
|
|
|
bool BLI_path_is_rel(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
|
2014-04-21 16:49:35 +02:00
|
|
|
bool BLI_path_is_unc(const char *path);
|
|
|
|
|
|
|
|
#if defined(WIN32)
|
|
|
|
void BLI_cleanup_unc_16(wchar_t *path_16);
|
|
|
|
void BLI_cleanup_unc(char *path_16, int maxlen);
|
|
|
|
#endif
|
2012-08-29 10:32:38 +00:00
|
|
|
|
2014-04-16 14:25:23 -03:00
|
|
|
bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char *sep) ATTR_NONNULL();
|
|
|
|
|
2013-03-05 03:17:46 +00:00
|
|
|
/* path string comparisons: case-insensitive for Windows, case-sensitive otherwise */
|
2013-06-18 18:42:29 +00:00
|
|
|
#if defined(WIN32)
|
2011-04-06 06:03:48 +00:00
|
|
|
# define BLI_path_cmp BLI_strcasecmp
|
|
|
|
# define BLI_path_ncmp BLI_strncasecmp
|
|
|
|
#else
|
|
|
|
# define BLI_path_cmp strcmp
|
|
|
|
# define BLI_path_ncmp strncmp
|
|
|
|
#endif
|
|
|
|
|
2013-09-01 15:01:15 +00:00
|
|
|
void BLI_char_switch(char *string, char from, char to) ATTR_NONNULL();
|
2008-12-20 10:02:00 +00:00
|
|
|
|
|
|
|
#ifdef WITH_ICONV
|
|
|
|
void BLI_string_to_utf8(char *original, char *utf_8, const char *code);
|
|
|
|
#endif
|
|
|
|
|
2012-09-03 22:04:14 +00:00
|
|
|
/* these values need to be hardcoded in structs, dna does not recognize defines */
|
|
|
|
/* also defined in DNA_space_types.h */
|
|
|
|
#ifndef FILE_MAXDIR
|
|
|
|
# define FILE_MAXDIR 768
|
|
|
|
# define FILE_MAXFILE 256
|
|
|
|
# define FILE_MAX 1024
|
|
|
|
#endif
|
|
|
|
|
2015-01-26 16:58:02 +01:00
|
|
|
/* Parent and current dir helpers. */
|
|
|
|
#define FILENAME_PARENT ".."
|
|
|
|
#define FILENAME_CURRENT "."
|
|
|
|
|
|
|
|
/* Avoid calling strcmp on one or two chars! */
|
|
|
|
#define FILENAME_IS_PARENT(_n) (((_n)[0] == '.') && ((_n)[1] == '.') && ((_n)[2] == '\0'))
|
|
|
|
#define FILENAME_IS_CURRENT(_n) (((_n)[0] == '.') && ((_n)[1] == '\0'))
|
|
|
|
#define FILENAME_IS_CURRPAR(_n) (((_n)[0] == '.') && (((_n)[1] == '\0') || (((_n)[1] == '.') && ((_n)[2] == '\0'))))
|
|
|
|
|
2010-07-04 16:20:42 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-12-20 10:02:00 +00:00
|
|
|
#endif
|
|
|
|
|