patch [#34103] path_util_split_dirstring.patch, path_util_split_dirstring_2.patch...
authorCampbell Barton <ideasman42@gmail.com>
Tue, 5 Mar 2013 06:26:10 +0000 (06:26 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 5 Mar 2013 06:26:10 +0000 (06:26 +0000)
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.

14 files changed:
source/blender/blenkernel/intern/font.c
source/blender/blenkernel/intern/packedFile.c
source/blender/blenkernel/intern/texture.c
source/blender/blenlib/BLI_path_util.h
source/blender/blenlib/intern/fileops.c
source/blender/blenlib/intern/path_util.c
source/blender/blenlib/intern/storage.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/physics/physics_fluid.c
source/blender/editors/space_buttons/buttons_ops.c
source/blender/editors/space_image/image_ops.c
source/blender/editors/util/ed_util.c
source/blender/imbuf/intern/indexer.c
source/blender/render/intern/source/render_result.c

index 3e1e551..e4170a3 100644 (file)
@@ -195,11 +195,7 @@ VFont *BKE_vfont_load(Main *bmain, const char *name)
                is_builtin = TRUE;
        }
        else {
-               char dir[FILE_MAXDIR];
-               
-               BLI_strncpy(dir, name, sizeof(dir));
-               BLI_splitdirstring(dir, filename);
-
+               BLI_split_file_part(name, filename, sizeof(filename));
                pf = newPackedFile(NULL, name, bmain->name);
                temp_pf = newPackedFile(NULL, name, bmain->name);
                
index cd3357a..ec13e58 100644 (file)
@@ -488,11 +488,8 @@ int unpackVFont(ReportList *reports, VFont *vfont, int how)
        int ret_value = RET_ERROR;
        
        if (vfont != NULL) {
-               BLI_strncpy(localname, vfont->name, sizeof(localname));
-               BLI_splitdirstring(localname, fi);
-               
+               BLI_split_file_part(vfont->name, fi, sizeof(fi));
                BLI_snprintf(localname, sizeof(localname), "//fonts/%s", fi);
-               
                newname = unpackFile(reports, vfont->name, localname, vfont->packedfile, how);
                if (newname != NULL) {
                        ret_value = RET_OK;
@@ -513,10 +510,8 @@ int unpackSound(Main *bmain, ReportList *reports, bSound *sound, int how)
        int ret_value = RET_ERROR;
 
        if (sound != NULL) {
-               BLI_strncpy(localname, sound->name, sizeof(localname));
-               BLI_splitdirstring(localname, fi);
+               BLI_split_file_part(sound->name, fi, sizeof(fi));
                BLI_snprintf(localname, sizeof(localname), "//sounds/%s", fi);
-
                newname = unpackFile(reports, sound->name, localname, sound->packedfile, how);
                if (newname != NULL) {
                        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;
        
        if (ima != NULL && ima->name[0]) {
-               BLI_strncpy(localname, ima->name, sizeof(localname));
-               BLI_splitdirstring(localname, fi);
+               BLI_split_file_part(ima->name, fi, sizeof(fi));
                BLI_snprintf(localname, sizeof(localname), "//textures/%s", fi);
-
                newname = unpackFile(reports, ima->name, localname, ima->packedfile, how);
                if (newname != NULL) {
                        ret_value = RET_OK;
index 2ae76ea..665e3cb 100644 (file)
@@ -911,8 +911,7 @@ void autotexname(Tex *tex)
                else if (tex->type == TEX_IMAGE) {
                        ima = tex->ima;
                        if (ima) {
-                               BLI_strncpy(di, ima->name, sizeof(di));
-                               BLI_splitdirstring(di, fi);
+                               BLI_split_file_part(ima->name, fi, sizeof(fi));
                                strcpy(di, "I.");
                                strcat(di, fi);
                                new_id(&bmain->tex, (ID *)tex, di);
index 92c68de..20fc489 100644 (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);
 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);
-void BLI_splitdirstring(char *di, char *fi);
 
 /* make sure path separators conform to system one */
 void BLI_clean(char *path)
index 3f8b211..937fdf5 100644 (file)
@@ -176,7 +176,7 @@ bool BLI_file_is_writable(const char *filename)
        else {
                /* file doesn't exist -- check I can create it in parent directory */
                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;
        }
        return writable;
index 045572c..913a664 100644 (file)
@@ -867,23 +867,6 @@ bool BLI_path_cwd(char *path)
        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.
  */
@@ -1433,15 +1416,12 @@ void BLI_make_exist(char *dir)
  */
 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));
-       /* FIXME: use BLI_split_dir_part instead and get rid of fi. */
-       BLI_splitdirstring(di, fi);
-       
-       /* test exist */
-       if (BLI_exists(di) == 0) {
-               BLI_dir_create_recursive(di);
-       }
+       BLI_split_dir_part(name, di, sizeof(di));
+
+       /* make if if the dir doesn't exist */
+       BLI_dir_create_recursive(di);
 }
 
 /**
index 9263c25..22558fc 100644 (file)
@@ -272,7 +272,7 @@ static void bli_builddir(const char *dirname, const char *relname,
                                        memset(file, 0, sizeof(struct direntry));
                                        file->relname = 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. 
 // Excluding other than current MSVC compiler until able to test
 #ifdef WIN32
index 78ae5b0..a99bdda 100644 (file)
@@ -493,16 +493,6 @@ void blo_split_main(ListBase *mainlist, Main *main)
                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)
 {
        BHead *bhead;
@@ -531,7 +521,7 @@ static Main *blo_find_main(FileData *fd, const char *filepath, const char *relab
        char name1[FILE_MAX];
        
        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: 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 */
        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: filepath %s\n", lib->filepath);
@@ -10440,7 +10430,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
                                                        if (scanf("%s", newlib_path) > 0) {
                                                                BLI_strncpy(mainptr->curlib->name, newlib_path, sizeof(mainptr->curlib->name));
                                                                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);
 
index 714b1be..bf81db3 100644 (file)
@@ -683,14 +683,11 @@ static int fluid_init_filepaths(Object *fsDomain, char *targetDir, char *targetF
        }
        
        if (targetDir[0] == '\0' || (!dirExist)) {
-               char blendDir[FILE_MAX];
                char blendFile[FILE_MAX];
                
                // invalid dir, reset to current/previous
-               BLI_strncpy(blendDir, G.main->name, FILE_MAX);
-               BLI_splitdirstring(blendDir, blendFile);
+               BLI_split_file_part(G.main->name, blendFile, sizeof(blendFile));
                BLI_replace_extension(blendFile, FILE_MAX, ""); /* strip .blend */
-
                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);
index 812ea8c..bd53a8e 100644 (file)
@@ -113,7 +113,6 @@ static int file_browse_exec(bContext *C, wmOperator *op)
 
        /* add slash for directories, important for some properties */
        if (RNA_property_subtype(fbo->prop) == PROP_DIRPATH) {
-               char name[FILE_MAX];
                int is_relative = RNA_boolean_get(op->ptr, "relative_path");
                id = fbo->ptr.id.data;
 
@@ -132,8 +131,10 @@ static int file_browse_exec(bContext *C, wmOperator *op)
                        }
                        BLI_add_slash(str);
                }
-               else
-                       BLI_splitdirstring(str, name);
+               else {
+                       char * const lslash = (char *)BLI_last_slash(str);
+                       if (lslash) lslash[1] = '\0';
+               }
        }
 
        RNA_property_string_set(&fbo->ptr, fbo->prop, str);
index 55f6324..46acd25 100644 (file)
@@ -1603,7 +1603,7 @@ static int image_save_sequence_exec(bContext *C, wmOperator *op)
        SpaceImage *sima = CTX_wm_space_image(C);
        ImBuf *ibuf;
        int tot = 0;
-       char di[FILE_MAX], fi[FILE_MAX];
+       char di[FILE_MAX];
        
        if (sima->image == NULL)
                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)
                if (ibuf->userflags & IB_BITMAPDIRTY)
                        break;
-       
-       BLI_strncpy(di, ibuf->name, FILE_MAX);
-       BLI_splitdirstring(di, fi);
-       
+
+       BLI_split_dir_part(ibuf->name, di, sizeof(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) {
index f0f31b1..73062c5 100644 (file)
@@ -187,8 +187,7 @@ void unpack_menu(bContext *C, const char *opname, const char *id_name, const cha
        if (G.relbase_valid) {
                char local_name[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX];
 
-               BLI_strncpy(local_name, abs_name, sizeof(local_name));
-               BLI_splitdirstring(local_name, fi);
+               BLI_split_file_part(abs_name, fi, sizeof(fi));
                BLI_snprintf(local_name, sizeof(local_name), "//%s/%s", folder, fi);
                if (strcmp(abs_name, local_name) != 0) {
                        switch (checkPackedFile(local_name, pf)) {
index 56e5be7..33b2fb6 100644 (file)
@@ -361,17 +361,16 @@ int IMB_timecode_to_array_index(IMB_Timecode_Type tc)
  * - 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]) {
                char fname[FILE_MAXFILE];
-               BLI_strncpy(index_dir, anim->name, FILE_MAXDIR);
-               BLI_splitdirstring(index_dir, fname);
-               BLI_join_dirfile(index_dir, FILE_MAXDIR, index_dir, "BL_proxy");
-               BLI_join_dirfile(index_dir, FILE_MAXDIR, index_dir, fname);
+               BLI_split_dirfile(anim->name, index_dir, fname, index_dir_len, sizeof(fname));
+               BLI_join_dirfile(index_dir, index_dir_len, index_dir, "BL_proxy");
+               BLI_join_dirfile(index_dir, index_dir_len, index_dir, fname);
        }
        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",
                     (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, 
                         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);
 
-       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, index_name);
index ec926c3..ab0f16c 100644 (file)
@@ -983,11 +983,9 @@ void render_result_exr_file_merge(RenderResult *rr, RenderResult *rrpart)
 /* path to temporary exr file */
 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];
-       
-       BLI_strncpy(di, G.main->name, FILE_MAX);
-       BLI_splitdirstring(di, fi);
+       char name[FILE_MAXFILE + MAX_ID_NAME + MAX_ID_NAME + 100], fi[FILE_MAXFILE];
        
+       BLI_split_file_part(G.main->name, fi, sizeof(fi));
        if (sample == 0)
                BLI_snprintf(name, sizeof(name), "%s_%s_%s.exr", fi, scene->id.name + 2, layname);
        else