1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* sm_list.c |
6 |
|
* Routines for handling linked generic linked lists, stack, and |
17 |
|
extern int Malloc_cnt; |
18 |
|
#endif |
19 |
|
LIST |
20 |
+ |
/* NOTE: Memory is not initialized */ |
21 |
|
*new_list() |
22 |
|
{ |
23 |
|
LIST *l; |
24 |
|
|
27 |
– |
|
28 |
– |
|
25 |
|
/* check free list for available edges */ |
26 |
|
if( free_lists ) |
27 |
|
{ |
34 |
|
if( !(l = (LIST *)malloc(sizeof(LIST)))) |
35 |
|
error(SYSTEM,"new_list():Unable to allocate memory"); |
36 |
|
} |
41 |
– |
/* clear the memory */ |
42 |
– |
bzero(l, sizeof(LIST)); |
43 |
– |
|
37 |
|
return(l); |
38 |
|
} |
39 |
|
|
45 |
|
{ |
46 |
|
LIST * l; |
47 |
|
|
55 |
– |
if(!a) |
56 |
– |
return(b); |
57 |
– |
|
48 |
|
if(!b) |
49 |
|
return(a); |
50 |
|
|
57 |
|
return(b); |
58 |
|
} |
59 |
|
|
60 |
+ |
/* attaches list a at the end of list b */ |
61 |
+ |
LIST |
62 |
+ |
*add_data(l,d,end) |
63 |
+ |
LIST *l; |
64 |
+ |
int d; |
65 |
+ |
LIST **end; |
66 |
+ |
|
67 |
+ |
{ |
68 |
+ |
LIST *list,*lptr; |
69 |
+ |
|
70 |
+ |
list = new_list(); |
71 |
+ |
SET_LIST_DATA(list,d); |
72 |
+ |
SET_LIST_NEXT(list,NULL); |
73 |
+ |
if(!l) |
74 |
+ |
{ |
75 |
+ |
if(end) |
76 |
+ |
*end = list; |
77 |
+ |
return(list); |
78 |
+ |
} |
79 |
+ |
if(end) |
80 |
+ |
lptr = *end; |
81 |
+ |
else |
82 |
+ |
{ |
83 |
+ |
lptr = l; |
84 |
+ |
while(LIST_NEXT(lptr)) |
85 |
+ |
lptr = LIST_NEXT(lptr); |
86 |
+ |
} |
87 |
+ |
LIST_NEXT(lptr) = list; |
88 |
+ |
if(end) |
89 |
+ |
*end = list; |
90 |
+ |
|
91 |
+ |
return(l); |
92 |
+ |
} |
93 |
+ |
|
94 |
|
/* Adds data to the end of a circular list. If set, "end" |
95 |
|
* is a pointer to the last element in the list |
96 |
|
*/ |
119 |
|
return(l); |
120 |
|
} |
121 |
|
|
98 |
– |
/* Pushes data element d at the top of the list- returns pointer |
99 |
– |
to new top of list |
100 |
– |
*/ |
101 |
– |
LIST |
102 |
– |
*push_data(l,d) |
103 |
– |
LIST *l; |
104 |
– |
int d; |
105 |
– |
{ |
106 |
– |
LIST * list; |
107 |
– |
|
108 |
– |
list = new_list(); |
109 |
– |
SET_LIST_DATA(list,d); |
110 |
– |
SET_LIST_NEXT(list,l); |
111 |
– |
return(list); |
112 |
– |
} |
122 |
|
|
123 |
+ |
|
124 |
|
/* frees the list */ |
125 |
|
LIST |
126 |
|
*free_list(l) |
128 |
|
{ |
129 |
|
if(!l) |
130 |
|
return(NULL); |
131 |
+ |
|
132 |
|
free_lists = append_list(free_lists,l); |
133 |
|
|
134 |
|
return(NULL); |
135 |
|
} |
136 |
|
|
137 |
+ |
/* Pushes data element d at the top of the list- returns pointer |
138 |
+ |
to new top of list |
139 |
+ |
*/ |
140 |
+ |
LIST |
141 |
+ |
*push_data(l,d) |
142 |
+ |
LIST *l; |
143 |
+ |
int d; |
144 |
+ |
{ |
145 |
+ |
LIST *list; |
146 |
+ |
|
147 |
+ |
list = new_list(); |
148 |
+ |
SET_LIST_DATA(list,d); |
149 |
+ |
SET_LIST_NEXT(list,l); |
150 |
+ |
return(list); |
151 |
+ |
} |
152 |
|
/* Returns data element d at the top of the list- returns pointer |
153 |
|
to new top of list |
154 |
|
*/ |
157 |
|
LIST **l; |
158 |
|
{ |
159 |
|
LIST *p; |
160 |
< |
void *d; |
160 |
> |
int d; |
161 |
|
|
162 |
|
if(!l) |
163 |
|
return(NULL); |
205 |
|
} |
206 |
|
return(FALSE); |
207 |
|
} |
208 |
+ |
|
209 |
+ |
|
210 |
+ |
|
211 |
+ |
|
212 |
|
|
213 |
|
|
214 |
|
|