use BLI_strncpy and BLI_snprintf when the size of the string is known.
[blender.git] / source / blender / blenkernel / intern / ipo.c
index 4f921f005f40979eadfe267eb1ec480150dede3e..40fe36268488a772fadde42751a17086f1190b61 100644 (file)
@@ -1,7 +1,4 @@
-/* ipo.c
- * 
- * $Id$
- *
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -46,7 +43,8 @@
 #include <string.h>
 #include <stddef.h>
 
 #include <string.h>
 #include <stddef.h>
 
-#include "MEM_guardedalloc.h"
+/* since we have versioning code here */
+#define DNA_DEPRECATED_ALLOW
 
 #include "DNA_anim_types.h"
 #include "DNA_constraint_types.h"
 
 #include "DNA_anim_types.h"
 #include "DNA_constraint_types.h"
@@ -76,6 +74,7 @@
 #include "BKE_nla.h"
 #include "BKE_sequencer.h"
 
 #include "BKE_nla.h"
 #include "BKE_sequencer.h"
 
+#include "MEM_guardedalloc.h"
 
 /* *************************************************** */
 /* Old-Data Freeing Tools */
 
 /* *************************************************** */
 /* Old-Data Freeing Tools */
@@ -320,7 +319,7 @@ static const char *constraint_adrcodes_to_paths (int adrcode, int *array_index)
 
 /* ShapeKey types 
  * NOTE: as we don't have access to the keyblock where the data comes from (for now), 
 
 /* ShapeKey types 
  * NOTE: as we don't have access to the keyblock where the data comes from (for now), 
- *             we'll just use numerical indices for now... 
+ *       we'll just use numerical indices for now...
  */
 static char *shapekey_adrcodes_to_paths (int adrcode, int *UNUSED(array_index))
 {
  */
 static char *shapekey_adrcodes_to_paths (int adrcode, int *UNUSED(array_index))
 {
@@ -329,9 +328,9 @@ static char *shapekey_adrcodes_to_paths (int adrcode, int *UNUSED(array_index))
        /* block will be attached to ID_KE block, and setting that we alter is the 'value' (which sets keyblock.curval) */
        // XXX adrcode 0 was dummy 'speed' curve 
        if (adrcode == 0) 
        /* block will be attached to ID_KE block, and setting that we alter is the 'value' (which sets keyblock.curval) */
        // XXX adrcode 0 was dummy 'speed' curve 
        if (adrcode == 0) 
-               sprintf(buf, "speed");
+               strcpy(buf, "speed");
        else
        else
-               sprintf(buf, "key_blocks[%d].value", adrcode);
+               BLI_snprintf(buf, sizeof(buf), "key_blocks[%d].value", adrcode);
        return buf;
 }
 
        return buf;
 }
 
@@ -518,7 +517,7 @@ static const char *material_adrcodes_to_paths (int adrcode, int *array_index)
                        return "alpha";
                        
                case MA_REF:
                        return "alpha";
                        
                case MA_REF:
-                       return "diffuse_reflection";
+                       return "diffuse_intensity";
                
                case MA_EMIT:
                        return "emit";
                
                case MA_EMIT:
                        return "emit";
@@ -527,7 +526,7 @@ static const char *material_adrcodes_to_paths (int adrcode, int *array_index)
                        return "ambient";
                
                case MA_SPEC:
                        return "ambient";
                
                case MA_SPEC:
-                       return "specular_reflection";
+                       return "specular_intensity";
                
                case MA_HARD:
                        return "specular_hardness";
                
                case MA_HARD:
                        return "specular_hardness";
@@ -551,13 +550,13 @@ static const char *material_adrcodes_to_paths (int adrcode, int *array_index)
                        return "raytrace_mirror.fresnel";
                        
                case MA_FRESMIRI:
                        return "raytrace_mirror.fresnel";
                        
                case MA_FRESMIRI:
