}
}
-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, anytype cdata, format_flag flags)
{
- ssize_t pos = (flags & M_FORMAT_ARROWCURSOR && option (OPTARROWCURSOR)) ? 3 : 0;
+ ssize_t pos = flags & M_FORMAT_ARROWCURSOR ? 3 : 0;
+
+ m_strpad(dst, dlen, '\0', pos + 1);
+ if (!fmt)
+ return;
while (*fmt) {
- char ifstring[STRING] = "", elsestring[STRING] = "", prefix[STRING] = "";
int ch;
if (*fmt == '%') {
+ char ifstr[STRING], elstr[STRING], prefix[STRING];
+
+ *ifstr = *elstr = *prefix = '\0';
+
if (*++fmt == '%') {
- pos += m_strputc(dst + pos, dlen - pos, '%');
- fmt++;
+ pos += m_strputc(dst + pos, dlen - pos, *fmt++);
continue;
}
/* eat the `if' part of the string */
iflen = strcspn(fmt, "?&");
- m_strncpy(ifstring, ssizeof(ifstring), fmt, iflen);
+ m_strncpy(ifstr, ssizeof(ifstr), fmt, iflen);
fmt += iflen;
/* eat the `else' part of the string (optional) */
fmt++; /* skip the & */
p = m_strchrnul(fmt, '?');
- m_strncpy(elsestring, ssizeof(elsestring), fmt, p - fmt);
+ m_strncpy(elstr, ssizeof(elstr), fmt, p - fmt);
fmt = p;
if (!*fmt++) /* move past the trailing `?' */
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, cdata, 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 */
- case '|':
- col = mutt_strwidth(dst);
-
- ch = *fmt++;
- /* pad to EOL */
- pos += m_strpad(dst + pos, dlen - pos, ch, COLS - SW - col);
- return pos; /* skip rest of input */
+ case '|': /* pad to EOL */
+ return pos + m_strpad(dst + pos, dlen - pos, *fmt,
+ COLS - SW - mutt_strwidth(dst));
default:
lower = nodots = 0;
/* use callback function to handle this case */
fmt = callback(buf, sizeof (buf), ch, fmt, prefix,
- ifstring, elsestring, data, flags);
+ ifstr, elstr, cdata, flags);
if (lower)
m_strtolower(buf);
}
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, "%\\");