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

Linux Cross Reference
Tina4/src/sys/lists/ddstr.c

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

  1 /**@(#)List handling (doubly directed).
  2  * @(#)List is {int type; List *next; List *last; void *to;}
  3  * @(#)They are always referenced by both start and end pointers neither of
  4  * @(#)which should be nil. The important points being (a) that start and
  5  * @(#)end are included in the list, and (b) that the list may be part of a
  6  * @(#)larger list.
  7  */
  8 
  9 #include <stdio.h>
 10 #include <tina/sys.h>
 11 
 12 void    rfree();
 13 
 14 #define LOOPOVER while (1)
 15 
 16 int     ddstr_count(List * start, List * end)
 17 {
 18     List *dptr;
 19     int     count;
 20 
 21     if (start == NULL || end == NULL)
 22         return (0);
 23 
 24     count = 1;
 25     for (dptr = start; dptr != end; dptr = dptr->next)
 26         ++count;
 27     return (count);
 28 }
 29 
 30 void    ddstr_free(List * start, List * end, void (*freefunc) ( /* ??? */ ))
 31 {
 32     List *dptr;
 33     void    dd_ref_free();
 34 
 35     if (start == NULL || end == NULL)
 36         return;
 37 
 38     dptr = start;
 39 
 40     LOOPOVER
 41     {
 42         dd_ref_free(dptr, freefunc);
 43         if (dptr == end)
 44             break;
 45         dptr = dptr->next;
 46     }
 47 }
 48 
 49 void    ddstr_rm_links(List * start, List * end)
 50 {
 51     List *dptr;
 52     List *next;
 53     List *dd_link_rm_el();
 54 
 55     if (start == NULL || end == NULL)
 56         return;
 57 
 58     dptr = start;
 59 
 60     LOOPOVER
 61     {
 62         next = dd_link_rm_el(dptr);
 63         if (dptr == end)
 64             break;
 65         dptr = next;
 66     }
 67 }
 68 
 69 void    ddstr_rm(List * start, List * end, void (*freefunc) ( /* ??? */ ))
 70 {
 71     List *dptr;
 72     List *next;
 73     List *dd_link_rm();
 74 
 75     if (start == NULL || end == NULL)
 76         return;
 77 
 78     dptr = start;
 79     LOOPOVER
 80     {
 81         next = dd_link_rm(dptr, freefunc);
 82         if (dptr == end)
 83             break;
 84         dptr = next;
 85     }
 86 }
 87 
 88 List *ddstr_link_get_by_ref(List * start, List * end, void *ptr)
 89 {
 90     List *dptr;
 91 
 92     if (start == NULL || end == NULL)
 93         return (NULL);
 94 
 95     dptr = start;
 96     LOOPOVER
 97     {
 98         if (dptr->to == ptr)
 99             return (dptr);
100         if (dptr == end)
101             break;
102         dptr = dptr->next;
103     }
104     return (NULL);
105 }
106 
107 void    ddstr_reverse(List ** startp, List ** endp)
108 {
109     List *dptr;
110     List *start;
111     List *end;
112     List *dd_link_addtostart();
113 
114     if (*startp == NULL || *endp == NULL)
115         return;
116 
117     end = dptr = *startp;
118     start = NULL;
119 
120     LOOPOVER
121     {
122         List *next = dptr->next;
123 
124         start = dd_link_addtostart(start, dptr);
125         if (dptr == *endp)
126             break;
127         dptr = next;
128     }
129     *startp = start;
130     *endp = end;
131 }
132 
133 void    ddstr_copy(List ** startp, List ** endp, void *(*copyfunc) ( /* ??? */ ), void *data)
134 {
135     List *dptr;
136     List *start = NULL;
137     List *end = NULL;
138     List *dd_link_copy();
139     List *dd_link_addtoend();
140 
141     if (*startp == NULL || *endp == NULL)
142         return;
143 
144 
145     dptr = *startp;
146     LOOPOVER
147     {
148         end = dd_link_addtoend(end, dd_link_copy(dptr, copyfunc, data));
149         if (start == NULL)
150             start = end;
151         if (dptr == *endp)
152             break;
153         dptr = dptr->next;
154     }
155     *startp = start;
156     *endp = end;
157 }
158 
159 void    ddstr_set_type(List * start, List * end, int type, int n)
160 {
161     List *dptr;
162     int     i;
163 
164     if (start == NULL || end == NULL)
165         return;
166 
167     for (i = 0, dptr = start; dptr != end; dptr = dptr->next, ++i)
168         if (i % n == 0)
169             dptr->type = type;
170     end->type = type;
171 }
172 
173 List *ddstr_nth_point(List * start, List * end, int n)
174 {
175     List *dptr;
176     int     i;
177 
178     if (start == NULL || end == NULL)
179         return (NULL);
180 
181     for (i = 0, dptr = start;; dptr = dptr->next, ++i)
182     {
183         if (i == n)
184             return (dptr);
185         if (dptr == end)
186             break;
187     }
188     return (NULL);
189 }
190 
191 List *ddstr_mid_point(List * start, List * end)
192 {
193     int     n;
194 
195     if (start == NULL || end == NULL)
196         return (NULL);
197 
198     n = ddstr_count(start, end) / 2;
199     return (ddstr_nth_point(start, end, n));
200 }
201 
202 void    ddstr_apply_func(List * start, List * end, void (*func) ( /* ??? */ ), void *data)
203 {
204     List *dptr;
205 
206     if (start == NULL || end == NULL)
207         return;
208 
209     dptr = start;
210 
211     LOOPOVER
212     {
213         func(dptr->to, dptr->type, data);
214         if (dptr == end)
215             break;
216         dptr = dptr->next;
217     }
218 }
219 
220 List *ddstr_get_min(List * start, List * end, Bool(*func) ( /* ??? */ ), void *data)
221 {
222     List *dptr;
223     List *min_ptr = NULL;
224     double  d, min_d = 0.0;
225 
226     if (start == NULL || end == NULL)
227         return (NULL);
228 
229     dptr = start;
230 
231     LOOPOVER
232     {
233         if (func(dptr->to, dptr->type, data, &d) == true &&
234             (min_ptr == NULL || d < min_d))
235         {
236             min_ptr = dptr;
237             min_d = d;
238         }
239         if (dptr == end)
240             break;
241         dptr = dptr->next;
242     }
243     return (min_ptr);
244 }
245 

~ [ 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.