EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/sorcerer/lib/sorlist.c

Go to the documentation of this file.
00001 /*
00002  * slist.c
00003  *
00004  * SOFTWARE RIGHTS
00005  *
00006  * We reserve no LEGAL rights to SORCERER -- SORCERER is in the public
00007  * domain.  An individual or company may do whatever they wish with
00008  * source code distributed with SORCERER or the code generated by
00009  * SORCERER, including the incorporation of SORCERER, or its output, into
00010  * commerical software.
00011  *
00012  * We encourage users to develop software with SORCERER.  However, we do
00013  * ask that credit is given to us for developing SORCERER.  By "credit",
00014  * we mean that if you incorporate our source code into one of your
00015  * programs (commercial product, research project, or otherwise) that you
00016  * acknowledge this fact somewhere in the documentation, research report,
00017  * etc...  If you like SORCERER and have developed a nice tool with the
00018  * output, please mention that you developed it using SORCERER.  In
00019  * addition, we ask that this header remain intact in our source code.
00020  * As long as these guidelines are kept, we expect to continue enhancing
00021  * this system and expect to make other tools available as they are
00022  * completed.
00023  *
00024  * SORCERER 1.00B
00025  * Terence Parr
00026  * AHPCRC, University of Minnesota
00027  * 1992-1994
00028  */
00029 #include <stdio.h>
00030 #include <setjmp.h>
00031 
00032 #ifdef PCCTS_USE_STDARG
00033 #include <stdarg.h>
00034 #else
00035 #include <varargs.h>
00036 #endif
00037 
00038 #include "CASTBase.h"
00039 #include "sorlist.h"
00040 
00041 /* Iterate over a list of elements; returns ptr to a new element
00042  * in list upon every call and NULL when no more are left.
00043  * Very useful like this:
00044  *
00045  *    cursor = mylist;
00046  *    while ( (p=slist_iterate(mylist,&cursor)) ) {
00047  *      / * place with element p * /
00048  *    }
00049  *
00050  * The cursor must be initialized to point to the list to iterate over.
00051  */
00052 void *
00053 #ifdef __USE_PROTOS
00054 slist_iterate(SList *list, SList **cursor)
00055 #else
00056 slist_iterate(list, cursor)
00057 SList *list, **cursor;
00058 #endif
00059 {
00060   void *e;
00061 
00062   if ( list==NULL || cursor == NULL || *cursor==NULL ) return NULL;
00063   if ( list== *cursor ) { *cursor = (*cursor)->next; }
00064   e = (*cursor)->elem;
00065   (*cursor) = (*cursor)->next;
00066   return e;
00067 }
00068 
00069 /*
00070  * add an element to a list.
00071  *
00072  * Any non-empty list has a sentinel node whose 'elem' pointer is really
00073  * a pointer to the last element.  (i.e. length(list) = #elemIn(list)+1).
00074  * Elements are appended to the list.
00075  */
00076 void
00077 #ifdef __USE_PROTOS
00078 slist_add( SList **list, void *e )
00079 #else
00080 slist_add( list, e )
00081 SList **list;
00082 void *e;
00083 #endif
00084 {
00085   SList *p, *tail;
00086   require(e!=NULL, "slist_add: attempting to add NULL list element");
00087 
00088   p = newSList;
00089   require(p!=NULL, "slist_add: cannot alloc new list node");
00090   p->elem = e;
00091   if ( *list == NULL )
00092   {
00093     SList *sentinel = newSList;
00094     require(sentinel!=NULL, "slist_add: cannot alloc sentinel node");
00095     *list=sentinel;
00096     sentinel->next = p;
00097     sentinel->elem = (char *)p;    /* set tail pointer */
00098   }
00099   else                /* find end of list */
00100   {
00101     tail = (SList *) (*list)->elem;  /* get tail pointer */
00102     tail->next = p;
00103     (*list)->elem = (char *) p;    /* reset tail */
00104   }
00105 }
00106 
00107 void
00108 #ifdef __USE_PROTOS
00109 slist_free(SList *list)
00110 #else
00111 slist_free(list)
00112 SList *list;
00113 #endif
00114 {
00115   SList *p,*q;
00116 
00117   if ( list==NULL ) return;  /* empty list */
00118   for (p = list->next; p!=NULL; p=q)
00119   {
00120     q = p->next;
00121     free(p);
00122   }
00123 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines