#define DBG 1 #define ARG 0 #include "frmwrk/inc/main.h" /* --------------------------------------------------------------------- */ #include "include/list.h" #include #include /* macros ============================================================== */ /* constants =========================================================== */ /* types =============================================================== */ /* structures ========================================================== */ /* private variables =================================================== */ /* private functions =================================================== */ /* internal public functions =========================================== */ list_s *list_first (list_s *l) { for (; l && l->prev; l = list_prev (l)) { } return l; } list_s *list_append (list_s *l, void *data) { list_s *tmp = l; if (l) { for (l = list_first (l); l->next; l = list_next (l)) { } } { list_s *new = NULL; new = malloc (sizeof (*new)); if (new) { if (l) { l->next = new; } new->prev = l; new->next = NULL; new->data = data; tmp = new; } else { fprintf (stderr, "Memoire insufisante\n"); exit (EXIT_FAILURE); } } return tmp; } list_s *list_remove (list_s *l, void *data) { list_s *tmp = NULL; if (l) { for (l = list_first (l); l->data != data; l = list_next (l)) { } { list_s *prev = l->prev; list_s *next = l->next; if (prev) { prev->next = next; tmp = prev; } if (next) { next->prev = prev; if (!tmp) { tmp = next; } } free (l), l = NULL; } } return tmp; } void list_foreach (list_s *l, void (*func) (void *, void *), void *user_data) { for (l = list_first (l); l; l = list_next (l)) { func (l->data, user_data); } } size_t list_size (list_s *l) { size_t size = 0; if (l) { l = list_first (l); while (l) { size++; l = list_next (l); } } return size; } /* entry points ======================================================== */ /* public variables ==================================================== */