diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-11-01 10:19:41 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-11-01 10:19:41 +0300 |
commit | daa4feaaeae4312eb23f66b948b668a7e9dc1959 (patch) | |
tree | dabd2bedd213f9fdfbfc31e6710b2913707dfa1f /source/blender/editors/transform/transform_orientations.c | |
parent | 8bbcef4c7a377045f6b93580efda93eb4adf800d (diff) |
bugfix [#24477] Can easily create bones with duplicate names
- 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
Diffstat (limited to 'source/blender/editors/transform/transform_orientations.c')
-rw-r--r-- | source/blender/editors/transform/transform_orientations.c | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c index a01a3b17cd2..2d936460c53 100644 --- a/source/blender/editors/transform/transform_orientations.c +++ b/source/blender/editors/transform/transform_orientations.c @@ -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)); } } |