some routines for removing a device on demand. thist do not work properly
[ppcskel.git] / usb / lib / list.c
index 05ffc078a12dc6ebebd385f6d240d67cb95d1442..9ea2090c5a0254eb6b430198380ff14d47cabcfb 100644 (file)
 //#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));
-  l->head = NULL;
-  return l;
+       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;
+       e->next = NULL;
 
-  /* if head is empty put first element here */
-  if(l->head==NULL){
-    l->head = e;
-    return 1;
-  }
+       /* if head is empty put first element here */
+       if(l->head==NULL){
+               l->head = e;
+               return 1;
+       }
 
-  /* find last element */
-  element * iterator;
-  iterator = l->head;
+       /* find last element */
+       struct element *iterator = l->head;
 
-  while(iterator->next!=NULL) {
-    iterator = iterator->next;
-  } 
-  iterator->next = e;
+       while(iterator->next!=NULL) {
+               iterator = iterator->next;
+       
+       iterator->next = e;
 
-  return 1;
+       return 1;
 }
 
 
 
-// FIXME: untested and unused!! 
-u8 list_delete_element(list *l, element *e)
+// FIXME: untested
+u8 list_delete_element(struct list *l, struct element *e)
 {
-  return 1;
+       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;
-  else
-    return 0;
+       if(e->next==NULL)
+               return 1;
+       else
+               return 0;
 }
 
 
 
 // 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;
-
-  while(iterator!=NULL){
-    if(iterator == e)
-      return iterator->next;
-    iterator = iterator->next;
-  }
-  return NULL;
+       struct element *iterator = l->head;
+
+       while(iterator!=NULL){
+               if(iterator == e)
+                       return iterator->next;
+               iterator = iterator->next;
+       }
+       return NULL;
 }