changeset 725:1aff92625bdb

Expand tabs when receiving a message
author Mikael Berthe <mikael@lilotux.net>
date Sun, 05 Mar 2006 18:48:43 +0100
parents 264375fe7159
children 51be2bc1a820
files mcabber/src/screen.c
diffstat 1 files changed, 28 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/screen.c	Sun Mar 05 16:54:01 2006 +0100
+++ b/mcabber/src/screen.c	Sun Mar 05 18:48:43 2006 +0100
@@ -987,12 +987,38 @@
 void scr_WriteIncomingMessage(const char *jidfrom, const char *text,
         time_t timestamp, guint prefix)
 {
+  char *p, *xtext;
+  guint8 n =0;
+
   if (!(prefix & ~HBB_PREFIX_NOFLAG))
     prefix |= HBB_PREFIX_IN;
-  // FIXME expand tabs / filter out special chars...
-  scr_WriteMessage(jidfrom, text, timestamp, prefix);
+
+  xtext = (char*)text;
+
+  // Expand tabs
+  for (p=xtext; *p; p++)
+    if (*p == '\t') n++;
+  if (n) {
+    char *q;
+    xtext = g_new(char, strlen(text) + 1 + 8*n);
+    p = (char*)text;
+    q = xtext;
+    do {
+      if (*p == '\t') {
+        do { *q++ = ' '; } while ((q-xtext)%8);
+      } else {
+        *q++ = *p;
+      }
+    } while (*p++);
+  }
+
+  // FIXME Filter out special chars...
+  scr_WriteMessage(jidfrom, xtext, timestamp, prefix);
   update_panels();
   doupdate();
+
+  if (xtext != (char*)text)
+    g_free(xtext);
 }
 
 void scr_WriteOutgoingMessage(const char *jidto, const char *text)