1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /********************************************************************20**
21 Name: common functions - linked list management
25 Desc: common functions for linked lists
29 *********************************************************************21*/
31 /* header include files (.h) */
33 #include "envopt.h" /* environment options */
34 #include "envdep.h" /* environment dependent */
35 #include "envind.h" /* environment independent */
37 #include "gen.h" /* general layer */
38 #include "ssi.h" /* system services */
40 /* header/extern include files (.x) */
42 #include "gen.x" /* general layer */
43 #include "ssi.x" /* system services */
44 #include "cm_llist.x" /* common functions */
47 /* Linked List functions */
54 * Desc: initializes a linked list control pointer.
65 CmLListCp *lCp /* list control point */
69 lCp->first = (CmLList *)NULLP;
70 lCp->last = (CmLList *)NULLP;
71 lCp->crnt = (CmLList *)NULLP;
75 } /* end of cmLListInit */
79 /*insert before head*/
82 * Fun: cmLListAdd2Head
84 * Desc: adds node to linked list before head.
95 CmLListCp *lCp, /* list control point */
96 CmLList *node /* node to be added */
101 if (lCp == (CmLListCp *)NULLP)
107 node->next = lCp->first;
109 lCp->first = lCp->crnt = node;
117 node->next->prev = node;
119 } /* end of cmLListAdd2Head */
124 * Fun: cmLListAdd2Tail
126 * Desc: adds node to linked list after last.
137 CmLListCp *lCp, /* list control point */
138 CmLList *node /* node to be added */
143 if (lCp == (CmLListCp *)NULLP)
149 node->prev = lCp->last;
151 lCp->last = lCp->crnt = node;
159 node->prev->next = node;
161 } /* end of cmLListAdd2Tail */
166 * Fun: cmLListInsCrnt
168 * Desc: adds node to linked list before crnt.
179 CmLListCp *lCp, /* list control point */
180 CmLList *node /* node to be added */
193 lCp->crnt = lCp->first = lCp->last = node;
198 node->next = lCp->crnt;
199 node->prev = lCp->crnt->prev;
201 node->prev->next = node;
202 node->next->prev = node;
204 if (lCp->first == lCp->crnt)
209 } /* end of cmLListInsCrnt */
211 /* cm_llist_c_001.main_7 - Add function */
214 * Fun: cmLListInsAfterCrnt
216 * Desc: adds node to linked list after crnt.
225 Void cmLListInsAfterCrnt
227 CmLListCp *lCp, /* list control point */
228 CmLList *node /* node to be added */
241 lCp->crnt = lCp->first = lCp->last = node;
245 node->prev = lCp->crnt;
246 node->next = lCp->crnt->next;
248 node->next->prev = node;
249 node->prev->next = node;
251 if (lCp->last == lCp->crnt)
256 } /* end of cmLListInsAfterCrnt */
264 * Desc: remove node pointed to by nodePtr from list and return node.
265 * nodePtr could be anywhere in the list.
266 * - resets crnt to NULLP.
275 CmLList *cmLListDelFrm
277 CmLListCp *lCp, /* list control pointer */
278 CmLList *node /* node to be removed */
283 /* cm_llist_c_001.main_8 : added null check for node */
284 if (lCp == (CmLListCp *)NULLP || lCp->count == 0 || !node)
292 lCp->first = lCp->crnt = lCp->last = (CmLList *)NULLP;
298 lCp->crnt = (CmLList *)NULLP;
299 if (lCp->first == node)
302 node->next->prev = (CmLList *)NULLP;
303 lCp->first = node->next;
304 node->next = node->prev = (CmLList *)NULLP;
308 if (lCp->last == node)
311 node->prev->next = (CmLList *)NULLP;
312 lCp->last = node->prev;
313 node->next = node->prev = (CmLList *)NULLP;
317 node->prev->next = node->next;
318 node->next->prev = node->prev;
319 node->next = node->prev = (CmLList *)NULLP;
321 } /* end of cmLListDelFrm */
326 * Fun: cmLListCatLList
328 * Desc: adds a linked list to the end of the first list. list2 is
329 * added at the end of list1
340 CmLListCp *list1, /*-- list control point --*/
341 CmLListCp *list2 /*-- node to be added --*/
345 /*-- if the second list is empty nothing to do --*/
346 if(list2->count == 0)
351 /*-- if the first list is empty make first the same as second*/
352 if(list1->count == 0)
354 list1->first = list2->first;
355 list1->last = list2->last;
356 list1->count = list2->count;
357 list1->crnt = list1->first;
361 list2->first->prev = list1->last;
362 list1->last->next = list2->first;
363 /* Set the last to the end of the 2nd list */
364 list1->last = list2->last;
365 list1->count += list2->count;
371 } /*-- end of cmLListCatLList --*/
373 /**********************************************************************
375 **********************************************************************/