Renamed Symlist PtrList.

Sat, 26 Feb 2005 21:38:55 +0100

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sat, 26 Feb 2005 21:38:55 +0100
changeset 90
f5a392131875
parent 89
17a16ed84bbf
child 91
817f90f58aec

Renamed Symlist PtrList.

Makefile file | annotate | diff | comparison | revisions
ptrlist.c file | annotate | diff | comparison | revisions
ptrlist.h file | annotate | diff | comparison | revisions
symlist.c file | annotate | diff | comparison | revisions
symlist.h file | annotate | diff | comparison | revisions
--- a/Makefile	Sat Feb 26 10:37:20 2005 +0100
+++ b/Makefile	Sat Feb 26 21:38:55 2005 +0100
@@ -11,7 +11,7 @@
 CFLAGS += $(C89_SOURCE) $(POSIX_SOURCE) 
 
 SOURCES=misc.c output.c util.c optparser.c parser.c tokenizer.c \
-        map.c obj.c objlist.c errorlog.c symlist.c rb.c \
+        map.c obj.c objlist.c errorlog.c ptrlist.c rb.c \
         stringstore.c
 
 ifdef LIBTU_NO_ERRMSG
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ptrlist.c	Sat Feb 26 21:38:55 2005 +0100
@@ -0,0 +1,167 @@
+/*
+ * libtu/ptrlist.c
+ *
+ * Copyright (c) Tuomo Valkonen 1999-2005. 
+ *
+ * You may distribute and modify this library under the terms of either
+ * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
+ */
+
+#include "obj.h"
+#include "ptrlist.h"
+#include "types.h"
+#include "dlist.h"
+#include "misc.h"
+
+
+static void free_node(PtrList **ptrlist, PtrList *node)
+{
+    UNLINK_ITEM(*ptrlist, node, next, prev);
+    free(node);
+}
+
+
+static PtrList *mknode(void *ptr)
+{
+    PtrList *node;
+    
+    if(ptr==NULL)
+        return NULL;
+    
+    node=ALLOC(PtrList);
+    
+    if(node==NULL)
+        return FALSE;
+        
+    node->ptr=ptr;
+    
+    return node;
+}
+
+
+static PtrList *ptrlist_find_node(PtrList *ptrlist, void *ptr)
+{
+    PtrList *node=ptrlist;
+    
+    while(node!=NULL){
+        if(node->ptr==ptr)
+            break;
+        node=node->next;
+    }
+    
+    return node;
+}
+
+
+bool ptrlist_insert_last(PtrList **ptrlist, void *ptr)
+{
+    PtrList *node=mknode(ptr);
+    
+    if(node==NULL)
+        return FALSE;
+    
+    LINK_ITEM_LAST(*ptrlist, node, next, prev);
+    
+    return TRUE;
+}
+
+
+bool ptrlist_insert_first(PtrList **ptrlist, void *ptr)
+{
+    PtrList *node=mknode(ptr);
+    
+    if(node==NULL)
+        return FALSE;
+    
+    LINK_ITEM_FIRST(*ptrlist, node, next, prev);
+    
+    return TRUE;
+}
+
+
+bool ptrlist_reinsert_last(PtrList **ptrlist, void *ptr)
+{
+    PtrList *node=ptrlist_find_node(*ptrlist, ptr);
+    
+    if(node==NULL)
+        return FALSE;
+    
+    UNLINK_ITEM(*ptrlist, node, next, prev);
+    LINK_ITEM_LAST(*ptrlist, node, next, prev);
+    
+    return TRUE;
+}
+
+
+bool ptrlist_reinsert_first(PtrList **ptrlist, void *ptr)
+{
+    PtrList *node=ptrlist_find_node(*ptrlist, ptr);
+    
+    if(node==NULL)
+        return FALSE;
+    
+    UNLINK_ITEM(*ptrlist, node, next, prev);
+    LINK_ITEM_FIRST(*ptrlist, node, next, prev);
+    
+    return TRUE;
+}
+
+
+void ptrlist_remove(PtrList **ptrlist, void *ptr)
+{
+    PtrList *node=ptrlist_find_node(*ptrlist, ptr);
+    
+    if(node!=NULL)
+        free_node(ptrlist, node);
+}
+
+
+void ptrlist_clear(PtrList **ptrlist)
+{
+    while(*ptrlist!=NULL)
+        free_node(ptrlist, *ptrlist);
+}
+
+
+PtrListIterTmp ptrlist_iter_tmp=NULL;
+
+
+void ptrlist_iter_init(PtrListIterTmp *state, PtrList *ptrlist)
+{
+    *state=ptrlist;
+}
+
+
+void *ptrlist_iter(PtrListIterTmp *state)
+{
+    void *ptr=NULL;
+    
+    if(*state!=NULL){
+        ptr=(*state)->ptr;
+        (*state)=(*state)->next;
+    }
+    
+    return ptr;
+}
+
+
+void ptrlist_iter_rev_init(PtrListIterTmp *state, PtrList *ptrlist)
+{
+    *state=(ptrlist==NULL ? NULL : ptrlist->prev);
+}
+
+
+void *ptrlist_iter_rev(PtrListIterTmp *state)
+{
+    void *ptr=NULL;
+    
+    if(*state!=NULL){
+        ptr=(*state)->ptr;
+        *state=(*state)->prev;
+        if((*state)->next==NULL)
+            *state=NULL;
+    }
+    
+    return ptr;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ptrlist.h	Sat Feb 26 21:38:55 2005 +0100
@@ -0,0 +1,60 @@
+/*
+ * libtu/ptrlist.h
+ *
+ * Copyright (c) Tuomo Valkonen 1999-2005.
+ *
+ * You may distribute and modify this library under the terms of either
+ * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
+ */
+
+#ifndef LIBTU_PTRLIST_H
+#define LIBTU_PTRLIST_H
+
+#include "types.h"
+#include "obj.h"
+
+
+INTRSTRUCT(PtrList);
+
+
+DECLSTRUCT(PtrList){
+    void *ptr;
+    PtrList *next, *prev;
+};
+
+
+typedef PtrList* PtrListIterTmp;
+
+#define PTRLIST_FIRST(TYPE, LL) ((LL)==NULL ? NULL : (TYPE)(LL)->ptr)
+#define PTRLIST_LAST(TYPE, LL) ((LL)==NULL ? NULL : (TYPE)(LL)->prev->ptr)
+#define PTRLIST_EMPTY(LIST) ((LIST)==NULL)
+
+#define FOR_ALL_ON_PTRLIST(TYPE, VAR, LL, TMP) \
+    for(ptrlist_iter_init(&(TMP), LL),         \
+         VAR=(TYPE)ptrlist_iter(&(TMP));       \
+        VAR!=NULL;                             \
+        VAR=(TYPE)ptrlist_iter(&(TMP)))
+
+#define FOR_ALL_ON_PTRLIST_REV(TYPE, VAR, LL, TMP) \
+    for(ptrlist_iter_rev_init(&(TMP), LL),         \
+         VAR=(TYPE)ptrlist_iter_rev(&(TMP));       \
+        VAR!=NULL;                                 \
+        VAR=(TYPE)ptrlist_iter_rev(&(TMP)))
+
+#define FOR_ALL_ON_PTRLIST_UNSAFE(TYPE, VAR, LL) \
+    FOR_ALL_ON_PTRLIST(TYPE, VAR, LL, ptrlist_iter_tmp)
+
+extern PtrListIterTmp ptrlist_iter_tmp;
+
+extern bool ptrlist_insert_last(PtrList **ptrlist, void *ptr);
+extern bool ptrlist_insert_first(PtrList **ptrlist, void *ptr);
+extern bool ptrlist_reinsert_last(PtrList **ptrlist, void *ptr);
+extern bool ptrlist_reinsert_first(PtrList **ptrlist, void *ptr);
+extern void ptrlist_remove(PtrList **ptrlist, void *ptr);
+extern void ptrlist_clear(PtrList **ptrlist);
+extern void ptrlist_iter_init(PtrListIterTmp *state, PtrList *ptrlist);
+extern void *ptrlist_iter(PtrListIterTmp *state);
+extern void ptrlist_iter_rev_init(PtrListIterTmp *state, PtrList *ptrlist);
+extern void *ptrlist_iter_rev(PtrListIterTmp *state);
+
+#endif /* LIBTU_PTRLIST_H */
--- a/symlist.c	Sat Feb 26 10:37:20 2005 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,167 +0,0 @@
-/*
- * libtu/symlist.c
- *
- * Copyright (c) Tuomo Valkonen 1999-2004. 
- *
- * You may distribute and modify this library under the terms of either
- * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
- */
-
-#include "obj.h"
-#include "symlist.h"
-#include "types.h"
-#include "dlist.h"
-#include "misc.h"
-
-
-static void free_node(Symlist **symlist, Symlist *node)
-{
-    UNLINK_ITEM(*symlist, node, next, prev);
-    free(node);
-}
-
-
-static Symlist *mknode(void *symbol)
-{
-    Symlist *node;
-    
-    if(symbol==NULL)
-        return NULL;
-    
-    node=ALLOC(Symlist);
-    
-    if(node==NULL)
-        return FALSE;
-        
-    node->symbol=symbol;
-    
-    return node;
-}
-
-
-static Symlist *symlist_find_node(Symlist *symlist, void *symbol)
-{
-    Symlist *node=symlist;
-    
-    while(node!=NULL){
-        if(node->symbol==symbol)
-            break;
-        node=node->next;
-    }
-    
-    return node;
-}
-
-
-bool symlist_insert_last(Symlist **symlist, void *symbol)
-{
-    Symlist *node=mknode(symbol);
-    
-    if(node==NULL)
-        return FALSE;
-    
-    LINK_ITEM_LAST(*symlist, node, next, prev);
-    
-    return TRUE;
-}
-
-
-bool symlist_insert_first(Symlist **symlist, void *symbol)
-{
-    Symlist *node=mknode(symbol);
-    
-    if(node==NULL)
-        return FALSE;
-    
-    LINK_ITEM_FIRST(*symlist, node, next, prev);
-    
-    return TRUE;
-}
-
-
-bool symlist_reinsert_last(Symlist **symlist, void *symbol)
-{
-    Symlist *node=symlist_find_node(*symlist, symbol);
-    
-    if(node==NULL)
-        return FALSE;
-    
-    UNLINK_ITEM(*symlist, node, next, prev);
-    LINK_ITEM_LAST(*symlist, node, next, prev);
-    
-    return TRUE;
-}
-
-
-bool symlist_reinsert_first(Symlist **symlist, void *symbol)
-{
-    Symlist *node=symlist_find_node(*symlist, symbol);
-    
-    if(node==NULL)
-        return FALSE;
-    
-    UNLINK_ITEM(*symlist, node, next, prev);
-    LINK_ITEM_FIRST(*symlist, node, next, prev);
-    
-    return TRUE;
-}
-
-
-void symlist_remove(Symlist **symlist, void *symbol)
-{
-    Symlist *node=symlist_find_node(*symlist, symbol);
-    
-    if(node!=NULL)
-        free_node(symlist, node);
-}
-
-
-void symlist_clear(Symlist **symlist)
-{
-    while(*symlist!=NULL)
-        free_node(symlist, *symlist);
-}
-
-
-SymlistIterTmp symlist_iter_tmp=NULL;
-
-
-void symlist_iter_init(SymlistIterTmp *state, Symlist *symlist)
-{
-    *state=symlist;
-}
-
-
-void *symlist_iter(SymlistIterTmp *state)
-{
-    void *symbol=NULL;
-    
-    if(*state!=NULL){
-        symbol=(*state)->symbol;
-        (*state)=(*state)->next;
-    }
-    
-    return symbol;
-}
-
-
-void symlist_iter_rev_init(SymlistIterTmp *state, Symlist *symlist)
-{
-    *state=(symlist==NULL ? NULL : symlist->prev);
-}
-
-
-void *symlist_iter_rev(SymlistIterTmp *state)
-{
-    void *symbol=NULL;
-    
-    if(*state!=NULL){
-        symbol=(*state)->symbol;
-        *state=(*state)->prev;
-        if((*state)->next==NULL)
-            *state=NULL;
-    }
-    
-    return symbol;
-}
-
--- a/symlist.h	Sat Feb 26 10:37:20 2005 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-/*
- * libtu/symlist.h
- *
- * Copyright (c) Tuomo Valkonen 1999-2004. 
- *
- * You may distribute and modify this library under the terms of either
- * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
- */
-
-#ifndef LIBTU_SYMLIST_H
-#define LIBTU_SYMLIST_H
-
-#include "types.h"
-#include "obj.h"
-
-
-INTRSTRUCT(Symlist);
-
-
-DECLSTRUCT(Symlist){
-    void *symbol;
-    Symlist *next, *prev;
-};
-
-
-typedef Symlist* SymlistIterTmp;
-
-#define SYMLIST_FIRST(TYPE, LL) ((LL)==NULL ? NULL : (TYPE)(LL)->symbol)
-#define SYMLIST_LAST(TYPE, LL) ((LL)==NULL ? NULL : (TYPE)(LL)->prev->symbol)
-
-#define FOR_ALL_ON_SYMLIST(TYPE, VAR, LL, TMP) \
-    for(symlist_iter_init(&(TMP), LL),         \
-         VAR=(TYPE)symlist_iter(&(TMP));       \
-        VAR!=NULL;                             \
-        VAR=(TYPE)symlist_iter(&(TMP)))
-
-#define FOR_ALL_ON_SYMLIST_REV(TYPE, VAR, LL, TMP) \
-    for(symlist_iter_rev_init(&(TMP), LL),         \
-         VAR=(TYPE)symlist_iter_rev(&(TMP));       \
-        VAR!=NULL;                                 \
-        VAR=(TYPE)symlist_iter_rev(&(TMP)))
-
-#define FOR_ALL_ON_SYMLIST_UNSAFE(TYPE, VAR, LL) \
-    FOR_ALL_ON_SYMLIST(TYPE, VAR, LL, symlist_iter_tmp)
-
-extern SymlistIterTmp symlist_iter_tmp;
-
-#define SYMLIST_EMPTY(LIST) ((LIST)==NULL)
-
-extern bool symlist_insert_last(Symlist **symlist, void *symbol);
-extern bool symlist_insert_first(Symlist **symlist, void *symbol);
-extern bool symlist_reinsert_last(Symlist **symlist, void *symbol);
-extern bool symlist_reinsert_first(Symlist **symlist, void *symbol);
-extern void symlist_remove(Symlist **symlist, void *symbol);
-extern void symlist_clear(Symlist **symlist);
-extern void symlist_iter_init(SymlistIterTmp *state, Symlist *symlist);
-extern void *symlist_iter(SymlistIterTmp *state);
-extern void symlist_iter_rev_init(SymlistIterTmp *state, Symlist *symlist);
-extern void *symlist_iter_rev(SymlistIterTmp *state);
-
-#endif /* LIBTU_SYMLIST_H */

mercurial