bugfix [#24477] Can easily create bones with duplicate names
authorCampbell Barton <ideasman42@gmail.com>
Mon, 1 Nov 2010 07:19:41 +0000 (07:19 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 1 Nov 2010 07:19:41 +0000 (07:19 +0000)
- fixed this error 7 different functions (deform groups, uv layers & similar).
- support for numbers over 999.
- renamed splitIDname() to BLI_split_name_num(), moved to BLI_path_utils

12 files changed:
source/blender/blenkernel/BKE_library.h
source/blender/blenkernel/intern/customdata.c
source/blender/blenkernel/intern/deform.c
source/blender/blenkernel/intern/library.c
source/blender/blenkernel/intern/mball.c
source/blender/blenkernel/intern/nla.c
source/blender/blenlib/BLI_path_util.h
source/blender/blenlib/intern/path_util.c
source/blender/editors/armature/editarmature.c
source/blender/editors/object/object_vgroup.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/editors/transform/transform_orientations.c

index b74de66..d98fb08 100644 (file)
@@ -67,7 +67,6 @@ void free_libblock_us(struct ListBase *lb, void *idv);
 void free_main(struct Main *mainvar);
 void tag_main(struct Main *mainvar, int tag);
 
-int splitIDname(char *name, char *left, int *nr);
 void rename_id(struct ID *id, char *name);
 void name_uiprefix_id(char *name, struct ID *id);
 void test_idbutton(char *name);
index 9c4f0d7..c1aaa86 100644 (file)
@@ -2249,69 +2249,56 @@ static int  CustomData_is_property_layer(int type)
        return 0;
 }
 
-void CustomData_set_layer_unique_name(CustomData *data, int index)
+static int cd_layer_find_dupe(CustomData *data, const char *name, int type, int index)
 {
-       char tempname[64];
-       int number, i, type;
-       char *dot, *name;
-       CustomDataLayer *layer, *nlayer= &data->layers[index];
-       const LayerTypeInfo *typeInfo= layerType_getInfo(nlayer->type);
-
-       if (!typeInfo->defaultname)
-               return;
-
-       type = nlayer->type;
-       name = nlayer->name;
-
-       if (name[0] == '\0')
-               BLI_strncpy(nlayer->name, typeInfo->defaultname, sizeof(nlayer->name));
-       
+       int i;
        /* see if there is a duplicate */
        for(i=0; i<data->totlayer; i++) {
-               layer = &data->layers[i];
-               
-               if(CustomData_is_property_layer(type)){
-                       if(i!=index && CustomData_is_property_layer(layer->type) && 
-                               strcmp(layer->name, name)==0)
-                                       break;  
-               
-               }
-               else{
-                       if(i!=index && layer->type==type && strcmp(layer->name, name)==0)
-                               break;
+               if(i != index) {
+                       CustomDataLayer *layer= &data->layers[i];
+                       
+                       if(CustomData_is_property_layer(type)) {
+                               if(CustomData_is_property_layer(layer->type) && strcmp(layer->name, name)==0) {
+                                       return 1;
+                               }
+                       }
+                       else{
+                               if(i!=index && layer->type==type && strcmp(layer->name, name)==0) {
+                                       return 1;
+                               }
+                       }
                }
        }
+       
+       return 0;
+}
 
-       if(i == data->totlayer)
-               return;
+void CustomData_set_layer_unique_name(CustomData *data, int index)
+{
+       CustomDataLayer *nlayer= &data->layers[index];
+       const LayerTypeInfo *typeInfo= layerType_getInfo(nlayer->type);
 
-       /* strip off the suffix */
-       dot = strchr(nlayer->name, '.');
-       if(dot) *dot=0;
-       
-       for(number=1; number <=999; number++) {
-               sprintf(tempname, "%s.%03d", nlayer->name, number);
+       if (!typeInfo->defaultname)
+               return;
 
-               for(i=0; i<data->totlayer; i++) {
-                       layer = &data->layers[i];
-                       
-                       if(CustomData_is_property_layer(type)){
-                               if(i!=index && CustomData_is_property_layer(layer->type) && 
-                                       strcmp(layer->name, tempname)==0)
+       if (nlayer->name[0] == '\0')
+               BLI_strncpy(nlayer->name, typeInfo->defaultname, sizeof(nlayer->name));
 
-                               break;
+       if(cd_layer_find_dupe(data, nlayer->name, nlayer->type, index)) {
+               /* note: this block is used in other places, when changing logic apply to all others, search this message */
+               char    tempname[sizeof(nlayer->name)];
+               char    left[sizeof(nlayer->name)];
+               int             number;
+               int             len= BLI_split_name_num(left, &number, nlayer->name);
+               do {    /* nested while loop looks bad but likely it wont run most times */
+                       while(BLI_snprintf(tempname, sizeof(tempname), "%s.%03d", left, number) >= sizeof(tempname)) {
+                               if(len > 0)     left[--len]= '\0';      /* word too long */
+                               else            number= 0;                      /* reset, must be a massive number */
                        }
-                       else{
-                               if(i!=index && layer->type==type && strcmp(layer->name, tempname)==0)
-                                       break;
-                       }
-               }
-
-               if(i == data->totlayer) {
-                       BLI_strncpy(nlayer->name, tempname, sizeof(nlayer->name));
-                       return;
-               }
-       }       
+               } while(number++, cd_layer_find_dupe(data, tempname, nlayer->type, index));
+               
+               BLI_strncpy(nlayer->name, tempname, sizeof(nlayer->name));
+       }
 }
 
 int CustomData_verify_versions(struct CustomData *data, int index)
index 91584b6..10fbd24 100644 (file)
@@ -304,14 +304,23 @@ int defgroup_flip_index(Object *ob, int index, int use_default)
        return (flip_index==-1 && use_default) ? index : flip_index;
 }
 
-void defgroup_unique_name (bDeformGroup *dg, Object *ob)
+static int defgroup_find_name_dupe(const char *name, bDeformGroup *dg, Object *ob)
 {
        bDeformGroup *curdef;
-       int number;
-       int exists = 0;
-       char tempname[64];
-       char *dot;
        
+       for (curdef = ob->defbase.first; curdef; curdef=curdef->next) {
+               if (dg!=curdef) {
+                       if (!strcmp(curdef->name, name)) {
+                               return 1;
+                       }
+               }
+       }
+
+       return 0;
+}
+
+void defgroup_unique_name (bDeformGroup *dg, Object *ob)
+{      
        if (!ob)
                return;
                
@@ -320,44 +329,23 @@ void defgroup_unique_name (bDeformGroup *dg, Object *ob)
                /* give it default name first */
                strcpy (dg->name, "Group");
        }       
-               
-       /* See if we even need to do this */
-       for (curdef = ob->defbase.first; curdef; curdef=curdef->next) {
-               if (dg!=curdef) {
-                       if (!strcmp(curdef->name, dg->name)) {
-                               exists = 1;
-                               break;
-                       }
-               }
-       }
-       
-       if (!exists)
-               return;
 
-       /*      Strip off the suffix */
-       dot=strchr(dg->name, '.');
-       if (dot)
-               *dot=0;
-       
-       for (number = 1; number <=999; number++) {
-               sprintf (tempname, "%s.%03d", dg->name, number);
-               
-               exists = 0;
-               for (curdef=ob->defbase.first; curdef; curdef=curdef->next) {
-                       if (dg!=curdef) {
-                               if (!strcmp (curdef->name, tempname)) {
-                                       exists = 1;
-                                       break;
-                               }
+       if(defgroup_find_name_dupe(dg->name, dg, ob)) {
+               /* note: this block is used in other places, when changing logic apply to all others, search this message */
+               char    tempname[sizeof(dg->name)];
+               char    left[sizeof(dg->name)];
+               int             number;
+               int             len= BLI_split_name_num(left, &number, dg->name);
+               do {    /* nested while loop looks bad but likely it wont run most times */
+                       while(BLI_snprintf(tempname, sizeof(tempname), "%s.%03d", left, number) >= sizeof(tempname)) {
+                               if(len > 0)     left[--len]= '\0';      /* word too long */
+                               else            number= 0;                      /* reset, must be a massive number */
                        }
-               }
-               if (!exists) {
-                       BLI_strncpy (dg->name, tempname, 32);
-                       return;
-               }
-       }       
-}
+               } while(number++, defgroup_find_name_dupe(tempname, dg, ob));
 
+               BLI_strncpy(dg->name, tempname, sizeof(dg->name));
+       }
+}
 
 /* finds the best possible flipped name. For renaming; check for unique names afterwards */
 /* if strip_number: removes number extensions */
index dc3c120..4227c63 100644 (file)
@@ -984,35 +984,6 @@ void IMAnames_to_pupstring(char **str, char *title, char *extraops, ListBase *lb
        BLI_dynstr_free(pupds);
 }
 
-
-/* used by buttons.c library.c mball.c */
-int splitIDname(char *name, char *left, int *nr)
-{
-       int a;
-       
-       *nr= 0;
-       strncpy(left, name, 21);
-       
-       a= strlen(name);
-       if(a>1 && name[a-1]=='.') return a;
-       
-       while(a--) {
-               if( name[a]=='.' ) {
-                       left[a]= 0;
-                       *nr= atol(name+a+1);
-                       return a;
-               }
-               if( isdigit(name[a])==0 ) break;
-               
-               left[a]= 0;
-       }
-
-       for(a= 0; name[a]; a++)
-               left[a]= name[a];
-
-       return a;
-}
-
 static void sort_alpha_id(ListBase *lb, ID *id)
 {
        ID *idtest;
@@ -1092,7 +1063,7 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name)
                memset(in_use, 0, sizeof(in_use));
 
                /* get name portion, number portion ("name.number") */
-               left_len= splitIDname(name, left, &nr);
+               left_len= BLI_split_name_num(left, &nr, name);
 
                /* if new name will be too long, truncate it */
                if(nr > 999 && left_len > 16) {
@@ -1109,7 +1080,7 @@ static int check_for_dupid(ListBase *lb, ID *id, char *name)
                                        (idtest->lib == NULL) &&
                                        (*name == *(idtest->name+2)) &&
                                        (strncmp(name, idtest->name+2, left_len)==0) &&
-                                       (splitIDname(idtest->name+2, leftest, &nrtest) == left_len)
+                                       (BLI_split_name_num(leftest, &nrtest, idtest->name+2) == left_len)
                        ) {
                                if(nrtest < sizeof(in_use))
                                        in_use[nrtest]= 1;      /* mark as used */
index e6f38e0..fd3bc47 100644 (file)
@@ -330,8 +330,8 @@ int is_mball_basis_for(Object *ob1, Object *ob2)
        int basis1nr, basis2nr;
        char basis1name[32], basis2name[32];
 
-       splitIDname(ob1->id.name+2, basis1name, &basis1nr);
-       splitIDname(ob2->id.name+2, basis2name, &basis2nr);
+       BLI_split_name_num(basis1name, &basis1nr, ob1->id.name+2);
+       BLI_split_name_num(basis2name, &basis2nr, ob2->id.name+2);
 
        if(!strcmp(basis1name, basis2name)) return is_basis_mball(ob1);
        else return 0;
@@ -352,7 +352,7 @@ void copy_mball_properties(Scene *scene, Object *active_object)
        int basisnr, obnr;
        char basisname[32], obname[32];
        
-       splitIDname(active_object->id.name+2, basisname, &basisnr);
+       BLI_split_name_num(basisname, &basisnr, active_object->id.name+2);
 
        /* XXX recursion check, see scene.c, just too simple code this next_object() */
        if(F_ERROR==next_object(&sce_iter, 0, 0, 0))
@@ -361,7 +361,7 @@ void copy_mball_properties(Scene *scene, Object *active_object)
        while(next_object(&sce_iter, 1, &base, &ob)) {
                if (ob->type==OB_MBALL) {
                        if(ob!=active_object){
-                               splitIDname(ob->id.name+2, obname, &obnr);
+                               BLI_split_name_num(obname, &obnr, ob->id.name+2);
 
                                /* Object ob has to be in same "group" ... it means, that it has to have
                                 * same base of its name */
@@ -394,8 +394,8 @@ Object *find_basis_mball(Scene *scene, Object *basis)
        MetaElem *ml=NULL;
        int basisnr, obnr;
        char basisname[32], obname[32];
-       
-       splitIDname(basis->id.name+2, basisname, &basisnr);
+
+       BLI_split_name_num(basisname, &basisnr, basis->id.name+2);
        totelem= 0;
 
        /* XXX recursion check, see scene.c, just too simple code this next_object() */
@@ -415,7 +415,7 @@ Object *find_basis_mball(Scene *scene, Object *basis)
                                else ml= mb->elems.first;
                        }
                        else{
-                               splitIDname(ob->id.name+2, obname, &obnr);
+                               BLI_split_name_num(obname, &obnr, ob->id.name+2);
 
                                /* object ob has to be in same "group" ... it means, that it has to have
                                 * same base of its name */
@@ -1572,7 +1572,7 @@ float init_meta(Scene *scene, Object *ob) /* return totsize */
        invert_m4_m4(obinv, ob->obmat);
        a= 0;
        
-       splitIDname(ob->id.name+2, obname, &obnr);
+       BLI_split_name_num(obname, &obnr, ob->id.name+2);
        
        /* make main array */
        next_object(&sce_iter, 0, 0, 0);
@@ -1593,7 +1593,7 @@ float init_meta(Scene *scene, Object *ob) /* return totsize */
                                char name[32];
                                int nr;
                                
-                               splitIDname(bob->id.name+2, name, &nr);
+                               BLI_split_name_num(name, &nr, bob->id.name+2);
                                if( strcmp(obname, name)==0 ) {
                                        mb= bob->data;
                                        
index 67c3e74..6c8eb69 100644 (file)
@@ -1260,27 +1260,21 @@ void BKE_nlastrip_validate_name (AnimData *adt, NlaStrip *strip)
         *      - in an extreme case, it might not be able to find a name, but then everything else in Blender would fail too :)
         */
        if (BLI_ghash_haskey(gh, strip->name)) {
-               char tempname[128];
-               int     number = 1;
-               char *dot;
-               
-               /* Strip off the suffix */
-               dot = strrchr(strip->name, '.');
-               if (dot) *dot=0;
-               
-               /* Try different possibilities */
-               for (number = 1; number <= 999; number++) {
-                       /* assemble alternative name */
-                       BLI_snprintf(tempname, 128, "%s.%03d", strip->name, number);
-                       
-                       /* if hash doesn't have this, set it */
-                       if (BLI_ghash_haskey(gh, tempname) == 0) {
-                               BLI_strncpy(strip->name, tempname, sizeof(strip->name));
-                               break;
+               /* note: this block is used in other places, when changing logic apply to all others, search this message */
+               char    tempname[sizeof(strip->name)];
+               char    left[sizeof(strip->name)];
+               int             number;
+               int             len= BLI_split_name_num(left, &number, strip->name);
+               do {    /* nested while loop looks bad but likely it wont run most times */
+                       while(BLI_snprintf(tempname, sizeof(tempname), "%s.%03d", left, number) >= sizeof(tempname)) {
+                               if(len > 0)     left[--len]= '\0';      /* word too long */
+                               else            number= 0;                      /* reset, must be a massive number */
                        }
-               }
-       }
+               } while(number++, BLI_ghash_haskey(gh, tempname));
        
+               BLI_strncpy(strip->name, tempname, sizeof(strip->name));
+       }
+
        /* free the hash... */
        BLI_ghash_free(gh, NULL, NULL);
 }
index 5dbb137..69b1066 100644 (file)
@@ -120,6 +120,7 @@ void BLI_uniquename(struct ListBase *list, void *vlink, const char defname[], ch
 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);
 void BLI_splitdirstring(char *di,char *fi);
 
 /* make sure path separators conform to system one */
index 91558d4..466012e 100644 (file)
@@ -136,6 +136,37 @@ void BLI_stringenc(char *string, const char *head, const char *tail, unsigned sh
        sprintf(string, fmtstr, head, pic, tail);
 }
 
+/* Foo.001 -> "Foo", 1
+ * Returns the length of "Foo" */
+int BLI_split_name_num(char *left, int *nr, const char *name)
+{
+       int a;
+       
+       *nr= 0;
+       a= strlen(name);
+       memcpy(left, name, (a + 1) * sizeof(char));
+
+       if(a>1 && name[a-1]=='.') return a;
+       
+       while(a--) {
+               if( name[a]=='.' ) {
+                       left[a]= 0;
+                       *nr= atol(name+a+1);
+                       /* casting down to an int, can overflow for large numbers */
+                       if(*nr < 0)
+                               *nr= 0;
+                       return a;
+               }
+               if( isdigit(name[a])==0 ) break;
+               
+               left[a]= 0;
+       }
+
+       for(a= 0; name[a]; a++)
+               left[a]= name[a];
+
+       return a;
+}
 
 void BLI_newname(char *name, int add)
 {
@@ -174,15 +205,25 @@ void BLI_newname(char *name, int add)
  *     defname: the name that should be used by default if none is specified already
  *     delim: the character which acts as a delimeter between parts of the name
  */
-void BLI_uniquename(ListBase *list, void *vlink, const char defname[], char delim, short name_offs, short len)
+static int uniquename_find_dupe(ListBase *list, void *vlink, const char *name, short name_offs)
 {
        Link *link;
-       char tempname[128];
-       int     number = 1, exists = 0;
-       char *dot;
-       
+
+       for (link = list->first; link; link= link->next) {
+               if (link != vlink) {
+                       if (!strcmp(GIVE_STRADDR(link, name_offs), name)) {
+                               return 1;
+                       }
+               }
+       }
+
+       return 0;
+}
+
+void BLI_uniquename(ListBase *list, void *vlink, const char defname[], char delim, short name_offs, short name_len)
+{      
        /* Make sure length can be handled */
-       if ((len < 0) || (len > 128))
+       if ((name_len < 0) || (name_len > 128))
                return;
        
        /* See if we are given an empty string */
@@ -191,45 +232,27 @@ void BLI_uniquename(ListBase *list, void *vlink, const char defname[], char deli
        
        if (GIVE_STRADDR(vlink, name_offs) == '\0') {
                /* give it default name first */
-               BLI_strncpy(GIVE_STRADDR(vlink, name_offs), defname, len);
+               BLI_strncpy(GIVE_STRADDR(vlink, name_offs), defname, name_len);
        }
        
        /* See if we even need to do this */
        if (list == NULL)
                return;
-       
-       for (link = list->first; link; link= link->next) {
-               if (link != vlink) {
-                       if (!strcmp(GIVE_STRADDR(link, name_offs), GIVE_STRADDR(vlink, name_offs))) {
-                               exists = 1;
-                               break;
-                       }
-               }
-       }
-       if (exists == 0)
-               return;
 
-       /* Strip off the suffix */
-       dot = strrchr(GIVE_STRADDR(vlink, name_offs), delim);
-       if (dot)
-               *dot=0;
-       
-       for (number = 1; number <= 999; number++) {
-               BLI_snprintf(tempname, sizeof(tempname), "%s%c%03d", GIVE_STRADDR(vlink, name_offs), delim, number);
-               
-               exists = 0;
-               for (link= list->first; link; link= link->next) {
-                       if (vlink != link) {
-                               if (!strcmp(GIVE_STRADDR(link, name_offs), tempname)) {
-                                       exists = 1;
-                                       break;
-                               }
+       if(uniquename_find_dupe(list,vlink, GIVE_STRADDR(vlink, name_offs), name_offs)) {
+               /* note: this block is used in other places, when changing logic apply to all others, search this message */
+               char    tempname[128];
+               char    left[128];
+               int             number;
+               int             len= BLI_split_name_num(left, &number, GIVE_STRADDR(vlink, name_offs));
+               do {    /* nested while loop looks bad but likely it wont run most times */
+                       while(BLI_snprintf(tempname, name_len, "%s%c%03d", left, delim, number) >= name_len) {
+                               if(len > 0)     left[--len]= '\0';      /* word too long */
+                               else            number= 0;                      /* reset, must be a massive number */
                        }
-               }
-               if (exists == 0) {
-                       BLI_strncpy(GIVE_STRADDR(vlink, name_offs), tempname, len);
-                       return;
-               }
+               } while(number++, uniquename_find_dupe(list, vlink, tempname, name_offs));
+               
+               BLI_strncpy(GIVE_STRADDR(vlink, name_offs), tempname, name_len);
        }
 }
 
index fd747cc..0be27e9 100644 (file)
@@ -509,28 +509,23 @@ static EditBone *editbone_name_exists (ListBase *edbo, const char *name)
 void unique_editbone_name (ListBase *edbo, char *name, EditBone *bone)
 {
        EditBone *dupli;
-       char    tempname[64];
-       int             number;
-       char    *dot;
 
        dupli = editbone_name_exists(edbo, name);
        
        if (dupli && bone != dupli) {
-               /*      Strip off the suffix, if it's a number */
-               number= strlen(name);
-               if (number && isdigit(name[number-1])) {
-                       dot= strrchr(name, '.');        // last occurrence
-                       if (dot)
-                               *dot=0;
-               }
-               
-               for (number = 1; number <= 999; number++) {
-                       sprintf(tempname, "%s.%03d", name, number);
-                       if (!editbone_name_exists(edbo, tempname)) {
-                               BLI_strncpy(name, tempname, 32);
-                               return;
+               /* note: this block is used in other places, when changing logic apply to all others, search this message */
+               char    tempname[sizeof(bone->name)];
+               char    left[sizeof(bone->name)];
+               int             number;
+               int             len= BLI_split_name_num(left, &number, name);
+               do {    /* nested while loop looks bad but likely it wont run most times */
+                       while(BLI_snprintf(tempname, sizeof(tempname), "%s.%03d", left, number) >= sizeof(tempname)) {
+                               if(len > 0)     left[--len]= '\0';      /* word too long */
+                               else            number= 0;                      /* reset, must be a massive number */
                        }
-               }
+               } while(number++, ((dupli= editbone_name_exists(edbo, tempname)) && bone != dupli));
+
+               BLI_strncpy(name, tempname, sizeof(bone->name));
        }
 }
 
@@ -5389,29 +5384,22 @@ void POSE_OT_reveal(wmOperatorType *ot)
 /* ************* RENAMING DISASTERS ************ */
 
 /* note: there's a unique_editbone_name() too! */
-void unique_bone_name (bArmature *arm, char *name)
-{
-       char            tempname[64];
-       int                     number;
-       char            *dot;
-       
+static void unique_bone_name (bArmature *arm, char *name)
+{      
        if (get_named_bone(arm, name)) {
-               
-               /*      Strip off the suffix, if it's a number */
-               number= strlen(name);
-               if(number && isdigit(name[number-1])) {
-                       dot= strrchr(name, '.');        // last occurrence
-                       if (dot)
-                               *dot=0;
-               }
-               
-               for (number = 1; number <=999; number++) {
-                       sprintf (tempname, "%s.%03d", name, number);
-                       if (!get_named_bone(arm, tempname)) {
-                               BLI_strncpy (name, tempname, 32);
-                               return;
+               /* note: this block is used in other places, when changing logic apply to all others, search this message */
+               char    tempname[sizeof(((Bone *)NULL)->name)];
+               char    left[sizeof(((Bone *)NULL)->name)];
+               int             number;
+               int             len= BLI_split_name_num(left, &number, name);
+               do {    /* nested while loop looks bad but likely it wont run most times */
+                       while(BLI_snprintf(tempname, sizeof(tempname), "%s.%03d", left, number) >= sizeof(tempname)) {
+                               if(len > 0)     left[--len]= '\0';      /* word too long */
+                               else            number= 0;                      /* reset, must be a massive number */
                        }
-               }
+               } while(number++, get_named_bone(arm, tempname));
+
+               BLI_strncpy(name, tempname, sizeof(tempname));
        }
 }
 
index 015fab0..dd4864f 100644 (file)
@@ -596,7 +596,7 @@ static void vgroup_select_verts(Object *ob, int select)
 static void vgroup_duplicate(Object *ob)
 {
        bDeformGroup *dg, *cdg;
-       char name[32], s[32];
+       char name[sizeof(dg->name)];
        MDeformWeight *org, *cpy;
        MDeformVert *dvert, **dvert_array=NULL;
        int i, idg, icdg, dvert_tot=0;
@@ -605,26 +605,17 @@ static void vgroup_duplicate(Object *ob)
        if(!dg)
                return;
        
-       if(strstr(dg->name, "_copy")) {
-               BLI_strncpy(name, dg->name, 32); /* will be renamed _copy.001... etc */
+       if(!strstr(dg->name, "_copy")) {
+               BLI_snprintf(name, sizeof(name), "%s_copy", dg->name);
        }
        else {
-               BLI_snprintf(name, 32, "%s_copy", dg->name);
-               while(defgroup_find_name(ob, name)) {
-                       if((strlen(name) + 6) > 32) {
-                               if (G.f & G_DEBUG)
-                                       printf("Internal error: the name for the new vertex group is > 32 characters");
-                               return;
-                       }
-                       strcpy(s, name);
-                       BLI_snprintf(name, 32, "%s_copy", s);
-               }
-       }               
+               BLI_snprintf(name, sizeof(name), "%s", dg->name);
+       }
 
        cdg = defgroup_duplicate(dg);
        strcpy(cdg->name, name);
        defgroup_unique_name(cdg, ob);
-       
+
        BLI_addtail(&ob->defbase, cdg);
 
        idg = (ob->actdef-1);
index 22143db..f5c1612 100644 (file)
@@ -191,7 +191,7 @@ static SpaceLink *view3d_new(const bContext *C)
                v3d->lay= v3d->layact= scene->lay;
                v3d->camera= scene->camera;
        }
-       v3d->scenelock= 1;
+       v3d->scenelock= TRUE;
        v3d->grid= 1.0f;
        v3d->gridlines= 16;
        v3d->gridsubdiv = 10;
@@ -250,8 +250,8 @@ static SpaceLink *view3d_new(const bContext *C)
        ar->regiondata= MEM_callocN(sizeof(RegionView3D), "region view3d");
        rv3d= ar->regiondata;
        rv3d->viewquat[0]= 1.0f;
-       rv3d->persp= 1;
-       rv3d->view= 7;
+       rv3d->persp= RV3D_PERSP;
+       rv3d->view= RV3D_VIEW_PERSPORTHO;
        rv3d->dist= 10.0;
        
        return (SpaceLink *)v3d;
index a01a3b1..2d93646 100644 (file)
@@ -86,33 +86,23 @@ TransformOrientation* findOrientationName(bContext *C, char *name)
        return NULL;
 }
 
-void uniqueOrientationName(bContext *C, char *name)
+static void uniqueOrientationName(bContext *C, char *name)
 {
        if (findOrientationName(C, name) != NULL)
        {
-               char            tempname[64];
-               int                     number;
-               char            *dot;
-
-               
-               number = strlen(name);
-
-               if (number && isdigit(name[number-1]))
-               {
-                       dot = strrchr(name, '.');       // last occurrence
-                       if (dot)
-                               *dot=0;
-               }
-
-               for (number = 1; number <= 999; number++)
-               {
-                       sprintf(tempname, "%s.%03d", name, number);
-                       if (findOrientationName(C, tempname) == NULL)
-                       {
-                               BLI_strncpy(name, tempname, 32);
-                               break;
+               /* note: this block is used in other places, when changing logic apply to all others, search this message */
+               char    tempname[sizeof(((TransformOrientation *)NULL)->name)];
+               char    left[sizeof(((TransformOrientation *)NULL)->name)];
+               int             number;
+               int             len= BLI_split_name_num(left, &number, name);
+               do {    /* nested while loop looks bad but likely it wont run most times */
+                       while(BLI_snprintf(tempname, sizeof(tempname), "%s.%03d", left, number) >= sizeof(tempname)) {
+                               if(len > 0)     left[--len]= '\0';      /* word too long */
+                               else            number= 0;                      /* reset, must be a massive number */
                        }
-               }
+               } while(number++, findOrientationName(C, tempname));
+       
+               BLI_strncpy(name, tempname, sizeof(tempname));  
        }
 }