[ekg2-commit] r4063 - trunk/ekg: trunk/ekg/dynstuff_inline.h trunk/ekg/log.c trunk/ekg/sessions.c

SVN commit svn w toxygen.net
Wto, 8 Lip 2008, 11:17:36 CEST


Author: darkjames
Date: 2008-07-08 11:17:36 +0200 (Tue, 08 Jul 2008)
New Revision: 4063

Modified:
   trunk/ekg/dynstuff_inline.h
   trunk/ekg/log.c
   trunk/ekg/sessions.c
Log:


Modified: trunk/ekg/dynstuff_inline.h
===================================================================
--- trunk/ekg/dynstuff_inline.h	2008-07-08 08:17:16 UTC (rev 4062)
+++ trunk/ekg/dynstuff_inline.h	2008-07-08 09:17:36 UTC (rev 4063)
@@ -225,7 +225,151 @@
 	}
 
 #else
+	/* XXX, checkit */
 
+#define __DYNSTUFF_ADD(prefix, typ) 				\
+	void prefix##_add(typ **lista, typ *new) {		\
+		typ *tmp = *lista;				\
+								\
+		new->next = NULL;				\
+		if (!(tmp = *lista)) {				\
+			*lista = new;				\
+		} else {					\
+			while (tmp->next)			\
+				tmp = tmp->next;		\
+			tmp->next = new;			\
+		}						\
+}
+
+#define __DYNSTUFF_ADD_BEGINNING(prefix, typ) 			\
+	void prefix##_add(typ **lista, typ *new) {		\
+		new->next = *lista;				\
+		*lista  = new;					\
+	}
+
+#define __DYNSTUFF_ADD_SORTED(prefix, typ, comparision) 	\
+	void prefix##_add(typ **lista, typ *new) {		\
+		typ *tmp = lista;				\
+								\
+		new->next = NULL;				\
+		if (!(tmp = *lista)) {				\
+			*lista = new;				\
+		} else {					\
+			typ *prev = NULL;			\
+								\
+			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_REMOVE_SAFE(prefix, typ, free_func)		\
+	void prefix##_remove(typ **lista, typ *elem) {		\
+		if (!lista || !(*lista))	/* programmer's fault */\
+			return;					\
+								\
+		if (*lista == elem) 				\
+			*lista = (*lista)->next;		\
+		else {						\
+			typ *tmp, *last = *lista;		\
+								\
+			for (tmp = (*lista)->next; tmp; tmp = tmp->next) { \
+				if (tmp == elem)		\
+					break;			\
+				if (tmp->next == NULL) {	\
+					/* errno = ENOENT; */	\
+					return;			\
+				}				\
+				last = tmp;			\
+			}					\
+			last->next = tmp->next;			\
+		}						\
+		/* if (free_func) */				\
+			free_func(elem);			\
+		xfree(elem);					\
+	}
+
+#define __DYNSTUFF_REMOVE_ITER(prefix, typ, free_func)		\
+	typ *prefix##_removei(typ **lista, typ *elem) {		\
+		typ *ret;					\
+								\
+		if (*lista == elem) { 				\
+			*lista = (*lista)->next;		\
+			ret = (typ *) lista;			\
+		} else {					\
+			typ *tmp, *last = *lista;		\
+								\
+			for (tmp = (*lista)->next; tmp; tmp = tmp->next) { \
+				if (tmp == elem)		\
+					break;			\
+				last = tmp;			\
+			}					\
+			last->next = tmp->next;			\
+			ret = last;				\
+		}						\
+		/* if (free_func) */				\
+			free_func(elem);			\
+		xfree(elem);					\
+		return ret;					\
+	}
+
+#define __DYNSTUFF_UNLINK(prefix, typ)				\
+	void prefix##_unlink(typ **lista, typ *elem) {		\
+		if (!lista || !(*lista))	/* programmer's fault */	\
+			return;					\
+								\
+		if (*lista == elem) 				\
+			*lista = (*lista)->next;		\
+		else {						\
+			typ *tmp, *last = *lista;		\
+								\
+			for (tmp = (*lista)->next; tmp; tmp = tmp->next) { \
+				if (tmp == elem)		\
+					break;			\
+				if (tmp->next == NULL) {	\
+					/* errno = ENOENT; */	\
+					return;			\
+				}				\
+				last = tmp;			\
+			}					\
+			last->next = tmp->next;			\
+		}						\
+	}
+
+#define __DYNSTUFF_DESTROY(prefix, typ, free_func)		\
+	void prefix##_destroy(typ **lista) {			\
+		while (*lista) {				\
+			typ *tmp = *lista;			\
+								\
+			*lista = (*lista)->next;		\
+								\
+			/* if (free_func) */			\
+				free_func(tmp);			\
+								\
+			xfree(tmp);				\
+		}						\
+	}
+
+#define __DYNSTUFF_COUNT(prefix, typ)					\
+	int prefix##_count(typ *list) {					\
+		int count = 0;						\
+									\
+		for (; list; list = list->next)				\
+			count++;					\
+		return count;						\
+	}
+
 #endif
 
 #endif

