}
ssize_t m_strformat(char *dst, ssize_t dlen, const char *fmt,
- format_t *callback, unsigned long data, format_flag flags)
+ 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++);
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 `?' */
break; /* bad format */
- } else {
- *ifstring = *elsestring = '\0';
}
switch (ch) {
ch = *fmt++; /* pad char */
if (COLS - SW > col) {
- m_strformat(buf, sizeof(buf), fmt, callback, data, flags);
+ 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);