diff mcabber/src/hbuf.c @ 184:b5aa2b9c425a

[/trunk] Changeset 196 by mikael * Don't use a char* as prefix, but split it to timestamp + flags. * Don't use a boolean for timestamp, use a time_t (actually we always use a timestamp so the bool made no sense...).
author mikael
date Thu, 05 May 2005 19:38:44 +0000
parents f7b03201877a
children 4f3975f1b852
line wrap: on
line diff
--- a/mcabber/src/hbuf.c	Thu May 05 15:01:48 2005 +0000
+++ b/mcabber/src/hbuf.c	Thu May 05 19:38:44 2005 +0000
@@ -26,7 +26,6 @@
 
 /* This is a private structure type */
 
-#define PREFIX_LENGTH 32
 typedef struct {
   char *ptr;
   char *ptr_end;        // beginning of the block
@@ -36,20 +35,21 @@
   // XXX This should certainly be a pointer, and be allocated only when needed
   // (for ex. when HBB_FLAG_PERSISTENT is set).
   struct { // hbuf_line_info
-    char prefix[PREFIX_LENGTH];
-  } persist;
+    time_t timestamp;
+    guchar flags;
+  } prefix;
 } hbuf_block;
 
 
-//  hbuf_add_line(p_hbuf, text, prefix, width)
+//  hbuf_add_line(p_hbuf, text, prefix_flags, width)
 // Add a line to the given buffer.  If width is not null, then lines are
 // wrapped at this length.
 //
 // Note 1: Splitting according to width won't work if there are tabs; they
 //         should be expanded before.
 // Note 2: width does not include the ending \0.
-void hbuf_add_line(GList **p_hbuf, const char *text, const char *prefix,
-        unsigned int width)
+void hbuf_add_line(GList **p_hbuf, const char *text, time_t timestamp,
+        guint prefix_flags, guint width)
 {
   GList *hbuf = *p_hbuf;
   char *line, *cr, *end;
@@ -58,8 +58,8 @@
   if (!text) return;
 
   hbuf_block_elt = g_new0(hbuf_block, 1);
-  if (prefix)
-    strncpy(hbuf_block_elt->persist.prefix, prefix, PREFIX_LENGTH-1);
+  hbuf_block_elt->prefix.timestamp  = timestamp;
+  hbuf_block_elt->prefix.flags      = prefix_flags;
   if (!hbuf) {
     do {
       hbuf_block_elt->ptr  = g_new(char, HBB_BLOCKSIZE);
@@ -217,28 +217,33 @@
   }
 }
 
-//  hbuf_get_lines(hbuf, n, where)
+//  hbuf_get_lines(hbuf, n, where)  FIXME bad comments XXX
 // Returns an array of 2*n pointers (for n prefixes + n lines from hbuf)
 // (prefix line 1, line 1, prefix line 2, line 2, etc.)
 // (The first line will be the line currently pointed by hbuf)
 // Note:The caller should free the array after use.
-char **hbuf_get_lines(GList *hbuf, unsigned int n)
+hbb_line **hbuf_get_lines(GList *hbuf, unsigned int n)
 {
   unsigned int i;
 
-  char **array = g_new0(char*, n*2);
-  char **array_elt = array;
+  hbb_line **array = g_new0(hbb_line*, n);
+  hbb_line **array_elt = array;
 
   for (i=0 ; i < n ; i++) {
     if (hbuf) {
       hbuf_block *blk = (hbuf_block*)(hbuf->data);
       int maxlen;
       maxlen = blk->ptr_end - blk->ptr;
-      *array_elt++ = blk->persist.prefix;
-      *array_elt++ = g_strndup(blk->ptr, maxlen);
+      *array_elt = (hbb_line*)g_new(hbb_line, 1);
+      (*array_elt)->timestamp = blk->prefix.timestamp;
+      (*array_elt)->flags     = blk->prefix.flags;
+      (*array_elt)->text      = g_strndup(blk->ptr, maxlen);
+
       hbuf = g_list_next(hbuf);
     } else
-      *array_elt++ = NULL;
+      break;
+
+    array_elt++;
   }
 
   return array;