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.
64 PUBLIC Void cmLListInit
66 CmLListCp *lCp /* list control point */
69 PUBLIC Void cmLListInit(lCp)
70 CmLListCp *lCp; /* list control point */
75 lCp->first = (CmLList *)NULLP;
76 lCp->last = (CmLList *)NULLP;
77 lCp->crnt = (CmLList *)NULLP;
81 } /* end of cmLListInit */
85 /*insert before head*/
88 * Fun: cmLListAdd2Head
90 * Desc: adds node to linked list before head.
100 PUBLIC Void cmLListAdd2Head
102 CmLListCp *lCp, /* list control point */
103 CmLList *node /* node to be added */
106 PUBLIC Void cmLListAdd2Head(lCp, node)
107 CmLListCp *lCp; /* list control point */
108 CmLList *node; /* node to be added */
111 TRC3(cmLListAdd2Head);
114 if (lCp == (CmLListCp *)NULLP)
120 node->next = lCp->first;
122 lCp->first = lCp->crnt = node;
130 node->next->prev = node;
132 } /* end of cmLListAdd2Head */
137 * Fun: cmLListAdd2Tail
139 * Desc: adds node to linked list after last.
149 PUBLIC Void cmLListAdd2Tail
151 CmLListCp *lCp, /* list control point */
152 CmLList *node /* node to be added */
155 PUBLIC Void cmLListAdd2Tail(lCp, node)
156 CmLListCp *lCp; /* list control point */
157 CmLList *node; /* node to be added */
160 TRC3(cmLListAdd2Tail);
163 if (lCp == (CmLListCp *)NULLP)
169 node->prev = lCp->last;
171 lCp->last = lCp->crnt = node;
179 node->prev->next = node;
181 } /* end of cmLListAdd2Tail */
186 * Fun: cmLListInsCrnt
188 * Desc: adds node to linked list before crnt.
198 PUBLIC Void cmLListInsCrnt
200 CmLListCp *lCp, /* list control point */
201 CmLList *node /* node to be added */
204 PUBLIC Void cmLListInsCrnt(lCp, node)
205 CmLListCp *lCp; /* list control point */
206 CmLList *node; /* node to be added */
209 TRC3(cmLListInsCrnt);
220 lCp->crnt = lCp->first = lCp->last = node;
225 node->next = lCp->crnt;
226 node->prev = lCp->crnt->prev;
228 node->prev->next = node;
229 node->next->prev = node;
231 if (lCp->first == lCp->crnt)
236 } /* end of cmLListInsCrnt */
238 /* cm_llist_c_001.main_7 - Add function */
241 * Fun: cmLListInsAfterCrnt
243 * Desc: adds node to linked list after crnt.
253 PUBLIC Void cmLListInsAfterCrnt
255 CmLListCp *lCp, /* list control point */
256 CmLList *node /* node to be added */
259 PUBLIC Void cmLListInsAfterCrnt(lCp, node)
260 CmLListCp *lCp; /* list control point */
261 CmLList *node; /* node to be added */
264 TRC3(cmLListInsAfterCrnt);
275 lCp->crnt = lCp->first = lCp->last = node;
279 node->prev = lCp->crnt;
280 node->next = lCp->crnt->next;
282 node->next->prev = node;
283 node->prev->next = node;
285 if (lCp->last == lCp->crnt)
290 } /* end of cmLListInsAfterCrnt */
298 * Desc: remove node pointed to by nodePtr from list and return node.
299 * nodePtr could be anywhere in the list.
300 * - resets crnt to NULLP.
310 PUBLIC CmLList *cmLListDelFrm
312 CmLListCp *lCp, /* list control pointer */
313 CmLList *node /* node to be removed */
316 PUBLIC CmLList *cmLListDelFrm(lCp, node)
317 CmLListCp *lCp; /* list control pointer */
318 CmLList *node; /* node to be removed */
324 /* cm_llist_c_001.main_8 : added null check for node */
325 if (lCp == (CmLListCp *)NULLP || lCp->count == 0 || !node)
333 lCp->first = lCp->crnt = lCp->last = (CmLList *)NULLP;
339 lCp->crnt = (CmLList *)NULLP;
340 if (lCp->first == node)
343 node->next->prev = (CmLList *)NULLP;
344 lCp->first = node->next;
345 node->next = node->prev = (CmLList *)NULLP;
349 if (lCp->last == node)
352 node->prev->next = (CmLList *)NULLP;
353 lCp->last = node->prev;
354 node->next = node->prev = (CmLList *)NULLP;
358 node->prev->next = node->next;
359 node->next->prev = node->prev;
360 node->next = node->prev = (CmLList *)NULLP;
362 } /* end of cmLListDelFrm */
367 * Fun: cmLListCatLList
369 * Desc: adds a linked list to the end of the first list. list2 is
370 * added at the end of list1
380 PUBLIC Void cmLListCatLList
382 CmLListCp *list1, /*-- list control point --*/
383 CmLListCp *list2 /*-- node to be added --*/
386 PUBLIC Void cmLListCatLList(list1, list2)
387 CmLListCp *list1; /*-- list control point --*/
388 CmLListCp *list2; /*-- node to be added --*/
391 TRC3(cmLListCatLList);
393 /*-- if the second list is empty nothing to do --*/
394 if(list2->count == 0)
399 /*-- if the first list is empty make first the same as second*/
400 if(list1->count == 0)
402 list1->first = list2->first;
403 list1->last = list2->last;
404 list1->count = list2->count;
405 list1->crnt = list1->first;
409 list2->first->prev = list1->last;
410 list1->last->next = list2->first;
411 /* Set the last to the end of the 2nd list */
412 list1->last = list2->last;
413 list1->count += list2->count;
419 } /*-- end of cmLListCatLList --*/
421 /**********************************************************************
423 **********************************************************************/