patch [#34103] path_util_split_dirstring.patch, path_util_split_dirstring_2.patch, path_util_split_dirstring_3.patch

from Lawrence D'Oliveiro (ldo)

Get rid of BLI_splitdirstring, replace with calls to BLI_split_dirfile, BLI_split_dir_part and BLI_split_file_part as appropriate.
This commit is contained in:
2013-03-05 06:26:10 +00:00
parent 34233e7fd6
commit 384948908a
14 changed files with 33 additions and 84 deletions

View File

@@ -195,11 +195,7 @@ VFont *BKE_vfont_load(Main *bmain, const char *name)
is_builtin = TRUE; is_builtin = TRUE;
} }
else { else {
char dir[FILE_MAXDIR]; BLI_split_file_part(name, filename, sizeof(filename));
BLI_strncpy(dir, name, sizeof(dir));
BLI_splitdirstring(dir, filename);
pf = newPackedFile(NULL, name, bmain->name); pf = newPackedFile(NULL, name, bmain->name);
temp_pf = newPackedFile(NULL, name, bmain->name); temp_pf = newPackedFile(NULL, name, bmain->name);

View File

@@ -488,11 +488,8 @@ int unpackVFont(ReportList *reports, VFont *vfont, int how)
int ret_value = RET_ERROR; int ret_value = RET_ERROR;
if (vfont != NULL) { if (vfont != NULL) {
BLI_strncpy(localname, vfont->name, sizeof(localname)); BLI_split_file_part(vfont->name, fi, sizeof(fi));
BLI_splitdirstring(localname, fi);
BLI_snprintf(localname, sizeof(localname), "//fonts/%s", fi); BLI_snprintf(localname, sizeof(localname), "//fonts/%s", fi);
newname = unpackFile(reports, vfont->name, localname, vfont->packedfile, how); newname = unpackFile(reports, vfont->name, localname, vfont->packedfile, how);
if (newname != NULL) { if (newname != NULL) {
ret_value = RET_OK; ret_value = RET_OK;
@@ -513,10 +510,8 @@ int unpackSound(Main *bmain, ReportList *reports, bSound *sound, int how)
int ret_value = RET_ERROR; int ret_value = RET_ERROR;
if (sound != NULL) { if (sound != NULL) {
BLI_strncpy(localname, sound->name, sizeof(localname)); BLI_split_file_part(sound->name, fi, sizeof(fi));
BLI_splitdirstring(localname, fi);
BLI_snprintf(localname, sizeof(localname), "//sounds/%s", fi); BLI_snprintf(localname, sizeof(localname), "//sounds/%s", fi);
newname = unpackFile(reports, sound->name, localname, sound->packedfile, how); newname = unpackFile(reports, sound->name, localname, sound->packedfile, how);
if (newname != NULL) { if (newname != NULL) {
BLI_strncpy(sound->name, newname, sizeof(sound->name)); BLI_strncpy(sound->name, newname, sizeof(sound->name));
@@ -541,10 +536,8 @@ int unpackImage(ReportList *reports, Image *ima, int how)
int ret_value = RET_ERROR; int ret_value = RET_ERROR;
if (ima != NULL && ima->name[0]) { if (ima != NULL && ima->name[0]) {
BLI_strncpy(localname, ima->name, sizeof(localname)); BLI_split_file_part(ima->name, fi, sizeof(fi));
BLI_splitdirstring(localname, fi);
BLI_snprintf(localname, sizeof(localname), "//textures/%s", fi); BLI_snprintf(localname, sizeof(localname), "//textures/%s", fi);
newname = unpackFile(reports, ima->name, localname, ima->packedfile, how); newname = unpackFile(reports, ima->name, localname, ima->packedfile, how);
if (newname != NULL) { if (newname != NULL) {
ret_value = RET_OK; ret_value = RET_OK;

View File

@@ -911,8 +911,7 @@ void autotexname(Tex *tex)
else if (tex->type == TEX_IMAGE) { else if (tex->type == TEX_IMAGE) {
ima = tex->ima; ima = tex->ima;
if (ima) { if (ima) {
BLI_strncpy(di, ima->name, sizeof(di)); BLI_split_file_part(ima->name, fi, sizeof(fi));
BLI_splitdirstring(di, fi);
strcpy(di, "I."); strcpy(di, "I.");
strcat(di, fi); strcat(di, fi);
new_id(&bmain->tex, (ID *)tex, di); new_id(&bmain->tex, (ID *)tex, di);

View File

@@ -118,7 +118,6 @@ void BLI_newname(char *name, int add);
int BLI_stringdec(const char *string, char *head, char *start, unsigned short *numlen); 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); void BLI_stringenc(char *string, const char *head, const char *tail, unsigned short numlen, int pic);
int BLI_split_name_num(char *left, int *nr, const char *name, char delim); int BLI_split_name_num(char *left, int *nr, const char *name, char delim);
void BLI_splitdirstring(char *di, char *fi);
/* make sure path separators conform to system one */ /* make sure path separators conform to system one */
void BLI_clean(char *path) void BLI_clean(char *path)

View File

@@ -176,7 +176,7 @@ bool BLI_file_is_writable(const char *filename)
else { else {
/* file doesn't exist -- check I can create it in parent directory */ /* file doesn't exist -- check I can create it in parent directory */
char parent[FILE_MAX]; char parent[FILE_MAX];
BLI_split_dirfile(filename, parent, NULL, sizeof parent, 0); BLI_split_dirfile(filename, parent, NULL, sizeof(parent), 0);
writable = access(parent, X_OK | W_OK) == 0; writable = access(parent, X_OK | W_OK) == 0;
} }
return writable; return writable;

View File

@@ -867,23 +867,6 @@ bool BLI_path_cwd(char *path)
return wasrelative; return wasrelative;
} }
/* 'di's filename component is moved into 'fi', di is made a dir path */
/* FIXME: duplicates functionality of BLI_split_dirfile. */
void BLI_splitdirstring(char *di, char *fi)
{
char *lslash = (char *)BLI_last_slash(di);
if (lslash) {
BLI_strncpy(fi, lslash + 1, FILE_MAXFILE);
*(lslash + 1) = 0;
}
else {
BLI_strncpy(fi, di, FILE_MAXFILE);
di[0] = 0;
}
}
/** /**
* Copies into *last the part of *dir following the second-last slash. * Copies into *last the part of *dir following the second-last slash.
*/ */
@@ -1433,15 +1416,12 @@ void BLI_make_exist(char *dir)
*/ */
void BLI_make_existing_file(const char *name) void BLI_make_existing_file(const char *name)
{ {
char di[FILE_MAX], fi[FILE_MAXFILE]; char di[FILE_MAX];
BLI_strncpy(di, name, sizeof(di)); BLI_strncpy(di, name, sizeof(di));
/* FIXME: use BLI_split_dir_part instead and get rid of fi. */ BLI_split_dir_part(name, di, sizeof(di));
BLI_splitdirstring(di, fi);
/* make if if the dir doesn't exist */
/* test exist */ BLI_dir_create_recursive(di);
if (BLI_exists(di) == 0) {
BLI_dir_create_recursive(di);
}
} }
/** /**

View File

@@ -272,7 +272,7 @@ static void bli_builddir(const char *dirname, const char *relname,
memset(file, 0, sizeof(struct direntry)); memset(file, 0, sizeof(struct direntry));
file->relname = dlink->name; file->relname = dlink->name;
file->path = BLI_strdupcat(dirname, dlink->name); file->path = BLI_strdupcat(dirname, dlink->name);
BLI_join_dirfile(fullname, sizeof fullname, dirname, dlink->name); BLI_join_dirfile(fullname, sizeof(fullname), dirname, dlink->name);
// use 64 bit file size, only needed for WIN32 and WIN64. // use 64 bit file size, only needed for WIN32 and WIN64.
// Excluding other than current MSVC compiler until able to test // Excluding other than current MSVC compiler until able to test
#ifdef WIN32 #ifdef WIN32

View File

@@ -493,16 +493,6 @@ void blo_split_main(ListBase *mainlist, Main *main)
split_libdata(lbarray[i], main->next); split_libdata(lbarray[i], main->next);
} }
/* removes things like /blah/blah/../../blah/ etc, then writes in *name the full path */
static void cleanup_path(const char *relabase, char *name)
{
char filename[FILE_MAXFILE];
BLI_splitdirstring(name, filename);
BLI_cleanup_dir(relabase, name);
strcat(name, filename);
}
static void read_file_version(FileData *fd, Main *main) static void read_file_version(FileData *fd, Main *main)
{ {
BHead *bhead; BHead *bhead;
@@ -531,7 +521,7 @@ static Main *blo_find_main(FileData *fd, const char *filepath, const char *relab
char name1[FILE_MAX]; char name1[FILE_MAX];
BLI_strncpy(name1, filepath, sizeof(name1)); BLI_strncpy(name1, filepath, sizeof(name1));
cleanup_path(relabase, name1); BLI_cleanup_path(relabase, name1);
// printf("blo_find_main: relabase %s\n", relabase); // printf("blo_find_main: relabase %s\n", relabase);
// printf("blo_find_main: original in %s\n", filepath); // printf("blo_find_main: original in %s\n", filepath);
@@ -6256,7 +6246,7 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main)
} }
/* make sure we have full path in lib->filepath */ /* make sure we have full path in lib->filepath */
BLI_strncpy(lib->filepath, lib->name, sizeof(lib->name)); BLI_strncpy(lib->filepath, lib->name, sizeof(lib->name));
cleanup_path(fd->relabase, lib->filepath); BLI_cleanup_path(fd->relabase, lib->filepath);
// printf("direct_link_library: name %s\n", lib->name); // printf("direct_link_library: name %s\n", lib->name);
// printf("direct_link_library: filepath %s\n", lib->filepath); // printf("direct_link_library: filepath %s\n", lib->filepath);
@@ -10440,7 +10430,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
if (scanf("%s", newlib_path) > 0) { if (scanf("%s", newlib_path) > 0) {
BLI_strncpy(mainptr->curlib->name, newlib_path, sizeof(mainptr->curlib->name)); BLI_strncpy(mainptr->curlib->name, newlib_path, sizeof(mainptr->curlib->name));
BLI_strncpy(mainptr->curlib->filepath, newlib_path, sizeof(mainptr->curlib->filepath)); BLI_strncpy(mainptr->curlib->filepath, newlib_path, sizeof(mainptr->curlib->filepath));
cleanup_path(G.main->name, mainptr->curlib->filepath); BLI_cleanup_path(G.main->name, mainptr->curlib->filepath);
fd = blo_openblenderfile(mainptr->curlib->filepath, basefd->reports); fd = blo_openblenderfile(mainptr->curlib->filepath, basefd->reports);

View File

@@ -683,14 +683,11 @@ static int fluid_init_filepaths(Object *fsDomain, char *targetDir, char *targetF
} }
if (targetDir[0] == '\0' || (!dirExist)) { if (targetDir[0] == '\0' || (!dirExist)) {
char blendDir[FILE_MAX];
char blendFile[FILE_MAX]; char blendFile[FILE_MAX];
// invalid dir, reset to current/previous // invalid dir, reset to current/previous
BLI_strncpy(blendDir, G.main->name, FILE_MAX); BLI_split_file_part(G.main->name, blendFile, sizeof(blendFile));
BLI_splitdirstring(blendDir, blendFile);
BLI_replace_extension(blendFile, FILE_MAX, ""); /* strip .blend */ BLI_replace_extension(blendFile, FILE_MAX, ""); /* strip .blend */
BLI_snprintf(newSurfdataPath, FILE_MAX, "//fluidsimdata/%s_%s_", blendFile, fsDomain->id.name); BLI_snprintf(newSurfdataPath, FILE_MAX, "//fluidsimdata/%s_%s_", blendFile, fsDomain->id.name);
BLI_snprintf(debugStrBuffer, 256, "fluidsimBake::error - warning resetting output dir to '%s'\n", newSurfdataPath); BLI_snprintf(debugStrBuffer, 256, "fluidsimBake::error - warning resetting output dir to '%s'\n", newSurfdataPath);

View File

@@ -113,7 +113,6 @@ static int file_browse_exec(bContext *C, wmOperator *op)
/* add slash for directories, important for some properties */ /* add slash for directories, important for some properties */
if (RNA_property_subtype(fbo->prop) == PROP_DIRPATH) { if (RNA_property_subtype(fbo->prop) == PROP_DIRPATH) {
char name[FILE_MAX];
int is_relative = RNA_boolean_get(op->ptr, "relative_path"); int is_relative = RNA_boolean_get(op->ptr, "relative_path");
id = fbo->ptr.id.data; id = fbo->ptr.id.data;
@@ -132,8 +131,10 @@ static int file_browse_exec(bContext *C, wmOperator *op)
} }
BLI_add_slash(str); BLI_add_slash(str);
} }
else else {
BLI_splitdirstring(str, name); char * const lslash = (char *)BLI_last_slash(str);
if (lslash) lslash[1] = '\0';
}
} }
RNA_property_string_set(&fbo->ptr, fbo->prop, str); RNA_property_string_set(&fbo->ptr, fbo->prop, str);

View File

@@ -1603,7 +1603,7 @@ static int image_save_sequence_exec(bContext *C, wmOperator *op)
SpaceImage *sima = CTX_wm_space_image(C); SpaceImage *sima = CTX_wm_space_image(C);
ImBuf *ibuf; ImBuf *ibuf;
int tot = 0; int tot = 0;
char di[FILE_MAX], fi[FILE_MAX]; char di[FILE_MAX];
if (sima->image == NULL) if (sima->image == NULL)
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;
@@ -1632,10 +1632,8 @@ static int image_save_sequence_exec(bContext *C, wmOperator *op)
for (ibuf = sima->image->ibufs.first; ibuf; ibuf = ibuf->next) for (ibuf = sima->image->ibufs.first; ibuf; ibuf = ibuf->next)
if (ibuf->userflags & IB_BITMAPDIRTY) if (ibuf->userflags & IB_BITMAPDIRTY)
break; break;
BLI_strncpy(di, ibuf->name, FILE_MAX); BLI_split_dir_part(ibuf->name, di, sizeof(di));
BLI_splitdirstring(di, fi);
BKE_reportf(op->reports, RPT_INFO, "%d image(s) will be saved in %s", tot, di); BKE_reportf(op->reports, RPT_INFO, "%d image(s) will be saved in %s", tot, di);
for (ibuf = sima->image->ibufs.first; ibuf; ibuf = ibuf->next) { for (ibuf = sima->image->ibufs.first; ibuf; ibuf = ibuf->next) {

View File

@@ -187,8 +187,7 @@ void unpack_menu(bContext *C, const char *opname, const char *id_name, const cha
if (G.relbase_valid) { if (G.relbase_valid) {
char local_name[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX]; char local_name[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX];
BLI_strncpy(local_name, abs_name, sizeof(local_name)); BLI_split_file_part(abs_name, fi, sizeof(fi));
BLI_splitdirstring(local_name, fi);
BLI_snprintf(local_name, sizeof(local_name), "//%s/%s", folder, fi); BLI_snprintf(local_name, sizeof(local_name), "//%s/%s", folder, fi);
if (strcmp(abs_name, local_name) != 0) { if (strcmp(abs_name, local_name) != 0) {
switch (checkPackedFile(local_name, pf)) { switch (checkPackedFile(local_name, pf)) {

View File

@@ -361,17 +361,16 @@ int IMB_timecode_to_array_index(IMB_Timecode_Type tc)
* - rebuild helper functions * - rebuild helper functions
* ---------------------------------------------------------------------- */ * ---------------------------------------------------------------------- */
static void get_index_dir(struct anim *anim, char *index_dir) static void get_index_dir(struct anim *anim, char *index_dir, size_t index_dir_len)
{ {
if (!anim->index_dir[0]) { if (!anim->index_dir[0]) {
char fname[FILE_MAXFILE]; char fname[FILE_MAXFILE];
BLI_strncpy(index_dir, anim->name, FILE_MAXDIR); BLI_split_dirfile(anim->name, index_dir, fname, index_dir_len, sizeof(fname));
BLI_splitdirstring(index_dir, fname); BLI_join_dirfile(index_dir, index_dir_len, index_dir, "BL_proxy");
BLI_join_dirfile(index_dir, FILE_MAXDIR, index_dir, "BL_proxy"); BLI_join_dirfile(index_dir, index_dir_len, index_dir, fname);
BLI_join_dirfile(index_dir, FILE_MAXDIR, index_dir, fname);
} }
else { else {
BLI_strncpy(index_dir, anim->index_dir, FILE_MAXDIR); BLI_strncpy(index_dir, anim->index_dir, index_dir_len);
} }
} }
@@ -396,7 +395,7 @@ static void get_proxy_filename(struct anim *anim, IMB_Proxy_Size preview_size,
BLI_snprintf(proxy_temp_name, sizeof(proxy_temp_name), "proxy_%d%s_part.avi", BLI_snprintf(proxy_temp_name, sizeof(proxy_temp_name), "proxy_%d%s_part.avi",
(int) (proxy_fac[i] * 100), stream_suffix); (int) (proxy_fac[i] * 100), stream_suffix);
get_index_dir(anim, index_dir); get_index_dir(anim, index_dir, sizeof(index_dir));
BLI_join_dirfile(fname, FILE_MAXFILE + FILE_MAXDIR, index_dir, BLI_join_dirfile(fname, FILE_MAXFILE + FILE_MAXDIR, index_dir,
temp ? proxy_temp_name : proxy_name); temp ? proxy_temp_name : proxy_name);
@@ -425,7 +424,7 @@ static void get_tc_filename(struct anim *anim, IMB_Timecode_Type tc,
BLI_snprintf(index_name, 256, index_names[i], stream_suffix); BLI_snprintf(index_name, 256, index_names[i], stream_suffix);
get_index_dir(anim, index_dir); get_index_dir(anim, index_dir, sizeof(index_dir));
BLI_join_dirfile(fname, FILE_MAXFILE + FILE_MAXDIR, BLI_join_dirfile(fname, FILE_MAXFILE + FILE_MAXDIR,
index_dir, index_name); index_dir, index_name);

View File

@@ -983,11 +983,9 @@ void render_result_exr_file_merge(RenderResult *rr, RenderResult *rrpart)
/* path to temporary exr file */ /* path to temporary exr file */
void render_result_exr_file_path(Scene *scene, const char *layname, int sample, char *filepath) void render_result_exr_file_path(Scene *scene, const char *layname, int sample, char *filepath)
{ {
char di[FILE_MAX], name[FILE_MAXFILE + MAX_ID_NAME + MAX_ID_NAME + 100], fi[FILE_MAXFILE]; char name[FILE_MAXFILE + MAX_ID_NAME + MAX_ID_NAME + 100], fi[FILE_MAXFILE];
BLI_strncpy(di, G.main->name, FILE_MAX);
BLI_splitdirstring(di, fi);
BLI_split_file_part(G.main->name, fi, sizeof(fi));
if (sample == 0) if (sample == 0)
BLI_snprintf(name, sizeof(name), "%s_%s_%s.exr", fi, scene->id.name + 2, layname); BLI_snprintf(name, sizeof(name), "%s_%s_%s.exr", fi, scene->id.name + 2, layname);
else else