comparison mcabber/src/utils.c @ 1568:e89787ee40f7

Fix tab expansion when using say_to -f
author Myhailo Danylenko <isbear@ukrpost.net>
date Tue, 10 Mar 2009 20:44:16 +0100
parents 9f92c0edde1c
children a087125d8fc8
comparison
equal deleted inserted replaced
1567:48c2060845ac 1568:e89787ee40f7
493 // If there are some tabs or bad chars, a new string with expanded chars 493 // If there are some tabs or bad chars, a new string with expanded chars
494 // and no bad chars is returned; this is up to the caller to free this 494 // and no bad chars is returned; this is up to the caller to free this
495 // string after use. 495 // string after use.
496 char *ut_expand_tabs(const char *text) 496 char *ut_expand_tabs(const char *text)
497 { 497 {
498 char *xtext; 498 char *xtext, *linestart;
499 char *p, *q; 499 char *p, *q;
500 guint n = 0, bc = 0; 500 guint n = 0, bc = 0;
501 501
502 xtext = (char*)text; 502 xtext = (char*)text;
503 for (p=xtext; *p; p++) 503 for (p=xtext; *p; p++)
510 if (!n && !bc) 510 if (!n && !bc)
511 return (char*)text; 511 return (char*)text;
512 512
513 xtext = g_new(char, strlen(text) + 1 + 8*n); 513 xtext = g_new(char, strlen(text) + 1 + 8*n);
514 p = (char*)text; 514 p = (char*)text;
515 q = xtext; 515 q = linestart = xtext;
516 do { 516 do {
517 if (*p == '\t') { 517 if (*p == '\t') {
518 do { *q++ = ' '; } while ((q-xtext)%8); 518 do { *q++ = ' '; } while ((q-linestart)%8);
519 } else if (*p != '\x0d') { 519 } else if (*p != '\x0d') {
520 *q++ = *p; 520 *q++ = *p;
521 if (*p =='\n')
522 linestart = q;
521 } 523 }
522 } while (*p++); 524 } while (*p++);
523 525
524 return xtext; 526 return xtext;
525 } 527 }