Andreas Krennmair:
[apps/madmutt.git] / muttlib.c
index c3ec12b..6e95088 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
  *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  */ 
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "mutt.h"
 #include "mutt_curses.h"
 #include "mime.h"
@@ -935,11 +939,12 @@ void mutt_FormatString (char *dest,               /* output buffer */
 {
   char prefix[SHORT_STRING], buf[LONG_STRING], *cp, *wptr = dest, ch;
   char ifstring[SHORT_STRING], elsestring[SHORT_STRING];
-  size_t wlen, count, len;
+  size_t wlen, count, len, col, wid;
 
   prefix[0] = '\0';
   destlen--; /* save room for the terminal \0 */
   wlen = (flags & M_FORMAT_ARROWCURSOR && option (OPTARROWCURSOR)) ? 3 : 0;
+  col = wlen;
     
   while (*src && wlen < destlen)
   {
@@ -949,6 +954,7 @@ void mutt_FormatString (char *dest,         /* output buffer */
       {
        *wptr++ = '%';
        wlen++;
+       col++;
        src++;
        continue;
       }
@@ -1024,23 +1030,24 @@ void mutt_FormatString (char *dest,             /* output buffer */
          count = (COLS < destlen ? COLS : destlen);
        else
          count = ((COLS-SidebarWidth) < destlen ? COLS - SidebarWidth : destlen);
-       if (count > wlen)
+       if (count > col)
        {
-         count -= wlen; /* how many chars left on this line */
+         count -= col; /* how many columns left on this line */
          mutt_FormatString (buf, sizeof (buf), src, callback, data, flags);
-         len = mutt_strlen (buf);
-         if (count > len)
+         wid = mutt_strlen (buf);
+         if (count > wid)
          {
-           count -= len; /* how many chars to pad */
+           count -= wid; /* how many chars to pad */
            memset (wptr, ch, count);
            wptr += count;
-           wlen += count;
+           col += count;
          }
          if (len + wlen > destlen)
            len = destlen - wlen;
          memcpy (wptr, buf, len);
          wptr += len;
          wlen += len;
+         col += mutt_strwidth (buf);
        }
        break; /* skip rest of input */
       }
@@ -1092,6 +1099,7 @@ void mutt_FormatString (char *dest,               /* output buffer */
        memcpy (wptr, buf, len);
        wptr += len;
        wlen += len;
+       col += mutt_strwidth (buf);
       }
     }
     else if (*src == '\\')
@@ -1122,11 +1130,13 @@ void mutt_FormatString (char *dest,             /* output buffer */
       src++;
       wptr++;
       wlen++;
+      col++;
     }
     else
     {
       *wptr++ = *src++;
       wlen++;
+      col++;
     }
   }
   *wptr = 0;