use BLI_strncpy and BLI_snprintf when the size of the string is known.
[blender-staging.git] / source / blender / editors / util / ed_util.c
index 081bda60ba2dc513ab11447e0ef84c92442f4479..73322a8292d16ade68171d731853ee6aef70a7e4 100644 (file)
@@ -1,6 +1,4 @@
-/**
- * $Id$
- *
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/editors/util/ed_util.c
+ *  \ingroup edutil
+ */
+
+
 #include <stdlib.h>
 #include <string.h>
 #include <math.h>
@@ -52,6 +55,7 @@
 #include "ED_util.h"
 
 #include "UI_interface.h"
+#include "UI_resources.h"
 
 #include "WM_types.h"
 #include "RNA_access.h"
@@ -100,10 +104,6 @@ void ED_editors_exit(bContext *C)
                if(sce->obedit) {
                        Object *ob= sce->obedit;
                
-                       /* global in meshtools... */
-                       mesh_octree_table(NULL, NULL, NULL, 'e');
-                       mesh_mirrtopo_table(NULL, 'e');
-                       
                        if(ob) {
                                if(ob->type==OB_MESH) {
                                        Mesh *me= ob->data;
@@ -116,26 +116,13 @@ void ED_editors_exit(bContext *C)
                                else if(ob->type==OB_ARMATURE) {
                                        ED_armature_edit_free(ob);
                                }
-                               else if(ob->type==OB_FONT) {
-                                       //                      free_editText();
-                               }
-                               //              else if(ob->type==OB_MBALL) 
-                               //                      BLI_freelistN(&editelems);
-                               //      free_editLatt();
-                               //      free_posebuf();         // XXX this is still a global...
-                       }
-               }
-               else if(sce->basact && sce->basact->object) {
-                       Object *ob= sce->basact->object;
-                       
-                       /* if weight-painting is on, free mesh octree data */
-                       if(ob->mode & OB_MODE_WEIGHT_PAINT) {
-                               mesh_octree_table(NULL, NULL, NULL, 'e');
-                               mesh_mirrtopo_table(NULL, 'e');
                        }
                }
        }
-       
+
+       /* global in meshtools... */
+       mesh_octree_table(NULL, NULL, NULL, 'e');
+       mesh_mirrtopo_table(NULL, 'e');
 }
 
 
@@ -151,13 +138,13 @@ void apply_keyb_grid(int shift, int ctrl, float *val, float fac1, float fac2, fl
                ctrl= !ctrl;
        
        if(ctrl && shift) {
-               if(fac3!= 0.0) *val= fac3*floor(*val/fac3 +.5);
+               if(fac3 != 0.0f) *val= fac3*floorf(*val/fac3 +0.5f);
        }
        else if(ctrl) {
-               if(fac2!= 0.0) *val= fac2*floor(*val/fac2 +.5);
+               if(fac2 != 0.0f) *val= fac2*floorf(*val/fac2 +0.5f);
        }
        else {
-               if(fac1!= 0.0) *val= fac1*floor(*val/fac1 +.5);
+               if(fac1 != 0.0f) *val= fac1*floorf(*val/fac1 +0.5f);
        }
 }
 
