Mercurial > hg
changeset 727:1c3620668857
Expand tabs when reading history files
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 05 Mar 2006 22:29:14 +0100 |
parents | 51be2bc1a820 |
children | 421b337dc6d2 |
files | mcabber/src/histolog.c mcabber/src/screen.c mcabber/src/utils.c mcabber/src/utils.h |
diffstat | 4 files changed, 43 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/mcabber/src/histolog.c Sun Mar 05 19:09:17 2006 +0100 +++ b/mcabber/src/histolog.c Sun Mar 05 22:29:14 2006 +0100 @@ -33,6 +33,7 @@ #include "utils.h" #include "logprint.h" #include "settings.h" +#include "utils.h" static guint UseFileLogging; static guint FileLoadLogs; @@ -123,6 +124,7 @@ char *filename; guchar type, info; char *data, *tail; + char *xtext; time_t timestamp; guint prefix_flags; guint len; @@ -217,8 +219,10 @@ prefix_flags = HBB_PREFIX_OUT; else prefix_flags = HBB_PREFIX_IN; - hbuf_add_line(p_buddyhbuf, &data[26], timestamp, - prefix_flags, width); + xtext = ut_expand_tabs(&data[26]); // Expand tabs + hbuf_add_line(p_buddyhbuf, xtext, timestamp, prefix_flags, width); + if (xtext != &data[26]) + g_free(xtext); err = 0; } }
--- a/mcabber/src/screen.c Sun Mar 05 19:09:17 2006 +0100 +++ b/mcabber/src/screen.c Sun Mar 05 22:29:14 2006 +0100 @@ -978,29 +978,11 @@ inline void scr_WriteMessage(const char *jid, const char *text, time_t timestamp, guint prefix_flags) { - char *p, *xtext; - guint8 n =0; + char *xtext; if (!timestamp) timestamp = time(NULL); - 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++); - } + xtext = ut_expand_tabs(text); // Expand tabs // XXX Are there other special chars we should filter out?
--- a/mcabber/src/utils.c Sun Mar 05 19:09:17 2006 +0100 +++ b/mcabber/src/utils.c Sun Mar 05 22:29:14 2006 +0100 @@ -459,4 +459,38 @@ } } +// ut_expand_tabs(text) +// Expand tabs in string text. +// If there is no tab in the string, a pointer to text is returned (be +// careful _not_ to free the pointer in this case). +// If there are some tabs, a new string with expanded chars is returned; this +// is up to the caller to free this string after use. +char *ut_expand_tabs(const char *text) +{ + char *xtext; + char *p, *q; + guint8 n=0; + + xtext = (char*)text; + for (p=xtext; *p; p++) + if (*p == '\t') n++; + + if (!n) + return (char*)text; + + 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++); + + return xtext; +} + + /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */