2005-01-31 09:44:30 -08:00
|
|
|
/*
|
|
|
|
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
|
|
|
*/
|
2002-11-08 00:02:15 -08:00
|
|
|
#include "evas_common.h"
|
|
|
|
#include "evas_private.h"
|
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
static int _evas_list_alloc_error = 0;
|
|
|
|
|
|
|
|
/**
|
2004-08-15 22:13:25 -07:00
|
|
|
* @defgroup Evas_List_Data_Group Linked List Creation Functions
|
|
|
|
*
|
|
|
|
* Functions that add data to an Evas_List.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Appends the given data to the given linked list.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-08-15 22:13:25 -07:00
|
|
|
* The following example code demonstrates how to ensure that the
|
|
|
|
* given data has been successfully appended.
|
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* @code
|
|
|
|
* Evas_List *list = NULL;
|
|
|
|
* extern void *my_data;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* list = evas_list_append(list, my_data);
|
|
|
|
* if (evas_list_alloc_error())
|
|
|
|
* {
|
|
|
|
* fprintf(stderr, "ERROR: Memory is low. List allocation failed.\n");
|
|
|
|
* exit(-1);
|
|
|
|
* }
|
|
|
|
* @endcode
|
2004-08-15 22:13:25 -07:00
|
|
|
*
|
|
|
|
* @param list The given list. If @c NULL is given, then a new list
|
|
|
|
* is created.
|
|
|
|
* @param data The data to append.
|
|
|
|
* @return A new list pointer that should be used in place of the one
|
|
|
|
* given to this function if successful. Otherwise, the old
|
|
|
|
* pointer is returned.
|
|
|
|
* @ingroup Evas_List_Data_Group
|
2002-11-13 05:15:30 -08:00
|
|
|
*/
|
2002-11-08 00:02:15 -08:00
|
|
|
Evas_List *
|
2003-01-09 20:58:51 -08:00
|
|
|
evas_list_append(Evas_List *list, const void *data)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
|
|
|
Evas_List *l, *new_l;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
_evas_list_alloc_error = 0;
|
2002-11-08 00:02:15 -08:00
|
|
|
new_l = malloc(sizeof(Evas_List));
|
2002-11-13 05:15:30 -08:00
|
|
|
if (!new_l)
|
|
|
|
{
|
|
|
|
_evas_list_alloc_error = 1;
|
|
|
|
return list;
|
|
|
|
}
|
2002-11-08 00:02:15 -08:00
|
|
|
new_l->next = NULL;
|
|
|
|
new_l->prev = NULL;
|
2003-01-09 20:58:51 -08:00
|
|
|
new_l->data = (void *)data;
|
2005-05-21 19:49:50 -07:00
|
|
|
if (!list)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
|
|
|
new_l->last = new_l;
|
|
|
|
new_l->count = 1;
|
|
|
|
return new_l;
|
|
|
|
}
|
|
|
|
if (list->last)
|
|
|
|
{
|
|
|
|
l = list->last;
|
|
|
|
l->next = new_l;
|
|
|
|
new_l->prev = l;
|
|
|
|
list->last = new_l;
|
|
|
|
list->count++;
|
2005-05-21 19:49:50 -07:00
|
|
|
return list;
|
2002-11-08 00:02:15 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (l = list; l; l = l->next)
|
|
|
|
{
|
|
|
|
if (!l->next)
|
|
|
|
{
|
|
|
|
l->next = new_l;
|
|
|
|
new_l->prev = l;
|
|
|
|
list->last = new_l;
|
|
|
|
list->count++;
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
/**
|
2004-08-15 22:13:25 -07:00
|
|
|
* Prepends the given data to the given linked list.
|
|
|
|
*
|
|
|
|
* The following example code demonstrates how to ensure that the
|
|
|
|
* given data has been successfully prepended.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* Evas_List *list = NULL;
|
|
|
|
* extern void *my_data;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* list = evas_list_prepend(list, my_data);
|
|
|
|
* if (evas_list_alloc_error())
|
|
|
|
* {
|
|
|
|
* fprintf(stderr, "ERROR: Memory is low. List allocation failed.\n");
|
|
|
|
* exit(-1);
|
|
|
|
* }
|
|
|
|
* @endcode
|
2004-08-15 22:13:25 -07:00
|
|
|
*
|
|
|
|
* @param list The given list.
|
|
|
|
* @param data The given data.
|
|
|
|
* @return A new list pointer that should be used in place of the one
|
|
|
|
* given to this function, if successful. Otherwise, the old
|
|
|
|
* pointer is returned.
|
|
|
|
* @ingroup Evas_List_Data_Group
|
2002-11-13 05:15:30 -08:00
|
|
|
*/
|
2002-11-08 00:02:15 -08:00
|
|
|
Evas_List *
|
2003-01-09 20:58:51 -08:00
|
|
|
evas_list_prepend(Evas_List *list, const void *data)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
|
|
|
Evas_List *new_l;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
_evas_list_alloc_error = 0;
|
2002-11-08 00:02:15 -08:00
|
|
|
new_l = malloc(sizeof(Evas_List));
|
2002-11-13 05:15:30 -08:00
|
|
|
if (!new_l)
|
|
|
|
{
|
|
|
|
_evas_list_alloc_error = 1;
|
|
|
|
return list;
|
|
|
|
}
|
2002-11-08 00:02:15 -08:00
|
|
|
new_l->prev = NULL;
|
2003-01-09 20:58:51 -08:00
|
|
|
new_l->data = (void *)data;
|
2005-05-21 19:49:50 -07:00
|
|
|
if (!list)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
|
|
|
new_l->next = NULL;
|
|
|
|
new_l->last = new_l;
|
|
|
|
new_l->count = 1;
|
|
|
|
return new_l;
|
|
|
|
}
|
|
|
|
new_l->next = list;
|
|
|
|
list->prev = new_l;
|
|
|
|
new_l->last = list->last;
|
|
|
|
list->last = NULL;
|
|
|
|
new_l->count = list->count + 1;
|
|
|
|
return new_l;
|
|
|
|
}
|
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
/**
|
2004-08-15 22:13:25 -07:00
|
|
|
* Inserts the given data into the given linked list after the specified data.
|
|
|
|
*
|
|
|
|
* If @p relative is not in the list, @p data is appended to the end of the
|
2005-05-21 19:49:50 -07:00
|
|
|
* list. If there are multiple instances of @p relative in the list,
|
2004-08-15 22:13:25 -07:00
|
|
|
* @p data is inserted after the first instance.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-08-15 22:13:25 -07:00
|
|
|
* The following example code demonstrates how to ensure that the
|
|
|
|
* given data has been successfully inserted.
|
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* @code
|
|
|
|
* Evas_List *list = NULL;
|
|
|
|
* extern void *my_data;
|
|
|
|
* extern void *relative_member;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* list = evas_list_append(list, relative_member);
|
|
|
|
* if (evas_list_alloc_error())
|
|
|
|
* {
|
|
|
|
* fprintf(stderr, "ERROR: Memory is low. List allocation failed.\n");
|
|
|
|
* exit(-1);
|
|
|
|
* }
|
|
|
|
* list = evas_list_append_relative(list, my_data, relative_member);
|
|
|
|
* if (evas_list_alloc_error())
|
|
|
|
* {
|
|
|
|
* fprintf(stderr, "ERROR: Memory is low. List allocation failed.\n");
|
|
|
|
* exit(-1);
|
|
|
|
* }
|
|
|
|
* @endcode
|
2004-08-15 22:13:25 -07:00
|
|
|
*
|
|
|
|
* @param list The given linked list.
|
|
|
|
* @param data The given data.
|
|
|
|
* @param relative The data to insert after.
|
|
|
|
* @return A new list pointer that should be used in place of the one
|
|
|
|
* given to this function if successful. Otherwise, the old pointer
|
|
|
|
* is returned.
|
|
|
|
* @ingroup Evas_List_Data_Group
|
2002-11-13 05:15:30 -08:00
|
|
|
*/
|
2002-11-08 00:02:15 -08:00
|
|
|
Evas_List *
|
2003-01-09 20:58:51 -08:00
|
|
|
evas_list_append_relative(Evas_List *list, const void *data, const void *relative)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
|
|
|
Evas_List *l;
|
2002-11-13 05:15:30 -08:00
|
|
|
|
|
|
|
_evas_list_alloc_error = 0;
|
2002-11-08 00:02:15 -08:00
|
|
|
for (l = list; l; l = l->next)
|
|
|
|
{
|
|
|
|
if (l->data == relative)
|
|
|
|
{
|
|
|
|
Evas_List *new_l;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2002-11-08 00:02:15 -08:00
|
|
|
new_l = malloc(sizeof(Evas_List));
|
2002-11-13 05:15:30 -08:00
|
|
|
if (!new_l)
|
|
|
|
{
|
|
|
|
_evas_list_alloc_error = 1;
|
|
|
|
return list;
|
|
|
|
}
|
2003-01-09 20:58:51 -08:00
|
|
|
new_l->data = (void *)data;
|
2002-11-08 00:02:15 -08:00
|
|
|
if (l->next)
|
|
|
|
{
|
|
|
|
new_l->next = l->next;
|
|
|
|
l->next->prev = new_l;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
new_l->next = NULL;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2002-11-08 00:02:15 -08:00
|
|
|
l->next = new_l;
|
|
|
|
new_l->prev = l;
|
|
|
|
if (!new_l->next) list->last = new_l;
|
|
|
|
list->count++;
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return evas_list_append(list, data);
|
|
|
|
}
|
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
/**
|
|
|
|
* Prepend a data pointer to a linked list before the memeber specified
|
|
|
|
* @param list The list handle to prepend @p data too
|
|
|
|
* @param data The data pointer to prepend to list @p list before @p relative
|
|
|
|
* @param relative The data pointer before which to insert @p data
|
|
|
|
* @return A new list handle to replace the old one
|
2004-08-15 22:13:25 -07:00
|
|
|
|
|
|
|
* Inserts the given data into the given linked list before the member
|
|
|
|
* specified.
|
|
|
|
*
|
|
|
|
* If @p relative is not in the list, @p data is prepended to the
|
|
|
|
* start of the list. If there are multiple instances of @p relative
|
|
|
|
* in the list, @p data is inserted before the first instance.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-08-15 22:13:25 -07:00
|
|
|
* The following code example demonstrates how to ensure that the
|
|
|
|
* given data has been successfully inserted.
|
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* @code
|
|
|
|
* Evas_List *list = NULL;
|
|
|
|
* extern void *my_data;
|
|
|
|
* extern void *relative_member;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* list = evas_list_append(list, relative_member);
|
|
|
|
* if (evas_list_alloc_error())
|
|
|
|
* {
|
|
|
|
* fprintf(stderr, "ERROR: Memory is low. List allocation failed.\n");
|
|
|
|
* exit(-1);
|
|
|
|
* }
|
|
|
|
* list = evas_list_prepend_relative(list, my_data, relative_member);
|
|
|
|
* if (evas_list_alloc_error())
|
|
|
|
* {
|
|
|
|
* fprintf(stderr, "ERROR: Memory is low. List allocation failed.\n");
|
|
|
|
* exit(-1);
|
|
|
|
* }
|
|
|
|
* @endcode
|
2004-08-15 22:13:25 -07:00
|
|
|
*
|
|
|
|
* @param list The given linked list.
|
|
|
|
* @param data The given data.
|
|
|
|
* @param relative The data to insert before.
|
|
|
|
* @return A new list pointer that should be used in place of the one
|
|
|
|
* given to this function if successful. Otherwise the old pointer
|
|
|
|
* is returned.
|
|
|
|
* @ingroup Evas_List_Data_Group
|
2002-11-13 05:15:30 -08:00
|
|
|
*/
|
2002-11-08 00:02:15 -08:00
|
|
|
Evas_List *
|
2003-01-09 20:58:51 -08:00
|
|
|
evas_list_prepend_relative(Evas_List *list, const void *data, const void *relative)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
|
|
|
Evas_List *l;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
_evas_list_alloc_error = 0;
|
2002-11-08 00:02:15 -08:00
|
|
|
for (l = list; l; l = l->next)
|
|
|
|
{
|
|
|
|
if (l->data == relative)
|
|
|
|
{
|
|
|
|
Evas_List *new_l;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2002-11-08 00:02:15 -08:00
|
|
|
new_l = malloc(sizeof(Evas_List));
|
2002-11-13 05:15:30 -08:00
|
|
|
if (!new_l)
|
|
|
|
{
|
|
|
|
_evas_list_alloc_error = 1;
|
|
|
|
return list;
|
|
|
|
}
|
2003-01-09 20:58:51 -08:00
|
|
|
new_l->data = (void *)data;
|
2002-11-08 00:02:15 -08:00
|
|
|
new_l->prev = l->prev;
|
|
|
|
new_l->next = l;
|
|
|
|
if (l->prev) l->prev->next = new_l;
|
|
|
|
l->prev = new_l;
|
|
|
|
if (new_l->prev)
|
|
|
|
{
|
|
|
|
if (!new_l->next) list->last = new_l;
|
|
|
|
list->count++;
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
new_l->last = list->last;
|
|
|
|
list->last = NULL;
|
|
|
|
new_l->count = list->count + 1;
|
|
|
|
return new_l;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return evas_list_prepend(list, data);
|
|
|
|
}
|
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
/**
|
2004-08-15 22:13:25 -07:00
|
|
|
* @defgroup Evas_List_Remove_Group Linked List Remove Functions
|
|
|
|
*
|
|
|
|
* Functions that remove data from linked lists.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the first instance of the specified data from the given list.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-08-15 22:13:25 -07:00
|
|
|
* If the specified data is not in the given list, nothing is done.
|
|
|
|
*
|
|
|
|
* @param list The given list.
|
|
|
|
* @param data The specified data.
|
2005-05-21 19:49:50 -07:00
|
|
|
* @return A new list pointer that should be used in place of the one
|
2004-08-15 22:13:25 -07:00
|
|
|
* passed to this functions.
|
|
|
|
* @ingroup Evas_List_Remove_Group
|
2002-11-13 05:15:30 -08:00
|
|
|
*/
|
2002-11-08 00:02:15 -08:00
|
|
|
Evas_List *
|
2003-01-09 20:58:51 -08:00
|
|
|
evas_list_remove(Evas_List *list, const void *data)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
|
|
|
Evas_List *l;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2002-11-08 00:02:15 -08:00
|
|
|
for (l = list; l; l = l->next)
|
|
|
|
{
|
|
|
|
if (l->data == data)
|
|
|
|
return evas_list_remove_list(list, l);
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
/**
|
2004-08-15 22:13:25 -07:00
|
|
|
* Removes the specified data
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* Remove a specified member from a list
|
|
|
|
* @param list The list handle to remove @p remove_list from
|
|
|
|
* @param remove_list The list node which is to be removed
|
|
|
|
* @return A new list handle to replace the old one
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* Calling this function takes the list note @p remove_list and removes it
|
|
|
|
* from the list @p list, freeing the list node structure @p remove_list.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* extern Evas_List *list;
|
|
|
|
* Evas_List *l;
|
|
|
|
* extern void *my_data;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* for (l = list; l; l= l->next)
|
|
|
|
* {
|
|
|
|
* if (l->data == my_data)
|
|
|
|
* {
|
|
|
|
* list = evas_list_remove_list(list, l);
|
|
|
|
* break;
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* @endcode
|
2004-08-15 22:13:25 -07:00
|
|
|
* @ingroup Evas_List_Remove_Group
|
2002-11-13 05:15:30 -08:00
|
|
|
*/
|
2002-11-08 00:02:15 -08:00
|
|
|
Evas_List *
|
|
|
|
evas_list_remove_list(Evas_List *list, Evas_List *remove_list)
|
|
|
|
{
|
|
|
|
Evas_List *return_l;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2002-11-08 00:02:15 -08:00
|
|
|
if (!remove_list) return list;
|
|
|
|
if (remove_list->next) remove_list->next->prev = remove_list->prev;
|
|
|
|
if (remove_list->prev)
|
|
|
|
{
|
|
|
|
remove_list->prev->next = remove_list->next;
|
|
|
|
return_l = list;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (remove_list->next)
|
|
|
|
remove_list->next->count = remove_list->count;
|
|
|
|
return_l = remove_list->next;
|
|
|
|
if (return_l) return_l->last = list->last;
|
|
|
|
}
|
|
|
|
if (remove_list == list->last) list->last = remove_list->prev;
|
|
|
|
free(remove_list);
|
|
|
|
if (return_l) return_l->count--;
|
|
|
|
return return_l;
|
|
|
|
}
|
|
|
|
|
2004-08-15 22:13:25 -07:00
|
|
|
/**
|
|
|
|
* @defgroup Evas_List_Find_Group Linked List Find Functions
|
|
|
|
*
|
|
|
|
* Functions that find specified data in a linked list.
|
|
|
|
*/
|
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
/**
|
|
|
|
* Find a member of a list and return the member
|
|
|
|
* @param list The list handle to search for @p data
|
|
|
|
* @param data The data pointer to find in the list @p list
|
|
|
|
* @return The found member data pointer
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* A call to this function will search the list @p list from beginning to end
|
|
|
|
* for the first member whose data pointer is @p data. If it is found, @p data
|
|
|
|
* will be returned, otherwise NULL will be returned.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* extern Evas_List *list;
|
|
|
|
* extern void *my_data;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* if (evas_list_find(list, my_data) == my_data)
|
|
|
|
* {
|
|
|
|
* printf("Found member %p\n", my_data);
|
|
|
|
* }
|
|
|
|
* @endcode
|
2004-08-15 22:13:25 -07:00
|
|
|
* @ingroup Evas_List_Find_Group
|
2002-11-13 05:15:30 -08:00
|
|
|
*/
|
2002-11-08 00:02:15 -08:00
|
|
|
void *
|
2003-01-09 20:58:51 -08:00
|
|
|
evas_list_find(Evas_List *list, const void *data)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
|
|
|
Evas_List *l;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2002-11-08 00:02:15 -08:00
|
|
|
for (l = list; l; l = l->next)
|
|
|
|
{
|
2003-01-09 20:58:51 -08:00
|
|
|
if (l->data == data) return (void *)data;
|
2002-11-08 00:02:15 -08:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
/**
|
|
|
|
* Find a member of a list and return the list node containing that member
|
|
|
|
* @param list The list handle to search for @p data
|
|
|
|
* @param data The data pointer to find in the list @p list
|
|
|
|
* @return The found members list node
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* A call to this function will search the list @p list from beginning to end
|
|
|
|
* for the first member whose data pointer is @p data. If it is found, the
|
|
|
|
* list node containing the specified member will be returned, otherwise NULL
|
|
|
|
* will be returned.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* extern Evas_List *list;
|
|
|
|
* extern void *my_data;
|
|
|
|
* Evas_List *found_node;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* found_node = evas_list_find_list(list, my_data);
|
|
|
|
* if (found_node)
|
|
|
|
* {
|
|
|
|
* printf("Found member %p\n", found_node->data);
|
|
|
|
* }
|
|
|
|
* @endcode
|
2004-08-15 22:13:25 -07:00
|
|
|
* @ingroup Evas_List_Find_Group
|
2002-11-13 05:15:30 -08:00
|
|
|
*/
|
|
|
|
Evas_List *
|
2003-01-09 20:58:51 -08:00
|
|
|
evas_list_find_list(Evas_List *list, const void *data)
|
2002-11-13 05:15:30 -08:00
|
|
|
{
|
|
|
|
Evas_List *l;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
for (l = list; l; l = l->next)
|
|
|
|
{
|
|
|
|
if (l->data == data) return l;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free an entire list and all the nodes, ignoring the data contained
|
|
|
|
* @param list The list to free
|
|
|
|
* @return A NULL pointer
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* This function will free all the list nodes in list specified by @p list.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* extern Evas_List *list;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* list = evas_list_free(list);
|
|
|
|
* @endcode
|
2004-08-15 22:13:25 -07:00
|
|
|
* @ingroup Evas_List_Remove_Group
|
2002-11-13 05:15:30 -08:00
|
|
|
*/
|
2002-11-08 00:02:15 -08:00
|
|
|
Evas_List *
|
|
|
|
evas_list_free(Evas_List *list)
|
|
|
|
{
|
|
|
|
Evas_List *l, *free_l;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2002-11-08 00:02:15 -08:00
|
|
|
for (l = list; l;)
|
|
|
|
{
|
|
|
|
free_l = l;
|
|
|
|
l = l->next;
|
|
|
|
free(free_l);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-08-15 22:13:25 -07:00
|
|
|
/**
|
|
|
|
* @defgroup Evas_List_Traverse_Group Linked List Traverse Functions
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-08-15 22:13:25 -07:00
|
|
|
* Functions that you can use to traverse a linked list.
|
|
|
|
*/
|
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
/**
|
|
|
|
* Get the last list node in the list
|
|
|
|
* @param list The list to get the last list node from
|
|
|
|
* @return The last list node in the list @p list
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* This function will return the last list node in the list (or NULL if the
|
|
|
|
* list is empty).
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* NB: This is a order-1 operation (it takes the same short time regardless of
|
|
|
|
* the length of the list).
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* extern Evas_List *list;
|
|
|
|
* Evas_List *last, *l;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* last = evas_list_last(list);
|
|
|
|
* printf("The list in reverse:\n");
|
|
|
|
* for (l = last; l; l = l->prev)
|
|
|
|
* {
|
|
|
|
* printf("%p\n", l->data);
|
|
|
|
* }
|
|
|
|
* @endcode
|
2004-08-15 22:13:25 -07:00
|
|
|
* @ingroup Evas_List_Traverse_Group
|
2002-11-13 05:15:30 -08:00
|
|
|
*/
|
2002-11-08 00:02:15 -08:00
|
|
|
Evas_List *
|
|
|
|
evas_list_last(Evas_List *list)
|
|
|
|
{
|
|
|
|
if (!list) return NULL;
|
|
|
|
return list->last;
|
|
|
|
}
|
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
/**
|
|
|
|
* Get the next list node after the specified list node
|
|
|
|
* @param list The list node to get the next list node from
|
|
|
|
* @return The next list node, or NULL if no next list node exists
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* This function returns the next list node after the current one. It is
|
|
|
|
* equivalent to list->next.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* extern Evas_List *list;
|
|
|
|
* Evas_List *l;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* printf("The list:\n");
|
|
|
|
* for (l = list; l; l = evas_list_next(l))
|
|
|
|
* {
|
|
|
|
* printf("%p\n", l->data);
|
|
|
|
* }
|
|
|
|
* @endcode
|
2004-08-15 22:13:25 -07:00
|
|
|
* @ingroup Evas_List_Traverse_Group
|
2002-11-13 05:15:30 -08:00
|
|
|
*/
|
2002-11-08 00:02:15 -08:00
|
|
|
Evas_List *
|
|
|
|
evas_list_next(Evas_List *list)
|
|
|
|
{
|
|
|
|
if (!list) return NULL;
|
|
|
|
return list->next;
|
|
|
|
}
|
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
/**
|
|
|
|
* Get the previous list node before the specified list node
|
|
|
|
* @param list The list node to get the previous list node from
|
|
|
|
* @return The previous list node, or NULL if no previous list node exists
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* This function returns the previous list node before the current one. It is
|
|
|
|
* equivalent to list->prev.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* extern Evas_List *list;
|
|
|
|
* Evas_List *last, *l;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* last = evas_list_last(list);
|
|
|
|
* printf("The list in reverse:\n");
|
|
|
|
* for (l = last; l; l = evas_list_prev(l))
|
|
|
|
* {
|
|
|
|
* printf("%p\n", l->data);
|
|
|
|
* }
|
|
|
|
* @endcode
|
2004-08-15 22:13:25 -07:00
|
|
|
* @ingroup Evas_List_Traverse_Group
|
2002-11-13 05:15:30 -08:00
|
|
|
*/
|
2002-11-08 00:02:15 -08:00
|
|
|
Evas_List *
|
|
|
|
evas_list_prev(Evas_List *list)
|
|
|
|
{
|
|
|
|
if (!list) return NULL;
|
|
|
|
return list->prev;
|
|
|
|
}
|
|
|
|
|
2004-08-15 22:13:25 -07:00
|
|
|
/**
|
|
|
|
* @defgroup Evas_List_General_Group Linked List General Functions
|
|
|
|
*
|
|
|
|
* Miscellaneous functions that work on linked lists.
|
|
|
|
*/
|
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
/**
|
|
|
|
* Get the list node data member
|
|
|
|
* @param list The list node to get the data member of
|
|
|
|
* @return The data member from the list node @p list
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* This function returns the data member of the specified list node @p list.
|
|
|
|
* It is equivalent to list->data.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* Example:
|
2002-11-19 20:34:05 -08:00
|
|
|
* @code
|
2002-11-13 05:15:30 -08:00
|
|
|
* extern Evas_List *list;
|
|
|
|
* Evas_List *l;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* printf("The list:\n");
|
|
|
|
* for (l = list; l; l = evas_list_next(l))
|
|
|
|
* {
|
|
|
|
* printf("%p\n", evas_list_data(l));
|
|
|
|
* }
|
|
|
|
* @endcode
|
2004-08-15 22:13:25 -07:00
|
|
|
* @ingroup Evas_List_General_Group
|
2002-11-13 05:15:30 -08:00
|
|
|
*/
|
2002-11-08 00:02:15 -08:00
|
|
|
void *
|
|
|
|
evas_list_data(Evas_List *list)
|
|
|
|
{
|
|
|
|
if (!list) return NULL;
|
|
|
|
return list->data;
|
|
|
|
}
|
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
/**
|
|
|
|
* Get the count of the number of items in a list
|
|
|
|
* @param list The list whose count to return
|
|
|
|
* @return The number of members in the list @p list
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* This function returns how many members in the specified list: @p list. If
|
|
|
|
* the list is empty (NULL), 0 is returned.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* NB: This is an order-1 operation and takes the same tiem regardless of the
|
|
|
|
* length of the list.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* extern Evas_List *list;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* printf("The list has %i members\n", evas_list_count(list));
|
|
|
|
* @endcode
|
2004-08-15 22:13:25 -07:00
|
|
|
* @ingroup Evas_List_General_Group
|
2002-11-13 05:15:30 -08:00
|
|
|
*/
|
2002-11-08 00:02:15 -08:00
|
|
|
int
|
|
|
|
evas_list_count(Evas_List *list)
|
|
|
|
{
|
|
|
|
if (!list) return 0;
|
|
|
|
return list->count;
|
|
|
|
}
|
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
/**
|
|
|
|
* Get the nth member's data pointer in a list
|
|
|
|
* @param list The list to get member number @p n from
|
|
|
|
* @param n The number of the element (0 being the first)
|
|
|
|
* @return The data pointer stored in the specified element
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* This function returns the data pointer of element number @p n, in the list
|
|
|
|
* @p list. The first element in the array is element number 0. If the element
|
|
|
|
* number @p n does not exist, NULL will be returned.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* extern Evas_List *list;
|
|
|
|
* extern int number;
|
|
|
|
* void *data;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* data = evas_list_nth(list, number);
|
|
|
|
* if (data)
|
|
|
|
* printf("Element number %i has data %p\n", number, data);
|
|
|
|
* @endcode
|
2004-08-15 22:13:25 -07:00
|
|
|
* @ingroup Evas_List_Find_Group
|
2002-11-13 05:15:30 -08:00
|
|
|
*/
|
2002-11-08 00:02:15 -08:00
|
|
|
void *
|
|
|
|
evas_list_nth(Evas_List *list, int n)
|
|
|
|
{
|
2005-01-31 09:26:11 -08:00
|
|
|
Evas_List *l = evas_list_nth_list(list, n);
|
|
|
|
|
|
|
|
return l ? l->data : NULL;
|
2002-11-08 00:02:15 -08:00
|
|
|
}
|
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
/**
|
|
|
|
* Get the nth member's list node in a list
|
|
|
|
* @param list The list to get member number @p n from
|
|
|
|
* @param n The number of the element (0 being the first)
|
|
|
|
* @return The list node stored in the numbered element
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* This function returns the list node of element number @p n, in the list
|
|
|
|
* @p list. The first element in the array is element number 0. If the element
|
|
|
|
* number @p n does not exist, NULL will be returned.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* extern Evas_List *list;
|
|
|
|
* extern int number;
|
|
|
|
* Evas_List *nth_list;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* nth_list = evas_list_nth_list(list, number);
|
|
|
|
* if (nth_list)
|
|
|
|
* printf("Element number %i has data %p\n", number, nth_list->data);
|
|
|
|
* @endcode
|
2004-08-15 22:13:25 -07:00
|
|
|
* @ingroup Evas_List_Find_Group
|
2002-11-13 05:15:30 -08:00
|
|
|
*/
|
2002-11-08 00:02:15 -08:00
|
|
|
Evas_List *
|
2002-11-13 05:15:30 -08:00
|
|
|
evas_list_nth_list(Evas_List *list, int n)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
2002-11-13 05:15:30 -08:00
|
|
|
int i;
|
|
|
|
Evas_List *l;
|
2005-01-31 09:44:30 -08:00
|
|
|
|
|
|
|
/* check for non-existing nodes */
|
2005-01-31 19:12:26 -08:00
|
|
|
if ((!list) || (n < 0) || (n > list->count - 1)) return NULL;
|
2005-01-31 09:44:30 -08:00
|
|
|
|
|
|
|
/* if the node is in the 2nd half of the list, search from the end
|
|
|
|
* else, search from the beginning.
|
|
|
|
*/
|
|
|
|
if (n > list->count / 2)
|
2002-11-13 05:15:30 -08:00
|
|
|
{
|
2005-01-31 19:04:26 -08:00
|
|
|
for (i = list->count - 1, l = list->last; l; l = l->prev, i--)
|
2005-01-31 09:44:30 -08:00
|
|
|
{
|
|
|
|
if (i == n) return l;
|
|
|
|
}
|
2002-11-13 05:15:30 -08:00
|
|
|
}
|
2005-01-31 09:44:30 -08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0, l = list; l; l = l->next, i++)
|
|
|
|
{
|
|
|
|
if (i == n) return l;
|
|
|
|
}
|
|
|
|
}
|
2002-11-13 05:15:30 -08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-08-15 22:13:25 -07:00
|
|
|
/**
|
|
|
|
* @defgroup Evas_List_Ordering_Group Linked List Ordering Functions
|
|
|
|
*
|
|
|
|
* Functions that change the ordering of data in a linked list.
|
|
|
|
*/
|
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
/**
|
|
|
|
* Reverse all the elements in the list
|
|
|
|
* @param list The list to reverse
|
|
|
|
* @return The list after it has been reversed
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* This takes a list @p list, and reverses the order of all elements in the
|
|
|
|
* list, so the last member is now first, and so on.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* extern Evas_List *list;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* list = evas_list_reverse(list);
|
|
|
|
* @endcode
|
2004-08-15 22:13:25 -07:00
|
|
|
* @ingroup Evas_List_Ordering_Group
|
2002-11-13 05:15:30 -08:00
|
|
|
*/
|
|
|
|
Evas_List *
|
|
|
|
evas_list_reverse(Evas_List *list)
|
|
|
|
{
|
|
|
|
Evas_List *l1, *l2;
|
|
|
|
|
|
|
|
if (!list) return NULL;
|
|
|
|
l1 = list;
|
|
|
|
l2 = list->last;
|
|
|
|
while (l1 != l2)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
|
|
|
void *data;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2002-11-13 05:15:30 -08:00
|
|
|
data = l1->data;
|
|
|
|
l1->data = l2->data;
|
|
|
|
l2->data = data;
|
|
|
|
l1 = l1->next;
|
|
|
|
if (l1 == l2) break;
|
|
|
|
l2 = l2->prev;
|
2002-11-08 00:02:15 -08:00
|
|
|
}
|
2002-11-13 05:15:30 -08:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2004-03-23 23:23:51 -08:00
|
|
|
static Evas_List *
|
|
|
|
evas_list_combine(Evas_List *l, Evas_List *ll, int (*func)(void *, void*))
|
|
|
|
{
|
2005-04-21 01:28:21 -07:00
|
|
|
Evas_List *result = NULL;
|
|
|
|
Evas_List *l_head = NULL, *ll_head = NULL;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2005-04-21 01:28:21 -07:00
|
|
|
l_head = l;
|
|
|
|
ll_head = ll;
|
|
|
|
while (l && ll)
|
|
|
|
{
|
|
|
|
int cmp;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2005-04-21 01:28:21 -07:00
|
|
|
cmp = func(l->data, ll->data);
|
|
|
|
if (cmp < 0)
|
|
|
|
{
|
|
|
|
result = evas_list_append(result, l->data);
|
|
|
|
l = evas_list_next(l);
|
|
|
|
}
|
|
|
|
else if (cmp == 0)
|
|
|
|
{
|
|
|
|
result = evas_list_append(result, l->data);
|
|
|
|
l = evas_list_next(l);
|
|
|
|
result = evas_list_append(result, ll->data);
|
|
|
|
ll = evas_list_next(ll);
|
|
|
|
}
|
|
|
|
else if (cmp > 0)
|
|
|
|
{
|
|
|
|
result = evas_list_append(result, ll->data);
|
|
|
|
ll = evas_list_next(ll);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
l = ll = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (l)
|
|
|
|
{
|
2004-03-23 23:23:51 -08:00
|
|
|
result = evas_list_append(result, l->data);
|
|
|
|
l = evas_list_next(l);
|
2005-04-21 01:28:21 -07:00
|
|
|
}
|
|
|
|
evas_list_free(l_head);
|
|
|
|
while (ll)
|
|
|
|
{
|
2004-03-23 23:23:51 -08:00
|
|
|
result = evas_list_append(result, ll->data);
|
|
|
|
ll = evas_list_next(ll);
|
2005-04-21 01:28:21 -07:00
|
|
|
}
|
|
|
|
evas_list_free(ll_head);
|
|
|
|
return (result);
|
2004-03-23 23:23:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sort a list according to the ordering func will return
|
|
|
|
* @param list The list handle to sort
|
|
|
|
* @param size The length of the list to sort
|
|
|
|
* @param func A function pointer that can handle comparing the list data
|
|
|
|
* nodes
|
|
|
|
* @return A new sorted list
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-03-23 23:23:51 -08:00
|
|
|
* This function sorts your list. The data in your nodes can be arbitrary,
|
|
|
|
* you just have to be smart enough to know what kind of data is in your
|
|
|
|
* lists
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-03-23 23:23:51 -08:00
|
|
|
* In the event of a memory allocation failure, It might segv.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-03-23 23:23:51 -08:00
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* int
|
|
|
|
* sort_cb(void *d1, void *d2)
|
|
|
|
* {
|
|
|
|
* const char *txt = NULL;
|
|
|
|
* const char *txt2 = NULL;
|
|
|
|
*
|
|
|
|
* if(!d1) return(1);
|
|
|
|
* if(!d2) return(-1);
|
|
|
|
*
|
|
|
|
* return(strcmp((const char*)d1, (const char*)d2));
|
|
|
|
* }
|
|
|
|
* extern Evas_List *list;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-03-23 23:23:51 -08:00
|
|
|
* list = evas_list_sort(list, evas_list_count(list), sort_cb);
|
|
|
|
* if (evas_list_alloc_error())
|
|
|
|
* {
|
|
|
|
* fprintf(stderr, "ERROR: Memory is low. List Sorting failed.\n");
|
|
|
|
* exit(-1);
|
|
|
|
* }
|
|
|
|
* @endcode
|
2004-08-15 22:13:25 -07:00
|
|
|
* @ingroup Evas_List_Ordering_Group
|
2004-03-23 23:23:51 -08:00
|
|
|
*/
|
|
|
|
Evas_List *
|
|
|
|
evas_list_sort(Evas_List *list, int size, int (*func)(void *, void *))
|
|
|
|
{
|
2005-04-21 01:28:21 -07:00
|
|
|
Evas_List *l = NULL, *ll = NULL;
|
|
|
|
int mid;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2005-04-21 01:28:21 -07:00
|
|
|
if (!list || !func)
|
|
|
|
return NULL;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2005-04-21 01:28:21 -07:00
|
|
|
/* if the caller specified an invalid size, sort the whole list */
|
|
|
|
if (size <= 0 || size > list->count)
|
|
|
|
size = list->count;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2005-04-21 01:28:21 -07:00
|
|
|
mid = size / 2;
|
|
|
|
if (mid < 1)
|
|
|
|
return list;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2005-04-21 01:28:21 -07:00
|
|
|
/* bleh evas list splicing */
|
|
|
|
ll = evas_list_nth_list(list, mid);
|
|
|
|
if (ll->prev)
|
|
|
|
{
|
|
|
|
list->last = ll->prev;
|
|
|
|
list->count = mid;
|
|
|
|
ll->prev->next = NULL;
|
|
|
|
ll->prev = NULL;
|
|
|
|
}
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2005-04-21 01:28:21 -07:00
|
|
|
ll->count = size - mid;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2005-04-21 01:28:21 -07:00
|
|
|
/* merge sort */
|
|
|
|
l = evas_list_sort(list, mid, func);
|
|
|
|
ll = evas_list_sort(ll, size - mid, func);
|
|
|
|
list = evas_list_combine(l, ll, func);
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2005-04-21 01:28:21 -07:00
|
|
|
return(list);
|
2004-03-23 23:23:51 -08:00
|
|
|
}
|
2002-11-13 05:15:30 -08:00
|
|
|
/**
|
|
|
|
* Return the memory allocation failure flag after any operation needin allocation
|
|
|
|
* @return The state of the allocation flag
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* This function returns the state of the memory allocation flag. This flag is
|
|
|
|
* set if memory allocations during evas_list_append(), evas_list_prepend(),
|
|
|
|
* evas_list_append_relative(), or evas_list_prepend_relative() fail. If they
|
2002-11-19 20:34:05 -08:00
|
|
|
* do fail, 1 will be returned, otherwise 0 will be returned. The flag will
|
2002-11-13 05:15:30 -08:00
|
|
|
* remain in its current state until the next call that requires allocation
|
|
|
|
* is called, and is then reset.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* Evas_List *list = NULL;
|
|
|
|
* extern void *my_data;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2002-11-13 05:15:30 -08:00
|
|
|
* list = evas_list_append(list, my_data);
|
|
|
|
* if (evas_list_alloc_error())
|
|
|
|
* {
|
|
|
|
* fprintf(stderr, "ERROR: Memory is low. List allocation failed.\n");
|
|
|
|
* exit(-1);
|
|
|
|
* }
|
|
|
|
* @endcode
|
2004-08-15 22:13:25 -07:00
|
|
|
* @ingroup Evas_List_General_Group
|
2002-11-13 05:15:30 -08:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
evas_list_alloc_error(void)
|
|
|
|
{
|
|
|
|
return _evas_list_alloc_error;
|
2002-11-08 00:02:15 -08:00
|
|
|
}
|