-                       return "raytrace_mirror.fresnel_fac";
+                       return "raytrace_mirror.fresnel_factor";
                        
                case MA_FRESTRA:
                        return "raytrace_transparency.fresnel";
                        
                case MA_FRESTRAI:
                        
                case MA_FRESTRA:
                        return "raytrace_transparency.fresnel";
                        
                case MA_FRESTRAI:
-                       return "raytrace_transparency.fresnel_fac";
+                       return "raytrace_transparency.fresnel_factor";
                        
                case MA_ADD:
                        return "halo.add";
                        
                case MA_ADD:
                        return "halo.add";
@@ -706,14 +705,7 @@ static const char *world_adrcodes_to_paths (int adrcode, int *array_index)
                        return "mist.start";
                case WO_MISTHI:
                        return "mist.height";
                        return "mist.start";
                case WO_MISTHI:
                        return "mist.height";
-               
-       /*      Star Color is unused -- recommend removal */
-       /*      case WO_STAR_R:
-                       *array_index= 0; return "stars.color";
-               case WO_STAR_G:
-                       *array_index= 1; return "stars.color";
-               case WO_STAR_B:
-                       *array_index= 2; return "stars.color"; */
+
                case WO_STAR_R:
                case WO_STAR_G:
                case WO_STAR_B:
                case WO_STAR_R:
                case WO_STAR_G:
                case WO_STAR_B:
@@ -917,15 +909,18 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co
                if (array_index)
                        *array_index= dummy_index;
        }
                if (array_index)
                        *array_index= dummy_index;
        }
-       
+
+       /* 'buf' _must_ be initialized in this block */
        /* append preceding bits to path */
        /* append preceding bits to path */
+       /* note, strings are not escapted and they should be! */
        if ((actname && actname[0]) && (constname && constname[0])) {
                /* Constraint in Pose-Channel */
        if ((actname && actname[0]) && (constname && constname[0])) {
                /* Constraint in Pose-Channel */
-               sprintf(buf, "pose.bones[\"%s\"].constraints[\"%s\"]", actname, constname);
+               BLI_snprintf(buf, sizeof(buf), "pose.bones[\"%s\"].constraints[\"%s\"]", actname, constname);
        }
        else if (actname && actname[0]) {
                if ((blocktype == ID_OB) && strcmp(actname, "Object")==0) {
                        /* Actionified "Object" IPO's... no extra path stuff needed */
        }
        else if (actname && actname[0]) {
                if ((blocktype == ID_OB) && strcmp(actname, "Object")==0) {
                        /* Actionified "Object" IPO's... no extra path stuff needed */
+                       buf[0]= '\0'; /* empty string */
                }
                else if ((blocktype == ID_KE) && strcmp(actname, "Shape")==0) {
                        /* Actionified "Shape" IPO's - these are forced onto object level via the action container there... */
                }
                else if ((blocktype == ID_KE) && strcmp(actname, "Shape")==0) {
                        /* Actionified "Shape" IPO's - these are forced onto object level via the action container there... */
@@ -933,19 +928,21 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co
                }
                else {
                        /* Pose-Channel */
                }
                else {
                        /* Pose-Channel */
-                       sprintf(buf, "pose.bones[\"%s\"]", actname);
+                       BLI_snprintf(buf, sizeof(buf), "pose.bones[\"%s\"]", actname);
                }
        }
        else if (constname && constname[0]) {
                /* Constraint in Object */
                }
        }
        else if (constname && constname[0]) {
                /* Constraint in Object */
-               sprintf(buf, "constraints[\"%s\"]", constname);
+               BLI_snprintf(buf, sizeof(buf), "constraints[\"%s\"]", constname);
        }
        else if (seq) {
                /* Sequence names in Scene */
        }
        else if (seq) {
                /* Sequence names in Scene */
-               sprintf(buf, "sequence_editor.sequences_all[\"%s\"]", seq->name+2);
+               BLI_snprintf(buf, sizeof(buf), "sequence_editor.sequences_all[\"%s\"]", seq->name+2);
        }
        }
