Cleanup: names in text functions

- Use filepath instead of file.
- Use relbase instead of relpath.

In both cases the new names are used more frequently throughout
exiting functions.
This commit is contained in:
Campbell Barton 2022-04-26 13:59:54 +10:00
parent 0f583d9d60
commit c63a6d3057
2 changed files with 28 additions and 25 deletions

View File

@ -36,22 +36,22 @@ bool BKE_text_reload(struct Text *text);
* \note text data-blocks have no real user but have 'fake user' enabled by default
*/
struct Text *BKE_text_load_ex(struct Main *bmain,
const char *file,
const char *relpath,
const char *filepath,
const char *relbase,
bool is_internal);
/**
* Load a text file.
*
* \note Text data-blocks have no user by default, only the 'real user' flag.
*/
struct Text *BKE_text_load(struct Main *bmain, const char *file, const char *relpath);
struct Text *BKE_text_load(struct Main *bmain, const char *filepath, const char *relbase);
void BKE_text_clear(struct Text *text) ATTR_NONNULL(1);
void BKE_text_write(struct Text *text, const char *str, int str_len) ATTR_NONNULL(1, 2);
/**
* \return codes:
* - 0 if file on disk is the same or Text is in memory only.
* - 1 if file has been modified on disk since last local edit.
* - 2 if file on disk has been deleted.
* - 0 if filepath on disk is the same or Text is in memory only.
* - 1 if filepath has been modified on disk since last local edit.
* - 2 if filepath on disk has been deleted.
* - -1 is returned if an error occurs.
*/
int BKE_text_file_modified_check(struct Text *text);

View File

@ -454,7 +454,10 @@ bool BKE_text_reload(Text *text)
return true;
}
Text *BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const bool is_internal)
Text *BKE_text_load_ex(Main *bmain,
const char *filepath,
const char *relbase,
const bool is_internal)
{
unsigned char *buffer;
size_t buffer_len;
@ -462,9 +465,9 @@ Text *BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const
char filepath_abs[FILE_MAX];
BLI_stat_t st;
BLI_strncpy(filepath_abs, file, FILE_MAX);
if (relpath) { /* Can be NULL (background mode). */
BLI_path_abs(filepath_abs, relpath);
BLI_strncpy(filepath_abs, filepath, FILE_MAX);
if (relbase) { /* Can be NULL (background mode). */
BLI_path_abs(filepath_abs, relbase);
}
buffer = BLI_file_read_text_as_mem(filepath_abs, 0, &buffer_len);
@ -484,9 +487,9 @@ Text *BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const
}
if (is_internal == false) {
const size_t file_len = strlen(file);
ta->filepath = MEM_mallocN(file_len + 1, "text_name");
memcpy(ta->filepath, file, file_len + 1);
const size_t filepath_len = strlen(filepath);
ta->filepath = MEM_mallocN(filepath_len + 1, "text_name");
memcpy(ta->filepath, filepath, filepath_len + 1);
}
else {
ta->flags |= TXT_ISMEM | TXT_ISDIRTY;
@ -507,9 +510,9 @@ Text *BKE_text_load_ex(Main *bmain, const char *file, const char *relpath, const
return ta;
}
Text *BKE_text_load(Main *bmain, const char *file, const char *relpath)
Text *BKE_text_load(Main *bmain, const char *filepath, const char *relbase)
{
return BKE_text_load_ex(bmain, file, relpath, false);
return BKE_text_load_ex(bmain, filepath, relbase, false);
}
void BKE_text_clear(Text *text) /* called directly from rna */
@ -530,20 +533,20 @@ int BKE_text_file_modified_check(Text *text)
{
BLI_stat_t st;
int result;
char file[FILE_MAX];
char filepath[FILE_MAX];
if (!text->filepath) {
return 0;
}
BLI_strncpy(file, text->filepath, FILE_MAX);
BLI_path_abs(file, ID_BLEND_PATH_FROM_GLOBAL(&text->id));
BLI_strncpy(filepath, text->filepath, FILE_MAX);
BLI_path_abs(filepath, ID_BLEND_PATH_FROM_GLOBAL(&text->id));
if (!BLI_exists(file)) {
if (!BLI_exists(filepath)) {
return 2;
}
result = BLI_stat(file, &st);
result = BLI_stat(filepath, &st);
if (result == -1) {
return -1;
@ -564,20 +567,20 @@ void BKE_text_file_modified_ignore(Text *text)
{
BLI_stat_t st;
int result;
char file[FILE_MAX];
char filepath[FILE_MAX];
if (!text->filepath) {
return;
}
BLI_strncpy(file, text->filepath, FILE_MAX);
BLI_path_abs(file, ID_BLEND_PATH_FROM_GLOBAL(&text->id));
BLI_strncpy(filepath, text->filepath, FILE_MAX);
BLI_path_abs(filepath, ID_BLEND_PATH_FROM_GLOBAL(&text->id));
if (!BLI_exists(file)) {
if (!BLI_exists(filepath)) {
return;
}
result = BLI_stat(file, &st);
result = BLI_stat(filepath, &st);
if (result == -1 || (st.st_mode & S_IFMT) != S_IFREG) {
return;