Skip to content

Commit

Permalink
collection_info_list_to_dnd_data(): simplify and optimize.
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurent Monin committed Jun 10, 2008
1 parent 55be71b commit 554bfe9
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions src/collect.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,63 +472,59 @@ CollectionData *collection_from_dnd_data(const gchar *data, GList **list, GList

gchar *collection_info_list_to_dnd_data(CollectionData *cd, GList *list, gint *length)
{
gchar *uri_text = NULL;
gint total;
GList *work;
gint n;
GList *temp;
GList *temp = NULL;
gchar *ptr;
gchar *text;
gchar *uri_text;
gint collection_number;

n = collection_to_number(cd);
*length = 0;
if (!list) return NULL;

if (!list || n < 0)
{
*length = 0;
return NULL;
}
collection_number = collection_to_number(cd);
if (collection_number < 0) return NULL;

text = g_strdup_printf("COLLECTION:%d\n", collection_number);
*length += strlen(text);
temp = g_list_prepend(temp, text);

temp = NULL;
temp = g_list_prepend(temp, g_strdup_printf("COLLECTION:%d\n", n));
work = list;
while (work)
{
n = g_list_index(cd->list, work->data);
if (n >= 0)
{
temp = g_list_prepend(temp, g_strdup_printf("%d\n", n));
}
work = work->next;
}
gint item_number = g_list_index(cd->list, work->data);

total = 0;
work = temp;
while (work)
{
total += strlen((gchar *)work->data);
work = work->next;

if (item_number < 0) continue;

text = g_strdup_printf("%d\n", item_number);
temp = g_list_prepend(temp, text);
*length += strlen(text);
}
total += 1;

uri_text = g_malloc(total);
*length += 1; /* ending nul char */

uri_text = g_malloc(*length);
ptr = uri_text;

work = g_list_last(temp);
while (work)
{
gint len;
gchar *text = work->data;

work = work->prev;

strcpy(ptr, text);
ptr += strlen(text);
len = strlen(text);
memcpy(ptr, text, len);
ptr += len;
}

ptr[0] = '\0';

string_list_free(temp);

*length = total;

return uri_text;
}

Expand Down

0 comments on commit 554bfe9

Please sign in to comment.