-       else
-               strcpy(buf, ""); /* empty string */
+       else {
+               buf[0]= '\0'; /* empty string */
+       }
+
        BLI_dynstr_append(path, buf);
        
        /* need to add dot before property if there was anything precceding this */
        BLI_dynstr_append(path, buf);
        
        /* need to add dot before property if there was anything precceding this */
@@ -957,7 +954,7 @@ static char *get_rna_access (int blocktype, int adrcode, char actname[], char co
        
        /* if there was no array index pointer provided, add it to the path */
        if (array_index == NULL) {
        
        /* if there was no array index pointer provided, add it to the path */
        if (array_index == NULL) {
-               sprintf(buf, "[\"%d\"]", dummy_index);
+               BLI_snprintf(buf, sizeof(buf), "[\"%d\"]", dummy_index);
                BLI_dynstr_append(path, buf);
        }
        
                BLI_dynstr_append(path, buf);
        }
        
@@ -1035,12 +1032,14 @@ static ChannelDriver *idriver_to_cdriver (IpoDriver *idriver)
                                        /* first bone target */
                                dtar= &dvar->targets[0];
                                dtar->id= (ID *)idriver->ob;
                                        /* first bone target */
                                dtar= &dvar->targets[0];
                                dtar->id= (ID *)idriver->ob;
+                               dtar->idtype= ID_OB;
                                if (idriver->name[0])
                                        BLI_strncpy(dtar->pchan_name, idriver->name, sizeof(dtar->pchan_name));
                                
                                        /* second bone target (name was stored in same var as the first one) */
                                dtar= &dvar->targets[1];
                                dtar->id= (ID *)idriver->ob;
                                if (idriver->name[0])
                                        BLI_strncpy(dtar->pchan_name, idriver->name, sizeof(dtar->pchan_name));
                                
                                        /* second bone target (name was stored in same var as the first one) */
                                dtar= &dvar->targets[1];
                                dtar->id= (ID *)idriver->ob;
+                               dtar->idtype= ID_OB;
                                if (idriver->name[0]) // xxx... for safety
                                        BLI_strncpy(dtar->pchan_name, idriver->name+DRIVER_NAME_OFFS, sizeof(dtar->pchan_name));
                        }
                                if (idriver->name[0]) // xxx... for safety
                                        BLI_strncpy(dtar->pchan_name, idriver->name+DRIVER_NAME_OFFS, sizeof(dtar->pchan_name));
                        }
@@ -1052,6 +1051,7 @@ static ChannelDriver *idriver_to_cdriver (IpoDriver *idriver)
                                /* only requires a single target */
                                dtar= &dvar->targets[0];
                                dtar->id= (ID *)idriver->ob;
                                /* only requires a single target */
                                dtar= &dvar->targets[0];
                                dtar->id= (ID *)idriver->ob;
+                               dtar->idtype= ID_OB;
                                if (idriver->name[0])
                                        BLI_strncpy(dtar->pchan_name, idriver->name, sizeof(dtar->pchan_name));
                                dtar->transChan= adrcode_to_dtar_transchan(idriver->adrcode);
                                if (idriver->name[0])
                                        BLI_strncpy(dtar->pchan_name, idriver->name, sizeof(dtar->pchan_name));
                                dtar->transChan= adrcode_to_dtar_transchan(idriver->adrcode);
@@ -1066,6 +1066,7 @@ static ChannelDriver *idriver_to_cdriver (IpoDriver *idriver)
                                /* only requires single target */
                        dtar= &dvar->targets[0];
                        dtar->id= (ID *)idriver->ob;
                                /* only requires single target */
                        dtar= &dvar->targets[0];
                        dtar->id= (ID *)idriver->ob;
+                       dtar->idtype= ID_OB;
                        dtar->transChan= adrcode_to_dtar_transchan(idriver->adrcode);
                }
        }
                        dtar->transChan= adrcode_to_dtar_transchan(idriver->adrcode);
                }
        }
