#include <lib-crypt/crypt.h>
-#define SW (option(OPTMBOXPANE)?SidebarWidth:0)
-
/* Modified by blong to accept a "suggestion" for file name. If
* that file exists, then construct one with unique name but
* keep any extension. This might fail, I guess.
}
}
-ssize_t m_strformat(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, int width, const char *fmt,
+ format_t *callback, anytype cdata, format_flag flags)
{
ssize_t pos = flags & M_FORMAT_ARROWCURSOR ? 3 : 0;
+ m_strpad(dst, dlen, '\0', pos + 1);
+ if (!fmt)
+ return pos;
+
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) {
- ssize_t col;
char lower, nodots, buf[LONG_STRING];
case '>': /* right justify to EOL */
- col = mutt_strwidth(dst);
+ width -= mutt_strwidth(dst);
ch = *fmt++; /* pad char */
- if (COLS - SW > col) {
- m_strformat(buf, sizeof(buf), fmt, callback, data, flags);
- pos += m_strpad(dst + pos, dlen - pos, ch,
- COLS - SW - col - mutt_strwidth(buf));
+ if (width > 0) {
+ m_strformat(buf, sizeof(buf), 0, fmt, callback, cdata, flags);
+ width -= mutt_strwidth(buf);
+ pos += m_strpad(dst + pos, dlen - pos, ch, width);
pos += m_strcpy(dst + pos, dlen - pos, buf);
}
return pos; /* skip rest of input */
case '|': /* pad to EOL */
- return pos + m_strpad(dst + pos, dlen - pos, *fmt,
- COLS - SW - mutt_strwidth(dst));
+ width -= mutt_strwidth(dst);
+ return pos + m_strpad(dst + pos, dlen - pos, *fmt, width);
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);