@@ -177,13 +164,13 @@ void unpack_menu(bContext *C, const char *opname, const char *id_name, const cha
        PointerRNA props_ptr;
        uiPopupMenu *pup;
        uiLayout *layout;
-       char line[FILE_MAXDIR + FILE_MAXFILE + 100];
+       char line[FILE_MAX + 100];
 
-       pup= uiPupMenuBegin(C, "Unpack file", ICON_NULL);
+       pup= uiPupMenuBegin(C, "Unpack file", ICON_NONE);
        layout= uiPupMenuLayout(pup);
 
-       sprintf(line, "Remove Pack");
-       props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
+       strcpy(line, "Remove Pack");
+       props_ptr= uiItemFullO(layout, opname, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
        RNA_enum_set(&props_ptr, "method", PF_REMOVE);
        RNA_string_set(&props_ptr, "id", id_name);
 
@@ -192,34 +179,34 @@ void unpack_menu(bContext *C, const char *opname, const char *id_name, const cha
 
                BLI_strncpy(local_name, abs_name, sizeof(local_name));
                BLI_splitdirstring(local_name, fi);
-               sprintf(local_name, "//%s/%s", folder, fi);
+               BLI_snprintf(local_name, sizeof(local_name), "//%s/%s", folder, fi);
                if(strcmp(abs_name, local_name)!=0) {
                        switch(checkPackedFile(local_name, pf)) {
                                case PF_NOFILE:
-                                       sprintf(line, "Create %s", local_name);
-                                       props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
+                                       BLI_snprintf(line, sizeof(line), "Create %s", local_name);
+                                       props_ptr= uiItemFullO(layout, opname, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
                                        RNA_enum_set(&props_ptr, "method", PF_WRITE_LOCAL);
                                        RNA_string_set(&props_ptr, "id", id_name);
 
                                        break;
                                case PF_EQUAL:
-                                       sprintf(line, "Use %s (identical)", local_name);
+                                       BLI_snprintf(line, sizeof(line), "Use %s (identical)", local_name);
                                        //uiItemEnumO(layout, opname, line, 0, "method", PF_USE_LOCAL);
-                                       props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
+                                       props_ptr= uiItemFullO(layout, opname, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
                                        RNA_enum_set(&props_ptr, "method", PF_USE_LOCAL);
                                        RNA_string_set(&props_ptr, "id", id_name);
 
                                        break;
                                case PF_DIFFERS:
-                                       sprintf(line, "Use %s (differs)", local_name);
+                                       BLI_snprintf(line, sizeof(line), "Use %s (differs)", local_name);
                                        //uiItemEnumO(layout, opname, line, 0, "method", PF_USE_LOCAL);
-                                       props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
+                                       props_ptr= uiItemFullO(layout, opname, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
                                        RNA_enum_set(&props_ptr, "method", PF_USE_LOCAL);
                                        RNA_string_set(&props_ptr, "id", id_name);
 
-                                       sprintf(line, "Overwrite %s", local_name);
+                                       BLI_snprintf(line, sizeof(line), "Overwrite %s", local_name);
                                        //uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_LOCAL);
-                                       props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
+                                       props_ptr= uiItemFullO(layout, opname, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
                                        RNA_enum_set(&props_ptr, "method", PF_WRITE_LOCAL);
                                        RNA_string_set(&props_ptr, "id", id_name);
                                        break;
@@ -229,29 +216,29 @@ void unpack_menu(bContext *C, const char *opname, const char *id_name, const cha
 
        switch(checkPackedFile(abs_name, pf)) {
                case PF_NOFILE:
-                       sprintf(line, "Create %s", abs_name);
+                       BLI_snprintf(line, sizeof(line), "Create %s", abs_name);
                        //uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_ORIGINAL);
-                       props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
+                       props_ptr= uiItemFullO(layout, opname, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
                        RNA_enum_set(&props_ptr, "method", PF_WRITE_ORIGINAL);
                        RNA_string_set(&props_ptr, "id", id_name);
                        break;
                case PF_EQUAL:
-                       sprintf(line, "Use %s (identical)", abs_name);
+                       BLI_snprintf(line, sizeof(line), "Use %s (identical)", abs_name);
                        //uiItemEnumO(layout, opname, line, 0, "method", PF_USE_ORIGINAL);
-                       props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
+                       props_ptr= uiItemFullO(layout, opname, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
                        RNA_enum_set(&props_ptr, "method", PF_USE_ORIGINAL);
                        RNA_string_set(&props_ptr, "id", id_name);
                        break;
                case PF_DIFFERS:
-                       sprintf(line, "Use %s (differs)", abs_name);
+                       BLI_snprintf(line, sizeof(line), "Use %s (differs)", abs_name);
                        //uiItemEnumO(layout, opname, line, 0, "method", PF_USE_ORIGINAL);
-                       props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
+                       props_ptr= uiItemFullO(layout, opname, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
                        RNA_enum_set(&props_ptr, "method", PF_USE_ORIGINAL);
                        RNA_string_set(&props_ptr, "id", id_name);
 
-                       sprintf(line, "Overwrite %s", abs_name);
+                       BLI_snprintf(line, sizeof(line), "Overwrite %s", abs_name);
                        //uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_ORIGINAL);
-                       props_ptr= uiItemFullO(layout, opname, line, ICON_NULL, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
+                       props_ptr= uiItemFullO(layout, opname, line, ICON_NONE, NULL, WM_OP_EXEC_DEFAULT, UI_ITEM_O_RETURN_PROPS);
                        RNA_enum_set(&props_ptr, "method", PF_WRITE_ORIGINAL);
                        RNA_string_set(&props_ptr, "id", id_name);
                        break;