]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/sorcerer/lib/sorlist.c
Add in the 1st version of ECP.
[mirror_edk2.git] / EdkCompatibilityPkg / Other / Maintained / Tools / Pccts / sorcerer / lib / sorlist.c
diff --git a/EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/sorcerer/lib/sorlist.c b/EdkCompatibilityPkg/Other/Maintained/Tools/Pccts/sorcerer/lib/sorlist.c
new file mode 100644 (file)
index 0000000..6872974
--- /dev/null
@@ -0,0 +1,123 @@
+/*\r
+ * slist.c\r
+ *\r
+ * SOFTWARE RIGHTS\r
+ *\r
+ * We reserve no LEGAL rights to SORCERER -- SORCERER is in the public\r
+ * domain.  An individual or company may do whatever they wish with\r
+ * source code distributed with SORCERER or the code generated by\r
+ * SORCERER, including the incorporation of SORCERER, or its output, into\r
+ * commerical software.\r
+ *\r
+ * We encourage users to develop software with SORCERER.  However, we do\r
+ * ask that credit is given to us for developing SORCERER.  By "credit",\r
+ * we mean that if you incorporate our source code into one of your\r
+ * programs (commercial product, research project, or otherwise) that you\r
+ * acknowledge this fact somewhere in the documentation, research report,\r
+ * etc...  If you like SORCERER and have developed a nice tool with the\r
+ * output, please mention that you developed it using SORCERER.  In\r
+ * addition, we ask that this header remain intact in our source code.\r
+ * As long as these guidelines are kept, we expect to continue enhancing\r
+ * this system and expect to make other tools available as they are\r
+ * completed.\r
+ *\r
+ * SORCERER 1.00B\r
+ * Terence Parr\r
+ * AHPCRC, University of Minnesota\r
+ * 1992-1994\r
+ */\r
+#include <stdio.h>\r
+#include <setjmp.h>\r
+\r
+#ifdef PCCTS_USE_STDARG\r
+#include <stdarg.h>\r
+#else\r
+#include <varargs.h>\r
+#endif\r
+\r
+#include "CASTBase.h"\r
+#include "sorlist.h"\r
+\r
+/* Iterate over a list of elements; returns ptr to a new element\r
+ * in list upon every call and NULL when no more are left.\r
+ * Very useful like this:\r
+ *\r
+ *    cursor = mylist;\r
+ *    while ( (p=slist_iterate(mylist,&cursor)) ) {\r
+ *      / * place with element p * /\r
+ *    }\r
+ *\r
+ * The cursor must be initialized to point to the list to iterate over.\r
+ */\r
+void *\r
+#ifdef __USE_PROTOS\r
+slist_iterate(SList *list, SList **cursor)\r
+#else\r
+slist_iterate(list, cursor)\r
+SList *list, **cursor;\r
+#endif\r
+{\r
+  void *e;\r
+\r
+  if ( list==NULL || cursor == NULL || *cursor==NULL ) return NULL;\r
+  if ( list== *cursor ) { *cursor = (*cursor)->next; }\r
+  e = (*cursor)->elem;\r
+  (*cursor) = (*cursor)->next;\r
+  return e;\r
+}\r
+\r
+/*\r
+ * add an element to a list.\r
+ *\r
+ * Any non-empty list has a sentinel node whose 'elem' pointer is really\r
+ * a pointer to the last element.  (i.e. length(list) = #elemIn(list)+1).\r
+ * Elements are appended to the list.\r
+ */\r
+void\r
+#ifdef __USE_PROTOS\r
+slist_add( SList **list, void *e )\r
+#else\r
+slist_add( list, e )\r
+SList **list;\r
+void *e;\r
+#endif\r
+{\r
+  SList *p, *tail;\r
+  require(e!=NULL, "slist_add: attempting to add NULL list element");\r
+\r
+  p = newSList;\r
+  require(p!=NULL, "slist_add: cannot alloc new list node");\r
+  p->elem = e;\r
+  if ( *list == NULL )\r
+  {\r
+    SList *sentinel = newSList;\r
+    require(sentinel!=NULL, "slist_add: cannot alloc sentinel node");\r
+    *list=sentinel;\r
+    sentinel->next = p;\r
+    sentinel->elem = (char *)p;    /* set tail pointer */\r
+  }\r
+  else                /* find end of list */\r
+  {\r
+    tail = (SList *) (*list)->elem;  /* get tail pointer */\r
+    tail->next = p;\r
+    (*list)->elem = (char *) p;    /* reset tail */\r
+  }\r
+}\r
+\r
+void\r
+#ifdef __USE_PROTOS\r
+slist_free(SList *list)\r
+#else\r
+slist_free(list)\r
+SList *list;\r
+#endif\r
+{\r
+  SList *p,*q;\r
+\r
+  if ( list==NULL ) return;  /* empty list */\r
+  for (p = list->next; p!=NULL; p=q)\r
+  {\r
+    q = p->next;\r
+    free(p);\r
+  }\r
+}\r