{
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)
{
{
*wptr++ = '%';
wlen++;
+ col++;
src++;
continue;
}
/* 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 */
}
memcpy (wptr, buf, len);
wptr += len;
wlen += len;
+ col += mutt_strwidth (buf);
}
}
else if (*src == '\\')
src++;
wptr++;
wlen++;
+ col++;
}
else
{
*wptr++ = *src++;
wlen++;
+ col++;
}
}
*wptr = 0;
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);