[ekg2-commit] r3873 - in trunk: ekg plugins/gg plugins/gtk plugins/jabber plugins/ncurses plugins/polchat plugins/python plugins/rc plugins/readline: trunk/ekg/commands.c trunk/ekg/configfile.c trunk/ekg/dynstuff.c trunk/ekg/dynstuff.h trunk/ekg/ekg.c trunk/ekg/log.c trunk/ekg/msgqueue.c trunk/ekg/plugins.c trunk/ekg/plugins.h trunk/ekg/queries.h trunk/ekg/scripts.c trunk/ekg/sessions.c trunk/ekg/themes.c trunk/plugins/gg/commands.c trunk/plugins/gtk/completion.c trunk/plugins/jabber/commands.c trunk/plugins/ncurses/completion.c trunk/plugins/polchat/polchat.c trunk/plugins/python/python-ekg.c trunk/plugins/rc/main.c trunk/plugins/readline/readline-completion.c

SVN commit svn w toxygen.net
Nie, 9 Mar 2008, 12:05:09 CET


Author: peres
Date: 2008-03-09 12:05:08 +0100 (Sun, 09 Mar 2008)
New Revision: 3873

Modified:
   trunk/ekg/commands.c
   trunk/ekg/configfile.c
   trunk/ekg/dynstuff.c
   trunk/ekg/dynstuff.h
   trunk/ekg/ekg.c
   trunk/ekg/log.c
   trunk/ekg/msgqueue.c
   trunk/ekg/plugins.c
   trunk/ekg/plugins.h
   trunk/ekg/queries.h
   trunk/ekg/scripts.c
   trunk/ekg/sessions.c
   trunk/ekg/themes.c
   trunk/plugins/gg/commands.c
   trunk/plugins/gtk/completion.c
   trunk/plugins/jabber/commands.c
   trunk/plugins/ncurses/completion.c
   trunk/plugins/polchat/polchat.c
   trunk/plugins/python/python-ekg.c
   trunk/plugins/rc/main.c
   trunk/plugins/readline/readline-completion.c
Log:

Plugins, watches, queries, idles.

Dunno what to do with queries_external. Problably they'd stay on list_t.



