[ekg2-commit] r4053 - trunk/ekg: +trunk/ekg/dynstuff_inline.h trunk/ekg/Makefile.am

SVN commit svn w toxygen.net
Pon, 7 Lip 2008, 20:05:01 CEST


Author: darkjames
Date: 2008-07-07 20:05:00 +0200 (Mon, 07 Jul 2008)
New Revision: 4053

Added:
   trunk/ekg/dynstuff_inline.h
Modified:
   trunk/ekg/Makefile.am
Log:


Modified: trunk/ekg/Makefile.am
===================================================================
--- trunk/ekg/Makefile.am	2008-07-07 17:44:43 UTC (rev 4052)
+++ trunk/ekg/Makefile.am	2008-07-07 18:05:00 UTC (rev 4053)
@@ -1,4 +1,4 @@
-ekg2_headers = audio.h audio_wav.h configfile.h dynstuff.h events.h metacontacts.h queries.h objects.h protocol.h sessions.h strings.h themes.h vars.h xmalloc.h \
+ekg2_headers = audio.h audio_wav.h configfile.h dynstuff.h dynstuff_inline.h events.h metacontacts.h queries.h objects.h protocol.h sessions.h strings.h themes.h vars.h xmalloc.h \
 		commands.h debug.h emoticons.h log.h msgqueue.h plugins.h scripts.h stuff.h userlist.h windows.h win32.h ../gettext.h ../ekg2-config.h
 
 bin_PROGRAMS = ekg2

Added: trunk/ekg/dynstuff_inline.h
===================================================================
--- trunk/ekg/dynstuff_inline.h	                        (rev 0)
+++ trunk/ekg/dynstuff_inline.h	2008-07-07 18:05:00 UTC (rev 4053)
@@ -0,0 +1,133 @@
+#ifndef __EKG_DYNSTUFF_INLINE_H
+#define __EKG_DYNSTUFF_INLINE_H
+
+/* we could use typeof() instead of passing paramtype, but let's be more portable */
+
+#define DYNSTUFF_USE_LIST3 1
+
+#if DYNSTUFF_USE_LIST3
+
+#define __DYNSTUFF_LIST_ADD_SORTED(lista, typ, comparision) \
+	void lista##_add(typ *new) { list_add_sorted3((list_t *) &lista, (list_t) new, (void *) comparision); }
+
+#define __DYNSTUFF_LIST_REMOVE_SAFE(lista, typ, free_func)				\
+	void lista##_remove(typ *elem) { 						\
+		list_remove3((list_t *) &lista, (list_t) elem, (void *) free_func);	\
+	}
+
+#define __DYNSTUFF_LIST_DESTROY(lista, typ, free_func)					\
+	void lista##_destroy(void) { 							\
+		list_destroy3((list_t) &lista, (void *) free_func);			\
+		lista = NULL;								\
+	}
+
+#else
+
+#define __DYNSTUFF_LIST_ADD(lista, typ) 			\
+	void lista##_add(typ *new) {				\
+		new->next = NULL;				\
+		if (!lista) {					\
+			lista = new;				\
+		} else {					\
+			typ *tmp = lista;			\
+								\
+			while (tmp->next)			\
+				tmp = tmp->next;		\
+			tmp->next = new;			\
+		}						\
+}
+
+#define __DYNSTUFF_LIST_ADD_BEGINNING(lista, typ) 		\
+	void lista##_add(typ *new) {				\
+		new->next = lista;				\
+		lista  = new;					\
+	}
+
+#define __DYNSTUFF_LIST_ADD_SORTED(lista, typ, comparision) 	\
+	void lista##_add(typ *new) {				\
+		new->next = NULL;				\
+		if (!lista) {					\
+			lista = new;				\
+		} else {					\
+			typ *tmp = lista;			\
+			typ *prev = NULL;			\
+								\
+			while (tmp->next)			\
+				tmp = tmp->next;		\
+			tmp->next = new;			\
+								\
+			while (comparision(new, tmp) > 0) {	\
+				prev = tmp;			\
+				tmp = tmp->next;		\
+				if (!tmp)			\
+					break;			\
+			}					\
+								\
+			if (!prev) {				\
+				new->next = lista;		\
+				lista = new;			\
+			} else {				\
+				prev->next = new;		\
+				new->next = tmp;		\
+			}					\
+		}						\
+	}
+
+#define __DYNSTUFF_LIST_REMOVE(lista, typ, free_func)		\
+	void lista##_remove(typ *elem) {			\
+		if (lista == elem) 				\
+			lista = lista->next;			\
+		else {						\
+			typ *tmp, *last;			\
+								\
+			for (tmp = lista; tmp; tmp = tmp->next){\
+				if (tmp == elem)		\
+					break;			\
+				last = tmp;			\
+			}					\
+			last->next = tmp->next;			\
+		}						\
+		free_func(elem);				\
+	}
+
+#define __DYNSTUFF_LIST_REMOVE_SAFE(lista, typ, free_func)	\
+	void lista##_remove(typ *elem) {			\
+		if (!lista)	/* programmer's fault */	\
+			return;					\
+								\
+		if (lista == elem) 				\
+			lista = lista->next;			\
+		else {						\
+			typ *tmp, *last;			\
+								\
+			for (tmp = lista; tmp; tmp = tmp->next){\
+				if (tmp == elem)		\
+					break;			\
+				if (tmp->next == NULL) {	\
+					errno = ENOENT;		\
+					return;			\
+				}				\
+				last = tmp;			\
+			}					\
+			last->next = tmp->next;			\
+		}						\
+		free_func(elem);				\
+	}
+
+#define __DYNSTUFF_LIST_DESTROY(lista, typ, free_func)		\
+	void lista##_destroy(void) {				\
+		while (lista) {					\
+			typ *tmp = lista;			\
+								\
+			lista = lista->next;			\
+								\
+			if (free_func)				\
+				free_func(tmp);			\
+								\
+			xfree(tmp);				\
+		}						\
+	}
+
+#endif	/* !DYNSTUFF_USE_LIST3 */
+
+#endif



Więcej informacji o liście dyskusyjnej ekg2-commit