FreeCalypso > hg > fc-tourmaline
comparison src/g23m-aci/aci/aci_lst.c @ 1:fa8dc04885d8
src/g23m-*: import from Magnetite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 16 Oct 2020 06:25:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:4e78acac3d88 | 1:fa8dc04885d8 |
---|---|
1 /* | |
2 +----------------------------------------------------------------------------- | |
3 | Project : GSM-PS (6147) | |
4 | Modul : aci_lst | |
5 +----------------------------------------------------------------------------- | |
6 | Copyright 2002 Texas Instruments Berlin, AG | |
7 | All rights reserved. | |
8 | | |
9 | This file is confidential and a trade secret of Texas | |
10 | Instruments Berlin, AG | |
11 | The receipt of or possession of this file does not convey | |
12 | any rights to reproduce or disclose its contents or to | |
13 | manufacture, use, or sell anything it may describe, in | |
14 | whole, or in part, without the specific written consent of | |
15 | Texas Instruments Berlin, AG. | |
16 +----------------------------------------------------------------------------- | |
17 | Purpose : Process lists in ACI | |
18 +----------------------------------------------------------------------------- | |
19 */ | |
20 | |
21 #ifndef ACI_LST_C | |
22 #define ACI_LST_C | |
23 #endif | |
24 | |
25 #include "aci_all.h" | |
26 | |
27 /*==== INCLUDES ===================================================*/ | |
28 | |
29 #include "aci_lst.h" | |
30 #include "aci_mem.h" | |
31 | |
32 /*==== CONSTANTS ==================================================*/ | |
33 | |
34 /*==== EXPORT =====================================================*/ | |
35 | |
36 /*==== VARIABLES ==================================================*/ | |
37 | |
38 /*==== FUNCTIONS ==================================================*/ | |
39 | |
40 /*==== TYPES ======================================================*/ | |
41 | |
42 | |
43 /* | |
44 +--------------------------------------------------------------------+ | |
45 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST | | |
46 | STATE : code ROUTINE : new_list | | |
47 +--------------------------------------------------------------------+ | |
48 | |
49 PURPOSE : create a new list. | |
50 */ | |
51 | |
52 GLOBAL T_ACI_LIST *new_list (void) | |
53 { | |
54 T_ACI_LIST *new_elem = NULL; | |
55 | |
56 ACI_MALLOC(new_elem, sizeof(T_ACI_LIST)); | |
57 new_elem->msg = NULL; | |
58 new_elem->next = NULL; | |
59 | |
60 return (new_elem); | |
61 } | |
62 | |
63 GLOBAL USHORT get_list_count (T_ACI_LIST *list) | |
64 { | |
65 T_ACI_LIST *curr; | |
66 USHORT count = 0; | |
67 | |
68 curr = list; | |
69 while (curr NEQ NULL) | |
70 { | |
71 if (curr->msg NEQ NULL) | |
72 count++; | |
73 | |
74 curr = curr->next; | |
75 } | |
76 | |
77 return (count); | |
78 } | |
79 | |
80 /* | |
81 +--------------------------------------------------------------------+ | |
82 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST | | |
83 | STATE : code ROUTINE : insert_list | | |
84 +--------------------------------------------------------------------+ | |
85 | |
86 PURPOSE : insert a new element in an existing list. | |
87 - list: pointer to the list where the element is to be added | |
88 - buffer: pointer to the buffer containing the datas that are to | |
89 be written in the new element. | |
90 - buffer_len: length of the datas to be stored. | |
91 | |
92 */ | |
93 | |
94 GLOBAL BOOL insert_list (T_ACI_LIST *list, void *buffer) | |
95 { | |
96 T_ACI_LIST *current; | |
97 T_ACI_LIST *new_elem; | |
98 | |
99 if (list EQ NULL) | |
100 return (FALSE); | |
101 | |
102 if (list->msg EQ NULL) | |
103 { | |
104 list->msg = buffer; | |
105 return (TRUE); | |
106 } | |
107 | |
108 ACI_MALLOC(new_elem, sizeof(T_ACI_LIST)); | |
109 | |
110 new_elem->msg = buffer; | |
111 new_elem->next = NULL; | |
112 | |
113 current = list; | |
114 while (current->next NEQ NULL) | |
115 { | |
116 current = (T_ACI_LIST *)current->next; | |
117 } | |
118 current->next = new_elem; | |
119 | |
120 return TRUE; | |
121 } | |
122 | |
123 /* | |
124 +--------------------------------------------------------------------+ | |
125 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST | | |
126 | STATE : code ROUTINE : find_element | | |
127 +--------------------------------------------------------------------+ | |
128 | |
129 PURPOSE : find an element in a list: | |
130 - search_list: list to be scanned. | |
131 - criterium: search criterium. (source Id for instance) | |
132 - test_criterium: function(criterium, element) that returns TRUE if | |
133 the criterium is found in the element. | |
134 | |
135 */ | |
136 | |
137 GLOBAL void *find_element (T_ACI_LIST *search_list, | |
138 UBYTE criterium, | |
139 T_LIST_FIND_FCT test_criterium) | |
140 { | |
141 T_ACI_LIST *current; | |
142 | |
143 if ((search_list EQ NULL) OR (search_list->msg EQ NULL)) | |
144 return NULL; | |
145 | |
146 current = search_list; | |
147 | |
148 do | |
149 { | |
150 if (current->msg NEQ NULL) | |
151 { | |
152 if (test_criterium(criterium, current->msg)) | |
153 return (current->msg); | |
154 else | |
155 current = current->next; | |
156 } | |
157 } | |
158 while( current NEQ NULL ); | |
159 | |
160 return NULL; | |
161 } | |
162 | |
163 /* | |
164 +--------------------------------------------------------------------+ | |
165 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST | | |
166 | STATE : code ROUTINE : psi_find_element | | |
167 +--------------------------------------------------------------------+ | |
168 | |
169 PURPOSE : find an element in a list: | |
170 - search_list: list to be scanned. | |
171 - criterium: search criterium. (source Id for instance) | |
172 - test_criterium: function(criterium, element) that returns TRUE if | |
173 the criterium is found in the element. | |
174 | |
175 */ | |
176 #ifdef FF_PSI | |
177 GLOBAL void *psi_find_element (T_ACI_LIST *search_list, | |
178 U32 criterium, | |
179 T_LIST_FIND_FCT_PSI test_criterium) | |
180 { | |
181 T_ACI_LIST *current; | |
182 | |
183 if ((search_list EQ NULL) OR (search_list->msg EQ NULL)) | |
184 return NULL; | |
185 | |
186 current = search_list; | |
187 | |
188 do | |
189 { | |
190 if (current->msg NEQ NULL) | |
191 { | |
192 if (test_criterium(criterium, current->msg)) | |
193 return (current->msg); | |
194 else | |
195 current = current->next; | |
196 } | |
197 } | |
198 while( current NEQ NULL ); | |
199 | |
200 return NULL; | |
201 } | |
202 #endif /*FF_PSI*/ | |
203 | |
204 /* | |
205 +--------------------------------------------------------------------+ | |
206 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST | | |
207 | STATE : code ROUTINE : find_next_element | | |
208 +--------------------------------------------------------------------+ | |
209 | |
210 PURPOSE : find the next element in a list: | |
211 - search_list: list to be scanned. | |
212 - previous element | |
213 - criterium: search criterium. (source Id for instance) | |
214 - test_criterium: function(criterium, element) that returns TRUE if | |
215 the criterium is found in the element. | |
216 | |
217 */ | |
218 GLOBAL void *find_next_element (T_ACI_LIST *search_list, | |
219 void *prev_elem, | |
220 UBYTE criterium, | |
221 T_LIST_FIND_FCT test_criterium) | |
222 { | |
223 T_ACI_LIST *current; | |
224 | |
225 if ((search_list EQ NULL) OR (search_list->msg EQ NULL)) | |
226 return NULL; | |
227 | |
228 current = search_list; | |
229 | |
230 if (prev_elem NEQ NULL) | |
231 { | |
232 while (current NEQ NULL) | |
233 { | |
234 if (current->msg EQ prev_elem) | |
235 break; | |
236 | |
237 current = current->next; | |
238 } | |
239 if ((current EQ NULL) OR (current->next EQ NULL)) | |
240 return (NULL); | |
241 | |
242 current = current->next; | |
243 } | |
244 | |
245 do | |
246 { | |
247 if( test_criterium(criterium, current->msg) ) | |
248 return (current->msg); | |
249 else | |
250 current = current->next; | |
251 } | |
252 while( current NEQ NULL ); | |
253 | |
254 return NULL; | |
255 } | |
256 | |
257 | |
258 /* | |
259 +--------------------------------------------------------------------+ | |
260 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST | | |
261 | STATE : code ROUTINE : find_next_element | | |
262 +--------------------------------------------------------------------+ | |
263 | |
264 PURPOSE : find the next element in a list: | |
265 - search_list: list to be scanned. | |
266 - previous element | |
267 - criterium: search criterium. (source Id for instance) | |
268 - test_criterium: function(criterium, element) that returns TRUE if | |
269 the criterium is found in the element. | |
270 | |
271 */ | |
272 #ifdef FF_PSI | |
273 GLOBAL void *psi_find_next_element (T_ACI_LIST *search_list, | |
274 void *prev_elem, | |
275 U32 criterium, | |
276 T_LIST_FIND_FCT_PSI test_criterium) | |
277 { | |
278 T_ACI_LIST *current; | |
279 | |
280 if ((search_list EQ NULL) OR (search_list->msg EQ NULL)) | |
281 return NULL; | |
282 | |
283 current = search_list; | |
284 | |
285 if (prev_elem NEQ NULL) | |
286 { | |
287 while (current NEQ NULL) | |
288 { | |
289 if (current->msg EQ prev_elem) | |
290 break; | |
291 | |
292 current = current->next; | |
293 } | |
294 if ((current EQ NULL) OR (current->next EQ NULL)) | |
295 return (NULL); | |
296 | |
297 current = current->next; | |
298 } | |
299 | |
300 do | |
301 { | |
302 if( test_criterium(criterium, current->msg) ) | |
303 return (current->msg); | |
304 else | |
305 current = current->next; | |
306 } | |
307 while( current NEQ NULL ); | |
308 | |
309 return NULL; | |
310 } | |
311 #endif /*FF_PSI*/ | |
312 | |
313 /* | |
314 +--------------------------------------------------------------------+ | |
315 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST | | |
316 | STATE : code ROUTINE : remove_element | | |
317 +--------------------------------------------------------------------+ | |
318 | |
319 PURPOSE : remove a element from the list. | |
320 | |
321 */ | |
322 GLOBAL void *remove_element (T_ACI_LIST *search_list, | |
323 UBYTE criterium, | |
324 T_LIST_FIND_FCT test_criterium) | |
325 { | |
326 T_ACI_LIST *previous = NULL, | |
327 *current = search_list, | |
328 *next = NULL; | |
329 void *msg = NULL; | |
330 | |
331 current = search_list; | |
332 while (current NEQ NULL) | |
333 { | |
334 if (test_criterium (criterium, current->msg)) | |
335 { | |
336 msg = current->msg; | |
337 break; | |
338 } | |
339 previous = current; | |
340 current = current->next; | |
341 } | |
342 | |
343 if (current EQ NULL) | |
344 return (NULL); | |
345 | |
346 if (msg EQ NULL) | |
347 return (NULL); | |
348 | |
349 /* the first element is to delete */ | |
350 if (previous EQ NULL) | |
351 { | |
352 /* the header contains the element */ | |
353 if (current->next EQ NULL) | |
354 { | |
355 /* one element in list */ | |
356 current->msg = NULL; | |
357 } | |
358 else | |
359 { | |
360 /* actually deletes the second element and redirects the pointers */ | |
361 next = current->next; | |
362 current->msg = next->msg; | |
363 current->next = next->next; | |
364 | |
365 ACI_MFREE (next); } | |
366 } | |
367 else | |
368 { | |
369 previous->next = current->next; | |
370 | |
371 ACI_MFREE (current); | |
372 } | |
373 | |
374 return (msg); | |
375 } | |
376 | |
377 #ifdef FF_PSI | |
378 GLOBAL void *psi_remove_element (T_ACI_LIST *search_list, | |
379 U32 criterium, | |
380 T_LIST_FIND_FCT_PSI test_criterium) | |
381 { | |
382 T_ACI_LIST *previous = NULL, | |
383 *current = search_list, | |
384 *next = NULL; | |
385 void *msg = NULL; | |
386 | |
387 current = search_list; | |
388 while (current NEQ NULL) | |
389 { | |
390 if (test_criterium (criterium, current->msg)) | |
391 { | |
392 msg = current->msg; | |
393 break; | |
394 } | |
395 previous = current; | |
396 current = current->next; | |
397 } | |
398 | |
399 if (current EQ NULL) | |
400 return (NULL); | |
401 | |
402 if (msg EQ NULL) | |
403 return (NULL); | |
404 | |
405 /* the first element is to delete */ | |
406 if (previous EQ NULL) | |
407 { | |
408 /* the header contains the element */ | |
409 if (current->next EQ NULL) | |
410 { | |
411 /* one element in list */ | |
412 current->msg = NULL; | |
413 } | |
414 else | |
415 { | |
416 /* actually deletes the second element and redirects the pointers */ | |
417 next = current->next; | |
418 current->msg = next->msg; | |
419 current->next = next->next; | |
420 | |
421 ACI_MFREE (next); } | |
422 } | |
423 else | |
424 { | |
425 previous->next = current->next; | |
426 | |
427 ACI_MFREE (current); | |
428 } | |
429 | |
430 return (msg); | |
431 } | |
432 | |
433 #endif /*FF_PSI*/ | |
434 | |
435 | |
436 /* | |
437 +--------------------------------------------------------------------+ | |
438 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST | | |
439 | STATE : code ROUTINE : remove_first_element | | |
440 +--------------------------------------------------------------------+ | |
441 | |
442 PURPOSE : get and remove the first element from the list | |
443 | |
444 */ | |
445 GLOBAL void *remove_first_element (T_ACI_LIST *search_list) | |
446 { | |
447 T_ACI_LIST *next = NULL; | |
448 void *msg = NULL; | |
449 | |
450 if ((search_list EQ NULL) OR (search_list->msg EQ NULL)) | |
451 return (NULL); | |
452 | |
453 msg = search_list->msg; | |
454 search_list->msg = NULL; | |
455 | |
456 if (search_list->next EQ NULL) | |
457 return (msg); | |
458 | |
459 next = search_list->next; | |
460 search_list->next = next->next; | |
461 search_list->msg = next->msg; | |
462 | |
463 ACI_MFREE (next); | |
464 | |
465 return (msg); | |
466 } | |
467 | |
468 /* | |
469 +--------------------------------------------------------------------+ | |
470 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST | | |
471 | STATE : code ROUTINE : get_first_element | | |
472 +--------------------------------------------------------------------+ | |
473 | |
474 PURPOSE : get the next element from the list | |
475 - search_list: list to be scanned. | |
476 - previous element | |
477 */ | |
478 | |
479 GLOBAL void *get_next_element (T_ACI_LIST *search_list, | |
480 void *prev_elem) | |
481 { | |
482 T_ACI_LIST *current; | |
483 | |
484 if ((search_list EQ NULL) OR (search_list->msg EQ NULL)) | |
485 return NULL; | |
486 | |
487 if (prev_elem EQ NULL) | |
488 { | |
489 /* return first element */ | |
490 return (search_list->msg); | |
491 } | |
492 | |
493 current = search_list; | |
494 | |
495 /* search the previous element */ | |
496 while (current NEQ NULL) | |
497 { | |
498 if (current->msg EQ prev_elem) | |
499 { | |
500 break; | |
501 } | |
502 current = current->next; | |
503 } | |
504 | |
505 /* last entry found or previous entry not found */ | |
506 if ((current EQ NULL) OR (current->next EQ NULL)) | |
507 { | |
508 return (NULL); | |
509 } | |
510 | |
511 return (current->next->msg); | |
512 } | |
513 | |
514 /* | |
515 +---------------------------------------------------------------------+ | |
516 | PROJECT : GSM-F&D (8411) MODULE : ACI_LST | | |
517 | STATE : code ROUTINE : insert_shift_list | | |
518 +---------------------------------------------------------------------+ | |
519 | |
520 PURPOSE : | |
521 */ | |
522 GLOBAL BOOL insert_shift_list (T_ACI_LIST *list, void *buffer) | |
523 { | |
524 T_ACI_LIST *current; | |
525 T_ACI_LIST *new_elem; | |
526 void *old_buf; | |
527 | |
528 if (list EQ NULL) | |
529 return (FALSE); | |
530 | |
531 if (list->msg EQ NULL) | |
532 { | |
533 list->msg = buffer; | |
534 return (TRUE); | |
535 } | |
536 else if (list->next EQ NULL) | |
537 return (FALSE); | |
538 | |
539 current = list; | |
540 | |
541 old_buf = list->msg; | |
542 list->msg = list->next->msg; | |
543 | |
544 new_elem = list->next; | |
545 list->next = list->next->next; | |
546 | |
547 | |
548 new_elem->msg = buffer; | |
549 new_elem->next = NULL; | |
550 | |
551 while (current->next NEQ NULL) | |
552 { | |
553 current = (T_ACI_LIST *)current->next; | |
554 } | |
555 current->next = new_elem; | |
556 | |
557 ACI_MFREE (old_buf); | |
558 | |
559 return TRUE; | |
560 } | |
561 /**********************************************************************/ |