@@ -1106,7 +1107,7 @@ static void fcurve_add_to_list (ListBase *groups, ListBase *list, FCurve *fcu, c
                                agrp->flag = AGRP_SELECTED;
                                if (muteipo) agrp->flag |= AGRP_MUTED;
                                
                                agrp->flag = AGRP_SELECTED;
                                if (muteipo) agrp->flag |= AGRP_MUTED;
                                
-                               strncpy(agrp->name, grpname, sizeof(agrp->name));
+                               BLI_strncpy(agrp->name, grpname, sizeof(agrp->name));
                                
                                BLI_addtail(&tmp_act.groups, agrp);
                                BLI_uniquename(&tmp_act.groups, agrp, "Group", '.', offsetof(bActionGroup, name), sizeof(agrp->name));
                                
                                BLI_addtail(&tmp_act.groups, agrp);
                                BLI_uniquename(&tmp_act.groups, agrp, "Group", '.', offsetof(bActionGroup, name), sizeof(agrp->name));
@@ -1157,7 +1158,6 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve *
        if (icu->flag & IPO_ACTIVE) fcu->flag |= FCURVE_ACTIVE;
        if (icu->flag & IPO_MUTE) fcu->flag |= FCURVE_MUTED;
        if (icu->flag & IPO_PROTECT) fcu->flag |= FCURVE_PROTECTED;
        if (icu->flag & IPO_ACTIVE) fcu->flag |= FCURVE_ACTIVE;
        if (icu->flag & IPO_MUTE) fcu->flag |= FCURVE_MUTED;
        if (icu->flag & IPO_PROTECT) fcu->flag |= FCURVE_PROTECTED;
-       if (icu->flag & IPO_AUTO_HORIZ) fcu->flag |= FCURVE_AUTO_HANDLES;
        
        /* set extrapolation */
        switch (icu->extrap) {
        
        /* set extrapolation */
        switch (icu->extrap) {
@@ -1242,6 +1242,12 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve *
                                        /* 'hide' flag is now used for keytype - only 'keyframes' existed before */
                                        dst->hide= BEZT_KEYTYPE_KEYFRAME;
                                        
                                        /* 'hide' flag is now used for keytype - only 'keyframes' existed before */
                                        dst->hide= BEZT_KEYTYPE_KEYFRAME;
                                        
+                                       /* auto-handles - per curve to per handle */
+                                       if (icu->flag & IPO_AUTO_HORIZ) {
+                                               if (dst->h1 == HD_AUTO) dst->h1 = HD_AUTO_ANIM;
+                                               if (dst->h2 == HD_AUTO) dst->h2 = HD_AUTO_ANIM;
+                                       }
+                                       
                                        /* correct values, by checking if the flag of interest is set */
                                        if ( ((int)(dst->vec[1][1])) & (abp->bit) )
                                                dst->vec[0][1]= dst->vec[1][1]= dst->vec[2][1] = 1.0f;
                                        /* correct values, by checking if the flag of interest is set */
                                        if ( ((int)(dst->vec[1][1])) & (abp->bit) )
                                                dst->vec[0][1]= dst->vec[1][1]= dst->vec[2][1] = 1.0f;
@@ -1292,6 +1298,12 @@ static void icu_to_fcurves (ID *id, ListBase *groups, ListBase *list, IpoCurve *
                                        
                                /* 'hide' flag is now used for keytype - only 'keyframes' existed before */
                                dst->hide= BEZT_KEYTYPE_KEYFRAME;
                                        
                                /* 'hide' flag is now used for keytype - only 'keyframes' existed before */
                                dst->hide= BEZT_KEYTYPE_KEYFRAME;
+                               
+                               /* auto-handles - per curve to per handle */
+                               if (icu->flag & IPO_AUTO_HORIZ) {
+                                       if (dst->h1 == HD_AUTO) dst->h1 = HD_AUTO_ANIM;
+                                       if (dst->h2 == HD_AUTO) dst->h2 = HD_AUTO_ANIM;
+                               }
                                        
                                /* correct values for euler rotation curves 
                                 *      - they were degrees/10 
                                        
                                /* correct values for euler rotation curves 
                                 *      - they were degrees/10