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 |