symlist.c

changeset 62
aae5facf9fc5
parent 60
a4033700e35c
child 88
308dfa54da3e
equal deleted inserted replaced
61:fc585645ad05 62:aae5facf9fc5
14 #include "misc.h" 14 #include "misc.h"
15 15
16 16
17 static void free_node(Symlist **symlist, Symlist *node) 17 static void free_node(Symlist **symlist, Symlist *node)
18 { 18 {
19 UNLINK_ITEM(*symlist, node, next, prev); 19 UNLINK_ITEM(*symlist, node, next, prev);
20 free(node); 20 free(node);
21 } 21 }
22 22
23 23
24 bool symlist_insert(Symlist **symlist, void *symbol) 24 bool symlist_insert(Symlist **symlist, void *symbol)
25 { 25 {
26 Symlist *node; 26 Symlist *node;
27 27
28 if(symbol==NULL) 28 if(symbol==NULL)
29 return FALSE; 29 return FALSE;
30 30
31 node=ALLOC(Symlist); 31 node=ALLOC(Symlist);
32 32
33 if(node==NULL) 33 if(node==NULL)
34 return FALSE; 34 return FALSE;
35 35
36 node->symbol=symbol; 36 node->symbol=symbol;
37 37
38 LINK_ITEM_FIRST(*symlist, node, next, prev); 38 LINK_ITEM_FIRST(*symlist, node, next, prev);
39 39
40 return TRUE; 40 return TRUE;
41 } 41 }
42 42
43 43
44 void symlist_remove(Symlist **symlist, void *symbol) 44 void symlist_remove(Symlist **symlist, void *symbol)
45 { 45 {
46 Symlist *node=*symlist; 46 Symlist *node=*symlist;
47 47
48 while(node!=NULL){ 48 while(node!=NULL){
49 if(node->symbol==symbol){ 49 if(node->symbol==symbol){
50 free_node(symlist, node); 50 free_node(symlist, node);
51 return; 51 return;
52 } 52 }
53 node=node->next; 53 node=node->next;
54 } 54 }
55 } 55 }
56 56
57 57
58 void symlist_clear(Symlist **symlist) 58 void symlist_clear(Symlist **symlist)
59 { 59 {
60 while(*symlist!=NULL) 60 while(*symlist!=NULL)
61 free_node(symlist, *symlist); 61 free_node(symlist, *symlist);
62 } 62 }
63 63
64 64
65 /* Warning: not thread-safe */ 65 /* Warning: not thread-safe */
66 66
68 static Symlist *iter_next=NULL; 68 static Symlist *iter_next=NULL;
69 69
70 70
71 void *symlist_init_iter(Symlist *symlist) 71 void *symlist_init_iter(Symlist *symlist)
72 { 72 {
73 if(symlist==NULL){ 73 if(symlist==NULL){
74 iter_next=NULL; 74 iter_next=NULL;
75 return NULL; 75 return NULL;
76 } 76 }
77 77
78 iter_next=symlist->next; 78 iter_next=symlist->next;
79 return symlist->symbol; 79 return symlist->symbol;
80 } 80 }
81 81
82 82
83 void *symlist_iter() 83 void *symlist_iter()
84 { 84 {
85 Symlist *ret; 85 Symlist *ret;
86 86
87 if(iter_next==NULL) 87 if(iter_next==NULL)
88 return NULL; 88 return NULL;
89 89
90 ret=iter_next; 90 ret=iter_next;
91 iter_next=iter_next->next; 91 iter_next=iter_next->next;
92 92
93 return ret->symbol; 93 return ret->symbol;
94 } 94 }
95 95

mercurial