Some of the stupidity from the previous commit was copied from here

This commit is contained in:
Michael Natterer 2010-02-08 00:28:47 +01:00
parent 2cb6669d01
commit 52eaf96a6c
1 changed files with 53 additions and 45 deletions

View File

@ -491,8 +491,8 @@ static void
gimp_list_uniquefy_name (GimpList *gimp_list,
GimpObject *object)
{
gchar *name = (gchar *) gimp_object_get_name (object);
GList *list;
const gchar *name = gimp_object_get_name (object);
if (! name)
return;
@ -505,31 +505,39 @@ gimp_list_uniquefy_name (GimpList *gimp_list,
if (object != object2 &&
name2 &&
! strcmp (name, name2))
break;
}
if (list)
{
GList *list2;
gchar *ext = strrchr (name, '#');
gchar *ext;
gchar *new_name = NULL;
gint unique_ext = 0;
name = g_strdup (name);
ext = strrchr (name, '#');
if (ext)
{
gchar *ext_str;
gchar ext_str[8];
unique_ext = atoi (ext + 1);
ext_str = g_strdup_printf ("%d", unique_ext);
g_snprintf (ext_str, sizeof (ext_str), "%d", unique_ext);
/* check if the extension really is of the form "#<n>" */
if (! strcmp (ext_str, ext + 1))
{
if (ext > name && *(ext - 1) == ' ')
ext--;
*ext = '\0';
}
else
{
unique_ext = 0;
}
g_free (ext_str);
}
do
@ -540,10 +548,10 @@ gimp_list_uniquefy_name (GimpList *gimp_list,
new_name = g_strdup_printf ("%s #%d", name, unique_ext);
for (list2 = gimp_list->list; list2; list2 = g_list_next (list2))
for (list = gimp_list->list; list; list = g_list_next (list))
{
object2 = list2->data;
name2 = gimp_object_get_name (object2);
GimpObject *object2 = list->data;
const gchar *name2 = gimp_object_get_name (object2);
if (object != object2 &&
name2 &&
@ -551,11 +559,11 @@ gimp_list_uniquefy_name (GimpList *gimp_list,
break;
}
}
while (list2);
while (list);
g_free (name);
gimp_object_take_name (object, new_name);
break;
}
}
}