symlist.c

Mon, 17 Jan 2005 22:02:09 +0100

author
tuomov
date
Mon, 17 Jan 2005 22:02:09 +0100
changeset 85
9f94b2e96e3b
parent 62
aae5facf9fc5
child 88
308dfa54da3e
permissions
-rw-r--r--

trunk: changeset 1934
Fixed everything that requires locale stuff to check CF_NO_LOCALE.

60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
1 /*
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
2 * libtu/symlist.c
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
3 *
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
4 * Copyright (c) Tuomo Valkonen 1999-2004.
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
5 *
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
6 * You may distribute and modify this library under the terms of either
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
7 * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
8 */
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
9
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
10 #include "obj.h"
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
11 #include "symlist.h"
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
12 #include "types.h"
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
13 #include "dlist.h"
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
14 #include "misc.h"
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
15
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
16
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
17 static void free_node(Symlist **symlist, Symlist *node)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
18 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
19 UNLINK_ITEM(*symlist, node, next, prev);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
20 free(node);
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
21 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
22
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
23
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
24 bool symlist_insert(Symlist **symlist, void *symbol)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
25 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
26 Symlist *node;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
27
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
28 if(symbol==NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
29 return FALSE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
30
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
31 node=ALLOC(Symlist);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
32
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
33 if(node==NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
34 return FALSE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
35
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
36 node->symbol=symbol;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
37
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
38 LINK_ITEM_FIRST(*symlist, node, next, prev);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
39
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
40 return TRUE;
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
41 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
42
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
43
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
44 void symlist_remove(Symlist **symlist, void *symbol)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
45 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
46 Symlist *node=*symlist;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
47
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
48 while(node!=NULL){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
49 if(node->symbol==symbol){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
50 free_node(symlist, node);
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
51 return;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
52 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
53 node=node->next;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
54 }
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
55 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
56
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
57
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
58 void symlist_clear(Symlist **symlist)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
59 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
60 while(*symlist!=NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
61 free_node(symlist, *symlist);
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
62 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
63
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
64
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
65 /* Warning: not thread-safe */
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
66
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
67
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
68 static Symlist *iter_next=NULL;
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
69
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
70
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
71 void *symlist_init_iter(Symlist *symlist)
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
72 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
73 if(symlist==NULL){
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
74 iter_next=NULL;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
75 return NULL;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
76 }
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
77
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
78 iter_next=symlist->next;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
79 return symlist->symbol;
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
80 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
81
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
82
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
83 void *symlist_iter()
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
84 {
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
85 Symlist *ret;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
86
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
87 if(iter_next==NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
88 return NULL;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
89
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
90 ret=iter_next;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
91 iter_next=iter_next->next;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
92
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
93 return ret->symbol;
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
94 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
95

mercurial