]>
git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/sorcerer/lib/sorlist.c
6 * We reserve no LEGAL rights to SORCERER -- SORCERER is in the public
7 * domain. An individual or company may do whatever they wish with
8 * source code distributed with SORCERER or the code generated by
9 * SORCERER, including the incorporation of SORCERER, or its output, into
10 * commerical software.
12 * We encourage users to develop software with SORCERER. However, we do
13 * ask that credit is given to us for developing SORCERER. By "credit",
14 * we mean that if you incorporate our source code into one of your
15 * programs (commercial product, research project, or otherwise) that you
16 * acknowledge this fact somewhere in the documentation, research report,
17 * etc... If you like SORCERER and have developed a nice tool with the
18 * output, please mention that you developed it using SORCERER. In
19 * addition, we ask that this header remain intact in our source code.
20 * As long as these guidelines are kept, we expect to continue enhancing
21 * this system and expect to make other tools available as they are
26 * AHPCRC, University of Minnesota
32 #ifdef PCCTS_USE_STDARG
41 /* Iterate over a list of elements; returns ptr to a new element
42 * in list upon every call and NULL when no more are left.
43 * Very useful like this:
46 * while ( (p=slist_iterate(mylist,&cursor)) ) {
47 * / * place with element p * /
50 * The cursor must be initialized to point to the list to iterate over.
54 slist_iterate(SList
*list
, SList
**cursor
)
56 slist_iterate(list
, cursor
)
57 SList
*list
, **cursor
;
62 if ( list
==NULL
|| cursor
== NULL
|| *cursor
==NULL
) return NULL
;
63 if ( list
== *cursor
) { *cursor
= (*cursor
)->next
; }
65 (*cursor
) = (*cursor
)->next
;
70 * add an element to a list.
72 * Any non-empty list has a sentinel node whose 'elem' pointer is really
73 * a pointer to the last element. (i.e. length(list) = #elemIn(list)+1).
74 * Elements are appended to the list.
78 slist_add( SList
**list
, void *e
)
86 require(e
!=NULL
, "slist_add: attempting to add NULL list element");
89 require(p
!=NULL
, "slist_add: cannot alloc new list node");
93 SList
*sentinel
= newSList
;
94 require(sentinel
!=NULL
, "slist_add: cannot alloc sentinel node");
97 sentinel
->elem
= (char *)p
; /* set tail pointer */
99 else /* find end of list */
101 tail
= (SList
*) (*list
)->elem
; /* get tail pointer */
103 (*list
)->elem
= (char *) p
; /* reset tail */
109 slist_free(SList
*list
)
117 if ( list
==NULL
) return; /* empty list */
118 for (p
= list
->next
; p
!=NULL
; p
=q
)