[ekg2-commit] r4098 - trunk/ekg: trunk/ekg/dynstuff_inline.h trunk/ekg/stuff.c
SVN commit
svn w toxygen.net
Czw, 10 Lip 2008, 21:50:05 CEST
Author: darkjames
Date: 2008-07-10 21:50:04 +0200 (Thu, 10 Jul 2008)
New Revision: 4098
Modified:
trunk/ekg/dynstuff_inline.h
trunk/ekg/stuff.c
Log:
- convert buffers to new list api
- fix /say && friends
Modified: trunk/ekg/dynstuff_inline.h
===================================================================
--- trunk/ekg/dynstuff_inline.h 2008-07-10 18:06:36 UTC (rev 4097)
+++ trunk/ekg/dynstuff_inline.h 2008-07-10 19:50:04 UTC (rev 4098)
@@ -186,6 +186,9 @@
#if DYNSTUFF_USE_LIST3
+#define __DYNSTUFF_ADD(prefix, typ, __notused) \
+ void prefix##_add(typ **lista, typ *new) { list_add3((list_t *) lista, (list_t) new); }
+
#define __DYNSTUFF_ADD_BEGINNING(prefix, typ, __notused) \
void prefix##_add(typ **lista, typ *new) { list_add_beginning3((list_t *) lista, (list_t) new); }
@@ -213,6 +216,11 @@
return list_count((list_t) lista); \
}
+#define __DYNSTUFF_GET_NTH(prefix, typ) \
+ typ *prefix##_get_nth(typ *lista, int id) { \
+ return list_get_nth3((list_t) lista, id); \
+ }
+
#else
/* XXX, checkit */
@@ -359,6 +367,17 @@
return count; \
}
+#define __DYNSTUFF_GET_NTH(prefix, typ) \
+ typ *prefix##_get_nth(typ *lista, int id) { \
+ while (lista) { \
+ if ((--id) == 0) \
+ return lista; \
+ \
+ lista = lista->next; \
+ } \
+ return NULL; \
+ }
+
#endif
#define __DYNSTUFF_NOREMOVE(lista, typ, free_func)
Modified: trunk/ekg/stuff.c
===================================================================
--- trunk/ekg/stuff.c 2008-07-10 18:06:36 UTC (rev 4097)
+++ trunk/ekg/stuff.c 2008-07-10 19:50:04 UTC (rev 4098)
@@ -438,12 +438,15 @@
bindings_added_destroy();
}
-static LIST_FREE_ITEM(list_buffer_free, struct buffer *) {
- xfree(data->line);
- xfree(data->target);
-}
+static LIST_FREE_ITEM(list_buffer_free, struct buffer *) { xfree(data->line); xfree(data->target); }
-inline static void buffer_add_common(struct buffer_info *type, const char *target, const char *line, time_t ts) {
+static __DYNSTUFF_ADD(buffers, struct buffer, NULL) /* buffers_add() */
+static __DYNSTUFF_REMOVE_ITER(buffers, struct buffer, list_buffer_free) /* buffers_removei() */
+static __DYNSTUFF_DESTROY(buffers, struct buffer, list_buffer_free) /* buffers_destroy() */
+static __DYNSTUFF_COUNT(buffers, struct buffer) /* buffers_count() */
+static __DYNSTUFF_GET_NTH(buffers, struct buffer) /* buffers_get_nth() */
+
+static void buffer_add_common(struct buffer_info *type, const char *target, const char *line, time_t ts) {
struct buffer *b;
struct buffer **addpoint = (type->last ? &(type->last) : &(type->data));
@@ -460,20 +463,25 @@
*/
if (type->max_lines) { /* XXX: move to idles? */
+ int n;
bac_countupd:
- b = type->data;
- int n = type->count - type->max_lines + 1;
+ n = type->count - type->max_lines + 1;
if (n > 0) { /* list slice removal */
- b = LIST_GET_NTH2(b, n); /* last element to remove */
+ b = buffers_get_nth(type->data, n); /* last element to remove */
if (!b) { /* count has been broken */
- type->count = LIST_COUNT2(type->data);
+ type->count = buffers_count(type->data);
goto bac_countupd;
}
type->data = b->next;
b->next = NULL; /* unlink elements to be removed */
type->count -= n;
- LIST_DESTROY2(b, list_buffer_free); /* and remove them */
+ /* XXX,
+ * b->next == NULL
+ * so buffers_destroy(&b) will free only b,
+ * shouldn't be saved type->data value?
+ */
+ buffers_destroy(&b); /* and remove them */
}
}
@@ -482,7 +490,7 @@
b->target = xstrdup(target);
b->line = xstrdup(line);
- LIST_ADD2(addpoint, b);
+ buffers_add(addpoint, b);
type->last = b;
type->count++;
@@ -562,9 +570,13 @@
b = type->data;
str = b->line; /* save b->line */
+ b->line = NULL;
- xfree(b->target); /* free b->target */
- LIST_REMOVE2(type, b, NULL); /* remove struct */
+ (void) buffers_removei(&(type->data), b);
+
+ if (type->last == b)
+ type->last = NULL;
+
type->count--;
return str; /* return saved b->line */
@@ -584,8 +596,9 @@
if (!type || !type->data)
return;
- LIST_DESTROY2(type->data, list_buffer_free);
- type->data = NULL;
+ buffers_destroy(&(type->data));
+
+ type->last = NULL;
type->count = 0;
}
Więcej informacji o liście dyskusyjnej ekg2-commit