]> granicus.if.org Git - neomutt/commitdiff
column-length and byte-length are different
authorTAKIZAWA Takashi <taki@luna.email.ne.jp>
Sat, 12 Feb 2005 19:28:26 +0000 (19:28 +0000)
committerTAKIZAWA Takashi <taki@luna.email.ne.jp>
Sat, 12 Feb 2005 19:28:26 +0000 (19:28 +0000)
muttlib.c
pager.c

index f55c8d37a7ccfd81c7b4b11ca39b3a0f67e39859..83fa34596667e476e50a00cfbe0d74b908d78c39 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -933,11 +933,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)
   {
@@ -947,6 +948,7 @@ void mutt_FormatString (char *dest,         /* output buffer */
       {
        *wptr++ = '%';
        wlen++;
+       col++;
        src++;
        continue;
       }
@@ -1019,23 +1021,26 @@ void mutt_FormatString (char *dest,             /* output buffer */
        /* calculate space left on line.  if we've already written more data
           than will fit on the line, ignore the rest of the line */
        count = (COLS < destlen ? COLS : 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_strwidth (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 */
       }
@@ -1087,6 +1092,7 @@ void mutt_FormatString (char *dest,               /* output buffer */
        memcpy (wptr, buf, len);
        wptr += len;
        wlen += len;
+       col += mutt_strwidth (buf);
       }
     }
     else if (*src == '\\')
@@ -1117,11 +1123,13 @@ void mutt_FormatString (char *dest,             /* output buffer */
       src++;
       wptr++;
       wlen++;
+      col++;
     }
     else
     {
       *wptr++ = *src++;
       wlen++;
+      col++;
     }
   }
   *wptr = 0;
diff --git a/pager.c b/pager.c
index 4f094fa4e1bd45bce888ce96615cef93b5f8c254..b558431ae0f4e8cec32608d0d7d8d1f8a717d7d9 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -1710,15 +1710,17 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
       CLEARLINE (statusoffset);
       if (IsHeader (extra))
       {
-       _mutt_make_string (buffer,
-                          COLS-9 < sizeof (buffer) ? COLS-9 : sizeof (buffer),
-                          NONULL (PagerFmt), Context, extra->hdr, M_FORMAT_MAKEPRINT);
+       size_t l1 = (COLS - 9) * MB_LEN_MAX;
+       size_t l2 = sizeof (buffer);
+       _mutt_make_string (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt),
+                          Context, extra->hdr, M_FORMAT_MAKEPRINT);
       }
       else if (IsMsgAttach (extra))
       {
-       _mutt_make_string (buffer,
-                          COLS - 9 < sizeof (buffer) ? COLS - 9: sizeof (buffer),
-                          NONULL (PagerFmt), Context, extra->bdy->hdr, M_FORMAT_MAKEPRINT);
+       size_t l1 = (COLS - 9) * MB_LEN_MAX;
+       size_t l2 = sizeof (buffer);
+       _mutt_make_string (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt),
+                          Context, extra->bdy->hdr, M_FORMAT_MAKEPRINT);
       }
       mutt_paddstr (COLS-10, IsHeader (extra) || IsMsgAttach (extra) ?
                    buffer : banner);