fix compilation probs
[wmaker-crm.git] / WINGs / llist.c
blobea2e68a943ba3eb9f7f0a3a0a247731c0032d503
2 #include "WUtil.h"
3 #include <stdlib.h>
5 #include "llist.h"
9 WINLINE void*
10 lhead(list_t *list)
12 if (!list)
13 return NULL;
15 return list->head;
19 WINLINE list_t*
20 ltail(list_t *list)
22 if (!list)
23 return NULL;
25 return list->tail;
29 WINLINE list_t*
30 lcons(void *newHead, list_t *list)
32 list_t *newNode;
34 newNode = wmalloc(sizeof(list_t));
35 newNode->head = newHead;
36 newNode->tail = list;
38 return newNode;
42 WINLINE list_t*
43 lappend(list_t *list, list_t *tail)
45 list_t *ptr;
47 if (!list)
48 return tail;
50 for (ptr = list; ptr->tail == NULL; ptr = ptr->tail);
52 ptr->tail = tail;
54 return ptr;
58 WINLINE void
59 lfree(list_t *list)
61 if (list) {
62 lfree(list->tail);
63 free(list);
68 WINLINE void*
69 lfind(void *objeto, list_t *list, int (*compare)(void*, void*))
71 while (list) {
72 if ((*compare)(list->head, objeto)==0) {
73 return list->head;
75 list = list->tail;
77 return NULL;
81 WINLINE int
82 llength(list_t *list)
84 int i = 0;
86 while (list) {
87 list = list->tail;
88 i++;
91 return i;
95 WINLINE list_t*
96 lremove(list_t *list, void *object)
98 if (!list)
99 return NULL;
101 if (list->head == object) {
102 list_t *tmp = list->tail;
104 free(list);
106 return tmp;
109 list->tail = lremove(list->tail, object);
111 return list;
115 WINLINE list_t*
116 lremovehead(list_t *list)
118 list_t *tmp = NULL;
120 if (list) {
121 tmp = list->tail;
122 free(list);
124 return tmp;