}
}
-ssize_t
-mutt_FormatString(char *dst, ssize_t dlen, const char *fmt,
- format_t *callback, unsigned long data, format_flag flags)
+ssize_t m_strformat(char *dst, ssize_t dlen, const char *fmt,
+ format_t *callback, unsigned long data, format_flag flags)
{
ssize_t pos = (flags & M_FORMAT_ARROWCURSOR && option (OPTARROWCURSOR)) ? 3 : 0;
while (*fmt) {
- char ifstring[STRING] = "", elsestring[STRING] = "", prefix[STRING] = "";
+ char ifstring[STRING], elsestring[STRING], prefix[STRING] = "";
int ch;
if (*fmt == '%') {
if (*++fmt == '%') {
- pos += m_strputc(dst + pos, dlen - pos, '%');
- fmt++;
+ pos += m_strputc(dst + pos, dlen - pos, *fmt++);
continue;
}
if (!*fmt++) /* move past the trailing `?' */
break; /* bad format */
+ } else {
+ *ifstring = *elsestring = '\0';
}
switch (ch) {
ch = *fmt++; /* pad char */
if (COLS - SW > col) {
- ssize_t wid;
-
- mutt_FormatString(buf, sizeof(buf), fmt, callback, data, flags);
- wid = mutt_strwidth(buf);
-
- pos += m_strpad(dst + pos, dlen - pos, ch, COLS - SW - col - wid);
+ m_strformat(buf, sizeof(buf), fmt, callback, data, flags);
+ pos += m_strpad(dst + pos, dlen - pos, ch,
+ COLS - SW - col - mutt_strwidth(buf));
pos += m_strcpy(dst + pos, dlen - pos, buf);
}
return pos; /* skip rest of input */
}
pos += m_strcpy(dst + pos, dlen - pos, buf);
- continue;
+ break;
}
+ continue;
}
if (*fmt == '\\') {
if (!*++fmt)
break;
- switch (*fmt) {
+ switch ((ch = *fmt++)) {
case 'n': pos += m_strputc(dst + pos, dlen - pos, '\n'); break;
case 't': pos += m_strputc(dst + pos, dlen - pos, '\t'); break;
case 'r': pos += m_strputc(dst + pos, dlen - pos, '\r'); break;
case 'f': pos += m_strputc(dst + pos, dlen - pos, '\f'); break;
case 'v': pos += m_strputc(dst + pos, dlen - pos, '\v'); break;
- default: pos += m_strputc(dst + pos, dlen - pos, *fmt); break;
+ default: pos += m_strputc(dst + pos, dlen - pos, ch); break;
}
- fmt++;
} else {
ssize_t len = strcspn(fmt, "%\\");