Modified: trunk/ekg/log.c
===================================================================
--- trunk/ekg/log.c	2008-07-08 08:17:16 UTC (rev 4062)
+++ trunk/ekg/log.c	2008-07-08 09:17:36 UTC (rev 4063)
@@ -44,6 +44,7 @@
 __DYNSTUFF_LIST_ADD(lasts, struct last);				/* lasts_add() */
 __DYNSTUFF_LIST_REMOVE_ITER(lasts, struct last, list_last_free);	/* lasts_removei() */
 __DYNSTUFF_LIST_DESTROY(lasts, struct last, list_last_free);		/* lasts_destroy() */
+__DYNSTUFF_LIST_COUNT(lasts, struct last);				/* lasts_count() */
 
 /*
  * last_add()
@@ -67,7 +68,7 @@
 	if (config_last & 2) 
 		count = last_count(uid);
 	else
-		count = LIST_COUNT2(lasts);
+		count = lasts_count();
 				
 	/* usuwamy ostatnią wiadomość, w razie potrzeby... */
 	if (count >= config_last_size) {
@@ -88,7 +89,7 @@
 		/* ...by teraz usunąć */
 		for (ll = lasts; ll; ll = ll->next) {
 			if (ll->time == tmp_time && !xstrcasecmp(ll->uid, uid)) {
-				LIST_REMOVE2(&lasts, ll, list_last_free);
+				(void) lasts_removei(ll);
 				break;
 			}
 		}

Modified: trunk/ekg/sessions.c
===================================================================
--- trunk/ekg/sessions.c	2008-07-08 08:17:16 UTC (rev 4062)
+++ trunk/ekg/sessions.c	2008-07-08 09:17:36 UTC (rev 4063)
@@ -57,6 +57,11 @@
 __DYNSTUFF_LIST_ADD_SORTED(sessions, session_t, session_compare);	/* sessions_add() */
 __DYNSTUFF_LIST_COUNT(sessions, session_t);				/* sessions_count() */
 
+static LIST_FREE_ITEM(session_param_free_item, session_param_t *) { xfree(data->key); xfree(data->value);  }
+
+__DYNSTUFF_ADD_BEGINNING(session_vars, session_param_t);			/* session_vars_add() */
+__DYNSTUFF_DESTROY(session_vars, session_param_t, session_param_free_item);	/* session_vars_destroy() */
+
 session_t *session_current = NULL;
 
 /**
@@ -211,17 +216,12 @@
 	return s;
 }
 
-static LIST_FREE_ITEM(session_param_free_item, session_param_t *) {
-	xfree(data->key);
-	xfree(data->value);
-}
-
 static LIST_FREE_ITEM(session_free_item, session_t *) {
 /* free _global_ session variables */
 	array_free_count(data->values, data->global_vars_count);
 
 /* free _local_ session variables */
-	LIST_DESTROY2(data->local_vars, session_param_free_item);
+	session_vars_destroy(&(data->local_vars));
 
 	xfree(data->alias);
 	xfree(data->uid);
@@ -706,7 +706,8 @@
 	v->key = xstrdup(key);
 	v->value = xstrdup(value);
 
-	return (LIST_ADD_BEGINNING2(&s->local_vars, v) != NULL) ? 0 : -1;
+	session_vars_add(&s->local_vars, v);
+	return 0;
 
 notify:
 	if (pa && pa->notify)
@@ -1443,30 +1444,27 @@
 void sessions_free() {
 	session_t *s;
 
+	struct timer *t;
+	watch_t *w;
+	window_t *wl;
+
         if (!sessions)
                 return;
 
-	{		/* remove _ALL_ session watches */
-		watch_t *w;
+/* remove _ALL_ session watches */
+	for (w = watches; w;) {
+		watch_t *next = w->next;
+		watch_t *tmp;
 
-		for (w = watches; w;) {
-			watch_t *tmp;
-			watch_t *next = w->next;
+		if (w->is_session && ((tmp = watch_free(w))))
+			next = tmp;
 
-			if (w->is_session && ((tmp = watch_free(w))))
-				next = tmp;
-
-			w = next;
-		}
+		w = next;
 	}
 
-	{
-		struct timer *t;
-
-		for (t = timers; t; t = t->next) {
-			if (t->is_session)
-				t = timers_removei(t);
-		}
+	for (t = timers; t; t = t->next) {
+		if (t->is_session)
+			t = timers_removei(t);
 	}
 
 /* it's sessions, not 'l' because we emit SESSION_REMOVED, which might want to search over sessions list...
@@ -1474,20 +1472,17 @@
  */
 /* mg: I modified it so it'll first emit all the events, and then start to free everything
  * That shouldn't be a problem, should it? */
-        for (s = sessions; s; s = s->next)
+        for (s = sessions; s; s = s->next) {
 		query_emit_id(s->plugin, SESSION_REMOVED, &(s->uid));	/* it notify only that plugin here, to free internal data. 
 									 * ui-plugin already removed.. other plugins @ quit.
 									 * shouldn't be aware about it. too...
 									 * XXX, think about it?
 									 */
-
-	{
-		window_t *w;
-
-		for (w = windows; w; w = w->next)
-			w->session = NULL;
 	}
 
+	for (wl = windows; wl; wl = wl->next)
+		wl->session = NULL;
+
 	sessions_destroy();
 	session_current = NULL;
 	window_current->session = NULL;



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