~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-libs/tina/sys/sysLst_list.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-libs/tina/sys/sysLst_list.c,v $
 37  * Date    :  $Date: 2007/02/15 01:52:29 $
 38  * Version :  $Revision: 1.5 $
 39  * CVS Id  :  $Id: sysLst_list.c,v 1.5 2007/02/15 01:52:29 paul Exp $
 40  */
 41 /**
 42  *  @file List handling. (singly directed)
 43  *  @ brief single directed list structures have now been replaced with double
 44  *  directed lists everywhere in Tina, in order to increase code re-use. 
 45  *  The functions in this file will disappear in a future release, the wrapped
 46  *  function should be used instead.
 47  *  
 48  *********
 49 */
 50 
 51 #include "sysLst_list.h"
 52 
 53 #if HAVE_CONFIG_H
 54   #include <config.h>
 55 #endif
 56 
 57 #include <stdio.h>
 58 
 59 #if HAVE_STDARG_H
 60 #  include <stdarg.h>
 61 #  define VA_START(a, f)                va_start(a, f)
 62 #else
 63 #  if HAVE_VARARGS_H
 64 #    include <varargs.h>
 65 #    define VA_START(a, f)  va_start(a)
 66 #  endif
 67 #endif /* HAVE_STDARG_H */
 68 #ifndef VA_START
 69   error no variadic api available
 70 #endif
 71 
 72 #include <tina/sys/sys_GenDef.h>
 73 #include <tina/sys/sys_LstDef.h>
 74 #include <tina/sys/sys_MemDef.h>
 75 #include <tina/sys/sysLst_dd.h>
 76 
 77 
 78 /* Allocate space for a single list element and set reference to ptr */
 79 List *link_alloc(void *ptr, int type)
 80 {
 81         return (dd_link_alloc(ptr, type));
 82 }
 83 
 84 /* Set list element reference to ptr */
 85 void ref_set(List * el, void *ptr, int type)
 86 {
 87         dd_ref_set(el, ptr, type);
 88 }
 89 
 90 /* Make a list of n elements */
 91 List *list_make(int n, int type)
 92 {
 93         return(dd_list_make(n, type));
 94 }
 95 
 96 /* Get last element of list */
 97 List *list_get_end(List * list)
 98 {
 99         return (dd_get_end(list));
100 }
101 
102 /* Append list l2 to l1 */
103 List *list_append(List * l1, List * l2)
104 {
105         return (dd_append(l1, l2));
106 }
107 
108 /* Add new element to front of list. Return new front of list */
109 List *link_addtostart(List * list, List * el)
110 {
111         return(dd_link_addtostart(list, el));
112 }
113 
114 List *ref_addtostart(List * list, void *ptr, int type)
115 {
116         return (dd_ref_addtostart(list, ptr, type));
117 }
118 
119 List *list_addtostart(List * list, List * el)
120 /* add new element to front of list */
121 /* return new front of list */
122 /* - same as link_addtostart */
123 {
124         return (dd_link_addtostart(list, el));
125 }
126 
127 List *link_addtoend(List * end, List * el)      /* add link to back of
128                                                                                                                                                                                  * * list */
129 /* return new back of list */
130 {
131         return (dd_link_addtoend(end, el));
132 }
133 
134 List *ref_addtoend(List * end, void *ptr, int type)
135 {
136         return (dd_ref_addtoend(end, ptr, type));
137 }
138 
139 List *list_addtoend(List * list, List * el)     /* add new element to
140                                                                                                                                                                                  * * back of list */
141 /* return new front of list */
142 /* only if list is NULL will front change */
143 {
144         return (dd_list_addtoend(list, el));
145 }
146 
147 void link_addafter(List * at, List * el)        /* add new element to
148                                                                                                                                                                          * * list after at */
149 {
150         dd_link_addafter(at, el);
151 }
152 
153 void link_rm_next_el(List * at) /* rm next element from list */
154 {
155         dd_link_rm_next_el(at);
156 }
157 
158 /* rm element from list, return next element in list, the list will now
159  * be broken */
160 List *link_rm_el(List * at)
161 {
162         return (dd_link_rm_el(at));
163 }
164 
165 /* Free the reference of this element */
166 void ref_free(List * at, void (*freefunc) ( /* ??? */ ))
167 {
168         dd_ref_free(at, freefunc);
169 }
170 
171 void link_rm_next(List * at, void (*freefunc) ( /* ??? */ ))
172 /* free and rm next
173    element of list */
174 {
175         dd_link_rm_next(at, freefunc);
176 }
177 
178 /* Free and rm this * element from list */
179 List *link_rm(List * at, void (*freefunc) ( /* ??? */ ))
180 /* return next element in list */
181 /* the list will now be broken */
182 {
183         return (dd_link_rm(at, freefunc));
184 }
185 
186 List *list_rm_el(List * list, List * el, void (*freefunc) ( /* ??? */ ))
187 /* rm this element from list */
188 /* return new list */
189 /* the list will not be broken */
190 {
191         return (dd_list_rm_el(list, el, freefunc));
192 }
193 
194 /* Rm element from list by reference. Return new list. The list will
195  * not be broken */
196 List *list_rm_ref(List * list, void *ptr, void (*freefunc) ( /* ??? */ ))
197 {
198         return (dd_list_rm_ref(list, ptr, freefunc));
199 }
200 
201 void list_rm_links(List * list) /* rm all elements of list */
202 {
203         dd_list_rm_links(list);
204 }
205 
206 List *list_rm_links_on_type(List * list, int type)
207 {
208         return (dd_list_rm_links_on_type(list, type));
209 }
210 
211 List *list_rm_links_on_func(List * list, Bool(*func) ( /* ??? */ ),
212                                                                                                                 void *data)
213 {
214         return (dd_list_rm_links_on_func(list, func, data));
215 }
216 
217 /* Free all references of list */
218 void list_free_refs(List * list, void (*freefunc) ( /* ??? */ ))
219 {
220         dd_list_free_refs(list, freefunc);
221 }
222 
223 /* Free and rm all elements of list */
224 void list_rm(List * list, void (*freefunc) ())
225 {
226         dd_list_rm(list, freefunc);
227 }
228 
229 void list_list_rm(List * list)
230 {
231         dd_list_rm(list, list_rm_links);
232 }
233 
234 List *link_copy(List * el, void *(*cpfunc) ( /* ??? */ ), void *data)
235 /* copy list element */
236 {
237         return (dd_link_copy(el, cpfunc, data));
238 }
239 
240 List *list_copy(List * list, void *(*cpfunc) ( /* ??? */ ), void *data) /* copy whole list */
241 {
242         return (dd_list_copy(list, cpfunc, data));
243 }
244 
245 List *list_reverse(List * list) /* reverse list */
246 {
247         return (dd_list_reverse(list));
248 }
249 
250 /* Copy list reversed */
251 List *list_reversecopy(List * list, void *(*cpfunc) ( /* ??? */ ),
252                                                                                          void *data)
253 {
254         return (dd_list_reversecopy(list, cpfunc, data));
255 }
256 
257 /* Apply function to list */
258 void list_apply_func(List * list, void (*func) ( /* ??? */ ), void *data)
259 {
260         dd_apply_func(list, func, data);
261 }
262 
263 /* Find min function value */
264 List *list_get_min(List * list, Bool(*func) ( /* ??? */ ), void *data)
265 {
266         return (dd_get_min(list, func, data));
267 }
268 
269 /* Get list element by reference */
270 List *link_get_by_ref(List * list, void *ptr)
271 {
272         return (dd_link_get_by_ref(list, ptr));
273 }
274 
275 /* Get first list element of type */
276 List *link_get_by_type(List * list, int type)
277 {
278         return (dd_link_get_by_type(list, type));
279 }
280 
281 List *list_add_sorted(List * list, List * el,
282                                                                                         double (*sortfunc) ( /* ??? */ ))
283 {
284         return (dd_list_add_sorted(list, el, sortfunc));
285 }
286 
287 
288 List 
289 #if HAVE_STDARG_H
290 *list_of(int type, ...)
291 #else
292 *list_of(type, va_alist)
293         int type;
294   va_dcl
295 #endif /* HAVE_STDARG_H */
296 {
297         va_list ap;
298         List *list = NULL;
299 
300         VA_START(ap, type);
301 
302         while (type)
303         {
304                 void *ptr = va_arg(ap, void *);
305 
306                 list = ref_addtostart(list, ptr, type);
307                 type = va_arg(ap, int);
308         }
309         va_end(ap);
310         return (list_reverse(list));
311 }
312 
313 
314 void *list_query(List * list, void *(*match_func) ( /* ??? */ ), void *key)
315 {
316         void *data;
317 
318         for (data = NULL;
319                          list && !(data = match_func(key, list->to)); list = list->next);
320 
321         return data;
322 }
323 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.