[ekg2-commit] r4062 - trunk/ekg: trunk/ekg/commands.c trunk/ekg/dynstuff_inline.h trunk/ekg/ekg.c trunk/ekg/plugins.h trunk/ekg/themes.c trunk/ekg/vars.c trunk/ekg/vars.h trunk/ekg/windows.c trunk/ekg/windows.h

SVN commit svn w toxygen.net
Wto, 8 Lip 2008, 10:17:16 CEST


Author: darkjames
Date: 2008-07-08 10:17:16 +0200 (Tue, 08 Jul 2008)
New Revision: 4062

Modified:
   trunk/ekg/commands.c
   trunk/ekg/dynstuff_inline.h
   trunk/ekg/ekg.c
   trunk/ekg/plugins.h
   trunk/ekg/themes.c
   trunk/ekg/vars.c
   trunk/ekg/vars.h
   trunk/ekg/windows.c
   trunk/ekg/windows.h
Log:
variables, formats, windows



Modified: trunk/ekg/commands.c
===================================================================
--- trunk/ekg/commands.c	2008-07-08 07:38:48 UTC (rev 4061)
+++ trunk/ekg/commands.c	2008-07-08 08:17:16 UTC (rev 4062)
@@ -4054,7 +4054,7 @@
 	}
 
 	if (params[1] && (pl = plugin_find(params[0]))) {
-		LIST_UNLINK2(&plugins, pl);
+		plugins_unlink(pl);
 		plugin_register(pl, atoi(params[1])); 
 
 		queries_reconnect();

Modified: trunk/ekg/dynstuff_inline.h
===================================================================
--- trunk/ekg/dynstuff_inline.h	2008-07-08 07:38:48 UTC (rev 4061)
+++ trunk/ekg/dynstuff_inline.h	2008-07-08 08:17:16 UTC (rev 4062)
@@ -77,10 +77,6 @@
 			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;		\

Modified: trunk/ekg/ekg.c
===================================================================
--- trunk/ekg/ekg.c	2008-07-08 07:38:48 UTC (rev 4061)
+++ trunk/ekg/ekg.c	2008-07-08 08:17:16 UTC (rev 4062)
@@ -1182,7 +1182,7 @@
 	audio_deinitialize();
 	alias_free();
 	theme_free();
-	variable_free();
+	variables_destroy();
 	script_variables_free(1);
 	emoticons_destroy();
 	commands_destroy();
@@ -1195,15 +1195,11 @@
 
 	xfree(read_file(NULL, -1));	/* free internal read_file() buffer */
 
-	{
-		window_t *w;
+/* windows: */
+	windows_destroy();
+	window_status = NULL; window_debug = NULL; window_current = NULL;	/* just in case */
 
-		for (w = windows; w; w = w->next) /* XXX: some LIST_ITEM_FREE ? */
-			xfree(w->target);
-
-		LIST_DESTROY2(windows, NULL);	window_status = NULL; window_debug = NULL; window_current = NULL;	/* just in case */
-	}
-
+/* queries: */
 	{
 		query_t **ll;
 

Modified: trunk/ekg/plugins.h
===================================================================
--- trunk/ekg/plugins.h	2008-07-08 07:38:48 UTC (rev 4061)
+++ trunk/ekg/plugins.h	2008-07-08 08:17:16 UTC (rev 4062)
@@ -83,6 +83,7 @@
 int plugin_var_add(plugin_t *pl, const char *name, int type, const char *value, int secret, plugin_notify_func_t *notify);
 int plugin_var_find(plugin_t *pl, const char *name);
 
+void plugins_unlink(plugin_t *pl);
 #endif
 
 #ifdef USINGANANTIQUECOMPILER

Modified: trunk/ekg/themes.c
===================================================================
--- trunk/ekg/themes.c	2008-07-08 07:38:48 UTC (rev 4061)
+++ trunk/ekg/themes.c	2008-07-08 08:17:16 UTC (rev 4062)
@@ -38,6 +38,7 @@
 #include "userlist.h"
 
 #include "debug.h"
+#include "dynstuff_inline.h"
 #include "queries.h"
 
 static char *prompt_cache = NULL, *prompt2_cache = NULL, *error_cache = NULL;
@@ -47,19 +48,24 @@
 static int no_prompt_cache_hash = 0x139dcbd6;	/* hash value of "no_prompt_cache" */
 
 struct format {
+	struct format *next;
 	char *name;
 	int name_hash;
 	char *value;
 };
 
-static list_t formats[0x100];
+static struct format* formats[0x100];
 
 static LIST_FREE_ITEM(list_format_free, struct format *) {
 	xfree(data->value);
 	xfree(data->name);
-	xfree(data);
 }
 
+__DYNSTUFF_ADD_BEGINNING(formats, struct format);				/* formats_add() */
+__DYNSTUFF_REMOVE_ITER(formats, struct format, list_format_free);		/* formats_removei() */
+__DYNSTUFF_DESTROY(formats, struct format, list_format_free);			/* formats_destroy() */
+
+
 /**
  * gim_hash()
  *
@@ -88,9 +94,9 @@
  */
 const char *format_find(const char *name)
 {
+	struct format *fl;
 	const char *tmp;
 	int hash;
-	list_t l;
 
 	if (!name)
 		return "";
@@ -117,8 +123,8 @@
 
 	hash = gim_hash(name);
 
-	for (l = formats[hash & 0xff]; l; l = l->next) {
-		struct format *f = l->data;
+	for (fl = formats[hash & 0xff]; fl; fl = fl->next) {
+		struct format *f = fl;
 
 		if (hash == f->name_hash && !xstrcmp(f->name, name))
 			return f->value;
@@ -924,8 +930,8 @@
  */
 
 void format_add(const char *name, const char *value, int replace) {
+	struct format *fl;
 	struct format *f;
-	list_t l;
 	int hash;
 
 	if (!name || !value)
@@ -938,8 +944,8 @@
 		return;
 	}
 
-	for (l = formats[hash & 0xff]; l; l = l->next) {
-		struct format *f = l->data;
+	for (fl = formats[hash & 0xff]; fl; fl = fl->next) {
+		struct format *f = fl;
 
 		if (hash == f->name_hash && !xstrcmp(name, f->name)) {
 			if (replace) {
@@ -955,7 +961,7 @@
 	f->name_hash	= hash;
 	f->value	= xstrdup(value);
 
-	list_add_beginning(&(formats[hash & 0xff]), f);
+	formats_add(&(formats[hash & 0xff]), f);
 	return;
 }
 
@@ -973,7 +979,7 @@
  */
 
 static int format_remove(const char *name) {
-	list_t l;
+	struct format *fl;
 	int hash;
 
 	if (!name)
@@ -981,11 +987,11 @@
 
 	hash = gim_hash(name);
 
-	for (l = formats[hash & 0xff]; l; l = l->next) {
-		struct format *f = l->data;
+	for (fl = formats[hash & 0xff]; fl; fl = fl->next) {
+		struct format *f = fl;
 
 		if (hash == f->name_hash && !xstrcmp(f->name, name)) {
-			LIST_REMOVE(&(formats[hash & 0xff]), f, list_format_free);
+			(void) formats_removei(&(formats[hash & 0xff]), f);
 			return 0;
 		}
 	}
@@ -1116,10 +1122,8 @@
 void theme_free() {
 	int i;
 
-	for (i = 0; i < 0x100; i++) {
-		LIST_DESTROY(formats[i], list_format_free);
-		formats[i] = NULL;
-	}
+	for (i = 0; i < 0x100; i++)
+		formats_destroy(&(formats[i]));
 
 	no_prompt_cache = 0;
 

Modified: trunk/ekg/vars.c
===================================================================
--- trunk/ekg/vars.c	2008-07-08 07:38:48 UTC (rev 4061)
+++ trunk/ekg/vars.c	2008-07-08 08:17:16 UTC (rev 4062)
@@ -41,13 +41,17 @@
 #include "xmalloc.h"
 #include "plugins.h"
 
+#include "dynstuff_inline.h"
 #include "queries.h"
 
-variable_t *variables = NULL;
+void changed_session_locks(const char *varname); /* sessions.c */
 char *console_charset;
 
-void changed_session_locks(const char *varname); /* sessions.c */
+static LIST_ADD_COMPARE(variable_add_compare, variable_t *) { return xstrcasecmp(data1->name, data2->name); }
+__DYNSTUFF_LIST_ADD_SORTED(variables, variable_t, variable_add_compare);	/* variables_add() */
 
+variable_t *variables = NULL;
+
 /*
  * dd_*()
  *
@@ -247,17 +251,6 @@
 }
 
 /*
- * variable_add_compare()
- *
- * funkcja porównująca nazwy zmiennych,, by występowały alfabetycznie w liście.
- *
- *  - data1, data2 - dwa wpisy zmiennychd do porównania.
- *
- * zwraca wynik xstrcasecmp() na nazwach zmiennych.
- */
-static LIST_ADD_COMPARE(variable_add_compare, variable_t *) { return xstrcasecmp(data1->name, data2->name); }
-
-/*
  * variable_add()
  *
  * dodaje zmienną do listy zmiennych.
@@ -323,7 +316,8 @@
 	v->dyndisplay 	= dyndisplay;
 	v->plugin 	= plugin;
 
-	return LIST_ADD_SORTED2(&variables, v, variable_add_compare);
+	variables_add(v);
+	return v;
 }
 
 /*
@@ -559,15 +553,7 @@
 	}
 }
 
-/*
- * variable_free()
- *
- * zwalnia pamięć używaną przez zmienne.
- */
-void variable_free() {
-	LIST_DESTROY2(variables, variable_list_freeone);
-	variables = NULL;
-}
+__DYNSTUFF_LIST_DESTROY(variables, variable_t, variable_list_freeone);	/* variables_destroy() */
 
 /*
  * variable_help()

Modified: trunk/ekg/vars.h
===================================================================
--- trunk/ekg/vars.h	2008-07-08 07:38:48 UTC (rev 4061)
+++ trunk/ekg/vars.h	2008-07-08 08:17:16 UTC (rev 4062)
@@ -88,7 +88,7 @@
 
 int variable_set(const char *name, const char *value, int allow_foreign);
 void variable_help(const char *name);
-void variable_free();
+void variables_destroy();
 
 #endif
 

Modified: trunk/ekg/windows.c
===================================================================
--- trunk/ekg/windows.c	2008-07-08 07:38:48 UTC (rev 4061)
+++ trunk/ekg/windows.c	2008-07-08 08:17:16 UTC (rev 4062)
@@ -41,11 +41,21 @@
 #include "stuff.h"
 #include "xmalloc.h"
 
+#include "dynstuff_inline.h"
 #include "queries.h"
 
 int window_last_id = -1;		/* ostatnio wyświetlone okno */
 
 window_t *windows = NULL;		/* lista okien */
+
+static LIST_ADD_COMPARE(window_new_compare, window_t *) { return data1->id - data2->id; }
+static LIST_FREE_ITEM(list_window_free, window_t *) { xfree(data->target);  userlist_free_u(&(data->userlist)); }
+
+__DYNSTUFF_LIST_ADD_SORTED(windows, window_t, window_new_compare);				/* windows_add() */
+__DYNSTUFF_LIST_UNLINK(windows, window_t);							/* windows_unlink() */
+__DYNSTUFF_LIST_REMOVE_SAFE(windows, window_t, list_window_free);				/* windows_remove() */
+__DYNSTUFF_LIST_DESTROY(windows, window_t, list_window_free);					/* windows_destroy() */
+
 int config_display_crap = 1;		/* czy wyświetlać śmieci? */
 
 window_t *window_current = NULL;	/* okno aktualne, zawsze na coś musi wskazywać! */
@@ -226,19 +236,6 @@
 }
 
 /**
- * window_new_compare()
- *
- * internal function to sort windows by id
- * used by LIST_ADD_SORTED()
- *
- * @param data1 - first window_t to compare
- * @param data2 - second window_t to compare
- *
- * @return It returns result of window id subtractions.
- */
-static LIST_ADD_COMPARE(window_new_compare, window_t *) { return data1->id - data2->id; }
-
-/**
  * window_new()
  *
  * Create new window_t, with given @a new_id (if @a new_id != 0)
@@ -328,7 +325,7 @@
 	w->session = session;
 /*	w->userlist = NULL; */		/* xmalloc memset() to 0 memory */
 
-	LIST_ADD_SORTED2(&windows, w, window_new_compare);
+	windows_add(w);
 	query_emit_id(NULL, UI_WINDOW_NEW, &w);	/* XXX */
 
 	return w;
@@ -441,10 +438,10 @@
 
 	if (id == 1 && w->target) {
 		print("query_finished", w->target, session_name(w->session));
-		xfree(window_current->target);
+		list_window_free(w);
+
 		w->target	= NULL;
 /*		w->session	= NULL; */
-		userlist_free_u(&(w->userlist));	/* wtf? */
 
 		query_emit_id(NULL, UI_WINDOW_TARGET_CHANGED, &w);
 		return;
@@ -475,10 +472,7 @@
 	}
 
 	query_emit_id(NULL, UI_WINDOW_KILL, &w);
-
-	xfree(w->target);
-	userlist_free_u(&(w->userlist));
-	LIST_REMOVE2(&windows, w, NULL);	/* XXX: LIST_ITEM_FREE ? */
+	windows_remove(w);
 }
 
 /**
@@ -523,14 +517,14 @@
 	if (!(w1 = window_exist(first)) || !(w2 = window_exist(second)))
 		return;
 
-        LIST_UNLINK2(&windows, w1);
-	w1->id = second;
+	windows_unlink(w1);
+	windows_unlink(w2);
 
-        LIST_UNLINK2(&windows, w2);
+	w1->id = second;
 	w2->id = first;
 
-	LIST_ADD_SORTED2(&windows, w1, window_new_compare);
-	LIST_ADD_SORTED2(&windows, w2, window_new_compare);
+	windows_add(w1);
+	windows_add(w2);
 }
 
 /* really move window, i.e. insert it at given id and move right all other windows */
@@ -561,8 +555,8 @@
 	}
 	ws->id = dest;
 
-	LIST_UNLINK2(&windows, ws);
-	LIST_ADD_SORTED2(&windows, ws, window_new_compare);
+	windows_unlink(ws);
+	windows_add(ws);
 }
 
 /**

Modified: trunk/ekg/windows.h
===================================================================
--- trunk/ekg/windows.h	2008-07-08 07:38:48 UTC (rev 4061)
+++ trunk/ekg/windows.h	2008-07-08 08:17:16 UTC (rev 4062)
@@ -105,6 +105,8 @@
 
 int window_lock_inc(window_t *w);
 int window_lock_dec(window_t *w);
+
+void windows_destroy(void);
 #endif
 
 COMMAND(cmd_window);



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