Modified: trunk/ekg/commands.c
===================================================================
--- trunk/ekg/commands.c	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/ekg/commands.c	2008-03-09 11:05:08 UTC (rev 3873)
@@ -1939,13 +1939,12 @@
 
 static COMMAND(cmd_debug_watches)
 {
-	list_t l;
+	watch_t *w;
 	char buf[256];
 	
 	printq("generic_bold", ("fd     wa   plugin  pers tout  started     rm"));
 	
-	for (l = watches; l; l = l->next) {
-		watch_t *w = l->data;
+	for (w = watches; w; w = w->next) {
 		char wa[4];
 		char *plugin;
 
@@ -1972,7 +1971,7 @@
 
 static COMMAND(cmd_debug_queries)
 {
-	list_t l, *ll;
+	query_t **ll, *q;
 	
 	printq("generic", ("name                             | plugin      | count"));
 	printq("generic", ("---------------------------------|-------------|------"));
@@ -1980,9 +1979,8 @@
 	for (ll = queries; ll <= &queries[QUERY_EXTERNAL]; ll++) {
 		if (ll == &queries[QUERY_EXTERNAL] && *ll)
 			printq("generic", ("------EXTERNAL-QUERIES-----------|-------------|-----"));
-		for (l = *ll; l; l = l->next) {
+		for (q = *ll; q; q = q->next) {
 			char buf[256];
-			query_t *q = l->data;
 			const char *plugin = (q->plugin) ? q->plugin->name : ("-");
 
 			snprintf(buf, sizeof(buf), "%-32s | %-11s | %d", __(query_name(q->id)), plugin, q->count);
@@ -4014,13 +4012,10 @@
 	plugin_t *pl;
 
 	if (!params[0]) {
-		list_t l;
+		plugin_t *p;
 
-		for (l = plugins; l; l = l->next) {
-			plugin_t *p = l->data;
-
+		for (p = plugins; p; p = p->next)
 			printq("plugin_list", p->name ? p->name : ("?"), itoa(p->prio));
-		}
 
 		if (!plugins) {
 			/* XXX, display info: no plugins. */
@@ -4030,15 +4025,15 @@
 	}
 
         if (match_arg(params[0], 'd', ("default"), 2)) {
-                list_t l;
+                plugin_t *p;
 
-                for (l = plugins; l;) {
-                        plugin_t *p = l->data;
+                for (p = plugins; p;) {
+			plugin_t *next;
 
-                        l = l->next;
-
-                        list_remove(&plugins, p, 0);
+                        next = (plugin_t *) LIST_UNLINK2(&plugins, p);
                         plugin_register(p, -254);
+
+			p = next;
                 }
 
 		queries_reconnect();
@@ -4069,7 +4064,7 @@
 	}
 
 	if (params[1] && (pl = plugin_find(params[0]))) {
-		list_remove(&plugins, pl, 0);
+		LIST_UNLINK2(&plugins, pl);
 		plugin_register(pl, atoi(params[1])); 
 
 		queries_reconnect();

Modified: trunk/ekg/configfile.c
===================================================================
--- trunk/ekg/configfile.c	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/ekg/configfile.c	2008-03-09 11:05:08 UTC (rev 3873)
@@ -171,7 +171,6 @@
 {
 	char *buf, *foo;
 	FILE *f;
-	list_t l;
 	int i = 0, good_file = 0, first = (filename) ? 0 : 1, ret = 1;
 	struct stat st;
 
@@ -312,8 +311,9 @@
 	fclose(f);
 
 	if (first) {
-		for (l = plugins; l; l = l->next) {
-			plugin_t *p = l->data;
+		plugin_t *p;
+
+		for (p = plugins; p; p = p->next) {
 			const char *tmp;
 			
 			if ((tmp = prepare_pathf("config-%s", p->name)))
@@ -362,14 +362,13 @@
  */
 static void config_write_plugins(FILE *f)
 {
-	list_t l;
+	plugin_t *p;
 
 	if (!f)
 		return;
 
-        for (l = plugins; l; l = l->next) {
-                plugin_t *p = l->data;
-                if (p && p->name) fprintf(f, "plugin %s %d\n", p->name, p->prio);
+        for (p = plugins; p; p = p->next) {
+                if (p->name) fprintf(f, "plugin %s %d\n", p->name, p->prio);
         }
 }
 
@@ -479,7 +478,7 @@
 int config_write()
 {
 	FILE *f;
-	list_t l;
+	plugin_t *p;
 
 	if (!prepare_path(NULL, 1))	/* try to create ~/.ekg2 dir */
 		return -1;
@@ -505,8 +504,7 @@
         fclose(f);
 
 	/* now plugins variables */
-	for (l = plugins; l; l = l->next) {
-		plugin_t *p = l->data;
+	for (p = plugins; p; p = p->next) {
 		const char *tmp;
 		variable_t *v;
 
@@ -661,7 +659,7 @@
 {
 	char name[32];
 	FILE *f;
-	list_t l;
+	plugin_t *p;
 
 	chdir(config_dir);
 
@@ -691,8 +689,7 @@
 	fclose(f);
 
         /* now plugins variables */
-        for (l = plugins; l; l = l->next) {
-                plugin_t *p = l->data;
+        for (p = plugins; p; p = p->next) {
 		variable_t *v;
 
 		snprintf(name, sizeof(name), "config-%s.%d", p->name, (int) getpid());

Modified: trunk/ekg/dynstuff.c
===================================================================
--- trunk/ekg/dynstuff.c	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/ekg/dynstuff.c	2008-03-09 11:05:08 UTC (rev 3873)
@@ -287,34 +287,60 @@
 	return 0;
 }
 
-int list_remove3(list_t *list, void *data, void (*func)(void *data)) {
+list_t list_remove3(list_t *list, list_t elem, void (*func)(void *data)) {
 	list_t tmp, last = NULL;
+	void *ret = NULL;
 
 	if (!list) {
 		errno = EFAULT;
-		return -1;
+		return ret;
 	}
 
 	tmp = *list;
-	if (tmp && tmp == data) {
-		*list = tmp->next;
+	if (tmp && tmp == elem) {
+		*list = ret = tmp->next;
 	} else {
-		for (; tmp && tmp != data; tmp = tmp->next)
+		for (; tmp && tmp != elem; tmp = tmp->next)
 			last = tmp;
 		if (!tmp) {
 			errno = ENOENT;
-			return -1;
+			return ret;
 		}
-		last->next = tmp->next;
+		last->next = ret = tmp->next;
 	}
 
 	if (func)
 		func(tmp);
 	xfree(tmp);
 
-	return 0;
+	return ret;
 }
 
+list_t list_unlink3(list_t *list, list_t elem) {
+	list_t tmp, last = NULL;
+	void *ret = NULL;
+
+	if (!list) {
+		errno = EFAULT;
+		return ret;
+	}
+
+	tmp = *list;
+	if (tmp && tmp == elem) {
+		*list = ret = tmp->next;
+	} else {
+		for (; tmp && tmp != elem; tmp = tmp->next)
+			last = tmp;
+		if (!tmp) {
+			errno = ENOENT;
+			return ret;
+		}
+		last->next = ret = tmp->next;
+	}
+
+	return ret;
+}
+
 /**
  * list_remove()
  *

Modified: trunk/ekg/dynstuff.h
===================================================================
--- trunk/ekg/dynstuff.h	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/ekg/dynstuff.h	2008-03-09 11:05:08 UTC (rev 3873)
@@ -84,6 +84,7 @@
 
 #define LIST_REMOVE(list, data, func)			list_remove2(list, data, (void *) func)
 #define LIST_REMOVE2(list, elem, func)			list_remove3((list_t *) list, (list_t) elem, (void *) func)
+#define LIST_UNLINK2(list, elem)			list_unlink3((list_t *) list, (list_t) elem)
 #define LIST_FREE_ITEM(x, type)				void x(type data)
 
 #define LIST_DESTROY(list, func)			list_destroy2(list, (void *) func)
@@ -106,7 +107,8 @@
 
 int list_remove(list_t *list, void *data, int free_data);
 int list_remove2(list_t *list, void *data, void (*func)(void *));
-int list_remove3(list_t *list, void *elem, void (*func)(void *));
+list_t list_remove3(list_t *list, list_t elem, void (*func)(void *));
+list_t list_unlink3(list_t *list, list_t elem);
 
 int list_destroy(list_t list, int free_data);
 int list_destroy2(list_t list, void (*func)(void *));

Modified: trunk/ekg/ekg.c
===================================================================
--- trunk/ekg/ekg.c	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/ekg/ekg.c	2008-03-09 11:05:08 UTC (rev 3873)
@@ -154,17 +154,21 @@
                         }
                 }
 
-		/* removed 'w->removed' watches, timeout checking moved below select() */
-                for (l = watches; l; l = l->next) {
-                        watch_t *w = l->data;
+		{
+			watch_t *w;
+				/* removed 'w->removed' watches, timeout checking moved below select() */
+			for (w = watches; w;) {
+				watch_t *next = w->next;
 
-			if (!w)
-				continue;
+				if (w->removed == 1) {
+					watch_t *tmp;
 
-			if (w->removed == 1) {
-				w->removed = 0;
-				watch_free(w);
-				continue;
+					w->removed = 0;
+					if ((tmp = watch_free(w))) /* if watch was really deleted, we shall jump */
+						next = tmp;
+				}
+
+				w = next;
 			}
 		}
 
@@ -262,21 +266,23 @@
                 FD_ZERO(&rd);
                 FD_ZERO(&wd);
 
-                for (maxfd = 0, l = watches; l; l = l->next) {
-                        watch_t *w = l->data;
+		{
+			watch_t *w;
 
-			if (!w)
-				continue;
+			for (maxfd = 0, w = watches; w; w = w->next) {
+				if (!w)
+					continue;
 
-                        if (w->fd > maxfd)
-                                maxfd = w->fd;
-                        if ((w->type & WATCH_READ))
-                                FD_SET(w->fd, &rd);
-                        if ((w->type & WATCH_WRITE)) {
-				if (w->buf && !w->buf->len) continue; /* if we have WATCH_WRITE_LINE and there's nothink to send, ignore this */ 
-				FD_SET(w->fd, &wd); 
+				if (w->fd > maxfd)
+					maxfd = w->fd;
+				if ((w->type & WATCH_READ))
+					FD_SET(w->fd, &rd);
+				if ((w->type & WATCH_WRITE)) {
+					if (w->buf && !w->buf->len) continue; /* if we have WATCH_WRITE_LINE and there's nothink to send, ignore this */ 
+					FD_SET(w->fd, &wd); 
+				}
 			}
-                }
+		}
 
 		stv.tv_sec = 1;
 		stv.tv_usec = 0;
@@ -328,15 +334,20 @@
                          * ekg mogło działać dalej, sprawdźmy który to i go
                          * usuńmy z listy. */
 			if (errno == EBADF) {
-				for (l = watches; l; l = l->next) {
-					watch_t *w = l->data;
+				watch_t *w;
+
+				for (w = watches; w;) {
 					struct stat st;
+					watch_t *next = w->next;
 
-					if (!w || !fstat(w->fd, &st))
-						continue;
+					if (w && fstat(w->fd, &st)) {
+						watch_t *tmp;
+						debug("select(): bad file descriptor: fd=%d, type=%d, plugin=%s\n", w->fd, w->type, (w->plugin) ? w->plugin->name : ("none"));
+						if ((tmp = watch_free(w)))
+							next = tmp;
+					}
 
-					debug("select(): bad file descriptor: fd=%d, type=%d, plugin=%s\n", w->fd, w->type, (w->plugin) ? w->plugin->name : ("none"));
-					watch_free(w);
+					w = next;
 				}
 			} else if (errno != EINTR)
 				debug("select() failed: %s\n", strerror(errno));
@@ -352,8 +363,8 @@
 			 *  yeah, i know it can be do better. note: it's just for gtk.. maybe later we have prios and so (and ekg2 become operation system with scheduler)
 			 */
 
-			idle_handle((idle_t *) idles->data);
-			list_remove(&idles, idles->data, 0);
+			idle_handle(idles);
+			LIST_REMOVE2(&idles, idles, 0);
 
 			/* Here I think we can do return; coz select() return 0 when nothing happen on given fds */
 			/* but to avoid regression on broken systems */
@@ -361,70 +372,72 @@
 			/* return; */
 		}
 
-		for (l = watches; l; l = l->next) {
-                }
-                /* przejrzyj deskryptory */
-		for (l = watches; l; l = l->next) {
-			watch_t *w = l->data;
+		{		/* przejrzyj deskryptory */
+			watch_t *w, *next;
 
-			if (!w)
-				continue;
+			for (w = watches; w; w = next) {
+				next = w->next;
 
-			if (!FD_ISSET(w->fd, &rd) && !FD_ISSET(w->fd, &wd)) { /* timeout checking */
-				if (w->timeout < 1 || (tv.tv_sec - w->started) < w->timeout)
-					continue;
-				w->removed = -1;
-				if (w->buf) {
-					int (*handler)(int, int, char*, void*) = w->handler;
-					if (handler(2, w->fd, NULL, w->data) == -1 || w->removed == 1) {
-						w->removed = 0;
-						watch_free(w);
+				if (!FD_ISSET(w->fd, &rd) && !FD_ISSET(w->fd, &wd)) { /* timeout checking */
+					watch_t *tmp;
+
+					if (w->timeout < 1 || (tv.tv_sec - w->started) < w->timeout)
 						continue;
+					w->removed = -1;
+					if (w->buf) {
+						int (*handler)(int, int, char*, void*) = w->handler;
+						if (handler(2, w->fd, NULL, w->data) == -1 || w->removed == 1) {
+							w->removed = 0;
+							if ((tmp = watch_free(w)))
+								next = tmp;
+							continue;
+						}
+					} else {
+						int (*handler)(int, int, int, void*) = w->handler;
+						if (handler(2, w->fd, w->type, w->data) == -1 || w->removed == 1) {
+							w->removed = 0;
+							if ((tmp = watch_free(w)))
+								next = tmp;
+							continue;
+						}
 					}
-				} else {
-					int (*handler)(int, int, int, void*) = w->handler;
-					if (handler(2, w->fd, w->type, w->data) == -1 || w->removed == 1) {
-						w->removed = 0;
-						watch_free(w);
-						continue;
-					}
+					w->removed = 0;
+
+					continue;
 				}
-				w->removed = 0;
 
-				continue;
-			}
+				if (w->fd == 0) {
+					list_t session_list;
+					for (
+						session_list = sessions;
+						session_list;
+						session_list = session_list->next) 
+					{
+						session_t *s = session_list->data;
 
-			if (w->fd == 0) {
-				list_t session_list;
-				for (
-					session_list = sessions;
-					session_list;
-					session_list = session_list->next) 
-				{
-					session_t *s = session_list->data;
+						if (!s->connected || !s->autoaway)
+							continue;
 
-					if (!s->connected || !s->autoaway)
-						continue;
+						if (session_int_get(s, "auto_back") != 2)
+							continue;
 
-					if (session_int_get(s, "auto_back") != 2)
-						continue;
-
-					command_exec(NULL, s, ("/_autoback"), 2);
+						command_exec(NULL, s, ("/_autoback"), 2);
+					}
 				}
+				if (!w->buf) {
+					if (((w->type == WATCH_WRITE) && FD_ISSET(w->fd, &wd)) ||
+							((w->type == WATCH_READ) && FD_ISSET(w->fd, &rd)))
+						watch_handle(w);
+				} else {
+					if (FD_ISSET(w->fd, &rd) && w->type == WATCH_READ) 		watch_handle_line(w);
+					else if (FD_ISSET(w->fd, &wd) && w->type == WATCH_WRITE)	watch_handle_write(w);
+				}
 			}
-			if (!w->buf) {
-				if (((w->type == WATCH_WRITE) && FD_ISSET(w->fd, &wd)) ||
-						((w->type == WATCH_READ) && FD_ISSET(w->fd, &rd)))
-					watch_handle(w);
-			} else {
-				if (FD_ISSET(w->fd, &rd) && w->type == WATCH_READ) 		watch_handle_line(w);
-				else if (FD_ISSET(w->fd, &wd) && w->type == WATCH_WRITE)	watch_handle_write(w);
-			}
 		}
 
 		if (ekg_watches_removed > 0) {
 			debug("ekg_loop() Removed %d watches this loop, let's cleanup calling: list_cleanup() ...\n", ekg_watches_removed);
-			list_cleanup(&watches);
+			//list_cleanup(&watches); /* not needed anymore, left for historical reasons ( ; */
 			ekg_watches_removed = 0;
 		}
 	}
@@ -453,7 +466,7 @@
 
 static void handle_sigsegv()
 {
-        list_t l;
+        plugin_t *p;
 
         signal(SIGSEGV, SIG_DFL);
 
@@ -462,9 +475,7 @@
 
         /* wyłącz pluginy ui, żeby oddały terminal
 	 * destroy also log plugins to make sure that latest changes are written */
-        for (l = plugins; l; l = l->next) {
-                plugin_t *p = l->data;
-
+        for (p = plugins; p; p = p->next) {
                 if (p->pclass != PLUGIN_UI && p->pclass != PLUGIN_LOG)
                         continue;
 
@@ -862,7 +873,7 @@
         tmp = NULL;
 
 	{
-		list_t *ll;
+		query_t **ll;
 
 		for (ll = queries; ll <= &queries[QUERY_EXTERNAL]; ll++)
 			*ll = NULL;
@@ -1083,25 +1094,36 @@
 	}
 	list_destroy(children, 1);	children = NULL;
 
-	for (l = watches; l; l = l->next) {
-		watch_t *w = l->data;
+	{
+		watch_t *w;
 
-		watch_free(w);
+		for (w = watches; w;) {
+			watch_t *tmp;
+
+			if ((tmp = watch_free(w)))
+				w = tmp;
+			else
+				w = w->next;
+		}
 	}
 
-	for (l = plugins; l; ) {
-		plugin_t *p = l->data;
+	{
+		plugin_t *p;
 
-		l = l->next;
+		for (p = plugins; p; ) {
+			plugin_t *next = p->next;
 
-		if (p->pclass != PLUGIN_UI)
-			continue;
+			if (p->pclass != PLUGIN_UI)
+				continue;
 
-		p->destroy();
+			p->destroy();
 
-//		if (p->dl) ekg2_dlclose(p->dl);
+//			if (p->dl) ekg2_dlclose(p->dl);
+			
+			p = next;
+		}
 	}
-	list_destroy(watches, 0);	 watches = NULL;
+	LIST_DESTROY2(watches, NULL);	 watches = NULL;
 
 	if (config_changed && !config_speech_app && config_save_quit == 1) {
 		char line[80];
@@ -1150,14 +1172,18 @@
 	metacontact_free();
 	sessions_free();
 
-	for (l = plugins; l; ) {
-		plugin_t *p = l->data;
+	{
+		plugin_t *p;
 
-		l = l->next;
+		for (p = plugins; p; ) {
+			plugin_t *next = p->next;
 
-		p->destroy();
+			p->destroy();
 
-//		if (p->dl) ekg2_dlclose(p->dl);
+//			if (p->dl) ekg2_dlclose(p->dl);
+
+			p = next;
+		}
 	}
 
 	audio_deinitialize();
@@ -1195,18 +1221,20 @@
 	list_destroy(windows, 1);	window_status = NULL; window_debug = NULL; window_current = NULL;	/* just in case */
 
 	{
-		list_t *ll;
+		query_t **ll;
 
 		for (ll = queries; ll <= &queries[QUERY_EXTERNAL]; ll++) {
-			for (l = *ll; l; ) {	/* free other queries... connected by protocol_init() for example */
-				query_t *q = l->data;
+			query_t *q;
 
-				l = l->next;
+			for (q = *ll; q; ) {	/* free other queries... connected by protocol_init() for example */
+				query_t *next = q->next;
 
 				query_free(q);
+
+				q = next;
 			}
 
-			list_destroy(*ll, 0);
+			LIST_DESTROY2(*ll, NULL); /* XXX: really needed? */
 		}
 	}
 	query_external_free();

Modified: trunk/ekg/log.c
===================================================================
--- trunk/ekg/log.c	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/ekg/log.c	2008-03-09 11:05:08 UTC (rev 3873)
@@ -111,12 +111,10 @@
 	struct last *ll;
 
 	for (ll = lasts; ll; ) {
-		struct last *next = ll->next;
-
 		if (!xstrcasecmp(uid, ll->uid))
-			LIST_REMOVE2(&lasts, ll, list_last_free);
-
-		ll = next;
+			ll = (struct last *) LIST_REMOVE2(&lasts, ll, list_last_free);
+		else
+			ll = ll->next;
 	}
 }
 

Modified: trunk/ekg/msgqueue.c
===================================================================
--- trunk/ekg/msgqueue.c	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/ekg/msgqueue.c	2008-03-09 11:05:08 UTC (rev 3873)
@@ -91,14 +91,11 @@
 	int res = -1;
 
 	for (m = msg_queue; m; ) {
-		msg_queue_t *next = m->next;
-
 		if (!xstrcasecmp(m->rcpts, uid)) {
-			LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
+			m = (msg_queue_t *) LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
 			res = 0;
-		}
-
-		m = next;
+		} else
+			m = m->next;
 	}
 
 	return res;
@@ -122,14 +119,11 @@
 		return -1;
 
 	for (m = msg_queue; m; ) {
-		msg_queue_t *next = m->next;
-
 		if (!xstrcasecmp(m->seq, seq)) {
-			LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
+			m = (msg_queue_t *) LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
 			res = 0;
-		}
-
-		m = next;
+		} else
+			m = m->next;
 	}
 
 	return res;
@@ -166,7 +160,6 @@
 
 	for (m = msg_queue; m;) {
 		session_t *s;
-		msg_queue_t *next = m->next;
 		char *cmd = "/msg \"%s\" %s";
 
 		/* czy wiadomość dodano w trakcie opróżniania kolejki? */
@@ -177,7 +170,7 @@
 			continue;
 				/* wiadomość wysyłana z nieistniejącej już sesji? usuwamy. */
 		else if (!(s = session_find(m->session))) {
-			LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
+			m = (msg_queue_t *) LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
 			continue;
 		}
 
@@ -192,10 +185,8 @@
 		}
 		command_exec_format(NULL, s, 1, cmd, m->rcpts, m->message);
 
-		LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
-
+		m = (msg_queue_t *) LIST_REMOVE2(&msg_queue, m, list_msg_queue_free);
 		ret = 0;
-		m = next;
 	}
 
 	return ret;

Modified: trunk/ekg/plugins.c
===================================================================
--- trunk/ekg/plugins.c	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/ekg/plugins.c	2008-03-09 11:05:08 UTC (rev 3873)
@@ -52,11 +52,11 @@
 #define va_copy(DST,SRC) __va_copy(DST,SRC)
 #endif
 
-list_t plugins = NULL;
-list_t watches = NULL;
-list_t idles   = NULL;
+plugin_t *plugins = NULL;
+watch_t *watches = NULL;
+idle_t *idles   = NULL;
 
-list_t queries[QUERY_EXTERNAL+1];
+query_t *queries[QUERY_EXTERNAL+1];
 
 #ifdef EKG2_WIN32_HELPERS
 # define WIN32_REQUEST_HELPER
@@ -342,12 +342,10 @@
 
 plugin_t *plugin_find(const char *name)
 {
-	list_t l;
+	plugin_t *p;
 
-	for (l = plugins; l; l = l->next) {
-		plugin_t *p = l->data;
-
-		if (p && !xstrcmp(p->name, name))
+	for (p = plugins; p; p = p->next) {
+		if (!xstrcmp(p->name, name))
 			return p;
 	}
 
@@ -367,11 +365,9 @@
  */
 
 plugin_t *plugin_find_uid(const char *uid) {
-        list_t l;
+        plugin_t *p;
 
-        for (l = plugins; l; l = l->next) {
-		plugin_t *p = l->data;
-
+        for (p = plugins; p; p = p->next) {
                 if (p && p->pclass == PLUGIN_PROTOCOL && p->name && valid_plugin_uid(p, uid))
                 	return p;
         }
@@ -390,17 +386,16 @@
 int plugin_unload(plugin_t *p)
 {
 	char *name; 
-	list_t l;
 
 	if (!p)
 		return -1;
 
 
 	if (config_expert_mode == 0 && p->pclass == PLUGIN_UI) {
-		list_t l;
+		plugin_t *plug;
+
 		int unloadable = 0;
-		for (l=plugins; l; l = l->next) {
-			plugin_t *plug = l->data;
+		for (plug = plugins; plug; plug = plug->next) {
 			if (plug->pclass == PLUGIN_UI && plug != p) 
 				unloadable = 1;
 		}
@@ -410,11 +405,14 @@
 		}
 	}
 
-	for (l = watches; l; l = l->next) {
-		watch_t *w = l->data;
-		if (w && w->plugin == p && (w->removed == 1 || w->removed == -1)) {
-			print("generic_error", "XXX cannot remove this plugin when there some watches active");
-			return -1;
+	{
+		watch_t *w;
+
+		for (w = watches; w; w = w->next) {
+			if (w && w->plugin == p && (w->removed == 1 || w->removed == -1)) {
+				print("generic_error", "XXX cannot remove this plugin when there some watches active");
+				return -1;
+			}
 		}
 	}
 	/* XXX, to samo dla timerow */
@@ -486,7 +484,7 @@
 		p->prio = prio;
 	}
 
-	LIST_ADD_SORTED(&plugins, p, plugin_register_compare);
+	LIST_ADD_SORTED2(&plugins, p, plugin_register_compare);
 
 	return 0;
 }
@@ -518,11 +516,17 @@
 
 /* XXX think about sequence of unloading....: currently: watches, timers, sessions, queries, variables, commands */
 
-	for (l = watches; l; l = l->next) {
-		watch_t *w = l->data;
+	{
+		watch_t *w;
 
-		if (w && w->plugin == p)
-			watch_free(w);
+		for (w = watches; w;) {
+			watch_t *next = w->next;
+
+			if (w && w->plugin == p)
+				watch_free(w);
+
+			w = next;
+		}
 	}
 
 	for (l = timers; l; ) {
@@ -534,13 +538,15 @@
 			timer_free(t);
 	}
 
-	for (l = idles; l; ) {
-		idle_t *i = l->data;
-
-		l = l->next;
-
-		if (i->plugin == p)
-			list_remove(&idles, i, 1);
+	{
+		idle_t *i;
+		
+		for (i = idles; i; ) {
+			if (i->plugin == p)
+				i = (idle_t *) LIST_REMOVE2(&idles, i, NULL);
+			else
+				i = i->next;
+		}
 	}
 
 	for (l = sessions; l; ) {
@@ -553,16 +559,18 @@
 	}
 
 	{
-		list_t *ll;
+		query_t **ll;
 
 		for (ll = queries; ll <= &queries[QUERY_EXTERNAL]; ll++) {
-			for (l = *ll; l; ) {
-				query_t *q = l->data;
+			query_t *q;
 
-				l = l->next;
+			for (q = *ll; q; ) {
+				query_t *next = q->next;
 
 				if (q->plugin == p)
 					query_free(q);
+
+				q = next;
 			}
 		}
 	}
@@ -593,7 +601,7 @@
 		}
 	}
 
-	list_remove(&plugins, p, 0);
+	LIST_REMOVE2(&plugins, p, NULL);
 
 	return 0;
 }
@@ -624,6 +632,10 @@
 
 int plugin_var_add(plugin_t *pl, const char *name, int type, const char *value, int secret, plugin_notify_func_t *notify) { return -1; }
 
+static LIST_FREE_ITEM(query_external_free_data, struct query_def *) {
+	xfree(data->name);
+}
+
 /**
  * query_external_free()
  *
@@ -634,18 +646,11 @@
  */
 
 void query_external_free() {
-	list_t l;
-
 	if (!queries_external)
 		return;
 
-	for (l = queries_external; l; l = l->next) {
-		struct query *a = l->data;
+	LIST_DESTROY(queries_external, query_external_free_data);
 
-		xfree(a->name);
-	}
-	list_destroy(queries_external, 1);
-
 	queries_external 	= NULL;
 	queries_count		= QUERY_EXTERNAL;
 }
@@ -664,7 +669,7 @@
  */
 
 static int query_id(const char *name) {
-	struct query *a = NULL;
+	struct query_def *a = NULL;
 	list_t l;
 	int i;
 
@@ -685,11 +690,11 @@
 	}
 	debug_error("query_id() NOT FOUND[%d]: %s\n", queries_count - QUERY_EXTERNAL, __(name));
 
-	a 	= xmalloc(sizeof(struct query));
+	a 	= xmalloc(sizeof(struct query_def));
 	a->id 	= queries_count++;
 	a->name	= xstrdup(name);
 
-	list_add(&queries_external, a);
+	LIST_ADD2(&queries_external, a);
 
 	return a->id;
 }
@@ -701,14 +706,14 @@
  *
  */
 
-const struct query *query_struct(const int id) {
+const struct query_def *query_struct(const int id) {
 	list_t l;
 
 	if (id < QUERY_EXTERNAL) 
 		return &(query_list[id]);
 
 	for (l = queries_external; l; l = l->next) {
-		struct query* a = l->data;
+		struct query_def *a = l->data;
 
 		if (a->id == id) 
 			return a;
@@ -737,7 +742,7 @@
 		return query_list[id].name;
 
 	for (l = queries_external; l; l = l->next) {
-		struct query* a = l->data;
+		struct query_def *a = l->data;
 
 		if (a->id == id) 
 			return a->name;
@@ -756,7 +761,7 @@
 	q->handler	= handler;
 	q->data		= data;
 
-	return list_add(&queries[id >= QUERY_EXTERNAL ? QUERY_EXTERNAL : id], q);
+	return LIST_ADD2(&queries[id >= QUERY_EXTERNAL ? QUERY_EXTERNAL : id], q);
 }
 
 #define ID_AND_QUERY_EXTERNAL	\
@@ -782,7 +787,7 @@
 int query_free(query_t *q) {
 	if (!q) return -1;
 
-	list_remove(&queries[q->id >= QUERY_EXTERNAL ? QUERY_EXTERNAL : q->id], q, 1);
+	LIST_REMOVE2(&queries[q->id >= QUERY_EXTERNAL ? QUERY_EXTERNAL : q->id], q, NULL);
 	return 0;
 }
 
@@ -820,7 +825,7 @@
 int query_emit_id(plugin_t *plugin, const int id, ...) {
 	int result = -2;
 	va_list ap;
-	list_t l;
+	query_t *q;
 
 	if (id >= QUERY_EXTERNAL) {
 		debug_error("%s", ID_AND_QUERY_EXTERNAL);
@@ -828,9 +833,7 @@
 	}
 		
 	va_start(ap, id);
-	for (l = queries[id]; l; l = l->next) {
-		query_t *q = l->data;
-
+	for (q = queries[id]; q; q = q->next) {
 		if ((!plugin || (plugin == q->plugin))) {
 			result = query_emit_common(q, ap);
 
@@ -844,15 +847,13 @@
 int query_emit(plugin_t *plugin, const char *name, ...) {
 	int result = -2;
 	va_list ap;
-	list_t l;
+	query_t *q;
 	int id;
 
 	id = query_id(name);
 
 	va_start(ap, name);
-	for (l = queries[id >= QUERY_EXTERNAL ? QUERY_EXTERNAL : id]; l; l = l->next) {
-		query_t *q = l->data;
-
+	for (q = queries[id >= QUERY_EXTERNAL ? QUERY_EXTERNAL : id]; q; q = q->next) {
 		if ((!plugin || (plugin == q->plugin)) && q->id == id) {
 			result = query_emit_common(q, ap);
 
@@ -881,7 +882,7 @@
 	int i;
 
 	for (i = 0; i <= QUERY_EXTERNAL; i++)
-		LIST_RESORT(&(queries[i]), query_compare);
+		LIST_RESORT2(&(queries[i]), query_compare);
 }
 
 /*
@@ -891,10 +892,9 @@
  */
 watch_t *watch_find(plugin_t *plugin, int fd, watch_type_t type)
 {
-	list_t l;
+	watch_t *w;
 	
-	for (l = watches; l; l = l->next) {
-		watch_t *w = l->data;
+	for (w = watches; w; w = w->next) {
 			/* XXX: added simple plugin ignoring, make something nicer? */
 		if (w && ((plugin == (void*) -1) || w->plugin == plugin) && w->fd == fd && (w->type & type) && !(w->removed > 0))
 			return w;
@@ -903,44 +903,53 @@
 	return NULL;
 }
 
+static LIST_FREE_ITEM(watch_free_data, watch_t *) {
+	data->removed = 2;	/* to avoid situation: when handler of watch, execute watch_free() on this watch... stupid */
+
+	if (data->buf) {
+		int (*handler)(int, int, const char *, void *) = data->handler;
+		string_free(data->buf, 1);
+		/* DO WE WANT TO SEND ALL  IN BUFOR TO FD ? IF IT'S WATCH_WRITE_LINE? or parse all data if it's WATCH_READ_LINE? mmh. XXX */
+		if (handler)
+			handler(1, data->fd, NULL, data->data);
+	} else {
+		int (*handler)(int, int, int, void *) = data->handler;
+		if (handler)
+			handler(1, data->fd, data->type, data->data);
+	}
+}
+
 /*
  * watch_free()
  *
  * zwalnia pamięć po obiekcie watch_t.
+ * zwraca wskaźnik do następnego obiektu do iterowania
+ * albo NULL, jak nie można skasować.
  */
-void watch_free(watch_t *w) {
+watch_t *watch_free(watch_t *w) {
+	void *next;
+
 	if (!w)
-		return;
+		return NULL;
 
 	if (w->removed == 2)
-		return;
+		return NULL;
 
 	if (w->removed == -1 || w->removed == 1) { /* watch is running.. we cannot remove it */
 		w->removed = 1;
-		return;
+		return NULL;
 	}
 
 	if (w->type == WATCH_WRITE && w->buf && !w->handler) { 
 		debug_error("[INTERNAL_DEBUG] WATCH_LINE_WRITE must be removed by plugin, manually (settype to WATCH_NONE and than call watch_free()\n");
-		return;
+		return NULL;
 	}
 
-	w->removed = 2;	/* to avoid situation: when handler of watch, execute watch_free() on this watch... stupid */
-
-	if (w->buf) {
-		int (*handler)(int, int, const char *, void *) = w->handler;
-		string_free(w->buf, 1);
-		/* DO WE WANT TO SEND ALL  IN BUFOR TO FD ? IF IT'S WATCH_WRITE_LINE? or parse all data if it's WATCH_READ_LINE? mmh. XXX */
-		if (handler)
-			handler(1, w->fd, NULL, w->data);
-	} else {
-		int (*handler)(int, int, int, void *) = w->handler;
-		if (handler)
-			handler(1, w->fd, w->type, w->data);
-	}
-	list_remove_safe(&watches, w, 1);
+	next = LIST_REMOVE2(&watches, w, watch_free_data);
 	ekg_watches_removed++;
 	debug("watch_free() REMOVED WATCH, watches removed this loop: %d oldwatch: 0x%x\n", ekg_watches_removed, w);
+
+	return next;
 }
 
 /*
@@ -1175,7 +1184,7 @@
 	w->handler = handler;
 	w->data    = data;
 
-	list_add_beginning(&watches, w);
+	LIST_ADD_BEGINNING2(&watches, w);
 
 	return w;
 }
@@ -1228,7 +1237,7 @@
 			
 	} else {
 		/* add idler again [at end] */
-		list_add(&idles, i);
+		LIST_ADD2(&idles, i);
 	}
 }
 
@@ -1239,7 +1248,7 @@
 	i->data		= data;
 
 	/* XXX, prios? */
-	list_add_beginning(&idles, i);		/* first item */
+	LIST_ADD_BEGINNING2(&idles, i);		/* first item */
 
 	return i;
 }
@@ -1256,11 +1265,12 @@
  */
 
 int have_plugin_of_class(plugin_class_t pclass) {
-	list_t l;
-	for(l = plugins; l; l = l->next) {
-		plugin_t *p = l->data;
+	plugin_t *p;
+
+	for (p = plugins; p; p = p->next) {
 		if (p->pclass == pclass) return 1;
 	}
+
 	return 0;
 }
 

Modified: trunk/ekg/plugins.h
===================================================================
--- trunk/ekg/plugins.h	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/ekg/plugins.h	2008-03-09 11:05:08 UTC (rev 3873)
@@ -26,17 +26,10 @@
 #include "dynstuff.h"
 #include "sessions.h"
 
-#define EKG_ABI_VER 3870
+#define EKG_ABI_VER 3873
 
 #define EXPORT __attribute__ ((visibility("default")))
 
-#ifndef EKG2_WIN32_NOFUNCTION
-extern list_t plugins;
-extern list_t watches;
-extern list_t idles;
-extern list_t queries[];
-#endif
-
 typedef enum {
 	PLUGIN_ANY = 0,
 	PLUGIN_GENERIC,
@@ -66,7 +59,9 @@
 	plugin_notify_func_t *notify;	/* notify */
 } plugins_params_t;
 
-typedef struct {
+typedef struct plugin {
+	struct plugin *next;
+
 	char *name;
 	int prio;
 	plugin_class_t pclass;
@@ -117,7 +112,9 @@
 #define QUERY(x) int x(void *data, va_list ap)
 typedef QUERY(query_handler_func_t);
 
-typedef struct {
+typedef struct queryx {
+	struct queryx *next;
+
 	int id;
 	plugin_t *plugin;
 	void *data;
@@ -137,7 +134,7 @@
 void queries_reconnect();
 
 const char *query_name(const int id);
-const struct query *query_struct(const int id);
+const struct query_def *query_struct(const int id);
 
 #endif
 
@@ -158,7 +155,9 @@
 /* typedef WATCHER_LINE(watcher_handler_line_func_t); */
 typedef WATCHER_SESSION(watcher_session_handler_func_t);
 
-typedef struct {
+typedef struct watch {
+	struct watch *next;
+
 	int fd;			/* obserwowany deskryptor */
 	watch_type_t type;	/* co sprawdzamy */
 	plugin_t *plugin;	/* wtyczka obsługująca deskryptor */
@@ -189,7 +188,7 @@
 #endif
 
 watch_t *watch_find(plugin_t *plugin, int fd, watch_type_t type);
-void watch_free(watch_t *w);
+watch_t *watch_free(watch_t *w);
 
 typedef void *watch_handler_func_t;
 
@@ -210,7 +209,9 @@
 
 typedef IDLER(idle_handler_func_t);
 
-typedef struct {
+typedef struct idle {
+	struct idle *next;
+
 	plugin_t *plugin;
 	idle_handler_func_t *handler;
 	void *data;
@@ -225,6 +226,13 @@
 
 #endif
 
+#ifndef EKG2_WIN32_NOFUNCTION
+extern plugin_t *plugins;
+extern watch_t *watches;
+extern idle_t *idles;
+extern query_t *queries[];
+#endif
+
 #endif /* __EKG_PLUGINS_H */
 
 /*

Modified: trunk/ekg/queries.h
===================================================================
--- trunk/ekg/queries.h	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/ekg/queries.h	2008-03-09 11:05:08 UTC (rev 3873)
@@ -17,7 +17,7 @@
 	QUERY_ARG_SESSION	/* session_t	*/
 };
 
-struct query {
+struct query_def {
 	int id;
 	char *name;
 	enum query_arg_type params[QUERY_ARGS_MAX];	/* scripts will use it */
@@ -75,7 +75,7 @@
 
 /* list of known queries. keep it sorted with enum. */
 
-const struct query query_list[] = {
+const struct query_def query_list[] = {
 	{ MAIL_COUNT, "mail-count", {
 		QUERY_ARG_INT,			/* mail count */
 		QUERY_ARG_END } },
@@ -467,7 +467,7 @@
 static int queries_count = QUERY_EXTERNAL;	/* list_count(queries_other)+QUERY_EXTERNAL */
 #else
 
-extern struct query query_list[];		/* for: events.h scripts.h */
+extern struct query_def query_list[];		/* for: events.h scripts.h */
 
 #endif
 

Modified: trunk/ekg/scripts.c
===================================================================
--- trunk/ekg/scripts.c	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/ekg/scripts.c	2008-03-09 11:05:08 UTC (rev 3873)
@@ -660,7 +660,7 @@
 		int i;
 		for (i = 0; i < QUERY_EXTERNAL; i++) {
 			if (!xstrcmp(qname, (query_name(i)))) {
-				const struct query *q = query_struct(i);
+				const struct query_def *q = query_struct(i);
 				int j = 0;
 
 				while (j < QUERY_ARGS_MAX && q->params[j] != QUERY_ARG_END) {

Modified: trunk/ekg/sessions.c
===================================================================
--- trunk/ekg/sessions.c	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/ekg/sessions.c	2008-03-09 11:05:08 UTC (rev 3873)
@@ -286,12 +286,21 @@
 	}
 #endif
 
-	/* remove session watches */
-	for (l = watches; l; l = l->next) {
-		watch_t *w = l->data;
+	{		/* remove session watches */
+		watch_t *w;
 
-		if (w && w->is_session && w->data == s)
-			watch_free(w);
+		for (w = watches; w;) {
+			watch_t *next = w->next;
+
+			if (w && w->is_session && w->data == s) {
+				watch_t *tmp;
+				
+				if ((tmp = watch_free(w)))
+					next = tmp;
+			}
+
+			w = next;
+		}
 	}
 
 	for (l = timers; l;) {
@@ -735,10 +744,11 @@
 	char *line;
 	FILE *f;
 	session_t *s = NULL;
-	list_t l;
 	int ret = 0;
 
 	if (!filename) {
+		plugin_t *p;
+
 		if (!in_autoexec) {
 			list_t l;
 
@@ -751,8 +761,7 @@
 			debug("	 flushed sessions\n");
 		}
 
-		for (l = plugins; l; l = l->next) {
-			plugin_t *p = l->data;
+		for (p = plugins; p; p = p->next) {
 			const char *tmp;
 
 			if (!p || p->pclass != PLUGIN_PROTOCOL)
@@ -812,15 +821,15 @@
  */
 int session_write()
 {
-	list_t l, ls;
+	plugin_t *p;
 	FILE *f = NULL;
 	int ret = 0;
 
 	if (!prepare_path(NULL, 1))	/* try to create ~/.ekg2 */
 		return -1;
 
-	for (l = plugins; l; l = l->next) {
-		plugin_t *p = l->data;
+	for (p = plugins; p; p = p->next) {
+		list_t ls;
 		const char *tmp;
 
 		if (p->pclass != PLUGIN_PROTOCOL) continue; /* skip no protocol plugins */
@@ -1455,12 +1464,17 @@
         if (!sessions)
                 return;
 
-	/* remove _ALL_ session watches */
-	for (l = watches; l; l = l->next) {
-		watch_t *w = l->data;
+	{		/* remove _ALL_ session watches */
+		watch_t *w;
 
-		if (w && w->is_session)
-			watch_free(w);
+		for (w = watches; w;) {
+			watch_t *tmp;
+
+			if (w->is_session && ((tmp = watch_free(w))))
+				w = tmp;
+			else
+				w = w->next;
+		}
 	}
 
 	for (l = timers; l;) {

Modified: trunk/ekg/themes.c
===================================================================
--- trunk/ekg/themes.c	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/ekg/themes.c	2008-03-09 11:05:08 UTC (rev 3873)
@@ -1105,11 +1105,9 @@
 }
 
 void theme_plugins_init() {
-        list_t l;
+	plugin_t *p;
 
-        for (l = plugins; l; l = l->next) {
-                plugin_t *p = l->data;
-
+        for (p = plugins; p; p = p->next) {
                 if (!p || !p->theme_init)
                         continue;
 

Modified: trunk/plugins/gg/commands.c
===================================================================
--- trunk/plugins/gg/commands.c	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/plugins/gg/commands.c	2008-03-09 11:05:08 UTC (rev 3873)
@@ -1449,9 +1449,9 @@
 	/* if we free token... we must search for it in all watches, and point data to NULL */
 	/* XXX, hack... let's copy token data to all watch ? */
 
-	list_t l;
-	for (l = watches; l; l = l->next) {
-		watch_t *w = l->data;
+	watch_t *w;
+
+	for (w = watches; w; w = w->next) {
 		if (w && w->data == h) {
 			w->data = NULL;
 			/* maybe we call remove here ? */

Modified: trunk/plugins/gtk/completion.c
===================================================================
--- trunk/plugins/gtk/completion.c	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/plugins/gtk/completion.c	2008-03-09 11:05:08 UTC (rev 3873)
@@ -220,11 +220,9 @@
 
 static void plugin_generator(const char *text, int len)
 {
-        list_t l;
+        plugin_t *p;
 
-        for (l = plugins; l; l = l->next) {
-                plugin_t *p = l->data;
-
+        for (p = plugins; p; p = p->next) {
                 if (!xstrncasecmp(text, p->name, len)) {
                         array_add_check(&completions, xstrdup(p->name), 1);
 		}

Modified: trunk/plugins/jabber/commands.c
===================================================================
--- trunk/plugins/jabber/commands.c	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/plugins/jabber/commands.c	2008-03-09 11:05:08 UTC (rev 3873)
@@ -1519,8 +1519,9 @@
 
 /* Synchronize config (?) */
 		if (config) {
-			for (l = plugins; l; l = l->next) {
-				plugin_t *p = l->data;
+			plugin_t *p;
+
+			for (p = plugins; p; p = p->next) {
 				variable_t *v;
 				watch_write(j->send_watch, "<plugin xmlns=\"ekg2:plugin\" name=\"%s\" prio=\"%d\">", p->name, p->prio);
 back:

Modified: trunk/plugins/ncurses/completion.c
===================================================================
--- trunk/plugins/ncurses/completion.c	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/plugins/ncurses/completion.c	2008-03-09 11:05:08 UTC (rev 3873)
@@ -220,11 +220,9 @@
 
 static void plugin_generator(const char *text, int len)
 {
-        list_t l;
+        plugin_t *p;
 
-        for (l = plugins; l; l = l->next) {
-                plugin_t *p = l->data;
-
+        for (p = plugins; p; p = p->next) {
                 if (!xstrncasecmp(text, p->name, len)) {
                         array_add_check(&completions, xstrdup(p->name), 1);
 		}

Modified: trunk/plugins/polchat/polchat.c
===================================================================
--- trunk/plugins/polchat/polchat.c	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/plugins/polchat/polchat.c	2008-03-09 11:05:08 UTC (rev 3873)
@@ -116,13 +116,11 @@
 
 	if (len == fulllen) {	/* we sent all data, ok.. */
 		watch_t *next_watch = NULL;
-		list_t l;
+		watch_t *w;
 
 		/* turn on next watch */
 
-		for (l = watches; l; l = l->next) {	/* watche sa od najnowszego po najstarszy.. dlatego musimy znalezc ostatni... */
-			watch_t *w = l->data;
-
+		for (w = watches; w; w = w->next) {	/* watche sa od najnowszego po najstarszy.. dlatego musimy znalezc ostatni... */
 			if (w && w->fd == fd && w->type == WATCH_NONE) 
 				next_watch = w;
 		}
@@ -133,11 +131,9 @@
 		errno = 0;
 
 	} else if (len > 0) {
-		list_t l;
+		watch_t *w;
 
-		for (l = watches; l; l = l->next) {
-			watch_t *w = l->data;
-
+		for (w = watches; w; w = w->next) {
 			if (w && w->fd == fd && w->type == WATCH_WRITE_LINE && w->data == data) { /* this watch */
 				w->data = (void *) fulllen - len;
 				break;
@@ -314,15 +310,17 @@
 	}
 
 	if (j->fd != -1) {
-		list_t l;
+		watch_t *w;
 
-		for (l = watches; l; l = l->next) {
-			watch_t *w = l->data;
+		for (w = watches; w;) {
+			watch_t *tmp;
 
-			if (!w || w->fd != j->fd) continue;
-
-			if (1 /* || w->type == WATCH_NONE || w->type == WATCH_WRITE_LINE */)
-				watch_free(w);
+			if (w && w->fd == j->fd &&
+					(1 /* || w->type == WATCH_NONE || w->type == WATCH_WRITE_LINE */)
+					&& ((tmp = watch_free(w))))
+				w = tmp;
+			else
+				w = w->next;
 		}
 
 		close(j->fd);

Modified: trunk/plugins/python/python-ekg.c
===================================================================
--- trunk/plugins/python/python-ekg.c	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/plugins/python/python-ekg.c	2008-03-09 11:05:08 UTC (rev 3873)
@@ -410,18 +410,17 @@
 PyObject *ekg_cmd_plugins(PyObject * self, PyObject * pyargs)
 {
         PyObject *list;
-        list_t l;
+        plugin_t *p;
         int len = 0;
 
-        for (l = plugins; l; l = l->next) {
+        for (p = plugins; p; p = p->next) {
                 len++;
         }
 
         list = PyList_New(len);
         len = 0;
 
-        for (l = plugins; l; l = l->next) {
-                plugin_t *p = l->data;
+        for (p = plugins; p; p = p->next) {
                 PyList_SetItem(list, len, PyString_FromString(p->name));
                 len++;
         }

Modified: trunk/plugins/rc/main.c
===================================================================
--- trunk/plugins/rc/main.c	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/plugins/rc/main.c	2008-03-09 11:05:08 UTC (rev 3873)
@@ -123,11 +123,9 @@
 }
 
 static watch_t *rc_watch_find(int fd) {
-	list_t l;
+	watch_t *w;
 	
-	for (l = watches; l; l = l->next) {
-		watch_t *w = l->data;
-
+	for (w = watches; w; w = w->next) {
 		if (w && w->plugin == &rc_plugin && w->fd == fd)
 			return w;
 	}

Modified: trunk/plugins/readline/readline-completion.c
===================================================================
--- trunk/plugins/readline/readline-completion.c	2008-03-09 00:31:52 UTC (rev 3872)
+++ trunk/plugins/readline/readline-completion.c	2008-03-09 11:05:08 UTC (rev 3873)
@@ -36,23 +36,21 @@
 
 GENERATOR(plugin) {
 	static int len;
-	static list_t el;
+	static plugin_t *p;
 
 	if (!state) {
 		len = xstrlen(text);
-		el = plugins;
+		p = plugins;
 	}
 
-	while (el) {
-		plugin_t *p = el->data;
-
-		el = el->next;
-
+	while (p) {
 		if (!xstrncasecmp(text, p->name, len)) 
 			return xstrdup(p->name);
 
 		if ((text[0] == '+' || text[0] == '-') && !xstrncasecmp(text + 1, p->name, len - 1))
 			return saprintf("%c%s", text[0], p->name);
+
+		p = p->next;
 	}
 	return NULL;
 }



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