2011-02-18 13:58:08 +00:00
|
|
|
/*
|
2008-12-20 10:02:00 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2020-08-07 09:50:34 +02:00
|
|
|
#pragma once
|
2008-12-20 10:02:00 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bli
|
2011-02-18 13:58:08 +00:00
|
|
|
*/
|
|
|
|
|
2020-05-08 18:16:39 +02:00
|
|
|
#include "BLI_compiler_attrs.h"
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2010-07-04 16:20:42 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#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);
|
2018-09-05 14:31:10 +10:00
|
|
|
const char *BLI_getenv(const char *env) ATTR_NONNULL(1);
|
2009-04-11 02:18:24 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file);
|
2017-04-17 12:04:38 +02:00
|
|
|
bool BLI_make_existing_file(const char *name);
|
2019-04-17 06:17:24 +02:00
|
|
|
void BLI_split_dirfile(
|
|
|
|
const char *string, char *dir, char *file, const size_t dirlen, const size_t filelen);
|
2013-03-17 18:30:31 +00:00
|
|
|
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);
|
2019-08-13 15:35:48 +02:00
|
|
|
const char *BLI_path_extension(const char *filepath) ATTR_NONNULL();
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void BLI_path_append(char *__restrict dst, const size_t maxlen, const char *__restrict file)
|
|
|
|
ATTR_NONNULL();
|
2020-09-04 20:59:13 +02:00
|
|
|
void BLI_join_dirfile(char *__restrict dst,
|
2019-04-17 06:17:24 +02:00
|
|
|
const size_t maxlen,
|
|
|
|
const char *__restrict dir,
|
|
|
|
const char *__restrict file) ATTR_NONNULL();
|
|
|
|
size_t BLI_path_join(char *__restrict dst, const size_t dst_len, const char *path_first, ...)
|
|
|
|
ATTR_NONNULL(1, 3) ATTR_SENTINEL(0);
|
2014-01-31 03:09:01 +11:00
|
|
|
const char *BLI_path_basename(const char *path) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
|
2019-04-17 06:17:24 +02:00
|
|
|
bool BLI_path_name_at_index(const char *__restrict path,
|
|
|
|
const int index,
|
|
|
|
int *__restrict r_offset,
|
|
|
|
int *__restrict r_len) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
|
2012-06-22 15:38:49 +00:00
|
|
|
|
2020-04-07 12:02:21 +10:00
|
|
|
const char *BLI_path_slash_rfind(const char *string) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
|
|
|
|
int BLI_path_slash_ensure(char *string) ATTR_NONNULL();
|
|
|
|
void BLI_path_slash_rstrip(char *string) ATTR_NONNULL();
|
|
|
|
const char *BLI_path_slash_find(const char *string) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
|
|
|
|
void BLI_path_slash_native(char *path) ATTR_NONNULL();
|
2010-10-27 06:41:48 +00:00
|
|
|
|
2015-05-06 06:05:31 +10:00
|
|
|
#ifdef _WIN32
|
2015-05-06 06:34:19 +10:00
|
|
|
bool BLI_path_program_extensions_add_win32(char *name, const size_t maxlen);
|
2015-05-06 06:05:31 +10:00
|
|
|
#endif
|
2015-05-06 06:34:19 +10:00
|
|
|
bool BLI_path_program_search(char *fullname, const size_t maxlen, const char *name);
|
2015-05-06 06:05:31 +10:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bool BLI_path_extension_check(const char *str, const char *ext)
|
|
|
|
ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
|
2018-06-17 16:13:24 +02:00
|
|
|
bool BLI_path_extension_check_n(const char *str, ...) ATTR_NONNULL(1) ATTR_SENTINEL(0);
|
2019-04-17 06:17:24 +02:00
|
|
|
bool BLI_path_extension_check_array(const char *str, const char **ext_array)
|
|
|
|
ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
|
|
|
|
bool BLI_path_extension_check_glob(const char *str, const char *ext_fnmatch)
|
|
|
|
ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
|
2018-06-18 12:26:47 +02:00
|
|
|
bool BLI_path_extension_glob_validate(char *ext_fnmatch) ATTR_NONNULL();
|
2018-06-17 16:13:24 +02:00
|
|
|
bool BLI_path_extension_replace(char *path, size_t maxlen, const char *ext) ATTR_NONNULL();
|
|
|
|
bool BLI_path_extension_ensure(char *path, size_t maxlen, const char *ext) ATTR_NONNULL();
|
2020-04-07 12:02:21 +10:00
|
|
|
bool BLI_path_filename_ensure(char *filepath, size_t maxlen, const char *filename) ATTR_NONNULL();
|
2020-09-04 20:59:13 +02:00
|
|
|
int BLI_path_sequence_decode(const char *string,
|
|
|
|
char *head,
|
|
|
|
char *tail,
|
|
|
|
unsigned short *r_num_len);
|
2020-04-07 12:02:21 +10:00
|
|
|
void BLI_path_sequence_encode(
|
2019-04-17 06:17:24 +02:00
|
|
|
char *string, const char *head, const char *tail, unsigned short numlen, int pic);
|
2008-12-20 10:02:00 +00:00
|
|
|
|
2020-04-07 12:02:21 +10:00
|
|
|
void BLI_path_normalize(const char *relabase, char *path) ATTR_NONNULL(2);
|
2020-03-07 00:13:03 +11:00
|
|
|
/* Same as above but adds a trailing slash. */
|
2020-04-07 12:02:21 +10:00
|
|
|
void BLI_path_normalize_dir(const char *relabase, char *dir) ATTR_NONNULL(2);
|
2008-12-20 10:02:00 +00:00
|
|
|
|
2015-07-14 18:42:22 +02:00
|
|
|
bool BLI_filename_make_safe(char *fname) ATTR_NONNULL(1);
|
|
|
|
bool BLI_path_make_safe(char *path) ATTR_NONNULL(1);
|
2015-01-16 18:48:59 +01:00
|
|
|
|
2020-02-15 10:33:16 +11:00
|
|
|
/* Go back one directory. */
|
2020-04-07 12:02:21 +10:00
|
|
|
bool BLI_path_parent_dir(char *path) ATTR_NONNULL();
|
2020-02-15 10:33:16 +11:00
|
|
|
/* Go back until the directory is found. */
|
2020-04-07 12:02:21 +10:00
|
|
|
bool BLI_path_parent_dir_until_exists(char *path) ATTR_NONNULL();
|
2008-12-20 10:02:00 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bool BLI_path_abs(char *path, const char *basepath) ATTR_NONNULL();
|
2014-02-01 00:51:53 +11:00
|
|
|
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();
|
2015-06-04 20:40:11 +02:00
|
|
|
bool BLI_path_frame_get(char *path, int *r_frame, int *numdigits) ATTR_NONNULL();
|
Fix BLI_path_frame_strip
The `BLI_path_frame_strip` function was completely broken, unless the
number of digits in the sequence number was the same as the length of
the extension. In other words, it would work fine for `file.0001.abc` (4
digit `0001` and 4 char `.abc`), but other combinations would truncate
to the shortest (`file.001.abc` would become `file.###.ab` and
`file.00001.a` would become `file.##.a`). The dependency between the
sequence number and the file extension is now removed.
The behaviour has changed a little bit in the case where there are no
numbers in the filename. Previously, `path="filename.abc"` would result
in `path="filename.abc"` and `ext=""`, but now it results in
`path="filename"` and `ext=".abc"`. This way `ext` always contains the
extension, and the behaviour is consistent regardless of whether there
were any numbers found.
Furthermore, I've removed the `bool set_frame_char` parameter, because
it was unclear, probably also buggy, and most importantly, never used.
I've also added a unit test for the `BLI_path_frame_strip` function.
2019-03-20 12:59:11 +01:00
|
|
|
void BLI_path_frame_strip(char *path, char *ext) ATTR_NONNULL();
|
2014-02-01 00:51:53 +11:00
|
|
|
bool BLI_path_frame_check_chars(const char *path) ATTR_NONNULL();
|
2020-04-08 16:35:13 +10:00
|
|
|
bool BLI_path_abs_from_cwd(char *path, const size_t maxlen) ATTR_NONNULL();
|
2014-02-01 00:51:53 +11:00
|
|
|
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);
|
|
|
|
|
2018-08-28 15:12:14 +02:00
|
|
|
void BLI_path_to_display_name(char *display_name, int maxlen, const char *name) ATTR_NONNULL();
|
|
|
|
|
2014-04-21 16:49:35 +02:00
|
|
|
#if defined(WIN32)
|
2020-04-08 16:29:46 +10:00
|
|
|
void BLI_path_normalize_unc_16(wchar_t *path_16);
|
2020-04-07 12:02:21 +10:00
|
|
|
void BLI_path_normalize_unc(char *path_16, int maxlen);
|
2014-04-21 16:49:35 +02:00
|
|
|
#endif
|
2012-08-29 10:32:38 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char *sep)
|
|
|
|
ATTR_NONNULL();
|
2014-04-16 14:25:23 -03:00
|
|
|
|
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
|
|
|
|
|
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
|
2019-04-17 06:17:24 +02:00
|
|
|
# define FILE_MAXDIR 768
|
|
|
|
# define FILE_MAXFILE 256
|
|
|
|
# define FILE_MAX 1024
|
2012-09-03 22:04:14 +00:00
|
|
|
#endif
|
|
|
|
|
2017-03-24 05:23:03 +11:00
|
|
|
#ifdef WIN32
|
2019-04-17 06:17:24 +02:00
|
|
|
# define SEP '\\'
|
|
|
|
# define ALTSEP '/'
|
|
|
|
# define SEP_STR "\\"
|
2017-03-24 05:23:03 +11:00
|
|
|
# define ALTSEP_STR "/"
|
|
|
|
#else
|
2019-04-17 06:17:24 +02:00
|
|
|
# define SEP '/'
|
|
|
|
# define ALTSEP '\\'
|
|
|
|
# define SEP_STR "/"
|
2017-03-24 05:23:03 +11:00
|
|
|
# define ALTSEP_STR "\\"
|
|
|
|
#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'))
|
2019-04-17 06:17:24 +02:00
|
|
|
#define FILENAME_IS_CURRPAR(_n) \
|
|
|
|
(((_n)[0] == '.') && (((_n)[1] == '\0') || (((_n)[1] == '.') && ((_n)[2] == '\0'))))
|
2015-01-26 16:58:02 +01:00
|
|
|
|
2010-07-04 16:20:42 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|