//#include <stdlib.h>
#include "list.h"
#include "../../malloc.h"
+#include "../../string.h"
+#include "../../bootmii_ppc.h"
-list* list_create()
+struct list* list_create()
{
- list *l = (list*)malloc(sizeof(list));
+ struct list *l = (struct list*)malloc(sizeof(struct list));
l->head = NULL;
return l;
}
-u8 list_add_tail(list *l, element *e)
+u8 list_add_tail(struct list *l, struct element *e)
{
e->next = NULL;
}
/* find last element */
- element * iterator;
- iterator = l->head;
+ struct element *iterator = l->head;
while(iterator->next!=NULL) {
iterator = iterator->next;
-// FIXME: untested and unused!!
-u8 list_delete_element(list *l, element *e)
+// FIXME: untested
+u8 list_delete_element(struct list *l, struct element *e)
{
+ struct element *iterator = l->head;
+ struct element *delete = NULL;
+
+ if(!l->head) {
+ return 0;
+ } else {
+ if(l->head->data && !(memcmp(l->head->data, e->data, sizeof(struct element)))) {
+ delete = l->head;
+ l->head = NULL;
+ }
+ }
+
+ while(iterator->next!=NULL) {
+ if(iterator->next->data && !(memcmp(iterator->next->data, e->data, sizeof(struct element)))) {
+ delete = iterator->next;
+ iterator->next = iterator->next->next;
+ break;
+ }
+
+ iterator = iterator->next;
+ }
+
+ if(delete) {
+ free(delete->data);
+ free(delete);
+ }
+
return 1;
}
// FIXME: untested and unused!!
-u8 list_is_element_last(list *l, element *e)
+u8 list_is_element_last(struct list *l, struct element *e)
{
if(e->next==NULL)
return 1;
// FIXME: untested and unused!!
-element * list_find_next_element(list *l, element *e)
+struct element *list_find_next_element(struct list *l, struct element *e)
{
- element * iterator;
- iterator = l->head;
+ struct element *iterator = l->head;
while(iterator!=NULL){
if(iterator == e)