X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=muttlib.c;h=9c108b730da64dfc32d73a7157624d2b6a2ab4b1;hp=e56bbcd012a2e456433884f310956cf1214009f0;hb=3242c00b2d3f7f1c1554bcebfb8a390fddea095f;hpb=3755188848d66fd8c0638ce8514fbf57aa94518f diff --git a/muttlib.c b/muttlib.c index e56bbcd..9c108b7 100644 --- a/muttlib.c +++ b/muttlib.c @@ -328,20 +328,18 @@ void mutt_safe_path(char *s, ssize_t l, address_t *a) } } -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; + ssize_t pos = flags & M_FORMAT_ARROWCURSOR ? 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; } @@ -384,6 +382,8 @@ mutt_FormatString(char *dst, ssize_t dlen, const char *fmt, if (!*fmt++) /* move past the trailing `?' */ break; /* bad format */ + } else { + *ifstring = *elsestring = '\0'; } switch (ch) { @@ -396,23 +396,16 @@ mutt_FormatString(char *dst, ssize_t dlen, const char *fmt, 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 */ - 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; @@ -440,22 +433,22 @@ mutt_FormatString(char *dst, ssize_t dlen, const char *fmt, } 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, "%\\");