[ekg2-commit] ekg2: dynstuff.c (HEAD) dynstuff.h (HEAD) plugins.c (HEAD) [darkjames]

CVS commit cvs w toxygen.net
Nie, 20 Sty 2008, 23:06:46 CET


Module name:	ekg2
Changes by:	darkjames	2008-01-20 23:06:44

Modified files:
	dynstuff.c dynstuff.h plugins.c

Log message:
introduce list_resort()
- move query_compare() outside queries_reconnect() function.
- use LIST_RESORT() in queries_reconnect()
i think it's okej.

Index: dynstuff.c
===================================================================
RCS file: /home/cvs/ekg2/ekg/dynstuff.c,v
diff -d -u -r1.47 -r1.48
--- dynstuff.c	11 Jan 2008 12:55:21 -0000	1.47
+++ dynstuff.c	20 Jan 2008 22:06:44 -0000	1.48
@@ -280,6 +280,23 @@
 	return NULL;
 }
 
+void list_resort(list_t *list, int (*comparision)(void *, void *)) {
+	list_t tmplist = NULL;
+	list_t l = *list;
+
+	while (l) {
+		list_t cur = l;
+
+		l = l->next;
+
+		list_add_sorted(&tmplist, cur->data, 0, comparision);
+
+		xfree(cur);
+	}
+
+	*list = tmplist;
+}
+
 /**
  * list_count()
  *

Index: dynstuff.h
===================================================================
RCS file: /home/cvs/ekg2/ekg/dynstuff.h,v
diff -d -u -r1.30 -r1.31
--- dynstuff.h	11 Jan 2008 12:55:21 -0000	1.30
+++ dynstuff.h	20 Jan 2008 22:06:44 -0000	1.31
@@ -54,6 +54,8 @@
 #define LIST_ADD_COMPARE(x, type)			int x(const type data1, const type data2)
 #define LIST_ADD_SORTED(list, data, alloc_size, comp)	list_add_sorted(list, data, alloc_size, (void *) comp)
 
+#define LIST_RESORT(list, comp)				list_resort(list, (void *) comp)
+
 #define LIST_REMOVE(list, data, func)			list_remove2(list, data, (void *) func)
 #define LIST_FREE_ITEM(x, type)				void x(type data)
 
@@ -65,6 +67,7 @@
 
 int list_count(list_t list);
 void *list_get_nth(list_t list, int id);
+void list_resort(list_t *list, int (*comparision)(void *, void *));
 
 int list_remove(list_t *list, void *data, int free_data);
 int list_remove2(list_t *list, void *data, void (*func)(void *));

Index: plugins.c
===================================================================
RCS file: /home/cvs/ekg2/ekg/plugins.c,v
diff -d -u -r1.117 -r1.118
--- plugins.c	20 Jan 2008 21:44:26 -0000	1.117
+++ plugins.c	20 Jan 2008 22:06:44 -0000	1.118
@@ -900,6 +900,14 @@
 	return result;
 }
 
+static LIST_ADD_COMPARE(query_compare, query_t *) {
+	/*				any other suggestions: vvv ? */
+	const int ap = (data1->plugin ? data2->plugin->prio : -666);
+	const int bp = (data2->plugin ? data2->plugin->prio : -666);
+
+	return (bp-ap);
+}
+
 /**
  * queries_reconnect()
  *
@@ -907,34 +915,10 @@
  */
 
 void queries_reconnect() {
+	int i;
 
-	int query_compare(query_t *a, query_t *b) {
-				/*	any other suggestions: vvv ? */
-		const int ap = (a->plugin ? a->plugin->prio : -666);
-		const int bp = (b->plugin ? b->plugin->prio : -666);
-		
-		return (bp-ap);
-	}
-
-	list_t tmplist;
-	list_t l, *ll;
-
-	for (ll = queries; ll <= &queries[QUERY_EXTERNAL]; ll++) {
-		tmplist = NULL;
-
-		for (l = *ll; l; l = l->next) {
-			if (l->data) {
-				if (!(LIST_ADD_SORTED(&tmplist, l->data, 0, query_compare))) {
-					debug_error("resort_queries(), list_add_sorted() failed, not continuing!\n");
-					list_destroy(tmplist, 0);
-					return;
-				}
-			}
-		}
-
-		list_destroy(*ll, 0);
-		*ll = tmplist;
-	}
+	for (i = 0; i <= QUERY_EXTERNAL; i++)
+		LIST_RESORT(&(queries[i]), query_compare);
 }
 
 /*


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